@@ -0,0 +1,127 @@
2+ * Copyright (C) 2006, 2007 Apple Inc.
3+ * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5+ * Copyright (C) 2009 Michael Snoyman <michael@snoyman.com>
7+ * Redistribution and use in source and binary forms, with or without
8+ * modification, are permitted provided that the following conditions
10+ * 1. Redistributions of source code must retain the above copyright
11+ * notice, this list of conditions and the following disclaimer.
12+ * 2. Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
16+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
17+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
20+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+#include <webkit/webkit.h>
32+static GtkWidget* main_window;
33+static WebKitWebView* web_view;
34+static gchar* main_title;
37+update_title (GtkWindow* window)
39+ GString* string = g_string_new (main_title);
40+ gchar* title = g_string_free (string, FALSE);
41+ gtk_window_set_title (window, title);
46+title_change_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, const gchar* title, gpointer data)
50+ main_title = g_strdup (title);
51+ update_title (GTK_WINDOW (main_window));
56+ notify_load_status_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
58+ if (webkit_web_view_get_load_status (web_view) == WEBKIT_LOAD_COMMITTED) {
59+ WebKitWebFrame* frame = webkit_web_view_get_main_frame (web_view);
60+ const gchar* uri = webkit_web_frame_get_uri (frame);
62+ gtk_entry_set_text (GTK_ENTRY (uri_entry), uri);
68+ notify_progress_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
70+ load_progress = webkit_web_view_get_progress (web_view) * 100;
71+ update_title (GTK_WINDOW (main_window));
76+destroy_cb (GtkWidget* widget, gpointer data)
84+ GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL);
85+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
87+ web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ());
88+ gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view));
90+ g_signal_connect (web_view, "title-changed", G_CALLBACK (title_change_cb), web_view);
92+ return scrolled_window;
98+ GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
99+ gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
100+ gtk_widget_set_name (window, "GtkLauncher");
101+ g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL);
106+void start_browser(void)
110+ char **argv = &argv0;
111+ gtk_init (&argc, &argv);
112+ if (!g_thread_supported ())
113+ g_thread_init (NULL);
115+ GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
116+ gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0);
118+ main_window = create_window ();
119+ gtk_container_add (GTK_CONTAINER (main_window), vbox);
121+ gchar* uri = (gchar*) ("http://localhost:3000");
122+ webkit_web_view_open (web_view, uri);
124+ gtk_widget_grab_focus (GTK_WIDGET (web_view));
125+ gtk_widget_show_all (main_window);