2 * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #include "WKPagePrivate.h"
31 #include "APIContextMenuClient.h"
33 #include "APIDictionary.h"
34 #include "APIFindClient.h"
35 #include "APIFrameInfo.h"
36 #include "APILoaderClient.h"
37 #include "APINavigationAction.h"
38 #include "APINavigationClient.h"
39 #include "APINavigationResponse.h"
40 #include "APIPolicyClient.h"
41 #include "APISessionState.h"
42 #include "APIUIClient.h"
43 #include "AuthenticationChallengeProxy.h"
44 #include "LegacySessionStateCoding.h"
46 #include "NativeWebKeyboardEvent.h"
47 #include "NativeWebWheelEvent.h"
48 #include "NavigationActionData.h"
49 #include "PluginInformation.h"
50 #include "PrintInfo.h"
51 #include "WKAPICast.h"
52 #include "WKPagePolicyClientInternal.h"
53 #include "WKPageRenderingProgressEventsInternal.h"
54 #include "WKPluginInformation.h"
55 #include "WebBackForwardList.h"
56 #include "WebFormClient.h"
57 #include "WebInspectorProxy.h"
58 #include "WebOpenPanelParameters.h"
59 #include "WebOpenPanelResultListenerProxy.h"
60 #include "WebPageGroup.h"
61 #include "WebPageMessages.h"
62 #include "WebPageProxy.h"
63 #include "WebProcessPool.h"
64 #include "WebProcessProxy.h"
65 #include "WebProtectionSpace.h"
66 #include <WebCore/Page.h>
67 #include <WebCore/WindowFeatures.h>
73 #if ENABLE(CONTEXT_MENUS)
74 #include "WebContextMenuItem.h"
78 #include "WebVibrationProxy.h"
81 #if ENABLE(MEDIA_SESSION)
82 #include <WebCore/MediaEventTypes.h>
85 using namespace WebCore;
86 using namespace WebKit;
89 template<> struct ClientTraits<WKPageLoaderClientBase> {
90 typedef std::tuple<WKPageLoaderClientV0, WKPageLoaderClientV1, WKPageLoaderClientV2, WKPageLoaderClientV3, WKPageLoaderClientV4, WKPageLoaderClientV5, WKPageLoaderClientV6> Versions;
93 template<> struct ClientTraits<WKPageNavigationClientBase> {
94 typedef std::tuple<WKPageNavigationClientV0> Versions;
97 template<> struct ClientTraits<WKPagePolicyClientBase> {
98 typedef std::tuple<WKPagePolicyClientV0, WKPagePolicyClientV1, WKPagePolicyClientInternal> Versions;
101 template<> struct ClientTraits<WKPageUIClientBase> {
102 typedef std::tuple<WKPageUIClientV0, WKPageUIClientV1, WKPageUIClientV2, WKPageUIClientV3, WKPageUIClientV4, WKPageUIClientV5> Versions;
105 #if ENABLE(CONTEXT_MENUS)
106 template<> struct ClientTraits<WKPageContextMenuClientBase> {
107 typedef std::tuple<WKPageContextMenuClientV0, WKPageContextMenuClientV1, WKPageContextMenuClientV2, WKPageContextMenuClientV3> Versions;
113 WKTypeID WKPageGetTypeID()
115 return toAPI(WebPageProxy::APIType);
118 WKContextRef WKPageGetContext(WKPageRef pageRef)
120 return toAPI(&toImpl(pageRef)->process().processPool());
123 WKPageGroupRef WKPageGetPageGroup(WKPageRef pageRef)
125 return toAPI(&toImpl(pageRef)->pageGroup());
128 void WKPageLoadURL(WKPageRef pageRef, WKURLRef URLRef)
130 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)));
133 void WKPageLoadURLWithShouldOpenExternalURLsPolicy(WKPageRef pageRef, WKURLRef URLRef, bool shouldOpenExternalURLs)
135 ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLs ? ShouldOpenExternalURLsPolicy::ShouldAllow : ShouldOpenExternalURLsPolicy::ShouldNotAllow;
136 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), shouldOpenExternalURLsPolicy);
139 void WKPageLoadURLWithUserData(WKPageRef pageRef, WKURLRef URLRef, WKTypeRef userDataRef)
141 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef));
144 void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef)
146 toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest());
149 void WKPageLoadURLRequestWithUserData(WKPageRef pageRef, WKURLRequestRef urlRequestRef, WKTypeRef userDataRef)
151 toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest(), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef));
154 void WKPageLoadFile(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL)
156 toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL));
159 void WKPageLoadFileWithUserData(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL, WKTypeRef userDataRef)
161 toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL), toImpl(userDataRef));
164 void WKPageLoadData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef)
166 toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef));
169 void WKPageLoadDataWithUserData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
171 toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef), toImpl(userDataRef));
174 void WKPageLoadHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef)
176 toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef));
179 void WKPageLoadHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
181 toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toImpl(userDataRef));
184 void WKPageLoadAlternateHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef)
186 toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef));
189 void WKPageLoadAlternateHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef, WKTypeRef userDataRef)
191 toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef), toImpl(userDataRef));
194 void WKPageLoadPlainTextString(WKPageRef pageRef, WKStringRef plainTextStringRef)
196 toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef));
199 void WKPageLoadPlainTextStringWithUserData(WKPageRef pageRef, WKStringRef plainTextStringRef, WKTypeRef userDataRef)
201 toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef), toImpl(userDataRef));
204 void WKPageLoadWebArchiveData(WKPageRef pageRef, WKDataRef webArchiveDataRef)
206 toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef));
209 void WKPageLoadWebArchiveDataWithUserData(WKPageRef pageRef, WKDataRef webArchiveDataRef, WKTypeRef userDataRef)
211 toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef), toImpl(userDataRef));
214 void WKPageStopLoading(WKPageRef pageRef)
216 toImpl(pageRef)->stopLoading();
219 void WKPageReload(WKPageRef pageRef)
221 toImpl(pageRef)->reload(false);
224 void WKPageReloadFromOrigin(WKPageRef pageRef)
226 toImpl(pageRef)->reload(true);
229 bool WKPageTryClose(WKPageRef pageRef)
231 return toImpl(pageRef)->tryClose();
234 void WKPageClose(WKPageRef pageRef)
236 toImpl(pageRef)->close();
239 bool WKPageIsClosed(WKPageRef pageRef)
241 return toImpl(pageRef)->isClosed();
244 void WKPageGoForward(WKPageRef pageRef)
246 toImpl(pageRef)->goForward();
249 bool WKPageCanGoForward(WKPageRef pageRef)
251 return toImpl(pageRef)->backForwardList().forwardItem();
254 void WKPageGoBack(WKPageRef pageRef)
256 toImpl(pageRef)->goBack();
259 bool WKPageCanGoBack(WKPageRef pageRef)
261 return toImpl(pageRef)->backForwardList().backItem();
264 void WKPageGoToBackForwardListItem(WKPageRef pageRef, WKBackForwardListItemRef itemRef)
266 toImpl(pageRef)->goToBackForwardItem(toImpl(itemRef));
269 void WKPageTryRestoreScrollPosition(WKPageRef pageRef)
271 toImpl(pageRef)->tryRestoreScrollPosition();
274 WKBackForwardListRef WKPageGetBackForwardList(WKPageRef pageRef)
276 return toAPI(&toImpl(pageRef)->backForwardList());
279 bool WKPageWillHandleHorizontalScrollEvents(WKPageRef pageRef)
281 return toImpl(pageRef)->willHandleHorizontalScrollEvents();
284 WKStringRef WKPageCopyTitle(WKPageRef pageRef)
286 return toCopiedAPI(toImpl(pageRef)->pageLoadState().title());
289 WKFrameRef WKPageGetMainFrame(WKPageRef pageRef)
291 return toAPI(toImpl(pageRef)->mainFrame());
294 WKFrameRef WKPageGetFocusedFrame(WKPageRef pageRef)
296 return toAPI(toImpl(pageRef)->focusedFrame());
299 WKFrameRef WKPageGetFrameSetLargestFrame(WKPageRef pageRef)
301 return toAPI(toImpl(pageRef)->frameSetLargestFrame());
304 uint64_t WKPageGetRenderTreeSize(WKPageRef page)
306 return toImpl(page)->renderTreeSize();
309 WKInspectorRef WKPageGetInspector(WKPageRef pageRef)
311 return toAPI(toImpl(pageRef)->inspector());
314 WKVibrationRef WKPageGetVibration(WKPageRef page)
316 #if ENABLE(VIBRATION)
317 return toAPI(toImpl(page)->vibration());
324 double WKPageGetEstimatedProgress(WKPageRef pageRef)
326 return toImpl(pageRef)->estimatedProgress();
329 WKStringRef WKPageCopyUserAgent(WKPageRef pageRef)
331 return toCopiedAPI(toImpl(pageRef)->userAgent());
334 WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef pageRef)
336 return toCopiedAPI(toImpl(pageRef)->applicationNameForUserAgent());
339 void WKPageSetApplicationNameForUserAgent(WKPageRef pageRef, WKStringRef applicationNameRef)
341 toImpl(pageRef)->setApplicationNameForUserAgent(toWTFString(applicationNameRef));
344 WKStringRef WKPageCopyCustomUserAgent(WKPageRef pageRef)
346 return toCopiedAPI(toImpl(pageRef)->customUserAgent());
349 void WKPageSetCustomUserAgent(WKPageRef pageRef, WKStringRef userAgentRef)
351 toImpl(pageRef)->setCustomUserAgent(toWTFString(userAgentRef));
354 bool WKPageSupportsTextEncoding(WKPageRef pageRef)
356 return toImpl(pageRef)->supportsTextEncoding();
359 WKStringRef WKPageCopyCustomTextEncodingName(WKPageRef pageRef)
361 return toCopiedAPI(toImpl(pageRef)->customTextEncodingName());
364 void WKPageSetCustomTextEncodingName(WKPageRef pageRef, WKStringRef encodingNameRef)
366 toImpl(pageRef)->setCustomTextEncodingName(toWTFString(encodingNameRef));
369 void WKPageTerminate(WKPageRef pageRef)
371 toImpl(pageRef)->terminateProcess();
374 WKStringRef WKPageGetSessionHistoryURLValueType()
376 static API::String& sessionHistoryURLValueType = API::String::create("SessionHistoryURL").leakRef();
377 return toAPI(&sessionHistoryURLValueType);
380 WKStringRef WKPageGetSessionBackForwardListItemValueType()
382 static API::String& sessionBackForwardListValueType = API::String::create("SessionBackForwardListItem").leakRef();
383 return toAPI(&sessionBackForwardListValueType);
386 WKTypeRef WKPageCopySessionState(WKPageRef pageRef, void* context, WKPageSessionStateFilterCallback filter)
388 // FIXME: This is a hack to make sure we return a WKDataRef to maintain compatibility with older versions of Safari.
389 bool shouldReturnData = !(reinterpret_cast<uintptr_t>(context) & 1);
390 context = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(context) & ~1);
392 auto sessionState = toImpl(pageRef)->sessionState([pageRef, context, filter](WebBackForwardListItem& item) {
394 if (!filter(pageRef, WKPageGetSessionBackForwardListItemValueType(), toAPI(&item), context))
397 if (!filter(pageRef, WKPageGetSessionHistoryURLValueType(), toURLRef(item.originalURL().impl()), context))
404 if (shouldReturnData)
405 return toAPI(encodeLegacySessionState(sessionState).release().leakRef());
407 return toAPI(API::SessionState::create(WTF::move(sessionState)).leakRef());
410 void WKPageRestoreFromSessionState(WKPageRef pageRef, WKTypeRef sessionStateRef)
412 SessionState sessionState;
414 // FIXME: This is for backwards compatibility with Safari. Remove it once Safari no longer depends on it.
415 if (toImpl(sessionStateRef)->type() == API::Object::Type::Data) {
416 if (!decodeLegacySessionState(toImpl(static_cast<WKDataRef>(sessionStateRef))->bytes(), toImpl(static_cast<WKDataRef>(sessionStateRef))->size(), sessionState))
419 ASSERT(toImpl(sessionStateRef)->type() == API::Object::Type::SessionState);
421 sessionState = toImpl(static_cast<WKSessionStateRef>(sessionStateRef))->sessionState();
424 toImpl(pageRef)->restoreFromSessionState(WTF::move(sessionState), true);
427 double WKPageGetTextZoomFactor(WKPageRef pageRef)
429 return toImpl(pageRef)->textZoomFactor();
432 double WKPageGetBackingScaleFactor(WKPageRef pageRef)
434 return toImpl(pageRef)->deviceScaleFactor();
437 void WKPageSetCustomBackingScaleFactor(WKPageRef pageRef, double customScaleFactor)
439 toImpl(pageRef)->setCustomDeviceScaleFactor(customScaleFactor);
442 bool WKPageSupportsTextZoom(WKPageRef pageRef)
444 return toImpl(pageRef)->supportsTextZoom();
447 void WKPageSetTextZoomFactor(WKPageRef pageRef, double zoomFactor)
449 toImpl(pageRef)->setTextZoomFactor(zoomFactor);
452 double WKPageGetPageZoomFactor(WKPageRef pageRef)
454 return toImpl(pageRef)->pageZoomFactor();
457 void WKPageSetPageZoomFactor(WKPageRef pageRef, double zoomFactor)
459 toImpl(pageRef)->setPageZoomFactor(zoomFactor);
462 void WKPageSetPageAndTextZoomFactors(WKPageRef pageRef, double pageZoomFactor, double textZoomFactor)
464 toImpl(pageRef)->setPageAndTextZoomFactors(pageZoomFactor, textZoomFactor);
467 void WKPageSetScaleFactor(WKPageRef pageRef, double scale, WKPoint origin)
469 toImpl(pageRef)->scalePage(scale, toIntPoint(origin));
472 double WKPageGetScaleFactor(WKPageRef pageRef)
474 return toImpl(pageRef)->pageScaleFactor();
477 void WKPageSetUseFixedLayout(WKPageRef pageRef, bool fixed)
479 toImpl(pageRef)->setUseFixedLayout(fixed);
482 void WKPageSetFixedLayoutSize(WKPageRef pageRef, WKSize size)
484 toImpl(pageRef)->setFixedLayoutSize(toIntSize(size));
487 bool WKPageUseFixedLayout(WKPageRef pageRef)
489 return toImpl(pageRef)->useFixedLayout();
492 WKSize WKPageFixedLayoutSize(WKPageRef pageRef)
494 return toAPI(toImpl(pageRef)->fixedLayoutSize());
497 void WKPageListenForLayoutMilestones(WKPageRef pageRef, WKLayoutMilestones milestones)
499 toImpl(pageRef)->listenForLayoutMilestones(toLayoutMilestones(milestones));
502 bool WKPageHasHorizontalScrollbar(WKPageRef pageRef)
504 return toImpl(pageRef)->hasHorizontalScrollbar();
507 bool WKPageHasVerticalScrollbar(WKPageRef pageRef)
509 return toImpl(pageRef)->hasVerticalScrollbar();
512 void WKPageSetSuppressScrollbarAnimations(WKPageRef pageRef, bool suppressAnimations)
514 toImpl(pageRef)->setSuppressScrollbarAnimations(suppressAnimations);
517 bool WKPageAreScrollbarAnimationsSuppressed(WKPageRef pageRef)
519 return toImpl(pageRef)->areScrollbarAnimationsSuppressed();
522 bool WKPageIsPinnedToLeftSide(WKPageRef pageRef)
524 return toImpl(pageRef)->isPinnedToLeftSide();
527 bool WKPageIsPinnedToRightSide(WKPageRef pageRef)
529 return toImpl(pageRef)->isPinnedToRightSide();
532 bool WKPageIsPinnedToTopSide(WKPageRef pageRef)
534 return toImpl(pageRef)->isPinnedToTopSide();
537 bool WKPageIsPinnedToBottomSide(WKPageRef pageRef)
539 return toImpl(pageRef)->isPinnedToBottomSide();
542 bool WKPageRubberBandsAtLeft(WKPageRef pageRef)
544 return toImpl(pageRef)->rubberBandsAtLeft();
547 void WKPageSetRubberBandsAtLeft(WKPageRef pageRef, bool rubberBandsAtLeft)
549 toImpl(pageRef)->setRubberBandsAtLeft(rubberBandsAtLeft);
552 bool WKPageRubberBandsAtRight(WKPageRef pageRef)
554 return toImpl(pageRef)->rubberBandsAtRight();
557 void WKPageSetRubberBandsAtRight(WKPageRef pageRef, bool rubberBandsAtRight)
559 toImpl(pageRef)->setRubberBandsAtRight(rubberBandsAtRight);
562 bool WKPageRubberBandsAtTop(WKPageRef pageRef)
564 return toImpl(pageRef)->rubberBandsAtTop();
567 void WKPageSetRubberBandsAtTop(WKPageRef pageRef, bool rubberBandsAtTop)
569 toImpl(pageRef)->setRubberBandsAtTop(rubberBandsAtTop);
572 bool WKPageRubberBandsAtBottom(WKPageRef pageRef)
574 return toImpl(pageRef)->rubberBandsAtBottom();
577 void WKPageSetRubberBandsAtBottom(WKPageRef pageRef, bool rubberBandsAtBottom)
579 toImpl(pageRef)->setRubberBandsAtBottom(rubberBandsAtBottom);
582 bool WKPageVerticalRubberBandingIsEnabled(WKPageRef pageRef)
584 return toImpl(pageRef)->verticalRubberBandingIsEnabled();
587 void WKPageSetEnableVerticalRubberBanding(WKPageRef pageRef, bool enableVerticalRubberBanding)
589 toImpl(pageRef)->setEnableVerticalRubberBanding(enableVerticalRubberBanding);
592 bool WKPageHorizontalRubberBandingIsEnabled(WKPageRef pageRef)
594 return toImpl(pageRef)->horizontalRubberBandingIsEnabled();
597 void WKPageSetEnableHorizontalRubberBanding(WKPageRef pageRef, bool enableHorizontalRubberBanding)
599 toImpl(pageRef)->setEnableHorizontalRubberBanding(enableHorizontalRubberBanding);
602 void WKPageSetBackgroundExtendsBeyondPage(WKPageRef pageRef, bool backgroundExtendsBeyondPage)
604 toImpl(pageRef)->setBackgroundExtendsBeyondPage(backgroundExtendsBeyondPage);
607 bool WKPageBackgroundExtendsBeyondPage(WKPageRef pageRef)
609 return toImpl(pageRef)->backgroundExtendsBeyondPage();
612 void WKPageSetPaginationMode(WKPageRef pageRef, WKPaginationMode paginationMode)
614 Pagination::Mode mode;
615 switch (paginationMode) {
616 case kWKPaginationModeUnpaginated:
617 mode = Pagination::Unpaginated;
619 case kWKPaginationModeLeftToRight:
620 mode = Pagination::LeftToRightPaginated;
622 case kWKPaginationModeRightToLeft:
623 mode = Pagination::RightToLeftPaginated;
625 case kWKPaginationModeTopToBottom:
626 mode = Pagination::TopToBottomPaginated;
628 case kWKPaginationModeBottomToTop:
629 mode = Pagination::BottomToTopPaginated;
634 toImpl(pageRef)->setPaginationMode(mode);
637 WKPaginationMode WKPageGetPaginationMode(WKPageRef pageRef)
639 switch (toImpl(pageRef)->paginationMode()) {
640 case Pagination::Unpaginated:
641 return kWKPaginationModeUnpaginated;
642 case Pagination::LeftToRightPaginated:
643 return kWKPaginationModeLeftToRight;
644 case Pagination::RightToLeftPaginated:
645 return kWKPaginationModeRightToLeft;
646 case Pagination::TopToBottomPaginated:
647 return kWKPaginationModeTopToBottom;
648 case Pagination::BottomToTopPaginated:
649 return kWKPaginationModeBottomToTop;
652 ASSERT_NOT_REACHED();
653 return kWKPaginationModeUnpaginated;
656 void WKPageSetPaginationBehavesLikeColumns(WKPageRef pageRef, bool behavesLikeColumns)
658 toImpl(pageRef)->setPaginationBehavesLikeColumns(behavesLikeColumns);
661 bool WKPageGetPaginationBehavesLikeColumns(WKPageRef pageRef)
663 return toImpl(pageRef)->paginationBehavesLikeColumns();
666 void WKPageSetPageLength(WKPageRef pageRef, double pageLength)
668 toImpl(pageRef)->setPageLength(pageLength);
671 double WKPageGetPageLength(WKPageRef pageRef)
673 return toImpl(pageRef)->pageLength();
676 void WKPageSetGapBetweenPages(WKPageRef pageRef, double gap)
678 toImpl(pageRef)->setGapBetweenPages(gap);
681 double WKPageGetGapBetweenPages(WKPageRef pageRef)
683 return toImpl(pageRef)->gapBetweenPages();
686 unsigned WKPageGetPageCount(WKPageRef pageRef)
688 return toImpl(pageRef)->pageCount();
691 bool WKPageCanDelete(WKPageRef pageRef)
693 return toImpl(pageRef)->canDelete();
696 bool WKPageHasSelectedRange(WKPageRef pageRef)
698 return toImpl(pageRef)->hasSelectedRange();
701 bool WKPageIsContentEditable(WKPageRef pageRef)
703 return toImpl(pageRef)->isContentEditable();
706 void WKPageSetMaintainsInactiveSelection(WKPageRef pageRef, bool newValue)
708 return toImpl(pageRef)->setMaintainsInactiveSelection(newValue);
711 void WKPageCenterSelectionInVisibleArea(WKPageRef pageRef)
713 return toImpl(pageRef)->centerSelectionInVisibleArea();
716 void WKPageFindStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
718 toImpl(pageRef)->findStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
721 void WKPageGetImageForFindMatch(WKPageRef pageRef, int32_t matchIndex)
723 toImpl(pageRef)->getImageForFindMatch(matchIndex);
726 void WKPageSelectFindMatch(WKPageRef pageRef, int32_t matchIndex)
728 toImpl(pageRef)->selectFindMatch(matchIndex);
731 void WKPageFindString(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
733 toImpl(pageRef)->findString(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
736 void WKPageHideFindUI(WKPageRef pageRef)
738 toImpl(pageRef)->hideFindUI();
741 void WKPageCountStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
743 toImpl(pageRef)->countStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
746 void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuClientBase* wkClient)
748 #if ENABLE(CONTEXT_MENUS)
749 class ContextMenuClient final : public API::Client<WKPageContextMenuClientBase>, public API::ContextMenuClient {
751 explicit ContextMenuClient(const WKPageContextMenuClientBase* client)
757 virtual bool getContextMenuFromProposedMenu(WebPageProxy& page, const Vector<RefPtr<WebKit::WebContextMenuItem>>& proposedMenuVector, Vector<RefPtr<WebKit::WebContextMenuItem>>& customMenu, const WebHitTestResult::Data& hitTestResultData, API::Object* userData) override
759 if (!m_client.getContextMenuFromProposedMenu && !m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0)
762 if (m_client.base.version >= 2 && !m_client.getContextMenuFromProposedMenu)
765 Vector<RefPtr<API::Object>> proposedMenuItems;
766 proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size());
768 for (const auto& menuItem : proposedMenuVector)
769 proposedMenuItems.uncheckedAppend(menuItem);
771 WKArrayRef newMenu = nullptr;
772 if (m_client.base.version >= 2) {
773 RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(hitTestResultData);
774 m_client.getContextMenuFromProposedMenu(toAPI(&page), toAPI(API::Array::create(WTF::move(proposedMenuItems)).ptr()), &newMenu, toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo);
776 m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0(toAPI(&page), toAPI(API::Array::create(WTF::move(proposedMenuItems)).ptr()), &newMenu, toAPI(userData), m_client.base.clientInfo);
778 RefPtr<API::Array> array = adoptRef(toImpl(newMenu));
782 size_t newSize = array ? array->size() : 0;
783 for (size_t i = 0; i < newSize; ++i) {
784 WebContextMenuItem* item = array->at<WebContextMenuItem>(i);
786 LOG(ContextMenu, "New menu entry at index %i is not a WebContextMenuItem", (int)i);
790 customMenu.append(item);
796 virtual void customContextMenuItemSelected(WebPageProxy& page, const WebContextMenuItemData& itemData) override
798 if (!m_client.customContextMenuItemSelected)
801 m_client.customContextMenuItemSelected(toAPI(&page), toAPI(WebContextMenuItem::create(itemData).get()), m_client.base.clientInfo);
804 virtual void contextMenuDismissed(WebPageProxy& page) override
806 if (!m_client.contextMenuDismissed)
809 m_client.contextMenuDismissed(toAPI(&page), m_client.base.clientInfo);
812 virtual bool showContextMenu(WebPageProxy& page, const WebCore::IntPoint& menuLocation, const Vector<RefPtr<WebContextMenuItem>>& menuItemsVector) override
814 if (!m_client.showContextMenu)
817 Vector<RefPtr<API::Object>> menuItems;
818 menuItems.reserveInitialCapacity(menuItemsVector.size());
820 for (const auto& menuItem : menuItemsVector)
821 menuItems.uncheckedAppend(menuItem);
823 m_client.showContextMenu(toAPI(&page), toAPI(menuLocation), toAPI(API::Array::create(WTF::move(menuItems)).ptr()), m_client.base.clientInfo);
828 virtual bool hideContextMenu(WebPageProxy& page) override
830 if (!m_client.hideContextMenu)
833 m_client.hideContextMenu(toAPI(&page), m_client.base.clientInfo);
839 toImpl(pageRef)->setContextMenuClient(std::make_unique<ContextMenuClient>(wkClient));
841 UNUSED_PARAM(pageRef);
842 UNUSED_PARAM(wkClient);
846 void WKPageSetPageDiagnosticLoggingClient(WKPageRef pageRef, const WKPageDiagnosticLoggingClientBase* wkClient)
848 toImpl(pageRef)->setDiagnosticLoggingClient(std::make_unique<WebPageDiagnosticLoggingClient>(wkClient));
851 void WKPageSetPageFindClient(WKPageRef pageRef, const WKPageFindClientBase* wkClient)
853 class FindClient : public API::Client<WKPageFindClientBase>, public API::FindClient {
855 explicit FindClient(const WKPageFindClientBase* client)
861 virtual void didFindString(WebPageProxy* page, const String& string, uint32_t matchCount, int32_t) override
863 if (!m_client.didFindString)
866 m_client.didFindString(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
869 virtual void didFailToFindString(WebPageProxy* page, const String& string) override
871 if (!m_client.didFailToFindString)
874 m_client.didFailToFindString(toAPI(page), toAPI(string.impl()), m_client.base.clientInfo);
877 virtual void didCountStringMatches(WebPageProxy* page, const String& string, uint32_t matchCount) override
879 if (!m_client.didCountStringMatches)
882 m_client.didCountStringMatches(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
886 toImpl(pageRef)->setFindClient(std::make_unique<FindClient>(wkClient));
889 void WKPageSetPageFindMatchesClient(WKPageRef pageRef, const WKPageFindMatchesClientBase* wkClient)
891 toImpl(pageRef)->initializeFindMatchesClient(wkClient);
894 void WKPageSetPageInjectedBundleClient(WKPageRef pageRef, const WKPageInjectedBundleClientBase* wkClient)
896 toImpl(pageRef)->setInjectedBundleClient(wkClient);
899 void WKPageSetPageFormClient(WKPageRef pageRef, const WKPageFormClientBase* wkClient)
901 toImpl(pageRef)->setFormClient(std::make_unique<WebFormClient>(wkClient));
904 void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase* wkClient)
906 class LoaderClient : public API::Client<WKPageLoaderClientBase>, public API::LoaderClient {
908 explicit LoaderClient(const WKPageLoaderClientBase* client)
914 virtual void didStartProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
916 if (!m_client.didStartProvisionalLoadForFrame)
919 m_client.didStartProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
922 virtual void didReceiveServerRedirectForProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
924 if (!m_client.didReceiveServerRedirectForProvisionalLoadForFrame)
927 m_client.didReceiveServerRedirectForProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
930 virtual void didFailProvisionalLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
932 if (!m_client.didFailProvisionalLoadWithErrorForFrame)
935 m_client.didFailProvisionalLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
938 virtual void didCommitLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
940 if (!m_client.didCommitLoadForFrame)
943 m_client.didCommitLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
946 virtual void didFinishDocumentLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
948 if (!m_client.didFinishDocumentLoadForFrame)
951 m_client.didFinishDocumentLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
954 virtual void didFinishLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
956 if (!m_client.didFinishLoadForFrame)
959 m_client.didFinishLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
962 virtual void didFailLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
964 if (!m_client.didFailLoadWithErrorForFrame)
967 m_client.didFailLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
970 virtual void didSameDocumentNavigationForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, SameDocumentNavigationType type, API::Object* userData) override
972 if (!m_client.didSameDocumentNavigationForFrame)
975 m_client.didSameDocumentNavigationForFrame(toAPI(&page), toAPI(&frame), toAPI(type), toAPI(userData), m_client.base.clientInfo);
978 virtual void didReceiveTitleForFrame(WebPageProxy& page, const String& title, WebFrameProxy& frame, API::Object* userData) override
980 if (!m_client.didReceiveTitleForFrame)
983 m_client.didReceiveTitleForFrame(toAPI(&page), toAPI(title.impl()), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
986 virtual void didFirstLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
988 if (!m_client.didFirstLayoutForFrame)
991 m_client.didFirstLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
994 virtual void didFirstVisuallyNonEmptyLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
996 if (!m_client.didFirstVisuallyNonEmptyLayoutForFrame)
999 m_client.didFirstVisuallyNonEmptyLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1002 virtual void didLayout(WebPageProxy& page, LayoutMilestones milestones, API::Object* userData) override
1004 if (!m_client.didLayout)
1007 m_client.didLayout(toAPI(&page), toWKLayoutMilestones(milestones), toAPI(userData), m_client.base.clientInfo);
1010 virtual void didRemoveFrameFromHierarchy(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1012 if (!m_client.didRemoveFrameFromHierarchy)
1015 m_client.didRemoveFrameFromHierarchy(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1018 virtual void didDisplayInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1020 if (!m_client.didDisplayInsecureContentForFrame)
1023 m_client.didDisplayInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1026 virtual void didRunInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1028 if (!m_client.didRunInsecureContentForFrame)
1031 m_client.didRunInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1034 virtual void didDetectXSSForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1036 if (!m_client.didDetectXSSForFrame)
1039 m_client.didDetectXSSForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1042 virtual bool canAuthenticateAgainstProtectionSpaceInFrame(WebPageProxy& page, WebFrameProxy& frame, WebProtectionSpace* protectionSpace) override
1044 if (!m_client.canAuthenticateAgainstProtectionSpaceInFrame)
1047 return m_client.canAuthenticateAgainstProtectionSpaceInFrame(toAPI(&page), toAPI(&frame), toAPI(protectionSpace), m_client.base.clientInfo);
1050 virtual void didReceiveAuthenticationChallengeInFrame(WebPageProxy& page, WebFrameProxy& frame, AuthenticationChallengeProxy* authenticationChallenge) override
1052 if (!m_client.didReceiveAuthenticationChallengeInFrame)
1055 m_client.didReceiveAuthenticationChallengeInFrame(toAPI(&page), toAPI(&frame), toAPI(authenticationChallenge), m_client.base.clientInfo);
1058 virtual void didStartProgress(WebPageProxy& page) override
1060 if (!m_client.didStartProgress)
1063 m_client.didStartProgress(toAPI(&page), m_client.base.clientInfo);
1066 virtual void didChangeProgress(WebPageProxy& page) override
1068 if (!m_client.didChangeProgress)
1071 m_client.didChangeProgress(toAPI(&page), m_client.base.clientInfo);
1074 virtual void didFinishProgress(WebPageProxy& page) override
1076 if (!m_client.didFinishProgress)
1079 m_client.didFinishProgress(toAPI(&page), m_client.base.clientInfo);
1082 virtual void processDidBecomeUnresponsive(WebPageProxy& page) override
1084 if (!m_client.processDidBecomeUnresponsive)
1087 m_client.processDidBecomeUnresponsive(toAPI(&page), m_client.base.clientInfo);
1090 virtual void interactionOccurredWhileProcessUnresponsive(WebPageProxy& page) override
1092 if (!m_client.interactionOccurredWhileProcessUnresponsive)
1095 m_client.interactionOccurredWhileProcessUnresponsive(toAPI(&page), m_client.base.clientInfo);
1098 virtual void processDidBecomeResponsive(WebPageProxy& page) override
1100 if (!m_client.processDidBecomeResponsive)
1103 m_client.processDidBecomeResponsive(toAPI(&page), m_client.base.clientInfo);
1106 virtual void processDidCrash(WebPageProxy& page) override
1108 if (!m_client.processDidCrash)
1111 m_client.processDidCrash(toAPI(&page), m_client.base.clientInfo);
1114 virtual void didChangeBackForwardList(WebPageProxy& page, WebBackForwardListItem* addedItem, Vector<RefPtr<WebBackForwardListItem>> removedItems) override
1116 if (!m_client.didChangeBackForwardList)
1119 RefPtr<API::Array> removedItemsArray;
1120 if (!removedItems.isEmpty()) {
1121 Vector<RefPtr<API::Object>> removedItemsVector;
1122 removedItemsVector.reserveInitialCapacity(removedItems.size());
1123 for (auto& removedItem : removedItems)
1124 removedItemsVector.append(WTF::move(removedItem));
1126 removedItemsArray = API::Array::create(WTF::move(removedItemsVector));
1129 m_client.didChangeBackForwardList(toAPI(&page), toAPI(addedItem), toAPI(removedItemsArray.get()), m_client.base.clientInfo);
1132 virtual bool shouldKeepCurrentBackForwardListItemInList(WebKit::WebPageProxy& page, WebKit::WebBackForwardListItem* item) override
1134 if (!m_client.shouldKeepCurrentBackForwardListItemInList)
1137 return m_client.shouldKeepCurrentBackForwardListItemInList(toAPI(&page), toAPI(item), m_client.base.clientInfo);
1140 virtual void willGoToBackForwardListItem(WebPageProxy& page, WebBackForwardListItem* item, API::Object* userData) override
1142 if (m_client.willGoToBackForwardListItem)
1143 m_client.willGoToBackForwardListItem(toAPI(&page), toAPI(item), toAPI(userData), m_client.base.clientInfo);
1146 virtual PassRefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
1148 return page.process().processPool().client().copyWebCryptoMasterKey(&page.process().processPool());
1151 virtual void navigationGestureDidBegin(WebPageProxy& page) override
1153 if (m_client.navigationGestureDidBegin)
1154 m_client.navigationGestureDidBegin(toAPI(&page), m_client.base.clientInfo);
1157 virtual void navigationGestureWillEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override
1159 if (m_client.navigationGestureWillEnd)
1160 m_client.navigationGestureWillEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo);
1163 virtual void navigationGestureDidEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override
1165 if (m_client.navigationGestureDidEnd)
1166 m_client.navigationGestureDidEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo);
1169 #if ENABLE(NETSCAPE_PLUGIN_API)
1170 virtual void didFailToInitializePlugin(WebPageProxy& page, API::Dictionary* pluginInformation) override
1172 if (m_client.didFailToInitializePlugin_deprecatedForUseWithV0)
1173 m_client.didFailToInitializePlugin_deprecatedForUseWithV0(toAPI(&page), toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), m_client.base.clientInfo);
1175 if (m_client.pluginDidFail_deprecatedForUseWithV1)
1176 m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), 0, 0, m_client.base.clientInfo);
1178 if (m_client.pluginDidFail)
1179 m_client.pluginDidFail(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation), m_client.base.clientInfo);
1182 virtual void didBlockInsecurePluginVersion(WebPageProxy& page, API::Dictionary* pluginInformation) override
1184 if (m_client.pluginDidFail_deprecatedForUseWithV1)
1185 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);
1187 if (m_client.pluginDidFail)
1188 m_client.pluginDidFail(toAPI(&page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation), m_client.base.clientInfo);
1191 virtual PluginModuleLoadPolicy pluginLoadPolicy(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
1193 WKStringRef unavailabilityDescriptionOut = 0;
1194 PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
1196 if (m_client.pluginLoadPolicy_deprecatedForUseWithV2)
1197 loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy_deprecatedForUseWithV2(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), m_client.base.clientInfo));
1198 else if (m_client.pluginLoadPolicy)
1199 loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
1201 if (unavailabilityDescriptionOut) {
1202 RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
1203 unavailabilityDescription = webUnavailabilityDescription->string();
1208 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1211 virtual WebCore::WebGLLoadPolicy webGLLoadPolicy(WebPageProxy& page, const String& url) const override
1213 WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
1215 if (m_client.webGLLoadPolicy)
1216 loadPolicy = toWebGLLoadPolicy(m_client.webGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
1221 virtual WebCore::WebGLLoadPolicy resolveWebGLLoadPolicy(WebPageProxy& page, const String& url) const override
1223 WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
1225 if (m_client.resolveWebGLLoadPolicy)
1226 loadPolicy = toWebGLLoadPolicy(m_client.resolveWebGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
1231 #endif // ENABLE(WEBGL)
1234 WebPageProxy* webPageProxy = toImpl(pageRef);
1236 auto loaderClient = std::make_unique<LoaderClient>(wkClient);
1238 // It would be nice to get rid of this code and transition all clients to using didLayout instead of
1239 // didFirstLayoutInFrame and didFirstVisuallyNonEmptyLayoutInFrame. In the meantime, this is required
1240 // for backwards compatibility.
1241 WebCore::LayoutMilestones milestones = 0;
1242 if (loaderClient->client().didFirstLayoutForFrame)
1243 milestones |= WebCore::DidFirstLayout;
1244 if (loaderClient->client().didFirstVisuallyNonEmptyLayoutForFrame)
1245 milestones |= WebCore::DidFirstVisuallyNonEmptyLayout;
1248 webPageProxy->process().send(Messages::WebPage::ListenForLayoutMilestones(milestones), webPageProxy->pageID());
1250 webPageProxy->setLoaderClient(WTF::move(loaderClient));
1253 void WKPageSetPagePolicyClient(WKPageRef pageRef, const WKPagePolicyClientBase* wkClient)
1255 class PolicyClient : public API::Client<WKPagePolicyClientBase>, public API::PolicyClient {
1257 explicit PolicyClient(const WKPagePolicyClientBase* client)
1263 virtual void decidePolicyForNavigationAction(WebPageProxy& page, WebFrameProxy* frame, const NavigationActionData& navigationActionData, WebFrameProxy* originatingFrame, const WebCore::ResourceRequest& originalResourceRequest, const WebCore::ResourceRequest& resourceRequest, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1265 if (!m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0 && !m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1 && !m_client.decidePolicyForNavigationAction) {
1270 Ref<API::URLRequest> originalRequest = API::URLRequest::create(originalResourceRequest);
1271 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1273 if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0)
1274 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);
1275 else if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1)
1276 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);
1278 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);
1281 virtual void decidePolicyForNewWindowAction(WebPageProxy& page, WebFrameProxy& frame, const NavigationActionData& navigationActionData, const ResourceRequest& resourceRequest, const String& frameName, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1283 if (!m_client.decidePolicyForNewWindowAction) {
1288 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1290 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);
1293 virtual void decidePolicyForResponse(WebPageProxy& page, WebFrameProxy& frame, const ResourceResponse& resourceResponse, const ResourceRequest& resourceRequest, bool canShowMIMEType, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1295 if (!m_client.decidePolicyForResponse_deprecatedForUseWithV0 && !m_client.decidePolicyForResponse) {
1300 Ref<API::URLResponse> response = API::URLResponse::create(resourceResponse);
1301 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1303 if (m_client.decidePolicyForResponse_deprecatedForUseWithV0)
1304 m_client.decidePolicyForResponse_deprecatedForUseWithV0(toAPI(&page), toAPI(&frame), toAPI(response.ptr()), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1306 m_client.decidePolicyForResponse(toAPI(&page), toAPI(&frame), toAPI(response.ptr()), toAPI(request.ptr()), canShowMIMEType, toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1309 virtual void unableToImplementPolicy(WebPageProxy& page, WebFrameProxy& frame, const ResourceError& error, API::Object* userData) override
1311 if (!m_client.unableToImplementPolicy)
1314 m_client.unableToImplementPolicy(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1318 toImpl(pageRef)->setPolicyClient(std::make_unique<PolicyClient>(wkClient));
1321 void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient)
1323 class UIClient : public API::Client<WKPageUIClientBase>, public API::UIClient {
1325 explicit UIClient(const WKPageUIClientBase* client)
1331 virtual PassRefPtr<WebPageProxy> createNewPage(WebPageProxy* page, WebFrameProxy*, const ResourceRequest& resourceRequest, const WindowFeatures& windowFeatures, const NavigationActionData& navigationActionData) override
1333 if (!m_client.base.version && !m_client.createNewPage_deprecatedForUseWithV0)
1336 if (m_client.base.version > 0 && !m_client.createNewPage)
1339 API::Dictionary::MapType map;
1340 if (windowFeatures.xSet)
1341 map.set("x", API::Double::create(windowFeatures.x));
1342 if (windowFeatures.ySet)
1343 map.set("y", API::Double::create(windowFeatures.y));
1344 if (windowFeatures.widthSet)
1345 map.set("width", API::Double::create(windowFeatures.width));
1346 if (windowFeatures.heightSet)
1347 map.set("height", API::Double::create(windowFeatures.height));
1348 map.set("menuBarVisible", API::Boolean::create(windowFeatures.menuBarVisible));
1349 map.set("statusBarVisible", API::Boolean::create(windowFeatures.statusBarVisible));
1350 map.set("toolBarVisible", API::Boolean::create(windowFeatures.toolBarVisible));
1351 map.set("locationBarVisible", API::Boolean::create(windowFeatures.locationBarVisible));
1352 map.set("scrollbarsVisible", API::Boolean::create(windowFeatures.scrollbarsVisible));
1353 map.set("resizable", API::Boolean::create(windowFeatures.resizable));
1354 map.set("fullscreen", API::Boolean::create(windowFeatures.fullscreen));
1355 map.set("dialog", API::Boolean::create(windowFeatures.dialog));
1356 Ref<API::Dictionary> featuresMap = API::Dictionary::create(WTF::move(map));
1358 if (!m_client.base.version)
1359 return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV0(toAPI(page), toAPI(featuresMap.ptr()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
1361 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1362 return adoptRef(toImpl(m_client.createNewPage(toAPI(page), toAPI(request.ptr()), toAPI(featuresMap.ptr()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
1365 virtual void showPage(WebPageProxy* page) override
1367 if (!m_client.showPage)
1370 m_client.showPage(toAPI(page), m_client.base.clientInfo);
1373 virtual void close(WebPageProxy* page) override
1375 if (!m_client.close)
1378 m_client.close(toAPI(page), m_client.base.clientInfo);
1381 virtual void takeFocus(WebPageProxy* page, WKFocusDirection direction) override
1383 if (!m_client.takeFocus)
1386 m_client.takeFocus(toAPI(page), direction, m_client.base.clientInfo);
1389 virtual void focus(WebPageProxy* page) override
1391 if (!m_client.focus)
1394 m_client.focus(toAPI(page), m_client.base.clientInfo);
1397 virtual void unfocus(WebPageProxy* page) override
1399 if (!m_client.unfocus)
1402 m_client.unfocus(toAPI(page), m_client.base.clientInfo);
1405 virtual void runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame, std::function<void ()> completionHandler) override
1407 if (!m_client.runJavaScriptAlert) {
1408 completionHandler();
1412 m_client.runJavaScriptAlert(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1413 completionHandler();
1416 virtual void runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame, std::function<void (bool)> completionHandler) override
1418 if (!m_client.runJavaScriptConfirm) {
1419 completionHandler(false);
1423 bool result = m_client.runJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1424 completionHandler(result);
1427 virtual void runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame, std::function<void (const String&)> completionHandler) override
1429 if (!m_client.runJavaScriptPrompt) {
1430 completionHandler(String());
1434 RefPtr<API::String> string = adoptRef(toImpl(m_client.runJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.base.clientInfo)));
1436 completionHandler(String());
1440 completionHandler(string->string());
1443 virtual void setStatusText(WebPageProxy* page, const String& text) override
1445 if (!m_client.setStatusText)
1448 m_client.setStatusText(toAPI(page), toAPI(text.impl()), m_client.base.clientInfo);
1451 virtual void mouseDidMoveOverElement(WebPageProxy* page, const WebHitTestResult::Data& data, WebEvent::Modifiers modifiers, API::Object* userData) override
1453 if (!m_client.mouseDidMoveOverElement && !m_client.mouseDidMoveOverElement_deprecatedForUseWithV0)
1456 if (m_client.base.version > 0 && !m_client.mouseDidMoveOverElement)
1459 if (!m_client.base.version) {
1460 m_client.mouseDidMoveOverElement_deprecatedForUseWithV0(toAPI(page), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
1464 RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(data);
1465 m_client.mouseDidMoveOverElement(toAPI(page), toAPI(webHitTestResult.get()), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
1468 #if ENABLE(NETSCAPE_PLUGIN_API)
1469 virtual void unavailablePluginButtonClicked(WebPageProxy* page, WKPluginUnavailabilityReason pluginUnavailabilityReason, API::Dictionary* pluginInformation) override
1471 if (pluginUnavailabilityReason == kWKPluginUnavailabilityReasonPluginMissing) {
1472 if (m_client.missingPluginButtonClicked_deprecatedForUseWithV0)
1473 m_client.missingPluginButtonClicked_deprecatedForUseWithV0(
1475 toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
1476 toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
1477 toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
1478 m_client.base.clientInfo);
1481 if (m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1)
1482 m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1(
1484 pluginUnavailabilityReason,
1485 toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
1486 toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
1487 toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
1488 m_client.base.clientInfo);
1490 if (m_client.unavailablePluginButtonClicked)
1491 m_client.unavailablePluginButtonClicked(
1493 pluginUnavailabilityReason,
1494 toAPI(pluginInformation),
1495 m_client.base.clientInfo);
1497 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1499 virtual bool implementsDidNotHandleKeyEvent() const override
1501 return m_client.didNotHandleKeyEvent;
1504 virtual void didNotHandleKeyEvent(WebPageProxy* page, const NativeWebKeyboardEvent& event) override
1506 if (!m_client.didNotHandleKeyEvent)
1508 m_client.didNotHandleKeyEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
1511 virtual bool implementsDidNotHandleWheelEvent() const override
1513 return m_client.didNotHandleWheelEvent;
1516 virtual void didNotHandleWheelEvent(WebPageProxy* page, const NativeWebWheelEvent& event) override
1518 if (!m_client.didNotHandleWheelEvent)
1520 m_client.didNotHandleWheelEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
1523 virtual bool toolbarsAreVisible(WebPageProxy* page) override
1525 if (!m_client.toolbarsAreVisible)
1527 return m_client.toolbarsAreVisible(toAPI(page), m_client.base.clientInfo);
1530 virtual void setToolbarsAreVisible(WebPageProxy* page, bool visible) override
1532 if (!m_client.setToolbarsAreVisible)
1534 m_client.setToolbarsAreVisible(toAPI(page), visible, m_client.base.clientInfo);
1537 virtual bool menuBarIsVisible(WebPageProxy* page) override
1539 if (!m_client.menuBarIsVisible)
1541 return m_client.menuBarIsVisible(toAPI(page), m_client.base.clientInfo);
1544 virtual void setMenuBarIsVisible(WebPageProxy* page, bool visible) override
1546 if (!m_client.setMenuBarIsVisible)
1548 m_client.setMenuBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
1551 virtual bool statusBarIsVisible(WebPageProxy* page) override
1553 if (!m_client.statusBarIsVisible)
1555 return m_client.statusBarIsVisible(toAPI(page), m_client.base.clientInfo);
1558 virtual void setStatusBarIsVisible(WebPageProxy* page, bool visible) override
1560 if (!m_client.setStatusBarIsVisible)
1562 m_client.setStatusBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
1565 virtual bool isResizable(WebPageProxy* page) override
1567 if (!m_client.isResizable)
1569 return m_client.isResizable(toAPI(page), m_client.base.clientInfo);
1572 virtual void setIsResizable(WebPageProxy* page, bool resizable) override
1574 if (!m_client.setIsResizable)
1576 m_client.setIsResizable(toAPI(page), resizable, m_client.base.clientInfo);
1579 virtual void setWindowFrame(WebPageProxy* page, const FloatRect& frame) override
1581 if (!m_client.setWindowFrame)
1584 m_client.setWindowFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1587 virtual FloatRect windowFrame(WebPageProxy* page) override
1589 if (!m_client.getWindowFrame)
1592 return toFloatRect(m_client.getWindowFrame(toAPI(page), m_client.base.clientInfo));
1595 virtual bool canRunBeforeUnloadConfirmPanel() const override
1597 return m_client.runBeforeUnloadConfirmPanel;
1600 virtual bool runBeforeUnloadConfirmPanel(WebPageProxy* page, const String& message, WebFrameProxy* frame) override
1602 if (!m_client.runBeforeUnloadConfirmPanel)
1605 return m_client.runBeforeUnloadConfirmPanel(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1608 virtual void didDraw(WebPageProxy* page) override
1610 if (!m_client.didDraw)
1613 m_client.didDraw(toAPI(page), m_client.base.clientInfo);
1616 virtual void pageDidScroll(WebPageProxy* page) override
1618 if (!m_client.pageDidScroll)
1621 m_client.pageDidScroll(toAPI(page), m_client.base.clientInfo);
1624 virtual void exceededDatabaseQuota(WebPageProxy* page, WebFrameProxy* frame, API::SecurityOrigin* origin, const String& databaseName, const String& databaseDisplayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage, std::function<void (unsigned long long)> completionHandler) override
1626 if (!m_client.exceededDatabaseQuota) {
1627 completionHandler(currentQuota);
1631 completionHandler(m_client.exceededDatabaseQuota(toAPI(page), toAPI(frame), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, m_client.base.clientInfo));
1634 virtual bool runOpenPanel(WebPageProxy* page, WebFrameProxy* frame, WebOpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener) override
1636 if (!m_client.runOpenPanel)
1639 m_client.runOpenPanel(toAPI(page), toAPI(frame), toAPI(parameters), toAPI(listener), m_client.base.clientInfo);
1643 virtual bool decidePolicyForGeolocationPermissionRequest(WebPageProxy* page, WebFrameProxy* frame, API::SecurityOrigin* origin, GeolocationPermissionRequestProxy* permissionRequest) override
1645 if (!m_client.decidePolicyForGeolocationPermissionRequest)
1648 m_client.decidePolicyForGeolocationPermissionRequest(toAPI(page), toAPI(frame), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
1652 virtual bool decidePolicyForUserMediaPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, UserMediaPermissionRequestProxy& permissionRequest) override
1654 if (!m_client.decidePolicyForUserMediaPermissionRequest)
1657 m_client.decidePolicyForUserMediaPermissionRequest(toAPI(&page), toAPI(&frame), toAPI(&origin), toAPI(&permissionRequest), m_client.base.clientInfo);
1661 virtual bool decidePolicyForNotificationPermissionRequest(WebPageProxy* page, API::SecurityOrigin* origin, NotificationPermissionRequest* permissionRequest) override
1663 if (!m_client.decidePolicyForNotificationPermissionRequest)
1666 m_client.decidePolicyForNotificationPermissionRequest(toAPI(page), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
1671 virtual float headerHeight(WebPageProxy* page, WebFrameProxy* frame) override
1673 if (!m_client.headerHeight)
1676 return m_client.headerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1679 virtual float footerHeight(WebPageProxy* page, WebFrameProxy* frame) override
1681 if (!m_client.footerHeight)
1684 return m_client.footerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1687 virtual void drawHeader(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
1689 if (!m_client.drawHeader)
1692 m_client.drawHeader(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
1695 virtual void drawFooter(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
1697 if (!m_client.drawFooter)
1700 m_client.drawFooter(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
1703 virtual void printFrame(WebPageProxy* page, WebFrameProxy* frame) override
1705 if (!m_client.printFrame)
1708 m_client.printFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1711 virtual bool canRunModal() const override
1713 return m_client.runModal;
1716 virtual void runModal(WebPageProxy* page) override
1718 if (!m_client.runModal)
1721 m_client.runModal(toAPI(page), m_client.base.clientInfo);
1724 virtual void saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data) override
1726 if (!m_client.saveDataToFileInDownloadsFolder)
1729 m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURLString.impl()), toAPI(data), m_client.base.clientInfo);
1732 virtual bool shouldInterruptJavaScript(WebPageProxy* page) override
1734 if (!m_client.shouldInterruptJavaScript)
1737 return m_client.shouldInterruptJavaScript(toAPI(page), m_client.base.clientInfo);
1740 virtual void pinnedStateDidChange(WebPageProxy& page) override
1742 if (!m_client.pinnedStateDidChange)
1745 m_client.pinnedStateDidChange(toAPI(&page), m_client.base.clientInfo);
1748 virtual void didBeginTrackingPotentialLongMousePress(WebPageProxy* page, const IntPoint& mouseDownPosition, const WebHitTestResult::Data& data, API::Object* userInfo) override
1750 if (!m_client.didBeginTrackingPotentialLongMousePress)
1753 RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(data);
1754 m_client.didBeginTrackingPotentialLongMousePress(toAPI(page), toAPI(mouseDownPosition), toAPI(webHitTestResult.get()), toAPI(userInfo), m_client.base.clientInfo);
1757 virtual void didRecognizeLongMousePress(WebPageProxy* page, API::Object* userInfo) override
1759 if (!m_client.didRecognizeLongMousePress)
1762 m_client.didRecognizeLongMousePress(toAPI(page), toAPI(userInfo), m_client.base.clientInfo);
1765 virtual void didCancelTrackingPotentialLongMousePress(WebPageProxy* page, API::Object* userInfo) override
1767 if (!m_client.didCancelTrackingPotentialLongMousePress)
1770 m_client.didCancelTrackingPotentialLongMousePress(toAPI(page), toAPI(userInfo), m_client.base.clientInfo);
1773 virtual void isPlayingAudioDidChange(WebPageProxy& page) override
1775 if (!m_client.isPlayingAudioDidChange)
1778 m_client.isPlayingAudioDidChange(toAPI(&page), m_client.base.clientInfo);
1781 virtual void didClickAutoFillButton(WebPageProxy& page, API::Object* userInfo) override
1783 if (!m_client.didClickAutoFillButton)
1786 m_client.didClickAutoFillButton(toAPI(&page), toAPI(userInfo), m_client.base.clientInfo);
1790 toImpl(pageRef)->setUIClient(std::make_unique<UIClient>(wkClient));
1793 void WKPageSetPageNavigationClient(WKPageRef pageRef, const WKPageNavigationClientBase* wkClient)
1795 class NavigationClient : public API::Client<WKPageNavigationClientBase>, public API::NavigationClient {
1797 explicit NavigationClient(const WKPageNavigationClientBase* client)
1803 virtual void decidePolicyForNavigationAction(WebPageProxy& page, API::NavigationAction& navigationAction, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1805 if (!m_client.decidePolicyForNavigationAction)
1807 m_client.decidePolicyForNavigationAction(toAPI(&page), toAPI(&navigationAction), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1810 virtual void decidePolicyForNavigationResponse(WebPageProxy& page, API::NavigationResponse& navigationResponse, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1812 if (!m_client.decidePolicyForNavigationResponse)
1814 m_client.decidePolicyForNavigationResponse(toAPI(&page), toAPI(&navigationResponse), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1817 virtual void didStartProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1819 if (!m_client.didStartProvisionalNavigation)
1821 m_client.didStartProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1824 virtual void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1826 if (!m_client.didReceiveServerRedirectForProvisionalNavigation)
1828 m_client.didReceiveServerRedirectForProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1831 virtual void didFailProvisionalNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
1833 if (!m_client.didFailProvisionalNavigation)
1835 m_client.didFailProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1838 virtual void didCommitNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1840 if (!m_client.didCommitNavigation)
1842 m_client.didCommitNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1845 virtual void didFinishNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1847 if (!m_client.didFinishNavigation)
1849 m_client.didFinishNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1852 virtual void didFailNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
1854 if (!m_client.didFailNavigation)
1856 m_client.didFailNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1859 virtual void didFailProvisionalLoadInSubframeWithError(WebPageProxy& page, WebFrameProxy& subframe, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
1861 if (!m_client.didFailProvisionalLoadInSubframe)
1863 m_client.didFailProvisionalLoadInSubframe(toAPI(&page), toAPI(navigation), toAPI(API::FrameInfo::create(subframe).ptr()), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1866 virtual void didFinishDocumentLoad(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1868 if (!m_client.didFinishDocumentLoad)
1870 m_client.didFinishDocumentLoad(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1873 virtual void didSameDocumentNavigation(WebPageProxy& page, API::Navigation* navigation, WebKit::SameDocumentNavigationType navigationType, API::Object* userData) override
1875 if (!m_client.didSameDocumentNavigation)
1877 m_client.didSameDocumentNavigation(toAPI(&page), toAPI(navigation), toAPI(navigationType), toAPI(userData), m_client.base.clientInfo);
1880 virtual void renderingProgressDidChange(WebPageProxy& page, WebCore::LayoutMilestones milestones, API::Object* userData) override
1882 if (!m_client.renderingProgressDidChange)
1884 m_client.renderingProgressDidChange(toAPI(&page), pageRenderingProgressEvents(milestones), toAPI(userData), m_client.base.clientInfo);
1887 virtual bool canAuthenticateAgainstProtectionSpace(WebPageProxy& page, WebProtectionSpace* protectionSpace) override
1889 if (!m_client.canAuthenticateAgainstProtectionSpace)
1891 return m_client.canAuthenticateAgainstProtectionSpace(toAPI(&page), toAPI(protectionSpace), m_client.base.clientInfo);
1894 virtual void didReceiveAuthenticationChallenge(WebPageProxy& page, AuthenticationChallengeProxy* authenticationChallenge) override
1896 if (!m_client.didReceiveAuthenticationChallenge)
1898 m_client.didReceiveAuthenticationChallenge(toAPI(&page), toAPI(authenticationChallenge), m_client.base.clientInfo);
1901 virtual void processDidCrash(WebPageProxy& page) override
1903 if (!m_client.webProcessDidCrash)
1905 m_client.webProcessDidCrash(toAPI(&page), m_client.base.clientInfo);
1908 virtual PassRefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
1910 if (!m_client.copyWebCryptoMasterKey)
1912 return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(&page), m_client.base.clientInfo)));
1915 #if ENABLE(NETSCAPE_PLUGIN_API)
1916 virtual PluginModuleLoadPolicy decidePolicyForPluginLoad(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
1918 WKStringRef unavailabilityDescriptionOut = 0;
1919 PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
1921 if (m_client.decidePolicyForPluginLoad)
1922 loadPolicy = toPluginModuleLoadPolicy(m_client.decidePolicyForPluginLoad(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
1924 if (unavailabilityDescriptionOut) {
1925 RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
1926 unavailabilityDescription = webUnavailabilityDescription->string();
1934 WebPageProxy* webPageProxy = toImpl(pageRef);
1936 auto navigationClient = std::make_unique<NavigationClient>(wkClient);
1937 webPageProxy->setNavigationClient(WTF::move(navigationClient));
1940 void WKPageSetSession(WKPageRef pageRef, WKSessionRef session)
1942 toImpl(pageRef)->setSessionID(toImpl(session)->getID());
1945 void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback)
1947 toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), toGenericCallbackFunction(context, callback));
1951 static void callRunJavaScriptBlockAndRelease(WKSerializedScriptValueRef resultValue, WKErrorRef error, void* context)
1953 WKPageRunJavaScriptBlock block = (WKPageRunJavaScriptBlock)context;
1954 block(resultValue, error);
1955 Block_release(block);
1958 void WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef, WKStringRef scriptRef, WKPageRunJavaScriptBlock block)
1960 WKPageRunJavaScriptInMainFrame(pageRef, scriptRef, Block_copy(block), callRunJavaScriptBlockAndRelease);
1964 static std::function<void (const String&, WebKit::CallbackBase::Error)> toGenericCallbackFunction(void* context, void (*callback)(WKStringRef, WKErrorRef, void*))
1966 return [context, callback](const String& returnValue, WebKit::CallbackBase::Error error) {
1967 callback(toAPI(API::String::create(returnValue).ptr()), error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
1971 void WKPageRenderTreeExternalRepresentation(WKPageRef pageRef, void* context, WKPageRenderTreeExternalRepresentationFunction callback)
1973 toImpl(pageRef)->getRenderTreeExternalRepresentation(toGenericCallbackFunction(context, callback));
1976 void WKPageGetSourceForFrame(WKPageRef pageRef, WKFrameRef frameRef, void* context, WKPageGetSourceForFrameFunction callback)
1978 toImpl(pageRef)->getSourceForFrame(toImpl(frameRef), toGenericCallbackFunction(context, callback));
1981 void WKPageGetContentsAsString(WKPageRef pageRef, void* context, WKPageGetContentsAsStringFunction callback)
1983 toImpl(pageRef)->getContentsAsString(toGenericCallbackFunction(context, callback));
1986 void WKPageGetBytecodeProfile(WKPageRef pageRef, void* context, WKPageGetBytecodeProfileFunction callback)
1988 toImpl(pageRef)->getBytecodeProfile(toGenericCallbackFunction(context, callback));
1991 void WKPageGetSelectionAsWebArchiveData(WKPageRef pageRef, void* context, WKPageGetSelectionAsWebArchiveDataFunction callback)
1993 toImpl(pageRef)->getSelectionAsWebArchiveData(toGenericCallbackFunction(context, callback));
1996 void WKPageGetContentsAsMHTMLData(WKPageRef pageRef, bool useBinaryEncoding, void* context, WKPageGetContentsAsMHTMLDataFunction callback)
1999 toImpl(pageRef)->getContentsAsMHTMLData(toGenericCallbackFunction(context, callback), useBinaryEncoding);
2001 UNUSED_PARAM(pageRef);
2002 UNUSED_PARAM(useBinaryEncoding);
2003 UNUSED_PARAM(context);
2004 UNUSED_PARAM(callback);
2008 void WKPageForceRepaint(WKPageRef pageRef, void* context, WKPageForceRepaintFunction callback)
2010 toImpl(pageRef)->forceRepaint(VoidCallback::create([context, callback](WebKit::CallbackBase::Error error) {
2011 callback(error == WebKit::CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().ptr()), context);
2015 WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef pageRef)
2017 const String& pendingAPIRequestURL = toImpl(pageRef)->pageLoadState().pendingAPIRequestURL();
2019 if (pendingAPIRequestURL.isNull())
2022 return toCopiedURLAPI(pendingAPIRequestURL);
2025 WKURLRef WKPageCopyActiveURL(WKPageRef pageRef)
2027 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().activeURL());
2030 WKURLRef WKPageCopyProvisionalURL(WKPageRef pageRef)
2032 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().provisionalURL());
2035 WKURLRef WKPageCopyCommittedURL(WKPageRef pageRef)
2037 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().url());
2040 WKStringRef WKPageCopyStandardUserAgentWithApplicationName(WKStringRef applicationName)
2042 return toCopiedAPI(WebPageProxy::standardUserAgent(toImpl(applicationName)->string()));
2045 void WKPageValidateCommand(WKPageRef pageRef, WKStringRef command, void* context, WKPageValidateCommandCallback callback)
2047 toImpl(pageRef)->validateCommand(toImpl(command)->string(), [context, callback](const String& commandName, bool isEnabled, int32_t state, WebKit::CallbackBase::Error error) {
2048 callback(toAPI(API::String::create(commandName).ptr()), isEnabled, state, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
2052 void WKPageExecuteCommand(WKPageRef pageRef, WKStringRef command)
2054 toImpl(pageRef)->executeEditCommand(toImpl(command)->string());
2058 static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo)
2061 result.pageSetupScaleFactor = printInfo.pageSetupScaleFactor;
2062 result.availablePaperWidth = printInfo.availablePaperWidth;
2063 result.availablePaperHeight = printInfo.availablePaperHeight;
2067 void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, WKPageComputePagesForPrintingFunction callback, void* context)
2069 toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create([context, callback](const Vector<WebCore::IntRect>& rects, double scaleFactor, WebKit::CallbackBase::Error error) {
2070 Vector<WKRect> wkRects(rects.size());
2071 for (size_t i = 0; i < rects.size(); ++i)
2072 wkRects[i] = toAPI(rects[i]);
2073 callback(wkRects.data(), wkRects.size(), scaleFactor, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
2077 void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo)
2079 toImpl(page)->beginPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo));
2082 void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
2084 toImpl(page)->drawPagesToPDF(toImpl(frame), printInfoFromWKPrintInfo(printInfo), first, count, DataCallback::create(toGenericCallbackFunction(context, callback)));
2087 void WKPageEndPrinting(WKPageRef page)
2089 toImpl(page)->endPrinting();
2093 void WKPageSetShouldSendEventsSynchronously(WKPageRef page, bool sync)
2095 toImpl(page)->setShouldSendEventsSynchronously(sync);
2098 bool WKPageGetAllowsRemoteInspection(WKPageRef page)
2100 #if ENABLE(REMOTE_INSPECTOR)
2101 return toImpl(page)->allowsRemoteInspection();
2108 void WKPageSetAllowsRemoteInspection(WKPageRef page, bool allow)
2110 #if ENABLE(REMOTE_INSPECTOR)
2111 toImpl(page)->setAllowsRemoteInspection(allow);
2114 UNUSED_PARAM(allow);
2118 void WKPageSetMediaVolume(WKPageRef page, float volume)
2120 toImpl(page)->setMediaVolume(volume);
2123 void WKPageSetMuted(WKPageRef page, bool muted)
2125 toImpl(page)->setMuted(muted);
2128 void WKPageHandleMediaEvent(WKPageRef page, WKMediaEventType wkEventType)
2130 #if ENABLE(MEDIA_SESSION)
2131 MediaEventType eventType;
2133 switch (wkEventType) {
2134 case kWKMediaEventTypePlayPause:
2135 eventType = MediaEventType::PlayPause;
2137 case kWKMediaEventTypeTrackNext:
2138 eventType = MediaEventType::TrackNext;
2140 case kWKMediaEventTypeTrackPrevious:
2141 eventType = MediaEventType::TrackPrevious;
2144 ASSERT_NOT_REACHED();
2147 toImpl(page)->handleMediaEvent(eventType);
2150 UNUSED_PARAM(wkEventType);
2154 void WKPagePostMessageToInjectedBundle(WKPageRef pageRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef)
2156 toImpl(pageRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef));
2159 WKArrayRef WKPageCopyRelatedPages(WKPageRef pageRef)
2161 Vector<RefPtr<API::Object>> relatedPages;
2163 for (auto& page : toImpl(pageRef)->process().pages()) {
2164 if (page != toImpl(pageRef))
2165 relatedPages.append(page);
2168 return toAPI(&API::Array::create(WTF::move(relatedPages)).leakRef());
2171 void WKPageSetMayStartMediaWhenInWindow(WKPageRef pageRef, bool mayStartMedia)
2173 toImpl(pageRef)->setMayStartMediaWhenInWindow(mayStartMedia);
2177 void WKPageSelectContextMenuItem(WKPageRef page, WKContextMenuItemRef item)
2179 #if ENABLE(CONTEXT_MENUS)
2180 toImpl(page)->contextMenuItemSelected(*(toImpl(item)->data()));
2187 WKScrollPinningBehavior WKPageGetScrollPinningBehavior(WKPageRef page)
2189 ScrollPinningBehavior pinning = toImpl(page)->scrollPinningBehavior();
2192 case WebCore::ScrollPinningBehavior::DoNotPin:
2193 return kWKScrollPinningBehaviorDoNotPin;
2194 case WebCore::ScrollPinningBehavior::PinToTop:
2195 return kWKScrollPinningBehaviorPinToTop;
2196 case WebCore::ScrollPinningBehavior::PinToBottom:
2197 return kWKScrollPinningBehaviorPinToBottom;
2200 ASSERT_NOT_REACHED();
2201 return kWKScrollPinningBehaviorDoNotPin;
2204 void WKPageSetScrollPinningBehavior(WKPageRef page, WKScrollPinningBehavior pinning)
2206 ScrollPinningBehavior corePinning = ScrollPinningBehavior::DoNotPin;
2209 case kWKScrollPinningBehaviorDoNotPin:
2210 corePinning = ScrollPinningBehavior::DoNotPin;
2212 case kWKScrollPinningBehaviorPinToTop:
2213 corePinning = ScrollPinningBehavior::PinToTop;
2215 case kWKScrollPinningBehaviorPinToBottom:
2216 corePinning = ScrollPinningBehavior::PinToBottom;
2219 ASSERT_NOT_REACHED();
2222 toImpl(page)->setScrollPinningBehavior(corePinning);
2225 bool WKPageGetAddsVisitedLinks(WKPageRef page)
2227 return toImpl(page)->addsVisitedLinks();
2230 void WKPageSetAddsVisitedLinks(WKPageRef page, bool addsVisitedLinks)
2232 toImpl(page)->setAddsVisitedLinks(addsVisitedLinks);
2235 bool WKPageIsPlayingAudio(WKPageRef page)
2237 return toImpl(page)->isPlayingAudio();
2240 void WKPageClearWheelEventTestTrigger(WKPageRef pageRef)
2242 toImpl(pageRef)->clearWheelEventTestTrigger();
2246 #if ENABLE(NETSCAPE_PLUGIN_API)
2250 WKStringRef WKPageGetPluginInformationBundleIdentifierKey()
2252 return WKPluginInformationBundleIdentifierKey();
2255 WKStringRef WKPageGetPluginInformationBundleVersionKey()
2257 return WKPluginInformationBundleVersionKey();
2260 WKStringRef WKPageGetPluginInformationDisplayNameKey()
2262 return WKPluginInformationDisplayNameKey();
2265 WKStringRef WKPageGetPluginInformationFrameURLKey()
2267 return WKPluginInformationFrameURLKey();
2270 WKStringRef WKPageGetPluginInformationMIMETypeKey()
2272 return WKPluginInformationMIMETypeKey();
2275 WKStringRef WKPageGetPluginInformationPageURLKey()
2277 return WKPluginInformationPageURLKey();
2280 WKStringRef WKPageGetPluginInformationPluginspageAttributeURLKey()
2282 return WKPluginInformationPluginspageAttributeURLKey();
2285 WKStringRef WKPageGetPluginInformationPluginURLKey()
2287 return WKPluginInformationPluginURLKey();
2292 #endif // ENABLE(NETSCAPE_PLUGIN_API)