4cc608baaf59c11b49e76f94472f5fac5c2ede8b
[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 Collabora Ltd.
10  *  Copyright (C) 2009 Igalia S.L.
11  *
12  *  This library is free software; you can redistribute it and/or
13  *  modify it under the terms of the GNU Lesser General Public
14  *  License as published by the Free Software Foundation; either
15  *  version 2 of the License, or (at your option) any later version.
16  *
17  *  This library is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  *  Lesser General Public License for more details.
21  *
22  *  You should have received a copy of the GNU Lesser General Public
23  *  License along with this library; if not, write to the Free Software
24  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
25  */
26
27 #include "config.h"
28
29 #include "webkitdownload.h"
30 #include "webkitwebview.h"
31 #include "webkitenumtypes.h"
32 #include "webkitmarshal.h"
33 #include "webkitprivate.h"
34 #include "webkitwebinspector.h"
35 #include "webkitwebbackforwardlist.h"
36 #include "webkitwebhistoryitem.h"
37
38 #include "AXObjectCache.h"
39 #include "NotImplemented.h"
40 #include "BackForwardList.h"
41 #include "CString.h"
42 #include "ChromeClientGtk.h"
43 #include "ContextMenu.h"
44 #include "ContextMenuClientGtk.h"
45 #include "ContextMenuController.h"
46 #include "Cursor.h"
47 #include "Document.h"
48 #include "DocumentLoader.h"
49 #include "DragClientGtk.h"
50 #include "Editor.h"
51 #include "EditorClientGtk.h"
52 #include "EventHandler.h"
53 #include "FloatQuad.h"
54 #include "FocusController.h"
55 #include "FrameLoaderTypes.h"
56 #include "HitTestRequest.h"
57 #include "HitTestResult.h"
58 #include "GraphicsContext.h"
59 #include "InspectorClientGtk.h"
60 #include "FrameLoader.h"
61 #include "FrameView.h"
62 #include "PasteboardHelper.h"
63 #include "PlatformKeyboardEvent.h"
64 #include "PlatformWheelEvent.h"
65 #include "ResourceHandle.h"
66 #include "ScriptValue.h"
67 #include "Scrollbar.h"
68 #include <wtf/GOwnPtr.h>
69
70 #include <gdk/gdkkeysyms.h>
71
72 /**
73  * SECTION:webkitwebview
74  * @short_description: The central class of the WebKit/Gtk+ API
75  * @see_also: #WebKitWebSettings, #WebKitWebFrame
76  *
77  * #WebKitWebView is the central class of the WebKit/Gtk+ API. It is a
78  * #GtkWidget implementing the scrolling interface which means you can
79  * embed in a #GtkScrolledWindow. It is responsible for managing the
80  * drawing of the content, forwarding of events. You can load any URI
81  * into the #WebKitWebView or any kind of data string. With #WebKitWebSettings
82  * you can control various aspects of the rendering and loading of the content.
83  * Each #WebKitWebView has exactly one #WebKitWebFrame as main frame. A
84  * #WebKitWebFrame can have n children.
85  *
86  * <programlisting>
87  * /<!-- -->* Create the widgets *<!-- -->/
88  * GtkWidget *main_window = gtk_window_new (GTK_WIDGET_TOPLEVEL);
89  * GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
90  * GtkWidget *web_view = webkit_web_view_new ();
91  *
92  * /<!-- -->* Place the WebKitWebView in the GtkScrolledWindow *<!-- -->/
93  * gtk_container_add (GTK_CONTAINER (scrolled_window), web_view);
94  * gtk_container_add (GTK_CONTAINER (main_window), scrolled_window);
95  *
96  * /<!-- -->* Open a webpage *<!-- -->/
97  * webkit_web_view_open (WEBKIT_WEB_VIEW (web_view), "http://www.gnome.org");
98  *
99  * /<!-- -->* Show the result *<!-- -->/
100  * gtk_window_set_default_size (GTK_WINDOW (main_window), 800, 600);
101  * gtk_widget_show_all (main_window);
102  * </programlisting>
103  */
104
105 static const double defaultDPI = 96.0;
106
107 using namespace WebKit;
108 using namespace WebCore;
109
110 extern "C" {
111
112 enum {
113     /* normal signals */
114     NAVIGATION_REQUESTED,
115     NAVIGATION_POLICY_DECISION_REQUESTED,
116     MIME_TYPE_POLICY_DECISION_REQUESTED,
117     CREATE_WEB_VIEW,
118     WEB_VIEW_READY,
119     WINDOW_OBJECT_CLEARED,
120     LOAD_STARTED,
121     LOAD_COMMITTED,
122     LOAD_PROGRESS_CHANGED,
123     LOAD_FINISHED,
124     TITLE_CHANGED,
125     HOVERING_OVER_LINK,
126     POPULATE_POPUP,
127     STATUS_BAR_TEXT_CHANGED,
128     ICOND_LOADED,
129     SELECTION_CHANGED,
130     CONSOLE_MESSAGE,
131     SCRIPT_ALERT,
132     SCRIPT_CONFIRM,
133     SCRIPT_PROMPT,
134     SELECT_ALL,
135     COPY_CLIPBOARD,
136     PASTE_CLIPBOARD,
137     CUT_CLIPBOARD,
138     DOWNLOAD_REQUESTED,
139     LAST_SIGNAL
140 };
141
142 enum {
143     PROP_0,
144
145     PROP_COPY_TARGET_LIST,
146     PROP_PASTE_TARGET_LIST,
147     PROP_EDITABLE,
148     PROP_SETTINGS,
149     PROP_WEB_INSPECTOR,
150     PROP_WINDOW_FEATURES,
151     PROP_TRANSPARENT,
152     PROP_ZOOM_LEVEL,
153     PROP_FULL_CONTENT_ZOOM,
154     PROP_ENCODING,
155     PROP_CUSTOM_ENCODING
156 };
157
158 static guint webkit_web_view_signals[LAST_SIGNAL] = { 0, };
159
160 G_DEFINE_TYPE(WebKitWebView, webkit_web_view, GTK_TYPE_CONTAINER)
161
162 static void webkit_web_view_settings_notify(WebKitWebSettings* webSettings, GParamSpec* pspec, WebKitWebView* webView);
163 static void webkit_web_view_set_window_features(WebKitWebView* webView, WebKitWebWindowFeatures* webWindowFeatures);
164
165 static void webkit_web_view_context_menu_position_func(GtkMenu*, gint* x, gint* y, gboolean* pushIn, WebKitWebViewPrivate* data)
166 {
167     *pushIn = FALSE;
168     *x = data->lastPopupXPosition;
169     *y = data->lastPopupYPosition;
170 }
171
172 static gboolean webkit_web_view_forward_context_menu_event(WebKitWebView* webView, const PlatformMouseEvent& event)
173 {
174     Page* page = core(webView);
175     page->contextMenuController()->clearContextMenu();
176     Frame* focusedFrame = page->focusController()->focusedOrMainFrame();
177
178     if (!focusedFrame->view())
179         return FALSE;
180
181     focusedFrame->view()->setCursor(pointerCursor());
182     bool handledEvent = focusedFrame->eventHandler()->sendContextMenuEvent(event);
183     if (!handledEvent)
184         return FALSE;
185
186     ContextMenu* coreMenu = page->contextMenuController()->contextMenu();
187     if (!coreMenu)
188         return FALSE;
189
190     GtkMenu* menu = GTK_MENU(coreMenu->platformDescription());
191     if (!menu)
192         return FALSE;
193
194     g_signal_emit(webView, webkit_web_view_signals[POPULATE_POPUP], 0, menu);
195
196     GList* items = gtk_container_get_children(GTK_CONTAINER(menu));
197     bool empty = !g_list_nth(items, 0);
198     g_list_free(items);
199     if (empty)
200         return FALSE;
201
202     WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(webView);
203     priv->lastPopupXPosition = event.globalX();
204     priv->lastPopupYPosition = event.globalY();
205     gtk_menu_popup(menu, NULL, NULL,
206                    reinterpret_cast<GtkMenuPositionFunc>(webkit_web_view_context_menu_position_func),
207                    priv, event.button() + 1, gtk_get_current_event_time());
208     return TRUE;
209 }
210
211 static gboolean webkit_web_view_popup_menu_handler(GtkWidget* widget)
212 {
213     static const int contextMenuMargin = 1;
214
215     // The context menu event was generated from the keyboard, so show the context menu by the current selection.
216     Page* page = core(WEBKIT_WEB_VIEW(widget));
217     FrameView* view = page->mainFrame()->view();
218     if (!view)
219         return FALSE;    
220
221     Position start = page->mainFrame()->selection()->selection().start();
222     Position end = page->mainFrame()->selection()->selection().end();
223
224     int rightAligned = FALSE;
225     IntPoint location;
226
227     if (!start.node() || !end.node())
228         location = IntPoint(rightAligned ? view->contentsWidth() - contextMenuMargin : contextMenuMargin, contextMenuMargin);
229     else {
230         RenderObject* renderer = start.node()->renderer();
231         if (!renderer)
232             return FALSE;
233
234         // Calculate the rect of the first line of the selection (cribbed from -[WebCoreFrameBridge firstRectForDOMRange:],
235         // now Frame::firstRectForRange(), which perhaps this should call).
236         int extraWidthToEndOfLine = 0;
237
238         InlineBox* startInlineBox;
239         int startCaretOffset;
240         start.getInlineBoxAndOffset(DOWNSTREAM, startInlineBox, startCaretOffset);
241         IntRect startCaretRect = renderer->localCaretRect(startInlineBox, startCaretOffset, &extraWidthToEndOfLine);
242         if (startCaretRect != IntRect())
243             startCaretRect = renderer->localToAbsoluteQuad(FloatRect(startCaretRect)).enclosingBoundingBox();
244
245         InlineBox* endInlineBox;
246         int endCaretOffset;
247         end.getInlineBoxAndOffset(UPSTREAM, endInlineBox, endCaretOffset);
248         IntRect endCaretRect = renderer->localCaretRect(endInlineBox, endCaretOffset);
249         if (endCaretRect != IntRect())
250             endCaretRect = renderer->localToAbsoluteQuad(FloatRect(endCaretRect)).enclosingBoundingBox();
251
252         IntRect firstRect;
253         if (startCaretRect.y() == endCaretRect.y())
254             firstRect = IntRect(MIN(startCaretRect.x(), endCaretRect.x()),
255                                 startCaretRect.y(),
256                                 abs(endCaretRect.x() - startCaretRect.x()),
257                                 MAX(startCaretRect.height(), endCaretRect.height()));
258         else
259             firstRect = IntRect(startCaretRect.x(),
260                                 startCaretRect.y(),
261                                 startCaretRect.width() + extraWidthToEndOfLine,
262                                 startCaretRect.height());
263
264         location = IntPoint(rightAligned ? firstRect.right() : firstRect.x(), firstRect.bottom());
265     }
266
267     int x, y;
268     gdk_window_get_origin(GTK_WIDGET(view->hostWindow()->platformWindow())->window, &x, &y);
269
270     // FIXME: The IntSize(0, -1) is a hack to get the hit-testing to result in the selected element.
271     // Ideally we'd have the position of a context menu event be separate from its target node.
272     location = view->contentsToWindow(location) + IntSize(0, -1);
273     IntPoint global = location + IntSize(x, y);
274     PlatformMouseEvent event(location, global, NoButton, MouseEventPressed, 0, false, false, false, false, gtk_get_current_event_time());
275
276     return webkit_web_view_forward_context_menu_event(WEBKIT_WEB_VIEW(widget), event);
277 }
278
279 static void webkit_web_view_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
280 {
281     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
282
283     switch(prop_id) {
284 #if GTK_CHECK_VERSION(2,10,0)
285     case PROP_COPY_TARGET_LIST:
286         g_value_set_boxed(value, webkit_web_view_get_copy_target_list(webView));
287         break;
288     case PROP_PASTE_TARGET_LIST:
289         g_value_set_boxed(value, webkit_web_view_get_paste_target_list(webView));
290         break;
291 #endif
292     case PROP_EDITABLE:
293         g_value_set_boolean(value, webkit_web_view_get_editable(webView));
294         break;
295     case PROP_SETTINGS:
296         g_value_set_object(value, webkit_web_view_get_settings(webView));
297         break;
298     case PROP_WEB_INSPECTOR:
299         g_value_set_object(value, webkit_web_view_get_inspector(webView));
300         break;
301     case PROP_WINDOW_FEATURES:
302         g_value_set_object(value, webkit_web_view_get_window_features(webView));
303         break;
304     case PROP_TRANSPARENT:
305         g_value_set_boolean(value, webkit_web_view_get_transparent(webView));
306         break;
307     case PROP_ZOOM_LEVEL:
308         g_value_set_float(value, webkit_web_view_get_zoom_level(webView));
309         break;
310     case PROP_FULL_CONTENT_ZOOM:
311         g_value_set_boolean(value, webkit_web_view_get_full_content_zoom(webView));
312         break;
313     case PROP_ENCODING:
314         g_value_set_string(value, webkit_web_view_get_encoding(webView));
315         break;
316     case PROP_CUSTOM_ENCODING:
317         g_value_set_string(value, webkit_web_view_get_custom_encoding(webView));
318         break;
319     default:
320         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
321     }
322 }
323
324 static void webkit_web_view_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec *pspec)
325 {
326     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
327
328     switch(prop_id) {
329     case PROP_EDITABLE:
330         webkit_web_view_set_editable(webView, g_value_get_boolean(value));
331         break;
332     case PROP_SETTINGS:
333         webkit_web_view_set_settings(webView, WEBKIT_WEB_SETTINGS(g_value_get_object(value)));
334         break;
335     case PROP_WINDOW_FEATURES:
336         webkit_web_view_set_window_features(webView, WEBKIT_WEB_WINDOW_FEATURES(g_value_get_object(value)));
337         break;
338     case PROP_TRANSPARENT:
339         webkit_web_view_set_transparent(webView, g_value_get_boolean(value));
340         break;
341     case PROP_ZOOM_LEVEL:
342         webkit_web_view_set_zoom_level(webView, g_value_get_float(value));
343         break;
344     case PROP_FULL_CONTENT_ZOOM:
345         webkit_web_view_set_full_content_zoom(webView, g_value_get_boolean(value));
346         break;
347     case PROP_CUSTOM_ENCODING:
348         webkit_web_view_set_custom_encoding(webView, g_value_get_string(value));
349         break;
350     default:
351         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
352     }
353 }
354
355 static bool shouldCoalesce(GdkRectangle rect, GdkRectangle* rects, int count)
356 {
357     const int cRectThreshold = 10;
358     const float cWastedSpaceThreshold = 0.75f;
359     bool useUnionedRect = (count <= 1) || (count > cRectThreshold);
360     if (!useUnionedRect) {
361         // Attempt to guess whether or not we should use the unioned rect or the individual rects.
362         // We do this by computing the percentage of "wasted space" in the union.  If that wasted space
363         // is too large, then we will do individual rect painting instead.
364         float unionPixels = (rect.width * rect.height);
365         float singlePixels = 0;
366         for (int i = 0; i < count; ++i)
367             singlePixels += rects[i].width * rects[i].height;
368         float wastedSpace = 1 - (singlePixels / unionPixels);
369         if (wastedSpace <= cWastedSpaceThreshold)
370             useUnionedRect = true;
371     }
372     return useUnionedRect;
373 }
374
375 static gboolean webkit_web_view_expose_event(GtkWidget* widget, GdkEventExpose* event)
376 {
377     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
378     WebKitWebViewPrivate* priv = webView->priv;
379
380     Frame* frame = core(webView)->mainFrame();
381     if (frame->contentRenderer() && frame->view()) {
382         frame->view()->layoutIfNeededRecursive();
383
384         cairo_t* cr = gdk_cairo_create(event->window);
385         GraphicsContext ctx(cr);
386         cairo_destroy(cr);
387         ctx.setGdkExposeEvent(event);
388
389         GOwnPtr<GdkRectangle> rects;
390         int rectCount;
391         gdk_region_get_rectangles(event->region, &rects.outPtr(), &rectCount);
392
393         // Avoid recursing into the render tree excessively
394         bool coalesce = shouldCoalesce(event->area, rects.get(), rectCount);
395
396         if (coalesce) {
397             IntRect rect = event->area;
398             ctx.clip(rect);
399             if (priv->transparent)
400                 ctx.clearRect(rect);
401             frame->view()->paint(&ctx, rect);
402         } else {
403             for (int i = 0; i < rectCount; i++) {
404                 IntRect rect = rects.get()[i];
405                 ctx.save();
406                 ctx.clip(rect);
407                 if (priv->transparent)
408                     ctx.clearRect(rect);
409                 frame->view()->paint(&ctx, rect);
410                 ctx.restore();
411             }
412         }
413     }
414
415     return FALSE;
416 }
417
418 static gboolean webkit_web_view_key_press_event(GtkWidget* widget, GdkEventKey* event)
419 {
420     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
421
422     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
423     PlatformKeyboardEvent keyboardEvent(event);
424
425     if (!frame->view())
426         return FALSE;
427
428     if (frame->eventHandler()->keyEvent(keyboardEvent))
429         return TRUE;
430
431     FrameView* view = frame->view();
432     SelectionController::EAlteration alteration;
433     if (event->state & GDK_SHIFT_MASK)
434         alteration = SelectionController::EXTEND;
435     else
436         alteration = SelectionController::MOVE;
437
438     // TODO: We probably want to use GTK+ key bindings here and perhaps take an
439     // approach more like the Win and Mac ports for key handling.
440     switch (event->keyval) {
441     case GDK_Down:
442         view->scrollBy(IntSize(0, cScrollbarPixelsPerLineStep));
443         return TRUE;
444     case GDK_Up:
445         view->scrollBy(IntSize(0, -cScrollbarPixelsPerLineStep));
446         return TRUE;
447     case GDK_Right:
448         view->scrollBy(IntSize(cScrollbarPixelsPerLineStep, 0));
449         return TRUE;
450     case GDK_Left:
451         view->scrollBy(IntSize(-cScrollbarPixelsPerLineStep, 0));
452         return TRUE;
453     case GDK_space:
454         if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
455             view->scrollBy(IntSize(0, -view->visibleHeight()));
456         else
457             view->scrollBy(IntSize(0, view->visibleHeight()));
458         return TRUE;
459     case GDK_Home:
460         view->scrollBy(IntSize(0, -view->contentsHeight()));
461         return TRUE;
462     case GDK_End:
463         view->scrollBy(IntSize(0, view->contentsHeight()));
464         return TRUE;
465     }
466
467     /* Chain up to our parent class for binding activation */
468     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->key_press_event(widget, event);
469 }
470
471 static gboolean webkit_web_view_key_release_event(GtkWidget* widget, GdkEventKey* event)
472 {
473     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
474
475     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
476     if (!frame->view())
477         return FALSE;
478
479     PlatformKeyboardEvent keyboardEvent(event);
480
481     if (frame->eventHandler()->keyEvent(keyboardEvent))
482         return TRUE;
483
484     /* Chain up to our parent class for binding activation */
485     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->key_release_event(widget, event);
486 }
487
488 static gboolean webkit_web_view_button_press_event(GtkWidget* widget, GdkEventButton* event)
489 {
490     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
491
492     // FIXME: need to keep track of subframe focus for key events
493     gtk_widget_grab_focus(widget);
494
495     if (event->button == 3)
496         return webkit_web_view_forward_context_menu_event(webView, PlatformMouseEvent(event));
497
498     Frame* frame = core(webView)->mainFrame();
499     if (!frame->view())
500         return FALSE;
501
502     return frame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(event));
503 }
504
505 static gboolean webkit_web_view_button_release_event(GtkWidget* widget, GdkEventButton* event)
506 {
507     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
508
509     Frame* focusedFrame = core(webView)->focusController()->focusedFrame();
510
511     if (focusedFrame && focusedFrame->editor()->canEdit()) {
512 #ifdef MAEMO_CHANGES
513         WebKitWebViewPrivate* priv = webView->priv;
514         hildon_gtk_im_context_filter_event(priv->imContext, (GdkEvent*)event);
515 #endif
516     }
517
518     Frame* mainFrame = core(webView)->mainFrame();
519     if (mainFrame->view())
520         mainFrame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(event));
521
522     /* We always return FALSE here because WebKit can, for the same click, decide
523      * to not handle press-event but handle release-event, which can totally confuse
524      * some GTK+ containers when there are no other events in between. This way we
525      * guarantee that this case never happens, and that if press-event goes through
526      * release-event also goes through.
527      */
528
529     return FALSE;
530 }
531
532 static gboolean webkit_web_view_motion_event(GtkWidget* widget, GdkEventMotion* event)
533 {
534     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
535
536     Frame* frame = core(webView)->mainFrame();
537     if (!frame->view())
538         return FALSE;
539
540     return frame->eventHandler()->mouseMoved(PlatformMouseEvent(event));
541 }
542
543 static gboolean webkit_web_view_scroll_event(GtkWidget* widget, GdkEventScroll* event)
544 {
545     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
546
547     Frame* frame = core(webView)->mainFrame();
548     if (!frame->view())
549         return FALSE;
550
551     PlatformWheelEvent wheelEvent(event);
552     return frame->eventHandler()->handleWheelEvent(wheelEvent);
553 }
554
555 static void webkit_web_view_size_allocate(GtkWidget* widget, GtkAllocation* allocation)
556 {
557     GTK_WIDGET_CLASS(webkit_web_view_parent_class)->size_allocate(widget,allocation);
558
559     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
560
561     Frame* frame = core(webView)->mainFrame();
562     if (!frame->view())
563         return;
564
565     frame->view()->resize(allocation->width, allocation->height);
566     frame->view()->forceLayout();
567     frame->view()->adjustViewSize();
568 }
569
570 static gboolean webkit_web_view_focus_in_event(GtkWidget* widget, GdkEventFocus* event)
571 {
572     // TODO: Improve focus handling as suggested in
573     // http://bugs.webkit.org/show_bug.cgi?id=16910
574     GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
575     if (GTK_WIDGET_TOPLEVEL(toplevel) && gtk_window_has_toplevel_focus(GTK_WINDOW(toplevel))) {
576         WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
577
578         Frame* frame = core(webView)->mainFrame();
579         core(webView)->focusController()->setActive(frame);
580     }
581     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->focus_in_event(widget, event);
582 }
583
584 static gboolean webkit_web_view_focus_out_event(GtkWidget* widget, GdkEventFocus* event)
585 {
586     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
587
588     core(webView)->focusController()->setActive(false);
589
590     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->focus_out_event(widget, event);
591 }
592
593 static void webkit_web_view_realize(GtkWidget* widget)
594 {
595     GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
596
597     GdkWindowAttr attributes;
598     attributes.window_type = GDK_WINDOW_CHILD;
599     attributes.x = widget->allocation.x;
600     attributes.y = widget->allocation.y;
601     attributes.width = widget->allocation.width;
602     attributes.height = widget->allocation.height;
603     attributes.wclass = GDK_INPUT_OUTPUT;
604     attributes.visual = gtk_widget_get_visual (widget);
605     attributes.colormap = gtk_widget_get_colormap (widget);
606     attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK
607                             | GDK_EXPOSURE_MASK
608                             | GDK_BUTTON_PRESS_MASK
609                             | GDK_BUTTON_RELEASE_MASK
610                             | GDK_POINTER_MOTION_MASK
611                             | GDK_KEY_PRESS_MASK
612                             | GDK_KEY_RELEASE_MASK
613                             | GDK_BUTTON_MOTION_MASK
614                             | GDK_BUTTON1_MOTION_MASK
615                             | GDK_BUTTON2_MOTION_MASK
616                             | GDK_BUTTON3_MOTION_MASK;
617
618     gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
619     widget->window = gdk_window_new(gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
620     gdk_window_set_user_data(widget->window, widget);
621
622     widget->style = gtk_style_attach(widget->style, widget->window);
623     gdk_window_set_background(widget->window, &widget->style->base[GTK_WIDGET_STATE(widget)]);
624
625     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
626     WebKitWebViewPrivate* priv = webView->priv;
627     gtk_im_context_set_client_window(priv->imContext, widget->window);
628 }
629
630 static void webkit_web_view_set_scroll_adjustments(WebKitWebView* webView, GtkAdjustment* hadj, GtkAdjustment* vadj)
631 {
632     if (!core(webView))
633         return;
634
635     FrameView* view = core(webkit_web_view_get_main_frame(webView))->view();
636
637     if (hadj)
638         g_object_ref(hadj);
639     if (vadj)
640         g_object_ref(vadj);
641
642     WebKitWebViewPrivate* priv = webView->priv;
643
644     if (priv->horizontalAdjustment)
645         g_object_unref(priv->horizontalAdjustment);
646     if (priv->verticalAdjustment)
647         g_object_unref(priv->verticalAdjustment);
648
649     priv->horizontalAdjustment = hadj;
650     priv->verticalAdjustment = vadj;
651
652     if (!view)
653         return;
654
655     view->setGtkAdjustments(hadj, vadj);
656 }
657
658 static void webkit_web_view_container_add(GtkContainer* container, GtkWidget* widget)
659 {
660     WebKitWebView* webView = WEBKIT_WEB_VIEW(container);
661     WebKitWebViewPrivate* priv = webView->priv;
662
663     priv->children.add(widget);
664     if (GTK_WIDGET_REALIZED(container))
665         gtk_widget_set_parent_window(widget, GTK_WIDGET(webView)->window);
666     gtk_widget_set_parent(widget, GTK_WIDGET(container));
667 }
668
669 static void webkit_web_view_container_remove(GtkContainer* container, GtkWidget* widget)
670 {
671     WebKitWebView* webView = WEBKIT_WEB_VIEW(container);
672     WebKitWebViewPrivate* priv = webView->priv;
673
674     if (priv->children.contains(widget)) {
675         gtk_widget_unparent(widget);
676         priv->children.remove(widget);
677     }
678 }
679
680 static void webkit_web_view_container_forall(GtkContainer* container, gboolean, GtkCallback callback, gpointer callbackData)
681 {
682     WebKitWebView* webView = WEBKIT_WEB_VIEW(container);
683     WebKitWebViewPrivate* priv = webView->priv;
684
685     HashSet<GtkWidget*> children = priv->children;
686     HashSet<GtkWidget*>::const_iterator end = children.end();
687     for (HashSet<GtkWidget*>::const_iterator current = children.begin(); current != end; ++current)
688         (*callback)(*current, callbackData);
689 }
690
691 static WebKitWebView* webkit_web_view_real_create_web_view(WebKitWebView*, WebKitWebFrame*)
692 {
693     return 0;
694 }
695
696 static gboolean webkit_web_view_real_web_view_ready(WebKitWebView*)
697 {
698     return FALSE;
699 }
700
701 static WebKitNavigationResponse webkit_web_view_real_navigation_requested(WebKitWebView*, WebKitWebFrame*, WebKitNetworkRequest*)
702 {
703     return WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
704 }
705
706 static void webkit_web_view_real_window_object_cleared(WebKitWebView*, WebKitWebFrame*, JSGlobalContextRef context, JSObjectRef window_object)
707 {
708     notImplemented();
709 }
710
711 static gchar* webkit_web_view_real_choose_file(WebKitWebView*, WebKitWebFrame*, const gchar* old_name)
712 {
713     notImplemented();
714     return g_strdup(old_name);
715 }
716
717 typedef enum {
718     WEBKIT_SCRIPT_DIALOG_ALERT,
719     WEBKIT_SCRIPT_DIALOG_CONFIRM,
720     WEBKIT_SCRIPT_DIALOG_PROMPT
721  } WebKitScriptDialogType;
722
723 static gboolean webkit_web_view_script_dialog(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, WebKitScriptDialogType type, const gchar* defaultValue, gchar** value)
724 {
725     GtkMessageType messageType;
726     GtkButtonsType buttons;
727     gint defaultResponse;
728     GtkWidget* window;
729     GtkWidget* dialog;
730     GtkWidget* entry = 0;
731     gboolean didConfirm = FALSE;
732
733     switch (type) {
734     case WEBKIT_SCRIPT_DIALOG_ALERT:
735         messageType = GTK_MESSAGE_WARNING;
736         buttons = GTK_BUTTONS_CLOSE;
737         defaultResponse = GTK_RESPONSE_CLOSE;
738         break;
739     case WEBKIT_SCRIPT_DIALOG_CONFIRM:
740         messageType = GTK_MESSAGE_QUESTION;
741         buttons = GTK_BUTTONS_YES_NO;
742         defaultResponse = GTK_RESPONSE_YES;
743         break;
744     case WEBKIT_SCRIPT_DIALOG_PROMPT:
745         messageType = GTK_MESSAGE_QUESTION;
746         buttons = GTK_BUTTONS_OK_CANCEL;
747         defaultResponse = GTK_RESPONSE_OK;
748         break;
749     default:
750         g_warning("Unknown value for WebKitScriptDialogType.");
751         return FALSE;
752     }
753
754     window = gtk_widget_get_toplevel(GTK_WIDGET(webView));
755     dialog = gtk_message_dialog_new(GTK_WIDGET_TOPLEVEL(window) ? GTK_WINDOW(window) : 0, GTK_DIALOG_DESTROY_WITH_PARENT, messageType, buttons, "%s", message);
756     gchar* title = g_strconcat("JavaScript - ", webkit_web_frame_get_uri(frame), NULL);
757     gtk_window_set_title(GTK_WINDOW(dialog), title);
758     g_free(title);
759
760     if (type == WEBKIT_SCRIPT_DIALOG_PROMPT) {
761         entry = gtk_entry_new();
762         gtk_entry_set_text(GTK_ENTRY(entry), defaultValue);
763         gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entry);
764         gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
765         gtk_widget_show(entry);
766     }
767
768     gtk_dialog_set_default_response(GTK_DIALOG(dialog), defaultResponse);
769     gint response = gtk_dialog_run(GTK_DIALOG(dialog));
770
771     switch (response) {
772     case GTK_RESPONSE_YES:
773         didConfirm = TRUE;
774         break;
775     case GTK_RESPONSE_OK:
776         didConfirm = TRUE;
777         if (entry)
778             *value = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
779         else
780             *value = 0;
781         break;
782     case GTK_RESPONSE_NO:
783     case GTK_RESPONSE_CANCEL:
784         didConfirm = FALSE;
785         break;
786
787     }
788     gtk_widget_destroy(GTK_WIDGET(dialog));
789     return didConfirm;
790 }
791
792 static gboolean webkit_web_view_real_script_alert(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message)
793 {
794     webkit_web_view_script_dialog(webView, frame, message, WEBKIT_SCRIPT_DIALOG_ALERT, 0, 0);
795     return TRUE;
796 }
797
798 static gboolean webkit_web_view_real_script_confirm(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, gboolean* didConfirm)
799 {
800     *didConfirm = webkit_web_view_script_dialog(webView, frame, message, WEBKIT_SCRIPT_DIALOG_CONFIRM, 0, 0);
801     return TRUE;
802 }
803
804 static gboolean webkit_web_view_real_script_prompt(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, const gchar* defaultValue, gchar** value)
805 {
806     if (!webkit_web_view_script_dialog(webView, frame, message, WEBKIT_SCRIPT_DIALOG_PROMPT, defaultValue, value))
807         *value = NULL;
808     return TRUE;
809 }
810
811 static gboolean webkit_web_view_real_console_message(WebKitWebView* webView, const gchar* message, unsigned int line, const gchar* sourceId)
812 {
813     g_print("console message: %s @%d: %s\n", sourceId, line, message);
814     return TRUE;
815 }
816
817 static void webkit_web_view_real_select_all(WebKitWebView* webView)
818 {
819     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
820     frame->editor()->command("SelectAll").execute();
821 }
822
823 static void webkit_web_view_real_cut_clipboard(WebKitWebView* webView)
824 {
825     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
826     frame->editor()->command("Cut").execute();
827 }
828
829 static void webkit_web_view_real_copy_clipboard(WebKitWebView* webView)
830 {
831     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
832     frame->editor()->command("Copy").execute();
833 }
834
835 static void webkit_web_view_real_paste_clipboard(WebKitWebView* webView)
836 {
837     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
838     frame->editor()->command("Paste").execute();
839 }
840
841 static void webkit_web_view_dispose(GObject* object)
842 {
843     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
844     WebKitWebViewPrivate* priv = webView->priv;
845
846     priv->disposing = TRUE;
847
848     if (priv->corePage) {
849         webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(object));
850
851         core(priv->mainFrame)->loader()->detachChildren();
852         delete priv->corePage;
853         priv->corePage = NULL;
854     }
855
856     if (priv->horizontalAdjustment) {
857         g_object_unref(priv->horizontalAdjustment);
858         priv->horizontalAdjustment = NULL;
859     }
860
861     if (priv->verticalAdjustment) {
862         g_object_unref(priv->verticalAdjustment);
863         priv->verticalAdjustment = NULL;
864     }
865
866     if (priv->backForwardList) {
867         g_object_unref(priv->backForwardList);
868         priv->backForwardList = NULL;
869
870         g_signal_handlers_disconnect_by_func(priv->webSettings, (gpointer)webkit_web_view_settings_notify, webView);
871         g_object_unref(priv->webSettings);
872         priv->webSettings = NULL;
873
874         g_object_unref(priv->webInspector);
875         priv->webInspector = NULL;
876
877         g_object_unref(priv->webWindowFeatures);
878         priv->webWindowFeatures = NULL;
879
880         g_object_unref(priv->imContext);
881         priv->imContext = NULL;
882
883         gtk_target_list_unref(priv->copy_target_list);
884         priv->copy_target_list = NULL;
885
886         gtk_target_list_unref(priv->paste_target_list);
887         priv->paste_target_list = NULL;
888
889         delete priv->userAgent;
890         priv->userAgent = NULL;
891     }
892
893     G_OBJECT_CLASS(webkit_web_view_parent_class)->dispose(object);
894 }
895
896 static void webkit_web_view_finalize(GObject* object)
897 {
898     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
899     WebKitWebViewPrivate* priv = webView->priv;
900
901     g_free(priv->encoding);
902     g_free(priv->customEncoding);
903
904     G_OBJECT_CLASS(webkit_web_view_parent_class)->finalize(object);
905 }
906
907 static gboolean webkit_create_web_view_request_handled(GSignalInvocationHint* ihint, GValue* returnAccu, const GValue* handlerReturn, gpointer dummy)
908 {
909     gpointer newWebView = g_value_get_object(handlerReturn);
910     g_value_set_object(returnAccu, newWebView);
911
912     // Continue if we don't have a newWebView
913     return !newWebView;
914 }
915
916 static gboolean webkit_navigation_request_handled(GSignalInvocationHint* ihint, GValue* returnAccu, const GValue* handlerReturn, gpointer dummy)
917 {
918     WebKitNavigationResponse navigationResponse = (WebKitNavigationResponse)g_value_get_enum(handlerReturn);
919     g_value_set_enum(returnAccu, navigationResponse);
920
921     if (navigationResponse != WEBKIT_NAVIGATION_RESPONSE_ACCEPT)
922         return FALSE;
923
924     return TRUE;
925 }
926
927 static AtkObject* webkit_web_view_get_accessible(GtkWidget* widget)
928 {
929     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
930     if (!core(webView))
931         return NULL;
932
933     AXObjectCache::enableAccessibility();
934
935     Frame* coreFrame = core(webView)->mainFrame();
936     if (!coreFrame)
937         return NULL;
938
939     Document* doc = coreFrame->document();
940     if (!doc)
941         return NULL;
942
943     AccessibilityObject* coreAccessible = doc->axObjectCache()->get(doc->renderer());
944     if (!coreAccessible || !coreAccessible->wrapper())
945         return NULL;
946
947     return coreAccessible->wrapper();
948 }
949
950 static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
951 {
952     GtkBindingSet* binding_set;
953
954     webkit_init();
955
956     /*
957      * Signals
958      */
959
960     /**
961      * WebKitWebView::create-web-view:
962      * @web_view: the object on which the signal is emitted
963      * @frame: the #WebKitWebFrame
964      * @return: a newly allocated #WebKitWebView or %NULL
965      *
966      * Emitted when the creation of a new window is requested.
967      * If this signal is handled the signal handler should return the
968      * newly created #WebKitWebView.
969      *
970      * The new #WebKitWebView should not be displayed to the user
971      * until the #WebKitWebView::web-view-ready signal is emitted.
972      *
973      * The signal handlers should not try to deal with the reference
974      * count for the new #WebKitWebView. The widget to which the
975      * widget is added will handle that.
976      *
977      * Since 1.0.3
978      */
979     webkit_web_view_signals[CREATE_WEB_VIEW] = g_signal_new("create-web-view",
980             G_TYPE_FROM_CLASS(webViewClass),
981             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
982             G_STRUCT_OFFSET (WebKitWebViewClass, create_web_view),
983             webkit_create_web_view_request_handled,
984             NULL,
985             webkit_marshal_OBJECT__OBJECT,
986             WEBKIT_TYPE_WEB_VIEW , 1,
987             WEBKIT_TYPE_WEB_FRAME);
988
989     /**
990      * WebKitWebView::web-view-ready:
991      * @web_view: the object on which the signal is emitted
992      * @return: %TRUE to stop other handlers from being invoked for
993      * the event, %FALSE to propagate the event further
994      *
995      * Emitted after #WebKitWebView::create-web-view when the new #WebKitWebView
996      * should be displayed to the user. When this signal is emitted
997      * all the information about how the window should look, including
998      * size, position, whether the location, status and scroll bars
999      * should be displayed, is already set on the
1000      * #WebKitWebWindowFeatures object contained by the #WebKitWebView.
1001      *
1002      * Notice that some of that information may change during the life
1003      * time of the window, so you may want to connect to the ::notify
1004      * signal of the #WebKitWebWindowFeatures object to handle those.
1005      *
1006      * Since 1.0.3
1007      */
1008     webkit_web_view_signals[WEB_VIEW_READY] = g_signal_new("web-view-ready",
1009             G_TYPE_FROM_CLASS(webViewClass),
1010             (GSignalFlags)(G_SIGNAL_RUN_LAST),
1011             G_STRUCT_OFFSET (WebKitWebViewClass, web_view_ready),
1012             g_signal_accumulator_true_handled,
1013             NULL,
1014             webkit_marshal_BOOLEAN__VOID,
1015             G_TYPE_BOOLEAN, 0);
1016
1017     /**
1018      * WebKitWebView::navigation-requested:
1019      * @web_view: the object on which the signal is emitted
1020      * @frame: the #WebKitWebFrame that required the navigation
1021      * @request: a #WebKitNetworkRequest
1022      * @return: a WebKitNavigationResponse
1023      *
1024      * Emitted when @frame requests a navigation to another page.
1025      *
1026      * Deprecated: Use WebKitWebView::navigation-policy-decision-requested
1027      * instead
1028      */
1029     webkit_web_view_signals[NAVIGATION_REQUESTED] = g_signal_new("navigation-requested",
1030             G_TYPE_FROM_CLASS(webViewClass),
1031             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1032             G_STRUCT_OFFSET (WebKitWebViewClass, navigation_requested),
1033             webkit_navigation_request_handled,
1034             NULL,
1035             webkit_marshal_ENUM__OBJECT_OBJECT,
1036             WEBKIT_TYPE_NAVIGATION_RESPONSE, 2,
1037             WEBKIT_TYPE_WEB_FRAME,
1038             WEBKIT_TYPE_NETWORK_REQUEST);
1039
1040     /**
1041      * WebKitWebView::navigation-policy-decision-requested:
1042      * @web_view: the object on which the signal is emitted
1043      * @frame: the #WebKitWebFrame that required the navigation
1044      * @request: a #WebKitNetworkRequest
1045      * @navigation_action: a #WebKitWebNavigation
1046      * @policy_decision: a #WebKitWebPolicyDecision
1047      * @return: TRUE if the signal will be handled, FALSE to have the
1048      *          default behavior apply
1049      *
1050      * Emitted when @frame requests a navigation to another page.
1051      * If this signal is not handled, the default behavior is to allow the
1052      * navigation.
1053      *
1054      * Since: 1.0.3
1055      */
1056     webkit_web_view_signals[NAVIGATION_POLICY_DECISION_REQUESTED] = g_signal_new("navigation-policy-decision-requested",
1057             G_TYPE_FROM_CLASS(webViewClass),
1058             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1059             0,
1060             g_signal_accumulator_true_handled,
1061             NULL,
1062             webkit_marshal_BOOLEAN__OBJECT_OBJECT_OBJECT_OBJECT,
1063             G_TYPE_BOOLEAN, 4,
1064             WEBKIT_TYPE_WEB_FRAME,
1065             WEBKIT_TYPE_NETWORK_REQUEST,
1066             WEBKIT_TYPE_WEB_NAVIGATION_ACTION,
1067             WEBKIT_TYPE_WEB_POLICY_DECISION);
1068
1069     /**
1070      * WebKitWebView::mime-type-policy-decision-requested:
1071      * @web_view: the object on which the signal is emitted
1072      * @frame: the #WebKitWebFrame that required the policy decision
1073      * @request: a WebKitNetworkRequest
1074      * @mimetype: the MIME type attempted to load
1075      * @policy_decision: a #WebKitWebPolicyDecision
1076      * @return: TRUE if the signal will be handled, FALSE to have the
1077      *          default behavior apply
1078      *
1079      * Decide whether or not to display the given MIME type.  If this
1080      * signal is not handled, the default behavior is to show the
1081      * content of the requested URI if WebKit can show this MIME
1082      * type; if WebKit is not able to show the MIME type nothing
1083      * happens.
1084      *
1085      * Since: 1.0.3
1086      */
1087     webkit_web_view_signals[MIME_TYPE_POLICY_DECISION_REQUESTED] = g_signal_new("mime-type-policy-decision-requested",
1088             G_TYPE_FROM_CLASS(webViewClass),
1089             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1090             0,
1091             g_signal_accumulator_true_handled,
1092             NULL,
1093             webkit_marshal_BOOLEAN__OBJECT_OBJECT_STRING_OBJECT,
1094             G_TYPE_BOOLEAN, 4,
1095             WEBKIT_TYPE_WEB_FRAME,
1096             WEBKIT_TYPE_NETWORK_REQUEST,
1097             G_TYPE_STRING,
1098             WEBKIT_TYPE_WEB_POLICY_DECISION);
1099
1100     /**
1101      * WebKitWebView::window-object-cleared:
1102      * @web_view: the object on which the signal is emitted
1103      * @frame: the #WebKitWebFrame to which @window_object belongs
1104      * @context: the #JSGlobalContextRef holding the global object and other
1105      * execution state; equivalent to the return value of
1106      * webkit_web_frame_get_global_context(@frame)
1107      *
1108      * @window_object: the #JSObjectRef representing the frame's JavaScript
1109      * window object
1110      *
1111      * Emitted when the JavaScript window object in a #WebKitWebFrame has been
1112      * cleared in preparation for a new load. This is the preferred place to
1113      * set custom properties on the window object using the JavaScriptCore API.
1114      */
1115     webkit_web_view_signals[WINDOW_OBJECT_CLEARED] = g_signal_new("window-object-cleared",
1116             G_TYPE_FROM_CLASS(webViewClass),
1117             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1118             G_STRUCT_OFFSET (WebKitWebViewClass, window_object_cleared),
1119             NULL,
1120             NULL,
1121             webkit_marshal_VOID__OBJECT_POINTER_POINTER,
1122             G_TYPE_NONE, 3,
1123             WEBKIT_TYPE_WEB_FRAME,
1124             G_TYPE_POINTER,
1125             G_TYPE_POINTER);
1126
1127     /**
1128      * WebKitWebView::download-requested:
1129      * @web_view: the object on which the signal is emitted
1130      * @download: the message text
1131      * @return: TRUE if the download was handled.
1132      *
1133      * A new Download is being requested. By default, if the signal is
1134      * not handled, the download is cancelled.
1135      *
1136      * Since: 1.1.2
1137      */
1138     webkit_web_view_signals[DOWNLOAD_REQUESTED] = g_signal_new("download-requested",
1139             G_TYPE_FROM_CLASS(webViewClass),
1140             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1141             0,
1142             g_signal_accumulator_true_handled,
1143             NULL,
1144             webkit_marshal_BOOLEAN__OBJECT,
1145             G_TYPE_BOOLEAN, 1,
1146             G_TYPE_OBJECT);
1147
1148     /**
1149      * WebKitWebView::load-started:
1150      * @web_view: the object on which the signal is emitted
1151      * @frame: the frame going to do the load
1152      *
1153      * When a #WebKitWebFrame begins to load this signal is emitted.
1154      */
1155     webkit_web_view_signals[LOAD_STARTED] = g_signal_new("load-started",
1156             G_TYPE_FROM_CLASS(webViewClass),
1157             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1158             0,
1159             NULL,
1160             NULL,
1161             g_cclosure_marshal_VOID__OBJECT,
1162             G_TYPE_NONE, 1,
1163             WEBKIT_TYPE_WEB_FRAME);
1164
1165     /**
1166      * WebKitWebView::load-committed:
1167      * @web_view: the object on which the signal is emitted
1168      * @frame: the main frame that received the first data
1169      *
1170      * When a #WebKitWebFrame loaded the first data this signal is emitted.
1171      */
1172     webkit_web_view_signals[LOAD_COMMITTED] = g_signal_new("load-committed",
1173             G_TYPE_FROM_CLASS(webViewClass),
1174             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1175             0,
1176             NULL,
1177             NULL,
1178             g_cclosure_marshal_VOID__OBJECT,
1179             G_TYPE_NONE, 1,
1180             WEBKIT_TYPE_WEB_FRAME);
1181
1182
1183     /**
1184      * WebKitWebView::load-progress-changed:
1185      * @web_view: the #WebKitWebView
1186      * @progress: the global progress
1187      */
1188     webkit_web_view_signals[LOAD_PROGRESS_CHANGED] = g_signal_new("load-progress-changed",
1189             G_TYPE_FROM_CLASS(webViewClass),
1190             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1191             0,
1192             NULL,
1193             NULL,
1194             g_cclosure_marshal_VOID__INT,
1195             G_TYPE_NONE, 1,
1196             G_TYPE_INT);
1197
1198     webkit_web_view_signals[LOAD_FINISHED] = g_signal_new("load-finished",
1199             G_TYPE_FROM_CLASS(webViewClass),
1200             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1201             0,
1202             NULL,
1203             NULL,
1204             g_cclosure_marshal_VOID__OBJECT,
1205             G_TYPE_NONE, 1,
1206             WEBKIT_TYPE_WEB_FRAME);
1207
1208     /**
1209      * WebKitWebView::title-changed:
1210      * @web_view: the object on which the signal is emitted
1211      * @frame: the main frame
1212      * @title: the new title
1213      *
1214      * When a #WebKitWebFrame changes the document title this signal is emitted.
1215      */
1216     webkit_web_view_signals[TITLE_CHANGED] = g_signal_new("title-changed",
1217             G_TYPE_FROM_CLASS(webViewClass),
1218             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1219             0,
1220             NULL,
1221             NULL,
1222             webkit_marshal_VOID__OBJECT_STRING,
1223             G_TYPE_NONE, 2,
1224             WEBKIT_TYPE_WEB_FRAME,
1225             G_TYPE_STRING);
1226
1227     /**
1228      * WebKitWebView::hovering-over-link:
1229      * @web_view: the object on which the signal is emitted
1230      * @title: the link's title
1231      * @uri: the URI the link points to
1232      *
1233      * When the cursor is over a link, this signal is emitted.
1234      */
1235     webkit_web_view_signals[HOVERING_OVER_LINK] = g_signal_new("hovering-over-link",
1236             G_TYPE_FROM_CLASS(webViewClass),
1237             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1238             0,
1239             NULL,
1240             NULL,
1241             webkit_marshal_VOID__STRING_STRING,
1242             G_TYPE_NONE, 2,
1243             G_TYPE_STRING,
1244             G_TYPE_STRING);
1245
1246     /**
1247      * WebKitWebView::populate-popup:
1248      * @web_view: the object on which the signal is emitted
1249      * @menu: the context menu
1250      *
1251      * When a context menu is about to be displayed this signal is emitted.
1252      *
1253      * Add menu items to #menu to extend the context menu.
1254      */
1255     webkit_web_view_signals[POPULATE_POPUP] = g_signal_new("populate-popup",
1256             G_TYPE_FROM_CLASS(webViewClass),
1257             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1258             0,
1259             NULL,
1260             NULL,
1261             g_cclosure_marshal_VOID__OBJECT,
1262             G_TYPE_NONE, 1,
1263             GTK_TYPE_MENU);
1264
1265     webkit_web_view_signals[STATUS_BAR_TEXT_CHANGED] = g_signal_new("status-bar-text-changed",
1266             G_TYPE_FROM_CLASS(webViewClass),
1267             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1268             0,
1269             NULL,
1270             NULL,
1271             g_cclosure_marshal_VOID__STRING,
1272             G_TYPE_NONE, 1,
1273             G_TYPE_STRING);
1274
1275     webkit_web_view_signals[ICOND_LOADED] = g_signal_new("icon-loaded",
1276             G_TYPE_FROM_CLASS(webViewClass),
1277             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1278             0,
1279             NULL,
1280             NULL,
1281             g_cclosure_marshal_VOID__VOID,
1282             G_TYPE_NONE, 0);
1283
1284     webkit_web_view_signals[SELECTION_CHANGED] = g_signal_new("selection-changed",
1285             G_TYPE_FROM_CLASS(webViewClass),
1286             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1287             0,
1288             NULL,
1289             NULL,
1290             g_cclosure_marshal_VOID__VOID,
1291             G_TYPE_NONE, 0);
1292
1293     /**
1294      * WebKitWebView::console-message:
1295      * @web_view: the object on which the signal is emitted
1296      * @message: the message text
1297      * @line: the line where the error occured
1298      * @source_id: the source id
1299      * @return: TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
1300      *
1301      * A JavaScript console message was created.
1302      */
1303     webkit_web_view_signals[CONSOLE_MESSAGE] = g_signal_new("console-message",
1304             G_TYPE_FROM_CLASS(webViewClass),
1305             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1306             G_STRUCT_OFFSET(WebKitWebViewClass, console_message),
1307             g_signal_accumulator_true_handled,
1308             NULL,
1309             webkit_marshal_BOOLEAN__STRING_INT_STRING,
1310             G_TYPE_BOOLEAN, 3,
1311             G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
1312
1313     /**
1314      * WebKitWebView::script-alert:
1315      * @web_view: the object on which the signal is emitted
1316      * @frame: the relevant frame
1317      * @message: the message text
1318      * @return: TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
1319      *
1320      * A JavaScript alert dialog was created.
1321      */
1322     webkit_web_view_signals[SCRIPT_ALERT] = g_signal_new("script-alert",
1323             G_TYPE_FROM_CLASS(webViewClass),
1324             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1325             G_STRUCT_OFFSET(WebKitWebViewClass, script_alert),
1326             g_signal_accumulator_true_handled,
1327             NULL,
1328             webkit_marshal_BOOLEAN__OBJECT_STRING,
1329             G_TYPE_BOOLEAN, 2,
1330             WEBKIT_TYPE_WEB_FRAME, G_TYPE_STRING);
1331
1332     /**
1333      * WebKitWebView::script-confirm:
1334      * @web_view: the object on which the signal is emitted
1335      * @frame: the relevant frame
1336      * @message: the message text
1337      * @confirmed: whether the dialog has been confirmed
1338      * @return: TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
1339      *
1340      * A JavaScript confirm dialog was created, providing Yes and No buttons.
1341      */
1342     webkit_web_view_signals[SCRIPT_CONFIRM] = g_signal_new("script-confirm",
1343             G_TYPE_FROM_CLASS(webViewClass),
1344             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1345             G_STRUCT_OFFSET(WebKitWebViewClass, script_confirm),
1346             g_signal_accumulator_true_handled,
1347             NULL,
1348             webkit_marshal_BOOLEAN__OBJECT_STRING_BOOLEAN,
1349             G_TYPE_BOOLEAN, 3,
1350             WEBKIT_TYPE_WEB_FRAME, G_TYPE_STRING, G_TYPE_BOOLEAN);
1351
1352     /**
1353      * WebKitWebView::script-prompt:
1354      * @web_view: the object on which the signal is emitted
1355      * @frame: the relevant frame
1356      * @message: the message text
1357      * @default: the default value
1358      * @text: To be filled with the return value or NULL if the dialog was cancelled.
1359      * @return: TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
1360      *
1361      * A JavaScript prompt dialog was created, providing an entry to input text.
1362      */
1363     webkit_web_view_signals[SCRIPT_PROMPT] = g_signal_new("script-prompt",
1364             G_TYPE_FROM_CLASS(webViewClass),
1365             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1366             G_STRUCT_OFFSET(WebKitWebViewClass, script_prompt),
1367             g_signal_accumulator_true_handled,
1368             NULL,
1369             webkit_marshal_BOOLEAN__OBJECT_STRING_STRING_STRING,
1370             G_TYPE_BOOLEAN, 4,
1371             WEBKIT_TYPE_WEB_FRAME, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
1372
1373     /**
1374      * WebKitWebView::select-all:
1375      * @web_view: the object which received the signal
1376      *
1377      * The #WebKitWebView::select-all signal is a keybinding signal which gets emitted to
1378      * select the complete contents of the text view.
1379      *
1380      * The default bindings for this signal is Ctrl-a.
1381      */
1382     webkit_web_view_signals[SELECT_ALL] = g_signal_new("select-all",
1383             G_TYPE_FROM_CLASS(webViewClass),
1384             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1385             G_STRUCT_OFFSET(WebKitWebViewClass, select_all),
1386             NULL, NULL,
1387             g_cclosure_marshal_VOID__VOID,
1388             G_TYPE_NONE, 0);
1389
1390     /**
1391      * WebKitWebView::cut-clipboard:
1392      * @web_view: the object which received the signal
1393      *
1394      * The #WebKitWebView::cut-clipboard signal is a keybinding signal which gets emitted to
1395      * cut the selection to the clipboard.
1396      *
1397      * The default bindings for this signal are Ctrl-x and Shift-Delete.
1398      */
1399     webkit_web_view_signals[CUT_CLIPBOARD] = g_signal_new("cut-clipboard",
1400             G_TYPE_FROM_CLASS(webViewClass),
1401             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1402             G_STRUCT_OFFSET(WebKitWebViewClass, cut_clipboard),
1403             NULL, NULL,
1404             g_cclosure_marshal_VOID__VOID,
1405             G_TYPE_NONE, 0);
1406
1407     /**
1408      * WebKitWebView::copy-clipboard:
1409      * @web_view: the object which received the signal
1410      *
1411      * The #WebKitWebView::copy-clipboard signal is a keybinding signal which gets emitted to
1412      * copy the selection to the clipboard.
1413      *
1414      * The default bindings for this signal are Ctrl-c and Ctrl-Insert.
1415      */
1416     webkit_web_view_signals[COPY_CLIPBOARD] = g_signal_new("copy-clipboard",
1417             G_TYPE_FROM_CLASS(webViewClass),
1418             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1419             G_STRUCT_OFFSET(WebKitWebViewClass, copy_clipboard),
1420             NULL, NULL,
1421             g_cclosure_marshal_VOID__VOID,
1422             G_TYPE_NONE, 0);
1423
1424     /**
1425      * WebKitWebView::paste-clipboard:
1426      * @web_view: the object which received the signal
1427      *
1428      * The #WebKitWebView::paste-clipboard signal is a keybinding signal which gets emitted to
1429      * paste the contents of the clipboard into the Web view.
1430      *
1431      * The default bindings for this signal are Ctrl-v and Shift-Insert.
1432      */
1433     webkit_web_view_signals[PASTE_CLIPBOARD] = g_signal_new("paste-clipboard",
1434             G_TYPE_FROM_CLASS(webViewClass),
1435             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1436             G_STRUCT_OFFSET(WebKitWebViewClass, paste_clipboard),
1437             NULL, NULL,
1438             g_cclosure_marshal_VOID__VOID,
1439             G_TYPE_NONE, 0);
1440
1441     /*
1442      * implementations of virtual methods
1443      */
1444     webViewClass->create_web_view = webkit_web_view_real_create_web_view;
1445     webViewClass->web_view_ready = webkit_web_view_real_web_view_ready;
1446     webViewClass->navigation_requested = webkit_web_view_real_navigation_requested;
1447     webViewClass->window_object_cleared = webkit_web_view_real_window_object_cleared;
1448     webViewClass->choose_file = webkit_web_view_real_choose_file;
1449     webViewClass->script_alert = webkit_web_view_real_script_alert;
1450     webViewClass->script_confirm = webkit_web_view_real_script_confirm;
1451     webViewClass->script_prompt = webkit_web_view_real_script_prompt;
1452     webViewClass->console_message = webkit_web_view_real_console_message;
1453     webViewClass->select_all = webkit_web_view_real_select_all;
1454     webViewClass->cut_clipboard = webkit_web_view_real_cut_clipboard;
1455     webViewClass->copy_clipboard = webkit_web_view_real_copy_clipboard;
1456     webViewClass->paste_clipboard = webkit_web_view_real_paste_clipboard;
1457
1458     GObjectClass* objectClass = G_OBJECT_CLASS(webViewClass);
1459     objectClass->dispose = webkit_web_view_dispose;
1460     objectClass->finalize = webkit_web_view_finalize;
1461     objectClass->get_property = webkit_web_view_get_property;
1462     objectClass->set_property = webkit_web_view_set_property;
1463
1464     GtkWidgetClass* widgetClass = GTK_WIDGET_CLASS(webViewClass);
1465     widgetClass->realize = webkit_web_view_realize;
1466     widgetClass->expose_event = webkit_web_view_expose_event;
1467     widgetClass->key_press_event = webkit_web_view_key_press_event;
1468     widgetClass->key_release_event = webkit_web_view_key_release_event;
1469     widgetClass->button_press_event = webkit_web_view_button_press_event;
1470     widgetClass->button_release_event = webkit_web_view_button_release_event;
1471     widgetClass->motion_notify_event = webkit_web_view_motion_event;
1472     widgetClass->scroll_event = webkit_web_view_scroll_event;
1473     widgetClass->size_allocate = webkit_web_view_size_allocate;
1474     widgetClass->popup_menu = webkit_web_view_popup_menu_handler;
1475     widgetClass->focus_in_event = webkit_web_view_focus_in_event;
1476     widgetClass->focus_out_event = webkit_web_view_focus_out_event;
1477     widgetClass->get_accessible = webkit_web_view_get_accessible;
1478
1479     GtkContainerClass* containerClass = GTK_CONTAINER_CLASS(webViewClass);
1480     containerClass->add = webkit_web_view_container_add;
1481     containerClass->remove = webkit_web_view_container_remove;
1482     containerClass->forall = webkit_web_view_container_forall;
1483
1484     /*
1485      * make us scrollable (e.g. addable to a GtkScrolledWindow)
1486      */
1487     webViewClass->set_scroll_adjustments = webkit_web_view_set_scroll_adjustments;
1488     GTK_WIDGET_CLASS(webViewClass)->set_scroll_adjustments_signal = g_signal_new("set-scroll-adjustments",
1489             G_TYPE_FROM_CLASS(webViewClass),
1490             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1491             G_STRUCT_OFFSET(WebKitWebViewClass, set_scroll_adjustments),
1492             NULL, NULL,
1493             webkit_marshal_VOID__OBJECT_OBJECT,
1494             G_TYPE_NONE, 2,
1495             GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
1496
1497     /*
1498      * Key bindings
1499      */
1500
1501     binding_set = gtk_binding_set_by_class(webViewClass);
1502
1503     gtk_binding_entry_add_signal(binding_set, GDK_a, GDK_CONTROL_MASK,
1504                                  "select_all", 0);
1505
1506     /* Cut/copy/paste */
1507
1508     gtk_binding_entry_add_signal(binding_set, GDK_x, GDK_CONTROL_MASK,
1509                                  "cut_clipboard", 0);
1510     gtk_binding_entry_add_signal(binding_set, GDK_c, GDK_CONTROL_MASK,
1511                                  "copy_clipboard", 0);
1512     gtk_binding_entry_add_signal(binding_set, GDK_v, GDK_CONTROL_MASK,
1513                                  "paste_clipboard", 0);
1514
1515     gtk_binding_entry_add_signal(binding_set, GDK_Delete, GDK_SHIFT_MASK,
1516                                  "cut_clipboard", 0);
1517     gtk_binding_entry_add_signal(binding_set, GDK_Insert, GDK_CONTROL_MASK,
1518                                  "copy_clipboard", 0);
1519     gtk_binding_entry_add_signal(binding_set, GDK_Insert, GDK_SHIFT_MASK,
1520                                  "paste_clipboard", 0);
1521
1522     /*
1523      * properties
1524      */
1525
1526 #if GTK_CHECK_VERSION(2,10,0)
1527     /**
1528     * WebKitWebView:copy-target-list:
1529     *
1530     * The list of targets this web view supports for clipboard copying.
1531     *
1532     * Since: 1.0.2
1533     */
1534     g_object_class_install_property(objectClass, PROP_COPY_TARGET_LIST,
1535                                     g_param_spec_boxed("copy-target-list",
1536                                                        "Copy target list",
1537                                                        "The list of targets this web view supports for clipboard copying",
1538                                                        GTK_TYPE_TARGET_LIST,
1539                                                        WEBKIT_PARAM_READABLE));
1540
1541     /**
1542     * WebKitWebView:paste-target-list:
1543     *
1544     * The list of targets this web view supports for clipboard pasting.
1545     *
1546     * Since: 1.0.2
1547     */
1548     g_object_class_install_property(objectClass, PROP_PASTE_TARGET_LIST,
1549                                     g_param_spec_boxed("paste-target-list",
1550                                                        "Paste target list",
1551                                                        "The list of targets this web view supports for clipboard pasting",
1552                                                        GTK_TYPE_TARGET_LIST,
1553                                                        WEBKIT_PARAM_READABLE));
1554 #endif
1555
1556     g_object_class_install_property(objectClass, PROP_SETTINGS,
1557                                     g_param_spec_object("settings",
1558                                                         "Settings",
1559                                                         "An associated WebKitWebSettings instance",
1560                                                         WEBKIT_TYPE_WEB_SETTINGS,
1561                                                         WEBKIT_PARAM_READWRITE));
1562
1563     /**
1564     * WebKitWebView:web-inspector:
1565     *
1566     * The associated WebKitWebInspector instance.
1567     *
1568     * Since: 1.0.3
1569     */
1570     g_object_class_install_property(objectClass, PROP_WEB_INSPECTOR,
1571                                     g_param_spec_object("web-inspector",
1572                                                         "Web Inspector",
1573                                                         "The associated WebKitWebInspector instance",
1574                                                         WEBKIT_TYPE_WEB_INSPECTOR,
1575                                                         WEBKIT_PARAM_READABLE));
1576
1577     /**
1578     * WebKitWebView:window-features:
1579     *
1580     * An associated WebKitWebWindowFeatures instance.
1581     *
1582     * Since: 1.0.3
1583     */
1584     g_object_class_install_property(objectClass, PROP_WINDOW_FEATURES,
1585                                     g_param_spec_object("window-features",
1586                                                         "Window Features",
1587                                                         "An associated WebKitWebWindowFeatures instance",
1588                                                         WEBKIT_TYPE_WEB_WINDOW_FEATURES,
1589                                                         WEBKIT_PARAM_READWRITE));
1590
1591     g_object_class_install_property(objectClass, PROP_EDITABLE,
1592                                     g_param_spec_boolean("editable",
1593                                                          "Editable",
1594                                                          "Whether content can be modified by the user",
1595                                                          FALSE,
1596                                                          WEBKIT_PARAM_READWRITE));
1597
1598     g_object_class_install_property(objectClass, PROP_TRANSPARENT,
1599                                     g_param_spec_boolean("transparent",
1600                                                          "Transparent",
1601                                                          "Whether content has a transparent background",
1602                                                          FALSE,
1603                                                          WEBKIT_PARAM_READWRITE));
1604
1605     /**
1606     * WebKitWebView:zoom-level:
1607     *
1608     * The level of zoom of the content.
1609     *
1610     * Since: 1.0.1
1611     */
1612     g_object_class_install_property(objectClass, PROP_ZOOM_LEVEL,
1613                                     g_param_spec_float("zoom-level",
1614                                                        "Zoom level",
1615                                                        "The level of zoom of the content",
1616                                                        G_MINFLOAT,
1617                                                        G_MAXFLOAT,
1618                                                        1.0f,
1619                                                        WEBKIT_PARAM_READWRITE));
1620
1621     /**
1622     * WebKitWebView:full-content-zoom:
1623     *
1624     * Whether the full content is scaled when zooming.
1625     *
1626     * Since: 1.0.1
1627     */
1628     g_object_class_install_property(objectClass, PROP_FULL_CONTENT_ZOOM,
1629                                     g_param_spec_boolean("full-content-zoom",
1630                                                          "Full content zoom",
1631                                                          "Whether the full content is scaled when zooming",
1632                                                          FALSE,
1633                                                          WEBKIT_PARAM_READWRITE));
1634
1635     /**
1636      * WebKitWebView:encoding:
1637      *
1638      * The default encoding of the web view.
1639      *
1640      * Since: 1.1.2
1641      */
1642     g_object_class_install_property(objectClass, PROP_ENCODING,
1643                                     g_param_spec_string("encoding",
1644                                                         "Encoding",
1645                                                         "The default encoding of the web view",
1646                                                         NULL,
1647                                                         WEBKIT_PARAM_READABLE));
1648
1649     /**
1650      * WebKitWebView:custom-encoding:
1651      *
1652      * The custom encoding of the web view.
1653      *
1654      * Since: 1.1.2
1655      */
1656     g_object_class_install_property(objectClass, PROP_CUSTOM_ENCODING,
1657                                     g_param_spec_string("custom-encoding",
1658                                                         "Custom Encoding",
1659                                                         "The custom encoding of the web view",
1660                                                         NULL,
1661                                                         WEBKIT_PARAM_READWRITE));
1662
1663     g_type_class_add_private(webViewClass, sizeof(WebKitWebViewPrivate));
1664 }
1665
1666 static gdouble webViewGetDPI(WebKitWebView* webView)
1667 {
1668     WebKitWebViewPrivate* priv = webView->priv;
1669     WebKitWebSettings* webSettings = priv->webSettings;
1670     gboolean enforce96DPI;
1671     g_object_get(webSettings, "enforce-96-dpi", &enforce96DPI, NULL);
1672     if (enforce96DPI)
1673         return 96.0;
1674
1675     gdouble DPI = defaultDPI;
1676 #if GTK_CHECK_VERSION(2,10,0)
1677     GdkScreen* screen = gtk_widget_has_screen(GTK_WIDGET(webView)) ? gtk_widget_get_screen(GTK_WIDGET(webView)) : gdk_screen_get_default();
1678     if (screen) {
1679         DPI = gdk_screen_get_resolution(screen);
1680         // gdk_screen_get_resolution() returns -1 when no DPI is set.
1681         if (DPI == -1)
1682             DPI = defaultDPI;
1683     }
1684 #endif
1685     ASSERT(DPI > 0);
1686     return DPI;
1687 }
1688
1689 static void webkit_web_view_screen_changed(WebKitWebView* webView, GdkScreen* previousScreen, gpointer userdata)
1690 {
1691     WebKitWebViewPrivate* priv = webView->priv;
1692     WebKitWebSettings* webSettings = priv->webSettings;
1693     Settings* settings = core(webView)->settings();
1694     gdouble DPI = webViewGetDPI(webView);
1695
1696     guint defaultFontSize, defaultMonospaceFontSize, minimumFontSize, minimumLogicalFontSize;
1697
1698     g_object_get(webSettings,
1699                  "default-font-size", &defaultFontSize,
1700                  "default-monospace-font-size", &defaultMonospaceFontSize,
1701                  "minimum-font-size", &minimumFontSize,
1702                  "minimum-logical-font-size", &minimumLogicalFontSize,
1703                  NULL);
1704
1705     settings->setDefaultFontSize(defaultFontSize / 72.0 * DPI);
1706     settings->setDefaultFixedFontSize(defaultMonospaceFontSize / 72.0 * DPI);
1707     settings->setMinimumFontSize(minimumFontSize / 72.0 * DPI);
1708     settings->setMinimumLogicalFontSize(minimumLogicalFontSize / 72.0 * DPI);
1709 }
1710
1711 static void webkit_web_view_update_settings(WebKitWebView* webView)
1712 {
1713     WebKitWebViewPrivate* priv = webView->priv;
1714     WebKitWebSettings* webSettings = priv->webSettings;
1715     Settings* settings = core(webView)->settings();
1716
1717     gchar* defaultEncoding, *cursiveFontFamily, *defaultFontFamily, *fantasyFontFamily, *monospaceFontFamily, *sansSerifFontFamily, *serifFontFamily, *userStylesheetUri;
1718     gboolean autoLoadImages, autoShrinkImages, printBackgrounds,
1719         enableScripts, enablePlugins, enableDeveloperExtras, resizableTextAreas,
1720         enablePrivateBrowsing;
1721
1722     g_object_get(webSettings,
1723                  "default-encoding", &defaultEncoding,
1724                  "cursive-font-family", &cursiveFontFamily,
1725                  "default-font-family", &defaultFontFamily,
1726                  "fantasy-font-family", &fantasyFontFamily,
1727                  "monospace-font-family", &monospaceFontFamily,
1728                  "sans-serif-font-family", &sansSerifFontFamily,
1729                  "serif-font-family", &serifFontFamily,
1730                  "auto-load-images", &autoLoadImages,
1731                  "auto-shrink-images", &autoShrinkImages,
1732                  "print-backgrounds", &printBackgrounds,
1733                  "enable-scripts", &enableScripts,
1734                  "enable-plugins", &enablePlugins,
1735                  "resizable-text-areas", &resizableTextAreas,
1736                  "user-stylesheet-uri", &userStylesheetUri,
1737                  "enable-developer-extras", &enableDeveloperExtras,
1738                  "enable-private-browsing", &enablePrivateBrowsing,
1739                  NULL);
1740
1741     settings->setDefaultTextEncodingName(defaultEncoding);
1742     settings->setCursiveFontFamily(cursiveFontFamily);
1743     settings->setStandardFontFamily(defaultFontFamily);
1744     settings->setFantasyFontFamily(fantasyFontFamily);
1745     settings->setFixedFontFamily(monospaceFontFamily);
1746     settings->setSansSerifFontFamily(sansSerifFontFamily);
1747     settings->setSerifFontFamily(serifFontFamily);
1748     settings->setLoadsImagesAutomatically(autoLoadImages);
1749     settings->setShrinksStandaloneImagesToFit(autoShrinkImages);
1750     settings->setShouldPrintBackgrounds(printBackgrounds);
1751     settings->setJavaScriptEnabled(enableScripts);
1752     settings->setPluginsEnabled(enablePlugins);
1753     settings->setTextAreasAreResizable(resizableTextAreas);
1754     settings->setUserStyleSheetLocation(KURL(KURL(), userStylesheetUri));
1755     settings->setDeveloperExtrasEnabled(enableDeveloperExtras);
1756     settings->setPrivateBrowsingEnabled(enablePrivateBrowsing);
1757
1758     g_free(defaultEncoding);
1759     g_free(cursiveFontFamily);
1760     g_free(defaultFontFamily);
1761     g_free(fantasyFontFamily);
1762     g_free(monospaceFontFamily);
1763     g_free(sansSerifFontFamily);
1764     g_free(serifFontFamily);
1765     g_free(userStylesheetUri);
1766
1767     webkit_web_view_screen_changed(webView, NULL, NULL);
1768 }
1769
1770 static inline gint pixelsFromSize(WebKitWebView* webView, gint size)
1771 {
1772     gdouble DPI = webViewGetDPI(webView);
1773     return size / 72.0 * DPI;
1774 }
1775
1776 static void webkit_web_view_settings_notify(WebKitWebSettings* webSettings, GParamSpec* pspec, WebKitWebView* webView)
1777 {
1778     Settings* settings = core(webView)->settings();
1779
1780     const gchar* name = g_intern_string(pspec->name);
1781     GValue value = { 0, { { 0 } } };
1782     g_value_init(&value, pspec->value_type);
1783     g_object_get_property(G_OBJECT(webSettings), name, &value);
1784
1785     if (name == g_intern_string("default-encoding"))
1786         settings->setDefaultTextEncodingName(g_value_get_string(&value));
1787     else if (name == g_intern_string("cursive-font-family"))
1788         settings->setCursiveFontFamily(g_value_get_string(&value));
1789     else if (name == g_intern_string("default-font-family"))
1790         settings->setStandardFontFamily(g_value_get_string(&value));
1791     else if (name == g_intern_string("fantasy-font-family"))
1792         settings->setFantasyFontFamily(g_value_get_string(&value));
1793     else if (name == g_intern_string("monospace-font-family"))
1794         settings->setFixedFontFamily(g_value_get_string(&value));
1795     else if (name == g_intern_string("sans-serif-font-family"))
1796         settings->setSansSerifFontFamily(g_value_get_string(&value));
1797     else if (name == g_intern_string("serif-font-family"))
1798         settings->setSerifFontFamily(g_value_get_string(&value));
1799     else if (name == g_intern_string("default-font-size"))
1800         settings->setDefaultFontSize(pixelsFromSize(webView, g_value_get_int(&value)));
1801     else if (name == g_intern_string("default-monospace-font-size"))
1802         settings->setDefaultFixedFontSize(pixelsFromSize(webView, g_value_get_int(&value)));
1803     else if (name == g_intern_string("minimum-font-size"))
1804         settings->setMinimumFontSize(pixelsFromSize(webView, g_value_get_int(&value)));
1805     else if (name == g_intern_string("minimum-logical-font-size"))
1806         settings->setMinimumLogicalFontSize(pixelsFromSize(webView, g_value_get_int(&value)));
1807     else if (name == g_intern_string("enforce-96-dpi"))
1808         webkit_web_view_screen_changed(webView, NULL, NULL);
1809     else if (name == g_intern_string("auto-load-images"))
1810         settings->setLoadsImagesAutomatically(g_value_get_boolean(&value));
1811     else if (name == g_intern_string("auto-shrink-images"))
1812         settings->setShrinksStandaloneImagesToFit(g_value_get_boolean(&value));
1813     else if (name == g_intern_string("print-backgrounds"))
1814         settings->setShouldPrintBackgrounds(g_value_get_boolean(&value));
1815     else if (name == g_intern_string("enable-scripts"))
1816         settings->setJavaScriptEnabled(g_value_get_boolean(&value));
1817     else if (name == g_intern_string("enable-plugins"))
1818         settings->setPluginsEnabled(g_value_get_boolean(&value));
1819     else if (name == g_intern_string("resizable-text-areas"))
1820         settings->setTextAreasAreResizable(g_value_get_boolean(&value));
1821     else if (name == g_intern_string("user-stylesheet-uri"))
1822         settings->setUserStyleSheetLocation(KURL(KURL(), g_value_get_string(&value)));
1823     else if (name == g_intern_string("enable-developer-extras"))
1824         settings->setDeveloperExtrasEnabled(g_value_get_boolean(&value));
1825     else if (name == g_intern_string("enable-private-browsing"))
1826         settings->setPrivateBrowsingEnabled(g_value_get_boolean(&value));
1827     else if (!g_object_class_find_property(G_OBJECT_GET_CLASS(webSettings), name))
1828         g_warning("Unexpected setting '%s'", name);
1829     g_value_unset(&value);
1830 }
1831
1832 static void webkit_web_view_init(WebKitWebView* webView)
1833 {
1834     WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(webView);
1835     webView->priv = priv;
1836
1837     priv->imContext = gtk_im_multicontext_new();
1838
1839     WebKit::InspectorClient* inspectorClient = new WebKit::InspectorClient(webView);
1840     priv->corePage = new Page(new WebKit::ChromeClient(webView), new WebKit::ContextMenuClient(webView), new WebKit::EditorClient(webView), new WebKit::DragClient, inspectorClient);
1841
1842     // We also add a simple wrapper class to provide the public
1843     // interface for the Web Inspector.
1844     priv->webInspector = WEBKIT_WEB_INSPECTOR(g_object_new(WEBKIT_TYPE_WEB_INSPECTOR, NULL));
1845     webkit_web_inspector_set_inspector_client(priv->webInspector, priv->corePage);
1846
1847     priv->horizontalAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
1848     priv->verticalAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
1849
1850     g_object_ref_sink(priv->horizontalAdjustment);
1851     g_object_ref_sink(priv->verticalAdjustment);
1852
1853     GTK_WIDGET_SET_FLAGS(webView, GTK_CAN_FOCUS);
1854     priv->mainFrame = WEBKIT_WEB_FRAME(webkit_web_frame_new(webView));
1855     priv->lastPopupXPosition = priv->lastPopupYPosition = -1;
1856     priv->editable = false;
1857
1858     priv->backForwardList = webkit_web_back_forward_list_new_with_web_view(webView);
1859
1860     priv->zoomFullContent = FALSE;
1861
1862 #if GTK_CHECK_VERSION(2,10,0)
1863     GdkAtom textHtml = gdk_atom_intern_static_string("text/html");
1864 #else
1865     GdkAtom textHtml = gdk_atom_intern("text/html", false);
1866 #endif
1867     /* Targets for copy */
1868     priv->copy_target_list = gtk_target_list_new(NULL, 0);
1869     gtk_target_list_add(priv->copy_target_list, textHtml, 0, WEBKIT_WEB_VIEW_TARGET_INFO_HTML);
1870     gtk_target_list_add_text_targets(priv->copy_target_list, WEBKIT_WEB_VIEW_TARGET_INFO_TEXT);
1871
1872     /* Targets for pasting */
1873     priv->paste_target_list = gtk_target_list_new(NULL, 0);
1874     gtk_target_list_add(priv->paste_target_list, textHtml, 0, WEBKIT_WEB_VIEW_TARGET_INFO_HTML);
1875     gtk_target_list_add_text_targets(priv->paste_target_list, WEBKIT_WEB_VIEW_TARGET_INFO_TEXT);
1876
1877     priv->webSettings = webkit_web_settings_new();
1878     webkit_web_view_update_settings(webView);
1879     g_signal_connect(webView, "screen-changed", G_CALLBACK(webkit_web_view_screen_changed), NULL);
1880     g_signal_connect(priv->webSettings, "notify", G_CALLBACK(webkit_web_view_settings_notify), webView);
1881
1882     priv->webWindowFeatures = webkit_web_window_features_new();
1883 }
1884
1885 GtkWidget* webkit_web_view_new(void)
1886 {
1887     WebKitWebView* webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, NULL));
1888
1889     return GTK_WIDGET(webView);
1890 }
1891
1892 // for internal use only
1893 void webkit_web_view_notify_ready(WebKitWebView* webView)
1894 {
1895     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
1896
1897     gboolean isHandled = FALSE;
1898     g_signal_emit(webView, webkit_web_view_signals[WEB_VIEW_READY], 0, &isHandled);
1899 }
1900
1901
1902 void webkit_web_view_set_settings(WebKitWebView* webView, WebKitWebSettings* webSettings)
1903 {
1904     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
1905     g_return_if_fail(WEBKIT_IS_WEB_SETTINGS(webSettings));
1906
1907     WebKitWebViewPrivate* priv = webView->priv;
1908     g_signal_handlers_disconnect_by_func(priv->webSettings, (gpointer)webkit_web_view_settings_notify, webView);
1909     g_object_unref(priv->webSettings);
1910     g_object_ref(webSettings);
1911     priv->webSettings = webSettings;
1912     webkit_web_view_update_settings(webView);
1913     g_signal_connect(webSettings, "notify", G_CALLBACK(webkit_web_view_settings_notify), webView);
1914     g_object_notify(G_OBJECT(webView), "settings");
1915 }
1916
1917 WebKitWebSettings* webkit_web_view_get_settings(WebKitWebView* webView)
1918 {
1919     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
1920
1921     WebKitWebViewPrivate* priv = webView->priv;
1922     return priv->webSettings;
1923 }
1924
1925 /**
1926  * webkit_web_view_get_inspector:
1927  * @web_view: a #WebKitWebView
1928  *
1929  * Obtains the #WebKitWebInspector associated with the
1930  * #WebKitWebView. Every #WebKitWebView object has a
1931  * #WebKitWebInspector object attached to it as soon as it is created,
1932  * so this function will only return NULL if the argument is not a
1933  * valid #WebKitWebView.
1934  *
1935  * Returns: the #WebKitWebInspector instance associated with the
1936  * #WebKitWebView; %NULL is only returned if the argument is not a
1937  * valid #WebKitWebView.
1938  *
1939  * Since: 1.0.3
1940  */
1941 WebKitWebInspector* webkit_web_view_get_inspector(WebKitWebView* webView)
1942 {
1943     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
1944
1945     WebKitWebViewPrivate* priv = webView->priv;
1946     return priv->webInspector;
1947 }
1948
1949 // internal
1950 static void webkit_web_view_set_window_features(WebKitWebView* webView, WebKitWebWindowFeatures* webWindowFeatures)
1951 {
1952     WebKitWebViewPrivate* priv = webView->priv;
1953
1954     if(webkit_web_window_features_equal(priv->webWindowFeatures, webWindowFeatures))
1955       return;
1956
1957     g_object_unref(priv->webWindowFeatures);
1958     g_object_ref(webWindowFeatures);
1959     priv->webWindowFeatures = webWindowFeatures;
1960 }
1961
1962 /**
1963  * webkit_web_view_get_window_features
1964  * @web_view: a #WebKitWebView
1965  *
1966  * Returns the instance of #WebKitWebWindowFeatures held by the given
1967  * #WebKitWebView.
1968  *
1969  * Return value: the #WebKitWebWindowFeatures
1970  *
1971  * Since: 1.0.3
1972  */
1973 WebKitWebWindowFeatures* webkit_web_view_get_window_features(WebKitWebView* webView)
1974 {
1975     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
1976
1977     WebKitWebViewPrivate* priv = webView->priv;
1978     return priv->webWindowFeatures;
1979 }
1980
1981 /**
1982  * webkit_web_view_set_maintains_back_forward_list:
1983  * @web_view: a #WebKitWebView
1984  * @flag: to tell the view to maintain a back or forward list
1985  *
1986  * Set the view to maintain a back or forward list of history items.
1987  */
1988 void webkit_web_view_set_maintains_back_forward_list(WebKitWebView* webView, gboolean flag)
1989 {
1990     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
1991
1992     core(webView)->backForwardList()->setEnabled(flag);
1993 }
1994
1995 /**
1996  * webkit_web_view_get_back_forward_list:
1997  * @web_view: a #WebKitWebView
1998  *
1999  * Returns a #WebKitWebBackForwardList
2000  *
2001  * Return value: the #WebKitWebBackForwardList
2002  */
2003 WebKitWebBackForwardList* webkit_web_view_get_back_forward_list(WebKitWebView* webView)
2004 {
2005     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2006
2007     WebKitWebViewPrivate* priv = webView->priv;
2008
2009     if (!core(webView) || !core(webView)->backForwardList()->enabled())
2010         return NULL;
2011
2012     return priv->backForwardList;
2013 }
2014
2015 /**
2016  * webkit_web_view_go_to_back_forward_item:
2017  * @web_view: a #WebKitWebView
2018  * @item: a #WebKitWebHistoryItem*
2019  *
2020  * Go to the specified #WebKitWebHistoryItem
2021  *
2022  * Return value: %TRUE if loading of item is successful, %FALSE if not
2023  */
2024 gboolean webkit_web_view_go_to_back_forward_item(WebKitWebView* webView, WebKitWebHistoryItem* item)
2025 {
2026     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2027     g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(item), FALSE);
2028
2029     WebKitWebBackForwardList* backForwardList = webkit_web_view_get_back_forward_list(webView);
2030     if (!webkit_web_back_forward_list_contains_item(backForwardList, item))
2031         return FALSE;
2032
2033     core(webView)->goToItem(core(item), FrameLoadTypeIndexedBackForward);
2034     return TRUE;
2035 }
2036
2037 /**
2038  * webkit_web_view_go_back:
2039  * @web_view: a #WebKitWebView
2040  *
2041  * Loads the previous history item.
2042  */
2043 void webkit_web_view_go_back(WebKitWebView* webView)
2044 {
2045     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2046
2047     core(webView)->goBack();
2048 }
2049
2050 /**
2051  * webkit_web_view_go_back_or_forward:
2052  * @web_view: a #WebKitWebView
2053  * @steps: the number of steps
2054  *
2055  * Loads the history item that is the number of @steps away from the current
2056  * item. Negative values represent steps backward while positive values
2057  * represent steps forward.
2058  */
2059 void webkit_web_view_go_back_or_forward(WebKitWebView* webView, gint steps)
2060 {
2061     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2062
2063     Frame* frame = core(webView)->mainFrame();
2064     frame->loader()->goBackOrForward(steps);
2065 }
2066
2067 /**
2068  * webkit_web_view_go_forward:
2069  * @web_view: a #WebKitWebView
2070  *
2071  * Loads the next history item.
2072  */
2073 void webkit_web_view_go_forward(WebKitWebView* webView)
2074 {
2075     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2076
2077     core(webView)->goForward();
2078 }
2079
2080 /**
2081  * webkit_web_view_can_go_back:
2082  * @web_view: a #WebKitWebView
2083  *
2084  * Determines whether #web_view has a previous history item.
2085  *
2086  * Return value: %TRUE if able to move back, %FALSE otherwise
2087  */
2088 gboolean webkit_web_view_can_go_back(WebKitWebView* webView)
2089 {
2090     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2091
2092     if (!core(webView) || !core(webView)->backForwardList()->backItem())
2093         return FALSE;
2094
2095     return TRUE;
2096 }
2097
2098 /**
2099  * webkit_web_view_can_go_back_or_forward:
2100  * @web_view: a #WebKitWebView
2101  * @steps: the number of steps
2102  *
2103  * Determines whether #web_view has a history item of @steps. Negative values
2104  * represent steps backward while positive values represent steps forward.
2105  *
2106  * Return value: %TRUE if able to move back or forward the given number of
2107  * steps, %FALSE otherwise
2108  */
2109 gboolean webkit_web_view_can_go_back_or_forward(WebKitWebView* webView, gint steps)
2110 {
2111     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2112
2113     Frame* frame = core(webView)->mainFrame();
2114     return frame->loader()->canGoBackOrForward(steps);
2115 }
2116
2117 /**
2118  * webkit_web_view_can_go_forward:
2119  * @web_view: a #WebKitWebView
2120  *
2121  * Determines whether #web_view has a next history item.
2122  *
2123  * Return value: %TRUE if able to move forward, %FALSE otherwise
2124  */
2125 gboolean webkit_web_view_can_go_forward(WebKitWebView* webView)
2126 {
2127     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2128
2129     Page* page = core(webView);
2130
2131     if (!page)
2132         return FALSE;
2133
2134     if (!page->backForwardList()->forwardItem())
2135         return FALSE;
2136
2137     return TRUE;
2138 }
2139
2140 /**
2141  * webkit_web_view_open:
2142  * @web_view: a #WebKitWebView
2143  * @uri: an URI
2144  *
2145  * Requests loading of the specified URI string.
2146  *
2147  * Deprecated: 1.1.1: Use webkit_web_view_load_uri() instead.
2148   */
2149 void webkit_web_view_open(WebKitWebView* webView, const gchar* uri)
2150 {
2151     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2152     g_return_if_fail(uri);
2153
2154     // We used to support local paths, unlike the newer
2155     // function webkit_web_view_load_uri
2156     if (g_path_is_absolute(uri)) {
2157         gchar* fileUri = g_strdup_printf("file://%s", uri);
2158         webkit_web_view_load_uri(webView, fileUri);
2159         g_free(fileUri);
2160     }
2161     else
2162         webkit_web_view_load_uri(webView, uri);
2163 }
2164
2165 void webkit_web_view_reload(WebKitWebView* webView)
2166 {
2167     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2168
2169     core(webView)->mainFrame()->loader()->reload();
2170 }
2171
2172 /**
2173  * webkit_web_view_reload_bypass_cache:
2174  * @web_view: a #WebKitWebView
2175  *
2176  * Reloads the @web_view without using any cached data.
2177  *
2178  * Since: 1.0.3
2179  */
2180 void webkit_web_view_reload_bypass_cache(WebKitWebView* webView)
2181 {
2182     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2183
2184     core(webView)->mainFrame()->loader()->reload(true);
2185 }
2186
2187 /**
2188  * webkit_web_view_load_uri:
2189  * @web_view: a #WebKitWebView
2190  * @uri: an URI string
2191  *
2192  * Requests loading of the specified URI string.
2193  *
2194  * Since: 1.1.1
2195  */
2196 void webkit_web_view_load_uri(WebKitWebView* webView, const gchar* uri)
2197 {
2198     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2199     g_return_if_fail(uri);
2200
2201     WebKitWebFrame* frame = webView->priv->mainFrame;
2202     webkit_web_frame_load_uri(frame, uri);
2203 }
2204
2205 /**
2206 +  * webkit_web_view_load_string:
2207 +  * @web_view: a #WebKitWebView
2208 +  * @content: an URI string
2209 +  * @mime_type: the MIME type, or %NULL
2210 +  * @encoding: the encoding, or %NULL
2211 +  * @base_uri: the base URI for relative locations
2212 +  *
2213 +  * Requests loading of the given @content with the specified @mime_type,
2214 +  * @encoding and @base_uri.
2215 +  *
2216 +  * If @mime_type is %NULL, "text/html" is assumed.
2217 +  *
2218 +  * If @encoding is %NULL, "UTF-8" is assumed.
2219 +  */
2220 void webkit_web_view_load_string(WebKitWebView* webView, const gchar* content, const gchar* mimeType, const gchar* encoding, const gchar* baseUri)
2221 {
2222     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2223     g_return_if_fail(content);
2224
2225     WebKitWebFrame* frame = webView->priv->mainFrame;
2226     webkit_web_frame_load_string(frame, content, mimeType, encoding, baseUri);
2227 }
2228 /**
2229  * webkit_web_view_load_html_string:
2230  * @web_view: a #WebKitWebView
2231  * @content: an URI string
2232  * @base_uri: the base URI for relative locations
2233  *
2234  * Requests loading of the given @content with the specified @base_uri.
2235  *
2236  * Deprecated: 1.1.1: Use webkit_web_view_load_string() instead.
2237  */
2238 void webkit_web_view_load_html_string(WebKitWebView* webView, const gchar* content, const gchar* baseUri)
2239 {
2240     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2241     g_return_if_fail(content);
2242
2243     webkit_web_view_load_string(webView, content, NULL, NULL, baseUri);
2244 }
2245
2246 /**
2247  * webkit_web_view_load_request:
2248  * @web_view: a #WebKitWebView
2249  * @request: a #WebKitNetworkRequest
2250  *
2251  * Requests loading of the specified asynchronous client request.
2252  *
2253  * Creates a provisional data source that will transition to a committed data
2254  * source once any data has been received. Use webkit_web_view_stop_loading() to
2255  * stop the load.
2256  *
2257  * Since: 1.1.1
2258  */
2259 void webkit_web_view_load_request(WebKitWebView* webView, WebKitNetworkRequest* request)
2260 {
2261     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2262     g_return_if_fail(WEBKIT_IS_NETWORK_REQUEST(request));
2263
2264     WebKitWebFrame* frame = webView->priv->mainFrame;
2265     webkit_web_frame_load_request(frame, request);
2266 }
2267
2268 void webkit_web_view_stop_loading(WebKitWebView* webView)
2269 {
2270     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2271
2272     Frame* frame = core(webView)->mainFrame();
2273
2274     if (FrameLoader* loader = frame->loader())
2275         loader->stopAllLoaders();
2276 }
2277
2278 /**
2279  * webkit_web_view_search_text:
2280  * @web_view: a #WebKitWebView
2281  * @text: a string to look for
2282  * @forward: whether to find forward or not
2283  * @case_sensitive: whether to respect the case of text
2284  * @wrap: whether to continue looking at the beginning after reaching the end
2285  *
2286  * Looks for a specified string inside #web_view.
2287  *
2288  * Return value: %TRUE on success or %FALSE on failure
2289  */
2290 gboolean webkit_web_view_search_text(WebKitWebView* webView, const gchar* string, gboolean caseSensitive, gboolean forward, gboolean shouldWrap)
2291 {
2292     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2293     g_return_val_if_fail(string, FALSE);
2294
2295     TextCaseSensitivity caseSensitivity = caseSensitive ? TextCaseSensitive : TextCaseInsensitive;
2296     FindDirection direction = forward ? FindDirectionForward : FindDirectionBackward;
2297
2298     return core(webView)->findString(String::fromUTF8(string), caseSensitivity, direction, shouldWrap);
2299 }
2300
2301 /**
2302  * webkit_web_view_mark_text_matches:
2303  * @web_view: a #WebKitWebView
2304  * @string: a string to look for
2305  * @case_sensitive: whether to respect the case of text
2306  * @limit: the maximum number of strings to look for or %0 for all
2307  *
2308  * Attempts to highlight all occurances of #string inside #web_view.
2309  *
2310  * Return value: the number of strings highlighted
2311  */
2312 guint webkit_web_view_mark_text_matches(WebKitWebView* webView, const gchar* string, gboolean caseSensitive, guint limit)
2313 {
2314     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
2315     g_return_val_if_fail(string, 0);
2316
2317     TextCaseSensitivity caseSensitivity = caseSensitive ? TextCaseSensitive : TextCaseInsensitive;
2318
2319     return core(webView)->markAllMatchesForText(String::fromUTF8(string), caseSensitivity, false, limit);
2320 }
2321
2322 /**
2323  * webkit_web_view_set_highlight_text_matches:
2324  * @web_view: a #WebKitWebView
2325  * @highlight: whether to highlight text matches
2326  *
2327  * Highlights text matches previously marked by webkit_web_view_mark_text_matches.
2328  */
2329 void webkit_web_view_set_highlight_text_matches(WebKitWebView* webView, gboolean shouldHighlight)
2330 {
2331     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2332
2333     core(webView)->mainFrame()->setMarkedTextMatchesAreHighlighted(shouldHighlight);
2334 }
2335
2336 /**
2337  * webkit_web_view_unmark_text_matches:
2338  * @web_view: a #WebKitWebView
2339  *
2340  * Removes highlighting previously set by webkit_web_view_mark_text_matches.
2341  */
2342 void webkit_web_view_unmark_text_matches(WebKitWebView* webView)
2343 {
2344     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2345
2346     return core(webView)->unmarkAllTextMatches();
2347 }
2348
2349 WebKitWebFrame* webkit_web_view_get_main_frame(WebKitWebView* webView)
2350 {
2351     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2352
2353     WebKitWebViewPrivate* priv = webView->priv;
2354     return priv->mainFrame;
2355 }
2356
2357 /**
2358  * webkit_web_view_get_focused_frame:
2359  * @web_view: a #WebKitWebView
2360  *
2361  * Returns the frame that has focus or an active text selection.
2362  *
2363  * Return value: The focused #WebKitWebFrame or %NULL if no frame is focused
2364  */
2365 WebKitWebFrame* webkit_web_view_get_focused_frame(WebKitWebView* webView)
2366 {
2367     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2368
2369     Frame* focusedFrame = core(webView)->focusController()->focusedFrame();
2370     return kit(focusedFrame);
2371 }
2372
2373 void webkit_web_view_execute_script(WebKitWebView* webView, const gchar* script)
2374 {
2375     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2376     g_return_if_fail(script);
2377
2378     if (FrameLoader* loader = core(webView)->mainFrame()->loader())
2379         loader->executeScript(String::fromUTF8(script), true);
2380 }
2381
2382 /**
2383  * webkit_web_view_cut_clipboard:
2384  * @web_view: a #WebKitWebView
2385  *
2386  * Determines whether or not it is currently possible to cut to the clipboard.
2387  *
2388  * Return value: %TRUE if a selection can be cut, %FALSE if not
2389  */
2390 gboolean webkit_web_view_can_cut_clipboard(WebKitWebView* webView)
2391 {
2392     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2393
2394     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
2395     return frame->editor()->canCut() || frame->editor()->canDHTMLCut();
2396 }
2397
2398 /**
2399  * webkit_web_view_copy_clipboard:
2400  * @web_view: a #WebKitWebView
2401  *
2402  * Determines whether or not it is currently possible to copy to the clipboard.
2403  *
2404  * Return value: %TRUE if a selection can be copied, %FALSE if not
2405  */
2406 gboolean webkit_web_view_can_copy_clipboard(WebKitWebView* webView)
2407 {
2408     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2409
2410     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
2411     return frame->editor()->canCopy() || frame->editor()->canDHTMLCopy();
2412 }
2413
2414 /**
2415  * webkit_web_view_paste_clipboard:
2416  * @web_view: a #WebKitWebView
2417  *
2418  * Determines whether or not it is currently possible to paste from the clipboard.
2419  *
2420  * Return value: %TRUE if a selection can be pasted, %FALSE if not
2421  */
2422 gboolean webkit_web_view_can_paste_clipboard(WebKitWebView* webView)
2423 {
2424     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2425
2426     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
2427     return frame->editor()->canPaste() || frame->editor()->canDHTMLPaste();
2428 }
2429
2430 /**
2431  * webkit_web_view_cut_clipboard:
2432  * @web_view: a #WebKitWebView
2433  *
2434  * Cuts the current selection inside the @web_view to the clipboard.
2435  */
2436 void webkit_web_view_cut_clipboard(WebKitWebView* webView)
2437 {
2438     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2439
2440     if (webkit_web_view_can_cut_clipboard(webView))
2441         g_signal_emit(webView, webkit_web_view_signals[CUT_CLIPBOARD], 0);
2442 }
2443
2444 /**
2445  * webkit_web_view_copy_clipboard:
2446  * @web_view: a #WebKitWebView
2447  *
2448  * Copies the current selection inside the @web_view to the clipboard.
2449  */
2450 void webkit_web_view_copy_clipboard(WebKitWebView* webView)
2451 {
2452     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2453
2454     if (webkit_web_view_can_copy_clipboard(webView))
2455         g_signal_emit(webView, webkit_web_view_signals[COPY_CLIPBOARD], 0);
2456 }
2457
2458 /**
2459  * webkit_web_view_paste_clipboard:
2460  * @web_view: a #WebKitWebView
2461  *
2462  * Pastes the current contents of the clipboard to the @web_view.
2463  */
2464 void webkit_web_view_paste_clipboard(WebKitWebView* webView)
2465 {
2466     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2467
2468     if (webkit_web_view_can_paste_clipboard(webView))
2469         g_signal_emit(webView, webkit_web_view_signals[PASTE_CLIPBOARD], 0);
2470 }
2471
2472 /**
2473  * webkit_web_view_delete_selection:
2474  * @web_view: a #WebKitWebView
2475  *
2476  * Deletes the current selection inside the @web_view.
2477  */
2478 void webkit_web_view_delete_selection(WebKitWebView* webView)
2479 {
2480     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2481
2482     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
2483     frame->editor()->performDelete();
2484 }
2485
2486 /**
2487  * webkit_web_view_has_selection:
2488  * @web_view: a #WebKitWebView
2489  *
2490  * Determines whether text was selected.
2491  *
2492  * Return value: %TRUE if there is selected text, %FALSE if not
2493  */
2494 gboolean webkit_web_view_has_selection(WebKitWebView* webView)
2495 {
2496     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2497
2498     return !core(webView)->selection().isNone();
2499 }
2500
2501 /**
2502  * webkit_web_view_get_selected_text:
2503  * @web_view: a #WebKitWebView
2504  *
2505  * Retrieves the selected text if any.
2506  *
2507  * Return value: a newly allocated string with the selection or %NULL
2508  */
2509 gchar* webkit_web_view_get_selected_text(WebKitWebView* webView)
2510 {
2511     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
2512
2513     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
2514     return g_strdup(frame->selectedText().utf8().data());
2515 }
2516
2517 /**
2518  * webkit_web_view_select_all:
2519  * @web_view: a #WebKitWebView
2520  *
2521  * Attempts to select everything inside the @web_view.
2522  */
2523 void webkit_web_view_select_all(WebKitWebView* webView)
2524 {
2525     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2526
2527     g_signal_emit(webView, webkit_web_view_signals[SELECT_ALL], 0);
2528 }
2529
2530 /**
2531  * webkit_web_view_get_editable:
2532  * @web_view: a #WebKitWebView
2533  *
2534  * Returns whether the user is allowed to edit the document.
2535  *
2536  * Returns %TRUE if @web_view allows the user to edit the HTML document, %FALSE if
2537  * it doesn't. You can change @web_view's document programmatically regardless of
2538  * this setting.
2539  *
2540  * Return value: a #gboolean indicating the editable state
2541  */
2542 gboolean webkit_web_view_get_editable(WebKitWebView* webView)
2543 {
2544     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2545
2546     WebKitWebViewPrivate* priv = webView->priv;
2547
2548     return priv->editable;
2549 }
2550
2551 /**
2552  * webkit_web_view_set_editable:
2553  * @web_view: a #WebKitWebView
2554  * @flag: a #gboolean indicating the editable state
2555  *
2556  * Sets whether @web_view allows the user to edit its HTML document.
2557  *
2558  * If @flag is %TRUE, @web_view allows the user to edit the document. If @flag is
2559  * %FALSE, an element in @web_view's document can only be edited if the
2560  * CONTENTEDITABLE attribute has been set on the element or one of its parent
2561  * elements. You can change @web_view's document programmatically regardless of
2562  * this setting. By default a #WebKitWebView is not editable.
2563
2564  * Normally, an HTML document is not editable unless the elements within the
2565  * document are editable. This function provides a low-level way to make the
2566  * contents of a #WebKitWebView editable without altering the document or DOM
2567  * structure.
2568  */
2569 void webkit_web_view_set_editable(WebKitWebView* webView, gboolean flag)
2570 {
2571     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2572
2573     WebKitWebViewPrivate* priv = webView->priv;
2574
2575     Frame* frame = core(webView)->mainFrame();
2576     g_return_if_fail(frame);
2577
2578     // TODO: What happens when the frame is replaced?
2579     flag = flag != FALSE;
2580     if (flag == priv->editable)
2581         return;
2582
2583     priv->editable = flag;
2584
2585     if (flag) {
2586         frame->applyEditingStyleToBodyElement();
2587         // TODO: If the WebKitWebView is made editable and the selection is empty, set it to something.
2588         //if (!webkit_web_view_get_selected_dom_range(webView))
2589         //    mainFrame->setSelectionFromNone();
2590     } else
2591         frame->removeEditingStyleFromBodyElement();
2592     g_object_notify(G_OBJECT(webView), "editable");
2593 }
2594
2595 /**
2596  * webkit_web_view_get_copy_target_list:
2597  * @web_view: a #WebKitWebView
2598  *
2599  * This function returns the list of targets this #WebKitWebView can
2600  * provide for clipboard copying and as DND source. The targets in the list are
2601  * added with %info values from the #WebKitWebViewTargetInfo enum,
2602  * using gtk_target_list_add() and
2603  * gtk_target_list_add_text_targets().
2604  *
2605  * Return value: the #GtkTargetList
2606  **/
2607 GtkTargetList* webkit_web_view_get_copy_target_list(WebKitWebView* webView)
2608 {
2609     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2610
2611     WebKitWebViewPrivate* priv = webView->priv;
2612     return priv->copy_target_list;
2613 }
2614
2615 /**
2616  * webkit_web_view_get_paste_target_list:
2617  * @web_view: a #WebKitWebView
2618  *
2619  * This function returns the list of targets this #WebKitWebView can
2620  * provide for clipboard pasting and as DND destination. The targets in the list are
2621  * added with %info values from the #WebKitWebViewTargetInfo enum,
2622  * using gtk_target_list_add() and
2623  * gtk_target_list_add_text_targets().
2624  *
2625  * Return value: the #GtkTargetList
2626  **/
2627 GtkTargetList* webkit_web_view_get_paste_target_list(WebKitWebView* webView)
2628 {
2629     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2630
2631     WebKitWebViewPrivate* priv = webView->priv;
2632     return priv->paste_target_list;
2633 }
2634
2635 /**
2636  * webkit_web_view_can_show_mime_type:
2637  * @web_view: a #WebKitWebView
2638  * @mime_type: a MIME type
2639  *
2640  * This functions returns whether or not a MIME type can be displayed using this view.
2641  *
2642  * Return value: a #gboolean indicating if the MIME type can be displayed
2643  *
2644  * Since: 1.0.3
2645  **/
2646
2647 gboolean webkit_web_view_can_show_mime_type(WebKitWebView* webView, const gchar* mimeType)
2648 {
2649     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2650
2651     Frame* frame = core(webkit_web_view_get_main_frame(webView));
2652     if (FrameLoader* loader = frame->loader())
2653         return loader->canShowMIMEType(String::fromUTF8(mimeType));
2654     else
2655         return FALSE;
2656 }
2657
2658 /**
2659  * webkit_web_view_get_transparent:
2660  * @web_view: a #WebKitWebView
2661  *
2662  * Returns whether the #WebKitWebView has a transparent background.
2663  *
2664  * Return value: %FALSE when the #WebKitWebView draws a solid background
2665  * (the default), otherwise %TRUE.
2666  */
2667 gboolean webkit_web_view_get_transparent(WebKitWebView* webView)
2668 {
2669     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2670
2671     WebKitWebViewPrivate* priv = webView->priv;
2672     return priv->transparent;
2673 }
2674
2675 /**
2676  * webkit_web_view_set_transparent:
2677  * @web_view: a #WebKitWebView
2678  *
2679  * Sets whether the #WebKitWebView has a transparent background.
2680  *
2681  * Pass %FALSE to have the #WebKitWebView draw a solid background
2682  * (the default), otherwise %TRUE.
2683  */
2684 void webkit_web_view_set_transparent(WebKitWebView* webView, gboolean flag)
2685 {
2686     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2687
2688     WebKitWebViewPrivate* priv = webView->priv;
2689     priv->transparent = flag;
2690
2691     // TODO: This needs to be made persistent or it could become a problem when
2692     // the main frame is replaced.
2693     Frame* frame = core(webView)->mainFrame();
2694     g_return_if_fail(frame);
2695     frame->view()->setTransparent(flag);
2696     g_object_notify(G_OBJECT(webView), "transparent");
2697 }
2698
2699 /**
2700  * webkit_web_view_get_zoom_level:
2701  * @web_view: a #WebKitWebView
2702  *
2703  * Returns the zoom level of @web_view, i.e. the factor by which elements in
2704  * the page are scaled with respect to their original size.
2705  * If the "full-content-zoom" property is set to %FALSE (the default)
2706  * the zoom level changes the text size, or if %TRUE, scales all
2707  * elements in the page.
2708  *
2709  * Return value: the zoom level of @web_view
2710  *
2711  * Since: 1.0.1
2712  */
2713 gfloat webkit_web_view_get_zoom_level(WebKitWebView* webView)
2714 {
2715     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 1.0f);
2716
2717     Frame* frame = core(webView)->mainFrame();
2718     if (!frame)
2719         return 1.0f;
2720
2721     return frame->zoomFactor();
2722 }
2723
2724 static void webkit_web_view_apply_zoom_level(WebKitWebView* webView, gfloat zoomLevel)
2725 {
2726     Frame* frame = core(webView)->mainFrame();
2727     if (!frame)
2728         return;
2729
2730     WebKitWebViewPrivate* priv = webView->priv;
2731     frame->setZoomFactor(zoomLevel, !priv->zoomFullContent);
2732 }
2733
2734 /**
2735  * webkit_web_view_set_zoom_level:
2736  * @web_view: a #WebKitWebView
2737  * @zoom_level: the new zoom level
2738  *
2739  * Sets the zoom level of @web_view, i.e. the factor by which elements in
2740  * the page are scaled with respect to their original size.
2741  * If the "full-content-zoom" property is set to %FALSE (the default)
2742  * the zoom level changes the text size, or if %TRUE, scales all
2743  * elements in the page.
2744  *
2745  * Since: 1.0.1
2746  */
2747 void webkit_web_view_set_zoom_level(WebKitWebView* webView, gfloat zoomLevel)
2748 {
2749     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2750
2751     webkit_web_view_apply_zoom_level(webView, zoomLevel);
2752     g_object_notify(G_OBJECT(webView), "zoom-level");
2753 }
2754
2755 /**
2756  * webkit_web_view_zoom_in:
2757  * @web_view: a #WebKitWebView
2758  *
2759  * Increases the zoom level of @web_view. The current zoom
2760  * level is incremented by the value of the "zoom-step"
2761  * property of the #WebKitWebSettings associated with @web_view.
2762  *
2763  * Since: 1.0.1
2764  */
2765 void webkit_web_view_zoom_in(WebKitWebView* webView)
2766 {
2767     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2768
2769     WebKitWebViewPrivate* priv = webView->priv;
2770     gfloat zoomMultiplierRatio;
2771     g_object_get(priv->webSettings, "zoom-step", &zoomMultiplierRatio, NULL);
2772
2773     webkit_web_view_set_zoom_level(webView, webkit_web_view_get_zoom_level(webView) + zoomMultiplierRatio);
2774 }
2775
2776 /**
2777  * webkit_web_view_zoom_out:
2778  * @web_view: a #WebKitWebView
2779  *
2780  * Decreases the zoom level of @web_view. The current zoom
2781  * level is decremented by the value of the "zoom-step"
2782  * property of the #WebKitWebSettings associated with @web_view.
2783  *
2784  * Since: 1.0.1
2785  */
2786 void webkit_web_view_zoom_out(WebKitWebView* webView)
2787 {
2788     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2789
2790     WebKitWebViewPrivate* priv = webView->priv;
2791     gfloat zoomMultiplierRatio;
2792     g_object_get(priv->webSettings, "zoom-step", &zoomMultiplierRatio, NULL);
2793
2794     webkit_web_view_set_zoom_level(webView, webkit_web_view_get_zoom_level(webView) - zoomMultiplierRatio);
2795 }
2796
2797 /**
2798  * webkit_web_view_get_full_content_zoom:
2799  * @web_view: a #WebKitWebView
2800  *
2801  * Returns whether the zoom level affects only text or all elements.
2802  *
2803  * Return value: %FALSE if only text should be scaled (the default),
2804  * %TRUE if the full content of the view should be scaled.
2805  *
2806  * Since: 1.0.1
2807  */
2808 gboolean webkit_web_view_get_full_content_zoom(WebKitWebView* webView)
2809 {
2810     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2811
2812     WebKitWebViewPrivate* priv = webView->priv;
2813     return priv->zoomFullContent;
2814 }
2815
2816 /**
2817  * webkit_web_view_set_full_content_zoom:
2818  * @web_view: a #WebKitWebView
2819  * @full_content_zoom: %FALSE if only text should be scaled (the default),
2820  * %TRUE if the full content of the view should be scaled.
2821  *
2822  * Sets whether the zoom level affects only text or all elements.
2823  *
2824  * Since: 1.0.1
2825  */
2826 void webkit_web_view_set_full_content_zoom(WebKitWebView* webView, gboolean zoomFullContent)
2827 {
2828     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2829
2830     WebKitWebViewPrivate* priv = webView->priv;
2831     if (priv->zoomFullContent == zoomFullContent)
2832       return;
2833
2834     priv->zoomFullContent = zoomFullContent;
2835     webkit_web_view_apply_zoom_level(webView, webkit_web_view_get_zoom_level(webView));
2836
2837     g_object_notify(G_OBJECT(webView), "full-content-zoom");
2838 }
2839
2840 /**
2841  * webkit_get_default_session:
2842  *
2843  * Retrieves the default #SoupSession used by all web views.
2844  * Note that the session features are added by WebKit on demand,
2845  * so if you insert your own #SoupCookieJar before any network
2846  * traffic occurs, WebKit will use it instead of the default.
2847  *
2848  * Return value: the default #SoupSession
2849  *
2850  * Since: 1.1.1
2851  */
2852 SoupSession* webkit_get_default_session ()
2853 {
2854     return ResourceHandle::defaultSession();
2855 }
2856
2857 }
2858
2859 /**
2860  * webkit_web_view_get_encoding:
2861  * @web_view: a #WebKitWebView
2862  *
2863  * Returns the default encoding of the #WebKitWebView.
2864  *
2865  * Return value: the default encoding
2866  *
2867  * Since: 1.1.1
2868  */
2869 const gchar* webkit_web_view_get_encoding(WebKitWebView* webView)
2870 {
2871     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2872
2873     String encoding = core(webView)->mainFrame()->loader()->encoding();
2874
2875     if (!encoding.isEmpty()) {
2876         WebKitWebViewPrivate* priv = webView->priv;
2877         g_free(priv->encoding);
2878         priv->encoding = g_strdup(encoding.utf8().data());
2879         return priv->encoding;
2880     } else
2881       return NULL;
2882 }
2883
2884 /**
2885  * webkit_web_view_set_custom_encoding:
2886  * @web_view: a #WebKitWebView
2887  * @encoding: the new encoding, or %NULL to restore the default encoding
2888  *
2889  * Sets the current #WebKitWebView encoding, without modifying the default one,
2890  * and reloads the page.
2891  *
2892  * Since: 1.1.1
2893  */
2894 void webkit_web_view_set_custom_encoding(WebKitWebView* webView, const char* encoding)
2895 {
2896     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2897
2898     core(webView)->mainFrame()->loader()->reloadWithOverrideEncoding(String::fromUTF8(encoding));
2899 }
2900
2901 /**
2902  * webkit_web_view_get_custom_encoding:
2903  * @web_view: a #WebKitWebView
2904  *
2905  * Returns the current encoding of the #WebKitWebView, not the default-encoding
2906  * of WebKitWebSettings.
2907  *
2908  * Return value: a string containing the current custom encoding for @web_view, or %NULL if there's none set.
2909  *
2910  * Since: 1.1.1
2911  */
2912 const char* webkit_web_view_get_custom_encoding(WebKitWebView* webView)
2913 {
2914     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2915
2916     String overrideEncoding = core(webView)->mainFrame()->loader()->documentLoader()->overrideEncoding();
2917
2918     if (!overrideEncoding.isEmpty()) {
2919         WebKitWebViewPrivate* priv = webView->priv;
2920         g_free (priv->customEncoding);
2921         priv->customEncoding = g_strdup(overrideEncoding.utf8().data());
2922         return priv->customEncoding;
2923     } else
2924       return NULL;
2925 }