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 "APIFindMatchesClient.h"
36 #include "APIFrameHandle.h"
37 #include "APIFrameInfo.h"
38 #include "APIGeometry.h"
39 #include "APIHitTestResult.h"
40 #include "APILoaderClient.h"
41 #include "APINavigationAction.h"
42 #include "APINavigationClient.h"
43 #include "APINavigationResponse.h"
44 #include "APIOpenPanelParameters.h"
45 #include "APIPageConfiguration.h"
46 #include "APIPolicyClient.h"
47 #include "APISessionState.h"
48 #include "APIUIClient.h"
49 #include "APIWindowFeatures.h"
50 #include "AuthenticationChallengeProxy.h"
51 #include "LegacySessionStateCoding.h"
53 #include "NativeWebKeyboardEvent.h"
54 #include "NativeWebWheelEvent.h"
55 #include "NavigationActionData.h"
56 #include "PluginInformation.h"
57 #include "PrintInfo.h"
58 #include "WKAPICast.h"
59 #include "WKPagePolicyClientInternal.h"
60 #include "WKPageRenderingProgressEventsInternal.h"
61 #include "WKPluginInformation.h"
62 #include "WebBackForwardList.h"
63 #include "WebFormClient.h"
65 #include "WebInspectorProxy.h"
66 #include "WebOpenPanelResultListenerProxy.h"
67 #include "WebPageGroup.h"
68 #include "WebPageMessages.h"
69 #include "WebPageProxy.h"
70 #include "WebProcessPool.h"
71 #include "WebProcessProxy.h"
72 #include "WebProtectionSpace.h"
73 #include <WebCore/Page.h>
74 #include <WebCore/SecurityOriginData.h>
75 #include <WebCore/SerializedCryptoKeyWrap.h>
76 #include <WebCore/WindowFeatures.h>
82 #if ENABLE(CONTEXT_MENUS)
83 #include "WebContextMenuItem.h"
87 #include "WebVibrationProxy.h"
90 #if ENABLE(MEDIA_SESSION)
91 #include "WebMediaSessionMetadata.h"
92 #include <WebCore/MediaSessionEvents.h>
95 using namespace WebCore;
96 using namespace WebKit;
99 template<> struct ClientTraits<WKPageLoaderClientBase> {
100 typedef std::tuple<WKPageLoaderClientV0, WKPageLoaderClientV1, WKPageLoaderClientV2, WKPageLoaderClientV3, WKPageLoaderClientV4, WKPageLoaderClientV5, WKPageLoaderClientV6> Versions;
103 template<> struct ClientTraits<WKPageNavigationClientBase> {
104 typedef std::tuple<WKPageNavigationClientV0> Versions;
107 template<> struct ClientTraits<WKPagePolicyClientBase> {
108 typedef std::tuple<WKPagePolicyClientV0, WKPagePolicyClientV1, WKPagePolicyClientInternal> Versions;
111 template<> struct ClientTraits<WKPageUIClientBase> {
112 typedef std::tuple<WKPageUIClientV0, WKPageUIClientV1, WKPageUIClientV2, WKPageUIClientV3, WKPageUIClientV4, WKPageUIClientV5, WKPageUIClientV6, WKPageUIClientV7> Versions;
115 #if ENABLE(CONTEXT_MENUS)
116 template<> struct ClientTraits<WKPageContextMenuClientBase> {
117 typedef std::tuple<WKPageContextMenuClientV0, WKPageContextMenuClientV1, WKPageContextMenuClientV2, WKPageContextMenuClientV3, WKPageContextMenuClientV4> Versions;
121 template<> struct ClientTraits<WKPageFindClientBase> {
122 typedef std::tuple<WKPageFindClientV0> Versions;
125 template<> struct ClientTraits<WKPageFindMatchesClientBase> {
126 typedef std::tuple<WKPageFindMatchesClientV0> Versions;
131 WKTypeID WKPageGetTypeID()
133 return toAPI(WebPageProxy::APIType);
136 WKContextRef WKPageGetContext(WKPageRef pageRef)
138 return toAPI(&toImpl(pageRef)->process().processPool());
141 WKPageGroupRef WKPageGetPageGroup(WKPageRef pageRef)
143 return toAPI(&toImpl(pageRef)->pageGroup());
146 WKPageConfigurationRef WKPageCopyPageConfiguration(WKPageRef pageRef)
148 return toAPI(&toImpl(pageRef)->configuration().copy().leakRef());
151 void WKPageLoadURL(WKPageRef pageRef, WKURLRef URLRef)
153 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)));
156 void WKPageLoadURLWithShouldOpenExternalURLsPolicy(WKPageRef pageRef, WKURLRef URLRef, bool shouldOpenExternalURLs)
158 ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLs ? ShouldOpenExternalURLsPolicy::ShouldAllow : ShouldOpenExternalURLsPolicy::ShouldNotAllow;
159 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), shouldOpenExternalURLsPolicy);
162 void WKPageLoadURLWithUserData(WKPageRef pageRef, WKURLRef URLRef, WKTypeRef userDataRef)
164 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef));
167 void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef)
169 toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest());
172 void WKPageLoadURLRequestWithUserData(WKPageRef pageRef, WKURLRequestRef urlRequestRef, WKTypeRef userDataRef)
174 toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest(), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef));
177 void WKPageLoadFile(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL)
179 toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL));
182 void WKPageLoadFileWithUserData(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL, WKTypeRef userDataRef)
184 toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL), toImpl(userDataRef));
187 void WKPageLoadData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef)
189 toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef));
192 void WKPageLoadDataWithUserData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
194 toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef), toImpl(userDataRef));
197 void WKPageLoadHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef)
199 toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef));
202 void WKPageLoadHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
204 toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toImpl(userDataRef));
207 void WKPageLoadAlternateHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef)
209 toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef));
212 void WKPageLoadAlternateHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef, WKTypeRef userDataRef)
214 toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef), toImpl(userDataRef));
217 void WKPageLoadPlainTextString(WKPageRef pageRef, WKStringRef plainTextStringRef)
219 toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef));
222 void WKPageLoadPlainTextStringWithUserData(WKPageRef pageRef, WKStringRef plainTextStringRef, WKTypeRef userDataRef)
224 toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef), toImpl(userDataRef));
227 void WKPageLoadWebArchiveData(WKPageRef pageRef, WKDataRef webArchiveDataRef)
229 toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef));
232 void WKPageLoadWebArchiveDataWithUserData(WKPageRef pageRef, WKDataRef webArchiveDataRef, WKTypeRef userDataRef)
234 toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef), toImpl(userDataRef));
237 void WKPageStopLoading(WKPageRef pageRef)
239 toImpl(pageRef)->stopLoading();
242 void WKPageReload(WKPageRef pageRef)
244 const bool reloadFromOrigin = false;
245 const bool contentBlockersEnabled = true;
246 toImpl(pageRef)->reload(reloadFromOrigin, contentBlockersEnabled);
249 void WKPageReloadWithoutContentBlockers(WKPageRef pageRef)
251 const bool reloadFromOrigin = false;
252 const bool contentBlockersEnabled = false;
253 toImpl(pageRef)->reload(reloadFromOrigin, contentBlockersEnabled);
256 void WKPageReloadFromOrigin(WKPageRef pageRef)
258 const bool reloadFromOrigin = true;
259 const bool contentBlockersEnabled = true;
260 toImpl(pageRef)->reload(reloadFromOrigin, contentBlockersEnabled);
263 bool WKPageTryClose(WKPageRef pageRef)
265 return toImpl(pageRef)->tryClose();
268 void WKPageClose(WKPageRef pageRef)
270 toImpl(pageRef)->close();
273 bool WKPageIsClosed(WKPageRef pageRef)
275 return toImpl(pageRef)->isClosed();
278 void WKPageGoForward(WKPageRef pageRef)
280 toImpl(pageRef)->goForward();
283 bool WKPageCanGoForward(WKPageRef pageRef)
285 return toImpl(pageRef)->backForwardList().forwardItem();
288 void WKPageGoBack(WKPageRef pageRef)
290 toImpl(pageRef)->goBack();
293 bool WKPageCanGoBack(WKPageRef pageRef)
295 return toImpl(pageRef)->backForwardList().backItem();
298 void WKPageGoToBackForwardListItem(WKPageRef pageRef, WKBackForwardListItemRef itemRef)
300 toImpl(pageRef)->goToBackForwardItem(toImpl(itemRef));
303 void WKPageTryRestoreScrollPosition(WKPageRef pageRef)
305 toImpl(pageRef)->tryRestoreScrollPosition();
308 WKBackForwardListRef WKPageGetBackForwardList(WKPageRef pageRef)
310 return toAPI(&toImpl(pageRef)->backForwardList());
313 bool WKPageWillHandleHorizontalScrollEvents(WKPageRef pageRef)
315 return toImpl(pageRef)->willHandleHorizontalScrollEvents();
318 WKStringRef WKPageCopyTitle(WKPageRef pageRef)
320 return toCopiedAPI(toImpl(pageRef)->pageLoadState().title());
323 WKFrameRef WKPageGetMainFrame(WKPageRef pageRef)
325 return toAPI(toImpl(pageRef)->mainFrame());
328 WKFrameRef WKPageGetFocusedFrame(WKPageRef pageRef)
330 return toAPI(toImpl(pageRef)->focusedFrame());
333 WKFrameRef WKPageGetFrameSetLargestFrame(WKPageRef pageRef)
335 return toAPI(toImpl(pageRef)->frameSetLargestFrame());
338 uint64_t WKPageGetRenderTreeSize(WKPageRef page)
340 return toImpl(page)->renderTreeSize();
343 WKInspectorRef WKPageGetInspector(WKPageRef pageRef)
345 return toAPI(toImpl(pageRef)->inspector());
348 WKVibrationRef WKPageGetVibration(WKPageRef page)
350 #if ENABLE(VIBRATION)
351 return toAPI(toImpl(page)->vibration());
358 double WKPageGetEstimatedProgress(WKPageRef pageRef)
360 return toImpl(pageRef)->estimatedProgress();
363 WKStringRef WKPageCopyUserAgent(WKPageRef pageRef)
365 return toCopiedAPI(toImpl(pageRef)->userAgent());
368 WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef pageRef)
370 return toCopiedAPI(toImpl(pageRef)->applicationNameForUserAgent());
373 void WKPageSetApplicationNameForUserAgent(WKPageRef pageRef, WKStringRef applicationNameRef)
375 toImpl(pageRef)->setApplicationNameForUserAgent(toWTFString(applicationNameRef));
378 WKStringRef WKPageCopyCustomUserAgent(WKPageRef pageRef)
380 return toCopiedAPI(toImpl(pageRef)->customUserAgent());
383 void WKPageSetCustomUserAgent(WKPageRef pageRef, WKStringRef userAgentRef)
385 toImpl(pageRef)->setCustomUserAgent(toWTFString(userAgentRef));
388 void WKPageSetUserContentExtensionsEnabled(WKPageRef pageRef, bool enabled)
390 // FIXME: Remove this function once it is no longer used.
393 bool WKPageSupportsTextEncoding(WKPageRef pageRef)
395 return toImpl(pageRef)->supportsTextEncoding();
398 WKStringRef WKPageCopyCustomTextEncodingName(WKPageRef pageRef)
400 return toCopiedAPI(toImpl(pageRef)->customTextEncodingName());
403 void WKPageSetCustomTextEncodingName(WKPageRef pageRef, WKStringRef encodingNameRef)
405 toImpl(pageRef)->setCustomTextEncodingName(toWTFString(encodingNameRef));
408 void WKPageTerminate(WKPageRef pageRef)
410 toImpl(pageRef)->terminateProcess();
413 WKStringRef WKPageGetSessionHistoryURLValueType()
415 static API::String& sessionHistoryURLValueType = API::String::create("SessionHistoryURL").leakRef();
416 return toAPI(&sessionHistoryURLValueType);
419 WKStringRef WKPageGetSessionBackForwardListItemValueType()
421 static API::String& sessionBackForwardListValueType = API::String::create("SessionBackForwardListItem").leakRef();
422 return toAPI(&sessionBackForwardListValueType);
425 WKTypeRef WKPageCopySessionState(WKPageRef pageRef, void* context, WKPageSessionStateFilterCallback filter)
427 // FIXME: This is a hack to make sure we return a WKDataRef to maintain compatibility with older versions of Safari.
428 bool shouldReturnData = !(reinterpret_cast<uintptr_t>(context) & 1);
429 context = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(context) & ~1);
431 auto sessionState = toImpl(pageRef)->sessionState([pageRef, context, filter](WebBackForwardListItem& item) {
433 if (!filter(pageRef, WKPageGetSessionBackForwardListItemValueType(), toAPI(&item), context))
436 if (!filter(pageRef, WKPageGetSessionHistoryURLValueType(), toURLRef(item.originalURL().impl()), context))
443 if (shouldReturnData)
444 return toAPI(encodeLegacySessionState(sessionState).leakRef());
446 return toAPI(&API::SessionState::create(WTFMove(sessionState)).leakRef());
449 static void restoreFromSessionState(WKPageRef pageRef, WKTypeRef sessionStateRef, bool navigate)
451 SessionState sessionState;
453 // FIXME: This is for backwards compatibility with Safari. Remove it once Safari no longer depends on it.
454 if (toImpl(sessionStateRef)->type() == API::Object::Type::Data) {
455 if (!decodeLegacySessionState(toImpl(static_cast<WKDataRef>(sessionStateRef))->bytes(), toImpl(static_cast<WKDataRef>(sessionStateRef))->size(), sessionState))
458 ASSERT(toImpl(sessionStateRef)->type() == API::Object::Type::SessionState);
460 sessionState = toImpl(static_cast<WKSessionStateRef>(sessionStateRef))->sessionState();
463 toImpl(pageRef)->restoreFromSessionState(WTFMove(sessionState), navigate);
466 void WKPageRestoreFromSessionState(WKPageRef pageRef, WKTypeRef sessionStateRef)
468 restoreFromSessionState(pageRef, sessionStateRef, true);
471 void WKPageRestoreFromSessionStateWithoutNavigation(WKPageRef pageRef, WKTypeRef sessionStateRef)
473 restoreFromSessionState(pageRef, sessionStateRef, false);
476 double WKPageGetTextZoomFactor(WKPageRef pageRef)
478 return toImpl(pageRef)->textZoomFactor();
481 double WKPageGetBackingScaleFactor(WKPageRef pageRef)
483 return toImpl(pageRef)->deviceScaleFactor();
486 void WKPageSetCustomBackingScaleFactor(WKPageRef pageRef, double customScaleFactor)
488 toImpl(pageRef)->setCustomDeviceScaleFactor(customScaleFactor);
491 bool WKPageSupportsTextZoom(WKPageRef pageRef)
493 return toImpl(pageRef)->supportsTextZoom();
496 void WKPageSetTextZoomFactor(WKPageRef pageRef, double zoomFactor)
498 toImpl(pageRef)->setTextZoomFactor(zoomFactor);
501 double WKPageGetPageZoomFactor(WKPageRef pageRef)
503 return toImpl(pageRef)->pageZoomFactor();
506 void WKPageSetPageZoomFactor(WKPageRef pageRef, double zoomFactor)
508 toImpl(pageRef)->setPageZoomFactor(zoomFactor);
511 void WKPageSetPageAndTextZoomFactors(WKPageRef pageRef, double pageZoomFactor, double textZoomFactor)
513 toImpl(pageRef)->setPageAndTextZoomFactors(pageZoomFactor, textZoomFactor);
516 void WKPageSetScaleFactor(WKPageRef pageRef, double scale, WKPoint origin)
518 toImpl(pageRef)->scalePage(scale, toIntPoint(origin));
521 double WKPageGetScaleFactor(WKPageRef pageRef)
523 return toImpl(pageRef)->pageScaleFactor();
526 void WKPageSetUseFixedLayout(WKPageRef pageRef, bool fixed)
528 toImpl(pageRef)->setUseFixedLayout(fixed);
531 void WKPageSetFixedLayoutSize(WKPageRef pageRef, WKSize size)
533 toImpl(pageRef)->setFixedLayoutSize(toIntSize(size));
536 bool WKPageUseFixedLayout(WKPageRef pageRef)
538 return toImpl(pageRef)->useFixedLayout();
541 WKSize WKPageFixedLayoutSize(WKPageRef pageRef)
543 return toAPI(toImpl(pageRef)->fixedLayoutSize());
546 void WKPageListenForLayoutMilestones(WKPageRef pageRef, WKLayoutMilestones milestones)
548 toImpl(pageRef)->listenForLayoutMilestones(toLayoutMilestones(milestones));
551 bool WKPageHasHorizontalScrollbar(WKPageRef pageRef)
553 return toImpl(pageRef)->hasHorizontalScrollbar();
556 bool WKPageHasVerticalScrollbar(WKPageRef pageRef)
558 return toImpl(pageRef)->hasVerticalScrollbar();
561 void WKPageSetSuppressScrollbarAnimations(WKPageRef pageRef, bool suppressAnimations)
563 toImpl(pageRef)->setSuppressScrollbarAnimations(suppressAnimations);
566 bool WKPageAreScrollbarAnimationsSuppressed(WKPageRef pageRef)
568 return toImpl(pageRef)->areScrollbarAnimationsSuppressed();
571 bool WKPageIsPinnedToLeftSide(WKPageRef pageRef)
573 return toImpl(pageRef)->isPinnedToLeftSide();
576 bool WKPageIsPinnedToRightSide(WKPageRef pageRef)
578 return toImpl(pageRef)->isPinnedToRightSide();
581 bool WKPageIsPinnedToTopSide(WKPageRef pageRef)
583 return toImpl(pageRef)->isPinnedToTopSide();
586 bool WKPageIsPinnedToBottomSide(WKPageRef pageRef)
588 return toImpl(pageRef)->isPinnedToBottomSide();
591 bool WKPageRubberBandsAtLeft(WKPageRef pageRef)
593 return toImpl(pageRef)->rubberBandsAtLeft();
596 void WKPageSetRubberBandsAtLeft(WKPageRef pageRef, bool rubberBandsAtLeft)
598 toImpl(pageRef)->setRubberBandsAtLeft(rubberBandsAtLeft);
601 bool WKPageRubberBandsAtRight(WKPageRef pageRef)
603 return toImpl(pageRef)->rubberBandsAtRight();
606 void WKPageSetRubberBandsAtRight(WKPageRef pageRef, bool rubberBandsAtRight)
608 toImpl(pageRef)->setRubberBandsAtRight(rubberBandsAtRight);
611 bool WKPageRubberBandsAtTop(WKPageRef pageRef)
613 return toImpl(pageRef)->rubberBandsAtTop();
616 void WKPageSetRubberBandsAtTop(WKPageRef pageRef, bool rubberBandsAtTop)
618 toImpl(pageRef)->setRubberBandsAtTop(rubberBandsAtTop);
621 bool WKPageRubberBandsAtBottom(WKPageRef pageRef)
623 return toImpl(pageRef)->rubberBandsAtBottom();
626 void WKPageSetRubberBandsAtBottom(WKPageRef pageRef, bool rubberBandsAtBottom)
628 toImpl(pageRef)->setRubberBandsAtBottom(rubberBandsAtBottom);
631 bool WKPageVerticalRubberBandingIsEnabled(WKPageRef pageRef)
633 return toImpl(pageRef)->verticalRubberBandingIsEnabled();
636 void WKPageSetEnableVerticalRubberBanding(WKPageRef pageRef, bool enableVerticalRubberBanding)
638 toImpl(pageRef)->setEnableVerticalRubberBanding(enableVerticalRubberBanding);
641 bool WKPageHorizontalRubberBandingIsEnabled(WKPageRef pageRef)
643 return toImpl(pageRef)->horizontalRubberBandingIsEnabled();
646 void WKPageSetEnableHorizontalRubberBanding(WKPageRef pageRef, bool enableHorizontalRubberBanding)
648 toImpl(pageRef)->setEnableHorizontalRubberBanding(enableHorizontalRubberBanding);
651 void WKPageSetBackgroundExtendsBeyondPage(WKPageRef pageRef, bool backgroundExtendsBeyondPage)
653 toImpl(pageRef)->setBackgroundExtendsBeyondPage(backgroundExtendsBeyondPage);
656 bool WKPageBackgroundExtendsBeyondPage(WKPageRef pageRef)
658 return toImpl(pageRef)->backgroundExtendsBeyondPage();
661 void WKPageSetPaginationMode(WKPageRef pageRef, WKPaginationMode paginationMode)
663 Pagination::Mode mode;
664 switch (paginationMode) {
665 case kWKPaginationModeUnpaginated:
666 mode = Pagination::Unpaginated;
668 case kWKPaginationModeLeftToRight:
669 mode = Pagination::LeftToRightPaginated;
671 case kWKPaginationModeRightToLeft:
672 mode = Pagination::RightToLeftPaginated;
674 case kWKPaginationModeTopToBottom:
675 mode = Pagination::TopToBottomPaginated;
677 case kWKPaginationModeBottomToTop:
678 mode = Pagination::BottomToTopPaginated;
683 toImpl(pageRef)->setPaginationMode(mode);
686 WKPaginationMode WKPageGetPaginationMode(WKPageRef pageRef)
688 switch (toImpl(pageRef)->paginationMode()) {
689 case Pagination::Unpaginated:
690 return kWKPaginationModeUnpaginated;
691 case Pagination::LeftToRightPaginated:
692 return kWKPaginationModeLeftToRight;
693 case Pagination::RightToLeftPaginated:
694 return kWKPaginationModeRightToLeft;
695 case Pagination::TopToBottomPaginated:
696 return kWKPaginationModeTopToBottom;
697 case Pagination::BottomToTopPaginated:
698 return kWKPaginationModeBottomToTop;
701 ASSERT_NOT_REACHED();
702 return kWKPaginationModeUnpaginated;
705 void WKPageSetPaginationBehavesLikeColumns(WKPageRef pageRef, bool behavesLikeColumns)
707 toImpl(pageRef)->setPaginationBehavesLikeColumns(behavesLikeColumns);
710 bool WKPageGetPaginationBehavesLikeColumns(WKPageRef pageRef)
712 return toImpl(pageRef)->paginationBehavesLikeColumns();
715 void WKPageSetPageLength(WKPageRef pageRef, double pageLength)
717 toImpl(pageRef)->setPageLength(pageLength);
720 double WKPageGetPageLength(WKPageRef pageRef)
722 return toImpl(pageRef)->pageLength();
725 void WKPageSetGapBetweenPages(WKPageRef pageRef, double gap)
727 toImpl(pageRef)->setGapBetweenPages(gap);
730 double WKPageGetGapBetweenPages(WKPageRef pageRef)
732 return toImpl(pageRef)->gapBetweenPages();
735 void WKPageSetPaginationLineGridEnabled(WKPageRef pageRef, bool lineGridEnabled)
737 toImpl(pageRef)->setPaginationLineGridEnabled(lineGridEnabled);
740 bool WKPageGetPaginationLineGridEnabled(WKPageRef pageRef)
742 return toImpl(pageRef)->paginationLineGridEnabled();
745 unsigned WKPageGetPageCount(WKPageRef pageRef)
747 return toImpl(pageRef)->pageCount();
750 bool WKPageCanDelete(WKPageRef pageRef)
752 return toImpl(pageRef)->canDelete();
755 bool WKPageHasSelectedRange(WKPageRef pageRef)
757 return toImpl(pageRef)->hasSelectedRange();
760 bool WKPageIsContentEditable(WKPageRef pageRef)
762 return toImpl(pageRef)->isContentEditable();
765 void WKPageSetMaintainsInactiveSelection(WKPageRef pageRef, bool newValue)
767 return toImpl(pageRef)->setMaintainsInactiveSelection(newValue);
770 void WKPageCenterSelectionInVisibleArea(WKPageRef pageRef)
772 return toImpl(pageRef)->centerSelectionInVisibleArea();
775 void WKPageFindStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
777 toImpl(pageRef)->findStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
780 void WKPageGetImageForFindMatch(WKPageRef pageRef, int32_t matchIndex)
782 toImpl(pageRef)->getImageForFindMatch(matchIndex);
785 void WKPageSelectFindMatch(WKPageRef pageRef, int32_t matchIndex)
787 toImpl(pageRef)->selectFindMatch(matchIndex);
790 void WKPageFindString(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
792 toImpl(pageRef)->findString(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
795 void WKPageHideFindUI(WKPageRef pageRef)
797 toImpl(pageRef)->hideFindUI();
800 void WKPageCountStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
802 toImpl(pageRef)->countStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
805 void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuClientBase* wkClient)
807 #if ENABLE(CONTEXT_MENUS)
808 class ContextMenuClient final : public API::Client<WKPageContextMenuClientBase>, public API::ContextMenuClient {
810 explicit ContextMenuClient(const WKPageContextMenuClientBase* client)
816 bool getContextMenuFromProposedMenu(WebPageProxy& page, const Vector<RefPtr<WebKit::WebContextMenuItem>>& proposedMenuVector, Vector<RefPtr<WebKit::WebContextMenuItem>>& customMenu, const WebHitTestResultData& hitTestResultData, API::Object* userData) override
818 if (!m_client.getContextMenuFromProposedMenu && !m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0)
821 if (m_client.base.version >= 2 && !m_client.getContextMenuFromProposedMenu)
824 Vector<RefPtr<API::Object>> proposedMenuItems;
825 proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size());
827 for (const auto& menuItem : proposedMenuVector)
828 proposedMenuItems.uncheckedAppend(menuItem);
830 WKArrayRef newMenu = nullptr;
831 if (m_client.base.version >= 2) {
832 RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(hitTestResultData);
833 m_client.getContextMenuFromProposedMenu(toAPI(&page), toAPI(API::Array::create(WTFMove(proposedMenuItems)).ptr()), &newMenu, toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo);
835 m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0(toAPI(&page), toAPI(API::Array::create(WTFMove(proposedMenuItems)).ptr()), &newMenu, toAPI(userData), m_client.base.clientInfo);
837 RefPtr<API::Array> array = adoptRef(toImpl(newMenu));
841 size_t newSize = array ? array->size() : 0;
842 for (size_t i = 0; i < newSize; ++i) {
843 WebContextMenuItem* item = array->at<WebContextMenuItem>(i);
845 LOG(ContextMenu, "New menu entry at index %i is not a WebContextMenuItem", (int)i);
849 customMenu.append(item);
855 bool getContextMenuFromProposedMenuAsync(WebPageProxy& page, const Vector<RefPtr<WebKit::WebContextMenuItem>>& proposedMenuVector, WebKit::WebContextMenuListenerProxy* contextMenuListener, const WebHitTestResultData& hitTestResultData, API::Object* userData) override
857 if (m_client.base.version < 4 || !m_client.getContextMenuFromProposedMenuAsync)
860 Vector<RefPtr<API::Object>> proposedMenuItems;
861 proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size());
863 for (const auto& menuItem : proposedMenuVector)
864 proposedMenuItems.uncheckedAppend(menuItem);
866 RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(hitTestResultData);
867 m_client.getContextMenuFromProposedMenuAsync(toAPI(&page), toAPI(API::Array::create(WTFMove(proposedMenuItems)).ptr()), toAPI(contextMenuListener), toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo);
872 void customContextMenuItemSelected(WebPageProxy& page, const WebContextMenuItemData& itemData) override
874 if (!m_client.customContextMenuItemSelected)
877 m_client.customContextMenuItemSelected(toAPI(&page), toAPI(WebContextMenuItem::create(itemData).ptr()), m_client.base.clientInfo);
880 bool showContextMenu(WebPageProxy& page, const WebCore::IntPoint& menuLocation, const Vector<RefPtr<WebContextMenuItem>>& menuItemsVector) override
882 if (!m_client.showContextMenu)
885 Vector<RefPtr<API::Object>> menuItems;
886 menuItems.reserveInitialCapacity(menuItemsVector.size());
888 for (const auto& menuItem : menuItemsVector)
889 menuItems.uncheckedAppend(menuItem);
891 m_client.showContextMenu(toAPI(&page), toAPI(menuLocation), toAPI(API::Array::create(WTFMove(menuItems)).ptr()), m_client.base.clientInfo);
896 bool hideContextMenu(WebPageProxy& page) override
898 if (!m_client.hideContextMenu)
901 m_client.hideContextMenu(toAPI(&page), m_client.base.clientInfo);
907 toImpl(pageRef)->setContextMenuClient(std::make_unique<ContextMenuClient>(wkClient));
909 UNUSED_PARAM(pageRef);
910 UNUSED_PARAM(wkClient);
914 void WKPageSetPageDiagnosticLoggingClient(WKPageRef pageRef, const WKPageDiagnosticLoggingClientBase* wkClient)
916 toImpl(pageRef)->setDiagnosticLoggingClient(std::make_unique<WebPageDiagnosticLoggingClient>(wkClient));
919 void WKPageSetPageFindClient(WKPageRef pageRef, const WKPageFindClientBase* wkClient)
921 class FindClient : public API::Client<WKPageFindClientBase>, public API::FindClient {
923 explicit FindClient(const WKPageFindClientBase* client)
929 void didFindString(WebPageProxy* page, const String& string, const Vector<WebCore::IntRect>&, uint32_t matchCount, int32_t) override
931 if (!m_client.didFindString)
934 m_client.didFindString(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
937 void didFailToFindString(WebPageProxy* page, const String& string) override
939 if (!m_client.didFailToFindString)
942 m_client.didFailToFindString(toAPI(page), toAPI(string.impl()), m_client.base.clientInfo);
945 void didCountStringMatches(WebPageProxy* page, const String& string, uint32_t matchCount) override
947 if (!m_client.didCountStringMatches)
950 m_client.didCountStringMatches(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
954 toImpl(pageRef)->setFindClient(std::make_unique<FindClient>(wkClient));
957 void WKPageSetPageFindMatchesClient(WKPageRef pageRef, const WKPageFindMatchesClientBase* wkClient)
959 class FindMatchesClient : public API::Client<WKPageFindMatchesClientBase>, public API::FindMatchesClient {
961 explicit FindMatchesClient(const WKPageFindMatchesClientBase* client)
967 void didFindStringMatches(WebPageProxy* page, const String& string, const Vector<Vector<WebCore::IntRect>>& matchRects, int32_t index) override
969 if (!m_client.didFindStringMatches)
972 Vector<RefPtr<API::Object>> matches;
973 matches.reserveInitialCapacity(matchRects.size());
975 for (const auto& rects : matchRects) {
976 Vector<RefPtr<API::Object>> apiRects;
977 apiRects.reserveInitialCapacity(rects.size());
979 for (const auto& rect : rects)
980 apiRects.uncheckedAppend(API::Rect::create(toAPI(rect)));
982 matches.uncheckedAppend(API::Array::create(WTFMove(apiRects)));
985 m_client.didFindStringMatches(toAPI(page), toAPI(string.impl()), toAPI(API::Array::create(WTFMove(matches)).ptr()), index, m_client.base.clientInfo);
988 void didGetImageForMatchResult(WebPageProxy* page, WebImage* image, int32_t index) override
990 if (!m_client.didGetImageForMatchResult)
993 m_client.didGetImageForMatchResult(toAPI(page), toAPI(image), index, m_client.base.clientInfo);
997 toImpl(pageRef)->setFindMatchesClient(std::make_unique<FindMatchesClient>(wkClient));
1000 void WKPageSetPageInjectedBundleClient(WKPageRef pageRef, const WKPageInjectedBundleClientBase* wkClient)
1002 toImpl(pageRef)->setInjectedBundleClient(wkClient);
1005 void WKPageSetPageFormClient(WKPageRef pageRef, const WKPageFormClientBase* wkClient)
1007 toImpl(pageRef)->setFormClient(std::make_unique<WebFormClient>(wkClient));
1010 void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase* wkClient)
1012 class LoaderClient : public API::Client<WKPageLoaderClientBase>, public API::LoaderClient {
1014 explicit LoaderClient(const WKPageLoaderClientBase* client)
1020 void didStartProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
1022 if (!m_client.didStartProvisionalLoadForFrame)
1025 m_client.didStartProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1028 void didReceiveServerRedirectForProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
1030 if (!m_client.didReceiveServerRedirectForProvisionalLoadForFrame)
1033 m_client.didReceiveServerRedirectForProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1036 void didFailProvisionalLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
1038 if (!m_client.didFailProvisionalLoadWithErrorForFrame)
1041 m_client.didFailProvisionalLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1044 void didCommitLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
1046 if (!m_client.didCommitLoadForFrame)
1049 m_client.didCommitLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1052 void didFinishDocumentLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
1054 if (!m_client.didFinishDocumentLoadForFrame)
1057 m_client.didFinishDocumentLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1060 void didFinishLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
1062 if (!m_client.didFinishLoadForFrame)
1065 m_client.didFinishLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1068 void didFailLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
1070 if (!m_client.didFailLoadWithErrorForFrame)
1073 m_client.didFailLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1076 void didSameDocumentNavigationForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, SameDocumentNavigationType type, API::Object* userData) override
1078 if (!m_client.didSameDocumentNavigationForFrame)
1081 m_client.didSameDocumentNavigationForFrame(toAPI(&page), toAPI(&frame), toAPI(type), toAPI(userData), m_client.base.clientInfo);
1084 void didReceiveTitleForFrame(WebPageProxy& page, const String& title, WebFrameProxy& frame, API::Object* userData) override
1086 if (!m_client.didReceiveTitleForFrame)
1089 m_client.didReceiveTitleForFrame(toAPI(&page), toAPI(title.impl()), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1092 void didFirstLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1094 if (!m_client.didFirstLayoutForFrame)
1097 m_client.didFirstLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1100 void didFirstVisuallyNonEmptyLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1102 if (!m_client.didFirstVisuallyNonEmptyLayoutForFrame)
1105 m_client.didFirstVisuallyNonEmptyLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1108 void didReachLayoutMilestone(WebPageProxy& page, LayoutMilestones milestones) override
1110 if (!m_client.didLayout)
1113 m_client.didLayout(toAPI(&page), toWKLayoutMilestones(milestones), nullptr, m_client.base.clientInfo);
1116 void didDisplayInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1118 if (!m_client.didDisplayInsecureContentForFrame)
1121 m_client.didDisplayInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1124 void didRunInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1126 if (!m_client.didRunInsecureContentForFrame)
1129 m_client.didRunInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1132 void didDetectXSSForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1134 if (!m_client.didDetectXSSForFrame)
1137 m_client.didDetectXSSForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1140 bool canAuthenticateAgainstProtectionSpaceInFrame(WebPageProxy& page, WebFrameProxy& frame, WebProtectionSpace* protectionSpace) override
1142 if (!m_client.canAuthenticateAgainstProtectionSpaceInFrame)
1145 return m_client.canAuthenticateAgainstProtectionSpaceInFrame(toAPI(&page), toAPI(&frame), toAPI(protectionSpace), m_client.base.clientInfo);
1148 void didReceiveAuthenticationChallengeInFrame(WebPageProxy& page, WebFrameProxy& frame, AuthenticationChallengeProxy* authenticationChallenge) override
1150 if (!m_client.didReceiveAuthenticationChallengeInFrame)
1153 m_client.didReceiveAuthenticationChallengeInFrame(toAPI(&page), toAPI(&frame), toAPI(authenticationChallenge), m_client.base.clientInfo);
1156 void didStartProgress(WebPageProxy& page) override
1158 if (!m_client.didStartProgress)
1161 m_client.didStartProgress(toAPI(&page), m_client.base.clientInfo);
1164 void didChangeProgress(WebPageProxy& page) override
1166 if (!m_client.didChangeProgress)
1169 m_client.didChangeProgress(toAPI(&page), m_client.base.clientInfo);
1172 void didFinishProgress(WebPageProxy& page) override
1174 if (!m_client.didFinishProgress)
1177 m_client.didFinishProgress(toAPI(&page), m_client.base.clientInfo);
1180 void processDidBecomeUnresponsive(WebPageProxy& page) override
1182 if (!m_client.processDidBecomeUnresponsive)
1185 m_client.processDidBecomeUnresponsive(toAPI(&page), m_client.base.clientInfo);
1188 void processDidBecomeResponsive(WebPageProxy& page) override
1190 if (!m_client.processDidBecomeResponsive)
1193 m_client.processDidBecomeResponsive(toAPI(&page), m_client.base.clientInfo);
1196 void processDidCrash(WebPageProxy& page) override
1198 if (!m_client.processDidCrash)
1201 m_client.processDidCrash(toAPI(&page), m_client.base.clientInfo);
1204 void didChangeBackForwardList(WebPageProxy& page, WebBackForwardListItem* addedItem, Vector<RefPtr<WebBackForwardListItem>> removedItems) override
1206 if (!m_client.didChangeBackForwardList)
1209 RefPtr<API::Array> removedItemsArray;
1210 if (!removedItems.isEmpty()) {
1211 Vector<RefPtr<API::Object>> removedItemsVector;
1212 removedItemsVector.reserveInitialCapacity(removedItems.size());
1213 for (auto& removedItem : removedItems)
1214 removedItemsVector.append(WTFMove(removedItem));
1216 removedItemsArray = API::Array::create(WTFMove(removedItemsVector));
1219 m_client.didChangeBackForwardList(toAPI(&page), toAPI(addedItem), toAPI(removedItemsArray.get()), m_client.base.clientInfo);
1222 bool shouldKeepCurrentBackForwardListItemInList(WebKit::WebPageProxy& page, WebKit::WebBackForwardListItem* item) override
1224 if (!m_client.shouldKeepCurrentBackForwardListItemInList)
1227 return m_client.shouldKeepCurrentBackForwardListItemInList(toAPI(&page), toAPI(item), m_client.base.clientInfo);
1230 void willGoToBackForwardListItem(WebPageProxy& page, WebBackForwardListItem* item, API::Object* userData) override
1232 if (m_client.willGoToBackForwardListItem)
1233 m_client.willGoToBackForwardListItem(toAPI(&page), toAPI(item), toAPI(userData), m_client.base.clientInfo);
1236 void navigationGestureDidBegin(WebPageProxy& page) override
1238 if (m_client.navigationGestureDidBegin)
1239 m_client.navigationGestureDidBegin(toAPI(&page), m_client.base.clientInfo);
1242 void navigationGestureWillEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override
1244 if (m_client.navigationGestureWillEnd)
1245 m_client.navigationGestureWillEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo);
1248 void navigationGestureDidEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override
1250 if (m_client.navigationGestureDidEnd)
1251 m_client.navigationGestureDidEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo);
1254 #if ENABLE(NETSCAPE_PLUGIN_API)
1255 void didFailToInitializePlugin(WebPageProxy& page, API::Dictionary* pluginInformation) override
1257 if (m_client.didFailToInitializePlugin_deprecatedForUseWithV0)
1258 m_client.didFailToInitializePlugin_deprecatedForUseWithV0(toAPI(&page), toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), m_client.base.clientInfo);
1260 if (m_client.pluginDidFail_deprecatedForUseWithV1)
1261 m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), 0, 0, m_client.base.clientInfo);
1263 if (m_client.pluginDidFail)
1264 m_client.pluginDidFail(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation), m_client.base.clientInfo);
1267 void didBlockInsecurePluginVersion(WebPageProxy& page, API::Dictionary* pluginInformation) override
1269 if (m_client.pluginDidFail_deprecatedForUseWithV1)
1270 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);
1272 if (m_client.pluginDidFail)
1273 m_client.pluginDidFail(toAPI(&page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation), m_client.base.clientInfo);
1276 PluginModuleLoadPolicy pluginLoadPolicy(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
1278 WKStringRef unavailabilityDescriptionOut = 0;
1279 PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
1281 if (m_client.pluginLoadPolicy_deprecatedForUseWithV2)
1282 loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy_deprecatedForUseWithV2(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), m_client.base.clientInfo));
1283 else if (m_client.pluginLoadPolicy)
1284 loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
1286 if (unavailabilityDescriptionOut) {
1287 RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
1288 unavailabilityDescription = webUnavailabilityDescription->string();
1293 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1296 WebCore::WebGLLoadPolicy webGLLoadPolicy(WebPageProxy& page, const String& url) const override
1298 WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
1300 if (m_client.webGLLoadPolicy)
1301 loadPolicy = toWebGLLoadPolicy(m_client.webGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
1306 WebCore::WebGLLoadPolicy resolveWebGLLoadPolicy(WebPageProxy& page, const String& url) const override
1308 WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
1310 if (m_client.resolveWebGLLoadPolicy)
1311 loadPolicy = toWebGLLoadPolicy(m_client.resolveWebGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
1316 #endif // ENABLE(WEBGL)
1319 WebPageProxy* webPageProxy = toImpl(pageRef);
1321 auto loaderClient = std::make_unique<LoaderClient>(wkClient);
1323 // It would be nice to get rid of this code and transition all clients to using didLayout instead of
1324 // didFirstLayoutInFrame and didFirstVisuallyNonEmptyLayoutInFrame. In the meantime, this is required
1325 // for backwards compatibility.
1326 WebCore::LayoutMilestones milestones = 0;
1327 if (loaderClient->client().didFirstLayoutForFrame)
1328 milestones |= WebCore::DidFirstLayout;
1329 if (loaderClient->client().didFirstVisuallyNonEmptyLayoutForFrame)
1330 milestones |= WebCore::DidFirstVisuallyNonEmptyLayout;
1333 webPageProxy->process().send(Messages::WebPage::ListenForLayoutMilestones(milestones), webPageProxy->pageID());
1335 webPageProxy->setLoaderClient(WTFMove(loaderClient));
1338 void WKPageSetPagePolicyClient(WKPageRef pageRef, const WKPagePolicyClientBase* wkClient)
1340 class PolicyClient : public API::Client<WKPagePolicyClientBase>, public API::PolicyClient {
1342 explicit PolicyClient(const WKPagePolicyClientBase* client)
1348 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
1350 if (!m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0 && !m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1 && !m_client.decidePolicyForNavigationAction) {
1355 Ref<API::URLRequest> originalRequest = API::URLRequest::create(originalResourceRequest);
1356 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1358 if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0)
1359 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);
1360 else if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1)
1361 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);
1363 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);
1366 void decidePolicyForNewWindowAction(WebPageProxy& page, WebFrameProxy& frame, const NavigationActionData& navigationActionData, const ResourceRequest& resourceRequest, const String& frameName, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1368 if (!m_client.decidePolicyForNewWindowAction) {
1373 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1375 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);
1378 void decidePolicyForResponse(WebPageProxy& page, WebFrameProxy& frame, const ResourceResponse& resourceResponse, const ResourceRequest& resourceRequest, bool canShowMIMEType, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1380 if (!m_client.decidePolicyForResponse_deprecatedForUseWithV0 && !m_client.decidePolicyForResponse) {
1385 Ref<API::URLResponse> response = API::URLResponse::create(resourceResponse);
1386 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1388 if (m_client.decidePolicyForResponse_deprecatedForUseWithV0)
1389 m_client.decidePolicyForResponse_deprecatedForUseWithV0(toAPI(&page), toAPI(&frame), toAPI(response.ptr()), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1391 m_client.decidePolicyForResponse(toAPI(&page), toAPI(&frame), toAPI(response.ptr()), toAPI(request.ptr()), canShowMIMEType, toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1394 void unableToImplementPolicy(WebPageProxy& page, WebFrameProxy& frame, const ResourceError& error, API::Object* userData) override
1396 if (!m_client.unableToImplementPolicy)
1399 m_client.unableToImplementPolicy(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1403 toImpl(pageRef)->setPolicyClient(std::make_unique<PolicyClient>(wkClient));
1406 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000
1407 static void fixUpBotchedPageUIClient(WKPageRef pageRef, const WKPageUIClientBase& wkClient)
1409 struct BotchedWKPageUIClientV4 {
1410 WKPageUIClientBase base;
1413 WKPageCreateNewPageCallback_deprecatedForUseWithV0 createNewPage_deprecatedForUseWithV0;
1414 WKPageUIClientCallback showPage;
1415 WKPageUIClientCallback close;
1416 WKPageTakeFocusCallback takeFocus;
1417 WKPageFocusCallback focus;
1418 WKPageUnfocusCallback unfocus;
1419 WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert_deprecatedForUseWithV0;
1420 WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm_deprecatedForUseWithV0;
1421 WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt_deprecatedForUseWithV0;
1422 WKPageSetStatusTextCallback setStatusText;
1423 WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0;
1424 WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0;
1425 WKPageDidNotHandleKeyEventCallback didNotHandleKeyEvent;
1426 WKPageDidNotHandleWheelEventCallback didNotHandleWheelEvent;
1427 WKPageGetToolbarsAreVisibleCallback toolbarsAreVisible;
1428 WKPageSetToolbarsAreVisibleCallback setToolbarsAreVisible;
1429 WKPageGetMenuBarIsVisibleCallback menuBarIsVisible;
1430 WKPageSetMenuBarIsVisibleCallback setMenuBarIsVisible;
1431 WKPageGetStatusBarIsVisibleCallback statusBarIsVisible;
1432 WKPageSetStatusBarIsVisibleCallback setStatusBarIsVisible;
1433 WKPageGetIsResizableCallback isResizable;
1434 WKPageSetIsResizableCallback setIsResizable;
1435 WKPageGetWindowFrameCallback getWindowFrame;
1436 WKPageSetWindowFrameCallback setWindowFrame;
1437 WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6 runBeforeUnloadConfirmPanel;
1438 WKPageUIClientCallback didDraw;
1439 WKPageUIClientCallback pageDidScroll;
1440 WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota;
1441 WKPageRunOpenPanelCallback runOpenPanel;
1442 WKPageDecidePolicyForGeolocationPermissionRequestCallback decidePolicyForGeolocationPermissionRequest;
1443 WKPageHeaderHeightCallback headerHeight;
1444 WKPageFooterHeightCallback footerHeight;
1445 WKPageDrawHeaderCallback drawHeader;
1446 WKPageDrawFooterCallback drawFooter;
1447 WKPagePrintFrameCallback printFrame;
1448 WKPageUIClientCallback runModal;
1449 void* unused1; // Used to be didCompleteRubberBandForMainFrame
1450 WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder;
1451 void* shouldInterruptJavaScript_unavailable;
1454 WKPageCreateNewPageCallback_deprecatedForUseWithV1 createNewPage;
1455 WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement;
1456 WKPageDecidePolicyForNotificationPermissionRequestCallback decidePolicyForNotificationPermissionRequest;
1457 WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1;
1460 WKPageShowColorPickerCallback showColorPicker;
1461 WKPageHideColorPickerCallback hideColorPicker;
1462 WKPageUnavailablePluginButtonClickedCallback unavailablePluginButtonClicked;
1465 WKPagePinnedStateDidChangeCallback pinnedStateDidChange;
1468 WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV5 runJavaScriptAlert;
1469 WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV5 runJavaScriptConfirm;
1470 WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV5 runJavaScriptPrompt;
1473 const auto& botchedPageUIClient = reinterpret_cast<const BotchedWKPageUIClientV4&>(wkClient);
1475 WKPageUIClientV5 fixedPageUIClient = {
1476 { 5, botchedPageUIClient.base.clientInfo },
1477 botchedPageUIClient.createNewPage_deprecatedForUseWithV0,
1478 botchedPageUIClient.showPage,
1479 botchedPageUIClient.close,
1480 botchedPageUIClient.takeFocus,
1481 botchedPageUIClient.focus,
1482 botchedPageUIClient.unfocus,
1483 botchedPageUIClient.runJavaScriptAlert_deprecatedForUseWithV0,
1484 botchedPageUIClient.runJavaScriptConfirm_deprecatedForUseWithV0,
1485 botchedPageUIClient.runJavaScriptPrompt_deprecatedForUseWithV0,
1486 botchedPageUIClient.setStatusText,
1487 botchedPageUIClient.mouseDidMoveOverElement_deprecatedForUseWithV0,
1488 botchedPageUIClient.missingPluginButtonClicked_deprecatedForUseWithV0,
1489 botchedPageUIClient.didNotHandleKeyEvent,
1490 botchedPageUIClient.didNotHandleWheelEvent,
1491 botchedPageUIClient.toolbarsAreVisible,
1492 botchedPageUIClient.setToolbarsAreVisible,
1493 botchedPageUIClient.menuBarIsVisible,
1494 botchedPageUIClient.setMenuBarIsVisible,
1495 botchedPageUIClient.statusBarIsVisible,
1496 botchedPageUIClient.setStatusBarIsVisible,
1497 botchedPageUIClient.isResizable,
1498 botchedPageUIClient.setIsResizable,
1499 botchedPageUIClient.getWindowFrame,
1500 botchedPageUIClient.setWindowFrame,
1501 botchedPageUIClient.runBeforeUnloadConfirmPanel,
1502 botchedPageUIClient.didDraw,
1503 botchedPageUIClient.pageDidScroll,
1504 botchedPageUIClient.exceededDatabaseQuota,
1505 botchedPageUIClient.runOpenPanel,
1506 botchedPageUIClient.decidePolicyForGeolocationPermissionRequest,
1507 botchedPageUIClient.headerHeight,
1508 botchedPageUIClient.footerHeight,
1509 botchedPageUIClient.drawHeader,
1510 botchedPageUIClient.drawFooter,
1511 botchedPageUIClient.printFrame,
1512 botchedPageUIClient.runModal,
1513 botchedPageUIClient.unused1,
1514 botchedPageUIClient.saveDataToFileInDownloadsFolder,
1515 botchedPageUIClient.shouldInterruptJavaScript_unavailable,
1516 botchedPageUIClient.createNewPage,
1517 botchedPageUIClient.mouseDidMoveOverElement,
1518 botchedPageUIClient.decidePolicyForNotificationPermissionRequest,
1519 botchedPageUIClient.unavailablePluginButtonClicked_deprecatedForUseWithV1,
1520 botchedPageUIClient.showColorPicker,
1521 botchedPageUIClient.hideColorPicker,
1522 botchedPageUIClient.unavailablePluginButtonClicked,
1523 botchedPageUIClient.pinnedStateDidChange,
1530 botchedPageUIClient.runJavaScriptAlert,
1531 botchedPageUIClient.runJavaScriptConfirm,
1532 botchedPageUIClient.runJavaScriptPrompt,
1536 WKPageSetPageUIClient(pageRef, &fixedPageUIClient.base);
1542 class RunBeforeUnloadConfirmPanelResultListener : public API::ObjectImpl<API::Object::Type::RunBeforeUnloadConfirmPanelResultListener> {
1544 static PassRefPtr<RunBeforeUnloadConfirmPanelResultListener> create(Function<void (bool)>&& completionHandler)
1546 return adoptRef(new RunBeforeUnloadConfirmPanelResultListener(WTFMove(completionHandler)));
1549 virtual ~RunBeforeUnloadConfirmPanelResultListener()
1553 void call(bool result)
1555 m_completionHandler(result);
1559 explicit RunBeforeUnloadConfirmPanelResultListener(Function<void (bool)>&& completionHandler)
1560 : m_completionHandler(WTFMove(completionHandler))
1564 Function<void (bool)> m_completionHandler;
1567 class RunJavaScriptAlertResultListener : public API::ObjectImpl<API::Object::Type::RunJavaScriptAlertResultListener> {
1569 static PassRefPtr<RunJavaScriptAlertResultListener> create(Function<void ()>&& completionHandler)
1571 return adoptRef(new RunJavaScriptAlertResultListener(WTFMove(completionHandler)));
1574 virtual ~RunJavaScriptAlertResultListener()
1580 m_completionHandler();
1584 explicit RunJavaScriptAlertResultListener(Function<void ()>&& completionHandler)
1585 : m_completionHandler(WTFMove(completionHandler))
1589 Function<void ()> m_completionHandler;
1592 class RunJavaScriptConfirmResultListener : public API::ObjectImpl<API::Object::Type::RunJavaScriptConfirmResultListener> {
1594 static PassRefPtr<RunJavaScriptConfirmResultListener> create(Function<void (bool)>&& completionHandler)
1596 return adoptRef(new RunJavaScriptConfirmResultListener(WTFMove(completionHandler)));
1599 virtual ~RunJavaScriptConfirmResultListener()
1603 void call(bool result)
1605 m_completionHandler(result);
1609 explicit RunJavaScriptConfirmResultListener(Function<void (bool)>&& completionHandler)
1610 : m_completionHandler(WTFMove(completionHandler))
1614 Function<void (bool)> m_completionHandler;
1617 class RunJavaScriptPromptResultListener : public API::ObjectImpl<API::Object::Type::RunJavaScriptPromptResultListener> {
1619 static PassRefPtr<RunJavaScriptPromptResultListener> create(Function<void (const String&)>&& completionHandler)
1621 return adoptRef(new RunJavaScriptPromptResultListener(WTFMove(completionHandler)));
1624 virtual ~RunJavaScriptPromptResultListener()
1628 void call(const String& result)
1630 m_completionHandler(result);
1634 explicit RunJavaScriptPromptResultListener(Function<void (const String&)>&& completionHandler)
1635 : m_completionHandler(WTFMove(completionHandler))
1639 Function<void (const String&)> m_completionHandler;
1642 WK_ADD_API_MAPPING(WKPageRunBeforeUnloadConfirmPanelResultListenerRef, RunBeforeUnloadConfirmPanelResultListener)
1643 WK_ADD_API_MAPPING(WKPageRunJavaScriptAlertResultListenerRef, RunJavaScriptAlertResultListener)
1644 WK_ADD_API_MAPPING(WKPageRunJavaScriptConfirmResultListenerRef, RunJavaScriptConfirmResultListener)
1645 WK_ADD_API_MAPPING(WKPageRunJavaScriptPromptResultListenerRef, RunJavaScriptPromptResultListener)
1649 WKTypeID WKPageRunBeforeUnloadConfirmPanelResultListenerGetTypeID()
1651 return toAPI(RunBeforeUnloadConfirmPanelResultListener::APIType);
1654 void WKPageRunBeforeUnloadConfirmPanelResultListenerCall(WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, bool result)
1656 toImpl(listener)->call(result);
1659 WKTypeID WKPageRunJavaScriptAlertResultListenerGetTypeID()
1661 return toAPI(RunJavaScriptAlertResultListener::APIType);
1664 void WKPageRunJavaScriptAlertResultListenerCall(WKPageRunJavaScriptAlertResultListenerRef listener)
1666 toImpl(listener)->call();
1669 WKTypeID WKPageRunJavaScriptConfirmResultListenerGetTypeID()
1671 return toAPI(RunJavaScriptConfirmResultListener::APIType);
1674 void WKPageRunJavaScriptConfirmResultListenerCall(WKPageRunJavaScriptConfirmResultListenerRef listener, bool result)
1676 toImpl(listener)->call(result);
1679 WKTypeID WKPageRunJavaScriptPromptResultListenerGetTypeID()
1681 return toAPI(RunJavaScriptPromptResultListener::APIType);
1684 void WKPageRunJavaScriptPromptResultListenerCall(WKPageRunJavaScriptPromptResultListenerRef listener, WKStringRef result)
1686 toImpl(listener)->call(toWTFString(result));
1689 void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient)
1691 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000
1692 if (wkClient && wkClient->version == 4) {
1693 fixUpBotchedPageUIClient(pageRef, *wkClient);
1698 class UIClient : public API::Client<WKPageUIClientBase>, public API::UIClient {
1700 explicit UIClient(const WKPageUIClientBase* client)
1706 PassRefPtr<WebPageProxy> createNewPage(WebPageProxy* page, WebFrameProxy* initiatingFrame, const SecurityOriginData& securityOriginData, const ResourceRequest& resourceRequest, const WindowFeatures& windowFeatures, const NavigationActionData& navigationActionData) override
1708 if (m_client.createNewPage) {
1709 auto configuration = page->configuration().copy();
1710 configuration->setRelatedPage(page);
1712 auto sourceFrameInfo = API::FrameInfo::create(*initiatingFrame, securityOriginData.securityOrigin());
1714 auto userInitiatedActivity = page->process().userInitiatedActivity(navigationActionData.userGestureTokenIdentifier);
1715 bool shouldOpenAppLinks = !hostsAreEqual(WebCore::URL(WebCore::ParsedURLString, initiatingFrame->url()), resourceRequest.url());
1716 auto apiNavigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.ptr(), nullptr, resourceRequest, WebCore::URL(), shouldOpenAppLinks, userInitiatedActivity);
1718 auto apiWindowFeatures = API::WindowFeatures::create(windowFeatures);
1720 return adoptRef(toImpl(m_client.createNewPage(toAPI(page), toAPI(configuration.ptr()), toAPI(apiNavigationAction.ptr()), toAPI(apiWindowFeatures.ptr()), m_client.base.clientInfo)));
1723 if (m_client.createNewPage_deprecatedForUseWithV1 || m_client.createNewPage_deprecatedForUseWithV0) {
1724 API::Dictionary::MapType map;
1725 if (windowFeatures.x)
1726 map.set("x", API::Double::create(*windowFeatures.x));
1727 if (windowFeatures.y)
1728 map.set("y", API::Double::create(*windowFeatures.y));
1729 if (windowFeatures.width)
1730 map.set("width", API::Double::create(*windowFeatures.width));
1731 if (windowFeatures.height)
1732 map.set("height", API::Double::create(*windowFeatures.height));
1733 map.set("menuBarVisible", API::Boolean::create(windowFeatures.menuBarVisible));
1734 map.set("statusBarVisible", API::Boolean::create(windowFeatures.statusBarVisible));
1735 map.set("toolBarVisible", API::Boolean::create(windowFeatures.toolBarVisible));
1736 map.set("locationBarVisible", API::Boolean::create(windowFeatures.locationBarVisible));
1737 map.set("scrollbarsVisible", API::Boolean::create(windowFeatures.scrollbarsVisible));
1738 map.set("resizable", API::Boolean::create(windowFeatures.resizable));
1739 map.set("fullscreen", API::Boolean::create(windowFeatures.fullscreen));
1740 map.set("dialog", API::Boolean::create(windowFeatures.dialog));
1741 Ref<API::Dictionary> featuresMap = API::Dictionary::create(WTFMove(map));
1743 if (m_client.createNewPage_deprecatedForUseWithV1) {
1744 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1745 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)));
1748 ASSERT(m_client.createNewPage_deprecatedForUseWithV0);
1749 return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV0(toAPI(page), toAPI(featuresMap.ptr()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
1755 void showPage(WebPageProxy* page) override
1757 if (!m_client.showPage)
1760 m_client.showPage(toAPI(page), m_client.base.clientInfo);
1763 void fullscreenMayReturnToInline(WebPageProxy* page) override
1765 if (!m_client.fullscreenMayReturnToInline)
1768 m_client.fullscreenMayReturnToInline(toAPI(page), m_client.base.clientInfo);
1771 void close(WebPageProxy* page) override
1773 if (!m_client.close)
1776 m_client.close(toAPI(page), m_client.base.clientInfo);
1779 void takeFocus(WebPageProxy* page, WKFocusDirection direction) override
1781 if (!m_client.takeFocus)
1784 m_client.takeFocus(toAPI(page), direction, m_client.base.clientInfo);
1787 void focus(WebPageProxy* page) override
1789 if (!m_client.focus)
1792 m_client.focus(toAPI(page), m_client.base.clientInfo);
1795 void unfocus(WebPageProxy* page) override
1797 if (!m_client.unfocus)
1800 m_client.unfocus(toAPI(page), m_client.base.clientInfo);
1803 void runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame, const SecurityOriginData& securityOriginData, Function<void ()>&& completionHandler) override
1805 if (m_client.runJavaScriptAlert) {
1806 RefPtr<RunJavaScriptAlertResultListener> listener = RunJavaScriptAlertResultListener::create(WTFMove(completionHandler));
1807 RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
1808 m_client.runJavaScriptAlert(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), toAPI(listener.get()), m_client.base.clientInfo);
1812 if (m_client.runJavaScriptAlert_deprecatedForUseWithV5) {
1813 RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
1814 m_client.runJavaScriptAlert_deprecatedForUseWithV5(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), m_client.base.clientInfo);
1815 completionHandler();
1819 if (m_client.runJavaScriptAlert_deprecatedForUseWithV0) {
1820 m_client.runJavaScriptAlert_deprecatedForUseWithV0(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1821 completionHandler();
1826 completionHandler();
1829 void runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame, const SecurityOriginData& securityOriginData, Function<void (bool)>&& completionHandler) override
1831 if (m_client.runJavaScriptConfirm) {
1832 RefPtr<RunJavaScriptConfirmResultListener> listener = RunJavaScriptConfirmResultListener::create(WTFMove(completionHandler));
1833 RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
1834 m_client.runJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), toAPI(listener.get()), m_client.base.clientInfo);
1838 if (m_client.runJavaScriptConfirm_deprecatedForUseWithV5) {
1839 RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
1840 bool result = m_client.runJavaScriptConfirm_deprecatedForUseWithV5(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), m_client.base.clientInfo);
1842 completionHandler(result);
1846 if (m_client.runJavaScriptConfirm_deprecatedForUseWithV0) {
1847 bool result = m_client.runJavaScriptConfirm_deprecatedForUseWithV0(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1849 completionHandler(result);
1853 completionHandler(false);
1856 void runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame, const SecurityOriginData& securityOriginData, Function<void (const String&)>&& completionHandler) override
1858 if (m_client.runJavaScriptPrompt) {
1859 RefPtr<RunJavaScriptPromptResultListener> listener = RunJavaScriptPromptResultListener::create(WTFMove(completionHandler));
1860 RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
1861 m_client.runJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), toAPI(securityOrigin.get()), toAPI(listener.get()), m_client.base.clientInfo);
1865 if (m_client.runJavaScriptPrompt_deprecatedForUseWithV5) {
1866 RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
1867 RefPtr<API::String> string = adoptRef(toImpl(m_client.runJavaScriptPrompt_deprecatedForUseWithV5(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), toAPI(securityOrigin.get()), m_client.base.clientInfo)));
1870 completionHandler(string->string());
1872 completionHandler(String());
1876 if (m_client.runJavaScriptPrompt_deprecatedForUseWithV0) {
1877 RefPtr<API::String> string = adoptRef(toImpl(m_client.runJavaScriptPrompt_deprecatedForUseWithV0(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.base.clientInfo)));
1880 completionHandler(string->string());
1882 completionHandler(String());
1886 completionHandler(String());
1889 void setStatusText(WebPageProxy* page, const String& text) override
1891 if (!m_client.setStatusText)
1894 m_client.setStatusText(toAPI(page), toAPI(text.impl()), m_client.base.clientInfo);
1897 void mouseDidMoveOverElement(WebPageProxy* page, const WebHitTestResultData& data, WebEvent::Modifiers modifiers, API::Object* userData) override
1899 if (!m_client.mouseDidMoveOverElement && !m_client.mouseDidMoveOverElement_deprecatedForUseWithV0)
1902 if (m_client.base.version > 0 && !m_client.mouseDidMoveOverElement)
1905 if (!m_client.base.version) {
1906 m_client.mouseDidMoveOverElement_deprecatedForUseWithV0(toAPI(page), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
1910 RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(data);
1911 m_client.mouseDidMoveOverElement(toAPI(page), toAPI(webHitTestResult.get()), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
1914 #if ENABLE(NETSCAPE_PLUGIN_API)
1915 void unavailablePluginButtonClicked(WebPageProxy* page, WKPluginUnavailabilityReason pluginUnavailabilityReason, API::Dictionary* pluginInformation) override
1917 if (pluginUnavailabilityReason == kWKPluginUnavailabilityReasonPluginMissing) {
1918 if (m_client.missingPluginButtonClicked_deprecatedForUseWithV0)
1919 m_client.missingPluginButtonClicked_deprecatedForUseWithV0(
1921 toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
1922 toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
1923 toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
1924 m_client.base.clientInfo);
1927 if (m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1)
1928 m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1(
1930 pluginUnavailabilityReason,
1931 toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
1932 toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
1933 toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
1934 m_client.base.clientInfo);
1936 if (m_client.unavailablePluginButtonClicked)
1937 m_client.unavailablePluginButtonClicked(
1939 pluginUnavailabilityReason,
1940 toAPI(pluginInformation),
1941 m_client.base.clientInfo);
1943 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1945 bool implementsDidNotHandleKeyEvent() const override
1947 return m_client.didNotHandleKeyEvent;
1950 void didNotHandleKeyEvent(WebPageProxy* page, const NativeWebKeyboardEvent& event) override
1952 if (!m_client.didNotHandleKeyEvent)
1954 m_client.didNotHandleKeyEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
1957 bool implementsDidNotHandleWheelEvent() const override
1959 return m_client.didNotHandleWheelEvent;
1962 void didNotHandleWheelEvent(WebPageProxy* page, const NativeWebWheelEvent& event) override
1964 if (!m_client.didNotHandleWheelEvent)
1966 m_client.didNotHandleWheelEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
1969 bool toolbarsAreVisible(WebPageProxy* page) override
1971 if (!m_client.toolbarsAreVisible)
1973 return m_client.toolbarsAreVisible(toAPI(page), m_client.base.clientInfo);
1976 void setToolbarsAreVisible(WebPageProxy* page, bool visible) override
1978 if (!m_client.setToolbarsAreVisible)
1980 m_client.setToolbarsAreVisible(toAPI(page), visible, m_client.base.clientInfo);
1983 bool menuBarIsVisible(WebPageProxy* page) override
1985 if (!m_client.menuBarIsVisible)
1987 return m_client.menuBarIsVisible(toAPI(page), m_client.base.clientInfo);
1990 void setMenuBarIsVisible(WebPageProxy* page, bool visible) override
1992 if (!m_client.setMenuBarIsVisible)
1994 m_client.setMenuBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
1997 bool statusBarIsVisible(WebPageProxy* page) override
1999 if (!m_client.statusBarIsVisible)
2001 return m_client.statusBarIsVisible(toAPI(page), m_client.base.clientInfo);
2004 void setStatusBarIsVisible(WebPageProxy* page, bool visible) override
2006 if (!m_client.setStatusBarIsVisible)
2008 m_client.setStatusBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
2011 bool isResizable(WebPageProxy* page) override
2013 if (!m_client.isResizable)
2015 return m_client.isResizable(toAPI(page), m_client.base.clientInfo);
2018 void setIsResizable(WebPageProxy* page, bool resizable) override
2020 if (!m_client.setIsResizable)
2022 m_client.setIsResizable(toAPI(page), resizable, m_client.base.clientInfo);
2025 void setWindowFrame(WebPageProxy* page, const FloatRect& frame) override
2027 if (!m_client.setWindowFrame)
2030 m_client.setWindowFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
2033 FloatRect windowFrame(WebPageProxy* page) override
2035 if (!m_client.getWindowFrame)
2038 return toFloatRect(m_client.getWindowFrame(toAPI(page), m_client.base.clientInfo));
2041 bool canRunBeforeUnloadConfirmPanel() const override
2043 return m_client.runBeforeUnloadConfirmPanel_deprecatedForUseWithV6 || m_client.runBeforeUnloadConfirmPanel;
2046 void runBeforeUnloadConfirmPanel(WebKit::WebPageProxy* page, const WTF::String& message, WebKit::WebFrameProxy* frame, Function<void (bool)>&& completionHandler) override
2048 if (m_client.runBeforeUnloadConfirmPanel) {
2049 RefPtr<RunBeforeUnloadConfirmPanelResultListener> listener = RunBeforeUnloadConfirmPanelResultListener::create(WTFMove(completionHandler));
2050 m_client.runBeforeUnloadConfirmPanel(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(listener.get()), m_client.base.clientInfo);
2054 if (m_client.runBeforeUnloadConfirmPanel_deprecatedForUseWithV6) {
2055 bool result = m_client.runBeforeUnloadConfirmPanel_deprecatedForUseWithV6(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
2056 completionHandler(result);
2060 completionHandler(true);
2063 void pageDidScroll(WebPageProxy* page) override
2065 if (!m_client.pageDidScroll)
2068 m_client.pageDidScroll(toAPI(page), m_client.base.clientInfo);
2071 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, Function<void (unsigned long long)>&& completionHandler) override
2073 if (!m_client.exceededDatabaseQuota) {
2074 completionHandler(currentQuota);
2078 completionHandler(m_client.exceededDatabaseQuota(toAPI(page), toAPI(frame), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, m_client.base.clientInfo));
2081 bool runOpenPanel(WebPageProxy* page, WebFrameProxy* frame, const WebCore::SecurityOriginData&, API::OpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener) override
2083 if (!m_client.runOpenPanel)
2086 m_client.runOpenPanel(toAPI(page), toAPI(frame), toAPI(parameters), toAPI(listener), m_client.base.clientInfo);
2090 bool decidePolicyForGeolocationPermissionRequest(WebPageProxy* page, WebFrameProxy* frame, API::SecurityOrigin* origin, GeolocationPermissionRequestProxy* permissionRequest) override
2092 if (!m_client.decidePolicyForGeolocationPermissionRequest)
2095 m_client.decidePolicyForGeolocationPermissionRequest(toAPI(page), toAPI(frame), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
2099 bool decidePolicyForUserMediaPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& userMediaDocumentOrigin, API::SecurityOrigin& topLevelDocumentOrigin, UserMediaPermissionRequestProxy& permissionRequest) override
2101 if (!m_client.decidePolicyForUserMediaPermissionRequest)
2104 m_client.decidePolicyForUserMediaPermissionRequest(toAPI(&page), toAPI(&frame), toAPI(&userMediaDocumentOrigin), toAPI(&topLevelDocumentOrigin), toAPI(&permissionRequest), m_client.base.clientInfo);
2108 bool checkUserMediaPermissionForOrigin(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& userMediaDocumentOrigin, API::SecurityOrigin& topLevelDocumentOrigin, UserMediaPermissionCheckProxy& request) override
2110 if (!m_client.checkUserMediaPermissionForOrigin)
2113 m_client.checkUserMediaPermissionForOrigin(toAPI(&page), toAPI(&frame), toAPI(&userMediaDocumentOrigin), toAPI(&topLevelDocumentOrigin), toAPI(&request), m_client.base.clientInfo);
2117 bool decidePolicyForNotificationPermissionRequest(WebPageProxy* page, API::SecurityOrigin* origin, NotificationPermissionRequest* permissionRequest) override
2119 if (!m_client.decidePolicyForNotificationPermissionRequest)
2122 m_client.decidePolicyForNotificationPermissionRequest(toAPI(page), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
2127 float headerHeight(WebPageProxy* page, WebFrameProxy* frame) override
2129 if (!m_client.headerHeight)
2132 return m_client.headerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
2135 float footerHeight(WebPageProxy* page, WebFrameProxy* frame) override
2137 if (!m_client.footerHeight)
2140 return m_client.footerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
2143 void drawHeader(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
2145 if (!m_client.drawHeader)
2148 m_client.drawHeader(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
2151 void drawFooter(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
2153 if (!m_client.drawFooter)
2156 m_client.drawFooter(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
2159 void printFrame(WebPageProxy* page, WebFrameProxy* frame) override
2161 if (!m_client.printFrame)
2164 m_client.printFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
2167 bool canRunModal() const override
2169 return m_client.runModal;
2172 void runModal(WebPageProxy* page) override
2174 if (!m_client.runModal)
2177 m_client.runModal(toAPI(page), m_client.base.clientInfo);
2180 void saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data) override
2182 if (!m_client.saveDataToFileInDownloadsFolder)
2185 m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURLString.impl()), toAPI(data), m_client.base.clientInfo);
2188 void pinnedStateDidChange(WebPageProxy& page) override
2190 if (!m_client.pinnedStateDidChange)
2193 m_client.pinnedStateDidChange(toAPI(&page), m_client.base.clientInfo);
2196 void isPlayingAudioDidChange(WebPageProxy& page) override
2198 if (!m_client.isPlayingAudioDidChange)
2201 m_client.isPlayingAudioDidChange(toAPI(&page), m_client.base.clientInfo);
2204 void didClickAutoFillButton(WebPageProxy& page, API::Object* userInfo) override
2206 if (!m_client.didClickAutoFillButton)
2209 m_client.didClickAutoFillButton(toAPI(&page), toAPI(userInfo), m_client.base.clientInfo);
2212 #if ENABLE(MEDIA_SESSION)
2213 void mediaSessionMetadataDidChange(WebPageProxy& page, WebMediaSessionMetadata* metadata) override
2215 if (!m_client.mediaSessionMetadataDidChange)
2218 m_client.mediaSessionMetadataDidChange(toAPI(&page), toAPI(metadata), m_client.base.clientInfo);
2223 toImpl(pageRef)->setUIClient(std::make_unique<UIClient>(wkClient));
2226 void WKPageSetPageNavigationClient(WKPageRef pageRef, const WKPageNavigationClientBase* wkClient)
2228 class NavigationClient : public API::Client<WKPageNavigationClientBase>, public API::NavigationClient {
2230 explicit NavigationClient(const WKPageNavigationClientBase* client)
2236 void decidePolicyForNavigationAction(WebPageProxy& page, API::NavigationAction& navigationAction, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
2238 if (!m_client.decidePolicyForNavigationAction)
2240 m_client.decidePolicyForNavigationAction(toAPI(&page), toAPI(&navigationAction), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
2243 void decidePolicyForNavigationResponse(WebPageProxy& page, API::NavigationResponse& navigationResponse, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
2245 if (!m_client.decidePolicyForNavigationResponse)
2247 m_client.decidePolicyForNavigationResponse(toAPI(&page), toAPI(&navigationResponse), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
2250 void didStartProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
2252 if (!m_client.didStartProvisionalNavigation)
2254 m_client.didStartProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
2257 void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
2259 if (!m_client.didReceiveServerRedirectForProvisionalNavigation)
2261 m_client.didReceiveServerRedirectForProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
2264 void didFailProvisionalNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
2266 if (!m_client.didFailProvisionalNavigation)
2268 m_client.didFailProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
2271 void didCommitNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
2273 if (!m_client.didCommitNavigation)
2275 m_client.didCommitNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
2278 void didFinishNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
2280 if (!m_client.didFinishNavigation)
2282 m_client.didFinishNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
2285 void didFailNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
2287 if (!m_client.didFailNavigation)
2289 m_client.didFailNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
2292 void didFailProvisionalLoadInSubframeWithError(WebPageProxy& page, WebFrameProxy& subframe, const WebCore::SecurityOriginData& securityOriginData, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
2294 if (!m_client.didFailProvisionalLoadInSubframe)
2296 m_client.didFailProvisionalLoadInSubframe(toAPI(&page), toAPI(navigation), toAPI(API::FrameInfo::create(subframe, securityOriginData.securityOrigin()).ptr()), toAPI(error), toAPI(userData), m_client.base.clientInfo);
2299 void didFinishDocumentLoad(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
2301 if (!m_client.didFinishDocumentLoad)
2303 m_client.didFinishDocumentLoad(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
2306 void didSameDocumentNavigation(WebPageProxy& page, API::Navigation* navigation, WebKit::SameDocumentNavigationType navigationType, API::Object* userData) override
2308 if (!m_client.didSameDocumentNavigation)
2310 m_client.didSameDocumentNavigation(toAPI(&page), toAPI(navigation), toAPI(navigationType), toAPI(userData), m_client.base.clientInfo);
2313 void renderingProgressDidChange(WebPageProxy& page, WebCore::LayoutMilestones milestones) override
2315 if (!m_client.renderingProgressDidChange)
2317 m_client.renderingProgressDidChange(toAPI(&page), pageRenderingProgressEvents(milestones), nullptr, m_client.base.clientInfo);
2320 bool canAuthenticateAgainstProtectionSpace(WebPageProxy& page, WebProtectionSpace* protectionSpace) override
2322 if (!m_client.canAuthenticateAgainstProtectionSpace)
2324 return m_client.canAuthenticateAgainstProtectionSpace(toAPI(&page), toAPI(protectionSpace), m_client.base.clientInfo);
2327 void didReceiveAuthenticationChallenge(WebPageProxy& page, AuthenticationChallengeProxy* authenticationChallenge) override
2329 if (!m_client.didReceiveAuthenticationChallenge)
2331 m_client.didReceiveAuthenticationChallenge(toAPI(&page), toAPI(authenticationChallenge), m_client.base.clientInfo);
2334 void processDidCrash(WebPageProxy& page) override
2336 if (!m_client.webProcessDidCrash)
2338 m_client.webProcessDidCrash(toAPI(&page), m_client.base.clientInfo);
2341 RefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
2343 if (m_client.copyWebCryptoMasterKey)
2344 return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(&page), m_client.base.clientInfo)));
2346 Vector<uint8_t> masterKey;
2347 #if ENABLE(SUBTLE_CRYPTO)
2348 if (!getDefaultWebCryptoMasterKey(masterKey))
2352 return API::Data::create(masterKey.data(), masterKey.size());
2355 void didBeginNavigationGesture(WebPageProxy& page) override
2357 if (!m_client.didBeginNavigationGesture)
2359 m_client.didBeginNavigationGesture(toAPI(&page), m_client.base.clientInfo);
2362 void didEndNavigationGesture(WebPageProxy& page, bool willNavigate, WebKit::WebBackForwardListItem& item) override
2364 if (!m_client.didEndNavigationGesture)
2366 m_client.didEndNavigationGesture(toAPI(&page), willNavigate ? toAPI(&item) : nullptr, m_client.base.clientInfo);
2369 void willEndNavigationGesture(WebPageProxy& page, bool willNavigate, WebKit::WebBackForwardListItem& item) override
2371 if (!m_client.willEndNavigationGesture)
2373 m_client.willEndNavigationGesture(toAPI(&page), willNavigate ? toAPI(&item) : nullptr, m_client.base.clientInfo);
2376 void didRemoveNavigationGestureSnapshot(WebPageProxy& page) override
2378 if (!m_client.didRemoveNavigationGestureSnapshot)
2380 m_client.didRemoveNavigationGestureSnapshot(toAPI(&page), m_client.base.clientInfo);
2383 #if ENABLE(NETSCAPE_PLUGIN_API)
2384 PluginModuleLoadPolicy decidePolicyForPluginLoad(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
2386 WKStringRef unavailabilityDescriptionOut = 0;
2387 PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
2389 if (m_client.decidePolicyForPluginLoad)
2390 loadPolicy = toPluginModuleLoadPolicy(m_client.decidePolicyForPluginLoad(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
2392 if (unavailabilityDescriptionOut) {
2393 RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
2394 unavailabilityDescription = webUnavailabilityDescription->string();
2402 WebPageProxy* webPageProxy = toImpl(pageRef);
2404 auto navigationClient = std::make_unique<NavigationClient>(wkClient);
2405 webPageProxy->setNavigationClient(WTFMove(navigationClient));
2408 void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback)
2410 toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), [context, callback](API::SerializedScriptValue* returnValue, bool, const WebCore::ExceptionDetails&, CallbackBase::Error error) {
2411 callback(toAPI(returnValue), (error != CallbackBase::Error::None) ? toAPI(API::Error::create().ptr()) : 0, context);
2416 static void callRunJavaScriptBlockAndRelease(WKSerializedScriptValueRef resultValue, WKErrorRef error, void* context)
2418 WKPageRunJavaScriptBlock block = (WKPageRunJavaScriptBlock)context;
2419 block(resultValue, error);
2420 Block_release(block);
2423 void WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef, WKStringRef scriptRef, WKPageRunJavaScriptBlock block)
2425 WKPageRunJavaScriptInMainFrame(pageRef, scriptRef, Block_copy(block), callRunJavaScriptBlockAndRelease);
2429 static std::function<void (const String&, WebKit::CallbackBase::Error)> toGenericCallbackFunction(void* context, void (*callback)(WKStringRef, WKErrorRef, void*))
2431 return [context, callback](const String& returnValue, WebKit::CallbackBase::Error error) {
2432 callback(toAPI(API::String::create(returnValue).ptr()), error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
2436 void WKPageRenderTreeExternalRepresentation(WKPageRef pageRef, void* context, WKPageRenderTreeExternalRepresentationFunction callback)
2438 toImpl(pageRef)->getRenderTreeExternalRepresentation(toGenericCallbackFunction(context, callback));
2441 void WKPageGetSourceForFrame(WKPageRef pageRef, WKFrameRef frameRef, void* context, WKPageGetSourceForFrameFunction callback)
2443 toImpl(pageRef)->getSourceForFrame(toImpl(frameRef), toGenericCallbackFunction(context, callback));
2446 void WKPageGetContentsAsString(WKPageRef pageRef, void* context, WKPageGetContentsAsStringFunction callback)
2448 toImpl(pageRef)->getContentsAsString(toGenericCallbackFunction(context, callback));
2451 void WKPageGetBytecodeProfile(WKPageRef pageRef, void* context, WKPageGetBytecodeProfileFunction callback)
2453 toImpl(pageRef)->getBytecodeProfile(toGenericCallbackFunction(context, callback));
2456 void WKPageGetSamplingProfilerOutput(WKPageRef pageRef, void* context, WKPageGetSamplingProfilerOutputFunction callback)
2458 toImpl(pageRef)->getSamplingProfilerOutput(toGenericCallbackFunction(context, callback));
2461 void WKPageIsWebProcessResponsive(WKPageRef pageRef, void* context, WKPageIsWebProcessResponsiveFunction callback)
2463 toImpl(pageRef)->isWebProcessResponsive([context, callback](bool isWebProcessResponsive) {
2464 callback(isWebProcessResponsive, context);
2468 void WKPageGetSelectionAsWebArchiveData(WKPageRef pageRef, void* context, WKPageGetSelectionAsWebArchiveDataFunction callback)
2470 toImpl(pageRef)->getSelectionAsWebArchiveData(toGenericCallbackFunction(context, callback));
2473 void WKPageGetContentsAsMHTMLData(WKPageRef pageRef, void* context, WKPageGetContentsAsMHTMLDataFunction callback)
2476 toImpl(pageRef)->getContentsAsMHTMLData(toGenericCallbackFunction(context, callback));
2478 UNUSED_PARAM(pageRef);
2479 UNUSED_PARAM(context);
2480 UNUSED_PARAM(callback);
2484 void WKPageForceRepaint(WKPageRef pageRef, void* context, WKPageForceRepaintFunction callback)
2486 toImpl(pageRef)->forceRepaint(VoidCallback::create([context, callback](WebKit::CallbackBase::Error error) {
2487 callback(error == WebKit::CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().ptr()), context);
2491 WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef pageRef)
2493 const String& pendingAPIRequestURL = toImpl(pageRef)->pageLoadState().pendingAPIRequestURL();
2495 if (pendingAPIRequestURL.isNull())
2498 return toCopiedURLAPI(pendingAPIRequestURL);
2501 WKURLRef WKPageCopyActiveURL(WKPageRef pageRef)
2503 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().activeURL());
2506 WKURLRef WKPageCopyProvisionalURL(WKPageRef pageRef)
2508 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().provisionalURL());
2511 WKURLRef WKPageCopyCommittedURL(WKPageRef pageRef)
2513 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().url());
2516 WKStringRef WKPageCopyStandardUserAgentWithApplicationName(WKStringRef applicationName)
2518 return toCopiedAPI(WebPageProxy::standardUserAgent(toImpl(applicationName)->string()));
2521 void WKPageValidateCommand(WKPageRef pageRef, WKStringRef command, void* context, WKPageValidateCommandCallback callback)
2523 toImpl(pageRef)->validateCommand(toImpl(command)->string(), [context, callback](const String& commandName, bool isEnabled, int32_t state, WebKit::CallbackBase::Error error) {
2524 callback(toAPI(API::String::create(commandName).ptr()), isEnabled, state, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
2528 void WKPageExecuteCommand(WKPageRef pageRef, WKStringRef command)
2530 toImpl(pageRef)->executeEditCommand(toImpl(command)->string());
2534 static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo)
2537 result.pageSetupScaleFactor = printInfo.pageSetupScaleFactor;
2538 result.availablePaperWidth = printInfo.availablePaperWidth;
2539 result.availablePaperHeight = printInfo.availablePaperHeight;
2543 void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, WKPageComputePagesForPrintingFunction callback, void* context)
2545 toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create([context, callback](const Vector<WebCore::IntRect>& rects, double scaleFactor, WebKit::CallbackBase::Error error) {
2546 Vector<WKRect> wkRects(rects.size());
2547 for (size_t i = 0; i < rects.size(); ++i)
2548 wkRects[i] = toAPI(rects[i]);
2549 callback(wkRects.data(), wkRects.size(), scaleFactor, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
2553 void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo)
2555 toImpl(page)->beginPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo));
2558 void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
2560 toImpl(page)->drawPagesToPDF(toImpl(frame), printInfoFromWKPrintInfo(printInfo), first, count, DataCallback::create(toGenericCallbackFunction(context, callback)));
2563 void WKPageEndPrinting(WKPageRef page)
2565 toImpl(page)->endPrinting();
2569 bool WKPageGetIsControlledByAutomation(WKPageRef page)
2571 return toImpl(page)->isControlledByAutomation();
2574 void WKPageSetControlledByAutomation(WKPageRef page, bool controlled)
2576 toImpl(page)->setControlledByAutomation(controlled);
2579 bool WKPageGetAllowsRemoteInspection(WKPageRef page)
2581 #if ENABLE(REMOTE_INSPECTOR)
2582 return toImpl(page)->allowsRemoteInspection();
2589 void WKPageSetAllowsRemoteInspection(WKPageRef page, bool allow)
2591 #if ENABLE(REMOTE_INSPECTOR)
2592 toImpl(page)->setAllowsRemoteInspection(allow);
2595 UNUSED_PARAM(allow);
2599 void WKPageSetMediaVolume(WKPageRef page, float volume)
2601 toImpl(page)->setMediaVolume(volume);
2604 void WKPageSetMuted(WKPageRef page, WKMediaMutedState muted)
2606 toImpl(page)->setMuted(muted);
2609 bool WKPageHasMediaSessionWithActiveMediaElements(WKPageRef page)
2611 #if ENABLE(MEDIA_SESSION)
2612 return toImpl(page)->hasMediaSessionWithActiveMediaElements();
2619 void WKPageHandleMediaEvent(WKPageRef page, WKMediaEventType wkEventType)
2621 #if ENABLE(MEDIA_SESSION)
2622 MediaEventType eventType;
2624 switch (wkEventType) {
2625 case kWKMediaEventTypePlayPause:
2626 eventType = MediaEventType::PlayPause;
2628 case kWKMediaEventTypeTrackNext:
2629 eventType = MediaEventType::TrackNext;
2631 case kWKMediaEventTypeTrackPrevious:
2632 eventType = MediaEventType::TrackPrevious;
2635 ASSERT_NOT_REACHED();
2639 toImpl(page)->handleMediaEvent(eventType);
2642 UNUSED_PARAM(wkEventType);
2646 void WKPagePostMessageToInjectedBundle(WKPageRef pageRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef)
2648 toImpl(pageRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef));
2651 WKArrayRef WKPageCopyRelatedPages(WKPageRef pageRef)
2653 Vector<RefPtr<API::Object>> relatedPages;
2655 for (auto& page : toImpl(pageRef)->process().pages()) {
2656 if (page != toImpl(pageRef))
2657 relatedPages.append(page);
2660 return toAPI(&API::Array::create(WTFMove(relatedPages)).leakRef());
2663 WKFrameRef WKPageLookUpFrameFromHandle(WKPageRef pageRef, WKFrameHandleRef handleRef)
2665 auto page = toImpl(pageRef);
2666 auto frame = page->process().webFrame(toImpl(handleRef)->frameID());
2667 if (!frame || frame->page() != page)
2670 return toAPI(frame);
2673 void WKPageSetMayStartMediaWhenInWindow(WKPageRef pageRef, bool mayStartMedia)
2675 toImpl(pageRef)->setMayStartMediaWhenInWindow(mayStartMedia);
2679 void WKPageSelectContextMenuItem(WKPageRef page, WKContextMenuItemRef item)
2681 #if ENABLE(CONTEXT_MENUS)
2682 toImpl(page)->contextMenuItemSelected((toImpl(item)->data()));
2689 WKScrollPinningBehavior WKPageGetScrollPinningBehavior(WKPageRef page)
2691 ScrollPinningBehavior pinning = toImpl(page)->scrollPinningBehavior();
2694 case WebCore::ScrollPinningBehavior::DoNotPin:
2695 return kWKScrollPinningBehaviorDoNotPin;
2696 case WebCore::ScrollPinningBehavior::PinToTop:
2697 return kWKScrollPinningBehaviorPinToTop;
2698 case WebCore::ScrollPinningBehavior::PinToBottom:
2699 return kWKScrollPinningBehaviorPinToBottom;
2702 ASSERT_NOT_REACHED();
2703 return kWKScrollPinningBehaviorDoNotPin;
2706 void WKPageSetScrollPinningBehavior(WKPageRef page, WKScrollPinningBehavior pinning)
2708 ScrollPinningBehavior corePinning = ScrollPinningBehavior::DoNotPin;
2711 case kWKScrollPinningBehaviorDoNotPin:
2712 corePinning = ScrollPinningBehavior::DoNotPin;
2714 case kWKScrollPinningBehaviorPinToTop:
2715 corePinning = ScrollPinningBehavior::PinToTop;
2717 case kWKScrollPinningBehaviorPinToBottom:
2718 corePinning = ScrollPinningBehavior::PinToBottom;
2721 ASSERT_NOT_REACHED();
2724 toImpl(page)->setScrollPinningBehavior(corePinning);
2727 bool WKPageGetAddsVisitedLinks(WKPageRef page)
2729 return toImpl(page)->addsVisitedLinks();
2732 void WKPageSetAddsVisitedLinks(WKPageRef page, bool addsVisitedLinks)
2734 toImpl(page)->setAddsVisitedLinks(addsVisitedLinks);
2737 bool WKPageIsPlayingAudio(WKPageRef page)
2739 return toImpl(page)->isPlayingAudio();
2742 WKMediaState WKPageGetMediaState(WKPageRef page)
2744 WebCore::MediaProducer::MediaStateFlags coreState = toImpl(page)->mediaStateFlags();
2745 WKMediaState state = kWKMediaIsNotPlaying;
2747 if (coreState & WebCore::MediaProducer::IsPlayingAudio)
2748 state |= kWKMediaIsPlayingAudio;
2749 if (coreState & WebCore::MediaProducer::IsPlayingVideo)
2750 state |= kWKMediaIsPlayingVideo;
2751 if (coreState & WebCore::MediaProducer::HasMediaCaptureDevice)
2752 state |= kWKMediaHasCaptureDevice;
2753 if (coreState & WebCore::MediaProducer::HasActiveMediaCaptureDevice)
2754 state |= kWKMediaHasActiveCaptureDevice;
2759 void WKPageClearWheelEventTestTrigger(WKPageRef pageRef)
2761 toImpl(pageRef)->clearWheelEventTestTrigger();
2764 void WKPageCallAfterNextPresentationUpdate(WKPageRef pageRef, void* context, WKPagePostPresentationUpdateFunction callback)
2766 toImpl(pageRef)->callAfterNextPresentationUpdate([context, callback](WebKit::CallbackBase::Error error) {
2767 callback(error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
2771 bool WKPageGetResourceCachingDisabled(WKPageRef page)
2773 return toImpl(page)->isResourceCachingDisabled();
2776 void WKPageSetResourceCachingDisabled(WKPageRef page, bool disabled)
2778 toImpl(page)->setResourceCachingDisabled(disabled);
2781 void WKPageSetIgnoresViewportScaleLimits(WKPageRef page, bool ignoresViewportScaleLimits)
2784 toImpl(page)->setForceAlwaysUserScalable(ignoresViewportScaleLimits);
2788 pid_t WKPageGetProcessIdentifier(WKPageRef page)
2790 return toImpl(page)->processIdentifier();
2793 #if ENABLE(NETSCAPE_PLUGIN_API)
2797 WKStringRef WKPageGetPluginInformationBundleIdentifierKey()
2799 return WKPluginInformationBundleIdentifierKey();
2802 WKStringRef WKPageGetPluginInformationBundleVersionKey()
2804 return WKPluginInformationBundleVersionKey();
2807 WKStringRef WKPageGetPluginInformationDisplayNameKey()
2809 return WKPluginInformationDisplayNameKey();
2812 WKStringRef WKPageGetPluginInformationFrameURLKey()
2814 return WKPluginInformationFrameURLKey();
2817 WKStringRef WKPageGetPluginInformationMIMETypeKey()
2819 return WKPluginInformationMIMETypeKey();
2822 WKStringRef WKPageGetPluginInformationPageURLKey()
2824 return WKPluginInformationPageURLKey();
2827 WKStringRef WKPageGetPluginInformationPluginspageAttributeURLKey()
2829 return WKPluginInformationPluginspageAttributeURLKey();
2832 WKStringRef WKPageGetPluginInformationPluginURLKey()
2834 return WKPluginInformationPluginURLKey();
2839 #endif // ENABLE(NETSCAPE_PLUGIN_API)