diff options
Diffstat (limited to 'Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp')
-rw-r--r-- | Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp | 373 |
1 files changed, 297 insertions, 76 deletions
diff --git a/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp b/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp index f71fe9360..f247b362b 100644 --- a/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp +++ b/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved. + * Copyright (C) 2010-2017 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,20 +29,20 @@ #include "ActivateFonts.h" #include "InjectedBundlePage.h" #include "StringFunctions.h" -#include <WebKit2/WKBundle.h> -#include <WebKit2/WKBundlePage.h> -#include <WebKit2/WKBundlePagePrivate.h> -#include <WebKit2/WKBundlePrivate.h> -#include <WebKit2/WKRetainPtr.h> -#include <WebKit2/WebKit2_C.h> -#include <wtf/PassOwnPtr.h> +#include "WebCoreTestSupport.h" +#include <WebKit/WKBundle.h> +#include <WebKit/WKBundlePage.h> +#include <WebKit/WKBundlePagePrivate.h> +#include <WebKit/WKBundlePrivate.h> +#include <WebKit/WKRetainPtr.h> +#include <WebKit/WebKit2_C.h> #include <wtf/text/CString.h> #include <wtf/text/StringBuilder.h> #include <wtf/Vector.h> namespace WTR { -InjectedBundle& InjectedBundle::shared() +InjectedBundle& InjectedBundle::singleton() { static InjectedBundle& shared = *new InjectedBundle; return shared; @@ -101,23 +101,18 @@ void InjectedBundle::initialize(WKBundleRef bundle, WKTypeRef initializationUser platformInitialize(initializationUserData); activateFonts(); - WKBundleActivateMacFontAscentHack(m_bundle); } void InjectedBundle::didCreatePage(WKBundlePageRef page) { - m_pages.append(adoptPtr(new InjectedBundlePage(page))); + m_pages.append(std::make_unique<InjectedBundlePage>(page)); } void InjectedBundle::willDestroyPage(WKBundlePageRef page) { - size_t size = m_pages.size(); - for (size_t i = 0; i < size; ++i) { - if (m_pages[i]->page() == page) { - m_pages.remove(i); - break; - } - } + m_pages.removeFirstMatching([page](auto& current) { + return current->page() == page; + }); } void InjectedBundle::didInitializePageGroup(WKBundlePageGroupRef pageGroup) @@ -139,6 +134,13 @@ void InjectedBundle::resetLocalSettings() void InjectedBundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody) { + WKRetainPtr<WKStringRef> errorMessageName(AdoptWK, WKStringCreateWithUTF8CString("Error")); + WKRetainPtr<WKStringRef> errorMessageBody(AdoptWK, WKStringCreateWithUTF8CString("Unknown")); + WKBundlePostMessage(m_bundle, errorMessageName.get(), errorMessageBody.get()); +} + +void InjectedBundle::didReceiveMessageToPage(WKBundlePageRef page, WKStringRef messageName, WKTypeRef messageBody) +{ if (WKStringIsEqualToUTF8CString(messageName, "BeginTest")) { ASSERT(messageBody); ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); @@ -153,13 +155,18 @@ void InjectedBundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messag WKRetainPtr<WKStringRef> timeoutKey(AdoptWK, WKStringCreateWithUTF8CString("Timeout")); m_timeout = (int)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, timeoutKey.get()))); + WKRetainPtr<WKStringRef> dumpJSConsoleLogInStdErrKey(AdoptWK, WKStringCreateWithUTF8CString("DumpJSConsoleLogInStdErr")); + m_dumpJSConsoleLogInStdErr = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, dumpJSConsoleLogInStdErrKey.get()))); + WKRetainPtr<WKStringRef> ackMessageName(AdoptWK, WKStringCreateWithUTF8CString("Ack")); WKRetainPtr<WKStringRef> ackMessageBody(AdoptWK, WKStringCreateWithUTF8CString("BeginTest")); - WKBundlePostMessage(m_bundle, ackMessageName.get(), ackMessageBody.get()); + WKBundlePagePostMessage(page, ackMessageName.get(), ackMessageBody.get()); beginTesting(messageBodyDictionary); return; - } else if (WKStringIsEqualToUTF8CString(messageName, "Reset")) { + } + + if (WKStringIsEqualToUTF8CString(messageName, "Reset")) { ASSERT(messageBody); ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); @@ -170,48 +177,103 @@ void InjectedBundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messag if (shouldGC) WKBundleGarbageCollectJavaScriptObjects(m_bundle); + WKRetainPtr<WKStringRef> allowedHostsKey(AdoptWK, WKStringCreateWithUTF8CString("AllowedHosts")); + WKTypeRef allowedHostsValue = WKDictionaryGetItemForKey(messageBodyDictionary, allowedHostsKey.get()); + if (allowedHostsValue && WKGetTypeID(allowedHostsValue) == WKArrayGetTypeID()) { + WKArrayRef allowedHostsArray = static_cast<WKArrayRef>(allowedHostsValue); + for (size_t i = 0, size = WKArrayGetSize(allowedHostsArray); i < size; ++i) { + WKTypeRef item = WKArrayGetItemAtIndex(allowedHostsArray, i); + if (item && WKGetTypeID(item) == WKStringGetTypeID()) + m_allowedHosts.append(toWTFString(static_cast<WKStringRef>(item))); + } + } + m_state = Idle; m_dumpPixels = false; + m_pixelResultIsPending = false; resetLocalSettings(); - m_testRunner->removeAllWebNotificationPermissions(); + TestRunner::removeAllWebNotificationPermissions(); - page()->resetAfterTest(); + InjectedBundle::page()->resetAfterTest(); return; } + if (WKStringIsEqualToUTF8CString(messageName, "CallAddChromeInputFieldCallback")) { m_testRunner->callAddChromeInputFieldCallback(); return; } + if (WKStringIsEqualToUTF8CString(messageName, "CallRemoveChromeInputFieldCallback")) { m_testRunner->callRemoveChromeInputFieldCallback(); return; } + if (WKStringIsEqualToUTF8CString(messageName, "CallFocusWebViewCallback")) { m_testRunner->callFocusWebViewCallback(); return; } + if (WKStringIsEqualToUTF8CString(messageName, "CallSetBackingScaleFactorCallback")) { m_testRunner->callSetBackingScaleFactorCallback(); return; - } + } + + if (WKStringIsEqualToUTF8CString(messageName, "CallDidBeginSwipeCallback")) { + m_testRunner->callDidBeginSwipeCallback(); + return; + } + + if (WKStringIsEqualToUTF8CString(messageName, "CallWillEndSwipeCallback")) { + m_testRunner->callWillEndSwipeCallback(); + return; + } + + if (WKStringIsEqualToUTF8CString(messageName, "CallDidEndSwipeCallback")) { + m_testRunner->callDidEndSwipeCallback(); + return; + } + + if (WKStringIsEqualToUTF8CString(messageName, "CallDidRemoveSwipeSnapshotCallback")) { + m_testRunner->callDidRemoveSwipeSnapshotCallback(); + return; + } + + if (WKStringIsEqualToUTF8CString(messageName, "NotifyDownloadDone")) { + m_testRunner->notifyDone(); + return; + } + + if (WKStringIsEqualToUTF8CString(messageName, "CallUISideScriptCallback")) { + WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); + + WKRetainPtr<WKStringRef> resultKey(AdoptWK, WKStringCreateWithUTF8CString("Result")); + WKRetainPtr<WKStringRef> callbackIDKey(AdoptWK, WKStringCreateWithUTF8CString("CallbackID")); + + unsigned callbackID = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, callbackIDKey.get()))); + + WKStringRef resultString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, resultKey.get())); + auto resultJSString = toJS(resultString); + + m_testRunner->runUIScriptCallback(callbackID, resultJSString.get()); + return; + } + if (WKStringIsEqualToUTF8CString(messageName, "WorkQueueProcessedCallback")) { if (!topLoadingFrame() && !m_testRunner->waitToDump()) - page()->dump(); + InjectedBundle::page()->dump(); return; } - WKRetainPtr<WKStringRef> errorMessageName(AdoptWK, WKStringCreateWithUTF8CString("Error")); - WKRetainPtr<WKStringRef> errorMessageBody(AdoptWK, WKStringCreateWithUTF8CString("Unknown")); - WKBundlePostMessage(m_bundle, errorMessageName.get(), errorMessageBody.get()); -} + if (WKStringIsEqualToUTF8CString(messageName, "WebsiteDataDeletionForTopPrivatelyOwnedDomainsFinished")) { + m_testRunner->statisticsDidModifyDataRecordsCallback(); + return; + } -void InjectedBundle::didReceiveMessageToPage(WKBundlePageRef page, WKStringRef messageName, WKTypeRef messageBody) -{ WKRetainPtr<WKStringRef> errorMessageName(AdoptWK, WKStringCreateWithUTF8CString("Error")); WKRetainPtr<WKStringRef> errorMessageBody(AdoptWK, WKStringCreateWithUTF8CString("Unknown")); - WKBundlePostMessage(m_bundle, errorMessageName.get(), errorMessageBody.get()); + WKBundlePagePostMessage(page, errorMessageName.get(), errorMessageBody.get()); } bool InjectedBundle::booleanForKey(WKDictionaryRef dictionary, const char* key) @@ -236,41 +298,60 @@ void InjectedBundle::beginTesting(WKDictionaryRef settings) m_gcController = GCController::create(); m_eventSendingController = EventSendingController::create(); m_textInputController = TextInputController::create(); +#if HAVE(ACCESSIBILITY) m_accessibilityController = AccessibilityController::create(); +#endif - WKBundleSetShouldTrackVisitedLinks(m_bundle, false); - WKBundleRemoveAllVisitedLinks(m_bundle); WKBundleSetAllowUniversalAccessFromFileURLs(m_bundle, m_pageGroup, true); WKBundleSetJavaScriptCanAccessClipboard(m_bundle, m_pageGroup, true); WKBundleSetPrivateBrowsingEnabled(m_bundle, m_pageGroup, false); + WKBundleSetUseDashboardCompatibilityMode(m_bundle, m_pageGroup, false); WKBundleSetAuthorAndUserStylesEnabled(m_bundle, m_pageGroup, true); WKBundleSetFrameFlatteningEnabled(m_bundle, m_pageGroup, false); WKBundleSetMinimumLogicalFontSize(m_bundle, m_pageGroup, 9); WKBundleSetSpatialNavigationEnabled(m_bundle, m_pageGroup, false); WKBundleSetAllowFileAccessFromFileURLs(m_bundle, m_pageGroup, true); - WKBundleSetPluginsEnabled(m_bundle, m_pageGroup, true); WKBundleSetPopupBlockingEnabled(m_bundle, m_pageGroup, false); - WKBundleSetAlwaysAcceptCookies(m_bundle, false); - WKBundleSetSerialLoadingEnabled(m_bundle, false); - WKBundleSetShadowDOMEnabled(m_bundle, true); - WKBundleSetSeamlessIFramesEnabled(m_bundle, true); - WKBundleSetCacheModel(m_bundle, 1 /*CacheModelDocumentBrowser*/); + WKBundleSetAllowStorageAccessFromFileURLS(m_bundle, m_pageGroup, false); - WKBundleRemoveAllUserContent(m_bundle, m_pageGroup); +#if PLATFORM(IOS) + WKBundlePageSetUseTestingViewportConfiguration(page()->page(), !booleanForKey(settings, "UseFlexibleViewport")); +#endif + + m_testRunner->setPluginsEnabled(true); m_testRunner->setShouldDumpFrameLoadCallbacks(booleanForKey(settings, "DumpFrameLoadDelegates")); m_testRunner->setUserStyleSheetEnabled(false); m_testRunner->setXSSAuditorEnabled(false); + + m_testRunner->setShadowDOMEnabled(true); + m_testRunner->setCustomElementsEnabled(true); + + m_testRunner->setWebGL2Enabled(true); + + m_testRunner->setFetchAPIEnabled(true); + + m_testRunner->setDownloadAttributeEnabled(true); + + m_testRunner->setEncryptedMediaAPIEnabled(true); + m_testRunner->setCloseRemainingWindowsWhenComplete(false); m_testRunner->setAcceptsEditing(true); m_testRunner->setTabKeyCyclesThroughElements(true); + m_testRunner->clearTestRunnerCallbacks(); + + m_testRunner->setSubtleCryptoEnabled(true); - m_testRunner->setCustomTimeout(m_timeout); + m_testRunner->setMediaStreamEnabled(true); + m_testRunner->setPeerConnectionEnabled(true); + + if (m_timeout > 0) + m_testRunner->setCustomTimeout(m_timeout); page()->prepare(); WKBundleClearAllDatabases(m_bundle); - WKBundleClearApplicationCache(m_bundle); + WKBundlePageClearApplicationCache(page()->page()); WKBundleResetOriginAccessWhitelists(m_bundle); // [WK2] REGRESSION(r128623): It made layout tests extremely slow @@ -287,13 +368,21 @@ void InjectedBundle::done() page()->stopLoading(); setTopLoadingFrame(0); + m_testRunner->invalidateWaitToDumpWatchdogTimer(); + m_accessibilityController->resetToConsistentState(); WKRetainPtr<WKStringRef> doneMessageName(AdoptWK, WKStringCreateWithUTF8CString("Done")); WKRetainPtr<WKMutableDictionaryRef> doneMessageBody(AdoptWK, WKMutableDictionaryCreate()); - WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult")); - WKDictionarySetItem(doneMessageBody.get(), pixelResultKey.get(), m_pixelResult.get()); + WKRetainPtr<WKStringRef> pixelResultIsPendingKey = adoptWK(WKStringCreateWithUTF8CString("PixelResultIsPending")); + WKRetainPtr<WKBooleanRef> pixelResultIsPending(AdoptWK, WKBooleanCreate(m_pixelResultIsPending)); + WKDictionarySetItem(doneMessageBody.get(), pixelResultIsPendingKey.get(), pixelResultIsPending.get()); + + if (!m_pixelResultIsPending) { + WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult")); + WKDictionarySetItem(doneMessageBody.get(), pixelResultKey.get(), m_pixelResult.get()); + } WKRetainPtr<WKStringRef> repaintRectsKey = adoptWK(WKStringCreateWithUTF8CString("RepaintRects")); WKDictionarySetItem(doneMessageBody.get(), repaintRectsKey.get(), m_repaintRects.get()); @@ -301,7 +390,7 @@ void InjectedBundle::done() WKRetainPtr<WKStringRef> audioResultKey = adoptWK(WKStringCreateWithUTF8CString("AudioResult")); WKDictionarySetItem(doneMessageBody.get(), audioResultKey.get(), m_audioResult.get()); - WKBundlePostMessage(m_bundle, doneMessageName.get(), doneMessageBody.get()); + WKBundlePagePostMessage(page()->page(), doneMessageName.get(), doneMessageBody.get()); closeOtherPages(); @@ -326,6 +415,17 @@ void InjectedBundle::dumpBackForwardListsForAllPages(StringBuilder& stringBuilde m_pages[i]->dumpBackForwardList(stringBuilder); } +void InjectedBundle::dumpToStdErr(const String& output) +{ + if (m_state != Testing) + return; + if (output.isEmpty()) + return; + WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("DumpToStdErr")); + WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithUTF8CString(output.utf8().data())); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); +} + void InjectedBundle::outputText(const String& output) { if (m_state != Testing) @@ -334,60 +434,85 @@ void InjectedBundle::outputText(const String& output) return; WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("TextOutput")); WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithUTF8CString(output.utf8().data())); - WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get()); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); } void InjectedBundle::postNewBeforeUnloadReturnValue(bool value) { WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("BeforeUnloadReturnValue")); WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value)); - WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get()); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); } void InjectedBundle::postAddChromeInputField() { WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("AddChromeInputField")); - WKBundlePostMessage(m_bundle, messageName.get(), 0); + WKBundlePagePostMessage(page()->page(), messageName.get(), 0); } void InjectedBundle::postRemoveChromeInputField() { WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("RemoveChromeInputField")); - WKBundlePostMessage(m_bundle, messageName.get(), 0); + WKBundlePagePostMessage(page()->page(), messageName.get(), 0); } void InjectedBundle::postFocusWebView() { WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("FocusWebView")); - WKBundlePostMessage(m_bundle, messageName.get(), 0); + WKBundlePagePostMessage(page()->page(), messageName.get(), 0); } void InjectedBundle::postSetBackingScaleFactor(double backingScaleFactor) { WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetBackingScaleFactor")); WKRetainPtr<WKDoubleRef> messageBody(AdoptWK, WKDoubleCreate(backingScaleFactor)); - WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get()); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); } void InjectedBundle::postSetWindowIsKey(bool isKey) { WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetWindowIsKey")); WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(isKey)); - WKBundlePostSynchronousMessage(m_bundle, messageName.get(), messageBody.get(), 0); + WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), messageBody.get(), 0); +} + +void InjectedBundle::postSetViewSize(double width, double height) +{ + WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetViewSize")); + + WKRetainPtr<WKStringRef> widthKey(AdoptWK, WKStringCreateWithUTF8CString("width")); + WKRetainPtr<WKStringRef> heightKey(AdoptWK, WKStringCreateWithUTF8CString("height")); + + WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate()); + + WKRetainPtr<WKDoubleRef> widthWK(AdoptWK, WKDoubleCreate(width)); + WKDictionarySetItem(messageBody.get(), widthKey.get(), widthWK.get()); + + WKRetainPtr<WKDoubleRef> heightWK(AdoptWK, WKDoubleCreate(height)); + WKDictionarySetItem(messageBody.get(), heightKey.get(), heightWK.get()); + + WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), messageBody.get(), 0); } void InjectedBundle::postSimulateWebNotificationClick(uint64_t notificationID) { WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SimulateWebNotificationClick")); WKRetainPtr<WKUInt64Ref> messageBody(AdoptWK, WKUInt64Create(notificationID)); - WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get()); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); +} + +void InjectedBundle::postSetAddsVisitedLinks(bool addsVisitedLinks) +{ + WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetAddsVisitedLinks")); + WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(addsVisitedLinks)); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); } void InjectedBundle::setGeolocationPermission(bool enabled) { WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetGeolocationPermission")); WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(enabled)); - WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get()); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); } void InjectedBundle::setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed) @@ -440,13 +565,90 @@ void InjectedBundle::setMockGeolocationPosition(double latitude, double longitud WKRetainPtr<WKDoubleRef> speedWK(AdoptWK, WKDoubleCreate(speed)); WKDictionarySetItem(messageBody.get(), speedKeyWK.get(), speedWK.get()); - WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get()); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); } void InjectedBundle::setMockGeolocationPositionUnavailableError(WKStringRef errorMessage) { WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetMockGeolocationPositionUnavailableError")); - WKBundlePostMessage(m_bundle, messageName.get(), errorMessage); + WKBundlePagePostMessage(page()->page(), messageName.get(), errorMessage); +} + +bool InjectedBundle::isGeolocationProviderActive() const +{ + WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("IsGeolocationClientActive")); + WKTypeRef resultToPass = 0; + WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), 0, &resultToPass); + WKRetainPtr<WKBooleanRef> isActive(AdoptWK, static_cast<WKBooleanRef>(resultToPass)); + + return WKBooleanGetValue(isActive.get()); +} + +unsigned InjectedBundle::imageCountInGeneralPasteboard() const +{ + WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("ImageCountInGeneralPasteboard")); + WKTypeRef resultToPass = 0; + WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), 0, &resultToPass); + WKRetainPtr<WKUInt64Ref> imageCount(AdoptWK, static_cast<WKUInt64Ref>(resultToPass)); + + return static_cast<unsigned>(WKUInt64GetValue(imageCount.get())); +} + +void InjectedBundle::setUserMediaPermission(bool enabled) +{ + auto messageName = adoptWK(WKStringCreateWithUTF8CString("SetUserMediaPermission")); + auto messageBody = adoptWK(WKBooleanCreate(enabled)); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); +} + +void InjectedBundle::setUserMediaPersistentPermissionForOrigin(bool permission, WKStringRef origin, WKStringRef parentOrigin) +{ + auto messageName = adoptWK(WKStringCreateWithUTF8CString("SetUserMediaPersistentPermissionForOrigin")); + WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate()); + + WKRetainPtr<WKStringRef> permissionKeyWK(AdoptWK, WKStringCreateWithUTF8CString("permission")); + WKRetainPtr<WKBooleanRef> permissionWK(AdoptWK, WKBooleanCreate(permission)); + WKDictionarySetItem(messageBody.get(), permissionKeyWK.get(), permissionWK.get()); + + WKRetainPtr<WKStringRef> originKeyWK(AdoptWK, WKStringCreateWithUTF8CString("origin")); + WKDictionarySetItem(messageBody.get(), originKeyWK.get(), origin); + + WKRetainPtr<WKStringRef> parentOriginKeyWK(AdoptWK, WKStringCreateWithUTF8CString("parentOrigin")); + WKDictionarySetItem(messageBody.get(), parentOriginKeyWK.get(), parentOrigin); + + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); +} + +unsigned InjectedBundle::userMediaPermissionRequestCountForOrigin(WKStringRef origin, WKStringRef parentOrigin) const +{ + WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("UserMediaPermissionRequestCountForOrigin")); + WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate()); + + WKRetainPtr<WKStringRef> originKeyWK(AdoptWK, WKStringCreateWithUTF8CString("origin")); + WKDictionarySetItem(messageBody.get(), originKeyWK.get(), origin); + + WKRetainPtr<WKStringRef> parentOriginKeyWK(AdoptWK, WKStringCreateWithUTF8CString("parentOrigin")); + WKDictionarySetItem(messageBody.get(), parentOriginKeyWK.get(), parentOrigin); + + WKTypeRef resultToPass = 0; + WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), messageBody.get(), &resultToPass); + WKRetainPtr<WKUInt64Ref> count(AdoptWK, static_cast<WKUInt64Ref>(resultToPass)); + + return static_cast<unsigned>(WKUInt64GetValue(count.get())); +} + +void InjectedBundle::resetUserMediaPermissionRequestCountForOrigin(WKStringRef origin, WKStringRef parentOrigin) +{ + WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("ResetUserMediaPermissionRequestCountForOrigin")); + WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate()); + + WKRetainPtr<WKStringRef> originKeyWK(AdoptWK, WKStringCreateWithUTF8CString("origin")); + WKDictionarySetItem(messageBody.get(), originKeyWK.get(), origin); + + WKRetainPtr<WKStringRef> parentOriginKeyWK(AdoptWK, WKStringCreateWithUTF8CString("parentOrigin")); + WKDictionarySetItem(messageBody.get(), parentOriginKeyWK.get(), parentOrigin); + + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); } void InjectedBundle::setCustomPolicyDelegate(bool enabled, bool permissive) @@ -463,23 +665,26 @@ void InjectedBundle::setCustomPolicyDelegate(bool enabled, bool permissive) WKRetainPtr<WKBooleanRef> permissiveWK(AdoptWK, WKBooleanCreate(permissive)); WKDictionarySetItem(messageBody.get(), permissiveKeyWK.get(), permissiveWK.get()); - WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get()); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); } -void InjectedBundle::setVisibilityState(WKPageVisibilityState visibilityState, bool isInitialState) +void InjectedBundle::setHidden(bool hidden) { - WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetVisibilityState")); + WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetHidden")); WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate()); - WKRetainPtr<WKStringRef> visibilityStateKeyWK(AdoptWK, WKStringCreateWithUTF8CString("visibilityState")); - WKRetainPtr<WKUInt64Ref> visibilityStateWK(AdoptWK, WKUInt64Create(visibilityState)); - WKDictionarySetItem(messageBody.get(), visibilityStateKeyWK.get(), visibilityStateWK.get()); - - WKRetainPtr<WKStringRef> isInitialKeyWK(AdoptWK, WKStringCreateWithUTF8CString("isInitialState")); - WKRetainPtr<WKBooleanRef> isInitialWK(AdoptWK, WKBooleanCreate(isInitialState)); + WKRetainPtr<WKStringRef> isInitialKeyWK(AdoptWK, WKStringCreateWithUTF8CString("hidden")); + WKRetainPtr<WKBooleanRef> isInitialWK(AdoptWK, WKBooleanCreate(hidden)); WKDictionarySetItem(messageBody.get(), isInitialKeyWK.get(), isInitialWK.get()); - WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get()); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); +} + +void InjectedBundle::setCacheModel(int model) +{ + WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetCacheModel")); + WKRetainPtr<WKUInt64Ref> messageBody(AdoptWK, WKUInt64Create(model)); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); } bool InjectedBundle::shouldProcessWorkQueue() const @@ -489,7 +694,7 @@ bool InjectedBundle::shouldProcessWorkQueue() const WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("IsWorkQueueEmpty")); WKTypeRef resultToPass = 0; - WKBundlePostSynchronousMessage(m_bundle, messageName.get(), 0, &resultToPass); + WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), 0, &resultToPass); WKRetainPtr<WKBooleanRef> isEmpty(AdoptWK, static_cast<WKBooleanRef>(resultToPass)); return !WKBooleanGetValue(isEmpty.get()); @@ -498,7 +703,7 @@ bool InjectedBundle::shouldProcessWorkQueue() const void InjectedBundle::processWorkQueue() { WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("ProcessWorkQueue")); - WKBundlePostMessage(m_bundle, messageName.get(), 0); + WKBundlePagePostMessage(page()->page(), messageName.get(), 0); } void InjectedBundle::queueBackNavigation(unsigned howFarBackward) @@ -507,7 +712,7 @@ void InjectedBundle::queueBackNavigation(unsigned howFarBackward) WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueBackNavigation")); WKRetainPtr<WKUInt64Ref> messageBody(AdoptWK, WKUInt64Create(howFarBackward)); - WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get()); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); } void InjectedBundle::queueForwardNavigation(unsigned howFarForward) @@ -516,10 +721,10 @@ void InjectedBundle::queueForwardNavigation(unsigned howFarForward) WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueForwardNavigation")); WKRetainPtr<WKUInt64Ref> messageBody(AdoptWK, WKUInt64Create(howFarForward)); - WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get()); + WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); } -void InjectedBundle::queueLoad(WKStringRef url, WKStringRef target) +void InjectedBundle::queueLoad(WKStringRef url, WKStringRef target, bool shouldOpenExternalURLs) { m_useWorkQueue = true; @@ -533,7 +738,11 @@ void InjectedBundle::queueLoad(WKStringRef url, WKStringRef target) WKRetainPtr<WKStringRef> targetKey(AdoptWK, WKStringCreateWithUTF8CString("target")); WKDictionarySetItem(loadData.get(), targetKey.get(), target); - WKBundlePostMessage(m_bundle, messageName.get(), loadData.get()); + WKRetainPtr<WKStringRef> shouldOpenExternalURLsKey(AdoptWK, WKStringCreateWithUTF8CString("shouldOpenExternalURLs")); + WKRetainPtr<WKBooleanRef> shouldOpenExternalURLsValue(AdoptWK, WKBooleanCreate(shouldOpenExternalURLs)); + WKDictionarySetItem(loadData.get(), shouldOpenExternalURLsKey.get(), shouldOpenExternalURLsValue.get()); + + WKBundlePagePostMessage(page()->page(), messageName.get(), loadData.get()); } void InjectedBundle::queueLoadHTMLString(WKStringRef content, WKStringRef baseURL, WKStringRef unreachableURL) @@ -557,7 +766,7 @@ void InjectedBundle::queueLoadHTMLString(WKStringRef content, WKStringRef baseUR WKDictionarySetItem(loadData.get(), unreachableURLKey.get(), unreachableURL); } - WKBundlePostMessage(m_bundle, messageName.get(), loadData.get()); + WKBundlePagePostMessage(page()->page(), messageName.get(), loadData.get()); } void InjectedBundle::queueReload() @@ -565,7 +774,7 @@ void InjectedBundle::queueReload() m_useWorkQueue = true; WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueReload")); - WKBundlePostMessage(m_bundle, messageName.get(), 0); + WKBundlePagePostMessage(page()->page(), messageName.get(), 0); } void InjectedBundle::queueLoadingScript(WKStringRef script) @@ -573,7 +782,7 @@ void InjectedBundle::queueLoadingScript(WKStringRef script) m_useWorkQueue = true; WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueLoadingScript")); - WKBundlePostMessage(m_bundle, messageName.get(), script); + WKBundlePagePostMessage(page()->page(), messageName.get(), script); } void InjectedBundle::queueNonLoadingScript(WKStringRef script) @@ -581,7 +790,19 @@ void InjectedBundle::queueNonLoadingScript(WKStringRef script) m_useWorkQueue = true; WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueNonLoadingScript")); - WKBundlePostMessage(m_bundle, messageName.get(), script); + WKBundlePagePostMessage(page()->page(), messageName.get(), script); +} + +bool InjectedBundle::isAllowedHost(WKStringRef host) +{ + if (m_allowedHosts.isEmpty()) + return false; + return m_allowedHosts.contains(toWTFString(host)); +} + +void InjectedBundle::setAllowsAnySSLCertificate(bool allowsAnySSLCertificate) +{ + WebCoreTestSupport::setAllowsAnySSLCertificate(allowsAnySSLCertificate); } } // namespace WTR |