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 // We can be called from webkit_web_view_dispose() during the window
36 // destruction, don't use half-destroyed object in this case.
37 if ( webKitCtrl
->IsBeingDeleted() )
40 wxString url
= webKitCtrl
->GetCurrentURL();
42 WebKitLoadStatus status
;
43 g_object_get(G_OBJECT(widget
), "load-status", &status
, NULL
);
45 wxString target
; // TODO: get target (if possible)
47 if (status
== WEBKIT_LOAD_FINISHED
)
49 WebKitWebBackForwardList
* hist
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(widget
));
50 WebKitWebHistoryItem
* item
= webkit_web_back_forward_list_get_current_item(hist
);
51 //We have to check if we are actually storing history
52 //If the item isn't added we add it ourselves, it isn't added otherwise
53 //with a custom scheme.
54 if(WEBKIT_IS_WEB_HISTORY_ITEM(item
) && webkit_web_history_item_get_uri(item
) != url
)
57 newitem
= webkit_web_history_item_new_with_data
60 webKitCtrl
->GetCurrentTitle().utf8_str()
62 webkit_web_back_forward_list_add_item(hist
, newitem
);
65 webKitCtrl
->m_busy
= false;
66 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
,
70 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
71 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
73 else if (status
== WEBKIT_LOAD_COMMITTED
)
75 webKitCtrl
->m_busy
= true;
76 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
80 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
81 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
86 wxgtk_webview_webkit_navigation(WebKitWebView
*,
87 WebKitWebFrame
*frame
,
88 WebKitNetworkRequest
*request
,
89 WebKitWebNavigationAction
*,
90 WebKitWebPolicyDecision
*policy_decision
,
91 wxWebViewWebKit
*webKitCtrl
)
93 if(webKitCtrl
->m_guard
)
95 webKitCtrl
->m_guard
= false;
96 //We set this to make sure that we don't try to load the page again from
97 //the resource request callback
98 webKitCtrl
->m_vfsurl
= webkit_network_request_get_uri(request
);
99 webkit_web_policy_decision_use(policy_decision
);
103 webKitCtrl
->m_busy
= true;
105 const gchar
* uri
= webkit_network_request_get_uri(request
);
107 wxString target
= webkit_web_frame_get_name (frame
);
108 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
110 wxString( uri
, wxConvUTF8
),
113 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
114 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
116 if (!event
.IsAllowed())
118 webKitCtrl
->m_busy
= false;
119 webkit_web_policy_decision_ignore(policy_decision
);
124 wxString wxuri
= uri
;
125 wxSharedPtr
<wxWebViewHandler
> handler
;
126 wxVector
<wxSharedPtr
<wxWebViewHandler
> > hanlders
= webKitCtrl
->GetHandlers();
127 //We are not vetoed so see if we match one of the additional handlers
128 for(wxVector
<wxSharedPtr
<wxWebViewHandler
> >::iterator it
= hanlders
.begin();
129 it
!= hanlders
.end(); ++it
)
131 if(wxuri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
136 //If we found a handler we can then use it to load the file directly
140 webKitCtrl
->m_guard
= true;
141 wxFSFile
* file
= handler
->GetFile(wxuri
);
144 webKitCtrl
->SetPage(*file
->GetStream(), wxuri
);
146 //We need to throw some sort of error here if file is NULL
147 webkit_web_policy_decision_ignore(policy_decision
);
155 wxgtk_webview_webkit_error(WebKitWebView
*,
159 wxWebViewWebKit
* webKitWindow
)
161 webKitWindow
->m_busy
= false;
162 wxWebViewNavigationError type
= wxWEB_NAV_ERR_OTHER
;
164 GError
* error
= (GError
*)web_error
;
165 wxString
description(error
->message
, wxConvUTF8
);
167 if (strcmp(g_quark_to_string(error
->domain
), "soup_http_error_quark") == 0)
171 case SOUP_STATUS_CANCELLED
:
172 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
175 case SOUP_STATUS_CANT_RESOLVE
:
176 case SOUP_STATUS_NOT_FOUND
:
177 type
= wxWEB_NAV_ERR_NOT_FOUND
;
180 case SOUP_STATUS_CANT_RESOLVE_PROXY
:
181 case SOUP_STATUS_CANT_CONNECT
:
182 case SOUP_STATUS_CANT_CONNECT_PROXY
:
183 case SOUP_STATUS_SSL_FAILED
:
184 case SOUP_STATUS_IO_ERROR
:
185 type
= wxWEB_NAV_ERR_CONNECTION
;
188 case SOUP_STATUS_MALFORMED
:
189 //case SOUP_STATUS_TOO_MANY_REDIRECTS:
190 type
= wxWEB_NAV_ERR_REQUEST
;
193 //case SOUP_STATUS_NO_CONTENT:
194 //case SOUP_STATUS_RESET_CONTENT:
196 case SOUP_STATUS_BAD_REQUEST
:
197 type
= wxWEB_NAV_ERR_REQUEST
;
200 case SOUP_STATUS_UNAUTHORIZED
:
201 case SOUP_STATUS_FORBIDDEN
:
202 type
= wxWEB_NAV_ERR_AUTH
;
205 case SOUP_STATUS_METHOD_NOT_ALLOWED
:
206 case SOUP_STATUS_NOT_ACCEPTABLE
:
207 type
= wxWEB_NAV_ERR_SECURITY
;
210 case SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED
:
211 type
= wxWEB_NAV_ERR_AUTH
;
214 case SOUP_STATUS_REQUEST_TIMEOUT
:
215 type
= wxWEB_NAV_ERR_CONNECTION
;
218 //case SOUP_STATUS_PAYMENT_REQUIRED:
219 case SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE
:
220 case SOUP_STATUS_REQUEST_URI_TOO_LONG
:
221 case SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE
:
222 type
= wxWEB_NAV_ERR_REQUEST
;
225 case SOUP_STATUS_BAD_GATEWAY
:
226 case SOUP_STATUS_SERVICE_UNAVAILABLE
:
227 case SOUP_STATUS_GATEWAY_TIMEOUT
:
228 type
= wxWEB_NAV_ERR_CONNECTION
;
231 case SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED
:
232 type
= wxWEB_NAV_ERR_REQUEST
;
234 //case SOUP_STATUS_INSUFFICIENT_STORAGE:
235 //case SOUP_STATUS_NOT_EXTENDED:
238 else if (strcmp(g_quark_to_string(error
->domain
),
239 "webkit-network-error-quark") == 0)
243 //WEBKIT_NETWORK_ERROR_FAILED:
244 //WEBKIT_NETWORK_ERROR_TRANSPORT:
246 case WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL
:
247 type
= wxWEB_NAV_ERR_REQUEST
;
250 case WEBKIT_NETWORK_ERROR_CANCELLED
:
251 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
254 case WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST
:
255 type
= wxWEB_NAV_ERR_NOT_FOUND
;
259 else if (strcmp(g_quark_to_string(error
->domain
),
260 "webkit-policy-error-quark") == 0)
264 //case WEBKIT_POLICY_ERROR_FAILED:
265 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE:
266 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_URL:
267 //case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE:
268 case WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT
:
269 type
= wxWEB_NAV_ERR_SECURITY
;
274 webkit_plugin_error_quark
277 printf("Error domain %s\n", g_quark_to_string(error->domain));
281 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
,
282 webKitWindow
->GetId(),
284 event
.SetString(description
);
287 if (webKitWindow
&& webKitWindow
->GetEventHandler())
289 webKitWindow
->GetEventHandler()->ProcessEvent(event
);
296 wxgtk_webview_webkit_new_window(WebKitWebView
*,
297 WebKitWebFrame
*frame
,
298 WebKitNetworkRequest
*request
,
299 WebKitWebNavigationAction
*,
300 WebKitWebPolicyDecision
*policy_decision
,
301 wxWebViewWebKit
*webKitCtrl
)
303 const gchar
* uri
= webkit_network_request_get_uri(request
);
305 wxString target
= webkit_web_frame_get_name (frame
);
306 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
308 wxString( uri
, wxConvUTF8
),
311 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
312 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
314 //We always want the user to handle this themselves
315 webkit_web_policy_decision_ignore(policy_decision
);
320 wxgtk_webview_webkit_title_changed(WebKitWebView
*,
323 wxWebViewWebKit
*webKitCtrl
)
325 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
327 webKitCtrl
->GetCurrentURL(),
329 event
.SetString(wxString(title
, wxConvUTF8
));
331 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
332 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
337 wxgtk_webview_webkit_resource_req(WebKitWebView
*,
340 WebKitNetworkRequest
*request
,
341 WebKitNetworkResponse
*,
342 wxWebViewWebKit
*webKitCtrl
)
344 wxString uri
= webkit_network_request_get_uri(request
);
346 wxSharedPtr
<wxWebViewHandler
> handler
;
347 wxVector
<wxSharedPtr
<wxWebViewHandler
> > hanlders
= webKitCtrl
->GetHandlers();
349 //We are not vetoed so see if we match one of the additional handlers
350 for(wxVector
<wxSharedPtr
<wxWebViewHandler
> >::iterator it
= hanlders
.begin();
351 it
!= hanlders
.end(); ++it
)
353 if(uri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
358 //If we found a handler we can then use it to load the file directly
362 //If it is requsting the page itself then return as we have already
363 //loaded it from the archive
364 if(webKitCtrl
->m_vfsurl
== uri
)
367 wxFSFile
* file
= handler
->GetFile(uri
);
370 //We load the data into a data url to save it being written out again
371 size_t size
= file
->GetStream()->GetLength();
372 char *buffer
= new char[size
];
373 file
->GetStream()->Read(buffer
, size
);
374 wxString data
= wxBase64Encode(buffer
, size
);
376 wxString mime
= file
->GetMimeType();
377 wxString path
= "data:" + mime
+ ";base64," + data
;
378 //Then we can redirect the call
379 webkit_network_request_set_uri(request
, path
.utf8_str());
387 //-----------------------------------------------------------------------------
389 //-----------------------------------------------------------------------------
391 wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit
, wxWebView
);
393 bool wxWebViewWebKit::Create(wxWindow
*parent
,
399 const wxString
& name
)
404 if (!PreCreation( parent
, pos
, size
) ||
405 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
407 wxFAIL_MSG( wxT("wxWebViewWebKit creation failed") );
411 m_widget
= gtk_scrolled_window_new(NULL
, NULL
);
412 g_object_ref(m_widget
);
413 m_web_view
= WEBKIT_WEB_VIEW(webkit_web_view_new());
415 /* Place the WebKitWebView in the GtkScrolledWindow */
416 gtk_container_add(GTK_CONTAINER(m_widget
), GTK_WIDGET(m_web_view
));
417 gtk_widget_show(GTK_WIDGET(m_web_view
));
419 g_signal_connect_after(m_web_view
, "navigation-policy-decision-requested",
420 G_CALLBACK(wxgtk_webview_webkit_navigation
),
422 g_signal_connect_after(m_web_view
, "load-error",
423 G_CALLBACK(wxgtk_webview_webkit_error
),
426 g_signal_connect_after(m_web_view
, "new-window-policy-decision-requested",
427 G_CALLBACK(wxgtk_webview_webkit_new_window
), this);
429 g_signal_connect_after(m_web_view
, "title-changed",
430 G_CALLBACK(wxgtk_webview_webkit_title_changed
), this);
432 g_signal_connect_after(m_web_view
, "resource-request-starting",
433 G_CALLBACK(wxgtk_webview_webkit_resource_req
), this);
435 m_parent
->DoAddChild( this );
440 webkit_web_view_load_uri(m_web_view
, url
.utf8_str());
442 //Get the initial history limit so we can enable and disable it later
443 WebKitWebBackForwardList
* history
;
444 history
= webkit_web_view_get_back_forward_list(m_web_view
);
445 m_historyLimit
= webkit_web_back_forward_list_get_limit(history
);
447 // last to avoid getting signal too early
448 g_signal_connect_after(m_web_view
, "notify::load-status",
449 G_CALLBACK(wxgtk_webview_webkit_load_status
),
455 wxWebViewWebKit::~wxWebViewWebKit()
457 // The main goal here is to set m_isBeingDeleted to true to avoid the use
458 // of this -- already half-destroyed -- object from WebKit callbacks, but
459 // just setting it would prevent wxWindowDestroyEvent from being sent, so
460 // send it now instead.
464 bool wxWebViewWebKit::Enable( bool enable
)
466 if (!wxControl::Enable(enable
))
469 gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(m_widget
)), enable
);
472 // GTKFixSensitivity();
478 wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
480 GdkWindow
* window
= gtk_widget_get_parent_window(m_widget
);
484 void wxWebViewWebKit::ZoomIn()
486 webkit_web_view_zoom_in(m_web_view
);
489 void wxWebViewWebKit::ZoomOut()
491 webkit_web_view_zoom_out(m_web_view
);
494 void wxWebViewWebKit::SetWebkitZoom(float level
)
496 webkit_web_view_set_zoom_level(m_web_view
, level
);
499 float wxWebViewWebKit::GetWebkitZoom() const
501 return webkit_web_view_get_zoom_level(m_web_view
);
504 void wxWebViewWebKit::Stop()
506 webkit_web_view_stop_loading(m_web_view
);
509 void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags
)
511 if (flags
& wxWEB_VIEW_RELOAD_NO_CACHE
)
513 webkit_web_view_reload_bypass_cache(m_web_view
);
517 webkit_web_view_reload(m_web_view
);
521 void wxWebViewWebKit::LoadURL(const wxString
& url
)
523 webkit_web_view_load_uri(m_web_view
, wxGTK_CONV(url
));
527 void wxWebViewWebKit::GoBack()
529 webkit_web_view_go_back(m_web_view
);
532 void wxWebViewWebKit::GoForward()
534 webkit_web_view_go_forward(m_web_view
);
538 bool wxWebViewWebKit::CanGoBack() const
540 return webkit_web_view_can_go_back(m_web_view
);
544 bool wxWebViewWebKit::CanGoForward() const
546 return webkit_web_view_can_go_forward(m_web_view
);
549 void wxWebViewWebKit::ClearHistory()
551 WebKitWebBackForwardList
* history
;
552 history
= webkit_web_view_get_back_forward_list(m_web_view
);
553 webkit_web_back_forward_list_clear(history
);
556 void wxWebViewWebKit::EnableHistory(bool enable
)
558 WebKitWebBackForwardList
* history
;
559 history
= webkit_web_view_get_back_forward_list(m_web_view
);
562 webkit_web_back_forward_list_set_limit(history
, m_historyLimit
);
566 webkit_web_back_forward_list_set_limit(history
, 0);
570 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewWebKit::GetBackwardHistory()
572 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > backhist
;
573 WebKitWebBackForwardList
* history
;
574 history
= webkit_web_view_get_back_forward_list(m_web_view
);
575 GList
* list
= webkit_web_back_forward_list_get_back_list_with_limit(history
,
577 //We need to iterate in reverse to get the order we desire
578 for(int i
= g_list_length(list
) - 1; i
>= 0 ; i
--)
580 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
581 wxWebViewHistoryItem
* wxitem
= new wxWebViewHistoryItem(
582 webkit_web_history_item_get_uri(gtkitem
),
583 webkit_web_history_item_get_title(gtkitem
));
584 wxitem
->m_histItem
= gtkitem
;
585 wxSharedPtr
<wxWebViewHistoryItem
> item(wxitem
);
586 backhist
.push_back(item
);
591 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewWebKit::GetForwardHistory()
593 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > forwardhist
;
594 WebKitWebBackForwardList
* history
;
595 history
= webkit_web_view_get_back_forward_list(m_web_view
);
596 GList
* list
= webkit_web_back_forward_list_get_forward_list_with_limit(history
,
598 for(guint i
= 0; i
< g_list_length(list
); i
++)
600 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
601 wxWebViewHistoryItem
* wxitem
= new wxWebViewHistoryItem(
602 webkit_web_history_item_get_uri(gtkitem
),
603 webkit_web_history_item_get_title(gtkitem
));
604 wxitem
->m_histItem
= gtkitem
;
605 wxSharedPtr
<wxWebViewHistoryItem
> item(wxitem
);
606 forwardhist
.push_back(item
);
611 void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
)
613 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)item
->m_histItem
;
616 webkit_web_view_go_to_back_forward_item(m_web_view
,
617 WEBKIT_WEB_HISTORY_ITEM(gtkitem
));
621 bool wxWebViewWebKit::CanCut() const
623 return webkit_web_view_can_cut_clipboard(m_web_view
);
626 bool wxWebViewWebKit::CanCopy() const
628 return webkit_web_view_can_copy_clipboard(m_web_view
);
631 bool wxWebViewWebKit::CanPaste() const
633 return webkit_web_view_can_paste_clipboard(m_web_view
);
636 void wxWebViewWebKit::Cut()
638 webkit_web_view_cut_clipboard(m_web_view
);
641 void wxWebViewWebKit::Copy()
643 webkit_web_view_copy_clipboard(m_web_view
);
646 void wxWebViewWebKit::Paste()
648 webkit_web_view_paste_clipboard(m_web_view
);
651 bool wxWebViewWebKit::CanUndo() const
653 return webkit_web_view_can_undo(m_web_view
);
656 bool wxWebViewWebKit::CanRedo() const
658 return webkit_web_view_can_redo(m_web_view
);
661 void wxWebViewWebKit::Undo()
663 webkit_web_view_undo(m_web_view
);
666 void wxWebViewWebKit::Redo()
668 webkit_web_view_redo(m_web_view
);
671 wxString
wxWebViewWebKit::GetCurrentURL() const
673 // FIXME: check which encoding the web kit control uses instead of
674 // assuming UTF8 (here and elsewhere too)
675 return wxString::FromUTF8(webkit_web_view_get_uri(m_web_view
));
679 wxString
wxWebViewWebKit::GetCurrentTitle() const
681 return wxString::FromUTF8(webkit_web_view_get_title(m_web_view
));
685 wxString
wxWebViewWebKit::GetPageSource() const
687 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(m_web_view
);
688 WebKitWebDataSource
* src
= webkit_web_frame_get_data_source (frame
);
690 // TODO: check encoding with
692 // webkit_web_data_source_get_encoding(WebKitWebDataSource *data_source);
693 return wxString(webkit_web_data_source_get_data (src
)->str
, wxConvUTF8
);
697 wxWebViewZoom
wxWebViewWebKit::GetZoom() const
699 float zoom
= GetWebkitZoom();
701 // arbitrary way to map float zoom to our common zoom enum
704 return wxWEB_VIEW_ZOOM_TINY
;
706 else if (zoom
> 0.65 && zoom
<= 0.90)
708 return wxWEB_VIEW_ZOOM_SMALL
;
710 else if (zoom
> 0.90 && zoom
<= 1.15)
712 return wxWEB_VIEW_ZOOM_MEDIUM
;
714 else if (zoom
> 1.15 && zoom
<= 1.45)
716 return wxWEB_VIEW_ZOOM_LARGE
;
718 else if (zoom
> 1.45)
720 return wxWEB_VIEW_ZOOM_LARGEST
;
723 // to shut up compilers, this can never be reached logically
725 return wxWEB_VIEW_ZOOM_MEDIUM
;
729 void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom
)
731 // arbitrary way to map our common zoom enum to float zoom
734 case wxWEB_VIEW_ZOOM_TINY
:
738 case wxWEB_VIEW_ZOOM_SMALL
:
742 case wxWEB_VIEW_ZOOM_MEDIUM
:
746 case wxWEB_VIEW_ZOOM_LARGE
:
750 case wxWEB_VIEW_ZOOM_LARGEST
:
759 void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type
)
761 webkit_web_view_set_full_content_zoom(m_web_view
,
762 (type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
?
766 wxWebViewZoomType
wxWebViewWebKit::GetZoomType() const
768 gboolean fczoom
= webkit_web_view_get_full_content_zoom(m_web_view
);
770 if (fczoom
) return wxWEB_VIEW_ZOOM_TYPE_LAYOUT
;
771 else return wxWEB_VIEW_ZOOM_TYPE_TEXT
;
774 bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType
) const
776 // this port supports all zoom types
780 void wxWebViewWebKit::DoSetPage(const wxString
& html
, const wxString
& baseUri
)
782 webkit_web_view_load_string (m_web_view
,
783 html
.mb_str(wxConvUTF8
),
786 baseUri
.mb_str(wxConvUTF8
));
789 void wxWebViewWebKit::Print()
791 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(m_web_view
);
792 webkit_web_frame_print (frame
);
794 // GtkPrintOperationResult webkit_web_frame_print_full
795 // (WebKitWebFrame *frame,
796 // GtkPrintOperation *operation,
797 // GtkPrintOperationAction action,
803 bool wxWebViewWebKit::IsBusy() const
807 // This code looks nice but returns true after a page was cancelled
809 WebKitLoadStatus status = webkit_web_view_get_load_status
810 (WEBKIT_WEB_VIEW(web_view));
813 #if WEBKIT_CHECK_VERSION(1,1,16)
814 // WEBKIT_LOAD_FAILED is new in webkit 1.1.16
815 if (status == WEBKIT_LOAD_FAILED)
820 if (status == WEBKIT_LOAD_FINISHED)
829 void wxWebViewWebKit::SetEditable(bool enable
)
831 webkit_web_view_set_editable(m_web_view
, enable
);
834 bool wxWebViewWebKit::IsEditable() const
836 return webkit_web_view_get_editable(m_web_view
);
839 void wxWebViewWebKit::DeleteSelection()
841 webkit_web_view_delete_selection(m_web_view
);
844 bool wxWebViewWebKit::HasSelection() const
846 return webkit_web_view_has_selection(m_web_view
);
849 void wxWebViewWebKit::SelectAll()
851 webkit_web_view_select_all(m_web_view
);
854 wxString
wxWebViewWebKit::GetSelectedText() const
856 WebKitDOMDocument
* doc
;
857 WebKitDOMDOMWindow
* win
;
858 WebKitDOMDOMSelection
* sel
;
859 WebKitDOMRange
* range
;
861 doc
= webkit_web_view_get_dom_document(m_web_view
);
862 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
863 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
864 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
866 return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range
)),
870 wxString
wxWebViewWebKit::GetSelectedSource() const
872 WebKitDOMDocument
* doc
;
873 WebKitDOMDOMWindow
* win
;
874 WebKitDOMDOMSelection
* sel
;
875 WebKitDOMRange
* range
;
876 WebKitDOMElement
* div
;
877 WebKitDOMDocumentFragment
* clone
;
878 WebKitDOMHTMLElement
* html
;
880 doc
= webkit_web_view_get_dom_document(m_web_view
);
881 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
882 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
883 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
885 div
= webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc
), "div", NULL
);
887 clone
= webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range
), NULL
);
888 webkit_dom_node_append_child(&div
->parent_instance
, &clone
->parent_instance
, NULL
);
889 html
= (WebKitDOMHTMLElement
*)div
;
891 return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html
)),
895 void wxWebViewWebKit::ClearSelection()
897 WebKitDOMDocument
* doc
;
898 WebKitDOMDOMWindow
* win
;
899 WebKitDOMDOMSelection
* sel
;
901 doc
= webkit_web_view_get_dom_document(m_web_view
);
902 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
903 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
904 webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel
));
908 wxString
wxWebViewWebKit::GetPageText() const
910 WebKitDOMDocument
* doc
;
911 WebKitDOMHTMLElement
* body
;
913 doc
= webkit_web_view_get_dom_document(m_web_view
);
914 body
= webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc
));
915 return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body
)),
919 void wxWebViewWebKit::RunScript(const wxString
& javascript
)
921 webkit_web_view_execute_script(m_web_view
,
922 javascript
.mb_str(wxConvUTF8
));
925 void wxWebViewWebKit::RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
)
927 m_handlerList
.push_back(handler
);
932 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
934 return GetDefaultAttributesFromGTKWidget(webkit_web_view_new
);
938 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT