Add WKPageNavigationClient as C SPI around API::NavigationClient, and adopt in WKTR
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / C / WKPage.cpp
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25
26 #include "config.h"
27 #include "WKPage.h"
28 #include "WKPagePrivate.h"
29
30 #include "APIArray.h"
31 #include "APIContextMenuClient.h"
32 #include "APIData.h"
33 #include "APIDictionary.h"
34 #include "APIFindClient.h"
35 #include "APIFrameInfo.h"
36 #include "APILoaderClient.h"
37 #include "APINavigationClient.h"
38 #include "APIPolicyClient.h"
39 #include "APISessionState.h"
40 #include "APIUIClient.h"
41 #include "AuthenticationChallengeProxy.h"
42 #include "LegacySessionStateCoding.h"
43 #include "Logging.h"
44 #include "NativeWebKeyboardEvent.h"
45 #include "NativeWebWheelEvent.h"
46 #include "NavigationActionData.h"
47 #include "PluginInformation.h"
48 #include "PrintInfo.h"
49 #include "WKAPICast.h"
50 #include "WKPagePolicyClientInternal.h"
51 #include "WKPageRenderingProgressEventsInternal.h"
52 #include "WKPluginInformation.h"
53 #include "WebBackForwardList.h"
54 #include "WebFormClient.h"
55 #include "WebInspectorProxy.h"
56 #include "WebOpenPanelParameters.h"
57 #include "WebOpenPanelResultListenerProxy.h"
58 #include "WebPageGroup.h"
59 #include "WebPageMessages.h"
60 #include "WebPageProxy.h"
61 #include "WebProcessPool.h"
62 #include "WebProcessProxy.h"
63 #include "WebProtectionSpace.h"
64 #include <WebCore/Page.h>
65 #include <WebCore/WindowFeatures.h>
66
67 #ifdef __BLOCKS__
68 #include <Block.h>
69 #endif
70
71 #if ENABLE(CONTEXT_MENUS)
72 #include "WebContextMenuItem.h"
73 #endif
74
75 using namespace WebCore;
76 using namespace WebKit;
77
78 namespace API {
79 template<> struct ClientTraits<WKPageLoaderClientBase> {
80     typedef std::tuple<WKPageLoaderClientV0, WKPageLoaderClientV1, WKPageLoaderClientV2, WKPageLoaderClientV3, WKPageLoaderClientV4, WKPageLoaderClientV5> Versions;
81 };
82
83 template<> struct ClientTraits<WKPageNavigationClientBase> {
84     typedef std::tuple<WKPageNavigationClientV0> Versions;
85 };
86
87 template<> struct ClientTraits<WKPagePolicyClientBase> {
88     typedef std::tuple<WKPagePolicyClientV0, WKPagePolicyClientV1, WKPagePolicyClientInternal> Versions;
89 };
90
91 template<> struct ClientTraits<WKPageUIClientBase> {
92     typedef std::tuple<WKPageUIClientV0, WKPageUIClientV1, WKPageUIClientV2, WKPageUIClientV3, WKPageUIClientV4, WKPageUIClientV5> Versions;
93 };
94
95 #if ENABLE(CONTEXT_MENUS)
96 template<> struct ClientTraits<WKPageContextMenuClientBase> {
97     typedef std::tuple<WKPageContextMenuClientV0, WKPageContextMenuClientV1, WKPageContextMenuClientV2, WKPageContextMenuClientV3> Versions;
98 };
99 #endif
100
101 }
102
103 WKTypeID WKPageGetTypeID()
104 {
105     return toAPI(WebPageProxy::APIType);
106 }
107
108 WKContextRef WKPageGetContext(WKPageRef pageRef)
109 {
110     return toAPI(&toImpl(pageRef)->process().processPool());
111 }
112
113 WKPageGroupRef WKPageGetPageGroup(WKPageRef pageRef)
114 {
115     return toAPI(&toImpl(pageRef)->pageGroup());
116 }
117
118 void WKPageLoadURL(WKPageRef pageRef, WKURLRef URLRef)
119 {
120     toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)));
121 }
122
123 void WKPageLoadURLWithUserData(WKPageRef pageRef, WKURLRef URLRef, WKTypeRef userDataRef)
124 {
125     toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), toImpl(userDataRef));
126 }
127
128 void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef)
129 {
130     toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest());
131 }
132
133 void WKPageLoadURLRequestWithUserData(WKPageRef pageRef, WKURLRequestRef urlRequestRef, WKTypeRef userDataRef)
134 {
135     toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest(), toImpl(userDataRef));
136 }
137
138 void WKPageLoadFile(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL)
139 {
140     toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL));
141 }
142
143 void WKPageLoadFileWithUserData(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL, WKTypeRef userDataRef)
144 {
145     toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL), toImpl(userDataRef));
146 }
147
148 void WKPageLoadData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef)
149 {
150     toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef));
151 }
152
153 void WKPageLoadDataWithUserData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
154 {
155     toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef), toImpl(userDataRef));
156 }
157
158 void WKPageLoadHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef)
159 {
160     toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef));
161 }
162
163 void WKPageLoadHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
164 {
165     toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toImpl(userDataRef));
166 }
167
168 void WKPageLoadAlternateHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef)
169 {
170     toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef));
171 }
172
173 void WKPageLoadAlternateHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef, WKTypeRef userDataRef)
174 {
175     toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef), toImpl(userDataRef));
176 }
177
178 void WKPageLoadPlainTextString(WKPageRef pageRef, WKStringRef plainTextStringRef)
179 {
180     toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef));    
181 }
182
183 void WKPageLoadPlainTextStringWithUserData(WKPageRef pageRef, WKStringRef plainTextStringRef, WKTypeRef userDataRef)
184 {
185     toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef), toImpl(userDataRef));    
186 }
187
188 void WKPageLoadWebArchiveData(WKPageRef pageRef, WKDataRef webArchiveDataRef)
189 {
190     toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef));
191 }
192
193 void WKPageLoadWebArchiveDataWithUserData(WKPageRef pageRef, WKDataRef webArchiveDataRef, WKTypeRef userDataRef)
194 {
195     toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef), toImpl(userDataRef));
196 }
197
198 void WKPageStopLoading(WKPageRef pageRef)
199 {
200     toImpl(pageRef)->stopLoading();
201 }
202
203 void WKPageReload(WKPageRef pageRef)
204 {
205     toImpl(pageRef)->reload(false);
206 }
207
208 void WKPageReloadFromOrigin(WKPageRef pageRef)
209 {
210     toImpl(pageRef)->reload(true);
211 }
212
213 bool WKPageTryClose(WKPageRef pageRef)
214 {
215     return toImpl(pageRef)->tryClose();
216 }
217
218 void WKPageClose(WKPageRef pageRef)
219 {
220     toImpl(pageRef)->close();
221 }
222
223 bool WKPageIsClosed(WKPageRef pageRef)
224 {
225     return toImpl(pageRef)->isClosed();
226 }
227
228 void WKPageGoForward(WKPageRef pageRef)
229 {
230     toImpl(pageRef)->goForward();
231 }
232
233 bool WKPageCanGoForward(WKPageRef pageRef)
234 {
235     return toImpl(pageRef)->backForwardList().forwardItem();
236 }
237
238 void WKPageGoBack(WKPageRef pageRef)
239 {
240     toImpl(pageRef)->goBack();
241 }
242
243 bool WKPageCanGoBack(WKPageRef pageRef)
244 {
245     return toImpl(pageRef)->backForwardList().backItem();
246 }
247
248 void WKPageGoToBackForwardListItem(WKPageRef pageRef, WKBackForwardListItemRef itemRef)
249 {
250     toImpl(pageRef)->goToBackForwardItem(toImpl(itemRef));
251 }
252
253 void WKPageTryRestoreScrollPosition(WKPageRef pageRef)
254 {
255     toImpl(pageRef)->tryRestoreScrollPosition();
256 }
257
258 WKBackForwardListRef WKPageGetBackForwardList(WKPageRef pageRef)
259 {
260     return toAPI(&toImpl(pageRef)->backForwardList());
261 }
262
263 bool WKPageWillHandleHorizontalScrollEvents(WKPageRef pageRef)
264 {
265     return toImpl(pageRef)->willHandleHorizontalScrollEvents();
266 }
267
268 WKStringRef WKPageCopyTitle(WKPageRef pageRef)
269 {
270     return toCopiedAPI(toImpl(pageRef)->pageLoadState().title());
271 }
272
273 WKFrameRef WKPageGetMainFrame(WKPageRef pageRef)
274 {
275     return toAPI(toImpl(pageRef)->mainFrame());
276 }
277
278 WKFrameRef WKPageGetFocusedFrame(WKPageRef pageRef)
279 {
280     return toAPI(toImpl(pageRef)->focusedFrame());
281 }
282
283 WKFrameRef WKPageGetFrameSetLargestFrame(WKPageRef pageRef)
284 {
285     return toAPI(toImpl(pageRef)->frameSetLargestFrame());
286 }
287
288 uint64_t WKPageGetRenderTreeSize(WKPageRef page)
289 {
290     return toImpl(page)->renderTreeSize();
291 }
292
293 WKInspectorRef WKPageGetInspector(WKPageRef pageRef)
294 {
295     return toAPI(toImpl(pageRef)->inspector());
296 }
297
298 WKVibrationRef WKPageGetVibration(WKPageRef page)
299 {
300 #if ENABLE(VIBRATION)
301     return toAPI(toImpl(page)->vibration());
302 #else
303     UNUSED_PARAM(page);
304     return 0;
305 #endif
306 }
307
308 double WKPageGetEstimatedProgress(WKPageRef pageRef)
309 {
310     return toImpl(pageRef)->estimatedProgress();
311 }
312
313 WKStringRef WKPageCopyUserAgent(WKPageRef pageRef)
314 {
315     return toCopiedAPI(toImpl(pageRef)->userAgent());
316 }
317
318 WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef pageRef)
319 {
320     return toCopiedAPI(toImpl(pageRef)->applicationNameForUserAgent());
321 }
322
323 void WKPageSetApplicationNameForUserAgent(WKPageRef pageRef, WKStringRef applicationNameRef)
324 {
325     toImpl(pageRef)->setApplicationNameForUserAgent(toWTFString(applicationNameRef));
326 }
327
328 WKStringRef WKPageCopyCustomUserAgent(WKPageRef pageRef)
329 {
330     return toCopiedAPI(toImpl(pageRef)->customUserAgent());
331 }
332
333 void WKPageSetCustomUserAgent(WKPageRef pageRef, WKStringRef userAgentRef)
334 {
335     toImpl(pageRef)->setCustomUserAgent(toWTFString(userAgentRef));
336 }
337
338 bool WKPageSupportsTextEncoding(WKPageRef pageRef)
339 {
340     return toImpl(pageRef)->supportsTextEncoding();
341 }
342
343 WKStringRef WKPageCopyCustomTextEncodingName(WKPageRef pageRef)
344 {
345     return toCopiedAPI(toImpl(pageRef)->customTextEncodingName());
346 }
347
348 void WKPageSetCustomTextEncodingName(WKPageRef pageRef, WKStringRef encodingNameRef)
349 {
350     toImpl(pageRef)->setCustomTextEncodingName(toWTFString(encodingNameRef));
351 }
352
353 void WKPageTerminate(WKPageRef pageRef)
354 {
355     toImpl(pageRef)->terminateProcess();
356 }
357
358 WKStringRef WKPageGetSessionHistoryURLValueType()
359 {
360     static API::String* sessionHistoryURLValueType = API::String::create("SessionHistoryURL").leakRef();
361     return toAPI(sessionHistoryURLValueType);
362 }
363
364 WKStringRef WKPageGetSessionBackForwardListItemValueType()
365 {
366     static API::String* sessionBackForwardListValueType = API::String::create("SessionBackForwardListItem").leakRef();
367     return toAPI(sessionBackForwardListValueType);
368 }
369
370 WKTypeRef WKPageCopySessionState(WKPageRef pageRef, void* context, WKPageSessionStateFilterCallback filter)
371 {
372     // FIXME: This is a hack to make sure we return a WKDataRef to maintain compatibility with older versions of Safari.
373     bool shouldReturnData = !(reinterpret_cast<uintptr_t>(context) & 1);
374     context = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(context) & ~1);
375
376     auto sessionState = toImpl(pageRef)->sessionState([pageRef, context, filter](WebBackForwardListItem& item) {
377         if (filter) {
378             if (!filter(pageRef, WKPageGetSessionBackForwardListItemValueType(), toAPI(&item), context))
379                 return false;
380
381             if (!filter(pageRef, WKPageGetSessionHistoryURLValueType(), toURLRef(item.originalURL().impl()), context))
382                 return false;
383         }
384
385         return true;
386     });
387
388     if (shouldReturnData)
389         return toAPI(encodeLegacySessionState(sessionState).release().leakRef());
390
391     return toAPI(API::SessionState::create(WTF::move(sessionState)).leakRef());
392 }
393
394 void WKPageRestoreFromSessionState(WKPageRef pageRef, WKTypeRef sessionStateRef)
395 {
396     SessionState sessionState;
397
398     // FIXME: This is for backwards compatibility with Safari. Remove it once Safari no longer depends on it.
399     if (toImpl(sessionStateRef)->type() == API::Object::Type::Data) {
400         if (!decodeLegacySessionState(toImpl(static_cast<WKDataRef>(sessionStateRef))->bytes(), toImpl(static_cast<WKDataRef>(sessionStateRef))->size(), sessionState))
401             return;
402     } else {
403         ASSERT(toImpl(sessionStateRef)->type() == API::Object::Type::SessionState);
404
405         sessionState = toImpl(static_cast<WKSessionStateRef>(sessionStateRef))->sessionState();
406     }
407
408     toImpl(pageRef)->restoreFromSessionState(WTF::move(sessionState), true);
409 }
410
411 double WKPageGetTextZoomFactor(WKPageRef pageRef)
412 {
413     return toImpl(pageRef)->textZoomFactor();
414 }
415
416 double WKPageGetBackingScaleFactor(WKPageRef pageRef)
417 {
418     return toImpl(pageRef)->deviceScaleFactor();
419 }
420
421 void WKPageSetCustomBackingScaleFactor(WKPageRef pageRef, double customScaleFactor)
422 {
423     toImpl(pageRef)->setCustomDeviceScaleFactor(customScaleFactor);
424 }
425
426 bool WKPageSupportsTextZoom(WKPageRef pageRef)
427 {
428     return toImpl(pageRef)->supportsTextZoom();
429 }
430
431 void WKPageSetTextZoomFactor(WKPageRef pageRef, double zoomFactor)
432 {
433     toImpl(pageRef)->setTextZoomFactor(zoomFactor);
434 }
435
436 double WKPageGetPageZoomFactor(WKPageRef pageRef)
437 {
438     return toImpl(pageRef)->pageZoomFactor();
439 }
440
441 void WKPageSetPageZoomFactor(WKPageRef pageRef, double zoomFactor)
442 {
443     toImpl(pageRef)->setPageZoomFactor(zoomFactor);
444 }
445
446 void WKPageSetPageAndTextZoomFactors(WKPageRef pageRef, double pageZoomFactor, double textZoomFactor)
447 {
448     toImpl(pageRef)->setPageAndTextZoomFactors(pageZoomFactor, textZoomFactor);
449 }
450
451 void WKPageSetScaleFactor(WKPageRef pageRef, double scale, WKPoint origin)
452 {
453     toImpl(pageRef)->scalePage(scale, toIntPoint(origin));
454 }
455
456 double WKPageGetScaleFactor(WKPageRef pageRef)
457 {
458     return toImpl(pageRef)->pageScaleFactor();
459 }
460
461 void WKPageSetUseFixedLayout(WKPageRef pageRef, bool fixed)
462 {
463     toImpl(pageRef)->setUseFixedLayout(fixed);
464 }
465
466 void WKPageSetFixedLayoutSize(WKPageRef pageRef, WKSize size)
467 {
468     toImpl(pageRef)->setFixedLayoutSize(toIntSize(size));
469 }
470
471 bool WKPageUseFixedLayout(WKPageRef pageRef)
472 {
473     return toImpl(pageRef)->useFixedLayout();
474 }
475
476 WKSize WKPageFixedLayoutSize(WKPageRef pageRef)
477 {
478     return toAPI(toImpl(pageRef)->fixedLayoutSize());
479 }
480
481 void WKPageListenForLayoutMilestones(WKPageRef pageRef, WKLayoutMilestones milestones)
482 {
483     toImpl(pageRef)->listenForLayoutMilestones(toLayoutMilestones(milestones));
484 }
485
486 bool WKPageHasHorizontalScrollbar(WKPageRef pageRef)
487 {
488     return toImpl(pageRef)->hasHorizontalScrollbar();
489 }
490
491 bool WKPageHasVerticalScrollbar(WKPageRef pageRef)
492 {
493     return toImpl(pageRef)->hasVerticalScrollbar();
494 }
495
496 void WKPageSetSuppressScrollbarAnimations(WKPageRef pageRef, bool suppressAnimations)
497 {
498     toImpl(pageRef)->setSuppressScrollbarAnimations(suppressAnimations);
499 }
500
501 bool WKPageAreScrollbarAnimationsSuppressed(WKPageRef pageRef)
502 {
503     return toImpl(pageRef)->areScrollbarAnimationsSuppressed();
504 }
505
506 bool WKPageIsPinnedToLeftSide(WKPageRef pageRef)
507 {
508     return toImpl(pageRef)->isPinnedToLeftSide();
509 }
510
511 bool WKPageIsPinnedToRightSide(WKPageRef pageRef)
512 {
513     return toImpl(pageRef)->isPinnedToRightSide();
514 }
515
516 bool WKPageIsPinnedToTopSide(WKPageRef pageRef)
517 {
518     return toImpl(pageRef)->isPinnedToTopSide();
519 }
520
521 bool WKPageIsPinnedToBottomSide(WKPageRef pageRef)
522 {
523     return toImpl(pageRef)->isPinnedToBottomSide();
524 }
525
526 bool WKPageRubberBandsAtLeft(WKPageRef pageRef)
527 {
528     return toImpl(pageRef)->rubberBandsAtLeft();
529 }
530
531 void WKPageSetRubberBandsAtLeft(WKPageRef pageRef, bool rubberBandsAtLeft)
532 {
533     toImpl(pageRef)->setRubberBandsAtLeft(rubberBandsAtLeft);
534 }
535
536 bool WKPageRubberBandsAtRight(WKPageRef pageRef)
537 {
538     return toImpl(pageRef)->rubberBandsAtRight();
539 }
540
541 void WKPageSetRubberBandsAtRight(WKPageRef pageRef, bool rubberBandsAtRight)
542 {
543     toImpl(pageRef)->setRubberBandsAtRight(rubberBandsAtRight);
544 }
545
546 bool WKPageRubberBandsAtTop(WKPageRef pageRef)
547 {
548     return toImpl(pageRef)->rubberBandsAtTop();
549 }
550
551 void WKPageSetRubberBandsAtTop(WKPageRef pageRef, bool rubberBandsAtTop)
552 {
553     toImpl(pageRef)->setRubberBandsAtTop(rubberBandsAtTop);
554 }
555
556 bool WKPageRubberBandsAtBottom(WKPageRef pageRef)
557 {
558     return toImpl(pageRef)->rubberBandsAtBottom();
559 }
560
561 void WKPageSetRubberBandsAtBottom(WKPageRef pageRef, bool rubberBandsAtBottom)
562 {
563     toImpl(pageRef)->setRubberBandsAtBottom(rubberBandsAtBottom);
564 }
565
566 bool WKPageVerticalRubberBandingIsEnabled(WKPageRef pageRef)
567 {
568     return toImpl(pageRef)->verticalRubberBandingIsEnabled();
569 }
570
571 void WKPageSetEnableVerticalRubberBanding(WKPageRef pageRef, bool enableVerticalRubberBanding)
572 {
573     toImpl(pageRef)->setEnableVerticalRubberBanding(enableVerticalRubberBanding);
574 }
575
576 bool WKPageHorizontalRubberBandingIsEnabled(WKPageRef pageRef)
577 {
578     return toImpl(pageRef)->horizontalRubberBandingIsEnabled();
579 }
580
581 void WKPageSetEnableHorizontalRubberBanding(WKPageRef pageRef, bool enableHorizontalRubberBanding)
582 {
583     toImpl(pageRef)->setEnableHorizontalRubberBanding(enableHorizontalRubberBanding);
584 }
585
586 void WKPageSetBackgroundExtendsBeyondPage(WKPageRef pageRef, bool backgroundExtendsBeyondPage)
587 {
588     toImpl(pageRef)->setBackgroundExtendsBeyondPage(backgroundExtendsBeyondPage);
589 }
590
591 bool WKPageBackgroundExtendsBeyondPage(WKPageRef pageRef)
592 {
593     return toImpl(pageRef)->backgroundExtendsBeyondPage();
594 }
595
596 void WKPageSetPaginationMode(WKPageRef pageRef, WKPaginationMode paginationMode)
597 {
598     Pagination::Mode mode;
599     switch (paginationMode) {
600     case kWKPaginationModeUnpaginated:
601         mode = Pagination::Unpaginated;
602         break;
603     case kWKPaginationModeLeftToRight:
604         mode = Pagination::LeftToRightPaginated;
605         break;
606     case kWKPaginationModeRightToLeft:
607         mode = Pagination::RightToLeftPaginated;
608         break;
609     case kWKPaginationModeTopToBottom:
610         mode = Pagination::TopToBottomPaginated;
611         break;
612     case kWKPaginationModeBottomToTop:
613         mode = Pagination::BottomToTopPaginated;
614         break;
615     default:
616         return;
617     }
618     toImpl(pageRef)->setPaginationMode(mode);
619 }
620
621 WKPaginationMode WKPageGetPaginationMode(WKPageRef pageRef)
622 {
623     switch (toImpl(pageRef)->paginationMode()) {
624     case Pagination::Unpaginated:
625         return kWKPaginationModeUnpaginated;
626     case Pagination::LeftToRightPaginated:
627         return kWKPaginationModeLeftToRight;
628     case Pagination::RightToLeftPaginated:
629         return kWKPaginationModeRightToLeft;
630     case Pagination::TopToBottomPaginated:
631         return kWKPaginationModeTopToBottom;
632     case Pagination::BottomToTopPaginated:
633         return kWKPaginationModeBottomToTop;
634     }
635
636     ASSERT_NOT_REACHED();
637     return kWKPaginationModeUnpaginated;
638 }
639
640 void WKPageSetPaginationBehavesLikeColumns(WKPageRef pageRef, bool behavesLikeColumns)
641 {
642     toImpl(pageRef)->setPaginationBehavesLikeColumns(behavesLikeColumns);
643 }
644
645 bool WKPageGetPaginationBehavesLikeColumns(WKPageRef pageRef)
646 {
647     return toImpl(pageRef)->paginationBehavesLikeColumns();
648 }
649
650 void WKPageSetPageLength(WKPageRef pageRef, double pageLength)
651 {
652     toImpl(pageRef)->setPageLength(pageLength);
653 }
654
655 double WKPageGetPageLength(WKPageRef pageRef)
656 {
657     return toImpl(pageRef)->pageLength();
658 }
659
660 void WKPageSetGapBetweenPages(WKPageRef pageRef, double gap)
661 {
662     toImpl(pageRef)->setGapBetweenPages(gap);
663 }
664
665 double WKPageGetGapBetweenPages(WKPageRef pageRef)
666 {
667     return toImpl(pageRef)->gapBetweenPages();
668 }
669
670 unsigned WKPageGetPageCount(WKPageRef pageRef)
671 {
672     return toImpl(pageRef)->pageCount();
673 }
674
675 bool WKPageCanDelete(WKPageRef pageRef)
676 {
677     return toImpl(pageRef)->canDelete();
678 }
679
680 bool WKPageHasSelectedRange(WKPageRef pageRef)
681 {
682     return toImpl(pageRef)->hasSelectedRange();
683 }
684
685 bool WKPageIsContentEditable(WKPageRef pageRef)
686 {
687     return toImpl(pageRef)->isContentEditable();
688 }
689
690 void WKPageSetMaintainsInactiveSelection(WKPageRef pageRef, bool newValue)
691 {
692     return toImpl(pageRef)->setMaintainsInactiveSelection(newValue);
693 }
694
695 void WKPageCenterSelectionInVisibleArea(WKPageRef pageRef)
696 {
697     return toImpl(pageRef)->centerSelectionInVisibleArea();
698 }
699
700 void WKPageFindStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
701 {
702     toImpl(pageRef)->findStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
703 }
704
705 void WKPageGetImageForFindMatch(WKPageRef pageRef, int32_t matchIndex)
706 {
707     toImpl(pageRef)->getImageForFindMatch(matchIndex);
708 }
709
710 void WKPageSelectFindMatch(WKPageRef pageRef, int32_t matchIndex)
711 {
712     toImpl(pageRef)->selectFindMatch(matchIndex);
713 }
714
715 void WKPageFindString(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
716 {
717     toImpl(pageRef)->findString(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
718 }
719
720 void WKPageHideFindUI(WKPageRef pageRef)
721 {
722     toImpl(pageRef)->hideFindUI();
723 }
724
725 void WKPageCountStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
726 {
727     toImpl(pageRef)->countStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
728 }
729
730 void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuClientBase* wkClient)
731 {
732 #if ENABLE(CONTEXT_MENUS)
733     class ContextMenuClient final : public API::Client<WKPageContextMenuClientBase>, public API::ContextMenuClient {
734     public:
735         explicit ContextMenuClient(const WKPageContextMenuClientBase* client)
736         {
737             initialize(client);
738         }
739
740     private:
741         virtual bool getContextMenuFromProposedMenu(WebPageProxy& page, const Vector<WebContextMenuItemData>& proposedMenuVector, Vector<WebContextMenuItemData>& customMenu, const WebHitTestResult::Data& hitTestResultData, API::Object* userData) override
742         {
743             if (!m_client.getContextMenuFromProposedMenu && !m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0)
744                 return false;
745
746             if (m_client.base.version >= 2 && !m_client.getContextMenuFromProposedMenu)
747                 return false;
748
749             Vector<RefPtr<API::Object>> proposedMenuItems;
750             proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size());
751
752             for (const auto& menuItem : proposedMenuVector)
753                 proposedMenuItems.uncheckedAppend(WebContextMenuItem::create(menuItem));
754
755             WKArrayRef newMenu = nullptr;
756             if (m_client.base.version >= 2) {
757                 RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(hitTestResultData);
758                 m_client.getContextMenuFromProposedMenu(toAPI(&page), toAPI(API::Array::create(WTF::move(proposedMenuItems)).get()), &newMenu, toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo);
759             } else
760                 m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0(toAPI(&page), toAPI(API::Array::create(WTF::move(proposedMenuItems)).get()), &newMenu, toAPI(userData), m_client.base.clientInfo);
761
762             RefPtr<API::Array> array = adoptRef(toImpl(newMenu));
763
764             customMenu.clear();
765
766             size_t newSize = array ? array->size() : 0;
767             for (size_t i = 0; i < newSize; ++i) {
768                 WebContextMenuItem* item = array->at<WebContextMenuItem>(i);
769                 if (!item) {
770                     LOG(ContextMenu, "New menu entry at index %i is not a WebContextMenuItem", (int)i);
771                     continue;
772                 }
773
774                 customMenu.append(*item->data());
775             }
776
777             return true;
778         }
779
780         virtual void customContextMenuItemSelected(WebPageProxy& page, const WebContextMenuItemData& itemData) override
781         {
782             if (!m_client.customContextMenuItemSelected)
783                 return;
784
785             m_client.customContextMenuItemSelected(toAPI(&page), toAPI(WebContextMenuItem::create(itemData).get()), m_client.base.clientInfo);
786         }
787
788         virtual void contextMenuDismissed(WebPageProxy& page) override
789         {
790             if (!m_client.contextMenuDismissed)
791                 return;
792
793             m_client.contextMenuDismissed(toAPI(&page), m_client.base.clientInfo);
794         }
795
796         virtual bool showContextMenu(WebPageProxy& page, const WebCore::IntPoint& menuLocation, const Vector<WebContextMenuItemData>& menuItemsVector) override
797         {
798             if (!m_client.showContextMenu)
799                 return false;
800
801             Vector<RefPtr<API::Object>> menuItems;
802             menuItems.reserveInitialCapacity(menuItemsVector.size());
803
804             for (const auto& menuItem : menuItemsVector)
805                 menuItems.uncheckedAppend(WebContextMenuItem::create(menuItem));
806
807             m_client.showContextMenu(toAPI(&page), toAPI(menuLocation), toAPI(API::Array::create(WTF::move(menuItems)).get()), m_client.base.clientInfo);
808
809             return true;
810         }
811
812         virtual bool hideContextMenu(WebPageProxy& page) override
813         {
814             if (!m_client.hideContextMenu)
815                 return false;
816
817             m_client.hideContextMenu(toAPI(&page), m_client.base.clientInfo);
818
819             return true;
820         }
821     };
822
823     toImpl(pageRef)->setContextMenuClient(std::make_unique<ContextMenuClient>(wkClient));
824 #else
825     UNUSED_PARAM(pageRef);
826     UNUSED_PARAM(wkClient);
827 #endif
828 }
829
830 void WKPageSetPageDiagnosticLoggingClient(WKPageRef pageRef, const WKPageDiagnosticLoggingClientBase* wkClient)
831 {
832     toImpl(pageRef)->setDiagnosticLoggingClient(std::make_unique<WebPageDiagnosticLoggingClient>(wkClient));
833 }
834
835 void WKPageSetPageFindClient(WKPageRef pageRef, const WKPageFindClientBase* wkClient)
836 {
837     class FindClient : public API::Client<WKPageFindClientBase>, public API::FindClient {
838     public:
839         explicit FindClient(const WKPageFindClientBase* client)
840         {
841             initialize(client);
842         }
843
844     private:
845         virtual void didFindString(WebPageProxy* page, const String& string, uint32_t matchCount, int32_t) override
846         {
847             if (!m_client.didFindString)
848                 return;
849             
850             m_client.didFindString(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
851         }
852
853         virtual void didFailToFindString(WebPageProxy* page, const String& string) override
854         {
855             if (!m_client.didFailToFindString)
856                 return;
857             
858             m_client.didFailToFindString(toAPI(page), toAPI(string.impl()), m_client.base.clientInfo);
859         }
860
861         virtual void didCountStringMatches(WebPageProxy* page, const String& string, uint32_t matchCount) override
862         {
863             if (!m_client.didCountStringMatches)
864                 return;
865
866             m_client.didCountStringMatches(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
867         }
868     };
869
870     toImpl(pageRef)->setFindClient(std::make_unique<FindClient>(wkClient));
871 }
872
873 void WKPageSetPageFindMatchesClient(WKPageRef pageRef, const WKPageFindMatchesClientBase* wkClient)
874 {
875     toImpl(pageRef)->initializeFindMatchesClient(wkClient);
876 }
877
878 void WKPageSetPageFormClient(WKPageRef pageRef, const WKPageFormClientBase* wkClient)
879 {
880     toImpl(pageRef)->setFormClient(std::make_unique<WebFormClient>(wkClient));
881 }
882
883 void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase* wkClient)
884 {
885     class LoaderClient : public API::Client<WKPageLoaderClientBase>, public API::LoaderClient {
886     public:
887         explicit LoaderClient(const WKPageLoaderClientBase* client)
888         {
889             initialize(client);
890         }
891
892     private:
893         virtual void didStartProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
894         {
895             if (!m_client.didStartProvisionalLoadForFrame)
896                 return;
897
898             m_client.didStartProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
899         }
900
901         virtual void didReceiveServerRedirectForProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
902         {
903             if (!m_client.didReceiveServerRedirectForProvisionalLoadForFrame)
904                 return;
905
906             m_client.didReceiveServerRedirectForProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
907         }
908
909         virtual void didFailProvisionalLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
910         {
911             if (!m_client.didFailProvisionalLoadWithErrorForFrame)
912                 return;
913
914             m_client.didFailProvisionalLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
915         }
916
917         virtual void didCommitLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
918         {
919             if (!m_client.didCommitLoadForFrame)
920                 return;
921
922             m_client.didCommitLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
923         }
924
925         virtual void didFinishDocumentLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
926         {
927             if (!m_client.didFinishDocumentLoadForFrame)
928                 return;
929
930             m_client.didFinishDocumentLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
931         }
932
933         virtual void didFinishLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
934         {
935             if (!m_client.didFinishLoadForFrame)
936                 return;
937
938             m_client.didFinishLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
939         }
940
941         virtual void didFailLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
942         {
943             if (!m_client.didFailLoadWithErrorForFrame)
944                 return;
945
946             m_client.didFailLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
947         }
948
949         virtual void didSameDocumentNavigationForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, SameDocumentNavigationType type, API::Object* userData) override
950         {
951             if (!m_client.didSameDocumentNavigationForFrame)
952                 return;
953
954             m_client.didSameDocumentNavigationForFrame(toAPI(&page), toAPI(&frame), toAPI(type), toAPI(userData), m_client.base.clientInfo);
955         }
956
957         virtual void didReceiveTitleForFrame(WebPageProxy& page, const String& title, WebFrameProxy& frame, API::Object* userData) override
958         {
959             if (!m_client.didReceiveTitleForFrame)
960                 return;
961
962             m_client.didReceiveTitleForFrame(toAPI(&page), toAPI(title.impl()), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
963         }
964
965         virtual void didFirstLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
966         {
967             if (!m_client.didFirstLayoutForFrame)
968                 return;
969
970             m_client.didFirstLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
971         }
972
973         virtual void didFirstVisuallyNonEmptyLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
974         {
975             if (!m_client.didFirstVisuallyNonEmptyLayoutForFrame)
976                 return;
977
978             m_client.didFirstVisuallyNonEmptyLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
979         }
980
981         virtual void didLayout(WebPageProxy& page, LayoutMilestones milestones, API::Object* userData) override
982         {
983             if (!m_client.didLayout)
984                 return;
985
986             m_client.didLayout(toAPI(&page), toWKLayoutMilestones(milestones), toAPI(userData), m_client.base.clientInfo);
987         }
988
989         virtual void didRemoveFrameFromHierarchy(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
990         {
991             if (!m_client.didRemoveFrameFromHierarchy)
992                 return;
993
994             m_client.didRemoveFrameFromHierarchy(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
995         }
996
997         virtual void didDisplayInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
998         {
999             if (!m_client.didDisplayInsecureContentForFrame)
1000                 return;
1001
1002             m_client.didDisplayInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1003         }
1004
1005         virtual void didRunInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1006         {
1007             if (!m_client.didRunInsecureContentForFrame)
1008                 return;
1009
1010             m_client.didRunInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1011         }
1012
1013         virtual void didDetectXSSForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
1014         {
1015             if (!m_client.didDetectXSSForFrame)
1016                 return;
1017
1018             m_client.didDetectXSSForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
1019         }
1020
1021         virtual bool canAuthenticateAgainstProtectionSpaceInFrame(WebPageProxy& page, WebFrameProxy& frame, WebProtectionSpace* protectionSpace) override
1022         {
1023             if (!m_client.canAuthenticateAgainstProtectionSpaceInFrame)
1024                 return false;
1025
1026             return m_client.canAuthenticateAgainstProtectionSpaceInFrame(toAPI(&page), toAPI(&frame), toAPI(protectionSpace), m_client.base.clientInfo);
1027         }
1028
1029         virtual void didReceiveAuthenticationChallengeInFrame(WebPageProxy& page, WebFrameProxy& frame, AuthenticationChallengeProxy* authenticationChallenge) override
1030         {
1031             if (!m_client.didReceiveAuthenticationChallengeInFrame)
1032                 return;
1033
1034             m_client.didReceiveAuthenticationChallengeInFrame(toAPI(&page), toAPI(&frame), toAPI(authenticationChallenge), m_client.base.clientInfo);
1035         }
1036
1037         virtual void didStartProgress(WebPageProxy& page) override
1038         {
1039             if (!m_client.didStartProgress)
1040                 return;
1041
1042             m_client.didStartProgress(toAPI(&page), m_client.base.clientInfo);
1043         }
1044
1045         virtual void didChangeProgress(WebPageProxy& page) override
1046         {
1047             if (!m_client.didChangeProgress)
1048                 return;
1049
1050             m_client.didChangeProgress(toAPI(&page), m_client.base.clientInfo);
1051         }
1052
1053         virtual void didFinishProgress(WebPageProxy& page) override
1054         {
1055             if (!m_client.didFinishProgress)
1056                 return;
1057
1058             m_client.didFinishProgress(toAPI(&page), m_client.base.clientInfo);
1059         }
1060
1061         virtual void processDidBecomeUnresponsive(WebPageProxy& page) override
1062         {
1063             if (!m_client.processDidBecomeUnresponsive)
1064                 return;
1065
1066             m_client.processDidBecomeUnresponsive(toAPI(&page), m_client.base.clientInfo);
1067         }
1068
1069         virtual void interactionOccurredWhileProcessUnresponsive(WebPageProxy& page) override
1070         {
1071             if (!m_client.interactionOccurredWhileProcessUnresponsive)
1072                 return;
1073
1074             m_client.interactionOccurredWhileProcessUnresponsive(toAPI(&page), m_client.base.clientInfo);
1075         }
1076
1077         virtual void processDidBecomeResponsive(WebPageProxy& page) override
1078         {
1079             if (!m_client.processDidBecomeResponsive)
1080                 return;
1081
1082             m_client.processDidBecomeResponsive(toAPI(&page), m_client.base.clientInfo);
1083         }
1084
1085         virtual void processDidCrash(WebPageProxy& page) override
1086         {
1087             if (!m_client.processDidCrash)
1088                 return;
1089
1090             m_client.processDidCrash(toAPI(&page), m_client.base.clientInfo);
1091         }
1092
1093         virtual void didChangeBackForwardList(WebPageProxy& page, WebBackForwardListItem* addedItem, Vector<RefPtr<WebBackForwardListItem>> removedItems) override
1094         {
1095             if (!m_client.didChangeBackForwardList)
1096                 return;
1097
1098             RefPtr<API::Array> removedItemsArray;
1099             if (!removedItems.isEmpty()) {
1100                 Vector<RefPtr<API::Object>> removedItemsVector;
1101                 removedItemsVector.reserveInitialCapacity(removedItems.size());
1102                 for (auto& removedItem : removedItems)
1103                     removedItemsVector.append(WTF::move(removedItem));
1104
1105                 removedItemsArray = API::Array::create(WTF::move(removedItemsVector));
1106             }
1107
1108             m_client.didChangeBackForwardList(toAPI(&page), toAPI(addedItem), toAPI(removedItemsArray.get()), m_client.base.clientInfo);
1109         }
1110
1111         virtual bool shouldKeepCurrentBackForwardListItemInList(WebKit::WebPageProxy& page, WebKit::WebBackForwardListItem* item) override
1112         {
1113             if (!m_client.shouldKeepCurrentBackForwardListItemInList)
1114                 return true;
1115
1116             return m_client.shouldKeepCurrentBackForwardListItemInList(toAPI(&page), toAPI(item), m_client.base.clientInfo);
1117         }
1118
1119         virtual void willGoToBackForwardListItem(WebPageProxy& page, WebBackForwardListItem* item, API::Object* userData) override
1120         {
1121             if (m_client.willGoToBackForwardListItem)
1122                 m_client.willGoToBackForwardListItem(toAPI(&page), toAPI(item), toAPI(userData), m_client.base.clientInfo);
1123         }
1124
1125         virtual PassRefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
1126         {
1127             return page.process().processPool().client().copyWebCryptoMasterKey(&page.process().processPool());
1128         }
1129
1130 #if ENABLE(NETSCAPE_PLUGIN_API)
1131         virtual void didFailToInitializePlugin(WebPageProxy& page, API::Dictionary* pluginInformation) override
1132         {
1133             if (m_client.didFailToInitializePlugin_deprecatedForUseWithV0)
1134                 m_client.didFailToInitializePlugin_deprecatedForUseWithV0(toAPI(&page), toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), m_client.base.clientInfo);
1135
1136             if (m_client.pluginDidFail_deprecatedForUseWithV1)
1137                 m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), 0, 0, m_client.base.clientInfo);
1138
1139             if (m_client.pluginDidFail)
1140                 m_client.pluginDidFail(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation), m_client.base.clientInfo);
1141         }
1142
1143         virtual void didBlockInsecurePluginVersion(WebPageProxy& page, API::Dictionary* pluginInformation) override
1144         {
1145             if (m_client.pluginDidFail_deprecatedForUseWithV1)
1146                 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);
1147
1148             if (m_client.pluginDidFail)
1149                 m_client.pluginDidFail(toAPI(&page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation), m_client.base.clientInfo);
1150         }
1151
1152         virtual PluginModuleLoadPolicy pluginLoadPolicy(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
1153         {
1154             WKStringRef unavailabilityDescriptionOut = 0;
1155             PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
1156
1157             if (m_client.pluginLoadPolicy_deprecatedForUseWithV2)
1158                 loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy_deprecatedForUseWithV2(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), m_client.base.clientInfo));
1159             else if (m_client.pluginLoadPolicy)
1160                 loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
1161
1162             if (unavailabilityDescriptionOut) {
1163                 RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
1164                 unavailabilityDescription = webUnavailabilityDescription->string();
1165             }
1166             
1167             return loadPolicy;
1168         }
1169 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1170
1171 #if ENABLE(WEBGL)
1172         virtual WebCore::WebGLLoadPolicy webGLLoadPolicy(WebPageProxy& page, const String& url) const override
1173         {
1174             WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
1175
1176             if (m_client.webGLLoadPolicy)
1177                 loadPolicy = toWebGLLoadPolicy(m_client.webGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
1178
1179             return loadPolicy;
1180         }
1181
1182         virtual WebCore::WebGLLoadPolicy resolveWebGLLoadPolicy(WebPageProxy& page, const String& url) const override
1183         {
1184             WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
1185
1186             if (m_client.resolveWebGLLoadPolicy)
1187                 loadPolicy = toWebGLLoadPolicy(m_client.resolveWebGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
1188
1189             return loadPolicy;
1190         }
1191
1192 #endif // ENABLE(WEBGL)
1193     };
1194
1195     WebPageProxy* webPageProxy = toImpl(pageRef);
1196
1197     auto loaderClient = std::make_unique<LoaderClient>(wkClient);
1198
1199     // It would be nice to get rid of this code and transition all clients to using didLayout instead of
1200     // didFirstLayoutInFrame and didFirstVisuallyNonEmptyLayoutInFrame. In the meantime, this is required
1201     // for backwards compatibility.
1202     WebCore::LayoutMilestones milestones = 0;
1203     if (loaderClient->client().didFirstLayoutForFrame)
1204         milestones |= WebCore::DidFirstLayout;
1205     if (loaderClient->client().didFirstVisuallyNonEmptyLayoutForFrame)
1206         milestones |= WebCore::DidFirstVisuallyNonEmptyLayout;
1207
1208     if (milestones)
1209         webPageProxy->process().send(Messages::WebPage::ListenForLayoutMilestones(milestones), webPageProxy->pageID());
1210
1211     webPageProxy->setLoaderClient(WTF::move(loaderClient));
1212 }
1213
1214 void WKPageSetPagePolicyClient(WKPageRef pageRef, const WKPagePolicyClientBase* wkClient)
1215 {
1216     class PolicyClient : public API::Client<WKPagePolicyClientBase>, public API::PolicyClient {
1217     public:
1218         explicit PolicyClient(const WKPagePolicyClientBase* client)
1219         {
1220             initialize(client);
1221         }
1222
1223     private:
1224         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
1225         {
1226             if (!m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0 && !m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1 && !m_client.decidePolicyForNavigationAction) {
1227                 listener->use();
1228                 return;
1229             }
1230
1231             RefPtr<API::URLRequest> originalRequest = API::URLRequest::create(originalResourceRequest);
1232             RefPtr<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1233
1234             if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0)
1235                 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);
1236             else if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1)
1237                 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);
1238             else
1239                 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);
1240         }
1241
1242         virtual void decidePolicyForNewWindowAction(WebPageProxy& page, WebFrameProxy& frame, const NavigationActionData& navigationActionData, const ResourceRequest& resourceRequest, const String& frameName, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1243         {
1244             if (!m_client.decidePolicyForNewWindowAction) {
1245                 listener->use();
1246                 return;
1247             }
1248
1249             RefPtr<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1250
1251             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);
1252         }
1253
1254         virtual void decidePolicyForResponse(WebPageProxy& page, WebFrameProxy& frame, const ResourceResponse& resourceResponse, const ResourceRequest& resourceRequest, bool canShowMIMEType, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1255         {
1256             if (!m_client.decidePolicyForResponse_deprecatedForUseWithV0 && !m_client.decidePolicyForResponse) {
1257                 listener->use();
1258                 return;
1259             }
1260
1261             RefPtr<API::URLResponse> response = API::URLResponse::create(resourceResponse);
1262             RefPtr<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1263
1264             if (m_client.decidePolicyForResponse_deprecatedForUseWithV0)
1265                 m_client.decidePolicyForResponse_deprecatedForUseWithV0(toAPI(&page), toAPI(&frame), toAPI(response.get()), toAPI(request.get()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1266             else
1267                 m_client.decidePolicyForResponse(toAPI(&page), toAPI(&frame), toAPI(response.get()), toAPI(request.get()), canShowMIMEType, toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1268         }
1269
1270         virtual void unableToImplementPolicy(WebPageProxy& page, WebFrameProxy& frame, const ResourceError& error, API::Object* userData) override
1271         {
1272             if (!m_client.unableToImplementPolicy)
1273                 return;
1274             
1275             m_client.unableToImplementPolicy(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1276         }
1277     };
1278
1279     toImpl(pageRef)->setPolicyClient(std::make_unique<PolicyClient>(wkClient));
1280 }
1281
1282 void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient)
1283 {
1284     class UIClient : public API::Client<WKPageUIClientBase>, public API::UIClient {
1285     public:
1286         explicit UIClient(const WKPageUIClientBase* client)
1287         {
1288             initialize(client);
1289         }
1290
1291     private:
1292         virtual PassRefPtr<WebPageProxy> createNewPage(WebPageProxy* page, WebFrameProxy*, const ResourceRequest& resourceRequest, const WindowFeatures& windowFeatures, const NavigationActionData& navigationActionData) override
1293         {
1294             if (!m_client.base.version && !m_client.createNewPage_deprecatedForUseWithV0)
1295                 return 0;
1296
1297             if (m_client.base.version > 0 && !m_client.createNewPage)
1298                 return 0;
1299
1300             API::Dictionary::MapType map;
1301             if (windowFeatures.xSet)
1302                 map.set("x", API::Double::create(windowFeatures.x));
1303             if (windowFeatures.ySet)
1304                 map.set("y", API::Double::create(windowFeatures.y));
1305             if (windowFeatures.widthSet)
1306                 map.set("width", API::Double::create(windowFeatures.width));
1307             if (windowFeatures.heightSet)
1308                 map.set("height", API::Double::create(windowFeatures.height));
1309             map.set("menuBarVisible", API::Boolean::create(windowFeatures.menuBarVisible));
1310             map.set("statusBarVisible", API::Boolean::create(windowFeatures.statusBarVisible));
1311             map.set("toolBarVisible", API::Boolean::create(windowFeatures.toolBarVisible));
1312             map.set("locationBarVisible", API::Boolean::create(windowFeatures.locationBarVisible));
1313             map.set("scrollbarsVisible", API::Boolean::create(windowFeatures.scrollbarsVisible));
1314             map.set("resizable", API::Boolean::create(windowFeatures.resizable));
1315             map.set("fullscreen", API::Boolean::create(windowFeatures.fullscreen));
1316             map.set("dialog", API::Boolean::create(windowFeatures.dialog));
1317             RefPtr<API::Dictionary> featuresMap = API::Dictionary::create(WTF::move(map));
1318
1319             if (!m_client.base.version)
1320                 return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV0(toAPI(page), toAPI(featuresMap.get()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
1321
1322             RefPtr<API::URLRequest> request = API::URLRequest::create(resourceRequest);
1323             return adoptRef(toImpl(m_client.createNewPage(toAPI(page), toAPI(request.get()), toAPI(featuresMap.get()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
1324         }
1325
1326         virtual void showPage(WebPageProxy* page) override
1327         {
1328             if (!m_client.showPage)
1329                 return;
1330
1331             m_client.showPage(toAPI(page), m_client.base.clientInfo);
1332         }
1333
1334         virtual void close(WebPageProxy* page) override
1335         {
1336             if (!m_client.close)
1337                 return;
1338
1339             m_client.close(toAPI(page), m_client.base.clientInfo);
1340         }
1341
1342         virtual void takeFocus(WebPageProxy* page, WKFocusDirection direction) override
1343         {
1344             if (!m_client.takeFocus)
1345                 return;
1346
1347             m_client.takeFocus(toAPI(page), direction, m_client.base.clientInfo);
1348         }
1349
1350         virtual void focus(WebPageProxy* page) override
1351         {
1352             if (!m_client.focus)
1353                 return;
1354
1355             m_client.focus(toAPI(page), m_client.base.clientInfo);
1356         }
1357
1358         virtual void unfocus(WebPageProxy* page) override
1359         {
1360             if (!m_client.unfocus)
1361                 return;
1362
1363             m_client.unfocus(toAPI(page), m_client.base.clientInfo);
1364         }
1365
1366         virtual void runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame, std::function<void ()> completionHandler) override
1367         {
1368             if (!m_client.runJavaScriptAlert) {
1369                 completionHandler();
1370                 return;
1371             }
1372
1373             m_client.runJavaScriptAlert(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1374             completionHandler();
1375         }
1376
1377         virtual void runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame, std::function<void (bool)> completionHandler) override
1378         {
1379             if (!m_client.runJavaScriptConfirm) {
1380                 completionHandler(false);
1381                 return;
1382             }
1383
1384             bool result = m_client.runJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1385             completionHandler(result);
1386         }
1387
1388         virtual void runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame, std::function<void (const String&)> completionHandler) override
1389         {
1390             if (!m_client.runJavaScriptPrompt) {
1391                 completionHandler(String());
1392                 return;
1393             }
1394
1395             RefPtr<API::String> string = adoptRef(toImpl(m_client.runJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.base.clientInfo)));
1396             if (!string) {
1397                 completionHandler(String());
1398                 return;
1399             }
1400
1401             completionHandler(string->string());
1402         }
1403
1404         virtual void setStatusText(WebPageProxy* page, const String& text) override
1405         {
1406             if (!m_client.setStatusText)
1407                 return;
1408
1409             m_client.setStatusText(toAPI(page), toAPI(text.impl()), m_client.base.clientInfo);
1410         }
1411
1412         virtual void mouseDidMoveOverElement(WebPageProxy* page, const WebHitTestResult::Data& data, WebEvent::Modifiers modifiers, API::Object* userData) override
1413         {
1414             if (!m_client.mouseDidMoveOverElement && !m_client.mouseDidMoveOverElement_deprecatedForUseWithV0)
1415                 return;
1416
1417             if (m_client.base.version > 0 && !m_client.mouseDidMoveOverElement)
1418                 return;
1419
1420             if (!m_client.base.version) {
1421                 m_client.mouseDidMoveOverElement_deprecatedForUseWithV0(toAPI(page), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
1422                 return;
1423             }
1424
1425             RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(data);
1426             m_client.mouseDidMoveOverElement(toAPI(page), toAPI(webHitTestResult.get()), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
1427         }
1428
1429 #if ENABLE(NETSCAPE_PLUGIN_API)
1430         virtual void unavailablePluginButtonClicked(WebPageProxy* page, WKPluginUnavailabilityReason pluginUnavailabilityReason, API::Dictionary* pluginInformation) override
1431         {
1432             if (pluginUnavailabilityReason == kWKPluginUnavailabilityReasonPluginMissing) {
1433                 if (m_client.missingPluginButtonClicked_deprecatedForUseWithV0)
1434                     m_client.missingPluginButtonClicked_deprecatedForUseWithV0(
1435                         toAPI(page),
1436                         toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
1437                         toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
1438                         toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
1439                         m_client.base.clientInfo);
1440             }
1441
1442             if (m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1)
1443                 m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1(
1444                     toAPI(page),
1445                     pluginUnavailabilityReason,
1446                     toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
1447                     toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
1448                     toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
1449                     m_client.base.clientInfo);
1450
1451             if (m_client.unavailablePluginButtonClicked)
1452                 m_client.unavailablePluginButtonClicked(
1453                     toAPI(page),
1454                     pluginUnavailabilityReason,
1455                     toAPI(pluginInformation),
1456                     m_client.base.clientInfo);
1457         }
1458 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1459
1460         virtual bool implementsDidNotHandleKeyEvent() const override
1461         {
1462             return m_client.didNotHandleKeyEvent;
1463         }
1464
1465         virtual void didNotHandleKeyEvent(WebPageProxy* page, const NativeWebKeyboardEvent& event) override
1466         {
1467             if (!m_client.didNotHandleKeyEvent)
1468                 return;
1469             m_client.didNotHandleKeyEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
1470         }
1471
1472         virtual bool implementsDidNotHandleWheelEvent() const override
1473         {
1474             return m_client.didNotHandleWheelEvent;
1475         }
1476
1477         virtual void didNotHandleWheelEvent(WebPageProxy* page, const NativeWebWheelEvent& event) override
1478         {
1479             if (!m_client.didNotHandleWheelEvent)
1480                 return;
1481             m_client.didNotHandleWheelEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
1482         }
1483
1484         virtual bool toolbarsAreVisible(WebPageProxy* page) override
1485         {
1486             if (!m_client.toolbarsAreVisible)
1487                 return true;
1488             return m_client.toolbarsAreVisible(toAPI(page), m_client.base.clientInfo);
1489         }
1490
1491         virtual void setToolbarsAreVisible(WebPageProxy* page, bool visible) override
1492         {
1493             if (!m_client.setToolbarsAreVisible)
1494                 return;
1495             m_client.setToolbarsAreVisible(toAPI(page), visible, m_client.base.clientInfo);
1496         }
1497
1498         virtual bool menuBarIsVisible(WebPageProxy* page) override
1499         {
1500             if (!m_client.menuBarIsVisible)
1501                 return true;
1502             return m_client.menuBarIsVisible(toAPI(page), m_client.base.clientInfo);
1503         }
1504
1505         virtual void setMenuBarIsVisible(WebPageProxy* page, bool visible) override
1506         {
1507             if (!m_client.setMenuBarIsVisible)
1508                 return;
1509             m_client.setMenuBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
1510         }
1511
1512         virtual bool statusBarIsVisible(WebPageProxy* page) override
1513         {
1514             if (!m_client.statusBarIsVisible)
1515                 return true;
1516             return m_client.statusBarIsVisible(toAPI(page), m_client.base.clientInfo);
1517         }
1518
1519         virtual void setStatusBarIsVisible(WebPageProxy* page, bool visible) override
1520         {
1521             if (!m_client.setStatusBarIsVisible)
1522                 return;
1523             m_client.setStatusBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
1524         }
1525
1526         virtual bool isResizable(WebPageProxy* page) override
1527         {
1528             if (!m_client.isResizable)
1529                 return true;
1530             return m_client.isResizable(toAPI(page), m_client.base.clientInfo);
1531         }
1532
1533         virtual void setIsResizable(WebPageProxy* page, bool resizable) override
1534         {
1535             if (!m_client.setIsResizable)
1536                 return;
1537             m_client.setIsResizable(toAPI(page), resizable, m_client.base.clientInfo);
1538         }
1539
1540         virtual void setWindowFrame(WebPageProxy* page, const FloatRect& frame) override
1541         {
1542             if (!m_client.setWindowFrame)
1543                 return;
1544
1545             m_client.setWindowFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1546         }
1547
1548         virtual FloatRect windowFrame(WebPageProxy* page) override
1549         {
1550             if (!m_client.getWindowFrame)
1551                 return FloatRect();
1552
1553             return toFloatRect(m_client.getWindowFrame(toAPI(page), m_client.base.clientInfo));
1554         }
1555
1556         virtual bool canRunBeforeUnloadConfirmPanel() const override
1557         {
1558             return m_client.runBeforeUnloadConfirmPanel;
1559         }
1560
1561         virtual bool runBeforeUnloadConfirmPanel(WebPageProxy* page, const String& message, WebFrameProxy* frame) override
1562         {
1563             if (!m_client.runBeforeUnloadConfirmPanel)
1564                 return true;
1565
1566             return m_client.runBeforeUnloadConfirmPanel(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
1567         }
1568
1569         virtual void didDraw(WebPageProxy* page) override
1570         {
1571             if (!m_client.didDraw)
1572                 return;
1573
1574             m_client.didDraw(toAPI(page), m_client.base.clientInfo);
1575         }
1576
1577         virtual void pageDidScroll(WebPageProxy* page) override
1578         {
1579             if (!m_client.pageDidScroll)
1580                 return;
1581
1582             m_client.pageDidScroll(toAPI(page), m_client.base.clientInfo);
1583         }
1584
1585         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
1586         {
1587             if (!m_client.exceededDatabaseQuota) {
1588                 completionHandler(currentQuota);
1589                 return;
1590             }
1591
1592             completionHandler(m_client.exceededDatabaseQuota(toAPI(page), toAPI(frame), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, m_client.base.clientInfo));
1593         }
1594
1595         virtual bool runOpenPanel(WebPageProxy* page, WebFrameProxy* frame, WebOpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener) override
1596         {
1597             if (!m_client.runOpenPanel)
1598                 return false;
1599
1600             m_client.runOpenPanel(toAPI(page), toAPI(frame), toAPI(parameters), toAPI(listener), m_client.base.clientInfo);
1601             return true;
1602         }
1603
1604         virtual bool decidePolicyForGeolocationPermissionRequest(WebPageProxy* page, WebFrameProxy* frame, API::SecurityOrigin* origin, GeolocationPermissionRequestProxy* permissionRequest) override
1605         {
1606             if (!m_client.decidePolicyForGeolocationPermissionRequest)
1607                 return false;
1608
1609             m_client.decidePolicyForGeolocationPermissionRequest(toAPI(page), toAPI(frame), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
1610             return true;
1611         }
1612
1613         virtual bool decidePolicyForUserMediaPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, UserMediaPermissionRequestProxy& permissionRequest) override
1614         {
1615             if (!m_client.decidePolicyForUserMediaPermissionRequest)
1616                 return false;
1617
1618             m_client.decidePolicyForUserMediaPermissionRequest(toAPI(&page), toAPI(&frame), toAPI(&origin), toAPI(&permissionRequest), m_client.base.clientInfo);
1619             return true;
1620         }
1621
1622         virtual bool decidePolicyForNotificationPermissionRequest(WebPageProxy* page, API::SecurityOrigin* origin, NotificationPermissionRequest* permissionRequest) override
1623         {
1624             if (!m_client.decidePolicyForNotificationPermissionRequest)
1625                 return false;
1626
1627             m_client.decidePolicyForNotificationPermissionRequest(toAPI(page), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
1628             return true;
1629         }
1630
1631         // Printing.
1632         virtual float headerHeight(WebPageProxy* page, WebFrameProxy* frame) override
1633         {
1634             if (!m_client.headerHeight)
1635                 return 0;
1636
1637             return m_client.headerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1638         }
1639
1640         virtual float footerHeight(WebPageProxy* page, WebFrameProxy* frame) override
1641         {
1642             if (!m_client.footerHeight)
1643                 return 0;
1644
1645             return m_client.footerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1646         }
1647
1648         virtual void drawHeader(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
1649         {
1650             if (!m_client.drawHeader)
1651                 return;
1652
1653             m_client.drawHeader(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
1654         }
1655
1656         virtual void drawFooter(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
1657         {
1658             if (!m_client.drawFooter)
1659                 return;
1660
1661             m_client.drawFooter(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
1662         }
1663
1664         virtual void printFrame(WebPageProxy* page, WebFrameProxy* frame) override
1665         {
1666             if (!m_client.printFrame)
1667                 return;
1668
1669             m_client.printFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
1670         }
1671
1672         virtual bool canRunModal() const override
1673         {
1674             return m_client.runModal;
1675         }
1676
1677         virtual void runModal(WebPageProxy* page) override
1678         {
1679             if (!m_client.runModal)
1680                 return;
1681
1682             m_client.runModal(toAPI(page), m_client.base.clientInfo);
1683         }
1684
1685         virtual void saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data) override
1686         {
1687             if (!m_client.saveDataToFileInDownloadsFolder)
1688                 return;
1689
1690             m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURLString.impl()), toAPI(data), m_client.base.clientInfo);
1691         }
1692
1693         virtual bool shouldInterruptJavaScript(WebPageProxy* page) override
1694         {
1695             if (!m_client.shouldInterruptJavaScript)
1696                 return false;
1697
1698             return m_client.shouldInterruptJavaScript(toAPI(page), m_client.base.clientInfo);
1699         }
1700
1701         virtual void pinnedStateDidChange(WebPageProxy& page) override
1702         {
1703             if (!m_client.pinnedStateDidChange)
1704                 return;
1705
1706             m_client.pinnedStateDidChange(toAPI(&page), m_client.base.clientInfo);
1707         }
1708
1709         virtual void didBeginTrackingPotentialLongMousePress(WebPageProxy* page, const IntPoint& mouseDownPosition, const WebHitTestResult::Data& data, API::Object* userInfo) override
1710         {
1711             if (!m_client.didBeginTrackingPotentialLongMousePress)
1712                 return;
1713
1714             RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(data);
1715             m_client.didBeginTrackingPotentialLongMousePress(toAPI(page), toAPI(mouseDownPosition), toAPI(webHitTestResult.get()), toAPI(userInfo), m_client.base.clientInfo);
1716         }
1717
1718         virtual void didRecognizeLongMousePress(WebPageProxy* page, API::Object* userInfo) override
1719         {
1720             if (!m_client.didRecognizeLongMousePress)
1721                 return;
1722
1723             m_client.didRecognizeLongMousePress(toAPI(page), toAPI(userInfo), m_client.base.clientInfo);
1724         }
1725
1726         virtual void didCancelTrackingPotentialLongMousePress(WebPageProxy* page, API::Object* userInfo) override
1727         {
1728             if (!m_client.didCancelTrackingPotentialLongMousePress)
1729                 return;
1730
1731             m_client.didCancelTrackingPotentialLongMousePress(toAPI(page), toAPI(userInfo), m_client.base.clientInfo);
1732         }
1733
1734         virtual void isPlayingAudioDidChange(WebPageProxy& page) override
1735         {
1736             if (!m_client.isPlayingAudioDidChange)
1737                 return;
1738
1739             m_client.isPlayingAudioDidChange(toAPI(&page), m_client.base.clientInfo);
1740         }
1741     };
1742
1743     toImpl(pageRef)->setUIClient(std::make_unique<UIClient>(wkClient));
1744 }
1745
1746 void WKPageSetPageNavigationClient(WKPageRef pageRef, const WKPageNavigationClientBase* wkClient)
1747 {
1748     class NavigationClient : public API::Client<WKPageNavigationClientBase>, public API::NavigationClient {
1749     public:
1750         explicit NavigationClient(const WKPageNavigationClientBase* client)
1751         {
1752             initialize(client);
1753         }
1754
1755     private:
1756         virtual void decidePolicyForNavigationAction(WebPageProxy& page, API::NavigationAction& navigationAction, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1757         {
1758             if (!m_client.decidePolicyForNavigationAction)
1759                 return;
1760             m_client.decidePolicyForNavigationAction(toAPI(&page), toAPI(&navigationAction), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1761         }
1762
1763         virtual void decidePolicyForNavigationResponse(WebPageProxy& page, API::NavigationResponse& navigationResponse, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
1764         {
1765             if (!m_client.decidePolicyForNavigationResponse)
1766                 return;
1767             m_client.decidePolicyForNavigationResponse(toAPI(&page), toAPI(&navigationResponse), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
1768         }
1769
1770         virtual void didStartProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1771         {
1772             if (!m_client.didStartProvisionalNavigation)
1773                 return;
1774             m_client.didStartProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1775         }
1776
1777         virtual void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1778         {
1779             if (!m_client.didReceiveServerRedirectForProvisionalNavigation)
1780                 return;
1781             m_client.didReceiveServerRedirectForProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1782         }
1783
1784         virtual void didFailProvisionalNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
1785         {
1786             if (!m_client.didFailProvisionalNavigation)
1787                 return;
1788             m_client.didFailProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1789         }
1790
1791         virtual void didCommitNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1792         {
1793             if (!m_client.didCommitNavigation)
1794                 return;
1795             m_client.didCommitNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1796         }
1797
1798         virtual void didFinishNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1799         {
1800             if (!m_client.didFinishNavigation)
1801                 return;
1802             m_client.didFinishNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1803         }
1804
1805         virtual void didFailNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
1806         {
1807             if (!m_client.didFailNavigation)
1808                 return;
1809             m_client.didFailNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1810         }
1811
1812         virtual void didFailProvisionalLoadInSubframeWithError(WebPageProxy& page, WebFrameProxy& subframe, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
1813         {
1814             if (!m_client.didFailProvisionalLoadInSubframe)
1815                 return;
1816             m_client.didFailProvisionalLoadInSubframe(toAPI(&page), toAPI(navigation), toAPI(API::FrameInfo::create(subframe).ptr()), toAPI(error), toAPI(userData), m_client.base.clientInfo);
1817         }
1818
1819         virtual void didFinishDocumentLoad(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
1820         {
1821             if (!m_client.didFinishDocumentLoad)
1822                 return;
1823             m_client.didFinishDocumentLoad(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
1824         }
1825
1826         virtual void didSameDocumentNavigation(WebPageProxy& page, API::Navigation* navigation, WebKit::SameDocumentNavigationType navigationType, API::Object* userData) override
1827         {
1828             if (!m_client.didSameDocumentNavigation)
1829                 return;
1830             m_client.didSameDocumentNavigation(toAPI(&page), toAPI(navigation), toAPI(navigationType), toAPI(userData), m_client.base.clientInfo);
1831         }
1832         
1833         virtual void renderingProgressDidChange(WebPageProxy& page, WebCore::LayoutMilestones milestones, API::Object* userData) override
1834         {
1835             if (!m_client.renderingProgressDidChange)
1836                 return;
1837             m_client.renderingProgressDidChange(toAPI(&page), pageRenderingProgressEvents(milestones), toAPI(userData), m_client.base.clientInfo);
1838         }
1839         
1840         virtual bool canAuthenticateAgainstProtectionSpace(WebPageProxy& page, WebProtectionSpace* protectionSpace) override
1841         {
1842             if (!m_client.canAuthenticateAgainstProtectionSpace)
1843                 return false;
1844             return m_client.canAuthenticateAgainstProtectionSpace(toAPI(&page), toAPI(protectionSpace), m_client.base.clientInfo);
1845         }
1846         
1847         virtual void didReceiveAuthenticationChallenge(WebPageProxy& page, AuthenticationChallengeProxy* authenticationChallenge) override
1848         {
1849             if (!m_client.didReceiveAuthenticationChallenge)
1850                 return;
1851             m_client.didReceiveAuthenticationChallenge(toAPI(&page), toAPI(authenticationChallenge), m_client.base.clientInfo);
1852         }
1853
1854         virtual void processDidCrash(WebPageProxy& page) override
1855         {
1856             if (!m_client.webProcessDidCrash)
1857                 return;
1858             m_client.webProcessDidCrash(toAPI(&page), m_client.base.clientInfo);
1859         }
1860
1861         virtual PassRefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
1862         {
1863             if (!m_client.copyWebCryptoMasterKey)
1864                 return nullptr;
1865             return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(&page), m_client.base.clientInfo)));
1866         }
1867         
1868 #if ENABLE(NETSCAPE_PLUGIN_API)
1869         virtual PluginModuleLoadPolicy decidePolicyForPluginLoad(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
1870         {
1871             WKStringRef unavailabilityDescriptionOut = 0;
1872             PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
1873             
1874             if (m_client.decidePolicyForPluginLoad)
1875                 loadPolicy = toPluginModuleLoadPolicy(m_client.decidePolicyForPluginLoad(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
1876             
1877             if (unavailabilityDescriptionOut) {
1878                 RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
1879                 unavailabilityDescription = webUnavailabilityDescription->string();
1880             }
1881             
1882             return loadPolicy;
1883         }
1884 #endif
1885     };
1886
1887     WebPageProxy* webPageProxy = toImpl(pageRef);
1888
1889     auto navigationClient = std::make_unique<NavigationClient>(wkClient);
1890     webPageProxy->setNavigationClient(WTF::move(navigationClient));
1891 }
1892
1893 void WKPageSetSession(WKPageRef pageRef, WKSessionRef session)
1894 {
1895     toImpl(pageRef)->setSessionID(toImpl(session)->getID());
1896 }
1897
1898 void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback)
1899 {
1900     toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), toGenericCallbackFunction(context, callback));
1901 }
1902
1903 #ifdef __BLOCKS__
1904 static void callRunJavaScriptBlockAndRelease(WKSerializedScriptValueRef resultValue, WKErrorRef error, void* context)
1905 {
1906     WKPageRunJavaScriptBlock block = (WKPageRunJavaScriptBlock)context;
1907     block(resultValue, error);
1908     Block_release(block);
1909 }
1910
1911 void WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef, WKStringRef scriptRef, WKPageRunJavaScriptBlock block)
1912 {
1913     WKPageRunJavaScriptInMainFrame(pageRef, scriptRef, Block_copy(block), callRunJavaScriptBlockAndRelease);
1914 }
1915 #endif
1916
1917 static std::function<void (const String&, CallbackBase::Error)> toGenericCallbackFunction(void* context, void (*callback)(WKStringRef, WKErrorRef, void*))
1918 {
1919     return [context, callback](const String& returnValue, CallbackBase::Error error) {
1920         callback(toAPI(API::String::create(returnValue).get()), error != CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
1921     };
1922 }
1923
1924 void WKPageRenderTreeExternalRepresentation(WKPageRef pageRef, void* context, WKPageRenderTreeExternalRepresentationFunction callback)
1925 {
1926     toImpl(pageRef)->getRenderTreeExternalRepresentation(toGenericCallbackFunction(context, callback));
1927 }
1928
1929 void WKPageGetSourceForFrame(WKPageRef pageRef, WKFrameRef frameRef, void* context, WKPageGetSourceForFrameFunction callback)
1930 {
1931     toImpl(pageRef)->getSourceForFrame(toImpl(frameRef), toGenericCallbackFunction(context, callback));
1932 }
1933
1934 void WKPageGetContentsAsString(WKPageRef pageRef, void* context, WKPageGetContentsAsStringFunction callback)
1935 {
1936     toImpl(pageRef)->getContentsAsString(toGenericCallbackFunction(context, callback));
1937 }
1938
1939 void WKPageGetBytecodeProfile(WKPageRef pageRef, void* context, WKPageGetBytecodeProfileFunction callback)
1940 {
1941     toImpl(pageRef)->getBytecodeProfile(toGenericCallbackFunction(context, callback));
1942 }
1943
1944 void WKPageGetSelectionAsWebArchiveData(WKPageRef pageRef, void* context, WKPageGetSelectionAsWebArchiveDataFunction callback)
1945 {
1946     toImpl(pageRef)->getSelectionAsWebArchiveData(toGenericCallbackFunction(context, callback));
1947 }
1948
1949 void WKPageGetContentsAsMHTMLData(WKPageRef pageRef, bool useBinaryEncoding, void* context, WKPageGetContentsAsMHTMLDataFunction callback)
1950 {
1951 #if ENABLE(MHTML)
1952     toImpl(pageRef)->getContentsAsMHTMLData(toGenericCallbackFunction(context, callback), useBinaryEncoding);
1953 #else
1954     UNUSED_PARAM(pageRef);
1955     UNUSED_PARAM(useBinaryEncoding);
1956     UNUSED_PARAM(context);
1957     UNUSED_PARAM(callback);
1958 #endif
1959 }
1960
1961 void WKPageForceRepaint(WKPageRef pageRef, void* context, WKPageForceRepaintFunction callback)
1962 {
1963     toImpl(pageRef)->forceRepaint(VoidCallback::create([context, callback](CallbackBase::Error error) {
1964         callback(error == CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().get()), context);
1965     }));
1966 }
1967
1968 WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef pageRef)
1969 {
1970     const String& pendingAPIRequestURL = toImpl(pageRef)->pageLoadState().pendingAPIRequestURL();
1971
1972     if (pendingAPIRequestURL.isNull())
1973         return nullptr;
1974
1975     return toCopiedURLAPI(pendingAPIRequestURL);
1976 }
1977
1978 WKURLRef WKPageCopyActiveURL(WKPageRef pageRef)
1979 {
1980     return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().activeURL());
1981 }
1982
1983 WKURLRef WKPageCopyProvisionalURL(WKPageRef pageRef)
1984 {
1985     return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().provisionalURL());
1986 }
1987
1988 WKURLRef WKPageCopyCommittedURL(WKPageRef pageRef)
1989 {
1990     return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().url());
1991 }
1992
1993 WKStringRef WKPageCopyStandardUserAgentWithApplicationName(WKStringRef applicationName)
1994 {
1995     return toCopiedAPI(WebPageProxy::standardUserAgent(toImpl(applicationName)->string()));
1996 }
1997
1998 void WKPageValidateCommand(WKPageRef pageRef, WKStringRef command, void* context, WKPageValidateCommandCallback callback)
1999 {
2000     toImpl(pageRef)->validateCommand(toImpl(command)->string(), [context, callback](const String& commandName, bool isEnabled, int32_t state, CallbackBase::Error error) {
2001         callback(toAPI(API::String::create(commandName).get()), isEnabled, state, error != CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
2002     });
2003 }
2004
2005 void WKPageExecuteCommand(WKPageRef pageRef, WKStringRef command)
2006 {
2007     toImpl(pageRef)->executeEditCommand(toImpl(command)->string());
2008 }
2009
2010 #if PLATFORM(COCOA)
2011 static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo)
2012 {
2013     PrintInfo result;
2014     result.pageSetupScaleFactor = printInfo.pageSetupScaleFactor;
2015     result.availablePaperWidth = printInfo.availablePaperWidth;
2016     result.availablePaperHeight = printInfo.availablePaperHeight;
2017     return result;
2018 }
2019
2020 void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, WKPageComputePagesForPrintingFunction callback, void* context)
2021 {
2022     toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create([context, callback](const Vector<WebCore::IntRect>& rects, double scaleFactor, CallbackBase::Error error) {
2023         Vector<WKRect> wkRects(rects.size());
2024         for (size_t i = 0; i < rects.size(); ++i)
2025             wkRects[i] = toAPI(rects[i]);
2026         callback(wkRects.data(), wkRects.size(), scaleFactor, error != CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
2027     }));
2028 }
2029
2030 void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo)
2031 {
2032     toImpl(page)->beginPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo));
2033 }
2034
2035 void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
2036 {
2037     toImpl(page)->drawPagesToPDF(toImpl(frame), printInfoFromWKPrintInfo(printInfo), first, count, DataCallback::create(toGenericCallbackFunction(context, callback)));
2038 }
2039
2040 void WKPageEndPrinting(WKPageRef page)
2041 {
2042     toImpl(page)->endPrinting();
2043 }
2044 #endif
2045
2046 void WKPageSetShouldSendEventsSynchronously(WKPageRef page, bool sync)
2047 {
2048     toImpl(page)->setShouldSendEventsSynchronously(sync);
2049 }
2050
2051 bool WKPageGetAllowsRemoteInspection(WKPageRef page)
2052 {
2053 #if ENABLE(REMOTE_INSPECTOR)
2054     return toImpl(page)->allowsRemoteInspection();
2055 #else
2056     UNUSED_PARAM(page);
2057     return false;
2058 #endif    
2059 }
2060
2061 void WKPageSetAllowsRemoteInspection(WKPageRef page, bool allow)
2062 {
2063 #if ENABLE(REMOTE_INSPECTOR)
2064     toImpl(page)->setAllowsRemoteInspection(allow);
2065 #else
2066     UNUSED_PARAM(page);
2067     UNUSED_PARAM(allow);
2068 #endif
2069 }
2070
2071 void WKPageSetMediaVolume(WKPageRef page, float volume)
2072 {
2073     toImpl(page)->setMediaVolume(volume);    
2074 }
2075
2076 void WKPageSetMuted(WKPageRef page, bool muted)
2077 {
2078     toImpl(page)->setMuted(muted);
2079 }
2080
2081 void WKPagePostMessageToInjectedBundle(WKPageRef pageRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef)
2082 {
2083     toImpl(pageRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef));
2084 }
2085
2086 WKArrayRef WKPageCopyRelatedPages(WKPageRef pageRef)
2087 {
2088     Vector<RefPtr<API::Object>> relatedPages;
2089
2090     for (auto& page : toImpl(pageRef)->process().pages()) {
2091         if (page != toImpl(pageRef))
2092             relatedPages.append(page);
2093     }
2094
2095     return toAPI(API::Array::create(WTF::move(relatedPages)).leakRef());
2096 }
2097
2098 void WKPageSetMayStartMediaWhenInWindow(WKPageRef pageRef, bool mayStartMedia)
2099 {
2100     toImpl(pageRef)->setMayStartMediaWhenInWindow(mayStartMedia);
2101 }
2102
2103
2104 void WKPageSelectContextMenuItem(WKPageRef page, WKContextMenuItemRef item)
2105 {
2106 #if ENABLE(CONTEXT_MENUS)
2107     toImpl(page)->contextMenuItemSelected(*(toImpl(item)->data()));
2108 #else
2109     UNUSED_PARAM(page);
2110     UNUSED_PARAM(item);
2111 #endif
2112 }
2113
2114 WKScrollPinningBehavior WKPageGetScrollPinningBehavior(WKPageRef page)
2115 {
2116     ScrollPinningBehavior pinning = toImpl(page)->scrollPinningBehavior();
2117     
2118     switch (pinning) {
2119     case WebCore::ScrollPinningBehavior::DoNotPin:
2120         return kWKScrollPinningBehaviorDoNotPin;
2121     case WebCore::ScrollPinningBehavior::PinToTop:
2122         return kWKScrollPinningBehaviorPinToTop;
2123     case WebCore::ScrollPinningBehavior::PinToBottom:
2124         return kWKScrollPinningBehaviorPinToBottom;
2125     }
2126     
2127     ASSERT_NOT_REACHED();
2128     return kWKScrollPinningBehaviorDoNotPin;
2129 }
2130
2131 void WKPageSetScrollPinningBehavior(WKPageRef page, WKScrollPinningBehavior pinning)
2132 {
2133     ScrollPinningBehavior corePinning = ScrollPinningBehavior::DoNotPin;
2134
2135     switch (pinning) {
2136     case kWKScrollPinningBehaviorDoNotPin:
2137         corePinning = ScrollPinningBehavior::DoNotPin;
2138         break;
2139     case kWKScrollPinningBehaviorPinToTop:
2140         corePinning = ScrollPinningBehavior::PinToTop;
2141         break;
2142     case kWKScrollPinningBehaviorPinToBottom:
2143         corePinning = ScrollPinningBehavior::PinToBottom;
2144         break;
2145     default:
2146         ASSERT_NOT_REACHED();
2147     }
2148     
2149     toImpl(page)->setScrollPinningBehavior(corePinning);
2150 }
2151
2152 bool WKPageGetAddsVisitedLinks(WKPageRef page)
2153 {
2154     return toImpl(page)->addsVisitedLinks();
2155 }
2156
2157 void WKPageSetAddsVisitedLinks(WKPageRef page, bool addsVisitedLinks)
2158 {
2159     toImpl(page)->setAddsVisitedLinks(addsVisitedLinks);
2160 }
2161
2162 bool WKPageIsPlayingAudio(WKPageRef page)
2163 {
2164     return toImpl(page)->isPlayingAudio();
2165 }
2166
2167 #if ENABLE(NETSCAPE_PLUGIN_API)
2168
2169 // -- DEPRECATED --
2170
2171 WKStringRef WKPageGetPluginInformationBundleIdentifierKey()
2172 {
2173     return WKPluginInformationBundleIdentifierKey();
2174 }
2175
2176 WKStringRef WKPageGetPluginInformationBundleVersionKey()
2177 {
2178     return WKPluginInformationBundleVersionKey();
2179 }
2180
2181 WKStringRef WKPageGetPluginInformationDisplayNameKey()
2182 {
2183     return WKPluginInformationDisplayNameKey();
2184 }
2185
2186 WKStringRef WKPageGetPluginInformationFrameURLKey()
2187 {
2188     return WKPluginInformationFrameURLKey();
2189 }
2190
2191 WKStringRef WKPageGetPluginInformationMIMETypeKey()
2192 {
2193     return WKPluginInformationMIMETypeKey();
2194 }
2195
2196 WKStringRef WKPageGetPluginInformationPageURLKey()
2197 {
2198     return WKPluginInformationPageURLKey();
2199 }
2200
2201 WKStringRef WKPageGetPluginInformationPluginspageAttributeURLKey()
2202 {
2203     return WKPluginInformationPluginspageAttributeURLKey();
2204 }
2205
2206 WKStringRef WKPageGetPluginInformationPluginURLKey()
2207 {
2208     return WKPluginInformationPluginURLKey();
2209 }
2210
2211 // -- DEPRECATED --
2212
2213 #endif // ENABLE(NETSCAPE_PLUGIN_API)