2 * Copyright (C) 2010-2018 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"
29 #include "ActivateFonts.h"
30 #include "InjectedBundlePage.h"
31 #include "StringFunctions.h"
32 #include "WebCoreTestSupport.h"
33 #include <JavaScriptCore/Options.h>
34 #include <WebKit/WKBundle.h>
35 #include <WebKit/WKBundlePage.h>
36 #include <WebKit/WKBundlePagePrivate.h>
37 #include <WebKit/WKBundlePrivate.h>
38 #include <WebKit/WKRetainPtr.h>
39 #include <WebKit/WebKit2_C.h>
40 #include <wtf/text/CString.h>
41 #include <wtf/text/StringBuilder.h>
42 #include <wtf/Vector.h>
46 static void handleTextDidChangeInTextField(WKBundlePageRef, WKBundleNodeHandleRef, WKBundleFrameRef, const void* context)
48 static_cast<InjectedBundle*>(const_cast<void*>(context))->textDidChangeInTextField();
51 static void handleTextFieldDidBeginEditing(WKBundlePageRef, WKBundleNodeHandleRef, WKBundleFrameRef, const void* context)
53 static_cast<InjectedBundle*>(const_cast<void*>(context))->textFieldDidBeginEditing();
56 static void handleTextFieldDidEndEditing(WKBundlePageRef, WKBundleNodeHandleRef, WKBundleFrameRef, const void* context)
58 static_cast<InjectedBundle*>(const_cast<void*>(context))->textFieldDidEndEditing();
61 InjectedBundle& InjectedBundle::singleton()
63 static InjectedBundle& shared = *new InjectedBundle;
67 void InjectedBundle::didCreatePage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo)
69 static_cast<InjectedBundle*>(const_cast<void*>(clientInfo))->didCreatePage(page);
72 void InjectedBundle::willDestroyPage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo)
74 static_cast<InjectedBundle*>(const_cast<void*>(clientInfo))->willDestroyPage(page);
77 void InjectedBundle::didInitializePageGroup(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, const void* clientInfo)
79 static_cast<InjectedBundle*>(const_cast<void*>(clientInfo))->didInitializePageGroup(pageGroup);
82 void InjectedBundle::didReceiveMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo)
84 static_cast<InjectedBundle*>(const_cast<void*>(clientInfo))->didReceiveMessage(messageName, messageBody);
87 void InjectedBundle::didReceiveMessageToPage(WKBundleRef bundle, WKBundlePageRef page, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo)
89 static_cast<InjectedBundle*>(const_cast<void*>(clientInfo))->didReceiveMessageToPage(page, messageName, messageBody);
92 void InjectedBundle::initialize(WKBundleRef bundle, WKTypeRef initializationUserData)
96 WKBundleClientV1 client = {
100 didInitializePageGroup,
102 didReceiveMessageToPage
104 WKBundleSetClient(m_bundle, &client.base);
105 WKBundleSetServiceWorkerProxyCreationCallback(m_bundle, WebCoreTestSupport::setupNewlyCreatedServiceWorker);
106 platformInitialize(initializationUserData);
111 void InjectedBundle::didCreatePage(WKBundlePageRef page)
113 bool isMainPage = m_pages.isEmpty();
114 m_pages.append(std::make_unique<InjectedBundlePage>(page));
116 setUpInjectedBundleClients(page);
121 WKRetainPtr<WKStringRef> messsageName(AdoptWK, WKStringCreateWithUTF8CString("Initialization"));
122 WKTypeRef result = 0;
123 WKBundlePostSynchronousMessage(m_bundle, messsageName.get(), 0, &result);
124 ASSERT(WKGetTypeID(result) == WKDictionaryGetTypeID());
125 WKDictionaryRef initializationDictionary = static_cast<WKDictionaryRef>(result);
127 WKRetainPtr<WKStringRef> resumeTestingKey(AdoptWK, WKStringCreateWithUTF8CString("ResumeTesting"));
128 WKTypeRef resumeTestingValue = WKDictionaryGetItemForKey(initializationDictionary, resumeTestingKey.get());
129 ASSERT(WKGetTypeID(resumeTestingValue) == WKBooleanGetTypeID());
130 if (WKBooleanGetValue(static_cast<WKBooleanRef>(resumeTestingValue)))
131 beginTesting(initializationDictionary, BegingTestingMode::Resume);
134 void InjectedBundle::willDestroyPage(WKBundlePageRef page)
136 m_pages.removeFirstMatching([page](auto& current) {
137 return current->page() == page;
141 void InjectedBundle::didInitializePageGroup(WKBundlePageGroupRef pageGroup)
143 m_pageGroup = pageGroup;
146 void InjectedBundle::setUpInjectedBundleClients(WKBundlePageRef page)
148 WKBundlePageFormClientV2 formClient = {
150 handleTextFieldDidBeginEditing,
151 handleTextFieldDidEndEditing,
152 handleTextDidChangeInTextField,
153 0, // textDidChangeInTextArea
154 0, // shouldPerformActionInTextField
156 0, // willSendSubmitEvent
157 0, // didFocusTextField
158 0, // shouldNotifyOnFormChanges
159 0, // didAssociateFormControls
161 WKBundlePageSetFormClient(page, &formClient.base);
164 InjectedBundlePage* InjectedBundle::page() const
166 // It might be better to have the UI process send over a reference to the main
167 // page instead of just assuming it's the first one.
168 return m_pages[0].get();
171 void InjectedBundle::resetLocalSettings()
173 setlocale(LC_ALL, "");
176 void InjectedBundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
178 WKRetainPtr<WKStringRef> errorMessageName(AdoptWK, WKStringCreateWithUTF8CString("Error"));
179 WKRetainPtr<WKStringRef> errorMessageBody(AdoptWK, WKStringCreateWithUTF8CString("Unknown"));
180 WKBundlePostMessage(m_bundle, errorMessageName.get(), errorMessageBody.get());
183 static void postGCTask(void* context)
185 WKBundlePageRef page = reinterpret_cast<WKBundlePageRef>(context);
186 InjectedBundle::singleton().reportLiveDocuments(page);
190 void InjectedBundle::reportLiveDocuments(WKBundlePageRef page)
192 const bool excludeDocumentsInPageGroup = true;
193 auto documentURLs = adoptWK(WKBundleGetLiveDocumentURLs(m_bundle, m_pageGroup, excludeDocumentsInPageGroup));
194 auto ackMessageName = adoptWK(WKStringCreateWithUTF8CString("LiveDocuments"));
195 WKBundlePagePostMessage(page, ackMessageName.get(), documentURLs.get());
198 void InjectedBundle::didReceiveMessageToPage(WKBundlePageRef page, WKStringRef messageName, WKTypeRef messageBody)
200 if (WKStringIsEqualToUTF8CString(messageName, "BeginTest")) {
202 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
203 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
205 WKRetainPtr<WKStringRef> dumpPixelsKey(AdoptWK, WKStringCreateWithUTF8CString("DumpPixels"));
206 m_dumpPixels = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, dumpPixelsKey.get())));
208 WKRetainPtr<WKStringRef> useWaitToDumpWatchdogTimerKey(AdoptWK, WKStringCreateWithUTF8CString("UseWaitToDumpWatchdogTimer"));
209 m_useWaitToDumpWatchdogTimer = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, useWaitToDumpWatchdogTimerKey.get())));
211 WKRetainPtr<WKStringRef> timeoutKey(AdoptWK, WKStringCreateWithUTF8CString("Timeout"));
212 m_timeout = Seconds::fromMilliseconds(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, timeoutKey.get()))));
214 WKRetainPtr<WKStringRef> dumpJSConsoleLogInStdErrKey(AdoptWK, WKStringCreateWithUTF8CString("DumpJSConsoleLogInStdErr"));
215 m_dumpJSConsoleLogInStdErr = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, dumpJSConsoleLogInStdErrKey.get())));
217 WKRetainPtr<WKStringRef> ackMessageName(AdoptWK, WKStringCreateWithUTF8CString("Ack"));
218 WKRetainPtr<WKStringRef> ackMessageBody(AdoptWK, WKStringCreateWithUTF8CString("BeginTest"));
219 WKBundlePagePostMessage(page, ackMessageName.get(), ackMessageBody.get());
221 beginTesting(messageBodyDictionary, BegingTestingMode::New);
225 if (WKStringIsEqualToUTF8CString(messageName, "Reset")) {
227 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
228 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
229 WKRetainPtr<WKStringRef> jscOptionsKey(AdoptWK, WKStringCreateWithUTF8CString("JSCOptions"));
230 WKRetainPtr<WKStringRef> jscOptionsString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, jscOptionsKey.get()));
231 if (jscOptionsString) {
232 String options = toWTFString(jscOptionsString);
233 JSC::Options::setOptions(options.utf8().data());
236 WKRetainPtr<WKStringRef> shouldGCKey(AdoptWK, WKStringCreateWithUTF8CString("ShouldGC"));
237 bool shouldGC = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, shouldGCKey.get())));
239 WKBundleGarbageCollectJavaScriptObjects(m_bundle);
241 WKRetainPtr<WKStringRef> allowedHostsKey(AdoptWK, WKStringCreateWithUTF8CString("AllowedHosts"));
242 WKTypeRef allowedHostsValue = WKDictionaryGetItemForKey(messageBodyDictionary, allowedHostsKey.get());
243 if (allowedHostsValue && WKGetTypeID(allowedHostsValue) == WKArrayGetTypeID()) {
244 m_allowedHosts.clear();
246 WKArrayRef allowedHostsArray = static_cast<WKArrayRef>(allowedHostsValue);
247 for (size_t i = 0, size = WKArrayGetSize(allowedHostsArray); i < size; ++i) {
248 WKTypeRef item = WKArrayGetItemAtIndex(allowedHostsArray, i);
249 if (item && WKGetTypeID(item) == WKStringGetTypeID())
250 m_allowedHosts.append(toWTFString(static_cast<WKStringRef>(item)));
255 m_dumpPixels = false;
256 m_pixelResultIsPending = false;
258 resetLocalSettings();
259 TestRunner::removeAllWebNotificationPermissions();
261 InjectedBundle::page()->resetAfterTest();
265 if (WKStringIsEqualToUTF8CString(messageName, "GetLiveDocuments")) {
266 const bool excludeDocumentsInPageGroup = false;
267 auto documentURLs = adoptWK(WKBundleGetLiveDocumentURLs(m_bundle, m_pageGroup, excludeDocumentsInPageGroup));
268 auto ackMessageName = adoptWK(WKStringCreateWithUTF8CString("LiveDocuments"));
269 WKBundlePagePostMessage(page, ackMessageName.get(), documentURLs.get());
273 if (WKStringIsEqualToUTF8CString(messageName, "CheckForWorldLeaks")) {
274 WKBundleReleaseMemory(m_bundle);
276 WKRetain(page); // Balanced by the release in postGCTask.
277 WKBundlePagePostTask(page, postGCTask, (void*)page);
281 if (WKStringIsEqualToUTF8CString(messageName, "CallAddChromeInputFieldCallback")) {
282 m_testRunner->callAddChromeInputFieldCallback();
286 if (WKStringIsEqualToUTF8CString(messageName, "CallRemoveChromeInputFieldCallback")) {
287 m_testRunner->callRemoveChromeInputFieldCallback();
291 if (WKStringIsEqualToUTF8CString(messageName, "CallFocusWebViewCallback")) {
292 m_testRunner->callFocusWebViewCallback();
296 if (WKStringIsEqualToUTF8CString(messageName, "CallSetBackingScaleFactorCallback")) {
297 m_testRunner->callSetBackingScaleFactorCallback();
301 if (WKStringIsEqualToUTF8CString(messageName, "CallDidBeginSwipeCallback")) {
302 m_testRunner->callDidBeginSwipeCallback();
306 if (WKStringIsEqualToUTF8CString(messageName, "CallWillEndSwipeCallback")) {
307 m_testRunner->callWillEndSwipeCallback();
311 if (WKStringIsEqualToUTF8CString(messageName, "CallDidEndSwipeCallback")) {
312 m_testRunner->callDidEndSwipeCallback();
316 if (WKStringIsEqualToUTF8CString(messageName, "CallDidRemoveSwipeSnapshotCallback")) {
317 m_testRunner->callDidRemoveSwipeSnapshotCallback();
321 if (WKStringIsEqualToUTF8CString(messageName, "CallDidClearStatisticsThroughWebsiteDataRemoval")) {
322 m_testRunner->statisticsCallClearThroughWebsiteDataRemovalCallback();
326 if (WKStringIsEqualToUTF8CString(messageName, "CallDidResetStatisticsToConsistentState")) {
327 m_testRunner->statisticsCallDidResetToConsistentStateCallback();
331 if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetBlockCookiesForHost")) {
332 m_testRunner->statisticsCallDidSetBlockCookiesForHostCallback();
336 if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetStatisticsDebugMode")) {
337 m_testRunner->statisticsCallDidSetDebugModeCallback();
341 if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetPrevalentResourceForDebugMode")) {
342 m_testRunner->statisticsCallDidSetPrevalentResourceForDebugModeCallback();
346 if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetLastSeen")) {
347 m_testRunner->statisticsCallDidSetLastSeenCallback();
351 if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetPrevalentResource")) {
352 m_testRunner->statisticsCallDidSetPrevalentResourceCallback();
356 if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetVeryPrevalentResource")) {
357 m_testRunner->statisticsCallDidSetVeryPrevalentResourceCallback();
361 if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetHasHadUserInteraction")) {
362 m_testRunner->statisticsCallDidSetHasHadUserInteractionCallback();
366 if (WKStringIsEqualToUTF8CString(messageName, "CallDidReceiveAllStorageAccessEntries")) {
368 ASSERT(WKGetTypeID(messageBody) == WKArrayGetTypeID());
370 WKArrayRef domainsArray = static_cast<WKArrayRef>(messageBody);
371 auto size = WKArrayGetSize(domainsArray);
372 Vector<String> domains;
373 domains.reserveInitialCapacity(size);
374 for (size_t i = 0; i < size; ++i) {
375 WKTypeRef item = WKArrayGetItemAtIndex(domainsArray, i);
376 if (item && WKGetTypeID(item) == WKStringGetTypeID())
377 domains.append(toWTFString(static_cast<WKStringRef>(item)));
380 m_testRunner->callDidReceiveAllStorageAccessEntriesCallback(domains);
384 if (WKStringIsEqualToUTF8CString(messageName, "CallDidRemoveAllSessionCredentialsCallback")) {
385 m_testRunner->callDidRemoveAllSessionCredentialsCallback();
389 if (WKStringIsEqualToUTF8CString(messageName, "NotifyDownloadDone")) {
390 if (m_testRunner->shouldFinishAfterDownload())
391 m_testRunner->notifyDone();
395 if (WKStringIsEqualToUTF8CString(messageName, "CallUISideScriptCallback")) {
396 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
398 WKRetainPtr<WKStringRef> resultKey(AdoptWK, WKStringCreateWithUTF8CString("Result"));
399 WKRetainPtr<WKStringRef> callbackIDKey(AdoptWK, WKStringCreateWithUTF8CString("CallbackID"));
401 unsigned callbackID = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, callbackIDKey.get())));
403 WKStringRef resultString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, resultKey.get()));
404 auto resultJSString = toJS(resultString);
406 m_testRunner->runUIScriptCallback(callbackID, resultJSString.get());
410 if (WKStringIsEqualToUTF8CString(messageName, "WorkQueueProcessedCallback")) {
411 if (!topLoadingFrame() && !m_testRunner->shouldWaitUntilDone())
412 InjectedBundle::page()->dump();
416 if (WKStringIsEqualToUTF8CString(messageName, "WebsiteDataDeletionForTopPrivatelyOwnedDomainsFinished")) {
417 m_testRunner->statisticsDidModifyDataRecordsCallback();
421 if (WKStringIsEqualToUTF8CString(messageName, "WebsiteDataScanForTopPrivatelyControlledDomainsFinished")) {
422 m_testRunner->statisticsDidScanDataRecordsCallback();
426 if (WKStringIsEqualToUTF8CString(messageName, "ResourceLoadStatisticsTelemetryFinished")) {
427 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
429 unsigned totalPrevalentResources = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, WKStringCreateWithUTF8CString("TotalPrevalentResources"))));
430 unsigned totalPrevalentResourcesWithUserInteraction = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, WKStringCreateWithUTF8CString("TotalPrevalentResourcesWithUserInteraction"))));
431 unsigned top3SubframeUnderTopFrameOrigins = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, WKStringCreateWithUTF8CString("Top3SubframeUnderTopFrameOrigins"))));
433 m_testRunner->statisticsDidRunTelemetryCallback(totalPrevalentResources, totalPrevalentResourcesWithUserInteraction, top3SubframeUnderTopFrameOrigins);
437 if (WKStringIsEqualToUTF8CString(messageName, "DidGetApplicationManifest")) {
438 m_testRunner->didGetApplicationManifest();
442 WKRetainPtr<WKStringRef> errorMessageName(AdoptWK, WKStringCreateWithUTF8CString("Error"));
443 WKRetainPtr<WKStringRef> errorMessageBody(AdoptWK, WKStringCreateWithUTF8CString("Unknown"));
444 WKBundlePagePostMessage(page, errorMessageName.get(), errorMessageBody.get());
447 bool InjectedBundle::booleanForKey(WKDictionaryRef dictionary, const char* key)
449 WKRetainPtr<WKStringRef> wkKey(AdoptWK, WKStringCreateWithUTF8CString(key));
450 WKTypeRef value = WKDictionaryGetItemForKey(dictionary, wkKey.get());
451 if (WKGetTypeID(value) != WKBooleanGetTypeID()) {
452 outputText(makeString("Boolean value for key", key, " not found in dictionary\n"));
455 return WKBooleanGetValue(static_cast<WKBooleanRef>(value));
458 void InjectedBundle::beginTesting(WKDictionaryRef settings, BegingTestingMode testingMode)
462 m_pixelResult.clear();
463 m_repaintRects.clear();
465 m_testRunner = TestRunner::create();
466 m_gcController = GCController::create();
467 m_eventSendingController = EventSendingController::create();
468 m_textInputController = TextInputController::create();
469 #if HAVE(ACCESSIBILITY)
470 m_accessibilityController = AccessibilityController::create();
473 WKBundleSetAllowUniversalAccessFromFileURLs(m_bundle, m_pageGroup, true);
474 WKBundleSetJavaScriptCanAccessClipboard(m_bundle, m_pageGroup, true);
475 WKBundleSetPrivateBrowsingEnabled(m_bundle, m_pageGroup, false);
476 WKBundleSetUseDashboardCompatibilityMode(m_bundle, m_pageGroup, false);
477 WKBundleSetAuthorAndUserStylesEnabled(m_bundle, m_pageGroup, true);
478 WKBundleSetFrameFlatteningEnabled(m_bundle, m_pageGroup, false);
479 WKBundleSetAsyncFrameScrollingEnabled(m_bundle, m_pageGroup, false);
480 WKBundleSetMinimumLogicalFontSize(m_bundle, m_pageGroup, 9);
481 WKBundleSetSpatialNavigationEnabled(m_bundle, m_pageGroup, false);
482 WKBundleSetAllowFileAccessFromFileURLs(m_bundle, m_pageGroup, true);
483 WKBundleSetPopupBlockingEnabled(m_bundle, m_pageGroup, false);
484 WKBundleSetAllowStorageAccessFromFileURLS(m_bundle, m_pageGroup, false);
487 WKBundlePageSetUseTestingViewportConfiguration(page()->page(), !booleanForKey(settings, "UseFlexibleViewport"));
490 m_testRunner->setPluginsEnabled(true);
492 m_testRunner->setUserStyleSheetEnabled(false);
493 m_testRunner->setXSSAuditorEnabled(false);
495 m_testRunner->setWebGL2Enabled(true);
496 m_testRunner->setWebGPUEnabled(true);
498 m_testRunner->setWritableStreamAPIEnabled(true);
499 m_testRunner->setReadableByteStreamAPIEnabled(true);
501 m_testRunner->setEncryptedMediaAPIEnabled(true);
503 m_testRunner->setCloseRemainingWindowsWhenComplete(false);
504 m_testRunner->setAcceptsEditing(true);
505 m_testRunner->setTabKeyCyclesThroughElements(true);
506 m_testRunner->clearTestRunnerCallbacks();
509 m_testRunner->setCustomTimeout(m_timeout);
513 if (testingMode != BegingTestingMode::New)
516 WKBundleClearAllDatabases(m_bundle);
517 WKBundlePageClearApplicationCache(page()->page());
518 WKBundleResetOriginAccessWhitelists(m_bundle);
519 WKBundleClearResourceLoadStatistics(m_bundle);
521 // [WK2] REGRESSION(r128623): It made layout tests extremely slow
522 // https://bugs.webkit.org/show_bug.cgi?id=96862
523 // WKBundleSetDatabaseQuota(m_bundle, 5 * 1024 * 1024);
526 void InjectedBundle::done()
530 m_useWorkQueue = false;
532 page()->stopLoading();
533 setTopLoadingFrame(0);
535 m_testRunner->invalidateWaitToDumpWatchdogTimer();
537 #if HAVE(ACCESSIBILITY)
538 m_accessibilityController->resetToConsistentState();
541 WKRetainPtr<WKStringRef> doneMessageName(AdoptWK, WKStringCreateWithUTF8CString("Done"));
542 WKRetainPtr<WKMutableDictionaryRef> doneMessageBody(AdoptWK, WKMutableDictionaryCreate());
544 WKRetainPtr<WKStringRef> pixelResultIsPendingKey = adoptWK(WKStringCreateWithUTF8CString("PixelResultIsPending"));
545 WKRetainPtr<WKBooleanRef> pixelResultIsPending(AdoptWK, WKBooleanCreate(m_pixelResultIsPending));
546 WKDictionarySetItem(doneMessageBody.get(), pixelResultIsPendingKey.get(), pixelResultIsPending.get());
548 if (!m_pixelResultIsPending) {
549 WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult"));
550 WKDictionarySetItem(doneMessageBody.get(), pixelResultKey.get(), m_pixelResult.get());
553 WKRetainPtr<WKStringRef> repaintRectsKey = adoptWK(WKStringCreateWithUTF8CString("RepaintRects"));
554 WKDictionarySetItem(doneMessageBody.get(), repaintRectsKey.get(), m_repaintRects.get());
556 WKRetainPtr<WKStringRef> audioResultKey = adoptWK(WKStringCreateWithUTF8CString("AudioResult"));
557 WKDictionarySetItem(doneMessageBody.get(), audioResultKey.get(), m_audioResult.get());
559 WKBundlePagePostMessage(page()->page(), doneMessageName.get(), doneMessageBody.get());
566 void InjectedBundle::closeOtherPages()
568 Vector<WKBundlePageRef> pagesToClose;
569 size_t size = m_pages.size();
570 for (size_t i = 1; i < size; ++i)
571 pagesToClose.append(m_pages[i]->page());
572 size = pagesToClose.size();
573 for (size_t i = 0; i < size; ++i)
574 WKBundlePageClose(pagesToClose[i]);
577 void InjectedBundle::dumpBackForwardListsForAllPages(StringBuilder& stringBuilder)
579 size_t size = m_pages.size();
580 for (size_t i = 0; i < size; ++i)
581 m_pages[i]->dumpBackForwardList(stringBuilder);
584 void InjectedBundle::dumpToStdErr(const String& output)
586 if (m_state != Testing)
588 if (output.isEmpty())
590 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("DumpToStdErr"));
591 WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithUTF8CString(output.utf8().data()));
592 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
595 void InjectedBundle::outputText(const String& output)
597 if (m_state != Testing)
599 if (output.isEmpty())
601 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("TextOutput"));
602 WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithUTF8CString(output.utf8().data()));
603 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
606 void InjectedBundle::postNewBeforeUnloadReturnValue(bool value)
608 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("BeforeUnloadReturnValue"));
609 WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
610 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
613 void InjectedBundle::postAddChromeInputField()
615 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("AddChromeInputField"));
616 WKBundlePagePostMessage(page()->page(), messageName.get(), 0);
619 void InjectedBundle::postRemoveChromeInputField()
621 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("RemoveChromeInputField"));
622 WKBundlePagePostMessage(page()->page(), messageName.get(), 0);
625 void InjectedBundle::postFocusWebView()
627 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("FocusWebView"));
628 WKBundlePagePostMessage(page()->page(), messageName.get(), 0);
631 void InjectedBundle::postSetBackingScaleFactor(double backingScaleFactor)
633 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetBackingScaleFactor"));
634 WKRetainPtr<WKDoubleRef> messageBody(AdoptWK, WKDoubleCreate(backingScaleFactor));
635 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
638 void InjectedBundle::postSetWindowIsKey(bool isKey)
640 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetWindowIsKey"));
641 WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(isKey));
642 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), messageBody.get(), 0);
645 void InjectedBundle::postSetViewSize(double width, double height)
647 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetViewSize"));
649 WKRetainPtr<WKStringRef> widthKey(AdoptWK, WKStringCreateWithUTF8CString("width"));
650 WKRetainPtr<WKStringRef> heightKey(AdoptWK, WKStringCreateWithUTF8CString("height"));
652 WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate());
654 WKRetainPtr<WKDoubleRef> widthWK(AdoptWK, WKDoubleCreate(width));
655 WKDictionarySetItem(messageBody.get(), widthKey.get(), widthWK.get());
657 WKRetainPtr<WKDoubleRef> heightWK(AdoptWK, WKDoubleCreate(height));
658 WKDictionarySetItem(messageBody.get(), heightKey.get(), heightWK.get());
660 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), messageBody.get(), 0);
663 void InjectedBundle::postSimulateWebNotificationClick(uint64_t notificationID)
665 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SimulateWebNotificationClick"));
666 WKRetainPtr<WKUInt64Ref> messageBody(AdoptWK, WKUInt64Create(notificationID));
667 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
670 void InjectedBundle::postSetAddsVisitedLinks(bool addsVisitedLinks)
672 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetAddsVisitedLinks"));
673 WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(addsVisitedLinks));
674 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
677 void InjectedBundle::setGeolocationPermission(bool enabled)
679 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetGeolocationPermission"));
680 WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(enabled));
681 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
684 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, bool providesFloorLevel, double floorLevel)
686 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetMockGeolocationPosition"));
688 WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate());
690 WKRetainPtr<WKStringRef> latitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("latitude"));
691 WKRetainPtr<WKDoubleRef> latitudeWK(AdoptWK, WKDoubleCreate(latitude));
692 WKDictionarySetItem(messageBody.get(), latitudeKeyWK.get(), latitudeWK.get());
694 WKRetainPtr<WKStringRef> longitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("longitude"));
695 WKRetainPtr<WKDoubleRef> longitudeWK(AdoptWK, WKDoubleCreate(longitude));
696 WKDictionarySetItem(messageBody.get(), longitudeKeyWK.get(), longitudeWK.get());
698 WKRetainPtr<WKStringRef> accuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("accuracy"));
699 WKRetainPtr<WKDoubleRef> accuracyWK(AdoptWK, WKDoubleCreate(accuracy));
700 WKDictionarySetItem(messageBody.get(), accuracyKeyWK.get(), accuracyWK.get());
702 WKRetainPtr<WKStringRef> providesAltitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesAltitude"));
703 WKRetainPtr<WKBooleanRef> providesAltitudeWK(AdoptWK, WKBooleanCreate(providesAltitude));
704 WKDictionarySetItem(messageBody.get(), providesAltitudeKeyWK.get(), providesAltitudeWK.get());
706 WKRetainPtr<WKStringRef> altitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("altitude"));
707 WKRetainPtr<WKDoubleRef> altitudeWK(AdoptWK, WKDoubleCreate(altitude));
708 WKDictionarySetItem(messageBody.get(), altitudeKeyWK.get(), altitudeWK.get());
710 WKRetainPtr<WKStringRef> providesAltitudeAccuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesAltitudeAccuracy"));
711 WKRetainPtr<WKBooleanRef> providesAltitudeAccuracyWK(AdoptWK, WKBooleanCreate(providesAltitudeAccuracy));
712 WKDictionarySetItem(messageBody.get(), providesAltitudeAccuracyKeyWK.get(), providesAltitudeAccuracyWK.get());
714 WKRetainPtr<WKStringRef> altitudeAccuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("altitudeAccuracy"));
715 WKRetainPtr<WKDoubleRef> altitudeAccuracyWK(AdoptWK, WKDoubleCreate(altitudeAccuracy));
716 WKDictionarySetItem(messageBody.get(), altitudeAccuracyKeyWK.get(), altitudeAccuracyWK.get());
718 WKRetainPtr<WKStringRef> providesHeadingKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesHeading"));
719 WKRetainPtr<WKBooleanRef> providesHeadingWK(AdoptWK, WKBooleanCreate(providesHeading));
720 WKDictionarySetItem(messageBody.get(), providesHeadingKeyWK.get(), providesHeadingWK.get());
722 WKRetainPtr<WKStringRef> headingKeyWK(AdoptWK, WKStringCreateWithUTF8CString("heading"));
723 WKRetainPtr<WKDoubleRef> headingWK(AdoptWK, WKDoubleCreate(heading));
724 WKDictionarySetItem(messageBody.get(), headingKeyWK.get(), headingWK.get());
726 WKRetainPtr<WKStringRef> providesSpeedKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesSpeed"));
727 WKRetainPtr<WKBooleanRef> providesSpeedWK(AdoptWK, WKBooleanCreate(providesSpeed));
728 WKDictionarySetItem(messageBody.get(), providesSpeedKeyWK.get(), providesSpeedWK.get());
730 WKRetainPtr<WKStringRef> speedKeyWK(AdoptWK, WKStringCreateWithUTF8CString("speed"));
731 WKRetainPtr<WKDoubleRef> speedWK(AdoptWK, WKDoubleCreate(speed));
732 WKDictionarySetItem(messageBody.get(), speedKeyWK.get(), speedWK.get());
734 WKRetainPtr<WKStringRef> providesFloorLevelKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesFloorLevel"));
735 WKRetainPtr<WKBooleanRef> providesFloorLevelWK(AdoptWK, WKBooleanCreate(providesFloorLevel));
736 WKDictionarySetItem(messageBody.get(), providesFloorLevelKeyWK.get(), providesFloorLevelWK.get());
738 WKRetainPtr<WKStringRef> floorLevelKeyWK(AdoptWK, WKStringCreateWithUTF8CString("floorLevel"));
739 WKRetainPtr<WKDoubleRef> floorLevelWK(AdoptWK, WKDoubleCreate(floorLevel));
740 WKDictionarySetItem(messageBody.get(), floorLevelKeyWK.get(), floorLevelWK.get());
742 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
745 void InjectedBundle::setMockGeolocationPositionUnavailableError(WKStringRef errorMessage)
747 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetMockGeolocationPositionUnavailableError"));
748 WKBundlePagePostMessage(page()->page(), messageName.get(), errorMessage);
751 bool InjectedBundle::isGeolocationProviderActive() const
753 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("IsGeolocationClientActive"));
754 WKTypeRef resultToPass = 0;
755 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), 0, &resultToPass);
756 WKRetainPtr<WKBooleanRef> isActive(AdoptWK, static_cast<WKBooleanRef>(resultToPass));
758 return WKBooleanGetValue(isActive.get());
761 unsigned InjectedBundle::imageCountInGeneralPasteboard() const
763 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("ImageCountInGeneralPasteboard"));
764 WKTypeRef resultToPass = 0;
765 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), 0, &resultToPass);
766 WKRetainPtr<WKUInt64Ref> imageCount(AdoptWK, static_cast<WKUInt64Ref>(resultToPass));
768 return static_cast<unsigned>(WKUInt64GetValue(imageCount.get()));
771 void InjectedBundle::setUserMediaPermission(bool enabled)
773 auto messageName = adoptWK(WKStringCreateWithUTF8CString("SetUserMediaPermission"));
774 auto messageBody = adoptWK(WKBooleanCreate(enabled));
775 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
778 void InjectedBundle::resetUserMediaPermission()
780 auto messageName = adoptWK(WKStringCreateWithUTF8CString("ResetUserMediaPermission"));
781 WKBundlePagePostMessage(page()->page(), messageName.get(), 0);
784 void InjectedBundle::setUserMediaPersistentPermissionForOrigin(bool permission, WKStringRef origin, WKStringRef parentOrigin)
786 auto messageName = adoptWK(WKStringCreateWithUTF8CString("SetUserMediaPersistentPermissionForOrigin"));
787 WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate());
789 WKRetainPtr<WKStringRef> permissionKeyWK(AdoptWK, WKStringCreateWithUTF8CString("permission"));
790 WKRetainPtr<WKBooleanRef> permissionWK(AdoptWK, WKBooleanCreate(permission));
791 WKDictionarySetItem(messageBody.get(), permissionKeyWK.get(), permissionWK.get());
793 WKRetainPtr<WKStringRef> originKeyWK(AdoptWK, WKStringCreateWithUTF8CString("origin"));
794 WKDictionarySetItem(messageBody.get(), originKeyWK.get(), origin);
796 WKRetainPtr<WKStringRef> parentOriginKeyWK(AdoptWK, WKStringCreateWithUTF8CString("parentOrigin"));
797 WKDictionarySetItem(messageBody.get(), parentOriginKeyWK.get(), parentOrigin);
799 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
802 unsigned InjectedBundle::userMediaPermissionRequestCountForOrigin(WKStringRef origin, WKStringRef parentOrigin) const
804 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("UserMediaPermissionRequestCountForOrigin"));
805 WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate());
807 WKRetainPtr<WKStringRef> originKeyWK(AdoptWK, WKStringCreateWithUTF8CString("origin"));
808 WKDictionarySetItem(messageBody.get(), originKeyWK.get(), origin);
810 WKRetainPtr<WKStringRef> parentOriginKeyWK(AdoptWK, WKStringCreateWithUTF8CString("parentOrigin"));
811 WKDictionarySetItem(messageBody.get(), parentOriginKeyWK.get(), parentOrigin);
813 WKTypeRef resultToPass = 0;
814 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), messageBody.get(), &resultToPass);
815 WKRetainPtr<WKUInt64Ref> count(AdoptWK, static_cast<WKUInt64Ref>(resultToPass));
817 return static_cast<unsigned>(WKUInt64GetValue(count.get()));
820 void InjectedBundle::resetUserMediaPermissionRequestCountForOrigin(WKStringRef origin, WKStringRef parentOrigin)
822 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("ResetUserMediaPermissionRequestCountForOrigin"));
823 WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate());
825 WKRetainPtr<WKStringRef> originKeyWK(AdoptWK, WKStringCreateWithUTF8CString("origin"));
826 WKDictionarySetItem(messageBody.get(), originKeyWK.get(), origin);
828 WKRetainPtr<WKStringRef> parentOriginKeyWK(AdoptWK, WKStringCreateWithUTF8CString("parentOrigin"));
829 WKDictionarySetItem(messageBody.get(), parentOriginKeyWK.get(), parentOrigin);
831 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
834 void InjectedBundle::setCustomPolicyDelegate(bool enabled, bool permissive)
836 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetCustomPolicyDelegate"));
838 WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate());
840 WKRetainPtr<WKStringRef> enabledKeyWK(AdoptWK, WKStringCreateWithUTF8CString("enabled"));
841 WKRetainPtr<WKBooleanRef> enabledWK(AdoptWK, WKBooleanCreate(enabled));
842 WKDictionarySetItem(messageBody.get(), enabledKeyWK.get(), enabledWK.get());
844 WKRetainPtr<WKStringRef> permissiveKeyWK(AdoptWK, WKStringCreateWithUTF8CString("permissive"));
845 WKRetainPtr<WKBooleanRef> permissiveWK(AdoptWK, WKBooleanCreate(permissive));
846 WKDictionarySetItem(messageBody.get(), permissiveKeyWK.get(), permissiveWK.get());
848 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
851 void InjectedBundle::setHidden(bool hidden)
853 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetHidden"));
854 WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate());
856 WKRetainPtr<WKStringRef> isInitialKeyWK(AdoptWK, WKStringCreateWithUTF8CString("hidden"));
857 WKRetainPtr<WKBooleanRef> isInitialWK(AdoptWK, WKBooleanCreate(hidden));
858 WKDictionarySetItem(messageBody.get(), isInitialKeyWK.get(), isInitialWK.get());
860 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
863 void InjectedBundle::setCacheModel(int model)
865 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetCacheModel"));
866 WKRetainPtr<WKUInt64Ref> messageBody(AdoptWK, WKUInt64Create(model));
867 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
870 bool InjectedBundle::shouldProcessWorkQueue() const
875 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("IsWorkQueueEmpty"));
876 WKTypeRef resultToPass = 0;
877 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), 0, &resultToPass);
878 WKRetainPtr<WKBooleanRef> isEmpty(AdoptWK, static_cast<WKBooleanRef>(resultToPass));
880 // The IPC failed. This happens when swapping processes on navigation because the WebPageProxy unregisters itself
881 // as a MessageReceiver from the old WebProcessProxy and register itself with the new WebProcessProxy instead.
885 return !WKBooleanGetValue(isEmpty.get());
888 void InjectedBundle::processWorkQueue()
890 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("ProcessWorkQueue"));
891 WKBundlePagePostMessage(page()->page(), messageName.get(), 0);
894 void InjectedBundle::queueBackNavigation(unsigned howFarBackward)
896 m_useWorkQueue = true;
898 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueBackNavigation"));
899 WKRetainPtr<WKUInt64Ref> messageBody(AdoptWK, WKUInt64Create(howFarBackward));
900 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
903 void InjectedBundle::queueForwardNavigation(unsigned howFarForward)
905 m_useWorkQueue = true;
907 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueForwardNavigation"));
908 WKRetainPtr<WKUInt64Ref> messageBody(AdoptWK, WKUInt64Create(howFarForward));
909 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get());
912 void InjectedBundle::queueLoad(WKStringRef url, WKStringRef target, bool shouldOpenExternalURLs)
914 m_useWorkQueue = true;
916 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueLoad"));
918 WKRetainPtr<WKMutableDictionaryRef> loadData(AdoptWK, WKMutableDictionaryCreate());
920 WKRetainPtr<WKStringRef> urlKey(AdoptWK, WKStringCreateWithUTF8CString("url"));
921 WKDictionarySetItem(loadData.get(), urlKey.get(), url);
923 WKRetainPtr<WKStringRef> targetKey(AdoptWK, WKStringCreateWithUTF8CString("target"));
924 WKDictionarySetItem(loadData.get(), targetKey.get(), target);
926 WKRetainPtr<WKStringRef> shouldOpenExternalURLsKey(AdoptWK, WKStringCreateWithUTF8CString("shouldOpenExternalURLs"));
927 WKRetainPtr<WKBooleanRef> shouldOpenExternalURLsValue(AdoptWK, WKBooleanCreate(shouldOpenExternalURLs));
928 WKDictionarySetItem(loadData.get(), shouldOpenExternalURLsKey.get(), shouldOpenExternalURLsValue.get());
930 WKBundlePagePostMessage(page()->page(), messageName.get(), loadData.get());
933 void InjectedBundle::queueLoadHTMLString(WKStringRef content, WKStringRef baseURL, WKStringRef unreachableURL)
935 m_useWorkQueue = true;
937 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueLoadHTMLString"));
939 WKRetainPtr<WKMutableDictionaryRef> loadData(AdoptWK, WKMutableDictionaryCreate());
941 WKRetainPtr<WKStringRef> contentKey(AdoptWK, WKStringCreateWithUTF8CString("content"));
942 WKDictionarySetItem(loadData.get(), contentKey.get(), content);
945 WKRetainPtr<WKStringRef> baseURLKey(AdoptWK, WKStringCreateWithUTF8CString("baseURL"));
946 WKDictionarySetItem(loadData.get(), baseURLKey.get(), baseURL);
949 if (unreachableURL) {
950 WKRetainPtr<WKStringRef> unreachableURLKey(AdoptWK, WKStringCreateWithUTF8CString("unreachableURL"));
951 WKDictionarySetItem(loadData.get(), unreachableURLKey.get(), unreachableURL);
954 WKBundlePagePostMessage(page()->page(), messageName.get(), loadData.get());
957 void InjectedBundle::queueReload()
959 m_useWorkQueue = true;
961 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueReload"));
962 WKBundlePagePostMessage(page()->page(), messageName.get(), 0);
965 void InjectedBundle::queueLoadingScript(WKStringRef script)
967 m_useWorkQueue = true;
969 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueLoadingScript"));
970 WKBundlePagePostMessage(page()->page(), messageName.get(), script);
973 void InjectedBundle::queueNonLoadingScript(WKStringRef script)
975 m_useWorkQueue = true;
977 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueNonLoadingScript"));
978 WKBundlePagePostMessage(page()->page(), messageName.get(), script);
981 bool InjectedBundle::isAllowedHost(WKStringRef host)
983 if (m_allowedHosts.isEmpty())
985 return m_allowedHosts.contains(toWTFString(host));
988 void InjectedBundle::setAllowsAnySSLCertificate(bool allowsAnySSLCertificate)
990 WebCoreTestSupport::setAllowsAnySSLCertificate(allowsAnySSLCertificate);
993 void InjectedBundle::statisticsNotifyObserver()
995 WKBundleResourceLoadStatisticsNotifyObserver(m_bundle);
998 void InjectedBundle::textDidChangeInTextField()
1000 m_testRunner->textDidChangeInTextFieldCallback();
1003 void InjectedBundle::textFieldDidBeginEditing()
1005 m_testRunner->textFieldDidBeginEditingCallback();
1008 void InjectedBundle::textFieldDidEndEditing()
1010 m_testRunner->textFieldDidEndEditingCallback();