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