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