2
* Copyright (C) 2010, 2011, 2012 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 <WebKit2/WKBundle.h>
33
#include <WebKit2/WKBundlePage.h>
34
#include <WebKit2/WKBundlePagePrivate.h>
35
#include <WebKit2/WKBundlePrivate.h>
36
#include <WebKit2/WKRetainPtr.h>
37
#include <WebKit2/WebKit2_C.h>
38
#include <wtf/PassOwnPtr.h>
39
#include <wtf/text/CString.h>
40
#include <wtf/text/StringBuilder.h>
41
#include <wtf/Vector.h>
45
InjectedBundle& InjectedBundle::shared()
47
static InjectedBundle& shared = *new InjectedBundle;
51
InjectedBundle::InjectedBundle()
53
, m_topLoadingFrame(0)
56
, m_useWaitToDumpWatchdogTimer(true)
57
, m_useWorkQueue(false)
61
void InjectedBundle::didCreatePage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo)
63
static_cast<InjectedBundle*>(const_cast<void*>(clientInfo))->didCreatePage(page);
66
void InjectedBundle::willDestroyPage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo)
68
static_cast<InjectedBundle*>(const_cast<void*>(clientInfo))->willDestroyPage(page);
71
void InjectedBundle::didInitializePageGroup(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, const void* clientInfo)
73
static_cast<InjectedBundle*>(const_cast<void*>(clientInfo))->didInitializePageGroup(pageGroup);
76
void InjectedBundle::didReceiveMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo)
78
static_cast<InjectedBundle*>(const_cast<void*>(clientInfo))->didReceiveMessage(messageName, messageBody);
81
void InjectedBundle::didReceiveMessageToPage(WKBundleRef bundle, WKBundlePageRef page, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo)
83
static_cast<InjectedBundle*>(const_cast<void*>(clientInfo))->didReceiveMessageToPage(page, messageName, messageBody);
86
void InjectedBundle::initialize(WKBundleRef bundle, WKTypeRef initializationUserData)
89
m_stringBuilder = WTF::adoptPtr(new WTF::StringBuilder());
91
WKBundleClient client = {
92
kWKBundleClientCurrentVersion,
96
didInitializePageGroup,
98
didReceiveMessageToPage
100
WKBundleSetClient(m_bundle, &client);
102
platformInitialize(initializationUserData);
105
WKBundleActivateMacFontAscentHack(m_bundle);
107
// FIXME: We'd like to start with a clean state for every test, but this function can't be used more than once yet.
108
WKBundleSwitchNetworkLoaderToNewTestingSession(m_bundle);
111
void InjectedBundle::didCreatePage(WKBundlePageRef page)
113
m_pages.append(adoptPtr(new InjectedBundlePage(page)));
116
void InjectedBundle::willDestroyPage(WKBundlePageRef page)
118
size_t size = m_pages.size();
119
for (size_t i = 0; i < size; ++i) {
120
if (m_pages[i]->page() == page) {
127
void InjectedBundle::didInitializePageGroup(WKBundlePageGroupRef pageGroup)
129
m_pageGroup = pageGroup;
132
InjectedBundlePage* InjectedBundle::page() const
134
// It might be better to have the UI process send over a reference to the main
135
// page instead of just assuming it's the first one.
136
return m_pages[0].get();
139
void InjectedBundle::resetLocalSettings()
141
setlocale(LC_ALL, "");
144
void InjectedBundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
146
if (WKStringIsEqualToUTF8CString(messageName, "BeginTest")) {
148
ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
149
WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
151
WKRetainPtr<WKStringRef> dumpPixelsKey(AdoptWK, WKStringCreateWithUTF8CString("DumpPixels"));
152
m_dumpPixels = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, dumpPixelsKey.get())));
154
WKRetainPtr<WKStringRef> useWaitToDumpWatchdogTimerKey(AdoptWK, WKStringCreateWithUTF8CString("UseWaitToDumpWatchdogTimer"));
155
m_useWaitToDumpWatchdogTimer = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, useWaitToDumpWatchdogTimerKey.get())));
157
WKRetainPtr<WKStringRef> ackMessageName(AdoptWK, WKStringCreateWithUTF8CString("Ack"));
158
WKRetainPtr<WKStringRef> ackMessageBody(AdoptWK, WKStringCreateWithUTF8CString("BeginTest"));
159
WKBundlePostMessage(m_bundle, ackMessageName.get(), ackMessageBody.get());
161
beginTesting(messageBodyDictionary);
163
} else if (WKStringIsEqualToUTF8CString(messageName, "Reset")) {
165
ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
166
WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
168
WKRetainPtr<WKStringRef> shouldGCKey(AdoptWK, WKStringCreateWithUTF8CString("ShouldGC"));
169
bool shouldGC = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, shouldGCKey.get())));
172
WKBundleGarbageCollectJavaScriptObjects(m_bundle);
175
m_dumpPixels = false;
177
resetLocalSettings();
178
m_testRunner->removeAllWebNotificationPermissions();
182
if (WKStringIsEqualToUTF8CString(messageName, "CallAddChromeInputFieldCallback")) {
183
m_testRunner->callAddChromeInputFieldCallback();
186
if (WKStringIsEqualToUTF8CString(messageName, "CallRemoveChromeInputFieldCallback")) {
187
m_testRunner->callRemoveChromeInputFieldCallback();
190
if (WKStringIsEqualToUTF8CString(messageName, "CallFocusWebViewCallback")) {
191
m_testRunner->callFocusWebViewCallback();
194
if (WKStringIsEqualToUTF8CString(messageName, "CallSetBackingScaleFactorCallback")) {
195
m_testRunner->callSetBackingScaleFactorCallback();
198
if (WKStringIsEqualToUTF8CString(messageName, "WorkQueueProcessedCallback")) {
199
if (!topLoadingFrame() && !m_testRunner->waitToDump())
204
WKRetainPtr<WKStringRef> errorMessageName(AdoptWK, WKStringCreateWithUTF8CString("Error"));
205
WKRetainPtr<WKStringRef> errorMessageBody(AdoptWK, WKStringCreateWithUTF8CString("Unknown"));
206
WKBundlePostMessage(m_bundle, errorMessageName.get(), errorMessageBody.get());
209
void InjectedBundle::didReceiveMessageToPage(WKBundlePageRef page, WKStringRef messageName, WKTypeRef messageBody)
211
WKRetainPtr<WKStringRef> errorMessageName(AdoptWK, WKStringCreateWithUTF8CString("Error"));
212
WKRetainPtr<WKStringRef> errorMessageBody(AdoptWK, WKStringCreateWithUTF8CString("Unknown"));
213
WKBundlePostMessage(m_bundle, errorMessageName.get(), errorMessageBody.get());
216
bool InjectedBundle::booleanForKey(WKDictionaryRef dictionary, const char* key)
218
WKRetainPtr<WKStringRef> wkKey(AdoptWK, WKStringCreateWithUTF8CString(key));
219
WKTypeRef value = WKDictionaryGetItemForKey(dictionary, wkKey.get());
220
if (WKGetTypeID(value) != WKBooleanGetTypeID()) {
221
stringBuilder()->appendLiteral("Boolean value for key \"");
222
stringBuilder()->append(key);
223
stringBuilder()->appendLiteral("\" not found in dictionary\n");
226
return WKBooleanGetValue(static_cast<WKBooleanRef>(value));
229
void InjectedBundle::beginTesting(WKDictionaryRef settings)
233
m_pixelResult.clear();
234
m_repaintRects.clear();
235
m_stringBuilder->clear();
237
m_testRunner = TestRunner::create();
238
m_gcController = GCController::create();
239
m_eventSendingController = EventSendingController::create();
240
m_textInputController = TextInputController::create();
241
m_accessibilityController = AccessibilityController::create();
243
WKBundleSetShouldTrackVisitedLinks(m_bundle, false);
244
WKBundleRemoveAllVisitedLinks(m_bundle);
245
WKBundleSetAllowUniversalAccessFromFileURLs(m_bundle, m_pageGroup, true);
246
WKBundleSetJavaScriptCanAccessClipboard(m_bundle, m_pageGroup, true);
247
WKBundleSetPrivateBrowsingEnabled(m_bundle, m_pageGroup, false);
248
WKBundleSetAuthorAndUserStylesEnabled(m_bundle, m_pageGroup, true);
249
WKBundleSetFrameFlatteningEnabled(m_bundle, m_pageGroup, false);
250
WKBundleSetMinimumLogicalFontSize(m_bundle, m_pageGroup, 9);
251
WKBundleSetMinimumTimerInterval(m_bundle, m_pageGroup, 0.010); // 10 milliseconds (DOMTimer::s_minDefaultTimerInterval)
252
WKBundleSetSpatialNavigationEnabled(m_bundle, m_pageGroup, false);
253
WKBundleSetAllowFileAccessFromFileURLs(m_bundle, m_pageGroup, true);
254
WKBundleSetPluginsEnabled(m_bundle, m_pageGroup, true);
255
WKBundleSetPopupBlockingEnabled(m_bundle, m_pageGroup, false);
256
WKBundleSetAlwaysAcceptCookies(m_bundle, false);
257
WKBundleSetSerialLoadingEnabled(m_bundle, false);
258
WKBundleSetShadowDOMEnabled(m_bundle, true);
259
WKBundleSetCacheModel(m_bundle, 1 /*CacheModelDocumentBrowser*/);
261
WKBundleRemoveAllUserContent(m_bundle, m_pageGroup);
263
m_testRunner->setShouldDumpFrameLoadCallbacks(booleanForKey(settings, "DumpFrameLoadDelegates"));
264
m_testRunner->setUserStyleSheetEnabled(false);
265
m_testRunner->setXSSAuditorEnabled(false);
266
m_testRunner->setCloseRemainingWindowsWhenComplete(false);
267
m_testRunner->setAcceptsEditing(true);
268
m_testRunner->setTabKeyCyclesThroughElements(true);
272
WKBundleClearAllDatabases(m_bundle);
273
WKBundleClearApplicationCache(m_bundle);
274
WKBundleResetOriginAccessWhitelists(m_bundle);
276
// [WK2] REGRESSION(r128623): It made layout tests extremely slow
277
// https://bugs.webkit.org/show_bug.cgi?id=96862
278
// WKBundleSetDatabaseQuota(m_bundle, 5 * 1024 * 1024);
281
void InjectedBundle::done()
285
m_useWorkQueue = false;
287
page()->stopLoading();
288
setTopLoadingFrame(0);
290
m_accessibilityController->resetToConsistentState();
292
WKRetainPtr<WKStringRef> doneMessageName(AdoptWK, WKStringCreateWithUTF8CString("Done"));
293
WKRetainPtr<WKMutableDictionaryRef> doneMessageBody(AdoptWK, WKMutableDictionaryCreate());
295
WKRetainPtr<WKStringRef> textOutputKey(AdoptWK, WKStringCreateWithUTF8CString("TextOutput"));
296
WKRetainPtr<WKStringRef> textOutput(AdoptWK, WKStringCreateWithUTF8CString(m_stringBuilder->toString().utf8().data()));
297
WKDictionaryAddItem(doneMessageBody.get(), textOutputKey.get(), textOutput.get());
299
WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult"));
300
WKDictionaryAddItem(doneMessageBody.get(), pixelResultKey.get(), m_pixelResult.get());
302
WKRetainPtr<WKStringRef> repaintRectsKey = adoptWK(WKStringCreateWithUTF8CString("RepaintRects"));
303
WKDictionaryAddItem(doneMessageBody.get(), repaintRectsKey.get(), m_repaintRects.get());
305
WKBundlePostMessage(m_bundle, doneMessageName.get(), doneMessageBody.get());
309
page()->resetAfterTest();
314
void InjectedBundle::closeOtherPages()
316
Vector<WKBundlePageRef> pagesToClose;
317
size_t size = m_pages.size();
318
for (size_t i = 1; i < size; ++i)
319
pagesToClose.append(m_pages[i]->page());
320
size = pagesToClose.size();
321
for (size_t i = 0; i < size; ++i)
322
WKBundlePageClose(pagesToClose[i]);
325
void InjectedBundle::dumpBackForwardListsForAllPages()
327
size_t size = m_pages.size();
328
for (size_t i = 0; i < size; ++i)
329
m_pages[i]->dumpBackForwardList();
332
void InjectedBundle::postNewBeforeUnloadReturnValue(bool value)
334
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("BeforeUnloadReturnValue"));
335
WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
336
WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get());
339
void InjectedBundle::postAddChromeInputField()
341
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("AddChromeInputField"));
342
WKBundlePostMessage(m_bundle, messageName.get(), 0);
345
void InjectedBundle::postRemoveChromeInputField()
347
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("RemoveChromeInputField"));
348
WKBundlePostMessage(m_bundle, messageName.get(), 0);
351
void InjectedBundle::postFocusWebView()
353
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("FocusWebView"));
354
WKBundlePostMessage(m_bundle, messageName.get(), 0);
357
void InjectedBundle::postSetBackingScaleFactor(double backingScaleFactor)
359
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetBackingScaleFactor"));
360
WKRetainPtr<WKDoubleRef> messageBody(AdoptWK, WKDoubleCreate(backingScaleFactor));
361
WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get());
364
void InjectedBundle::postSetWindowIsKey(bool isKey)
366
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetWindowIsKey"));
367
WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(isKey));
368
WKBundlePostSynchronousMessage(m_bundle, messageName.get(), messageBody.get(), 0);
371
void InjectedBundle::postSimulateWebNotificationClick(uint64_t notificationID)
373
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SimulateWebNotificationClick"));
374
WKRetainPtr<WKUInt64Ref> messageBody(AdoptWK, WKUInt64Create(notificationID));
375
WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get());
378
void InjectedBundle::setGeolocationPermission(bool enabled)
380
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetGeolocationPermission"));
381
WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(enabled));
382
WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get());
385
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)
387
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetMockGeolocationPosition"));
389
WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate());
391
WKRetainPtr<WKStringRef> latitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("latitude"));
392
WKRetainPtr<WKDoubleRef> latitudeWK(AdoptWK, WKDoubleCreate(latitude));
393
WKDictionaryAddItem(messageBody.get(), latitudeKeyWK.get(), latitudeWK.get());
395
WKRetainPtr<WKStringRef> longitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("longitude"));
396
WKRetainPtr<WKDoubleRef> longitudeWK(AdoptWK, WKDoubleCreate(longitude));
397
WKDictionaryAddItem(messageBody.get(), longitudeKeyWK.get(), longitudeWK.get());
399
WKRetainPtr<WKStringRef> accuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("accuracy"));
400
WKRetainPtr<WKDoubleRef> accuracyWK(AdoptWK, WKDoubleCreate(accuracy));
401
WKDictionaryAddItem(messageBody.get(), accuracyKeyWK.get(), accuracyWK.get());
403
WKRetainPtr<WKStringRef> providesAltitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesAltitude"));
404
WKRetainPtr<WKBooleanRef> providesAltitudeWK(AdoptWK, WKBooleanCreate(providesAltitude));
405
WKDictionaryAddItem(messageBody.get(), providesAltitudeKeyWK.get(), providesAltitudeWK.get());
407
WKRetainPtr<WKStringRef> altitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("altitude"));
408
WKRetainPtr<WKDoubleRef> altitudeWK(AdoptWK, WKDoubleCreate(altitude));
409
WKDictionaryAddItem(messageBody.get(), altitudeKeyWK.get(), altitudeWK.get());
411
WKRetainPtr<WKStringRef> providesAltitudeAccuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesAltitudeAccuracy"));
412
WKRetainPtr<WKBooleanRef> providesAltitudeAccuracyWK(AdoptWK, WKBooleanCreate(providesAltitudeAccuracy));
413
WKDictionaryAddItem(messageBody.get(), providesAltitudeAccuracyKeyWK.get(), providesAltitudeAccuracyWK.get());
415
WKRetainPtr<WKStringRef> altitudeAccuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("altitudeAccuracy"));
416
WKRetainPtr<WKDoubleRef> altitudeAccuracyWK(AdoptWK, WKDoubleCreate(altitudeAccuracy));
417
WKDictionaryAddItem(messageBody.get(), altitudeAccuracyKeyWK.get(), altitudeAccuracyWK.get());
419
WKRetainPtr<WKStringRef> providesHeadingKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesHeading"));
420
WKRetainPtr<WKBooleanRef> providesHeadingWK(AdoptWK, WKBooleanCreate(providesHeading));
421
WKDictionaryAddItem(messageBody.get(), providesHeadingKeyWK.get(), providesHeadingWK.get());
423
WKRetainPtr<WKStringRef> headingKeyWK(AdoptWK, WKStringCreateWithUTF8CString("heading"));
424
WKRetainPtr<WKDoubleRef> headingWK(AdoptWK, WKDoubleCreate(heading));
425
WKDictionaryAddItem(messageBody.get(), headingKeyWK.get(), headingWK.get());
427
WKRetainPtr<WKStringRef> providesSpeedKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesSpeed"));
428
WKRetainPtr<WKBooleanRef> providesSpeedWK(AdoptWK, WKBooleanCreate(providesSpeed));
429
WKDictionaryAddItem(messageBody.get(), providesSpeedKeyWK.get(), providesSpeedWK.get());
431
WKRetainPtr<WKStringRef> speedKeyWK(AdoptWK, WKStringCreateWithUTF8CString("speed"));
432
WKRetainPtr<WKDoubleRef> speedWK(AdoptWK, WKDoubleCreate(speed));
433
WKDictionaryAddItem(messageBody.get(), speedKeyWK.get(), speedWK.get());
435
WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get());
438
void InjectedBundle::setMockGeolocationPositionUnavailableError(WKStringRef errorMessage)
440
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetMockGeolocationPositionUnavailableError"));
441
WKBundlePostMessage(m_bundle, messageName.get(), errorMessage);
444
void InjectedBundle::setCustomPolicyDelegate(bool enabled, bool permissive)
446
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetCustomPolicyDelegate"));
448
WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate());
450
WKRetainPtr<WKStringRef> enabledKeyWK(AdoptWK, WKStringCreateWithUTF8CString("enabled"));
451
WKRetainPtr<WKBooleanRef> enabledWK(AdoptWK, WKBooleanCreate(enabled));
452
WKDictionaryAddItem(messageBody.get(), enabledKeyWK.get(), enabledWK.get());
454
WKRetainPtr<WKStringRef> permissiveKeyWK(AdoptWK, WKStringCreateWithUTF8CString("permissive"));
455
WKRetainPtr<WKBooleanRef> permissiveWK(AdoptWK, WKBooleanCreate(permissive));
456
WKDictionaryAddItem(messageBody.get(), permissiveKeyWK.get(), permissiveWK.get());
458
WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get());
461
bool InjectedBundle::shouldProcessWorkQueue() const
466
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("IsWorkQueueEmpty"));
467
WKTypeRef resultToPass = 0;
468
WKBundlePostSynchronousMessage(m_bundle, messageName.get(), 0, &resultToPass);
469
WKRetainPtr<WKBooleanRef> isEmpty(AdoptWK, static_cast<WKBooleanRef>(resultToPass));
471
return !WKBooleanGetValue(isEmpty.get());
474
void InjectedBundle::processWorkQueue()
476
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("ProcessWorkQueue"));
477
WKBundlePostMessage(m_bundle, messageName.get(), 0);
480
void InjectedBundle::queueBackNavigation(unsigned howFarBackward)
482
m_useWorkQueue = true;
484
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueBackNavigation"));
485
WKRetainPtr<WKUInt64Ref> messageBody(AdoptWK, WKUInt64Create(howFarBackward));
486
WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get());
489
void InjectedBundle::queueForwardNavigation(unsigned howFarForward)
491
m_useWorkQueue = true;
493
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueForwardNavigation"));
494
WKRetainPtr<WKUInt64Ref> messageBody(AdoptWK, WKUInt64Create(howFarForward));
495
WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get());
498
void InjectedBundle::queueLoad(WKStringRef url, WKStringRef target)
500
m_useWorkQueue = true;
502
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueLoad"));
504
WKRetainPtr<WKMutableDictionaryRef> loadData(AdoptWK, WKMutableDictionaryCreate());
506
WKRetainPtr<WKStringRef> urlKey(AdoptWK, WKStringCreateWithUTF8CString("url"));
507
WKDictionaryAddItem(loadData.get(), urlKey.get(), url);
509
WKRetainPtr<WKStringRef> targetKey(AdoptWK, WKStringCreateWithUTF8CString("target"));
510
WKDictionaryAddItem(loadData.get(), targetKey.get(), target);
512
WKBundlePostMessage(m_bundle, messageName.get(), loadData.get());
515
void InjectedBundle::queueLoadHTMLString(WKStringRef content, WKStringRef baseURL, WKStringRef unreachableURL)
517
m_useWorkQueue = true;
519
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueLoadHTMLString"));
521
WKRetainPtr<WKMutableDictionaryRef> loadData(AdoptWK, WKMutableDictionaryCreate());
523
WKRetainPtr<WKStringRef> contentKey(AdoptWK, WKStringCreateWithUTF8CString("content"));
524
WKDictionaryAddItem(loadData.get(), contentKey.get(), content);
527
WKRetainPtr<WKStringRef> baseURLKey(AdoptWK, WKStringCreateWithUTF8CString("baseURL"));
528
WKDictionaryAddItem(loadData.get(), baseURLKey.get(), baseURL);
531
if (unreachableURL) {
532
WKRetainPtr<WKStringRef> unreachableURLKey(AdoptWK, WKStringCreateWithUTF8CString("unreachableURL"));
533
WKDictionaryAddItem(loadData.get(), unreachableURLKey.get(), unreachableURL);
536
WKBundlePostMessage(m_bundle, messageName.get(), loadData.get());
539
void InjectedBundle::queueReload()
541
m_useWorkQueue = true;
543
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueReload"));
544
WKBundlePostMessage(m_bundle, messageName.get(), 0);
547
void InjectedBundle::queueLoadingScript(WKStringRef script)
549
m_useWorkQueue = true;
551
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueLoadingScript"));
552
WKBundlePostMessage(m_bundle, messageName.get(), script);
555
void InjectedBundle::queueNonLoadingScript(WKStringRef script)
557
m_useWorkQueue = true;
559
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("QueueNonLoadingScript"));
560
WKBundlePostMessage(m_bundle, messageName.get(), script);