1d26276
From ec6e54bc893fb7516731ca9c71e0d0bbc5ae9ff7 Mon Sep 17 00:00:00 2001
37c4987
From: Scott Talbert <swt@techie.net>
1d26276
Date: Thu, 30 Mar 2017 21:34:24 -0400
1d26276
Subject: [PATCH] Add support for WebKit2GTK+ in wxWebView
37c4987
1d26276
Closes https://github.com/wxWidgets/wxWidgets/pull/469
37c4987
---
1d26276
 Makefile.in                                |   58 +-
1d26276
 autoconf_inc.m4                            |    6 +
1d26276
 build/bakefiles/config.bkl                 |    1 +
1d26276
 build/bakefiles/files.bkl                  |    5 +
1d26276
 build/bakefiles/multilib.bkl               |    1 +
1d26276
 build/bakefiles/plugins.bkl                |    5 +
1d26276
 configure                                  |  108 ++-
1d26276
 configure.in                               |   42 +-
1d26276
 docs/changes.txt                           |    8 +
1d26276
 include/wx/android/setup.h                 |   13 +-
1d26276
 include/wx/chkconf.h                       |    2 +-
1d26276
 include/wx/gtk/setup0.h                    |   13 +-
1d26276
 include/wx/gtk/webview_webkit.h            |   18 +-
1d26276
 include/wx/gtk/webview_webkit2_extension.h |   15 +
1d26276
 include/wx/gtk/webviewhistoryitem_webkit.h |    2 +-
1d26276
 include/wx/motif/setup0.h                  |   13 +-
1d26276
 include/wx/msw/setup0.h                    |   13 +-
1d26276
 include/wx/msw/wince/setup.h               |   13 +-
1d26276
 include/wx/os2/setup0.h                    |   13 +-
1d26276
 include/wx/osx/setup0.h                    |   13 +-
1d26276
 include/wx/setup_inc.h                     |   13 +-
1d26276
 include/wx/univ/setup0.h                   |   13 +-
1d26276
 interface/wx/webview.h                     |    4 +
1d26276
 samples/webview/webview.cpp                |    2 +-
1d26276
 setup.h.in                                 |    8 +-
1d26276
 src/gtk/webview_webkit2.cpp                | 1261 ++++++++++++++++++++++++++++
1d26276
 src/gtk/webview_webkit2_extension.cpp      |  421 ++++++++++
1d26276
 27 files changed, 2046 insertions(+), 38 deletions(-)
1d26276
 create mode 100644 include/wx/gtk/webview_webkit2_extension.h
1d26276
 create mode 100644 src/gtk/webview_webkit2.cpp
1d26276
 create mode 100644 src/gtk/webview_webkit2_extension.cpp
37c4987
1d26276
diff --git a/Makefile.in b/Makefile.in
1d26276
index 7a10765..f032587 100644
1d26276
--- a/Makefile.in
1d26276
+++ b/Makefile.in
1d26276
@@ -1655,12 +1655,14 @@ WEBVIEWDLL_CXXFLAGS = $(__webviewdll_PCH_INC) -D__WX$(TOOLKIT)__ \
1d26276
 	$(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) -DWXBUILDING $(__INC_TIFF_BUILD_p) \
1d26276
 	$(__INC_TIFF_p) $(__INC_JPEG_p) $(__INC_PNG_p) $(__INC_ZLIB_p) \
1d26276
 	$(__INC_REGEX_p) $(__INC_EXPAT_p) -DWXUSINGDLL -DWXMAKINGDLL_WEBVIEW \
1d26276
+	-DWX_WEB_EXTENSIONS_DIRECTORY=\"$(PLUGINS_INST_DIR)/web-extensions\" \
1d26276
 	$(PIC_FLAG) $(CXXWARNINGS) $(CPPFLAGS) $(CXXFLAGS)
1d26276
 WEBVIEWDLL_OBJCXXFLAGS = $(__webviewdll_PCH_INC) -D__WX$(TOOLKIT)__ \
1d26276
 	$(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) \
1d26276
 	$(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) -DWXBUILDING $(__INC_TIFF_BUILD_p) \
1d26276
 	$(__INC_TIFF_p) $(__INC_JPEG_p) $(__INC_PNG_p) $(__INC_ZLIB_p) \
1d26276
 	$(__INC_REGEX_p) $(__INC_EXPAT_p) -DWXUSINGDLL -DWXMAKINGDLL_WEBVIEW \
1d26276
+	-DWX_WEB_EXTENSIONS_DIRECTORY=\"$(PLUGINS_INST_DIR)/web-extensions\" \
1d26276
 	$(PIC_FLAG) $(CPPFLAGS) $(OBJCXXFLAGS)
1d26276
 WEBVIEWDLL_OBJECTS =  \
1d26276
 	$(__webviewdll___win32rc) \
1d26276
@@ -2078,6 +2080,10 @@ SOUND_SDL_CXXFLAGS = -DWXUSINGDLL -DwxUSE_GUI=0 $(PIC_FLAG) $(CPPFLAGS) \
1d26276
 	$(CXXFLAGS)
1d26276
 SOUND_SDL_OBJECTS =  \
1d26276
 	sound_sdl_sound_sdl.o
1d26276
+WEBKIT2_EXT_CXXFLAGS = -DWXUSINGDLL -DwxUSE_GUI=0 $(PIC_FLAG) $(CPPFLAGS) \
1d26276
+	$(CXXFLAGS)
1d26276
+WEBKIT2_EXT_OBJECTS =  \
1d26276
+	webkit2_ext_webview_webkit2_extension.o
1d26276
 LOCALE_LINGUAS = ca cs da de el es fi fr hu id it ja nl pl ru sl sv tr uk zh zh_CN zh_TW
1d26276
 LOCALE_MSW_LINGUAS =  it
1d26276
 
1d26276
@@ -6754,6 +6760,8 @@ COND_TOOLKIT_X11___ADVANCED_PLATFORM_SRC_OBJECTS_1 =  \
1d26276
 @COND_PLATFORM_MACOSX_1@	= monodll_osx_webview_webkit.o
1d26276
 @COND_TOOLKIT_GTK@__WEBVIEW_SRC_PLATFORM_OBJECTS = \
1d26276
 @COND_TOOLKIT_GTK@	monodll_gtk_webview_webkit.o
1d26276
+@COND_TOOLKIT_GTK@__WEBVIEW_SRC_PLATFORM_OBJECTS = \
1d26276
+@COND_TOOLKIT_GTK@	monodll_webview_webkit2.o
1d26276
 @COND_TOOLKIT_MSW@__WEBVIEW_SRC_PLATFORM_OBJECTS = monodll_webview_ie.o
1d26276
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__AUI_GTK_SRC_OBJECTS \
1d26276
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@	= monodll_tabartgtk.o
1d26276
@@ -9009,6 +9017,8 @@ COND_TOOLKIT_X11___ADVANCED_PLATFORM_SRC_OBJECTS_3 =  \
1d26276
 @COND_PLATFORM_MACOSX_1@	= monolib_osx_webview_webkit.o
1d26276
 @COND_TOOLKIT_GTK@__WEBVIEW_SRC_PLATFORM_OBJECTS_1 = \
1d26276
 @COND_TOOLKIT_GTK@	monolib_gtk_webview_webkit.o
1d26276
+@COND_TOOLKIT_GTK@__WEBVIEW_SRC_PLATFORM_OBJECTS_1 = \
1d26276
+@COND_TOOLKIT_GTK@	monolib_webview_webkit2.o
1d26276
 @COND_TOOLKIT_MSW@__WEBVIEW_SRC_PLATFORM_OBJECTS_1 = monolib_webview_ie.o
1d26276
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__AUI_GTK_SRC_OBJECTS_1 \
1d26276
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@	= monolib_tabartgtk.o
1d26276
@@ -13765,6 +13775,8 @@ COND_USE_SOVERSOLARIS_1___webviewdll___so_symlinks_uninst_cmd = rm -f \
1d26276
 @COND_PLATFORM_MACOSX_1@	= webviewdll_osx_webview_webkit.o
1d26276
 @COND_TOOLKIT_GTK@__WEBVIEW_SRC_PLATFORM_OBJECTS_2 = \
1d26276
 @COND_TOOLKIT_GTK@	webviewdll_gtk_webview_webkit.o
1d26276
+@COND_TOOLKIT_GTK@__WEBVIEW_SRC_PLATFORM_OBJECTS_2 = \
1d26276
+@COND_TOOLKIT_GTK@	webviewdll_webview_webkit2.o
1d26276
 @COND_TOOLKIT_MSW@__WEBVIEW_SRC_PLATFORM_OBJECTS_2 = \
1d26276
 @COND_TOOLKIT_MSW@	webviewdll_webview_ie.o
1d26276
 COND_MONOLITHIC_0_SHARED_0_USE_GUI_1_USE_WEBVIEW_1___webviewlib___depname = \
1d26276
@@ -13784,6 +13796,8 @@ COND_MONOLITHIC_0_SHARED_0_USE_GUI_1_USE_WEBVIEW_1___webviewlib___depname = \
1d26276
 @COND_PLATFORM_MACOSX_1@	= webviewlib_osx_webview_webkit.o
1d26276
 @COND_TOOLKIT_GTK@__WEBVIEW_SRC_PLATFORM_OBJECTS_3 = \
1d26276
 @COND_TOOLKIT_GTK@	webviewlib_gtk_webview_webkit.o
1d26276
+@COND_TOOLKIT_GTK@__WEBVIEW_SRC_PLATFORM_OBJECTS_3 = \
1d26276
+@COND_TOOLKIT_GTK@	webviewlib_webview_webkit2.o
1d26276
 @COND_TOOLKIT_MSW@__WEBVIEW_SRC_PLATFORM_OBJECTS_3 = \
1d26276
 @COND_TOOLKIT_MSW@	webviewlib_webview_ie.o
1d26276
 @COND_SHARED_1@____wxwebview_namedll_DEP = $(__webviewdll___depname)
1d26276
@@ -14586,6 +14600,13 @@ COND_WITH_PLUGIN_SDL_1___sound_sdl___depname = \
1d26276
 @COND_WITH_PLUGIN_SDL_1@__install_sound_sdl___depname = install_sound_sdl
1d26276
 @COND_WITH_PLUGIN_SDL_1@__uninstall_sound_sdl___depname \
1d26276
 @COND_WITH_PLUGIN_SDL_1@	= uninstall_sound_sdl
1d26276
+COND_USE_WEBVIEW_WEBKIT2_1___webkit2_ext___depname = \
1d26276
+	$(DLLPREFIX_MODULE)webkit2_ext$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(PLUGVERDELIM)$(PLUGIN_VERSION0)$(WXCOMPILER).$(SO_SUFFIX_MODULE)
1d26276
+@COND_USE_WEBVIEW_WEBKIT2_1@__webkit2_ext___depname = $(COND_USE_WEBVIEW_WEBKIT2_1___webkit2_ext___depname)
1d26276
+@COND_USE_WEBVIEW_WEBKIT2_1@__install_webkit2_ext___depname \
1d26276
+@COND_USE_WEBVIEW_WEBKIT2_1@	= install_webkit2_ext
1d26276
+@COND_USE_WEBVIEW_WEBKIT2_1@__uninstall_webkit2_ext___depname \
1d26276
+@COND_USE_WEBVIEW_WEBKIT2_1@	= uninstall_webkit2_ext
1d26276
 @COND_USE_XRC_1@__wxrc___depname = wxrc
1d26276
 @COND_USE_XRC_1@__clean_wxrc___depname = clean-wxrc
1d26276
 @COND_USE_XRC_1@__install_wxrc___depname = install-wxrc
1d26276
@@ -15255,9 +15276,9 @@ COND_wxUSE_REGEX_builtin___LIB_REGEX_p = \
1d26276
 
1d26276
 ### Targets: ###
1d26276
 
1d26276
-all: $(__wxregex___depname) $(__wxzlib___depname) $(__wxpng___depname) $(__wxjpeg___depname) $(__wxtiff___depname) $(__wxexpat___depname) $(__wxscintilla___depname) $(__monodll___depname) $(__monolib___depname) $(__basedll___depname) $(__baselib___depname) $(__netdll___depname) $(__netlib___depname) $(__coredll___depname) $(__corelib___depname) $(__advdll___depname) $(__advlib___depname) $(__mediadll___depname) $(__medialib___depname) $(__htmldll___depname) $(__htmllib___depname) $(__webviewdll___depname) $(__webviewlib___depname) $(__qadll___depname) $(__qalib___depname) $(__xmldll___depname) $(__xmllib___depname) $(__xrcdll___depname) $(__xrclib___depname) $(__auidll___depname) $(__auilib___depname) $(__ribbondll___depname) $(__ribbonlib___depname) $(__propgriddll___depname) $(__propgridlib___depname) $(__richtextdll___depname) $(__richtextlib___depname) $(__stcdll___depname) $(__stclib___depname) $(__gldll___depname) $(__gllib___depname) $(__sound_sdl___depname) $(__wxrc___depname) $(__cocoa_res___depname)
1d26276
+all: $(__wxregex___depname) $(__wxzlib___depname) $(__wxpng___depname) $(__wxjpeg___depname) $(__wxtiff___depname) $(__wxexpat___depname) $(__wxscintilla___depname) $(__monodll___depname) $(__monolib___depname) $(__basedll___depname) $(__baselib___depname) $(__netdll___depname) $(__netlib___depname) $(__coredll___depname) $(__corelib___depname) $(__advdll___depname) $(__advlib___depname) $(__mediadll___depname) $(__medialib___depname) $(__htmldll___depname) $(__htmllib___depname) $(__webviewdll___depname) $(__webviewlib___depname) $(__qadll___depname) $(__qalib___depname) $(__xmldll___depname) $(__xmllib___depname) $(__xrcdll___depname) $(__xrclib___depname) $(__auidll___depname) $(__auilib___depname) $(__ribbondll___depname) $(__ribbonlib___depname) $(__propgriddll___depname) $(__propgridlib___depname) $(__richtextdll___depname) $(__richtextlib___depname) $(__stcdll___depname) $(__stclib___depname) $(__gldll___depname) $(__gllib___depname) $(__sound_sdl___depname) $(__webkit2_ext___depname) $(__wxrc___depname) $(__cocoa_res___depname)
1d26276
 
1d26276
-install: $(__install_wxregex___depname) $(__install_wxzlib___depname) $(__install_wxpng___depname) $(__install_wxjpeg___depname) $(__install_wxtiff___depname) $(__install_wxexpat___depname) $(__install_wxscintilla___depname) $(__install_monodll___depname) $(__install_monolib___depname) $(__install_basedll___depname) $(__install_baselib___depname) $(__install_netdll___depname) $(__install_netlib___depname) $(__install_coredll___depname) $(__install_corelib___depname) $(__install_advdll___depname) $(__install_advlib___depname) $(__install_mediadll___depname) $(__install_medialib___depname) $(__install_htmldll___depname) $(__install_htmllib___depname) $(__install_webviewdll___depname) $(__install_webviewlib___depname) $(__install_qadll___depname) $(__install_qalib___depname) $(__install_xmldll___depname) $(__install_xmllib___depname) $(__install_xrcdll___depname) $(__install_xrclib___depname) $(__install_auidll___depname) $(__install_auilib___depname) $(__install_ribbondll___depname) $(__install_ribbonlib___depname) $(__install_propgriddll___depname) $(__install_propgridlib___depname) $(__install_richtextdll___depname) $(__install_richtextlib___depname) $(__install_stcdll___depname) $(__install_stclib___depname) $(__install_gldll___depname) $(__install_gllib___depname) $(__install_sound_sdl___depname) $(__install_wxrc___depname) install-wxconfig locale_install locale_msw_install $(__cocoa_res_install___depname)
1d26276
+install: $(__install_wxregex___depname) $(__install_wxzlib___depname) $(__install_wxpng___depname) $(__install_wxjpeg___depname) $(__install_wxtiff___depname) $(__install_wxexpat___depname) $(__install_wxscintilla___depname) $(__install_monodll___depname) $(__install_monolib___depname) $(__install_basedll___depname) $(__install_baselib___depname) $(__install_netdll___depname) $(__install_netlib___depname) $(__install_coredll___depname) $(__install_corelib___depname) $(__install_advdll___depname) $(__install_advlib___depname) $(__install_mediadll___depname) $(__install_medialib___depname) $(__install_htmldll___depname) $(__install_htmllib___depname) $(__install_webviewdll___depname) $(__install_webviewlib___depname) $(__install_qadll___depname) $(__install_qalib___depname) $(__install_xmldll___depname) $(__install_xmllib___depname) $(__install_xrcdll___depname) $(__install_xrclib___depname) $(__install_auidll___depname) $(__install_auilib___depname) $(__install_ribbondll___depname) $(__install_ribbonlib___depname) $(__install_propgriddll___depname) $(__install_propgridlib___depname) $(__install_richtextdll___depname) $(__install_richtextlib___depname) $(__install_stcdll___depname) $(__install_stclib___depname) $(__install_gldll___depname) $(__install_gllib___depname) $(__install_sound_sdl___depname) $(__install_webkit2_ext___depname) $(__install_wxrc___depname) install-wxconfig locale_install locale_msw_install $(__cocoa_res_install___depname)
1d26276
 	$(INSTALL_DIR) $(DESTDIR)$(datadir)/aclocal
1d26276
 	(cd $(srcdir) ; $(INSTALL_DATA)  wxwin.m4 $(DESTDIR)$(datadir)/aclocal)
1d26276
 	$(INSTALL_DIR) $(DESTDIR)$(datadir)/bakefile/presets
1d26276
@@ -15293,7 +15314,7 @@ install: $(__install_wxregex___depname) $(__install_wxzlib___depname) $(__instal
1d26276
 	@echo " ------------------------------------------------------"
1d26276
 	@echo " "
1d26276
 
1d26276
-uninstall: $(__uninstall_wxregex___depname) $(__uninstall_wxzlib___depname) $(__uninstall_wxpng___depname) $(__uninstall_wxjpeg___depname) $(__uninstall_wxtiff___depname) $(__uninstall_wxexpat___depname) $(__uninstall_wxscintilla___depname) $(__uninstall_monodll___depname) $(__uninstall_monolib___depname) $(__uninstall_basedll___depname) $(__uninstall_baselib___depname) $(__uninstall_netdll___depname) $(__uninstall_netlib___depname) $(__uninstall_coredll___depname) $(__uninstall_corelib___depname) $(__uninstall_advdll___depname) $(__uninstall_advlib___depname) $(__uninstall_mediadll___depname) $(__uninstall_medialib___depname) $(__uninstall_htmldll___depname) $(__uninstall_htmllib___depname) $(__uninstall_webviewdll___depname) $(__uninstall_webviewlib___depname) $(__uninstall_qadll___depname) $(__uninstall_qalib___depname) $(__uninstall_xmldll___depname) $(__uninstall_xmllib___depname) $(__uninstall_xrcdll___depname) $(__uninstall_xrclib___depname) $(__uninstall_auidll___depname) $(__uninstall_auilib___depname) $(__uninstall_ribbondll___depname) $(__uninstall_ribbonlib___depname) $(__uninstall_propgriddll___depname) $(__uninstall_propgridlib___depname) $(__uninstall_richtextdll___depname) $(__uninstall_richtextlib___depname) $(__uninstall_stcdll___depname) $(__uninstall_stclib___depname) $(__uninstall_gldll___depname) $(__uninstall_gllib___depname) $(__uninstall_sound_sdl___depname) locale_uninstall locale_msw_uninstall
1d26276
+uninstall: $(__uninstall_wxregex___depname) $(__uninstall_wxzlib___depname) $(__uninstall_wxpng___depname) $(__uninstall_wxjpeg___depname) $(__uninstall_wxtiff___depname) $(__uninstall_wxexpat___depname) $(__uninstall_wxscintilla___depname) $(__uninstall_monodll___depname) $(__uninstall_monolib___depname) $(__uninstall_basedll___depname) $(__uninstall_baselib___depname) $(__uninstall_netdll___depname) $(__uninstall_netlib___depname) $(__uninstall_coredll___depname) $(__uninstall_corelib___depname) $(__uninstall_advdll___depname) $(__uninstall_advlib___depname) $(__uninstall_mediadll___depname) $(__uninstall_medialib___depname) $(__uninstall_htmldll___depname) $(__uninstall_htmllib___depname) $(__uninstall_webviewdll___depname) $(__uninstall_webviewlib___depname) $(__uninstall_qadll___depname) $(__uninstall_qalib___depname) $(__uninstall_xmldll___depname) $(__uninstall_xmllib___depname) $(__uninstall_xrcdll___depname) $(__uninstall_xrclib___depname) $(__uninstall_auidll___depname) $(__uninstall_auilib___depname) $(__uninstall_ribbondll___depname) $(__uninstall_ribbonlib___depname) $(__uninstall_propgriddll___depname) $(__uninstall_propgridlib___depname) $(__uninstall_richtextdll___depname) $(__uninstall_richtextlib___depname) $(__uninstall_stcdll___depname) $(__uninstall_stclib___depname) $(__uninstall_gldll___depname) $(__uninstall_gllib___depname) $(__uninstall_sound_sdl___depname) $(__uninstall_webkit2_ext___depname) locale_uninstall locale_msw_uninstall
1d26276
 	(cd $(DESTDIR)$(datadir)/aclocal ; rm -f wxwin.m4)
1d26276
 	(cd $(DESTDIR)$(datadir)/bakefile/presets ; rm -f wx.bkl wx_unix.bkl wx_win32.bkl wx_xrc.bkl wx_presets.py)
1d26276
 	for f in setup.h $(RCDEFS_H); do \
1d26276
@@ -15322,6 +15343,7 @@ install-strip: install
1d26276
 	$(STRIP) $(DESTDIR)$(libdir)/$(DLLPREFIX)$(WXDLLNAMEPREFIXGUI)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_stc$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)$(dll___targetsuf3)
1d26276
 	$(STRIP) $(DESTDIR)$(libdir)/$(DLLPREFIX)$(WXDLLNAMEPREFIXGUI)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)$(dll___targetsuf3)
1d26276
 	$(STRIP) $(DESTDIR)$(PLUGINS_INST_DIR)/$(DLLPREFIX_MODULE)sound_sdl$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(PLUGVERDELIM)$(PLUGIN_VERSION0)$(WXCOMPILER).$(SO_SUFFIX_MODULE)
1d26276
+	$(STRIP) $(DESTDIR)$(PLUGINS_INST_DIR)/web-extensions/$(DLLPREFIX_MODULE)webkit2_ext$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(PLUGVERDELIM)$(PLUGIN_VERSION0)$(WXCOMPILER).$(SO_SUFFIX_MODULE)
1d26276
 
1d26276
 clean: $(__clean_wxrc___depname)
1d26276
 	rm -rf ./.deps ./.pch
1d26276
@@ -15402,6 +15424,7 @@ clean: $(__clean_wxrc___depname)
1d26276
 	rm -f $(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX) $(LIBDIRNAME)/$(DLLPREFIX)$(WXDLLNAMEPREFIXGUI)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)$(dll___targetsuf2)
1d26276
 	rm -f $(LIBDIRNAME)/$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl-$(WX_RELEASE)$(HOST_SUFFIX)$(LIBEXT)
1d26276
 	rm -f $(DLLPREFIX_MODULE)sound_sdl$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(PLUGVERDELIM)$(PLUGIN_VERSION0)$(WXCOMPILER).$(SO_SUFFIX_MODULE)
1d26276
+	rm -f $(DLLPREFIX_MODULE)webkit2_ext$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(PLUGVERDELIM)$(PLUGIN_VERSION0)$(WXCOMPILER).$(SO_SUFFIX_MODULE)
1d26276
 	-(cd samples && $(MAKE) clean)
1d26276
 	rm -f lib/libwx_$(TOOLCHAIN_NAME).0.rsrc lib/libwx_$(TOOLCHAIN_NAME).0.r
1d26276
 
1d26276
@@ -16130,6 +16153,16 @@ distclean: clean
1d26276
 @COND_WITH_PLUGIN_SDL_1@uninstall_sound_sdl: 
1d26276
 @COND_WITH_PLUGIN_SDL_1@	rm -f $(DESTDIR)$(PLUGINS_INST_DIR)/$(DLLPREFIX_MODULE)sound_sdl$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(PLUGVERDELIM)$(PLUGIN_VERSION0)$(WXCOMPILER).$(SO_SUFFIX_MODULE)
1d26276
 
1d26276
+@COND_USE_WEBVIEW_WEBKIT2_1@$(DLLPREFIX_MODULE)webkit2_ext$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(PLUGVERDELIM)$(PLUGIN_VERSION0)$(WXCOMPILER).$(SO_SUFFIX_MODULE): $(WEBKIT2_EXT_OBJECTS)
1d26276
+@COND_USE_WEBVIEW_WEBKIT2_1@	$(SHARED_LD_MODULE_CXX) $@ $(WEBKIT2_EXT_OBJECTS)  $(LDFLAGS)  $(EXTRALIBS_WEBVIEW) $(LIBS)
1d26276
+
1d26276
+@COND_USE_WEBVIEW_WEBKIT2_1@install_webkit2_ext: $(__webkit2_ext___depname)
1d26276
+@COND_USE_WEBVIEW_WEBKIT2_1@	$(INSTALL_DIR) $(DESTDIR)$(PLUGINS_INST_DIR)/web-extensions
1d26276
+@COND_USE_WEBVIEW_WEBKIT2_1@	$(INSTALL_PROGRAM) $(DLLPREFIX_MODULE)webkit2_ext$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(PLUGVERDELIM)$(PLUGIN_VERSION0)$(WXCOMPILER).$(SO_SUFFIX_MODULE) $(DESTDIR)$(PLUGINS_INST_DIR)/web-extensions
1d26276
+
1d26276
+@COND_USE_WEBVIEW_WEBKIT2_1@uninstall_webkit2_ext: 
1d26276
+@COND_USE_WEBVIEW_WEBKIT2_1@	rm -f $(DESTDIR)$(PLUGINS_INST_DIR)/web-extensions/$(DLLPREFIX_MODULE)webkit2_ext$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(PLUGVERDELIM)$(PLUGIN_VERSION0)$(WXCOMPILER).$(SO_SUFFIX_MODULE)
1d26276
+
1d26276
 samples: 
1d26276
 	(cd samples && $(MAKE) all)
1d26276
 
1d26276
@@ -18563,6 +18596,9 @@ monodll_webview_ie.o: $(srcdir)/src/msw/webview_ie.cpp $(MONODLL_ODEP)
1d26276
 monodll_gtk_webview_webkit.o: $(srcdir)/src/gtk/webview_webkit.cpp $(MONODLL_ODEP)
1d26276
 	$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/gtk/webview_webkit.cpp
1d26276
 
1d26276
+monodll_webview_webkit2.o: $(srcdir)/src/gtk/webview_webkit2.cpp $(MONODLL_ODEP)
1d26276
+	$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/gtk/webview_webkit2.cpp
1d26276
+
1d26276
 monodll_osx_webview_webkit.o: $(srcdir)/src/osx/webview_webkit.mm $(MONODLL_ODEP)
1d26276
 	$(CXXC) -c -o $@ $(MONODLL_OBJCXXFLAGS) $(srcdir)/src/osx/webview_webkit.mm
1d26276
 
1d26276
@@ -24440,6 +24476,9 @@ monolib_webview_ie.o: $(srcdir)/src/msw/webview_ie.cpp $(MONOLIB_ODEP)
1d26276
 monolib_gtk_webview_webkit.o: $(srcdir)/src/gtk/webview_webkit.cpp $(MONOLIB_ODEP)
1d26276
 	$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/gtk/webview_webkit.cpp
1d26276
 
1d26276
+monolib_webview_webkit2.o: $(srcdir)/src/gtk/webview_webkit2.cpp $(MONOLIB_ODEP)
1d26276
+	$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/gtk/webview_webkit2.cpp
1d26276
+
1d26276
 monolib_osx_webview_webkit.o: $(srcdir)/src/osx/webview_webkit.mm $(MONOLIB_ODEP)
1d26276
 	$(CXXC) -c -o $@ $(MONOLIB_OBJCXXFLAGS) $(srcdir)/src/osx/webview_webkit.mm
1d26276
 
1d26276
@@ -39792,7 +39831,7 @@ htmllib_htmllbox.o: $(srcdir)/src/generic/htmllbox.cpp $(HTMLLIB_ODEP)
1d26276
 @COND_PLATFORM_MACOSX_1@	$(CXXC) -c -o $@ $(HTMLLIB_CXXFLAGS) $(srcdir)/src/html/chm.cpp
1d26276
 
1d26276
 webviewdll_version_rc.o: $(srcdir)/src/msw/version.rc $(WEBVIEWDLL_ODEP)
1d26276
-	$(WINDRES) -i$< -o$@    --define __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_67) $(__DEBUG_DEFINE_p_66)  $(__EXCEPTIONS_DEFINE_p_65) $(__RTTI_DEFINE_p_65) $(__THREAD_DEFINE_p_65)   --define WXBUILDING --define WXDLLNAME=$(WXDLLNAMEPREFIXGUI)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_webview$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG) $(__RCDEFDIR_p) --include-dir $(top_srcdir)/include $(__INC_TIFF_BUILD_p_66) $(__INC_TIFF_p_66) $(__INC_JPEG_p_66) $(__INC_PNG_p_65) $(__INC_ZLIB_p_67) $(__INC_REGEX_p_65) $(__INC_EXPAT_p_65) --define WXUSINGDLL --define WXMAKINGDLL_WEBVIEW
1d26276
+	$(WINDRES) -i$< -o$@    --define __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_67) $(__DEBUG_DEFINE_p_66)  $(__EXCEPTIONS_DEFINE_p_65) $(__RTTI_DEFINE_p_65) $(__THREAD_DEFINE_p_65)   --define WXBUILDING --define WXDLLNAME=$(WXDLLNAMEPREFIXGUI)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_webview$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG) $(__RCDEFDIR_p) --include-dir $(top_srcdir)/include $(__INC_TIFF_BUILD_p_66) $(__INC_TIFF_p_66) $(__INC_JPEG_p_66) $(__INC_PNG_p_65) $(__INC_ZLIB_p_67) $(__INC_REGEX_p_65) $(__INC_EXPAT_p_65) --define WXUSINGDLL --define WXMAKINGDLL_WEBVIEW --define WX_WEB_EXTENSIONS_DIRECTORY="$(PLUGINS_INST_DIR)/web-extensions"
1d26276
 
1d26276
 webviewdll_webview_ie.o: $(srcdir)/src/msw/webview_ie.cpp $(WEBVIEWDLL_ODEP)
1d26276
 	$(CXXC) -c -o $@ $(WEBVIEWDLL_CXXFLAGS) $(srcdir)/src/msw/webview_ie.cpp
1d26276
@@ -39800,6 +39839,9 @@ webviewdll_webview_ie.o: $(srcdir)/src/msw/webview_ie.cpp $(WEBVIEWDLL_ODEP)
1d26276
 webviewdll_gtk_webview_webkit.o: $(srcdir)/src/gtk/webview_webkit.cpp $(WEBVIEWDLL_ODEP)
1d26276
 	$(CXXC) -c -o $@ $(WEBVIEWDLL_CXXFLAGS) $(srcdir)/src/gtk/webview_webkit.cpp
1d26276
 
1d26276
+webviewdll_webview_webkit2.o: $(srcdir)/src/gtk/webview_webkit2.cpp $(WEBVIEWDLL_ODEP)
1d26276
+	$(CXXC) -c -o $@ $(WEBVIEWDLL_CXXFLAGS) $(srcdir)/src/gtk/webview_webkit2.cpp
1d26276
+
1d26276
 webviewdll_osx_webview_webkit.o: $(srcdir)/src/osx/webview_webkit.mm $(WEBVIEWDLL_ODEP)
1d26276
 	$(CXXC) -c -o $@ $(WEBVIEWDLL_OBJCXXFLAGS) $(srcdir)/src/osx/webview_webkit.mm
1d26276
 
1d26276
@@ -39818,6 +39860,9 @@ webviewlib_webview_ie.o: $(srcdir)/src/msw/webview_ie.cpp $(WEBVIEWLIB_ODEP)
1d26276
 webviewlib_gtk_webview_webkit.o: $(srcdir)/src/gtk/webview_webkit.cpp $(WEBVIEWLIB_ODEP)
1d26276
 	$(CXXC) -c -o $@ $(WEBVIEWLIB_CXXFLAGS) $(srcdir)/src/gtk/webview_webkit.cpp
1d26276
 
1d26276
+webviewlib_webview_webkit2.o: $(srcdir)/src/gtk/webview_webkit2.cpp $(WEBVIEWLIB_ODEP)
1d26276
+	$(CXXC) -c -o $@ $(WEBVIEWLIB_CXXFLAGS) $(srcdir)/src/gtk/webview_webkit2.cpp
1d26276
+
1d26276
 webviewlib_osx_webview_webkit.o: $(srcdir)/src/osx/webview_webkit.mm $(WEBVIEWLIB_ODEP)
1d26276
 	$(CXXC) -c -o $@ $(WEBVIEWLIB_OBJCXXFLAGS) $(srcdir)/src/osx/webview_webkit.mm
1d26276
 
1d26276
@@ -40658,6 +40703,9 @@ gllib_os2_glcanvas.o: $(srcdir)/src/os2/glcanvas.cpp $(GLLIB_ODEP)
1d26276
 sound_sdl_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp
1d26276
 	$(CXXC) -c -o $@ $(SOUND_SDL_CXXFLAGS) $(srcdir)/src/unix/sound_sdl.cpp
1d26276
 
1d26276
+webkit2_ext_webview_webkit2_extension.o: $(srcdir)/src/gtk/webview_webkit2_extension.cpp
1d26276
+	$(CXXC) -c -o $@ $(WEBKIT2_EXT_CXXFLAGS) $(srcdir)/src/gtk/webview_webkit2_extension.cpp
1d26276
+
1d26276
 
1d26276
 @COND_PYTHON@@COND_USE_STC_1@$(srcdir)/include/wx/stc/stc.h: \
1d26276
 @COND_PYTHON@@COND_USE_STC_1@$(srcdir)/src/stc/scintilla/include/Scintilla.iface \
1d26276
@@ -41569,4 +41617,4 @@ win-dist: MSW_ZIP_TEXT_DIST SAMPLES_DIST DEMOS_DIST UTILS_DIST MISC_DIST INTL_DI
1d26276
 	uninstall_richtextlib wxrichtext install_stcdll uninstall_stcdll \
1d26276
 	install_stclib uninstall_stclib wxstc install_gldll uninstall_gldll \
1d26276
 	install_gllib uninstall_gllib wxgl install_sound_sdl uninstall_sound_sdl \
1d26276
-	samples
1d26276
+	install_webkit2_ext uninstall_webkit2_ext samples
1d26276
diff --git a/autoconf_inc.m4 b/autoconf_inc.m4
1d26276
index 76cea6a..6bc6a0c 100644
1d26276
--- a/autoconf_inc.m4
1d26276
+++ b/autoconf_inc.m4
1d26276
@@ -1088,6 +1088,12 @@ dnl ### begin block 20_COND_USE_THREADS_1[../../demos/bombs/bombs.bkl,../../demo
1d26276
         COND_USE_THREADS_1=""
1d26276
     fi
1d26276
     AC_SUBST(COND_USE_THREADS_1)
1d26276
+dnl ### begin block 20_COND_USE_WEBVIEW_WEBKIT2_1[wx.bkl] ###
1d26276
+    COND_USE_WEBVIEW_WEBKIT2_1="#"
1d26276
+    if test "x$USE_WEBVIEW_WEBKIT2" = "x1" ; then
1d26276
+        COND_USE_WEBVIEW_WEBKIT2_1=""
1d26276
+    fi
1d26276
+    AC_SUBST(COND_USE_WEBVIEW_WEBKIT2_1)
1d26276
 dnl ### begin block 20_COND_USE_XRC_1[../../utils/execmon/execmon.bkl,../../utils/wxrc/wxrc.bkl,wx.bkl] ###
1d26276
     COND_USE_XRC_1="#"
1d26276
     if test "x$USE_XRC" = "x1" ; then
1d26276
diff --git a/build/bakefiles/config.bkl b/build/bakefiles/config.bkl
1d26276
index a43afb49..a95b405 100644
1d26276
--- a/build/bakefiles/config.bkl
1d26276
+++ b/build/bakefiles/config.bkl
1d26276
@@ -429,6 +429,7 @@ to run the tests, include CppUnit library here.
1d26276
         <option name="DYLIB_RPATH_INSTALL"/>
1d26276
         <option name="DYLIB_RPATH_POSTLINK"/>
1d26276
         <option name="SAMPLES_RPATH_FLAG"/>
1d26276
+        <option name="USE_WEBVIEW_WEBKIT2"/>
1d26276
 
1d26276
         
1d26276
         <option name="HEADER_PAD_OPTION"/>
1d26276
diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl
1d26276
index 6c32a7b..956a808 100644
1d26276
--- a/build/bakefiles/files.bkl
1d26276
+++ b/build/bakefiles/files.bkl
1d26276
@@ -3418,6 +3418,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
1d26276
 <set var="WEBVIEW_SRC_PLATFORM">
1d26276
     <if cond="TOOLKIT=='MSW'">src/msw/webview_ie.cpp</if>
1d26276
     <if cond="TOOLKIT=='GTK'">src/gtk/webview_webkit.cpp</if>
1d26276
+    <if cond="TOOLKIT=='GTK'">src/gtk/webview_webkit2.cpp</if>
1d26276
     <if cond="PLATFORM_MACOSX=='1'">src/osx/webview_webkit.mm</if>
1d26276
 </set>
1d26276
 <set var="WEBVIEW_SRC" hints="files">
1d26276
@@ -3449,6 +3450,10 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
1d26276
     wx/webviewfshandler.h
1d26276
 </set>
1d26276
 
1d26276
+<set var="WEBVIEW_WEBKIT2_EXTENSION_SRC" hints="files">
1d26276
+    src/gtk/webview_webkit2_extension.cpp
1d26276
+</set>
1d26276
+
1d26276
 
1d26276
 
1d26276
 
1d26276
diff --git a/build/bakefiles/multilib.bkl b/build/bakefiles/multilib.bkl
1d26276
index cf2d4eb..aa811b9 100644
1d26276
--- a/build/bakefiles/multilib.bkl
1d26276
+++ b/build/bakefiles/multilib.bkl
1d26276
@@ -180,6 +180,7 @@
1d26276
          cond="SHARED=='1' and USE_GUI=='1' and USE_WEBVIEW=='1' and MONOLITHIC=='0'">
1d26276
         <define>WXUSINGDLL</define>
1d26276
         <define>WXMAKINGDLL_WEBVIEW</define>
1d26276
+        <define>WX_WEB_EXTENSIONS_DIRECTORY="$(PLUGINS_INST_DIR)/web-extensions"</define>
1d26276
         <sources>$(WEBVIEW_SRC)</sources>
1d26276
         <library>coredll</library>
1d26276
         <library>basedll</library>
1d26276
diff --git a/build/bakefiles/plugins.bkl b/build/bakefiles/plugins.bkl
1d26276
index 2034f8c..cbf4ddb 100644
1d26276
--- a/build/bakefiles/plugins.bkl
1d26276
+++ b/build/bakefiles/plugins.bkl
1d26276
@@ -11,5 +11,10 @@
1d26276
         <ldlibs>$(EXTRALIBS_SDL)</ldlibs>
1d26276
     </wx-base-plugin>
1d26276
 
1d26276
+    <wx-base-plugin id="webkit2_ext" cond="USE_WEBVIEW_WEBKIT2=='1'">
1d26276
+        <sources>$(WEBVIEW_WEBKIT2_EXTENSION_SRC)</sources>
1d26276
+        <ldlibs>$(EXTRALIBS_WEBVIEW)</ldlibs>
1d26276
+        <install-to>$(PLUGINS_INST_DIR)/web-extensions</install-to>
1d26276
+    </wx-base-plugin>
1d26276
 
1d26276
 </makefile>
1d26276
diff --git a/configure b/configure
1d26276
index b01f393..3fa466a 100755
1d26276
--- a/configure
1d26276
+++ b/configure
1d26276
@@ -675,6 +675,7 @@ COND_WXUNIV_0
1d26276
 COND_WITH_PLUGIN_SDL_1
1d26276
 COND_WINDOWS_IMPLIB_1
1d26276
 COND_USE_XRC_1
1d26276
+COND_USE_WEBVIEW_WEBKIT2_1
1d26276
 COND_USE_THREADS_1
1d26276
 COND_USE_THREADS_0
1d26276
 COND_USE_STC_1
1d26276
@@ -37295,12 +37296,95 @@ fi
1d26276
 
1d26276
 if test "$wxUSE_WEBVIEW" = "yes"; then
1d26276
     USE_WEBVIEW_WEBKIT=0
1d26276
+    USE_WEBVIEW_WEBKIT2=0
1d26276
     if test "$wxUSE_WEBVIEW_WEBKIT" = "yes"; then
1d26276
         if test "$wxUSE_GTK" = 1; then
1d26276
-            webkitgtk=webkit-1.0
1d26276
             if test "$WXGTK3" = 1; then
1d26276
-                webkitgtk=webkitgtk-3.0
1d26276
+
1d26276
+pkg_failed=no
1d26276
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for WEBKIT" >&5
1d26276
+$as_echo_n "checking for WEBKIT... " >&6; }
1d26276
+
1d26276
+if test -n "$PKG_CONFIG"; then
1d26276
+    if test -n "$WEBKIT_CFLAGS"; then
1d26276
+        pkg_cv_WEBKIT_CFLAGS="$WEBKIT_CFLAGS"
1d26276
+    else
1d26276
+        if test -n "$PKG_CONFIG" && \
1d26276
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"webkit2gtk-4.0\""; } >&5
1d26276
+  ($PKG_CONFIG --exists --print-errors "webkit2gtk-4.0") 2>&5
1d26276
+  ac_status=$?
1d26276
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
1d26276
+  test $ac_status = 0; }; then
1d26276
+  pkg_cv_WEBKIT_CFLAGS=`$PKG_CONFIG --cflags "webkit2gtk-4.0" 2>/dev/null`
1d26276
+else
1d26276
+  pkg_failed=yes
1d26276
+fi
1d26276
+    fi
1d26276
+else
1d26276
+	pkg_failed=untried
1d26276
+fi
1d26276
+if test -n "$PKG_CONFIG"; then
1d26276
+    if test -n "$WEBKIT_LIBS"; then
1d26276
+        pkg_cv_WEBKIT_LIBS="$WEBKIT_LIBS"
1d26276
+    else
1d26276
+        if test -n "$PKG_CONFIG" && \
1d26276
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"webkit2gtk-4.0\""; } >&5
1d26276
+  ($PKG_CONFIG --exists --print-errors "webkit2gtk-4.0") 2>&5
1d26276
+  ac_status=$?
1d26276
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
1d26276
+  test $ac_status = 0; }; then
1d26276
+  pkg_cv_WEBKIT_LIBS=`$PKG_CONFIG --libs "webkit2gtk-4.0" 2>/dev/null`
1d26276
+else
1d26276
+  pkg_failed=yes
1d26276
+fi
1d26276
+    fi
1d26276
+else
1d26276
+	pkg_failed=untried
1d26276
+fi
1d26276
+
1d26276
+
1d26276
+
1d26276
+if test $pkg_failed = yes; then
1d26276
+
1d26276
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
1d26276
+        _pkg_short_errors_supported=yes
1d26276
+else
1d26276
+        _pkg_short_errors_supported=no
1d26276
+fi
1d26276
+        if test $_pkg_short_errors_supported = yes; then
1d26276
+	        WEBKIT_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "webkit2gtk-4.0"`
1d26276
+        else
1d26276
+	        WEBKIT_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "webkit2gtk-4.0"`
1d26276
+        fi
1d26276
+	# Put the nasty error message in config.log where it belongs
1d26276
+	echo "$WEBKIT_PKG_ERRORS" >&5
1d26276
+
1d26276
+
1d26276
+                                    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: webkit2gtk not found, falling back to webkitgtk" >&5
1d26276
+$as_echo "$as_me: WARNING: webkit2gtk not found, falling back to webkitgtk" >&2;}
1d26276
+
1d26276
+elif test $pkg_failed = untried; then
1d26276
+
1d26276
+                                    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: webkit2gtk not found, falling back to webkitgtk" >&5
1d26276
+$as_echo "$as_me: WARNING: webkit2gtk not found, falling back to webkitgtk" >&2;}
1d26276
+
1d26276
+else
1d26276
+	WEBKIT_CFLAGS=$pkg_cv_WEBKIT_CFLAGS
1d26276
+	WEBKIT_LIBS=$pkg_cv_WEBKIT_LIBS
1d26276
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
1d26276
+$as_echo "yes" >&6; }
1d26276
+
1d26276
+                                    USE_WEBVIEW_WEBKIT2=1
1d26276
+                                    CPPFLAGS="$CPPFLAGS $WEBKIT_CFLAGS"
1d26276
+                                    EXTRALIBS_WEBVIEW="$WEBKIT_LIBS"
1d26276
+
1d26276
+fi
1d26276
             fi
1d26276
+            if test "$USE_WEBVIEW_WEBKIT2" = 0; then
1d26276
+                webkitgtk=webkit-1.0
1d26276
+                if test "$WXGTK3" = 1; then
1d26276
+                    webkitgtk=webkitgtk-3.0
1d26276
+                fi
1d26276
 
1d26276
 pkg_failed=no
1d26276
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for WEBKIT" >&5
1d26276
@@ -37361,12 +37445,12 @@ fi
1d26276
 	echo "$WEBKIT_PKG_ERRORS" >&5
1d26276
 
1d26276
 
1d26276
-                                { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: webkitgtk not found." >&5
1d26276
+                                    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: webkitgtk not found." >&5
1d26276
 $as_echo "$as_me: WARNING: webkitgtk not found." >&2;}
1d26276
 
1d26276
 elif test $pkg_failed = untried; then
1d26276
 
1d26276
-                                { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: webkitgtk not found." >&5
1d26276
+                                    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: webkitgtk not found." >&5
1d26276
 $as_echo "$as_me: WARNING: webkitgtk not found." >&2;}
1d26276
 
1d26276
 else
1d26276
@@ -37375,11 +37459,12 @@ else
1d26276
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
1d26276
 $as_echo "yes" >&6; }
1d26276
 
1d26276
-                                USE_WEBVIEW_WEBKIT=1
1d26276
-                                CPPFLAGS="$CPPFLAGS $WEBKIT_CFLAGS"
1d26276
-                                EXTRALIBS_WEBVIEW="$WEBKIT_LIBS"
1d26276
+                                    USE_WEBVIEW_WEBKIT=1
1d26276
+                                    CPPFLAGS="$CPPFLAGS $WEBKIT_CFLAGS"
1d26276
+                                    EXTRALIBS_WEBVIEW="$WEBKIT_LIBS"
1d26276
 
1d26276
 fi
1d26276
+            fi
1d26276
         elif test "$wxUSE_MAC" = 1 -a "$USE_DARWIN" = 1; then
1d26276
                                     old_CPPFLAGS="$CPPFLAGS"
1d26276
             CPPFLAGS="-x objective-c++ $CPPFLAGS"
1d26276
@@ -37411,6 +37496,10 @@ fi
1d26276
             wxUSE_WEBVIEW="yes"
1d26276
             $as_echo "#define wxUSE_WEBVIEW_WEBKIT 1" >>confdefs.h
1d26276
 
1d26276
+        elif test "$USE_WEBVIEW_WEBKIT2" = 1; then
1d26276
+            wxUSE_WEBVIEW="yes"
1d26276
+            $as_echo "#define wxUSE_WEBVIEW_WEBKIT2 1" >>confdefs.h
1d26276
+
1d26276
         else
1d26276
             { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: WebKit not available, disabling wxWebView" >&5
1d26276
 $as_echo "$as_me: WARNING: WebKit not available, disabling wxWebView" >&2;}
1d26276
@@ -41665,6 +41754,11 @@ EOF
1d26276
         COND_USE_THREADS_1=""
1d26276
     fi
1d26276
 
1d26276
+    COND_USE_WEBVIEW_WEBKIT2_1="#"
1d26276
+    if test "x$USE_WEBVIEW_WEBKIT2" = "x1" ; then
1d26276
+        COND_USE_WEBVIEW_WEBKIT2_1=""
1d26276
+    fi
1d26276
+
1d26276
     COND_USE_XRC_1="#"
1d26276
     if test "x$USE_XRC" = "x1" ; then
1d26276
         COND_USE_XRC_1=""
37c4987
diff --git a/configure.in b/configure.in
1d26276
index 20d3eff..632fd70 100644
37c4987
--- a/configure.in
37c4987
+++ b/configure.in
1d26276
@@ -7252,22 +7252,37 @@ fi
1d26276
 
1d26276
 if test "$wxUSE_WEBVIEW" = "yes"; then
1d26276
     USE_WEBVIEW_WEBKIT=0
1d26276
+    USE_WEBVIEW_WEBKIT2=0
1d26276
     if test "$wxUSE_WEBVIEW_WEBKIT" = "yes"; then
37c4987
         if test "$wxUSE_GTK" = 1; then
1d26276
-            webkitgtk=webkit-1.0
37c4987
             if test "$WXGTK3" = 1; then
37c4987
-                webkitgtk=webkitgtk-3.0
1d26276
+                PKG_CHECK_MODULES([WEBKIT],
1d26276
+                                  [webkit2gtk-4.0],
1d26276
+                                  [
1d26276
+                                    USE_WEBVIEW_WEBKIT2=1
1d26276
+                                    CPPFLAGS="$CPPFLAGS $WEBKIT_CFLAGS"
1d26276
+                                    EXTRALIBS_WEBVIEW="$WEBKIT_LIBS"
1d26276
+                                  ],
1d26276
+                                  [
1d26276
+                                    AC_MSG_WARN([webkit2gtk not found, falling back to webkitgtk])
1d26276
+                                  ])
1d26276
+            fi
1d26276
+            if test "$USE_WEBVIEW_WEBKIT2" = 0; then
1d26276
+                webkitgtk=webkit-1.0
1d26276
+                if test "$WXGTK3" = 1; then
1d26276
+                    webkitgtk=webkitgtk-3.0
1d26276
+                fi
1d26276
+                PKG_CHECK_MODULES([WEBKIT],
1d26276
+                                  [$webkitgtk >= 1.3.1],
1d26276
+                                  [
1d26276
+                                    USE_WEBVIEW_WEBKIT=1
1d26276
+                                    CPPFLAGS="$CPPFLAGS $WEBKIT_CFLAGS"
1d26276
+                                    EXTRALIBS_WEBVIEW="$WEBKIT_LIBS"
1d26276
+                                  ],
1d26276
+                                  [
1d26276
+                                    AC_MSG_WARN([webkitgtk not found.])
1d26276
+                                  ])
37c4987
             fi
1d26276
-            PKG_CHECK_MODULES([WEBKIT],
1d26276
-                              [$webkitgtk >= 1.3.1],
1d26276
-                              [
1d26276
-                                USE_WEBVIEW_WEBKIT=1
1d26276
-                                CPPFLAGS="$CPPFLAGS $WEBKIT_CFLAGS"
1d26276
-                                EXTRALIBS_WEBVIEW="$WEBKIT_LIBS"
1d26276
-                              ],
1d26276
-                              [
1d26276
-                                AC_MSG_WARN([webkitgtk not found.])
1d26276
-                              ])
1d26276
         elif test "$wxUSE_MAC" = 1 -a "$USE_DARWIN" = 1; then
1d26276
             dnl Under Mac we always have the libraries but check for the
1d26276
             dnl headers
1d26276
@@ -7294,6 +7309,9 @@ if test "$wxUSE_WEBVIEW" = "yes"; then
1d26276
         if test "$USE_WEBVIEW_WEBKIT" = 1; then
1d26276
             wxUSE_WEBVIEW="yes"
1d26276
             AC_DEFINE(wxUSE_WEBVIEW_WEBKIT)
1d26276
+        elif test "$USE_WEBVIEW_WEBKIT2" = 1; then
1d26276
+            wxUSE_WEBVIEW="yes"
1d26276
+            AC_DEFINE(wxUSE_WEBVIEW_WEBKIT2)
1d26276
         else
1d26276
             AC_MSG_WARN([WebKit not available, disabling wxWebView])
1d26276
         fi
1d26276
diff --git a/docs/changes.txt b/docs/changes.txt
1d26276
index 0565bca..75158a5 100644
1d26276
--- a/docs/changes.txt
1d26276
+++ b/docs/changes.txt
1d26276
@@ -580,6 +580,14 @@ Major new features in this release
1d26276
 
1d26276
 
1d26276
 
1d26276
+3.0.4: (released 2017-??-??)
1d26276
+----------------------------
1d26276
+
1d26276
+wxGTK:
1d26276
+
1d26276
+- Allow using more recent WebKit2GTK+ in wxWebView (Scott Talbert).
1d26276
+
1d26276
+
1d26276
 3.0.3: (released 2017-05-02)
1d26276
 ----------------------------
1d26276
 
1d26276
diff --git a/include/wx/android/setup.h b/include/wx/android/setup.h
1d26276
index 3b9ab29..2bbbdaa 100644
1d26276
--- a/include/wx/android/setup.h
1d26276
+++ b/include/wx/android/setup.h
1d26276
@@ -726,12 +726,23 @@
1d26276
 // Default is 1 on GTK and OSX
1d26276
 //
1d26276
 // Recommended setting: 1
1d26276
-#if defined(__WXGTK__) || defined(__WXOSX__)
1d26276
+#if (defined(__WXGTK__) && !defined(__WXGTK3__)) || defined(__WXOSX__)
1d26276
 #define wxUSE_WEBVIEW_WEBKIT 1
1d26276
 #else
1d26276
 #define wxUSE_WEBVIEW_WEBKIT 0
1d26276
 #endif
1d26276
 
1d26276
+// Use the WebKit2 wxWebView backend
1d26276
+//
1d26276
+// Default is 1 on GTK3
1d26276
+//
1d26276
+// Recommended setting: 1
1d26276
+#if defined(__WXGTK3__)
1d26276
+#define wxUSE_WEBVIEW_WEBKIT2 1
1d26276
+#else
1d26276
+#define wxUSE_WEBVIEW_WEBKIT2 0
1d26276
+#endif
1d26276
+
1d26276
 // Enable the new wxGraphicsPath and wxGraphicsContext classes for an advanced
1d26276
 // 2D drawing API.  (Still somewhat experimental)
1d26276
 //
1d26276
diff --git a/include/wx/chkconf.h b/include/wx/chkconf.h
1d26276
index 47fa8ee..0c73823 100644
1d26276
--- a/include/wx/chkconf.h
1d26276
+++ b/include/wx/chkconf.h
1d26276
@@ -2190,7 +2190,7 @@
1d26276
 #   endif
1d26276
 #endif /* wxUSE_TREELISTCTRL */
1d26276
 
1d26276
-#if wxUSE_WEBVIEW && !(wxUSE_WEBVIEW_WEBKIT || wxUSE_WEBVIEW_IE)
1d26276
+#if wxUSE_WEBVIEW && !(wxUSE_WEBVIEW_WEBKIT || wxUSE_WEBVIEW_WEBKIT2 || wxUSE_WEBVIEW_IE)
1d26276
 #   ifdef wxABORT_ON_CONFIG_ERROR
1d26276
 #       error "wxUSE_WEBVIEW requires at least one backend"
1d26276
 #   else
37c4987
diff --git a/include/wx/gtk/webview_webkit.h b/include/wx/gtk/webview_webkit.h
1d26276
index e1a01bf..046554e 100644
37c4987
--- a/include/wx/gtk/webview_webkit.h
37c4987
+++ b/include/wx/gtk/webview_webkit.h
1d26276
@@ -11,10 +11,15 @@
37c4987
 
1d26276
 #include "wx/defs.h"
1d26276
 
1d26276
-#if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
1d26276
+// NOTE: this header is used for both the WebKit1 and WebKit2 implementations
1d26276
+#if wxUSE_WEBVIEW && (wxUSE_WEBVIEW_WEBKIT || wxUSE_WEBVIEW_WEBKIT2) && defined(__WXGTK__)
37c4987
 
1d26276
 #include "wx/sharedptr.h"
1d26276
 #include "wx/webview.h"
1d26276
+#if wxUSE_WEBVIEW_WEBKIT2
1d26276
+#include <glib.h>
1d26276
+#include <gio/gio.h>
1d26276
+#endif
37c4987
 
1d26276
 typedef struct _WebKitWebView WebKitWebView;
37c4987
 
1d26276
@@ -152,6 +157,11 @@ class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit : public wxWebView
1d26276
     // focus event handler: calls GTKUpdateBitmap()
1d26276
     void GTKOnFocus(wxFocusEvent& event);
1d26276
 
1d26276
+#if wxUSE_WEBVIEW_WEBKIT2
1d26276
+    bool CanExecuteEditingCommand(const gchar* command) const;
1d26276
+    void SetupWebExtensionServer();
1d26276
+#endif
1d26276
+
1d26276
     WebKitWebView *m_web_view;
1d26276
     int m_historyLimit;
1d26276
 
1d26276
@@ -163,6 +173,12 @@ class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit : public wxWebView
1d26276
     int m_findPosition;
1d26276
     int m_findCount;
1d26276
 
1d26276
+#if wxUSE_WEBVIEW_WEBKIT2
1d26276
+    //Used for webkit2 extension
1d26276
+    GDBusServer *m_dbusServer;
1d26276
+    GDBusProxy *m_extension;
1d26276
+#endif
1d26276
+
37c4987
     wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit);
37c4987
 };
37c4987
 
1d26276
diff --git a/include/wx/gtk/webview_webkit2_extension.h b/include/wx/gtk/webview_webkit2_extension.h
1d26276
new file mode 100644
1d26276
index 0000000..f554d69
1d26276
--- /dev/null
1d26276
+++ b/include/wx/gtk/webview_webkit2_extension.h
1d26276
@@ -0,0 +1,15 @@
1d26276
+/////////////////////////////////////////////////////////////////////////////
1d26276
+// Name:        include/gtk/wx/webview_webkit2_extension.h
1d26276
+// Purpose:     Common elements for webview webkit2 extension
1d26276
+// Author:      Scott Talbert
1d26276
+// Copyright:   (c) 2017 Scott Talbert
1d26276
+// Licence:     wxWindows licence
1d26276
+/////////////////////////////////////////////////////////////////////////////
1d26276
+
1d26276
+#ifndef _WX_GTK_WEBVIEW_WEBKIT2_EXTENSION_H_
1d26276
+#define _WX_GTK_WEBVIEW_WEBKIT2_EXTENSION_H_
1d26276
+
1d26276
+#define WXGTK_WEB_EXTENSION_OBJECT_PATH "/org/wxwidgets/wxGTK/WebExtension"
1d26276
+#define WXGTK_WEB_EXTENSION_INTERFACE   "org.wxwidgets.wxGTK.WebExtension"
1d26276
+
1d26276
+#endif
1d26276
diff --git a/include/wx/gtk/webviewhistoryitem_webkit.h b/include/wx/gtk/webviewhistoryitem_webkit.h
1d26276
index a798efd..3137b3a 100644
1d26276
--- a/include/wx/gtk/webviewhistoryitem_webkit.h
1d26276
+++ b/include/wx/gtk/webviewhistoryitem_webkit.h
1d26276
@@ -11,7 +11,7 @@
37c4987
 
1d26276
 #include "wx/setup.h"
1d26276
 
1d26276
-#if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
1d26276
+#if wxUSE_WEBVIEW && (wxUSE_WEBVIEW_WEBKIT || wxUSE_WEBVIEW_WEBKIT2) && defined(__WXGTK__)
1d26276
 
1d26276
 class WXDLLIMPEXP_WEBVIEW wxWebViewHistoryItem
37c4987
 {
1d26276
diff --git a/include/wx/msw/wince/setup.h b/include/wx/msw/wince/setup.h
1d26276
index 692445c..7044250 100644
1d26276
--- a/include/wx/msw/wince/setup.h
1d26276
+++ b/include/wx/msw/wince/setup.h
1d26276
@@ -745,12 +745,23 @@
1d26276
 // Default is 1 on GTK and OSX
1d26276
 //
1d26276
 // Recommended setting: 1
1d26276
-#if defined(__WXGTK__) || defined(__WXOSX__)
1d26276
+#if (defined(__WXGTK__) && !defined(__WXGTK3__)) || defined(__WXOSX__)
1d26276
 #define wxUSE_WEBVIEW_WEBKIT 1
1d26276
 #else
1d26276
 #define wxUSE_WEBVIEW_WEBKIT 0
1d26276
 #endif
1d26276
 
1d26276
+// Use the WebKit2 wxWebView backend
1d26276
+//
1d26276
+// Default is 1 on GTK3
1d26276
+//
1d26276
+// Recommended setting: 1
1d26276
+#if defined(__WXGTK3__)
1d26276
+#define wxUSE_WEBVIEW_WEBKIT2 1
1d26276
+#else
1d26276
+#define wxUSE_WEBVIEW_WEBKIT2 0
1d26276
+#endif
1d26276
+
1d26276
 // Enable the new wxGraphicsPath and wxGraphicsContext classes for an advanced
1d26276
 // 2D drawing API.  (Still somewhat experimental)
1d26276
 //
1d26276
diff --git a/include/wx/setup_inc.h b/include/wx/setup_inc.h
1d26276
index dbca6a4..f87b39d 100644
1d26276
--- a/include/wx/setup_inc.h
1d26276
+++ b/include/wx/setup_inc.h
1d26276
@@ -741,12 +741,23 @@
1d26276
 // Default is 1 on GTK and OSX
1d26276
 //
1d26276
 // Recommended setting: 1
1d26276
-#if defined(__WXGTK__) || defined(__WXOSX__)
1d26276
+#if (defined(__WXGTK__) && !defined(__WXGTK3__)) || defined(__WXOSX__)
1d26276
 #define wxUSE_WEBVIEW_WEBKIT 1
1d26276
 #else
1d26276
 #define wxUSE_WEBVIEW_WEBKIT 0
1d26276
 #endif
1d26276
 
1d26276
+// Use the WebKit2 wxWebView backend
1d26276
+//
1d26276
+// Default is 1 on GTK3
1d26276
+//
1d26276
+// Recommended setting: 1
1d26276
+#if defined(__WXGTK3__)
1d26276
+#define wxUSE_WEBVIEW_WEBKIT2 1
1d26276
+#else
1d26276
+#define wxUSE_WEBVIEW_WEBKIT2 0
1d26276
+#endif
1d26276
+
1d26276
 // Enable the new wxGraphicsPath and wxGraphicsContext classes for an advanced
1d26276
 // 2D drawing API.  (Still somewhat experimental)
1d26276
 //
1d26276
diff --git a/interface/wx/webview.h b/interface/wx/webview.h
1d26276
index 694eba7..e7ff2e9 100644
1d26276
--- a/interface/wx/webview.h
1d26276
+++ b/interface/wx/webview.h
1d26276
@@ -571,11 +571,15 @@ class wxWebView : public wxControl
1d26276
 
1d26276
     /**
1d26276
         Clear the history, this will also remove the visible page.
1d26276
+
1d26276
+        @note This is not implemented on the WebKit2GTK+ backend.
1d26276
     */
1d26276
     virtual void ClearHistory() = 0;
1d26276
 
1d26276
     /**
1d26276
         Enable or disable the history. This will also clear the history.
1d26276
+
1d26276
+        @note This is not implemented on the WebKit2GTK+ backend.
1d26276
     */
1d26276
     virtual void EnableHistory(bool enable = true) = 0;
1d26276
 
1d26276
diff --git a/samples/webview/webview.cpp b/samples/webview/webview.cpp
1d26276
index a1c6217..0c135c7 100644
1d26276
--- a/samples/webview/webview.cpp
1d26276
+++ b/samples/webview/webview.cpp
1d26276
@@ -21,7 +21,7 @@
1d26276
     #include "wx/wx.h"
1d26276
 #endif
1d26276
 
1d26276
-#if !wxUSE_WEBVIEW_WEBKIT && !wxUSE_WEBVIEW_IE
1d26276
+#if !wxUSE_WEBVIEW_WEBKIT && !wxUSE_WEBVIEW_WEBKIT2 && !wxUSE_WEBVIEW_IE
1d26276
 #error "A wxWebView backend is required by this sample"
1d26276
 #endif
1d26276
 
1d26276
diff --git a/setup.h.in b/setup.h.in
1d26276
index 86a162c..b1c630b 100644
1d26276
--- a/setup.h.in
1d26276
+++ b/setup.h.in
1d26276
@@ -340,12 +340,18 @@
1d26276
 #define wxUSE_WEBVIEW_IE 0
1d26276
 #endif
1d26276
 
1d26276
-#if defined(__WXGTK__) || defined(__WXOSX__)
1d26276
+#if (defined(__WXGTK__) && !defined(__WXGTK3__)) || defined(__WXOSX__)
1d26276
 #define wxUSE_WEBVIEW_WEBKIT 0
1d26276
 #else
1d26276
 #define wxUSE_WEBVIEW_WEBKIT 0
1d26276
 #endif
1d26276
 
1d26276
+#if defined(__WXGTK3__)
1d26276
+#define wxUSE_WEBVIEW_WEBKIT2 0
1d26276
+#else
1d26276
+#define wxUSE_WEBVIEW_WEBKIT2 0
1d26276
+#endif
1d26276
+
37c4987
 
1d26276
 #ifdef _MSC_VER
1d26276
 #   if _MSC_VER >= 1310
1d26276
diff --git a/src/gtk/webview_webkit2.cpp b/src/gtk/webview_webkit2.cpp
1d26276
new file mode 100644
1d26276
index 0000000..3e3393f
1d26276
--- /dev/null
1d26276
+++ b/src/gtk/webview_webkit2.cpp
1d26276
@@ -0,0 +1,1261 @@
1d26276
+/////////////////////////////////////////////////////////////////////////////
1d26276
+// Name:        src/gtk/webview_webkit2.cpp
1d26276
+// Purpose:     GTK WebKit2 backend for web view component
1d26276
+// Author:      Scott Talbert
1d26276
+// Copyright:   (c) 2017 Scott Talbert
1d26276
+// Licence:     wxWindows licence
1d26276
+/////////////////////////////////////////////////////////////////////////////
1d26276
+
1d26276
+// For compilers that support precompilation, includes "wx.h".
1d26276
+#include "wx/wxprec.h"
1d26276
+
1d26276
+#if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT2
1d26276
+
1d26276
+#include "wx/stockitem.h"
1d26276
+#include "wx/gtk/webview_webkit.h"
1d26276
+#include "wx/gtk/control.h"
1d26276
+#include "wx/gtk/private.h"
1d26276
+#include "wx/filesys.h"
1d26276
+#include "wx/base64.h"
1d26276
+#include "wx/log.h"
1d26276
+#include "wx/gtk/webview_webkit2_extension.h"
1d26276
+#include <webkit2/webkit2.h>
1d26276
+
1d26276
+// ----------------------------------------------------------------------------
1d26276
+// GTK callbacks
1d26276
+// ----------------------------------------------------------------------------
1d26276
+
1d26276
+extern "C"
1d26276
+{
1d26276
+
1d26276
+static void
37c4987
+wxgtk_webview_webkit_load_changed(GtkWidget *,
37c4987
+                                  WebKitLoadEvent load_event,
37c4987
+                                  wxWebViewWebKit *webKitCtrl)
1d26276
+{
1d26276
+    wxString url = webKitCtrl->GetCurrentURL();
1d26276
+
1d26276
+    wxString target; // TODO: get target (if possible)
1d26276
+
37c4987
+    if (load_event == WEBKIT_LOAD_FINISHED)
1d26276
+    {
1d26276
+        webKitCtrl->m_busy = false;
1d26276
+        wxWebViewEvent event(wxEVT_WEBVIEW_LOADED,
1d26276
+                             webKitCtrl->GetId(),
1d26276
+                             url, target);
1d26276
+
1d26276
+        if (webKitCtrl && webKitCtrl->GetEventHandler())
1d26276
+            webKitCtrl->GetEventHandler()->ProcessEvent(event);
1d26276
+    }
37c4987
+    else if (load_event == WEBKIT_LOAD_COMMITTED)
1d26276
+    {
1d26276
+        webKitCtrl->m_busy = true;
1d26276
+        wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATED,
1d26276
+                             webKitCtrl->GetId(),
1d26276
+                             url, target);
1d26276
+
1d26276
+        if (webKitCtrl && webKitCtrl->GetEventHandler())
1d26276
+            webKitCtrl->GetEventHandler()->ProcessEvent(event);
1d26276
+    }
1d26276
+}
1d26276
+
1d26276
+static gboolean
37c4987
+wxgtk_webview_webkit_navigation(WebKitWebView *web_view,
37c4987
+                                WebKitPolicyDecision *decision,
1d26276
+                                wxWebViewWebKit *webKitCtrl)
1d26276
+{
37c4987
+    WebKitNavigationPolicyDecision* navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION(decision);
37c4987
+    WebKitNavigationAction* action = webkit_navigation_policy_decision_get_navigation_action(navigation_decision);
37c4987
+    WebKitURIRequest* request = webkit_navigation_action_get_request(action);
37c4987
+    const gchar* uri = webkit_uri_request_get_uri(request);
37c4987
+    wxString target = webkit_navigation_policy_decision_get_frame_name(navigation_decision);
1d26276
+    
1d26276
+    //If m_creating is true then we are the result of a new window
1d26276
+    //and so we need to send the event and veto the load
1d26276
+    if(webKitCtrl->m_creating)
1d26276
+    {
1d26276
+        webKitCtrl->m_creating = false;
1d26276
+        wxWebViewEvent event(wxEVT_WEBVIEW_NEWWINDOW,
1d26276
+                             webKitCtrl->GetId(),
1d26276
+                             wxString(uri, wxConvUTF8),
1d26276
+                             target);
1d26276
+
1d26276
+        if(webKitCtrl && webKitCtrl->GetEventHandler())
1d26276
+            webKitCtrl->GetEventHandler()->ProcessEvent(event);
1d26276
+        
37c4987
+        webkit_policy_decision_ignore(decision);
1d26276
+        return TRUE;
1d26276
+    }
1d26276
+
1d26276
+    if(webKitCtrl->m_guard)
1d26276
+    {
1d26276
+        webKitCtrl->m_guard = false;
1d26276
+        //We set this to make sure that we don't try to load the page again from
1d26276
+        //the resource request callback
37c4987
+        webKitCtrl->m_vfsurl = webkit_web_view_get_uri(web_view);
37c4987
+        webkit_policy_decision_use(decision);
1d26276
+        return FALSE;
1d26276
+    }
1d26276
+
1d26276
+    webKitCtrl->m_busy = true;
1d26276
+
1d26276
+    wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATING,
1d26276
+                         webKitCtrl->GetId(),
1d26276
+                         wxString( uri, wxConvUTF8 ),
1d26276
+                         target);
1d26276
+
1d26276
+    if (webKitCtrl && webKitCtrl->GetEventHandler())
1d26276
+        webKitCtrl->GetEventHandler()->ProcessEvent(event);
1d26276
+
1d26276
+    if (!event.IsAllowed())
1d26276
+    {
1d26276
+        webKitCtrl->m_busy = false;
37c4987
+        webkit_policy_decision_ignore(decision);
1d26276
+        return TRUE;
1d26276
+    }
1d26276
+    else
1d26276
+    {
1d26276
+        wxString wxuri = uri;
1d26276
+        wxSharedPtr<wxWebViewHandler> handler;
37c4987
+        wxVector<wxSharedPtr<wxWebViewHandler> > handlers = webKitCtrl->GetHandlers();
1d26276
+        //We are not vetoed so see if we match one of the additional handlers
37c4987
+        for(wxVector<wxSharedPtr<wxWebViewHandler> >::iterator it = handlers.begin();
37c4987
+            it != handlers.end(); ++it)
1d26276
+        {
1d26276
+            if(wxuri.substr(0, (*it)->GetName().length()) == (*it)->GetName())
1d26276
+            {
1d26276
+                handler = (*it);
1d26276
+            }
1d26276
+        }
1d26276
+        //If we found a handler we can then use it to load the file directly
1d26276
+        //ourselves
1d26276
+        if(handler)
1d26276
+        {
1d26276
+            webKitCtrl->m_guard = true;
1d26276
+            wxFSFile* file = handler->GetFile(wxuri);
1d26276
+            if(file)
1d26276
+            {
1d26276
+                webKitCtrl->SetPage(*file->GetStream(), wxuri);
1d26276
+            }
1d26276
+            //We need to throw some sort of error here if file is NULL
37c4987
+            webkit_policy_decision_ignore(decision);
1d26276
+            return TRUE;
1d26276
+        }
1d26276
+        return FALSE;
1d26276
+    }
1d26276
+}
1d26276
+
1d26276
+static gboolean
37c4987
+wxgtk_webview_webkit_load_failed(WebKitWebView *,
37c4987
+                                 WebKitLoadEvent,
37c4987
+                                 gchar *uri,
37c4987
+                                 GError *error,
37c4987
+                                 wxWebViewWebKit* webKitWindow)
1d26276
+{
1d26276
+    webKitWindow->m_busy = false;
1d26276
+    wxWebViewNavigationError type = wxWEBVIEW_NAV_ERR_OTHER;
1d26276
+
1d26276
+    wxString description(error->message, wxConvUTF8);
1d26276
+
1d26276
+    if (strcmp(g_quark_to_string(error->domain), "soup_http_error_quark") == 0)
1d26276
+    {
1d26276
+        switch (error->code)
1d26276
+        {
1d26276
+            case SOUP_STATUS_CANCELLED:
1d26276
+                type = wxWEBVIEW_NAV_ERR_USER_CANCELLED;
1d26276
+                break;
1d26276
+
1d26276
+            case SOUP_STATUS_CANT_RESOLVE:
1d26276
+            case SOUP_STATUS_NOT_FOUND:
1d26276
+                type = wxWEBVIEW_NAV_ERR_NOT_FOUND;
1d26276
+                break;
1d26276
+
1d26276
+            case SOUP_STATUS_CANT_RESOLVE_PROXY:
1d26276
+            case SOUP_STATUS_CANT_CONNECT:
1d26276
+            case SOUP_STATUS_CANT_CONNECT_PROXY:
1d26276
+            case SOUP_STATUS_SSL_FAILED:
1d26276
+            case SOUP_STATUS_IO_ERROR:
1d26276
+                type = wxWEBVIEW_NAV_ERR_CONNECTION;
1d26276
+                break;
1d26276
+
1d26276
+            case SOUP_STATUS_MALFORMED:
1d26276
+                type = wxWEBVIEW_NAV_ERR_REQUEST;
1d26276
+                break;
1d26276
+
1d26276
+            case SOUP_STATUS_BAD_REQUEST:
1d26276
+                type = wxWEBVIEW_NAV_ERR_REQUEST;
1d26276
+                break;
1d26276
+
1d26276
+            case SOUP_STATUS_UNAUTHORIZED:
1d26276
+            case SOUP_STATUS_FORBIDDEN:
1d26276
+                type = wxWEBVIEW_NAV_ERR_AUTH;
1d26276
+                break;
1d26276
+
1d26276
+            case SOUP_STATUS_METHOD_NOT_ALLOWED:
1d26276
+            case SOUP_STATUS_NOT_ACCEPTABLE:
1d26276
+                type = wxWEBVIEW_NAV_ERR_SECURITY;
1d26276
+                break;
1d26276
+
1d26276
+            case SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED:
1d26276
+                type = wxWEBVIEW_NAV_ERR_AUTH;
1d26276
+                break;
1d26276
+
1d26276
+            case SOUP_STATUS_REQUEST_TIMEOUT:
1d26276
+                type = wxWEBVIEW_NAV_ERR_CONNECTION;
1d26276
+                break;
1d26276
+
1d26276
+            case SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE:
1d26276
+            case SOUP_STATUS_REQUEST_URI_TOO_LONG:
1d26276
+            case SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE:
1d26276
+                type = wxWEBVIEW_NAV_ERR_REQUEST;
1d26276
+                break;
1d26276
+
1d26276
+            case SOUP_STATUS_BAD_GATEWAY:
1d26276
+            case SOUP_STATUS_SERVICE_UNAVAILABLE:
1d26276
+            case SOUP_STATUS_GATEWAY_TIMEOUT:
1d26276
+                type = wxWEBVIEW_NAV_ERR_CONNECTION;
1d26276
+                break;
1d26276
+
1d26276
+            case SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED:
1d26276
+                type = wxWEBVIEW_NAV_ERR_REQUEST;
1d26276
+                break;
1d26276
+        }
1d26276
+    }
1d26276
+    else if (strcmp(g_quark_to_string(error->domain),
1d26276
+                    "webkit-network-error-quark") == 0)
1d26276
+    {
1d26276
+        switch (error->code)
1d26276
+        {
1d26276
+            case WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL:
1d26276
+                type = wxWEBVIEW_NAV_ERR_REQUEST;
1d26276
+                break;
1d26276
+
1d26276
+            case WEBKIT_NETWORK_ERROR_CANCELLED:
1d26276
+                type = wxWEBVIEW_NAV_ERR_USER_CANCELLED;
1d26276
+                break;
1d26276
+
1d26276
+            case WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST:
1d26276
+                type = wxWEBVIEW_NAV_ERR_NOT_FOUND;
1d26276
+                break;
1d26276
+        }
1d26276
+    }
1d26276
+    else if (strcmp(g_quark_to_string(error->domain),
1d26276
+                    "webkit-policy-error-quark") == 0)
1d26276
+    {
1d26276
+        switch (error->code)
1d26276
+        {
1d26276
+            case WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT:
1d26276
+                type = wxWEBVIEW_NAV_ERR_SECURITY;
1d26276
+                break;
1d26276
+        }
1d26276
+    }
1d26276
+
1d26276
+    wxWebViewEvent event(wxEVT_WEBVIEW_ERROR,
1d26276
+                         webKitWindow->GetId(),
1d26276
+                         uri, "");
1d26276
+    event.SetString(description);
1d26276
+    event.SetInt(type);
1d26276
+
1d26276
+    if (webKitWindow && webKitWindow->GetEventHandler())
1d26276
+    {
1d26276
+        webKitWindow->GetEventHandler()->ProcessEvent(event);
1d26276
+    }
1d26276
+
1d26276
+    return FALSE;
1d26276
+}
1d26276
+
1d26276
+static gboolean
37c4987
+wxgtk_webview_webkit_new_window(WebKitPolicyDecision *decision,
1d26276
+                                wxWebViewWebKit *webKitCtrl)
1d26276
+{
37c4987
+    WebKitNavigationPolicyDecision* navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION(decision);
37c4987
+    WebKitNavigationAction* action = webkit_navigation_policy_decision_get_navigation_action(navigation_decision);
37c4987
+    WebKitURIRequest* request = webkit_navigation_action_get_request(action);
37c4987
+    const gchar* uri = webkit_uri_request_get_uri(request);
1d26276
+
37c4987
+    wxString target = webkit_navigation_policy_decision_get_frame_name(navigation_decision);
1d26276
+    wxWebViewEvent event(wxEVT_WEBVIEW_NEWWINDOW,
1d26276
+                                       webKitCtrl->GetId(),
1d26276
+                                       wxString( uri, wxConvUTF8 ),
1d26276
+                                       target);
1d26276
+
1d26276
+    if (webKitCtrl && webKitCtrl->GetEventHandler())
1d26276
+        webKitCtrl->GetEventHandler()->ProcessEvent(event);
1d26276
+
1d26276
+    //We always want the user to handle this themselves
37c4987
+    webkit_policy_decision_ignore(decision);
1d26276
+    return TRUE;
1d26276
+}
1d26276
+
37c4987
+static gboolean
37c4987
+wxgtk_webview_webkit_decide_policy(WebKitWebView *web_view,
37c4987
+                                   WebKitPolicyDecision *decision,
37c4987
+                                   WebKitPolicyDecisionType type,
37c4987
+                                   wxWebViewWebKit *webKitCtrl)
37c4987
+{
37c4987
+    switch (type)
37c4987
+    {
37c4987
+        case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
37c4987
+            return wxgtk_webview_webkit_navigation(web_view, decision, webKitCtrl);
37c4987
+        case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
37c4987
+            return wxgtk_webview_webkit_new_window(decision, webKitCtrl);
37c4987
+        default:
37c4987
+            return FALSE;
37c4987
+    }
37c4987
+}
37c4987
+
1d26276
+static void
37c4987
+wxgtk_webview_webkit_title_changed(GtkWidget* widget,
37c4987
+                                   GParamSpec *,
1d26276
+                                   wxWebViewWebKit *webKitCtrl)
1d26276
+{
37c4987
+    gchar *title;
37c4987
+    g_object_get(G_OBJECT(widget), "title", &title, NULL);
37c4987
+
1d26276
+    wxWebViewEvent event(wxEVT_WEBVIEW_TITLE_CHANGED,
1d26276
+                         webKitCtrl->GetId(),
1d26276
+                         webKitCtrl->GetCurrentURL(),
1d26276
+                         "");
1d26276
+    event.SetString(wxString(title, wxConvUTF8));
1d26276
+
1d26276
+    if (webKitCtrl && webKitCtrl->GetEventHandler())
1d26276
+        webKitCtrl->GetEventHandler()->ProcessEvent(event);
1d26276
+
37c4987
+    g_free(title);
1d26276
+}
1d26276
+
1d26276
+static void
1d26276
+wxgtk_webview_webkit_resource_req(WebKitWebView *,
1d26276
+                                  WebKitWebResource *,
37c4987
+                                  WebKitURIRequest *request,
1d26276
+                                  wxWebViewWebKit *webKitCtrl)
1d26276
+{
37c4987
+    wxString uri = webkit_uri_request_get_uri(request);
1d26276
+
1d26276
+    wxSharedPtr<wxWebViewHandler> handler;
37c4987
+    wxVector<wxSharedPtr<wxWebViewHandler> > handlers = webKitCtrl->GetHandlers();
1d26276
+
1d26276
+    //We are not vetoed so see if we match one of the additional handlers
37c4987
+    for(wxVector<wxSharedPtr<wxWebViewHandler> >::iterator it = handlers.begin();
37c4987
+        it != handlers.end(); ++it)
1d26276
+    {
1d26276
+        if(uri.substr(0, (*it)->GetName().length()) == (*it)->GetName())
1d26276
+        {
1d26276
+            handler = (*it);
1d26276
+        }
1d26276
+    }
1d26276
+    //If we found a handler we can then use it to load the file directly
1d26276
+    //ourselves
1d26276
+    if(handler)
1d26276
+    {
1d26276
+        //If it is requsting the page itself then return as we have already
1d26276
+        //loaded it from the archive
1d26276
+        if(webKitCtrl->m_vfsurl == uri)
1d26276
+            return;
1d26276
+
1d26276
+        wxFSFile* file = handler->GetFile(uri);
1d26276
+        if(file)
1d26276
+        {
1d26276
+            //We load the data into a data url to save it being written out again
1d26276
+            size_t size = file->GetStream()->GetLength();
1d26276
+            char *buffer = new char[size];
1d26276
+            file->GetStream()->Read(buffer, size);
1d26276
+            wxString data = wxBase64Encode(buffer, size);
1d26276
+            delete[] buffer;
1d26276
+            wxString mime = file->GetMimeType();
1d26276
+            wxString path = "data:" + mime + ";base64," + data;
1d26276
+            //Then we can redirect the call
37c4987
+            webkit_uri_request_set_uri(request, path.utf8_str());
1d26276
+        }
1d26276
+
1d26276
+    }
1d26276
+}
1d26276
+
1d26276
+static gboolean
1d26276
+wxgtk_webview_webkit_context_menu(WebKitWebView *,
37c4987
+                                  WebKitContextMenu *,
37c4987
+                                  GdkEvent *,
1d26276
+                                  WebKitHitTestResult *,
1d26276
+                                  wxWebViewWebKit *webKitCtrl)
1d26276
+{
1d26276
+    if(webKitCtrl->IsContextMenuEnabled())
1d26276
+        return FALSE;
1d26276
+    else
1d26276
+        return TRUE;
1d26276
+}
1d26276
+
1d26276
+static WebKitWebView*
1d26276
+wxgtk_webview_webkit_create_webview(WebKitWebView *web_view,
37c4987
+                                    WebKitNavigationAction *,
1d26276
+                                    wxWebViewWebKit *webKitCtrl)
1d26276
+{
1d26276
+    //As we do not know the uri being loaded at this point allow the load to
1d26276
+    //continue and catch it in navigation-policy-decision-requested
1d26276
+    webKitCtrl->m_creating = true;
1d26276
+    return web_view;
1d26276
+}
1d26276
+
37c4987
+static void
37c4987
+wxgtk_webview_webkit_counted_matches(WebKitFindController *,
37c4987
+                                     guint match_count,
1d26276
+                                     int *findCount)
37c4987
+{
1d26276
+    *findCount = match_count;
37c4987
+}
37c4987
+
37c4987
+static void
1d26276
+wxgtk_initialize_web_extensions(WebKitWebContext *context,
1d26276
+                                GDBusServer *dbusServer)
37c4987
+{
1d26276
+    const char *address = g_dbus_server_get_client_address(dbusServer);
1d26276
+    GVariant *user_data = g_variant_new("(s)", address);
1d26276
+    webkit_web_context_set_web_extensions_directory(context,
1d26276
+                                                    WX_WEB_EXTENSIONS_DIRECTORY);
1d26276
+    webkit_web_context_set_web_extensions_initialization_user_data(context,
1d26276
+                                                                   user_data);
37c4987
+}
37c4987
+
1d26276
+static gboolean
1d26276
+wxgtk_new_connection_cb(GDBusServer *,
1d26276
+                        GDBusConnection *connection,
1d26276
+                        GDBusProxy **proxy)
37c4987
+{
1d26276
+    GError *error = NULL;
1d26276
+    GDBusProxyFlags flags = static_cast<GDBusProxyFlags>(static_cast<int>(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) | static_cast<int>(G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS));
1d26276
+    *proxy = g_dbus_proxy_new_sync(connection,
1d26276
+                                   flags,
1d26276
+                                   NULL,
1d26276
+                                   NULL,
1d26276
+                                   WXGTK_WEB_EXTENSION_OBJECT_PATH,
1d26276
+                                   WXGTK_WEB_EXTENSION_INTERFACE,
1d26276
+                                   NULL,
1d26276
+                                   &error);
1d26276
+    if (error)
1d26276
+    {
1d26276
+        g_warning("Failed to create dbus proxy: %s", error->message);
1d26276
+        g_error_free(error);
1d26276
+    }
1d26276
+
1d26276
+    return TRUE;
37c4987
+}
37c4987
+
1d26276
+gboolean
1d26276
+wxgtk_dbus_peer_is_authorized(GCredentials *peer_credentials)
1d26276
+{
1d26276
+    static GCredentials *own_credentials = g_credentials_new();
1d26276
+    GError *error = NULL;
1d26276
+
1d26276
+    if (peer_credentials && g_credentials_is_same_user(peer_credentials, own_credentials, &error))
1d26276
+    {
1d26276
+        return TRUE;
1d26276
+    }
1d26276
+
1d26276
+    if (error)
1d26276
+    {
1d26276
+        g_warning("Failed to authorize web extension connection: %s", error->message);
1d26276
+        g_error_free(error);
1d26276
+    }
1d26276
+    return FALSE;
1d26276
+}
1d26276
+
1d26276
+static gboolean
1d26276
+wxgtk_authorize_authenticated_peer_cb(GDBusAuthObserver *,
1d26276
+                                      GIOStream *,
1d26276
+                                      GCredentials *credentials,
1d26276
+                                      wxWebViewWebKit *)
1d26276
+{
1d26276
+    return wxgtk_dbus_peer_is_authorized(credentials);
1d26276
+}
1d26276
+
1d26276
+} // extern "C"
1d26276
+
1d26276
+//-----------------------------------------------------------------------------
1d26276
+// wxWebViewWebKit
1d26276
+//-----------------------------------------------------------------------------
1d26276
+
1d26276
+wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit, wxWebView);
1d26276
+
1d26276
+wxWebViewWebKit::wxWebViewWebKit()
1d26276
+{
1d26276
+    m_web_view = NULL;
1d26276
+    m_dbusServer = NULL;
1d26276
+    m_extension = NULL;
1d26276
+}
1d26276
+
1d26276
+bool wxWebViewWebKit::Create(wxWindow *parent,
1d26276
+                      wxWindowID id,
1d26276
+                      const wxString &url,
1d26276
+                      const wxPoint& pos,
1d26276
+                      const wxSize& size,
1d26276
+                      long style,
1d26276
+                      const wxString& name)
1d26276
+{
1d26276
+    m_busy = false;
1d26276
+    m_guard = false;
1d26276
+    m_creating = false;
1d26276
+    FindClear();
1d26276
+
1d26276
+    // We currently unconditionally impose scrolling in both directions as it's
1d26276
+    // necessary to show arbitrary pages.
1d26276
+    style |= wxHSCROLL | wxVSCROLL;
1d26276
+
1d26276
+    if (!PreCreation( parent, pos, size ) ||
1d26276
+        !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
1d26276
+    {
1d26276
+        wxFAIL_MSG( wxT("wxWebViewWebKit creation failed") );
1d26276
+        return false;
1d26276
+    }
1d26276
+
1d26276
+    SetupWebExtensionServer();
1d26276
+    g_signal_connect_after(webkit_web_context_get_default(),
1d26276
+                           "initialize-web-extensions",
1d26276
+                           G_CALLBACK(wxgtk_initialize_web_extensions),
1d26276
+                           m_dbusServer);
1d26276
+
1d26276
+    m_web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
1d26276
+    GTKCreateScrolledWindowWith(GTK_WIDGET(m_web_view));
1d26276
+    g_object_ref(m_widget);
1d26276
+
37c4987
+    g_signal_connect_after(m_web_view, "decide-policy",
37c4987
+                           G_CALLBACK(wxgtk_webview_webkit_decide_policy),
1d26276
+                           this);
1d26276
+
37c4987
+    g_signal_connect_after(m_web_view, "load-failed",
37c4987
+                           G_CALLBACK(wxgtk_webview_webkit_load_failed), this);
1d26276
+
37c4987
+    g_signal_connect_after(m_web_view, "notify::title",
1d26276
+                           G_CALLBACK(wxgtk_webview_webkit_title_changed), this);
1d26276
+
37c4987
+    g_signal_connect_after(m_web_view, "resource-load-started",
1d26276
+                           G_CALLBACK(wxgtk_webview_webkit_resource_req), this);
37c4987
+
37c4987
+    g_signal_connect_after(m_web_view, "context-menu",
1d26276
+                           G_CALLBACK(wxgtk_webview_webkit_context_menu), this);
37c4987
+
37c4987
+    g_signal_connect_after(m_web_view, "create",
1d26276
+                           G_CALLBACK(wxgtk_webview_webkit_create_webview), this);
1d26276
+
37c4987
+    WebKitFindController* findctrl = webkit_web_view_get_find_controller(m_web_view);
37c4987
+    g_signal_connect_after(findctrl, "counted-matches",
1d26276
+                           G_CALLBACK(wxgtk_webview_webkit_counted_matches),
1d26276
+                           &m_findCount);
1d26276
+
1d26276
+    m_parent->DoAddChild( this );
1d26276
+
1d26276
+    PostCreation(size);
1d26276
+
1d26276
+    /* Open a webpage */
1d26276
+    webkit_web_view_load_uri(m_web_view, url.utf8_str());
1d26276
+
1d26276
+    // last to avoid getting signal too early
37c4987
+    g_signal_connect_after(m_web_view, "load-changed",
37c4987
+                           G_CALLBACK(wxgtk_webview_webkit_load_changed),
1d26276
+                           this);
1d26276
+
1d26276
+    return true;
1d26276
+}
1d26276
+
1d26276
+wxWebViewWebKit::~wxWebViewWebKit()
1d26276
+{
1d26276
+    if (m_web_view)
1d26276
+        GTKDisconnect(m_web_view);
1d26276
+    if (m_dbusServer)
1d26276
+        g_dbus_server_stop(m_dbusServer);
1d26276
+    g_clear_object(&m_dbusServer);
1d26276
+    g_clear_object(&m_extension);
1d26276
+}
1d26276
+
1d26276
+bool wxWebViewWebKit::Enable( bool enable )
1d26276
+{
1d26276
+    if (!wxControl::Enable(enable))
1d26276
+        return false;
1d26276
+
1d26276
+    gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(m_widget)), enable);
1d26276
+
1d26276
+    return true;
1d26276
+}
1d26276
+
1d26276
+GdkWindow*
1d26276
+wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
1d26276
+{
1d26276
+    GdkWindow* window = gtk_widget_get_parent_window(m_widget);
1d26276
+    return window;
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::ZoomIn()
1d26276
+{
37c4987
+    SetWebkitZoom(GetWebkitZoom() + 0.1);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::ZoomOut()
1d26276
+{
37c4987
+    SetWebkitZoom(GetWebkitZoom() - 0.1);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::SetWebkitZoom(float level)
1d26276
+{
1d26276
+    webkit_web_view_set_zoom_level(m_web_view, level);
1d26276
+}
1d26276
+
1d26276
+float wxWebViewWebKit::GetWebkitZoom() const
1d26276
+{
1d26276
+    return webkit_web_view_get_zoom_level(m_web_view);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::Stop()
1d26276
+{
1d26276
+     webkit_web_view_stop_loading(m_web_view);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags)
1d26276
+{
1d26276
+    if (flags & wxWEBVIEW_RELOAD_NO_CACHE)
1d26276
+    {
1d26276
+        webkit_web_view_reload_bypass_cache(m_web_view);
1d26276
+    }
1d26276
+    else
1d26276
+    {
1d26276
+        webkit_web_view_reload(m_web_view);
1d26276
+    }
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::LoadURL(const wxString& url)
1d26276
+{
1d26276
+    webkit_web_view_load_uri(m_web_view, wxGTK_CONV(url));
1d26276
+}
1d26276
+
1d26276
+
1d26276
+void wxWebViewWebKit::GoBack()
1d26276
+{
1d26276
+    webkit_web_view_go_back(m_web_view);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::GoForward()
1d26276
+{
1d26276
+    webkit_web_view_go_forward(m_web_view);
1d26276
+}
1d26276
+
1d26276
+
1d26276
+bool wxWebViewWebKit::CanGoBack() const
1d26276
+{
1d26276
+    return webkit_web_view_can_go_back(m_web_view);
1d26276
+}
1d26276
+
1d26276
+
1d26276
+bool wxWebViewWebKit::CanGoForward() const
1d26276
+{
1d26276
+    return webkit_web_view_can_go_forward(m_web_view);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::ClearHistory()
1d26276
+{
37c4987
+    // In WebKit2GTK+, the BackForwardList can't be cleared so do nothing.
1d26276
+}
1d26276
+
37c4987
+void wxWebViewWebKit::EnableHistory(bool)
1d26276
+{
37c4987
+    // In WebKit2GTK+, history can't be disabled so do nothing here.
1d26276
+}
1d26276
+
1d26276
+wxVector<wxSharedPtr<wxWebViewHistoryItem> > wxWebViewWebKit::GetBackwardHistory()
1d26276
+{
1d26276
+    wxVector<wxSharedPtr<wxWebViewHistoryItem> > backhist;
1d26276
+    WebKitBackForwardList* history =
1d26276
+        webkit_web_view_get_back_forward_list(m_web_view);
37c4987
+    GList* list = webkit_back_forward_list_get_back_list_with_limit(history,
37c4987
+                                                                    m_historyLimit);
1d26276
+    //We need to iterate in reverse to get the order we desire
1d26276
+    for(int i = g_list_length(list) - 1; i >= 0 ; i--)
1d26276
+    {
37c4987
+        WebKitBackForwardListItem* gtkitem = (WebKitBackForwardListItem*)g_list_nth_data(list, i);
1d26276
+        wxWebViewHistoryItem* wxitem = new wxWebViewHistoryItem(
37c4987
+                              webkit_back_forward_list_item_get_uri(gtkitem),
37c4987
+                              webkit_back_forward_list_item_get_title(gtkitem));
1d26276
+        wxitem->m_histItem = gtkitem;
1d26276
+        wxSharedPtr<wxWebViewHistoryItem> item(wxitem);
1d26276
+        backhist.push_back(item);
1d26276
+    }
1d26276
+    return backhist;
1d26276
+}
1d26276
+
1d26276
+wxVector<wxSharedPtr<wxWebViewHistoryItem> > wxWebViewWebKit::GetForwardHistory()
1d26276
+{
1d26276
+    wxVector<wxSharedPtr<wxWebViewHistoryItem> > forwardhist;
1d26276
+    WebKitBackForwardList* history =
1d26276
+        webkit_web_view_get_back_forward_list(m_web_view);
37c4987
+    GList* list = webkit_back_forward_list_get_forward_list_with_limit(history,
37c4987
+                                                                       m_historyLimit);
1d26276
+    for(guint i = 0; i < g_list_length(list); i++)
1d26276
+    {
37c4987
+        WebKitBackForwardListItem* gtkitem = (WebKitBackForwardListItem*)g_list_nth_data(list, i);
1d26276
+        wxWebViewHistoryItem* wxitem = new wxWebViewHistoryItem(
37c4987
+                              webkit_back_forward_list_item_get_uri(gtkitem),
37c4987
+                              webkit_back_forward_list_item_get_title(gtkitem));
1d26276
+        wxitem->m_histItem = gtkitem;
1d26276
+        wxSharedPtr<wxWebViewHistoryItem> item(wxitem);
1d26276
+        forwardhist.push_back(item);
1d26276
+    }
1d26276
+    return forwardhist;
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item)
1d26276
+{
37c4987
+    WebKitBackForwardListItem* gtkitem = (WebKitBackForwardListItem*)item->m_histItem;
1d26276
+    if(gtkitem)
1d26276
+    {
37c4987
+        webkit_web_view_go_to_back_forward_list_item(m_web_view,
37c4987
+                                                     WEBKIT_BACK_FORWARD_LIST_ITEM(gtkitem));
1d26276
+    }
1d26276
+}
1d26276
+
1d26276
+static void wxgtk_can_execute_editing_command_cb(WebKitWebView *,
1d26276
+                                                 GAsyncResult *res,
1d26276
+                                                 GAsyncResult **res_out)
1d26276
+{
1d26276
+    *res_out = (GAsyncResult*)g_object_ref(res);
1d26276
+}
1d26276
+
1d26276
+bool wxWebViewWebKit::CanExecuteEditingCommand(const gchar* command) const
1d26276
+{
1d26276
+    GAsyncResult *result = NULL;
1d26276
+    webkit_web_view_can_execute_editing_command(m_web_view,
1d26276
+                                                command,
1d26276
+                                                NULL,
1d26276
+                                                (GAsyncReadyCallback)wxgtk_can_execute_editing_command_cb,
1d26276
+                                                &result);
1d26276
+
1d26276
+    GMainContext *main_context = g_main_context_get_thread_default();
1d26276
+    while (!result)
1d26276
+    {
1d26276
+        g_main_context_iteration(main_context, TRUE);
1d26276
+    }
1d26276
+
1d26276
+    gboolean can_execute = webkit_web_view_can_execute_editing_command_finish(m_web_view,
1d26276
+                                                                              result,
1d26276
+                                                                              NULL);
1d26276
+    g_object_unref(result);
1d26276
+
1d26276
+    return can_execute;
1d26276
+}
1d26276
+
1d26276
+bool wxWebViewWebKit::CanCut() const
1d26276
+{
1d26276
+    return CanExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT);
1d26276
+}
1d26276
+
1d26276
+bool wxWebViewWebKit::CanCopy() const
1d26276
+{
1d26276
+    return CanExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY);
1d26276
+}
1d26276
+
1d26276
+bool wxWebViewWebKit::CanPaste() const
1d26276
+{
1d26276
+    return CanExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::Cut()
1d26276
+{
37c4987
+    webkit_web_view_execute_editing_command(m_web_view,
37c4987
+                                            WEBKIT_EDITING_COMMAND_CUT);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::Copy()
1d26276
+{
37c4987
+    webkit_web_view_execute_editing_command(m_web_view,
37c4987
+                                            WEBKIT_EDITING_COMMAND_COPY);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::Paste()
1d26276
+{
37c4987
+    webkit_web_view_execute_editing_command(m_web_view,
37c4987
+                                            WEBKIT_EDITING_COMMAND_PASTE);
1d26276
+}
1d26276
+
1d26276
+bool wxWebViewWebKit::CanUndo() const
1d26276
+{
1d26276
+    return CanExecuteEditingCommand(WEBKIT_EDITING_COMMAND_UNDO);
1d26276
+}
1d26276
+
1d26276
+bool wxWebViewWebKit::CanRedo() const
1d26276
+{
1d26276
+    return CanExecuteEditingCommand(WEBKIT_EDITING_COMMAND_REDO);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::Undo()
1d26276
+{
37c4987
+    webkit_web_view_execute_editing_command(m_web_view,
37c4987
+                                            WEBKIT_EDITING_COMMAND_UNDO);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::Redo()
1d26276
+{
37c4987
+    webkit_web_view_execute_editing_command(m_web_view,
37c4987
+                                            WEBKIT_EDITING_COMMAND_REDO);
1d26276
+}
1d26276
+
1d26276
+wxString wxWebViewWebKit::GetCurrentURL() const
1d26276
+{
1d26276
+    // FIXME: check which encoding the web kit control uses instead of
1d26276
+    // assuming UTF8 (here and elsewhere too)
1d26276
+    return wxString::FromUTF8(webkit_web_view_get_uri(m_web_view));
1d26276
+}
1d26276
+
1d26276
+
1d26276
+wxString wxWebViewWebKit::GetCurrentTitle() const
1d26276
+{
1d26276
+    return wxString::FromUTF8(webkit_web_view_get_title(m_web_view));
1d26276
+}
1d26276
+
1d26276
+
1d26276
+static void wxgtk_web_resource_get_data_cb(WebKitWebResource *,
1d26276
+                                           GAsyncResult *res,
1d26276
+                                           GAsyncResult **res_out)
1d26276
+{
1d26276
+    *res_out = (GAsyncResult*)g_object_ref(res);
1d26276
+}
1d26276
+
1d26276
+wxString wxWebViewWebKit::GetPageSource() const
1d26276
+{
1d26276
+    WebKitWebResource *resource = webkit_web_view_get_main_resource(m_web_view);
1d26276
+    if (!resource)
1d26276
+    {
1d26276
+        return wxString();
1d26276
+    }
1d26276
+
1d26276
+    GAsyncResult *result = NULL;
1d26276
+    webkit_web_resource_get_data(resource, NULL,
1d26276
+                                 (GAsyncReadyCallback)wxgtk_web_resource_get_data_cb,
1d26276
+                                 &result);
1d26276
+
1d26276
+    GMainContext *main_context = g_main_context_get_thread_default();
1d26276
+    while (!result)
1d26276
+    {
1d26276
+        g_main_context_iteration(main_context, TRUE);
1d26276
+    }
1d26276
+
1d26276
+    guchar *source = webkit_web_resource_get_data_finish(resource, result,
1d26276
+                                                         NULL, NULL);
1d26276
+    if (result)
1d26276
+    {
1d26276
+        g_object_unref(result);
1d26276
+    }
1d26276
+
1d26276
+    if (source)
1d26276
+    {
1d26276
+        wxString wxs = wxString(source, wxConvUTF8);
1d26276
+        free(source);
1d26276
+        return wxs;
1d26276
+    }
1d26276
+    return wxString();
1d26276
+}
1d26276
+
1d26276
+
1d26276
+wxWebViewZoom wxWebViewWebKit::GetZoom() const
1d26276
+{
1d26276
+    float zoom = GetWebkitZoom();
1d26276
+
1d26276
+    // arbitrary way to map float zoom to our common zoom enum
1d26276
+    if (zoom <= 0.65)
1d26276
+    {
1d26276
+        return wxWEBVIEW_ZOOM_TINY;
1d26276
+    }
1d26276
+    else if (zoom > 0.65 && zoom <= 0.90)
1d26276
+    {
1d26276
+        return wxWEBVIEW_ZOOM_SMALL;
1d26276
+    }
1d26276
+    else if (zoom > 0.90 && zoom <= 1.15)
1d26276
+    {
1d26276
+        return wxWEBVIEW_ZOOM_MEDIUM;
1d26276
+    }
1d26276
+    else if (zoom > 1.15 && zoom <= 1.45)
1d26276
+    {
1d26276
+        return wxWEBVIEW_ZOOM_LARGE;
1d26276
+    }
1d26276
+    else if (zoom > 1.45)
1d26276
+    {
1d26276
+        return wxWEBVIEW_ZOOM_LARGEST;
1d26276
+    }
1d26276
+
1d26276
+    // to shut up compilers, this can never be reached logically
1d26276
+    wxFAIL;
1d26276
+    return wxWEBVIEW_ZOOM_MEDIUM;
1d26276
+}
1d26276
+
1d26276
+
1d26276
+void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom)
1d26276
+{
1d26276
+    // arbitrary way to map our common zoom enum to float zoom
1d26276
+    switch (zoom)
1d26276
+    {
1d26276
+        case wxWEBVIEW_ZOOM_TINY:
1d26276
+            SetWebkitZoom(0.6f);
1d26276
+            break;
1d26276
+
1d26276
+        case wxWEBVIEW_ZOOM_SMALL:
1d26276
+            SetWebkitZoom(0.8f);
1d26276
+            break;
1d26276
+
1d26276
+        case wxWEBVIEW_ZOOM_MEDIUM:
1d26276
+            SetWebkitZoom(1.0f);
1d26276
+            break;
1d26276
+
1d26276
+        case wxWEBVIEW_ZOOM_LARGE:
1d26276
+            SetWebkitZoom(1.3);
1d26276
+            break;
1d26276
+
1d26276
+        case wxWEBVIEW_ZOOM_LARGEST:
1d26276
+            SetWebkitZoom(1.6);
1d26276
+            break;
1d26276
+
1d26276
+        default:
1d26276
+            wxFAIL;
1d26276
+    }
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type)
1d26276
+{
37c4987
+    WebKitSettings* settings = webkit_web_view_get_settings(m_web_view);
37c4987
+    webkit_settings_set_zoom_text_only(settings,
37c4987
+                                       (type == wxWEBVIEW_ZOOM_TYPE_TEXT ?
37c4987
+                                       TRUE : FALSE));
1d26276
+}
1d26276
+
1d26276
+wxWebViewZoomType wxWebViewWebKit::GetZoomType() const
1d26276
+{
37c4987
+    WebKitSettings* settings = webkit_web_view_get_settings(m_web_view);
37c4987
+    gboolean tozoom = webkit_settings_get_zoom_text_only(settings);
1d26276
+
1d26276
+    if (tozoom)
1d26276
+        return wxWEBVIEW_ZOOM_TYPE_TEXT;
1d26276
+    else
1d26276
+        return wxWEBVIEW_ZOOM_TYPE_LAYOUT;
1d26276
+}
1d26276
+
1d26276
+bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType) const
1d26276
+{
1d26276
+    // this port supports all zoom types
1d26276
+    return true;
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::DoSetPage(const wxString& html, const wxString& baseUri)
1d26276
+{
37c4987
+    webkit_web_view_load_html(m_web_view,
37c4987
+                              html.mb_str(wxConvUTF8),
37c4987
+                              baseUri.mb_str(wxConvUTF8));
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::Print()
1d26276
+{
37c4987
+    WebKitPrintOperation* printop = webkit_print_operation_new(m_web_view);
37c4987
+    webkit_print_operation_run_dialog(printop, NULL);
37c4987
+    g_object_unref(printop);
1d26276
+}
1d26276
+
1d26276
+
1d26276
+bool wxWebViewWebKit::IsBusy() const
1d26276
+{
1d26276
+    return m_busy;
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::SetEditable(bool enable)
1d26276
+{
1d26276
+    webkit_web_view_set_editable(m_web_view, enable);
1d26276
+}
1d26276
+
1d26276
+bool wxWebViewWebKit::IsEditable() const
1d26276
+{
37c4987
+    gboolean editable;
37c4987
+    g_object_get(m_web_view, "editable", &editable, NULL);
37c4987
+    return editable;
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::DeleteSelection()
1d26276
+{
1d26276
+    if (m_extension)
1d26276
+    {
1d26276
+        guint64 page_id = webkit_web_view_get_page_id(m_web_view);
1d26276
+        GVariant *retval = g_dbus_proxy_call_sync(m_extension,
1d26276
+                                                  "DeleteSelection",
1d26276
+                                                  g_variant_new("(t)", page_id),
1d26276
+                                                  G_DBUS_CALL_FLAGS_NONE, -1,
1d26276
+                                                  NULL, NULL);
1d26276
+        if (retval)
1d26276
+        {
1d26276
+            g_variant_unref(retval);
1d26276
+        }
1d26276
+    }
1d26276
+}
1d26276
+
1d26276
+bool wxWebViewWebKit::HasSelection() const
1d26276
+{
1d26276
+    if (m_extension)
1d26276
+    {
1d26276
+        guint64 page_id = webkit_web_view_get_page_id(m_web_view);
1d26276
+        GVariant *retval = g_dbus_proxy_call_sync(m_extension,
1d26276
+                                                  "HasSelection",
1d26276
+                                                  g_variant_new("(t)", page_id),
1d26276
+                                                  G_DBUS_CALL_FLAGS_NONE, -1,
1d26276
+                                                  NULL, NULL);
1d26276
+        if (retval)
1d26276
+	{
1d26276
+            gboolean has_selection = FALSE;
1d26276
+            g_variant_get(retval, "(b)", &has_selection);
1d26276
+            g_variant_unref(retval);
1d26276
+            return has_selection;
1d26276
+        }
1d26276
+    }
37c4987
+    return false;
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::SelectAll()
1d26276
+{
37c4987
+    webkit_web_view_execute_editing_command(m_web_view,
37c4987
+                                            WEBKIT_EDITING_COMMAND_SELECT_ALL);
1d26276
+}
1d26276
+
1d26276
+wxString wxWebViewWebKit::GetSelectedText() const
1d26276
+{
1d26276
+    if (m_extension)
1d26276
+    {
1d26276
+        guint64 page_id = webkit_web_view_get_page_id(m_web_view);
1d26276
+        GVariant *retval = g_dbus_proxy_call_sync(m_extension,
1d26276
+                                                  "GetSelectedText",
1d26276
+                                                  g_variant_new("(t)", page_id),
1d26276
+                                                  G_DBUS_CALL_FLAGS_NONE, -1,
1d26276
+                                                  NULL, NULL);
1d26276
+        if (retval)
1d26276
+	{
1d26276
+            char *text;
1d26276
+            g_variant_get(retval, "(s)", &text);
1d26276
+            g_variant_unref(retval);
1d26276
+            return wxString(text, wxConvUTF8);
1d26276
+        }
1d26276
+    }
1d26276
+    return wxString();
1d26276
+}
1d26276
+
1d26276
+wxString wxWebViewWebKit::GetSelectedSource() const
1d26276
+{
1d26276
+    if (m_extension)
1d26276
+    {
1d26276
+        guint64 page_id = webkit_web_view_get_page_id(m_web_view);
1d26276
+        GVariant *retval = g_dbus_proxy_call_sync(m_extension,
1d26276
+                                                  "GetSelectedSource",
1d26276
+                                                  g_variant_new("(t)", page_id),
1d26276
+                                                  G_DBUS_CALL_FLAGS_NONE, -1,
1d26276
+                                                  NULL, NULL);
1d26276
+        if (retval)
1d26276
+	{
1d26276
+            char *source;
1d26276
+            g_variant_get(retval, "(s)", &source);
1d26276
+            g_variant_unref(retval);
1d26276
+            return wxString(source, wxConvUTF8);
1d26276
+        }
1d26276
+    }
1d26276
+    return wxString();
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::ClearSelection()
1d26276
+{
1d26276
+    if (m_extension)
1d26276
+    {
1d26276
+        guint64 page_id = webkit_web_view_get_page_id(m_web_view);
1d26276
+        GVariant *retval = g_dbus_proxy_call_sync(m_extension,
1d26276
+                                                  "ClearSelection",
1d26276
+                                                  g_variant_new("(t)", page_id),
1d26276
+                                                  G_DBUS_CALL_FLAGS_NONE, -1,
1d26276
+                                                  NULL, NULL);
1d26276
+        if (retval)
1d26276
+        {
1d26276
+            g_variant_unref(retval);
1d26276
+        }
1d26276
+    }
1d26276
+}
1d26276
+
1d26276
+wxString wxWebViewWebKit::GetPageText() const
1d26276
+{
1d26276
+    if (m_extension)
1d26276
+    {
1d26276
+        guint64 page_id = webkit_web_view_get_page_id(m_web_view);
1d26276
+        GVariant *retval = g_dbus_proxy_call_sync(m_extension,
1d26276
+                                                  "GetPageText",
1d26276
+                                                  g_variant_new("(t)", page_id),
1d26276
+                                                  G_DBUS_CALL_FLAGS_NONE, -1,
1d26276
+                                                  NULL, NULL);
1d26276
+        if (retval)
1d26276
+	{
1d26276
+            char *text;
1d26276
+            g_variant_get(retval, "(s)", &text);
1d26276
+            g_variant_unref(retval);
1d26276
+            return wxString(text, wxConvUTF8);
1d26276
+        }
1d26276
+    }
1d26276
+    return wxString();
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::RunScript(const wxString& javascript)
1d26276
+{
37c4987
+    webkit_web_view_run_javascript(m_web_view,
37c4987
+                                   javascript.mb_str(wxConvUTF8),
37c4987
+                                   NULL,
37c4987
+                                   NULL,
37c4987
+                                   NULL);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
1d26276
+{
1d26276
+    m_handlerList.push_back(handler);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::EnableContextMenu(bool enable)
1d26276
+{
1d26276
+    wxWebView::EnableContextMenu(enable);
1d26276
+}
1d26276
+
1d26276
+long wxWebViewWebKit::Find(const wxString& text, int flags)
1d26276
+{
37c4987
+    WebKitFindController* findctrl = webkit_web_view_get_find_controller(m_web_view);
1d26276
+    bool newSearch = false;
1d26276
+    if(text != m_findText || 
1d26276
+       (flags & wxWEBVIEW_FIND_MATCH_CASE) != (m_findFlags & wxWEBVIEW_FIND_MATCH_CASE))
1d26276
+    {
1d26276
+        newSearch = true;
1d26276
+        //If it is a new search we need to clear existing highlights
37c4987
+        webkit_find_controller_search_finish(findctrl);
1d26276
+    }
1d26276
+
1d26276
+    m_findFlags = flags;
1d26276
+    m_findText = text;
1d26276
+
1d26276
+    //If the search string is empty then we clear any selection and highlight
1d26276
+    if(text.empty())
37c4987
+    {
1d26276
+        webkit_find_controller_search_finish(findctrl);
1d26276
+        ClearSelection();
1d26276
+        return wxNOT_FOUND;
37c4987
+    }
1d26276
+
1d26276
+    bool wrap = false, forward = true;
1d26276
+    guint32 options = WEBKIT_FIND_OPTIONS_NONE;
1d26276
+    if(flags & wxWEBVIEW_FIND_WRAP)
37c4987
+    {
1d26276
+        wrap = true;
1d26276
+        options |= WEBKIT_FIND_OPTIONS_WRAP_AROUND;
37c4987
+    }
1d26276
+    if(!(flags & wxWEBVIEW_FIND_MATCH_CASE))
37c4987
+    {
37c4987
+        options |= WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE;
37c4987
+    }
1d26276
+    if(flags & wxWEBVIEW_FIND_BACKWARDS)
37c4987
+    {
1d26276
+        forward = false;
37c4987
+        options |= WEBKIT_FIND_OPTIONS_BACKWARDS;
37c4987
+    }
1d26276
+
1d26276
+    if(newSearch)
1d26276
+    {
1d26276
+        //Initially we count the matches to know how many we have
1d26276
+        m_findCount = -1;
1d26276
+        webkit_find_controller_count_matches(findctrl,
1d26276
+                                             wxGTK_CONV(text),
1d26276
+                                             options,
1d26276
+                                             G_MAXUINT);
1d26276
+        GMainContext *main_context = g_main_context_get_thread_default();
1d26276
+        while (m_findCount == -1)
1d26276
+        {
1d26276
+            g_main_context_iteration(main_context, TRUE);
1d26276
+        }
1d26276
+        //Highlight them if needed
37c4987
+        if(flags & wxWEBVIEW_FIND_HIGHLIGHT_RESULT)
37c4987
+        {
37c4987
+            webkit_find_controller_search(findctrl,
37c4987
+                                          wxGTK_CONV(text),
37c4987
+                                          options,
37c4987
+                                          G_MAXUINT);
37c4987
+        }
1d26276
+        //In this case we return early to match IE behaviour
1d26276
+        m_findPosition = -1;
1d26276
+        return m_findCount;
1d26276
+    }
1d26276
+    else
1d26276
+    {
1d26276
+        if(forward)
1d26276
+            m_findPosition++;
37c4987
+        else
1d26276
+            m_findPosition--;
1d26276
+        if(m_findPosition < 0)
1d26276
+            m_findPosition += m_findCount;
1d26276
+        if(m_findPosition > m_findCount)
1d26276
+            m_findPosition -= m_findCount;
1d26276
+    }
1d26276
+
37c4987
+    if(forward)
1d26276
+    {
37c4987
+        webkit_find_controller_search_next(findctrl);
37c4987
+        if(m_findPosition == m_findCount && !wrap)
37c4987
+        {
37c4987
+            return wxNOT_FOUND;
37c4987
+        }
1d26276
+    }
37c4987
+    else
37c4987
+    {
37c4987
+        webkit_find_controller_search_previous(findctrl);
37c4987
+        if(m_findPosition == -1 && !wrap)
37c4987
+        {
37c4987
+            return wxNOT_FOUND;
37c4987
+        }
37c4987
+    }
37c4987
+
1d26276
+    return newSearch ? m_findCount : m_findPosition;
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::FindClear()
1d26276
+{
1d26276
+    m_findCount = 0;
1d26276
+    m_findFlags = 0;
1d26276
+    m_findText.clear();
1d26276
+    m_findPosition = -1;
1d26276
+}
1d26276
+
1d26276
+// static
1d26276
+wxVisualAttributes
1d26276
+wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
1d26276
+{
1d26276
+     return GetDefaultAttributesFromGTKWidget(webkit_web_view_new());
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKit::SetupWebExtensionServer()
1d26276
+{
1d26276
+    char *address = g_strdup_printf("unix:tmpdir=%s", g_get_tmp_dir());
1d26276
+    char *guid = g_dbus_generate_guid();
1d26276
+    GDBusAuthObserver *observer = g_dbus_auth_observer_new();
1d26276
+    GError *error = NULL;
1d26276
+
1d26276
+    g_signal_connect(observer, "authorize-authenticated-peer",
1d26276
+                     G_CALLBACK(wxgtk_authorize_authenticated_peer_cb), this);
1d26276
+
1d26276
+    m_dbusServer = g_dbus_server_new_sync(address,
1d26276
+                                          G_DBUS_SERVER_FLAGS_NONE,
1d26276
+                                          guid,
1d26276
+                                          observer,
1d26276
+                                          NULL,
1d26276
+                                          &error);
1d26276
+
1d26276
+    if (error)
1d26276
+    {
1d26276
+        g_warning("Failed to start web extension server on %s: %s", address, error->message);
1d26276
+        g_error_free(error);
1d26276
+    }
1d26276
+    else
1d26276
+    {
1d26276
+        g_signal_connect(m_dbusServer, "new-connection",
1d26276
+                         G_CALLBACK(wxgtk_new_connection_cb), &m_extension);
1d26276
+        g_dbus_server_start(m_dbusServer);
1d26276
+    }
1d26276
+
1d26276
+    g_free(address);
1d26276
+    g_free(guid);
1d26276
+    g_object_unref(observer);
1d26276
+}
37c4987
+
1d26276
+#endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT2
1d26276
diff --git a/src/gtk/webview_webkit2_extension.cpp b/src/gtk/webview_webkit2_extension.cpp
1d26276
new file mode 100644
1d26276
index 0000000..ddd0d94
1d26276
--- /dev/null
1d26276
+++ b/src/gtk/webview_webkit2_extension.cpp
1d26276
@@ -0,0 +1,421 @@
1d26276
+/////////////////////////////////////////////////////////////////////////////
1d26276
+// Name:        src/gtk/webview_webkit2_extension.cpp
1d26276
+// Purpose:     GTK WebKit2 extension for web view component
1d26276
+// Author:      Scott Talbert
1d26276
+// Copyright:   (c) 2017 Scott Talbert
1d26276
+// Licence:     wxWindows licence
1d26276
+/////////////////////////////////////////////////////////////////////////////
37c4987
+
1d26276
+#include "wx/defs.h"
1d26276
+#include "wx/gtk/webview_webkit2_extension.h"
1d26276
+#include <webkit2/webkit-web-extension.h>
1d26276
+#define WEBKIT_DOM_USE_UNSTABLE_API
1d26276
+#include <webkitdom/WebKitDOMDOMSelection.h>
1d26276
+#include <webkitdom/WebKitDOMDOMWindowUnstable.h>
37c4987
+
1d26276
+static const char introspection_xml[] =
1d26276
+  "<node>"
1d26276
+  " <interface name='org.wxwidgets.wxGTK.WebExtension'>"
1d26276
+  "  <method name='ClearSelection'>"
1d26276
+  "   <arg type='t' name='page_id' direction='in'/>"
1d26276
+  "  </method>"
1d26276
+  "  <method name='DeleteSelection'>"
1d26276
+  "   <arg type='t' name='page_id' direction='in'/>"
1d26276
+  "  </method>"
1d26276
+  "  <method name='GetPageSource'>"
1d26276
+  "   <arg type='t' name='page_id' direction='in'/>"
1d26276
+  "   <arg type='s' name='source' direction='out'/>"
1d26276
+  "  </method>"
1d26276
+  "  <method name='GetPageText'>"
1d26276
+  "   <arg type='t' name='page_id' direction='in'/>"
1d26276
+  "   <arg type='s' name='text' direction='out'/>"
1d26276
+  "  </method>"
1d26276
+  "  <method name='GetSelectedSource'>"
1d26276
+  "   <arg type='t' name='page_id' direction='in'/>"
1d26276
+  "   <arg type='s' name='source' direction='out'/>"
1d26276
+  "  </method>"
1d26276
+  "  <method name='GetSelectedText'>"
1d26276
+  "   <arg type='t' name='page_id' direction='in'/>"
1d26276
+  "   <arg type='s' name='text' direction='out'/>"
1d26276
+  "  </method>"
1d26276
+  "  <method name='HasSelection'>"
1d26276
+  "   <arg type='t' name='page_id' direction='in'/>"
1d26276
+  "   <arg type='b' name='has_selection' direction='out'/>"
1d26276
+  "  </method>"
1d26276
+  " </interface>"
1d26276
+  "</node>";
1d26276
+
1d26276
+class wxWebViewWebKitExtension;
1d26276
+
1d26276
+static gboolean
1d26276
+wxgtk_webview_authorize_authenticated_peer_cb(GDBusAuthObserver *observer,
1d26276
+                                              GIOStream *stream,
1d26276
+                                              GCredentials *credentials,
1d26276
+                                              wxWebViewWebKitExtension *extension);
1d26276
+static void
1d26276
+wxgtk_webview_dbus_connection_created_cb(GObject *source_object,
1d26276
+                                         GAsyncResult *result,
1d26276
+                                         wxWebViewWebKitExtension *extension);
1d26276
+
1d26276
+static wxWebViewWebKitExtension *gs_extension = NULL;
1d26276
+
1d26276
+class wxWebViewWebKitExtension
1d26276
+{
1d26276
+public:
1d26276
+    wxWebViewWebKitExtension(WebKitWebExtension *webkit_extension, const char* server_address);
1d26276
+    void ClearSelection(GVariant *parameters, GDBusMethodInvocation *invocation);
1d26276
+    void DeleteSelection(GVariant *parameters, GDBusMethodInvocation *invocation);
1d26276
+    void GetPageSource(GVariant *parameters, GDBusMethodInvocation *invocation);
1d26276
+    void GetPageText(GVariant *parameters, GDBusMethodInvocation *invocation);
1d26276
+    void GetSelectedSource(GVariant *parameters, GDBusMethodInvocation *invocation);
1d26276
+    void GetSelectedText(GVariant *parameters, GDBusMethodInvocation *invocation);
1d26276
+    void HasSelection(GVariant *parameters, GDBusMethodInvocation *invocation);
1d26276
+    void SetDBusConnection(GDBusConnection *dbusConnection);
1d26276
+
1d26276
+private:
1d26276
+    WebKitWebPage* GetWebPageOrReturnError(GVariant *parameters, GDBusMethodInvocation *invocation);
1d26276
+    void ReturnDBusStringValue(GDBusMethodInvocation *invocation, gchar *value);
1d26276
+
1d26276
+    GDBusConnection *m_dbusConnection;
1d26276
+    WebKitWebExtension *m_webkitExtension;
1d26276
+};
1d26276
+
1d26276
+wxWebViewWebKitExtension::wxWebViewWebKitExtension(WebKitWebExtension *extension, const char* server_address)
1d26276
+{
1d26276
+    m_webkitExtension = (WebKitWebExtension*)g_object_ref(extension);
1d26276
+
1d26276
+    GDBusAuthObserver *observer = g_dbus_auth_observer_new();
1d26276
+    g_signal_connect(observer, "authorize-authenticated-peer",
1d26276
+                     G_CALLBACK(wxgtk_webview_authorize_authenticated_peer_cb),
1d26276
+                     this);
1d26276
+
1d26276
+    g_dbus_connection_new_for_address(server_address,
1d26276
+                                      G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
1d26276
+                                      observer,
1d26276
+                                      NULL,
1d26276
+                                      (GAsyncReadyCallback)wxgtk_webview_dbus_connection_created_cb,
1d26276
+                                      this);
1d26276
+    g_object_unref(observer);
1d26276
+}
1d26276
+
1d26276
+WebKitWebPage* wxWebViewWebKitExtension::GetWebPageOrReturnError(GVariant *parameters, GDBusMethodInvocation *invocation)
1d26276
+{
1d26276
+    guint64 page_id;
1d26276
+    g_variant_get(parameters, "(t)", &page_id);
1d26276
+    WebKitWebPage *web_page = webkit_web_extension_get_page(m_webkitExtension,
1d26276
+                                                            page_id);
1d26276
+    if (!web_page)
1d26276
+    {
1d26276
+        g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
1d26276
+                                              G_DBUS_ERROR_INVALID_ARGS,
1d26276
+                                              "Invalid page ID: %" G_GUINT64_FORMAT, page_id);
1d26276
+    }
1d26276
+    return web_page;
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKitExtension::GetSelectedSource(GVariant *parameters,
1d26276
+                                                 GDBusMethodInvocation *invocation)
1d26276
+{
1d26276
+    WebKitWebPage *web_page = GetWebPageOrReturnError(parameters, invocation);
1d26276
+    if (!web_page)
1d26276
+    {
1d26276
+        return;
1d26276
+    }
1d26276
+
1d26276
+    WebKitDOMDocument *doc = webkit_web_page_get_dom_document(web_page);
1d26276
+    WebKitDOMDOMWindow *win = webkit_dom_document_get_default_view(doc);
1d26276
+    WebKitDOMDOMSelection *sel = webkit_dom_dom_window_get_selection(win);
1d26276
+    g_object_unref(win);
1d26276
+    if (!sel)
1d26276
+    {
1d26276
+        ReturnDBusStringValue(invocation, NULL);
1d26276
+        return;
1d26276
+    }
1d26276
+    WebKitDOMRange *range = webkit_dom_dom_selection_get_range_at(sel, 0, NULL);
1d26276
+    if (!range)
1d26276
+    {
1d26276
+        ReturnDBusStringValue(invocation, NULL);
1d26276
+        return;
1d26276
+    }
1d26276
+    WebKitDOMElement *div = webkit_dom_document_create_element(doc, "div",
1d26276
+                                                               NULL);
1d26276
+    WebKitDOMDocumentFragment *clone = webkit_dom_range_clone_contents(range,
1d26276
+                                                                       NULL);
1d26276
+    webkit_dom_node_append_child(&div->parent_instance,
1d26276
+                                 &clone->parent_instance, NULL);
1d26276
+    WebKitDOMElement *html = (WebKitDOMElement*)div;
1d26276
+    gchar *text = webkit_dom_element_get_inner_html(html);
1d26276
+    g_object_unref(range);
1d26276
+
1d26276
+    ReturnDBusStringValue(invocation, text);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKitExtension::GetPageSource(GVariant *parameters,
1d26276
+                                             GDBusMethodInvocation *invocation)
1d26276
+{
1d26276
+    WebKitWebPage *web_page = GetWebPageOrReturnError(parameters, invocation);
1d26276
+    if (!web_page)
1d26276
+    {
1d26276
+        return;
1d26276
+    }
1d26276
+
1d26276
+    WebKitDOMDocument *doc = webkit_web_page_get_dom_document(web_page);
1d26276
+    WebKitDOMElement *body = webkit_dom_document_get_document_element(doc);
1d26276
+    gchar *source = webkit_dom_element_get_outer_html(body);
1d26276
+    g_dbus_method_invocation_return_value(invocation,
1d26276
+                                          g_variant_new("(s)", source ? source : ""));
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKitExtension::GetPageText(GVariant *parameters,
1d26276
+                                           GDBusMethodInvocation *invocation)
1d26276
+{
1d26276
+    WebKitWebPage *web_page = GetWebPageOrReturnError(parameters, invocation);
1d26276
+    if (!web_page)
1d26276
+    {
1d26276
+        return;
1d26276
+    }
1d26276
+
1d26276
+    WebKitDOMDocument *doc = webkit_web_page_get_dom_document(web_page);
1d26276
+    WebKitDOMHTMLElement *body = webkit_dom_document_get_body(doc);
1d26276
+    gchar *text = webkit_dom_html_element_get_inner_text(body);
1d26276
+    g_dbus_method_invocation_return_value(invocation,
1d26276
+                                          g_variant_new("(s)", text));
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKitExtension::GetSelectedText(GVariant *parameters,
1d26276
+                                               GDBusMethodInvocation *invocation)
1d26276
+{
1d26276
+    WebKitWebPage *web_page = GetWebPageOrReturnError(parameters, invocation);
1d26276
+    if (!web_page)
1d26276
+    {
1d26276
+        return;
1d26276
+    }
1d26276
+
1d26276
+    WebKitDOMDocument *doc = webkit_web_page_get_dom_document(web_page);
1d26276
+    WebKitDOMDOMWindow *win = webkit_dom_document_get_default_view(doc);
1d26276
+    WebKitDOMDOMSelection *sel = webkit_dom_dom_window_get_selection(win);
1d26276
+    g_object_unref(win);
1d26276
+    if (!sel)
1d26276
+    {
1d26276
+        ReturnDBusStringValue(invocation, NULL);
1d26276
+        return;
1d26276
+    }
1d26276
+    WebKitDOMRange *range = webkit_dom_dom_selection_get_range_at(sel, 0, NULL);
1d26276
+    if (!range)
1d26276
+    {
1d26276
+        ReturnDBusStringValue(invocation, NULL);
1d26276
+        return;
1d26276
+    }
1d26276
+    gchar *text = webkit_dom_range_get_text(range);
1d26276
+    g_object_unref(range);
1d26276
+
1d26276
+    ReturnDBusStringValue(invocation, text);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKitExtension::ClearSelection(GVariant *parameters,
1d26276
+                                              GDBusMethodInvocation *invocation)
1d26276
+{
1d26276
+    WebKitWebPage *web_page = GetWebPageOrReturnError(parameters, invocation);
1d26276
+    if (!web_page)
1d26276
+    {
1d26276
+        return;
1d26276
+    }
1d26276
+
1d26276
+    WebKitDOMDocument *doc = webkit_web_page_get_dom_document(web_page);
1d26276
+    WebKitDOMDOMWindow *win = webkit_dom_document_get_default_view(doc);
1d26276
+    WebKitDOMDOMSelection *sel = webkit_dom_dom_window_get_selection(win);
1d26276
+    g_object_unref(win);
1d26276
+    if (sel)
1d26276
+    {
1d26276
+        webkit_dom_dom_selection_remove_all_ranges(sel);
1d26276
+    }
1d26276
+
1d26276
+    g_dbus_method_invocation_return_value(invocation, NULL);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKitExtension::HasSelection(GVariant *parameters,
1d26276
+                                            GDBusMethodInvocation *invocation)
1d26276
+{
1d26276
+    WebKitWebPage *web_page = GetWebPageOrReturnError(parameters, invocation);
1d26276
+    if (!web_page)
1d26276
+    {
1d26276
+        return;
1d26276
+    }
1d26276
+
1d26276
+    WebKitDOMDocument *doc = webkit_web_page_get_dom_document(web_page);
1d26276
+    WebKitDOMDOMWindow *win = webkit_dom_document_get_default_view(doc);
1d26276
+    WebKitDOMDOMSelection *sel = webkit_dom_dom_window_get_selection(win);
1d26276
+    g_object_unref(win);
1d26276
+    gboolean has_selection = FALSE;
1d26276
+    if (WEBKIT_DOM_IS_DOM_SELECTION(sel))
1d26276
+    {
1d26276
+        if (!webkit_dom_dom_selection_get_is_collapsed(sel))
1d26276
+        {
1d26276
+            has_selection = TRUE;
1d26276
+        }
1d26276
+    }
1d26276
+    g_dbus_method_invocation_return_value(invocation,
1d26276
+                                          g_variant_new("(b)", has_selection));
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKitExtension::DeleteSelection(GVariant *parameters,
1d26276
+                                               GDBusMethodInvocation *invocation)
1d26276
+{
1d26276
+    WebKitWebPage *web_page = GetWebPageOrReturnError(parameters, invocation);
1d26276
+    if (!web_page)
1d26276
+    {
1d26276
+        return;
1d26276
+    }
1d26276
+
1d26276
+    WebKitDOMDocument *doc = webkit_web_page_get_dom_document(web_page);
1d26276
+    WebKitDOMDOMWindow *win = webkit_dom_document_get_default_view(doc);
1d26276
+    WebKitDOMDOMSelection *sel = webkit_dom_dom_window_get_selection(win);
1d26276
+    g_object_unref(win);
1d26276
+    if (sel)
1d26276
+    {
1d26276
+        webkit_dom_dom_selection_delete_from_document(sel);
1d26276
+    }
1d26276
+
1d26276
+    g_dbus_method_invocation_return_value(invocation, NULL);
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKitExtension::ReturnDBusStringValue(GDBusMethodInvocation *invocation, gchar *value)
1d26276
+{
1d26276
+    g_dbus_method_invocation_return_value(invocation,
1d26276
+                                          g_variant_new("(s)", value ? value : ""));
1d26276
+}
1d26276
+
1d26276
+void wxWebViewWebKitExtension::SetDBusConnection(GDBusConnection *dbusConnection)
1d26276
+{
1d26276
+    m_dbusConnection = dbusConnection;
1d26276
+}
1d26276
+
1d26276
+static void
1d26276
+wxgtk_webview_handle_method_call(GDBusConnection *connection,
1d26276
+                                 const char *sender,
1d26276
+                                 const char *object_path,
1d26276
+                                 const char *interface_name,
1d26276
+                                 const char *method_name,
1d26276
+                                 GVariant *parameters,
1d26276
+                                 GDBusMethodInvocation *invocation,
1d26276
+                                 gpointer user_data)
1d26276
+{
1d26276
+    if (g_strcmp0(interface_name, WXGTK_WEB_EXTENSION_INTERFACE) != 0)
1d26276
+    {
1d26276
+        return;
1d26276
+    }
1d26276
+
1d26276
+    wxWebViewWebKitExtension *extension = (wxWebViewWebKitExtension*)user_data;
1d26276
+
1d26276
+    if (g_strcmp0(method_name, "ClearSelection") == 0)
1d26276
+    {
1d26276
+        extension->ClearSelection(parameters, invocation);
1d26276
+    }
1d26276
+    else if (g_strcmp0(method_name, "DeleteSelection") == 0)
1d26276
+    {
1d26276
+        extension->DeleteSelection(parameters, invocation);
1d26276
+    }
1d26276
+    else if (g_strcmp0(method_name, "GetPageSource") == 0)
1d26276
+    {
1d26276
+        extension->GetPageSource(parameters, invocation);
1d26276
+    }
1d26276
+    else if (g_strcmp0(method_name, "GetPageText") == 0)
1d26276
+    {
1d26276
+        extension->GetPageText(parameters, invocation);
1d26276
+    }
1d26276
+    else if (g_strcmp0(method_name, "GetSelectedSource") == 0)
1d26276
+    {
1d26276
+        extension->GetSelectedSource(parameters, invocation);
1d26276
+    }
1d26276
+    else if (g_strcmp0(method_name, "GetSelectedText") == 0)
1d26276
+    {
1d26276
+        extension->GetSelectedText(parameters, invocation);
1d26276
+    }
1d26276
+    else if (g_strcmp0(method_name, "HasSelection") == 0)
1d26276
+    {
1d26276
+        extension->HasSelection(parameters, invocation);
1d26276
+    }
1d26276
+}
1d26276
+
1d26276
+static const GDBusInterfaceVTable interface_vtable = {
1d26276
+    wxgtk_webview_handle_method_call,
1d26276
+    NULL,
1d26276
+    NULL
1d26276
+};
1d26276
+
1d26276
+gboolean
1d26276
+wxgtk_webview_dbus_peer_is_authorized(GCredentials *peer_credentials)
1d26276
+{
1d26276
+    static GCredentials *own_credentials = g_credentials_new();
1d26276
+    GError *error = NULL;
1d26276
+
1d26276
+    if (peer_credentials && g_credentials_is_same_user(peer_credentials, own_credentials, &error))
1d26276
+    {
1d26276
+        return TRUE;
1d26276
+    }
1d26276
+
1d26276
+    if (error)
1d26276
+    {
1d26276
+        g_warning("Failed to authorize web extension connection: %s", error->message);
1d26276
+        g_error_free(error);
1d26276
+    }
1d26276
+    return FALSE;
1d26276
+}
1d26276
+
1d26276
+static gboolean
1d26276
+wxgtk_webview_authorize_authenticated_peer_cb(GDBusAuthObserver *observer,
1d26276
+                                              GIOStream *stream,
1d26276
+                                              GCredentials *credentials,
1d26276
+                                              wxWebViewWebKitExtension *extension)
1d26276
+{
1d26276
+    return wxgtk_webview_dbus_peer_is_authorized(credentials);
1d26276
+}
1d26276
+
1d26276
+static void
1d26276
+wxgtk_webview_dbus_connection_created_cb(GObject *source_object,
1d26276
+                                         GAsyncResult *result,
1d26276
+                                         wxWebViewWebKitExtension *extension)
1d26276
+{
1d26276
+    static GDBusNodeInfo *introspection_data =
1d26276
+        g_dbus_node_info_new_for_xml(introspection_xml, NULL);
1d26276
+
1d26276
+    GError *error = NULL;
1d26276
+    GDBusConnection *connection =
1d26276
+        g_dbus_connection_new_for_address_finish(result, &error);
1d26276
+    if (error)
1d26276
+    {
1d26276
+        g_warning("Failed to connect to UI process: %s", error->message);
1d26276
+        g_error_free(error);
1d26276
+        return;
1d26276
+    }
1d26276
+
1d26276
+    guint registration_id =
1d26276
+        g_dbus_connection_register_object(connection,
1d26276
+                                          WXGTK_WEB_EXTENSION_OBJECT_PATH,
1d26276
+                                          introspection_data->interfaces[0],
1d26276
+                                          &interface_vtable,
1d26276
+                                          extension,
1d26276
+                                          NULL,
1d26276
+                                          &error);
1d26276
+    if (!registration_id)
1d26276
+    {
1d26276
+        g_warning ("Failed to register web extension object: %s\n", error->message);
1d26276
+        g_error_free (error);
1d26276
+        g_object_unref (connection);
1d26276
+        return;
1d26276
+    }
1d26276
+
1d26276
+    extension->SetDBusConnection(connection);
1d26276
+}
1d26276
+
1d26276
+extern "C" WXEXPORT void
1d26276
+webkit_web_extension_initialize_with_user_data (WebKitWebExtension *webkit_extension,
1d26276
+                                                GVariant           *user_data)
1d26276
+{
1d26276
+    const char *server_address;
1d26276
+
1d26276
+    g_variant_get (user_data, "(&s)", &server_address);
1d26276
+
1d26276
+    gs_extension = new wxWebViewWebKitExtension(webkit_extension,
1d26276
+                                                server_address);
1d26276
+}