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