Skip to content

Commit 419bc8e

Browse files
[GTK] Add API to create a WebKitWebContext
https://bugs.webkit.org/show_bug.cgi?id=138826 Reviewed by Gustavo Noronha Silva. Source/WebKit2: We have always used a default web context without providing API to create others. The main reason was that nobody requested it and we haven't needed it either. The main problem of the default web context is that you can't configure anything during construction. This hasn't been a problem so far because all the web context configuration we expose in the API can be configured after construction. But now we need to expose API to allow the user to configure the local storage directory, which is a construct only configuration. The default web context was also a problem for our unit tests, because sharing the same context made it difficult to ensure tests cases are independent to each other. * UIProcess/API/gtk/WebKitGeolocationProvider.cpp: (WebKitGeolocationProvider::~WebKitGeolocationProvider): Reset the provider to avoid crashes when web context is destroyed and a new one is created. * UIProcess/API/gtk/WebKitWebContext.cpp: (webkitWebContextConstructed): Add constructed implementation to create the WebContext and initialize it. (webkitWebContextDispose): Detach web context clients to avoid crashes when a client callback is called on a disposed WebKitWebContext. (webkit_web_context_class_init): Initialize gettext, add constructed implementation and add the pointer to the vmethods when creating signals. (createDefaultWebContext): Simply create a WebKitWebContext. (webkit_web_context_new): New public method to create a WebKitWebContext. (injectedBundleFilename): Deleted. * UIProcess/API/gtk/WebKitWebContext.h: Add virtual methods for signals, so that users can inherit from WebKitWebContext and override the virtual methods. * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbol. Tools: Use a different WebKitWebContext for every test to ensure test cases are independent to each other. Tests using DBus to communicate with the injected bundle extension now use a unique name for the well known DBus name. * TestWebKitAPI/Tests/WebKit2Gtk/TestAuthentication.cpp: (beforeAll): Remove comment about the order of the tests and move the success test before the failed one now that tests don't depend on each others. * TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp: (beforeAll): Remove call to set the web extensions directory, since this is now done for all test in the Test constructor. * TestWebKitAPI/Tests/WebKit2Gtk/TestCookieManager.cpp: (beforeAll): Do not create a temporary directory, a temporary data directory is now created for all tests. (afterAll): * TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp: (testWebKitDOMNodeHierarchyNavigation): Pass the web extension ID to the web process test runner. (testWebKitDOMNodeInsertion): Ditto. (testWebKitDOMNodeTagNames): Ditto. (beforeAll): Remove call to set the web extensions directory. * TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNodeFilter.cpp: (runTest): Pass the web extension ID to the web process test runner. (beforeAll): Remove call to set the web extensions directory. * TestWebKitAPI/Tests/WebKit2Gtk/TestDOMXPathNSResolver.cpp: (runTest): Pass the web extension ID to the web process test runner. (beforeAll): Remove call to set the web extensions directory. * TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp: (createFileAtDestination): Use Test::dataDirectory() as base dir for temporary files. (beforeAll): Do not create a temporary directory. (afterAll): * TestWebKitAPI/Tests/WebKit2Gtk/TestFrame.cpp: (webkitFrameTestRun): Pass the web extension ID to the web process test runner. (beforeAll): Remove call to set the web extensions directory. * TestWebKitAPI/Tests/WebKit2Gtk/TestLoaderClient.cpp: (beforeAll): Remove call to set the web extensions directory. * TestWebKitAPI/Tests/WebKit2Gtk/TestMultiprocess.cpp: (testProcessPerWebView): Use local member instead of global variable. (testMultiprocessWebViewCreateReadyClose): Ditto. (beforeAll): Do not connect to initialize-web-extensions, Test now connects to the signal for all tests and calls a virtual method that test can override. (afterAll): (initializeWebExtensions): Deleted. * TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp: (testPrintOperationPrint): Use Test::dataDirectory() as base dir for temporary files. (beforeAll): Do not create a temporary directory. (afterAll): * TestWebKitAPI/Tests/WebKit2Gtk/TestResources.cpp: (beforeAll): Remove call to set the web extensions directory. * TestWebKitAPI/Tests/WebKit2Gtk/TestSSL.cpp: (beforeAll): Remove comment about the tests order. * TestWebKitAPI/Tests/WebKit2Gtk/TestWebExtensions.cpp: (testWebExtensionGetTitle): Build the DBus service name using the web extension ID. (testDocumentLoadedSignal): Ditto. (testWebKitWebViewProcessCrashed): Ditto. (testWebExtensionIsolatedWorld): Ditto. (beforeAll): Remove initialization-user-data test, since now all tests are passing user data to the web extension. (testWebExtensionInitializationUserData): Deleted. (initializeWebExtensions): Deleted. * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp: (testSetDirectory): Use the web context member inherited from Test. (testClearDatabase): Ditto. (testGetFaviconURI): Ditto. (beforeAll): Do not create a temporary directory. (afterAll): (webkitFaviconDatabaseFinalizedCallback): Deleted. * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp: (UserContentManagerTest::UserContentManagerTest): (beforeAll): Remove call to set the web extensions directory. * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp: (testWebContextDefault): Check also that a newly create web context is not the default web context. (testWebContextSpellChecker): Use the web context member inherited from Test. (testWebContextLanguages): Ditto. * TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp: (methodCallCallback): Remove GetInitializationUserData method. (webkit_web_extension_initialize_with_user_data): Always create the DBus name using the user data provided. (makeBusName): Deleted. * TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp: (webkit_web_extension_initialize_with_user_data): Create the DBus name using the user data provided. (webkit_web_extension_initialize): Deleted. * TestWebKitAPI/gtk/WebKit2Gtk/TestMain.cpp: (Test::dataDirectory): Return the temporary data directory. (removeNonEmptyDirectory): Also remove directories recursively. (main): Remove the disk cache directory initialization, since this is now done in the Test constructor. * TestWebKitAPI/gtk/WebKit2Gtk/TestMain.h: (Test::initializeWebExtensionsCallback): Call the virtual method initializeWebExtensions() (Test::Test): Create a new WebKitWebContext and initialize it. (Test::~Test): Disconnect initialize-web-extensions signal. (Test::initializeWebExtensions): Set the web extensions directory and user data. * TestWebKitAPI/gtk/WebKit2Gtk/WebProcessTestRunner.cpp: (WebProcessTestRunner::~WebProcessTestRunner): Use nullptr. (WebProcessTestRunner::runTest): Build the DBus proxy using a unique name created with the Test web extension ID. (WebProcessTestRunner::proxy): Deleted. * TestWebKitAPI/gtk/WebKit2Gtk/WebProcessTestRunner.h: * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp: (WebViewTest::WebViewTest): Create the web view with the Test web context. * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h: Add optional user content manager parameter to the constructor. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176256 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 874d603 commit 419bc8e

31 files changed

+412
-284
lines changed

Source/WebKit2/ChangeLog

+39
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
2014-11-18 Carlos Garcia Campos <[email protected]>
2+
3+
[GTK] Add API to create a WebKitWebContext
4+
https://bugs.webkit.org/show_bug.cgi?id=138826
5+
6+
Reviewed by Gustavo Noronha Silva.
7+
8+
We have always used a default web context without providing API to
9+
create others. The main reason was that nobody requested it and we
10+
haven't needed it either. The main problem of the default web
11+
context is that you can't configure anything during
12+
construction. This hasn't been a problem so far because all the
13+
web context configuration we expose in the API can be configured
14+
after construction. But now we need to expose API to allow the
15+
user to configure the local storage directory, which is a
16+
construct only configuration. The default web context was also a
17+
problem for our unit tests, because sharing the same context made
18+
it difficult to ensure tests cases are independent to each other.
19+
20+
* UIProcess/API/gtk/WebKitGeolocationProvider.cpp:
21+
(WebKitGeolocationProvider::~WebKitGeolocationProvider): Reset the
22+
provider to avoid crashes when web context is destroyed and a new
23+
one is created.
24+
* UIProcess/API/gtk/WebKitWebContext.cpp:
25+
(webkitWebContextConstructed): Add constructed implementation to
26+
create the WebContext and initialize it.
27+
(webkitWebContextDispose): Detach web context clients to avoid
28+
crashes when a client callback is called on a disposed WebKitWebContext.
29+
(webkit_web_context_class_init): Initialize gettext, add
30+
constructed implementation and add the pointer to the vmethods
31+
when creating signals.
32+
(createDefaultWebContext): Simply create a WebKitWebContext.
33+
(webkit_web_context_new): New public method to create a WebKitWebContext.
34+
(injectedBundleFilename): Deleted.
35+
* UIProcess/API/gtk/WebKitWebContext.h: Add virtual methods for
36+
signals, so that users can inherit from WebKitWebContext and
37+
override the virtual methods.
38+
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbol.
39+
140
2014-11-18 Carlos Alberto Lopez Perez <[email protected]>
241

342
[SOUP] [GnuTLS] Don't use a SSL3.0 record version in client hello.

Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static void stopUpdatingCallback(WKGeolocationManagerRef, const void* clientInfo
5151
WebKitGeolocationProvider::~WebKitGeolocationProvider()
5252
{
5353
m_provider.stopUpdating();
54+
WKGeolocationManagerSetProvider(toAPI(m_geolocationManager.get()), nullptr);
5455
}
5556

5657
PassRefPtr<WebKitGeolocationProvider> WebKitGeolocationProvider::create(WebGeolocationManagerProxy* geolocationManager)

Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp

+89-54
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "config.h"
2121
#include "WebKitWebContext.h"
2222

23+
#include "APIDownloadClient.h"
2324
#include "APIString.h"
2425
#include "WebBatteryManagerProxy.h"
2526
#include "WebCertificateInfo.h"
@@ -144,6 +145,7 @@ typedef HashMap<uint64_t, GRefPtr<WebKitURISchemeRequest> > URISchemeRequestMap;
144145

145146
struct _WebKitWebContextPrivate {
146147
RefPtr<WebContext> context;
148+
bool clientsDetached;
147149

148150
GRefPtr<WebKitCookieManager> cookieManager;
149151
GRefPtr<WebKitFaviconDatabase> faviconDatabase;
@@ -199,10 +201,73 @@ static inline WebKitProcessModel toWebKitProcessModel(WebKit::ProcessModel proce
199201
}
200202
}
201203

204+
static const char* injectedBundleDirectory()
205+
{
206+
const char* bundleDirectory = g_getenv("WEBKIT_INJECTED_BUNDLE_PATH");
207+
if (bundleDirectory && g_file_test(bundleDirectory, G_FILE_TEST_IS_DIR))
208+
return bundleDirectory;
209+
210+
static const char* injectedBundlePath = LIBDIR G_DIR_SEPARATOR_S "webkit2gtk-" WEBKITGTK_API_VERSION_STRING
211+
G_DIR_SEPARATOR_S "injected-bundle" G_DIR_SEPARATOR_S;
212+
return injectedBundlePath;
213+
}
214+
215+
static void webkitWebContextConstructed(GObject* object)
216+
{
217+
G_OBJECT_CLASS(webkit_web_context_parent_class)->constructed(object);
218+
219+
GUniquePtr<char> bundleFilename(g_build_filename(injectedBundleDirectory(), "libwebkit2gtkinjectedbundle.so", nullptr));
220+
WebContextConfiguration webContextConfiguration;
221+
webContextConfiguration.injectedBundlePath = WebCore::filenameToString(bundleFilename.get());
222+
WebContext::applyPlatformSpecificConfigurationDefaults(webContextConfiguration);
223+
224+
WebKitWebContext* webContext = WEBKIT_WEB_CONTEXT(object);
225+
WebKitWebContextPrivate* priv = webContext->priv;
226+
priv->context = WebContext::create(WTF::move(webContextConfiguration));
227+
228+
priv->requestManager = priv->context->supplement<WebSoupCustomProtocolRequestManager>();
229+
priv->context->setCacheModel(CacheModelPrimaryWebBrowser);
230+
231+
priv->tlsErrorsPolicy = WEBKIT_TLS_ERRORS_POLICY_FAIL;
232+
priv->context->setIgnoreTLSErrors(false);
233+
234+
attachInjectedBundleClientToContext(webContext);
235+
attachDownloadClientToContext(webContext);
236+
attachRequestManagerClientToContext(webContext);
237+
238+
#if ENABLE(GEOLOCATION)
239+
priv->geolocationProvider = WebKitGeolocationProvider::create(priv->context->supplement<WebGeolocationManagerProxy>());
240+
#endif
241+
#if ENABLE(BATTERY_STATUS)
242+
priv->batteryProvider = WebKitBatteryProvider::create(priv->context->supplement<WebBatteryManagerProxy>());
243+
#endif
244+
#if ENABLE(SPELLCHECK)
245+
priv->textChecker = WebKitTextChecker::create();
246+
#endif
247+
}
248+
249+
static void webkitWebContextDispose(GObject* object)
250+
{
251+
WebKitWebContextPrivate* priv = WEBKIT_WEB_CONTEXT(object)->priv;
252+
if (!priv->clientsDetached) {
253+
priv->clientsDetached = true;
254+
priv->context->initializeInjectedBundleClient(nullptr);
255+
priv->context->setDownloadClient(nullptr);
256+
}
257+
258+
G_OBJECT_CLASS(webkit_web_context_parent_class)->dispose(object);
259+
}
260+
202261
static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass)
203262
{
204263
GObjectClass* gObjectClass = G_OBJECT_CLASS(webContextClass);
205264

265+
bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
266+
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
267+
268+
gObjectClass->constructed = webkitWebContextConstructed;
269+
gObjectClass->dispose = webkitWebContextDispose;
270+
206271
/**
207272
* WebKitWebContext::download-started:
208273
* @context: the #WebKitWebContext
@@ -212,12 +277,13 @@ static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass
212277
*/
213278
signals[DOWNLOAD_STARTED] =
214279
g_signal_new("download-started",
215-
G_TYPE_FROM_CLASS(gObjectClass),
216-
G_SIGNAL_RUN_LAST,
217-
0, 0, 0,
218-
g_cclosure_marshal_VOID__OBJECT,
219-
G_TYPE_NONE, 1,
220-
WEBKIT_TYPE_DOWNLOAD);
280+
G_TYPE_FROM_CLASS(gObjectClass),
281+
G_SIGNAL_RUN_LAST,
282+
G_STRUCT_OFFSET(WebKitWebContextClass, download_started),
283+
nullptr, nullptr,
284+
g_cclosure_marshal_VOID__OBJECT,
285+
G_TYPE_NONE, 1,
286+
WEBKIT_TYPE_DOWNLOAD);
221287

222288
/**
223289
* WebKitWebContext::initialize-web-extensions:
@@ -234,60 +300,15 @@ static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass
234300
g_signal_new("initialize-web-extensions",
235301
G_TYPE_FROM_CLASS(gObjectClass),
236302
G_SIGNAL_RUN_LAST,
237-
0, nullptr, nullptr,
303+
G_STRUCT_OFFSET(WebKitWebContextClass, initialize_web_extensions),
304+
nullptr, nullptr,
238305
g_cclosure_marshal_VOID__VOID,
239306
G_TYPE_NONE, 0);
240307
}
241308

242-
static CString injectedBundleDirectory()
243-
{
244-
const char* bundleDirectory = g_getenv("WEBKIT_INJECTED_BUNDLE_PATH");
245-
if (bundleDirectory && g_file_test(bundleDirectory, G_FILE_TEST_IS_DIR))
246-
return bundleDirectory;
247-
248-
static const char* injectedBundlePath = LIBDIR G_DIR_SEPARATOR_S "webkit2gtk-" WEBKITGTK_API_VERSION_STRING
249-
G_DIR_SEPARATOR_S "injected-bundle" G_DIR_SEPARATOR_S;
250-
return injectedBundlePath;
251-
}
252-
253-
static CString injectedBundleFilename()
254-
{
255-
GUniquePtr<char> bundleFilename(g_build_filename(injectedBundleDirectory().data(), "libwebkit2gtkinjectedbundle.so", NULL));
256-
return bundleFilename.get();
257-
}
258-
259309
static gpointer createDefaultWebContext(gpointer)
260310
{
261-
bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
262-
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
263-
264-
static GRefPtr<WebKitWebContext> webContext = adoptGRef(WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, NULL)));
265-
WebKitWebContextPrivate* priv = webContext->priv;
266-
267-
WebContextConfiguration webContextConfiguration;
268-
webContextConfiguration.injectedBundlePath = WebCore::filenameToString(injectedBundleFilename().data());
269-
WebContext::applyPlatformSpecificConfigurationDefaults(webContextConfiguration);
270-
priv->context = WebContext::create(WTF::move(webContextConfiguration));
271-
272-
priv->requestManager = webContext->priv->context->supplement<WebSoupCustomProtocolRequestManager>();
273-
priv->context->setCacheModel(CacheModelPrimaryWebBrowser);
274-
275-
priv->tlsErrorsPolicy = WEBKIT_TLS_ERRORS_POLICY_FAIL;
276-
priv->context->setIgnoreTLSErrors(false);
277-
278-
attachInjectedBundleClientToContext(webContext.get());
279-
attachDownloadClientToContext(webContext.get());
280-
attachRequestManagerClientToContext(webContext.get());
281-
282-
#if ENABLE(GEOLOCATION)
283-
priv->geolocationProvider = WebKitGeolocationProvider::create(priv->context->supplement<WebGeolocationManagerProxy>());
284-
#endif
285-
#if ENABLE(BATTERY_STATUS)
286-
priv->batteryProvider = WebKitBatteryProvider::create(priv->context->supplement<WebBatteryManagerProxy>());
287-
#endif
288-
#if ENABLE(SPELLCHECK)
289-
priv->textChecker = WebKitTextChecker::create();
290-
#endif
311+
static GRefPtr<WebKitWebContext> webContext = adoptGRef(WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, nullptr)));
291312
return webContext.get();
292313
}
293314

@@ -304,6 +325,20 @@ WebKitWebContext* webkit_web_context_get_default(void)
304325
return WEBKIT_WEB_CONTEXT(g_once(&onceInit, createDefaultWebContext, 0));
305326
}
306327

328+
/**
329+
* webkit_web_context_new:
330+
*
331+
* Create a new #WebKitWebContext
332+
*
333+
* Returns: (transfer full): a newly created #WebKitWebContext
334+
*
335+
* Since: 2.8
336+
*/
337+
WebKitWebContext* webkit_web_context_new(void)
338+
{
339+
return WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, nullptr));
340+
}
341+
307342
/**
308343
* webkit_web_context_set_cache_model:
309344
* @context: the #WebKitWebContext

Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ struct _WebKitWebContext {
127127
struct _WebKitWebContextClass {
128128
GObjectClass parent;
129129

130+
void (* download_started) (WebKitWebContext *context,
131+
WebKitDownload *download);
132+
void (* initialize_web_extensions) (WebKitWebContext *context);
133+
130134
void (*_webkit_reserved0) (void);
131135
void (*_webkit_reserved1) (void);
132136
void (*_webkit_reserved2) (void);
133137
void (*_webkit_reserved3) (void);
134138
void (*_webkit_reserved4) (void);
135139
void (*_webkit_reserved5) (void);
136-
void (*_webkit_reserved6) (void);
137-
void (*_webkit_reserved7) (void);
138140
};
139141

140142
WEBKIT_API GType
@@ -143,6 +145,9 @@ webkit_web_context_get_type (void);
143145
WEBKIT_API WebKitWebContext *
144146
webkit_web_context_get_default (void);
145147

148+
WEBKIT_API WebKitWebContext *
149+
webkit_web_context_new (void);
150+
146151
WEBKIT_API void
147152
webkit_web_context_set_cache_model (WebKitWebContext *context,
148153
WebKitCacheModel cache_model);

Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ WebKitCacheModel
2828
WebKitProcessModel
2929
WebKitTLSErrorsPolicy
3030
webkit_web_context_get_default
31+
webkit_web_context_new
3132
webkit_web_context_get_cache_model
3233
webkit_web_context_set_cache_model
3334
webkit_web_context_clear_cache

0 commit comments

Comments
 (0)