virtual void RunScript(const wxString& javascript);
//Virtual Filesystem Support
- virtual void RegisterHandler(wxSharedPtr<wxWebHandler> handler);
- virtual wxVector<wxSharedPtr<wxWebHandler> > GetHandlers() { return m_handlerList; }
+ virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
+ virtual wxVector<wxSharedPtr<wxWebViewHandler> > GetHandlers() { return m_handlerList; }
/** FIXME: hack to work around signals being received too early */
bool m_ready;
GtkWidget *web_view;
gint m_historyLimit;
- wxVector<wxSharedPtr<wxWebHandler> > m_handlerList;
+ wxVector<wxSharedPtr<wxWebViewHandler> > m_handlerList;
wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit);
};
virtual void RunScript(const wxString& javascript);
//Virtual Filesystem Support
- virtual void RegisterHandler(wxSharedPtr<wxWebHandler> handler);
+ virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
// ---- IE-specific methods
VOID * fileP;
wxFSFile* m_file;
- wxSharedPtr<wxWebHandler> m_handler;
+ wxSharedPtr<wxWebViewHandler> m_handler;
public:
- VirtualProtocol(wxSharedPtr<wxWebHandler> handler);
+ VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler);
~VirtualProtocol();
//IUnknown
private:
ULONG m_refCount;
public:
- ClassFactory(wxSharedPtr<wxWebHandler> handler) : m_handler(handler) {}
+ ClassFactory(wxSharedPtr<wxWebViewHandler> handler) : m_handler(handler) {}
//IUnknown
ULONG STDMETHODCALLTYPE AddRef();
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
REFIID riid, void** ppvObject);
HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
private:
- wxSharedPtr<wxWebHandler> m_handler;
+ wxSharedPtr<wxWebViewHandler> m_handler;
};
#endif // wxUSE_WEBVIEW_IE && defined(__WXMSW__)
void RunScript(const wxString& javascript);
//Virtual Filesystem Support
- virtual void RegisterHandler(wxSharedPtr<wxWebHandler> handler);
+ virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
// ---- methods not from the parent (common) interface
bool CanGetPageSource();
};
//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[];
virtual void Redo() = 0;
//Virtual Filesystem Support
- virtual void RegisterHandler(wxSharedPtr<wxWebHandler> handler) = 0;
+ virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) = 0;
wxDECLARE_ABSTRACT_CLASS(wxWebView);
};
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// 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_
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// 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_
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// 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
};
/**
- @class wxWebHandler
+ @class wxWebViewHandler
The base class for handling custom schemes in wxWebView, for example to
allow virtual file system support.
@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;
};
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.
Registers a custom scheme handler.
@param handler A shared pointer to a wxWebHandler.
*/
- virtual void RegisterHandler(wxSharedPtr<wxWebHandler> handler) = 0;
+ virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) = 0;
/**
Reload the currently displayed URL.
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// 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
+ <code> scheme:///C:/exmaple/docs.zip;protocol=zip/main.htm </code>
+ 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
#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"
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<wxWebHandler>(new wxWebFileHandler()));
+ //We register the wxfs:// protocol for testing purposes
+ m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("wxfs")));
SetSizer(topsizer);
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// 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
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// 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
else
{
wxString wxuri = uri;
- wxSharedPtr<wxWebHandler> handler;
- wxVector<wxSharedPtr<wxWebHandler> > hanlders = webKitCtrl->GetHandlers();
+ wxSharedPtr<wxWebViewHandler> handler;
+ wxVector<wxSharedPtr<wxWebViewHandler> > hanlders = webKitCtrl->GetHandlers();
//We are not vetoed so see if we match one of the additional handlers
- for(wxVector<wxSharedPtr<wxWebHandler> >::iterator it = hanlders.begin();
+ for(wxVector<wxSharedPtr<wxWebViewHandler> >::iterator it = hanlders.begin();
it != hanlders.end(); ++it)
{
if(wxuri.substr(0, (*it)->GetName().length()) == (*it)->GetName())
{
wxString uri = webkit_network_request_get_uri(request);
- wxSharedPtr<wxWebHandler> handler;
- wxVector<wxSharedPtr<wxWebHandler> > hanlders = webKitCtrl->GetHandlers();
+ wxSharedPtr<wxWebViewHandler> handler;
+ wxVector<wxSharedPtr<wxWebViewHandler> > hanlders = webKitCtrl->GetHandlers();
//We are not vetoed so see if we match one of the additional handlers
- for(wxVector<wxSharedPtr<wxWebHandler> >::iterator it = hanlders.begin();
+ for(wxVector<wxSharedPtr<wxWebViewHandler> >::iterator it = hanlders.begin();
it != hanlders.end(); ++it)
{
if(uri.substr(0, (*it)->GetName().length()) == (*it)->GetName())
javascript.mb_str(wxConvUTF8));
}
-void wxWebViewWebKit::RegisterHandler(wxSharedPtr<wxWebHandler> handler)
+void wxWebViewWebKit::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
{
m_handlerList.push_back(handler);
}
document->Release();
}
-void wxWebViewIE::RegisterHandler(wxSharedPtr<wxWebHandler> handler)
+void wxWebViewIE::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
{
ClassFactory* cf = new ClassFactory(handler);
IInternetSession* session;
evt.Skip();
}
-VirtualProtocol::VirtualProtocol(wxSharedPtr<wxWebHandler> handler)
+VirtualProtocol::VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler)
{
m_refCount = 0;
m_file = NULL;
@end
-//We use a hash to map scheme names to wxWebHandlers
-WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxWebHandler>, wxStringToWebHandlerMap);
+//We use a hash to map scheme names to wxWebViewHandler
+WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxWebViewHandler>, wxStringToWebHandlerMap);
static wxStringToWebHandlerMap g_stringHandlerMap;
[[m_webView undoManager] redo];
}
-void wxWebViewWebKit::RegisterHandler(wxSharedPtr<wxWebHandler> handler)
+void wxWebViewWebKit::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
{
g_stringHandlerMap[handler->GetName()] = handler;
}
+ (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;
}