2 * Copyright (C) 2010, 2011, 2013, 2015 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 "WKBundlePage.h"
28 #include "WKBundlePagePrivate.h"
31 #include "APIFrameHandle.h"
32 #include "APIString.h"
34 #include "APIURLRequest.h"
35 #include "InjectedBundleBackForwardList.h"
36 #include "InjectedBundleNodeHandle.h"
37 #include "InjectedBundlePageEditorClient.h"
38 #include "InjectedBundlePageFormClient.h"
39 #include "InjectedBundlePageLoaderClient.h"
40 #include "InjectedBundlePageResourceLoadClient.h"
41 #include "InjectedBundlePageUIClient.h"
42 #include "PageBanner.h"
43 #include "WKAPICast.h"
45 #include "WKBundleAPICast.h"
46 #include "WKRetainPtr.h"
48 #include "WebContextMenu.h"
49 #include "WebContextMenuItem.h"
51 #include "WebFullScreenManager.h"
53 #include "WebInspector.h"
55 #include "WebPageGroupProxy.h"
56 #include "WebPageOverlay.h"
57 #include "WebRenderLayer.h"
58 #include "WebRenderObject.h"
59 #include <WebCore/AXObjectCache.h>
60 #include <WebCore/AccessibilityObject.h>
61 #include <WebCore/ApplicationCacheStorage.h>
62 #include <WebCore/Frame.h>
63 #include <WebCore/Page.h>
64 #include <WebCore/PageOverlay.h>
65 #include <WebCore/PageOverlayController.h>
66 #include <WebCore/RenderLayerCompositor.h>
67 #include <WebCore/ScriptExecutionContext.h>
68 #include <WebCore/SecurityOriginData.h>
69 #include <WebCore/URL.h>
70 #include <WebCore/WheelEventTestTrigger.h>
71 #include <wtf/StdLibExtras.h>
73 using namespace WebKit;
75 WKTypeID WKBundlePageGetTypeID()
77 return toAPI(WebPage::APIType);
80 void WKBundlePageSetContextMenuClient(WKBundlePageRef pageRef, WKBundlePageContextMenuClientBase* wkClient)
82 #if ENABLE(CONTEXT_MENUS)
83 toImpl(pageRef)->setInjectedBundleContextMenuClient(std::make_unique<InjectedBundlePageContextMenuClient>(wkClient));
85 UNUSED_PARAM(pageRef);
86 UNUSED_PARAM(wkClient);
90 void WKBundlePageSetEditorClient(WKBundlePageRef pageRef, WKBundlePageEditorClientBase* wkClient)
92 toImpl(pageRef)->setInjectedBundleEditorClient(wkClient ? std::make_unique<InjectedBundlePageEditorClient>(*wkClient) : std::make_unique<API::InjectedBundle::EditorClient>());
95 void WKBundlePageSetFormClient(WKBundlePageRef pageRef, WKBundlePageFormClientBase* wkClient)
97 toImpl(pageRef)->setInjectedBundleFormClient(std::make_unique<InjectedBundlePageFormClient>(wkClient));
100 void WKBundlePageSetPageLoaderClient(WKBundlePageRef pageRef, WKBundlePageLoaderClientBase* wkClient)
102 toImpl(pageRef)->setInjectedBundlePageLoaderClient(std::make_unique<InjectedBundlePageLoaderClient>(wkClient));
105 void WKBundlePageSetResourceLoadClient(WKBundlePageRef pageRef, WKBundlePageResourceLoadClientBase* wkClient)
107 toImpl(pageRef)->setInjectedBundleResourceLoadClient(std::make_unique<InjectedBundlePageResourceLoadClient>(wkClient));
110 void WKBundlePageSetPolicyClient(WKBundlePageRef pageRef, WKBundlePagePolicyClientBase* wkClient)
112 toImpl(pageRef)->initializeInjectedBundlePolicyClient(wkClient);
115 void WKBundlePageSetUIClient(WKBundlePageRef pageRef, WKBundlePageUIClientBase* wkClient)
117 toImpl(pageRef)->setInjectedBundleUIClient(std::make_unique<InjectedBundlePageUIClient>(wkClient));
120 void WKBundlePageSetFullScreenClient(WKBundlePageRef pageRef, WKBundlePageFullScreenClientBase* wkClient)
122 #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API
123 toImpl(pageRef)->initializeInjectedBundleFullScreenClient(wkClient);
125 UNUSED_PARAM(pageRef);
126 UNUSED_PARAM(wkClient);
130 void WKBundlePageWillEnterFullScreen(WKBundlePageRef pageRef)
132 #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API
133 toImpl(pageRef)->fullScreenManager()->willEnterFullScreen();
135 UNUSED_PARAM(pageRef);
139 void WKBundlePageDidEnterFullScreen(WKBundlePageRef pageRef)
141 #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API
142 toImpl(pageRef)->fullScreenManager()->didEnterFullScreen();
144 UNUSED_PARAM(pageRef);
148 void WKBundlePageWillExitFullScreen(WKBundlePageRef pageRef)
150 #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API
151 toImpl(pageRef)->fullScreenManager()->willExitFullScreen();
153 UNUSED_PARAM(pageRef);
157 void WKBundlePageDidExitFullScreen(WKBundlePageRef pageRef)
159 #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API
160 toImpl(pageRef)->fullScreenManager()->didExitFullScreen();
162 UNUSED_PARAM(pageRef);
166 WKBundlePageGroupRef WKBundlePageGetPageGroup(WKBundlePageRef pageRef)
168 return toAPI(toImpl(pageRef)->pageGroup());
171 WKBundleFrameRef WKBundlePageGetMainFrame(WKBundlePageRef pageRef)
173 return toAPI(toImpl(pageRef)->mainWebFrame());
176 WKFrameHandleRef WKBundleFrameCreateFrameHandle(WKBundleFrameRef bundleFrameRef)
178 return toAPI(&API::FrameHandle::create(toImpl(bundleFrameRef)->frameID()).leakRef());
181 void WKBundlePageClickMenuItem(WKBundlePageRef pageRef, WKContextMenuItemRef item)
183 #if ENABLE(CONTEXT_MENUS)
184 toImpl(pageRef)->contextMenu()->itemSelected(toImpl(item)->data());
186 UNUSED_PARAM(pageRef);
191 #if ENABLE(CONTEXT_MENUS)
192 static Ref<API::Array> contextMenuItems(const WebContextMenu& contextMenu)
194 auto items = contextMenu.items();
196 Vector<RefPtr<API::Object>> menuItems;
197 menuItems.reserveInitialCapacity(items.size());
199 for (const auto& item : items)
200 menuItems.uncheckedAppend(WebContextMenuItem::create(item));
202 return API::Array::create(WTFMove(menuItems));
206 WKArrayRef WKBundlePageCopyContextMenuItems(WKBundlePageRef pageRef)
208 #if ENABLE(CONTEXT_MENUS)
209 WebContextMenu* contextMenu = toImpl(pageRef)->contextMenu();
211 return toAPI(&contextMenuItems(*contextMenu).leakRef());
213 UNUSED_PARAM(pageRef);
218 WKArrayRef WKBundlePageCopyContextMenuAtPointInWindow(WKBundlePageRef pageRef, WKPoint point)
220 #if ENABLE(CONTEXT_MENUS)
221 WebContextMenu* contextMenu = toImpl(pageRef)->contextMenuAtPointInWindow(toIntPoint(point));
225 return toAPI(&contextMenuItems(*contextMenu).leakRef());
227 UNUSED_PARAM(pageRef);
233 void WKBundlePageInsertNewlineInQuotedContent(WKBundlePageRef pageRef)
235 toImpl(pageRef)->insertNewlineInQuotedContent();
238 void* WKAccessibilityRootObject(WKBundlePageRef pageRef)
240 #if HAVE(ACCESSIBILITY)
244 WebCore::Page* page = toImpl(pageRef)->corePage();
248 WebCore::Frame& core = page->mainFrame();
249 if (!core.document())
252 WebCore::AXObjectCache::enableAccessibility();
254 WebCore::AccessibilityObject* root = core.document()->axObjectCache()->rootObject();
258 return root->wrapper();
260 UNUSED_PARAM(pageRef);
265 void* WKAccessibilityFocusedObject(WKBundlePageRef pageRef)
267 #if HAVE(ACCESSIBILITY)
271 WebCore::Page* page = toImpl(pageRef)->corePage();
275 WebCore::AXObjectCache::enableAccessibility();
277 WebCore::AccessibilityObject* focusedObject = WebCore::AXObjectCache::focusedUIElementForPage(page);
281 return focusedObject->wrapper();
283 UNUSED_PARAM(pageRef);
288 void WKAccessibilityEnableEnhancedAccessibility(bool enable)
290 #if HAVE(ACCESSIBILITY)
291 WebCore::AXObjectCache::setEnhancedUserInterfaceAccessibility(enable);
295 bool WKAccessibilityEnhancedAccessibilityEnabled()
297 #if HAVE(ACCESSIBILITY)
298 return WebCore::AXObjectCache::accessibilityEnhancedUserInterfaceEnabled();
304 void WKBundlePageStopLoading(WKBundlePageRef pageRef)
306 toImpl(pageRef)->stopLoading();
309 void WKBundlePageSetDefersLoading(WKBundlePageRef pageRef, bool defersLoading)
311 toImpl(pageRef)->setDefersLoading(defersLoading);
314 WKStringRef WKBundlePageCopyRenderTreeExternalRepresentation(WKBundlePageRef pageRef)
316 return toCopiedAPI(toImpl(pageRef)->renderTreeExternalRepresentation());
319 WKStringRef WKBundlePageCopyRenderTreeExternalRepresentationForPrinting(WKBundlePageRef pageRef)
321 return toCopiedAPI(toImpl(pageRef)->renderTreeExternalRepresentationForPrinting());
324 void WKBundlePageExecuteEditingCommand(WKBundlePageRef pageRef, WKStringRef name, WKStringRef argument)
326 toImpl(pageRef)->executeEditingCommand(toWTFString(name), toWTFString(argument));
329 bool WKBundlePageIsEditingCommandEnabled(WKBundlePageRef pageRef, WKStringRef name)
331 return toImpl(pageRef)->isEditingCommandEnabled(toWTFString(name));
334 void WKBundlePageClearMainFrameName(WKBundlePageRef pageRef)
336 toImpl(pageRef)->clearMainFrameName();
339 void WKBundlePageClose(WKBundlePageRef pageRef)
341 toImpl(pageRef)->sendClose();
344 double WKBundlePageGetTextZoomFactor(WKBundlePageRef pageRef)
346 return toImpl(pageRef)->textZoomFactor();
349 void WKBundlePageSetTextZoomFactor(WKBundlePageRef pageRef, double zoomFactor)
351 toImpl(pageRef)->setTextZoomFactor(zoomFactor);
354 double WKBundlePageGetPageZoomFactor(WKBundlePageRef pageRef)
356 return toImpl(pageRef)->pageZoomFactor();
359 void WKBundlePageSetPageZoomFactor(WKBundlePageRef pageRef, double zoomFactor)
361 toImpl(pageRef)->setPageZoomFactor(zoomFactor);
364 void WKBundlePageSetScaleAtOrigin(WKBundlePageRef pageRef, double scale, WKPoint origin)
366 toImpl(pageRef)->scalePage(scale, toIntPoint(origin));
369 WKBundleBackForwardListRef WKBundlePageGetBackForwardList(WKBundlePageRef pageRef)
371 return toAPI(toImpl(pageRef)->backForwardList());
374 void WKBundlePageInstallPageOverlay(WKBundlePageRef pageRef, WKBundlePageOverlayRef pageOverlayRef)
376 toImpl(pageRef)->corePage()->pageOverlayController().installPageOverlay(*toImpl(pageOverlayRef)->coreOverlay(), WebCore::PageOverlay::FadeMode::DoNotFade);
379 void WKBundlePageUninstallPageOverlay(WKBundlePageRef pageRef, WKBundlePageOverlayRef pageOverlayRef)
381 toImpl(pageRef)->corePage()->pageOverlayController().uninstallPageOverlay(*toImpl(pageOverlayRef)->coreOverlay(), WebCore::PageOverlay::FadeMode::DoNotFade);
384 void WKBundlePageInstallPageOverlayWithAnimation(WKBundlePageRef pageRef, WKBundlePageOverlayRef pageOverlayRef)
386 toImpl(pageRef)->corePage()->pageOverlayController().installPageOverlay(*toImpl(pageOverlayRef)->coreOverlay(), WebCore::PageOverlay::FadeMode::Fade);
389 void WKBundlePageUninstallPageOverlayWithAnimation(WKBundlePageRef pageRef, WKBundlePageOverlayRef pageOverlayRef)
391 toImpl(pageRef)->corePage()->pageOverlayController().uninstallPageOverlay(*toImpl(pageOverlayRef)->coreOverlay(), WebCore::PageOverlay::FadeMode::Fade);
394 void WKBundlePageSetTopOverhangImage(WKBundlePageRef pageRef, WKImageRef imageRef)
397 toImpl(pageRef)->setTopOverhangImage(toImpl(imageRef));
399 UNUSED_PARAM(pageRef);
400 UNUSED_PARAM(imageRef);
404 void WKBundlePageSetBottomOverhangImage(WKBundlePageRef pageRef, WKImageRef imageRef)
407 toImpl(pageRef)->setBottomOverhangImage(toImpl(imageRef));
409 UNUSED_PARAM(pageRef);
410 UNUSED_PARAM(imageRef);
415 void WKBundlePageSetHeaderBanner(WKBundlePageRef pageRef, WKBundlePageBannerRef bannerRef)
417 toImpl(pageRef)->setHeaderPageBanner(toImpl(bannerRef));
420 void WKBundlePageSetFooterBanner(WKBundlePageRef pageRef, WKBundlePageBannerRef bannerRef)
422 toImpl(pageRef)->setFooterPageBanner(toImpl(bannerRef));
424 #endif // !PLATFORM(IOS)
426 bool WKBundlePageHasLocalDataForURL(WKBundlePageRef pageRef, WKURLRef urlRef)
428 return toImpl(pageRef)->hasLocalDataForURL(WebCore::URL(WebCore::URL(), toWTFString(urlRef)));
431 bool WKBundlePageCanHandleRequest(WKURLRequestRef requestRef)
435 return WebPage::canHandleRequest(toImpl(requestRef)->resourceRequest());
438 bool WKBundlePageFindString(WKBundlePageRef pageRef, WKStringRef target, WKFindOptions findOptions)
440 return toImpl(pageRef)->findStringFromInjectedBundle(toWTFString(target), toFindOptions(findOptions));
443 WKImageRef WKBundlePageCreateSnapshotWithOptions(WKBundlePageRef pageRef, WKRect rect, WKSnapshotOptions options)
445 RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotWithOptions(toIntRect(rect), 1, toSnapshotOptions(options));
446 return toAPI(webImage.leakRef());
449 WKImageRef WKBundlePageCreateSnapshotInViewCoordinates(WKBundlePageRef pageRef, WKRect rect, WKImageOptions options)
451 SnapshotOptions snapshotOptions = snapshotOptionsFromImageOptions(options);
452 snapshotOptions |= SnapshotOptionsInViewCoordinates;
453 RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotWithOptions(toIntRect(rect), 1, snapshotOptions);
454 return toAPI(webImage.leakRef());
457 WKImageRef WKBundlePageCreateSnapshotInDocumentCoordinates(WKBundlePageRef pageRef, WKRect rect, WKImageOptions options)
459 RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotWithOptions(toIntRect(rect), 1, snapshotOptionsFromImageOptions(options));
460 return toAPI(webImage.leakRef());
463 WKImageRef WKBundlePageCreateScaledSnapshotInDocumentCoordinates(WKBundlePageRef pageRef, WKRect rect, double scaleFactor, WKImageOptions options)
465 RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotWithOptions(toIntRect(rect), scaleFactor, snapshotOptionsFromImageOptions(options));
466 return toAPI(webImage.leakRef());
469 double WKBundlePageGetBackingScaleFactor(WKBundlePageRef pageRef)
471 return toImpl(pageRef)->deviceScaleFactor();
474 void WKBundlePageListenForLayoutMilestones(WKBundlePageRef pageRef, WKLayoutMilestones milestones)
476 toImpl(pageRef)->listenForLayoutMilestones(toLayoutMilestones(milestones));
479 WKBundleInspectorRef WKBundlePageGetInspector(WKBundlePageRef pageRef)
481 return toAPI(toImpl(pageRef)->inspector());
484 void WKBundlePageForceRepaint(WKBundlePageRef page)
486 toImpl(page)->forceRepaintWithoutCallback();
489 void WKBundlePageSimulateMouseDown(WKBundlePageRef page, int button, WKPoint position, int clickCount, WKEventModifiers modifiers, double time)
491 toImpl(page)->simulateMouseDown(button, toIntPoint(position), clickCount, modifiers, WallTime::fromRawSeconds(time));
494 void WKBundlePageSimulateMouseUp(WKBundlePageRef page, int button, WKPoint position, int clickCount, WKEventModifiers modifiers, double time)
496 toImpl(page)->simulateMouseUp(button, toIntPoint(position), clickCount, modifiers, WallTime::fromRawSeconds(time));
499 void WKBundlePageSimulateMouseMotion(WKBundlePageRef page, WKPoint position, double time)
501 toImpl(page)->simulateMouseMotion(toIntPoint(position), WallTime::fromRawSeconds(time));
504 uint64_t WKBundlePageGetRenderTreeSize(WKBundlePageRef pageRef)
506 return toImpl(pageRef)->renderTreeSize();
509 WKRenderObjectRef WKBundlePageCopyRenderTree(WKBundlePageRef pageRef)
511 return toAPI(WebRenderObject::create(toImpl(pageRef)).leakRef());
514 WKRenderLayerRef WKBundlePageCopyRenderLayerTree(WKBundlePageRef pageRef)
516 return toAPI(WebRenderLayer::create(toImpl(pageRef)).leakRef());
519 void WKBundlePageSetPaintedObjectsCounterThreshold(WKBundlePageRef, uint64_t)
521 // FIXME: This function is only still here to keep open source Mac builds building.
522 // We should remove it as soon as we can.
525 void WKBundlePageSetTracksRepaints(WKBundlePageRef pageRef, bool trackRepaints)
527 toImpl(pageRef)->setTracksRepaints(trackRepaints);
530 bool WKBundlePageIsTrackingRepaints(WKBundlePageRef pageRef)
532 return toImpl(pageRef)->isTrackingRepaints();
535 void WKBundlePageResetTrackedRepaints(WKBundlePageRef pageRef)
537 toImpl(pageRef)->resetTrackedRepaints();
540 WKArrayRef WKBundlePageCopyTrackedRepaintRects(WKBundlePageRef pageRef)
542 return toAPI(&toImpl(pageRef)->trackedRepaintRects().leakRef());
545 void WKBundlePageSetComposition(WKBundlePageRef pageRef, WKStringRef text, int from, int length, bool suppressUnderline)
547 toImpl(pageRef)->setCompositionForTesting(toWTFString(text), from, length, suppressUnderline);
550 bool WKBundlePageHasComposition(WKBundlePageRef pageRef)
552 return toImpl(pageRef)->hasCompositionForTesting();
555 void WKBundlePageConfirmComposition(WKBundlePageRef pageRef)
557 toImpl(pageRef)->confirmCompositionForTesting(String());
560 void WKBundlePageConfirmCompositionWithText(WKBundlePageRef pageRef, WKStringRef text)
562 toImpl(pageRef)->confirmCompositionForTesting(toWTFString(text));
565 bool WKBundlePageCanShowMIMEType(WKBundlePageRef pageRef, WKStringRef mimeTypeRef)
567 return toImpl(pageRef)->canShowMIMEType(toWTFString(mimeTypeRef));
570 WKRenderingSuppressionToken WKBundlePageExtendIncrementalRenderingSuppression(WKBundlePageRef pageRef)
572 return toImpl(pageRef)->extendIncrementalRenderingSuppression();
575 void WKBundlePageStopExtendingIncrementalRenderingSuppression(WKBundlePageRef pageRef, WKRenderingSuppressionToken token)
577 toImpl(pageRef)->stopExtendingIncrementalRenderingSuppression(token);
580 bool WKBundlePageIsUsingEphemeralSession(WKBundlePageRef pageRef)
582 return toImpl(pageRef)->usesEphemeralSession();
585 bool WKBundlePageIsControlledByAutomation(WKBundlePageRef pageRef)
587 return toImpl(pageRef)->isControlledByAutomation();
591 void WKBundlePageSetUseTestingViewportConfiguration(WKBundlePageRef pageRef, bool useTestingViewportConfiguration)
593 toImpl(pageRef)->setUseTestingViewportConfiguration(useTestingViewportConfiguration);
597 void WKBundlePageStartMonitoringScrollOperations(WKBundlePageRef pageRef)
599 WebKit::WebPage* webPage = toImpl(pageRef);
600 WebCore::Page* page = webPage ? webPage->corePage() : nullptr;
605 page->ensureTestTrigger();
608 void WKBundlePageRegisterScrollOperationCompletionCallback(WKBundlePageRef pageRef, WKBundlePageTestNotificationCallback callback, void* context)
613 WebKit::WebPage* webPage = toImpl(pageRef);
614 WebCore::Page* page = webPage ? webPage->corePage() : nullptr;
615 if (!page || !page->expectsWheelEventTriggers())
618 page->ensureTestTrigger().setTestCallbackAndStartNotificationTimer([=]() {
623 void WKBundlePageCallAfterTasksAndTimers(WKBundlePageRef pageRef, WKBundlePageTestNotificationCallback callback, void* context)
628 WebKit::WebPage* webPage = toImpl(pageRef);
629 WebCore::Page* page = webPage ? webPage->corePage() : nullptr;
633 WebCore::Document* document = page->mainFrame().document();
639 TimerOwner(WTF::Function<void (void*)>&& callback, void* context)
640 : m_timer(*this, &TimerOwner::timerFired)
641 , m_callback(WTFMove(callback))
644 m_timer.startOneShot(0_s);
649 m_callback(m_context);
653 WebCore::Timer m_timer;
654 WTF::Function<void (void*)> m_callback;
658 document->postTask([=] (WebCore::ScriptExecutionContext&) {
659 new TimerOwner(callback, context); // deletes itself when done.
663 void WKBundlePagePostMessage(WKBundlePageRef pageRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef)
665 toImpl(pageRef)->postMessage(toWTFString(messageNameRef), toImpl(messageBodyRef));
668 void WKBundlePagePostSynchronousMessageForTesting(WKBundlePageRef pageRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef, WKTypeRef* returnDataRef)
670 WebPage* page = toImpl(pageRef);
671 page->layoutIfNeeded();
673 RefPtr<API::Object> returnData;
674 page->postSynchronousMessageForTesting(toWTFString(messageNameRef), toImpl(messageBodyRef), returnData);
676 *returnDataRef = toAPI(returnData.leakRef());
679 void WKBundlePageAddUserScript(WKBundlePageRef pageRef, WKStringRef source, _WKUserScriptInjectionTime injectionTime, WKUserContentInjectedFrames injectedFrames)
681 toImpl(pageRef)->addUserScript(toWTFString(source), toUserContentInjectedFrames(injectedFrames), toUserScriptInjectionTime(injectionTime));
684 void WKBundlePageAddUserStyleSheet(WKBundlePageRef pageRef, WKStringRef source, WKUserContentInjectedFrames injectedFrames)
686 toImpl(pageRef)->addUserStyleSheet(toWTFString(source), toUserContentInjectedFrames(injectedFrames));
689 void WKBundlePageRemoveAllUserContent(WKBundlePageRef pageRef)
691 toImpl(pageRef)->removeAllUserContent();
694 WKStringRef WKBundlePageCopyGroupIdentifier(WKBundlePageRef pageRef)
696 return toCopiedAPI(toImpl(pageRef)->pageGroup()->identifier());
699 void WKBundlePageClearApplicationCache(WKBundlePageRef page)
701 toImpl(page)->corePage()->applicationCacheStorage().deleteAllEntries();
704 void WKBundlePageClearApplicationCacheForOrigin(WKBundlePageRef page, WKStringRef origin)
706 toImpl(page)->corePage()->applicationCacheStorage().deleteCacheForOrigin(WebCore::SecurityOrigin::createFromString(toImpl(origin)->string()));
709 void WKBundlePageSetAppCacheMaximumSize(WKBundlePageRef page, uint64_t size)
711 toImpl(page)->corePage()->applicationCacheStorage().setMaximumSize(size);
714 uint64_t WKBundlePageGetAppCacheUsageForOrigin(WKBundlePageRef page, WKStringRef origin)
716 return toImpl(page)->corePage()->applicationCacheStorage().diskUsageForOrigin(WebCore::SecurityOrigin::createFromString(toImpl(origin)->string()));
719 void WKBundlePageSetApplicationCacheOriginQuota(WKBundlePageRef page, WKStringRef origin, uint64_t bytes)
721 toImpl(page)->corePage()->applicationCacheStorage().storeUpdatedQuotaForOrigin(WebCore::SecurityOrigin::createFromString(toImpl(origin)->string()).ptr(), bytes);
724 void WKBundlePageResetApplicationCacheOriginQuota(WKBundlePageRef page, WKStringRef origin)
726 toImpl(page)->corePage()->applicationCacheStorage().storeUpdatedQuotaForOrigin(WebCore::SecurityOrigin::createFromString(toImpl(origin)->string()).ptr(), toImpl(page)->corePage()->applicationCacheStorage().defaultOriginQuota());
729 WKArrayRef WKBundlePageCopyOriginsWithApplicationCache(WKBundlePageRef page)
731 auto origins = toImpl(page)->corePage()->applicationCacheStorage().originsWithCache();
733 Vector<RefPtr<API::Object>> originIdentifiers;
734 originIdentifiers.reserveInitialCapacity(origins.size());
736 for (const auto& origin : origins)
737 originIdentifiers.uncheckedAppend(API::String::create(origin->data().databaseIdentifier()));
739 return toAPI(&API::Array::create(WTFMove(originIdentifiers)).leakRef());
742 void WKBundlePageSetEventThrottlingBehaviorOverride(WKBundlePageRef page, WKEventThrottlingBehavior* behavior)
744 std::optional<WebCore::EventThrottlingBehavior> behaviorValue;
747 case kWKEventThrottlingBehaviorResponsive:
748 behaviorValue = WebCore::EventThrottlingBehavior::Responsive;
750 case kWKEventThrottlingBehaviorUnresponsive:
751 behaviorValue = WebCore::EventThrottlingBehavior::Unresponsive;
756 toImpl(page)->corePage()->setEventThrottlingBehaviorOverride(behaviorValue);
759 void WKBundlePageSetCompositingPolicyOverride(WKBundlePageRef page, WKCompositingPolicy* policy)
761 std::optional<WebCore::CompositingPolicy> policyValue;
764 case kWKCompositingPolicyNormal:
765 policyValue = WebCore::CompositingPolicy::Normal;
767 case kWKCompositingPolicyConservative:
768 policyValue = WebCore::CompositingPolicy::Conservative;
773 toImpl(page)->corePage()->setCompositingPolicyOverride(policyValue);