diff options
Diffstat (limited to 'Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp')
-rw-r--r-- | Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp | 505 |
1 files changed, 202 insertions, 303 deletions
diff --git a/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp b/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp index 9d232ee16..e161156a7 100644 --- a/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp +++ b/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp @@ -31,20 +31,19 @@ #include "WebCoreTestSupport.h" #include <cmath> #include <JavaScriptCore/JSRetainPtr.h> -#include <WebKit/WKArray.h> -#include <WebKit/WKBundle.h> -#include <WebKit/WKBundleBackForwardList.h> -#include <WebKit/WKBundleBackForwardListItem.h> -#include <WebKit/WKBundleFrame.h> -#include <WebKit/WKBundleFramePrivate.h> -#include <WebKit/WKBundleHitTestResult.h> -#include <WebKit/WKBundleNavigationAction.h> -#include <WebKit/WKBundleNavigationActionPrivate.h> -#include <WebKit/WKBundleNodeHandlePrivate.h> -#include <WebKit/WKBundlePagePrivate.h> -#include <WebKit/WKBundlePrivate.h> -#include <WebKit/WKSecurityOriginRef.h> -#include <WebKit/WKURLRequest.h> +#include <WebKit2/WKArray.h> +#include <WebKit2/WKBundle.h> +#include <WebKit2/WKBundleBackForwardList.h> +#include <WebKit2/WKBundleBackForwardListItem.h> +#include <WebKit2/WKBundleFrame.h> +#include <WebKit2/WKBundleFramePrivate.h> +#include <WebKit2/WKBundleHitTestResult.h> +#include <WebKit2/WKBundleNavigationAction.h> +#include <WebKit2/WKBundleNodeHandlePrivate.h> +#include <WebKit2/WKBundlePagePrivate.h> +#include <WebKit2/WKBundlePrivate.h> +#include <WebKit2/WKSecurityOrigin.h> +#include <WebKit2/WKURLRequest.h> #include <wtf/HashMap.h> #include <wtf/text/CString.h> #include <wtf/text/StringBuilder.h> @@ -241,7 +240,7 @@ static inline WTF::String pathSuitableForTestResult(WKURLRef fileUrl) if (!isLocalFileScheme(schemeString.get())) return toWTFString(adoptWK(WKURLCopyString(fileUrl))); - WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()); + WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()); WKRetainPtr<WKURLRef> mainFrameURL = adoptWK(WKBundleFrameCopyURL(mainFrame)); if (!mainFrameURL) mainFrameURL = adoptWK(WKBundleFrameCopyProvisionalURL(mainFrame)); @@ -269,8 +268,8 @@ InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page) : m_page(page) , m_world(AdoptWK, WKBundleScriptWorldCreateWorld()) { - WKBundlePageLoaderClientV8 loaderClient = { - { 8, this }, + WKBundlePageLoaderClientV7 loaderClient = { + { 7, this }, didStartProvisionalLoadForFrame, didReceiveServerRedirectForProvisionalLoadForFrame, didFailProvisionalLoadWithErrorForFrame, @@ -305,8 +304,7 @@ InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page) 0, // featuresUsedInPage 0, // willLoadURLRequest 0, // willLoadDataRequest - 0, // willDestroyFrame_unavailable - 0, // userAgentForURL + 0, // willDestroyFrame }; WKBundlePageSetPageLoaderClient(m_page, &loaderClient.base); @@ -419,11 +417,6 @@ void InjectedBundlePage::prepare() void InjectedBundlePage::resetAfterTest() { WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page); - - // WebKit currently doesn't reset focus even when navigating to a new page. This may or may not be a bug - // (see <https://bugs.webkit.org/show_bug.cgi?id=138334>), however for tests, we want to start each one with a clean state. - WKBundleFrameFocus(frame); - JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame); WebCoreTestSupport::resetInternalsObject(context); assignedUrlsCache.clear(); @@ -464,7 +457,7 @@ static void dumpLoadEvent(WKBundleFrameRef frame, const char* eventName) stringBuilder.appendLiteral(" - "); stringBuilder.append(eventName); stringBuilder.append('\n'); - InjectedBundle::singleton().outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } static inline void dumpRequestDescriptionSuitableForTestResult(WKURLRequestRef request, StringBuilder& stringBuilder) @@ -653,61 +646,49 @@ bool InjectedBundlePage::shouldCacheResponse(WKBundlePageRef page, WKBundleFrame void InjectedBundlePage::didStartProvisionalLoadForFrame(WKBundleFrameRef frame) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->testURL()) { - WKRetainPtr<WKURLRef> testURL = adoptWK(WKBundleFrameCopyProvisionalURL(frame)); - injectedBundle.testRunner()->setTestURL(testURL.get()); - } - platformDidStartProvisionalLoadForFrame(frame); - if (injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) + if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) dumpLoadEvent(frame, "didStartProvisionalLoadForFrame"); - if (!injectedBundle.topLoadingFrame()) - injectedBundle.setTopLoadingFrame(frame); + if (!InjectedBundle::shared().topLoadingFrame()) + InjectedBundle::shared().setTopLoadingFrame(frame); - if (injectedBundle.testRunner()->shouldStopProvisionalFrameLoads()) + if (InjectedBundle::shared().testRunner()->shouldStopProvisionalFrameLoads()) dumpLoadEvent(frame, "stopping load in didStartProvisionalLoadForFrame callback"); } void InjectedBundlePage::didReceiveServerRedirectForProvisionalLoadForFrame(WKBundleFrameRef frame) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) + if (!InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) return; dumpLoadEvent(frame, "didReceiveServerRedirectForProvisionalLoadForFrame"); } -void InjectedBundlePage::didFailProvisionalLoadWithErrorForFrame(WKBundleFrameRef frame, WKErrorRef error) +void InjectedBundlePage::didFailProvisionalLoadWithErrorForFrame(WKBundleFrameRef frame, WKErrorRef) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) { + if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) dumpLoadEvent(frame, "didFailProvisionalLoadWithError"); - if (WKErrorGetErrorCode(error) == kWKErrorCodeCannotShowURL) - dumpLoadEvent(frame, "(kWKErrorCodeCannotShowURL)"); - } frameDidChangeLocation(frame); } void InjectedBundlePage::didCommitLoadForFrame(WKBundleFrameRef frame) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) + if (!InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) return; dumpLoadEvent(frame, "didCommitLoadForFrame"); @@ -715,14 +696,13 @@ void InjectedBundlePage::didCommitLoadForFrame(WKBundleFrameRef frame) void InjectedBundlePage::didFinishProgress() { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->shouldDumpProgressFinishedCallback()) + if (!InjectedBundle::shared().testRunner()->shouldDumpProgressFinishedCallback()) return; - injectedBundle.outputText("postProgressFinishedNotification\n"); + InjectedBundle::shared().outputText("postProgressFinishedNotification\n"); } enum FrameNamePolicy { ShouldNotIncludeFrameName, ShouldIncludeFrameName }; @@ -843,8 +823,9 @@ void InjectedBundlePage::dumpDOMAsWebArchive(WKBundleFrameRef frame, StringBuild void InjectedBundlePage::dump() { - auto& injectedBundle = InjectedBundle::singleton(); - ASSERT(injectedBundle.isTestRunning()); + ASSERT(InjectedBundle::shared().isTestRunning()); + + InjectedBundle::shared().testRunner()->invalidateWaitToDumpWatchdogTimer(); // Force a paint before dumping. This matches DumpRenderTree on Windows. (DumpRenderTree on Mac // does this at a slightly different time.) See <http://webkit.org/b/55469> for details. @@ -855,13 +836,13 @@ void InjectedBundlePage::dump() String url = toWTFString(adoptWK(WKURLCopyString(urlRef.get()))); WKRetainPtr<WKStringRef> mimeType = adoptWK(WKBundleFrameCopyMIMETypeForResourceWithURL(frame, urlRef.get())); if (url.find("dumpAsText/") != notFound || WKStringIsEqualToUTF8CString(mimeType.get(), "text/plain")) - injectedBundle.testRunner()->dumpAsText(false); + InjectedBundle::shared().testRunner()->dumpAsText(false); StringBuilder stringBuilder; - switch (injectedBundle.testRunner()->whatToDump()) { + switch (InjectedBundle::shared().testRunner()->whatToDump()) { case TestRunner::RenderTree: { - if (injectedBundle.testRunner()->isPrinting()) + if (InjectedBundle::shared().testRunner()->isPrinting()) stringBuilder.append(toWTFString(adoptWK(WKBundlePageCopyRenderTreeExternalRepresentationForPrinting(m_page)).get())); else stringBuilder.append(toWTFString(adoptWK(WKBundlePageCopyRenderTreeExternalRepresentation(m_page)).get())); @@ -880,35 +861,34 @@ void InjectedBundlePage::dump() break; } - if (injectedBundle.testRunner()->shouldDumpAllFrameScrollPositions()) + if (InjectedBundle::shared().testRunner()->shouldDumpAllFrameScrollPositions()) dumpAllFrameScrollPositions(stringBuilder); - else if (injectedBundle.testRunner()->shouldDumpMainFrameScrollPosition()) + else if (InjectedBundle::shared().testRunner()->shouldDumpMainFrameScrollPosition()) dumpFrameScrollPosition(WKBundlePageGetMainFrame(m_page), stringBuilder); - if (injectedBundle.testRunner()->shouldDumpBackForwardListsForAllWindows()) - injectedBundle.dumpBackForwardListsForAllPages(stringBuilder); + if (InjectedBundle::shared().testRunner()->shouldDumpBackForwardListsForAllWindows()) + InjectedBundle::shared().dumpBackForwardListsForAllPages(stringBuilder); - if (injectedBundle.shouldDumpPixels() && injectedBundle.testRunner()->shouldDumpPixels()) { + if (InjectedBundle::shared().shouldDumpPixels() && InjectedBundle::shared().testRunner()->shouldDumpPixels()) { WKSnapshotOptions options = kWKSnapshotOptionsShareable | kWKSnapshotOptionsInViewCoordinates; - if (injectedBundle.testRunner()->shouldDumpSelectionRect()) + if (InjectedBundle::shared().testRunner()->shouldDumpSelectionRect()) options |= kWKSnapshotOptionsPaintSelectionRectangle; - injectedBundle.setPixelResult(adoptWK(WKBundlePageCreateSnapshotWithOptions(m_page, WKBundleFrameGetVisibleContentBounds(WKBundlePageGetMainFrame(m_page)), options)).get()); + InjectedBundle::shared().setPixelResult(adoptWK(WKBundlePageCreateSnapshotWithOptions(m_page, WKBundleFrameGetVisibleContentBounds(WKBundlePageGetMainFrame(m_page)), options)).get()); if (WKBundlePageIsTrackingRepaints(m_page)) - injectedBundle.setRepaintRects(adoptWK(WKBundlePageCopyTrackedRepaintRects(m_page)).get()); + InjectedBundle::shared().setRepaintRects(adoptWK(WKBundlePageCopyTrackedRepaintRects(m_page)).get()); } - injectedBundle.outputText(stringBuilder.toString()); - injectedBundle.done(); + InjectedBundle::shared().outputText(stringBuilder.toString()); + InjectedBundle::shared().done(); } void InjectedBundlePage::didFinishLoadForFrame(WKBundleFrameRef frame) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) + if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) dumpLoadEvent(frame, "didFinishLoadForFrame"); frameDidChangeLocation(frame, /*shouldDump*/ true); @@ -916,11 +896,10 @@ void InjectedBundlePage::didFinishLoadForFrame(WKBundleFrameRef frame) void InjectedBundlePage::didFailLoadWithErrorForFrame(WKBundleFrameRef frame, WKErrorRef) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) + if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) dumpLoadEvent(frame, "didFailLoadWithError"); frameDidChangeLocation(frame); @@ -928,31 +907,29 @@ void InjectedBundlePage::didFailLoadWithErrorForFrame(WKBundleFrameRef frame, WK void InjectedBundlePage::didReceiveTitleForFrame(WKStringRef title, WKBundleFrameRef frame) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; StringBuilder stringBuilder; - if (injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) { + if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) { dumpFrameDescriptionSuitableForTestResult(frame, stringBuilder); stringBuilder.appendLiteral(" - didReceiveTitle: "); stringBuilder.append(toWTFString(title)); stringBuilder.append('\n'); } - if (injectedBundle.testRunner()->shouldDumpTitleChanges()) { + if (InjectedBundle::shared().testRunner()->shouldDumpTitleChanges()) { stringBuilder.appendLiteral("TITLE CHANGED: '"); stringBuilder.append(toWTFString(title)); stringBuilder.appendLiteral("'\n"); } - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } void InjectedBundlePage::didClearWindowForFrame(WKBundleFrameRef frame, WKBundleScriptWorldRef world) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; JSGlobalContextRef context = WKBundleFrameGetJavaScriptContextForWorld(frame, world); @@ -963,23 +940,22 @@ void InjectedBundlePage::didClearWindowForFrame(WKBundleFrameRef frame, WKBundle return; } - JSValueRef exception = nullptr; - injectedBundle.testRunner()->makeWindowObject(context, window, &exception); - injectedBundle.gcController()->makeWindowObject(context, window, &exception); - injectedBundle.eventSendingController()->makeWindowObject(context, window, &exception); - injectedBundle.textInputController()->makeWindowObject(context, window, &exception); - injectedBundle.accessibilityController()->makeWindowObject(context, window, &exception); + JSValueRef exception = 0; + InjectedBundle::shared().testRunner()->makeWindowObject(context, window, &exception); + InjectedBundle::shared().gcController()->makeWindowObject(context, window, &exception); + InjectedBundle::shared().eventSendingController()->makeWindowObject(context, window, &exception); + InjectedBundle::shared().textInputController()->makeWindowObject(context, window, &exception); + InjectedBundle::shared().accessibilityController()->makeWindowObject(context, window, &exception); WebCoreTestSupport::injectInternalsObject(context); } void InjectedBundlePage::didCancelClientRedirectForFrame(WKBundleFrameRef frame) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) + if (!InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) return; dumpLoadEvent(frame, "didCancelClientRedirectForFrame"); @@ -987,11 +963,10 @@ void InjectedBundlePage::didCancelClientRedirectForFrame(WKBundleFrameRef frame) void InjectedBundlePage::willPerformClientRedirectForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKURLRef url, double delay, double date) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) + if (!InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) return; StringBuilder stringBuilder; @@ -999,31 +974,19 @@ void InjectedBundlePage::willPerformClientRedirectForFrame(WKBundlePageRef, WKBu stringBuilder.appendLiteral(" - willPerformClientRedirectToURL: "); stringBuilder.append(pathSuitableForTestResult(url)); stringBuilder.appendLiteral(" \n"); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } void InjectedBundlePage::didSameDocumentNavigationForFrame(WKBundleFrameRef frame, WKSameDocumentNavigationType type) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) - return; - - if (!injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) - return; - - if (type != kWKSameDocumentNavigationAnchorNavigation) - return; - - dumpLoadEvent(frame, "didChangeLocationWithinPageForFrame"); } void InjectedBundlePage::didFinishDocumentLoadForFrame(WKBundleFrameRef frame) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) + if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) dumpLoadEvent(frame, "didFinishDocumentLoadForFrame"); unsigned pendingFrameUnloadEvents = WKBundleFrameGetPendingUnloadCount(frame); @@ -1033,44 +996,40 @@ void InjectedBundlePage::didFinishDocumentLoadForFrame(WKBundleFrameRef frame) stringBuilder.appendLiteral(" - has "); stringBuilder.appendNumber(pendingFrameUnloadEvents); stringBuilder.appendLiteral(" onunload handler(s)\n"); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } } void InjectedBundlePage::didHandleOnloadEventsForFrame(WKBundleFrameRef frame) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) + if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) dumpLoadEvent(frame, "didHandleOnloadEventsForFrame"); } -void InjectedBundlePage::didDisplayInsecureContentForFrame(WKBundleFrameRef) +void InjectedBundlePage::didDisplayInsecureContentForFrame(WKBundleFrameRef frame) { - auto& injectedBundle = InjectedBundle::singleton(); - if (injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) - injectedBundle.outputText("didDisplayInsecureContent\n"); + if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) + InjectedBundle::shared().outputText("didDisplayInsecureContent\n"); } -void InjectedBundlePage::didRunInsecureContentForFrame(WKBundleFrameRef) +void InjectedBundlePage::didRunInsecureContentForFrame(WKBundleFrameRef frame) { - auto& injectedBundle = InjectedBundle::singleton(); - if (injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) - injectedBundle.outputText("didRunInsecureContent\n"); + if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) + InjectedBundle::shared().outputText("didRunInsecureContent\n"); } -void InjectedBundlePage::didDetectXSSForFrame(WKBundleFrameRef) +void InjectedBundlePage::didDetectXSSForFrame(WKBundleFrameRef frame) { - auto& injectedBundle = InjectedBundle::singleton(); - if (injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) - injectedBundle.outputText("didDetectXSS\n"); + if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) + InjectedBundle::shared().outputText("didDetectXSS\n"); } void InjectedBundlePage::didInitiateLoadForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLRequestRef request, bool) { - if (!InjectedBundle::singleton().isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; WKRetainPtr<WKURLRef> url = adoptWK(WKURLRequestCopyURL(request)); @@ -1089,16 +1048,10 @@ static inline bool isHTTPOrHTTPSScheme(WKStringRef scheme) return WKStringIsEqualToUTF8CStringIgnoringCase(scheme, "http") || WKStringIsEqualToUTF8CStringIgnoringCase(scheme, "https"); } -static inline bool isAllowedHost(WKStringRef host) -{ - return InjectedBundle::singleton().isAllowedHost(host); -} - WKURLRequestRef InjectedBundlePage::willSendRequestForFrame(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKURLRequestRef request, WKURLResponseRef response) { - auto& injectedBundle = InjectedBundle::singleton(); - if (injectedBundle.isTestRunning() - && injectedBundle.testRunner()->shouldDumpResourceLoadCallbacks()) { + if (InjectedBundle::shared().isTestRunning() + && InjectedBundle::shared().testRunner()->shouldDumpResourceLoadCallbacks()) { StringBuilder stringBuilder; dumpResourceURL(identifier, stringBuilder); stringBuilder.appendLiteral(" - willSendRequest "); @@ -1106,16 +1059,16 @@ WKURLRequestRef InjectedBundlePage::willSendRequestForFrame(WKBundlePageRef page stringBuilder.appendLiteral(" redirectResponse "); dumpResponseDescriptionSuitableForTestResult(response, stringBuilder); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } - if (injectedBundle.isTestRunning() && injectedBundle.testRunner()->willSendRequestReturnsNull()) - return nullptr; + if (InjectedBundle::shared().isTestRunning() && InjectedBundle::shared().testRunner()->willSendRequestReturnsNull()) + return 0; WKRetainPtr<WKURLRef> redirectURL = adoptWK(WKURLResponseCopyURL(response)); - if (injectedBundle.isTestRunning() && injectedBundle.testRunner()->willSendRequestReturnsNullOnRedirect() && redirectURL) { - injectedBundle.outputText("Returning null for this redirect\n"); - return nullptr; + if (InjectedBundle::shared().isTestRunning() && InjectedBundle::shared().testRunner()->willSendRequestReturnsNullOnRedirect() && redirectURL) { + InjectedBundle::shared().outputText("Returning null for this redirect\n"); + return 0; } WKRetainPtr<WKURLRef> url = adoptWK(WKURLRequestCopyURL(request)); @@ -1127,23 +1080,23 @@ WKURLRequestRef InjectedBundlePage::willSendRequestForFrame(WKBundlePageRef page && !WKStringIsEqualToUTF8CString(host.get(), "255.255.255.255") // Used in some tests that expect to get back an error. && !isLocalHost(host.get())) { bool mainFrameIsExternal = false; - if (injectedBundle.isTestRunning()) { - WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(m_page); + if (InjectedBundle::shared().isTestRunning()) { + WKBundleFrameRef mainFrame = InjectedBundle::shared().topLoadingFrame(); WKRetainPtr<WKURLRef> mainFrameURL = adoptWK(WKBundleFrameCopyURL(mainFrame)); if (!mainFrameURL || WKStringIsEqualToUTF8CString(adoptWK(WKURLCopyString(mainFrameURL.get())).get(), "about:blank")) mainFrameURL = adoptWK(WKBundleFrameCopyProvisionalURL(mainFrame)); - WKRetainPtr<WKStringRef> mainFrameHost = adoptWK(WKURLCopyHostName(mainFrameURL.get())); - WKRetainPtr<WKStringRef> mainFrameScheme = adoptWK(WKURLCopyScheme(mainFrameURL.get())); + WKRetainPtr<WKStringRef> mainFrameHost = WKURLCopyHostName(mainFrameURL.get()); + WKRetainPtr<WKStringRef> mainFrameScheme = WKURLCopyScheme(mainFrameURL.get()); mainFrameIsExternal = isHTTPOrHTTPSScheme(mainFrameScheme.get()) && !isLocalHost(mainFrameHost.get()); } - if (!mainFrameIsExternal && !isAllowedHost(host.get())) { + if (!mainFrameIsExternal) { StringBuilder stringBuilder; stringBuilder.appendLiteral("Blocked access to external URL "); stringBuilder.append(toWTFString(urlString)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); - return nullptr; + InjectedBundle::shared().outputText(stringBuilder.toString()); + return 0; } } @@ -1153,21 +1106,20 @@ WKURLRequestRef InjectedBundlePage::willSendRequestForFrame(WKBundlePageRef page void InjectedBundlePage::didReceiveResponseForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLResponseRef response) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (injectedBundle.testRunner()->shouldDumpResourceLoadCallbacks()) { + if (InjectedBundle::shared().testRunner()->shouldDumpResourceLoadCallbacks()) { StringBuilder stringBuilder; dumpResourceURL(identifier, stringBuilder); stringBuilder.appendLiteral(" - didReceiveResponse "); dumpResponseDescriptionSuitableForTestResult(response, stringBuilder); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } - if (!injectedBundle.testRunner()->shouldDumpResourceResponseMIMETypes()) + if (!InjectedBundle::shared().testRunner()->shouldDumpResourceResponseMIMETypes()) return; WKRetainPtr<WKURLRef> url = adoptWK(WKURLResponseCopyURL(response)); @@ -1178,16 +1130,8 @@ void InjectedBundlePage::didReceiveResponseForResource(WKBundlePageRef page, WKB stringBuilder.append(toWTFString(urlString)); stringBuilder.appendLiteral(" has MIME type "); stringBuilder.append(toWTFString(mimeTypeString)); - - String platformMimeType = platformResponseMimeType(response); - if (!platformMimeType.isEmpty() && platformMimeType != toWTFString(mimeTypeString)) { - stringBuilder.appendLiteral(" but platform response has "); - stringBuilder.append(platformMimeType); - } - stringBuilder.append('\n'); - - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } void InjectedBundlePage::didReceiveContentLengthForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t, uint64_t) @@ -1196,26 +1140,24 @@ void InjectedBundlePage::didReceiveContentLengthForResource(WKBundlePageRef, WKB void InjectedBundlePage::didFinishLoadForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->shouldDumpResourceLoadCallbacks()) + if (!InjectedBundle::shared().testRunner()->shouldDumpResourceLoadCallbacks()) return; StringBuilder stringBuilder; dumpResourceURL(identifier, stringBuilder); stringBuilder.appendLiteral(" - didFinishLoading\n"); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } void InjectedBundlePage::didFailLoadForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKErrorRef error) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->shouldDumpResourceLoadCallbacks()) + if (!InjectedBundle::shared().testRunner()->shouldDumpResourceLoadCallbacks()) return; StringBuilder stringBuilder; @@ -1224,22 +1166,21 @@ void InjectedBundlePage::didFailLoadForResource(WKBundlePageRef, WKBundleFrameRe dumpErrorDescriptionSuitableForTestResult(error, stringBuilder); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } bool InjectedBundlePage::shouldCacheResponse(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return true; - if (!injectedBundle.testRunner()->shouldDumpWillCacheResponse()) + if (!InjectedBundle::shared().testRunner()->shouldDumpWillCacheResponse()) return true; StringBuilder stringBuilder; stringBuilder.appendNumber(identifier); stringBuilder.appendLiteral(" - willCacheResponse: called\n"); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); // The default behavior is the cache the response. return true; @@ -1270,23 +1211,10 @@ void InjectedBundlePage::unableToImplementPolicy(WKBundlePageRef page, WKBundleF WKBundlePagePolicyAction InjectedBundlePage::decidePolicyForNavigationAction(WKBundlePageRef page, WKBundleFrameRef frame, WKBundleNavigationActionRef navigationAction, WKURLRequestRef request, WKTypeRef* userData) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return WKBundlePagePolicyActionUse; - if (injectedBundle.testRunner()->shouldDumpPolicyCallbacks()) { - StringBuilder stringBuilder; - stringBuilder.appendLiteral(" - decidePolicyForNavigationAction \n"); - dumpRequestDescriptionSuitableForTestResult(request, stringBuilder); - stringBuilder.appendLiteral(" is main frame - "); - stringBuilder.append(WKBundleFrameIsMainFrame(frame) ? "yes" : "no"); - stringBuilder.appendLiteral(" should open URLs externally - "); - stringBuilder.append(WKBundleNavigationActionGetShouldOpenExternalURLs(navigationAction) ? "yes" : "no"); - stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); - } - - if (!injectedBundle.testRunner()->isPolicyDelegateEnabled()) + if (!InjectedBundle::shared().testRunner()->isPolicyDelegateEnabled()) return WKBundlePagePolicyActionUse; WKRetainPtr<WKURLRef> url = adoptWK(WKURLRequestCopyURL(request)); @@ -1311,10 +1239,10 @@ WKBundlePagePolicyAction InjectedBundlePage::decidePolicyForNavigationAction(WKB } stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); - injectedBundle.testRunner()->notifyDone(); + InjectedBundle::shared().outputText(stringBuilder.toString()); + InjectedBundle::shared().testRunner()->notifyDone(); - if (injectedBundle.testRunner()->isPolicyDelegatePermissive()) + if (InjectedBundle::shared().testRunner()->isPolicyDelegatePermissive()) return WKBundlePagePolicyActionUse; return WKBundlePagePolicyActionPassThrough; } @@ -1326,13 +1254,13 @@ WKBundlePagePolicyAction InjectedBundlePage::decidePolicyForNewWindowAction(WKBu WKBundlePagePolicyAction InjectedBundlePage::decidePolicyForResponse(WKBundlePageRef page, WKBundleFrameRef, WKURLResponseRef response, WKURLRequestRef, WKTypeRef*) { - if (InjectedBundle::singleton().testRunner()->isPolicyDelegateEnabled() && WKURLResponseIsAttachment(response)) { + if (WKURLResponseIsAttachment(response)) { StringBuilder stringBuilder; WKRetainPtr<WKStringRef> filename = adoptWK(WKURLResponseCopySuggestedFilename(response)); stringBuilder.appendLiteral("Policy delegate: resource is an attachment, suggested file name \'"); stringBuilder.append(toWTFString(filename)); stringBuilder.appendLiteral("\'\n"); - InjectedBundle::singleton().outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } WKRetainPtr<WKStringRef> mimeType = adoptWK(WKURLResponseCopyMIMEType(response)); @@ -1402,8 +1330,7 @@ static WTF::String lastFileURLPathComponent(const WTF::String& path) void InjectedBundlePage::willAddMessageToConsole(WKStringRef message, uint32_t lineNumber) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; WTF::String messageString = toWTFString(message); @@ -1425,49 +1352,46 @@ void InjectedBundlePage::willAddMessageToConsole(WKStringRef message, uint32_t l } stringBuilder.append(messageString); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } void InjectedBundlePage::willSetStatusbarText(WKStringRef statusbarText) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->shouldDumpStatusCallbacks()) + if (!InjectedBundle::shared().testRunner()->shouldDumpStatusCallbacks()) return; StringBuilder stringBuilder; stringBuilder.appendLiteral("UI DELEGATE STATUS CALLBACK: setStatusText:"); stringBuilder.append(toWTFString(statusbarText)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } void InjectedBundlePage::willRunJavaScriptAlert(WKStringRef message, WKBundleFrameRef) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; StringBuilder stringBuilder; stringBuilder.appendLiteral("ALERT: "); stringBuilder.append(toWTFString(message)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } void InjectedBundlePage::willRunJavaScriptConfirm(WKStringRef message, WKBundleFrameRef) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; StringBuilder stringBuilder; stringBuilder.appendLiteral("CONFIRM: "); stringBuilder.append(toWTFString(message)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } void InjectedBundlePage::willRunJavaScriptPrompt(WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef) @@ -1478,13 +1402,12 @@ void InjectedBundlePage::willRunJavaScriptPrompt(WKStringRef message, WKStringRe stringBuilder.appendLiteral(", default text: "); stringBuilder.append(toWTFString(defaultValue)); stringBuilder.append('\n'); - InjectedBundle::singleton().outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } void InjectedBundlePage::didReachApplicationCacheOriginQuota(WKSecurityOriginRef origin, int64_t totalBytesNeeded) { - auto& injectedBundle = InjectedBundle::singleton(); - if (injectedBundle.testRunner()->shouldDumpApplicationCacheDelegateCallbacks()) { + if (InjectedBundle::shared().testRunner()->shouldDumpApplicationCacheDelegateCallbacks()) { // For example, numbers from 30000 - 39999 will output as 30000. // Rounding up or down does not really matter for these tests. It's // sufficient to just get a range of 10000 to determine if we were @@ -1497,37 +1420,36 @@ void InjectedBundlePage::didReachApplicationCacheOriginQuota(WKSecurityOriginRef stringBuilder.appendLiteral(" totalSpaceNeeded:~"); stringBuilder.appendNumber(truncatedSpaceNeeded); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } - if (injectedBundle.testRunner()->shouldDisallowIncreaseForApplicationCacheQuota()) + if (InjectedBundle::shared().testRunner()->shouldDisallowIncreaseForApplicationCacheQuota()) return; // Reset default application cache quota. - WKBundleResetApplicationCacheOriginQuota(injectedBundle.bundle(), adoptWK(WKSecurityOriginCopyToString(origin)).get()); + WKBundleResetApplicationCacheOriginQuota(InjectedBundle::shared().bundle(), adoptWK(WKSecurityOriginCopyToString(origin)).get()); } uint64_t InjectedBundlePage::didExceedDatabaseQuota(WKSecurityOriginRef origin, WKStringRef databaseName, WKStringRef databaseDisplayName, uint64_t currentQuotaBytes, uint64_t currentOriginUsageBytes, uint64_t currentDatabaseUsageBytes, uint64_t expectedUsageBytes) { - auto& injectedBundle = InjectedBundle::singleton(); - if (injectedBundle.testRunner()->shouldDumpDatabaseCallbacks()) { + if (InjectedBundle::shared().testRunner()->shouldDumpDatabaseCallbacks()) { StringBuilder stringBuilder; stringBuilder.appendLiteral("UI DELEGATE DATABASE CALLBACK: exceededDatabaseQuotaForSecurityOrigin:"); stringBuilder.append(securityOriginToStr(origin)); stringBuilder.appendLiteral(" database:"); stringBuilder.append(toWTFString(databaseName)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } uint64_t defaultQuota = 5 * 1024 * 1024; - double testDefaultQuota = injectedBundle.testRunner()->databaseDefaultQuota(); + double testDefaultQuota = InjectedBundle::shared().testRunner()->databaseDefaultQuota(); if (testDefaultQuota >= 0) defaultQuota = testDefaultQuota; unsigned long long newQuota = defaultQuota; - double maxQuota = injectedBundle.testRunner()->databaseMaxQuota(); + double maxQuota = InjectedBundle::shared().testRunner()->databaseMaxQuota(); if (maxQuota >= 0) { if (defaultQuota < expectedUsageBytes && expectedUsageBytes <= maxQuota) { newQuota = expectedUsageBytes; @@ -1536,7 +1458,7 @@ uint64_t InjectedBundlePage::didExceedDatabaseQuota(WKSecurityOriginRef origin, stringBuilder.appendLiteral("UI DELEGATE DATABASE CALLBACK: increased quota to "); stringBuilder.appendNumber(newQuota); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } } return newQuota; @@ -1601,40 +1523,37 @@ void InjectedBundlePage::didChangeSelection(WKBundlePageRef page, WKStringRef no bool InjectedBundlePage::shouldBeginEditing(WKBundleRangeHandleRef range) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return true; - if (injectedBundle.testRunner()->shouldDumpEditingCallbacks()) { + if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) { StringBuilder stringBuilder; stringBuilder.appendLiteral("EDITING DELEGATE: shouldBeginEditingInDOMRange:"); stringBuilder.append(rangeToStr(m_page, m_world.get(), range)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } - return injectedBundle.testRunner()->shouldAllowEditing(); + return InjectedBundle::shared().testRunner()->shouldAllowEditing(); } bool InjectedBundlePage::shouldEndEditing(WKBundleRangeHandleRef range) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return true; - if (injectedBundle.testRunner()->shouldDumpEditingCallbacks()) { + if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) { StringBuilder stringBuilder; stringBuilder.appendLiteral("EDITING DELEGATE: shouldEndEditingInDOMRange:"); stringBuilder.append(rangeToStr(m_page, m_world.get(), range)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } - return injectedBundle.testRunner()->shouldAllowEditing(); + return InjectedBundle::shared().testRunner()->shouldAllowEditing(); } bool InjectedBundlePage::shouldInsertNode(WKBundleNodeHandleRef node, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType action) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return true; static const char* insertactionstring[] = { @@ -1643,7 +1562,7 @@ bool InjectedBundlePage::shouldInsertNode(WKBundleNodeHandleRef node, WKBundleRa "WebViewInsertActionDropped", }; - if (injectedBundle.testRunner()->shouldDumpEditingCallbacks()) { + if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) { StringBuilder stringBuilder; stringBuilder.appendLiteral("EDITING DELEGATE: shouldInsertNode:"); stringBuilder.append(dumpPath(m_page, m_world.get(), node)); @@ -1652,15 +1571,14 @@ bool InjectedBundlePage::shouldInsertNode(WKBundleNodeHandleRef node, WKBundleRa stringBuilder.appendLiteral(" givenAction:"); stringBuilder.append(insertactionstring[action]); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } - return injectedBundle.testRunner()->shouldAllowEditing(); + return InjectedBundle::shared().testRunner()->shouldAllowEditing(); } bool InjectedBundlePage::shouldInsertText(WKStringRef text, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType action) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return true; static const char *insertactionstring[] = { @@ -1669,7 +1587,7 @@ bool InjectedBundlePage::shouldInsertText(WKStringRef text, WKBundleRangeHandleR "WebViewInsertActionDropped", }; - if (injectedBundle.testRunner()->shouldDumpEditingCallbacks()) { + if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) { StringBuilder stringBuilder; stringBuilder.appendLiteral("EDITING DELEGATE: shouldInsertText:"); stringBuilder.append(toWTFString(text)); @@ -1678,31 +1596,29 @@ bool InjectedBundlePage::shouldInsertText(WKStringRef text, WKBundleRangeHandleR stringBuilder.appendLiteral(" givenAction:"); stringBuilder.append(insertactionstring[action]); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } - return injectedBundle.testRunner()->shouldAllowEditing(); + return InjectedBundle::shared().testRunner()->shouldAllowEditing(); } bool InjectedBundlePage::shouldDeleteRange(WKBundleRangeHandleRef range) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return true; - if (injectedBundle.testRunner()->shouldDumpEditingCallbacks()) { + if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) { StringBuilder stringBuilder; stringBuilder.appendLiteral("EDITING DELEGATE: shouldDeleteDOMRange:"); stringBuilder.append(rangeToStr(m_page, m_world.get(), range)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } - return injectedBundle.testRunner()->shouldAllowEditing(); + return InjectedBundle::shared().testRunner()->shouldAllowEditing(); } bool InjectedBundlePage::shouldChangeSelectedRange(WKBundleRangeHandleRef fromRange, WKBundleRangeHandleRef toRange, WKAffinityType affinity, bool stillSelecting) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return true; static const char *affinitystring[] = { @@ -1714,7 +1630,7 @@ bool InjectedBundlePage::shouldChangeSelectedRange(WKBundleRangeHandleRef fromRa "TRUE" }; - if (injectedBundle.testRunner()->shouldDumpEditingCallbacks()) { + if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) { StringBuilder stringBuilder; stringBuilder.appendLiteral("EDITING DELEGATE: shouldChangeSelectedDOMRange:"); stringBuilder.append(rangeToStr(m_page, m_world.get(), fromRange)); @@ -1725,105 +1641,98 @@ bool InjectedBundlePage::shouldChangeSelectedRange(WKBundleRangeHandleRef fromRa stringBuilder.appendLiteral(" stillSelecting:"); stringBuilder.append(boolstring[stillSelecting]); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } - return injectedBundle.testRunner()->shouldAllowEditing(); + return InjectedBundle::shared().testRunner()->shouldAllowEditing(); } bool InjectedBundlePage::shouldApplyStyle(WKBundleCSSStyleDeclarationRef style, WKBundleRangeHandleRef range) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return true; - if (injectedBundle.testRunner()->shouldDumpEditingCallbacks()) { + if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) { StringBuilder stringBuilder; stringBuilder.appendLiteral("EDITING DELEGATE: shouldApplyStyle:"); stringBuilder.append(styleDecToStr(style)); stringBuilder.appendLiteral(" toElementsInDOMRange:"); stringBuilder.append(rangeToStr(m_page, m_world.get(), range)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } - return injectedBundle.testRunner()->shouldAllowEditing(); + return InjectedBundle::shared().testRunner()->shouldAllowEditing(); } void InjectedBundlePage::didBeginEditing(WKStringRef notificationName) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->shouldDumpEditingCallbacks()) + if (!InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) return; StringBuilder stringBuilder; stringBuilder.appendLiteral("EDITING DELEGATE: webViewDidBeginEditing:"); stringBuilder.append(toWTFString(notificationName)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } void InjectedBundlePage::didEndEditing(WKStringRef notificationName) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->shouldDumpEditingCallbacks()) + if (!InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) return; StringBuilder stringBuilder; stringBuilder.appendLiteral("EDITING DELEGATE: webViewDidEndEditing:"); stringBuilder.append(toWTFString(notificationName)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } void InjectedBundlePage::didChange(WKStringRef notificationName) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->shouldDumpEditingCallbacks()) + if (!InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) return; StringBuilder stringBuilder; stringBuilder.appendLiteral("EDITING DELEGATE: webViewDidChange:"); stringBuilder.append(toWTFString(notificationName)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } void InjectedBundlePage::didChangeSelection(WKStringRef notificationName) { - auto& injectedBundle = InjectedBundle::singleton(); - if (!injectedBundle.isTestRunning()) + if (!InjectedBundle::shared().isTestRunning()) return; - if (!injectedBundle.testRunner()->shouldDumpEditingCallbacks()) + if (!InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) return; StringBuilder stringBuilder; stringBuilder.appendLiteral("EDITING DELEGATE: webViewDidChangeSelection:"); stringBuilder.append(toWTFString(notificationName)); stringBuilder.append('\n'); - injectedBundle.outputText(stringBuilder.toString()); + InjectedBundle::shared().outputText(stringBuilder.toString()); } #if ENABLE(FULLSCREEN_API) bool InjectedBundlePage::supportsFullScreen(WKBundlePageRef pageRef, WKFullScreenKeyboardRequestType requestType) { - auto& injectedBundle = InjectedBundle::singleton(); - if (injectedBundle.testRunner()->shouldDumpFullScreenCallbacks()) - injectedBundle.outputText("supportsFullScreen() == true\n"); + if (InjectedBundle::shared().testRunner()->shouldDumpFullScreenCallbacks()) + InjectedBundle::shared().outputText("supportsFullScreen() == true\n"); return true; } void InjectedBundlePage::enterFullScreenForElement(WKBundlePageRef pageRef, WKBundleNodeHandleRef elementRef) { - auto& injectedBundle = InjectedBundle::singleton(); - if (injectedBundle.testRunner()->shouldDumpFullScreenCallbacks()) - injectedBundle.outputText("enterFullScreenForElement()\n"); + if (InjectedBundle::shared().testRunner()->shouldDumpFullScreenCallbacks()) + InjectedBundle::shared().outputText("enterFullScreenForElement()\n"); - if (!injectedBundle.testRunner()->hasCustomFullScreenBehavior()) { + if (!InjectedBundle::shared().testRunner()->hasCustomFullScreenBehavior()) { WKBundlePageWillEnterFullScreen(pageRef); WKBundlePageDidEnterFullScreen(pageRef); } @@ -1831,11 +1740,10 @@ void InjectedBundlePage::enterFullScreenForElement(WKBundlePageRef pageRef, WKBu void InjectedBundlePage::exitFullScreenForElement(WKBundlePageRef pageRef, WKBundleNodeHandleRef elementRef) { - auto& injectedBundle = InjectedBundle::singleton(); - if (injectedBundle.testRunner()->shouldDumpFullScreenCallbacks()) - injectedBundle.outputText("exitFullScreenForElement()\n"); + if (InjectedBundle::shared().testRunner()->shouldDumpFullScreenCallbacks()) + InjectedBundle::shared().outputText("exitFullScreenForElement()\n"); - if (!injectedBundle.testRunner()->hasCustomFullScreenBehavior()) { + if (!InjectedBundle::shared().testRunner()->hasCustomFullScreenBehavior()) { WKBundlePageWillExitFullScreen(pageRef); WKBundlePageDidExitFullScreen(pageRef); } @@ -1843,25 +1751,22 @@ void InjectedBundlePage::exitFullScreenForElement(WKBundlePageRef pageRef, WKBun void InjectedBundlePage::beganEnterFullScreen(WKBundlePageRef, WKRect, WKRect) { - auto& injectedBundle = InjectedBundle::singleton(); - if (injectedBundle.testRunner()->shouldDumpFullScreenCallbacks()) - injectedBundle.outputText("beganEnterFullScreen()\n"); + if (InjectedBundle::shared().testRunner()->shouldDumpFullScreenCallbacks()) + InjectedBundle::shared().outputText("beganEnterFullScreen()\n"); } void InjectedBundlePage::beganExitFullScreen(WKBundlePageRef, WKRect, WKRect) { - auto& injectedBundle = InjectedBundle::singleton(); - if (injectedBundle.testRunner()->shouldDumpFullScreenCallbacks()) - injectedBundle.outputText("beganExitFullScreen()\n"); + if (InjectedBundle::shared().testRunner()->shouldDumpFullScreenCallbacks()) + InjectedBundle::shared().outputText("beganExitFullScreen()\n"); } void InjectedBundlePage::closeFullScreen(WKBundlePageRef pageRef) { - auto& injectedBundle = InjectedBundle::singleton(); - if (injectedBundle.testRunner()->shouldDumpFullScreenCallbacks()) - injectedBundle.outputText("closeFullScreen()\n"); + if (InjectedBundle::shared().testRunner()->shouldDumpFullScreenCallbacks()) + InjectedBundle::shared().outputText("closeFullScreen()\n"); - if (!injectedBundle.testRunner()->hasCustomFullScreenBehavior()) { + if (!InjectedBundle::shared().testRunner()->hasCustomFullScreenBehavior()) { WKBundlePageWillExitFullScreen(pageRef); WKBundlePageDidExitFullScreen(pageRef); } @@ -1957,37 +1862,31 @@ void InjectedBundlePage::dumpBackForwardList(StringBuilder& stringBuilder) stringBuilder.appendLiteral("===============================================\n"); } -#if !PLATFORM(COCOA) +#if !PLATFORM(MAC) void InjectedBundlePage::platformDidStartProvisionalLoadForFrame(WKBundleFrameRef) { } - -String InjectedBundlePage::platformResponseMimeType(WKURLResponseRef) -{ - return String(); -} #endif void InjectedBundlePage::frameDidChangeLocation(WKBundleFrameRef frame, bool shouldDump) { - auto& injectedBundle = InjectedBundle::singleton(); - if (frame != injectedBundle.topLoadingFrame()) + if (frame != InjectedBundle::shared().topLoadingFrame()) return; - injectedBundle.setTopLoadingFrame(nullptr); + InjectedBundle::shared().setTopLoadingFrame(0); - if (injectedBundle.testRunner()->waitToDump()) + if (InjectedBundle::shared().testRunner()->waitToDump()) return; - if (injectedBundle.shouldProcessWorkQueue()) { - injectedBundle.processWorkQueue(); + if (InjectedBundle::shared().shouldProcessWorkQueue()) { + InjectedBundle::shared().processWorkQueue(); return; } if (shouldDump) - injectedBundle.page()->dump(); + InjectedBundle::shared().page()->dump(); else - injectedBundle.done(); + InjectedBundle::shared().done(); } } // namespace WTR |