From: Steve Lamerton Date: Sun, 14 Aug 2011 12:15:34 +0000 (+0000) Subject: Rename wxWebFileHandler to wxWebViewArchiveHandler, wxWebHandler to wxWebViewHandler... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7d8d6163ad4e9aeea1d18341462c23693a42b9a3?ds=inline 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 --- 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/webviewarchivehandler.h b/include/wx/webviewarchivehandler.h new file mode 100644 index 0000000000..da8a926794 --- /dev/null +++ b/include/wx/webviewarchivehandler.h @@ -0,0 +1,36 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: webviewarchivehandler.h +// Purpose: Custom webview handler to allow archive browsing +// Author: Steven Lamerton +// Id: $Id$ +// Copyright: (c) 2011 Steven Lamerton +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_WEB_VIEW_FILE_HANDLER_H_ +#define _WX_WEB_VIEW_FILE_HANDLER_H_ + +#include "wx/setup.h" + +#if wxUSE_WEB + +class wxFSFile; +class wxFileSystem; + +#include "wx/webview.h" + +//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 wxWebViewArchiveHandler : public wxWebViewHandler +{ +public: + wxWebViewArchiveHandler(const wxString& scheme); + virtual wxFSFile* GetFile(const wxString &uri); +private: + wxFileSystem* m_fileSystem; +}; + +#endif + +#endif // _WX_WEB_VIEW_FILE_HANDLER_H_ diff --git a/include/wx/webviewfilehandler.h b/include/wx/webviewfilehandler.h deleted file mode 100644 index 787a0c4240..0000000000 --- a/include/wx/webviewfilehandler.h +++ /dev/null @@ -1,38 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: webviewfilehandler.h -// Purpose: Custom handler for the file scheme to allow archive browsing -// Author: Steven Lamerton -// Id: $Id$ -// Copyright: (c) 2011 Steven Lamerton -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_WEB_VIEW_FILE_HANDLER_H_ -#define _WX_WEB_VIEW_FILE_HANDLER_H_ - -#include "wx/setup.h" - -#if wxUSE_WEB - -class wxFSFile; -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 - -class WXDLLIMPEXP_WEB wxWebFileHandler : public wxWebHandler -{ -public: - wxWebFileHandler(); - virtual wxString GetName() const { return m_name; } - virtual wxFSFile* GetFile(const wxString &uri); -private: - wxString m_name; - wxFileSystem* m_fileSystem; -}; - -#endif - -#endif // _WX_WEB_VIEW_FILE_HANDLER_H_ diff --git a/interface/wx/webfilehandler.h b/interface/wx/webfilehandler.h deleted file mode 100644 index 74dd8510b8..0000000000 --- a/interface/wx/webfilehandler.h +++ /dev/null @@ -1,31 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: webfilehandler.h -// Purpose: interface of wxWebFileHandler -// Author: wxWidgets team -// RCS-ID: $Id$ -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -/** - @class wxWebFileHandler - - A custom handler for the file scheme which also supports loading from - archives. The syntax for wxWebFileHandler 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. - - @library{wxweb} - @category{web} - - @see wxWebView, wxWebHandler - */ -class wxWebFileHandler : public wxWebHandler -{ -public: - /** - @return The string @c "file" - */ - virtual wxString GetName() const; - virtual wxFSFile* GetFile(const wxString &uri); -}; \ No newline at end of file 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/webviewarchivehandler.h b/interface/wx/webviewarchivehandler.h new file mode 100644 index 0000000000..4077bc1a1d --- /dev/null +++ b/interface/wx/webviewarchivehandler.h @@ -0,0 +1,31 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: webfilehandler.h +// Purpose: interface of wxWebViewArchiveHandler +// Author: wxWidgets team +// RCS-ID: $Id$ +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +/** + @class wxWebViewArchiveHandler + + A custom handler for the file scheme which also supports loading from + archives. The syntax for wxWebViewArchiveHandler differs from virtual file + systems in the rest of wxWidgets by using a syntax such as + scheme:///C:/exmaple/docs.zip;protocol=zip/main.htm + Currently the only supported protocol is @c zip. + + @library{wxweb} + @category{web} + + @see wxWebView, wxWebViewHandler + */ +class wxWebViewArchiveHandler : public wxWebViewHandler +{ +public: + /** + Constructor. + */ + 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/webviewarchivehandler.cpp b/src/common/webviewarchivehandler.cpp new file mode 100644 index 0000000000..9a445526c3 --- /dev/null +++ b/src/common/webviewarchivehandler.cpp @@ -0,0 +1,113 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: webviewfilehandler.cpp +// Purpose: Custom webview handler to allow archive browsing +// Author: Steven Lamerton +// Id: $Id$ +// Copyright: (c) 2011 Steven Lamerton +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if wxUSE_WEB + +#if defined(__BORLANDC__) + #pragma hdrstop +#endif + +#include "wx/webviewarchivehandler.h" +#include "wx/filesys.h" + +//Taken from wx/filesys.cpp +static wxString EscapeFileNameCharsInURL(const char *in) +{ + wxString s; + + for ( const unsigned char *p = (const unsigned char*)in; *p; ++p ) + { + const unsigned char c = *p; + + if ( c == '/' || c == '-' || c == '.' || c == '_' || c == '~' || + (c >= '0' && c <= '9') || + (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') ) + { + s << c; + } + else + { + s << wxString::Format("%%%02x", c); + } + } + + return s; +} + +wxWebViewArchiveHandler::wxWebViewArchiveHandler(const wxString& scheme) : + wxWebViewHandler(scheme) +{ + m_fileSystem = new wxFileSystem(); +} + +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 + wxString path = uri; + size_t hashloc = uri.find('#'); + if(hashloc != wxString::npos) + { + path = uri.substr(0, hashloc); + } + + //We iterate through the string to see if there is a protocol description + size_t start = wxString::npos; + for(size_t i = 0; i < path.length(); i++) + { + if(path[i] == ';' && path.substr(i, 10) == ";protocol=") + { + start = i; + break; + } + } + + //We do not have a protocol string so we just pass the path withouth the + if(start == wxString::npos) + { + size_t doubleslash = path.find("//"); + //The path is incorrectly formed without // after the scheme + if(doubleslash == wxString::npos) + return NULL; + + wxString fspath = "file:" + + EscapeFileNameCharsInURL(path.substr(doubleslash + 2)); + return m_fileSystem->OpenFile(fspath); + } + //Otherwise we need to extract the protocol + else + { + size_t end = path.find('/', start); + //For the path to be valid there must to a path after the protocol + if(end == wxString::npos) + { + return NULL; + } + wxString mainpath = path.substr(0, start); + wxString archivepath = path.substr(end); + wxString protstring = path.substr(start, end - start); + wxString protocol = protstring.substr(10); + //We can now construct the correct path + size_t doubleslash = path.find("//"); + //The path is incorrectly formed without // after the first protocol + if(doubleslash == wxString::npos) + return NULL; + + wxString fspath = "file:" + + EscapeFileNameCharsInURL(mainpath.substr(doubleslash + 2)) + + "#" + protocol +":" + archivepath; + return m_fileSystem->OpenFile(fspath); + } +} + +#endif // wxUSE_WEB diff --git a/src/common/webviewfilehandler.cpp b/src/common/webviewfilehandler.cpp deleted file mode 100644 index 3dbbbb3398..0000000000 --- a/src/common/webviewfilehandler.cpp +++ /dev/null @@ -1,113 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: webviewfilehandler.cpp -// Purpose: Custom handler for the file scheme to allow archive browsing -// Author: Steven Lamerton -// Id: $Id$ -// Copyright: (c) 2011 Steven Lamerton -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#if wxUSE_WEB - -#if defined(__BORLANDC__) - #pragma hdrstop -#endif - -#include "wx/webviewfilehandler.h" -#include "wx/filesys.h" - -//Taken from wx/filesys.cpp -static wxString EscapeFileNameCharsInURL(const char *in) -{ - wxString s; - - for ( const unsigned char *p = (const unsigned char*)in; *p; ++p ) - { - const unsigned char c = *p; - - if ( c == '/' || c == '-' || c == '.' || c == '_' || c == '~' || - (c >= '0' && c <= '9') || - (c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') ) - { - s << c; - } - else - { - s << wxString::Format("%%%02x", c); - } - } - - return s; -} - -wxWebFileHandler::wxWebFileHandler() -{ - m_name = "file"; - m_fileSystem = new wxFileSystem(); -} - -wxFSFile* wxWebFileHandler::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 - wxString path = uri; - size_t hashloc = uri.find('#'); - if(hashloc != wxString::npos) - { - path = uri.substr(0, hashloc); - } - - //We iterate through the string to see if there is a protocol description - size_t start = wxString::npos; - for(size_t i = 0; i < path.length(); i++) - { - if(path[i] == ';' && path.substr(i, 10) == ";protocol=") - { - start = i; - break; - } - } - - //We do not have a protocol string so we just pass the path withouth the - if(start == wxString::npos) - { - size_t doubleslash = path.find("//"); - //The path is incorrectly formed without // after the scheme - if(doubleslash == wxString::npos) - return NULL; - - wxString fspath = "file:" + - EscapeFileNameCharsInURL(path.substr(doubleslash + 2)); - return m_fileSystem->OpenFile(fspath); - } - //Otherwise we need to extract the protocol - else - { - size_t end = path.find('/', start); - //For the path to be valid there must to a path after the protocol - if(end == wxString::npos) - { - return NULL; - } - wxString mainpath = path.substr(0, start); - wxString archivepath = path.substr(end); - wxString protstring = path.substr(start, end - start); - wxString protocol = protstring.substr(10); - //We can now construct the correct path - size_t doubleslash = path.find("//"); - //The path is incorrectly formed without // after the first protocol - if(doubleslash == wxString::npos) - return NULL; - - wxString fspath = "file:" + - EscapeFileNameCharsInURL(mainpath.substr(doubleslash + 2)) - + "#" + protocol +":" + archivepath; - return m_fileSystem->OpenFile(fspath); - } -} - -#endif // wxUSE_WEB 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; }