2 * Copyright (C) 2010, 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.
28 #include "WKPagePrivate.h"
31 #include "APIContextMenuClient.h"
33 #include "APIDictionary.h"
34 #include "APIFindClient.h"
35 #include "APIFrameInfo.h"
36 #include "APIHitTestResult.h"
37 #include "APILoaderClient.h"
38 #include "APINavigationAction.h"
39 #include "APINavigationClient.h"
40 #include "APINavigationResponse.h"
41 #include "APIPageConfiguration.h"
42 #include "APIPolicyClient.h"
43 #include "APISessionState.h"
44 #include "APIUIClient.h"
45 #include "APIWindowFeatures.h"
46 #include "AuthenticationChallengeProxy.h"
47 #include "LegacySessionStateCoding.h"
49 #include "NativeWebKeyboardEvent.h"
50 #include "NativeWebWheelEvent.h"
51 #include "NavigationActionData.h"
52 #include "PluginInformation.h"
53 #include "PrintInfo.h"
54 #include "WKAPICast.h"
55 #include "WKPagePolicyClientInternal.h"
56 #include "WKPageRenderingProgressEventsInternal.h"
57 #include "WKPluginInformation.h"
58 #include "WebBackForwardList.h"
59 #include "WebFormClient.h"
60 #include "WebInspectorProxy.h"
61 #include "WebOpenPanelParameters.h"
62 #include "WebOpenPanelResultListenerProxy.h"
63 #include "WebPageGroup.h"
64 #include "WebPageMessages.h"
65 #include "WebPageProxy.h"
66 #include "WebProcessPool.h"
67 #include "WebProcessProxy.h"
68 #include "WebProtectionSpace.h"
69 #include <WebCore/Page.h>
70 #include <WebCore/SecurityOriginData.h>
71 #include <WebCore/WindowFeatures.h>
77 #if ENABLE(CONTEXT_MENUS)
78 #include "WebContextMenuItem.h"
82 #include "WebVibrationProxy.h"
85 #if ENABLE(MEDIA_SESSION)
86 #include "WebMediaSessionMetadata.h"
87 #include <WebCore/MediaSessionEvents.h>
90 using namespace WebCore;
91 using namespace WebKit;
94 template<> struct ClientTraits<WKPageLoaderClientBase> {
95 typedef std::tuple<WKPageLoaderClientV0, WKPageLoaderClientV1, WKPageLoaderClientV2, WKPageLoaderClientV3, WKPageLoaderClientV4, WKPageLoaderClientV5, WKPageLoaderClientV6> Versions;
98 template<> struct ClientTraits<WKPageNavigationClientBase> {
99 typedef std::tuple<WKPageNavigationClientV0> Versions;
102 template<> struct ClientTraits<WKPagePolicyClientBase> {
103 typedef std::tuple<WKPagePolicyClientV0, WKPagePolicyClientV1, WKPagePolicyClientInternal> Versions;
106 template<> struct ClientTraits<WKPageUIClientBase> {
107 typedef std::tuple<WKPageUIClientV0, WKPageUIClientV1, WKPageUIClientV2, WKPageUIClientV3, WKPageUIClientV4, WKPageUIClientV5, WKPageUIClientV6> Versions;
110 #if ENABLE(CONTEXT_MENUS)
111 template<> struct ClientTraits<WKPageContextMenuClientBase> {
112 typedef std::tuple<WKPageContextMenuClientV0, WKPageContextMenuClientV1, WKPageContextMenuClientV2, WKPageContextMenuClientV3> Versions;
118 WKTypeID WKPageGetTypeID()
120 return toAPI(WebPageProxy::APIType);
123 WKContextRef WKPageGetContext(WKPageRef pageRef)
125 return toAPI(&toImpl(pageRef)->process().processPool());
128 WKPageGroupRef WKPageGetPageGroup(WKPageRef pageRef)
130 return toAPI(&toImpl(pageRef)->pageGroup());
133 WKPageConfigurationRef WKPageCopyPageConfiguration(WKPageRef pageRef)
135 return toAPI(&toImpl(pageRef)->configuration().copy().leakRef());
138 void WKPageLoadURL(WKPageRef pageRef, WKURLRef URLRef)
140 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)));
143 void WKPageLoadURLWithShouldOpenExternalURLsPolicy(WKPageRef pageRef, WKURLRef URLRef, bool shouldOpenExternalURLs)
145 ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLs ? ShouldOpenExternalURLsPolicy::ShouldAllow : ShouldOpenExternalURLsPolicy::ShouldNotAllow;
146 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), shouldOpenExternalURLsPolicy);
149 void WKPageLoadURLWithUserData(WKPageRef pageRef, WKURLRef URLRef, WKTypeRef userDataRef)
151 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef));
154 void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef)
156 toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest());
159 void WKPageLoadURLRequestWithUserData(WKPageRef pageRef, WKURLRequestRef urlRequestRef, WKTypeRef userDataRef)
161 toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest(), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef));
164 void WKPageLoadFile(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL)
166 toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL));
169 void WKPageLoadFileWithUserData(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL, WKTypeRef userDataRef)
171 toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL), toImpl(userDataRef));
174 void WKPageLoadData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef)
176 toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef));
179 void WKPageLoadDataWithUserData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
181 toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef), toImpl(userDataRef));
184 void WKPageLoadHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef)
186 toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef));
189 void WKPageLoadHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
191 toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toImpl(userDataRef));
194 void WKPageLoadAlternateHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef)
196 toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef));
199 void WKPageLoadAlternateHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef, WKTypeRef userDataRef)
201 toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef), toImpl(userDataRef));
204 void WKPageLoadPlainTextString(WKPageRef pageRef, WKStringRef plainTextStringRef)
206 toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef));
209 void WKPageLoadPlainTextStringWithUserData(WKPageRef pageRef, WKStringRef plainTextStringRef, WKTypeRef userDataRef)
211 toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef), toImpl(userDataRef));
214 void WKPageLoadWebArchiveData(WKPageRef pageRef, WKDataRef webArchiveDataRef)
216 toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef));
219 void WKPageLoadWebArchiveDataWithUserData(WKPageRef pageRef, WKDataRef webArchiveDataRef, WKTypeRef userDataRef)
221 toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef), toImpl(userDataRef));
224 void WKPageStopLoading(WKPageRef pageRef)
226 toImpl(pageRef)->stopLoading();
229 void WKPageReload(WKPageRef pageRef)
231 toImpl(pageRef)->reload(false);
234 void WKPageReloadFromOrigin(WKPageRef pageRef)
236 toImpl(pageRef)->reload(true);
239 bool WKPageTryClose(WKPageRef pageRef)
241 return toImpl(pageRef)->tryClose();
244 void WKPageClose(WKPageRef pageRef)
246 toImpl(pageRef)->close();
249 bool WKPageIsClosed(WKPageRef pageRef)
251 return toImpl(pageRef)->isClosed();
254 void WKPageGoForward(WKPageRef pageRef)
256 toImpl(pageRef)->goForward();
259 bool WKPageCanGoForward(WKPageRef pageRef)
261 return toImpl(pageRef)->backForwardList().forwardItem();
264 void WKPageGoBack(WKPageRef pageRef)
266 toImpl(pageRef)->goBack();
269 bool WKPageCanGoBack(WKPageRef pageRef)
271 return toImpl(pageRef)->backForwardList().backItem();
274 void WKPageGoToBackForwardListItem(WKPageRef pageRef, WKBackForwardListItemRef itemRef)
276 toImpl(pageRef)->goToBackForwardItem(toImpl(itemRef));
279 void WKPageTryRestoreScrollPosition(WKPageRef pageRef)
281 toImpl(pageRef)->tryRestoreScrollPosition();
284 WKBackForwardListRef WKPageGetBackForwardList(WKPageRef pageRef)
286 return toAPI(&toImpl(pageRef)->backForwardList());
289 bool WKPageWillHandleHorizontalScrollEvents(WKPageRef pageRef)
291 return toImpl(pageRef)->willHandleHorizontalScrollEvents();
294 WKStringRef WKPageCopyTitle(WKPageRef pageRef)
296 return toCopiedAPI(toImpl(pageRef)->pageLoadState().title());
299 WKFrameRef WKPageGetMainFrame(WKPageRef pageRef)
301 return toAPI(toImpl(pageRef)->mainFrame());
304 WKFrameRef WKPageGetFocusedFrame(WKPageRef pageRef)
306 return toAPI(toImpl(pageRef)->focusedFrame());
309 WKFrameRef WKPageGetFrameSetLargestFrame(WKPageRef pageRef)
311 return toAPI(toImpl(pageRef)->frameSetLargestFrame());
314 uint64_t WKPageGetRenderTreeSize(WKPageRef page)
316 return toImpl(page)->renderTreeSize();
319 WKInspectorRef WKPageGetInspector(WKPageRef pageRef)
321 return toAPI(toImpl(pageRef)->inspector());
324 WKVibrationRef WKPageGetVibration(WKPageRef page)
326 #if ENABLE(VIBRATION)
327 return toAPI(toImpl(page)->vibration());
334 double WKPageGetEstimatedProgress(WKPageRef pageRef)
336 return toImpl(pageRef)->estimatedProgress();
339 WKStringRef WKPageCopyUserAgent(WKPageRef pageRef)
341 return toCopiedAPI(toImpl(pageRef)->userAgent());
344 WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef pageRef)
346 return toCopiedAPI(toImpl(pageRef)->applicationNameForUserAgent());
349 void WKPageSetApplicationNameForUserAgent(WKPageRef pageRef, WKStringRef applicationNameRef)
351 toImpl(pageRef)->setApplicationNameForUserAgent(toWTFString(applicationNameRef));
354 WKStringRef WKPageCopyCustomUserAgent(WKPageRef pageRef)
356 return toCopiedAPI(toImpl(pageRef)->customUserAgent());
359 void WKPageSetCustomUserAgent(WKPageRef pageRef, WKStringRef userAgentRef)
361 toImpl(pageRef)->setCustomUserAgent(toWTFString(userAgentRef));
364 void WKPageSetUserContentExtensionsEnabled(WKPageRef pageRef, bool enabled)
366 toImpl(pageRef)->setUserContentExtensionsEnabled(enabled);
369 bool WKPageSupportsTextEncoding(WKPageRef pageRef)
371 return toImpl(pageRef)->supportsTextEncoding();
374 WKStringRef WKPageCopyCustomTextEncodingName(WKPageRef pageRef)
376 return toCopiedAPI(toImpl(pageRef)->customTextEncodingName());
379 void WKPageSetCustomTextEncodingName(WKPageRef pageRef, WKStringRef encodingNameRef)
381 toImpl(pageRef)->setCustomTextEncodingName(toWTFString(encodingNameRef));
384 void WKPageTerminate(WKPageRef pageRef)
386 toImpl(pageRef)->terminateProcess();
389 WKStringRef WKPageGetSessionHistoryURLValueType()
391 static API::String& sessionHistoryURLValueType = API::String::create("SessionHistoryURL").leakRef();
392 return toAPI(&sessionHistoryURLValueType);
395 WKStringRef WKPageGetSessionBackForwardListItemValueType()
397 static API::String& sessionBackForwardListValueType = API::String::create("SessionBackForwardListItem").leakRef();
398 return toAPI(&sessionBackForwardListValueType);
401 WKTypeRef WKPageCopySessionState(WKPageRef pageRef, void* context, WKPageSessionStateFilterCallback filter)
403 // FIXME: This is a hack to make sure we return a WKDataRef to maintain compatibility with older versions of Safari.
404 bool shouldReturnData = !(reinterpret_cast<uintptr_t>(context) & 1);
405 context = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(context) & ~1);
407 auto sessionState = toImpl(pageRef)->sessionState([pageRef, context, filter](WebBackForwardListItem& item) {
409 if (!filter(pageRef, WKPageGetSessionBackForwardListItemValueType(), toAPI(&item), context))
412 if (!filter(pageRef, WKPageGetSessionHistoryURLValueType(), toURLRef(item.originalURL().impl()), context))
419 if (shouldReturnData)
420 return toAPI(encodeLegacySessionState(sessionState).release().leakRef());
422 return toAPI(&API::SessionState::create(WTF::move(sessionState)).leakRef());
425 void WKPageRestoreFromSessionState(WKPageRef pageRef, WKTypeRef sessionStateRef)
427 SessionState sessionState;
429 // FIXME: This is for backwards compatibility with Safari. Remove it once Safari no longer depends on it.
430 if (toImpl(sessionStateRef)->type() == API::Object::Type::Data) {
431 if (!decodeLegacySessionState(toImpl(static_cast<WKDataRef>(sessionStateRef))->bytes(), toImpl(static_cast<WKDataRef>(sessionStateRef))->size(), sessionState))
434 ASSERT(toImpl(sessionStateRef)->type() == API::Object::Type::SessionState);
436 sessionState = toImpl(static_cast<WKSessionStateRef>(sessionStateRef))->sessionState();
439 toImpl(pageRef)->restoreFromSessionState(WTF::move(sessionState), true);
442 double WKPageGetTextZoomFactor(WKPageRef pageRef)
444 return toImpl(pageRef)->textZoomFactor();
447 double WKPageGetBackingScaleFactor(WKPageRef pageRef)
449 return toImpl(pageRef)->deviceScaleFactor();
452 void WKPageSetCustomBackingScaleFactor(WKPageRef pageRef, double customScaleFactor)
454 toImpl(pageRef)->setCustomDeviceScaleFactor(customScaleFactor);
457 bool WKPageSupportsTextZoom(WKPageRef pageRef)
459 return toImpl(pageRef)->supportsTextZoom();
462 void WKPageSetTextZoomFactor(WKPageRef pageRef, double zoomFactor)
464 toImpl(pageRef)->setTextZoomFactor(zoomFactor);
467 double WKPageGetPageZoomFactor(WKPageRef pageRef)
469 return toImpl(pageRef)->pageZoomFactor();
472 void WKPageSetPageZoomFactor(WKPageRef pageRef, double zoomFactor)
474 toImpl(pageRef)->setPageZoomFactor(zoomFactor);
477 void WKPageSetPageAndTextZoomFactors(WKPageRef pageRef, double pageZoomFactor, double textZoomFactor)
479 toImpl(pageRef)->setPageAndTextZoomFactors(pageZoomFactor, textZoomFactor);
482 void WKPageSetScaleFactor(WKPageRef pageRef, double scale, WKPoint origin)
484 toImpl(pageRef)->scalePage(scale, toIntPoint(origin));
487 double WKPageGetScaleFactor(WKPageRef pageRef)
489 return toImpl(pageRef)->pageScaleFactor();
492 void WKPageSetUseFixedLayout(WKPageRef pageRef, bool fixed)
494 toImpl(pageRef)->setUseFixedLayout(fixed);
497 void WKPageSetFixedLayoutSize(WKPageRef pageRef, WKSize size)
499 toImpl(pageRef)->setFixedLayoutSize(toIntSize(size));
502 bool WKPageUseFixedLayout(WKPageRef pageRef)
504 return toImpl(pageRef)->useFixedLayout();
507 WKSize WKPageFixedLayoutSize(WKPageRef pageRef)
509 return toAPI(toImpl(pageRef)->fixedLayoutSize());
512 void WKPageListenForLayoutMilestones(WKPageRef pageRef, WKLayoutMilestones milestones)
514 toImpl(pageRef)->listenForLayoutMilestones(toLayoutMilestones(milestones));
517 bool WKPageHasHorizontalScrollbar(WKPageRef pageRef)
519 return toImpl(pageRef)->hasHorizontalScrollbar();
522 bool WKPageHasVerticalScrollbar(WKPageRef pageRef)
524 return toImpl(pageRef)->hasVerticalScrollbar();
527 void WKPageSetSuppressScrollbarAnimations(WKPageRef pageRef, bool suppressAnimations)
529 toImpl(pageRef)->setSuppressScrollbarAnimations(suppressAnimations);
532 bool WKPageAreScrollbarAnimationsSuppressed(WKPageRef pageRef)
534 return toImpl(pageRef)->areScrollbarAnimationsSuppressed();
537 bool WKPageIsPinnedToLeftSide(WKPageRef pageRef)
539 return toImpl(pageRef)->isPinnedToLeftSide();
542 bool WKPageIsPinnedToRightSide(WKPageRef pageRef)
544 return toImpl(pageRef)->isPinnedToRightSide();
547 bool WKPageIsPinnedToTopSide(WKPageRef pageRef)
549 return toImpl(pageRef)->isPinnedToTopSide();
552 bool WKPageIsPinnedToBottomSide(WKPageRef pageRef)
554 return toImpl(pageRef)->isPinnedToBottomSide();
557 bool WKPageRubberBandsAtLeft(WKPageRef pageRef)
559 return toImpl(pageRef)->rubberBandsAtLeft();
562 void WKPageSetRubberBandsAtLeft(WKPageRef pageRef, bool rubberBandsAtLeft)
564 toImpl(pageRef)->setRubberBandsAtLeft(rubberBandsAtLeft);
567 bool WKPageRubberBandsAtRight(WKPageRef pageRef)
569 return toImpl(pageRef)->rubberBandsAtRight();
572 void WKPageSetRubberBandsAtRight(WKPageRef pageRef, bool rubberBandsAtRight)
574 toImpl(pageRef)->setRubberBandsAtRight(rubberBandsAtRight);
577 bool WKPageRubberBandsAtTop(WKPageRef pageRef)
579 return toImpl(pageRef)->rubberBandsAtTop();
582 void WKPageSetRubberBandsAtTop(WKPageRef pageRef, bool rubberBandsAtTop)
584 toImpl(pageRef)->setRubberBandsAtTop(rubberBandsAtTop);
587 bool WKPageRubberBandsAtBottom(WKPageRef pageRef)
589 return toImpl(pageRef)->rubberBandsAtBottom();
592 void WKPageSetRubberBandsAtBottom(WKPageRef pageRef, bool rubberBandsAtBottom)
594 toImpl(pageRef)->setRubberBandsAtBottom(rubberBandsAtBottom);
597 bool WKPageVerticalRubberBandingIsEnabled(WKPageRef pageRef)
599 return toImpl(pageRef)->verticalRubberBandingIsEnabled();
602 void WKPageSetEnableVerticalRubberBanding(WKPageRef pageRef, bool enableVerticalRubberBanding)
604 toImpl(pageRef)->setEnableVerticalRubberBanding(enableVerticalRubberBanding);
607 bool WKPageHorizontalRubberBandingIsEnabled(WKPageRef pageRef)
609 return toImpl(pageRef)->horizontalRubberBandingIsEnabled();
612 void WKPageSetEnableHorizontalRubberBanding(WKPageRef pageRef, bool enableHorizontalRubberBanding)
614 toImpl(pageRef)->setEnableHorizontalRubberBanding(enableHorizontalRubberBanding);
617 void WKPageSetBackgroundExtendsBeyondPage(WKPageRef pageRef, bool backgroundExtendsBeyondPage)
619 toImpl(pageRef)->setBackgroundExtendsBeyondPage(backgroundExtendsBeyondPage);
622 bool WKPageBackgroundExtendsBeyondPage(WKPageRef pageRef)
624 return toImpl(pageRef)->backgroundExtendsBeyondPage();
627 void WKPageSetPaginationMode(WKPageRef pageRef, WKPaginationMode paginationMode)
629 Pagination::Mode mode;
630 switch (paginationMode) {
631 case kWKPaginationModeUnpaginated:
632 mode = Pagination::Unpaginated;
634 case kWKPaginationModeLeftToRight:
635 mode = Pagination::LeftToRightPaginated;
637 case kWKPaginationModeRightToLeft:
638 mode = Pagination::RightToLeftPaginated;
640 case kWKPaginationModeTopToBottom:
641 mode = Pagination::TopToBottomPaginated;
643 case kWKPaginationModeBottomToTop:
644 mode = Pagination::BottomToTopPaginated;
649 toImpl(pageRef)->setPaginationMode(mode);
652 WKPaginationMode WKPageGetPaginationMode(WKPageRef pageRef)
654 switch (toImpl(pageRef)->paginationMode()) {
655 case Pagination::Unpaginated:
656 return kWKPaginationModeUnpaginated;
657 case Pagination::LeftToRightPaginated:
658 return kWKPaginationModeLeftToRight;
659 case Pagination::RightToLeftPaginated:
660 return kWKPaginationModeRightToLeft;
661 case Pagination::TopToBottomPaginated:
662 return kWKPaginationModeTopToBottom;
663 case Pagination::BottomToTopPaginated:
664 return kWKPaginationModeBottomToTop;
667 ASSERT_NOT_REACHED();
668 return kWKPaginationModeUnpaginated;
671 void WKPageSetPaginationBehavesLikeColumns(WKPageRef pageRef, bool behavesLikeColumns)
673 toImpl(pageRef)->setPaginationBehavesLikeColumns(behavesLikeColumns);
676 bool WKPageGetPaginationBehavesLikeColumns(WKPageRef pageRef)
678 return toImpl(pageRef)->paginationBehavesLikeColumns();
681 void WKPageSetPageLength(WKPageRef pageRef, double pageLength)
683 toImpl(pageRef)->setPageLength(pageLength);
686 double WKPageGetPageLength(WKPageRef pageRef)
688 return toImpl(pageRef)->pageLength();
691 void WKPageSetGapBetweenPages(WKPageRef pageRef, double gap)
693 toImpl(pageRef)->setGapBetweenPages(gap);
696 double WKPageGetGapBetweenPages(WKPageRef pageRef)
698 return toImpl(pageRef)->gapBetweenPages();
701 unsigned WKPageGetPageCount(WKPageRef pageRef)
703 return toImpl(pageRef)->pageCount();
706 bool WKPageCanDelete(WKPageRef pageRef)
708 return toImpl(pageRef)->canDelete();
711 bool WKPageHasSelectedRange(WKPageRef pageRef)
713 return toImpl(pageRef)->hasSelectedRange();
716 bool WKPageIsContentEditable(WKPageRef pageRef)
718 return toImpl(pageRef)->isContentEditable();
721 void WKPageSetMaintainsInactiveSelection(WKPageRef pageRef, bool newValue)
723 return toImpl(pageRef)->setMaintainsInactiveSelection(newValue);
726 void WKPageCenterSelectionInVisibleArea(WKPageRef pageRef)
728 return toImpl(pageRef)->centerSelectionInVisibleArea();
731 void WKPageFindStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
733 toImpl(pageRef)->findStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
736 void WKPageGetImageForFindMatch(WKPageRef pageRef, int32_t matchIndex)
738 toImpl(pageRef)->getImageForFindMatch(matchIndex);
741 void WKPageSelectFindMatch(WKPageRef pageRef, int32_t matchIndex)
743 toImpl(pageRef)->selectFindMatch(matchIndex);
746 void WKPageFindString(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
748 toImpl(pageRef)->findString(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
751 void WKPageHideFindUI(WKPageRef pageRef)
753 toImpl(pageRef)->hideFindUI();
756 void WKPageCountStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
758 toImpl(pageRef)->countStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
761 void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuClientBase* wkClient)
763 #if ENABLE(CONTEXT_MENUS)
764 class ContextMenuClient final : public API::Client<WKPageContextMenuClientBase>, public API::ContextMenuClient {
766 explicit ContextMenuClient(const WKPageContextMenuClientBase* client)
772 virtual bool getContextMenuFromProposedMenu(WebPageProxy& page, const Vector<RefPtr<WebKit::WebContextMenuItem>>& proposedMenuVector, Vector<RefPtr<WebKit::WebContextMenuItem>>& customMenu, const WebHitTestResultData& hitTestResultData, API::Object* userData) override
774 if (!m_client.getContextMenuFromProposedMenu && !m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0)
777 if (m_client.base.version >= 2 && !m_client.getContextMenuFromProposedMenu)
780 Vector<RefPtr<API::Object>> proposedMenuItems;
781 proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size());
783 for (const auto& menuItem : proposedMenuVector)
784 proposedMenuItems.uncheckedAppend(menuItem);
786 WKArrayRef newMenu = nullptr;
787 if (m_client.base.version >= 2) {
788 RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(hitTestResultData);
789 m_client.getContextMenuFromProposedMenu(toAPI(&page), toAPI(API::Array::create(WTF::move(proposedMenuItems)).ptr()), &newMenu, toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo);
791 m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0(toAPI(&page), toAPI(API::Array::create(WTF::move(proposedMenuItems)).ptr()), &newMenu, toAPI(userData), m_client.base.clientInfo);
793 RefPtr<API::Array> array = adoptRef(toImpl(newMenu));
797 size_t newSize = array ? array->size() : 0;
798 for (size_t i = 0; i < newSize; ++i) {
799 WebContextMenuItem* item = array->at<WebContextMenuItem>(i);
801 LOG(ContextMenu, "New menu entry at index %i is not a WebContextMenuItem", (int)i);
805 customMenu.append(item);
811 virtual void customContextMenuItemSelected(WebPageProxy& page, const WebContextMenuItemData& itemData) override
813 if (!m_client.customContextMenuItemSelected)
816 m_client.customContextMenuItemSelected(toAPI(&page), toAPI(WebContextMenuItem::create(itemData).ptr()), m_client.base.clientInfo);
819 virtual void contextMenuDismissed(WebPageProxy& page) override
821 if (!m_client.contextMenuDismissed)
824 m_client.contextMenuDismissed(toAPI(&page), m_client.base.clientInfo);
827 virtual bool showContextMenu(WebPageProxy& page, const WebCore::IntPoint& menuLocation, const Vector<RefPtr<WebContextMenuItem>>& menuItemsVector) override
829 if (!m_client.showContextMenu)
832 Vector<RefPtr<API::Object>> menuItems;
833 menuItems.reserveInitialCapacity(menuItemsVector.size());
835 for (const auto& menuItem : menuItemsVector)
836 menuItems.uncheckedAppend(menuItem);
838 m_client.showContextMenu(toAPI(&page), toAPI(menuLocation), toAPI(API::Array::create(WTF::move(menuItems)).ptr()), m_client.base.clientInfo);
843 virtual bool hideContextMenu(WebPageProxy& page) override
845 if (!m_client.hideContextMenu)
848 m_client.hideContextMenu(toAPI(&page), m_client.base.clientInfo);
854 toImpl(pageRef)->setContextMenuClient(std::make_unique<ContextMenuClient>(wkClient));
856 UNUSED_PARAM(pageRef);
857 UNUSED_PARAM(wkClient);
861 void WKPageSetPageDiagnosticLoggingClient(WKPageRef pageRef, const WKPageDiagnosticLoggingClientBase* wkClient)
863 toImpl(pageRef)->setDiagnosticLoggingClient(std::make_unique<WebPageDiagnosticLoggingClient>(wkClient));
866 void WKPageSetPageFindClient(WKPageRef pageRef, const WKPageFindClientBase* wkClient)
868 class FindClient : public API::Client<WKPageFindClientBase>, public API::FindClient {
870 explicit FindClient(const WKPageFindClientBase* client)
876 virtual void didFindString(WebPageProxy* page, const String& string, uint32_t matchCount, int32_t) override
878 if (!m_client.didFindString)
881 m_client.didFindString(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
884 virtual void didFailToFindString(WebPageProxy* page, const String& string) override
886 if (!m_client.didFailToFindString)
889 m_client.didFailToFindString(toAPI(page), toAPI(string.impl()), m_client.base.clientInfo);
892 virtual void didCountStringMatches(WebPageProxy* page, const String& string, uint32_t matchCount) override
894 if (!m_client.didCountStringMatches)
897 m_client.didCountStringMatches(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
901 toImpl(pageRef)->setFindClient(std::make_unique<FindClient>(wkClient));
904 void WKPageSetPageFindMatchesClient(WKPageRef pageRef, const WKPageFindMatchesClientBase* wkClient)
906 toImpl(pageRef)->initializeFindMatchesClient(wkClient);
909 void WKPageSetPageInjectedBundleClient(WKPageRef pageRef, const WKPageInjectedBundleClientBase* wkClient)
911 toImpl(pageRef)->setInjectedBundleClient(wkClient);
914 void WKPageSetPageFormClient(WKPageRef pageRef, const WKPageFormClientBase* wkClient)
916 toImpl(pageRef)->setFormClient(std::make_unique<WebFormClient>(wkClient));
919 void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase* wkClient)
921 class LoaderClient : public API::Client<WKPageLoaderClientBase>, public API::LoaderClient {
923 explicit LoaderClient(const WKPageLoaderClientBase* client)
929 virtual void didStartProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
931 if (!m_client.didStartProvisionalLoadForFrame)
934 m_client.didStartProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
937 virtual void didReceiveServerRedirectForProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
939 if (!m_client.didReceiveServerRedirectForProvisionalLoadForFrame)
942 m_client.didReceiveServerRedirectForProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
945 virtual void didFailProvisionalLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
947 if (!m_client.didFailProvisionalLoadWithErrorForFrame)
950 m_client.didFailProvisionalLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
953 virtual void didCommitLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
955 if (!m_client.didCommitLoadForFrame)
958 m_client.didCommitLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
961 virtual void didFinishDocumentLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
963 if (!m_client.didFinishDocumentLoadForFrame)
966 m_client.didFinishDocumentLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
969 virtual void didFinishLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
971 if (!m_client.didFinishLoadForFrame)
974 m_client.didFinishLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
977 virtual void didFailLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
979 if (!m_client.didFailLoadWithErrorForFrame)
982 m_client.didFailLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
985 virtual void didSameDocumentNavigationForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, SameDocumentNavigationType type, API::Object* userData) override
987 if (!m_client.didSameDocumentNavigationForFrame)
990 m_client.didSameDocumentNavigationForFrame(toAPI(&page), toAPI(&frame), toAPI(type), toAPI(userData), m_client.base.clientInfo);
993 virtual void didReceiveTitleForFrame(WebPageProxy& page, const String& title, WebFrameProxy& frame, API::Object* userData) override
995 if (!m_client.didReceiveTitleForFrame)
998 m_client.didReceiveTitleForFrame(toAPI(&page), toAPI(title.impl()), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1001 virtual void didFirstLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1003 if (!m_client.didFirstLayoutForFrame)
1006 m_client.didFirstLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1009 virtual void didFirstVisuallyNonEmptyLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1011 if (!m_client.didFirstVisuallyNonEmptyLayoutForFrame)
1014 m_client.didFirstVisuallyNonEmptyLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1017 virtual void didLayout(WebPageProxy& page, LayoutMilestones milestones) override
1019 if (!m_client.didLayout)
1022 m_client.didLayout(toAPI(&page), toWKLayoutMilestones(milestones), nullptr, m_client.base.clientInfo);
1025 virtual void didRemoveFrameFromHierarchy(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1027 if (!m_client.didRemoveFrameFromHierarchy)
1030 m_client.didRemoveFrameFromHierarchy(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1033 virtual void didDisplayInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1035 if (!m_client.didDisplayInsecureContentForFrame)
1038 m_client.didDisplayInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1041 virtual void didRunInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1043 if (!m_client.didRunInsecureContentForFrame)
1046 m_client.didRunInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1049 virtual void didDetectXSSForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1051 if (!m_client.didDetectXSSForFrame)
1054 m_client.didDetectXSSForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1057 virtual bool canAuthenticateAgainstProtectionSpaceInFrame(WebPageProxy& page, WebFrameProxy& frame, WebProtectionSpace* protectionSpace) override
1059 if (!m_client.canAuthenticateAgainstProtectionSpaceInFrame)
1062 return m_client.canAuthenticateAgainstProtectionSpaceInFrame(toAPI(&page), toAPI(&frame), toAPI(protectionSpace), m_client.base.clientInfo);
1065 virtual void didReceiveAuthenticationChallengeInFrame(WebPageProxy& page, WebFrameProxy& frame, AuthenticationChallengeProxy* authenticationChallenge) override
1067 if (!m_client.didReceiveAuthenticationChallengeInFrame)
1070 m_client.didReceiveAuthenticationChallengeInFrame(toAPI(&page), toAPI(&frame), toAPI(authenticationChallenge), m_client.base.clientInfo);
1073 virtual void didStartProgress(WebPageProxy& page) override
1075 if (!m_client.didStartProgress)
1078 m_client.didStartProgress(toAPI(&page), m_client.base.clientInfo);
1081 virtual void didChangeProgress(WebPageProxy& page) override
1083 if (!m_client.didChangeProgress)
1086 m_client.didChangeProgress(toAPI(&page), m_client.base.clientInfo);
1089 virtual void didFinishProgress(WebPageProxy& page) override
1091 if (!m_client.didFinishProgress)
1094 m_client.didFinishProgress(toAPI(&page), m_client.base.clientInfo);
1097 virtual void processDidBecomeUnresponsive(WebPageProxy& page) override
1099 if (!m_client.processDidBecomeUnresponsive)
1102 m_client.processDidBecomeUnresponsive(toAPI(&page), m_client.base.clientInfo);
1105 virtual void interactionOccurredWhileProcessUnresponsive(WebPageProxy& page) override
1107 if (!m_client.interactionOccurredWhileProcessUnresponsive)
1110 m_client.interactionOccurredWhileProcessUnresponsive(toAPI(&page), m_client.base.clientInfo);
1113 virtual void processDidBecomeResponsive(WebPageProxy& page) override
1115 if (!m_client.processDidBecomeResponsive)
1118 m_client.processDidBecomeResponsive(toAPI(&page), m_client.base.clientInfo);
1121 virtual void processDidCrash(WebPageProxy& page) override
1123 if (!m_client.processDidCrash)
1126 m_client.processDidCrash(toAPI(&page), m_client.base.clientInfo);
1129 virtual void didChangeBackForwardList(WebPageProxy& page, WebBackForwardListItem* addedItem, Vector<RefPtr<WebBackForwardListItem>> removedItems) override
1131 if (!m_client.didChangeBackForwardList)
1134 RefPtr<API::Array> removedItemsArray;
1135 if (!removedItems.isEmpty()) {
1136 Vector<RefPtr<API::Object>> removedItemsVector;
1137 removedItemsVector.reserveInitialCapacity(removedItems.size());
1138 for (auto& removedItem : removedItems)
1139 removedItemsVector.append(WTF::move(removedItem));
1141 removedItemsArray = API::Array::create(WTF::move(removedItemsVector));
1144 m_client.didChangeBackForwardList(toAPI(&page), toAPI(addedItem), toAPI(removedItemsArray.get()), m_client.base.clientInfo);
1147 virtual bool shouldKeepCurrentBackForwardListItemInList(WebKit::WebPageProxy& page, WebKit::WebBackForwardListItem* item) override
1149 if (!m_client.shouldKeepCurrentBackForwardListItemInList)
1152 return m_client.shouldKeepCurrentBackForwardListItemInList(toAPI(&page), toAPI(item), m_client.base.clientInfo);
1155 virtual void willGoToBackForwardListItem(WebPageProxy& page, WebBackForwardListItem* item, API::Object* userData) override
1157 if (m_client.willGoToBackForwardListItem)
1158 m_client.willGoToBackForwardListItem(toAPI(&page), toAPI(item), toAPI(userData), m_client.base.clientInfo);
1161 virtual RefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
1163 return page.process().processPool().client().copyWebCryptoMasterKey(&page.process().processPool());
1166 virtual void navigationGestureDidBegin(WebPageProxy& page) override
1168 if (m_client.navigationGestureDidBegin)
1169 m_client.navigationGestureDidBegin(toAPI(&page), m_client.base.clientInfo);
1172 virtual void navigationGestureWillEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override
1174 if (m_client.navigationGestureWillEnd)
1175 m_client.navigationGestureWillEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo);
1178 virtual void navigationGestureDidEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override
1180 if (m_client.navigationGestureDidEnd)
1181 m_client.navigationGestureDidEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo);
1184 #if ENABLE(NETSCAPE_PLUGIN_API)
1185 virtual void didFailToInitializePlugin(WebPageProxy& page, API::Dictionary* pluginInformation) override
1187 if (m_client.didFailToInitializePlugin_deprecatedForUseWithV0)
1188 m_client.didFailToInitializePlugin_deprecatedForUseWithV0(toAPI(&page), toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), m_client.base.clientInfo);
1190 if (m_client.pluginDidFail_deprecatedForUseWithV1)
1191 m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), 0, 0, m_client.base.clientInfo);
1193 if (m_client.pluginDidFail)
1194 m_client.pluginDidFail(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation), m_client.base.clientInfo);
1197 virtual void didBlockInsecurePluginVersion(WebPageProxy& page, API::Dictionary* pluginInformation) override
1199 if (m_client.pluginDidFail_deprecatedForUseWithV1)
1200 m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(&page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), toAPI(pluginInformation->get<API::String>(pluginInformationBundleIdentifierKey())), toAPI(pluginInformation->get<API::String>(pluginInformationBundleVersionKey())), m_client.base.clientInfo);
1202 if (m_client.pluginDidFail)
1203 m_client.pluginDidFail(toAPI(&page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation), m_client.base.clientInfo);
1206 virtual PluginModuleLoadPolicy pluginLoadPolicy(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
1208 WKStringRef unavailabilityDescriptionOut = 0;
1209 PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
1211 if (m_client.pluginLoadPolicy_deprecatedForUseWithV2)
1212 loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy_deprecatedForUseWithV2(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), m_client.base.clientInfo));
1213 else if (m_client.pluginLoadPolicy)
1214 loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
1216 if (unavailabilityDescriptionOut) {
1217 RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
1218 unavailabilityDescription = webUnavailabilityDescription->string();
1223 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1226 virtual WebCore::WebGLLoadPolicy webGLLoadPolicy(WebPageProxy& page, const String& url) const override
1228 WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
1230 if (m_client.webGLLoadPolicy)
1231 loadPolicy = toWebGLLoadPolicy(m_client.webGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
1236 virtual WebCore::WebGLLoadPolicy resolveWebGLLoadPolicy(WebPageProxy& page, const String& url) const override
1238 WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
1240 if (m_client.resolveWebGLLoadPolicy)
1241 loadPolicy = toWebGLLoadPolicy(m_client.resolveWebGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
1246 #endif // ENABLE(WEBGL)
1249 WebPageProxy* webPageProxy = toImpl(pageRef);
1251 auto loaderClient = std::make_unique<LoaderClient>(wkClient);
1253 // It would be nice to get rid of this code and transition all clients to using didLayout instead of
1254 // didFirstLayoutInFrame and didFirstVisuallyNonEmptyLayoutInFrame. In the meantime, this is required
1255 // for backwards compatibility.
1256 WebCore::LayoutMilestones milestones = 0;
1257 if (loaderClient->client().didFirstLayoutForFrame)
1258 milestones |= WebCore::DidFirstLayout;
1259 if (loaderClient->client().didFirstVisuallyNonEmptyLayoutForFrame)
1260 milestones |= WebCore::DidFirstVisuallyNonEmptyLayout;
1263 webPageProxy->process().send(Messages::WebPage::ListenForLayoutMilestones(milestones), webPageProxy->pageID());
1265 webPageProxy->setLoaderClient(WTF::move(loaderClient));
1268 void WKPageSetPagePolicyClient(WKPageRef pageRef, const WKPagePolicyClientBase* wkClient)
1270 class PolicyClient : public API::Client<WKPagePolicyClientBase>, public API::PolicyClient {
1272 explicit PolicyClient(const WKPagePolicyClientBase* client)
1278 virtual void decidePolicyForNavigationAction(WebPageProxy& page, WebFrameProxy* frame, const NavigationActionData& navigationActionData, WebFrameProxy* originatingFrame, const WebCore::ResourceRequest& originalResourceRequest, const WebCore::ResourceRequest& resourceRequest, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1280 if (!m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0 && !m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1 && !m_client.decidePolicyForNavigationAction) {
1285 Ref<API::URLRequest> originalRequest = API::URLRequest::create(originalResourceRequest);
1286 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1288 if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0)
1289 m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0(toAPI(&page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1290 else if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1)
1291 m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1(toAPI(&page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(originatingFrame), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1293 m_client.decidePolicyForNavigationAction(toAPI(&page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(originatingFrame), toAPI(originalRequest.ptr()), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1296 virtual void decidePolicyForNewWindowAction(WebPageProxy& page, WebFrameProxy& frame, const NavigationActionData& navigationActionData, const ResourceRequest& resourceRequest, const String& frameName, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1298 if (!m_client.decidePolicyForNewWindowAction) {
1303 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1305 m_client.decidePolicyForNewWindowAction(toAPI(&page), toAPI(&frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(request.ptr()), toAPI(frameName.impl()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1308 virtual void decidePolicyForResponse(WebPageProxy& page, WebFrameProxy& frame, const ResourceResponse& resourceResponse, const ResourceRequest& resourceRequest, bool canShowMIMEType, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1310 if (!m_client.decidePolicyForResponse_deprecatedForUseWithV0 && !m_client.decidePolicyForResponse) {
1315 Ref<API::URLResponse> response = API::URLResponse::create(resourceResponse);
1316 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1318 if (m_client.decidePolicyForResponse_deprecatedForUseWithV0)
1319 m_client.decidePolicyForResponse_deprecatedForUseWithV0(toAPI(&page), toAPI(&frame), toAPI(response.ptr()), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1321 m_client.decidePolicyForResponse(toAPI(&page), toAPI(&frame), toAPI(response.ptr()), toAPI(request.ptr()), canShowMIMEType, toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1324 virtual void unableToImplementPolicy(WebPageProxy& page, WebFrameProxy& frame, const ResourceError& error, API::Object* userData) override
1326 if (!m_client.unableToImplementPolicy)
1329 m_client.unableToImplementPolicy(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1333 toImpl(pageRef)->setPolicyClient(std::make_unique<PolicyClient>(wkClient));
1336 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000
1337 static void fixUpBotchedPageUIClient(WKPageRef pageRef, const WKPageUIClientBase& wkClient)
1339 struct BotchedWKPageUIClientV4 {
1340 WKPageUIClientBase base;
1343 WKPageCreateNewPageCallback_deprecatedForUseWithV0 createNewPage_deprecatedForUseWithV0;
1344 WKPageUIClientCallback showPage;
1345 WKPageUIClientCallback close;
1346 WKPageTakeFocusCallback takeFocus;
1347 WKPageFocusCallback focus;
1348 WKPageUnfocusCallback unfocus;
1349 WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert_deprecatedForUseWithV0;
1350 WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm_deprecatedForUseWithV0;
1351 WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt_deprecatedForUseWithV0;
1352 WKPageSetStatusTextCallback setStatusText;
1353 WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0;
1354 WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0;
1355 WKPageDidNotHandleKeyEventCallback didNotHandleKeyEvent;
1356 WKPageDidNotHandleWheelEventCallback didNotHandleWheelEvent;
1357 WKPageGetToolbarsAreVisibleCallback toolbarsAreVisible;
1358 WKPageSetToolbarsAreVisibleCallback setToolbarsAreVisible;
1359 WKPageGetMenuBarIsVisibleCallback menuBarIsVisible;
1360 WKPageSetMenuBarIsVisibleCallback setMenuBarIsVisible;
1361 WKPageGetStatusBarIsVisibleCallback statusBarIsVisible;
1362 WKPageSetStatusBarIsVisibleCallback setStatusBarIsVisible;
1363 WKPageGetIsResizableCallback isResizable;
1364 WKPageSetIsResizableCallback setIsResizable;
1365 WKPageGetWindowFrameCallback getWindowFrame;
1366 WKPageSetWindowFrameCallback setWindowFrame;
1367 WKPageRunBeforeUnloadConfirmPanelCallback runBeforeUnloadConfirmPanel;
1368 WKPageUIClientCallback didDraw;
1369 WKPageUIClientCallback pageDidScroll;
1370 WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota;
1371 WKPageRunOpenPanelCallback runOpenPanel;
1372 WKPageDecidePolicyForGeolocationPermissionRequestCallback decidePolicyForGeolocationPermissionRequest;
1373 WKPageHeaderHeightCallback headerHeight;
1374 WKPageFooterHeightCallback footerHeight;
1375 WKPageDrawHeaderCallback drawHeader;
1376 WKPageDrawFooterCallback drawFooter;
1377 WKPagePrintFrameCallback printFrame;
1378 WKPageUIClientCallback runModal;
1379 void* unused1; // Used to be didCompleteRubberBandForMainFrame
1380 WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder;
1381 void* shouldInterruptJavaScript_unavailable;
1384 WKPageCreateNewPageCallback_deprecatedForUseWithV1 createNewPage;
1385 WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement;
1386 WKPageDecidePolicyForNotificationPermissionRequestCallback decidePolicyForNotificationPermissionRequest;
1387 WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1;
1390 WKPageShowColorPickerCallback showColorPicker;
1391 WKPageHideColorPickerCallback hideColorPicker;
1392 WKPageUnavailablePluginButtonClickedCallback unavailablePluginButtonClicked;
1395 WKPagePinnedStateDidChangeCallback pinnedStateDidChange;
1398 WKPageRunJavaScriptAlertCallback runJavaScriptAlert;
1399 WKPageRunJavaScriptConfirmCallback runJavaScriptConfirm;
1400 WKPageRunJavaScriptPromptCallback runJavaScriptPrompt;
1403 const auto& botchedPageUIClient = reinterpret_cast<const BotchedWKPageUIClientV4&>(wkClient);
1405 WKPageUIClientV5 fixedPageUIClient = {
1406 { 5, botchedPageUIClient.base.clientInfo },
1407 botchedPageUIClient.createNewPage_deprecatedForUseWithV0,
1408 botchedPageUIClient.showPage,
1409 botchedPageUIClient.close,
1410 botchedPageUIClient.takeFocus,
1411 botchedPageUIClient.focus,
1412 botchedPageUIClient.unfocus,
1413 botchedPageUIClient.runJavaScriptAlert_deprecatedForUseWithV0,
1414 botchedPageUIClient.runJavaScriptConfirm_deprecatedForUseWithV0,
1415 botchedPageUIClient.runJavaScriptPrompt_deprecatedForUseWithV0,
1416 botchedPageUIClient.setStatusText,
1417 botchedPageUIClient.mouseDidMoveOverElement_deprecatedForUseWithV0,
1418 botchedPageUIClient.missingPluginButtonClicked_deprecatedForUseWithV0,
1419 botchedPageUIClient.didNotHandleKeyEvent,
1420 botchedPageUIClient.didNotHandleWheelEvent,
1421 botchedPageUIClient.toolbarsAreVisible,
1422 botchedPageUIClient.setToolbarsAreVisible,
1423 botchedPageUIClient.menuBarIsVisible,
1424 botchedPageUIClient.setMenuBarIsVisible,
1425 botchedPageUIClient.statusBarIsVisible,
1426 botchedPageUIClient.setStatusBarIsVisible,
1427 botchedPageUIClient.isResizable,
1428 botchedPageUIClient.setIsResizable,
1429 botchedPageUIClient.getWindowFrame,
1430 botchedPageUIClient.setWindowFrame,
1431 botchedPageUIClient.runBeforeUnloadConfirmPanel,
1432 botchedPageUIClient.didDraw,
1433 botchedPageUIClient.pageDidScroll,
1434 botchedPageUIClient.exceededDatabaseQuota,
1435 botchedPageUIClient.runOpenPanel,
1436 botchedPageUIClient.decidePolicyForGeolocationPermissionRequest,
1437 botchedPageUIClient.headerHeight,
1438 botchedPageUIClient.footerHeight,
1439 botchedPageUIClient.drawHeader,
1440 botchedPageUIClient.drawFooter,
1441 botchedPageUIClient.printFrame,
1442 botchedPageUIClient.runModal,
1443 botchedPageUIClient.unused1,
1444 botchedPageUIClient.saveDataToFileInDownloadsFolder,
1445 botchedPageUIClient.shouldInterruptJavaScript_unavailable,
1446 botchedPageUIClient.createNewPage,
1447 botchedPageUIClient.mouseDidMoveOverElement,
1448 botchedPageUIClient.decidePolicyForNotificationPermissionRequest,
1449 botchedPageUIClient.unavailablePluginButtonClicked_deprecatedForUseWithV1,
1450 botchedPageUIClient.showColorPicker,
1451 botchedPageUIClient.hideColorPicker,
1452 botchedPageUIClient.unavailablePluginButtonClicked,
1453 botchedPageUIClient.pinnedStateDidChange,
1460 botchedPageUIClient.runJavaScriptAlert,
1461 botchedPageUIClient.runJavaScriptConfirm,
1462 botchedPageUIClient.runJavaScriptPrompt,
1466 WKPageSetPageUIClient(pageRef, &fixedPageUIClient.base);
1470 void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient)
1472 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000
1473 if (wkClient && wkClient->version == 4) {
1474 fixUpBotchedPageUIClient(pageRef, *wkClient);
1479 class UIClient : public API::Client<WKPageUIClientBase>, public API::UIClient {
1481 explicit UIClient(const WKPageUIClientBase* client)
1487 virtual PassRefPtr<WebPageProxy> createNewPage(WebPageProxy* page, WebFrameProxy* initiatingFrame, const SecurityOriginData& securityOriginData, const ResourceRequest& resourceRequest, const WindowFeatures& windowFeatures, const NavigationActionData& navigationActionData) override
1489 if (m_client.base.version < 6) {
1490 if (!m_client.base.version && !m_client.createNewPage_deprecatedForUseWithV0)
1493 if (!m_client.createNewPage_deprecatedForUseWithV1)
1496 API::Dictionary::MapType map;
1497 if (windowFeatures.x)
1498 map.set("x", API::Double::create(*windowFeatures.x));
1499 if (windowFeatures.y)
1500 map.set("y", API::Double::create(*windowFeatures.y));
1501 if (windowFeatures.width)
1502 map.set("width", API::Double::create(*windowFeatures.width));
1503 if (windowFeatures.height)
1504 map.set("height", API::Double::create(*windowFeatures.height));
1505 map.set("menuBarVisible", API::Boolean::create(windowFeatures.menuBarVisible));
1506 map.set("statusBarVisible", API::Boolean::create(windowFeatures.statusBarVisible));
1507 map.set("toolBarVisible", API::Boolean::create(windowFeatures.toolBarVisible));
1508 map.set("locationBarVisible", API::Boolean::create(windowFeatures.locationBarVisible));
1509 map.set("scrollbarsVisible", API::Boolean::create(windowFeatures.scrollbarsVisible));
1510 map.set("resizable", API::Boolean::create(windowFeatures.resizable));
1511 map.set("fullscreen", API::Boolean::create(windowFeatures.fullscreen));
1512 map.set("dialog", API::Boolean::create(windowFeatures.dialog));
1513 Ref<API::Dictionary> featuresMap = API::Dictionary::create(WTF::move(map));
1515 if (!m_client.base.version)
1516 return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV0(toAPI(page), toAPI(featuresMap.ptr()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
1518 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1519 return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV1(toAPI(page), toAPI(request.ptr()), toAPI(featuresMap.ptr()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
1522 if (!m_client.createNewPage)
1525 auto configuration = page->configuration().copy();
1526 configuration->setRelatedPage(page);
1528 auto sourceFrameInfo = API::FrameInfo::create(*initiatingFrame, securityOriginData.securityOrigin());
1530 bool shouldOpenAppLinks = !protocolHostAndPortAreEqual(WebCore::URL(WebCore::ParsedURLString, initiatingFrame->url()), resourceRequest.url());
1531 auto apiNavigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.ptr(), nullptr, resourceRequest, WebCore::URL(), shouldOpenAppLinks);
1533 auto apiWindowFeatures = API::WindowFeatures::create(windowFeatures);
1535 return adoptRef(toImpl(m_client.createNewPage(toAPI(page), toAPI(configuration.ptr()), toAPI(apiNavigationAction.ptr()), toAPI(apiWindowFeatures.ptr()), m_client.base.clientInfo)));
1538 virtual void showPage(WebPageProxy* page) override
1540 if (!m_client.showPage)
1543 m_client.showPage(toAPI(page), m_client.base.clientInfo);
1546 virtual void close(WebPageProxy* page) override
1548 if (!m_client.close)
1551 m_client.close(toAPI(page), m_client.base.clientInfo);
1554 virtual void takeFocus(WebPageProxy* page, WKFocusDirection direction) override
1556 if (!m_client.takeFocus)
1559 m_client.takeFocus(toAPI(page), direction, m_client.base.clientInfo);
1562 virtual void focus(WebPageProxy* page) override
1564 if (!m_client.focus)
1567 m_client.focus(toAPI(page), m_client.base.clientInfo);
1570 virtual void unfocus(WebPageProxy* page) override
1572 if (!m_client.unfocus)
1575 m_client.unfocus(toAPI(page), m_client.base.clientInfo);
1578 virtual void runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame, const SecurityOriginData& securityOriginData, std::function<void ()> completionHandler) override
1580 if (!m_client.runJavaScriptAlert && !m_client.runJavaScriptAlert_deprecatedForUseWithV0) {
1581 completionHandler();
1585 if (m_client.runJavaScriptAlert) {
1586 RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
1587 m_client.runJavaScriptAlert(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), m_client.base.clientInfo);
1589 m_client.runJavaScriptAlert_deprecatedForUseWithV0(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1591 completionHandler();
1594 virtual void runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame, const SecurityOriginData& securityOriginData, std::function<void (bool)> completionHandler) override
1596 if (!m_client.runJavaScriptConfirm && !m_client.runJavaScriptConfirm_deprecatedForUseWithV0) {
1597 completionHandler(false);
1602 if (m_client.runJavaScriptConfirm) {
1603 RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
1604 result = m_client.runJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), m_client.base.clientInfo);
1606 result = m_client.runJavaScriptConfirm_deprecatedForUseWithV0(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1608 completionHandler(result);
1611 virtual void runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame, const SecurityOriginData& securityOriginData, std::function<void (const String&)> completionHandler) override
1613 if (!m_client.runJavaScriptPrompt && !m_client.runJavaScriptPrompt_deprecatedForUseWithV0) {
1614 completionHandler(String());
1618 RefPtr<API::String> string;
1619 if (m_client.runJavaScriptPrompt) {
1620 RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
1621 string = adoptRef(toImpl(m_client.runJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), toAPI(securityOrigin.get()), m_client.base.clientInfo)));
1623 string = adoptRef(toImpl(m_client.runJavaScriptPrompt_deprecatedForUseWithV0(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.base.clientInfo)));
1626 completionHandler(String());
1630 completionHandler(string->string());
1633 virtual void setStatusText(WebPageProxy* page, const String& text) override
1635 if (!m_client.setStatusText)
1638 m_client.setStatusText(toAPI(page), toAPI(text.impl()), m_client.base.clientInfo);
1641 virtual void mouseDidMoveOverElement(WebPageProxy* page, const WebHitTestResultData& data, WebEvent::Modifiers modifiers, API::Object* userData) override
1643 if (!m_client.mouseDidMoveOverElement && !m_client.mouseDidMoveOverElement_deprecatedForUseWithV0)
1646 if (m_client.base.version > 0 && !m_client.mouseDidMoveOverElement)
1649 if (!m_client.base.version) {
1650 m_client.mouseDidMoveOverElement_deprecatedForUseWithV0(toAPI(page), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
1654 RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(data);
1655 m_client.mouseDidMoveOverElement(toAPI(page), toAPI(webHitTestResult.get()), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
1658 #if ENABLE(NETSCAPE_PLUGIN_API)
1659 virtual void unavailablePluginButtonClicked(WebPageProxy* page, WKPluginUnavailabilityReason pluginUnavailabilityReason, API::Dictionary* pluginInformation) override
1661 if (pluginUnavailabilityReason == kWKPluginUnavailabilityReasonPluginMissing) {
1662 if (m_client.missingPluginButtonClicked_deprecatedForUseWithV0)
1663 m_client.missingPluginButtonClicked_deprecatedForUseWithV0(
1665 toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
1666 toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
1667 toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
1668 m_client.base.clientInfo);
1671 if (m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1)
1672 m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1(
1674 pluginUnavailabilityReason,
1675 toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
1676 toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
1677 toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
1678 m_client.base.clientInfo);
1680 if (m_client.unavailablePluginButtonClicked)
1681 m_client.unavailablePluginButtonClicked(
1683 pluginUnavailabilityReason,
1684 toAPI(pluginInformation),
1685 m_client.base.clientInfo);
1687 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1689 virtual bool implementsDidNotHandleKeyEvent() const override
1691 return m_client.didNotHandleKeyEvent;
1694 virtual void didNotHandleKeyEvent(WebPageProxy* page, const NativeWebKeyboardEvent& event) override
1696 if (!m_client.didNotHandleKeyEvent)
1698 m_client.didNotHandleKeyEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
1701 virtual bool implementsDidNotHandleWheelEvent() const override
1703 return m_client.didNotHandleWheelEvent;
1706 virtual void didNotHandleWheelEvent(WebPageProxy* page, const NativeWebWheelEvent& event) override
1708 if (!m_client.didNotHandleWheelEvent)
1710 m_client.didNotHandleWheelEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
1713 virtual bool toolbarsAreVisible(WebPageProxy* page) override
1715 if (!m_client.toolbarsAreVisible)
1717 return m_client.toolbarsAreVisible(toAPI(page), m_client.base.clientInfo);
1720 virtual void setToolbarsAreVisible(WebPageProxy* page, bool visible) override
1722 if (!m_client.setToolbarsAreVisible)
1724 m_client.setToolbarsAreVisible(toAPI(page), visible, m_client.base.clientInfo);
1727 virtual bool menuBarIsVisible(WebPageProxy* page) override
1729 if (!m_client.menuBarIsVisible)
1731 return m_client.menuBarIsVisible(toAPI(page), m_client.base.clientInfo);
1734 virtual void setMenuBarIsVisible(WebPageProxy* page, bool visible) override
1736 if (!m_client.setMenuBarIsVisible)
1738 m_client.setMenuBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
1741 virtual bool statusBarIsVisible(WebPageProxy* page) override
1743 if (!m_client.statusBarIsVisible)
1745 return m_client.statusBarIsVisible(toAPI(page), m_client.base.clientInfo);
1748 virtual void setStatusBarIsVisible(WebPageProxy* page, bool visible) override
1750 if (!m_client.setStatusBarIsVisible)
1752 m_client.setStatusBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
1755 virtual bool isResizable(WebPageProxy* page) override
1757 if (!m_client.isResizable)
1759 return m_client.isResizable(toAPI(page), m_client.base.clientInfo);
1762 virtual void setIsResizable(WebPageProxy* page, bool resizable) override
1764 if (!m_client.setIsResizable)
1766 m_client.setIsResizable(toAPI(page), resizable, m_client.base.clientInfo);
1769 virtual void setWindowFrame(WebPageProxy* page, const FloatRect& frame) override
1771 if (!m_client.setWindowFrame)
1774 m_client.setWindowFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1777 virtual FloatRect windowFrame(WebPageProxy* page) override
1779 if (!m_client.getWindowFrame)
1782 return toFloatRect(m_client.getWindowFrame(toAPI(page), m_client.base.clientInfo));
1785 virtual bool canRunBeforeUnloadConfirmPanel() const override
1787 return m_client.runBeforeUnloadConfirmPanel;
1790 virtual bool runBeforeUnloadConfirmPanel(WebPageProxy* page, const String& message, WebFrameProxy* frame) override
1792 if (!m_client.runBeforeUnloadConfirmPanel)
1795 return m_client.runBeforeUnloadConfirmPanel(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1798 virtual void pageDidScroll(WebPageProxy* page) override
1800 if (!m_client.pageDidScroll)
1803 m_client.pageDidScroll(toAPI(page), m_client.base.clientInfo);
1806 virtual void exceededDatabaseQuota(WebPageProxy* page, WebFrameProxy* frame, API::SecurityOrigin* origin, const String& databaseName, const String& databaseDisplayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage, std::function<void (unsigned long long)> completionHandler) override
1808 if (!m_client.exceededDatabaseQuota) {
1809 completionHandler(currentQuota);
1813 completionHandler(m_client.exceededDatabaseQuota(toAPI(page), toAPI(frame), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, m_client.base.clientInfo));
1816 virtual bool runOpenPanel(WebPageProxy* page, WebFrameProxy* frame, WebOpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener) override
1818 if (!m_client.runOpenPanel)
1821 m_client.runOpenPanel(toAPI(page), toAPI(frame), toAPI(parameters), toAPI(listener), m_client.base.clientInfo);
1825 virtual bool decidePolicyForGeolocationPermissionRequest(WebPageProxy* page, WebFrameProxy* frame, API::SecurityOrigin* origin, GeolocationPermissionRequestProxy* permissionRequest) override
1827 if (!m_client.decidePolicyForGeolocationPermissionRequest)
1830 m_client.decidePolicyForGeolocationPermissionRequest(toAPI(page), toAPI(frame), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
1834 virtual bool decidePolicyForUserMediaPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, UserMediaPermissionRequestProxy& permissionRequest) override
1836 if (!m_client.decidePolicyForUserMediaPermissionRequest)
1839 m_client.decidePolicyForUserMediaPermissionRequest(toAPI(&page), toAPI(&frame), toAPI(&origin), toAPI(&permissionRequest), m_client.base.clientInfo);
1843 virtual bool decidePolicyForNotificationPermissionRequest(WebPageProxy* page, API::SecurityOrigin* origin, NotificationPermissionRequest* permissionRequest) override
1845 if (!m_client.decidePolicyForNotificationPermissionRequest)
1848 m_client.decidePolicyForNotificationPermissionRequest(toAPI(page), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
1853 virtual float headerHeight(WebPageProxy* page, WebFrameProxy* frame) override
1855 if (!m_client.headerHeight)
1858 return m_client.headerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1861 virtual float footerHeight(WebPageProxy* page, WebFrameProxy* frame) override
1863 if (!m_client.footerHeight)
1866 return m_client.footerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1869 virtual void drawHeader(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
1871 if (!m_client.drawHeader)
1874 m_client.drawHeader(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
1877 virtual void drawFooter(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
1879 if (!m_client.drawFooter)
1882 m_client.drawFooter(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
1885 virtual void printFrame(WebPageProxy* page, WebFrameProxy* frame) override
1887 if (!m_client.printFrame)
1890 m_client.printFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1893 virtual bool canRunModal() const override
1895 return m_client.runModal;
1898 virtual void runModal(WebPageProxy* page) override
1900 if (!m_client.runModal)
1903 m_client.runModal(toAPI(page), m_client.base.clientInfo);
1906 virtual void saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data) override
1908 if (!m_client.saveDataToFileInDownloadsFolder)
1911 m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURLString.impl()), toAPI(data), m_client.base.clientInfo);
1914 virtual void pinnedStateDidChange(WebPageProxy& page) override
1916 if (!m_client.pinnedStateDidChange)
1919 m_client.pinnedStateDidChange(toAPI(&page), m_client.base.clientInfo);
1922 virtual void didBeginTrackingPotentialLongMousePress(WebPageProxy* page, const IntPoint& mouseDownPosition, const WebHitTestResultData& data, API::Object* userInfo) override
1924 if (!m_client.didBeginTrackingPotentialLongMousePress)
1927 RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(data);
1928 m_client.didBeginTrackingPotentialLongMousePress(toAPI(page), toAPI(mouseDownPosition), toAPI(webHitTestResult.get()), toAPI(userInfo), m_client.base.clientInfo);
1931 virtual void didRecognizeLongMousePress(WebPageProxy* page, API::Object* userInfo) override
1933 if (!m_client.didRecognizeLongMousePress)
1936 m_client.didRecognizeLongMousePress(toAPI(page), toAPI(userInfo), m_client.base.clientInfo);
1939 virtual void didCancelTrackingPotentialLongMousePress(WebPageProxy* page, API::Object* userInfo) override
1941 if (!m_client.didCancelTrackingPotentialLongMousePress)
1944 m_client.didCancelTrackingPotentialLongMousePress(toAPI(page), toAPI(userInfo), m_client.base.clientInfo);
1947 virtual void isPlayingAudioDidChange(WebPageProxy& page) override
1949 if (!m_client.isPlayingAudioDidChange)
1952 m_client.isPlayingAudioDidChange(toAPI(&page), m_client.base.clientInfo);
1955 virtual void didClickAutoFillButton(WebPageProxy& page, API::Object* userInfo) override
1957 if (!m_client.didClickAutoFillButton)
1960 m_client.didClickAutoFillButton(toAPI(&page), toAPI(userInfo), m_client.base.clientInfo);
1963 #if ENABLE(MEDIA_SESSION)
1964 virtual void mediaSessionMetadataDidChange(WebPageProxy& page, WebMediaSessionMetadata* metadata) override
1966 if (!m_client.mediaSessionMetadataDidChange)
1969 m_client.mediaSessionMetadataDidChange(toAPI(&page), toAPI(metadata), m_client.base.clientInfo);
1974 toImpl(pageRef)->setUIClient(std::make_unique<UIClient>(wkClient));
1977 void WKPageSetPageNavigationClient(WKPageRef pageRef, const WKPageNavigationClientBase* wkClient)
1979 class NavigationClient : public API::Client<WKPageNavigationClientBase>, public API::NavigationClient {
1981 explicit NavigationClient(const WKPageNavigationClientBase* client)
1987 virtual void decidePolicyForNavigationAction(WebPageProxy& page, API::NavigationAction& navigationAction, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1989 if (!m_client.decidePolicyForNavigationAction)
1991 m_client.decidePolicyForNavigationAction(toAPI(&page), toAPI(&navigationAction), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1994 virtual void decidePolicyForNavigationResponse(WebPageProxy& page, API::NavigationResponse& navigationResponse, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1996 if (!m_client.decidePolicyForNavigationResponse)
1998 m_client.decidePolicyForNavigationResponse(toAPI(&page), toAPI(&navigationResponse), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
2001 virtual void didStartProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
2003 if (!m_client.didStartProvisionalNavigation)
2005 m_client.didStartProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
2008 virtual void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
2010 if (!m_client.didReceiveServerRedirectForProvisionalNavigation)
2012 m_client.didReceiveServerRedirectForProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
2015 virtual void didFailProvisionalNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
2017 if (!m_client.didFailProvisionalNavigation)
2019 m_client.didFailProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
2022 virtual void didCommitNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
2024 if (!m_client.didCommitNavigation)
2026 m_client.didCommitNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
2029 virtual void didFinishNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
2031 if (!m_client.didFinishNavigation)
2033 m_client.didFinishNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
2036 virtual void didFailNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
2038 if (!m_client.didFailNavigation)
2040 m_client.didFailNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
2043 virtual void didFailProvisionalLoadInSubframeWithError(WebPageProxy& page, WebFrameProxy& subframe, const WebCore::SecurityOriginData& securityOriginData, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
2045 if (!m_client.didFailProvisionalLoadInSubframe)
2047 m_client.didFailProvisionalLoadInSubframe(toAPI(&page), toAPI(navigation), toAPI(API::FrameInfo::create(subframe, securityOriginData.securityOrigin()).ptr()), toAPI(error), toAPI(userData), m_client.base.clientInfo);
2050 virtual void didFinishDocumentLoad(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
2052 if (!m_client.didFinishDocumentLoad)
2054 m_client.didFinishDocumentLoad(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
2057 virtual void didSameDocumentNavigation(WebPageProxy& page, API::Navigation* navigation, WebKit::SameDocumentNavigationType navigationType, API::Object* userData) override
2059 if (!m_client.didSameDocumentNavigation)
2061 m_client.didSameDocumentNavigation(toAPI(&page), toAPI(navigation), toAPI(navigationType), toAPI(userData), m_client.base.clientInfo);
2064 virtual void renderingProgressDidChange(WebPageProxy& page, WebCore::LayoutMilestones milestones) override
2066 if (!m_client.renderingProgressDidChange)
2068 m_client.renderingProgressDidChange(toAPI(&page), pageRenderingProgressEvents(milestones), nullptr, m_client.base.clientInfo);
2071 virtual bool canAuthenticateAgainstProtectionSpace(WebPageProxy& page, WebProtectionSpace* protectionSpace) override
2073 if (!m_client.canAuthenticateAgainstProtectionSpace)
2075 return m_client.canAuthenticateAgainstProtectionSpace(toAPI(&page), toAPI(protectionSpace), m_client.base.clientInfo);
2078 virtual void didReceiveAuthenticationChallenge(WebPageProxy& page, AuthenticationChallengeProxy* authenticationChallenge) override
2080 if (!m_client.didReceiveAuthenticationChallenge)
2082 m_client.didReceiveAuthenticationChallenge(toAPI(&page), toAPI(authenticationChallenge), m_client.base.clientInfo);
2085 virtual void processDidCrash(WebPageProxy& page) override
2087 if (!m_client.webProcessDidCrash)
2089 m_client.webProcessDidCrash(toAPI(&page), m_client.base.clientInfo);
2092 virtual RefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
2094 if (!m_client.copyWebCryptoMasterKey)
2096 return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(&page), m_client.base.clientInfo)));
2099 virtual void didBeginNavigationGesture(WebPageProxy& page) override
2101 if (!m_client.didBeginNavigationGesture)
2103 m_client.didBeginNavigationGesture(toAPI(&page), m_client.base.clientInfo);
2106 virtual void didEndNavigationGesture(WebPageProxy& page, bool willNavigate, WebKit::WebBackForwardListItem& item) override
2108 if (!m_client.didEndNavigationGesture)
2110 m_client.didEndNavigationGesture(toAPI(&page), willNavigate ? toAPI(&item) : nullptr, m_client.base.clientInfo);
2113 virtual void willEndNavigationGesture(WebPageProxy& page, bool willNavigate, WebKit::WebBackForwardListItem& item) override
2115 if (!m_client.willEndNavigationGesture)
2117 m_client.willEndNavigationGesture(toAPI(&page), willNavigate ? toAPI(&item) : nullptr, m_client.base.clientInfo);
2120 virtual void didRemoveNavigationGestureSnapshot(WebPageProxy& page) override
2122 if (!m_client.didRemoveNavigationGestureSnapshot)
2124 m_client.didRemoveNavigationGestureSnapshot(toAPI(&page), m_client.base.clientInfo);
2127 #if ENABLE(NETSCAPE_PLUGIN_API)
2128 virtual PluginModuleLoadPolicy decidePolicyForPluginLoad(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
2130 WKStringRef unavailabilityDescriptionOut = 0;
2131 PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
2133 if (m_client.decidePolicyForPluginLoad)
2134 loadPolicy = toPluginModuleLoadPolicy(m_client.decidePolicyForPluginLoad(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
2136 if (unavailabilityDescriptionOut) {
2137 RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
2138 unavailabilityDescription = webUnavailabilityDescription->string();
2146 WebPageProxy* webPageProxy = toImpl(pageRef);
2148 auto navigationClient = std::make_unique<NavigationClient>(wkClient);
2149 webPageProxy->setNavigationClient(WTF::move(navigationClient));
2152 void WKPageSetSession(WKPageRef pageRef, WKSessionRef session)
2154 toImpl(pageRef)->setSessionID(toImpl(session)->getID());
2157 void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback)
2159 toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), [context, callback](API::SerializedScriptValue* returnValue, bool, CallbackBase::Error error) {
2160 callback(toAPI(returnValue), (error != CallbackBase::Error::None) ? toAPI(API::Error::create().ptr()) : 0, context);
2165 static void callRunJavaScriptBlockAndRelease(WKSerializedScriptValueRef resultValue, WKErrorRef error, void* context)
2167 WKPageRunJavaScriptBlock block = (WKPageRunJavaScriptBlock)context;
2168 block(resultValue, error);
2169 Block_release(block);
2172 void WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef, WKStringRef scriptRef, WKPageRunJavaScriptBlock block)
2174 WKPageRunJavaScriptInMainFrame(pageRef, scriptRef, Block_copy(block), callRunJavaScriptBlockAndRelease);
2178 static std::function<void (const String&, WebKit::CallbackBase::Error)> toGenericCallbackFunction(void* context, void (*callback)(WKStringRef, WKErrorRef, void*))
2180 return [context, callback](const String& returnValue, WebKit::CallbackBase::Error error) {
2181 callback(toAPI(API::String::create(returnValue).ptr()), error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
2185 void WKPageRenderTreeExternalRepresentation(WKPageRef pageRef, void* context, WKPageRenderTreeExternalRepresentationFunction callback)
2187 toImpl(pageRef)->getRenderTreeExternalRepresentation(toGenericCallbackFunction(context, callback));
2190 void WKPageGetSourceForFrame(WKPageRef pageRef, WKFrameRef frameRef, void* context, WKPageGetSourceForFrameFunction callback)
2192 toImpl(pageRef)->getSourceForFrame(toImpl(frameRef), toGenericCallbackFunction(context, callback));
2195 void WKPageGetContentsAsString(WKPageRef pageRef, void* context, WKPageGetContentsAsStringFunction callback)
2197 toImpl(pageRef)->getContentsAsString(toGenericCallbackFunction(context, callback));
2200 void WKPageGetBytecodeProfile(WKPageRef pageRef, void* context, WKPageGetBytecodeProfileFunction callback)
2202 toImpl(pageRef)->getBytecodeProfile(toGenericCallbackFunction(context, callback));
2205 void WKPageGetSelectionAsWebArchiveData(WKPageRef pageRef, void* context, WKPageGetSelectionAsWebArchiveDataFunction callback)
2207 toImpl(pageRef)->getSelectionAsWebArchiveData(toGenericCallbackFunction(context, callback));
2210 void WKPageGetContentsAsMHTMLData(WKPageRef pageRef, bool useBinaryEncoding, void* context, WKPageGetContentsAsMHTMLDataFunction callback)
2213 toImpl(pageRef)->getContentsAsMHTMLData(toGenericCallbackFunction(context, callback), useBinaryEncoding);
2215 UNUSED_PARAM(pageRef);
2216 UNUSED_PARAM(useBinaryEncoding);
2217 UNUSED_PARAM(context);
2218 UNUSED_PARAM(callback);
2222 void WKPageForceRepaint(WKPageRef pageRef, void* context, WKPageForceRepaintFunction callback)
2224 toImpl(pageRef)->forceRepaint(VoidCallback::create([context, callback](WebKit::CallbackBase::Error error) {
2225 callback(error == WebKit::CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().ptr()), context);
2229 WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef pageRef)
2231 const String& pendingAPIRequestURL = toImpl(pageRef)->pageLoadState().pendingAPIRequestURL();
2233 if (pendingAPIRequestURL.isNull())
2236 return toCopiedURLAPI(pendingAPIRequestURL);
2239 WKURLRef WKPageCopyActiveURL(WKPageRef pageRef)
2241 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().activeURL());
2244 WKURLRef WKPageCopyProvisionalURL(WKPageRef pageRef)
2246 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().provisionalURL());
2249 WKURLRef WKPageCopyCommittedURL(WKPageRef pageRef)
2251 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().url());
2254 WKStringRef WKPageCopyStandardUserAgentWithApplicationName(WKStringRef applicationName)
2256 return toCopiedAPI(WebPageProxy::standardUserAgent(toImpl(applicationName)->string()));
2259 void WKPageValidateCommand(WKPageRef pageRef, WKStringRef command, void* context, WKPageValidateCommandCallback callback)
2261 toImpl(pageRef)->validateCommand(toImpl(command)->string(), [context, callback](const String& commandName, bool isEnabled, int32_t state, WebKit::CallbackBase::Error error) {
2262 callback(toAPI(API::String::create(commandName).ptr()), isEnabled, state, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
2266 void WKPageExecuteCommand(WKPageRef pageRef, WKStringRef command)
2268 toImpl(pageRef)->executeEditCommand(toImpl(command)->string());
2272 static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo)
2275 result.pageSetupScaleFactor = printInfo.pageSetupScaleFactor;
2276 result.availablePaperWidth = printInfo.availablePaperWidth;
2277 result.availablePaperHeight = printInfo.availablePaperHeight;
2281 void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, WKPageComputePagesForPrintingFunction callback, void* context)
2283 toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create([context, callback](const Vector<WebCore::IntRect>& rects, double scaleFactor, WebKit::CallbackBase::Error error) {
2284 Vector<WKRect> wkRects(rects.size());
2285 for (size_t i = 0; i < rects.size(); ++i)
2286 wkRects[i] = toAPI(rects[i]);
2287 callback(wkRects.data(), wkRects.size(), scaleFactor, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
2291 void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo)
2293 toImpl(page)->beginPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo));
2296 void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
2298 toImpl(page)->drawPagesToPDF(toImpl(frame), printInfoFromWKPrintInfo(printInfo), first, count, DataCallback::create(toGenericCallbackFunction(context, callback)));
2301 void WKPageEndPrinting(WKPageRef page)
2303 toImpl(page)->endPrinting();
2307 bool WKPageGetAllowsRemoteInspection(WKPageRef page)
2309 #if ENABLE(REMOTE_INSPECTOR)
2310 return toImpl(page)->allowsRemoteInspection();
2317 void WKPageSetAllowsRemoteInspection(WKPageRef page, bool allow)
2319 #if ENABLE(REMOTE_INSPECTOR)
2320 toImpl(page)->setAllowsRemoteInspection(allow);
2323 UNUSED_PARAM(allow);
2327 void WKPageSetMediaVolume(WKPageRef page, float volume)
2329 toImpl(page)->setMediaVolume(volume);
2332 void WKPageSetMuted(WKPageRef page, bool muted)
2334 toImpl(page)->setMuted(muted);
2337 bool WKPageHasMediaSessionWithActiveMediaElements(WKPageRef page)
2339 #if ENABLE(MEDIA_SESSION)
2340 return toImpl(page)->hasMediaSessionWithActiveMediaElements();
2347 void WKPageHandleMediaEvent(WKPageRef page, WKMediaEventType wkEventType)
2349 #if ENABLE(MEDIA_SESSION)
2350 MediaEventType eventType;
2352 switch (wkEventType) {
2353 case kWKMediaEventTypePlayPause:
2354 eventType = MediaEventType::PlayPause;
2356 case kWKMediaEventTypeTrackNext:
2357 eventType = MediaEventType::TrackNext;
2359 case kWKMediaEventTypeTrackPrevious:
2360 eventType = MediaEventType::TrackPrevious;
2363 ASSERT_NOT_REACHED();
2367 toImpl(page)->handleMediaEvent(eventType);
2370 UNUSED_PARAM(wkEventType);
2374 void WKPagePostMessageToInjectedBundle(WKPageRef pageRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef)
2376 toImpl(pageRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef));
2379 WKArrayRef WKPageCopyRelatedPages(WKPageRef pageRef)
2381 Vector<RefPtr<API::Object>> relatedPages;
2383 for (auto& page : toImpl(pageRef)->process().pages()) {
2384 if (page != toImpl(pageRef))
2385 relatedPages.append(page);
2388 return toAPI(&API::Array::create(WTF::move(relatedPages)).leakRef());
2391 void WKPageSetMayStartMediaWhenInWindow(WKPageRef pageRef, bool mayStartMedia)
2393 toImpl(pageRef)->setMayStartMediaWhenInWindow(mayStartMedia);
2397 void WKPageSelectContextMenuItem(WKPageRef page, WKContextMenuItemRef item)
2399 #if ENABLE(CONTEXT_MENUS)
2400 toImpl(page)->contextMenuItemSelected(*(toImpl(item)->data()));
2407 WKScrollPinningBehavior WKPageGetScrollPinningBehavior(WKPageRef page)
2409 ScrollPinningBehavior pinning = toImpl(page)->scrollPinningBehavior();
2412 case WebCore::ScrollPinningBehavior::DoNotPin:
2413 return kWKScrollPinningBehaviorDoNotPin;
2414 case WebCore::ScrollPinningBehavior::PinToTop:
2415 return kWKScrollPinningBehaviorPinToTop;
2416 case WebCore::ScrollPinningBehavior::PinToBottom:
2417 return kWKScrollPinningBehaviorPinToBottom;
2420 ASSERT_NOT_REACHED();
2421 return kWKScrollPinningBehaviorDoNotPin;
2424 void WKPageSetScrollPinningBehavior(WKPageRef page, WKScrollPinningBehavior pinning)
2426 ScrollPinningBehavior corePinning = ScrollPinningBehavior::DoNotPin;
2429 case kWKScrollPinningBehaviorDoNotPin:
2430 corePinning = ScrollPinningBehavior::DoNotPin;
2432 case kWKScrollPinningBehaviorPinToTop:
2433 corePinning = ScrollPinningBehavior::PinToTop;
2435 case kWKScrollPinningBehaviorPinToBottom:
2436 corePinning = ScrollPinningBehavior::PinToBottom;
2439 ASSERT_NOT_REACHED();
2442 toImpl(page)->setScrollPinningBehavior(corePinning);
2445 bool WKPageGetAddsVisitedLinks(WKPageRef page)
2447 return toImpl(page)->addsVisitedLinks();
2450 void WKPageSetAddsVisitedLinks(WKPageRef page, bool addsVisitedLinks)
2452 toImpl(page)->setAddsVisitedLinks(addsVisitedLinks);
2455 bool WKPageIsPlayingAudio(WKPageRef page)
2457 return toImpl(page)->isPlayingAudio();
2460 void WKPageClearWheelEventTestTrigger(WKPageRef pageRef)
2462 toImpl(pageRef)->clearWheelEventTestTrigger();
2465 void WKPageCallAfterNextPresentationUpdate(WKPageRef pageRef, void* context, WKPagePostPresentationUpdateFunction callback)
2467 toImpl(pageRef)->callAfterNextPresentationUpdate([context, callback](WebKit::CallbackBase::Error error) {
2468 callback(error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
2472 #if ENABLE(NETSCAPE_PLUGIN_API)
2476 WKStringRef WKPageGetPluginInformationBundleIdentifierKey()
2478 return WKPluginInformationBundleIdentifierKey();
2481 WKStringRef WKPageGetPluginInformationBundleVersionKey()
2483 return WKPluginInformationBundleVersionKey();
2486 WKStringRef WKPageGetPluginInformationDisplayNameKey()
2488 return WKPluginInformationDisplayNameKey();
2491 WKStringRef WKPageGetPluginInformationFrameURLKey()
2493 return WKPluginInformationFrameURLKey();
2496 WKStringRef WKPageGetPluginInformationMIMETypeKey()
2498 return WKPluginInformationMIMETypeKey();
2501 WKStringRef WKPageGetPluginInformationPageURLKey()
2503 return WKPluginInformationPageURLKey();
2506 WKStringRef WKPageGetPluginInformationPluginspageAttributeURLKey()
2508 return WKPluginInformationPluginspageAttributeURLKey();
2511 WKStringRef WKPageGetPluginInformationPluginURLKey()
2513 return WKPluginInformationPluginURLKey();
2518 #endif // ENABLE(NETSCAPE_PLUGIN_API)