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 using namespace WebCore;
82 using namespace WebKit;
85 template<> struct ClientTraits<WKPageLoaderClientBase> {
86 typedef std::tuple<WKPageLoaderClientV0, WKPageLoaderClientV1, WKPageLoaderClientV2, WKPageLoaderClientV3, WKPageLoaderClientV4, WKPageLoaderClientV5, WKPageLoaderClientV6> Versions;
89 template<> struct ClientTraits<WKPageNavigationClientBase> {
90 typedef std::tuple<WKPageNavigationClientV0> Versions;
93 template<> struct ClientTraits<WKPagePolicyClientBase> {
94 typedef std::tuple<WKPagePolicyClientV0, WKPagePolicyClientV1, WKPagePolicyClientInternal> Versions;
97 template<> struct ClientTraits<WKPageUIClientBase> {
98 typedef std::tuple<WKPageUIClientV0, WKPageUIClientV1, WKPageUIClientV2, WKPageUIClientV3, WKPageUIClientV4, WKPageUIClientV5> Versions;
101 #if ENABLE(CONTEXT_MENUS)
102 template<> struct ClientTraits<WKPageContextMenuClientBase> {
103 typedef std::tuple<WKPageContextMenuClientV0, WKPageContextMenuClientV1, WKPageContextMenuClientV2, WKPageContextMenuClientV3> Versions;
109 WKTypeID WKPageGetTypeID()
111 return toAPI(WebPageProxy::APIType);
114 WKContextRef WKPageGetContext(WKPageRef pageRef)
116 return toAPI(&toImpl(pageRef)->process().processPool());
119 WKPageGroupRef WKPageGetPageGroup(WKPageRef pageRef)
121 return toAPI(&toImpl(pageRef)->pageGroup());
124 void WKPageLoadURL(WKPageRef pageRef, WKURLRef URLRef)
126 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)));
129 void WKPageLoadURLWithShouldOpenExternalURLsPolicy(WKPageRef pageRef, WKURLRef URLRef, bool shouldOpenExternalURLs)
131 ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLs ? ShouldOpenExternalURLsPolicy::ShouldAllow : ShouldOpenExternalURLsPolicy::ShouldNotAllow;
132 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), shouldOpenExternalURLsPolicy);
135 void WKPageLoadURLWithUserData(WKPageRef pageRef, WKURLRef URLRef, WKTypeRef userDataRef)
137 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef));
140 void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef)
142 toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest());
145 void WKPageLoadURLRequestWithUserData(WKPageRef pageRef, WKURLRequestRef urlRequestRef, WKTypeRef userDataRef)
147 toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest(), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef));
150 void WKPageLoadFile(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL)
152 toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL));
155 void WKPageLoadFileWithUserData(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL, WKTypeRef userDataRef)
157 toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL), toImpl(userDataRef));
160 void WKPageLoadData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef)
162 toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef));
165 void WKPageLoadDataWithUserData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
167 toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef), toImpl(userDataRef));
170 void WKPageLoadHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef)
172 toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef));
175 void WKPageLoadHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
177 toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toImpl(userDataRef));
180 void WKPageLoadAlternateHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef)
182 toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef));
185 void WKPageLoadAlternateHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef, WKTypeRef userDataRef)
187 toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef), toImpl(userDataRef));
190 void WKPageLoadPlainTextString(WKPageRef pageRef, WKStringRef plainTextStringRef)
192 toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef));
195 void WKPageLoadPlainTextStringWithUserData(WKPageRef pageRef, WKStringRef plainTextStringRef, WKTypeRef userDataRef)
197 toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef), toImpl(userDataRef));
200 void WKPageLoadWebArchiveData(WKPageRef pageRef, WKDataRef webArchiveDataRef)
202 toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef));
205 void WKPageLoadWebArchiveDataWithUserData(WKPageRef pageRef, WKDataRef webArchiveDataRef, WKTypeRef userDataRef)
207 toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef), toImpl(userDataRef));
210 void WKPageStopLoading(WKPageRef pageRef)
212 toImpl(pageRef)->stopLoading();
215 void WKPageReload(WKPageRef pageRef)
217 toImpl(pageRef)->reload(false);
220 void WKPageReloadFromOrigin(WKPageRef pageRef)
222 toImpl(pageRef)->reload(true);
225 bool WKPageTryClose(WKPageRef pageRef)
227 return toImpl(pageRef)->tryClose();
230 void WKPageClose(WKPageRef pageRef)
232 toImpl(pageRef)->close();
235 bool WKPageIsClosed(WKPageRef pageRef)
237 return toImpl(pageRef)->isClosed();
240 void WKPageGoForward(WKPageRef pageRef)
242 toImpl(pageRef)->goForward();
245 bool WKPageCanGoForward(WKPageRef pageRef)
247 return toImpl(pageRef)->backForwardList().forwardItem();
250 void WKPageGoBack(WKPageRef pageRef)
252 toImpl(pageRef)->goBack();
255 bool WKPageCanGoBack(WKPageRef pageRef)
257 return toImpl(pageRef)->backForwardList().backItem();
260 void WKPageGoToBackForwardListItem(WKPageRef pageRef, WKBackForwardListItemRef itemRef)
262 toImpl(pageRef)->goToBackForwardItem(toImpl(itemRef));
265 void WKPageTryRestoreScrollPosition(WKPageRef pageRef)
267 toImpl(pageRef)->tryRestoreScrollPosition();
270 WKBackForwardListRef WKPageGetBackForwardList(WKPageRef pageRef)
272 return toAPI(&toImpl(pageRef)->backForwardList());
275 bool WKPageWillHandleHorizontalScrollEvents(WKPageRef pageRef)
277 return toImpl(pageRef)->willHandleHorizontalScrollEvents();
280 WKStringRef WKPageCopyTitle(WKPageRef pageRef)
282 return toCopiedAPI(toImpl(pageRef)->pageLoadState().title());
285 WKFrameRef WKPageGetMainFrame(WKPageRef pageRef)
287 return toAPI(toImpl(pageRef)->mainFrame());
290 WKFrameRef WKPageGetFocusedFrame(WKPageRef pageRef)
292 return toAPI(toImpl(pageRef)->focusedFrame());
295 WKFrameRef WKPageGetFrameSetLargestFrame(WKPageRef pageRef)
297 return toAPI(toImpl(pageRef)->frameSetLargestFrame());
300 uint64_t WKPageGetRenderTreeSize(WKPageRef page)
302 return toImpl(page)->renderTreeSize();
305 WKInspectorRef WKPageGetInspector(WKPageRef pageRef)
307 return toAPI(toImpl(pageRef)->inspector());
310 WKVibrationRef WKPageGetVibration(WKPageRef page)
312 #if ENABLE(VIBRATION)
313 return toAPI(toImpl(page)->vibration());
320 double WKPageGetEstimatedProgress(WKPageRef pageRef)
322 return toImpl(pageRef)->estimatedProgress();
325 WKStringRef WKPageCopyUserAgent(WKPageRef pageRef)
327 return toCopiedAPI(toImpl(pageRef)->userAgent());
330 WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef pageRef)
332 return toCopiedAPI(toImpl(pageRef)->applicationNameForUserAgent());
335 void WKPageSetApplicationNameForUserAgent(WKPageRef pageRef, WKStringRef applicationNameRef)
337 toImpl(pageRef)->setApplicationNameForUserAgent(toWTFString(applicationNameRef));
340 WKStringRef WKPageCopyCustomUserAgent(WKPageRef pageRef)
342 return toCopiedAPI(toImpl(pageRef)->customUserAgent());
345 void WKPageSetCustomUserAgent(WKPageRef pageRef, WKStringRef userAgentRef)
347 toImpl(pageRef)->setCustomUserAgent(toWTFString(userAgentRef));
350 bool WKPageSupportsTextEncoding(WKPageRef pageRef)
352 return toImpl(pageRef)->supportsTextEncoding();
355 WKStringRef WKPageCopyCustomTextEncodingName(WKPageRef pageRef)
357 return toCopiedAPI(toImpl(pageRef)->customTextEncodingName());
360 void WKPageSetCustomTextEncodingName(WKPageRef pageRef, WKStringRef encodingNameRef)
362 toImpl(pageRef)->setCustomTextEncodingName(toWTFString(encodingNameRef));
365 void WKPageTerminate(WKPageRef pageRef)
367 toImpl(pageRef)->terminateProcess();
370 WKStringRef WKPageGetSessionHistoryURLValueType()
372 static API::String& sessionHistoryURLValueType = API::String::create("SessionHistoryURL").leakRef();
373 return toAPI(&sessionHistoryURLValueType);
376 WKStringRef WKPageGetSessionBackForwardListItemValueType()
378 static API::String& sessionBackForwardListValueType = API::String::create("SessionBackForwardListItem").leakRef();
379 return toAPI(&sessionBackForwardListValueType);
382 WKTypeRef WKPageCopySessionState(WKPageRef pageRef, void* context, WKPageSessionStateFilterCallback filter)
384 // FIXME: This is a hack to make sure we return a WKDataRef to maintain compatibility with older versions of Safari.
385 bool shouldReturnData = !(reinterpret_cast<uintptr_t>(context) & 1);
386 context = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(context) & ~1);
388 auto sessionState = toImpl(pageRef)->sessionState([pageRef, context, filter](WebBackForwardListItem& item) {
390 if (!filter(pageRef, WKPageGetSessionBackForwardListItemValueType(), toAPI(&item), context))
393 if (!filter(pageRef, WKPageGetSessionHistoryURLValueType(), toURLRef(item.originalURL().impl()), context))
400 if (shouldReturnData)
401 return toAPI(encodeLegacySessionState(sessionState).release().leakRef());
403 return toAPI(API::SessionState::create(WTF::move(sessionState)).leakRef());
406 void WKPageRestoreFromSessionState(WKPageRef pageRef, WKTypeRef sessionStateRef)
408 SessionState sessionState;
410 // FIXME: This is for backwards compatibility with Safari. Remove it once Safari no longer depends on it.
411 if (toImpl(sessionStateRef)->type() == API::Object::Type::Data) {
412 if (!decodeLegacySessionState(toImpl(static_cast<WKDataRef>(sessionStateRef))->bytes(), toImpl(static_cast<WKDataRef>(sessionStateRef))->size(), sessionState))
415 ASSERT(toImpl(sessionStateRef)->type() == API::Object::Type::SessionState);
417 sessionState = toImpl(static_cast<WKSessionStateRef>(sessionStateRef))->sessionState();
420 toImpl(pageRef)->restoreFromSessionState(WTF::move(sessionState), true);
423 double WKPageGetTextZoomFactor(WKPageRef pageRef)
425 return toImpl(pageRef)->textZoomFactor();
428 double WKPageGetBackingScaleFactor(WKPageRef pageRef)
430 return toImpl(pageRef)->deviceScaleFactor();
433 void WKPageSetCustomBackingScaleFactor(WKPageRef pageRef, double customScaleFactor)
435 toImpl(pageRef)->setCustomDeviceScaleFactor(customScaleFactor);
438 bool WKPageSupportsTextZoom(WKPageRef pageRef)
440 return toImpl(pageRef)->supportsTextZoom();
443 void WKPageSetTextZoomFactor(WKPageRef pageRef, double zoomFactor)
445 toImpl(pageRef)->setTextZoomFactor(zoomFactor);
448 double WKPageGetPageZoomFactor(WKPageRef pageRef)
450 return toImpl(pageRef)->pageZoomFactor();
453 void WKPageSetPageZoomFactor(WKPageRef pageRef, double zoomFactor)
455 toImpl(pageRef)->setPageZoomFactor(zoomFactor);
458 void WKPageSetPageAndTextZoomFactors(WKPageRef pageRef, double pageZoomFactor, double textZoomFactor)
460 toImpl(pageRef)->setPageAndTextZoomFactors(pageZoomFactor, textZoomFactor);
463 void WKPageSetScaleFactor(WKPageRef pageRef, double scale, WKPoint origin)
465 toImpl(pageRef)->scalePage(scale, toIntPoint(origin));
468 double WKPageGetScaleFactor(WKPageRef pageRef)
470 return toImpl(pageRef)->pageScaleFactor();
473 void WKPageSetUseFixedLayout(WKPageRef pageRef, bool fixed)
475 toImpl(pageRef)->setUseFixedLayout(fixed);
478 void WKPageSetFixedLayoutSize(WKPageRef pageRef, WKSize size)
480 toImpl(pageRef)->setFixedLayoutSize(toIntSize(size));
483 bool WKPageUseFixedLayout(WKPageRef pageRef)
485 return toImpl(pageRef)->useFixedLayout();
488 WKSize WKPageFixedLayoutSize(WKPageRef pageRef)
490 return toAPI(toImpl(pageRef)->fixedLayoutSize());
493 void WKPageListenForLayoutMilestones(WKPageRef pageRef, WKLayoutMilestones milestones)
495 toImpl(pageRef)->listenForLayoutMilestones(toLayoutMilestones(milestones));
498 bool WKPageHasHorizontalScrollbar(WKPageRef pageRef)
500 return toImpl(pageRef)->hasHorizontalScrollbar();
503 bool WKPageHasVerticalScrollbar(WKPageRef pageRef)
505 return toImpl(pageRef)->hasVerticalScrollbar();
508 void WKPageSetSuppressScrollbarAnimations(WKPageRef pageRef, bool suppressAnimations)
510 toImpl(pageRef)->setSuppressScrollbarAnimations(suppressAnimations);
513 bool WKPageAreScrollbarAnimationsSuppressed(WKPageRef pageRef)
515 return toImpl(pageRef)->areScrollbarAnimationsSuppressed();
518 bool WKPageIsPinnedToLeftSide(WKPageRef pageRef)
520 return toImpl(pageRef)->isPinnedToLeftSide();
523 bool WKPageIsPinnedToRightSide(WKPageRef pageRef)
525 return toImpl(pageRef)->isPinnedToRightSide();
528 bool WKPageIsPinnedToTopSide(WKPageRef pageRef)
530 return toImpl(pageRef)->isPinnedToTopSide();
533 bool WKPageIsPinnedToBottomSide(WKPageRef pageRef)
535 return toImpl(pageRef)->isPinnedToBottomSide();
538 bool WKPageRubberBandsAtLeft(WKPageRef pageRef)
540 return toImpl(pageRef)->rubberBandsAtLeft();
543 void WKPageSetRubberBandsAtLeft(WKPageRef pageRef, bool rubberBandsAtLeft)
545 toImpl(pageRef)->setRubberBandsAtLeft(rubberBandsAtLeft);
548 bool WKPageRubberBandsAtRight(WKPageRef pageRef)
550 return toImpl(pageRef)->rubberBandsAtRight();
553 void WKPageSetRubberBandsAtRight(WKPageRef pageRef, bool rubberBandsAtRight)
555 toImpl(pageRef)->setRubberBandsAtRight(rubberBandsAtRight);
558 bool WKPageRubberBandsAtTop(WKPageRef pageRef)
560 return toImpl(pageRef)->rubberBandsAtTop();
563 void WKPageSetRubberBandsAtTop(WKPageRef pageRef, bool rubberBandsAtTop)
565 toImpl(pageRef)->setRubberBandsAtTop(rubberBandsAtTop);
568 bool WKPageRubberBandsAtBottom(WKPageRef pageRef)
570 return toImpl(pageRef)->rubberBandsAtBottom();
573 void WKPageSetRubberBandsAtBottom(WKPageRef pageRef, bool rubberBandsAtBottom)
575 toImpl(pageRef)->setRubberBandsAtBottom(rubberBandsAtBottom);
578 bool WKPageVerticalRubberBandingIsEnabled(WKPageRef pageRef)
580 return toImpl(pageRef)->verticalRubberBandingIsEnabled();
583 void WKPageSetEnableVerticalRubberBanding(WKPageRef pageRef, bool enableVerticalRubberBanding)
585 toImpl(pageRef)->setEnableVerticalRubberBanding(enableVerticalRubberBanding);
588 bool WKPageHorizontalRubberBandingIsEnabled(WKPageRef pageRef)
590 return toImpl(pageRef)->horizontalRubberBandingIsEnabled();
593 void WKPageSetEnableHorizontalRubberBanding(WKPageRef pageRef, bool enableHorizontalRubberBanding)
595 toImpl(pageRef)->setEnableHorizontalRubberBanding(enableHorizontalRubberBanding);
598 void WKPageSetBackgroundExtendsBeyondPage(WKPageRef pageRef, bool backgroundExtendsBeyondPage)
600 toImpl(pageRef)->setBackgroundExtendsBeyondPage(backgroundExtendsBeyondPage);
603 bool WKPageBackgroundExtendsBeyondPage(WKPageRef pageRef)
605 return toImpl(pageRef)->backgroundExtendsBeyondPage();
608 void WKPageSetPaginationMode(WKPageRef pageRef, WKPaginationMode paginationMode)
610 Pagination::Mode mode;
611 switch (paginationMode) {
612 case kWKPaginationModeUnpaginated:
613 mode = Pagination::Unpaginated;
615 case kWKPaginationModeLeftToRight:
616 mode = Pagination::LeftToRightPaginated;
618 case kWKPaginationModeRightToLeft:
619 mode = Pagination::RightToLeftPaginated;
621 case kWKPaginationModeTopToBottom:
622 mode = Pagination::TopToBottomPaginated;
624 case kWKPaginationModeBottomToTop:
625 mode = Pagination::BottomToTopPaginated;
630 toImpl(pageRef)->setPaginationMode(mode);
633 WKPaginationMode WKPageGetPaginationMode(WKPageRef pageRef)
635 switch (toImpl(pageRef)->paginationMode()) {
636 case Pagination::Unpaginated:
637 return kWKPaginationModeUnpaginated;
638 case Pagination::LeftToRightPaginated:
639 return kWKPaginationModeLeftToRight;
640 case Pagination::RightToLeftPaginated:
641 return kWKPaginationModeRightToLeft;
642 case Pagination::TopToBottomPaginated:
643 return kWKPaginationModeTopToBottom;
644 case Pagination::BottomToTopPaginated:
645 return kWKPaginationModeBottomToTop;
648 ASSERT_NOT_REACHED();
649 return kWKPaginationModeUnpaginated;
652 void WKPageSetPaginationBehavesLikeColumns(WKPageRef pageRef, bool behavesLikeColumns)
654 toImpl(pageRef)->setPaginationBehavesLikeColumns(behavesLikeColumns);
657 bool WKPageGetPaginationBehavesLikeColumns(WKPageRef pageRef)
659 return toImpl(pageRef)->paginationBehavesLikeColumns();
662 void WKPageSetPageLength(WKPageRef pageRef, double pageLength)
664 toImpl(pageRef)->setPageLength(pageLength);
667 double WKPageGetPageLength(WKPageRef pageRef)
669 return toImpl(pageRef)->pageLength();
672 void WKPageSetGapBetweenPages(WKPageRef pageRef, double gap)
674 toImpl(pageRef)->setGapBetweenPages(gap);
677 double WKPageGetGapBetweenPages(WKPageRef pageRef)
679 return toImpl(pageRef)->gapBetweenPages();
682 unsigned WKPageGetPageCount(WKPageRef pageRef)
684 return toImpl(pageRef)->pageCount();
687 bool WKPageCanDelete(WKPageRef pageRef)
689 return toImpl(pageRef)->canDelete();
692 bool WKPageHasSelectedRange(WKPageRef pageRef)
694 return toImpl(pageRef)->hasSelectedRange();
697 bool WKPageIsContentEditable(WKPageRef pageRef)
699 return toImpl(pageRef)->isContentEditable();
702 void WKPageSetMaintainsInactiveSelection(WKPageRef pageRef, bool newValue)
704 return toImpl(pageRef)->setMaintainsInactiveSelection(newValue);
707 void WKPageCenterSelectionInVisibleArea(WKPageRef pageRef)
709 return toImpl(pageRef)->centerSelectionInVisibleArea();
712 void WKPageFindStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
714 toImpl(pageRef)->findStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
717 void WKPageGetImageForFindMatch(WKPageRef pageRef, int32_t matchIndex)
719 toImpl(pageRef)->getImageForFindMatch(matchIndex);
722 void WKPageSelectFindMatch(WKPageRef pageRef, int32_t matchIndex)
724 toImpl(pageRef)->selectFindMatch(matchIndex);
727 void WKPageFindString(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
729 toImpl(pageRef)->findString(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
732 void WKPageHideFindUI(WKPageRef pageRef)
734 toImpl(pageRef)->hideFindUI();
737 void WKPageCountStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
739 toImpl(pageRef)->countStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
742 void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuClientBase* wkClient)
744 #if ENABLE(CONTEXT_MENUS)
745 class ContextMenuClient final : public API::Client<WKPageContextMenuClientBase>, public API::ContextMenuClient {
747 explicit ContextMenuClient(const WKPageContextMenuClientBase* client)
753 virtual bool getContextMenuFromProposedMenu(WebPageProxy& page, const Vector<RefPtr<WebKit::WebContextMenuItem>>& proposedMenuVector, Vector<RefPtr<WebKit::WebContextMenuItem>>& customMenu, const WebHitTestResult::Data& hitTestResultData, API::Object* userData) override
755 if (!m_client.getContextMenuFromProposedMenu && !m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0)
758 if (m_client.base.version >= 2 && !m_client.getContextMenuFromProposedMenu)
761 Vector<RefPtr<API::Object>> proposedMenuItems;
762 proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size());
764 for (const auto& menuItem : proposedMenuVector)
765 proposedMenuItems.uncheckedAppend(menuItem);
767 WKArrayRef newMenu = nullptr;
768 if (m_client.base.version >= 2) {
769 RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(hitTestResultData);
770 m_client.getContextMenuFromProposedMenu(toAPI(&page), toAPI(API::Array::create(WTF::move(proposedMenuItems)).ptr()), &newMenu, toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo);
772 m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0(toAPI(&page), toAPI(API::Array::create(WTF::move(proposedMenuItems)).ptr()), &newMenu, toAPI(userData), m_client.base.clientInfo);
774 RefPtr<API::Array> array = adoptRef(toImpl(newMenu));
778 size_t newSize = array ? array->size() : 0;
779 for (size_t i = 0; i < newSize; ++i) {
780 WebContextMenuItem* item = array->at<WebContextMenuItem>(i);
782 LOG(ContextMenu, "New menu entry at index %i is not a WebContextMenuItem", (int)i);
786 customMenu.append(item);
792 virtual void customContextMenuItemSelected(WebPageProxy& page, const WebContextMenuItemData& itemData) override
794 if (!m_client.customContextMenuItemSelected)
797 m_client.customContextMenuItemSelected(toAPI(&page), toAPI(WebContextMenuItem::create(itemData).get()), m_client.base.clientInfo);
800 virtual void contextMenuDismissed(WebPageProxy& page) override
802 if (!m_client.contextMenuDismissed)
805 m_client.contextMenuDismissed(toAPI(&page), m_client.base.clientInfo);
808 virtual bool showContextMenu(WebPageProxy& page, const WebCore::IntPoint& menuLocation, const Vector<RefPtr<WebContextMenuItem>>& menuItemsVector) override
810 if (!m_client.showContextMenu)
813 Vector<RefPtr<API::Object>> menuItems;
814 menuItems.reserveInitialCapacity(menuItemsVector.size());
816 for (const auto& menuItem : menuItemsVector)
817 menuItems.uncheckedAppend(menuItem);
819 m_client.showContextMenu(toAPI(&page), toAPI(menuLocation), toAPI(API::Array::create(WTF::move(menuItems)).ptr()), m_client.base.clientInfo);
824 virtual bool hideContextMenu(WebPageProxy& page) override
826 if (!m_client.hideContextMenu)
829 m_client.hideContextMenu(toAPI(&page), m_client.base.clientInfo);
835 toImpl(pageRef)->setContextMenuClient(std::make_unique<ContextMenuClient>(wkClient));
837 UNUSED_PARAM(pageRef);
838 UNUSED_PARAM(wkClient);
842 void WKPageSetPageDiagnosticLoggingClient(WKPageRef pageRef, const WKPageDiagnosticLoggingClientBase* wkClient)
844 toImpl(pageRef)->setDiagnosticLoggingClient(std::make_unique<WebPageDiagnosticLoggingClient>(wkClient));
847 void WKPageSetPageFindClient(WKPageRef pageRef, const WKPageFindClientBase* wkClient)
849 class FindClient : public API::Client<WKPageFindClientBase>, public API::FindClient {
851 explicit FindClient(const WKPageFindClientBase* client)
857 virtual void didFindString(WebPageProxy* page, const String& string, uint32_t matchCount, int32_t) override
859 if (!m_client.didFindString)
862 m_client.didFindString(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
865 virtual void didFailToFindString(WebPageProxy* page, const String& string) override
867 if (!m_client.didFailToFindString)
870 m_client.didFailToFindString(toAPI(page), toAPI(string.impl()), m_client.base.clientInfo);
873 virtual void didCountStringMatches(WebPageProxy* page, const String& string, uint32_t matchCount) override
875 if (!m_client.didCountStringMatches)
878 m_client.didCountStringMatches(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
882 toImpl(pageRef)->setFindClient(std::make_unique<FindClient>(wkClient));
885 void WKPageSetPageFindMatchesClient(WKPageRef pageRef, const WKPageFindMatchesClientBase* wkClient)
887 toImpl(pageRef)->initializeFindMatchesClient(wkClient);
890 void WKPageSetPageInjectedBundleClient(WKPageRef pageRef, const WKPageInjectedBundleClientBase* wkClient)
892 toImpl(pageRef)->setInjectedBundleClient(wkClient);
895 void WKPageSetPageFormClient(WKPageRef pageRef, const WKPageFormClientBase* wkClient)
897 toImpl(pageRef)->setFormClient(std::make_unique<WebFormClient>(wkClient));
900 void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase* wkClient)
902 class LoaderClient : public API::Client<WKPageLoaderClientBase>, public API::LoaderClient {
904 explicit LoaderClient(const WKPageLoaderClientBase* client)
910 virtual void didStartProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
912 if (!m_client.didStartProvisionalLoadForFrame)
915 m_client.didStartProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
918 virtual void didReceiveServerRedirectForProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
920 if (!m_client.didReceiveServerRedirectForProvisionalLoadForFrame)
923 m_client.didReceiveServerRedirectForProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
926 virtual void didFailProvisionalLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
928 if (!m_client.didFailProvisionalLoadWithErrorForFrame)
931 m_client.didFailProvisionalLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
934 virtual void didCommitLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
936 if (!m_client.didCommitLoadForFrame)
939 m_client.didCommitLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
942 virtual void didFinishDocumentLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
944 if (!m_client.didFinishDocumentLoadForFrame)
947 m_client.didFinishDocumentLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
950 virtual void didFinishLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
952 if (!m_client.didFinishLoadForFrame)
955 m_client.didFinishLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
958 virtual void didFailLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
960 if (!m_client.didFailLoadWithErrorForFrame)
963 m_client.didFailLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
966 virtual void didSameDocumentNavigationForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, SameDocumentNavigationType type, API::Object* userData) override
968 if (!m_client.didSameDocumentNavigationForFrame)
971 m_client.didSameDocumentNavigationForFrame(toAPI(&page), toAPI(&frame), toAPI(type), toAPI(userData), m_client.base.clientInfo);
974 virtual void didReceiveTitleForFrame(WebPageProxy& page, const String& title, WebFrameProxy& frame, API::Object* userData) override
976 if (!m_client.didReceiveTitleForFrame)
979 m_client.didReceiveTitleForFrame(toAPI(&page), toAPI(title.impl()), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
982 virtual void didFirstLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
984 if (!m_client.didFirstLayoutForFrame)
987 m_client.didFirstLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
990 virtual void didFirstVisuallyNonEmptyLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
992 if (!m_client.didFirstVisuallyNonEmptyLayoutForFrame)
995 m_client.didFirstVisuallyNonEmptyLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
998 virtual void didLayout(WebPageProxy& page, LayoutMilestones milestones, API::Object* userData) override
1000 if (!m_client.didLayout)
1003 m_client.didLayout(toAPI(&page), toWKLayoutMilestones(milestones), toAPI(userData), m_client.base.clientInfo);
1006 virtual void didRemoveFrameFromHierarchy(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1008 if (!m_client.didRemoveFrameFromHierarchy)
1011 m_client.didRemoveFrameFromHierarchy(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1014 virtual void didDisplayInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1016 if (!m_client.didDisplayInsecureContentForFrame)
1019 m_client.didDisplayInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1022 virtual void didRunInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1024 if (!m_client.didRunInsecureContentForFrame)
1027 m_client.didRunInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1030 virtual void didDetectXSSForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1032 if (!m_client.didDetectXSSForFrame)
1035 m_client.didDetectXSSForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1038 virtual bool canAuthenticateAgainstProtectionSpaceInFrame(WebPageProxy& page, WebFrameProxy& frame, WebProtectionSpace* protectionSpace) override
1040 if (!m_client.canAuthenticateAgainstProtectionSpaceInFrame)
1043 return m_client.canAuthenticateAgainstProtectionSpaceInFrame(toAPI(&page), toAPI(&frame), toAPI(protectionSpace), m_client.base.clientInfo);
1046 virtual void didReceiveAuthenticationChallengeInFrame(WebPageProxy& page, WebFrameProxy& frame, AuthenticationChallengeProxy* authenticationChallenge) override
1048 if (!m_client.didReceiveAuthenticationChallengeInFrame)
1051 m_client.didReceiveAuthenticationChallengeInFrame(toAPI(&page), toAPI(&frame), toAPI(authenticationChallenge), m_client.base.clientInfo);
1054 virtual void didStartProgress(WebPageProxy& page) override
1056 if (!m_client.didStartProgress)
1059 m_client.didStartProgress(toAPI(&page), m_client.base.clientInfo);
1062 virtual void didChangeProgress(WebPageProxy& page) override
1064 if (!m_client.didChangeProgress)
1067 m_client.didChangeProgress(toAPI(&page), m_client.base.clientInfo);
1070 virtual void didFinishProgress(WebPageProxy& page) override
1072 if (!m_client.didFinishProgress)
1075 m_client.didFinishProgress(toAPI(&page), m_client.base.clientInfo);
1078 virtual void processDidBecomeUnresponsive(WebPageProxy& page) override
1080 if (!m_client.processDidBecomeUnresponsive)
1083 m_client.processDidBecomeUnresponsive(toAPI(&page), m_client.base.clientInfo);
1086 virtual void interactionOccurredWhileProcessUnresponsive(WebPageProxy& page) override
1088 if (!m_client.interactionOccurredWhileProcessUnresponsive)
1091 m_client.interactionOccurredWhileProcessUnresponsive(toAPI(&page), m_client.base.clientInfo);
1094 virtual void processDidBecomeResponsive(WebPageProxy& page) override
1096 if (!m_client.processDidBecomeResponsive)
1099 m_client.processDidBecomeResponsive(toAPI(&page), m_client.base.clientInfo);
1102 virtual void processDidCrash(WebPageProxy& page) override
1104 if (!m_client.processDidCrash)
1107 m_client.processDidCrash(toAPI(&page), m_client.base.clientInfo);
1110 virtual void didChangeBackForwardList(WebPageProxy& page, WebBackForwardListItem* addedItem, Vector<RefPtr<WebBackForwardListItem>> removedItems) override
1112 if (!m_client.didChangeBackForwardList)
1115 RefPtr<API::Array> removedItemsArray;
1116 if (!removedItems.isEmpty()) {
1117 Vector<RefPtr<API::Object>> removedItemsVector;
1118 removedItemsVector.reserveInitialCapacity(removedItems.size());
1119 for (auto& removedItem : removedItems)
1120 removedItemsVector.append(WTF::move(removedItem));
1122 removedItemsArray = API::Array::create(WTF::move(removedItemsVector));
1125 m_client.didChangeBackForwardList(toAPI(&page), toAPI(addedItem), toAPI(removedItemsArray.get()), m_client.base.clientInfo);
1128 virtual bool shouldKeepCurrentBackForwardListItemInList(WebKit::WebPageProxy& page, WebKit::WebBackForwardListItem* item) override
1130 if (!m_client.shouldKeepCurrentBackForwardListItemInList)
1133 return m_client.shouldKeepCurrentBackForwardListItemInList(toAPI(&page), toAPI(item), m_client.base.clientInfo);
1136 virtual void willGoToBackForwardListItem(WebPageProxy& page, WebBackForwardListItem* item, API::Object* userData) override
1138 if (m_client.willGoToBackForwardListItem)
1139 m_client.willGoToBackForwardListItem(toAPI(&page), toAPI(item), toAPI(userData), m_client.base.clientInfo);
1142 virtual PassRefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
1144 return page.process().processPool().client().copyWebCryptoMasterKey(&page.process().processPool());
1147 virtual void navigationGestureDidBegin(WebPageProxy& page) override
1149 if (m_client.navigationGestureDidBegin)
1150 m_client.navigationGestureDidBegin(toAPI(&page), m_client.base.clientInfo);
1153 virtual void navigationGestureWillEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override
1155 if (m_client.navigationGestureWillEnd)
1156 m_client.navigationGestureWillEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo);
1159 virtual void navigationGestureDidEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override
1161 if (m_client.navigationGestureDidEnd)
1162 m_client.navigationGestureDidEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo);
1165 #if ENABLE(NETSCAPE_PLUGIN_API)
1166 virtual void didFailToInitializePlugin(WebPageProxy& page, API::Dictionary* pluginInformation) override
1168 if (m_client.didFailToInitializePlugin_deprecatedForUseWithV0)
1169 m_client.didFailToInitializePlugin_deprecatedForUseWithV0(toAPI(&page), toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), m_client.base.clientInfo);
1171 if (m_client.pluginDidFail_deprecatedForUseWithV1)
1172 m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), 0, 0, m_client.base.clientInfo);
1174 if (m_client.pluginDidFail)
1175 m_client.pluginDidFail(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation), m_client.base.clientInfo);
1178 virtual void didBlockInsecurePluginVersion(WebPageProxy& page, API::Dictionary* pluginInformation) override
1180 if (m_client.pluginDidFail_deprecatedForUseWithV1)
1181 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);
1183 if (m_client.pluginDidFail)
1184 m_client.pluginDidFail(toAPI(&page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation), m_client.base.clientInfo);
1187 virtual PluginModuleLoadPolicy pluginLoadPolicy(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
1189 WKStringRef unavailabilityDescriptionOut = 0;
1190 PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
1192 if (m_client.pluginLoadPolicy_deprecatedForUseWithV2)
1193 loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy_deprecatedForUseWithV2(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), m_client.base.clientInfo));
1194 else if (m_client.pluginLoadPolicy)
1195 loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
1197 if (unavailabilityDescriptionOut) {
1198 RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
1199 unavailabilityDescription = webUnavailabilityDescription->string();
1204 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1207 virtual WebCore::WebGLLoadPolicy webGLLoadPolicy(WebPageProxy& page, const String& url) const override
1209 WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
1211 if (m_client.webGLLoadPolicy)
1212 loadPolicy = toWebGLLoadPolicy(m_client.webGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
1217 virtual WebCore::WebGLLoadPolicy resolveWebGLLoadPolicy(WebPageProxy& page, const String& url) const override
1219 WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
1221 if (m_client.resolveWebGLLoadPolicy)
1222 loadPolicy = toWebGLLoadPolicy(m_client.resolveWebGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
1227 #endif // ENABLE(WEBGL)
1230 WebPageProxy* webPageProxy = toImpl(pageRef);
1232 auto loaderClient = std::make_unique<LoaderClient>(wkClient);
1234 // It would be nice to get rid of this code and transition all clients to using didLayout instead of
1235 // didFirstLayoutInFrame and didFirstVisuallyNonEmptyLayoutInFrame. In the meantime, this is required
1236 // for backwards compatibility.
1237 WebCore::LayoutMilestones milestones = 0;
1238 if (loaderClient->client().didFirstLayoutForFrame)
1239 milestones |= WebCore::DidFirstLayout;
1240 if (loaderClient->client().didFirstVisuallyNonEmptyLayoutForFrame)
1241 milestones |= WebCore::DidFirstVisuallyNonEmptyLayout;
1244 webPageProxy->process().send(Messages::WebPage::ListenForLayoutMilestones(milestones), webPageProxy->pageID());
1246 webPageProxy->setLoaderClient(WTF::move(loaderClient));
1249 void WKPageSetPagePolicyClient(WKPageRef pageRef, const WKPagePolicyClientBase* wkClient)
1251 class PolicyClient : public API::Client<WKPagePolicyClientBase>, public API::PolicyClient {
1253 explicit PolicyClient(const WKPagePolicyClientBase* client)
1259 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
1261 if (!m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0 && !m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1 && !m_client.decidePolicyForNavigationAction) {
1266 Ref<API::URLRequest> originalRequest = API::URLRequest::create(originalResourceRequest);
1267 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1269 if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0)
1270 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);
1271 else if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1)
1272 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);
1274 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);
1277 virtual void decidePolicyForNewWindowAction(WebPageProxy& page, WebFrameProxy& frame, const NavigationActionData& navigationActionData, const ResourceRequest& resourceRequest, const String& frameName, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1279 if (!m_client.decidePolicyForNewWindowAction) {
1284 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1286 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);
1289 virtual void decidePolicyForResponse(WebPageProxy& page, WebFrameProxy& frame, const ResourceResponse& resourceResponse, const ResourceRequest& resourceRequest, bool canShowMIMEType, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1291 if (!m_client.decidePolicyForResponse_deprecatedForUseWithV0 && !m_client.decidePolicyForResponse) {
1296 Ref<API::URLResponse> response = API::URLResponse::create(resourceResponse);
1297 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1299 if (m_client.decidePolicyForResponse_deprecatedForUseWithV0)
1300 m_client.decidePolicyForResponse_deprecatedForUseWithV0(toAPI(&page), toAPI(&frame), toAPI(response.ptr()), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1302 m_client.decidePolicyForResponse(toAPI(&page), toAPI(&frame), toAPI(response.ptr()), toAPI(request.ptr()), canShowMIMEType, toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1305 virtual void unableToImplementPolicy(WebPageProxy& page, WebFrameProxy& frame, const ResourceError& error, API::Object* userData) override
1307 if (!m_client.unableToImplementPolicy)
1310 m_client.unableToImplementPolicy(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1314 toImpl(pageRef)->setPolicyClient(std::make_unique<PolicyClient>(wkClient));
1317 void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient)
1319 class UIClient : public API::Client<WKPageUIClientBase>, public API::UIClient {
1321 explicit UIClient(const WKPageUIClientBase* client)
1327 virtual PassRefPtr<WebPageProxy> createNewPage(WebPageProxy* page, WebFrameProxy*, const ResourceRequest& resourceRequest, const WindowFeatures& windowFeatures, const NavigationActionData& navigationActionData) override
1329 if (!m_client.base.version && !m_client.createNewPage_deprecatedForUseWithV0)
1332 if (m_client.base.version > 0 && !m_client.createNewPage)
1335 API::Dictionary::MapType map;
1336 if (windowFeatures.xSet)
1337 map.set("x", API::Double::create(windowFeatures.x));
1338 if (windowFeatures.ySet)
1339 map.set("y", API::Double::create(windowFeatures.y));
1340 if (windowFeatures.widthSet)
1341 map.set("width", API::Double::create(windowFeatures.width));
1342 if (windowFeatures.heightSet)
1343 map.set("height", API::Double::create(windowFeatures.height));
1344 map.set("menuBarVisible", API::Boolean::create(windowFeatures.menuBarVisible));
1345 map.set("statusBarVisible", API::Boolean::create(windowFeatures.statusBarVisible));
1346 map.set("toolBarVisible", API::Boolean::create(windowFeatures.toolBarVisible));
1347 map.set("locationBarVisible", API::Boolean::create(windowFeatures.locationBarVisible));
1348 map.set("scrollbarsVisible", API::Boolean::create(windowFeatures.scrollbarsVisible));
1349 map.set("resizable", API::Boolean::create(windowFeatures.resizable));
1350 map.set("fullscreen", API::Boolean::create(windowFeatures.fullscreen));
1351 map.set("dialog", API::Boolean::create(windowFeatures.dialog));
1352 Ref<API::Dictionary> featuresMap = API::Dictionary::create(WTF::move(map));
1354 if (!m_client.base.version)
1355 return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV0(toAPI(page), toAPI(featuresMap.ptr()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
1357 Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1358 return adoptRef(toImpl(m_client.createNewPage(toAPI(page), toAPI(request.ptr()), toAPI(featuresMap.ptr()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
1361 virtual void showPage(WebPageProxy* page) override
1363 if (!m_client.showPage)
1366 m_client.showPage(toAPI(page), m_client.base.clientInfo);
1369 virtual void close(WebPageProxy* page) override
1371 if (!m_client.close)
1374 m_client.close(toAPI(page), m_client.base.clientInfo);
1377 virtual void takeFocus(WebPageProxy* page, WKFocusDirection direction) override
1379 if (!m_client.takeFocus)
1382 m_client.takeFocus(toAPI(page), direction, m_client.base.clientInfo);
1385 virtual void focus(WebPageProxy* page) override
1387 if (!m_client.focus)
1390 m_client.focus(toAPI(page), m_client.base.clientInfo);
1393 virtual void unfocus(WebPageProxy* page) override
1395 if (!m_client.unfocus)
1398 m_client.unfocus(toAPI(page), m_client.base.clientInfo);
1401 virtual void runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame, std::function<void ()> completionHandler) override
1403 if (!m_client.runJavaScriptAlert) {
1404 completionHandler();
1408 m_client.runJavaScriptAlert(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1409 completionHandler();
1412 virtual void runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame, std::function<void (bool)> completionHandler) override
1414 if (!m_client.runJavaScriptConfirm) {
1415 completionHandler(false);
1419 bool result = m_client.runJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1420 completionHandler(result);
1423 virtual void runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame, std::function<void (const String&)> completionHandler) override
1425 if (!m_client.runJavaScriptPrompt) {
1426 completionHandler(String());
1430 RefPtr<API::String> string = adoptRef(toImpl(m_client.runJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.base.clientInfo)));
1432 completionHandler(String());
1436 completionHandler(string->string());
1439 virtual void setStatusText(WebPageProxy* page, const String& text) override
1441 if (!m_client.setStatusText)
1444 m_client.setStatusText(toAPI(page), toAPI(text.impl()), m_client.base.clientInfo);
1447 virtual void mouseDidMoveOverElement(WebPageProxy* page, const WebHitTestResult::Data& data, WebEvent::Modifiers modifiers, API::Object* userData) override
1449 if (!m_client.mouseDidMoveOverElement && !m_client.mouseDidMoveOverElement_deprecatedForUseWithV0)
1452 if (m_client.base.version > 0 && !m_client.mouseDidMoveOverElement)
1455 if (!m_client.base.version) {
1456 m_client.mouseDidMoveOverElement_deprecatedForUseWithV0(toAPI(page), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
1460 RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(data);
1461 m_client.mouseDidMoveOverElement(toAPI(page), toAPI(webHitTestResult.get()), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
1464 #if ENABLE(NETSCAPE_PLUGIN_API)
1465 virtual void unavailablePluginButtonClicked(WebPageProxy* page, WKPluginUnavailabilityReason pluginUnavailabilityReason, API::Dictionary* pluginInformation) override
1467 if (pluginUnavailabilityReason == kWKPluginUnavailabilityReasonPluginMissing) {
1468 if (m_client.missingPluginButtonClicked_deprecatedForUseWithV0)
1469 m_client.missingPluginButtonClicked_deprecatedForUseWithV0(
1471 toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
1472 toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
1473 toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
1474 m_client.base.clientInfo);
1477 if (m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1)
1478 m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1(
1480 pluginUnavailabilityReason,
1481 toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
1482 toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
1483 toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
1484 m_client.base.clientInfo);
1486 if (m_client.unavailablePluginButtonClicked)
1487 m_client.unavailablePluginButtonClicked(
1489 pluginUnavailabilityReason,
1490 toAPI(pluginInformation),
1491 m_client.base.clientInfo);
1493 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1495 virtual bool implementsDidNotHandleKeyEvent() const override
1497 return m_client.didNotHandleKeyEvent;
1500 virtual void didNotHandleKeyEvent(WebPageProxy* page, const NativeWebKeyboardEvent& event) override
1502 if (!m_client.didNotHandleKeyEvent)
1504 m_client.didNotHandleKeyEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
1507 virtual bool implementsDidNotHandleWheelEvent() const override
1509 return m_client.didNotHandleWheelEvent;
1512 virtual void didNotHandleWheelEvent(WebPageProxy* page, const NativeWebWheelEvent& event) override
1514 if (!m_client.didNotHandleWheelEvent)
1516 m_client.didNotHandleWheelEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
1519 virtual bool toolbarsAreVisible(WebPageProxy* page) override
1521 if (!m_client.toolbarsAreVisible)
1523 return m_client.toolbarsAreVisible(toAPI(page), m_client.base.clientInfo);
1526 virtual void setToolbarsAreVisible(WebPageProxy* page, bool visible) override
1528 if (!m_client.setToolbarsAreVisible)
1530 m_client.setToolbarsAreVisible(toAPI(page), visible, m_client.base.clientInfo);
1533 virtual bool menuBarIsVisible(WebPageProxy* page) override
1535 if (!m_client.menuBarIsVisible)
1537 return m_client.menuBarIsVisible(toAPI(page), m_client.base.clientInfo);
1540 virtual void setMenuBarIsVisible(WebPageProxy* page, bool visible) override
1542 if (!m_client.setMenuBarIsVisible)
1544 m_client.setMenuBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
1547 virtual bool statusBarIsVisible(WebPageProxy* page) override
1549 if (!m_client.statusBarIsVisible)
1551 return m_client.statusBarIsVisible(toAPI(page), m_client.base.clientInfo);
1554 virtual void setStatusBarIsVisible(WebPageProxy* page, bool visible) override
1556 if (!m_client.setStatusBarIsVisible)
1558 m_client.setStatusBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
1561 virtual bool isResizable(WebPageProxy* page) override
1563 if (!m_client.isResizable)
1565 return m_client.isResizable(toAPI(page), m_client.base.clientInfo);
1568 virtual void setIsResizable(WebPageProxy* page, bool resizable) override
1570 if (!m_client.setIsResizable)
1572 m_client.setIsResizable(toAPI(page), resizable, m_client.base.clientInfo);
1575 virtual void setWindowFrame(WebPageProxy* page, const FloatRect& frame) override
1577 if (!m_client.setWindowFrame)
1580 m_client.setWindowFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1583 virtual FloatRect windowFrame(WebPageProxy* page) override
1585 if (!m_client.getWindowFrame)
1588 return toFloatRect(m_client.getWindowFrame(toAPI(page), m_client.base.clientInfo));
1591 virtual bool canRunBeforeUnloadConfirmPanel() const override
1593 return m_client.runBeforeUnloadConfirmPanel;
1596 virtual bool runBeforeUnloadConfirmPanel(WebPageProxy* page, const String& message, WebFrameProxy* frame) override
1598 if (!m_client.runBeforeUnloadConfirmPanel)
1601 return m_client.runBeforeUnloadConfirmPanel(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1604 virtual void didDraw(WebPageProxy* page) override
1606 if (!m_client.didDraw)
1609 m_client.didDraw(toAPI(page), m_client.base.clientInfo);
1612 virtual void pageDidScroll(WebPageProxy* page) override
1614 if (!m_client.pageDidScroll)
1617 m_client.pageDidScroll(toAPI(page), m_client.base.clientInfo);
1620 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
1622 if (!m_client.exceededDatabaseQuota) {
1623 completionHandler(currentQuota);
1627 completionHandler(m_client.exceededDatabaseQuota(toAPI(page), toAPI(frame), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, m_client.base.clientInfo));
1630 virtual bool runOpenPanel(WebPageProxy* page, WebFrameProxy* frame, WebOpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener) override
1632 if (!m_client.runOpenPanel)
1635 m_client.runOpenPanel(toAPI(page), toAPI(frame), toAPI(parameters), toAPI(listener), m_client.base.clientInfo);
1639 virtual bool decidePolicyForGeolocationPermissionRequest(WebPageProxy* page, WebFrameProxy* frame, API::SecurityOrigin* origin, GeolocationPermissionRequestProxy* permissionRequest) override
1641 if (!m_client.decidePolicyForGeolocationPermissionRequest)
1644 m_client.decidePolicyForGeolocationPermissionRequest(toAPI(page), toAPI(frame), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
1648 virtual bool decidePolicyForUserMediaPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, UserMediaPermissionRequestProxy& permissionRequest) override
1650 if (!m_client.decidePolicyForUserMediaPermissionRequest)
1653 m_client.decidePolicyForUserMediaPermissionRequest(toAPI(&page), toAPI(&frame), toAPI(&origin), toAPI(&permissionRequest), m_client.base.clientInfo);
1657 virtual bool decidePolicyForNotificationPermissionRequest(WebPageProxy* page, API::SecurityOrigin* origin, NotificationPermissionRequest* permissionRequest) override
1659 if (!m_client.decidePolicyForNotificationPermissionRequest)
1662 m_client.decidePolicyForNotificationPermissionRequest(toAPI(page), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
1667 virtual float headerHeight(WebPageProxy* page, WebFrameProxy* frame) override
1669 if (!m_client.headerHeight)
1672 return m_client.headerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1675 virtual float footerHeight(WebPageProxy* page, WebFrameProxy* frame) override
1677 if (!m_client.footerHeight)
1680 return m_client.footerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1683 virtual void drawHeader(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
1685 if (!m_client.drawHeader)
1688 m_client.drawHeader(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
1691 virtual void drawFooter(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
1693 if (!m_client.drawFooter)
1696 m_client.drawFooter(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
1699 virtual void printFrame(WebPageProxy* page, WebFrameProxy* frame) override
1701 if (!m_client.printFrame)
1704 m_client.printFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1707 virtual bool canRunModal() const override
1709 return m_client.runModal;
1712 virtual void runModal(WebPageProxy* page) override
1714 if (!m_client.runModal)
1717 m_client.runModal(toAPI(page), m_client.base.clientInfo);
1720 virtual void saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data) override
1722 if (!m_client.saveDataToFileInDownloadsFolder)
1725 m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURLString.impl()), toAPI(data), m_client.base.clientInfo);
1728 virtual bool shouldInterruptJavaScript(WebPageProxy* page) override
1730 if (!m_client.shouldInterruptJavaScript)
1733 return m_client.shouldInterruptJavaScript(toAPI(page), m_client.base.clientInfo);
1736 virtual void pinnedStateDidChange(WebPageProxy& page) override
1738 if (!m_client.pinnedStateDidChange)
1741 m_client.pinnedStateDidChange(toAPI(&page), m_client.base.clientInfo);
1744 virtual void didBeginTrackingPotentialLongMousePress(WebPageProxy* page, const IntPoint& mouseDownPosition, const WebHitTestResult::Data& data, API::Object* userInfo) override
1746 if (!m_client.didBeginTrackingPotentialLongMousePress)
1749 RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(data);
1750 m_client.didBeginTrackingPotentialLongMousePress(toAPI(page), toAPI(mouseDownPosition), toAPI(webHitTestResult.get()), toAPI(userInfo), m_client.base.clientInfo);
1753 virtual void didRecognizeLongMousePress(WebPageProxy* page, API::Object* userInfo) override
1755 if (!m_client.didRecognizeLongMousePress)
1758 m_client.didRecognizeLongMousePress(toAPI(page), toAPI(userInfo), m_client.base.clientInfo);
1761 virtual void didCancelTrackingPotentialLongMousePress(WebPageProxy* page, API::Object* userInfo) override
1763 if (!m_client.didCancelTrackingPotentialLongMousePress)
1766 m_client.didCancelTrackingPotentialLongMousePress(toAPI(page), toAPI(userInfo), m_client.base.clientInfo);
1769 virtual void isPlayingAudioDidChange(WebPageProxy& page) override
1771 if (!m_client.isPlayingAudioDidChange)
1774 m_client.isPlayingAudioDidChange(toAPI(&page), m_client.base.clientInfo);
1777 virtual void didClickAutoFillButton(WebPageProxy& page, API::Object* userInfo) override
1779 if (!m_client.didClickAutoFillButton)
1782 m_client.didClickAutoFillButton(toAPI(&page), toAPI(userInfo), m_client.base.clientInfo);
1786 toImpl(pageRef)->setUIClient(std::make_unique<UIClient>(wkClient));
1789 void WKPageSetPageNavigationClient(WKPageRef pageRef, const WKPageNavigationClientBase* wkClient)
1791 class NavigationClient : public API::Client<WKPageNavigationClientBase>, public API::NavigationClient {
1793 explicit NavigationClient(const WKPageNavigationClientBase* client)
1799 virtual void decidePolicyForNavigationAction(WebPageProxy& page, API::NavigationAction& navigationAction, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1801 if (!m_client.decidePolicyForNavigationAction)
1803 m_client.decidePolicyForNavigationAction(toAPI(&page), toAPI(&navigationAction), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1806 virtual void decidePolicyForNavigationResponse(WebPageProxy& page, API::NavigationResponse& navigationResponse, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1808 if (!m_client.decidePolicyForNavigationResponse)
1810 m_client.decidePolicyForNavigationResponse(toAPI(&page), toAPI(&navigationResponse), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1813 virtual void didStartProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1815 if (!m_client.didStartProvisionalNavigation)
1817 m_client.didStartProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1820 virtual void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1822 if (!m_client.didReceiveServerRedirectForProvisionalNavigation)
1824 m_client.didReceiveServerRedirectForProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1827 virtual void didFailProvisionalNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
1829 if (!m_client.didFailProvisionalNavigation)
1831 m_client.didFailProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1834 virtual void didCommitNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1836 if (!m_client.didCommitNavigation)
1838 m_client.didCommitNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1841 virtual void didFinishNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1843 if (!m_client.didFinishNavigation)
1845 m_client.didFinishNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1848 virtual void didFailNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
1850 if (!m_client.didFailNavigation)
1852 m_client.didFailNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1855 virtual void didFailProvisionalLoadInSubframeWithError(WebPageProxy& page, WebFrameProxy& subframe, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
1857 if (!m_client.didFailProvisionalLoadInSubframe)
1859 m_client.didFailProvisionalLoadInSubframe(toAPI(&page), toAPI(navigation), toAPI(API::FrameInfo::create(subframe).ptr()), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1862 virtual void didFinishDocumentLoad(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1864 if (!m_client.didFinishDocumentLoad)
1866 m_client.didFinishDocumentLoad(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1869 virtual void didSameDocumentNavigation(WebPageProxy& page, API::Navigation* navigation, WebKit::SameDocumentNavigationType navigationType, API::Object* userData) override
1871 if (!m_client.didSameDocumentNavigation)
1873 m_client.didSameDocumentNavigation(toAPI(&page), toAPI(navigation), toAPI(navigationType), toAPI(userData), m_client.base.clientInfo);
1876 virtual void renderingProgressDidChange(WebPageProxy& page, WebCore::LayoutMilestones milestones, API::Object* userData) override
1878 if (!m_client.renderingProgressDidChange)
1880 m_client.renderingProgressDidChange(toAPI(&page), pageRenderingProgressEvents(milestones), toAPI(userData), m_client.base.clientInfo);
1883 virtual bool canAuthenticateAgainstProtectionSpace(WebPageProxy& page, WebProtectionSpace* protectionSpace) override
1885 if (!m_client.canAuthenticateAgainstProtectionSpace)
1887 return m_client.canAuthenticateAgainstProtectionSpace(toAPI(&page), toAPI(protectionSpace), m_client.base.clientInfo);
1890 virtual void didReceiveAuthenticationChallenge(WebPageProxy& page, AuthenticationChallengeProxy* authenticationChallenge) override
1892 if (!m_client.didReceiveAuthenticationChallenge)
1894 m_client.didReceiveAuthenticationChallenge(toAPI(&page), toAPI(authenticationChallenge), m_client.base.clientInfo);
1897 virtual void processDidCrash(WebPageProxy& page) override
1899 if (!m_client.webProcessDidCrash)
1901 m_client.webProcessDidCrash(toAPI(&page), m_client.base.clientInfo);
1904 virtual PassRefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
1906 if (!m_client.copyWebCryptoMasterKey)
1908 return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(&page), m_client.base.clientInfo)));
1911 #if ENABLE(NETSCAPE_PLUGIN_API)
1912 virtual PluginModuleLoadPolicy decidePolicyForPluginLoad(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
1914 WKStringRef unavailabilityDescriptionOut = 0;
1915 PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
1917 if (m_client.decidePolicyForPluginLoad)
1918 loadPolicy = toPluginModuleLoadPolicy(m_client.decidePolicyForPluginLoad(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
1920 if (unavailabilityDescriptionOut) {
1921 RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
1922 unavailabilityDescription = webUnavailabilityDescription->string();
1930 WebPageProxy* webPageProxy = toImpl(pageRef);
1932 auto navigationClient = std::make_unique<NavigationClient>(wkClient);
1933 webPageProxy->setNavigationClient(WTF::move(navigationClient));
1936 void WKPageSetSession(WKPageRef pageRef, WKSessionRef session)
1938 toImpl(pageRef)->setSessionID(toImpl(session)->getID());
1941 void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback)
1943 toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), toGenericCallbackFunction(context, callback));
1947 static void callRunJavaScriptBlockAndRelease(WKSerializedScriptValueRef resultValue, WKErrorRef error, void* context)
1949 WKPageRunJavaScriptBlock block = (WKPageRunJavaScriptBlock)context;
1950 block(resultValue, error);
1951 Block_release(block);
1954 void WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef, WKStringRef scriptRef, WKPageRunJavaScriptBlock block)
1956 WKPageRunJavaScriptInMainFrame(pageRef, scriptRef, Block_copy(block), callRunJavaScriptBlockAndRelease);
1960 static std::function<void (const String&, WebKit::CallbackBase::Error)> toGenericCallbackFunction(void* context, void (*callback)(WKStringRef, WKErrorRef, void*))
1962 return [context, callback](const String& returnValue, WebKit::CallbackBase::Error error) {
1963 callback(toAPI(API::String::create(returnValue).ptr()), error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
1967 void WKPageRenderTreeExternalRepresentation(WKPageRef pageRef, void* context, WKPageRenderTreeExternalRepresentationFunction callback)
1969 toImpl(pageRef)->getRenderTreeExternalRepresentation(toGenericCallbackFunction(context, callback));
1972 void WKPageGetSourceForFrame(WKPageRef pageRef, WKFrameRef frameRef, void* context, WKPageGetSourceForFrameFunction callback)
1974 toImpl(pageRef)->getSourceForFrame(toImpl(frameRef), toGenericCallbackFunction(context, callback));
1977 void WKPageGetContentsAsString(WKPageRef pageRef, void* context, WKPageGetContentsAsStringFunction callback)
1979 toImpl(pageRef)->getContentsAsString(toGenericCallbackFunction(context, callback));
1982 void WKPageGetBytecodeProfile(WKPageRef pageRef, void* context, WKPageGetBytecodeProfileFunction callback)
1984 toImpl(pageRef)->getBytecodeProfile(toGenericCallbackFunction(context, callback));
1987 void WKPageGetSelectionAsWebArchiveData(WKPageRef pageRef, void* context, WKPageGetSelectionAsWebArchiveDataFunction callback)
1989 toImpl(pageRef)->getSelectionAsWebArchiveData(toGenericCallbackFunction(context, callback));
1992 void WKPageGetContentsAsMHTMLData(WKPageRef pageRef, bool useBinaryEncoding, void* context, WKPageGetContentsAsMHTMLDataFunction callback)
1995 toImpl(pageRef)->getContentsAsMHTMLData(toGenericCallbackFunction(context, callback), useBinaryEncoding);
1997 UNUSED_PARAM(pageRef);
1998 UNUSED_PARAM(useBinaryEncoding);
1999 UNUSED_PARAM(context);
2000 UNUSED_PARAM(callback);
2004 void WKPageForceRepaint(WKPageRef pageRef, void* context, WKPageForceRepaintFunction callback)
2006 toImpl(pageRef)->forceRepaint(VoidCallback::create([context, callback](WebKit::CallbackBase::Error error) {
2007 callback(error == WebKit::CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().ptr()), context);
2011 WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef pageRef)
2013 const String& pendingAPIRequestURL = toImpl(pageRef)->pageLoadState().pendingAPIRequestURL();
2015 if (pendingAPIRequestURL.isNull())
2018 return toCopiedURLAPI(pendingAPIRequestURL);
2021 WKURLRef WKPageCopyActiveURL(WKPageRef pageRef)
2023 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().activeURL());
2026 WKURLRef WKPageCopyProvisionalURL(WKPageRef pageRef)
2028 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().provisionalURL());
2031 WKURLRef WKPageCopyCommittedURL(WKPageRef pageRef)
2033 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().url());
2036 WKStringRef WKPageCopyStandardUserAgentWithApplicationName(WKStringRef applicationName)
2038 return toCopiedAPI(WebPageProxy::standardUserAgent(toImpl(applicationName)->string()));
2041 void WKPageValidateCommand(WKPageRef pageRef, WKStringRef command, void* context, WKPageValidateCommandCallback callback)
2043 toImpl(pageRef)->validateCommand(toImpl(command)->string(), [context, callback](const String& commandName, bool isEnabled, int32_t state, WebKit::CallbackBase::Error error) {
2044 callback(toAPI(API::String::create(commandName).ptr()), isEnabled, state, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
2048 void WKPageExecuteCommand(WKPageRef pageRef, WKStringRef command)
2050 toImpl(pageRef)->executeEditCommand(toImpl(command)->string());
2054 static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo)
2057 result.pageSetupScaleFactor = printInfo.pageSetupScaleFactor;
2058 result.availablePaperWidth = printInfo.availablePaperWidth;
2059 result.availablePaperHeight = printInfo.availablePaperHeight;
2063 void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, WKPageComputePagesForPrintingFunction callback, void* context)
2065 toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create([context, callback](const Vector<WebCore::IntRect>& rects, double scaleFactor, WebKit::CallbackBase::Error error) {
2066 Vector<WKRect> wkRects(rects.size());
2067 for (size_t i = 0; i < rects.size(); ++i)
2068 wkRects[i] = toAPI(rects[i]);
2069 callback(wkRects.data(), wkRects.size(), scaleFactor, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
2073 void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo)
2075 toImpl(page)->beginPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo));
2078 void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
2080 toImpl(page)->drawPagesToPDF(toImpl(frame), printInfoFromWKPrintInfo(printInfo), first, count, DataCallback::create(toGenericCallbackFunction(context, callback)));
2083 void WKPageEndPrinting(WKPageRef page)
2085 toImpl(page)->endPrinting();
2089 void WKPageSetShouldSendEventsSynchronously(WKPageRef page, bool sync)
2091 toImpl(page)->setShouldSendEventsSynchronously(sync);
2094 bool WKPageGetAllowsRemoteInspection(WKPageRef page)
2096 #if ENABLE(REMOTE_INSPECTOR)
2097 return toImpl(page)->allowsRemoteInspection();
2104 void WKPageSetAllowsRemoteInspection(WKPageRef page, bool allow)
2106 #if ENABLE(REMOTE_INSPECTOR)
2107 toImpl(page)->setAllowsRemoteInspection(allow);
2110 UNUSED_PARAM(allow);
2114 void WKPageSetMediaVolume(WKPageRef page, float volume)
2116 toImpl(page)->setMediaVolume(volume);
2119 void WKPageSetMuted(WKPageRef page, bool muted)
2121 toImpl(page)->setMuted(muted);
2124 void WKPagePostMessageToInjectedBundle(WKPageRef pageRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef)
2126 toImpl(pageRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef));
2129 WKArrayRef WKPageCopyRelatedPages(WKPageRef pageRef)
2131 Vector<RefPtr<API::Object>> relatedPages;
2133 for (auto& page : toImpl(pageRef)->process().pages()) {
2134 if (page != toImpl(pageRef))
2135 relatedPages.append(page);
2138 return toAPI(&API::Array::create(WTF::move(relatedPages)).leakRef());
2141 void WKPageSetMayStartMediaWhenInWindow(WKPageRef pageRef, bool mayStartMedia)
2143 toImpl(pageRef)->setMayStartMediaWhenInWindow(mayStartMedia);
2147 void WKPageSelectContextMenuItem(WKPageRef page, WKContextMenuItemRef item)
2149 #if ENABLE(CONTEXT_MENUS)
2150 toImpl(page)->contextMenuItemSelected(*(toImpl(item)->data()));
2157 WKScrollPinningBehavior WKPageGetScrollPinningBehavior(WKPageRef page)
2159 ScrollPinningBehavior pinning = toImpl(page)->scrollPinningBehavior();
2162 case WebCore::ScrollPinningBehavior::DoNotPin:
2163 return kWKScrollPinningBehaviorDoNotPin;
2164 case WebCore::ScrollPinningBehavior::PinToTop:
2165 return kWKScrollPinningBehaviorPinToTop;
2166 case WebCore::ScrollPinningBehavior::PinToBottom:
2167 return kWKScrollPinningBehaviorPinToBottom;
2170 ASSERT_NOT_REACHED();
2171 return kWKScrollPinningBehaviorDoNotPin;
2174 void WKPageSetScrollPinningBehavior(WKPageRef page, WKScrollPinningBehavior pinning)
2176 ScrollPinningBehavior corePinning = ScrollPinningBehavior::DoNotPin;
2179 case kWKScrollPinningBehaviorDoNotPin:
2180 corePinning = ScrollPinningBehavior::DoNotPin;
2182 case kWKScrollPinningBehaviorPinToTop:
2183 corePinning = ScrollPinningBehavior::PinToTop;
2185 case kWKScrollPinningBehaviorPinToBottom:
2186 corePinning = ScrollPinningBehavior::PinToBottom;
2189 ASSERT_NOT_REACHED();
2192 toImpl(page)->setScrollPinningBehavior(corePinning);
2195 bool WKPageGetAddsVisitedLinks(WKPageRef page)
2197 return toImpl(page)->addsVisitedLinks();
2200 void WKPageSetAddsVisitedLinks(WKPageRef page, bool addsVisitedLinks)
2202 toImpl(page)->setAddsVisitedLinks(addsVisitedLinks);
2205 bool WKPageIsPlayingAudio(WKPageRef page)
2207 return toImpl(page)->isPlayingAudio();
2210 void WKPageClearWheelEventTestTrigger(WKPageRef pageRef)
2212 toImpl(pageRef)->clearWheelEventTestTrigger();
2216 #if ENABLE(NETSCAPE_PLUGIN_API)
2220 WKStringRef WKPageGetPluginInformationBundleIdentifierKey()
2222 return WKPluginInformationBundleIdentifierKey();
2225 WKStringRef WKPageGetPluginInformationBundleVersionKey()
2227 return WKPluginInformationBundleVersionKey();
2230 WKStringRef WKPageGetPluginInformationDisplayNameKey()
2232 return WKPluginInformationDisplayNameKey();
2235 WKStringRef WKPageGetPluginInformationFrameURLKey()
2237 return WKPluginInformationFrameURLKey();
2240 WKStringRef WKPageGetPluginInformationMIMETypeKey()
2242 return WKPluginInformationMIMETypeKey();
2245 WKStringRef WKPageGetPluginInformationPageURLKey()
2247 return WKPluginInformationPageURLKey();
2250 WKStringRef WKPageGetPluginInformationPluginspageAttributeURLKey()
2252 return WKPluginInformationPluginspageAttributeURLKey();
2255 WKStringRef WKPageGetPluginInformationPluginURLKey()
2257 return WKPluginInformationPluginURLKey();
2262 #endif // ENABLE(NETSCAPE_PLUGIN_API)