1/*
2 * Copyright (C) 2011 Igalia S.L.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "config.h"
21#include "WebKitWebContext.h"
22
23#include "APIAutomationClient.h"
24#include "APICustomProtocolManagerClient.h"
25#include "APIDownloadClient.h"
26#include "APIInjectedBundleClient.h"
27#include "APIPageConfiguration.h"
28#include "APIProcessPoolConfiguration.h"
29#include "APIString.h"
30#include "TextChecker.h"
31#include "TextCheckerState.h"
32#include "WebAutomationSession.h"
33#include "WebCertificateInfo.h"
34#include "WebKitAutomationSessionPrivate.h"
35#include "WebKitCustomProtocolManagerClient.h"
36#include "WebKitDownloadClient.h"
37#include "WebKitDownloadPrivate.h"
38#include "WebKitFaviconDatabasePrivate.h"
39#include "WebKitGeolocationManagerPrivate.h"
40#include "WebKitInjectedBundleClient.h"
41#include "WebKitNetworkProxySettingsPrivate.h"
42#include "WebKitNotificationProvider.h"
43#include "WebKitPluginPrivate.h"
44#include "WebKitPrivate.h"
45#include "WebKitSecurityManagerPrivate.h"
46#include "WebKitSecurityOriginPrivate.h"
47#include "WebKitSettingsPrivate.h"
48#include "WebKitURISchemeRequestPrivate.h"
49#include "WebKitUserContentManagerPrivate.h"
50#include "WebKitWebContextPrivate.h"
51#include "WebKitWebViewPrivate.h"
52#include "WebKitWebsiteDataManagerPrivate.h"
53#include "WebNotificationManagerProxy.h"
54#include "WebsiteDataType.h"
55#include <JavaScriptCore/RemoteInspector.h>
56#include <glib/gi18n-lib.h>
57#include <libintl.h>
58#include <memory>
59#include <wtf/FileSystem.h>
60#include <wtf/HashMap.h>
61#include <wtf/Language.h>
62#include <wtf/NeverDestroyed.h>
63#include <wtf/RefCounted.h>
64#include <wtf/RefPtr.h>
65#include <wtf/glib/GRefPtr.h>
66#include <wtf/glib/GUniquePtr.h>
67#include <wtf/glib/WTFGType.h>
68#include <wtf/text/CString.h>
69
70#if PLATFORM(GTK)
71#include "WebKitRemoteInspectorProtocolHandler.h"
72#endif
73
74using namespace WebKit;
75
76/**
77 * SECTION: WebKitWebContext
78 * @Short_description: Manages aspects common to all #WebKitWebView<!-- -->s
79 * @Title: WebKitWebContext
80 *
81 * The #WebKitWebContext manages all aspects common to all
82 * #WebKitWebView<!-- -->s.
83 *
84 * You can define the #WebKitCacheModel and #WebKitProcessModel with
85 * webkit_web_context_set_cache_model() and
86 * webkit_web_context_set_process_model(), depending on the needs of
87 * your application. You can access the #WebKitSecurityManager to specify
88 * the behaviour of your application regarding security using
89 * webkit_web_context_get_security_manager().
90 *
91 * It is also possible to change your preferred language or enable
92 * spell checking, using webkit_web_context_set_preferred_languages(),
93 * webkit_web_context_set_spell_checking_languages() and
94 * webkit_web_context_set_spell_checking_enabled().
95 *
96 * You can use webkit_web_context_register_uri_scheme() to register
97 * custom URI schemes, and manage several other settings.
98 *
99 * TLS certificate validation failure is now treated as a transport
100 * error by default. To handle TLS failures differently, you can
101 * connect to #WebKitWebView::load-failed-with-tls-errors.
102 * Alternatively, you can use webkit_web_context_set_tls_errors_policy()
103 * to set the policy %WEBKIT_TLS_ERRORS_POLICY_IGNORE; however, this is
104 * not appropriate for Internet applications.
105 *
106 */
107
108enum {
109 PROP_0,
110
111#if PLATFORM(GTK)
112 PROP_LOCAL_STORAGE_DIRECTORY,
113#endif
114 PROP_WEBSITE_DATA_MANAGER
115};
116
117enum {
118 DOWNLOAD_STARTED,
119 INITIALIZE_WEB_EXTENSIONS,
120 INITIALIZE_NOTIFICATION_PERMISSIONS,
121 AUTOMATION_STARTED,
122
123 LAST_SIGNAL
124};
125
126class WebKitURISchemeHandler: public RefCounted<WebKitURISchemeHandler> {
127public:
128 WebKitURISchemeHandler(WebKitURISchemeRequestCallback callback, void* userData, GDestroyNotify destroyNotify)
129 : m_callback(callback)
130 , m_userData(userData)
131 , m_destroyNotify(destroyNotify)
132 {
133 }
134
135 ~WebKitURISchemeHandler()
136 {
137 if (m_destroyNotify)
138 m_destroyNotify(m_userData);
139 }
140
141 bool hasCallback()
142 {
143 return m_callback;
144 }
145
146 void performCallback(WebKitURISchemeRequest* request)
147 {
148 ASSERT(m_callback);
149
150 m_callback(request, m_userData);
151 }
152
153private:
154 WebKitURISchemeRequestCallback m_callback { nullptr };
155 void* m_userData { nullptr };
156 GDestroyNotify m_destroyNotify { nullptr };
157};
158
159typedef HashMap<String, RefPtr<WebKitURISchemeHandler> > URISchemeHandlerMap;
160typedef HashMap<uint64_t, GRefPtr<WebKitURISchemeRequest> > URISchemeRequestMap;
161
162class WebKitAutomationClient;
163
164struct _WebKitWebContextPrivate {
165 RefPtr<WebProcessPool> processPool;
166 bool clientsDetached;
167
168 GRefPtr<WebKitFaviconDatabase> faviconDatabase;
169 GRefPtr<WebKitSecurityManager> securityManager;
170 URISchemeHandlerMap uriSchemeHandlers;
171 URISchemeRequestMap uriSchemeRequests;
172 GRefPtr<WebKitGeolocationManager> geolocationManager;
173 std::unique_ptr<WebKitNotificationProvider> notificationProvider;
174 GRefPtr<WebKitWebsiteDataManager> websiteDataManager;
175
176 CString faviconDatabaseDirectory;
177 WebKitTLSErrorsPolicy tlsErrorsPolicy;
178 WebKitProcessModel processModel;
179 unsigned processCountLimit;
180
181 HashMap<uint64_t, WebKitWebView*> webViews;
182 unsigned ephemeralPageCount;
183
184 CString webExtensionsDirectory;
185 GRefPtr<GVariant> webExtensionsInitializationUserData;
186
187 CString localStorageDirectory;
188#if ENABLE(REMOTE_INSPECTOR)
189#if PLATFORM(GTK)
190 std::unique_ptr<RemoteInspectorProtocolHandler> remoteInspectorProtocolHandler;
191#endif
192 std::unique_ptr<WebKitAutomationClient> automationClient;
193 GRefPtr<WebKitAutomationSession> automationSession;
194#endif
195};
196
197static guint signals[LAST_SIGNAL] = { 0, };
198
199#if ENABLE(REMOTE_INSPECTOR)
200class WebKitAutomationClient final : Inspector::RemoteInspector::Client {
201public:
202 explicit WebKitAutomationClient(WebKitWebContext* context)
203 : m_webContext(context)
204 {
205 Inspector::RemoteInspector::singleton().setClient(this);
206 }
207
208 ~WebKitAutomationClient()
209 {
210 Inspector::RemoteInspector::singleton().setClient(nullptr);
211 }
212
213private:
214 bool remoteAutomationAllowed() const override { return true; }
215
216 String browserName() const override
217 {
218 if (!m_webContext->priv->automationSession)
219 return { };
220
221 return webkitAutomationSessionGetBrowserName(m_webContext->priv->automationSession.get());
222 }
223
224 String browserVersion() const override
225 {
226 if (!m_webContext->priv->automationSession)
227 return { };
228
229 return webkitAutomationSessionGetBrowserVersion(m_webContext->priv->automationSession.get());
230 }
231
232 void requestAutomationSession(const String& sessionIdentifier, const Inspector::RemoteInspector::Client::SessionCapabilities& capabilities) override
233 {
234 ASSERT(!m_webContext->priv->automationSession);
235 m_webContext->priv->automationSession = adoptGRef(webkitAutomationSessionCreate(m_webContext, sessionIdentifier.utf8().data(), capabilities));
236 g_signal_emit(m_webContext, signals[AUTOMATION_STARTED], 0, m_webContext->priv->automationSession.get());
237 m_webContext->priv->processPool->setAutomationSession(&webkitAutomationSessionGetSession(m_webContext->priv->automationSession.get()));
238 }
239
240 WebKitWebContext* m_webContext;
241};
242
243void webkitWebContextWillCloseAutomationSession(WebKitWebContext* webContext)
244{
245 webContext->priv->processPool->setAutomationSession(nullptr);
246 webContext->priv->automationSession = nullptr;
247}
248#endif // ENABLE(REMOTE_INSPECTOR)
249
250WEBKIT_DEFINE_TYPE(WebKitWebContext, webkit_web_context, G_TYPE_OBJECT)
251
252#if PLATFORM(GTK)
253#define INJECTED_BUNDLE_FILENAME "libwebkit2gtkinjectedbundle.so"
254#elif PLATFORM(WPE)
255#define INJECTED_BUNDLE_FILENAME "libWPEInjectedBundle.so"
256#endif
257
258static const char* injectedBundleDirectory()
259{
260#if ENABLE(DEVELOPER_MODE)
261 const char* bundleDirectory = g_getenv("WEBKIT_INJECTED_BUNDLE_PATH");
262 if (bundleDirectory && g_file_test(bundleDirectory, G_FILE_TEST_IS_DIR))
263 return bundleDirectory;
264#endif
265
266#if PLATFORM(GTK)
267 static const char* injectedBundlePath = LIBDIR G_DIR_SEPARATOR_S "webkit2gtk-" WEBKITGTK_API_VERSION_STRING
268 G_DIR_SEPARATOR_S "injected-bundle" G_DIR_SEPARATOR_S;
269 return injectedBundlePath;
270#elif PLATFORM(WPE)
271 static const char* injectedBundlePath = PKGLIBDIR G_DIR_SEPARATOR_S "injected-bundle" G_DIR_SEPARATOR_S;
272 return injectedBundlePath;
273#endif
274}
275
276static void webkitWebContextGetProperty(GObject* object, guint propID, GValue* value, GParamSpec* paramSpec)
277{
278 WebKitWebContext* context = WEBKIT_WEB_CONTEXT(object);
279
280 switch (propID) {
281#if PLATFORM(GTK)
282 case PROP_LOCAL_STORAGE_DIRECTORY:
283 g_value_set_string(value, context->priv->localStorageDirectory.data());
284 break;
285#endif
286 case PROP_WEBSITE_DATA_MANAGER:
287 g_value_set_object(value, webkit_web_context_get_website_data_manager(context));
288 break;
289 default:
290 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, paramSpec);
291 }
292}
293
294static void webkitWebContextSetProperty(GObject* object, guint propID, const GValue* value, GParamSpec* paramSpec)
295{
296 WebKitWebContext* context = WEBKIT_WEB_CONTEXT(object);
297
298 switch (propID) {
299#if PLATFORM(GTK)
300 case PROP_LOCAL_STORAGE_DIRECTORY:
301 context->priv->localStorageDirectory = g_value_get_string(value);
302 break;
303#endif
304 case PROP_WEBSITE_DATA_MANAGER: {
305 gpointer manager = g_value_get_object(value);
306 context->priv->websiteDataManager = manager ? WEBKIT_WEBSITE_DATA_MANAGER(manager) : nullptr;
307 break;
308 }
309 default:
310 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, paramSpec);
311 }
312}
313
314static inline Ref<WebsiteDataStoreConfiguration> websiteDataStoreConfigurationForWebProcessPoolConfiguration(const API::ProcessPoolConfiguration& processPoolconfigurarion)
315{
316 auto configuration = WebsiteDataStoreConfiguration::create();
317 configuration->setApplicationCacheDirectory(String(processPoolconfigurarion.applicationCacheDirectory()));
318 configuration->setNetworkCacheDirectory(String(processPoolconfigurarion.diskCacheDirectory()));
319 configuration->setWebSQLDatabaseDirectory(String(processPoolconfigurarion.webSQLDatabaseDirectory()));
320 configuration->setLocalStorageDirectory(String(processPoolconfigurarion.localStorageDirectory()));
321 configuration->setDeviceIdHashSaltsStorageDirectory(String(processPoolconfigurarion.deviceIdHashSaltsStorageDirectory()));
322 configuration->setMediaKeysStorageDirectory(String(processPoolconfigurarion.mediaKeysStorageDirectory()));
323 return configuration;
324}
325
326static void webkitWebContextConstructed(GObject* object)
327{
328 G_OBJECT_CLASS(webkit_web_context_parent_class)->constructed(object);
329
330 GUniquePtr<char> bundleFilename(g_build_filename(injectedBundleDirectory(), INJECTED_BUNDLE_FILENAME, nullptr));
331
332 API::ProcessPoolConfiguration configuration;
333 configuration.setInjectedBundlePath(FileSystem::stringFromFileSystemRepresentation(bundleFilename.get()));
334 configuration.setDiskCacheSpeculativeValidationEnabled(true);
335
336 WebKitWebContext* webContext = WEBKIT_WEB_CONTEXT(object);
337 WebKitWebContextPrivate* priv = webContext->priv;
338 if (priv->websiteDataManager && !webkit_website_data_manager_is_ephemeral(priv->websiteDataManager.get())) {
339 configuration.setLocalStorageDirectory(FileSystem::stringFromFileSystemRepresentation(webkit_website_data_manager_get_local_storage_directory(priv->websiteDataManager.get())));
340 configuration.setDiskCacheDirectory(FileSystem::pathByAppendingComponent(FileSystem::stringFromFileSystemRepresentation(webkit_website_data_manager_get_disk_cache_directory(priv->websiteDataManager.get())), networkCacheSubdirectory));
341 configuration.setApplicationCacheDirectory(FileSystem::stringFromFileSystemRepresentation(webkit_website_data_manager_get_offline_application_cache_directory(priv->websiteDataManager.get())));
342 configuration.setIndexedDBDatabaseDirectory(FileSystem::stringFromFileSystemRepresentation(webkit_website_data_manager_get_indexeddb_directory(priv->websiteDataManager.get())));
343 configuration.setWebSQLDatabaseDirectory(FileSystem::stringFromFileSystemRepresentation(webkit_website_data_manager_get_websql_directory(priv->websiteDataManager.get())));
344 } else if (!priv->localStorageDirectory.isNull())
345 configuration.setLocalStorageDirectory(FileSystem::stringFromFileSystemRepresentation(priv->localStorageDirectory.data()));
346
347 priv->processPool = WebProcessPool::create(configuration);
348
349 if (!priv->websiteDataManager)
350 priv->websiteDataManager = adoptGRef(webkitWebsiteDataManagerCreate(websiteDataStoreConfigurationForWebProcessPoolConfiguration(configuration)));
351 priv->processPool->setPrimaryDataStore(webkitWebsiteDataManagerGetDataStore(priv->websiteDataManager.get()));
352
353 webkitWebsiteDataManagerAddProcessPool(priv->websiteDataManager.get(), *priv->processPool);
354
355 priv->tlsErrorsPolicy = WEBKIT_TLS_ERRORS_POLICY_FAIL;
356 priv->processPool->setIgnoreTLSErrors(false);
357
358#if ENABLE(MEMORY_SAMPLER)
359 if (getenv("WEBKIT_SAMPLE_MEMORY"))
360 priv->processPool->startMemorySampler(0);
361#endif
362
363 attachInjectedBundleClientToContext(webContext);
364 attachDownloadClientToContext(webContext);
365 attachCustomProtocolManagerClientToContext(webContext);
366
367 priv->geolocationManager = adoptGRef(webkitGeolocationManagerCreate(priv->processPool->supplement<WebGeolocationManagerProxy>()));
368 priv->notificationProvider = std::make_unique<WebKitNotificationProvider>(priv->processPool->supplement<WebNotificationManagerProxy>(), webContext);
369#if PLATFORM(GTK) && ENABLE(REMOTE_INSPECTOR)
370 priv->remoteInspectorProtocolHandler = std::make_unique<RemoteInspectorProtocolHandler>(webContext);
371#endif
372}
373
374static void webkitWebContextDispose(GObject* object)
375{
376 WebKitWebContextPrivate* priv = WEBKIT_WEB_CONTEXT(object)->priv;
377 if (!priv->clientsDetached) {
378 priv->clientsDetached = true;
379 priv->processPool->setInjectedBundleClient(nullptr);
380 priv->processPool->setDownloadClient(nullptr);
381 priv->processPool->setLegacyCustomProtocolManagerClient(nullptr);
382 }
383
384 if (priv->websiteDataManager) {
385 webkitWebsiteDataManagerRemoveProcessPool(priv->websiteDataManager.get(), *priv->processPool);
386 priv->websiteDataManager = nullptr;
387 }
388
389 G_OBJECT_CLASS(webkit_web_context_parent_class)->dispose(object);
390}
391
392static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass)
393{
394 GObjectClass* gObjectClass = G_OBJECT_CLASS(webContextClass);
395
396 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
397 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
398
399 gObjectClass->get_property = webkitWebContextGetProperty;
400 gObjectClass->set_property = webkitWebContextSetProperty;
401 gObjectClass->constructed = webkitWebContextConstructed;
402 gObjectClass->dispose = webkitWebContextDispose;
403
404#if PLATFORM(GTK)
405 /**
406 * WebKitWebContext:local-storage-directory:
407 *
408 * The directory where local storage data will be saved.
409 *
410 * Since: 2.8
411 *
412 * Deprecated: 2.10. Use #WebKitWebsiteDataManager:local-storage-directory instead.
413 */
414 g_object_class_install_property(
415 gObjectClass,
416 PROP_LOCAL_STORAGE_DIRECTORY,
417 g_param_spec_string(
418 "local-storage-directory",
419 _("Local Storage Directory"),
420 _("The directory where local storage data will be saved"),
421 nullptr,
422 static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
423#endif
424
425 /**
426 * WebKitWebContext:website-data-manager:
427 *
428 * The #WebKitWebsiteDataManager associated with this context.
429 *
430 * Since: 2.10
431 */
432 g_object_class_install_property(
433 gObjectClass,
434 PROP_WEBSITE_DATA_MANAGER,
435 g_param_spec_object(
436 "website-data-manager",
437 _("Website Data Manager"),
438 _("The WebKitWebsiteDataManager associated with this context"),
439 WEBKIT_TYPE_WEBSITE_DATA_MANAGER,
440 static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
441
442 /**
443 * WebKitWebContext::download-started:
444 * @context: the #WebKitWebContext
445 * @download: the #WebKitDownload associated with this event
446 *
447 * This signal is emitted when a new download request is made.
448 */
449 signals[DOWNLOAD_STARTED] =
450 g_signal_new("download-started",
451 G_TYPE_FROM_CLASS(gObjectClass),
452 G_SIGNAL_RUN_LAST,
453 G_STRUCT_OFFSET(WebKitWebContextClass, download_started),
454 nullptr, nullptr,
455 g_cclosure_marshal_VOID__OBJECT,
456 G_TYPE_NONE, 1,
457 WEBKIT_TYPE_DOWNLOAD);
458
459 /**
460 * WebKitWebContext::initialize-web-extensions:
461 * @context: the #WebKitWebContext
462 *
463 * This signal is emitted when a new web process is about to be
464 * launched. It signals the most appropriate moment to use
465 * webkit_web_context_set_web_extensions_initialization_user_data()
466 * and webkit_web_context_set_web_extensions_directory().
467 *
468 * Since: 2.4
469 */
470 signals[INITIALIZE_WEB_EXTENSIONS] =
471 g_signal_new("initialize-web-extensions",
472 G_TYPE_FROM_CLASS(gObjectClass),
473 G_SIGNAL_RUN_LAST,
474 G_STRUCT_OFFSET(WebKitWebContextClass, initialize_web_extensions),
475 nullptr, nullptr,
476 g_cclosure_marshal_VOID__VOID,
477 G_TYPE_NONE, 0);
478
479 /**
480 * WebKitWebContext::initialize-notification-permissions:
481 * @context: the #WebKitWebContext
482 *
483 * This signal is emitted when a #WebKitWebContext needs to set
484 * initial notification permissions for a web process. It is emitted
485 * when a new web process is about to be launched, and signals the
486 * most appropriate moment to use
487 * webkit_web_context_initialize_notification_permissions(). If no
488 * notification permissions have changed since the last time this
489 * signal was emitted, then there is no need to call
490 * webkit_web_context_initialize_notification_permissions() again.
491 *
492 * Since: 2.16
493 */
494 signals[INITIALIZE_NOTIFICATION_PERMISSIONS] =
495 g_signal_new("initialize-notification-permissions",
496 G_TYPE_FROM_CLASS(gObjectClass),
497 G_SIGNAL_RUN_LAST,
498 G_STRUCT_OFFSET(WebKitWebContextClass, initialize_notification_permissions),
499 nullptr, nullptr,
500 g_cclosure_marshal_VOID__VOID,
501 G_TYPE_NONE, 0);
502
503 /**
504 * WebKitWebContext::automation-started:
505 * @context: the #WebKitWebContext
506 * @session: the #WebKitAutomationSession associated with this event
507 *
508 * This signal is emitted when a new automation request is made.
509 * Note that it will never be emitted if automation is not enabled in @context,
510 * see webkit_web_context_set_automation_allowed() for more details.
511 *
512 * Since: 2.18
513 */
514 signals[AUTOMATION_STARTED] =
515 g_signal_new("automation-started",
516 G_TYPE_FROM_CLASS(gObjectClass),
517 G_SIGNAL_RUN_LAST,
518 G_STRUCT_OFFSET(WebKitWebContextClass, automation_started),
519 nullptr, nullptr,
520 g_cclosure_marshal_VOID__OBJECT,
521 G_TYPE_NONE, 1,
522 WEBKIT_TYPE_AUTOMATION_SESSION);
523}
524
525static gpointer createDefaultWebContext(gpointer)
526{
527 static GRefPtr<WebKitWebContext> webContext = adoptGRef(WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, nullptr)));
528 return webContext.get();
529}
530
531/**
532 * webkit_web_context_get_default:
533 *
534 * Gets the default web context
535 *
536 * Returns: (transfer none): a #WebKitWebContext
537 */
538WebKitWebContext* webkit_web_context_get_default(void)
539{
540 static GOnce onceInit = G_ONCE_INIT;
541 return WEBKIT_WEB_CONTEXT(g_once(&onceInit, createDefaultWebContext, 0));
542}
543
544/**
545 * webkit_web_context_new:
546 *
547 * Create a new #WebKitWebContext
548 *
549 * Returns: (transfer full): a newly created #WebKitWebContext
550 *
551 * Since: 2.8
552 */
553WebKitWebContext* webkit_web_context_new(void)
554{
555 return WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, nullptr));
556}
557
558/**
559 * webkit_web_context_new_ephemeral:
560 *
561 * Create a new ephemeral #WebKitWebContext. An ephemeral #WebKitWebContext is a context
562 * created with an ephemeral #WebKitWebsiteDataManager. This is just a convenient method
563 * to create ephemeral contexts without having to create your own #WebKitWebsiteDataManager.
564 * All #WebKitWebView<!-- -->s associated with this context will also be ephemeral. Websites will
565 * not store any data in the client storage.
566 * This is normally used to implement private instances.
567 *
568 * Returns: (transfer full): a new ephemeral #WebKitWebContext.
569 *
570 * Since: 2.16
571 */
572WebKitWebContext* webkit_web_context_new_ephemeral()
573{
574 GRefPtr<WebKitWebsiteDataManager> manager = adoptGRef(webkit_website_data_manager_new_ephemeral());
575 return WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, "website-data-manager", manager.get(), nullptr));
576}
577
578/**
579 * webkit_web_context_new_with_website_data_manager:
580 * @manager: a #WebKitWebsiteDataManager
581 *
582 * Create a new #WebKitWebContext with a #WebKitWebsiteDataManager.
583 *
584 * Returns: (transfer full): a newly created #WebKitWebContext
585 *
586 * Since: 2.10
587 */
588WebKitWebContext* webkit_web_context_new_with_website_data_manager(WebKitWebsiteDataManager* manager)
589{
590 g_return_val_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager), nullptr);
591
592 return WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, "website-data-manager", manager, nullptr));
593}
594
595/**
596 * webkit_web_context_get_website_data_manager:
597 * @context: the #WebKitWebContext
598 *
599 * Get the #WebKitWebsiteDataManager of @context.
600 *
601 * Returns: (transfer none): a #WebKitWebsiteDataManager
602 *
603 * Since: 2.10
604 */
605WebKitWebsiteDataManager* webkit_web_context_get_website_data_manager(WebKitWebContext* context)
606{
607 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), nullptr);
608
609 return context->priv->websiteDataManager.get();
610}
611
612/**
613 * webkit_web_context_is_ephemeral:
614 * @context: the #WebKitWebContext
615 *
616 * Get whether a #WebKitWebContext is ephemeral.
617 *
618 * Returns: %TRUE if @context is ephemeral or %FALSE otherwise.
619 *
620 * Since: 2.16
621 */
622gboolean webkit_web_context_is_ephemeral(WebKitWebContext* context)
623{
624 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), FALSE);
625
626 return webkit_website_data_manager_is_ephemeral(context->priv->websiteDataManager.get());
627}
628
629/**
630 * webkit_web_context_is_automation_allowed:
631 * @context: the #WebKitWebContext
632 *
633 * Get whether automation is allowed in @context.
634 * See also webkit_web_context_set_automation_allowed().
635 *
636 * Returns: %TRUE if automation is allowed or %FALSE otherwise.
637 *
638 * Since: 2.18
639 */
640gboolean webkit_web_context_is_automation_allowed(WebKitWebContext* context)
641{
642 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), FALSE);
643
644#if ENABLE(REMOTE_INSPECTOR)
645 return !!context->priv->automationClient;
646#else
647 return FALSE;
648#endif
649}
650
651/**
652 * webkit_web_context_set_automation_allowed:
653 * @context: the #WebKitWebContext
654 * @allowed: value to set
655 *
656 * Set whether automation is allowed in @context. When automation is enabled the browser could
657 * be controlled by another process by requesting an automation session. When a new automation
658 * session is requested the signal #WebKitWebContext::automation-started is emitted.
659 * Automation is disabled by default, so you need to explicitly call this method passing %TRUE
660 * to enable it.
661 *
662 * Note that only one #WebKitWebContext can have automation enabled, so this will do nothing
663 * if there's another #WebKitWebContext with automation already enabled.
664 *
665 * Since: 2.18
666 */
667void webkit_web_context_set_automation_allowed(WebKitWebContext* context, gboolean allowed)
668{
669 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
670
671 if (webkit_web_context_is_automation_allowed(context) == allowed)
672 return;
673#if ENABLE(REMOTE_INSPECTOR)
674 if (allowed) {
675 if (Inspector::RemoteInspector::singleton().client()) {
676 g_warning("Not enabling automation on WebKitWebContext because there's another context with automation enabled, only one is allowed");
677 return;
678 }
679 context->priv->automationClient = std::make_unique<WebKitAutomationClient>(context);
680 } else
681 context->priv->automationClient = nullptr;
682#endif
683}
684
685/**
686 * webkit_web_context_set_cache_model:
687 * @context: the #WebKitWebContext
688 * @cache_model: a #WebKitCacheModel
689 *
690 * Specifies a usage model for WebViews, which WebKit will use to
691 * determine its caching behavior. All web views follow the cache
692 * model. This cache model determines the RAM and disk space to use
693 * for caching previously viewed content .
694 *
695 * Research indicates that users tend to browse within clusters of
696 * documents that hold resources in common, and to revisit previously
697 * visited documents. WebKit and the frameworks below it include
698 * built-in caches that take advantage of these patterns,
699 * substantially improving document load speed in browsing
700 * situations. The WebKit cache model controls the behaviors of all of
701 * these caches, including various WebCore caches.
702 *
703 * Browsers can improve document load speed substantially by
704 * specifying %WEBKIT_CACHE_MODEL_WEB_BROWSER. Applications without a
705 * browsing interface can reduce memory usage substantially by
706 * specifying %WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER. The default value is
707 * %WEBKIT_CACHE_MODEL_WEB_BROWSER.
708 */
709void webkit_web_context_set_cache_model(WebKitWebContext* context, WebKitCacheModel model)
710{
711 CacheModel cacheModel;
712
713 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
714
715 switch (model) {
716 case WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER:
717 cacheModel = CacheModel::DocumentViewer;
718 break;
719 case WEBKIT_CACHE_MODEL_WEB_BROWSER:
720 cacheModel = CacheModel::PrimaryWebBrowser;
721 break;
722 case WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER:
723 cacheModel = CacheModel::DocumentBrowser;
724 break;
725 default:
726 g_assert_not_reached();
727 }
728
729 if (cacheModel != context->priv->processPool->cacheModel())
730 context->priv->processPool->setCacheModel(cacheModel);
731}
732
733/**
734 * webkit_web_context_get_cache_model:
735 * @context: the #WebKitWebContext
736 *
737 * Returns the current cache model. For more information about this
738 * value check the documentation of the function
739 * webkit_web_context_set_cache_model().
740 *
741 * Returns: the current #WebKitCacheModel
742 */
743WebKitCacheModel webkit_web_context_get_cache_model(WebKitWebContext* context)
744{
745 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), WEBKIT_CACHE_MODEL_WEB_BROWSER);
746
747 switch (context->priv->processPool->cacheModel()) {
748 case CacheModel::DocumentViewer:
749 return WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER;
750 case CacheModel::PrimaryWebBrowser:
751 return WEBKIT_CACHE_MODEL_WEB_BROWSER;
752 case CacheModel::DocumentBrowser:
753 return WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER;
754 default:
755 g_assert_not_reached();
756 }
757
758 return WEBKIT_CACHE_MODEL_WEB_BROWSER;
759}
760
761/**
762 * webkit_web_context_clear_cache:
763 * @context: a #WebKitWebContext
764 *
765 * Clears all resources currently cached.
766 * See also webkit_web_context_set_cache_model().
767 */
768void webkit_web_context_clear_cache(WebKitWebContext* context)
769{
770 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
771
772 OptionSet<WebsiteDataType> websiteDataTypes;
773 websiteDataTypes.add(WebsiteDataType::MemoryCache);
774 websiteDataTypes.add(WebsiteDataType::DiskCache);
775 auto& websiteDataStore = webkitWebsiteDataManagerGetDataStore(context->priv->websiteDataManager.get()).websiteDataStore();
776 websiteDataStore.removeData(websiteDataTypes, -WallTime::infinity(), [] { });
777}
778
779/**
780 * webkit_web_context_set_network_proxy_settings:
781 * @context: a #WebKitWebContext
782 * @proxy_mode: a #WebKitNetworkProxyMode
783 * @proxy_settings: (allow-none): a #WebKitNetworkProxySettings, or %NULL
784 *
785 * Set the network proxy settings to be used by connections started in @context.
786 * By default %WEBKIT_NETWORK_PROXY_MODE_DEFAULT is used, which means that the
787 * system settings will be used (g_proxy_resolver_get_default()).
788 * If you want to override the system default settings, you can either use
789 * %WEBKIT_NETWORK_PROXY_MODE_NO_PROXY to make sure no proxies are used at all,
790 * or %WEBKIT_NETWORK_PROXY_MODE_CUSTOM to provide your own proxy settings.
791 * When @proxy_mode is %WEBKIT_NETWORK_PROXY_MODE_CUSTOM @proxy_settings must be
792 * a valid #WebKitNetworkProxySettings; otherwise, @proxy_settings must be %NULL.
793 *
794 * Since: 2.16
795 */
796void webkit_web_context_set_network_proxy_settings(WebKitWebContext* context, WebKitNetworkProxyMode proxyMode, WebKitNetworkProxySettings* proxySettings)
797{
798 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
799 g_return_if_fail((proxyMode != WEBKIT_NETWORK_PROXY_MODE_CUSTOM && !proxySettings) || (proxyMode == WEBKIT_NETWORK_PROXY_MODE_CUSTOM && proxySettings));
800
801 WebKitWebContextPrivate* priv = context->priv;
802 switch (proxyMode) {
803 case WEBKIT_NETWORK_PROXY_MODE_DEFAULT:
804 priv->processPool->setNetworkProxySettings({ });
805 break;
806 case WEBKIT_NETWORK_PROXY_MODE_NO_PROXY:
807 priv->processPool->setNetworkProxySettings(WebCore::SoupNetworkProxySettings(WebCore::SoupNetworkProxySettings::Mode::NoProxy));
808 break;
809 case WEBKIT_NETWORK_PROXY_MODE_CUSTOM:
810 const auto& settings = webkitNetworkProxySettingsGetNetworkProxySettings(proxySettings);
811 if (settings.isEmpty()) {
812 g_warning("Invalid attempt to set custom network proxy settings with an empty WebKitNetworkProxySettings. Use "
813 "WEBKIT_NETWORK_PROXY_MODE_NO_PROXY to not use any proxy or WEBKIT_NETWORK_PROXY_MODE_DEFAULT to use the default system settings");
814 } else
815 priv->processPool->setNetworkProxySettings(settings);
816 break;
817 }
818}
819
820typedef HashMap<DownloadProxy*, GRefPtr<WebKitDownload> > DownloadsMap;
821
822static DownloadsMap& downloadsMap()
823{
824 static NeverDestroyed<DownloadsMap> downloads;
825 return downloads;
826}
827
828/**
829 * webkit_web_context_download_uri:
830 * @context: a #WebKitWebContext
831 * @uri: the URI to download
832 *
833 * Requests downloading of the specified URI string. The download operation
834 * will not be associated to any #WebKitWebView, if you are interested in
835 * starting a download from a particular #WebKitWebView use
836 * webkit_web_view_download_uri() instead.
837 *
838 * Returns: (transfer full): a new #WebKitDownload representing
839 * the download operation.
840 */
841WebKitDownload* webkit_web_context_download_uri(WebKitWebContext* context, const gchar* uri)
842{
843 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), nullptr);
844 g_return_val_if_fail(uri, nullptr);
845
846 GRefPtr<WebKitDownload> download = webkitWebContextStartDownload(context, uri, nullptr);
847 return download.leakRef();
848}
849
850/**
851 * webkit_web_context_get_cookie_manager:
852 * @context: a #WebKitWebContext
853 *
854 * Get the #WebKitCookieManager of the @context's #WebKitWebsiteDataManager.
855 *
856 * Returns: (transfer none): the #WebKitCookieManager of @context.
857 */
858WebKitCookieManager* webkit_web_context_get_cookie_manager(WebKitWebContext* context)
859{
860 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), nullptr);
861
862 return webkit_website_data_manager_get_cookie_manager(context->priv->websiteDataManager.get());
863}
864
865/**
866 * webkit_web_context_get_geolocation_manager:
867 * @context: a #WebKitWebContext
868 *
869 * Get the #WebKitGeolocationManager of @context.
870 *
871 * Returns: (transfer none): the #WebKitGeolocationManager of @context.
872 *
873 * Since: 2.26
874 */
875WebKitGeolocationManager* webkit_web_context_get_geolocation_manager(WebKitWebContext* context)
876{
877 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), nullptr);
878
879 return context->priv->geolocationManager.get();
880}
881
882static void ensureFaviconDatabase(WebKitWebContext* context)
883{
884 WebKitWebContextPrivate* priv = context->priv;
885 if (priv->faviconDatabase)
886 return;
887
888 priv->faviconDatabase = adoptGRef(webkitFaviconDatabaseCreate());
889}
890
891static void webkitWebContextEnableIconDatabasePrivateBrowsingIfNeeded(WebKitWebContext* context, WebKitWebView* webView)
892{
893 if (webkit_web_context_is_ephemeral(context))
894 return;
895 if (!webkit_web_view_is_ephemeral(webView))
896 return;
897
898 if (!context->priv->ephemeralPageCount && context->priv->faviconDatabase)
899 webkitFaviconDatabaseSetPrivateBrowsingEnabled(context->priv->faviconDatabase.get(), true);
900 context->priv->ephemeralPageCount++;
901}
902
903static void webkitWebContextDisableIconDatabasePrivateBrowsingIfNeeded(WebKitWebContext* context, WebKitWebView* webView)
904{
905 if (webkit_web_context_is_ephemeral(context))
906 return;
907 if (!webkit_web_view_is_ephemeral(webView))
908 return;
909
910 ASSERT(context->priv->ephemeralPageCount);
911 context->priv->ephemeralPageCount--;
912 if (!context->priv->ephemeralPageCount && context->priv->faviconDatabase)
913 webkitFaviconDatabaseSetPrivateBrowsingEnabled(context->priv->faviconDatabase.get(), false);
914}
915
916/**
917 * webkit_web_context_set_favicon_database_directory:
918 * @context: a #WebKitWebContext
919 * @path: (allow-none): an absolute path to the icon database
920 * directory or %NULL to use the defaults
921 *
922 * Set the directory path to be used to store the favicons database
923 * for @context on disk. Passing %NULL as @path means using the
924 * default directory for the platform (see g_get_user_cache_dir()).
925 *
926 * Calling this method also means enabling the favicons database for
927 * its use from the applications, so that's why it's expected to be
928 * called only once. Further calls for the same instance of
929 * #WebKitWebContext won't cause any effect.
930 */
931void webkit_web_context_set_favicon_database_directory(WebKitWebContext* context, const gchar* path)
932{
933 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
934
935 WebKitWebContextPrivate* priv = context->priv;
936 ensureFaviconDatabase(context);
937
938 String directoryPath = FileSystem::stringFromFileSystemRepresentation(path);
939 // Use default if nullptr is passed as parameter.
940 if (directoryPath.isEmpty()) {
941#if PLATFORM(GTK)
942 const char* portDirectory = "webkitgtk";
943#elif PLATFORM(WPE)
944 const char* portDirectory = "wpe";
945#endif
946 GUniquePtr<gchar> databaseDirectory(g_build_filename(g_get_user_cache_dir(), portDirectory, "icondatabase", nullptr));
947 directoryPath = FileSystem::stringFromFileSystemRepresentation(databaseDirectory.get());
948 }
949 priv->faviconDatabaseDirectory = directoryPath.utf8();
950
951 // Build the full path to the icon database file on disk.
952 GUniquePtr<gchar> faviconDatabasePath(g_build_filename(priv->faviconDatabaseDirectory.data(),
953 "WebpageIcons.db", nullptr));
954
955 // Setting the path will cause the icon database to be opened.
956 webkitFaviconDatabaseOpen(priv->faviconDatabase.get(), FileSystem::stringFromFileSystemRepresentation(faviconDatabasePath.get()));
957
958 if (webkit_web_context_is_ephemeral(context))
959 webkitFaviconDatabaseSetPrivateBrowsingEnabled(priv->faviconDatabase.get(), true);
960}
961
962/**
963 * webkit_web_context_get_favicon_database_directory:
964 * @context: a #WebKitWebContext
965 *
966 * Get the directory path being used to store the favicons database
967 * for @context, or %NULL if
968 * webkit_web_context_set_favicon_database_directory() hasn't been
969 * called yet.
970 *
971 * This function will always return the same path after having called
972 * webkit_web_context_set_favicon_database_directory() for the first
973 * time.
974 *
975 * Returns: (transfer none): the path of the directory of the favicons
976 * database associated with @context, or %NULL.
977 */
978const gchar* webkit_web_context_get_favicon_database_directory(WebKitWebContext *context)
979{
980 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
981
982 WebKitWebContextPrivate* priv = context->priv;
983 if (priv->faviconDatabaseDirectory.isNull())
984 return 0;
985
986 return priv->faviconDatabaseDirectory.data();
987}
988
989/**
990 * webkit_web_context_get_favicon_database:
991 * @context: a #WebKitWebContext
992 *
993 * Get the #WebKitFaviconDatabase associated with @context.
994 *
995 * To initialize the database you need to call
996 * webkit_web_context_set_favicon_database_directory().
997 *
998 * Returns: (transfer none): the #WebKitFaviconDatabase of @context.
999 */
1000WebKitFaviconDatabase* webkit_web_context_get_favicon_database(WebKitWebContext* context)
1001{
1002 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
1003
1004 ensureFaviconDatabase(context);
1005 return context->priv->faviconDatabase.get();
1006}
1007
1008/**
1009 * webkit_web_context_get_security_manager:
1010 * @context: a #WebKitWebContext
1011 *
1012 * Get the #WebKitSecurityManager of @context.
1013 *
1014 * Returns: (transfer none): the #WebKitSecurityManager of @context.
1015 */
1016WebKitSecurityManager* webkit_web_context_get_security_manager(WebKitWebContext* context)
1017{
1018 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
1019
1020 WebKitWebContextPrivate* priv = context->priv;
1021 if (!priv->securityManager)
1022 priv->securityManager = adoptGRef(webkitSecurityManagerCreate(context));
1023
1024 return priv->securityManager.get();
1025}
1026
1027/**
1028 * webkit_web_context_set_additional_plugins_directory:
1029 * @context: a #WebKitWebContext
1030 * @directory: the directory to add
1031 *
1032 * Set an additional directory where WebKit will look for plugins.
1033 */
1034void webkit_web_context_set_additional_plugins_directory(WebKitWebContext* context, const char* directory)
1035{
1036 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1037 g_return_if_fail(directory);
1038
1039#if ENABLE(NETSCAPE_PLUGIN_API)
1040 context->priv->processPool->setAdditionalPluginsDirectory(FileSystem::stringFromFileSystemRepresentation(directory));
1041#endif
1042}
1043
1044static void destroyPluginList(GList* plugins)
1045{
1046 g_list_free_full(plugins, g_object_unref);
1047}
1048
1049static void webkitWebContextGetPluginThread(GTask* task, gpointer object, gpointer /* taskData */, GCancellable*)
1050{
1051 GList* returnValue = 0;
1052#if ENABLE(NETSCAPE_PLUGIN_API)
1053 Vector<PluginModuleInfo> plugins = WEBKIT_WEB_CONTEXT(object)->priv->processPool->pluginInfoStore().plugins();
1054 for (size_t i = 0; i < plugins.size(); ++i)
1055 returnValue = g_list_prepend(returnValue, webkitPluginCreate(plugins[i]));
1056#endif
1057 g_task_return_pointer(task, returnValue, reinterpret_cast<GDestroyNotify>(destroyPluginList));
1058}
1059
1060/**
1061 * webkit_web_context_get_plugins:
1062 * @context: a #WebKitWebContext
1063 * @cancellable: (allow-none): a #GCancellable or %NULL to ignore
1064 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1065 * @user_data: (closure): the data to pass to callback function
1066 *
1067 * Asynchronously get the list of installed plugins.
1068 *
1069 * When the operation is finished, @callback will be called. You can then call
1070 * webkit_web_context_get_plugins_finish() to get the result of the operation.
1071 */
1072void webkit_web_context_get_plugins(WebKitWebContext* context, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData)
1073{
1074 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1075
1076 GRefPtr<GTask> task = adoptGRef(g_task_new(context, cancellable, callback, userData));
1077 g_task_run_in_thread(task.get(), webkitWebContextGetPluginThread);
1078}
1079
1080/**
1081 * webkit_web_context_get_plugins_finish:
1082 * @context: a #WebKitWebContext
1083 * @result: a #GAsyncResult
1084 * @error: return location for error or %NULL to ignore
1085 *
1086 * Finish an asynchronous operation started with webkit_web_context_get_plugins.
1087 *
1088 * Returns: (element-type WebKitPlugin) (transfer full): a #GList of #WebKitPlugin. You must free the #GList with
1089 * g_list_free() and unref the #WebKitPlugin<!-- -->s with g_object_unref() when you're done with them.
1090 */
1091GList* webkit_web_context_get_plugins_finish(WebKitWebContext* context, GAsyncResult* result, GError** error)
1092{
1093 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
1094 g_return_val_if_fail(g_task_is_valid(result, context), 0);
1095
1096 return static_cast<GList*>(g_task_propagate_pointer(G_TASK(result), error));
1097}
1098
1099/**
1100 * webkit_web_context_register_uri_scheme:
1101 * @context: a #WebKitWebContext
1102 * @scheme: the network scheme to register
1103 * @callback: (scope async): a #WebKitURISchemeRequestCallback
1104 * @user_data: data to pass to callback function
1105 * @user_data_destroy_func: destroy notify for @user_data
1106 *
1107 * Register @scheme in @context, so that when an URI request with @scheme is made in the
1108 * #WebKitWebContext, the #WebKitURISchemeRequestCallback registered will be called with a
1109 * #WebKitURISchemeRequest.
1110 * It is possible to handle URI scheme requests asynchronously, by calling g_object_ref() on the
1111 * #WebKitURISchemeRequest and calling webkit_uri_scheme_request_finish() later
1112 * when the data of the request is available or
1113 * webkit_uri_scheme_request_finish_error() in case of error.
1114 *
1115 * <informalexample><programlisting>
1116 * static void
1117 * about_uri_scheme_request_cb (WebKitURISchemeRequest *request,
1118 * gpointer user_data)
1119 * {
1120 * GInputStream *stream;
1121 * gsize stream_length;
1122 * const gchar *path;
1123 *
1124 * path = webkit_uri_scheme_request_get_path (request);
1125 * if (!g_strcmp0 (path, "plugins")) {
1126 * /<!-- -->* Create a GInputStream with the contents of plugins about page, and set its length to stream_length *<!-- -->/
1127 * } else if (!g_strcmp0 (path, "memory")) {
1128 * /<!-- -->* Create a GInputStream with the contents of memory about page, and set its length to stream_length *<!-- -->/
1129 * } else if (!g_strcmp0 (path, "applications")) {
1130 * /<!-- -->* Create a GInputStream with the contents of applications about page, and set its length to stream_length *<!-- -->/
1131 * } else if (!g_strcmp0 (path, "example")) {
1132 * gchar *contents;
1133 *
1134 * contents = g_strdup_printf ("&lt;html&gt;&lt;body&gt;&lt;p&gt;Example about page&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;");
1135 * stream_length = strlen (contents);
1136 * stream = g_memory_input_stream_new_from_data (contents, stream_length, g_free);
1137 * } else {
1138 * GError *error;
1139 *
1140 * error = g_error_new (ABOUT_HANDLER_ERROR, ABOUT_HANDLER_ERROR_INVALID, "Invalid about:%s page.", path);
1141 * webkit_uri_scheme_request_finish_error (request, error);
1142 * g_error_free (error);
1143 * return;
1144 * }
1145 * webkit_uri_scheme_request_finish (request, stream, stream_length, "text/html");
1146 * g_object_unref (stream);
1147 * }
1148 * </programlisting></informalexample>
1149 */
1150void webkit_web_context_register_uri_scheme(WebKitWebContext* context, const char* scheme, WebKitURISchemeRequestCallback callback, gpointer userData, GDestroyNotify destroyNotify)
1151{
1152 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1153 g_return_if_fail(scheme);
1154 g_return_if_fail(callback);
1155
1156 RefPtr<WebKitURISchemeHandler> handler = adoptRef(new WebKitURISchemeHandler(callback, userData, destroyNotify));
1157 auto addResult = context->priv->uriSchemeHandlers.set(String::fromUTF8(scheme), handler.get());
1158 if (addResult.isNewEntry)
1159 context->priv->processPool->registerSchemeForCustomProtocol(String::fromUTF8(scheme));
1160}
1161
1162/**
1163 * webkit_web_context_set_sandbox_enabled:
1164 * @context: a #WebKitWebContext
1165 * @enabled: if %TRUE enable sandboxing
1166 *
1167 * Set whether WebKit subprocesses will be sandboxed, limiting access to the system.
1168 *
1169 * This method **must be called before any web process has been created**,
1170 * as early as possible in your application. Calling it later is a fatal error.
1171 *
1172 * This is only implemented on Linux and is a no-op otherwise.
1173 *
1174 * Since: 2.26
1175 */
1176void webkit_web_context_set_sandbox_enabled(WebKitWebContext* context, gboolean enabled)
1177{
1178 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1179
1180 if (context->priv->processPool->processes().size())
1181 g_error("Sandboxing cannot be changed after subprocesses were spawned.");
1182
1183 context->priv->processPool->setSandboxEnabled(enabled);
1184}
1185
1186/**
1187 * webkit_web_context_add_path_to_sandbox:
1188 * @context: a #WebKitWebContext
1189 * @path: (type filename): an absolute path to mount in the sandbox
1190 * @read_only: if %TRUE the path will be read-only
1191 *
1192 * Adds a path to be mounted in the sandbox. @path must exist before any web process
1193 * has been created otherwise it will be silently ignored. It is a fatal error to
1194 * add paths after a web process has been spawned.
1195 *
1196 * See also webkit_web_context_set_sandbox_enabled()
1197 *
1198 * Since: 2.26
1199 */
1200void webkit_web_context_add_path_to_sandbox(WebKitWebContext* context, const char* path, gboolean readOnly)
1201{
1202 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1203 g_return_if_fail(g_path_is_absolute(path));
1204
1205 if (context->priv->processPool->processes().size())
1206 g_error("Sandbox paths cannot be changed after subprocesses were spawned.");
1207
1208 auto permission = readOnly ? SandboxPermission::ReadOnly : SandboxPermission::ReadWrite;
1209 context->priv->processPool->addSandboxPath(path, permission);
1210}
1211
1212/**
1213 * webkit_web_context_get_sandbox_enabled:
1214 * @context: a #WebKitWebContext
1215 *
1216 * Get whether sandboxing is currently enabled.
1217 *
1218 * Returns: %TRUE if sandboxing is enabled, or %FALSE otherwise.
1219 *
1220 * Since: 2.26
1221 */
1222gboolean webkit_web_context_get_sandbox_enabled(WebKitWebContext* context)
1223{
1224 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), FALSE);
1225
1226 return context->priv->processPool->sandboxEnabled();
1227}
1228
1229/**
1230 * webkit_web_context_get_spell_checking_enabled:
1231 * @context: a #WebKitWebContext
1232 *
1233 * Get whether spell checking feature is currently enabled.
1234 *
1235 * Returns: %TRUE If spell checking is enabled, or %FALSE otherwise.
1236 */
1237gboolean webkit_web_context_get_spell_checking_enabled(WebKitWebContext* context)
1238{
1239 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), FALSE);
1240
1241#if ENABLE(SPELLCHECK)
1242 return TextChecker::state().isContinuousSpellCheckingEnabled;
1243#else
1244 return false;
1245#endif
1246}
1247
1248/**
1249 * webkit_web_context_set_spell_checking_enabled:
1250 * @context: a #WebKitWebContext
1251 * @enabled: Value to be set
1252 *
1253 * Enable or disable the spell checking feature.
1254 */
1255void webkit_web_context_set_spell_checking_enabled(WebKitWebContext* context, gboolean enabled)
1256{
1257 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1258
1259#if ENABLE(SPELLCHECK)
1260 TextChecker::setContinuousSpellCheckingEnabled(enabled);
1261#endif
1262}
1263
1264/**
1265 * webkit_web_context_get_spell_checking_languages:
1266 * @context: a #WebKitWebContext
1267 *
1268 * Get the the list of spell checking languages associated with
1269 * @context, or %NULL if no languages have been previously set.
1270 *
1271 * See webkit_web_context_set_spell_checking_languages() for more
1272 * details on the format of the languages in the list.
1273 *
1274 * Returns: (array zero-terminated=1) (element-type utf8) (transfer none): A %NULL-terminated
1275 * array of languages if available, or %NULL otherwise.
1276 */
1277const gchar* const* webkit_web_context_get_spell_checking_languages(WebKitWebContext* context)
1278{
1279 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), nullptr);
1280
1281#if ENABLE(SPELLCHECK)
1282 Vector<String> spellCheckingLanguages = TextChecker::loadedSpellCheckingLanguages();
1283 if (spellCheckingLanguages.isEmpty())
1284 return nullptr;
1285
1286 static GRefPtr<GPtrArray> languagesToReturn;
1287 languagesToReturn = adoptGRef(g_ptr_array_new_with_free_func(g_free));
1288 for (const auto& language : spellCheckingLanguages)
1289 g_ptr_array_add(languagesToReturn.get(), g_strdup(language.utf8().data()));
1290 g_ptr_array_add(languagesToReturn.get(), nullptr);
1291
1292 return reinterpret_cast<char**>(languagesToReturn->pdata);
1293#else
1294 return 0;
1295#endif
1296}
1297
1298/**
1299 * webkit_web_context_set_spell_checking_languages:
1300 * @context: a #WebKitWebContext
1301 * @languages: (array zero-terminated=1) (transfer none): a %NULL-terminated list of spell checking languages
1302 *
1303 * Set the list of spell checking languages to be used for spell
1304 * checking.
1305 *
1306 * The locale string typically is in the form lang_COUNTRY, where lang
1307 * is an ISO-639 language code, and COUNTRY is an ISO-3166 country code.
1308 * For instance, sv_FI for Swedish as written in Finland or pt_BR
1309 * for Portuguese as written in Brazil.
1310 *
1311 * You need to call this function with a valid list of languages at
1312 * least once in order to properly enable the spell checking feature
1313 * in WebKit.
1314 */
1315void webkit_web_context_set_spell_checking_languages(WebKitWebContext* context, const gchar* const* languages)
1316{
1317 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1318 g_return_if_fail(languages);
1319
1320#if ENABLE(SPELLCHECK)
1321 Vector<String> spellCheckingLanguages;
1322 for (size_t i = 0; languages[i]; ++i)
1323 spellCheckingLanguages.append(String::fromUTF8(languages[i]));
1324 TextChecker::setSpellCheckingLanguages(spellCheckingLanguages);
1325#endif
1326}
1327
1328/**
1329 * webkit_web_context_set_preferred_languages:
1330 * @context: a #WebKitWebContext
1331 * @languages: (allow-none) (array zero-terminated=1) (element-type utf8) (transfer none): a %NULL-terminated list of language identifiers
1332 *
1333 * Set the list of preferred languages, sorted from most desirable
1334 * to least desirable. The list will be used to build the "Accept-Language"
1335 * header that will be included in the network requests started by
1336 * the #WebKitWebContext.
1337 */
1338void webkit_web_context_set_preferred_languages(WebKitWebContext* context, const gchar* const* languageList)
1339{
1340 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1341
1342 if (!languageList || !g_strv_length(const_cast<char**>(languageList)))
1343 return;
1344
1345 Vector<String> languages;
1346 for (size_t i = 0; languageList[i]; ++i) {
1347 // Do not propagate the C locale to WebCore.
1348 if (!g_ascii_strcasecmp(languageList[i], "C") || !g_ascii_strcasecmp(languageList[i], "POSIX"))
1349 languages.append("en-US"_s);
1350 else
1351 languages.append(String::fromUTF8(languageList[i]).replace("_", "-"));
1352 }
1353 overrideUserPreferredLanguages(languages);
1354}
1355
1356/**
1357 * webkit_web_context_set_tls_errors_policy:
1358 * @context: a #WebKitWebContext
1359 * @policy: a #WebKitTLSErrorsPolicy
1360 *
1361 * Set the TLS errors policy of @context as @policy
1362 */
1363void webkit_web_context_set_tls_errors_policy(WebKitWebContext* context, WebKitTLSErrorsPolicy policy)
1364{
1365 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1366
1367 if (context->priv->tlsErrorsPolicy == policy)
1368 return;
1369
1370 context->priv->tlsErrorsPolicy = policy;
1371 bool ignoreTLSErrors = policy == WEBKIT_TLS_ERRORS_POLICY_IGNORE;
1372 if (context->priv->processPool->ignoreTLSErrors() != ignoreTLSErrors)
1373 context->priv->processPool->setIgnoreTLSErrors(ignoreTLSErrors);
1374}
1375
1376/**
1377 * webkit_web_context_get_tls_errors_policy:
1378 * @context: a #WebKitWebContext
1379 *
1380 * Get the TLS errors policy of @context
1381 *
1382 * Returns: a #WebKitTLSErrorsPolicy
1383 */
1384WebKitTLSErrorsPolicy webkit_web_context_get_tls_errors_policy(WebKitWebContext* context)
1385{
1386 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), WEBKIT_TLS_ERRORS_POLICY_IGNORE);
1387
1388 return context->priv->tlsErrorsPolicy;
1389}
1390
1391/**
1392 * webkit_web_context_set_web_extensions_directory:
1393 * @context: a #WebKitWebContext
1394 * @directory: the directory to add
1395 *
1396 * Set the directory where WebKit will look for Web Extensions.
1397 * This method must be called before loading anything in this context,
1398 * otherwise it will not have any effect. You can connect to
1399 * #WebKitWebContext::initialize-web-extensions to call this method
1400 * before anything is loaded.
1401 */
1402void webkit_web_context_set_web_extensions_directory(WebKitWebContext* context, const char* directory)
1403{
1404 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1405 g_return_if_fail(directory);
1406
1407 context->priv->webExtensionsDirectory = directory;
1408}
1409
1410/**
1411 * webkit_web_context_set_web_extensions_initialization_user_data:
1412 * @context: a #WebKitWebContext
1413 * @user_data: a #GVariant
1414 *
1415 * Set user data to be passed to Web Extensions on initialization.
1416 * The data will be passed to the
1417 * #WebKitWebExtensionInitializeWithUserDataFunction.
1418 * This method must be called before loading anything in this context,
1419 * otherwise it will not have any effect. You can connect to
1420 * #WebKitWebContext::initialize-web-extensions to call this method
1421 * before anything is loaded.
1422 *
1423 * Since: 2.4
1424 */
1425void webkit_web_context_set_web_extensions_initialization_user_data(WebKitWebContext* context, GVariant* userData)
1426{
1427 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1428 g_return_if_fail(userData);
1429
1430 context->priv->webExtensionsInitializationUserData = userData;
1431}
1432
1433#if PLATFORM(GTK)
1434/**
1435 * webkit_web_context_set_disk_cache_directory:
1436 * @context: a #WebKitWebContext
1437 * @directory: the directory to set
1438 *
1439 * Set the directory where disk cache files will be stored
1440 * This method must be called before loading anything in this context, otherwise
1441 * it will not have any effect.
1442 *
1443 * Note that this method overrides the directory set in the #WebKitWebsiteDataManager,
1444 * but it doesn't change the value returned by webkit_website_data_manager_get_disk_cache_directory()
1445 * since the #WebKitWebsiteDataManager is immutable.
1446 *
1447 * Deprecated: 2.10. Use webkit_web_context_new_with_website_data_manager() instead.
1448 */
1449void webkit_web_context_set_disk_cache_directory(WebKitWebContext* context, const char* directory)
1450{
1451 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1452 g_return_if_fail(directory);
1453
1454 context->priv->processPool->configuration().setDiskCacheDirectory(FileSystem::pathByAppendingComponent(FileSystem::stringFromFileSystemRepresentation(directory), networkCacheSubdirectory));
1455}
1456#endif
1457
1458/**
1459 * webkit_web_context_prefetch_dns:
1460 * @context: a #WebKitWebContext
1461 * @hostname: a hostname to be resolved
1462 *
1463 * Resolve the domain name of the given @hostname in advance, so that if a URI
1464 * of @hostname is requested the load will be performed more quickly.
1465 */
1466void webkit_web_context_prefetch_dns(WebKitWebContext* context, const char* hostname)
1467{
1468 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1469 g_return_if_fail(hostname);
1470
1471 API::Dictionary::MapType message;
1472 message.set(String::fromUTF8("Hostname"), API::String::create(String::fromUTF8(hostname)));
1473 context->priv->processPool->postMessageToInjectedBundle(String::fromUTF8("PrefetchDNS"), API::Dictionary::create(WTFMove(message)).ptr());
1474}
1475
1476/**
1477 * webkit_web_context_allow_tls_certificate_for_host:
1478 * @context: a #WebKitWebContext
1479 * @certificate: a #GTlsCertificate
1480 * @host: the host for which a certificate is to be allowed
1481 *
1482 * Ignore further TLS errors on the @host for the certificate present in @info.
1483 *
1484 * Since: 2.6
1485 */
1486void webkit_web_context_allow_tls_certificate_for_host(WebKitWebContext* context, GTlsCertificate* certificate, const gchar* host)
1487{
1488 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1489 g_return_if_fail(G_IS_TLS_CERTIFICATE(certificate));
1490 g_return_if_fail(host);
1491
1492 auto webCertificateInfo = WebCertificateInfo::create(WebCore::CertificateInfo(certificate, static_cast<GTlsCertificateFlags>(0)));
1493 context->priv->processPool->allowSpecificHTTPSCertificateForHost(webCertificateInfo.ptr(), String::fromUTF8(host));
1494}
1495
1496/**
1497 * webkit_web_context_set_process_model:
1498 * @context: the #WebKitWebContext
1499 * @process_model: a #WebKitProcessModel
1500 *
1501 * Specifies a process model for WebViews, which WebKit will use to
1502 * determine how auxiliary processes are handled. The default setting
1503 * (%WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS) is suitable for most
1504 * applications which embed a small amount of WebViews, or are used to
1505 * display documents which are considered safe — like local files.
1506 *
1507 * Applications which may potentially use a large amount of WebViews
1508 * —for example a multi-tabbed web browser— may want to use
1509 * %WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES, which will use
1510 * one process per view most of the time, while still allowing for web
1511 * views to share a process when needed (for example when different
1512 * views interact with each other). Using this model, when a process
1513 * hangs or crashes, only the WebViews using it stop working, while
1514 * the rest of the WebViews in the application will still function
1515 * normally.
1516 *
1517 * This method **must be called before any web process has been created**,
1518 * as early as possible in your application. Calling it later will make
1519 * your application crash.
1520 *
1521 * Since: 2.4
1522 */
1523void webkit_web_context_set_process_model(WebKitWebContext* context, WebKitProcessModel processModel)
1524{
1525 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1526
1527 if (processModel == context->priv->processModel)
1528 return;
1529
1530 context->priv->processModel = processModel;
1531}
1532
1533/**
1534 * webkit_web_context_get_process_model:
1535 * @context: the #WebKitWebContext
1536 *
1537 * Returns the current process model. For more information about this value
1538 * see webkit_web_context_set_process_model().
1539 *
1540 * Returns: the current #WebKitProcessModel
1541 *
1542 * Since: 2.4
1543 */
1544WebKitProcessModel webkit_web_context_get_process_model(WebKitWebContext* context)
1545{
1546 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS);
1547
1548 return context->priv->processModel;
1549}
1550
1551/**
1552 * webkit_web_context_set_web_process_count_limit:
1553 * @context: the #WebKitWebContext
1554 * @limit: the maximum number of web processes
1555 *
1556 * Sets the maximum number of web processes that can be created at the same time for the @context.
1557 * The default value is 0 and means no limit.
1558 *
1559 * This method **must be called before any web process has been created**,
1560 * as early as possible in your application. Calling it later will make
1561 * your application crash.
1562 *
1563 * Since: 2.10
1564 */
1565void webkit_web_context_set_web_process_count_limit(WebKitWebContext* context, guint limit)
1566{
1567 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
1568
1569 if (context->priv->processCountLimit == limit)
1570 return;
1571
1572 context->priv->processCountLimit = limit;
1573}
1574
1575/**
1576 * webkit_web_context_get_web_process_count_limit:
1577 * @context: the #WebKitWebContext
1578 *
1579 * Gets the maximum number of web processes that can be created at the same time for the @context.
1580 *
1581 * Returns: the maximum limit of web processes, or 0 if there isn't a limit.
1582 *
1583 * Since: 2.10
1584 */
1585guint webkit_web_context_get_web_process_count_limit(WebKitWebContext* context)
1586{
1587 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
1588
1589 return context->priv->processCountLimit;
1590}
1591
1592static void addOriginToMap(WebKitSecurityOrigin* origin, HashMap<String, bool>* map, bool allowed)
1593{
1594 String string = webkitSecurityOriginGetSecurityOrigin(origin).toString();
1595 if (string != "null")
1596 map->set(string, allowed);
1597}
1598
1599/**
1600 * webkit_web_context_initialize_notification_permissions:
1601 * @context: the #WebKitWebContext
1602 * @allowed_origins: (element-type WebKitSecurityOrigin): a #GList of security origins
1603 * @disallowed_origins: (element-type WebKitSecurityOrigin): a #GList of security origins
1604 *
1605 * Sets initial desktop notification permissions for the @context.
1606 * @allowed_origins and @disallowed_origins must each be #GList of
1607 * #WebKitSecurityOrigin objects representing origins that will,
1608 * respectively, either always or never have permission to show desktop
1609 * notifications. No #WebKitNotificationPermissionRequest will ever be
1610 * generated for any of the security origins represented in
1611 * @allowed_origins or @disallowed_origins. This function is necessary
1612 * because some webpages proactively check whether they have permission
1613 * to display notifications without ever creating a permission request.
1614 *
1615 * This function only affects web processes that have not already been
1616 * created. The best time to call it is when handling
1617 * #WebKitWebContext::initialize-notification-permissions so as to
1618 * ensure that new web processes receive the most recent set of
1619 * permissions.
1620 *
1621 * Since: 2.16
1622 */
1623void webkit_web_context_initialize_notification_permissions(WebKitWebContext* context, GList* allowedOrigins, GList* disallowedOrigins)
1624{
1625 HashMap<String, bool> map;
1626 g_list_foreach(allowedOrigins, [](gpointer data, gpointer userData) {
1627 addOriginToMap(static_cast<WebKitSecurityOrigin*>(data), static_cast<HashMap<String, bool>*>(userData), true);
1628 }, &map);
1629 g_list_foreach(disallowedOrigins, [](gpointer data, gpointer userData) {
1630 addOriginToMap(static_cast<WebKitSecurityOrigin*>(data), static_cast<HashMap<String, bool>*>(userData), false);
1631 }, &map);
1632 context->priv->notificationProvider->setNotificationPermissions(WTFMove(map));
1633}
1634
1635void webkitWebContextInitializeNotificationPermissions(WebKitWebContext* context)
1636{
1637 g_signal_emit(context, signals[INITIALIZE_NOTIFICATION_PERMISSIONS], 0);
1638}
1639
1640WebKitDownload* webkitWebContextGetOrCreateDownload(DownloadProxy* downloadProxy)
1641{
1642 GRefPtr<WebKitDownload> download = downloadsMap().get(downloadProxy);
1643 if (download)
1644 return download.get();
1645
1646 download = adoptGRef(webkitDownloadCreate(downloadProxy));
1647 downloadsMap().set(downloadProxy, download.get());
1648 return download.get();
1649}
1650
1651WebKitDownload* webkitWebContextStartDownload(WebKitWebContext* context, const char* uri, WebPageProxy* initiatingPage)
1652{
1653 WebCore::ResourceRequest request(String::fromUTF8(uri));
1654 return webkitWebContextGetOrCreateDownload(&context->priv->processPool->download(initiatingPage, request));
1655}
1656
1657void webkitWebContextRemoveDownload(DownloadProxy* downloadProxy)
1658{
1659 downloadsMap().remove(downloadProxy);
1660}
1661
1662void webkitWebContextDownloadStarted(WebKitWebContext* context, WebKitDownload* download)
1663{
1664 g_signal_emit(context, signals[DOWNLOAD_STARTED], 0, download);
1665}
1666
1667GVariant* webkitWebContextInitializeWebExtensions(WebKitWebContext* context)
1668{
1669 g_signal_emit(context, signals[INITIALIZE_WEB_EXTENSIONS], 0);
1670 return g_variant_new("(msmv)",
1671 context->priv->webExtensionsDirectory.data(),
1672 context->priv->webExtensionsInitializationUserData.get());
1673}
1674
1675WebProcessPool& webkitWebContextGetProcessPool(WebKitWebContext* context)
1676{
1677 g_assert(WEBKIT_IS_WEB_CONTEXT(context));
1678
1679 return *context->priv->processPool;
1680}
1681
1682void webkitWebContextStartLoadingCustomProtocol(WebKitWebContext* context, uint64_t customProtocolID, const WebCore::ResourceRequest& resourceRequest, LegacyCustomProtocolManagerProxy& manager)
1683{
1684 GRefPtr<WebKitURISchemeRequest> request = adoptGRef(webkitURISchemeRequestCreate(customProtocolID, context, resourceRequest, manager));
1685 String scheme(String::fromUTF8(webkit_uri_scheme_request_get_scheme(request.get())));
1686 RefPtr<WebKitURISchemeHandler> handler = context->priv->uriSchemeHandlers.get(scheme);
1687 ASSERT(handler.get());
1688 if (!handler->hasCallback())
1689 return;
1690
1691 context->priv->uriSchemeRequests.set(customProtocolID, request.get());
1692 handler->performCallback(request.get());
1693}
1694
1695void webkitWebContextStopLoadingCustomProtocol(WebKitWebContext* context, uint64_t customProtocolID)
1696{
1697 GRefPtr<WebKitURISchemeRequest> request = context->priv->uriSchemeRequests.get(customProtocolID);
1698 if (!request.get())
1699 return;
1700 webkitURISchemeRequestCancel(request.get());
1701}
1702
1703void webkitWebContextInvalidateCustomProtocolRequests(WebKitWebContext* context, LegacyCustomProtocolManagerProxy& manager)
1704{
1705 for (auto& request : copyToVector(context->priv->uriSchemeRequests.values())) {
1706 if (webkitURISchemeRequestGetManager(request.get()) == &manager)
1707 webkitURISchemeRequestInvalidate(request.get());
1708 }
1709}
1710
1711void webkitWebContextDidFinishLoadingCustomProtocol(WebKitWebContext* context, uint64_t customProtocolID)
1712{
1713 context->priv->uriSchemeRequests.remove(customProtocolID);
1714}
1715
1716bool webkitWebContextIsLoadingCustomProtocol(WebKitWebContext* context, uint64_t customProtocolID)
1717{
1718 return context->priv->uriSchemeRequests.get(customProtocolID);
1719}
1720
1721void webkitWebContextCreatePageForWebView(WebKitWebContext* context, WebKitWebView* webView, WebKitUserContentManager* userContentManager, WebKitWebView* relatedView)
1722{
1723 // FIXME: icon database private mode is global, not per page, so while there are
1724 // pages in private mode we need to enable the private mode in the icon database.
1725 webkitWebContextEnableIconDatabasePrivateBrowsingIfNeeded(context, webView);
1726
1727 auto pageConfiguration = API::PageConfiguration::create();
1728 pageConfiguration->setProcessPool(context->priv->processPool.get());
1729 pageConfiguration->setPreferences(webkitSettingsGetPreferences(webkit_web_view_get_settings(webView)));
1730 pageConfiguration->setRelatedPage(relatedView ? &webkitWebViewGetPage(relatedView) : nullptr);
1731 pageConfiguration->setUserContentController(userContentManager ? webkitUserContentManagerGetUserContentControllerProxy(userContentManager) : nullptr);
1732 pageConfiguration->setControlledByAutomation(webkit_web_view_is_controlled_by_automation(webView));
1733
1734 WebKitWebsiteDataManager* manager = webkitWebViewGetWebsiteDataManager(webView);
1735 if (!manager)
1736 manager = context->priv->websiteDataManager.get();
1737 pageConfiguration->setWebsiteDataStore(&webkitWebsiteDataManagerGetDataStore(manager));
1738 pageConfiguration->setSessionID(pageConfiguration->websiteDataStore()->websiteDataStore().sessionID());
1739 webkitWebViewCreatePage(webView, WTFMove(pageConfiguration));
1740
1741 context->priv->webViews.set(webkit_web_view_get_page_id(webView), webView);
1742}
1743
1744void webkitWebContextWebViewDestroyed(WebKitWebContext* context, WebKitWebView* webView)
1745{
1746 webkitWebContextDisableIconDatabasePrivateBrowsingIfNeeded(context, webView);
1747 context->priv->webViews.remove(webkit_web_view_get_page_id(webView));
1748}
1749
1750WebKitWebView* webkitWebContextGetWebViewForPage(WebKitWebContext* context, WebPageProxy* page)
1751{
1752 return page ? context->priv->webViews.get(page->pageID()) : 0;
1753}
1754