2 * Copyright (C) 2010 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> 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 WKPageLoadURLWithUserData(WKPageRef pageRef, WKURLRef URLRef, WKTypeRef userDataRef)
131 toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), toImpl(userDataRef));
134 void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef)
136 toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest());
139 void WKPageLoadURLRequestWithUserData(WKPageRef pageRef, WKURLRequestRef urlRequestRef, WKTypeRef userDataRef)
141 toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest(), toImpl(userDataRef));
144 void WKPageLoadFile(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL)
146 toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL));
149 void WKPageLoadFileWithUserData(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL, WKTypeRef userDataRef)
151 toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL), toImpl(userDataRef));
154 void WKPageLoadData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef)
156 toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef));
159 void WKPageLoadDataWithUserData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
161 toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef), toImpl(userDataRef));
164 void WKPageLoadHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef)
166 toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef));
169 void WKPageLoadHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
171 toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toImpl(userDataRef));
174 void WKPageLoadAlternateHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef)
176 toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef));
179 void WKPageLoadAlternateHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef, WKTypeRef userDataRef)
181 toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef), toImpl(userDataRef));
184 void WKPageLoadPlainTextString(WKPageRef pageRef, WKStringRef plainTextStringRef)
186 toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef));
189 void WKPageLoadPlainTextStringWithUserData(WKPageRef pageRef, WKStringRef plainTextStringRef, WKTypeRef userDataRef)
191 toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef), toImpl(userDataRef));
194 void WKPageLoadWebArchiveData(WKPageRef pageRef, WKDataRef webArchiveDataRef)
196 toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef));
199 void WKPageLoadWebArchiveDataWithUserData(WKPageRef pageRef, WKDataRef webArchiveDataRef, WKTypeRef userDataRef)
201 toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef), toImpl(userDataRef));
204 void WKPageStopLoading(WKPageRef pageRef)
206 toImpl(pageRef)->stopLoading();
209 void WKPageReload(WKPageRef pageRef)
211 toImpl(pageRef)->reload(false);
214 void WKPageReloadFromOrigin(WKPageRef pageRef)
216 toImpl(pageRef)->reload(true);
219 bool WKPageTryClose(WKPageRef pageRef)
221 return toImpl(pageRef)->tryClose();
224 void WKPageClose(WKPageRef pageRef)
226 toImpl(pageRef)->close();
229 bool WKPageIsClosed(WKPageRef pageRef)
231 return toImpl(pageRef)->isClosed();
234 void WKPageGoForward(WKPageRef pageRef)
236 toImpl(pageRef)->goForward();
239 bool WKPageCanGoForward(WKPageRef pageRef)
241 return toImpl(pageRef)->backForwardList().forwardItem();
244 void WKPageGoBack(WKPageRef pageRef)
246 toImpl(pageRef)->goBack();
249 bool WKPageCanGoBack(WKPageRef pageRef)
251 return toImpl(pageRef)->backForwardList().backItem();
254 void WKPageGoToBackForwardListItem(WKPageRef pageRef, WKBackForwardListItemRef itemRef)
256 toImpl(pageRef)->goToBackForwardItem(toImpl(itemRef));
259 void WKPageTryRestoreScrollPosition(WKPageRef pageRef)
261 toImpl(pageRef)->tryRestoreScrollPosition();
264 WKBackForwardListRef WKPageGetBackForwardList(WKPageRef pageRef)
266 return toAPI(&toImpl(pageRef)->backForwardList());
269 bool WKPageWillHandleHorizontalScrollEvents(WKPageRef pageRef)
271 return toImpl(pageRef)->willHandleHorizontalScrollEvents();
274 WKStringRef WKPageCopyTitle(WKPageRef pageRef)
276 return toCopiedAPI(toImpl(pageRef)->pageLoadState().title());
279 WKFrameRef WKPageGetMainFrame(WKPageRef pageRef)
281 return toAPI(toImpl(pageRef)->mainFrame());
284 WKFrameRef WKPageGetFocusedFrame(WKPageRef pageRef)
286 return toAPI(toImpl(pageRef)->focusedFrame());
289 WKFrameRef WKPageGetFrameSetLargestFrame(WKPageRef pageRef)
291 return toAPI(toImpl(pageRef)->frameSetLargestFrame());
294 uint64_t WKPageGetRenderTreeSize(WKPageRef page)
296 return toImpl(page)->renderTreeSize();
299 WKInspectorRef WKPageGetInspector(WKPageRef pageRef)
301 return toAPI(toImpl(pageRef)->inspector());
304 WKVibrationRef WKPageGetVibration(WKPageRef page)
306 #if ENABLE(VIBRATION)
307 return toAPI(toImpl(page)->vibration());
314 double WKPageGetEstimatedProgress(WKPageRef pageRef)
316 return toImpl(pageRef)->estimatedProgress();
319 WKStringRef WKPageCopyUserAgent(WKPageRef pageRef)
321 return toCopiedAPI(toImpl(pageRef)->userAgent());
324 WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef pageRef)
326 return toCopiedAPI(toImpl(pageRef)->applicationNameForUserAgent());
329 void WKPageSetApplicationNameForUserAgent(WKPageRef pageRef, WKStringRef applicationNameRef)
331 toImpl(pageRef)->setApplicationNameForUserAgent(toWTFString(applicationNameRef));
334 WKStringRef WKPageCopyCustomUserAgent(WKPageRef pageRef)
336 return toCopiedAPI(toImpl(pageRef)->customUserAgent());
339 void WKPageSetCustomUserAgent(WKPageRef pageRef, WKStringRef userAgentRef)
341 toImpl(pageRef)->setCustomUserAgent(toWTFString(userAgentRef));
344 bool WKPageSupportsTextEncoding(WKPageRef pageRef)
346 return toImpl(pageRef)->supportsTextEncoding();
349 WKStringRef WKPageCopyCustomTextEncodingName(WKPageRef pageRef)
351 return toCopiedAPI(toImpl(pageRef)->customTextEncodingName());
354 void WKPageSetCustomTextEncodingName(WKPageRef pageRef, WKStringRef encodingNameRef)
356 toImpl(pageRef)->setCustomTextEncodingName(toWTFString(encodingNameRef));
359 void WKPageTerminate(WKPageRef pageRef)
361 toImpl(pageRef)->terminateProcess();
364 WKStringRef WKPageGetSessionHistoryURLValueType()
366 static API::String* sessionHistoryURLValueType = API::String::create("SessionHistoryURL").leakRef();
367 return toAPI(sessionHistoryURLValueType);
370 WKStringRef WKPageGetSessionBackForwardListItemValueType()
372 static API::String* sessionBackForwardListValueType = API::String::create("SessionBackForwardListItem").leakRef();
373 return toAPI(sessionBackForwardListValueType);
376 WKTypeRef WKPageCopySessionState(WKPageRef pageRef, void* context, WKPageSessionStateFilterCallback filter)
378 // FIXME: This is a hack to make sure we return a WKDataRef to maintain compatibility with older versions of Safari.
379 bool shouldReturnData = !(reinterpret_cast<uintptr_t>(context) & 1);
380 context = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(context) & ~1);
382 auto sessionState = toImpl(pageRef)->sessionState([pageRef, context, filter](WebBackForwardListItem& item) {
384 if (!filter(pageRef, WKPageGetSessionBackForwardListItemValueType(), toAPI(&item), context))
387 if (!filter(pageRef, WKPageGetSessionHistoryURLValueType(), toURLRef(item.originalURL().impl()), context))
394 if (shouldReturnData)
395 return toAPI(encodeLegacySessionState(sessionState).release().leakRef());
397 return toAPI(API::SessionState::create(WTF::move(sessionState)).leakRef());
400 void WKPageRestoreFromSessionState(WKPageRef pageRef, WKTypeRef sessionStateRef)
402 SessionState sessionState;
404 // FIXME: This is for backwards compatibility with Safari. Remove it once Safari no longer depends on it.
405 if (toImpl(sessionStateRef)->type() == API::Object::Type::Data) {
406 if (!decodeLegacySessionState(toImpl(static_cast<WKDataRef>(sessionStateRef))->bytes(), toImpl(static_cast<WKDataRef>(sessionStateRef))->size(), sessionState))
409 ASSERT(toImpl(sessionStateRef)->type() == API::Object::Type::SessionState);
411 sessionState = toImpl(static_cast<WKSessionStateRef>(sessionStateRef))->sessionState();
414 toImpl(pageRef)->restoreFromSessionState(WTF::move(sessionState), true);
417 double WKPageGetTextZoomFactor(WKPageRef pageRef)
419 return toImpl(pageRef)->textZoomFactor();
422 double WKPageGetBackingScaleFactor(WKPageRef pageRef)
424 return toImpl(pageRef)->deviceScaleFactor();
427 void WKPageSetCustomBackingScaleFactor(WKPageRef pageRef, double customScaleFactor)
429 toImpl(pageRef)->setCustomDeviceScaleFactor(customScaleFactor);
432 bool WKPageSupportsTextZoom(WKPageRef pageRef)
434 return toImpl(pageRef)->supportsTextZoom();
437 void WKPageSetTextZoomFactor(WKPageRef pageRef, double zoomFactor)
439 toImpl(pageRef)->setTextZoomFactor(zoomFactor);
442 double WKPageGetPageZoomFactor(WKPageRef pageRef)
444 return toImpl(pageRef)->pageZoomFactor();
447 void WKPageSetPageZoomFactor(WKPageRef pageRef, double zoomFactor)
449 toImpl(pageRef)->setPageZoomFactor(zoomFactor);
452 void WKPageSetPageAndTextZoomFactors(WKPageRef pageRef, double pageZoomFactor, double textZoomFactor)
454 toImpl(pageRef)->setPageAndTextZoomFactors(pageZoomFactor, textZoomFactor);
457 void WKPageSetScaleFactor(WKPageRef pageRef, double scale, WKPoint origin)
459 toImpl(pageRef)->scalePage(scale, toIntPoint(origin));
462 double WKPageGetScaleFactor(WKPageRef pageRef)
464 return toImpl(pageRef)->pageScaleFactor();
467 void WKPageSetUseFixedLayout(WKPageRef pageRef, bool fixed)
469 toImpl(pageRef)->setUseFixedLayout(fixed);
472 void WKPageSetFixedLayoutSize(WKPageRef pageRef, WKSize size)
474 toImpl(pageRef)->setFixedLayoutSize(toIntSize(size));
477 bool WKPageUseFixedLayout(WKPageRef pageRef)
479 return toImpl(pageRef)->useFixedLayout();
482 WKSize WKPageFixedLayoutSize(WKPageRef pageRef)
484 return toAPI(toImpl(pageRef)->fixedLayoutSize());
487 void WKPageListenForLayoutMilestones(WKPageRef pageRef, WKLayoutMilestones milestones)
489 toImpl(pageRef)->listenForLayoutMilestones(toLayoutMilestones(milestones));
492 bool WKPageHasHorizontalScrollbar(WKPageRef pageRef)
494 return toImpl(pageRef)->hasHorizontalScrollbar();
497 bool WKPageHasVerticalScrollbar(WKPageRef pageRef)
499 return toImpl(pageRef)->hasVerticalScrollbar();
502 void WKPageSetSuppressScrollbarAnimations(WKPageRef pageRef, bool suppressAnimations)
504 toImpl(pageRef)->setSuppressScrollbarAnimations(suppressAnimations);
507 bool WKPageAreScrollbarAnimationsSuppressed(WKPageRef pageRef)
509 return toImpl(pageRef)->areScrollbarAnimationsSuppressed();
512 bool WKPageIsPinnedToLeftSide(WKPageRef pageRef)
514 return toImpl(pageRef)->isPinnedToLeftSide();
517 bool WKPageIsPinnedToRightSide(WKPageRef pageRef)
519 return toImpl(pageRef)->isPinnedToRightSide();
522 bool WKPageIsPinnedToTopSide(WKPageRef pageRef)
524 return toImpl(pageRef)->isPinnedToTopSide();
527 bool WKPageIsPinnedToBottomSide(WKPageRef pageRef)
529 return toImpl(pageRef)->isPinnedToBottomSide();
532 bool WKPageRubberBandsAtLeft(WKPageRef pageRef)
534 return toImpl(pageRef)->rubberBandsAtLeft();
537 void WKPageSetRubberBandsAtLeft(WKPageRef pageRef, bool rubberBandsAtLeft)
539 toImpl(pageRef)->setRubberBandsAtLeft(rubberBandsAtLeft);
542 bool WKPageRubberBandsAtRight(WKPageRef pageRef)
544 return toImpl(pageRef)->rubberBandsAtRight();
547 void WKPageSetRubberBandsAtRight(WKPageRef pageRef, bool rubberBandsAtRight)
549 toImpl(pageRef)->setRubberBandsAtRight(rubberBandsAtRight);
552 bool WKPageRubberBandsAtTop(WKPageRef pageRef)
554 return toImpl(pageRef)->rubberBandsAtTop();
557 void WKPageSetRubberBandsAtTop(WKPageRef pageRef, bool rubberBandsAtTop)
559 toImpl(pageRef)->setRubberBandsAtTop(rubberBandsAtTop);
562 bool WKPageRubberBandsAtBottom(WKPageRef pageRef)
564 return toImpl(pageRef)->rubberBandsAtBottom();
567 void WKPageSetRubberBandsAtBottom(WKPageRef pageRef, bool rubberBandsAtBottom)
569 toImpl(pageRef)->setRubberBandsAtBottom(rubberBandsAtBottom);
572 bool WKPageVerticalRubberBandingIsEnabled(WKPageRef pageRef)
574 return toImpl(pageRef)->verticalRubberBandingIsEnabled();
577 void WKPageSetEnableVerticalRubberBanding(WKPageRef pageRef, bool enableVerticalRubberBanding)
579 toImpl(pageRef)->setEnableVerticalRubberBanding(enableVerticalRubberBanding);
582 bool WKPageHorizontalRubberBandingIsEnabled(WKPageRef pageRef)
584 return toImpl(pageRef)->horizontalRubberBandingIsEnabled();
587 void WKPageSetEnableHorizontalRubberBanding(WKPageRef pageRef, bool enableHorizontalRubberBanding)
589 toImpl(pageRef)->setEnableHorizontalRubberBanding(enableHorizontalRubberBanding);
592 void WKPageSetBackgroundExtendsBeyondPage(WKPageRef pageRef, bool backgroundExtendsBeyondPage)
594 toImpl(pageRef)->setBackgroundExtendsBeyondPage(backgroundExtendsBeyondPage);
597 bool WKPageBackgroundExtendsBeyondPage(WKPageRef pageRef)
599 return toImpl(pageRef)->backgroundExtendsBeyondPage();
602 void WKPageSetPaginationMode(WKPageRef pageRef, WKPaginationMode paginationMode)
604 Pagination::Mode mode;
605 switch (paginationMode) {
606 case kWKPaginationModeUnpaginated:
607 mode = Pagination::Unpaginated;
609 case kWKPaginationModeLeftToRight:
610 mode = Pagination::LeftToRightPaginated;
612 case kWKPaginationModeRightToLeft:
613 mode = Pagination::RightToLeftPaginated;
615 case kWKPaginationModeTopToBottom:
616 mode = Pagination::TopToBottomPaginated;
618 case kWKPaginationModeBottomToTop:
619 mode = Pagination::BottomToTopPaginated;
624 toImpl(pageRef)->setPaginationMode(mode);
627 WKPaginationMode WKPageGetPaginationMode(WKPageRef pageRef)
629 switch (toImpl(pageRef)->paginationMode()) {
630 case Pagination::Unpaginated:
631 return kWKPaginationModeUnpaginated;
632 case Pagination::LeftToRightPaginated:
633 return kWKPaginationModeLeftToRight;
634 case Pagination::RightToLeftPaginated:
635 return kWKPaginationModeRightToLeft;
636 case Pagination::TopToBottomPaginated:
637 return kWKPaginationModeTopToBottom;
638 case Pagination::BottomToTopPaginated:
639 return kWKPaginationModeBottomToTop;
642 ASSERT_NOT_REACHED();
643 return kWKPaginationModeUnpaginated;
646 void WKPageSetPaginationBehavesLikeColumns(WKPageRef pageRef, bool behavesLikeColumns)
648 toImpl(pageRef)->setPaginationBehavesLikeColumns(behavesLikeColumns);
651 bool WKPageGetPaginationBehavesLikeColumns(WKPageRef pageRef)
653 return toImpl(pageRef)->paginationBehavesLikeColumns();
656 void WKPageSetPageLength(WKPageRef pageRef, double pageLength)
658 toImpl(pageRef)->setPageLength(pageLength);
661 double WKPageGetPageLength(WKPageRef pageRef)
663 return toImpl(pageRef)->pageLength();
666 void WKPageSetGapBetweenPages(WKPageRef pageRef, double gap)
668 toImpl(pageRef)->setGapBetweenPages(gap);
671 double WKPageGetGapBetweenPages(WKPageRef pageRef)
673 return toImpl(pageRef)->gapBetweenPages();
676 unsigned WKPageGetPageCount(WKPageRef pageRef)
678 return toImpl(pageRef)->pageCount();
681 bool WKPageCanDelete(WKPageRef pageRef)
683 return toImpl(pageRef)->canDelete();
686 bool WKPageHasSelectedRange(WKPageRef pageRef)
688 return toImpl(pageRef)->hasSelectedRange();
691 bool WKPageIsContentEditable(WKPageRef pageRef)
693 return toImpl(pageRef)->isContentEditable();
696 void WKPageSetMaintainsInactiveSelection(WKPageRef pageRef, bool newValue)
698 return toImpl(pageRef)->setMaintainsInactiveSelection(newValue);
701 void WKPageCenterSelectionInVisibleArea(WKPageRef pageRef)
703 return toImpl(pageRef)->centerSelectionInVisibleArea();
706 void WKPageFindStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
708 toImpl(pageRef)->findStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
711 void WKPageGetImageForFindMatch(WKPageRef pageRef, int32_t matchIndex)
713 toImpl(pageRef)->getImageForFindMatch(matchIndex);
716 void WKPageSelectFindMatch(WKPageRef pageRef, int32_t matchIndex)
718 toImpl(pageRef)->selectFindMatch(matchIndex);
721 void WKPageFindString(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
723 toImpl(pageRef)->findString(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
726 void WKPageHideFindUI(WKPageRef pageRef)
728 toImpl(pageRef)->hideFindUI();
731 void WKPageCountStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
733 toImpl(pageRef)->countStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
736 void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuClientBase* wkClient)
738 #if ENABLE(CONTEXT_MENUS)
739 class ContextMenuClient final : public API::Client<WKPageContextMenuClientBase>, public API::ContextMenuClient {
741 explicit ContextMenuClient(const WKPageContextMenuClientBase* client)
747 virtual bool getContextMenuFromProposedMenu(WebPageProxy& page, const Vector<RefPtr<WebKit::WebContextMenuItem>>& proposedMenuVector, Vector<RefPtr<WebKit::WebContextMenuItem>>& customMenu, const WebHitTestResult::Data& hitTestResultData, API::Object* userData) override
749 if (!m_client.getContextMenuFromProposedMenu && !m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0)
752 if (m_client.base.version >= 2 && !m_client.getContextMenuFromProposedMenu)
755 Vector<RefPtr<API::Object>> proposedMenuItems;
756 proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size());
758 for (const auto& menuItem : proposedMenuVector)
759 proposedMenuItems.uncheckedAppend(menuItem);
761 WKArrayRef newMenu = nullptr;
762 if (m_client.base.version >= 2) {
763 RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(hitTestResultData);
764 m_client.getContextMenuFromProposedMenu(toAPI(&page), toAPI(API::Array::create(WTF::move(proposedMenuItems)).get()), &newMenu, toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo);
766 m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0(toAPI(&page), toAPI(API::Array::create(WTF::move(proposedMenuItems)).get()), &newMenu, toAPI(userData), m_client.base.clientInfo);
768 RefPtr<API::Array> array = adoptRef(toImpl(newMenu));
772 size_t newSize = array ? array->size() : 0;
773 for (size_t i = 0; i < newSize; ++i) {
774 WebContextMenuItem* item = array->at<WebContextMenuItem>(i);
776 LOG(ContextMenu, "New menu entry at index %i is not a WebContextMenuItem", (int)i);
780 customMenu.append(item);
786 virtual void customContextMenuItemSelected(WebPageProxy& page, const WebContextMenuItemData& itemData) override
788 if (!m_client.customContextMenuItemSelected)
791 m_client.customContextMenuItemSelected(toAPI(&page), toAPI(WebContextMenuItem::create(itemData).get()), m_client.base.clientInfo);
794 virtual void contextMenuDismissed(WebPageProxy& page) override
796 if (!m_client.contextMenuDismissed)
799 m_client.contextMenuDismissed(toAPI(&page), m_client.base.clientInfo);
802 virtual bool showContextMenu(WebPageProxy& page, const WebCore::IntPoint& menuLocation, const Vector<RefPtr<WebContextMenuItem>>& menuItemsVector) override
804 if (!m_client.showContextMenu)
807 Vector<RefPtr<API::Object>> menuItems;
808 menuItems.reserveInitialCapacity(menuItemsVector.size());
810 for (const auto& menuItem : menuItemsVector)
811 menuItems.uncheckedAppend(menuItem);
813 m_client.showContextMenu(toAPI(&page), toAPI(menuLocation), toAPI(API::Array::create(WTF::move(menuItems)).get()), m_client.base.clientInfo);
818 virtual bool hideContextMenu(WebPageProxy& page) override
820 if (!m_client.hideContextMenu)
823 m_client.hideContextMenu(toAPI(&page), m_client.base.clientInfo);
829 toImpl(pageRef)->setContextMenuClient(std::make_unique<ContextMenuClient>(wkClient));
831 UNUSED_PARAM(pageRef);
832 UNUSED_PARAM(wkClient);
836 void WKPageSetPageDiagnosticLoggingClient(WKPageRef pageRef, const WKPageDiagnosticLoggingClientBase* wkClient)
838 toImpl(pageRef)->setDiagnosticLoggingClient(std::make_unique<WebPageDiagnosticLoggingClient>(wkClient));
841 void WKPageSetPageFindClient(WKPageRef pageRef, const WKPageFindClientBase* wkClient)
843 class FindClient : public API::Client<WKPageFindClientBase>, public API::FindClient {
845 explicit FindClient(const WKPageFindClientBase* client)
851 virtual void didFindString(WebPageProxy* page, const String& string, uint32_t matchCount, int32_t) override
853 if (!m_client.didFindString)
856 m_client.didFindString(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
859 virtual void didFailToFindString(WebPageProxy* page, const String& string) override
861 if (!m_client.didFailToFindString)
864 m_client.didFailToFindString(toAPI(page), toAPI(string.impl()), m_client.base.clientInfo);
867 virtual void didCountStringMatches(WebPageProxy* page, const String& string, uint32_t matchCount) override
869 if (!m_client.didCountStringMatches)
872 m_client.didCountStringMatches(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
876 toImpl(pageRef)->setFindClient(std::make_unique<FindClient>(wkClient));
879 void WKPageSetPageFindMatchesClient(WKPageRef pageRef, const WKPageFindMatchesClientBase* wkClient)
881 toImpl(pageRef)->initializeFindMatchesClient(wkClient);
884 void WKPageSetPageInjectedBundleClient(WKPageRef pageRef, const WKPageInjectedBundleClientBase* wkClient)
886 toImpl(pageRef)->setInjectedBundleClient(wkClient);
889 void WKPageSetPageFormClient(WKPageRef pageRef, const WKPageFormClientBase* wkClient)
891 toImpl(pageRef)->setFormClient(std::make_unique<WebFormClient>(wkClient));
894 void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase* wkClient)
896 class LoaderClient : public API::Client<WKPageLoaderClientBase>, public API::LoaderClient {
898 explicit LoaderClient(const WKPageLoaderClientBase* client)
904 virtual void didStartProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
906 if (!m_client.didStartProvisionalLoadForFrame)
909 m_client.didStartProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
912 virtual void didReceiveServerRedirectForProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
914 if (!m_client.didReceiveServerRedirectForProvisionalLoadForFrame)
917 m_client.didReceiveServerRedirectForProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
920 virtual void didFailProvisionalLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
922 if (!m_client.didFailProvisionalLoadWithErrorForFrame)
925 m_client.didFailProvisionalLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
928 virtual void didCommitLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
930 if (!m_client.didCommitLoadForFrame)
933 m_client.didCommitLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
936 virtual void didFinishDocumentLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
938 if (!m_client.didFinishDocumentLoadForFrame)
941 m_client.didFinishDocumentLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
944 virtual void didFinishLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
946 if (!m_client.didFinishLoadForFrame)
949 m_client.didFinishLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
952 virtual void didFailLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
954 if (!m_client.didFailLoadWithErrorForFrame)
957 m_client.didFailLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
960 virtual void didSameDocumentNavigationForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, SameDocumentNavigationType type, API::Object* userData) override
962 if (!m_client.didSameDocumentNavigationForFrame)
965 m_client.didSameDocumentNavigationForFrame(toAPI(&page), toAPI(&frame), toAPI(type), toAPI(userData), m_client.base.clientInfo);
968 virtual void didReceiveTitleForFrame(WebPageProxy& page, const String& title, WebFrameProxy& frame, API::Object* userData) override
970 if (!m_client.didReceiveTitleForFrame)
973 m_client.didReceiveTitleForFrame(toAPI(&page), toAPI(title.impl()), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
976 virtual void didFirstLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
978 if (!m_client.didFirstLayoutForFrame)
981 m_client.didFirstLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
984 virtual void didFirstVisuallyNonEmptyLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
986 if (!m_client.didFirstVisuallyNonEmptyLayoutForFrame)
989 m_client.didFirstVisuallyNonEmptyLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
992 virtual void didLayout(WebPageProxy& page, LayoutMilestones milestones, API::Object* userData) override
994 if (!m_client.didLayout)
997 m_client.didLayout(toAPI(&page), toWKLayoutMilestones(milestones), toAPI(userData), m_client.base.clientInfo);
1000 virtual void didRemoveFrameFromHierarchy(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1002 if (!m_client.didRemoveFrameFromHierarchy)
1005 m_client.didRemoveFrameFromHierarchy(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1008 virtual void didDisplayInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1010 if (!m_client.didDisplayInsecureContentForFrame)
1013 m_client.didDisplayInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1016 virtual void didRunInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1018 if (!m_client.didRunInsecureContentForFrame)
1021 m_client.didRunInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1024 virtual void didDetectXSSForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1026 if (!m_client.didDetectXSSForFrame)
1029 m_client.didDetectXSSForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1032 virtual bool canAuthenticateAgainstProtectionSpaceInFrame(WebPageProxy& page, WebFrameProxy& frame, WebProtectionSpace* protectionSpace) override
1034 if (!m_client.canAuthenticateAgainstProtectionSpaceInFrame)
1037 return m_client.canAuthenticateAgainstProtectionSpaceInFrame(toAPI(&page), toAPI(&frame), toAPI(protectionSpace), m_client.base.clientInfo);
1040 virtual void didReceiveAuthenticationChallengeInFrame(WebPageProxy& page, WebFrameProxy& frame, AuthenticationChallengeProxy* authenticationChallenge) override
1042 if (!m_client.didReceiveAuthenticationChallengeInFrame)
1045 m_client.didReceiveAuthenticationChallengeInFrame(toAPI(&page), toAPI(&frame), toAPI(authenticationChallenge), m_client.base.clientInfo);
1048 virtual void didStartProgress(WebPageProxy& page) override
1050 if (!m_client.didStartProgress)
1053 m_client.didStartProgress(toAPI(&page), m_client.base.clientInfo);
1056 virtual void didChangeProgress(WebPageProxy& page) override
1058 if (!m_client.didChangeProgress)
1061 m_client.didChangeProgress(toAPI(&page), m_client.base.clientInfo);
1064 virtual void didFinishProgress(WebPageProxy& page) override
1066 if (!m_client.didFinishProgress)
1069 m_client.didFinishProgress(toAPI(&page), m_client.base.clientInfo);
1072 virtual void processDidBecomeUnresponsive(WebPageProxy& page) override
1074 if (!m_client.processDidBecomeUnresponsive)
1077 m_client.processDidBecomeUnresponsive(toAPI(&page), m_client.base.clientInfo);
1080 virtual void interactionOccurredWhileProcessUnresponsive(WebPageProxy& page) override
1082 if (!m_client.interactionOccurredWhileProcessUnresponsive)
1085 m_client.interactionOccurredWhileProcessUnresponsive(toAPI(&page), m_client.base.clientInfo);
1088 virtual void processDidBecomeResponsive(WebPageProxy& page) override
1090 if (!m_client.processDidBecomeResponsive)
1093 m_client.processDidBecomeResponsive(toAPI(&page), m_client.base.clientInfo);
1096 virtual void processDidCrash(WebPageProxy& page) override
1098 if (!m_client.processDidCrash)
1101 m_client.processDidCrash(toAPI(&page), m_client.base.clientInfo);
1104 virtual void didChangeBackForwardList(WebPageProxy& page, WebBackForwardListItem* addedItem, Vector<RefPtr<WebBackForwardListItem>> removedItems) override
1106 if (!m_client.didChangeBackForwardList)
1109 RefPtr<API::Array> removedItemsArray;
1110 if (!removedItems.isEmpty()) {
1111 Vector<RefPtr<API::Object>> removedItemsVector;
1112 removedItemsVector.reserveInitialCapacity(removedItems.size());
1113 for (auto& removedItem : removedItems)
1114 removedItemsVector.append(WTF::move(removedItem));
1116 removedItemsArray = API::Array::create(WTF::move(removedItemsVector));
1119 m_client.didChangeBackForwardList(toAPI(&page), toAPI(addedItem), toAPI(removedItemsArray.get()), m_client.base.clientInfo);
1122 virtual bool shouldKeepCurrentBackForwardListItemInList(WebKit::WebPageProxy& page, WebKit::WebBackForwardListItem* item) override
1124 if (!m_client.shouldKeepCurrentBackForwardListItemInList)
1127 return m_client.shouldKeepCurrentBackForwardListItemInList(toAPI(&page), toAPI(item), m_client.base.clientInfo);
1130 virtual void willGoToBackForwardListItem(WebPageProxy& page, WebBackForwardListItem* item, API::Object* userData) override
1132 if (m_client.willGoToBackForwardListItem)
1133 m_client.willGoToBackForwardListItem(toAPI(&page), toAPI(item), toAPI(userData), m_client.base.clientInfo);
1136 virtual PassRefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
1138 return page.process().processPool().client().copyWebCryptoMasterKey(&page.process().processPool());
1141 #if ENABLE(NETSCAPE_PLUGIN_API)
1142 virtual void didFailToInitializePlugin(WebPageProxy& page, API::Dictionary* pluginInformation) override
1144 if (m_client.didFailToInitializePlugin_deprecatedForUseWithV0)
1145 m_client.didFailToInitializePlugin_deprecatedForUseWithV0(toAPI(&page), toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), m_client.base.clientInfo);
1147 if (m_client.pluginDidFail_deprecatedForUseWithV1)
1148 m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), 0, 0, m_client.base.clientInfo);
1150 if (m_client.pluginDidFail)
1151 m_client.pluginDidFail(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation), m_client.base.clientInfo);
1154 virtual void didBlockInsecurePluginVersion(WebPageProxy& page, API::Dictionary* pluginInformation) override
1156 if (m_client.pluginDidFail_deprecatedForUseWithV1)
1157 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);
1159 if (m_client.pluginDidFail)
1160 m_client.pluginDidFail(toAPI(&page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation), m_client.base.clientInfo);
1163 virtual PluginModuleLoadPolicy pluginLoadPolicy(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
1165 WKStringRef unavailabilityDescriptionOut = 0;
1166 PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
1168 if (m_client.pluginLoadPolicy_deprecatedForUseWithV2)
1169 loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy_deprecatedForUseWithV2(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), m_client.base.clientInfo));
1170 else if (m_client.pluginLoadPolicy)
1171 loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
1173 if (unavailabilityDescriptionOut) {
1174 RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
1175 unavailabilityDescription = webUnavailabilityDescription->string();
1180 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1183 virtual WebCore::WebGLLoadPolicy webGLLoadPolicy(WebPageProxy& page, const String& url) const override
1185 WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
1187 if (m_client.webGLLoadPolicy)
1188 loadPolicy = toWebGLLoadPolicy(m_client.webGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
1193 virtual WebCore::WebGLLoadPolicy resolveWebGLLoadPolicy(WebPageProxy& page, const String& url) const override
1195 WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
1197 if (m_client.resolveWebGLLoadPolicy)
1198 loadPolicy = toWebGLLoadPolicy(m_client.resolveWebGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
1203 #endif // ENABLE(WEBGL)
1206 WebPageProxy* webPageProxy = toImpl(pageRef);
1208 auto loaderClient = std::make_unique<LoaderClient>(wkClient);
1210 // It would be nice to get rid of this code and transition all clients to using didLayout instead of
1211 // didFirstLayoutInFrame and didFirstVisuallyNonEmptyLayoutInFrame. In the meantime, this is required
1212 // for backwards compatibility.
1213 WebCore::LayoutMilestones milestones = 0;
1214 if (loaderClient->client().didFirstLayoutForFrame)
1215 milestones |= WebCore::DidFirstLayout;
1216 if (loaderClient->client().didFirstVisuallyNonEmptyLayoutForFrame)
1217 milestones |= WebCore::DidFirstVisuallyNonEmptyLayout;
1220 webPageProxy->process().send(Messages::WebPage::ListenForLayoutMilestones(milestones), webPageProxy->pageID());
1222 webPageProxy->setLoaderClient(WTF::move(loaderClient));
1225 void WKPageSetPagePolicyClient(WKPageRef pageRef, const WKPagePolicyClientBase* wkClient)
1227 class PolicyClient : public API::Client<WKPagePolicyClientBase>, public API::PolicyClient {
1229 explicit PolicyClient(const WKPagePolicyClientBase* client)
1235 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
1237 if (!m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0 && !m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1 && !m_client.decidePolicyForNavigationAction) {
1242 RefPtr<API::URLRequest> originalRequest = API::URLRequest::create(originalResourceRequest);
1243 RefPtr<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1245 if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0)
1246 m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0(toAPI(&page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(request.get()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1247 else if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1)
1248 m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1(toAPI(&page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(originatingFrame), toAPI(request.get()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1250 m_client.decidePolicyForNavigationAction(toAPI(&page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(originatingFrame), toAPI(originalRequest.get()), toAPI(request.get()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1253 virtual void decidePolicyForNewWindowAction(WebPageProxy& page, WebFrameProxy& frame, const NavigationActionData& navigationActionData, const ResourceRequest& resourceRequest, const String& frameName, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1255 if (!m_client.decidePolicyForNewWindowAction) {
1260 RefPtr<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1262 m_client.decidePolicyForNewWindowAction(toAPI(&page), toAPI(&frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(request.get()), toAPI(frameName.impl()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1265 virtual void decidePolicyForResponse(WebPageProxy& page, WebFrameProxy& frame, const ResourceResponse& resourceResponse, const ResourceRequest& resourceRequest, bool canShowMIMEType, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1267 if (!m_client.decidePolicyForResponse_deprecatedForUseWithV0 && !m_client.decidePolicyForResponse) {
1272 RefPtr<API::URLResponse> response = API::URLResponse::create(resourceResponse);
1273 RefPtr<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1275 if (m_client.decidePolicyForResponse_deprecatedForUseWithV0)
1276 m_client.decidePolicyForResponse_deprecatedForUseWithV0(toAPI(&page), toAPI(&frame), toAPI(response.get()), toAPI(request.get()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1278 m_client.decidePolicyForResponse(toAPI(&page), toAPI(&frame), toAPI(response.get()), toAPI(request.get()), canShowMIMEType, toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1281 virtual void unableToImplementPolicy(WebPageProxy& page, WebFrameProxy& frame, const ResourceError& error, API::Object* userData) override
1283 if (!m_client.unableToImplementPolicy)
1286 m_client.unableToImplementPolicy(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1290 toImpl(pageRef)->setPolicyClient(std::make_unique<PolicyClient>(wkClient));
1293 void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient)
1295 class UIClient : public API::Client<WKPageUIClientBase>, public API::UIClient {
1297 explicit UIClient(const WKPageUIClientBase* client)
1303 virtual PassRefPtr<WebPageProxy> createNewPage(WebPageProxy* page, WebFrameProxy*, const ResourceRequest& resourceRequest, const WindowFeatures& windowFeatures, const NavigationActionData& navigationActionData) override
1305 if (!m_client.base.version && !m_client.createNewPage_deprecatedForUseWithV0)
1308 if (m_client.base.version > 0 && !m_client.createNewPage)
1311 API::Dictionary::MapType map;
1312 if (windowFeatures.xSet)
1313 map.set("x", API::Double::create(windowFeatures.x));
1314 if (windowFeatures.ySet)
1315 map.set("y", API::Double::create(windowFeatures.y));
1316 if (windowFeatures.widthSet)
1317 map.set("width", API::Double::create(windowFeatures.width));
1318 if (windowFeatures.heightSet)
1319 map.set("height", API::Double::create(windowFeatures.height));
1320 map.set("menuBarVisible", API::Boolean::create(windowFeatures.menuBarVisible));
1321 map.set("statusBarVisible", API::Boolean::create(windowFeatures.statusBarVisible));
1322 map.set("toolBarVisible", API::Boolean::create(windowFeatures.toolBarVisible));
1323 map.set("locationBarVisible", API::Boolean::create(windowFeatures.locationBarVisible));
1324 map.set("scrollbarsVisible", API::Boolean::create(windowFeatures.scrollbarsVisible));
1325 map.set("resizable", API::Boolean::create(windowFeatures.resizable));
1326 map.set("fullscreen", API::Boolean::create(windowFeatures.fullscreen));
1327 map.set("dialog", API::Boolean::create(windowFeatures.dialog));
1328 RefPtr<API::Dictionary> featuresMap = API::Dictionary::create(WTF::move(map));
1330 if (!m_client.base.version)
1331 return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV0(toAPI(page), toAPI(featuresMap.get()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
1333 RefPtr<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1334 return adoptRef(toImpl(m_client.createNewPage(toAPI(page), toAPI(request.get()), toAPI(featuresMap.get()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
1337 virtual void showPage(WebPageProxy* page) override
1339 if (!m_client.showPage)
1342 m_client.showPage(toAPI(page), m_client.base.clientInfo);
1345 virtual void close(WebPageProxy* page) override
1347 if (!m_client.close)
1350 m_client.close(toAPI(page), m_client.base.clientInfo);
1353 virtual void takeFocus(WebPageProxy* page, WKFocusDirection direction) override
1355 if (!m_client.takeFocus)
1358 m_client.takeFocus(toAPI(page), direction, m_client.base.clientInfo);
1361 virtual void focus(WebPageProxy* page) override
1363 if (!m_client.focus)
1366 m_client.focus(toAPI(page), m_client.base.clientInfo);
1369 virtual void unfocus(WebPageProxy* page) override
1371 if (!m_client.unfocus)
1374 m_client.unfocus(toAPI(page), m_client.base.clientInfo);
1377 virtual void runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame, std::function<void ()> completionHandler) override
1379 if (!m_client.runJavaScriptAlert) {
1380 completionHandler();
1384 m_client.runJavaScriptAlert(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1385 completionHandler();
1388 virtual void runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame, std::function<void (bool)> completionHandler) override
1390 if (!m_client.runJavaScriptConfirm) {
1391 completionHandler(false);
1395 bool result = m_client.runJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1396 completionHandler(result);
1399 virtual void runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame, std::function<void (const String&)> completionHandler) override
1401 if (!m_client.runJavaScriptPrompt) {
1402 completionHandler(String());
1406 RefPtr<API::String> string = adoptRef(toImpl(m_client.runJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.base.clientInfo)));
1408 completionHandler(String());
1412 completionHandler(string->string());
1415 virtual void setStatusText(WebPageProxy* page, const String& text) override
1417 if (!m_client.setStatusText)
1420 m_client.setStatusText(toAPI(page), toAPI(text.impl()), m_client.base.clientInfo);
1423 virtual void mouseDidMoveOverElement(WebPageProxy* page, const WebHitTestResult::Data& data, WebEvent::Modifiers modifiers, API::Object* userData) override
1425 if (!m_client.mouseDidMoveOverElement && !m_client.mouseDidMoveOverElement_deprecatedForUseWithV0)
1428 if (m_client.base.version > 0 && !m_client.mouseDidMoveOverElement)
1431 if (!m_client.base.version) {
1432 m_client.mouseDidMoveOverElement_deprecatedForUseWithV0(toAPI(page), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
1436 RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(data);
1437 m_client.mouseDidMoveOverElement(toAPI(page), toAPI(webHitTestResult.get()), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
1440 #if ENABLE(NETSCAPE_PLUGIN_API)
1441 virtual void unavailablePluginButtonClicked(WebPageProxy* page, WKPluginUnavailabilityReason pluginUnavailabilityReason, API::Dictionary* pluginInformation) override
1443 if (pluginUnavailabilityReason == kWKPluginUnavailabilityReasonPluginMissing) {
1444 if (m_client.missingPluginButtonClicked_deprecatedForUseWithV0)
1445 m_client.missingPluginButtonClicked_deprecatedForUseWithV0(
1447 toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
1448 toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
1449 toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
1450 m_client.base.clientInfo);
1453 if (m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1)
1454 m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1(
1456 pluginUnavailabilityReason,
1457 toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
1458 toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
1459 toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
1460 m_client.base.clientInfo);
1462 if (m_client.unavailablePluginButtonClicked)
1463 m_client.unavailablePluginButtonClicked(
1465 pluginUnavailabilityReason,
1466 toAPI(pluginInformation),
1467 m_client.base.clientInfo);
1469 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1471 virtual bool implementsDidNotHandleKeyEvent() const override
1473 return m_client.didNotHandleKeyEvent;
1476 virtual void didNotHandleKeyEvent(WebPageProxy* page, const NativeWebKeyboardEvent& event) override
1478 if (!m_client.didNotHandleKeyEvent)
1480 m_client.didNotHandleKeyEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
1483 virtual bool implementsDidNotHandleWheelEvent() const override
1485 return m_client.didNotHandleWheelEvent;
1488 virtual void didNotHandleWheelEvent(WebPageProxy* page, const NativeWebWheelEvent& event) override
1490 if (!m_client.didNotHandleWheelEvent)
1492 m_client.didNotHandleWheelEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
1495 virtual bool toolbarsAreVisible(WebPageProxy* page) override
1497 if (!m_client.toolbarsAreVisible)
1499 return m_client.toolbarsAreVisible(toAPI(page), m_client.base.clientInfo);
1502 virtual void setToolbarsAreVisible(WebPageProxy* page, bool visible) override
1504 if (!m_client.setToolbarsAreVisible)
1506 m_client.setToolbarsAreVisible(toAPI(page), visible, m_client.base.clientInfo);
1509 virtual bool menuBarIsVisible(WebPageProxy* page) override
1511 if (!m_client.menuBarIsVisible)
1513 return m_client.menuBarIsVisible(toAPI(page), m_client.base.clientInfo);
1516 virtual void setMenuBarIsVisible(WebPageProxy* page, bool visible) override
1518 if (!m_client.setMenuBarIsVisible)
1520 m_client.setMenuBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
1523 virtual bool statusBarIsVisible(WebPageProxy* page) override
1525 if (!m_client.statusBarIsVisible)
1527 return m_client.statusBarIsVisible(toAPI(page), m_client.base.clientInfo);
1530 virtual void setStatusBarIsVisible(WebPageProxy* page, bool visible) override
1532 if (!m_client.setStatusBarIsVisible)
1534 m_client.setStatusBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
1537 virtual bool isResizable(WebPageProxy* page) override
1539 if (!m_client.isResizable)
1541 return m_client.isResizable(toAPI(page), m_client.base.clientInfo);
1544 virtual void setIsResizable(WebPageProxy* page, bool resizable) override
1546 if (!m_client.setIsResizable)
1548 m_client.setIsResizable(toAPI(page), resizable, m_client.base.clientInfo);
1551 virtual void setWindowFrame(WebPageProxy* page, const FloatRect& frame) override
1553 if (!m_client.setWindowFrame)
1556 m_client.setWindowFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1559 virtual FloatRect windowFrame(WebPageProxy* page) override
1561 if (!m_client.getWindowFrame)
1564 return toFloatRect(m_client.getWindowFrame(toAPI(page), m_client.base.clientInfo));
1567 virtual bool canRunBeforeUnloadConfirmPanel() const override
1569 return m_client.runBeforeUnloadConfirmPanel;
1572 virtual bool runBeforeUnloadConfirmPanel(WebPageProxy* page, const String& message, WebFrameProxy* frame) override
1574 if (!m_client.runBeforeUnloadConfirmPanel)
1577 return m_client.runBeforeUnloadConfirmPanel(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1580 virtual void didDraw(WebPageProxy* page) override
1582 if (!m_client.didDraw)
1585 m_client.didDraw(toAPI(page), m_client.base.clientInfo);
1588 virtual void pageDidScroll(WebPageProxy* page) override
1590 if (!m_client.pageDidScroll)
1593 m_client.pageDidScroll(toAPI(page), m_client.base.clientInfo);
1596 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
1598 if (!m_client.exceededDatabaseQuota) {
1599 completionHandler(currentQuota);
1603 completionHandler(m_client.exceededDatabaseQuota(toAPI(page), toAPI(frame), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, m_client.base.clientInfo));
1606 virtual bool runOpenPanel(WebPageProxy* page, WebFrameProxy* frame, WebOpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener) override
1608 if (!m_client.runOpenPanel)
1611 m_client.runOpenPanel(toAPI(page), toAPI(frame), toAPI(parameters), toAPI(listener), m_client.base.clientInfo);
1615 virtual bool decidePolicyForGeolocationPermissionRequest(WebPageProxy* page, WebFrameProxy* frame, API::SecurityOrigin* origin, GeolocationPermissionRequestProxy* permissionRequest) override
1617 if (!m_client.decidePolicyForGeolocationPermissionRequest)
1620 m_client.decidePolicyForGeolocationPermissionRequest(toAPI(page), toAPI(frame), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
1624 virtual bool decidePolicyForUserMediaPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, UserMediaPermissionRequestProxy& permissionRequest) override
1626 if (!m_client.decidePolicyForUserMediaPermissionRequest)
1629 m_client.decidePolicyForUserMediaPermissionRequest(toAPI(&page), toAPI(&frame), toAPI(&origin), toAPI(&permissionRequest), m_client.base.clientInfo);
1633 virtual bool decidePolicyForNotificationPermissionRequest(WebPageProxy* page, API::SecurityOrigin* origin, NotificationPermissionRequest* permissionRequest) override
1635 if (!m_client.decidePolicyForNotificationPermissionRequest)
1638 m_client.decidePolicyForNotificationPermissionRequest(toAPI(page), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
1643 virtual float headerHeight(WebPageProxy* page, WebFrameProxy* frame) override
1645 if (!m_client.headerHeight)
1648 return m_client.headerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1651 virtual float footerHeight(WebPageProxy* page, WebFrameProxy* frame) override
1653 if (!m_client.footerHeight)
1656 return m_client.footerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1659 virtual void drawHeader(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
1661 if (!m_client.drawHeader)
1664 m_client.drawHeader(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
1667 virtual void drawFooter(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
1669 if (!m_client.drawFooter)
1672 m_client.drawFooter(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
1675 virtual void printFrame(WebPageProxy* page, WebFrameProxy* frame) override
1677 if (!m_client.printFrame)
1680 m_client.printFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1683 virtual bool canRunModal() const override
1685 return m_client.runModal;
1688 virtual void runModal(WebPageProxy* page) override
1690 if (!m_client.runModal)
1693 m_client.runModal(toAPI(page), m_client.base.clientInfo);
1696 virtual void saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data) override
1698 if (!m_client.saveDataToFileInDownloadsFolder)
1701 m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURLString.impl()), toAPI(data), m_client.base.clientInfo);
1704 virtual bool shouldInterruptJavaScript(WebPageProxy* page) override
1706 if (!m_client.shouldInterruptJavaScript)
1709 return m_client.shouldInterruptJavaScript(toAPI(page), m_client.base.clientInfo);
1712 virtual void pinnedStateDidChange(WebPageProxy& page) override
1714 if (!m_client.pinnedStateDidChange)
1717 m_client.pinnedStateDidChange(toAPI(&page), m_client.base.clientInfo);
1720 virtual void didBeginTrackingPotentialLongMousePress(WebPageProxy* page, const IntPoint& mouseDownPosition, const WebHitTestResult::Data& data, API::Object* userInfo) override
1722 if (!m_client.didBeginTrackingPotentialLongMousePress)
1725 RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(data);
1726 m_client.didBeginTrackingPotentialLongMousePress(toAPI(page), toAPI(mouseDownPosition), toAPI(webHitTestResult.get()), toAPI(userInfo), m_client.base.clientInfo);
1729 virtual void didRecognizeLongMousePress(WebPageProxy* page, API::Object* userInfo) override
1731 if (!m_client.didRecognizeLongMousePress)
1734 m_client.didRecognizeLongMousePress(toAPI(page), toAPI(userInfo), m_client.base.clientInfo);
1737 virtual void didCancelTrackingPotentialLongMousePress(WebPageProxy* page, API::Object* userInfo) override
1739 if (!m_client.didCancelTrackingPotentialLongMousePress)
1742 m_client.didCancelTrackingPotentialLongMousePress(toAPI(page), toAPI(userInfo), m_client.base.clientInfo);
1745 virtual void isPlayingAudioDidChange(WebPageProxy& page) override
1747 if (!m_client.isPlayingAudioDidChange)
1750 m_client.isPlayingAudioDidChange(toAPI(&page), m_client.base.clientInfo);
1753 virtual void didClickAutoFillButton(WebPageProxy& page, API::Object* userInfo) override
1755 if (!m_client.didClickAutoFillButton)
1758 m_client.didClickAutoFillButton(toAPI(&page), toAPI(userInfo), m_client.base.clientInfo);
1762 toImpl(pageRef)->setUIClient(std::make_unique<UIClient>(wkClient));
1765 void WKPageSetPageNavigationClient(WKPageRef pageRef, const WKPageNavigationClientBase* wkClient)
1767 class NavigationClient : public API::Client<WKPageNavigationClientBase>, public API::NavigationClient {
1769 explicit NavigationClient(const WKPageNavigationClientBase* client)
1775 virtual void decidePolicyForNavigationAction(WebPageProxy& page, API::NavigationAction& navigationAction, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1777 if (!m_client.decidePolicyForNavigationAction)
1779 m_client.decidePolicyForNavigationAction(toAPI(&page), toAPI(&navigationAction), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1782 virtual void decidePolicyForNavigationResponse(WebPageProxy& page, API::NavigationResponse& navigationResponse, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1784 if (!m_client.decidePolicyForNavigationResponse)
1786 m_client.decidePolicyForNavigationResponse(toAPI(&page), toAPI(&navigationResponse), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1789 virtual void didStartProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1791 if (!m_client.didStartProvisionalNavigation)
1793 m_client.didStartProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1796 virtual void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1798 if (!m_client.didReceiveServerRedirectForProvisionalNavigation)
1800 m_client.didReceiveServerRedirectForProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1803 virtual void didFailProvisionalNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
1805 if (!m_client.didFailProvisionalNavigation)
1807 m_client.didFailProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1810 virtual void didCommitNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1812 if (!m_client.didCommitNavigation)
1814 m_client.didCommitNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1817 virtual void didFinishNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1819 if (!m_client.didFinishNavigation)
1821 m_client.didFinishNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1824 virtual void didFailNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
1826 if (!m_client.didFailNavigation)
1828 m_client.didFailNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1831 virtual void didFailProvisionalLoadInSubframeWithError(WebPageProxy& page, WebFrameProxy& subframe, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
1833 if (!m_client.didFailProvisionalLoadInSubframe)
1835 m_client.didFailProvisionalLoadInSubframe(toAPI(&page), toAPI(navigation), toAPI(API::FrameInfo::create(subframe).ptr()), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1838 virtual void didFinishDocumentLoad(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1840 if (!m_client.didFinishDocumentLoad)
1842 m_client.didFinishDocumentLoad(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1845 virtual void didSameDocumentNavigation(WebPageProxy& page, API::Navigation* navigation, WebKit::SameDocumentNavigationType navigationType, API::Object* userData) override
1847 if (!m_client.didSameDocumentNavigation)
1849 m_client.didSameDocumentNavigation(toAPI(&page), toAPI(navigation), toAPI(navigationType), toAPI(userData), m_client.base.clientInfo);
1852 virtual void renderingProgressDidChange(WebPageProxy& page, WebCore::LayoutMilestones milestones, API::Object* userData) override
1854 if (!m_client.renderingProgressDidChange)
1856 m_client.renderingProgressDidChange(toAPI(&page), pageRenderingProgressEvents(milestones), toAPI(userData), m_client.base.clientInfo);
1859 virtual bool canAuthenticateAgainstProtectionSpace(WebPageProxy& page, WebProtectionSpace* protectionSpace) override
1861 if (!m_client.canAuthenticateAgainstProtectionSpace)
1863 return m_client.canAuthenticateAgainstProtectionSpace(toAPI(&page), toAPI(protectionSpace), m_client.base.clientInfo);
1866 virtual void didReceiveAuthenticationChallenge(WebPageProxy& page, AuthenticationChallengeProxy* authenticationChallenge) override
1868 if (!m_client.didReceiveAuthenticationChallenge)
1870 m_client.didReceiveAuthenticationChallenge(toAPI(&page), toAPI(authenticationChallenge), m_client.base.clientInfo);
1873 virtual void processDidCrash(WebPageProxy& page) override
1875 if (!m_client.webProcessDidCrash)
1877 m_client.webProcessDidCrash(toAPI(&page), m_client.base.clientInfo);
1880 virtual PassRefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
1882 if (!m_client.copyWebCryptoMasterKey)
1884 return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(&page), m_client.base.clientInfo)));
1887 #if ENABLE(NETSCAPE_PLUGIN_API)
1888 virtual PluginModuleLoadPolicy decidePolicyForPluginLoad(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
1890 WKStringRef unavailabilityDescriptionOut = 0;
1891 PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
1893 if (m_client.decidePolicyForPluginLoad)
1894 loadPolicy = toPluginModuleLoadPolicy(m_client.decidePolicyForPluginLoad(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
1896 if (unavailabilityDescriptionOut) {
1897 RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
1898 unavailabilityDescription = webUnavailabilityDescription->string();
1906 WebPageProxy* webPageProxy = toImpl(pageRef);
1908 auto navigationClient = std::make_unique<NavigationClient>(wkClient);
1909 webPageProxy->setNavigationClient(WTF::move(navigationClient));
1912 void WKPageSetSession(WKPageRef pageRef, WKSessionRef session)
1914 toImpl(pageRef)->setSessionID(toImpl(session)->getID());
1917 void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback)
1919 toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), toGenericCallbackFunction(context, callback));
1923 static void callRunJavaScriptBlockAndRelease(WKSerializedScriptValueRef resultValue, WKErrorRef error, void* context)
1925 WKPageRunJavaScriptBlock block = (WKPageRunJavaScriptBlock)context;
1926 block(resultValue, error);
1927 Block_release(block);
1930 void WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef, WKStringRef scriptRef, WKPageRunJavaScriptBlock block)
1932 WKPageRunJavaScriptInMainFrame(pageRef, scriptRef, Block_copy(block), callRunJavaScriptBlockAndRelease);
1936 static std::function<void (const String&, WebKit::CallbackBase::Error)> toGenericCallbackFunction(void* context, void (*callback)(WKStringRef, WKErrorRef, void*))
1938 return [context, callback](const String& returnValue, WebKit::CallbackBase::Error error) {
1939 callback(toAPI(API::String::create(returnValue).get()), error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
1943 void WKPageRenderTreeExternalRepresentation(WKPageRef pageRef, void* context, WKPageRenderTreeExternalRepresentationFunction callback)
1945 toImpl(pageRef)->getRenderTreeExternalRepresentation(toGenericCallbackFunction(context, callback));
1948 void WKPageGetSourceForFrame(WKPageRef pageRef, WKFrameRef frameRef, void* context, WKPageGetSourceForFrameFunction callback)
1950 toImpl(pageRef)->getSourceForFrame(toImpl(frameRef), toGenericCallbackFunction(context, callback));
1953 void WKPageGetContentsAsString(WKPageRef pageRef, void* context, WKPageGetContentsAsStringFunction callback)
1955 toImpl(pageRef)->getContentsAsString(toGenericCallbackFunction(context, callback));
1958 void WKPageGetBytecodeProfile(WKPageRef pageRef, void* context, WKPageGetBytecodeProfileFunction callback)
1960 toImpl(pageRef)->getBytecodeProfile(toGenericCallbackFunction(context, callback));
1963 void WKPageGetSelectionAsWebArchiveData(WKPageRef pageRef, void* context, WKPageGetSelectionAsWebArchiveDataFunction callback)
1965 toImpl(pageRef)->getSelectionAsWebArchiveData(toGenericCallbackFunction(context, callback));
1968 void WKPageGetContentsAsMHTMLData(WKPageRef pageRef, bool useBinaryEncoding, void* context, WKPageGetContentsAsMHTMLDataFunction callback)
1971 toImpl(pageRef)->getContentsAsMHTMLData(toGenericCallbackFunction(context, callback), useBinaryEncoding);
1973 UNUSED_PARAM(pageRef);
1974 UNUSED_PARAM(useBinaryEncoding);
1975 UNUSED_PARAM(context);
1976 UNUSED_PARAM(callback);
1980 void WKPageForceRepaint(WKPageRef pageRef, void* context, WKPageForceRepaintFunction callback)
1982 toImpl(pageRef)->forceRepaint(VoidCallback::create([context, callback](WebKit::CallbackBase::Error error) {
1983 callback(error == WebKit::CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().get()), context);
1987 WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef pageRef)
1989 const String& pendingAPIRequestURL = toImpl(pageRef)->pageLoadState().pendingAPIRequestURL();
1991 if (pendingAPIRequestURL.isNull())
1994 return toCopiedURLAPI(pendingAPIRequestURL);
1997 WKURLRef WKPageCopyActiveURL(WKPageRef pageRef)
1999 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().activeURL());
2002 WKURLRef WKPageCopyProvisionalURL(WKPageRef pageRef)
2004 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().provisionalURL());
2007 WKURLRef WKPageCopyCommittedURL(WKPageRef pageRef)
2009 return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().url());
2012 WKStringRef WKPageCopyStandardUserAgentWithApplicationName(WKStringRef applicationName)
2014 return toCopiedAPI(WebPageProxy::standardUserAgent(toImpl(applicationName)->string()));
2017 void WKPageValidateCommand(WKPageRef pageRef, WKStringRef command, void* context, WKPageValidateCommandCallback callback)
2019 toImpl(pageRef)->validateCommand(toImpl(command)->string(), [context, callback](const String& commandName, bool isEnabled, int32_t state, WebKit::CallbackBase::Error error) {
2020 callback(toAPI(API::String::create(commandName).get()), isEnabled, state, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
2024 void WKPageExecuteCommand(WKPageRef pageRef, WKStringRef command)
2026 toImpl(pageRef)->executeEditCommand(toImpl(command)->string());
2030 static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo)
2033 result.pageSetupScaleFactor = printInfo.pageSetupScaleFactor;
2034 result.availablePaperWidth = printInfo.availablePaperWidth;
2035 result.availablePaperHeight = printInfo.availablePaperHeight;
2039 void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, WKPageComputePagesForPrintingFunction callback, void* context)
2041 toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create([context, callback](const Vector<WebCore::IntRect>& rects, double scaleFactor, WebKit::CallbackBase::Error error) {
2042 Vector<WKRect> wkRects(rects.size());
2043 for (size_t i = 0; i < rects.size(); ++i)
2044 wkRects[i] = toAPI(rects[i]);
2045 callback(wkRects.data(), wkRects.size(), scaleFactor, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
2049 void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo)
2051 toImpl(page)->beginPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo));
2054 void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
2056 toImpl(page)->drawPagesToPDF(toImpl(frame), printInfoFromWKPrintInfo(printInfo), first, count, DataCallback::create(toGenericCallbackFunction(context, callback)));
2059 void WKPageEndPrinting(WKPageRef page)
2061 toImpl(page)->endPrinting();
2065 void WKPageSetShouldSendEventsSynchronously(WKPageRef page, bool sync)
2067 toImpl(page)->setShouldSendEventsSynchronously(sync);
2070 bool WKPageGetAllowsRemoteInspection(WKPageRef page)
2072 #if ENABLE(REMOTE_INSPECTOR)
2073 return toImpl(page)->allowsRemoteInspection();
2080 void WKPageSetAllowsRemoteInspection(WKPageRef page, bool allow)
2082 #if ENABLE(REMOTE_INSPECTOR)
2083 toImpl(page)->setAllowsRemoteInspection(allow);
2086 UNUSED_PARAM(allow);
2090 void WKPageSetMediaVolume(WKPageRef page, float volume)
2092 toImpl(page)->setMediaVolume(volume);
2095 void WKPageSetMuted(WKPageRef page, bool muted)
2097 toImpl(page)->setMuted(muted);
2100 void WKPagePostMessageToInjectedBundle(WKPageRef pageRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef)
2102 toImpl(pageRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef));
2105 WKArrayRef WKPageCopyRelatedPages(WKPageRef pageRef)
2107 Vector<RefPtr<API::Object>> relatedPages;
2109 for (auto& page : toImpl(pageRef)->process().pages()) {
2110 if (page != toImpl(pageRef))
2111 relatedPages.append(page);
2114 return toAPI(API::Array::create(WTF::move(relatedPages)).leakRef());
2117 void WKPageSetMayStartMediaWhenInWindow(WKPageRef pageRef, bool mayStartMedia)
2119 toImpl(pageRef)->setMayStartMediaWhenInWindow(mayStartMedia);
2123 void WKPageSelectContextMenuItem(WKPageRef page, WKContextMenuItemRef item)
2125 #if ENABLE(CONTEXT_MENUS)
2126 toImpl(page)->contextMenuItemSelected(*(toImpl(item)->data()));
2133 WKScrollPinningBehavior WKPageGetScrollPinningBehavior(WKPageRef page)
2135 ScrollPinningBehavior pinning = toImpl(page)->scrollPinningBehavior();
2138 case WebCore::ScrollPinningBehavior::DoNotPin:
2139 return kWKScrollPinningBehaviorDoNotPin;
2140 case WebCore::ScrollPinningBehavior::PinToTop:
2141 return kWKScrollPinningBehaviorPinToTop;
2142 case WebCore::ScrollPinningBehavior::PinToBottom:
2143 return kWKScrollPinningBehaviorPinToBottom;
2146 ASSERT_NOT_REACHED();
2147 return kWKScrollPinningBehaviorDoNotPin;
2150 void WKPageSetScrollPinningBehavior(WKPageRef page, WKScrollPinningBehavior pinning)
2152 ScrollPinningBehavior corePinning = ScrollPinningBehavior::DoNotPin;
2155 case kWKScrollPinningBehaviorDoNotPin:
2156 corePinning = ScrollPinningBehavior::DoNotPin;
2158 case kWKScrollPinningBehaviorPinToTop:
2159 corePinning = ScrollPinningBehavior::PinToTop;
2161 case kWKScrollPinningBehaviorPinToBottom:
2162 corePinning = ScrollPinningBehavior::PinToBottom;
2165 ASSERT_NOT_REACHED();
2168 toImpl(page)->setScrollPinningBehavior(corePinning);
2171 bool WKPageGetAddsVisitedLinks(WKPageRef page)
2173 return toImpl(page)->addsVisitedLinks();
2176 void WKPageSetAddsVisitedLinks(WKPageRef page, bool addsVisitedLinks)
2178 toImpl(page)->setAddsVisitedLinks(addsVisitedLinks);
2181 bool WKPageIsPlayingAudio(WKPageRef page)
2183 return toImpl(page)->isPlayingAudio();
2186 #if ENABLE(NETSCAPE_PLUGIN_API)
2190 WKStringRef WKPageGetPluginInformationBundleIdentifierKey()
2192 return WKPluginInformationBundleIdentifierKey();
2195 WKStringRef WKPageGetPluginInformationBundleVersionKey()
2197 return WKPluginInformationBundleVersionKey();
2200 WKStringRef WKPageGetPluginInformationDisplayNameKey()
2202 return WKPluginInformationDisplayNameKey();
2205 WKStringRef WKPageGetPluginInformationFrameURLKey()
2207 return WKPluginInformationFrameURLKey();
2210 WKStringRef WKPageGetPluginInformationMIMETypeKey()
2212 return WKPluginInformationMIMETypeKey();
2215 WKStringRef WKPageGetPluginInformationPageURLKey()
2217 return WKPluginInformationPageURLKey();
2220 WKStringRef WKPageGetPluginInformationPluginspageAttributeURLKey()
2222 return WKPluginInformationPluginspageAttributeURLKey();
2225 WKStringRef WKPageGetPluginInformationPluginURLKey()
2227 return WKPluginInformationPluginURLKey();
2232 #endif // ENABLE(NETSCAPE_PLUGIN_API)