• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "WKPage.h"
28 #include "WKPagePrivate.h"
29 
30 #include "PrintInfo.h"
31 #include "WKAPICast.h"
32 #include "WebBackForwardList.h"
33 #include "WebData.h"
34 #include "WebPageProxy.h"
35 #include "WebProcessProxy.h"
36 
37 #ifdef __BLOCKS__
38 #include <Block.h>
39 #endif
40 
41 using namespace WebKit;
42 
WKPageGetTypeID()43 WKTypeID WKPageGetTypeID()
44 {
45     return toAPI(WebPageProxy::APIType);
46 }
47 
WKPageGetContext(WKPageRef pageRef)48 WKContextRef WKPageGetContext(WKPageRef pageRef)
49 {
50     return toAPI(toImpl(pageRef)->process()->context());
51 }
52 
WKPageGetPageGroup(WKPageRef pageRef)53 WKPageGroupRef WKPageGetPageGroup(WKPageRef pageRef)
54 {
55     return toAPI(toImpl(pageRef)->pageGroup());
56 }
57 
WKPageLoadURL(WKPageRef pageRef,WKURLRef URLRef)58 void WKPageLoadURL(WKPageRef pageRef, WKURLRef URLRef)
59 {
60     toImpl(pageRef)->loadURL(toWTFString(URLRef));
61 }
62 
WKPageLoadURLRequest(WKPageRef pageRef,WKURLRequestRef urlRequestRef)63 void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef)
64 {
65     toImpl(pageRef)->loadURLRequest(toImpl(urlRequestRef));
66 }
67 
WKPageLoadHTMLString(WKPageRef pageRef,WKStringRef htmlStringRef,WKURLRef baseURLRef)68 void WKPageLoadHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef)
69 {
70     toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef));
71 }
72 
WKPageLoadAlternateHTMLString(WKPageRef pageRef,WKStringRef htmlStringRef,WKURLRef baseURLRef,WKURLRef unreachableURLRef)73 void WKPageLoadAlternateHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef)
74 {
75     toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef));
76 }
77 
WKPageLoadPlainTextString(WKPageRef pageRef,WKStringRef plainTextStringRef)78 void WKPageLoadPlainTextString(WKPageRef pageRef, WKStringRef plainTextStringRef)
79 {
80     toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef));
81 }
82 
WKPageStopLoading(WKPageRef pageRef)83 void WKPageStopLoading(WKPageRef pageRef)
84 {
85     toImpl(pageRef)->stopLoading();
86 }
87 
WKPageReload(WKPageRef pageRef)88 void WKPageReload(WKPageRef pageRef)
89 {
90     toImpl(pageRef)->reload(false);
91 }
92 
WKPageReloadFromOrigin(WKPageRef pageRef)93 void WKPageReloadFromOrigin(WKPageRef pageRef)
94 {
95     toImpl(pageRef)->reload(true);
96 }
97 
WKPageTryClose(WKPageRef pageRef)98 bool WKPageTryClose(WKPageRef pageRef)
99 {
100     return toImpl(pageRef)->tryClose();
101 }
102 
WKPageClose(WKPageRef pageRef)103 void WKPageClose(WKPageRef pageRef)
104 {
105     toImpl(pageRef)->close();
106 }
107 
WKPageIsClosed(WKPageRef pageRef)108 bool WKPageIsClosed(WKPageRef pageRef)
109 {
110     return toImpl(pageRef)->isClosed();
111 }
112 
WKPageGoForward(WKPageRef pageRef)113 void WKPageGoForward(WKPageRef pageRef)
114 {
115     toImpl(pageRef)->goForward();
116 }
117 
WKPageCanGoForward(WKPageRef pageRef)118 bool WKPageCanGoForward(WKPageRef pageRef)
119 {
120     return toImpl(pageRef)->canGoForward();
121 }
122 
WKPageGoBack(WKPageRef pageRef)123 void WKPageGoBack(WKPageRef pageRef)
124 {
125     toImpl(pageRef)->goBack();
126 }
127 
WKPageCanGoBack(WKPageRef pageRef)128 bool WKPageCanGoBack(WKPageRef pageRef)
129 {
130     return toImpl(pageRef)->canGoBack();
131 }
132 
WKPageGoToBackForwardListItem(WKPageRef pageRef,WKBackForwardListItemRef itemRef)133 void WKPageGoToBackForwardListItem(WKPageRef pageRef, WKBackForwardListItemRef itemRef)
134 {
135     toImpl(pageRef)->goToBackForwardItem(toImpl(itemRef));
136 }
137 
WKPageGetBackForwardList(WKPageRef pageRef)138 WKBackForwardListRef WKPageGetBackForwardList(WKPageRef pageRef)
139 {
140     return toAPI(toImpl(pageRef)->backForwardList());
141 }
142 
WKPageCopyTitle(WKPageRef pageRef)143 WKStringRef WKPageCopyTitle(WKPageRef pageRef)
144 {
145     return toCopiedAPI(toImpl(pageRef)->pageTitle());
146 }
147 
WKPageGetMainFrame(WKPageRef pageRef)148 WKFrameRef WKPageGetMainFrame(WKPageRef pageRef)
149 {
150     return toAPI(toImpl(pageRef)->mainFrame());
151 }
152 
WKPageGetFocusedFrame(WKPageRef pageRef)153 WKFrameRef WKPageGetFocusedFrame(WKPageRef pageRef)
154 {
155     return toAPI(toImpl(pageRef)->focusedFrame());
156 }
157 
WKPageGetFrameSetLargestFrame(WKPageRef pageRef)158 WKFrameRef WKPageGetFrameSetLargestFrame(WKPageRef pageRef)
159 {
160     return toAPI(toImpl(pageRef)->frameSetLargestFrame());
161 }
162 
163 #if defined(ENABLE_INSPECTOR) && ENABLE_INSPECTOR
WKPageGetInspector(WKPageRef pageRef)164 WKInspectorRef WKPageGetInspector(WKPageRef pageRef)
165 {
166     return toAPI(toImpl(pageRef)->inspector());
167 }
168 #endif
169 
WKPageGetEstimatedProgress(WKPageRef pageRef)170 double WKPageGetEstimatedProgress(WKPageRef pageRef)
171 {
172     return toImpl(pageRef)->estimatedProgress();
173 }
174 
WKPageSetMemoryCacheClientCallsEnabled(WKPageRef pageRef,bool memoryCacheClientCallsEnabled)175 void WKPageSetMemoryCacheClientCallsEnabled(WKPageRef pageRef, bool memoryCacheClientCallsEnabled)
176 {
177     toImpl(pageRef)->setMemoryCacheClientCallsEnabled(memoryCacheClientCallsEnabled);
178 }
179 
WKPageCopyUserAgent(WKPageRef pageRef)180 WKStringRef WKPageCopyUserAgent(WKPageRef pageRef)
181 {
182     return toCopiedAPI(toImpl(pageRef)->userAgent());
183 }
184 
WKPageCopyApplicationNameForUserAgent(WKPageRef pageRef)185 WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef pageRef)
186 {
187     return toCopiedAPI(toImpl(pageRef)->applicationNameForUserAgent());
188 }
189 
WKPageSetApplicationNameForUserAgent(WKPageRef pageRef,WKStringRef applicationNameRef)190 void WKPageSetApplicationNameForUserAgent(WKPageRef pageRef, WKStringRef applicationNameRef)
191 {
192     toImpl(pageRef)->setApplicationNameForUserAgent(toWTFString(applicationNameRef));
193 }
194 
WKPageCopyCustomUserAgent(WKPageRef pageRef)195 WKStringRef WKPageCopyCustomUserAgent(WKPageRef pageRef)
196 {
197     return toCopiedAPI(toImpl(pageRef)->customUserAgent());
198 }
199 
WKPageSetCustomUserAgent(WKPageRef pageRef,WKStringRef userAgentRef)200 void WKPageSetCustomUserAgent(WKPageRef pageRef, WKStringRef userAgentRef)
201 {
202     toImpl(pageRef)->setCustomUserAgent(toWTFString(userAgentRef));
203 }
204 
WKPageSupportsTextEncoding(WKPageRef pageRef)205 bool WKPageSupportsTextEncoding(WKPageRef pageRef)
206 {
207     return toImpl(pageRef)->supportsTextEncoding();
208 }
209 
WKPageCopyCustomTextEncodingName(WKPageRef pageRef)210 WKStringRef WKPageCopyCustomTextEncodingName(WKPageRef pageRef)
211 {
212     return toCopiedAPI(toImpl(pageRef)->customTextEncodingName());
213 }
214 
WKPageSetCustomTextEncodingName(WKPageRef pageRef,WKStringRef encodingNameRef)215 void WKPageSetCustomTextEncodingName(WKPageRef pageRef, WKStringRef encodingNameRef)
216 {
217     toImpl(pageRef)->setCustomTextEncodingName(toWTFString(encodingNameRef));
218 }
219 
WKPageTerminate(WKPageRef pageRef)220 void WKPageTerminate(WKPageRef pageRef)
221 {
222     toImpl(pageRef)->terminateProcess();
223 }
224 
WKPageGetSessionHistoryURLValueType()225 WKStringRef WKPageGetSessionHistoryURLValueType()
226 {
227     static WebString* sessionHistoryURLValueType = WebString::create("SessionHistoryURL").releaseRef();
228     return toAPI(sessionHistoryURLValueType);
229 }
230 
WKPageCopySessionState(WKPageRef pageRef,void * context,WKPageSessionStateFilterCallback filter)231 WKDataRef WKPageCopySessionState(WKPageRef pageRef, void *context, WKPageSessionStateFilterCallback filter)
232 {
233     return toAPI(toImpl(pageRef)->sessionStateData(filter, context).releaseRef());
234 }
235 
WKPageRestoreFromSessionState(WKPageRef pageRef,WKDataRef sessionStateData)236 void WKPageRestoreFromSessionState(WKPageRef pageRef, WKDataRef sessionStateData)
237 {
238     toImpl(pageRef)->restoreFromSessionStateData(toImpl(sessionStateData));
239 }
240 
WKPageGetTextZoomFactor(WKPageRef pageRef)241 double WKPageGetTextZoomFactor(WKPageRef pageRef)
242 {
243     return toImpl(pageRef)->textZoomFactor();
244 }
245 
WKPageSupportsTextZoom(WKPageRef pageRef)246 bool WKPageSupportsTextZoom(WKPageRef pageRef)
247 {
248     return toImpl(pageRef)->supportsTextZoom();
249 }
250 
WKPageSetTextZoomFactor(WKPageRef pageRef,double zoomFactor)251 void WKPageSetTextZoomFactor(WKPageRef pageRef, double zoomFactor)
252 {
253     toImpl(pageRef)->setTextZoomFactor(zoomFactor);
254 }
255 
WKPageGetPageZoomFactor(WKPageRef pageRef)256 double WKPageGetPageZoomFactor(WKPageRef pageRef)
257 {
258     return toImpl(pageRef)->pageZoomFactor();
259 }
260 
WKPageSetPageZoomFactor(WKPageRef pageRef,double zoomFactor)261 void WKPageSetPageZoomFactor(WKPageRef pageRef, double zoomFactor)
262 {
263     toImpl(pageRef)->setPageZoomFactor(zoomFactor);
264 }
265 
WKPageSetPageAndTextZoomFactors(WKPageRef pageRef,double pageZoomFactor,double textZoomFactor)266 void WKPageSetPageAndTextZoomFactors(WKPageRef pageRef, double pageZoomFactor, double textZoomFactor)
267 {
268     toImpl(pageRef)->setPageAndTextZoomFactors(pageZoomFactor, textZoomFactor);
269 }
270 
WKPageSetScaleFactor(WKPageRef pageRef,double scale,WKPoint origin)271 void WKPageSetScaleFactor(WKPageRef pageRef, double scale, WKPoint origin)
272 {
273     toImpl(pageRef)->scaleWebView(scale, toIntPoint(origin));
274 }
275 
WKPageGetScaleFactor(WKPageRef pageRef)276 double WKPageGetScaleFactor(WKPageRef pageRef)
277 {
278     return toImpl(pageRef)->viewScaleFactor();
279 }
280 
WKPageSetUseFixedLayout(WKPageRef pageRef,bool fixed)281 void WKPageSetUseFixedLayout(WKPageRef pageRef, bool fixed)
282 {
283     toImpl(pageRef)->setUseFixedLayout(fixed);
284 }
285 
WKPageSetFixedLayoutSize(WKPageRef pageRef,WKSize size)286 void WKPageSetFixedLayoutSize(WKPageRef pageRef, WKSize size)
287 {
288     toImpl(pageRef)->setFixedLayoutSize(toIntSize(size));
289 }
290 
WKPageUseFixedLayout(WKPageRef pageRef)291 bool WKPageUseFixedLayout(WKPageRef pageRef)
292 {
293     return toImpl(pageRef)->useFixedLayout();
294 }
295 
WKPageFixedLayoutSize(WKPageRef pageRef)296 WKSize WKPageFixedLayoutSize(WKPageRef pageRef)
297 {
298     return toAPI(toImpl(pageRef)->fixedLayoutSize());
299 }
300 
WKPageHasHorizontalScrollbar(WKPageRef pageRef)301 bool WKPageHasHorizontalScrollbar(WKPageRef pageRef)
302 {
303     return toImpl(pageRef)->hasHorizontalScrollbar();
304 }
305 
WKPageHasVerticalScrollbar(WKPageRef pageRef)306 bool WKPageHasVerticalScrollbar(WKPageRef pageRef)
307 {
308     return toImpl(pageRef)->hasVerticalScrollbar();
309 }
310 
WKPageIsPinnedToLeftSide(WKPageRef pageRef)311 bool WKPageIsPinnedToLeftSide(WKPageRef pageRef)
312 {
313     return toImpl(pageRef)->isPinnedToLeftSide();
314 }
315 
WKPageIsPinnedToRightSide(WKPageRef pageRef)316 bool WKPageIsPinnedToRightSide(WKPageRef pageRef)
317 {
318     return toImpl(pageRef)->isPinnedToRightSide();
319 }
320 
WKPageCanDelete(WKPageRef pageRef)321 bool WKPageCanDelete(WKPageRef pageRef)
322 {
323     return toImpl(pageRef)->canDelete();
324 }
325 
WKPageHasSelectedRange(WKPageRef pageRef)326 bool WKPageHasSelectedRange(WKPageRef pageRef)
327 {
328     return toImpl(pageRef)->hasSelectedRange();
329 }
330 
WKPageIsContentEditable(WKPageRef pageRef)331 bool WKPageIsContentEditable(WKPageRef pageRef)
332 {
333     return toImpl(pageRef)->isContentEditable();
334 }
335 
WKPageFindString(WKPageRef pageRef,WKStringRef string,WKFindOptions options,unsigned maxMatchCount)336 void WKPageFindString(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
337 {
338     toImpl(pageRef)->findString(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
339 }
340 
WKPageHideFindUI(WKPageRef pageRef)341 void WKPageHideFindUI(WKPageRef pageRef)
342 {
343     toImpl(pageRef)->hideFindUI();
344 }
345 
WKPageCountStringMatches(WKPageRef pageRef,WKStringRef string,WKFindOptions options,unsigned maxMatchCount)346 void WKPageCountStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
347 {
348     toImpl(pageRef)->countStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
349 }
350 
WKPageSetPageContextMenuClient(WKPageRef pageRef,const WKPageContextMenuClient * wkClient)351 void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuClient* wkClient)
352 {
353     if (wkClient && wkClient->version)
354         return;
355     toImpl(pageRef)->initializeContextMenuClient(wkClient);
356 }
357 
WKPageSetPageFindClient(WKPageRef pageRef,const WKPageFindClient * wkClient)358 void WKPageSetPageFindClient(WKPageRef pageRef, const WKPageFindClient* wkClient)
359 {
360     if (wkClient && wkClient->version)
361         return;
362     toImpl(pageRef)->initializeFindClient(wkClient);
363 }
364 
WKPageSetPageFormClient(WKPageRef pageRef,const WKPageFormClient * wkClient)365 void WKPageSetPageFormClient(WKPageRef pageRef, const WKPageFormClient* wkClient)
366 {
367     if (wkClient && wkClient->version)
368         return;
369     toImpl(pageRef)->initializeFormClient(wkClient);
370 }
371 
WKPageSetPageLoaderClient(WKPageRef pageRef,const WKPageLoaderClient * wkClient)372 void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClient* wkClient)
373 {
374     if (wkClient && wkClient->version)
375         return;
376     toImpl(pageRef)->initializeLoaderClient(wkClient);
377 }
378 
WKPageSetPagePolicyClient(WKPageRef pageRef,const WKPagePolicyClient * wkClient)379 void WKPageSetPagePolicyClient(WKPageRef pageRef, const WKPagePolicyClient* wkClient)
380 {
381     if (wkClient && wkClient->version)
382         return;
383     toImpl(pageRef)->initializePolicyClient(wkClient);
384 }
385 
WKPageSetPageResourceLoadClient(WKPageRef pageRef,const WKPageResourceLoadClient * wkClient)386 void WKPageSetPageResourceLoadClient(WKPageRef pageRef, const WKPageResourceLoadClient* wkClient)
387 {
388     if (wkClient && wkClient->version)
389         return;
390     toImpl(pageRef)->initializeResourceLoadClient(wkClient);
391 }
392 
WKPageSetPageUIClient(WKPageRef pageRef,const WKPageUIClient * wkClient)393 void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClient* wkClient)
394 {
395     if (wkClient && wkClient->version)
396         return;
397     toImpl(pageRef)->initializeUIClient(wkClient);
398 }
399 
WKPageRunJavaScriptInMainFrame(WKPageRef pageRef,WKStringRef scriptRef,void * context,WKPageRunJavaScriptFunction callback)400 void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback)
401 {
402     toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), ScriptValueCallback::create(context, callback));
403 }
404 
405 #ifdef __BLOCKS__
callRunJavaScriptBlockAndRelease(WKSerializedScriptValueRef resultValue,WKErrorRef error,void * context)406 static void callRunJavaScriptBlockAndRelease(WKSerializedScriptValueRef resultValue, WKErrorRef error, void* context)
407 {
408     WKPageRunJavaScriptBlock block = (WKPageRunJavaScriptBlock)context;
409     block(resultValue, error);
410     Block_release(block);
411 }
412 
WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef,WKStringRef scriptRef,WKPageRunJavaScriptBlock block)413 void WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef, WKStringRef scriptRef, WKPageRunJavaScriptBlock block)
414 {
415     WKPageRunJavaScriptInMainFrame(pageRef, scriptRef, Block_copy(block), callRunJavaScriptBlockAndRelease);
416 }
417 #endif
418 
WKPageRenderTreeExternalRepresentation(WKPageRef pageRef,void * context,WKPageRenderTreeExternalRepresentationFunction callback)419 void WKPageRenderTreeExternalRepresentation(WKPageRef pageRef, void* context, WKPageRenderTreeExternalRepresentationFunction callback)
420 {
421     toImpl(pageRef)->getRenderTreeExternalRepresentation(StringCallback::create(context, callback));
422 }
423 
424 #ifdef __BLOCKS__
callRenderTreeExternalRepresentationBlockAndDispose(WKStringRef resultValue,WKErrorRef error,void * context)425 static void callRenderTreeExternalRepresentationBlockAndDispose(WKStringRef resultValue, WKErrorRef error, void* context)
426 {
427     WKPageRenderTreeExternalRepresentationBlock block = (WKPageRenderTreeExternalRepresentationBlock)context;
428     block(resultValue, error);
429     Block_release(block);
430 }
431 
WKPageRenderTreeExternalRepresentation_b(WKPageRef pageRef,WKPageRenderTreeExternalRepresentationBlock block)432 void WKPageRenderTreeExternalRepresentation_b(WKPageRef pageRef, WKPageRenderTreeExternalRepresentationBlock block)
433 {
434     WKPageRenderTreeExternalRepresentation(pageRef, Block_copy(block), callRenderTreeExternalRepresentationBlockAndDispose);
435 }
436 #endif
437 
WKPageGetSourceForFrame(WKPageRef pageRef,WKFrameRef frameRef,void * context,WKPageGetSourceForFrameFunction callback)438 void WKPageGetSourceForFrame(WKPageRef pageRef, WKFrameRef frameRef, void* context, WKPageGetSourceForFrameFunction callback)
439 {
440     toImpl(pageRef)->getSourceForFrame(toImpl(frameRef), StringCallback::create(context, callback));
441 }
442 
443 #ifdef __BLOCKS__
callGetSourceForFrameBlockBlockAndDispose(WKStringRef resultValue,WKErrorRef error,void * context)444 static void callGetSourceForFrameBlockBlockAndDispose(WKStringRef resultValue, WKErrorRef error, void* context)
445 {
446     WKPageGetSourceForFrameBlock block = (WKPageGetSourceForFrameBlock)context;
447     block(resultValue, error);
448     Block_release(block);
449 }
450 
WKPageGetSourceForFrame_b(WKPageRef pageRef,WKFrameRef frameRef,WKPageGetSourceForFrameBlock block)451 void WKPageGetSourceForFrame_b(WKPageRef pageRef, WKFrameRef frameRef, WKPageGetSourceForFrameBlock block)
452 {
453     WKPageGetSourceForFrame(pageRef, frameRef, Block_copy(block), callGetSourceForFrameBlockBlockAndDispose);
454 }
455 #endif
456 
WKPageGetContentsAsString(WKPageRef pageRef,void * context,WKPageGetContentsAsStringFunction callback)457 void WKPageGetContentsAsString(WKPageRef pageRef, void* context, WKPageGetContentsAsStringFunction callback)
458 {
459     toImpl(pageRef)->getContentsAsString(StringCallback::create(context, callback));
460 }
461 
462 #ifdef __BLOCKS__
callContentsAsStringBlockBlockAndDispose(WKStringRef resultValue,WKErrorRef error,void * context)463 static void callContentsAsStringBlockBlockAndDispose(WKStringRef resultValue, WKErrorRef error, void* context)
464 {
465     WKPageGetContentsAsStringBlock block = (WKPageGetContentsAsStringBlock)context;
466     block(resultValue, error);
467     Block_release(block);
468 }
469 
WKPageGetContentsAsString_b(WKPageRef pageRef,WKPageGetSourceForFrameBlock block)470 void WKPageGetContentsAsString_b(WKPageRef pageRef, WKPageGetSourceForFrameBlock block)
471 {
472     WKPageGetContentsAsString(pageRef, Block_copy(block), callContentsAsStringBlockBlockAndDispose);
473 }
474 #endif
475 
WKPageForceRepaint(WKPageRef pageRef,void * context,WKPageForceRepaintFunction callback)476 void WKPageForceRepaint(WKPageRef pageRef, void* context, WKPageForceRepaintFunction callback)
477 {
478     toImpl(pageRef)->forceRepaint(VoidCallback::create(context, callback));
479 }
480 
WKPageCopyPendingAPIRequestURL(WKPageRef pageRef)481 WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef pageRef)
482 {
483     if (toImpl(pageRef)->pendingAPIRequestURL().isNull())
484         return 0;
485     return toCopiedURLAPI(toImpl(pageRef)->pendingAPIRequestURL());
486 }
487 
WKPageSetDebugPaintFlags(WKPageDebugPaintFlags flags)488 void WKPageSetDebugPaintFlags(WKPageDebugPaintFlags flags)
489 {
490     WebPageProxy::setDebugPaintFlags(flags);
491 }
492 
WKPageGetDebugPaintFlags()493 WKPageDebugPaintFlags WKPageGetDebugPaintFlags()
494 {
495     return WebPageProxy::debugPaintFlags();
496 }
497 
WKPageValidateCommand(WKPageRef pageRef,WKStringRef command,void * context,WKPageValidateCommandCallback callback)498 void WKPageValidateCommand(WKPageRef pageRef, WKStringRef command, void* context, WKPageValidateCommandCallback callback)
499 {
500     toImpl(pageRef)->validateCommand(toImpl(command)->string(), ValidateCommandCallback::create(context, callback));
501 }
502 
WKPageExecuteCommand(WKPageRef pageRef,WKStringRef command)503 void WKPageExecuteCommand(WKPageRef pageRef, WKStringRef command)
504 {
505     toImpl(pageRef)->executeEditCommand(toImpl(command)->string());
506 }
507 
508 #if PLATFORM(MAC) || PLATFORM(WIN)
509 struct ComputedPagesContext {
ComputedPagesContextComputedPagesContext510     ComputedPagesContext(WKPageComputePagesForPrintingFunction callback, void* context)
511         : callback(callback)
512         , context(context)
513     {
514     }
515     WKPageComputePagesForPrintingFunction callback;
516     void* context;
517 };
518 
computedPagesCallback(const Vector<WebCore::IntRect> & rects,double scaleFactor,WKErrorRef error,void * untypedContext)519 static void computedPagesCallback(const Vector<WebCore::IntRect>& rects, double scaleFactor, WKErrorRef error, void* untypedContext)
520 {
521     OwnPtr<ComputedPagesContext> context = adoptPtr(static_cast<ComputedPagesContext*>(untypedContext));
522     Vector<WKRect> wkRects(rects.size());
523     for (size_t i = 0; i < rects.size(); ++i)
524         wkRects[i] = toAPI(rects[i]);
525     context->callback(wkRects.data(), wkRects.size(), scaleFactor, error, context->context);
526 }
527 
printInfoFromWKPrintInfo(const WKPrintInfo & printInfo)528 static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo)
529 {
530     PrintInfo result;
531     result.pageSetupScaleFactor = printInfo.pageSetupScaleFactor;
532     result.availablePaperWidth = printInfo.availablePaperWidth;
533     result.availablePaperHeight = printInfo.availablePaperHeight;
534     return result;
535 }
536 
WKPageComputePagesForPrinting(WKPageRef page,WKFrameRef frame,WKPrintInfo printInfo,WKPageComputePagesForPrintingFunction callback,void * context)537 void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, WKPageComputePagesForPrintingFunction callback, void* context)
538 {
539     toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create(new ComputedPagesContext(callback, context), computedPagesCallback));
540 }
541 
WKPageBeginPrinting(WKPageRef page,WKFrameRef frame,WKPrintInfo printInfo)542 void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo)
543 {
544     toImpl(page)->beginPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo));
545 }
546 
WKPageDrawPagesToPDF(WKPageRef page,WKFrameRef frame,uint32_t first,uint32_t count,WKPageDrawToPDFFunction callback,void * context)547 void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
548 {
549     toImpl(page)->drawPagesToPDF(toImpl(frame), first, count, DataCallback::create(context, callback));
550 }
551 #endif
552 
553