]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/webview_webkit.cpp
Initial implementation of wxWebProtocolHandler and wxWebFileProtocolHandler for the...
[wxWidgets.git] / src / gtk / webview_webkit.cpp
index f81872e41205976b3040823dc304ff98c62fbac1..27879488dfd335910ed958d816f54278067c60e7 100644 (file)
@@ -26,8 +26,9 @@ extern "C"
 {
 
 static void
-wxgtk_webkitctrl_load_status_callback(GtkWidget* widget, GParamSpec*,
-                                      wxWebViewWebKit *webKitCtrl)
+wxgtk_webview_webkit_load_status(GtkWidget* widget, 
+                                 GParamSpec*,
+                                 wxWebViewWebKit *webKitCtrl)
 {
     if (!webKitCtrl->m_ready) return;
 
@@ -60,11 +61,13 @@ wxgtk_webkitctrl_load_status_callback(GtkWidget* widget, GParamSpec*,
     }
 }
 
-static WebKitNavigationResponse
-wxgtk_webkitctrl_navigation_requ_callback(WebKitWebView*,
-                                          WebKitWebFrame       *frame,
-                                          WebKitNetworkRequest *request,
-                                          wxWebViewWebKit      *webKitCtrl)
+static gboolean
+wxgtk_webview_webkit_navigation(WebKitWebView*,
+                                WebKitWebFrame *frame,
+                                WebKitNetworkRequest *request,
+                                WebKitWebNavigationAction*,
+                                WebKitWebPolicyDecision *policy_decision,
+                                wxWebViewWebKit *webKitCtrl)
 {
     webKitCtrl->m_busy = true;
 
@@ -83,20 +86,21 @@ wxgtk_webkitctrl_navigation_requ_callback(WebKitWebView*,
     if (thisEvent.IsVetoed())
     {
         webKitCtrl->m_busy = false;
-        return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
+        webkit_web_policy_decision_ignore(policy_decision);
+        return TRUE;
     }
     else
     {
-        return  WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
+        return FALSE;
     }
 }
 
 static gboolean
-wxgtk_webkitctrl_error (WebKitWebView*,
-                        WebKitWebFrame*,
-                        gchar          *uri,
-                        gpointer        web_error,
-                        wxWebViewWebKit* webKitWindow)
+wxgtk_webview_webkit_error(WebKitWebView*,
+                           WebKitWebFrame*,
+                           gchar *uri,
+                           gpointer web_error,
+                           wxWebViewWebKit* webKitWindow)
 {
     webKitWindow->m_busy = false;
     wxWebNavigationError type = wxWEB_NAV_ERR_OTHER;
@@ -235,12 +239,12 @@ wxgtk_webkitctrl_error (WebKitWebView*,
 }
 
 static gboolean
-wxgtk_webkitctrl_new_window(WebKitWebView*,
-                            WebKitWebFrame *frame,
-                            WebKitNetworkRequest *request,
-                            WebKitWebNavigationAction*,
-                            WebKitWebPolicyDecision *policy_decision,
-                    wxWebViewWebKit *webKitCtrl)
+wxgtk_webview_webkit_new_window(WebKitWebView*,
+                                WebKitWebFrame *frame,
+                                WebKitNetworkRequest *request,
+                                WebKitWebNavigationAction*,
+                                WebKitWebPolicyDecision *policy_decision,
+                                wxWebViewWebKit *webKitCtrl)
 {
     const gchar* uri = webkit_network_request_get_uri(request);
 
@@ -254,14 +258,8 @@ wxgtk_webkitctrl_new_window(WebKitWebView*,
     if (webKitCtrl && webKitCtrl->GetEventHandler())
         webKitCtrl->GetEventHandler()->ProcessEvent(thisEvent);
 
-    if (thisEvent.IsVetoed())
-    {
-        webkit_web_policy_decision_ignore(policy_decision);
-    }
-    else
-    {
-        webkit_web_policy_decision_use(policy_decision);
-    }
+    //We always want the user to handle this themselves
+    webkit_web_policy_decision_ignore(policy_decision);
     return TRUE;
 }
 
@@ -304,17 +302,17 @@ bool wxWebViewWebKit::Create(wxWindow *parent,
     gtk_widget_show(web_view);
 
     g_signal_connect_after(web_view, "notify::load-status",
-                           G_CALLBACK(wxgtk_webkitctrl_load_status_callback),
+                           G_CALLBACK(wxgtk_webview_webkit_load_status),
                            this);
-    g_signal_connect_after(web_view, "navigation-requested",
-                           G_CALLBACK(wxgtk_webkitctrl_navigation_requ_callback),
+    g_signal_connect_after(web_view, "navigation-policy-decision-requested",
+                           G_CALLBACK(wxgtk_webview_webkit_navigation),
                            this);
     g_signal_connect_after(web_view, "load-error", 
-                           G_CALLBACK(wxgtk_webkitctrl_error),
+                           G_CALLBACK(wxgtk_webview_webkit_error),
                            this);
 
     g_signal_connect_after(web_view, "new-window-policy-decision-requested",
-                           G_CALLBACK(wxgtk_webkitctrl_new_window), this);
+                           G_CALLBACK(wxgtk_webview_webkit_new_window), this);
 
     m_parent->DoAddChild( this );
 
@@ -768,6 +766,36 @@ wxString wxWebViewWebKit::GetSelectedSource()
                     wxConvUTF8);
 }
 
+void wxWebViewWebKit::ClearSelection()
+{
+    WebKitDOMDocument* doc; 
+    WebKitDOMDOMWindow* win;
+    WebKitDOMDOMSelection* sel;
+
+    doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view));
+    win = webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc));
+    sel = webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win));
+    webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel));
+
+}
+
+wxString wxWebViewWebKit::GetPageText()
+{
+    WebKitDOMDocument* doc; 
+    WebKitDOMHTMLElement* body;
+
+    doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view));
+    body = webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc));
+    return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body)), 
+                    wxConvUTF8);
+}
+
+void wxWebViewWebKit::RunScript(const wxString& javascript)
+{
+    webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view), 
+                                   javascript.mb_str(wxConvUTF8));
+}
+
 // static
 wxVisualAttributes
 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))