2 * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "InjectedBundle.h"
31 #include "InjectedBundleScriptWorld.h"
32 #include "NetworkSessionCreationParameters.h"
33 #include "NotificationPermissionRequestManager.h"
34 #include "SessionTracker.h"
36 #include "WebConnectionToUIProcess.h"
37 #include "WebCookieManager.h"
38 #include "WebCoreArgumentCoders.h"
40 #include "WebFrameNetworkingContext.h"
42 #include "WebPageGroupProxy.h"
43 #include "WebPreferencesKeys.h"
44 #include "WebPreferencesStore.h"
45 #include "WebProcess.h"
46 #include "WebProcessCreationParameters.h"
47 #include "WebProcessMessages.h"
48 #include "WebProcessPoolMessages.h"
49 #include "WebUserContentController.h"
50 #include "WebsiteDataStoreParameters.h"
51 #include <JavaScriptCore/APICast.h>
52 #include <JavaScriptCore/Exception.h>
53 #include <JavaScriptCore/JSLock.h>
54 #include <WebCore/ApplicationCache.h>
55 #include <WebCore/ApplicationCacheStorage.h>
56 #include <WebCore/CommonVM.h>
57 #include <WebCore/FrameLoader.h>
58 #include <WebCore/FrameView.h>
59 #include <WebCore/GCController.h>
60 #include <WebCore/GeolocationClient.h>
61 #include <WebCore/GeolocationController.h>
62 #include <WebCore/GeolocationPosition.h>
63 #include <WebCore/JSDOMConvertBufferSource.h>
64 #include <WebCore/JSDOMExceptionHandling.h>
65 #include <WebCore/JSDOMWindow.h>
66 #include <WebCore/JSNotification.h>
67 #include <WebCore/MainFrame.h>
68 #include <WebCore/Page.h>
69 #include <WebCore/PageGroup.h>
70 #include <WebCore/PrintContext.h>
71 #include <WebCore/ResourceHandle.h>
72 #include <WebCore/RuntimeEnabledFeatures.h>
73 #include <WebCore/ScriptController.h>
74 #include <WebCore/SecurityOrigin.h>
75 #include <WebCore/SecurityPolicy.h>
76 #include <WebCore/Settings.h>
77 #include <WebCore/UserGestureIndicator.h>
78 #include <WebCore/UserScript.h>
79 #include <WebCore/UserStyleSheet.h>
80 #include <pal/SessionID.h>
82 #if ENABLE(NOTIFICATIONS)
83 #include "WebNotificationManager.h"
86 using namespace WebCore;
91 RefPtr<InjectedBundle> InjectedBundle::create(WebProcessCreationParameters& parameters, API::Object* initializationUserData)
93 auto bundle = adoptRef(*new InjectedBundle(parameters));
95 bundle->m_sandboxExtension = SandboxExtension::create(WTFMove(parameters.injectedBundlePathExtensionHandle));
96 if (!bundle->initialize(parameters, initializationUserData))
99 return WTFMove(bundle);
102 InjectedBundle::InjectedBundle(const WebProcessCreationParameters& parameters)
103 : m_path(parameters.injectedBundlePath)
104 , m_platformBundle(0)
105 , m_client(std::make_unique<API::InjectedBundle::Client>())
109 InjectedBundle::~InjectedBundle()
113 void InjectedBundle::setClient(std::unique_ptr<API::InjectedBundle::Client>&& client)
116 m_client = std::make_unique<API::InjectedBundle::Client>();
118 m_client = WTFMove(client);
121 void InjectedBundle::postMessage(const String& messageName, API::Object* messageBody)
123 auto& webProcess = WebProcess::singleton();
124 webProcess.parentProcessConnection()->send(Messages::WebProcessPool::HandleMessage(messageName, UserData(webProcess.transformObjectsToHandles(messageBody))), 0);
127 void InjectedBundle::postSynchronousMessage(const String& messageName, API::Object* messageBody, RefPtr<API::Object>& returnData)
129 UserData returnUserData;
131 auto& webProcess = WebProcess::singleton();
132 if (!webProcess.parentProcessConnection()->sendSync(Messages::WebProcessPool::HandleSynchronousMessage(messageName, UserData(webProcess.transformObjectsToHandles(messageBody))), Messages::WebProcessPool::HandleSynchronousMessage::Reply(returnUserData), 0))
133 returnData = nullptr;
135 returnData = webProcess.transformHandlesToObjects(returnUserData.object());
138 WebConnection* InjectedBundle::webConnectionToUIProcess() const
140 return WebProcess::singleton().webConnectionToUIProcess();
143 void InjectedBundle::overrideBoolPreferenceForTestRunner(WebPageGroupProxy* pageGroup, const String& preference, bool enabled)
145 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
147 if (preference == "WebKitTabToLinksPreferenceKey") {
148 WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::tabsToLinksKey(), enabled);
149 for (auto* page : pages)
150 WebPage::fromCorePage(page)->setTabToLinksEnabled(enabled);
153 if (preference == "WebKit2AsynchronousPluginInitializationEnabled") {
154 WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::asynchronousPluginInitializationEnabledKey(), enabled);
155 for (auto* page : pages)
156 WebPage::fromCorePage(page)->setAsynchronousPluginInitializationEnabled(enabled);
159 if (preference == "WebKit2AsynchronousPluginInitializationEnabledForAllPlugins") {
160 WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::asynchronousPluginInitializationEnabledForAllPluginsKey(), enabled);
161 for (auto* page : pages)
162 WebPage::fromCorePage(page)->setAsynchronousPluginInitializationEnabledForAllPlugins(enabled);
165 if (preference == "WebKit2ArtificialPluginInitializationDelayEnabled") {
166 WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::artificialPluginInitializationDelayEnabledKey(), enabled);
167 for (auto* page : pages)
168 WebPage::fromCorePage(page)->setArtificialPluginInitializationDelayEnabled(enabled);
171 #if ENABLE(SERVICE_CONTROLS)
172 if (preference == "WebKitImageControlsEnabled") {
173 WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::imageControlsEnabledKey(), enabled);
174 for (auto* page : pages)
175 page->settings().setImageControlsEnabled(enabled);
180 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
181 if (preference == "WebKitCSSAnimationTriggersEnabled")
182 RuntimeEnabledFeatures::sharedFeatures().setAnimationTriggersEnabled(enabled);
185 if (preference == "WebKitWebAnimationsEnabled")
186 RuntimeEnabledFeatures::sharedFeatures().setWebAnimationsEnabled(enabled);
188 if (preference == "WebKitCacheAPIEnabled")
189 RuntimeEnabledFeatures::sharedFeatures().setCacheAPIEnabled(enabled);
191 #if ENABLE(STREAMS_API)
192 if (preference == "WebKitReadableByteStreamAPIEnabled")
193 RuntimeEnabledFeatures::sharedFeatures().setReadableByteStreamAPIEnabled(enabled);
194 if (preference == "WebKitWritableStreamAPIEnabled")
195 RuntimeEnabledFeatures::sharedFeatures().setWritableStreamAPIEnabled(enabled);
198 if (preference == "WebKitCSSGridLayoutEnabled")
199 RuntimeEnabledFeatures::sharedFeatures().setCSSGridLayoutEnabled(enabled);
201 if (preference == "WebKitInteractiveFormValidationEnabled")
202 RuntimeEnabledFeatures::sharedFeatures().setInteractiveFormValidationEnabled(enabled);
205 if (preference == "WebKitWebGL2Enabled")
206 RuntimeEnabledFeatures::sharedFeatures().setWebGL2Enabled(enabled);
210 if (preference == "WebKitWebGPUEnabled")
211 RuntimeEnabledFeatures::sharedFeatures().setWebGPUEnabled(enabled);
214 if (preference == "WebKitModernMediaControlsEnabled")
215 RuntimeEnabledFeatures::sharedFeatures().setModernMediaControlsEnabled(enabled);
217 #if ENABLE(ENCRYPTED_MEDIA)
218 if (preference == "WebKitEncryptedMediaAPIEnabled") {
219 WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::encryptedMediaAPIEnabledKey(), enabled);
220 RuntimeEnabledFeatures::sharedFeatures().setEncryptedMediaAPIEnabled(enabled);
224 #if ENABLE(MEDIA_STREAM)
225 if (preference == "WebKitMediaDevicesEnabled")
226 RuntimeEnabledFeatures::sharedFeatures().setMediaDevicesEnabled(enabled);
227 if (preference == "WebKitScreenCaptureEnabled")
228 RuntimeEnabledFeatures::sharedFeatures().setScreenCaptureEnabled(enabled);
232 if (preference == "WebKitWebRTCLegacyAPIEnabled")
233 RuntimeEnabledFeatures::sharedFeatures().setWebRTCLegacyAPIEnabled(enabled);
236 if (preference == "WebKitIsSecureContextAttributeEnabled") {
237 WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::isSecureContextAttributeEnabledKey(), enabled);
238 RuntimeEnabledFeatures::sharedFeatures().setIsSecureContextAttributeEnabled(enabled);
241 // Map the names used in LayoutTests with the names used in WebCore::Settings and WebPreferencesStore.
242 #define FOR_EACH_OVERRIDE_BOOL_PREFERENCE(macro) \
243 macro(WebKitJavaEnabled, JavaEnabled, javaEnabled) \
244 macro(WebKitJavaScriptEnabled, ScriptEnabled, javaScriptEnabled) \
245 macro(WebKitPluginsEnabled, PluginsEnabled, pluginsEnabled) \
246 macro(WebKitUsesPageCachePreferenceKey, UsesPageCache, usesPageCache) \
247 macro(WebKitWebAudioEnabled, WebAudioEnabled, webAudioEnabled) \
248 macro(WebKitWebGLEnabled, WebGLEnabled, webGLEnabled) \
249 macro(WebKitXSSAuditorEnabled, XSSAuditorEnabled, xssAuditorEnabled) \
250 macro(WebKitShouldRespectImageOrientation, ShouldRespectImageOrientation, shouldRespectImageOrientation) \
251 macro(WebKitDisplayImagesKey, LoadsImagesAutomatically, loadsImagesAutomatically) \
252 macro(WebKitVisualViewportEnabled, VisualViewportEnabled, visualViewportEnabled) \
253 macro(WebKitLargeImageAsyncDecodingEnabled, LargeImageAsyncDecodingEnabled, largeImageAsyncDecodingEnabled) \
254 macro(WebKitAnimatedImageAsyncDecodingEnabled, AnimatedImageAsyncDecodingEnabled, animatedImageAsyncDecodingEnabled) \
257 #define OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES(TestRunnerName, SettingsName, WebPreferencesName) \
258 if (preference == #TestRunnerName) { \
259 WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::WebPreferencesName##Key(), enabled); \
260 for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter) \
261 (*iter)->settings().set##SettingsName(enabled); \
265 FOR_EACH_OVERRIDE_BOOL_PREFERENCE(OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES)
267 OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES(WebKitHiddenPageDOMTimerThrottlingEnabled, HiddenPageDOMTimerThrottlingEnabled, hiddenPageDOMTimerThrottlingEnabled)
269 #undef OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES
270 #undef FOR_EACH_OVERRIDE_BOOL_PREFERENCE
273 void InjectedBundle::setAllowUniversalAccessFromFileURLs(WebPageGroupProxy* pageGroup, bool enabled)
275 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
276 for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
277 (*iter)->settings().setAllowUniversalAccessFromFileURLs(enabled);
280 void InjectedBundle::setAllowFileAccessFromFileURLs(WebPageGroupProxy* pageGroup, bool enabled)
282 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
283 for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
284 (*iter)->settings().setAllowFileAccessFromFileURLs(enabled);
287 void InjectedBundle::setNeedsStorageAccessFromFileURLsQuirk(WebPageGroupProxy* pageGroup, bool needsQuirk)
289 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
290 for (auto page : pages)
291 page->settings().setNeedsStorageAccessFromFileURLsQuirk(needsQuirk);
294 void InjectedBundle::setMinimumLogicalFontSize(WebPageGroupProxy* pageGroup, int size)
296 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
297 for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
298 (*iter)->settings().setMinimumLogicalFontSize(size);
301 void InjectedBundle::setFrameFlatteningEnabled(WebPageGroupProxy* pageGroup, bool enabled)
303 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
304 for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
305 (*iter)->settings().setFrameFlattening(enabled ? FrameFlattening::FullyEnabled : FrameFlattening::Disabled);
308 void InjectedBundle::setAsyncFrameScrollingEnabled(WebPageGroupProxy* pageGroup, bool enabled)
310 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
311 for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
312 (*iter)->settings().setAsyncFrameScrollingEnabled(enabled);
315 void InjectedBundle::setJavaScriptCanAccessClipboard(WebPageGroupProxy* pageGroup, bool enabled)
317 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
318 for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
319 (*iter)->settings().setJavaScriptCanAccessClipboard(enabled);
322 void InjectedBundle::setPrivateBrowsingEnabled(WebPageGroupProxy* pageGroup, bool enabled)
325 WebProcess::singleton().ensureLegacyPrivateBrowsingSessionInNetworkProcess();
326 WebFrameNetworkingContext::ensureWebsiteDataStoreSession({ { }, { }, { }, { }, { }, { }, { PAL::SessionID::legacyPrivateSessionID(), { }, { }, AllowsCellularAccess::Yes }});
328 SessionTracker::destroySession(PAL::SessionID::legacyPrivateSessionID());
330 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
331 for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
332 (*iter)->enableLegacyPrivateBrowsing(enabled);
335 void InjectedBundle::setUseDashboardCompatibilityMode(WebPageGroupProxy* pageGroup, bool enabled)
337 #if ENABLE(DASHBOARD_SUPPORT)
338 for (auto& page : PageGroup::pageGroup(pageGroup->identifier())->pages())
339 page->settings().setUsesDashboardBackwardCompatibilityMode(enabled);
343 void InjectedBundle::setPopupBlockingEnabled(WebPageGroupProxy* pageGroup, bool enabled)
345 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
346 HashSet<Page*>::const_iterator end = pages.end();
347 for (HashSet<Page*>::const_iterator iter = pages.begin(); iter != end; ++iter)
348 (*iter)->settings().setJavaScriptCanOpenWindowsAutomatically(!enabled);
351 void InjectedBundle::setAuthorAndUserStylesEnabled(WebPageGroupProxy* pageGroup, bool enabled)
353 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
354 for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
355 (*iter)->settings().setAuthorAndUserStylesEnabled(enabled);
358 void InjectedBundle::setSpatialNavigationEnabled(WebPageGroupProxy* pageGroup, bool enabled)
360 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
361 for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
362 (*iter)->settings().setSpatialNavigationEnabled(enabled);
365 void InjectedBundle::addOriginAccessWhitelistEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains)
367 SecurityPolicy::addOriginAccessWhitelistEntry(SecurityOrigin::createFromString(sourceOrigin).get(), destinationProtocol, destinationHost, allowDestinationSubdomains);
370 void InjectedBundle::removeOriginAccessWhitelistEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains)
372 SecurityPolicy::removeOriginAccessWhitelistEntry(SecurityOrigin::createFromString(sourceOrigin).get(), destinationProtocol, destinationHost, allowDestinationSubdomains);
375 void InjectedBundle::resetOriginAccessWhitelists()
377 SecurityPolicy::resetOriginAccessWhitelists();
380 void InjectedBundle::setAsynchronousSpellCheckingEnabled(WebPageGroupProxy* pageGroup, bool enabled)
382 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
383 for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
384 (*iter)->settings().setAsynchronousSpellCheckingEnabled(enabled);
387 int InjectedBundle::numberOfPages(WebFrame* frame, double pageWidthInPixels, double pageHeightInPixels)
389 Frame* coreFrame = frame ? frame->coreFrame() : 0;
392 if (!pageWidthInPixels)
393 pageWidthInPixels = coreFrame->view()->width();
394 if (!pageHeightInPixels)
395 pageHeightInPixels = coreFrame->view()->height();
397 return PrintContext::numberOfPages(*coreFrame, FloatSize(pageWidthInPixels, pageHeightInPixels));
400 int InjectedBundle::pageNumberForElementById(WebFrame* frame, const String& id, double pageWidthInPixels, double pageHeightInPixels)
402 Frame* coreFrame = frame ? frame->coreFrame() : 0;
406 Element* element = coreFrame->document()->getElementById(id);
410 if (!pageWidthInPixels)
411 pageWidthInPixels = coreFrame->view()->width();
412 if (!pageHeightInPixels)
413 pageHeightInPixels = coreFrame->view()->height();
415 return PrintContext::pageNumberForElement(element, FloatSize(pageWidthInPixels, pageHeightInPixels));
418 String InjectedBundle::pageSizeAndMarginsInPixels(WebFrame* frame, int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft)
420 Frame* coreFrame = frame ? frame->coreFrame() : 0;
424 return PrintContext::pageSizeAndMarginsInPixels(coreFrame, pageIndex, width, height, marginTop, marginRight, marginBottom, marginLeft);
427 bool InjectedBundle::isPageBoxVisible(WebFrame* frame, int pageIndex)
429 Frame* coreFrame = frame ? frame->coreFrame() : 0;
433 return PrintContext::isPageBoxVisible(coreFrame, pageIndex);
436 bool InjectedBundle::isProcessingUserGesture()
438 return UserGestureIndicator::processingUserGesture();
441 void InjectedBundle::addUserScript(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, String&& source, String&& url, API::Array* whitelist, API::Array* blacklist, WebCore::UserScriptInjectionTime injectionTime, WebCore::UserContentInjectedFrames injectedFrames)
443 // url is not from URL::string(), i.e. it has not already been parsed by URL, so we have to use the relative URL constructor for URL instead of the ParsedURLStringTag version.
444 UserScript userScript { WTFMove(source), URL(URL(), url), whitelist ? whitelist->toStringVector() : Vector<String>(), blacklist ? blacklist->toStringVector() : Vector<String>(), injectionTime, injectedFrames };
446 pageGroup->userContentController().addUserScript(*scriptWorld, WTFMove(userScript));
449 void InjectedBundle::addUserStyleSheet(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, const String& source, const String& url, API::Array* whitelist, API::Array* blacklist, WebCore::UserContentInjectedFrames injectedFrames)
451 // url is not from URL::string(), i.e. it has not already been parsed by URL, so we have to use the relative URL constructor for URL instead of the ParsedURLStringTag version.
452 UserStyleSheet userStyleSheet{ source, URL(URL(), url), whitelist ? whitelist->toStringVector() : Vector<String>(), blacklist ? blacklist->toStringVector() : Vector<String>(), injectedFrames, UserStyleUserLevel };
454 pageGroup->userContentController().addUserStyleSheet(*scriptWorld, WTFMove(userStyleSheet));
457 void InjectedBundle::removeUserScript(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, const String& url)
459 // url is not from URL::string(), i.e. it has not already been parsed by URL, so we have to use the relative URL constructor for URL instead of the ParsedURLStringTag version.
460 pageGroup->userContentController().removeUserScriptWithURL(*scriptWorld, URL(URL(), url));
463 void InjectedBundle::removeUserStyleSheet(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, const String& url)
465 // url is not from URL::string(), i.e. it has not already been parsed by URL, so we have to use the relative URL constructor for URL instead of the ParsedURLStringTag version.
466 pageGroup->userContentController().removeUserStyleSheetWithURL(*scriptWorld, URL(URL(), url));
469 void InjectedBundle::removeUserScripts(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld)
471 pageGroup->userContentController().removeUserScripts(*scriptWorld);
474 void InjectedBundle::removeUserStyleSheets(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld)
476 pageGroup->userContentController().removeUserStyleSheets(*scriptWorld);
479 void InjectedBundle::removeAllUserContent(WebPageGroupProxy* pageGroup)
481 pageGroup->userContentController().removeAllUserContent();
484 void InjectedBundle::garbageCollectJavaScriptObjects()
486 GCController::singleton().garbageCollectNow();
489 void InjectedBundle::garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(bool waitUntilDone)
491 GCController::singleton().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
494 size_t InjectedBundle::javaScriptObjectsCount()
496 JSLockHolder lock(commonVM());
497 return commonVM().heap.objectCount();
500 void InjectedBundle::reportException(JSContextRef context, JSValueRef exception)
502 if (!context || !exception)
505 JSC::ExecState* execState = toJS(context);
506 JSLockHolder lock(execState);
508 // Make sure the context has a DOMWindow global object, otherwise this context didn't originate from a Page.
509 JSC::JSGlobalObject* globalObject = execState->lexicalGlobalObject();
510 if (!toJSDOMWindow(globalObject->vm(), globalObject))
513 WebCore::reportException(execState, toJS(execState, exception));
516 void InjectedBundle::didCreatePage(WebPage* page)
518 m_client->didCreatePage(*this, *page);
521 void InjectedBundle::willDestroyPage(WebPage* page)
523 m_client->willDestroyPage(*this, *page);
526 void InjectedBundle::didInitializePageGroup(WebPageGroupProxy* pageGroup)
528 m_client->didInitializePageGroup(*this, *pageGroup);
531 void InjectedBundle::didReceiveMessage(const String& messageName, API::Object* messageBody)
533 m_client->didReceiveMessage(*this, messageName, messageBody);
536 void InjectedBundle::didReceiveMessageToPage(WebPage* page, const String& messageName, API::Object* messageBody)
538 m_client->didReceiveMessageToPage(*this, *page, messageName, messageBody);
541 void InjectedBundle::setUserStyleSheetLocation(WebPageGroupProxy* pageGroup, const String& location)
543 const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
544 for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
545 (*iter)->settings().setUserStyleSheetLocation(URL(URL(), location));
548 void InjectedBundle::setWebNotificationPermission(WebPage* page, const String& originString, bool allowed)
550 #if ENABLE(NOTIFICATIONS)
551 page->notificationPermissionRequestManager()->setPermissionLevelForTesting(originString, allowed);
554 UNUSED_PARAM(originString);
555 UNUSED_PARAM(allowed);
559 void InjectedBundle::removeAllWebNotificationPermissions(WebPage* page)
561 #if ENABLE(NOTIFICATIONS)
562 page->notificationPermissionRequestManager()->removeAllPermissionsForTesting();
568 uint64_t InjectedBundle::webNotificationID(JSContextRef jsContext, JSValueRef jsNotification)
570 #if ENABLE(NOTIFICATIONS)
571 WebCore::Notification* notification = JSNotification::toWrapped(toJS(jsContext)->vm(), toJS(toJS(jsContext), jsNotification));
574 return WebProcess::singleton().supplement<WebNotificationManager>()->notificationIDForTesting(notification);
576 UNUSED_PARAM(jsContext);
577 UNUSED_PARAM(jsNotification);
582 // FIXME Get rid of this function and move it into WKBundle.cpp.
583 Ref<API::Data> InjectedBundle::createWebDataFromUint8Array(JSContextRef context, JSValueRef data)
585 JSC::ExecState* execState = toJS(context);
586 JSLockHolder lock(execState);
587 RefPtr<Uint8Array> arrayData = WebCore::toUnsharedUint8Array(execState->vm(), toJS(execState, data));
588 return API::Data::create(static_cast<unsigned char*>(arrayData->baseAddress()), arrayData->byteLength());
591 void InjectedBundle::setTabKeyCyclesThroughElements(WebPage* page, bool enabled)
593 page->corePage()->setTabKeyCyclesThroughElements(enabled);
596 void InjectedBundle::setCSSAnimationTriggersEnabled(bool enabled)
598 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
599 RuntimeEnabledFeatures::sharedFeatures().setAnimationTriggersEnabled(enabled);
601 UNUSED_PARAM(enabled);
605 void InjectedBundle::setWebAnimationsEnabled(bool enabled)
607 RuntimeEnabledFeatures::sharedFeatures().setWebAnimationsEnabled(enabled);
610 } // namespace WebKit