From f2049b683752950d1fe91aec07318e7f2122ff16 Mon Sep 17 00:00:00 2001 From: Steve Lamerton Date: Wed, 3 Aug 2011 09:29:30 +0000 Subject: [PATCH] Initial work on virtual file system support for the WebKitGTK+ backend. It now supports loading single pages from the VFS system. 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 | 5 ++++- src/gtk/webview_webkit.cpp | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/wx/gtk/webview_webkit.h b/include/wx/gtk/webview_webkit.h index 8f1e5f9e41..dd13885cbd 100644 --- a/include/wx/gtk/webview_webkit.h +++ b/include/wx/gtk/webview_webkit.h @@ -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 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 m_handlerList; + wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit); }; diff --git a/src/gtk/webview_webkit.cpp b/src/gtk/webview_webkit.cpp index 944c9cf540..23aec2a8a4 100644 --- a/src/gtk/webview_webkit.cpp +++ b/src/gtk/webview_webkit.cpp @@ -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 hanlders = webKitCtrl->GetHandlers(); + //We are not vetoed so see if we match one of the additional handlers + for(wxVector::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))