]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/webview_webkit.cpp
Add virtual ~wxAnyScrollHelperBase() to fix compiler warning.
[wxWidgets.git] / src / gtk / webview_webkit.cpp
index c6579f8fcb646ad35b7c5929548171141e8237f9..faaf4be80789c9dab54749056f27d227766c6ce9 100644 (file)
@@ -2,7 +2,6 @@
 // Name:        src/gtk/webview_webkit.cpp
 // Purpose:     GTK WebKit backend for web view component
 // Author:      Marianne Gagnon, Robert Roebling
-// Id:          $Id$
 // Copyright:   (c) 2010 Marianne Gagnon, 1998 Robert Roebling
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -47,7 +46,8 @@ wxgtk_webview_webkit_load_status(GtkWidget* widget,
         //We have to check if we are actually storing history
         //If the item isn't added we add it ourselves, it isn't added otherwise
         //with a custom scheme.
-        if(WEBKIT_IS_WEB_HISTORY_ITEM(item) && webkit_web_history_item_get_uri(item) != url)
+        if(!item || (WEBKIT_IS_WEB_HISTORY_ITEM(item) && 
+                     webkit_web_history_item_get_uri(item) != url))
         {
             WebKitWebHistoryItem*
                 newitem = webkit_web_history_item_new_with_data
@@ -59,7 +59,7 @@ wxgtk_webview_webkit_load_status(GtkWidget* widget,
         }
 
         webKitCtrl->m_busy = false;
-        wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_LOADED,
+        wxWebViewEvent event(wxEVT_WEBVIEW_LOADED,
                              webKitCtrl->GetId(),
                              url, target);
 
@@ -69,7 +69,7 @@ wxgtk_webview_webkit_load_status(GtkWidget* widget,
     else if (status ==  WEBKIT_LOAD_COMMITTED)
     {
         webKitCtrl->m_busy = true;
-        wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_NAVIGATED,
+        wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATED,
                              webKitCtrl->GetId(),
                              url, target);
 
@@ -86,6 +86,26 @@ wxgtk_webview_webkit_navigation(WebKitWebView *,
                                 WebKitWebPolicyDecision *policy_decision,
                                 wxWebViewWebKit *webKitCtrl)
 {
+    const gchar* uri = webkit_network_request_get_uri(request);
+    wxString target = webkit_web_frame_get_name (frame);
+    
+    //If m_creating is true then we are the result of a new window
+    //and so we need to send the event and veto the load
+    if(webKitCtrl->m_creating)
+    {
+        webKitCtrl->m_creating = false;
+        wxWebViewEvent event(wxEVT_WEBVIEW_NEWWINDOW,
+                             webKitCtrl->GetId(),
+                             wxString(uri, wxConvUTF8),
+                             target);
+
+        if(webKitCtrl && webKitCtrl->GetEventHandler())
+            webKitCtrl->GetEventHandler()->ProcessEvent(event);
+        
+        webkit_web_policy_decision_ignore(policy_decision);
+        return TRUE;
+    }
+
     if(webKitCtrl->m_guard)
     {
         webKitCtrl->m_guard = false;
@@ -98,10 +118,7 @@ wxgtk_webview_webkit_navigation(WebKitWebView *,
 
     webKitCtrl->m_busy = true;
 
-    const gchar* uri = webkit_network_request_get_uri(request);
-
-    wxString target = webkit_web_frame_get_name (frame);
-    wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_NAVIGATING,
+    wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATING,
                          webKitCtrl->GetId(),
                          wxString( uri, wxConvUTF8 ),
                          target);
@@ -274,7 +291,7 @@ wxgtk_webview_webkit_error(WebKitWebView*,
     }
     */
 
-    wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_ERROR,
+    wxWebViewEvent event(wxEVT_WEBVIEW_ERROR,
                          webKitWindow->GetId(),
                          uri, "");
     event.SetString(description);
@@ -299,7 +316,7 @@ wxgtk_webview_webkit_new_window(WebKitWebView*,
     const gchar* uri = webkit_network_request_get_uri(request);
 
     wxString target = webkit_web_frame_get_name (frame);
-    wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_NEWWINDOW,
+    wxWebViewEvent event(wxEVT_WEBVIEW_NEWWINDOW,
                                        webKitCtrl->GetId(),
                                        wxString( uri, wxConvUTF8 ),
                                        target);
@@ -318,7 +335,7 @@ wxgtk_webview_webkit_title_changed(WebKitWebView*,
                                    gchar *title,
                                    wxWebViewWebKit *webKitCtrl)
 {
-    wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_TITLE_CHANGED,
+    wxWebViewEvent event(wxEVT_WEBVIEW_TITLE_CHANGED,
                          webKitCtrl->GetId(),
                          webKitCtrl->GetCurrentURL(),
                          "");
@@ -395,6 +412,17 @@ wxgtk_webview_webkit_context_menu(WebKitWebView *,
 
 #endif
 
+static WebKitWebView*
+wxgtk_webview_webkit_create_webview(WebKitWebView *web_view,
+                                    WebKitWebFrame *frame,
+                                    wxWebViewWebKit *webKitCtrl)
+{
+    //As we do not know the uri being loaded at this point allow the load to
+    //continue and catch it in navigation-policy-decision-requested
+    webKitCtrl->m_creating = true;
+    return web_view;
+}
+
 } // extern "C"
 
 //-----------------------------------------------------------------------------
@@ -418,6 +446,7 @@ bool wxWebViewWebKit::Create(wxWindow *parent,
 {
     m_busy = false;
     m_guard = false;
+    m_creating = false;
     FindClear();
 
     // We currently unconditionally impose scrolling in both directions as it's
@@ -455,6 +484,9 @@ bool wxWebViewWebKit::Create(wxWindow *parent,
      g_signal_connect_after(m_web_view, "context-menu",
                            G_CALLBACK(wxgtk_webview_webkit_context_menu), this);
 #endif
+     
+     g_signal_connect_after(m_web_view, "create-web-view",
+                           G_CALLBACK(wxgtk_webview_webkit_create_webview), this);
 
     m_parent->DoAddChild( this );