From 7d8d6163ad4e9aeea1d18341462c23693a42b9a3 Mon Sep 17 00:00:00 2001 From: Steve Lamerton Date: Sun, 14 Aug 2011 12:15:34 +0000 Subject: [PATCH] Rename wxWebFileHandler to wxWebViewArchiveHandler, wxWebHandler to wxWebViewHandler. Update the documentation and the sample. Add a constructor taking a wxString to specify the scheme in wxWebViewHandler. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68689 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/webview_webkit.h | 6 +++--- include/wx/msw/webview_ie.h | 10 +++++----- include/wx/osx/webview_webkit.h | 2 +- include/wx/webview.h | 9 ++++++--- ...ewfilehandler.h => webviewarchivehandler.h} | 14 ++++++-------- interface/wx/webview.h | 17 +++++++++++------ ...ebfilehandler.h => webviewarchivehandler.h} | 18 +++++++++--------- samples/web/web.cpp | 6 +++--- ...lehandler.cpp => webviewarchivehandler.cpp} | 10 +++++----- src/gtk/webview_webkit.cpp | 14 +++++++------- src/msw/webview_ie.cpp | 4 ++-- src/osx/webview_webkit.mm | 8 ++++---- 12 files changed, 62 insertions(+), 56 deletions(-) rename include/wx/{webviewfilehandler.h => webviewarchivehandler.h} (59%) rename interface/wx/{webfilehandler.h => webviewarchivehandler.h} (54%) rename src/common/{webviewfilehandler.cpp => webviewarchivehandler.cpp} (91%) diff --git a/include/wx/gtk/webview_webkit.h b/include/wx/gtk/webview_webkit.h index 7d88128bed..72fc0259f2 100644 --- a/include/wx/gtk/webview_webkit.h +++ b/include/wx/gtk/webview_webkit.h @@ -122,8 +122,8 @@ public: virtual void RunScript(const wxString& javascript); //Virtual Filesystem Support - virtual void RegisterHandler(wxSharedPtr handler); - virtual wxVector > GetHandlers() { return m_handlerList; } + virtual void RegisterHandler(wxSharedPtr handler); + virtual wxVector > GetHandlers() { return m_handlerList; } /** FIXME: hack to work around signals being received too early */ bool m_ready; @@ -155,7 +155,7 @@ private: GtkWidget *web_view; gint m_historyLimit; - wxVector > m_handlerList; + wxVector > m_handlerList; wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit); }; diff --git a/include/wx/msw/webview_ie.h b/include/wx/msw/webview_ie.h index 9d4671e422..1ab66d5de3 100644 --- a/include/wx/msw/webview_ie.h +++ b/include/wx/msw/webview_ie.h @@ -110,7 +110,7 @@ public: virtual void RunScript(const wxString& javascript); //Virtual Filesystem Support - virtual void RegisterHandler(wxSharedPtr handler); + virtual void RegisterHandler(wxSharedPtr handler); // ---- IE-specific methods @@ -169,10 +169,10 @@ protected: VOID * fileP; wxFSFile* m_file; - wxSharedPtr m_handler; + wxSharedPtr m_handler; public: - VirtualProtocol(wxSharedPtr handler); + VirtualProtocol(wxSharedPtr handler); ~VirtualProtocol(); //IUnknown @@ -211,7 +211,7 @@ class ClassFactory : public IClassFactory private: ULONG m_refCount; public: - ClassFactory(wxSharedPtr handler) : m_handler(handler) {} + ClassFactory(wxSharedPtr handler) : m_handler(handler) {} //IUnknown ULONG STDMETHODCALLTYPE AddRef(); HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); @@ -222,7 +222,7 @@ public: REFIID riid, void** ppvObject); HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock); private: - wxSharedPtr m_handler; + wxSharedPtr m_handler; }; #endif // wxUSE_WEBVIEW_IE && defined(__WXMSW__) diff --git a/include/wx/osx/webview_webkit.h b/include/wx/osx/webview_webkit.h index 373439dd74..da88edfb6b 100644 --- a/include/wx/osx/webview_webkit.h +++ b/include/wx/osx/webview_webkit.h @@ -114,7 +114,7 @@ public: void RunScript(const wxString& javascript); //Virtual Filesystem Support - virtual void RegisterHandler(wxSharedPtr handler); + virtual void RegisterHandler(wxSharedPtr handler); // ---- methods not from the parent (common) interface bool CanGetPageSource(); diff --git a/include/wx/webview.h b/include/wx/webview.h index b76cba8970..4d4db3ad4d 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -101,11 +101,14 @@ enum wxWebViewBackend }; //Base class for custom scheme handlers -class WXDLLIMPEXP_WEB wxWebHandler +class WXDLLIMPEXP_WEB wxWebViewHandler { public: - virtual wxString GetName() const = 0; + wxWebViewHandler(const wxString& scheme) : m_scheme(scheme) {} + virtual wxString GetName() const { return m_scheme; } virtual wxFSFile* GetFile(const wxString &uri) = 0; +private: + wxString m_scheme; }; extern WXDLLIMPEXP_DATA_WEB(const char) wxWebViewNameStr[]; @@ -339,7 +342,7 @@ public: virtual void Redo() = 0; //Virtual Filesystem Support - virtual void RegisterHandler(wxSharedPtr handler) = 0; + virtual void RegisterHandler(wxSharedPtr handler) = 0; wxDECLARE_ABSTRACT_CLASS(wxWebView); }; diff --git a/include/wx/webviewfilehandler.h b/include/wx/webviewarchivehandler.h similarity index 59% rename from include/wx/webviewfilehandler.h rename to include/wx/webviewarchivehandler.h index 787a0c4240..da8a926794 100644 --- a/include/wx/webviewfilehandler.h +++ b/include/wx/webviewarchivehandler.h @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: webviewfilehandler.h -// Purpose: Custom handler for the file scheme to allow archive browsing +// Name: webviewarchivehandler.h +// Purpose: Custom webview handler to allow archive browsing // Author: Steven Lamerton // Id: $Id$ // Copyright: (c) 2011 Steven Lamerton @@ -19,17 +19,15 @@ class wxFileSystem; #include "wx/webview.h" -//Loads from uris such as file:///C:/example/example.html or archives such as -//file:///C:/example/example.zip;protocol=zip/example.html +//Loads from uris such as scheme:///C:/example/example.html or archives such as +//scheme:///C:/example/example.zip;protocol=zip/example.html -class WXDLLIMPEXP_WEB wxWebFileHandler : public wxWebHandler +class WXDLLIMPEXP_WEB wxWebViewArchiveHandler : public wxWebViewHandler { public: - wxWebFileHandler(); - virtual wxString GetName() const { return m_name; } + wxWebViewArchiveHandler(const wxString& scheme); virtual wxFSFile* GetFile(const wxString &uri); private: - wxString m_name; wxFileSystem* m_fileSystem; }; diff --git a/interface/wx/webview.h b/interface/wx/webview.h index e192e01ec5..e4641504df 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -117,7 +117,7 @@ public: }; /** - @class wxWebHandler + @class wxWebViewHandler The base class for handling custom schemes in wxWebView, for example to allow virtual file system support. @@ -127,16 +127,22 @@ public: @see wxWebView */ -class wxWebHandler +class wxWebViewHandler { public: + /** + Constructor. Takes the name of the scheme that will be handled by this + class for example @c file or @c zip. + */ + wxWebViewHandler(const wxString& scheme); + /** @return A pointer to the file represented by @c uri. */ virtual wxFSFile* GetFile(const wxString &uri) = 0; /** - @return The name of the scheme, for example @c file or @c http. + @return The name of the scheme, as passed to the constructor. */ virtual wxString GetName() const = 0; }; @@ -196,8 +202,7 @@ public: wxWebView supports the registering of custom scheme handlers, for example @c file or @c http. To do this create a new class which inherits from - wxWebHandler, where the wxWebHandler::GetName() method returns the scheme - you wish to handle and wxWebHandler::GetFile() returns a pointer to a + wxWebViewHandler, where wxWebHandler::GetFile() returns a pointer to a wxFSFile which represents the given url. You can then register your handler with RegisterHandler() it will be called for all pages and resources. @@ -338,7 +343,7 @@ public: Registers a custom scheme handler. @param handler A shared pointer to a wxWebHandler. */ - virtual void RegisterHandler(wxSharedPtr handler) = 0; + virtual void RegisterHandler(wxSharedPtr handler) = 0; /** Reload the currently displayed URL. diff --git a/interface/wx/webfilehandler.h b/interface/wx/webviewarchivehandler.h similarity index 54% rename from interface/wx/webfilehandler.h rename to interface/wx/webviewarchivehandler.h index 74dd8510b8..4077bc1a1d 100644 --- a/interface/wx/webfilehandler.h +++ b/interface/wx/webviewarchivehandler.h @@ -1,31 +1,31 @@ ///////////////////////////////////////////////////////////////////////////// // Name: webfilehandler.h -// Purpose: interface of wxWebFileHandler +// Purpose: interface of wxWebViewArchiveHandler // Author: wxWidgets team // RCS-ID: $Id$ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// /** - @class wxWebFileHandler + @class wxWebViewArchiveHandler A custom handler for the file scheme which also supports loading from - archives. The syntax for wxWebFileHandler differs from virtual file + archives. The syntax for wxWebViewArchiveHandler differs from virtual file systems in the rest of wxWidgets by using a syntax such as - @c file:///C:/exmaple/docs.zip;protocol=zip/main.htm Currently the only - supported protocol is @c zip. + scheme:///C:/exmaple/docs.zip;protocol=zip/main.htm + Currently the only supported protocol is @c zip. @library{wxweb} @category{web} - @see wxWebView, wxWebHandler + @see wxWebView, wxWebViewHandler */ -class wxWebFileHandler : public wxWebHandler +class wxWebViewArchiveHandler : public wxWebViewHandler { public: /** - @return The string @c "file" + Constructor. */ - virtual wxString GetName() const; + wxWebViewArchiveHandler(const wxString& scheme); virtual wxFSFile* GetFile(const wxString &uri); }; \ No newline at end of file diff --git a/samples/web/web.cpp b/samples/web/web.cpp index f1019dd585..e013f445b8 100644 --- a/samples/web/web.cpp +++ b/samples/web/web.cpp @@ -26,7 +26,7 @@ #include "wx/notifmsg.h" #include "wx/settings.h" #include "wx/webview.h" -#include "wx/webviewfilehandler.h" +#include "wx/webviewarchivehandler.h" #include "wx/infobar.h" #include "wx/filesys.h" #include "wx/fs_arc.h" @@ -209,8 +209,8 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample") m_browser = wxWebView::New(this, wxID_ANY, "http://www.wxwidgets.org"); topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1)); - //We register the file:// protocol for testing purposes - m_browser->RegisterHandler(wxSharedPtr(new wxWebFileHandler())); + //We register the wxfs:// protocol for testing purposes + m_browser->RegisterHandler(wxSharedPtr(new wxWebViewArchiveHandler("wxfs"))); SetSizer(topsizer); diff --git a/src/common/webviewfilehandler.cpp b/src/common/webviewarchivehandler.cpp similarity index 91% rename from src/common/webviewfilehandler.cpp rename to src/common/webviewarchivehandler.cpp index 3dbbbb3398..9a445526c3 100644 --- a/src/common/webviewfilehandler.cpp +++ b/src/common/webviewarchivehandler.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: webviewfilehandler.cpp -// Purpose: Custom handler for the file scheme to allow archive browsing +// Purpose: Custom webview handler to allow archive browsing // Author: Steven Lamerton // Id: $Id$ // Copyright: (c) 2011 Steven Lamerton @@ -16,7 +16,7 @@ #pragma hdrstop #endif -#include "wx/webviewfilehandler.h" +#include "wx/webviewarchivehandler.h" #include "wx/filesys.h" //Taken from wx/filesys.cpp @@ -44,13 +44,13 @@ static wxString EscapeFileNameCharsInURL(const char *in) return s; } -wxWebFileHandler::wxWebFileHandler() +wxWebViewArchiveHandler::wxWebViewArchiveHandler(const wxString& scheme) : + wxWebViewHandler(scheme) { - m_name = "file"; m_fileSystem = new wxFileSystem(); } -wxFSFile* wxWebFileHandler::GetFile(const wxString &uri) +wxFSFile* wxWebViewArchiveHandler::GetFile(const wxString &uri) { //If there is a fragment at the end of the path then we need to strip it //off as not all backends do this for us diff --git a/src/gtk/webview_webkit.cpp b/src/gtk/webview_webkit.cpp index c7c3d1c7a5..3b9f9f4930 100644 --- a/src/gtk/webview_webkit.cpp +++ b/src/gtk/webview_webkit.cpp @@ -104,10 +104,10 @@ wxgtk_webview_webkit_navigation(WebKitWebView *, else { wxString wxuri = uri; - wxSharedPtr handler; - wxVector > hanlders = webKitCtrl->GetHandlers(); + wxSharedPtr handler; + wxVector > hanlders = webKitCtrl->GetHandlers(); //We are not vetoed so see if we match one of the additional handlers - for(wxVector >::iterator it = hanlders.begin(); + for(wxVector >::iterator it = hanlders.begin(); it != hanlders.end(); ++it) { if(wxuri.substr(0, (*it)->GetName().length()) == (*it)->GetName()) @@ -329,11 +329,11 @@ wxgtk_webview_webkit_resource_req(WebKitWebView *, { wxString uri = webkit_network_request_get_uri(request); - wxSharedPtr handler; - wxVector > hanlders = webKitCtrl->GetHandlers(); + wxSharedPtr handler; + wxVector > hanlders = webKitCtrl->GetHandlers(); //We are not vetoed so see if we match one of the additional handlers - for(wxVector >::iterator it = hanlders.begin(); + for(wxVector >::iterator it = hanlders.begin(); it != hanlders.end(); ++it) { if(uri.substr(0, (*it)->GetName().length()) == (*it)->GetName()) @@ -911,7 +911,7 @@ void wxWebViewWebKit::RunScript(const wxString& javascript) javascript.mb_str(wxConvUTF8)); } -void wxWebViewWebKit::RegisterHandler(wxSharedPtr handler) +void wxWebViewWebKit::RegisterHandler(wxSharedPtr handler) { m_handlerList.push_back(handler); } diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index a02838dbdc..a8571a6109 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -665,7 +665,7 @@ void wxWebViewIE::RunScript(const wxString& javascript) document->Release(); } -void wxWebViewIE::RegisterHandler(wxSharedPtr handler) +void wxWebViewIE::RegisterHandler(wxSharedPtr handler) { ClassFactory* cf = new ClassFactory(handler); IInternetSession* session; @@ -965,7 +965,7 @@ void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt) evt.Skip(); } -VirtualProtocol::VirtualProtocol(wxSharedPtr handler) +VirtualProtocol::VirtualProtocol(wxSharedPtr handler) { m_refCount = 0; m_file = NULL; diff --git a/src/osx/webview_webkit.mm b/src/osx/webview_webkit.mm index f3efc4e2e5..f11a29a655 100644 --- a/src/osx/webview_webkit.mm +++ b/src/osx/webview_webkit.mm @@ -315,8 +315,8 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxWebViewWebKitEventHandler ) @end -//We use a hash to map scheme names to wxWebHandlers -WX_DECLARE_STRING_HASH_MAP(wxSharedPtr, wxStringToWebHandlerMap); +//We use a hash to map scheme names to wxWebViewHandler +WX_DECLARE_STRING_HASH_MAP(wxSharedPtr, wxStringToWebHandlerMap); static wxStringToWebHandlerMap g_stringHandlerMap; @@ -982,7 +982,7 @@ void wxWebViewWebKit::Redo() [[m_webView undoManager] redo]; } -void wxWebViewWebKit::RegisterHandler(wxSharedPtr handler) +void wxWebViewWebKit::RegisterHandler(wxSharedPtr handler) { g_stringHandlerMap[handler->GetName()] = handler; } @@ -1262,7 +1262,7 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebNavigationError* out) + (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request { - //We don't do any processing here as the wxWebHandler classes do it + //We don't do any processing here as the wxWebViewHandler classes do it return request; }