1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/webview_webkit.cpp
3 // Purpose: GTK WebKit backend for web view component
4 // Author: Marianne Gagnon, Robert Roebling
6 // Copyright: (c) 2010 Marianne Gagnon, 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT
15 #include "wx/stockitem.h"
16 #include "wx/gtk/webview_webkit.h"
17 #include "wx/gtk/control.h"
18 #include "wx/gtk/private.h"
19 #include "wx/filesys.h"
20 #include "wx/base64.h"
21 #include <webkit/webkit.h>
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
31 wxgtk_webview_webkit_load_status(GtkWidget
* widget
,
33 wxWebViewWebKit
*webKitCtrl
)
35 wxString url
= webKitCtrl
->GetCurrentURL();
37 WebKitLoadStatus status
;
38 g_object_get(G_OBJECT(widget
), "load-status", &status
, NULL
);
40 wxString target
; // TODO: get target (if possible)
42 if (status
== WEBKIT_LOAD_FINISHED
)
44 WebKitWebBackForwardList
* hist
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(widget
));
45 WebKitWebHistoryItem
* item
= webkit_web_back_forward_list_get_current_item(hist
);
46 //We have to check if we are actually storing history
47 //If the item isn't added we add it ourselves, it isn't added otherwise
48 //with a custom scheme.
49 if(WEBKIT_IS_WEB_HISTORY_ITEM(item
) && webkit_web_history_item_get_uri(item
) != url
)
52 newitem
= webkit_web_history_item_new_with_data
55 webKitCtrl
->GetCurrentTitle().utf8_str()
57 webkit_web_back_forward_list_add_item(hist
, newitem
);
60 webKitCtrl
->m_busy
= false;
61 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
,
65 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
66 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
68 else if (status
== WEBKIT_LOAD_COMMITTED
)
70 webKitCtrl
->m_busy
= true;
71 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
75 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
76 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
81 wxgtk_webview_webkit_navigation(WebKitWebView
*,
82 WebKitWebFrame
*frame
,
83 WebKitNetworkRequest
*request
,
84 WebKitWebNavigationAction
*,
85 WebKitWebPolicyDecision
*policy_decision
,
86 wxWebViewWebKit
*webKitCtrl
)
88 if(webKitCtrl
->m_guard
)
90 webKitCtrl
->m_guard
= false;
91 //We set this to make sure that we don't try to load the page again from
92 //the resource request callback
93 webKitCtrl
->m_vfsurl
= webkit_network_request_get_uri(request
);
94 webkit_web_policy_decision_use(policy_decision
);
98 webKitCtrl
->m_busy
= true;
100 const gchar
* uri
= webkit_network_request_get_uri(request
);
102 wxString target
= webkit_web_frame_get_name (frame
);
103 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
105 wxString( uri
, wxConvUTF8
),
108 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
109 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
111 if (!event
.IsAllowed())
113 webKitCtrl
->m_busy
= false;
114 webkit_web_policy_decision_ignore(policy_decision
);
119 wxString wxuri
= uri
;
120 wxSharedPtr
<wxWebViewHandler
> handler
;
121 wxVector
<wxSharedPtr
<wxWebViewHandler
> > hanlders
= webKitCtrl
->GetHandlers();
122 //We are not vetoed so see if we match one of the additional handlers
123 for(wxVector
<wxSharedPtr
<wxWebViewHandler
> >::iterator it
= hanlders
.begin();
124 it
!= hanlders
.end(); ++it
)
126 if(wxuri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
131 //If we found a handler we can then use it to load the file directly
135 webKitCtrl
->m_guard
= true;
136 wxFSFile
* file
= handler
->GetFile(wxuri
);
139 webKitCtrl
->SetPage(*file
->GetStream(), wxuri
);
141 //We need to throw some sort of error here if file is NULL
142 webkit_web_policy_decision_ignore(policy_decision
);
150 wxgtk_webview_webkit_error(WebKitWebView
*,
154 wxWebViewWebKit
* webKitWindow
)
156 webKitWindow
->m_busy
= false;
157 wxWebViewNavigationError type
= wxWEB_NAV_ERR_OTHER
;
159 GError
* error
= (GError
*)web_error
;
160 wxString
description(error
->message
, wxConvUTF8
);
162 if (strcmp(g_quark_to_string(error
->domain
), "soup_http_error_quark") == 0)
166 case SOUP_STATUS_CANCELLED
:
167 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
170 case SOUP_STATUS_CANT_RESOLVE
:
171 case SOUP_STATUS_NOT_FOUND
:
172 type
= wxWEB_NAV_ERR_NOT_FOUND
;
175 case SOUP_STATUS_CANT_RESOLVE_PROXY
:
176 case SOUP_STATUS_CANT_CONNECT
:
177 case SOUP_STATUS_CANT_CONNECT_PROXY
:
178 case SOUP_STATUS_SSL_FAILED
:
179 case SOUP_STATUS_IO_ERROR
:
180 type
= wxWEB_NAV_ERR_CONNECTION
;
183 case SOUP_STATUS_MALFORMED
:
184 //case SOUP_STATUS_TOO_MANY_REDIRECTS:
185 type
= wxWEB_NAV_ERR_REQUEST
;
188 //case SOUP_STATUS_NO_CONTENT:
189 //case SOUP_STATUS_RESET_CONTENT:
191 case SOUP_STATUS_BAD_REQUEST
:
192 type
= wxWEB_NAV_ERR_REQUEST
;
195 case SOUP_STATUS_UNAUTHORIZED
:
196 case SOUP_STATUS_FORBIDDEN
:
197 type
= wxWEB_NAV_ERR_AUTH
;
200 case SOUP_STATUS_METHOD_NOT_ALLOWED
:
201 case SOUP_STATUS_NOT_ACCEPTABLE
:
202 type
= wxWEB_NAV_ERR_SECURITY
;
205 case SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED
:
206 type
= wxWEB_NAV_ERR_AUTH
;
209 case SOUP_STATUS_REQUEST_TIMEOUT
:
210 type
= wxWEB_NAV_ERR_CONNECTION
;
213 //case SOUP_STATUS_PAYMENT_REQUIRED:
214 case SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE
:
215 case SOUP_STATUS_REQUEST_URI_TOO_LONG
:
216 case SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE
:
217 type
= wxWEB_NAV_ERR_REQUEST
;
220 case SOUP_STATUS_BAD_GATEWAY
:
221 case SOUP_STATUS_SERVICE_UNAVAILABLE
:
222 case SOUP_STATUS_GATEWAY_TIMEOUT
:
223 type
= wxWEB_NAV_ERR_CONNECTION
;
226 case SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED
:
227 type
= wxWEB_NAV_ERR_REQUEST
;
229 //case SOUP_STATUS_INSUFFICIENT_STORAGE:
230 //case SOUP_STATUS_NOT_EXTENDED:
233 else if (strcmp(g_quark_to_string(error
->domain
),
234 "webkit-network-error-quark") == 0)
238 //WEBKIT_NETWORK_ERROR_FAILED:
239 //WEBKIT_NETWORK_ERROR_TRANSPORT:
241 case WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL
:
242 type
= wxWEB_NAV_ERR_REQUEST
;
245 case WEBKIT_NETWORK_ERROR_CANCELLED
:
246 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
249 case WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST
:
250 type
= wxWEB_NAV_ERR_NOT_FOUND
;
254 else if (strcmp(g_quark_to_string(error
->domain
),
255 "webkit-policy-error-quark") == 0)
259 //case WEBKIT_POLICY_ERROR_FAILED:
260 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE:
261 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_URL:
262 //case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE:
263 case WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT
:
264 type
= wxWEB_NAV_ERR_SECURITY
;
269 webkit_plugin_error_quark
272 printf("Error domain %s\n", g_quark_to_string(error->domain));
276 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
,
277 webKitWindow
->GetId(),
279 event
.SetString(description
);
282 if (webKitWindow
&& webKitWindow
->GetEventHandler())
284 webKitWindow
->GetEventHandler()->ProcessEvent(event
);
291 wxgtk_webview_webkit_new_window(WebKitWebView
*,
292 WebKitWebFrame
*frame
,
293 WebKitNetworkRequest
*request
,
294 WebKitWebNavigationAction
*,
295 WebKitWebPolicyDecision
*policy_decision
,
296 wxWebViewWebKit
*webKitCtrl
)
298 const gchar
* uri
= webkit_network_request_get_uri(request
);
300 wxString target
= webkit_web_frame_get_name (frame
);
301 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
303 wxString( uri
, wxConvUTF8
),
306 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
307 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
309 //We always want the user to handle this themselves
310 webkit_web_policy_decision_ignore(policy_decision
);
315 wxgtk_webview_webkit_title_changed(WebKitWebView
*,
318 wxWebViewWebKit
*webKitCtrl
)
320 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
322 webKitCtrl
->GetCurrentURL(),
324 event
.SetString(wxString(title
, wxConvUTF8
));
326 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
327 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
332 wxgtk_webview_webkit_resource_req(WebKitWebView
*,
335 WebKitNetworkRequest
*request
,
336 WebKitNetworkResponse
*,
337 wxWebViewWebKit
*webKitCtrl
)
339 wxString uri
= webkit_network_request_get_uri(request
);
341 wxSharedPtr
<wxWebViewHandler
> handler
;
342 wxVector
<wxSharedPtr
<wxWebViewHandler
> > hanlders
= webKitCtrl
->GetHandlers();
344 //We are not vetoed so see if we match one of the additional handlers
345 for(wxVector
<wxSharedPtr
<wxWebViewHandler
> >::iterator it
= hanlders
.begin();
346 it
!= hanlders
.end(); ++it
)
348 if(uri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
353 //If we found a handler we can then use it to load the file directly
357 //If it is requsting the page itself then return as we have already
358 //loaded it from the archive
359 if(webKitCtrl
->m_vfsurl
== uri
)
362 wxFSFile
* file
= handler
->GetFile(uri
);
365 //We load the data into a data url to save it being written out again
366 size_t size
= file
->GetStream()->GetLength();
367 char *buffer
= new char[size
];
368 file
->GetStream()->Read(buffer
, size
);
369 wxString data
= wxBase64Encode(buffer
, size
);
371 wxString mime
= file
->GetMimeType();
372 wxString path
= "data:" + mime
+ ";base64," + data
;
373 //Then we can redirect the call
374 webkit_network_request_set_uri(request
, path
.utf8_str());
382 //-----------------------------------------------------------------------------
384 //-----------------------------------------------------------------------------
386 wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit
, wxWebView
);
388 bool wxWebViewWebKit::Create(wxWindow
*parent
,
394 const wxString
& name
)
399 if (!PreCreation( parent
, pos
, size
) ||
400 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
402 wxFAIL_MSG( wxT("wxWebViewWebKit creation failed") );
406 m_widget
= gtk_scrolled_window_new(NULL
, NULL
);
407 g_object_ref(m_widget
);
408 m_web_view
= WEBKIT_WEB_VIEW(webkit_web_view_new());
410 /* Place the WebKitWebView in the GtkScrolledWindow */
411 gtk_container_add(GTK_CONTAINER(m_widget
), GTK_WIDGET(m_web_view
));
412 gtk_widget_show(GTK_WIDGET(m_web_view
));
414 g_signal_connect_after(m_web_view
, "navigation-policy-decision-requested",
415 G_CALLBACK(wxgtk_webview_webkit_navigation
),
417 g_signal_connect_after(m_web_view
, "load-error",
418 G_CALLBACK(wxgtk_webview_webkit_error
),
421 g_signal_connect_after(m_web_view
, "new-window-policy-decision-requested",
422 G_CALLBACK(wxgtk_webview_webkit_new_window
), this);
424 g_signal_connect_after(m_web_view
, "title-changed",
425 G_CALLBACK(wxgtk_webview_webkit_title_changed
), this);
427 g_signal_connect_after(m_web_view
, "resource-request-starting",
428 G_CALLBACK(wxgtk_webview_webkit_resource_req
), this);
430 m_parent
->DoAddChild( this );
435 webkit_web_view_load_uri(m_web_view
, url
.utf8_str());
437 //Get the initial history limit so we can enable and disable it later
438 WebKitWebBackForwardList
* history
;
439 history
= webkit_web_view_get_back_forward_list(m_web_view
);
440 m_historyLimit
= webkit_web_back_forward_list_get_limit(history
);
442 // last to avoid getting signal too early
443 g_signal_connect_after(m_web_view
, "notify::load-status",
444 G_CALLBACK(wxgtk_webview_webkit_load_status
),
450 bool wxWebViewWebKit::Enable( bool enable
)
452 if (!wxControl::Enable(enable
))
455 gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(m_widget
)), enable
);
458 // GTKFixSensitivity();
464 wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
466 GdkWindow
* window
= gtk_widget_get_parent_window(m_widget
);
470 void wxWebViewWebKit::ZoomIn()
472 webkit_web_view_zoom_in(m_web_view
);
475 void wxWebViewWebKit::ZoomOut()
477 webkit_web_view_zoom_out(m_web_view
);
480 void wxWebViewWebKit::SetWebkitZoom(float level
)
482 webkit_web_view_set_zoom_level(m_web_view
, level
);
485 float wxWebViewWebKit::GetWebkitZoom() const
487 return webkit_web_view_get_zoom_level(m_web_view
);
490 void wxWebViewWebKit::Stop()
492 webkit_web_view_stop_loading(m_web_view
);
495 void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags
)
497 if (flags
& wxWEB_VIEW_RELOAD_NO_CACHE
)
499 webkit_web_view_reload_bypass_cache(m_web_view
);
503 webkit_web_view_reload(m_web_view
);
507 void wxWebViewWebKit::LoadURL(const wxString
& url
)
509 webkit_web_view_load_uri(m_web_view
, wxGTK_CONV(url
));
513 void wxWebViewWebKit::GoBack()
515 webkit_web_view_go_back(m_web_view
);
518 void wxWebViewWebKit::GoForward()
520 webkit_web_view_go_forward(m_web_view
);
524 bool wxWebViewWebKit::CanGoBack() const
526 return webkit_web_view_can_go_back(m_web_view
);
530 bool wxWebViewWebKit::CanGoForward() const
532 return webkit_web_view_can_go_forward(m_web_view
);
535 void wxWebViewWebKit::ClearHistory()
537 WebKitWebBackForwardList
* history
;
538 history
= webkit_web_view_get_back_forward_list(m_web_view
);
539 webkit_web_back_forward_list_clear(history
);
542 void wxWebViewWebKit::EnableHistory(bool enable
)
544 WebKitWebBackForwardList
* history
;
545 history
= webkit_web_view_get_back_forward_list(m_web_view
);
548 webkit_web_back_forward_list_set_limit(history
, m_historyLimit
);
552 webkit_web_back_forward_list_set_limit(history
, 0);
556 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewWebKit::GetBackwardHistory()
558 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > backhist
;
559 WebKitWebBackForwardList
* history
;
560 history
= webkit_web_view_get_back_forward_list(m_web_view
);
561 GList
* list
= webkit_web_back_forward_list_get_back_list_with_limit(history
,
563 //We need to iterate in reverse to get the order we desire
564 for(int i
= g_list_length(list
) - 1; i
>= 0 ; i
--)
566 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
567 wxWebViewHistoryItem
* wxitem
= new wxWebViewHistoryItem(
568 webkit_web_history_item_get_uri(gtkitem
),
569 webkit_web_history_item_get_title(gtkitem
));
570 wxitem
->m_histItem
= gtkitem
;
571 wxSharedPtr
<wxWebViewHistoryItem
> item(wxitem
);
572 backhist
.push_back(item
);
577 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewWebKit::GetForwardHistory()
579 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > forwardhist
;
580 WebKitWebBackForwardList
* history
;
581 history
= webkit_web_view_get_back_forward_list(m_web_view
);
582 GList
* list
= webkit_web_back_forward_list_get_forward_list_with_limit(history
,
584 for(guint i
= 0; i
< g_list_length(list
); i
++)
586 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
587 wxWebViewHistoryItem
* wxitem
= new wxWebViewHistoryItem(
588 webkit_web_history_item_get_uri(gtkitem
),
589 webkit_web_history_item_get_title(gtkitem
));
590 wxitem
->m_histItem
= gtkitem
;
591 wxSharedPtr
<wxWebViewHistoryItem
> item(wxitem
);
592 forwardhist
.push_back(item
);
597 void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
)
599 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)item
->m_histItem
;
602 webkit_web_view_go_to_back_forward_item(m_web_view
,
603 WEBKIT_WEB_HISTORY_ITEM(gtkitem
));
607 bool wxWebViewWebKit::CanCut() const
609 return webkit_web_view_can_cut_clipboard(m_web_view
);
612 bool wxWebViewWebKit::CanCopy() const
614 return webkit_web_view_can_copy_clipboard(m_web_view
);
617 bool wxWebViewWebKit::CanPaste() const
619 return webkit_web_view_can_paste_clipboard(m_web_view
);
622 void wxWebViewWebKit::Cut()
624 webkit_web_view_cut_clipboard(m_web_view
);
627 void wxWebViewWebKit::Copy()
629 webkit_web_view_copy_clipboard(m_web_view
);
632 void wxWebViewWebKit::Paste()
634 webkit_web_view_paste_clipboard(m_web_view
);
637 bool wxWebViewWebKit::CanUndo() const
639 return webkit_web_view_can_undo(m_web_view
);
642 bool wxWebViewWebKit::CanRedo() const
644 return webkit_web_view_can_redo(m_web_view
);
647 void wxWebViewWebKit::Undo()
649 webkit_web_view_undo(m_web_view
);
652 void wxWebViewWebKit::Redo()
654 webkit_web_view_redo(m_web_view
);
657 wxString
wxWebViewWebKit::GetCurrentURL() const
659 // FIXME: check which encoding the web kit control uses instead of
660 // assuming UTF8 (here and elsewhere too)
661 return wxString::FromUTF8(webkit_web_view_get_uri(m_web_view
));
665 wxString
wxWebViewWebKit::GetCurrentTitle() const
667 return wxString::FromUTF8(webkit_web_view_get_title(m_web_view
));
671 wxString
wxWebViewWebKit::GetPageSource() const
673 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(m_web_view
);
674 WebKitWebDataSource
* src
= webkit_web_frame_get_data_source (frame
);
676 // TODO: check encoding with
678 // webkit_web_data_source_get_encoding(WebKitWebDataSource *data_source);
679 return wxString(webkit_web_data_source_get_data (src
)->str
, wxConvUTF8
);
683 wxWebViewZoom
wxWebViewWebKit::GetZoom() const
685 float zoom
= GetWebkitZoom();
687 // arbitrary way to map float zoom to our common zoom enum
690 return wxWEB_VIEW_ZOOM_TINY
;
692 else if (zoom
> 0.65 && zoom
<= 0.90)
694 return wxWEB_VIEW_ZOOM_SMALL
;
696 else if (zoom
> 0.90 && zoom
<= 1.15)
698 return wxWEB_VIEW_ZOOM_MEDIUM
;
700 else if (zoom
> 1.15 && zoom
<= 1.45)
702 return wxWEB_VIEW_ZOOM_LARGE
;
704 else if (zoom
> 1.45)
706 return wxWEB_VIEW_ZOOM_LARGEST
;
709 // to shut up compilers, this can never be reached logically
711 return wxWEB_VIEW_ZOOM_MEDIUM
;
715 void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom
)
717 // arbitrary way to map our common zoom enum to float zoom
720 case wxWEB_VIEW_ZOOM_TINY
:
724 case wxWEB_VIEW_ZOOM_SMALL
:
728 case wxWEB_VIEW_ZOOM_MEDIUM
:
732 case wxWEB_VIEW_ZOOM_LARGE
:
736 case wxWEB_VIEW_ZOOM_LARGEST
:
745 void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type
)
747 webkit_web_view_set_full_content_zoom(m_web_view
,
748 (type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
?
752 wxWebViewZoomType
wxWebViewWebKit::GetZoomType() const
754 gboolean fczoom
= webkit_web_view_get_full_content_zoom(m_web_view
);
756 if (fczoom
) return wxWEB_VIEW_ZOOM_TYPE_LAYOUT
;
757 else return wxWEB_VIEW_ZOOM_TYPE_TEXT
;
760 bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType
) const
762 // this port supports all zoom types
766 void wxWebViewWebKit::SetPage(const wxString
& html
, const wxString
& baseUri
)
768 webkit_web_view_load_string (m_web_view
,
769 html
.mb_str(wxConvUTF8
),
772 baseUri
.mb_str(wxConvUTF8
));
775 void wxWebViewWebKit::Print()
777 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(m_web_view
);
778 webkit_web_frame_print (frame
);
780 // GtkPrintOperationResult webkit_web_frame_print_full
781 // (WebKitWebFrame *frame,
782 // GtkPrintOperation *operation,
783 // GtkPrintOperationAction action,
789 bool wxWebViewWebKit::IsBusy() const
793 // This code looks nice but returns true after a page was cancelled
795 WebKitLoadStatus status = webkit_web_view_get_load_status
796 (WEBKIT_WEB_VIEW(web_view));
799 #if WEBKIT_CHECK_VERSION(1,1,16)
800 // WEBKIT_LOAD_FAILED is new in webkit 1.1.16
801 if (status == WEBKIT_LOAD_FAILED)
806 if (status == WEBKIT_LOAD_FINISHED)
815 void wxWebViewWebKit::SetEditable(bool enable
)
817 webkit_web_view_set_editable(m_web_view
, enable
);
820 bool wxWebViewWebKit::IsEditable() const
822 return webkit_web_view_get_editable(m_web_view
);
825 void wxWebViewWebKit::DeleteSelection()
827 webkit_web_view_delete_selection(m_web_view
);
830 bool wxWebViewWebKit::HasSelection() const
832 return webkit_web_view_has_selection(m_web_view
);
835 void wxWebViewWebKit::SelectAll()
837 webkit_web_view_select_all(m_web_view
);
840 wxString
wxWebViewWebKit::GetSelectedText() const
842 WebKitDOMDocument
* doc
;
843 WebKitDOMDOMWindow
* win
;
844 WebKitDOMDOMSelection
* sel
;
845 WebKitDOMRange
* range
;
847 doc
= webkit_web_view_get_dom_document(m_web_view
);
848 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
849 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
850 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
852 return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range
)),
856 wxString
wxWebViewWebKit::GetSelectedSource() const
858 WebKitDOMDocument
* doc
;
859 WebKitDOMDOMWindow
* win
;
860 WebKitDOMDOMSelection
* sel
;
861 WebKitDOMRange
* range
;
862 WebKitDOMElement
* div
;
863 WebKitDOMDocumentFragment
* clone
;
864 WebKitDOMHTMLElement
* html
;
866 doc
= webkit_web_view_get_dom_document(m_web_view
);
867 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
868 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
869 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
871 div
= webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc
), "div", NULL
);
873 clone
= webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range
), NULL
);
874 webkit_dom_node_append_child(&div
->parent_instance
, &clone
->parent_instance
, NULL
);
875 html
= (WebKitDOMHTMLElement
*)div
;
877 return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html
)),
881 void wxWebViewWebKit::ClearSelection()
883 WebKitDOMDocument
* doc
;
884 WebKitDOMDOMWindow
* win
;
885 WebKitDOMDOMSelection
* sel
;
887 doc
= webkit_web_view_get_dom_document(m_web_view
);
888 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
889 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
890 webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel
));
894 wxString
wxWebViewWebKit::GetPageText() const
896 WebKitDOMDocument
* doc
;
897 WebKitDOMHTMLElement
* body
;
899 doc
= webkit_web_view_get_dom_document(m_web_view
);
900 body
= webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc
));
901 return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body
)),
905 void wxWebViewWebKit::RunScript(const wxString
& javascript
)
907 webkit_web_view_execute_script(m_web_view
,
908 javascript
.mb_str(wxConvUTF8
));
911 void wxWebViewWebKit::RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
)
913 m_handlerList
.push_back(handler
);
918 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
920 return GetDefaultAttributesFromGTKWidget(webkit_web_view_new
);
924 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT