]> git.saurik.com Git - wxWidgets.git/commitdiff
Initial work on virtual file system support for the WebKitGTK+ backend. It now suppor...
authorSteve Lamerton <steve.lamerton@gmail.com>
Wed, 3 Aug 2011 09:29:30 +0000 (09:29 +0000)
committerSteve Lamerton <steve.lamerton@gmail.com>
Wed, 3 Aug 2011 09:29:30 +0000 (09:29 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68503 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/webview_webkit.h
src/gtk/webview_webkit.cpp

index 8f1e5f9e41674f1d9156cabc46049703802de93f..dd13885cbd65af33fc0fdaae02308cf880db25b9 100644 (file)
@@ -122,7 +122,8 @@ public:
     virtual void RunScript(const wxString& javascript);
     
     //Virtual Filesystem Support
-    virtual void RegisterHandler(wxWebHandler* WXUNUSED(handler)) {};
+    virtual void RegisterHandler(wxWebHandler* handler);
+    virtual wxVector<wxWebHandler*> GetHandlers() { return m_handlerList; }
 
     /** FIXME: hack to work around signals being received too early */
     bool m_ready;
@@ -148,6 +149,8 @@ private:
     GtkWidget *web_view;
     gint m_historyLimit;
 
+    wxVector<wxWebHandler*> m_handlerList;
+
     wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit);
 };
 
index 944c9cf5409f3c9eeb093834691272089326a7a9..23aec2a8a4999809ee618d2359c3746003d53229 100644 (file)
@@ -16,6 +16,7 @@
 #include "wx/gtk/webview_webkit.h"
 #include "wx/gtk/control.h"
 #include "wx/gtk/private.h"
+#include "wx/filesys.h"
 #include "webkit/webkit.h"
 
 // ----------------------------------------------------------------------------
@@ -62,7 +63,7 @@ wxgtk_webview_webkit_load_status(GtkWidget* widget,
 }
 
 static gboolean
-wxgtk_webview_webkit_navigation(WebKitWebView*,
+wxgtk_webview_webkit_navigation(WebKitWebView *view,
                                 WebKitWebFrame *frame,
                                 WebKitNetworkRequest *request,
                                 WebKitWebNavigationAction *,
@@ -91,6 +92,31 @@ wxgtk_webview_webkit_navigation(WebKitWebView*,
     }
     else
     {
+        wxString wxuri = uri;
+        wxWebHandler *handler = NULL;
+        wxVector<wxWebHandler*> hanlders = webKitCtrl->GetHandlers();
+        //We are not vetoed so see if we match one of the additional handlers
+        for(wxVector<wxWebHandler*>::iterator it = hanlders.begin();
+            it != hanlders.end(); ++it)
+        {
+            if(wxuri.substr(0, (*it)->GetName().length()) == (*it)->GetName())
+            {
+                handler = (*it);
+            }
+        }
+        //If we found a handler we can then use it to load the file directly 
+        //ourselves
+        if(handler)
+        {
+            wxFSFile* file = handler->GetFile(wxuri);
+            g_signal_handlers_block_by_func(view, 
+                                           (gpointer)wxgtk_webview_webkit_navigation, 
+                                           webKitCtrl);
+            webKitCtrl->SetPage(*file->GetStream(), wxuri);
+            g_signal_handlers_unblock_by_func(view, 
+                                             (gpointer)wxgtk_webview_webkit_navigation, 
+                                             webKitCtrl);
+        }
         return FALSE;
     }
 }
@@ -820,6 +846,11 @@ void wxWebViewWebKit::RunScript(const wxString& javascript)
                                    javascript.mb_str(wxConvUTF8));
 }
 
+void wxWebViewWebKit::RegisterHandler(wxWebHandler* handler)
+{
+    m_handlerList.push_back(handler);
+}
+
 // static
 wxVisualAttributes
 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))