2011-05-04 14:24:30 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: include/gtk/wx/webview.h
|
|
|
|
// Purpose: GTK webkit backend for web view component
|
|
|
|
// Author: Robert Roebling, Marianne Gagnon
|
|
|
|
// Copyright: (c) 2010 Marianne Gagnon, 1998 Robert Roebling
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_GTK_WEBKITCTRL_H_
|
|
|
|
#define _WX_GTK_WEBKITCTRL_H_
|
|
|
|
|
2012-10-17 12:23:18 -04:00
|
|
|
#include "wx/defs.h"
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2017-03-30 21:34:24 -04:00
|
|
|
// NOTE: this header is used for both the WebKit1 and WebKit2 implementations
|
|
|
|
#if wxUSE_WEBVIEW && (wxUSE_WEBVIEW_WEBKIT || wxUSE_WEBVIEW_WEBKIT2) && defined(__WXGTK__)
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-07-01 15:46:31 -04:00
|
|
|
#include "wx/sharedptr.h"
|
2011-05-04 14:24:30 -04:00
|
|
|
#include "wx/webview.h"
|
2017-03-30 21:34:24 -04:00
|
|
|
#if wxUSE_WEBVIEW_WEBKIT2
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gio/gio.h>
|
|
|
|
#endif
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2012-03-01 11:36:58 -05:00
|
|
|
typedef struct _WebKitWebView WebKitWebView;
|
|
|
|
|
2011-05-04 14:24:30 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2011-06-28 12:57:49 -04:00
|
|
|
// wxWebViewWebKit
|
2011-05-04 14:24:30 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2011-08-19 06:45:16 -04:00
|
|
|
class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit : public wxWebView
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
|
|
|
public:
|
2012-10-17 12:23:18 -04:00
|
|
|
wxWebViewWebKit();
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-06-28 12:57:49 -04:00
|
|
|
wxWebViewWebKit(wxWindow *parent,
|
2011-05-04 14:24:30 -04:00
|
|
|
wxWindowID id = wxID_ANY,
|
|
|
|
const wxString& url = wxWebViewDefaultURLStr,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize, long style = 0,
|
2019-10-22 06:34:29 -04:00
|
|
|
const wxString& name = wxASCII_STR(wxWebViewNameStr))
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
|
|
|
Create(parent, id, url, pos, size, style, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Create(wxWindow *parent,
|
|
|
|
wxWindowID id = wxID_ANY,
|
|
|
|
const wxString& url = wxWebViewDefaultURLStr,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize, long style = 0,
|
2019-10-22 06:34:29 -04:00
|
|
|
const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE;
|
2011-05-04 14:24:30 -04:00
|
|
|
|
Fix crash on wxWebViewWebKit window destruction.
We were getting crashes due to using methods of already half-destroyed object
when wxWebView window was destroyed in wxGTK, with the following abbreviated
stack:
#0 wxgtk_webview_webkit_load_status (widget=0x12eb380, webKitCtrl=0x13ee040) at src/gtk/webview_webkit.cpp:38
...
#8 0x00007ffff05ca281 in dispatchDidFailLoad (error=..., this=0x7fffe32db900) at ../Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp:1054
#9 WebKit::FrameLoaderClient::dispatchDidFailLoad (this=0x7fffe32db900, error=...) at ../Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp:1049
#10 0x00007ffff0b0de54 in WebCore::FrameLoader::checkLoadCompleteForThisFrame (this=0x7fffe3221b70) at ../Source/WebCore/loader/FrameLoader.cpp:2128
#11 0x00007ffff0b0cfde in WebCore::FrameLoader::checkLoadComplete (this=<optimized out>) at ../Source/WebCore/loader/FrameLoader.cpp:2370
#12 0x00007ffff0b0a3b2 in WebCore::FrameLoader::receivedMainResourceError (this=0x7fffe3221b70, error=..., isComplete=true) at ../Source/WebCore/loader/FrameLoader.cpp:2640
#13 0x00007ffff0b423b7 in cancel (error=..., this=0x7fffe3279680) at ../Source/WebCore/loader/ResourceLoader.cpp:399
#14 WebCore::ResourceLoader::cancel (this=0x7fffe3279680, error=...) at ../Source/WebCore/loader/ResourceLoader.cpp:353
#15 0x00007ffff0b420c0 in WebCore::ResourceLoader::cancel (this=<optimized out>) at ../Source/WebCore/loader/ResourceLoader.cpp:350
#16 0x00007ffff0afda9e in WebCore::DocumentLoader::stopLoading (this=0x7fffa081d800) at ../Source/WebCore/loader/DocumentLoader.cpp:258
#17 0x00007ffff0b09561 in stopAllLoaders (clearProvisionalItemPolicy=WebCore::ShouldClearProvisionalItem, this=0x7fffe3221b70) at ../Source/WebCore/loader/FrameLoader.cpp:1523
#18 WebCore::FrameLoader::stopAllLoaders (this=0x7fffe3221b70, clearProvisionalItemPolicy=WebCore::ShouldClearProvisionalItem) at ../Source/WebCore/loader/FrameLoader.cpp:1501
#19 0x00007ffff0b0d17a in WebCore::FrameLoader::stopForUserCancel (this=0x7fffe3221b70, deferCheckLoadComplete=false) at ../Source/WebCore/loader/FrameLoader.cpp:1541
#20 0x00007ffff05f3a36 in webkit_web_view_dispose (object=0x12eb380) at ../Source/WebKit/gtk/webkit/webkitwebview.cpp:1327
#21 0x00007ffff27ff7a0 in g_object_run_dispose (object=0x12eb380) at /tmp/buildd/glib2.0-2.32.3/./gobject/gobject.c:1061
#22 0x00007ffff4476c1e in gtk_scrolled_window_forall (container=0x7fff9c007d10, include_internals=0, callback=0x7ffff452cd20 <IA__gtk_widget_destroy>, callback_data=0x0)
at /tmp/buildd/gtk+2.0-2.24.10/gtk/gtkscrolledwindow.c:1085
#23 0x00007ffff439872f in gtk_container_destroy (object=0x7fff9c007d10) at /tmp/buildd/gtk+2.0-2.24.10/gtk/gtkcontainer.c:1073
...
#28 0x00007ffff443cd60 in gtk_object_dispose (gobject=0x7fff9c007d10) at /tmp/buildd/gtk+2.0-2.24.10/gtk/gtkobject.c:421
#29 0x00007ffff27ff7a0 in g_object_run_dispose (object=0x7fff9c007d10) at /tmp/buildd/glib2.0-2.32.3/./gobject/gobject.c:1061
#30 0x00007ffff6cb65ac in wxWindow::~wxWindow (this=0x13ee040, __in_chrg=<optimized out>) at src/gtk/window.cpp:2367
#31 0x00007ffff6d71241 in wxControlBase::~wxControlBase (this=0x13ee040, __in_chrg=<optimized out>) at src/common/ctrlcmn.cpp:49
#32 0x00000000005cf761 in wxControl::~wxControl (this=0x13ee040, __in_chrg=<optimized out>) at include/wx/gtk/control.h:27
#33 0x00007ffff7bd1eae in wxWebView::~wxWebView (this=0x13ee040, __in_chrg=<optimized out>) at include/wx/webview.h:96
#34 0x00007ffff7bd3443 in wxWebViewWebKit::~wxWebViewWebKit (this=0x13ee040, __in_chrg=<optimized out>) at include/wx/gtk/webview_webkit.h:26
#35 0x00007ffff7bd34ae in wxWebViewWebKit::~wxWebViewWebKit (this=0x13ee040, __in_chrg=<optimized out>) at include/wx/gtk/webview_webkit.h:26
Fix this by setting m_isBeingDeleted flag for wxWebViewWebKit early and
checking it in the callback.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72173 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-07-23 11:03:05 -04:00
|
|
|
virtual ~wxWebViewWebKit();
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool Enable( bool enable = true ) wxOVERRIDE;
|
2011-05-04 14:24:30 -04:00
|
|
|
|
|
|
|
// implementation
|
|
|
|
// --------------
|
|
|
|
|
|
|
|
static wxVisualAttributes
|
|
|
|
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void Stop() wxOVERRIDE;
|
|
|
|
virtual void LoadURL(const wxString& url) wxOVERRIDE;
|
|
|
|
virtual void GoBack() wxOVERRIDE;
|
|
|
|
virtual void GoForward() wxOVERRIDE;
|
|
|
|
virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) wxOVERRIDE;
|
|
|
|
virtual bool CanGoBack() const wxOVERRIDE;
|
|
|
|
virtual bool CanGoForward() const wxOVERRIDE;
|
|
|
|
virtual void ClearHistory() wxOVERRIDE;
|
|
|
|
virtual void EnableContextMenu(bool enable = true) wxOVERRIDE;
|
|
|
|
virtual void EnableHistory(bool enable = true) wxOVERRIDE;
|
|
|
|
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory() wxOVERRIDE;
|
|
|
|
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory() wxOVERRIDE;
|
|
|
|
virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) wxOVERRIDE;
|
|
|
|
virtual wxString GetCurrentURL() const wxOVERRIDE;
|
|
|
|
virtual wxString GetCurrentTitle() const wxOVERRIDE;
|
|
|
|
virtual wxString GetPageSource() const wxOVERRIDE;
|
|
|
|
virtual wxString GetPageText() const wxOVERRIDE;
|
|
|
|
virtual void Print() wxOVERRIDE;
|
|
|
|
virtual bool IsBusy() const wxOVERRIDE;
|
|
|
|
|
|
|
|
void SetZoomType(wxWebViewZoomType) wxOVERRIDE;
|
|
|
|
wxWebViewZoomType GetZoomType() const wxOVERRIDE;
|
|
|
|
bool CanSetZoomType(wxWebViewZoomType) const wxOVERRIDE;
|
|
|
|
virtual wxWebViewZoom GetZoom() const wxOVERRIDE;
|
2020-06-13 11:50:55 -04:00
|
|
|
virtual float GetZoomFactor() const wxOVERRIDE;
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void SetZoom(wxWebViewZoom) wxOVERRIDE;
|
2020-06-13 11:50:55 -04:00
|
|
|
virtual void SetZoomFactor(float) wxOVERRIDE;
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-07-02 10:32:02 -04:00
|
|
|
//Clipboard functions
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool CanCut() const wxOVERRIDE;
|
|
|
|
virtual bool CanCopy() const wxOVERRIDE;
|
|
|
|
virtual bool CanPaste() const wxOVERRIDE;
|
|
|
|
virtual void Cut() wxOVERRIDE;
|
|
|
|
virtual void Copy() wxOVERRIDE;
|
|
|
|
virtual void Paste() wxOVERRIDE;
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-07-02 11:07:46 -04:00
|
|
|
//Undo / redo functionality
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool CanUndo() const wxOVERRIDE;
|
|
|
|
virtual bool CanRedo() const wxOVERRIDE;
|
|
|
|
virtual void Undo() wxOVERRIDE;
|
|
|
|
virtual void Redo() wxOVERRIDE;
|
2011-07-02 11:07:46 -04:00
|
|
|
|
2012-08-28 13:13:13 -04:00
|
|
|
//Find function
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT) wxOVERRIDE;
|
2012-08-28 13:13:13 -04:00
|
|
|
|
2011-07-08 15:34:56 -04:00
|
|
|
//Editing functions
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void SetEditable(bool enable = true) wxOVERRIDE;
|
|
|
|
virtual bool IsEditable() const wxOVERRIDE;
|
2011-07-08 15:34:56 -04:00
|
|
|
|
2011-07-09 10:31:29 -04:00
|
|
|
//Selection
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void DeleteSelection() wxOVERRIDE;
|
|
|
|
virtual bool HasSelection() const wxOVERRIDE;
|
|
|
|
virtual void SelectAll() wxOVERRIDE;
|
|
|
|
virtual wxString GetSelectedText() const wxOVERRIDE;
|
|
|
|
virtual wxString GetSelectedSource() const wxOVERRIDE;
|
|
|
|
virtual void ClearSelection() wxOVERRIDE;
|
2011-07-09 10:31:29 -04:00
|
|
|
|
2017-09-02 18:24:06 -04:00
|
|
|
virtual bool RunScript(const wxString& javascript, wxString* output = NULL) wxOVERRIDE;
|
2012-03-28 14:00:30 -04:00
|
|
|
|
2011-07-28 12:49:48 -04:00
|
|
|
//Virtual Filesystem Support
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE;
|
2011-08-14 08:15:34 -04:00
|
|
|
virtual wxVector<wxSharedPtr<wxWebViewHandler> > GetHandlers() { return m_handlerList; }
|
2011-07-15 08:38:47 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void* GetNativeBackend() const wxOVERRIDE { return m_web_view; }
|
2012-07-24 17:59:21 -04:00
|
|
|
|
2011-05-04 14:24:30 -04:00
|
|
|
/** TODO: check if this can be made private
|
|
|
|
* The native control has a getter to check for busy state, but except in
|
|
|
|
* very recent versions of webkit this getter doesn't say everything we need
|
|
|
|
* (namely it seems to stay indefinitely busy when loading is cancelled by
|
|
|
|
* user)
|
|
|
|
*/
|
|
|
|
bool m_busy;
|
2011-08-08 11:12:33 -04:00
|
|
|
|
2011-08-05 05:06:45 -04:00
|
|
|
wxString m_vfsurl;
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-08-04 04:30:37 -04:00
|
|
|
//We use this flag to stop recursion when we load a page from the navigation
|
|
|
|
//callback, mainly when loading a VFS page
|
|
|
|
bool m_guard;
|
2013-09-13 08:55:08 -04:00
|
|
|
//This flag is use to indicate when a navigation event is the result of a
|
|
|
|
//create-web-view signal and so we need to send a new window event
|
|
|
|
bool m_creating;
|
2011-08-04 04:30:37 -04:00
|
|
|
|
2011-05-04 14:24:30 -04:00
|
|
|
protected:
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void DoSetPage(const wxString& html, const wxString& baseUrl) wxOVERRIDE;
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE;
|
2011-05-04 14:24:30 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2011-08-17 06:36:14 -04:00
|
|
|
void ZoomIn();
|
|
|
|
void ZoomOut();
|
|
|
|
void SetWebkitZoom(float level);
|
|
|
|
float GetWebkitZoom() const;
|
|
|
|
|
2012-08-28 13:13:13 -04:00
|
|
|
//Find helper function
|
|
|
|
void FindClear();
|
|
|
|
|
2011-05-04 14:24:30 -04:00
|
|
|
// focus event handler: calls GTKUpdateBitmap()
|
|
|
|
void GTKOnFocus(wxFocusEvent& event);
|
|
|
|
|
2017-03-30 21:34:24 -04:00
|
|
|
#if wxUSE_WEBVIEW_WEBKIT2
|
|
|
|
bool CanExecuteEditingCommand(const gchar* command) const;
|
|
|
|
void SetupWebExtensionServer();
|
2020-10-05 10:41:26 -04:00
|
|
|
GDBusProxy *GetExtensionProxy() const;
|
2017-10-21 17:12:21 -04:00
|
|
|
bool RunScriptSync(const wxString& javascript, wxString* output = NULL);
|
2017-03-30 21:34:24 -04:00
|
|
|
#endif
|
|
|
|
|
2012-03-01 11:36:58 -05:00
|
|
|
WebKitWebView *m_web_view;
|
2011-11-16 20:23:03 -05:00
|
|
|
int m_historyLimit;
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-08-14 08:15:34 -04:00
|
|
|
wxVector<wxSharedPtr<wxWebViewHandler> > m_handlerList;
|
2011-08-03 05:29:30 -04:00
|
|
|
|
2012-08-28 13:13:13 -04:00
|
|
|
//variables used for Find()
|
|
|
|
int m_findFlags;
|
|
|
|
wxString m_findText;
|
|
|
|
int m_findPosition;
|
|
|
|
int m_findCount;
|
|
|
|
|
2017-03-30 21:34:24 -04:00
|
|
|
#if wxUSE_WEBVIEW_WEBKIT2
|
|
|
|
//Used for webkit2 extension
|
|
|
|
GDBusServer *m_dbusServer;
|
|
|
|
GDBusProxy *m_extension;
|
|
|
|
#endif
|
|
|
|
|
2011-08-01 11:49:05 -04:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit);
|
2011-05-04 14:24:30 -04:00
|
|
|
};
|
|
|
|
|
2013-01-13 14:22:24 -05:00
|
|
|
class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit : public wxWebViewFactory
|
|
|
|
{
|
|
|
|
public:
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxWebView* Create() wxOVERRIDE { return new wxWebViewWebKit; }
|
2013-01-13 14:22:24 -05:00
|
|
|
virtual wxWebView* Create(wxWindow* parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& url = wxWebViewDefaultURLStr,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0,
|
2019-10-22 06:34:29 -04:00
|
|
|
const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE
|
2013-01-13 14:22:24 -05:00
|
|
|
{ return new wxWebViewWebKit(parent, id, url, pos, size, style, name); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-12 14:35:39 -04:00
|
|
|
#endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-05-05 09:01:54 -04:00
|
|
|
#endif
|