2010-03-02 Arno Renevier <arno@renevier.net>
[WebKit-https.git] / WebKit / gtk / webkit / webkitwebview.cpp
1 /*
2  *  Copyright (C) 2007, 2008 Holger Hans Peter Freyther
3  *  Copyright (C) 2007, 2008, 2009 Christian Dywan <christian@imendio.com>
4  *  Copyright (C) 2007 Xan Lopez <xan@gnome.org>
5  *  Copyright (C) 2007, 2008 Alp Toker <alp@atoker.com>
6  *  Copyright (C) 2008 Jan Alonzo <jmalonzo@unpluggable.com>
7  *  Copyright (C) 2008 Gustavo Noronha Silva <gns@gnome.org>
8  *  Copyright (C) 2008 Nuanti Ltd.
9  *  Copyright (C) 2008, 2009, 2010 Collabora Ltd.
10  *  Copyright (C) 2009 Igalia S.L.
11  *  Copyright (C) 2009 Movial Creative Technologies Inc.
12  *  Copyright (C) 2009 Bobby Powers
13  *
14  *  This library is free software; you can redistribute it and/or
15  *  modify it under the terms of the GNU Lesser General Public
16  *  License as published by the Free Software Foundation; either
17  *  version 2 of the License, or (at your option) any later version.
18  *
19  *  This library is distributed in the hope that it will be useful,
20  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22  *  Lesser General Public License for more details.
23  *
24  *  You should have received a copy of the GNU Lesser General Public
25  *  License along with this library; if not, write to the Free Software
26  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
27  */
28
29 #include "config.h"
30 #include "webkitwebview.h"
31
32 #include "webkitdownload.h"
33 #include "webkitenumtypes.h"
34 #include "webkitgeolocationpolicydecision.h"
35 #include "webkitmarshal.h"
36 #include "webkitnetworkrequest.h"
37 #include "webkitnetworkresponse.h"
38 #include "webkitprivate.h"
39 #include "webkitwebinspector.h"
40 #include "webkitwebbackforwardlist.h"
41 #include "webkitwebhistoryitem.h"
42
43 #include "AXObjectCache.h"
44 #include "BackForwardList.h"
45 #include "Cache.h"
46 #include "ChromeClientGtk.h"
47 #include "ContextMenuClientGtk.h"
48 #include "ContextMenuController.h"
49 #include "ContextMenu.h"
50 #include "CString.h"
51 #include "Cursor.h"
52 #include "Document.h"
53 #include "DocumentLoader.h"
54 #include "DragClientGtk.h"
55 #include "EditorClientGtk.h"
56 #include "Editor.h"
57 #include "EventHandler.h"
58 #include "FloatQuad.h"
59 #include "FocusController.h"
60 #include "FrameLoader.h"
61 #include "FrameLoaderTypes.h"
62 #include "FrameView.h"
63 #include <glib/gi18n-lib.h>
64 #include <GOwnPtr.h>
65 #include "GraphicsContext.h"
66 #include "HitTestRequest.h"
67 #include "HitTestResult.h"
68 #include "IconDatabase.h"
69 #include "InspectorClientGtk.h"
70 #include "MouseEventWithHitTestResults.h"
71 #include "NotImplemented.h"
72 #include "PageCache.h"
73 #include "Pasteboard.h"
74 #include "PasteboardHelperGtk.h"
75 #include "PasteboardHelper.h"
76 #include "PlatformKeyboardEvent.h"
77 #include "PlatformWheelEvent.h"
78 #include "ProgressTracker.h"
79 #include "RenderView.h"
80 #include "ResourceHandle.h"
81 #include "ScriptValue.h"
82 #include "Scrollbar.h"
83
84 #include <gdk/gdkkeysyms.h>
85
86 /**
87  * SECTION:webkitwebview
88  * @short_description: The central class of the WebKitGTK+ API
89  * @see_also: #WebKitWebSettings, #WebKitWebFrame
90  *
91  * #WebKitWebView is the central class of the WebKitGTK+ API. It is a
92  * #GtkWidget implementing the scrolling interface which means you can
93  * embed in a #GtkScrolledWindow. It is responsible for managing the
94  * drawing of the content, forwarding of events. You can load any URI
95  * into the #WebKitWebView or any kind of data string. With #WebKitWebSettings
96  * you can control various aspects of the rendering and loading of the content.
97  * Each #WebKitWebView has exactly one #WebKitWebFrame as main frame. A
98  * #WebKitWebFrame can have n children.
99  *
100  * <programlisting>
101  * /<!-- -->* Create the widgets *<!-- -->/
102  * GtkWidget *main_window = gtk_window_new (GTK_WIDGET_TOPLEVEL);
103  * GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
104  * GtkWidget *web_view = webkit_web_view_new ();
105  *
106  * /<!-- -->* Place the WebKitWebView in the GtkScrolledWindow *<!-- -->/
107  * gtk_container_add (GTK_CONTAINER (scrolled_window), web_view);
108  * gtk_container_add (GTK_CONTAINER (main_window), scrolled_window);
109  *
110  * /<!-- -->* Open a webpage *<!-- -->/
111  * webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), "http://www.gnome.org");
112  *
113  * /<!-- -->* Show the result *<!-- -->/
114  * gtk_window_set_default_size (GTK_WINDOW (main_window), 800, 600);
115  * gtk_widget_show_all (main_window);
116  * </programlisting>
117  */
118
119 static const double defaultDPI = 96.0;
120 static WebKitCacheModel cacheModel;
121
122 using namespace WebKit;
123 using namespace WebCore;
124
125 enum {
126     /* normal signals */
127     NAVIGATION_REQUESTED,
128     NEW_WINDOW_POLICY_DECISION_REQUESTED,
129     NAVIGATION_POLICY_DECISION_REQUESTED,
130     MIME_TYPE_POLICY_DECISION_REQUESTED,
131     CREATE_WEB_VIEW,
132     WEB_VIEW_READY,
133     WINDOW_OBJECT_CLEARED,
134     LOAD_STARTED,
135     LOAD_COMMITTED,
136     LOAD_PROGRESS_CHANGED,
137     LOAD_ERROR,
138     LOAD_FINISHED,
139     TITLE_CHANGED,
140     HOVERING_OVER_LINK,
141     POPULATE_POPUP,
142     STATUS_BAR_TEXT_CHANGED,
143     ICON_LOADED,
144     SELECTION_CHANGED,
145     CONSOLE_MESSAGE,
146     SCRIPT_ALERT,
147     SCRIPT_CONFIRM,
148     SCRIPT_PROMPT,
149     SELECT_ALL,
150     COPY_CLIPBOARD,
151     PASTE_CLIPBOARD,
152     CUT_CLIPBOARD,
153     DOWNLOAD_REQUESTED,
154     MOVE_CURSOR,
155     PRINT_REQUESTED,
156     PLUGIN_WIDGET,
157     CLOSE_WEB_VIEW,
158     UNDO,
159     REDO,
160     DATABASE_QUOTA_EXCEEDED,
161     RESOURCE_REQUEST_STARTING,
162     DOCUMENT_LOAD_FINISHED,
163     GEOLOCATION_POLICY_DECISION_REQUESTED,
164     GEOLOCATION_POLICY_DECISION_CANCELLED,
165     LAST_SIGNAL
166 };
167
168 enum {
169     PROP_0,
170
171     PROP_TITLE,
172     PROP_URI,
173     PROP_COPY_TARGET_LIST,
174     PROP_PASTE_TARGET_LIST,
175     PROP_EDITABLE,
176     PROP_SETTINGS,
177     PROP_WEB_INSPECTOR,
178     PROP_WINDOW_FEATURES,
179     PROP_TRANSPARENT,
180     PROP_ZOOM_LEVEL,
181     PROP_FULL_CONTENT_ZOOM,
182     PROP_LOAD_STATUS,
183     PROP_PROGRESS,
184     PROP_ENCODING,
185     PROP_CUSTOM_ENCODING,
186     PROP_ICON_URI,
187     PROP_IM_CONTEXT
188 };
189
190 static guint webkit_web_view_signals[LAST_SIGNAL] = { 0, };
191
192 G_DEFINE_TYPE(WebKitWebView, webkit_web_view, GTK_TYPE_CONTAINER)
193
194 static void webkit_web_view_settings_notify(WebKitWebSettings* webSettings, GParamSpec* pspec, WebKitWebView* webView);
195 static void webkit_web_view_set_window_features(WebKitWebView* webView, WebKitWebWindowFeatures* webWindowFeatures);
196
197 static GtkIMContext* webkit_web_view_get_im_context(WebKitWebView*);
198
199 static void destroy_menu_cb(GtkObject* object, gpointer data)
200 {
201     WebKitWebView* webView = WEBKIT_WEB_VIEW(data);
202     WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(webView);
203
204     g_object_unref(priv->currentMenu);
205     priv->currentMenu = NULL;
206 }
207
208 static void PopupMenuPositionFunc(GtkMenu* menu, gint *x, gint *y, gboolean *pushIn, gpointer userData)
209 {
210     WebKitWebView* view = WEBKIT_WEB_VIEW(userData);
211     WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(view);
212     GdkScreen* screen = gtk_widget_get_screen(GTK_WIDGET(view));
213     GtkRequisition menuSize;
214
215     gtk_widget_size_request(GTK_WIDGET(menu), &menuSize);
216
217     *x = priv->lastPopupXPosition;
218     if ((*x + menuSize.width) >= gdk_screen_get_width(screen))
219       *x -= menuSize.width;
220
221     *y = priv->lastPopupYPosition;
222     if ((*y + menuSize.height) >= gdk_screen_get_height(screen))
223       *y -= menuSize.height;
224
225     *pushIn = FALSE;
226 }
227
228 static gboolean webkit_web_view_forward_context_menu_event(WebKitWebView* webView, const PlatformMouseEvent& event)
229 {
230     Page* page = core(webView);
231     page->contextMenuController()->clearContextMenu();
232     Frame* focusedFrame;
233     Frame* mainFrame = page->mainFrame();
234     gboolean mousePressEventResult = FALSE;
235
236     if (!mainFrame->view())
237         return FALSE;
238
239     mainFrame->view()->setCursor(pointerCursor());
240     if (page->frameCount()) {
241         HitTestRequest request(HitTestRequest::Active);
242         IntPoint point = mainFrame->view()->windowToContents(event.pos());
243         MouseEventWithHitTestResults mev = mainFrame->document()->prepareMouseEvent(request, point, event);
244
245         Frame* targetFrame = EventHandler::subframeForTargetNode(mev.targetNode());
246         if (!targetFrame)
247             targetFrame = mainFrame;
248
249         focusedFrame = page->focusController()->focusedOrMainFrame();
250         if (targetFrame != focusedFrame) {
251             page->focusController()->setFocusedFrame(targetFrame);
252             focusedFrame = targetFrame;
253         }
254     } else
255         focusedFrame = mainFrame;
256
257     if (focusedFrame->view() && focusedFrame->eventHandler()->handleMousePressEvent(event))
258         mousePressEventResult = TRUE;
259
260
261     bool handledEvent = focusedFrame->eventHandler()->sendContextMenuEvent(event);
262     if (!handledEvent)
263         return FALSE;
264
265     // If coreMenu is NULL, this means WebCore decided to not create
266     // the default context menu; this may happen when the page is
267     // handling the right-click for reasons other than the context menu.
268     ContextMenu* coreMenu = page->contextMenuController()->contextMenu();
269     if (!coreMenu)
270         return mousePressEventResult;
271
272     // If we reach here, it's because WebCore is going to show the
273     // default context menu. We check our setting to figure out
274     // whether we want it or not.
275     WebKitWebSettings* settings = webkit_web_view_get_settings(webView);
276     gboolean enableDefaultContextMenu;
277     g_object_get(settings, "enable-default-context-menu", &enableDefaultContextMenu, NULL);
278
279     if (!enableDefaultContextMenu)
280         return FALSE;
281
282     GtkMenu* menu = GTK_MENU(coreMenu->platformDescription());
283     if (!menu)
284         return FALSE;
285
286     g_signal_emit(webView, webkit_web_view_signals[POPULATE_POPUP], 0, menu);
287
288     GList* items = gtk_container_get_children(GTK_CONTAINER(menu));
289     bool empty = !g_list_nth(items, 0);
290     g_list_free(items);
291     if (empty)
292         return FALSE;
293
294     WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(webView);
295     priv->currentMenu = GTK_MENU(g_object_ref(menu));
296     priv->lastPopupXPosition = event.globalX();
297     priv->lastPopupYPosition = event.globalY();
298
299     g_signal_connect(menu, "destroy",
300                      G_CALLBACK(destroy_menu_cb),
301                      NULL);
302
303     gtk_menu_popup(menu, NULL, NULL,
304                    &PopupMenuPositionFunc,
305                    webView, event.button() + 1, gtk_get_current_event_time());
306     return TRUE;
307 }
308
309 static gboolean webkit_web_view_popup_menu_handler(GtkWidget* widget)
310 {
311     static const int contextMenuMargin = 1;
312
313     // The context menu event was generated from the keyboard, so show the context menu by the current selection.
314     Page* page = core(WEBKIT_WEB_VIEW(widget));
315     Frame* frame = page->focusController()->focusedOrMainFrame();
316     FrameView* view = frame->view();
317     if (!view)
318         return FALSE;    
319
320     Position start = frame->selection()->selection().start();
321     Position end = frame->selection()->selection().end();
322
323     int rightAligned = FALSE;
324     IntPoint location;
325
326     if (!start.node() || !end.node()
327         || (frame->selection()->selection().isCaret() && !frame->selection()->selection().isContentEditable()))
328         location = IntPoint(rightAligned ? view->contentsWidth() - contextMenuMargin : contextMenuMargin, contextMenuMargin);
329     else {
330         RenderObject* renderer = start.node()->renderer();
331         if (!renderer)
332             return FALSE;
333
334         // Calculate the rect of the first line of the selection (cribbed from -[WebCoreFrameBridge firstRectForDOMRange:],
335         // now Frame::firstRectForRange(), which perhaps this should call).
336         int extraWidthToEndOfLine = 0;
337
338         InlineBox* startInlineBox;
339         int startCaretOffset;
340         start.getInlineBoxAndOffset(DOWNSTREAM, startInlineBox, startCaretOffset);
341         IntRect startCaretRect = renderer->localCaretRect(startInlineBox, startCaretOffset, &extraWidthToEndOfLine);
342         if (startCaretRect != IntRect())
343             startCaretRect = renderer->localToAbsoluteQuad(FloatRect(startCaretRect)).enclosingBoundingBox();
344
345         InlineBox* endInlineBox;
346         int endCaretOffset;
347         end.getInlineBoxAndOffset(UPSTREAM, endInlineBox, endCaretOffset);
348         IntRect endCaretRect = renderer->localCaretRect(endInlineBox, endCaretOffset);
349         if (endCaretRect != IntRect())
350             endCaretRect = renderer->localToAbsoluteQuad(FloatRect(endCaretRect)).enclosingBoundingBox();
351
352         IntRect firstRect;
353         if (startCaretRect.y() == endCaretRect.y())
354             firstRect = IntRect(MIN(startCaretRect.x(), endCaretRect.x()),
355                                 startCaretRect.y(),
356                                 abs(endCaretRect.x() - startCaretRect.x()),
357                                 MAX(startCaretRect.height(), endCaretRect.height()));
358         else
359             firstRect = IntRect(startCaretRect.x(),
360                                 startCaretRect.y(),
361                                 startCaretRect.width() + extraWidthToEndOfLine,
362                                 startCaretRect.height());
363
364         location = IntPoint(rightAligned ? firstRect.right() : firstRect.x(), firstRect.bottom());
365     }
366
367     int x, y;
368     gdk_window_get_origin(GTK_WIDGET(view->hostWindow()->platformPageClient())->window, &x, &y);
369
370     // FIXME: The IntSize(0, -1) is a hack to get the hit-testing to result in the selected element.
371     // Ideally we'd have the position of a context menu event be separate from its target node.
372     location = view->contentsToWindow(location) + IntSize(0, -1);
373     if (location.y() < 0)
374         location.setY(contextMenuMargin);
375     else if (location.y() > view->height())
376         location.setY(view->height() - contextMenuMargin);
377     if (location.x() < 0)
378         location.setX(contextMenuMargin);
379     else if (location.x() > view->width())
380         location.setX(view->width() - contextMenuMargin);
381     IntPoint global = location + IntSize(x, y);
382
383     PlatformMouseEvent event(location, global, RightButton, MouseEventPressed, 0, false, false, false, false, gtk_get_current_event_time());
384
385     return webkit_web_view_forward_context_menu_event(WEBKIT_WEB_VIEW(widget), event);
386 }
387
388 static void webkit_web_view_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
389 {
390     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
391
392     switch(prop_id) {
393     case PROP_TITLE:
394         g_value_set_string(value, webkit_web_view_get_title(webView));
395         break;
396     case PROP_URI:
397         g_value_set_string(value, webkit_web_view_get_uri(webView));
398         break;
399     case PROP_COPY_TARGET_LIST:
400         g_value_set_boxed(value, webkit_web_view_get_copy_target_list(webView));
401         break;
402     case PROP_PASTE_TARGET_LIST:
403         g_value_set_boxed(value, webkit_web_view_get_paste_target_list(webView));
404         break;
405     case PROP_EDITABLE:
406         g_value_set_boolean(value, webkit_web_view_get_editable(webView));
407         break;
408     case PROP_SETTINGS:
409         g_value_set_object(value, webkit_web_view_get_settings(webView));
410         break;
411     case PROP_WEB_INSPECTOR:
412         g_value_set_object(value, webkit_web_view_get_inspector(webView));
413         break;
414     case PROP_WINDOW_FEATURES:
415         g_value_set_object(value, webkit_web_view_get_window_features(webView));
416         break;
417     case PROP_TRANSPARENT:
418         g_value_set_boolean(value, webkit_web_view_get_transparent(webView));
419         break;
420     case PROP_ZOOM_LEVEL:
421         g_value_set_float(value, webkit_web_view_get_zoom_level(webView));
422         break;
423     case PROP_FULL_CONTENT_ZOOM:
424         g_value_set_boolean(value, webkit_web_view_get_full_content_zoom(webView));
425         break;
426     case PROP_ENCODING:
427         g_value_set_string(value, webkit_web_view_get_encoding(webView));
428         break;
429     case PROP_CUSTOM_ENCODING:
430         g_value_set_string(value, webkit_web_view_get_custom_encoding(webView));
431         break;
432     case PROP_LOAD_STATUS:
433         g_value_set_enum(value, webkit_web_view_get_load_status(webView));
434         break;
435     case PROP_PROGRESS:
436         g_value_set_double(value, webkit_web_view_get_progress(webView));
437         break;
438     case PROP_ICON_URI:
439         g_value_set_string(value, webkit_web_view_get_icon_uri(webView));
440         break;
441     case PROP_IM_CONTEXT:
442         g_value_set_object(value, webkit_web_view_get_im_context(webView));
443         break;
444     default:
445         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
446     }
447 }
448
449 static void webkit_web_view_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec *pspec)
450 {
451     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
452
453     switch(prop_id) {
454     case PROP_EDITABLE:
455         webkit_web_view_set_editable(webView, g_value_get_boolean(value));
456         break;
457     case PROP_SETTINGS:
458         webkit_web_view_set_settings(webView, WEBKIT_WEB_SETTINGS(g_value_get_object(value)));
459         break;
460     case PROP_WINDOW_FEATURES:
461         webkit_web_view_set_window_features(webView, WEBKIT_WEB_WINDOW_FEATURES(g_value_get_object(value)));
462         break;
463     case PROP_TRANSPARENT:
464         webkit_web_view_set_transparent(webView, g_value_get_boolean(value));
465         break;
466     case PROP_ZOOM_LEVEL:
467         webkit_web_view_set_zoom_level(webView, g_value_get_float(value));
468         break;
469     case PROP_FULL_CONTENT_ZOOM:
470         webkit_web_view_set_full_content_zoom(webView, g_value_get_boolean(value));
471         break;
472     case PROP_CUSTOM_ENCODING:
473         webkit_web_view_set_custom_encoding(webView, g_value_get_string(value));
474         break;
475     default:
476         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
477     }
478 }
479
480 static bool shouldCoalesce(GdkRectangle rect, GdkRectangle* rects, int count)
481 {
482     const int cRectThreshold = 10;
483     const float cWastedSpaceThreshold = 0.75f;
484     bool useUnionedRect = (count <= 1) || (count > cRectThreshold);
485     if (!useUnionedRect) {
486         // Attempt to guess whether or not we should use the unioned rect or the individual rects.
487         // We do this by computing the percentage of "wasted space" in the union.  If that wasted space
488         // is too large, then we will do individual rect painting instead.
489         float unionPixels = (rect.width * rect.height);
490         float singlePixels = 0;
491         for (int i = 0; i < count; ++i)
492             singlePixels += rects[i].width * rects[i].height;
493         float wastedSpace = 1 - (singlePixels / unionPixels);
494         if (wastedSpace <= cWastedSpaceThreshold)
495             useUnionedRect = true;
496     }
497     return useUnionedRect;
498 }
499
500 static gboolean webkit_web_view_expose_event(GtkWidget* widget, GdkEventExpose* event)
501 {
502     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
503     WebKitWebViewPrivate* priv = webView->priv;
504
505     Frame* frame = core(webView)->mainFrame();
506     if (frame->contentRenderer() && frame->view()) {
507         frame->view()->layoutIfNeededRecursive();
508
509         cairo_t* cr = gdk_cairo_create(event->window);
510         GraphicsContext ctx(cr);
511         cairo_destroy(cr);
512         ctx.setGdkExposeEvent(event);
513
514         GOwnPtr<GdkRectangle> rects;
515         int rectCount;
516         gdk_region_get_rectangles(event->region, &rects.outPtr(), &rectCount);
517
518         // Avoid recursing into the render tree excessively
519         bool coalesce = shouldCoalesce(event->area, rects.get(), rectCount);
520
521         if (coalesce) {
522             IntRect rect = event->area;
523             ctx.clip(rect);
524             if (priv->transparent)
525                 ctx.clearRect(rect);
526             frame->view()->paint(&ctx, rect);
527         } else {
528             for (int i = 0; i < rectCount; i++) {
529                 IntRect rect = rects.get()[i];
530                 ctx.save();
531                 ctx.clip(rect);
532                 if (priv->transparent)
533                     ctx.clearRect(rect);
534                 frame->view()->paint(&ctx, rect);
535                 ctx.restore();
536             }
537         }
538     }
539
540     return FALSE;
541 }
542
543 static gboolean webkit_web_view_key_press_event(GtkWidget* widget, GdkEventKey* event)
544 {
545     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
546
547     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
548     PlatformKeyboardEvent keyboardEvent(event);
549
550     if (!frame->view())
551         return FALSE;
552
553     if (frame->eventHandler()->keyEvent(keyboardEvent))
554         return TRUE;
555
556     /* Chain up to our parent class for binding activation */
557     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->key_press_event(widget, event);
558 }
559
560 static gboolean webkit_web_view_key_release_event(GtkWidget* widget, GdkEventKey* event)
561 {
562     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
563
564     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
565     if (!frame->view())
566         return FALSE;
567
568     PlatformKeyboardEvent keyboardEvent(event);
569
570     if (frame->eventHandler()->keyEvent(keyboardEvent))
571         return TRUE;
572
573     /* Chain up to our parent class for binding activation */
574     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->key_release_event(widget, event);
575 }
576
577 static gboolean webkit_web_view_button_press_event(GtkWidget* widget, GdkEventButton* event)
578 {
579     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
580
581     // FIXME: need to keep track of subframe focus for key events
582     gtk_widget_grab_focus(widget);
583
584     if (event->button == 3)
585         return webkit_web_view_forward_context_menu_event(webView, PlatformMouseEvent(event));
586
587     Frame* frame = core(webView)->mainFrame();
588     if (!frame->view())
589         return FALSE;
590
591     gboolean result = frame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(event));
592
593 #if PLATFORM(X11)
594     /* Copy selection to the X11 selection clipboard */
595     if (event->button == 2) {
596         bool primary = webView->priv->usePrimaryForPaste;
597         webView->priv->usePrimaryForPaste = true;
598
599         Editor* editor = webView->priv->corePage->focusController()->focusedOrMainFrame()->editor();
600         result = result || editor->canPaste() || editor->canDHTMLPaste();
601         editor->paste();
602
603         webView->priv->usePrimaryForPaste = primary;
604     }
605 #endif
606
607     return result;
608 }
609
610 static gboolean webkit_web_view_button_release_event(GtkWidget* widget, GdkEventButton* event)
611 {
612     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
613
614     Frame* focusedFrame = core(webView)->focusController()->focusedFrame();
615
616     if (focusedFrame && focusedFrame->editor()->canEdit()) {
617 #ifdef MAEMO_CHANGES
618         WebKitWebViewPrivate* priv = webView->priv;
619         hildon_gtk_im_context_filter_event(priv->imContext, (GdkEvent*)event);
620 #endif
621     }
622
623     Frame* mainFrame = core(webView)->mainFrame();
624     if (mainFrame->view())
625         mainFrame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(event));
626
627     /* We always return FALSE here because WebKit can, for the same click, decide
628      * to not handle press-event but handle release-event, which can totally confuse
629      * some GTK+ containers when there are no other events in between. This way we
630      * guarantee that this case never happens, and that if press-event goes through
631      * release-event also goes through.
632      */
633
634     return FALSE;
635 }
636
637 static gboolean webkit_web_view_motion_event(GtkWidget* widget, GdkEventMotion* event)
638 {
639     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
640
641     Frame* frame = core(webView)->mainFrame();
642     if (!frame->view())
643         return FALSE;
644
645     return frame->eventHandler()->mouseMoved(PlatformMouseEvent(event));
646 }
647
648 static gboolean webkit_web_view_scroll_event(GtkWidget* widget, GdkEventScroll* event)
649 {
650     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
651
652     Frame* frame = core(webView)->mainFrame();
653     if (!frame->view())
654         return FALSE;
655
656     PlatformWheelEvent wheelEvent(event);
657     return frame->eventHandler()->handleWheelEvent(wheelEvent);
658 }
659
660 static void webkit_web_view_size_request(GtkWidget* widget, GtkRequisition* requisition)
661 {
662     WebKitWebView* web_view = WEBKIT_WEB_VIEW(widget);
663     Frame* coreFrame = core(webkit_web_view_get_main_frame(web_view));
664     if (!coreFrame)
665         return;
666
667     FrameView* view = coreFrame->view();
668     if (!view)
669         return;
670
671     requisition->width = view->contentsWidth();
672     requisition->height = view->contentsHeight();
673 }
674
675 static void webkit_web_view_size_allocate(GtkWidget* widget, GtkAllocation* allocation)
676 {
677     GTK_WIDGET_CLASS(webkit_web_view_parent_class)->size_allocate(widget,allocation);
678
679     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
680
681     Frame* frame = core(webView)->mainFrame();
682     if (!frame->view())
683         return;
684
685     frame->view()->resize(allocation->width, allocation->height);
686 }
687
688 static void webkit_web_view_grab_focus(GtkWidget* widget)
689 {
690     if (GTK_WIDGET_IS_SENSITIVE(widget)) {
691         WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
692         FocusController* focusController = core(webView)->focusController();
693
694         focusController->setActive(true);
695
696         if (focusController->focusedFrame())
697             focusController->setFocused(true);
698         else
699             focusController->setFocusedFrame(core(webView)->mainFrame());
700     }
701
702     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->grab_focus(widget);
703 }
704
705 static gboolean webkit_web_view_focus_in_event(GtkWidget* widget, GdkEventFocus* event)
706 {
707     // TODO: Improve focus handling as suggested in
708     // http://bugs.webkit.org/show_bug.cgi?id=16910
709     GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
710 #if GTK_CHECK_VERSION(2, 18, 0)
711     if (gtk_widget_is_toplevel(toplevel) && gtk_window_has_toplevel_focus(GTK_WINDOW(toplevel))) {
712 #else
713     if (GTK_WIDGET_TOPLEVEL(toplevel) && gtk_window_has_toplevel_focus(GTK_WINDOW(toplevel))) {
714 #endif
715         WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
716         FocusController* focusController = core(webView)->focusController();
717
718         focusController->setActive(true);
719
720         if (focusController->focusedFrame())
721             focusController->setFocused(true);
722         else
723             focusController->setFocusedFrame(core(webView)->mainFrame());
724     }
725     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->focus_in_event(widget, event);
726 }
727
728 static gboolean webkit_web_view_focus_out_event(GtkWidget* widget, GdkEventFocus* event)
729 {
730     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
731
732     // We may hit this code while destroying the widget, and we might
733     // no longer have a page, then.
734     Page* page = core(webView);
735     if (page) {
736         page->focusController()->setActive(false);
737         page->focusController()->setFocused(false);
738     }
739
740     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->focus_out_event(widget, event);
741 }
742
743 static void webkit_web_view_realize(GtkWidget* widget)
744 {
745     GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
746
747     GdkWindowAttr attributes;
748     attributes.window_type = GDK_WINDOW_CHILD;
749     attributes.x = widget->allocation.x;
750     attributes.y = widget->allocation.y;
751     attributes.width = widget->allocation.width;
752     attributes.height = widget->allocation.height;
753     attributes.wclass = GDK_INPUT_OUTPUT;
754     attributes.visual = gtk_widget_get_visual (widget);
755     attributes.colormap = gtk_widget_get_colormap (widget);
756     attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK
757                             | GDK_EXPOSURE_MASK
758                             | GDK_BUTTON_PRESS_MASK
759                             | GDK_BUTTON_RELEASE_MASK
760                             | GDK_POINTER_MOTION_MASK
761                             | GDK_KEY_PRESS_MASK
762                             | GDK_KEY_RELEASE_MASK
763                             | GDK_BUTTON_MOTION_MASK
764                             | GDK_BUTTON1_MOTION_MASK
765                             | GDK_BUTTON2_MOTION_MASK
766                             | GDK_BUTTON3_MOTION_MASK;
767
768     gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
769     widget->window = gdk_window_new(gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
770     gdk_window_set_user_data(widget->window, widget);
771
772     widget->style = gtk_style_attach(widget->style, widget->window);
773     gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
774
775     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
776     WebKitWebViewPrivate* priv = webView->priv;
777     gtk_im_context_set_client_window(priv->imContext, widget->window);
778 }
779
780 static void webkit_web_view_set_scroll_adjustments(WebKitWebView* webView, GtkAdjustment* hadj, GtkAdjustment* vadj)
781 {
782     if (!core(webView))
783         return;
784
785     FrameView* view = core(webkit_web_view_get_main_frame(webView))->view();
786
787     if (hadj)
788         g_object_ref(hadj);
789     if (vadj)
790         g_object_ref(vadj);
791
792     WebKitWebViewPrivate* priv = webView->priv;
793
794     if (priv->horizontalAdjustment)
795         g_object_unref(priv->horizontalAdjustment);
796     if (priv->verticalAdjustment)
797         g_object_unref(priv->verticalAdjustment);
798
799     priv->horizontalAdjustment = hadj;
800     priv->verticalAdjustment = vadj;
801
802     if (!view)
803         return;
804
805     view->setGtkAdjustments(hadj, vadj);
806 }
807
808 static void webkit_web_view_container_add(GtkContainer* container, GtkWidget* widget)
809 {
810     WebKitWebView* webView = WEBKIT_WEB_VIEW(container);
811     WebKitWebViewPrivate* priv = webView->priv;
812
813     priv->children.add(widget);
814     gtk_widget_set_parent(widget, GTK_WIDGET(container));
815 }
816
817 static void webkit_web_view_container_remove(GtkContainer* container, GtkWidget* widget)
818 {
819     WebKitWebView* webView = WEBKIT_WEB_VIEW(container);
820     WebKitWebViewPrivate* priv = webView->priv;
821
822     if (priv->children.contains(widget)) {
823         gtk_widget_unparent(widget);
824         priv->children.remove(widget);
825     }
826 }
827
828 static void webkit_web_view_container_forall(GtkContainer* container, gboolean, GtkCallback callback, gpointer callbackData)
829 {
830     WebKitWebView* webView = WEBKIT_WEB_VIEW(container);
831     WebKitWebViewPrivate* priv = webView->priv;
832
833     HashSet<GtkWidget*> children = priv->children;
834     HashSet<GtkWidget*>::const_iterator end = children.end();
835     for (HashSet<GtkWidget*>::const_iterator current = children.begin(); current != end; ++current)
836         (*callback)(*current, callbackData);
837 }
838
839 static WebKitWebView* webkit_web_view_real_create_web_view(WebKitWebView*, WebKitWebFrame*)
840 {
841     return 0;
842 }
843
844 static gboolean webkit_web_view_real_web_view_ready(WebKitWebView*)
845 {
846     return FALSE;
847 }
848
849 static gboolean webkit_web_view_real_close_web_view(WebKitWebView*)
850 {
851     return FALSE;
852 }
853
854 static WebKitNavigationResponse webkit_web_view_real_navigation_requested(WebKitWebView*, WebKitWebFrame*, WebKitNetworkRequest*)
855 {
856     return WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
857 }
858
859 static void webkit_web_view_real_window_object_cleared(WebKitWebView*, WebKitWebFrame*, JSGlobalContextRef context, JSObjectRef window_object)
860 {
861     notImplemented();
862 }
863
864 static gchar* webkit_web_view_real_choose_file(WebKitWebView*, WebKitWebFrame*, const gchar* old_name)
865 {
866     notImplemented();
867     return g_strdup(old_name);
868 }
869
870 typedef enum {
871     WEBKIT_SCRIPT_DIALOG_ALERT,
872     WEBKIT_SCRIPT_DIALOG_CONFIRM,
873     WEBKIT_SCRIPT_DIALOG_PROMPT
874  } WebKitScriptDialogType;
875
876 static gboolean webkit_web_view_script_dialog(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, WebKitScriptDialogType type, const gchar* defaultValue, gchar** value)
877 {
878     GtkMessageType messageType;
879     GtkButtonsType buttons;
880     gint defaultResponse;
881     GtkWidget* window;
882     GtkWidget* dialog;
883     GtkWidget* entry = 0;
884     gboolean didConfirm = FALSE;
885
886     switch (type) {
887     case WEBKIT_SCRIPT_DIALOG_ALERT:
888         messageType = GTK_MESSAGE_WARNING;
889         buttons = GTK_BUTTONS_CLOSE;
890         defaultResponse = GTK_RESPONSE_CLOSE;
891         break;
892     case WEBKIT_SCRIPT_DIALOG_CONFIRM:
893         messageType = GTK_MESSAGE_QUESTION;
894         buttons = GTK_BUTTONS_YES_NO;
895         defaultResponse = GTK_RESPONSE_YES;
896         break;
897     case WEBKIT_SCRIPT_DIALOG_PROMPT:
898         messageType = GTK_MESSAGE_QUESTION;
899         buttons = GTK_BUTTONS_OK_CANCEL;
900         defaultResponse = GTK_RESPONSE_OK;
901         break;
902     default:
903         g_warning("Unknown value for WebKitScriptDialogType.");
904         return FALSE;
905     }
906
907     window = gtk_widget_get_toplevel(GTK_WIDGET(webView));
908 #if GTK_CHECK_VERSION(2, 18, 0)
909     dialog = gtk_message_dialog_new(gtk_widget_is_toplevel(window) ? GTK_WINDOW(window) : 0, GTK_DIALOG_DESTROY_WITH_PARENT, messageType, buttons, "%s", message);
910 #else
911     dialog = gtk_message_dialog_new(GTK_WIDGET_TOPLEVEL(window) ? GTK_WINDOW(window) : 0, GTK_DIALOG_DESTROY_WITH_PARENT, messageType, buttons, "%s", message);
912 #endif
913     gchar* title = g_strconcat("JavaScript - ", webkit_web_frame_get_uri(frame), NULL);
914     gtk_window_set_title(GTK_WINDOW(dialog), title);
915     g_free(title);
916
917     if (type == WEBKIT_SCRIPT_DIALOG_PROMPT) {
918         entry = gtk_entry_new();
919         gtk_entry_set_text(GTK_ENTRY(entry), defaultValue);
920         gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entry);
921         gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
922         gtk_widget_show(entry);
923     }
924
925     gtk_dialog_set_default_response(GTK_DIALOG(dialog), defaultResponse);
926     gint response = gtk_dialog_run(GTK_DIALOG(dialog));
927
928     switch (response) {
929     case GTK_RESPONSE_YES:
930         didConfirm = TRUE;
931         break;
932     case GTK_RESPONSE_OK:
933         didConfirm = TRUE;
934         if (entry)
935             *value = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
936         else
937             *value = 0;
938         break;
939     case GTK_RESPONSE_NO:
940     case GTK_RESPONSE_CANCEL:
941         didConfirm = FALSE;
942         break;
943
944     }
945     gtk_widget_destroy(GTK_WIDGET(dialog));
946     return didConfirm;
947 }
948
949 static gboolean webkit_web_view_real_script_alert(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message)
950 {
951     webkit_web_view_script_dialog(webView, frame, message, WEBKIT_SCRIPT_DIALOG_ALERT, 0, 0);
952     return TRUE;
953 }
954
955 static gboolean webkit_web_view_real_script_confirm(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, gboolean* didConfirm)
956 {
957     *didConfirm = webkit_web_view_script_dialog(webView, frame, message, WEBKIT_SCRIPT_DIALOG_CONFIRM, 0, 0);
958     return TRUE;
959 }
960
961 static gboolean webkit_web_view_real_script_prompt(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, const gchar* defaultValue, gchar** value)
962 {
963     if (!webkit_web_view_script_dialog(webView, frame, message, WEBKIT_SCRIPT_DIALOG_PROMPT, defaultValue, value))
964         *value = NULL;
965     return TRUE;
966 }
967
968 static gboolean webkit_web_view_real_console_message(WebKitWebView* webView, const gchar* message, unsigned int line, const gchar* sourceId)
969 {
970     g_message("console message: %s @%d: %s\n", sourceId, line, message);
971     return TRUE;
972 }
973
974 static void webkit_web_view_real_select_all(WebKitWebView* webView)
975 {
976     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
977     frame->editor()->command("SelectAll").execute();
978 }
979
980 static void webkit_web_view_real_cut_clipboard(WebKitWebView* webView)
981 {
982     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
983     frame->editor()->command("Cut").execute();
984 }
985
986 static void webkit_web_view_real_copy_clipboard(WebKitWebView* webView)
987 {
988     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
989     frame->editor()->command("Copy").execute();
990 }
991
992 static void webkit_web_view_real_undo(WebKitWebView* webView)
993 {
994     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
995     frame->editor()->command("Undo").execute();
996 }
997
998 static void webkit_web_view_real_redo(WebKitWebView* webView)
999 {
1000     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
1001     frame->editor()->command("Redo").execute();
1002 }
1003
1004 static gboolean webkit_web_view_real_move_cursor (WebKitWebView* webView, GtkMovementStep step, gint count)
1005 {
1006     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW (webView), FALSE);
1007     g_return_val_if_fail(step == GTK_MOVEMENT_VISUAL_POSITIONS ||
1008                          step == GTK_MOVEMENT_DISPLAY_LINES ||
1009                          step == GTK_MOVEMENT_PAGES ||
1010                          step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
1011     g_return_val_if_fail(count == 1 || count == -1, FALSE);
1012
1013     ScrollDirection direction;
1014     ScrollGranularity granularity;
1015
1016     switch (step) {
1017     case GTK_MOVEMENT_DISPLAY_LINES:
1018         granularity = ScrollByLine;
1019         if (count == 1)
1020             direction = ScrollDown;
1021         else
1022             direction = ScrollUp;
1023         break;
1024     case GTK_MOVEMENT_VISUAL_POSITIONS:
1025         granularity = ScrollByLine;
1026         if (count == 1)
1027             direction = ScrollRight;
1028         else
1029             direction = ScrollLeft;
1030         break;
1031     case GTK_MOVEMENT_PAGES:
1032         granularity = ScrollByPage;
1033         if (count == 1)
1034             direction = ScrollDown;
1035         else
1036             direction = ScrollUp;
1037         break;
1038     case GTK_MOVEMENT_BUFFER_ENDS:
1039         granularity = ScrollByDocument;
1040         if (count == 1)
1041             direction = ScrollDown;
1042         else
1043             direction = ScrollUp;
1044         break;
1045     default:
1046         g_assert_not_reached();
1047         return false;
1048     }
1049
1050     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
1051     if (!frame->eventHandler()->scrollOverflow(direction, granularity))
1052         frame->view()->scroll(direction, granularity);
1053
1054     return true;
1055 }
1056
1057 static void webkit_web_view_real_paste_clipboard(WebKitWebView* webView)
1058 {
1059     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
1060     frame->editor()->command("Paste").execute();
1061 }
1062
1063 static void webkit_web_view_dispose(GObject* object)
1064 {
1065     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
1066     WebKitWebViewPrivate* priv = webView->priv;
1067
1068     priv->disposing = TRUE;
1069
1070     if (priv->horizontalAdjustment) {
1071         g_object_unref(priv->horizontalAdjustment);
1072         priv->horizontalAdjustment = NULL;
1073     }
1074
1075     if (priv->verticalAdjustment) {
1076         g_object_unref(priv->verticalAdjustment);
1077         priv->verticalAdjustment = NULL;
1078     }
1079
1080     if (priv->backForwardList) {
1081         g_object_unref(priv->backForwardList);
1082         priv->backForwardList = NULL;
1083     }
1084
1085     if (priv->corePage) {
1086         webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(object));
1087
1088         core(priv->mainFrame)->loader()->detachFromParent();
1089         delete priv->corePage;
1090         priv->corePage = NULL;
1091     }
1092
1093     if (priv->webSettings) {
1094         g_signal_handlers_disconnect_by_func(priv->webSettings, (gpointer)webkit_web_view_settings_notify, webView);
1095         g_object_unref(priv->webSettings);
1096         priv->webSettings = NULL;
1097
1098         g_object_unref(priv->webInspector);
1099         priv->webInspector = NULL;
1100
1101         g_object_unref(priv->webWindowFeatures);
1102         priv->webWindowFeatures = NULL;
1103
1104         g_object_unref(priv->imContext);
1105         priv->imContext = NULL;
1106     }
1107
1108     if (priv->mainResource) {
1109         g_object_unref(priv->mainResource);
1110         priv->mainResource = NULL;
1111     }
1112
1113     if (priv->subResources) {
1114         g_hash_table_unref(priv->subResources);
1115         priv->subResources = NULL;
1116     }
1117
1118     G_OBJECT_CLASS(webkit_web_view_parent_class)->dispose(object);
1119 }
1120
1121 static void webkit_web_view_finalize(GObject* object)
1122 {
1123     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
1124     WebKitWebViewPrivate* priv = webView->priv;
1125
1126     g_free(priv->tooltipText);
1127     g_free(priv->mainResourceIdentifier);
1128     g_free(priv->encoding);
1129     g_free(priv->customEncoding);
1130     g_free(priv->iconURI);
1131
1132     G_OBJECT_CLASS(webkit_web_view_parent_class)->finalize(object);
1133 }
1134
1135 static gboolean webkit_signal_accumulator_object_handled(GSignalInvocationHint* ihint, GValue* returnAccu, const GValue* handlerReturn, gpointer dummy)
1136 {
1137     gpointer newWebView = g_value_get_object(handlerReturn);
1138     g_value_set_object(returnAccu, newWebView);
1139
1140     // Continue if we don't have a newWebView
1141     return !newWebView;
1142 }
1143
1144 static gboolean webkit_navigation_request_handled(GSignalInvocationHint* ihint, GValue* returnAccu, const GValue* handlerReturn, gpointer dummy)
1145 {
1146     WebKitNavigationResponse navigationResponse = (WebKitNavigationResponse)g_value_get_enum(handlerReturn);
1147     g_value_set_enum(returnAccu, navigationResponse);
1148
1149     if (navigationResponse != WEBKIT_NAVIGATION_RESPONSE_ACCEPT)
1150         return FALSE;
1151
1152     return TRUE;
1153 }
1154
1155 static AtkObject* webkit_web_view_get_accessible(GtkWidget* widget)
1156 {
1157     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
1158     if (!core(webView))
1159         return NULL;
1160
1161     AXObjectCache::enableAccessibility();
1162
1163     Frame* coreFrame = core(webView)->mainFrame();
1164     if (!coreFrame)
1165         return NULL;
1166
1167     Document* doc = coreFrame->document();
1168     if (!doc)
1169         return NULL;
1170
1171     AccessibilityObject* coreAccessible = doc->axObjectCache()->getOrCreate(doc->renderer());
1172     if (!coreAccessible || !coreAccessible->wrapper())
1173         return NULL;
1174
1175     return coreAccessible->wrapper();
1176 }
1177
1178 static gdouble webViewGetDPI(WebKitWebView* webView)
1179 {
1180     WebKitWebViewPrivate* priv = webView->priv;
1181     WebKitWebSettings* webSettings = priv->webSettings;
1182     gboolean enforce96DPI;
1183     g_object_get(webSettings, "enforce-96-dpi", &enforce96DPI, NULL);
1184     if (enforce96DPI)
1185         return 96.0;
1186
1187     gdouble DPI = defaultDPI;
1188     GdkScreen* screen = gtk_widget_has_screen(GTK_WIDGET(webView)) ? gtk_widget_get_screen(GTK_WIDGET(webView)) : gdk_screen_get_default();
1189     if (screen) {
1190         DPI = gdk_screen_get_resolution(screen);
1191         // gdk_screen_get_resolution() returns -1 when no DPI is set.
1192         if (DPI == -1)
1193             DPI = defaultDPI;
1194     }
1195     ASSERT(DPI > 0);
1196     return DPI;
1197 }
1198
1199 static void webkit_web_view_screen_changed(GtkWidget* widget, GdkScreen* previousScreen)
1200 {
1201     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
1202     WebKitWebViewPrivate* priv = webView->priv;
1203
1204     if (priv->disposing)
1205         return;
1206
1207     WebKitWebSettings* webSettings = priv->webSettings;
1208     Settings* settings = core(webView)->settings();
1209     gdouble DPI = webViewGetDPI(webView);
1210
1211     guint defaultFontSize, defaultMonospaceFontSize, minimumFontSize, minimumLogicalFontSize;
1212
1213     g_object_get(webSettings,
1214                  "default-font-size", &defaultFontSize,
1215                  "default-monospace-font-size", &defaultMonospaceFontSize,
1216                  "minimum-font-size", &minimumFontSize,
1217                  "minimum-logical-font-size", &minimumLogicalFontSize,
1218                  NULL);
1219
1220     settings->setDefaultFontSize(defaultFontSize / 72.0 * DPI);
1221     settings->setDefaultFixedFontSize(defaultMonospaceFontSize / 72.0 * DPI);
1222     settings->setMinimumFontSize(minimumFontSize / 72.0 * DPI);
1223     settings->setMinimumLogicalFontSize(minimumLogicalFontSize / 72.0 * DPI);
1224 }
1225
1226 static void webkit_web_view_drag_end(GtkWidget* widget, GdkDragContext* context)
1227 {
1228     g_object_unref(context);
1229 }
1230
1231 struct DNDContentsRequest
1232 {
1233     gint info;
1234     GtkSelectionData* dnd_selection_data;
1235
1236     gboolean is_url_label_request;
1237     gchar* url;
1238 };
1239
1240 void clipboard_contents_received(GtkClipboard* clipboard, GtkSelectionData* selection_data, gpointer data)
1241 {
1242     DNDContentsRequest* contents_request = reinterpret_cast<DNDContentsRequest*>(data);
1243
1244     if (contents_request->is_url_label_request) {
1245         // We have received contents of the label clipboard. Use them to form
1246         // required structures. When formed, enhance the dnd's selection data
1247         // with them and return.
1248
1249         // If the label is empty, use the url itself.
1250         gchar* url_label = reinterpret_cast<gchar*>(gtk_selection_data_get_text(selection_data));
1251         if (!url_label)
1252             url_label = g_strdup(contents_request->url);
1253
1254         gchar* data = 0;
1255         switch (contents_request->info) {
1256         case WEBKIT_WEB_VIEW_TARGET_INFO_URI_LIST:
1257             data = g_strdup_printf("%s\r\n%s\r\n", contents_request->url, url_label);
1258             break;
1259         case WEBKIT_WEB_VIEW_TARGET_INFO_NETSCAPE_URL:
1260             data = g_strdup_printf("%s\n%s", contents_request->url, url_label);
1261             break;
1262         }
1263
1264         if (data) {
1265             gtk_selection_data_set(contents_request->dnd_selection_data,
1266                                    contents_request->dnd_selection_data->target, 8,
1267                                    reinterpret_cast<const guchar*>(data), strlen(data));
1268             g_free(data);
1269         }
1270
1271         g_free(url_label);
1272         g_free(contents_request->url);
1273         g_free(contents_request);
1274
1275         return;
1276     }
1277
1278     switch (contents_request->info) {
1279     case WEBKIT_WEB_VIEW_TARGET_INFO_HTML:
1280     case WEBKIT_WEB_VIEW_TARGET_INFO_TEXT:
1281         {
1282         gchar* data = reinterpret_cast<gchar*>(gtk_selection_data_get_text(selection_data));
1283         if (data) {
1284             gtk_selection_data_set(contents_request->dnd_selection_data,
1285                                    contents_request->dnd_selection_data->target, 8,
1286                                    reinterpret_cast<const guchar*>(data),
1287                                    strlen(data));
1288             g_free(data);
1289         }
1290         break;
1291         }
1292     case WEBKIT_WEB_VIEW_TARGET_INFO_IMAGE:
1293         {
1294         GdkPixbuf* pixbuf = gtk_selection_data_get_pixbuf(selection_data);
1295         if (pixbuf) {
1296             gtk_selection_data_set_pixbuf(contents_request->dnd_selection_data, pixbuf);
1297             g_object_unref(pixbuf);
1298         }
1299         break;
1300         }
1301     case WEBKIT_WEB_VIEW_TARGET_INFO_URI_LIST:
1302     case WEBKIT_WEB_VIEW_TARGET_INFO_NETSCAPE_URL:
1303         // URL's label is stored in another clipboard, so we store URL into
1304         // contents request, mark the latter as an url label request
1305         // and request for contents of the label clipboard.
1306         contents_request->is_url_label_request = TRUE;
1307         contents_request->url = reinterpret_cast<gchar*>(gtk_selection_data_get_text(selection_data));
1308
1309         gtk_clipboard_request_contents(gtk_clipboard_get(gdk_atom_intern_static_string("WebKitClipboardUrlLabel")),
1310                                        selection_data->target, clipboard_contents_received, contents_request);
1311         break;
1312     }
1313 }
1314
1315 static void webkit_web_view_drag_data_get(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selection_data, guint info, guint time_)
1316 {
1317     GdkAtom selection_atom = GDK_NONE;
1318     GdkAtom target_atom = selection_data->target;
1319
1320     switch (info) {
1321         case WEBKIT_WEB_VIEW_TARGET_INFO_HTML:
1322             selection_atom = gdk_atom_intern_static_string("WebKitClipboardHtml");
1323             // HTML markup data is set as text, therefor, we need a text-like target atom
1324             target_atom = gdk_atom_intern_static_string("UTF8_STRING");
1325             break;
1326         case WEBKIT_WEB_VIEW_TARGET_INFO_TEXT:
1327             selection_atom = gdk_atom_intern_static_string("WebKitClipboardText");
1328             break;
1329         case WEBKIT_WEB_VIEW_TARGET_INFO_IMAGE:
1330             selection_atom = gdk_atom_intern_static_string("WebKitClipboardImage");
1331             break;
1332         case WEBKIT_WEB_VIEW_TARGET_INFO_URI_LIST:
1333         case WEBKIT_WEB_VIEW_TARGET_INFO_NETSCAPE_URL:
1334             selection_atom = gdk_atom_intern_static_string("WebKitClipboardUrl");
1335             // We require URL and label, which are both stored in text format
1336             // and are needed to be retrieved as such.
1337             target_atom = gdk_atom_intern_static_string("UTF8_STRING");
1338             break;
1339     }
1340
1341     DNDContentsRequest* contents_request = g_new(DNDContentsRequest, 1);
1342     contents_request->info = info;
1343     contents_request->is_url_label_request = FALSE;
1344     contents_request->dnd_selection_data = selection_data;
1345
1346     gtk_clipboard_request_contents(gtk_clipboard_get(selection_atom), target_atom,
1347                                    clipboard_contents_received, contents_request);
1348 }
1349
1350 #if GTK_CHECK_VERSION(2, 12, 0)
1351 static gboolean webkit_web_view_query_tooltip(GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip)
1352 {
1353     WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(widget);
1354
1355     if (priv->tooltipText) {
1356         gtk_tooltip_set_text(tooltip, priv->tooltipText);
1357         return TRUE;
1358     }
1359
1360     return FALSE;
1361 }
1362 #endif
1363
1364 static GtkIMContext* webkit_web_view_get_im_context(WebKitWebView* webView)
1365 {
1366     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
1367     return GTK_IM_CONTEXT(webView->priv->imContext);
1368 }
1369
1370 static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
1371 {
1372     GtkBindingSet* binding_set;
1373
1374     webkit_init();
1375
1376     /*
1377      * Signals
1378      */
1379
1380     /**
1381      * WebKitWebView::create-web-view:
1382      * @web_view: the object on which the signal is emitted
1383      * @frame: the #WebKitWebFrame
1384      *
1385      * Emitted when the creation of a new window is requested.
1386      * If this signal is handled the signal handler should return the
1387      * newly created #WebKitWebView.
1388      *
1389      * The new #WebKitWebView should not be displayed to the user
1390      * until the #WebKitWebView::web-view-ready signal is emitted.
1391      *
1392      * The signal handlers should not try to deal with the reference count for
1393      * the new #WebKitWebView. The widget to which the widget is added will
1394      * handle that.
1395      *
1396      * Return value: a newly allocated #WebKitWebView, or %NULL
1397      *
1398      * Since: 1.0.3
1399      */
1400     webkit_web_view_signals[CREATE_WEB_VIEW] = g_signal_new("create-web-view",
1401             G_TYPE_FROM_CLASS(webViewClass),
1402             (GSignalFlags)G_SIGNAL_RUN_LAST,
1403             G_STRUCT_OFFSET (WebKitWebViewClass, create_web_view),
1404             webkit_signal_accumulator_object_handled,
1405             NULL,
1406             webkit_marshal_OBJECT__OBJECT,
1407             WEBKIT_TYPE_WEB_VIEW , 1,
1408             WEBKIT_TYPE_WEB_FRAME);
1409
1410     /**
1411      * WebKitWebView::web-view-ready:
1412      * @web_view: the object on which the signal is emitted
1413      *
1414      * Emitted after #WebKitWebView::create-web-view when the new #WebKitWebView
1415      * should be displayed to the user. When this signal is emitted
1416      * all the information about how the window should look, including
1417      * size, position, whether the location, status and scroll bars
1418      * should be displayed, is already set on the
1419      * #WebKitWebWindowFeatures object contained by the #WebKitWebView.
1420      *
1421      * Notice that some of that information may change during the life
1422      * time of the window, so you may want to connect to the ::notify
1423      * signal of the #WebKitWebWindowFeatures object to handle those.
1424      *
1425      * Return value: %TRUE to stop handlers from being invoked for the event or
1426      * %FALSE to propagate the event furter
1427      *
1428      * Since: 1.0.3
1429      */
1430     webkit_web_view_signals[WEB_VIEW_READY] = g_signal_new("web-view-ready",
1431             G_TYPE_FROM_CLASS(webViewClass),
1432             (GSignalFlags)G_SIGNAL_RUN_LAST,
1433             G_STRUCT_OFFSET (WebKitWebViewClass, web_view_ready),
1434             g_signal_accumulator_true_handled,
1435             NULL,
1436             webkit_marshal_BOOLEAN__VOID,
1437             G_TYPE_BOOLEAN, 0);
1438
1439     /**
1440      * WebKitWebView::close-web-view:
1441      * @web_view: the object on which the signal is emitted
1442      *
1443      * Emitted when closing a #WebKitWebView is requested. This occurs when a
1444      * call is made from JavaScript's window.close function. The default
1445      * signal handler does not do anything. It is the owner's responsibility
1446      * to hide or delete the web view, if necessary.
1447      *
1448      * Return value: %TRUE to stop handlers from being invoked for the event or
1449      * %FALSE to propagate the event furter
1450      *
1451      * Since: 1.1.11
1452      */
1453     webkit_web_view_signals[CLOSE_WEB_VIEW] = g_signal_new("close-web-view",
1454             G_TYPE_FROM_CLASS(webViewClass),
1455             (GSignalFlags)G_SIGNAL_RUN_LAST,
1456             G_STRUCT_OFFSET (WebKitWebViewClass, close_web_view),
1457             g_signal_accumulator_true_handled,
1458             NULL,
1459             webkit_marshal_BOOLEAN__VOID,
1460             G_TYPE_BOOLEAN, 0);
1461
1462     /**
1463      * WebKitWebView::navigation-requested:
1464      * @web_view: the object on which the signal is emitted
1465      * @frame: the #WebKitWebFrame that required the navigation
1466      * @request: a #WebKitNetworkRequest
1467      *
1468      * Emitted when @frame requests a navigation to another page.
1469      *
1470      * Return value: a #WebKitNavigationResponse
1471      *
1472      * Deprecated: Use WebKitWebView::navigation-policy-decision-requested
1473      * instead
1474      */
1475     webkit_web_view_signals[NAVIGATION_REQUESTED] = g_signal_new("navigation-requested",
1476             G_TYPE_FROM_CLASS(webViewClass),
1477             (GSignalFlags)G_SIGNAL_RUN_LAST,
1478             G_STRUCT_OFFSET (WebKitWebViewClass, navigation_requested),
1479             webkit_navigation_request_handled,
1480             NULL,
1481             webkit_marshal_ENUM__OBJECT_OBJECT,
1482             WEBKIT_TYPE_NAVIGATION_RESPONSE, 2,
1483             WEBKIT_TYPE_WEB_FRAME,
1484             WEBKIT_TYPE_NETWORK_REQUEST);
1485
1486     /**
1487      * WebKitWebView::new-window-policy-decision-requested:
1488      * @web_view: the object on which the signal is emitted
1489      * @frame: the #WebKitWebFrame that required the navigation
1490      * @request: a #WebKitNetworkRequest
1491      * @navigation_action: a #WebKitWebNavigation
1492      * @policy_decision: a #WebKitWebPolicyDecision
1493      *
1494      * Emitted when @frame requests opening a new window. With this
1495      * signal the browser can use the context of the request to decide
1496      * about the new window. If the request is not handled the default
1497      * behavior is to allow opening the new window to load the URI,
1498      * which will cause a create-web-view signal emission where the
1499      * browser handles the new window action but without information
1500      * of the context that caused the navigation. The following
1501      * navigation-policy-decision-requested emissions will load the
1502      * page after the creation of the new window just with the
1503      * information of this new navigation context, without any
1504      * information about the action that made this new window to be
1505      * opened.
1506      *
1507      * Notice that if you return TRUE, meaning that you handled the
1508      * signal, you are expected to have decided what to do, by calling
1509      * webkit_web_policy_decision_ignore(),
1510      * webkit_web_policy_decision_use(), or
1511      * webkit_web_policy_decision_download() on the @policy_decision
1512      * object.
1513      *
1514      * Return value: %TRUE if a decision was made, %FALSE to have the
1515      * default behavior apply
1516      *
1517      * Since: 1.1.4
1518      */
1519     webkit_web_view_signals[NEW_WINDOW_POLICY_DECISION_REQUESTED] =
1520         g_signal_new("new-window-policy-decision-requested",
1521             G_TYPE_FROM_CLASS(webViewClass),
1522             (GSignalFlags)G_SIGNAL_RUN_LAST,
1523             0,
1524             g_signal_accumulator_true_handled,
1525             NULL,
1526             webkit_marshal_BOOLEAN__OBJECT_OBJECT_OBJECT_OBJECT,
1527             G_TYPE_BOOLEAN, 4,
1528             WEBKIT_TYPE_WEB_FRAME,
1529             WEBKIT_TYPE_NETWORK_REQUEST,
1530             WEBKIT_TYPE_WEB_NAVIGATION_ACTION,
1531             WEBKIT_TYPE_WEB_POLICY_DECISION);
1532
1533     /**
1534      * WebKitWebView::navigation-policy-decision-requested:
1535      * @web_view: the object on which the signal is emitted
1536      * @frame: the #WebKitWebFrame that required the navigation
1537      * @request: a #WebKitNetworkRequest
1538      * @navigation_action: a #WebKitWebNavigation
1539      * @policy_decision: a #WebKitWebPolicyDecision
1540      *
1541      * Emitted when @frame requests a navigation to another page.
1542      * If this signal is not handled, the default behavior is to allow the
1543      * navigation.
1544      *
1545      * Notice that if you return TRUE, meaning that you handled the
1546      * signal, you are expected to have decided what to do, by calling
1547      * webkit_web_policy_decision_ignore(),
1548      * webkit_web_policy_decision_use(), or
1549      * webkit_web_policy_decision_download() on the @policy_decision
1550      * object.
1551      *
1552      * Return value: %TRUE if a decision was made, %FALSE to have the
1553      * default behavior apply
1554      *
1555      * Since: 1.0.3
1556      */
1557     webkit_web_view_signals[NAVIGATION_POLICY_DECISION_REQUESTED] = g_signal_new("navigation-policy-decision-requested",
1558             G_TYPE_FROM_CLASS(webViewClass),
1559             (GSignalFlags)G_SIGNAL_RUN_LAST,
1560             0,
1561             g_signal_accumulator_true_handled,
1562             NULL,
1563             webkit_marshal_BOOLEAN__OBJECT_OBJECT_OBJECT_OBJECT,
1564             G_TYPE_BOOLEAN, 4,
1565             WEBKIT_TYPE_WEB_FRAME,
1566             WEBKIT_TYPE_NETWORK_REQUEST,
1567             WEBKIT_TYPE_WEB_NAVIGATION_ACTION,
1568             WEBKIT_TYPE_WEB_POLICY_DECISION);
1569
1570     /**
1571      * WebKitWebView::mime-type-policy-decision-requested:
1572      * @web_view: the object on which the signal is emitted
1573      * @frame: the #WebKitWebFrame that required the policy decision
1574      * @request: a WebKitNetworkRequest
1575      * @mimetype: the MIME type attempted to load
1576      * @policy_decision: a #WebKitWebPolicyDecision
1577      *
1578      * Decide whether or not to display the given MIME type.  If this
1579      * signal is not handled, the default behavior is to show the
1580      * content of the requested URI if WebKit can show this MIME
1581      * type and the content disposition is not a download; if WebKit
1582      * is not able to show the MIME type nothing happens.
1583      *
1584      * Notice that if you return TRUE, meaning that you handled the
1585      * signal, you are expected to be aware of the "Content-Disposition"
1586      * header. A value of "attachment" usually indicates a download
1587      * regardless of the MIME type, see also
1588      * soup_message_headers_get_content_disposition(). And you must call
1589      * webkit_web_policy_decision_ignore(),
1590      * webkit_web_policy_decision_use(), or
1591      * webkit_web_policy_decision_download() on the @policy_decision
1592      * object.
1593      *
1594      * Return value: %TRUE if a decision was made, %FALSE to have the
1595      * default behavior apply
1596      *
1597      * Since: 1.0.3
1598      */
1599     webkit_web_view_signals[MIME_TYPE_POLICY_DECISION_REQUESTED] = g_signal_new("mime-type-policy-decision-requested",
1600             G_TYPE_FROM_CLASS(webViewClass),
1601             (GSignalFlags)G_SIGNAL_RUN_LAST,
1602             0,
1603             g_signal_accumulator_true_handled,
1604             NULL,
1605             webkit_marshal_BOOLEAN__OBJECT_OBJECT_STRING_OBJECT,
1606             G_TYPE_BOOLEAN, 4,
1607             WEBKIT_TYPE_WEB_FRAME,
1608             WEBKIT_TYPE_NETWORK_REQUEST,
1609             G_TYPE_STRING,
1610             WEBKIT_TYPE_WEB_POLICY_DECISION);
1611
1612     /**
1613      * WebKitWebView::window-object-cleared:
1614      * @web_view: the object on which the signal is emitted
1615      * @frame: the #WebKitWebFrame to which @window_object belongs
1616      * @context: the #JSGlobalContextRef holding the global object and other
1617      * execution state; equivalent to the return value of
1618      * webkit_web_frame_get_global_context(@frame)
1619      *
1620      * @window_object: the #JSObjectRef representing the frame's JavaScript
1621      * window object
1622      *
1623      * Emitted when the JavaScript window object in a #WebKitWebFrame has been
1624      * cleared in preparation for a new load. This is the preferred place to
1625      * set custom properties on the window object using the JavaScriptCore API.
1626      */
1627     webkit_web_view_signals[WINDOW_OBJECT_CLEARED] = g_signal_new("window-object-cleared",
1628             G_TYPE_FROM_CLASS(webViewClass),
1629             (GSignalFlags)G_SIGNAL_RUN_LAST,
1630             G_STRUCT_OFFSET (WebKitWebViewClass, window_object_cleared),
1631             NULL,
1632             NULL,
1633             webkit_marshal_VOID__OBJECT_POINTER_POINTER,
1634             G_TYPE_NONE, 3,
1635             WEBKIT_TYPE_WEB_FRAME,
1636             G_TYPE_POINTER,
1637             G_TYPE_POINTER);
1638
1639     /**
1640      * WebKitWebView::download-requested:
1641      * @web_view: the object on which the signal is emitted
1642      * @download: a #WebKitDownload object that lets you control the
1643      * download process
1644      *
1645      * A new Download is being requested. By default, if the signal is
1646      * not handled, the download is cancelled. If you handle the download
1647      * and call webkit_download_set_destination_uri(), it will be
1648      * started for you. If you need to set the destination asynchronously
1649      * you are responsible for starting or cancelling it yourself.
1650      *
1651      * If you intend to handle downloads yourself rather than using
1652      * the #WebKitDownload helper object you must handle this signal,
1653      * and return %FALSE.
1654      *
1655      * Also, keep in mind that the default policy for WebKitGTK+ is to
1656      * ignore files with a MIME type that it does not know how to
1657      * handle, which means this signal won't be emitted in the default
1658      * setup. One way to trigger downloads is to connect to
1659      * WebKitWebView::mime-type-policy-decision-requested and call
1660      * webkit_web_policy_decision_download() on the
1661      * #WebKitWebPolicyDecision in the parameter list for the kind of
1662      * files you want your application to download (a common solution
1663      * is to download anything that WebKit can't handle, which you can
1664      * figure out by using webkit_web_view_can_show_mime_type()).
1665      *
1666      * Return value: TRUE if the download should be performed, %FALSE to
1667      * cancel it
1668      *
1669      * Since: 1.1.2
1670      */
1671     webkit_web_view_signals[DOWNLOAD_REQUESTED] = g_signal_new("download-requested",
1672             G_TYPE_FROM_CLASS(webViewClass),
1673             (GSignalFlags)G_SIGNAL_RUN_LAST,
1674             0,
1675             g_signal_accumulator_true_handled,
1676             NULL,
1677             webkit_marshal_BOOLEAN__OBJECT,
1678             G_TYPE_BOOLEAN, 1,
1679             G_TYPE_OBJECT);
1680
1681     /**
1682      * WebKitWebView::load-started:
1683      * @web_view: the object on which the signal is emitted
1684      * @frame: the frame going to do the load
1685      *
1686      * When a #WebKitWebFrame begins to load this signal is emitted.
1687      *
1688      * Deprecated: Use the "load-status" property instead.
1689      */
1690     webkit_web_view_signals[LOAD_STARTED] = g_signal_new("load-started",
1691             G_TYPE_FROM_CLASS(webViewClass),
1692             (GSignalFlags)G_SIGNAL_RUN_LAST,
1693             0,
1694             NULL,
1695             NULL,
1696             g_cclosure_marshal_VOID__OBJECT,
1697             G_TYPE_NONE, 1,
1698             WEBKIT_TYPE_WEB_FRAME);
1699
1700     /**
1701      * WebKitWebView::load-committed:
1702      * @web_view: the object on which the signal is emitted
1703      * @frame: the main frame that received the first data
1704      *
1705      * When a #WebKitWebFrame loaded the first data this signal is emitted.
1706      *
1707      * Deprecated: Use the "load-status" property instead.
1708      */
1709     webkit_web_view_signals[LOAD_COMMITTED] = g_signal_new("load-committed",
1710             G_TYPE_FROM_CLASS(webViewClass),
1711             (GSignalFlags)G_SIGNAL_RUN_LAST,
1712             0,
1713             NULL,
1714             NULL,
1715             g_cclosure_marshal_VOID__OBJECT,
1716             G_TYPE_NONE, 1,
1717             WEBKIT_TYPE_WEB_FRAME);
1718
1719
1720     /**
1721      * WebKitWebView::load-progress-changed:
1722      * @web_view: the #WebKitWebView
1723      * @progress: the global progress
1724      *
1725      * Deprecated: Use the "progress" property instead.
1726      */
1727     webkit_web_view_signals[LOAD_PROGRESS_CHANGED] = g_signal_new("load-progress-changed",
1728             G_TYPE_FROM_CLASS(webViewClass),
1729             (GSignalFlags)G_SIGNAL_RUN_LAST,
1730             0,
1731             NULL,
1732             NULL,
1733             g_cclosure_marshal_VOID__INT,
1734             G_TYPE_NONE, 1,
1735             G_TYPE_INT);
1736
1737     /**
1738      * WebKitWebView::load-error
1739      * @web_view: the object on which the signal is emitted
1740      * @web_frame: the #WebKitWebFrame
1741      * @uri: the URI that triggered the error
1742      * @web_error: the #GError that was triggered
1743      *
1744      * An error occurred while loading. By default, if the signal is not
1745      * handled, the @web_view will display a stock error page. You need to
1746      * handle the signal if you want to provide your own error page.
1747      *
1748      * Since: 1.1.6
1749      *
1750      * Return value: %TRUE to stop other handlers from being invoked for the
1751      * event. %FALSE to propagate the event further.
1752      */
1753     webkit_web_view_signals[LOAD_ERROR] = g_signal_new("load-error",
1754             G_TYPE_FROM_CLASS(webViewClass),
1755             (GSignalFlags)(G_SIGNAL_RUN_LAST),
1756             0,
1757             g_signal_accumulator_true_handled,
1758             NULL,
1759             webkit_marshal_BOOLEAN__OBJECT_STRING_POINTER,
1760             G_TYPE_BOOLEAN, 3,
1761             WEBKIT_TYPE_WEB_FRAME,
1762             G_TYPE_STRING,
1763             G_TYPE_POINTER);
1764
1765     /**
1766      * WebKitWebView::load-finished:
1767      * @web_view: the #WebKitWebView
1768      * @frame: the #WebKitWebFrame
1769      *
1770      * Deprecated: Use the "load-status" property instead.
1771      */
1772     webkit_web_view_signals[LOAD_FINISHED] = g_signal_new("load-finished",
1773             G_TYPE_FROM_CLASS(webViewClass),
1774             (GSignalFlags)G_SIGNAL_RUN_LAST,
1775             0,
1776             NULL,
1777             NULL,
1778             g_cclosure_marshal_VOID__OBJECT,
1779             G_TYPE_NONE, 1,
1780             WEBKIT_TYPE_WEB_FRAME);
1781
1782     /**
1783      * WebKitWebView::title-changed:
1784      * @web_view: the object on which the signal is emitted
1785      * @frame: the main frame
1786      * @title: the new title
1787      *
1788      * When a #WebKitWebFrame changes the document title this signal is emitted.
1789      *
1790      * Deprecated: 1.1.4: Use "notify::title" instead.
1791      */
1792     webkit_web_view_signals[TITLE_CHANGED] = g_signal_new("title-changed",
1793             G_TYPE_FROM_CLASS(webViewClass),
1794             (GSignalFlags)G_SIGNAL_RUN_LAST,
1795             0,
1796             NULL,
1797             NULL,
1798             webkit_marshal_VOID__OBJECT_STRING,
1799             G_TYPE_NONE, 2,
1800             WEBKIT_TYPE_WEB_FRAME,
1801             G_TYPE_STRING);
1802
1803     /**
1804      * WebKitWebView::hovering-over-link:
1805      * @web_view: the object on which the signal is emitted
1806      * @title: the link's title
1807      * @uri: the URI the link points to
1808      *
1809      * When the cursor is over a link, this signal is emitted.
1810      */
1811     webkit_web_view_signals[HOVERING_OVER_LINK] = g_signal_new("hovering-over-link",
1812             G_TYPE_FROM_CLASS(webViewClass),
1813             (GSignalFlags)G_SIGNAL_RUN_LAST,
1814             0,
1815             NULL,
1816             NULL,
1817             webkit_marshal_VOID__STRING_STRING,
1818             G_TYPE_NONE, 2,
1819             G_TYPE_STRING,
1820             G_TYPE_STRING);
1821
1822     /**
1823      * WebKitWebView::populate-popup:
1824      * @web_view: the object on which the signal is emitted
1825      * @menu: the context menu
1826      *
1827      * When a context menu is about to be displayed this signal is emitted.
1828      *
1829      * Add menu items to #menu to extend the context menu.
1830      */
1831     webkit_web_view_signals[POPULATE_POPUP] = g_signal_new("populate-popup",
1832             G_TYPE_FROM_CLASS(webViewClass),
1833             (GSignalFlags)G_SIGNAL_RUN_LAST,
1834             0,
1835             NULL,
1836             NULL,
1837             g_cclosure_marshal_VOID__OBJECT,
1838             G_TYPE_NONE, 1,
1839             GTK_TYPE_MENU);
1840
1841     /**
1842      * WebKitWebView::print-requested
1843      * @web_view: the object in which the signal is emitted
1844      * @web_frame: the frame that is requesting to be printed
1845      *
1846      * Emitted when printing is requested by the frame, usually
1847      * because of a javascript call. When handling this signal you
1848      * should call webkit_web_frame_print_full() or
1849      * webkit_web_frame_print() to do the actual printing.
1850      *
1851      * The default handler will present a print dialog and carry a
1852      * print operation. Notice that this means that if you intend to
1853      * ignore a print request you must connect to this signal, and
1854      * return %TRUE.
1855      *
1856      * Return value: %TRUE if the print request has been handled, %FALSE if
1857      * the default handler should run
1858      *
1859      * Since: 1.1.5
1860      */
1861     webkit_web_view_signals[PRINT_REQUESTED] = g_signal_new("print-requested",
1862             G_TYPE_FROM_CLASS(webViewClass),
1863             (GSignalFlags)G_SIGNAL_RUN_LAST,
1864             0,
1865             g_signal_accumulator_true_handled,
1866             NULL,
1867             webkit_marshal_BOOLEAN__OBJECT,
1868             G_TYPE_BOOLEAN, 1,
1869             WEBKIT_TYPE_WEB_FRAME);
1870
1871     webkit_web_view_signals[STATUS_BAR_TEXT_CHANGED] = g_signal_new("status-bar-text-changed",
1872             G_TYPE_FROM_CLASS(webViewClass),
1873             (GSignalFlags)G_SIGNAL_RUN_LAST,
1874             0,
1875             NULL,
1876             NULL,
1877             g_cclosure_marshal_VOID__STRING,
1878             G_TYPE_NONE, 1,
1879             G_TYPE_STRING);
1880
1881     /**
1882      * WebKitWebView::icon-loaded:
1883      * @web_view: the object on which the signal is emitted
1884      * @icon_uri: the URI for the icon
1885      *
1886      * This signal is emitted when the main frame has got a favicon.
1887      *
1888      * Since: 1.1.18
1889      */
1890     webkit_web_view_signals[ICON_LOADED] = g_signal_new("icon-loaded",
1891             G_TYPE_FROM_CLASS(webViewClass),
1892             (GSignalFlags)G_SIGNAL_RUN_LAST,
1893             0,
1894             NULL,
1895             NULL,
1896             g_cclosure_marshal_VOID__STRING,
1897             G_TYPE_NONE, 1,
1898             G_TYPE_STRING);
1899
1900     webkit_web_view_signals[SELECTION_CHANGED] = g_signal_new("selection-changed",
1901             G_TYPE_FROM_CLASS(webViewClass),
1902             (GSignalFlags)G_SIGNAL_RUN_LAST,
1903             0,
1904             NULL,
1905             NULL,
1906             g_cclosure_marshal_VOID__VOID,
1907             G_TYPE_NONE, 0);
1908
1909     /**
1910      * WebKitWebView::console-message:
1911      * @web_view: the object on which the signal is emitted
1912      * @message: the message text
1913      * @line: the line where the error occured
1914      * @source_id: the source id
1915      *
1916      * A JavaScript console message was created.
1917      *
1918      * Return value: %TRUE to stop other handlers from being invoked for the
1919      * event. %FALSE to propagate the event further.
1920      */
1921     webkit_web_view_signals[CONSOLE_MESSAGE] = g_signal_new("console-message",
1922             G_TYPE_FROM_CLASS(webViewClass),
1923             (GSignalFlags)G_SIGNAL_RUN_LAST,
1924             G_STRUCT_OFFSET(WebKitWebViewClass, console_message),
1925             g_signal_accumulator_true_handled,
1926             NULL,
1927             webkit_marshal_BOOLEAN__STRING_INT_STRING,
1928             G_TYPE_BOOLEAN, 3,
1929             G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
1930
1931     /**
1932      * WebKitWebView::script-alert:
1933      * @web_view: the object on which the signal is emitted
1934      * @frame: the relevant frame
1935      * @message: the message text
1936      *
1937      * A JavaScript alert dialog was created.
1938      *
1939      * Return value: %TRUE to stop other handlers from being invoked for the
1940      * event. %FALSE to propagate the event further.
1941      */
1942     webkit_web_view_signals[SCRIPT_ALERT] = g_signal_new("script-alert",
1943             G_TYPE_FROM_CLASS(webViewClass),
1944             (GSignalFlags)G_SIGNAL_RUN_LAST,
1945             G_STRUCT_OFFSET(WebKitWebViewClass, script_alert),
1946             g_signal_accumulator_true_handled,
1947             NULL,
1948             webkit_marshal_BOOLEAN__OBJECT_STRING,
1949             G_TYPE_BOOLEAN, 2,
1950             WEBKIT_TYPE_WEB_FRAME, G_TYPE_STRING);
1951
1952     /**
1953      * WebKitWebView::script-confirm:
1954      * @web_view: the object on which the signal is emitted
1955      * @frame: the relevant frame
1956      * @message: the message text
1957      * @confirmed: whether the dialog has been confirmed
1958      *
1959      * A JavaScript confirm dialog was created, providing Yes and No buttons.
1960      *
1961      * Return value: %TRUE to stop other handlers from being invoked for the
1962      * event. %FALSE to propagate the event further.
1963      */
1964     webkit_web_view_signals[SCRIPT_CONFIRM] = g_signal_new("script-confirm",
1965             G_TYPE_FROM_CLASS(webViewClass),
1966             (GSignalFlags)G_SIGNAL_RUN_LAST,
1967             G_STRUCT_OFFSET(WebKitWebViewClass, script_confirm),
1968             g_signal_accumulator_true_handled,
1969             NULL,
1970             webkit_marshal_BOOLEAN__OBJECT_STRING_POINTER,
1971             G_TYPE_BOOLEAN, 3,
1972             WEBKIT_TYPE_WEB_FRAME, G_TYPE_STRING, G_TYPE_POINTER);
1973
1974     /**
1975      * WebKitWebView::script-prompt:
1976      * @web_view: the object on which the signal is emitted
1977      * @frame: the relevant frame
1978      * @message: the message text
1979      * @default: the default value
1980      * @text: To be filled with the return value or NULL if the dialog was cancelled.
1981      *
1982      * A JavaScript prompt dialog was created, providing an entry to input text.
1983      *
1984      * Return value: %TRUE to stop other handlers from being invoked for the
1985      * event. %FALSE to propagate the event further.
1986      */
1987     webkit_web_view_signals[SCRIPT_PROMPT] = g_signal_new("script-prompt",
1988             G_TYPE_FROM_CLASS(webViewClass),
1989             (GSignalFlags)G_SIGNAL_RUN_LAST,
1990             G_STRUCT_OFFSET(WebKitWebViewClass, script_prompt),
1991             g_signal_accumulator_true_handled,
1992             NULL,
1993             webkit_marshal_BOOLEAN__OBJECT_STRING_STRING_STRING,
1994             G_TYPE_BOOLEAN, 4,
1995             WEBKIT_TYPE_WEB_FRAME, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
1996
1997     /**
1998      * WebKitWebView::select-all:
1999      * @web_view: the object which received the signal
2000      *
2001      * The #WebKitWebView::select-all signal is a keybinding signal which gets emitted to
2002      * select the complete contents of the text view.
2003      *
2004      * The default bindings for this signal is Ctrl-a.
2005      */
2006     webkit_web_view_signals[SELECT_ALL] = g_signal_new("select-all",
2007             G_TYPE_FROM_CLASS(webViewClass),
2008             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
2009             G_STRUCT_OFFSET(WebKitWebViewClass, select_all),
2010             NULL, NULL,
2011             g_cclosure_marshal_VOID__VOID,
2012             G_TYPE_NONE, 0);
2013
2014     /**
2015      * WebKitWebView::cut-clipboard:
2016      * @web_view: the object which received the signal
2017      *
2018      * The #WebKitWebView::cut-clipboard signal is a keybinding signal which gets emitted to
2019      * cut the selection to the clipboard.
2020      *
2021      * The default bindings for this signal are Ctrl-x and Shift-Delete.
2022      */
2023     webkit_web_view_signals[CUT_CLIPBOARD] = g_signal_new("cut-clipboard",
2024             G_TYPE_FROM_CLASS(webViewClass),
2025             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
2026             G_STRUCT_OFFSET(WebKitWebViewClass, cut_clipboard),
2027             NULL, NULL,
2028             g_cclosure_marshal_VOID__VOID,
2029             G_TYPE_NONE, 0);
2030
2031     /**
2032      * WebKitWebView::copy-clipboard:
2033      * @web_view: the object which received the signal
2034      *
2035      * The #WebKitWebView::copy-clipboard signal is a keybinding signal which gets emitted to
2036      * copy the selection to the clipboard.
2037      *
2038      * The default bindings for this signal are Ctrl-c and Ctrl-Insert.
2039      */
2040     webkit_web_view_signals[COPY_CLIPBOARD] = g_signal_new("copy-clipboard",
2041             G_TYPE_FROM_CLASS(webViewClass),
2042             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
2043             G_STRUCT_OFFSET(WebKitWebViewClass, copy_clipboard),
2044             NULL, NULL,
2045             g_cclosure_marshal_VOID__VOID,
2046             G_TYPE_NONE, 0);
2047
2048     /**
2049      * WebKitWebView::paste-clipboard:
2050      * @web_view: the object which received the signal
2051      *
2052      * The #WebKitWebView::paste-clipboard signal is a keybinding signal which gets emitted to
2053      * paste the contents of the clipboard into the Web view.
2054      *
2055      * The default bindings for this signal are Ctrl-v and Shift-Insert.
2056      */
2057     webkit_web_view_signals[PASTE_CLIPBOARD] = g_signal_new("paste-clipboard",
2058             G_TYPE_FROM_CLASS(webViewClass),
2059             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
2060             G_STRUCT_OFFSET(WebKitWebViewClass, paste_clipboard),
2061             NULL, NULL,
2062             g_cclosure_marshal_VOID__VOID,
2063             G_TYPE_NONE, 0);
2064
2065     /**
2066      * WebKitWebView::undo
2067      * @web_view: the object which received the signal
2068      *
2069      * The #WebKitWebView::undo signal is a keybinding signal which gets emitted to
2070      * undo the last editing command.
2071      *
2072      * The default binding for this signal is Ctrl-z
2073      *
2074      * Since: 1.1.14
2075      */
2076     webkit_web_view_signals[UNDO] = g_signal_new("undo",
2077             G_TYPE_FROM_CLASS(webViewClass),
2078             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
2079             G_STRUCT_OFFSET(WebKitWebViewClass, undo),
2080             NULL, NULL,
2081             g_cclosure_marshal_VOID__VOID,
2082             G_TYPE_NONE, 0);
2083
2084     /**
2085      * WebKitWebView::redo
2086      * @web_view: the object which received the signal
2087      *
2088      * The #WebKitWebView::redo signal is a keybinding signal which gets emitted to
2089      * redo the last editing command.
2090      *
2091      * The default binding for this signal is Ctrl-Shift-z
2092      *
2093      * Since: 1.1.14
2094      */
2095     webkit_web_view_signals[REDO] = g_signal_new("redo",
2096             G_TYPE_FROM_CLASS(webViewClass),
2097             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
2098             G_STRUCT_OFFSET(WebKitWebViewClass, redo),
2099             NULL, NULL,
2100             g_cclosure_marshal_VOID__VOID,
2101             G_TYPE_NONE, 0);
2102
2103     /**
2104      * WebKitWebView::move-cursor:
2105      * @web_view: the object which received the signal
2106      * @step: the type of movement, one of #GtkMovementStep
2107      * @count: an integer indicating the subtype of movement. Currently
2108      *         the permitted values are '1' = forward, '-1' = backwards.
2109      *
2110      * The #WebKitWebView::move-cursor will be emitted to apply the
2111      * cursor movement described by its parameters to the @view.
2112      *
2113      * Return value: %TRUE or %FALSE
2114      * 
2115      * Since: 1.1.4
2116      */
2117     webkit_web_view_signals[MOVE_CURSOR] = g_signal_new("move-cursor",
2118             G_TYPE_FROM_CLASS(webViewClass),
2119             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
2120             G_STRUCT_OFFSET(WebKitWebViewClass, move_cursor),
2121             NULL, NULL,
2122             webkit_marshal_BOOLEAN__ENUM_INT,
2123             G_TYPE_BOOLEAN, 2,
2124             GTK_TYPE_MOVEMENT_STEP,
2125             G_TYPE_INT);
2126
2127     /**
2128      * WebKitWebView::create-plugin-widget:
2129      * @web_view: the object which received the signal
2130      * @mime_type: the mimetype of the requested object
2131      * @uri: the URI to load
2132      * @param: a #GHashTable with additional attributes (strings)
2133      *
2134      * The #WebKitWebView::create-plugin signal will be emitted to
2135      * create a plugin widget for embed or object HTML tags. This
2136      * allows to embed a GtkWidget as a plugin into HTML content. In
2137      * case of a textual selection of the GtkWidget WebCore will attempt
2138      * to set the property value of "webkit-widget-is-selected". This can
2139      * be used to draw a visual indicator of the selection.
2140      *
2141      * Return value: a new #GtkWidget, or %NULL
2142      *
2143      * Since: 1.1.8
2144      */
2145     webkit_web_view_signals[PLUGIN_WIDGET] = g_signal_new("create-plugin-widget",
2146             G_TYPE_FROM_CLASS(webViewClass),
2147             (GSignalFlags) (G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
2148             0,
2149             webkit_signal_accumulator_object_handled,
2150             NULL,
2151             webkit_marshal_OBJECT__STRING_STRING_POINTER,
2152             GTK_TYPE_WIDGET, 3,
2153             G_TYPE_STRING, G_TYPE_STRING, G_TYPE_HASH_TABLE);
2154
2155     /**
2156      * WebKitWebView::database-quota-exceeded
2157      * @web_view: the object which received the signal
2158      * @frame: the relevant frame
2159      * @database: the #WebKitWebDatabase which exceeded the quota of its #WebKitSecurityOrigin
2160      *
2161      * The #WebKitWebView::database-exceeded-quota signal will be emitted when
2162      * a Web Database exceeds the quota of its security origin. This signal
2163      * may be used to increase the size of the quota before the originating
2164      * operation fails.
2165      *
2166      * Since: 1.1.14
2167      */
2168     webkit_web_view_signals[DATABASE_QUOTA_EXCEEDED] = g_signal_new("database-quota-exceeded",
2169             G_TYPE_FROM_CLASS(webViewClass),
2170             (GSignalFlags) (G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
2171             0,
2172             NULL, NULL,
2173             webkit_marshal_VOID__OBJECT_OBJECT,
2174             G_TYPE_NONE, 2,
2175             G_TYPE_OBJECT, G_TYPE_OBJECT);
2176
2177     /**
2178      * WebKitWebView::resource-request-starting:
2179      * @web_view: the object which received the signal
2180      * @web_frame: the #WebKitWebFrame whose load dispatched this request
2181      * @web_resource: an empty #WebKitWebResource object
2182      * @request: the #WebKitNetworkRequest that will be dispatched
2183      * @response: the #WebKitNetworkResponse representing the redirect
2184      * response, if any
2185      *
2186      * Emitted when a request is about to be sent. You can modify the
2187      * request while handling this signal. You can set the URI in the
2188      * #WebKitNetworkRequest object itself, and add/remove/replace
2189      * headers using the #SoupMessage object it carries, if it is
2190      * present. See webkit_network_request_get_message(). Setting the
2191      * request URI to "about:blank" will effectively cause the request
2192      * to load nothing, and can be used to disable the loading of
2193      * specific resources.
2194      *
2195      * Notice that information about an eventual redirect is available
2196      * in @response's #SoupMessage, not in the #SoupMessage carried by
2197      * the @request. If @response is %NULL, then this is not a
2198      * redirected request.
2199      *
2200      * The #WebKitWebResource object will be the same throughout all
2201      * the lifetime of the resource, but the contents may change from
2202      * inbetween signal emissions.
2203      *
2204      * Since: 1.1.14
2205      */
2206     webkit_web_view_signals[RESOURCE_REQUEST_STARTING] = g_signal_new("resource-request-starting",
2207             G_TYPE_FROM_CLASS(webViewClass),
2208             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
2209             0,
2210             NULL, NULL,
2211             webkit_marshal_VOID__OBJECT_OBJECT_OBJECT_OBJECT,
2212             G_TYPE_NONE, 4,
2213             WEBKIT_TYPE_WEB_FRAME,
2214             WEBKIT_TYPE_WEB_RESOURCE,
2215             WEBKIT_TYPE_NETWORK_REQUEST,
2216             WEBKIT_TYPE_NETWORK_RESPONSE);
2217
2218     /**
2219      * WebKitWebView::geolocation-policy-decision-requested:
2220      * @web_view: the object on which the signal is emitted
2221      * @frame: the frame that requests permission
2222      * @policy_decision: a WebKitGeolocationPolicyDecision
2223      *
2224      * When a @frame wants to get its geolocation permission.
2225      * The receiver must reply with a boolean wether it handled or not the
2226      * request. If the request is not handled, default behaviour is to deny
2227      * geolocation.
2228      *
2229      * Since: 1.1.23
2230      */
2231     webkit_web_view_signals[GEOLOCATION_POLICY_DECISION_REQUESTED] = g_signal_new("geolocation-policy-decision-requested",
2232             G_TYPE_FROM_CLASS(webViewClass),
2233             (GSignalFlags)(G_SIGNAL_RUN_LAST),
2234             0,
2235             NULL, NULL,
2236             webkit_marshal_BOOLEAN__OBJECT_OBJECT,
2237             G_TYPE_BOOLEAN, 2,
2238             WEBKIT_TYPE_WEB_FRAME,
2239             WEBKIT_TYPE_GEOLOCATION_POLICY_DECISION);
2240
2241     /**
2242      * WebKitWebView::geolocation-policy-decision-cancelled:
2243      * @web_view: the object on which the signal is emitted
2244      * @frame: the frame that cancels geolocation request.
2245      *
2246      * When a @frame wants to cancel geolocation permission it had requested
2247      * before.
2248      *
2249      * Since: 1.1.23
2250      */
2251     webkit_web_view_signals[GEOLOCATION_POLICY_DECISION_REQUESTED] = g_signal_new("geolocation-policy-decision-cancelled",
2252             G_TYPE_FROM_CLASS(webViewClass),
2253             (GSignalFlags)(G_SIGNAL_RUN_LAST),
2254             0,
2255             NULL, NULL,
2256             g_cclosure_marshal_VOID__OBJECT,
2257             G_TYPE_NONE, 1,
2258             WEBKIT_TYPE_WEB_FRAME);
2259
2260     /*
2261      * DOM-related signals. These signals are experimental, for now,
2262      * and may change API and ABI. Their comments lack one * on
2263      * purpose, to make them not be catched by gtk-doc.
2264      */
2265
2266     /*
2267      * WebKitWebView::document-load-finished
2268      * @web_view: the object which received the signal
2269      * @web_frame: the #WebKitWebFrame whose load dispatched this request
2270      *
2271      * Emitted when the DOM document object load is finished for the
2272      * given frame.
2273      */
2274     webkit_web_view_signals[DOCUMENT_LOAD_FINISHED] = g_signal_new("document-load-finished",
2275             G_TYPE_FROM_CLASS(webViewClass),
2276             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
2277             0,
2278             NULL, NULL,
2279             g_cclosure_marshal_VOID__OBJECT,
2280             G_TYPE_NONE, 1,
2281             WEBKIT_TYPE_WEB_FRAME);
2282
2283
2284     /*
2285      * implementations of virtual methods
2286      */
2287     webViewClass->create_web_view = webkit_web_view_real_create_web_view;
2288     webViewClass->web_view_ready = webkit_web_view_real_web_view_ready;
2289     webViewClass->close_web_view = webkit_web_view_real_close_web_view;
2290     webViewClass->navigation_requested = webkit_web_view_real_navigation_requested;
2291     webViewClass->window_object_cleared = webkit_web_view_real_window_object_cleared;
2292     webViewClass->choose_file = webkit_web_view_real_choose_file;
2293     webViewClass->script_alert = webkit_web_view_real_script_alert;
2294     webViewClass->script_confirm = webkit_web_view_real_script_confirm;
2295     webViewClass->script_prompt = webkit_web_view_real_script_prompt;
2296     webViewClass->console_message = webkit_web_view_real_console_message;
2297     webViewClass->select_all = webkit_web_view_real_select_all;
2298     webViewClass->cut_clipboard = webkit_web_view_real_cut_clipboard;
2299     webViewClass->copy_clipboard = webkit_web_view_real_copy_clipboard;
2300     webViewClass->paste_clipboard = webkit_web_view_real_paste_clipboard;
2301     webViewClass->undo = webkit_web_view_real_undo;
2302     webViewClass->redo = webkit_web_view_real_redo;
2303     webViewClass->move_cursor = webkit_web_view_real_move_cursor;
2304
2305     GObjectClass* objectClass = G_OBJECT_CLASS(webViewClass);
2306     objectClass->dispose = webkit_web_view_dispose;
2307     objectClass->finalize = webkit_web_view_finalize;
2308     objectClass->get_property = webkit_web_view_get_property;
2309     objectClass->set_property = webkit_web_view_set_property;
2310
2311     GtkWidgetClass* widgetClass = GTK_WIDGET_CLASS(webViewClass);
2312     widgetClass->realize = webkit_web_view_realize;
2313     widgetClass->expose_event = webkit_web_view_expose_event;
2314     widgetClass->key_press_event = webkit_web_view_key_press_event;
2315     widgetClass->key_release_event = webkit_web_view_key_release_event;
2316     widgetClass->button_press_event = webkit_web_view_button_press_event;
2317     widgetClass->button_release_event = webkit_web_view_button_release_event;
2318     widgetClass->motion_notify_event = webkit_web_view_motion_event;
2319     widgetClass->scroll_event = webkit_web_view_scroll_event;
2320     widgetClass->size_allocate = webkit_web_view_size_allocate;
2321     widgetClass->size_request = webkit_web_view_size_request;
2322     widgetClass->popup_menu = webkit_web_view_popup_menu_handler;
2323     widgetClass->grab_focus = webkit_web_view_grab_focus;
2324     widgetClass->focus_in_event = webkit_web_view_focus_in_event;
2325     widgetClass->focus_out_event = webkit_web_view_focus_out_event;
2326     widgetClass->get_accessible = webkit_web_view_get_accessible;
2327     widgetClass->screen_changed = webkit_web_view_screen_changed;
2328     widgetClass->drag_end = webkit_web_view_drag_end;
2329     widgetClass->drag_data_get = webkit_web_view_drag_data_get;
2330 #if GTK_CHECK_VERSION(2, 12, 0)
2331     widgetClass->query_tooltip = webkit_web_view_query_tooltip;
2332 #endif
2333
2334     GtkContainerClass* containerClass = GTK_CONTAINER_CLASS(webViewClass);
2335     containerClass->add = webkit_web_view_container_add;
2336     containerClass->remove = webkit_web_view_container_remove;
2337     containerClass->forall = webkit_web_view_container_forall;
2338
2339     /*
2340      * make us scrollable (e.g. addable to a GtkScrolledWindow)
2341      */
2342     webViewClass->set_scroll_adjustments = webkit_web_view_set_scroll_adjustments;
2343     GTK_WIDGET_CLASS(webViewClass)->set_scroll_adjustments_signal = g_signal_new("set-scroll-adjustments",
2344             G_TYPE_FROM_CLASS(webViewClass),
2345             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
2346             G_STRUCT_OFFSET(WebKitWebViewClass, set_scroll_adjustments),
2347             NULL, NULL,
2348             webkit_marshal_VOID__OBJECT_OBJECT,
2349             G_TYPE_NONE, 2,
2350             GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
2351
2352     /*
2353      * Key bindings
2354      */
2355
2356     binding_set = gtk_binding_set_by_class(webViewClass);
2357
2358     gtk_binding_entry_add_signal(binding_set, GDK_a, GDK_CONTROL_MASK,
2359                                  "select_all", 0);
2360
2361     /* Cut/copy/paste */
2362
2363     gtk_binding_entry_add_signal(binding_set, GDK_x, GDK_CONTROL_MASK,
2364                                  "cut_clipboard", 0);
2365     gtk_binding_entry_add_signal(binding_set, GDK_c, GDK_CONTROL_MASK,
2366                                  "copy_clipboard", 0);
2367     gtk_binding_entry_add_signal(binding_set, GDK_v, GDK_CONTROL_MASK,
2368                                  "paste_clipboard", 0);
2369     gtk_binding_entry_add_signal(binding_set, GDK_z, GDK_CONTROL_MASK,
2370                                  "undo", 0);
2371     gtk_binding_entry_add_signal(binding_set, GDK_z, static_cast<GdkModifierType>(GDK_CONTROL_MASK | GDK_SHIFT_MASK),
2372                                  "redo", 0);
2373
2374     gtk_binding_entry_add_signal(binding_set, GDK_Delete, GDK_SHIFT_MASK,
2375                                  "cut_clipboard", 0);
2376     gtk_binding_entry_add_signal(binding_set, GDK_Insert, GDK_CONTROL_MASK,
2377                                  "copy_clipboard", 0);
2378     gtk_binding_entry_add_signal(binding_set, GDK_Insert, GDK_SHIFT_MASK,
2379                                  "paste_clipboard", 0);
2380
2381     /* Movement */
2382     
2383     gtk_binding_entry_add_signal(binding_set, GDK_Down, static_cast<GdkModifierType>(0),
2384                                  "move-cursor", 2,
2385                                  G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINES,
2386                                  G_TYPE_INT, 1);
2387     gtk_binding_entry_add_signal(binding_set, GDK_Up, static_cast<GdkModifierType>(0),
2388                                  "move-cursor", 2,
2389                                  G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINES,
2390                                  G_TYPE_INT, -1);
2391     gtk_binding_entry_add_signal(binding_set, GDK_Right, static_cast<GdkModifierType>(0),
2392                                  "move-cursor", 2,
2393                                  G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
2394                                  G_TYPE_INT, 1);
2395     gtk_binding_entry_add_signal(binding_set, GDK_Left, static_cast<GdkModifierType>(0),
2396                                  "move-cursor", 2,
2397                                  G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
2398                                  G_TYPE_INT, -1);
2399     gtk_binding_entry_add_signal(binding_set, GDK_space, static_cast<GdkModifierType>(0),
2400                                  "move-cursor", 2,
2401                                  G_TYPE_ENUM, GTK_MOVEMENT_PAGES,
2402                                  G_TYPE_INT, 1);
2403     gtk_binding_entry_add_signal(binding_set, GDK_space, GDK_SHIFT_MASK,
2404                                  "move-cursor", 2,
2405                                  G_TYPE_ENUM, GTK_MOVEMENT_PAGES,
2406                                  G_TYPE_INT, -1);
2407     gtk_binding_entry_add_signal(binding_set, GDK_Page_Down, static_cast<GdkModifierType>(0),
2408                                  "move-cursor", 2,
2409                                  G_TYPE_ENUM, GTK_MOVEMENT_PAGES,
2410                                  G_TYPE_INT, 1);
2411     gtk_binding_entry_add_signal(binding_set, GDK_Page_Up, static_cast<GdkModifierType>(0),
2412                                  "move-cursor", 2,
2413                                  G_TYPE_ENUM, GTK_MOVEMENT_PAGES,
2414                                  G_TYPE_INT, -1);
2415     gtk_binding_entry_add_signal(binding_set, GDK_End, static_cast<GdkModifierType>(0),
2416                                  "move-cursor", 2,
2417                                  G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
2418                                  G_TYPE_INT, 1);
2419     gtk_binding_entry_add_signal(binding_set, GDK_Home, static_cast<GdkModifierType>(0),
2420                                  "move-cursor", 2,
2421                                  G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
2422                                  G_TYPE_INT, -1);
2423
2424     /*
2425      * properties
2426      */
2427
2428     /**
2429     * WebKitWebView:title:
2430     *
2431     * Returns the @web_view's document title.
2432     *
2433     * Since: 1.1.4
2434     */
2435     g_object_class_install_property(objectClass, PROP_TITLE,
2436                                     g_param_spec_string("title",
2437                                                         _("Title"),
2438                                                         _("Returns the @web_view's document title"),
2439                                                         NULL,
2440                                                         WEBKIT_PARAM_READABLE));
2441
2442     /**
2443     * WebKitWebView:uri:
2444     *
2445     * Returns the current URI of the contents displayed by the @web_view.
2446     *
2447     * Since: 1.1.4
2448     */
2449     g_object_class_install_property(objectClass, PROP_URI,
2450                                     g_param_spec_string("uri",
2451                                                         _("URI"),
2452                                                         _("Returns the current URI of the contents displayed by the @web_view"),
2453                                                         NULL,
2454                                                         WEBKIT_PARAM_READABLE));
2455
2456     /**
2457     * WebKitWebView:copy-target-list:
2458     *
2459     * The list of targets this web view supports for clipboard copying.
2460     *
2461     * Since: 1.0.2
2462     */
2463     g_object_class_install_property(objectClass, PROP_COPY_TARGET_LIST,
2464                                     g_param_spec_boxed("copy-target-list",
2465                                                        _("Copy target list"),
2466                                                        _("The list of targets this web view supports for clipboard copying"),
2467                                                        GTK_TYPE_TARGET_LIST,
2468                                                        WEBKIT_PARAM_READABLE));
2469
2470     /**
2471     * WebKitWebView:paste-target-list:
2472     *
2473     * The list of targets this web view supports for clipboard pasting.
2474     *
2475     * Since: 1.0.2
2476     */
2477     g_object_class_install_property(objectClass, PROP_PASTE_TARGET_LIST,
2478                                     g_param_spec_boxed("paste-target-list",
2479                                                        _("Paste target list"),
2480                                                        _("The list of targets this web view supports for clipboard pasting"),
2481                                                        GTK_TYPE_TARGET_LIST,
2482                                                        WEBKIT_PARAM_READABLE));
2483
2484     g_object_class_install_property(objectClass, PROP_SETTINGS,
2485                                     g_param_spec_object("settings",
2486                                                         _("Settings"),
2487                                                         _("An associated WebKitWebSettings instance"),
2488                                                         WEBKIT_TYPE_WEB_SETTINGS,
2489                                                         WEBKIT_PARAM_READWRITE));
2490
2491     /**
2492     * WebKitWebView:web-inspector:
2493     *
2494     * The associated WebKitWebInspector instance.
2495     *
2496     * Since: 1.0.3
2497     */
2498     g_object_class_install_property(objectClass, PROP_WEB_INSPECTOR,
2499                                     g_param_spec_object("web-inspector",
2500                                                         _("Web Inspector"),
2501                                                         _("The associated WebKitWebInspector instance"),
2502                                                         WEBKIT_TYPE_WEB_INSPECTOR,
2503                                                         WEBKIT_PARAM_READABLE));
2504
2505     /**
2506     * WebKitWebView:window-features:
2507     *
2508     * An associated WebKitWebWindowFeatures instance.
2509     *
2510     * Since: 1.0.3
2511     */
2512     g_object_class_install_property(objectClass, PROP_WINDOW_FEATURES,
2513                                     g_param_spec_object("window-features",
2514                                                         "Window Features",
2515                                                         "An associated WebKitWebWindowFeatures instance",
2516                                                         WEBKIT_TYPE_WEB_WINDOW_FEATURES,
2517                                                         WEBKIT_PARAM_READWRITE));
2518
2519     g_object_class_install_property(objectClass, PROP_EDITABLE,
2520                                     g_param_spec_boolean("editable",
2521                                                          _("Editable"),
2522                                                          _("Whether content can be modified by the user"),
2523                                                          FALSE,
2524                                                          WEBKIT_PARAM_READWRITE));
2525
2526     g_object_class_install_property(objectClass, PROP_TRANSPARENT,
2527                                     g_param_spec_boolean("transparent",
2528                                                          _("Transparent"),
2529                                                          _("Whether content has a transparent background"),
2530                                                          FALSE,
2531                                                          WEBKIT_PARAM_READWRITE));
2532
2533     /**
2534     * WebKitWebView:zoom-level:
2535     *
2536     * The level of zoom of the content.
2537     *
2538     * Since: 1.0.1
2539     */
2540     g_object_class_install_property(objectClass, PROP_ZOOM_LEVEL,
2541                                     g_param_spec_float("zoom-level",
2542                                                        _("Zoom level"),
2543                                                        _("The level of zoom of the content"),
2544                                                        G_MINFLOAT,
2545                                                        G_MAXFLOAT,
2546                                                        1.0f,
2547                                                        WEBKIT_PARAM_READWRITE));
2548
2549     /**
2550     * WebKitWebView:full-content-zoom:
2551     *
2552     * Whether the full content is scaled when zooming.
2553     *
2554     * Since: 1.0.1
2555     */
2556     g_object_class_install_property(objectClass, PROP_FULL_CONTENT_ZOOM,
2557                                     g_param_spec_boolean("full-content-zoom",
2558                                                          _("Full content zoom"),
2559                                                          _("Whether the full content is scaled when zooming"),
2560                                                          FALSE,
2561                                                          WEBKIT_PARAM_READWRITE));
2562
2563     /**
2564      * WebKitWebView:encoding:
2565      *
2566      * The default encoding of the web view.
2567      *
2568      * Since: 1.1.2
2569      */
2570     g_object_class_install_property(objectClass, PROP_ENCODING,
2571                                     g_param_spec_string("encoding",
2572                                                         _("Encoding"),
2573                                                         _("The default encoding of the web view"),
2574                                                         NULL,
2575                                                         WEBKIT_PARAM_READABLE));
2576
2577     /**
2578      * WebKitWebView:custom-encoding:
2579      *
2580      * The custom encoding of the web view.
2581      *
2582      * Since: 1.1.2
2583      */
2584     g_object_class_install_property(objectClass, PROP_CUSTOM_ENCODING,
2585                                     g_param_spec_string("custom-encoding",
2586                                                         _("Custom Encoding"),
2587                                                         _("The custom encoding of the web view"),
2588                                                         NULL,
2589                                                         WEBKIT_PARAM_READWRITE));
2590
2591     /**
2592     * WebKitWebView:load-status:
2593     *
2594     * Determines the current status of the load.
2595     *
2596     * Connect to "notify::load-status" to monitor loading.
2597     *
2598     * Some versions of WebKitGTK+ emitted this signal for the default
2599     * error page, while loading it. This behavior was considered bad,
2600     * because it was essentially exposing an implementation
2601     * detail. From 1.1.19 onwards this signal is no longer emitted for
2602     * the default error pages, but keep in mind that if you override
2603     * the error pages by using webkit_web_frame_load_alternate_string()
2604     * the signals will be emitted.
2605     *
2606     * Since: 1.1.7
2607     */
2608     g_object_class_install_property(objectClass, PROP_LOAD_STATUS,
2609                                     g_param_spec_enum("load-status",
2610                                                       "Load Status",
2611                                                       "Determines the current status of the load",
2612                                                       WEBKIT_TYPE_LOAD_STATUS,
2613                                                       WEBKIT_LOAD_FINISHED,
2614                                                       WEBKIT_PARAM_READABLE));
2615
2616     /**
2617     * WebKitWebView:progress:
2618     *
2619     * Determines the current progress of the load.
2620     *
2621     * Since: 1.1.7
2622     */
2623     g_object_class_install_property(objectClass, PROP_PROGRESS,
2624                                     g_param_spec_double("progress",
2625                                                         "Progress",
2626                                                         "Determines the current progress of the load",
2627                                                         0.0, 1.0, 1.0,
2628                                                         WEBKIT_PARAM_READABLE));
2629
2630     /**
2631      * WebKitWebView:icon-uri:
2632      *
2633      * The URI for the favicon for the #WebKitWebView.
2634      *
2635      * Since: 1.1.18
2636      */
2637     g_object_class_install_property(objectClass, PROP_ICON_URI,
2638                                     g_param_spec_string("icon-uri",
2639                                                         _("Icon URI"),
2640                                                         _("The URI for the favicon for the #WebKitWebView."),
2641                                                         NULL,
2642                                                         WEBKIT_PARAM_READABLE));
2643     /**
2644     * WebKitWebView:im-context:
2645     *
2646     * The GtkIMMulticontext for the #WebKitWebView.
2647     *
2648     * This is the input method context used for all text entry widgets inside
2649     * the #WebKitWebView. It can be used to generate context menu items for
2650     * controlling the active input method.
2651     *
2652     * Since: 1.1.20
2653     */
2654     g_object_class_install_property(objectClass, PROP_IM_CONTEXT,
2655                                     g_param_spec_object("im-context",
2656                                                         "IM Context",
2657                                                         "The GtkIMMultiContext for the #WebKitWebView.",
2658                                                         GTK_TYPE_IM_CONTEXT,
2659                                                         WEBKIT_PARAM_READABLE));
2660
2661     g_type_class_add_private(webViewClass, sizeof(WebKitWebViewPrivate));
2662 }
2663
2664 static void webkit_web_view_update_settings(WebKitWebView* webView)
2665 {
2666     WebKitWebViewPrivate* priv = webView->priv;
2667     WebKitWebSettings* webSettings = priv->webSettings;
2668     Settings* settings = core(webView)->settings();
2669
2670     gchar* defaultEncoding, *cursiveFontFamily, *defaultFontFamily, *fantasyFontFamily, *monospaceFontFamily, *sansSerifFontFamily, *serifFontFamily, *userStylesheetUri;
2671     gboolean autoLoadImages, autoShrinkImages, printBackgrounds,
2672         enableScripts, enablePlugins, enableDeveloperExtras, resizableTextAreas,
2673         enablePrivateBrowsing, enableCaretBrowsing, enableHTML5Database, enableHTML5LocalStorage,
2674         enableXSSAuditor, javascriptCanOpenWindows, enableOfflineWebAppCache,
2675         enableUniversalAccessFromFileURI, enableFileAccessFromFileURI,
2676         enableDOMPaste, tabKeyCyclesThroughElements,
2677         enableSiteSpecificQuirks, usePageCache, enableJavaApplet;
2678
2679     WebKitEditingBehavior editingBehavior;
2680
2681     g_object_get(webSettings,
2682                  "default-encoding", &defaultEncoding,
2683                  "cursive-font-family", &cursiveFontFamily,
2684                  "default-font-family", &defaultFontFamily,
2685                  "fantasy-font-family", &fantasyFontFamily,
2686                  "monospace-font-family", &monospaceFontFamily,
2687                  "sans-serif-font-family", &sansSerifFontFamily,
2688                  "serif-font-family", &serifFontFamily,
2689                  "auto-load-images", &autoLoadImages,
2690                  "auto-shrink-images", &autoShrinkImages,
2691                  "print-backgrounds", &printBackgrounds,
2692                  "enable-scripts", &enableScripts,
2693                  "enable-plugins", &enablePlugins,
2694                  "resizable-text-areas", &resizableTextAreas,
2695                  "user-stylesheet-uri", &userStylesheetUri,
2696                  "enable-developer-extras", &enableDeveloperExtras,
2697                  "enable-private-browsing", &enablePrivateBrowsing,
2698                  "enable-caret-browsing", &enableCaretBrowsing,
2699                  "enable-html5-database", &enableHTML5Database,
2700                  "enable-html5-local-storage", &enableHTML5LocalStorage,
2701                  "enable-xss-auditor", &enableXSSAuditor,
2702                  "javascript-can-open-windows-automatically", &javascriptCanOpenWindows,
2703                  "enable-offline-web-application-cache", &enableOfflineWebAppCache,
2704                  "editing-behavior", &editingBehavior,
2705                  "enable-universal-access-from-file-uris", &enableUniversalAccessFromFileURI,
2706                  "enable-file-access-from-file-uris", &enableFileAccessFromFileURI,
2707                  "enable-dom-paste", &enableDOMPaste,
2708                  "tab-key-cycles-through-elements", &tabKeyCyclesThroughElements,
2709                  "enable-site-specific-quirks", &enableSiteSpecificQuirks,
2710                  "enable-page-cache", &usePageCache,
2711                  "enable-java-applet", &enableJavaApplet,
2712                  NULL);
2713
2714     settings->setDefaultTextEncodingName(defaultEncoding);
2715     settings->setCursiveFontFamily(cursiveFontFamily);
2716     settings->setStandardFontFamily(defaultFontFamily);
2717     settings->setFantasyFontFamily(fantasyFontFamily);
2718     settings->setFixedFontFamily(monospaceFontFamily);
2719     settings->setSansSerifFontFamily(sansSerifFontFamily);
2720     settings->setSerifFontFamily(serifFontFamily);
2721     settings->setLoadsImagesAutomatically(autoLoadImages);
2722     settings->setShrinksStandaloneImagesToFit(autoShrinkImages);
2723     settings->setShouldPrintBackgrounds(printBackgrounds);
2724     settings->setJavaScriptEnabled(enableScripts);
2725     settings->setPluginsEnabled(enablePlugins);
2726     settings->setTextAreasAreResizable(resizableTextAreas);
2727     settings->setUserStyleSheetLocation(KURL(KURL(), userStylesheetUri));
2728     settings->setDeveloperExtrasEnabled(enableDeveloperExtras);
2729     settings->setPrivateBrowsingEnabled(enablePrivateBrowsing);
2730     settings->setCaretBrowsingEnabled(enableCaretBrowsing);
2731     settings->setDatabasesEnabled(enableHTML5Database);
2732     settings->setLocalStorageEnabled(enableHTML5LocalStorage);
2733     settings->setXSSAuditorEnabled(enableXSSAuditor);
2734     settings->setJavaScriptCanOpenWindowsAutomatically(javascriptCanOpenWindows);
2735     settings->setOfflineWebApplicationCacheEnabled(enableOfflineWebAppCache);
2736     settings->setEditingBehavior(core(editingBehavior));
2737     settings->setAllowUniversalAccessFromFileURLs(enableUniversalAccessFromFileURI);
2738     settings->setAllowFileAccessFromFileURLs(enableFileAccessFromFileURI);
2739     settings->setDOMPasteAllowed(enableDOMPaste);
2740     settings->setNeedsSiteSpecificQuirks(enableSiteSpecificQuirks);
2741     settings->setUsesPageCache(usePageCache);
2742     settings->setJavaEnabled(enableJavaApplet);
2743
2744     Page* page = core(webView);
2745     if (page)
2746         page->setTabKeyCyclesThroughElements(tabKeyCyclesThroughElements);
2747
2748     g_free(defaultEncoding);
2749     g_free(cursiveFontFamily);
2750     g_free(defaultFontFamily);
2751     g_free(fantasyFontFamily);
2752     g_free(monospaceFontFamily);
2753     g_free(sansSerifFontFamily);
2754     g_free(serifFontFamily);
2755     g_free(userStylesheetUri);
2756
2757     webkit_web_view_screen_changed(GTK_WIDGET(webView), NULL);
2758 }
2759
2760 static inline gint pixelsFromSize(WebKitWebView* webView, gint size)
2761 {
2762     gdouble DPI = webViewGetDPI(webView);
2763     return size / 72.0 * DPI;
2764 }
2765
2766 static void webkit_web_view_settings_notify(WebKitWebSettings* webSettings, GParamSpec* pspec, WebKitWebView* webView)
2767 {
2768     Settings* settings = core(webView)->settings();
2769
2770     const gchar* name = g_intern_string(pspec->name);
2771     GValue value = { 0, { { 0 } } };
2772     g_value_init(&value, pspec->value_type);
2773     g_object_get_property(G_OBJECT(webSettings), name, &value);
2774
2775     if (name == g_intern_string("default-encoding"))
2776         settings->setDefaultTextEncodingName(g_value_get_string(&value));
2777     else if (name == g_intern_string("cursive-font-family"))
2778         settings->setCursiveFontFamily(g_value_get_string(&value));
2779     else if (name == g_intern_string("default-font-family"))
2780         settings->setStandardFontFamily(g_value_get_string(&value));
2781     else if (name == g_intern_string("fantasy-font-family"))
2782         settings->setFantasyFontFamily(g_value_get_string(&value));
2783     else if (name == g_intern_string("monospace-font-family"))
2784         settings->setFixedFontFamily(g_value_get_string(&value));
2785     else if (name == g_intern_string("sans-serif-font-family"))
2786         settings->setSansSerifFontFamily(g_value_get_string(&value));
2787     else if (name == g_intern_string("serif-font-family"))
2788         settings->setSerifFontFamily(g_value_get_string(&value));
2789     else if (name == g_intern_string("default-font-size"))
2790         settings->setDefaultFontSize(pixelsFromSize(webView, g_value_get_int(&value)));
2791     else if (name == g_intern_string("default-monospace-font-size"))
2792         settings->setDefaultFixedFontSize(pixelsFromSize(webView, g_value_get_int(&value)));
2793     else if (name == g_intern_string("minimum-font-size"))
2794         settings->setMinimumFontSize(pixelsFromSize(webView, g_value_get_int(&value)));
2795     else if (name == g_intern_string("minimum-logical-font-size"))
2796         settings->setMinimumLogicalFontSize(pixelsFromSize(webView, g_value_get_int(&value)));
2797     else if (name == g_intern_string("enforce-96-dpi"))
2798         webkit_web_view_screen_changed(GTK_WIDGET(webView), NULL);
2799     else if (name == g_intern_string("auto-load-images"))
2800         settings->setLoadsImagesAutomatically(g_value_get_boolean(&value));
2801     else if (name == g_intern_string("auto-shrink-images"))
2802         settings->setShrinksStandaloneImagesToFit(g_value_get_boolean(&value));
2803     else if (name == g_intern_string("print-backgrounds"))
2804         settings->setShouldPrintBackgrounds(g_value_get_boolean(&value));
2805     else if (name == g_intern_string("enable-scripts"))
2806         settings->setJavaScriptEnabled(g_value_get_boolean(&value));
2807     else if (name == g_intern_string("enable-plugins"))
2808         settings->setPluginsEnabled(g_value_get_boolean(&value));
2809     else if (name == g_intern_string("resizable-text-areas"))
2810         settings->setTextAreasAreResizable(g_value_get_boolean(&value));
2811     else if (name == g_intern_string("user-stylesheet-uri"))
2812         settings->setUserStyleSheetLocation(KURL(KURL(), g_value_get_string(&value)));
2813     else if (name == g_intern_string("enable-developer-extras"))
2814         settings->setDeveloperExtrasEnabled(g_value_get_boolean(&value));
2815     else if (name == g_intern_string("enable-private-browsing"))
2816         settings->setPrivateBrowsingEnabled(g_value_get_boolean(&value));
2817     else if (name == g_intern_string("enable-caret-browsing"))
2818         settings->setCaretBrowsingEnabled(g_value_get_boolean(&value));
2819     else if (name == g_intern_string("enable-html5-database"))
2820         settings->setDatabasesEnabled(g_value_get_boolean(&value));
2821     else if (name == g_intern_string("enable-html5-local-storage"))
2822         settings->setLocalStorageEnabled(g_value_get_boolean(&value));
2823     else if (name == g_intern_string("enable-xss-auditor"))
2824         settings->setXSSAuditorEnabled(g_value_get_boolean(&value));
2825     else if (name == g_intern_string("javascript-can-open-windows-automatically"))
2826         settings->setJavaScriptCanOpenWindowsAutomatically(g_value_get_boolean(&value));
2827     else if (name == g_intern_string("enable-offline-web-application-cache"))
2828         settings->setOfflineWebApplicationCacheEnabled(g_value_get_boolean(&value));
2829     else if (name == g_intern_string("editing-behavior"))
2830         settings->setEditingBehavior(core(static_cast<WebKitEditingBehavior>(g_value_get_enum(&value))));
2831     else if (name == g_intern_string("enable-universal-access-from-file-uris"))
2832         settings->setAllowUniversalAccessFromFileURLs(g_value_get_boolean(&value));
2833     else if (name == g_intern_string("enable-file-access-from-file-uris"))
2834         settings->setAllowFileAccessFromFileURLs(g_value_get_boolean(&value));
2835     else if (name == g_intern_string("enable-dom-paste"))
2836         settings->setDOMPasteAllowed(g_value_get_boolean(&value));
2837     else if (name == g_intern_string("tab-key-cycles-through-elements")) {
2838         Page* page = core(webView);
2839         if (page)
2840             page->setTabKeyCyclesThroughElements(g_value_get_boolean(&value));
2841     } else if (name == g_intern_string("enable-site-specific-quirks"))
2842         settings->setNeedsSiteSpecificQuirks(g_value_get_boolean(&value));
2843     else if (name == g_intern_string("enable-page-cache"))
2844         settings->setUsesPageCache(g_value_get_boolean(&value));
2845     else if (name == g_intern_string("enable-java-applet"))
2846         settings->setJavaEnabled(g_value_get_boolean(&value));
2847     else if (!g_object_class_find_property(G_OBJECT_GET_CLASS(webSettings), name))
2848         g_warning("Unexpected setting '%s'", name);
2849     g_value_unset(&value);
2850 }
2851
2852 static void webkit_web_view_init(WebKitWebView* webView)
2853 {
2854     WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(webView);
2855     webView->priv = priv;
2856
2857     priv->imContext = gtk_im_multicontext_new();
2858
2859     WebKit::InspectorClient* inspectorClient = new WebKit::InspectorClient(webView);
2860     priv->corePage = new Page(new WebKit::ChromeClient(webView), new WebKit::ContextMenuClient(webView), new WebKit::EditorClient(webView), new WebKit::DragClient(webView), inspectorClient, 0, 0);
2861
2862     // We also add a simple wrapper class to provide the public
2863     // interface for the Web Inspector.
2864     priv->webInspector = WEBKIT_WEB_INSPECTOR(g_object_new(WEBKIT_TYPE_WEB_INSPECTOR, NULL));
2865     webkit_web_inspector_set_inspector_client(priv->webInspector, priv->corePage);
2866
2867     priv->horizontalAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2868     priv->verticalAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2869
2870     g_object_ref_sink(priv->horizontalAdjustment);
2871     g_object_ref_sink(priv->verticalAdjustment);
2872
2873     GTK_WIDGET_SET_FLAGS(webView, GTK_CAN_FOCUS);
2874     priv->mainFrame = WEBKIT_WEB_FRAME(webkit_web_frame_new(webView));
2875     priv->lastPopupXPosition = priv->lastPopupYPosition = -1;
2876     priv->editable = false;
2877
2878     priv->backForwardList = webkit_web_back_forward_list_new_with_web_view(webView);
2879
2880     priv->zoomFullContent = FALSE;
2881
2882     priv->webSettings = webkit_web_settings_new();
2883     webkit_web_view_update_settings(webView);
2884     g_signal_connect(priv->webSettings, "notify", G_CALLBACK(webkit_web_view_settings_notify), webView);
2885
2886     priv->webWindowFeatures = webkit_web_window_features_new();
2887
2888     priv->subResources = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
2889
2890     priv->tooltipText = 0;
2891 }
2892
2893 GtkWidget* webkit_web_view_new(void)
2894 {
2895     WebKitWebView* webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, NULL));
2896
2897     return GTK_WIDGET(webView);
2898 }
2899
2900 // for internal use only
2901 void webkit_web_view_notify_ready(WebKitWebView* webView)
2902 {
2903     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2904
2905     gboolean isHandled = FALSE;
2906     g_signal_emit(webView, webkit_web_view_signals[WEB_VIEW_READY], 0, &isHandled);
2907 }
2908
2909 void webkit_web_view_request_download(WebKitWebView* webView, WebKitNetworkRequest* request, const ResourceResponse& response, ResourceHandle* handle)
2910 {
2911     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2912
2913     WebKitDownload* download;
2914
2915     if (handle)
2916         download = webkit_download_new_with_handle(request, handle, response);
2917     else
2918         download = webkit_download_new(request);
2919
2920     gboolean handled;
2921     g_signal_emit(webView, webkit_web_view_signals[DOWNLOAD_REQUESTED], 0, download, &handled);
2922
2923     if (!handled) {
2924         webkit_download_cancel(download);
2925         g_object_unref(download);
2926         return;
2927     }
2928
2929     /* Start the download now if it has a destination URI, otherwise it
2930         may be handled asynchronously by the application. */
2931     if (webkit_download_get_destination_uri(download))
2932         webkit_download_start(download);
2933 }
2934
2935 bool webkit_web_view_use_primary_for_paste(WebKitWebView* webView)
2936 {
2937     return webView->priv->usePrimaryForPaste;
2938 }
2939
2940 void webkit_web_view_set_settings(WebKitWebView* webView, WebKitWebSettings* webSettings)
2941 {
2942     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2943     g_return_if_fail(WEBKIT_IS_WEB_SETTINGS(webSettings));
2944
2945     WebKitWebViewPrivate* priv = webView->priv;
2946     g_signal_handlers_disconnect_by_func(priv->webSettings, (gpointer)webkit_web_view_settings_notify, webView);
2947     g_object_unref(priv->webSettings);
2948     g_object_ref(webSettings);
2949     priv->webSettings = webSettings;
2950     webkit_web_view_update_settings(webView);
2951     g_signal_connect(webSettings, "notify", G_CALLBACK(webkit_web_view_settings_notify), webView);
2952     g_object_notify(G_OBJECT(webView), "settings");
2953 }
2954
2955 WebKitWebSettings* webkit_web_view_get_settings(WebKitWebView* webView)
2956 {
2957     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2958
2959     WebKitWebViewPrivate* priv = webView->priv;
2960     return priv->webSettings;
2961 }
2962
2963 /**
2964  * webkit_web_view_get_inspector:
2965  * @web_view: a #WebKitWebView
2966  *
2967  * Obtains the #WebKitWebInspector associated with the
2968  * #WebKitWebView. Every #WebKitWebView object has a
2969  * #WebKitWebInspector object attached to it as soon as it is created,
2970  * so this function will only return NULL if the argument is not a
2971  * valid #WebKitWebView.
2972  *
2973  * Returns: the #WebKitWebInspector instance associated with the
2974  * #WebKitWebView; %NULL is only returned if the argument is not a
2975  * valid #WebKitWebView.
2976  *
2977  * Since: 1.0.3
2978  */
2979 WebKitWebInspector* webkit_web_view_get_inspector(WebKitWebView* webView)
2980 {
2981     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2982
2983     WebKitWebViewPrivate* priv = webView->priv;
2984     return priv->webInspector;
2985 }
2986
2987 // internal
2988 static void webkit_web_view_set_window_features(WebKitWebView* webView, WebKitWebWindowFeatures* webWindowFeatures)
2989 {
2990     WebKitWebViewPrivate* priv = webView->priv;
2991
2992     if(webkit_web_window_features_equal(priv->webWindowFeatures, webWindowFeatures))
2993       return;
2994
2995     g_object_unref(priv->webWindowFeatures);
2996     g_object_ref(webWindowFeatures);
2997     priv->webWindowFeatures = webWindowFeatures;
2998 }
2999
3000 /**
3001  * webkit_web_view_get_window_features
3002  * @web_view: a #WebKitWebView
3003  *
3004  * Returns the instance of #WebKitWebWindowFeatures held by the given
3005  * #WebKitWebView.
3006  *
3007  * Return value: the #WebKitWebWindowFeatures
3008  *
3009  * Since: 1.0.3
3010  */
3011 WebKitWebWindowFeatures* webkit_web_view_get_window_features(WebKitWebView* webView)
3012 {
3013     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
3014
3015     WebKitWebViewPrivate* priv = webView->priv;
3016     return priv->webWindowFeatures;
3017 }
3018
3019 /**
3020  * webkit_web_view_get_title:
3021  * @web_view: a #WebKitWebView
3022  *
3023  * Returns the @web_view's document title
3024  *
3025  * Since: 1.1.4
3026  *
3027  * Return value: the title of @web_view
3028  */
3029 G_CONST_RETURN gchar* webkit_web_view_get_title(WebKitWebView* webView)
3030 {
3031     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
3032
3033     WebKitWebViewPrivate* priv = webView->priv;
3034     return priv->mainFrame->priv->title;
3035 }
3036
3037 /**
3038  * webkit_web_view_get_uri:
3039  * @web_view: a #WebKitWebView
3040  *
3041  * Returns the current URI of the contents displayed by the @web_view
3042  *
3043  * Since: 1.1.4
3044  *
3045  * Return value: the URI of @web_view
3046  */
3047 G_CONST_RETURN gchar* webkit_web_view_get_uri(WebKitWebView* webView)
3048 {
3049     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
3050
3051     WebKitWebViewPrivate* priv = webView->priv;
3052     return priv->mainFrame->priv->uri;
3053 }
3054
3055 /**
3056  * webkit_web_view_set_maintains_back_forward_list:
3057  * @web_view: a #WebKitWebView
3058  * @flag: to tell the view to maintain a back or forward list
3059  *
3060  * Set the view to maintain a back or forward list of history items.
3061  */
3062 void webkit_web_view_set_maintains_back_forward_list(WebKitWebView* webView, gboolean flag)
3063 {
3064     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
3065
3066     core(webView)->backForwardList()->setEnabled(flag);
3067 }
3068
3069 /**
3070  * webkit_web_view_get_back_forward_list:
3071  * @web_view: a #WebKitWebView
3072  *
3073  * Returns a #WebKitWebBackForwardList
3074  *
3075  * Return value: the #WebKitWebBackForwardList
3076  */
3077 WebKitWebBackForwardList* webkit_web_view_get_back_forward_list(WebKitWebView* webView)
3078 {
3079     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
3080
3081     WebKitWebViewPrivate* priv = webView->priv;
3082
3083     if (!core(webView) || !core(webView)->backForwardList()->enabled())
3084         return NULL;
3085
3086     return priv->backForwardList;
3087 }
3088
3089 /**
3090  * webkit_web_view_go_to_back_forward_item:
3091  * @web_view: a #WebKitWebView
3092  * @item: a #WebKitWebHistoryItem*
3093  *
3094  * Go to the specified #WebKitWebHistoryItem
3095  *
3096  * Return value: %TRUE if loading of item is successful, %FALSE if not
3097  */
3098 gboolean webkit_web_view_go_to_back_forward_item(WebKitWebView* webView, WebKitWebHistoryItem* item)
3099 {
3100     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
3101     g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(item), FALSE);
3102
3103     WebKitWebBackForwardList* backForwardList = webkit_web_view_get_back_forward_list(webView);
3104     if (!webkit_web_back_forward_list_contains_item(backForwardList, item))
3105         return FALSE;
3106
3107     core(webView)->goToItem(core(item), FrameLoadTypeIndexedBackForward);
3108     return TRUE;
3109 }
3110
3111 /**
3112  * webkit_web_view_go_back:
3113  * @web_view: a #WebKitWebView
3114  *
3115  * Loads the previous history item.
3116  */
3117 void webkit_web_view_go_back(WebKitWebView* webView)
3118 {
3119     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
3120
3121     core(webView)->goBack();
3122 }
3123
3124 /**
3125  * webkit_web_view_go_back_or_forward:
3126  * @web_view: a #WebKitWebView
3127  * @steps: the number of steps
3128  *
3129  * Loads the history item that is the number of @steps away from the current
3130  * item. Negative values represent steps backward while positive values
3131  * represent steps forward.
3132  */
3133 void webkit_web_view_go_back_or_forward(WebKitWebView* webView, gint steps)
3134 {
3135     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
3136
3137     core(webView)->goBackOrForward(steps);
3138 }
3139
3140 /**
3141  * webkit_web_view_go_forward:
3142  * @web_view: a #WebKitWebView
3143  *
3144  * Loads the next history item.
3145  */
3146 void webkit_web_view_go_forward(WebKitWebView* webView)
3147 {
3148     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
3149
3150     core(webView)->goForward();
3151 }
3152
3153 /**
3154  * webkit_web_view_can_go_back:
3155  * @web_view: a #WebKitWebView
3156  *
3157  * Determines whether #web_view has a previous history item.
3158  *
3159  * Return value: %TRUE if able to move back, %FALSE otherwise
3160  */
3161 gboolean webkit_web_view_can_go_back(WebKitWebView* webView)
3162 {
3163     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
3164
3165     if (!core(webView) || !core(webView)->backForwardList()->backItem())
3166         return FALSE;
3167
3168     return TRUE;
3169 }
3170
3171 /**
3172  * webkit_web_view_can_go_back_or_forward:
3173  * @web_view: a #WebKitWebView
3174  * @steps: the number of steps
3175  *
3176  * Determines whether #web_view has a history item of @steps. Negative values
3177  * represent steps backward while positive values represent steps forward.
3178  *
3179  * Return value: %TRUE if able to move back or forward the given number of
3180  * steps, %FALSE otherwise
3181  */
3182 gboolean webkit_web_view_can_go_back_or_forward(WebKitWebView* webView, gint steps)
3183 {
3184     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
3185
3186     return core(webView)->canGoBackOrForward(steps);
3187 }
3188
3189 /**
3190  * webkit_web_view_can_go_forward:
3191  * @web_view: a #WebKitWebView
3192  *
3193  * Determines whether #web_view has a next history item.
3194  *
3195  * Return value: %TRUE if able to move forward, %FALSE otherwise
3196  */
3197 gboolean webkit_web_view_can_go_forward(WebKitWebView* webView)
3198 {
3199     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
3200
3201     Page* page = core(webView);
3202
3203     if (!page)
3204         return FALSE;
3205
3206     if (!page->backForwardList()->forwardItem())
3207         return FALSE;
3208
3209     return TRUE;
3210 }
3211
3212 /**
3213  * webkit_web_view_open:
3214  * @web_view: a #WebKitWebView
3215  * @uri: an URI
3216  *
3217  * Requests loading of the specified URI string.
3218  *
3219  * Deprecated: 1.1.1: Use webkit_web_view_load_uri() instead.
3220   */
3221 void webkit_web_view_open(WebKitWebView* webView, const gchar* uri)
3222 {
3223     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
3224     g_return_if_fail(uri);
3225
3226     // We used to support local paths, unlike the newer
3227     // function webkit_web_view_load_uri
3228     if (g_path_is_absolute(uri)) {
3229         gchar* fileUri = g_filename_to_uri(uri, NULL, NULL);
3230         webkit_web_view_load_uri(webView, fileUri);
3231         g_free(fileUri);
3232     }
3233     else
3234         webkit_web_view_load_uri(webView, uri);
3235 }
3236
3237 void webkit_web_view_reload(WebKitWebView* webView)
3238 {
3239     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
3240
3241     core(webView)->mainFrame()->loader()->reload();
3242 }
3243
3244 /**
3245  * webkit_web_view_reload_bypass_cache:
3246  * @web_view: a #WebKitWebView
3247  *
3248  * Reloads the @web_view without using any cached data.
3249  *
3250  * Since: 1.0.3
3251  */
3252 void webkit_web_view_reload_bypass_cache(WebKitWebView* webView)
3253 {
3254     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
3255
3256     core(webView)->mainFrame()->loader()->reload(true);
3257 }
3258
3259 /**
3260  * webkit_web_view_load_uri:
3261  * @web_view: a #WebKitWebView
3262  * @uri: an URI string
3263  *
3264  * Requests loading of the specified URI string.
3265  *
3266  * Since: 1.1.1
3267  */
3268 void webkit_web_view_load_uri(WebKitWebView* webView, const gchar* uri)
3269 {
3270     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
3271     g_return_if_fail(uri);
3272
3273     WebKitWebFrame* frame = webView->priv->mainFrame;
3274     webkit_web_frame_load_uri(frame, uri);
3275 }
3276
3277 /**
3278 +  * webkit_web_view_load_string:
3279 +  * @web_view: a #WebKitWebView
3280 +  * @content: an URI string
3281 +  * @mime_type: the MIME type, or %NULL
3282 +  * @encoding: the encoding, or %NULL
3283 +  * @base_uri: the base URI for relative locations
3284 +  *
3285 +  * Requests loading of the given @content with the specified @mime_type,
3286 +  * @encoding and @base_uri.
3287 +  *
3288 +  * If @mime_type is %NULL, "text/html" is assumed.
3289 +  *
3290 +  * If @encoding is %NULL, "UTF-8" is assumed.
3291 +  */
3292 void webkit_web_view_load_string(WebKitWebView* webView, const gchar* content, const gchar* mimeType, const gchar* encoding, const gchar* baseUri)
3293 {
3294     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
3295     g_return_if_fail(content);
3296
3297     WebKitWebFrame* frame = webView->priv->mainFrame;
3298     webkit_web_frame_load_string(frame, content, mimeType, encoding, baseUri);
3299 }
3300 /**
3301  * webkit_web_view_load_html_string:
3302  * @web_view: a #WebKitWebView
3303  * @content: an URI string
3304  * @base_uri: the base URI for relative locations
3305  *
3306  * Requests loading of the given @content with the specified @base_uri.
3307  *
3308  * Deprecated: 1.1.1: Use webkit_web_view_load_string() instead.
3309  */
3310 void webkit_web_view_load_html_string(WebKitWebView* webView, const gchar* content, const gchar* baseUri)
3311 {
3312     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
3313     g_return_if_fail(content);
3314
3315     webkit_web_view_load_string(webView, content, NULL, NULL, baseUri);
3316 }
3317
3318 /**
3319  * webkit_web_view_load_request:
3320  * @web_view: a #WebKitWebView
3321  * @request: a #WebKitNetworkRequest
3322  *
3323  * Requests loading of the specified asynchronous client request.
3324  *
3325  * Creates a provisional data source that will transition to a committed data
3326  * source once any data has been received. Use webkit_web_view_stop_loading() to
3327  * stop the load.
3328  *
3329  * Since: 1.1.1
3330  */
3331 void webkit_web_view_load_request(WebKitWebView* webView, WebKitNetworkRequest* request)
3332 {
3333     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
3334     g_return_if_fail(WEBKIT_IS_NETWORK_REQUEST(request));
3335
3336     WebKitWebFrame* frame = webView->priv->mainFrame;
3337     webkit_web_frame_load_request(frame, request);
3338 }
3339
3340 /**
3341  * webkit_web_view_stop_loading:
3342  * @webView: a #WebKitWebView
3343  * 
3344  * Stops any ongoing load in the @webView.
3345  **/
3346 void webkit_web_view_stop_loading(WebKitWebView* webView)
3347 {
3348     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
3349
3350     Frame* frame = core(webView)->mainFrame();
3351
3352     if (FrameLoader* loader = frame->loader())
3353         loader->stopForUserCancel();
3354 }
3355
3356 /**
3357  * webkit_web_view_search_text:
3358  * @web_view: a #WebKitWebView
3359  * @text: a string to look for
3360  * @forward: whether to find forward or not
3361  * @case_sensitive: whether to respect the case of text
3362  * @wrap: whether to continue looking at the beginning after reaching the end
3363  *
3364  * Looks for a specified string inside #web_view.
3365  *
3366  * Return value: %TRUE on success or %FALSE on failure
3367  */
3368 gboolean webkit_web_view_search_text(WebKitWebView* webView, const gchar* string, gboolean caseSensitive, gboolean forward, gboolean shouldWrap)
3369 {
3370     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
3371     g_return_val_if_fail(string, FALSE);
3372
3373     TextCaseSensitivity caseSensitivity = caseSensitive ? TextCaseSensitive : TextCaseInsensitive;
3374     FindDirection direction = forward ? FindDirectionForward : FindDirectionBackward;
3375
3376     return core(webView)->findString(String::fromUTF8(string), caseSensitivity, direction, shouldWrap);
3377 }
3378
3379 /**
3380  * webkit_web_view_mark_text_matches:
3381  * @web_view: a #WebKitWebView
3382  * @string: a string to look for
3383  * @case_sensitive: whether to respect the case of text
3384  * @limit: the maximum number of strings to look for or %0 for all
3385  *
3386  * Attempts to highlight all occurances of #string inside #web_view.
3387  *
3388  * Return value: the number of strings highlighted
3389  */
3390 guint webkit_web_view_mark_text_matches(WebKitWebView* webView, const gchar* string, gboolean caseSensitive, guint limit)
3391 {
3392     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
3393     g_return_val_if_fail(string, 0);
3394
3395     TextCaseSensitivity caseSensitivity = caseSensitive ? TextCaseSensitive : TextCaseInsensitive;
3396