1 | /* |
2 | * Copyright (C) 2010, 2011, 2013, 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 "WKBundlePage.h" |
28 | #include "WKBundlePagePrivate.h" |
29 | |
30 | #include "APIArray.h" |
31 | #include "APIFrameHandle.h" |
32 | #include "APIString.h" |
33 | #include "APIURL.h" |
34 | #include "APIURLRequest.h" |
35 | #include "InjectedBundleNodeHandle.h" |
36 | #include "InjectedBundlePageEditorClient.h" |
37 | #include "InjectedBundlePageFormClient.h" |
38 | #include "InjectedBundlePageLoaderClient.h" |
39 | #include "InjectedBundlePageResourceLoadClient.h" |
40 | #include "InjectedBundlePageUIClient.h" |
41 | #include "PageBanner.h" |
42 | #include "WKAPICast.h" |
43 | #include "WKArray.h" |
44 | #include "WKBundleAPICast.h" |
45 | #include "WKRetainPtr.h" |
46 | #include "WKString.h" |
47 | #include "WebContextMenu.h" |
48 | #include "WebContextMenuItem.h" |
49 | #include "WebFrame.h" |
50 | #include "WebFullScreenManager.h" |
51 | #include "WebImage.h" |
52 | #include "WebInspector.h" |
53 | #include "WebPage.h" |
54 | #include "WebPageGroupProxy.h" |
55 | #include "WebPageOverlay.h" |
56 | #include "WebRenderLayer.h" |
57 | #include "WebRenderObject.h" |
58 | #include <WebCore/AXObjectCache.h> |
59 | #include <WebCore/AccessibilityObject.h> |
60 | #include <WebCore/ApplicationCacheStorage.h> |
61 | #include <WebCore/Frame.h> |
62 | #include <WebCore/Page.h> |
63 | #include <WebCore/PageOverlay.h> |
64 | #include <WebCore/PageOverlayController.h> |
65 | #include <WebCore/RenderLayerCompositor.h> |
66 | #include <WebCore/ScriptExecutionContext.h> |
67 | #include <WebCore/SecurityOriginData.h> |
68 | #include <WebCore/WheelEventTestTrigger.h> |
69 | #include <wtf/StdLibExtras.h> |
70 | #include <wtf/URL.h> |
71 | |
72 | WKTypeID WKBundlePageGetTypeID() |
73 | { |
74 | return WebKit::toAPI(WebKit::WebPage::APIType); |
75 | } |
76 | |
77 | void (WKBundlePageRef , WKBundlePageContextMenuClientBase* wkClient) |
78 | { |
79 | #if ENABLE(CONTEXT_MENUS) |
80 | WebKit::toImpl(pageRef)->setInjectedBundleContextMenuClient(std::make_unique<WebKit::InjectedBundlePageContextMenuClient>(wkClient)); |
81 | #else |
82 | UNUSED_PARAM(pageRef); |
83 | UNUSED_PARAM(wkClient); |
84 | #endif |
85 | } |
86 | |
87 | void WKBundlePageSetEditorClient(WKBundlePageRef , WKBundlePageEditorClientBase* wkClient) |
88 | { |
89 | WebKit::toImpl(pageRef)->setInjectedBundleEditorClient(wkClient ? std::make_unique<WebKit::InjectedBundlePageEditorClient>(*wkClient) : std::make_unique<API::InjectedBundle::EditorClient>()); |
90 | } |
91 | |
92 | void WKBundlePageSetFormClient(WKBundlePageRef , WKBundlePageFormClientBase* wkClient) |
93 | { |
94 | WebKit::toImpl(pageRef)->setInjectedBundleFormClient(std::make_unique<WebKit::InjectedBundlePageFormClient>(wkClient)); |
95 | } |
96 | |
97 | void WKBundlePageSetPageLoaderClient(WKBundlePageRef , WKBundlePageLoaderClientBase* wkClient) |
98 | { |
99 | WebKit::toImpl(pageRef)->setInjectedBundlePageLoaderClient(std::make_unique<WebKit::InjectedBundlePageLoaderClient>(wkClient)); |
100 | } |
101 | |
102 | void WKBundlePageSetResourceLoadClient(WKBundlePageRef , WKBundlePageResourceLoadClientBase* wkClient) |
103 | { |
104 | WebKit::toImpl(pageRef)->setInjectedBundleResourceLoadClient(std::make_unique<WebKit::InjectedBundlePageResourceLoadClient>(wkClient)); |
105 | } |
106 | |
107 | void WKBundlePageSetPolicyClient(WKBundlePageRef , WKBundlePagePolicyClientBase* wkClient) |
108 | { |
109 | WebKit::toImpl(pageRef)->initializeInjectedBundlePolicyClient(wkClient); |
110 | } |
111 | |
112 | void WKBundlePageSetUIClient(WKBundlePageRef , WKBundlePageUIClientBase* wkClient) |
113 | { |
114 | WebKit::toImpl(pageRef)->setInjectedBundleUIClient(std::make_unique<WebKit::InjectedBundlePageUIClient>(wkClient)); |
115 | } |
116 | |
117 | void WKBundlePageSetFullScreenClient(WKBundlePageRef , WKBundlePageFullScreenClientBase* wkClient) |
118 | { |
119 | #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API |
120 | WebKit::toImpl(pageRef)->initializeInjectedBundleFullScreenClient(wkClient); |
121 | #else |
122 | UNUSED_PARAM(pageRef); |
123 | UNUSED_PARAM(wkClient); |
124 | #endif |
125 | } |
126 | |
127 | void WKBundlePageWillEnterFullScreen(WKBundlePageRef ) |
128 | { |
129 | #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API |
130 | WebKit::toImpl(pageRef)->fullScreenManager()->willEnterFullScreen(); |
131 | #else |
132 | UNUSED_PARAM(pageRef); |
133 | #endif |
134 | } |
135 | |
136 | void WKBundlePageDidEnterFullScreen(WKBundlePageRef ) |
137 | { |
138 | #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API |
139 | WebKit::toImpl(pageRef)->fullScreenManager()->didEnterFullScreen(); |
140 | #else |
141 | UNUSED_PARAM(pageRef); |
142 | #endif |
143 | } |
144 | |
145 | void WKBundlePageWillExitFullScreen(WKBundlePageRef ) |
146 | { |
147 | #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API |
148 | WebKit::toImpl(pageRef)->fullScreenManager()->willExitFullScreen(); |
149 | #else |
150 | UNUSED_PARAM(pageRef); |
151 | #endif |
152 | } |
153 | |
154 | void WKBundlePageDidExitFullScreen(WKBundlePageRef ) |
155 | { |
156 | #if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API |
157 | WebKit::toImpl(pageRef)->fullScreenManager()->didExitFullScreen(); |
158 | #else |
159 | UNUSED_PARAM(pageRef); |
160 | #endif |
161 | } |
162 | |
163 | WKBundlePageGroupRef WKBundlePageGetPageGroup(WKBundlePageRef ) |
164 | { |
165 | return toAPI(WebKit::toImpl(pageRef)->pageGroup()); |
166 | } |
167 | |
168 | WKBundleFrameRef WKBundlePageGetMainFrame(WKBundlePageRef ) |
169 | { |
170 | return toAPI(WebKit::toImpl(pageRef)->mainWebFrame()); |
171 | } |
172 | |
173 | WKFrameHandleRef WKBundleFrameCreateFrameHandle(WKBundleFrameRef bundleFrameRef) |
174 | { |
175 | return WebKit::toAPI(&API::FrameHandle::create(WebKit::toImpl(bundleFrameRef)->frameID()).leakRef()); |
176 | } |
177 | |
178 | void (WKBundlePageRef , WKContextMenuItemRef item) |
179 | { |
180 | #if ENABLE(CONTEXT_MENUS) |
181 | WebKit::toImpl(pageRef)->contextMenu()->itemSelected(WebKit::toImpl(item)->data()); |
182 | #else |
183 | UNUSED_PARAM(pageRef); |
184 | UNUSED_PARAM(item); |
185 | #endif |
186 | } |
187 | |
188 | #if ENABLE(CONTEXT_MENUS) |
189 | static Ref<API::Array> (const WebKit::WebContextMenu& ) |
190 | { |
191 | auto items = contextMenu.items(); |
192 | |
193 | Vector<RefPtr<API::Object>> ; |
194 | menuItems.reserveInitialCapacity(items.size()); |
195 | |
196 | for (const auto& item : items) |
197 | menuItems.uncheckedAppend(WebKit::WebContextMenuItem::create(item)); |
198 | |
199 | return API::Array::create(WTFMove(menuItems)); |
200 | } |
201 | #endif |
202 | |
203 | WKArrayRef (WKBundlePageRef ) |
204 | { |
205 | #if ENABLE(CONTEXT_MENUS) |
206 | WebKit::WebContextMenu* = WebKit::toImpl(pageRef)->contextMenu(); |
207 | |
208 | return WebKit::toAPI(&contextMenuItems(*contextMenu).leakRef()); |
209 | #else |
210 | UNUSED_PARAM(pageRef); |
211 | return nullptr; |
212 | #endif |
213 | } |
214 | |
215 | WKArrayRef (WKBundlePageRef , WKPoint point) |
216 | { |
217 | #if ENABLE(CONTEXT_MENUS) |
218 | WebKit::WebContextMenu* = WebKit::toImpl(pageRef)->contextMenuAtPointInWindow(WebKit::toIntPoint(point)); |
219 | if (!contextMenu) |
220 | return nullptr; |
221 | |
222 | return WebKit::toAPI(&contextMenuItems(*contextMenu).leakRef()); |
223 | #else |
224 | UNUSED_PARAM(pageRef); |
225 | UNUSED_PARAM(point); |
226 | return nullptr; |
227 | #endif |
228 | } |
229 | |
230 | void WKBundlePageInsertNewlineInQuotedContent(WKBundlePageRef ) |
231 | { |
232 | WebKit::toImpl(pageRef)->insertNewlineInQuotedContent(); |
233 | } |
234 | |
235 | void* WKAccessibilityRootObject(WKBundlePageRef ) |
236 | { |
237 | #if HAVE(ACCESSIBILITY) |
238 | if (!pageRef) |
239 | return 0; |
240 | |
241 | WebCore::Page* page = WebKit::toImpl(pageRef)->corePage(); |
242 | if (!page) |
243 | return 0; |
244 | |
245 | WebCore::Frame& core = page->mainFrame(); |
246 | if (!core.document()) |
247 | return 0; |
248 | |
249 | WebCore::AXObjectCache::enableAccessibility(); |
250 | |
251 | WebCore::AccessibilityObject* root = core.document()->axObjectCache()->rootObject(); |
252 | if (!root) |
253 | return 0; |
254 | |
255 | return root->wrapper(); |
256 | #else |
257 | UNUSED_PARAM(pageRef); |
258 | return 0; |
259 | #endif |
260 | } |
261 | |
262 | void* WKAccessibilityFocusedObject(WKBundlePageRef ) |
263 | { |
264 | #if HAVE(ACCESSIBILITY) |
265 | if (!pageRef) |
266 | return 0; |
267 | |
268 | WebCore::Page* page = WebKit::toImpl(pageRef)->corePage(); |
269 | if (!page) |
270 | return 0; |
271 | |
272 | WebCore::AXObjectCache::enableAccessibility(); |
273 | |
274 | WebCore::AccessibilityObject* focusedObject = WebCore::AXObjectCache::focusedUIElementForPage(page); |
275 | if (!focusedObject) |
276 | return 0; |
277 | |
278 | return focusedObject->wrapper(); |
279 | #else |
280 | UNUSED_PARAM(pageRef); |
281 | return 0; |
282 | #endif |
283 | } |
284 | |
285 | void WKAccessibilityEnableEnhancedAccessibility(bool enable) |
286 | { |
287 | #if HAVE(ACCESSIBILITY) |
288 | WebCore::AXObjectCache::setEnhancedUserInterfaceAccessibility(enable); |
289 | #endif |
290 | } |
291 | |
292 | bool WKAccessibilityEnhancedAccessibilityEnabled() |
293 | { |
294 | #if HAVE(ACCESSIBILITY) |
295 | return WebCore::AXObjectCache::accessibilityEnhancedUserInterfaceEnabled(); |
296 | #else |
297 | return false; |
298 | #endif |
299 | } |
300 | |
301 | void WKBundlePageStopLoading(WKBundlePageRef ) |
302 | { |
303 | WebKit::toImpl(pageRef)->stopLoading(); |
304 | } |
305 | |
306 | void WKBundlePageSetDefersLoading(WKBundlePageRef, bool) |
307 | { |
308 | } |
309 | |
310 | WKStringRef WKBundlePageCopyRenderTreeExternalRepresentation(WKBundlePageRef , RenderTreeExternalRepresentationBehavior options) |
311 | { |
312 | // Convert to webcore options. |
313 | return WebKit::toCopiedAPI(WebKit::toImpl(pageRef)->renderTreeExternalRepresentation(options)); |
314 | } |
315 | |
316 | WKStringRef WKBundlePageCopyRenderTreeExternalRepresentationForPrinting(WKBundlePageRef ) |
317 | { |
318 | return WebKit::toCopiedAPI(WebKit::toImpl(pageRef)->renderTreeExternalRepresentationForPrinting()); |
319 | } |
320 | |
321 | void WKBundlePageExecuteEditingCommand(WKBundlePageRef , WKStringRef name, WKStringRef argument) |
322 | { |
323 | WebKit::toImpl(pageRef)->executeEditingCommand(WebKit::toWTFString(name), WebKit::toWTFString(argument)); |
324 | } |
325 | |
326 | bool WKBundlePageIsEditingCommandEnabled(WKBundlePageRef , WKStringRef name) |
327 | { |
328 | return WebKit::toImpl(pageRef)->isEditingCommandEnabled(WebKit::toWTFString(name)); |
329 | } |
330 | |
331 | void WKBundlePageClearMainFrameName(WKBundlePageRef ) |
332 | { |
333 | WebKit::toImpl(pageRef)->clearMainFrameName(); |
334 | } |
335 | |
336 | void WKBundlePageClose(WKBundlePageRef ) |
337 | { |
338 | WebKit::toImpl(pageRef)->sendClose(); |
339 | } |
340 | |
341 | double WKBundlePageGetTextZoomFactor(WKBundlePageRef ) |
342 | { |
343 | return WebKit::toImpl(pageRef)->textZoomFactor(); |
344 | } |
345 | |
346 | void WKBundlePageSetTextZoomFactor(WKBundlePageRef , double zoomFactor) |
347 | { |
348 | WebKit::toImpl(pageRef)->setTextZoomFactor(zoomFactor); |
349 | } |
350 | |
351 | double WKBundlePageGetPageZoomFactor(WKBundlePageRef ) |
352 | { |
353 | return WebKit::toImpl(pageRef)->pageZoomFactor(); |
354 | } |
355 | |
356 | void WKBundlePageSetPageZoomFactor(WKBundlePageRef , double zoomFactor) |
357 | { |
358 | WebKit::toImpl(pageRef)->setPageZoomFactor(zoomFactor); |
359 | } |
360 | |
361 | void WKBundlePageSetScaleAtOrigin(WKBundlePageRef , double scale, WKPoint origin) |
362 | { |
363 | WebKit::toImpl(pageRef)->scalePage(scale, WebKit::toIntPoint(origin)); |
364 | } |
365 | |
366 | WKStringRef WKBundlePageDumpHistoryForTesting(WKBundlePageRef page, WKStringRef directory) |
367 | { |
368 | return WebKit::toCopiedAPI(WebKit::toImpl(page)->dumpHistoryForTesting(WebKit::toWTFString(directory))); |
369 | } |
370 | |
371 | void WKBundleClearHistoryForTesting(WKBundlePageRef page) |
372 | { |
373 | WebKit::toImpl(page)->clearHistory(); |
374 | } |
375 | |
376 | WKBundleBackForwardListRef WKBundlePageGetBackForwardList(WKBundlePageRef ) |
377 | { |
378 | return nullptr; |
379 | } |
380 | |
381 | void WKBundlePageInstallPageOverlay(WKBundlePageRef , WKBundlePageOverlayRef pageOverlayRef) |
382 | { |
383 | WebKit::toImpl(pageRef)->corePage()->pageOverlayController().installPageOverlay(*WebKit::toImpl(pageOverlayRef)->coreOverlay(), WebCore::PageOverlay::FadeMode::DoNotFade); |
384 | } |
385 | |
386 | void WKBundlePageUninstallPageOverlay(WKBundlePageRef , WKBundlePageOverlayRef pageOverlayRef) |
387 | { |
388 | WebKit::toImpl(pageRef)->corePage()->pageOverlayController().uninstallPageOverlay(*WebKit::toImpl(pageOverlayRef)->coreOverlay(), WebCore::PageOverlay::FadeMode::DoNotFade); |
389 | } |
390 | |
391 | void WKBundlePageInstallPageOverlayWithAnimation(WKBundlePageRef , WKBundlePageOverlayRef pageOverlayRef) |
392 | { |
393 | WebKit::toImpl(pageRef)->corePage()->pageOverlayController().installPageOverlay(*WebKit::toImpl(pageOverlayRef)->coreOverlay(), WebCore::PageOverlay::FadeMode::Fade); |
394 | } |
395 | |
396 | void WKBundlePageUninstallPageOverlayWithAnimation(WKBundlePageRef , WKBundlePageOverlayRef pageOverlayRef) |
397 | { |
398 | WebKit::toImpl(pageRef)->corePage()->pageOverlayController().uninstallPageOverlay(*WebKit::toImpl(pageOverlayRef)->coreOverlay(), WebCore::PageOverlay::FadeMode::Fade); |
399 | } |
400 | |
401 | void WKBundlePageSetTopOverhangImage(WKBundlePageRef , WKImageRef imageRef) |
402 | { |
403 | #if PLATFORM(MAC) |
404 | WebKit::toImpl(pageRef)->setTopOverhangImage(WebKit::toImpl(imageRef)); |
405 | #else |
406 | UNUSED_PARAM(pageRef); |
407 | UNUSED_PARAM(imageRef); |
408 | #endif |
409 | } |
410 | |
411 | void WKBundlePageSetBottomOverhangImage(WKBundlePageRef , WKImageRef imageRef) |
412 | { |
413 | #if PLATFORM(MAC) |
414 | WebKit::toImpl(pageRef)->setBottomOverhangImage(WebKit::toImpl(imageRef)); |
415 | #else |
416 | UNUSED_PARAM(pageRef); |
417 | UNUSED_PARAM(imageRef); |
418 | #endif |
419 | } |
420 | |
421 | #if !PLATFORM(IOS_FAMILY) |
422 | void (WKBundlePageRef , WKBundlePageBannerRef bannerRef) |
423 | { |
424 | WebKit::toImpl(pageRef)->setHeaderPageBanner(WebKit::toImpl(bannerRef)); |
425 | } |
426 | |
427 | void (WKBundlePageRef , WKBundlePageBannerRef bannerRef) |
428 | { |
429 | WebKit::toImpl(pageRef)->setFooterPageBanner(WebKit::toImpl(bannerRef)); |
430 | } |
431 | #endif // !PLATFORM(IOS_FAMILY) |
432 | |
433 | bool WKBundlePageHasLocalDataForURL(WKBundlePageRef , WKURLRef urlRef) |
434 | { |
435 | return WebKit::toImpl(pageRef)->hasLocalDataForURL(URL(URL(), WebKit::toWTFString(urlRef))); |
436 | } |
437 | |
438 | bool WKBundlePageCanHandleRequest(WKURLRequestRef requestRef) |
439 | { |
440 | if (!requestRef) |
441 | return false; |
442 | return WebKit::WebPage::canHandleRequest(WebKit::toImpl(requestRef)->resourceRequest()); |
443 | } |
444 | |
445 | bool WKBundlePageFindString(WKBundlePageRef , WKStringRef target, WKFindOptions findOptions) |
446 | { |
447 | return WebKit::toImpl(pageRef)->findStringFromInjectedBundle(WebKit::toWTFString(target), WebKit::toFindOptions(findOptions)); |
448 | } |
449 | |
450 | void WKBundlePageFindStringMatches(WKBundlePageRef , WKStringRef target, WKFindOptions findOptions) |
451 | { |
452 | WebKit::toImpl(pageRef)->findStringMatchesFromInjectedBundle(WebKit::toWTFString(target), WebKit::toFindOptions(findOptions)); |
453 | } |
454 | |
455 | void (WKBundlePageRef , WKArrayRef matchIndicesRef, WKStringRef replacementText, bool selectionOnly) |
456 | { |
457 | auto* matchIndices = WebKit::toImpl(matchIndicesRef); |
458 | |
459 | Vector<uint32_t> indices; |
460 | indices.reserveInitialCapacity(matchIndices->size()); |
461 | |
462 | auto numberOfMatchIndices = matchIndices->size(); |
463 | for (size_t i = 0; i < numberOfMatchIndices; ++i) { |
464 | if (auto* indexAsObject = matchIndices->at<API::UInt64>(i)) |
465 | indices.uncheckedAppend(indexAsObject->value()); |
466 | } |
467 | WebKit::toImpl(pageRef)->replaceStringMatchesFromInjectedBundle(indices, WebKit::toWTFString(replacementText), selectionOnly); |
468 | } |
469 | |
470 | WKImageRef WKBundlePageCreateSnapshotWithOptions(WKBundlePageRef , WKRect rect, WKSnapshotOptions options) |
471 | { |
472 | RefPtr<WebKit::WebImage> webImage = WebKit::toImpl(pageRef)->scaledSnapshotWithOptions(WebKit::toIntRect(rect), 1, WebKit::toSnapshotOptions(options)); |
473 | return toAPI(webImage.leakRef()); |
474 | } |
475 | |
476 | WKImageRef WKBundlePageCreateSnapshotInViewCoordinates(WKBundlePageRef , WKRect rect, WKImageOptions options) |
477 | { |
478 | auto snapshotOptions = WebKit::snapshotOptionsFromImageOptions(options); |
479 | snapshotOptions |= WebKit::SnapshotOptionsInViewCoordinates; |
480 | RefPtr<WebKit::WebImage> webImage = WebKit::toImpl(pageRef)->scaledSnapshotWithOptions(WebKit::toIntRect(rect), 1, snapshotOptions); |
481 | return toAPI(webImage.leakRef()); |
482 | } |
483 | |
484 | WKImageRef WKBundlePageCreateSnapshotInDocumentCoordinates(WKBundlePageRef , WKRect rect, WKImageOptions options) |
485 | { |
486 | RefPtr<WebKit::WebImage> webImage = WebKit::toImpl(pageRef)->scaledSnapshotWithOptions(WebKit::toIntRect(rect), 1, WebKit::snapshotOptionsFromImageOptions(options)); |
487 | return toAPI(webImage.leakRef()); |
488 | } |
489 | |
490 | WKImageRef WKBundlePageCreateScaledSnapshotInDocumentCoordinates(WKBundlePageRef , WKRect rect, double scaleFactor, WKImageOptions options) |
491 | { |
492 | RefPtr<WebKit::WebImage> webImage = WebKit::toImpl(pageRef)->scaledSnapshotWithOptions(WebKit::toIntRect(rect), scaleFactor, WebKit::snapshotOptionsFromImageOptions(options)); |
493 | return toAPI(webImage.leakRef()); |
494 | } |
495 | |
496 | double WKBundlePageGetBackingScaleFactor(WKBundlePageRef ) |
497 | { |
498 | return WebKit::toImpl(pageRef)->deviceScaleFactor(); |
499 | } |
500 | |
501 | void WKBundlePageListenForLayoutMilestones(WKBundlePageRef , WKLayoutMilestones milestones) |
502 | { |
503 | WebKit::toImpl(pageRef)->listenForLayoutMilestones(WebKit::toLayoutMilestones(milestones)); |
504 | } |
505 | |
506 | WKBundleInspectorRef WKBundlePageGetInspector(WKBundlePageRef ) |
507 | { |
508 | return WebKit::toAPI(WebKit::toImpl(pageRef)->inspector()); |
509 | } |
510 | |
511 | void WKBundlePageForceRepaint(WKBundlePageRef page) |
512 | { |
513 | WebKit::toImpl(page)->forceRepaintWithoutCallback(); |
514 | } |
515 | |
516 | void WKBundlePageSimulateMouseDown(WKBundlePageRef page, int button, WKPoint position, int clickCount, WKEventModifiers modifiers, double time) |
517 | { |
518 | WebKit::toImpl(page)->simulateMouseDown(button, WebKit::toIntPoint(position), clickCount, modifiers, WallTime::fromRawSeconds(time)); |
519 | } |
520 | |
521 | void WKBundlePageSimulateMouseUp(WKBundlePageRef page, int button, WKPoint position, int clickCount, WKEventModifiers modifiers, double time) |
522 | { |
523 | WebKit::toImpl(page)->simulateMouseUp(button, WebKit::toIntPoint(position), clickCount, modifiers, WallTime::fromRawSeconds(time)); |
524 | } |
525 | |
526 | void WKBundlePageSimulateMouseMotion(WKBundlePageRef page, WKPoint position, double time) |
527 | { |
528 | WebKit::toImpl(page)->simulateMouseMotion(WebKit::toIntPoint(position), WallTime::fromRawSeconds(time)); |
529 | } |
530 | |
531 | uint64_t WKBundlePageGetRenderTreeSize(WKBundlePageRef ) |
532 | { |
533 | return WebKit::toImpl(pageRef)->renderTreeSize(); |
534 | } |
535 | |
536 | WKRenderObjectRef WKBundlePageCopyRenderTree(WKBundlePageRef ) |
537 | { |
538 | return WebKit::toAPI(WebKit::WebRenderObject::create(WebKit::toImpl(pageRef)).leakRef()); |
539 | } |
540 | |
541 | WKRenderLayerRef WKBundlePageCopyRenderLayerTree(WKBundlePageRef ) |
542 | { |
543 | return WebKit::toAPI(WebKit::WebRenderLayer::create(WebKit::toImpl(pageRef)).leakRef()); |
544 | } |
545 | |
546 | void WKBundlePageSetPaintedObjectsCounterThreshold(WKBundlePageRef, uint64_t) |
547 | { |
548 | // FIXME: This function is only still here to keep open source Mac builds building. |
549 | // We should remove it as soon as we can. |
550 | } |
551 | |
552 | void WKBundlePageSetTracksRepaints(WKBundlePageRef , bool trackRepaints) |
553 | { |
554 | WebKit::toImpl(pageRef)->setTracksRepaints(trackRepaints); |
555 | } |
556 | |
557 | bool WKBundlePageIsTrackingRepaints(WKBundlePageRef ) |
558 | { |
559 | return WebKit::toImpl(pageRef)->isTrackingRepaints(); |
560 | } |
561 | |
562 | void (WKBundlePageRef ) |
563 | { |
564 | WebKit::toImpl(pageRef)->resetTrackedRepaints(); |
565 | } |
566 | |
567 | WKArrayRef WKBundlePageCopyTrackedRepaintRects(WKBundlePageRef ) |
568 | { |
569 | return WebKit::toAPI(&WebKit::toImpl(pageRef)->trackedRepaintRects().leakRef()); |
570 | } |
571 | |
572 | void WKBundlePageSetComposition(WKBundlePageRef , WKStringRef text, int from, int length, bool suppressUnderline) |
573 | { |
574 | WebKit::toImpl(pageRef)->setCompositionForTesting(WebKit::toWTFString(text), from, length, suppressUnderline); |
575 | } |
576 | |
577 | bool WKBundlePageHasComposition(WKBundlePageRef ) |
578 | { |
579 | return WebKit::toImpl(pageRef)->hasCompositionForTesting(); |
580 | } |
581 | |
582 | void WKBundlePageConfirmComposition(WKBundlePageRef ) |
583 | { |
584 | WebKit::toImpl(pageRef)->confirmCompositionForTesting(String()); |
585 | } |
586 | |
587 | void WKBundlePageConfirmCompositionWithText(WKBundlePageRef , WKStringRef text) |
588 | { |
589 | WebKit::toImpl(pageRef)->confirmCompositionForTesting(WebKit::toWTFString(text)); |
590 | } |
591 | |
592 | void WKBundlePageSetUseDarkAppearance(WKBundlePageRef , bool useDarkAppearance) |
593 | { |
594 | WebKit::WebPage* webPage = WebKit::toImpl(pageRef); |
595 | if (WebCore::Page* page = webPage ? webPage->corePage() : nullptr) |
596 | page->effectiveAppearanceDidChange(useDarkAppearance, page->useInactiveAppearance()); |
597 | } |
598 | |
599 | bool WKBundlePageIsUsingDarkAppearance(WKBundlePageRef ) |
600 | { |
601 | WebKit::WebPage* webPage = WebKit::toImpl(pageRef); |
602 | if (WebCore::Page* page = webPage ? webPage->corePage() : nullptr) |
603 | return page->useDarkAppearance(); |
604 | return false; |
605 | } |
606 | |
607 | bool WKBundlePageCanShowMIMEType(WKBundlePageRef , WKStringRef mimeTypeRef) |
608 | { |
609 | return WebKit::toImpl(pageRef)->canShowMIMEType(WebKit::toWTFString(mimeTypeRef)); |
610 | } |
611 | |
612 | WKRenderingSuppressionToken WKBundlePageExtendIncrementalRenderingSuppression(WKBundlePageRef ) |
613 | { |
614 | return WebKit::toImpl(pageRef)->extendIncrementalRenderingSuppression(); |
615 | } |
616 | |
617 | void WKBundlePageStopExtendingIncrementalRenderingSuppression(WKBundlePageRef , WKRenderingSuppressionToken token) |
618 | { |
619 | WebKit::toImpl(pageRef)->stopExtendingIncrementalRenderingSuppression(token); |
620 | } |
621 | |
622 | bool WKBundlePageIsUsingEphemeralSession(WKBundlePageRef ) |
623 | { |
624 | return WebKit::toImpl(pageRef)->usesEphemeralSession(); |
625 | } |
626 | |
627 | bool WKBundlePageIsControlledByAutomation(WKBundlePageRef ) |
628 | { |
629 | return WebKit::toImpl(pageRef)->isControlledByAutomation(); |
630 | } |
631 | |
632 | #if TARGET_OS_IPHONE |
633 | void WKBundlePageSetUseTestingViewportConfiguration(WKBundlePageRef pageRef, bool useTestingViewportConfiguration) |
634 | { |
635 | WebKit::toImpl(pageRef)->setUseTestingViewportConfiguration(useTestingViewportConfiguration); |
636 | } |
637 | #endif |
638 | |
639 | void WKBundlePageStartMonitoringScrollOperations(WKBundlePageRef ) |
640 | { |
641 | WebKit::WebPage* webPage = WebKit::toImpl(pageRef); |
642 | WebCore::Page* page = webPage ? webPage->corePage() : nullptr; |
643 | |
644 | if (!page) |
645 | return; |
646 | |
647 | page->ensureTestTrigger(); |
648 | } |
649 | |
650 | bool (WKBundlePageRef , WKBundlePageTestNotificationCallback callback, void* context) |
651 | { |
652 | if (!callback) |
653 | return false; |
654 | |
655 | WebKit::WebPage* webPage = WebKit::toImpl(pageRef); |
656 | WebCore::Page* page = webPage ? webPage->corePage() : nullptr; |
657 | if (!page || !page->expectsWheelEventTriggers()) |
658 | return false; |
659 | |
660 | page->ensureTestTrigger().setTestCallbackAndStartNotificationTimer([=]() { |
661 | callback(context); |
662 | }); |
663 | return true; |
664 | } |
665 | |
666 | void WKBundlePageCallAfterTasksAndTimers(WKBundlePageRef , WKBundlePageTestNotificationCallback callback, void* context) |
667 | { |
668 | if (!callback) |
669 | return; |
670 | |
671 | WebKit::WebPage* webPage = WebKit::toImpl(pageRef); |
672 | WebCore::Page* page = webPage ? webPage->corePage() : nullptr; |
673 | if (!page) |
674 | return; |
675 | |
676 | WebCore::Document* document = page->mainFrame().document(); |
677 | if (!document) |
678 | return; |
679 | |
680 | class TimerOwner { |
681 | public: |
682 | TimerOwner(WTF::Function<void (void*)>&& callback, void* context) |
683 | : m_timer(*this, &TimerOwner::timerFired) |
684 | , m_callback(WTFMove(callback)) |
685 | , m_context(context) |
686 | { |
687 | m_timer.startOneShot(0_s); |
688 | } |
689 | |
690 | void timerFired() |
691 | { |
692 | m_callback(m_context); |
693 | delete this; |
694 | } |
695 | |
696 | WebCore::Timer m_timer; |
697 | WTF::Function<void (void*)> m_callback; |
698 | void* m_context; |
699 | }; |
700 | |
701 | document->postTask([=] (WebCore::ScriptExecutionContext&) { |
702 | new TimerOwner(callback, context); // deletes itself when done. |
703 | }); |
704 | } |
705 | |
706 | void WKBundlePagePostMessage(WKBundlePageRef , WKStringRef messageNameRef, WKTypeRef messageBodyRef) |
707 | { |
708 | WebKit::toImpl(pageRef)->postMessage(WebKit::toWTFString(messageNameRef), WebKit::toImpl(messageBodyRef)); |
709 | } |
710 | |
711 | void WKBundlePagePostMessageIgnoringFullySynchronousMode(WKBundlePageRef , WKStringRef messageNameRef, WKTypeRef messageBodyRef) |
712 | { |
713 | WebKit::toImpl(pageRef)->postMessageIgnoringFullySynchronousMode(WebKit::toWTFString(messageNameRef), WebKit::toImpl(messageBodyRef)); |
714 | } |
715 | |
716 | void WKBundlePagePostSynchronousMessageForTesting(WKBundlePageRef , WKStringRef messageNameRef, WKTypeRef messageBodyRef, WKTypeRef* returnRetainedDataRef) |
717 | { |
718 | WebKit::WebPage* page = WebKit::toImpl(pageRef); |
719 | page->layoutIfNeeded(); |
720 | |
721 | RefPtr<API::Object> returnData; |
722 | page->postSynchronousMessageForTesting(WebKit::toWTFString(messageNameRef), WebKit::toImpl(messageBodyRef), returnData); |
723 | if (returnRetainedDataRef) |
724 | *returnRetainedDataRef = WebKit::toAPI(returnData.leakRef()); |
725 | } |
726 | |
727 | void WKBundlePageAddUserScript(WKBundlePageRef , WKStringRef source, _WKUserScriptInjectionTime injectionTime, WKUserContentInjectedFrames injectedFrames) |
728 | { |
729 | WebKit::toImpl(pageRef)->addUserScript(WebKit::toWTFString(source), WebKit::toUserContentInjectedFrames(injectedFrames), WebKit::toUserScriptInjectionTime(injectionTime)); |
730 | } |
731 | |
732 | void WKBundlePageAddUserStyleSheet(WKBundlePageRef , WKStringRef source, WKUserContentInjectedFrames injectedFrames) |
733 | { |
734 | WebKit::toImpl(pageRef)->addUserStyleSheet(WebKit::toWTFString(source), WebKit::toUserContentInjectedFrames(injectedFrames)); |
735 | } |
736 | |
737 | void (WKBundlePageRef ) |
738 | { |
739 | WebKit::toImpl(pageRef)->removeAllUserContent(); |
740 | } |
741 | |
742 | WKStringRef WKBundlePageCopyGroupIdentifier(WKBundlePageRef ) |
743 | { |
744 | return WebKit::toCopiedAPI(WebKit::toImpl(pageRef)->pageGroup()->identifier()); |
745 | } |
746 | |
747 | void WKBundlePageClearApplicationCache(WKBundlePageRef page) |
748 | { |
749 | WebKit::toImpl(page)->corePage()->applicationCacheStorage().deleteAllEntries(); |
750 | } |
751 | |
752 | void WKBundlePageClearApplicationCacheForOrigin(WKBundlePageRef page, WKStringRef origin) |
753 | { |
754 | WebKit::toImpl(page)->corePage()->applicationCacheStorage().deleteCacheForOrigin(WebCore::SecurityOrigin::createFromString(WebKit::toImpl(origin)->string())); |
755 | } |
756 | |
757 | void WKBundlePageSetAppCacheMaximumSize(WKBundlePageRef page, uint64_t size) |
758 | { |
759 | WebKit::toImpl(page)->corePage()->applicationCacheStorage().setMaximumSize(size); |
760 | } |
761 | |
762 | uint64_t WKBundlePageGetAppCacheUsageForOrigin(WKBundlePageRef page, WKStringRef origin) |
763 | { |
764 | return WebKit::toImpl(page)->corePage()->applicationCacheStorage().diskUsageForOrigin(WebCore::SecurityOrigin::createFromString(WebKit::toImpl(origin)->string())); |
765 | } |
766 | |
767 | void WKBundlePageSetApplicationCacheOriginQuota(WKBundlePageRef page, WKStringRef origin, uint64_t bytes) |
768 | { |
769 | WebKit::toImpl(page)->corePage()->applicationCacheStorage().storeUpdatedQuotaForOrigin(WebCore::SecurityOrigin::createFromString(WebKit::toImpl(origin)->string()).ptr(), bytes); |
770 | } |
771 | |
772 | void (WKBundlePageRef page, WKStringRef origin) |
773 | { |
774 | WebKit::toImpl(page)->corePage()->applicationCacheStorage().storeUpdatedQuotaForOrigin(WebCore::SecurityOrigin::createFromString(WebKit::toImpl(origin)->string()).ptr(), WebKit::toImpl(page)->corePage()->applicationCacheStorage().defaultOriginQuota()); |
775 | } |
776 | |
777 | WKArrayRef WKBundlePageCopyOriginsWithApplicationCache(WKBundlePageRef page) |
778 | { |
779 | auto origins = WebKit::toImpl(page)->corePage()->applicationCacheStorage().originsWithCache(); |
780 | |
781 | Vector<RefPtr<API::Object>> originIdentifiers; |
782 | originIdentifiers.reserveInitialCapacity(origins.size()); |
783 | |
784 | for (const auto& origin : origins) |
785 | originIdentifiers.uncheckedAppend(API::String::create(origin->data().databaseIdentifier())); |
786 | |
787 | return WebKit::toAPI(&API::Array::create(WTFMove(originIdentifiers)).leakRef()); |
788 | } |
789 | |
790 | void WKBundlePageSetEventThrottlingBehaviorOverride(WKBundlePageRef page, WKEventThrottlingBehavior* behavior) |
791 | { |
792 | Optional<WebCore::EventThrottlingBehavior> behaviorValue; |
793 | if (behavior) { |
794 | switch (*behavior) { |
795 | case kWKEventThrottlingBehaviorResponsive: |
796 | behaviorValue = WebCore::EventThrottlingBehavior::Responsive; |
797 | break; |
798 | case kWKEventThrottlingBehaviorUnresponsive: |
799 | behaviorValue = WebCore::EventThrottlingBehavior::Unresponsive; |
800 | break; |
801 | } |
802 | } |
803 | |
804 | WebKit::toImpl(page)->corePage()->setEventThrottlingBehaviorOverride(behaviorValue); |
805 | } |
806 | |