Storage Access API: Make document.hasStorageAccess() retrieve current status from...
[WebKit-https.git] / Source / WebKit / WebProcess / WebCoreSupport / WebChromeClient.cpp
1 /*
2  * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
3  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24  * THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include "config.h"
28 #include "WebChromeClient.h"
29
30 #include "APIArray.h"
31 #include "APISecurityOrigin.h"
32 #include "DrawingArea.h"
33 #include "FindController.h"
34 #include "FrameInfoData.h"
35 #include "HangDetectionDisabler.h"
36 #include "InjectedBundleNavigationAction.h"
37 #include "InjectedBundleNodeHandle.h"
38 #include "NavigationActionData.h"
39 #include "PageBanner.h"
40 #include "UserData.h"
41 #include "WebColorChooser.h"
42 #include "WebCoreArgumentCoders.h"
43 #include "WebFrame.h"
44 #include "WebFrameLoaderClient.h"
45 #include "WebFullScreenManager.h"
46 #include "WebHitTestResultData.h"
47 #include "WebImage.h"
48 #include "WebOpenPanelResultListener.h"
49 #include "WebPage.h"
50 #include "WebPageCreationParameters.h"
51 #include "WebPageProxyMessages.h"
52 #include "WebPopupMenu.h"
53 #include "WebProcess.h"
54 #include "WebProcessPoolMessages.h"
55 #include "WebProcessProxyMessages.h"
56 #include "WebSearchPopupMenu.h"
57 #include <WebCore/ApplicationCacheStorage.h>
58 #include <WebCore/AXObjectCache.h>
59 #include <WebCore/ColorChooser.h>
60 #include <WebCore/DatabaseTracker.h>
61 #include <WebCore/DocumentLoader.h>
62 #include <WebCore/FileChooser.h>
63 #include <WebCore/FileIconLoader.h>
64 #include <WebCore/FrameLoadRequest.h>
65 #include <WebCore/FrameLoader.h>
66 #include <WebCore/FrameView.h>
67 #include <WebCore/HTMLInputElement.h>
68 #include <WebCore/HTMLNames.h>
69 #include <WebCore/HTMLParserIdioms.h>
70 #include <WebCore/HTMLPlugInImageElement.h>
71 #include <WebCore/Icon.h>
72 #include <WebCore/MainFrame.h>
73 #include <WebCore/NotImplemented.h>
74 #include <WebCore/Page.h>
75 #include <WebCore/ScriptController.h>
76 #include <WebCore/SecurityOrigin.h>
77 #include <WebCore/SecurityOriginData.h>
78 #include <WebCore/Settings.h>
79
80 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
81 #include "PlaybackSessionManager.h"
82 #include "VideoFullscreenManager.h"
83 #endif
84
85 #if ENABLE(ASYNC_SCROLLING)
86 #include "RemoteScrollingCoordinator.h"
87 #endif
88
89 #if PLATFORM(GTK)
90 #include "PrinterListGtk.h"
91 #endif
92
93 using namespace WebCore;
94 using namespace HTMLNames;
95
96 namespace WebKit {
97
98 static double area(WebFrame* frame)
99 {
100     IntSize size = frame->visibleContentBoundsExcludingScrollbars().size();
101     return static_cast<double>(size.height()) * size.width();
102 }
103
104 static WebFrame* findLargestFrameInFrameSet(WebPage& page)
105 {
106     // Approximate what a user could consider a default target frame for application menu operations.
107
108     WebFrame* mainFrame = page.mainWebFrame();
109     if (!mainFrame || !mainFrame->isFrameSet())
110         return nullptr;
111
112     WebFrame* largestSoFar = nullptr;
113
114     Ref<API::Array> frameChildren = mainFrame->childFrames();
115     size_t count = frameChildren->size();
116     for (size_t i = 0; i < count; ++i) {
117         auto* childFrame = frameChildren->at<WebFrame>(i);
118         if (!largestSoFar || area(childFrame) > area(largestSoFar))
119             largestSoFar = childFrame;
120     }
121
122     return largestSoFar;
123 }
124
125 WebChromeClient::WebChromeClient(WebPage& page)
126     : m_page(page)
127 {
128 }
129
130 void WebChromeClient::didInsertMenuElement(HTMLMenuElement& element)
131 {
132     m_page.didInsertMenuElement(element);
133 }
134
135 void WebChromeClient::didRemoveMenuElement(HTMLMenuElement& element)
136 {
137     m_page.didRemoveMenuElement(element);
138 }
139
140 void WebChromeClient::didInsertMenuItemElement(HTMLMenuItemElement& element)
141 {
142     m_page.didInsertMenuItemElement(element);
143 }
144
145 void WebChromeClient::didRemoveMenuItemElement(HTMLMenuItemElement& element)
146 {
147     m_page.didRemoveMenuItemElement(element);
148 }
149
150 inline WebChromeClient::~WebChromeClient()
151 {
152 }
153
154 void WebChromeClient::chromeDestroyed()
155 {
156     delete this;
157 }
158
159 void WebChromeClient::setWindowRect(const FloatRect& windowFrame)
160 {
161     m_page.sendSetWindowFrame(windowFrame);
162 }
163
164 FloatRect WebChromeClient::windowRect()
165 {
166 #if PLATFORM(IOS)
167     return FloatRect();
168 #else
169 #if PLATFORM(MAC)
170     if (m_page.hasCachedWindowFrame())
171         return m_page.windowFrameInUnflippedScreenCoordinates();
172 #endif
173
174     FloatRect newWindowFrame;
175
176     if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetWindowFrame(), Messages::WebPageProxy::GetWindowFrame::Reply(newWindowFrame), m_page.pageID()))
177         return FloatRect();
178
179     return newWindowFrame;
180 #endif
181 }
182
183 FloatRect WebChromeClient::pageRect()
184 {
185     return FloatRect(FloatPoint(), m_page.size());
186 }
187
188 void WebChromeClient::focus()
189 {
190     m_page.send(Messages::WebPageProxy::SetFocus(true));
191 }
192
193 void WebChromeClient::unfocus()
194 {
195     m_page.send(Messages::WebPageProxy::SetFocus(false));
196 }
197
198 #if PLATFORM(COCOA)
199
200 void WebChromeClient::elementDidFocus(Element& element)
201 {
202     m_page.elementDidFocus(&element);
203 }
204
205 void WebChromeClient::elementDidBlur(Element& element)
206 {
207     m_page.elementDidBlur(&element);
208 }
209
210 void WebChromeClient::makeFirstResponder()
211 {
212     m_page.send(Messages::WebPageProxy::MakeFirstResponder());
213 }
214
215 #endif    
216
217 bool WebChromeClient::canTakeFocus(FocusDirection)
218 {
219     notImplemented();
220     return true;
221 }
222
223 void WebChromeClient::takeFocus(FocusDirection direction)
224 {
225     m_page.send(Messages::WebPageProxy::TakeFocus(direction));
226 }
227
228 void WebChromeClient::focusedElementChanged(Element* element)
229 {
230     if (!is<HTMLInputElement>(element))
231         return;
232
233     HTMLInputElement& inputElement = downcast<HTMLInputElement>(*element);
234     if (!inputElement.isText())
235         return;
236
237     WebFrame* webFrame = WebFrame::fromCoreFrame(*element->document().frame());
238     ASSERT(webFrame);
239     m_page.injectedBundleFormClient().didFocusTextField(&m_page, &inputElement, webFrame);
240 }
241
242 void WebChromeClient::focusedFrameChanged(Frame* frame)
243 {
244     WebFrame* webFrame = frame ? WebFrame::fromCoreFrame(*frame) : nullptr;
245
246     WebProcess::singleton().parentProcessConnection()->send(Messages::WebPageProxy::FocusedFrameChanged(webFrame ? webFrame->frameID() : 0), m_page.pageID());
247 }
248
249 Page* WebChromeClient::createWindow(Frame& frame, const FrameLoadRequest& request, const WindowFeatures& windowFeatures, const NavigationAction& navigationAction)
250 {
251 #if ENABLE(FULLSCREEN_API)
252     if (frame.document() && frame.document()->webkitCurrentFullScreenElement())
253         frame.document()->webkitCancelFullScreen();
254 #endif
255
256     auto& webProcess = WebProcess::singleton();
257
258     NavigationActionData navigationActionData;
259     navigationActionData.navigationType = navigationAction.type();
260     navigationActionData.modifiers = InjectedBundleNavigationAction::modifiersForNavigationAction(navigationAction);
261     navigationActionData.mouseButton = InjectedBundleNavigationAction::mouseButtonForNavigationAction(navigationAction);
262     navigationActionData.syntheticClickType = InjectedBundleNavigationAction::syntheticClickTypeForNavigationAction(navigationAction);
263     navigationActionData.clickLocationInRootViewCoordinates = InjectedBundleNavigationAction::clickLocationInRootViewCoordinatesForNavigationAction(navigationAction);
264     navigationActionData.userGestureTokenIdentifier = webProcess.userGestureTokenIdentifier(navigationAction.userGestureToken());
265     navigationActionData.canHandleRequest = m_page.canHandleRequest(request.resourceRequest());
266     navigationActionData.shouldOpenExternalURLsPolicy = navigationAction.shouldOpenExternalURLsPolicy();
267     navigationActionData.downloadAttribute = navigationAction.downloadAttribute();
268
269     WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
270
271     uint64_t newPageID = 0;
272     WebPageCreationParameters parameters;
273     if (!webProcess.parentProcessConnection()->sendSync(Messages::WebPageProxy::CreateNewPage(webFrame->info(), webFrame->page()->pageID(), request.resourceRequest(), windowFeatures, navigationActionData), Messages::WebPageProxy::CreateNewPage::Reply(newPageID, parameters), m_page.pageID()))
274         return nullptr;
275
276     if (!newPageID)
277         return nullptr;
278
279     webProcess.createWebPage(newPageID, WTFMove(parameters));
280     return webProcess.webPage(newPageID)->corePage();
281 }
282
283 void WebChromeClient::show()
284 {
285     m_page.show();
286 }
287
288 bool WebChromeClient::canRunModal()
289 {
290     return m_page.canRunModal();
291 }
292
293 void WebChromeClient::runModal()
294 {
295     m_page.runModal();
296 }
297
298 void WebChromeClient::reportProcessCPUTime(Seconds cpuTime, ActivityStateForCPUSampling activityState)
299 {
300     WebProcess::singleton().send(Messages::WebProcessPool::ReportWebContentCPUTime(cpuTime, static_cast<uint64_t>(activityState)), 0);
301 }
302
303 void WebChromeClient::setToolbarsVisible(bool toolbarsAreVisible)
304 {
305     m_page.send(Messages::WebPageProxy::SetToolbarsAreVisible(toolbarsAreVisible));
306 }
307
308 bool WebChromeClient::toolbarsVisible()
309 {
310     API::InjectedBundle::PageUIClient::UIElementVisibility toolbarsVisibility = m_page.injectedBundleUIClient().toolbarsAreVisible(&m_page);
311     if (toolbarsVisibility != API::InjectedBundle::PageUIClient::UIElementVisibility::Unknown)
312         return toolbarsVisibility == API::InjectedBundle::PageUIClient::UIElementVisibility::Visible;
313     
314     bool toolbarsAreVisible = true;
315     if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetToolbarsAreVisible(), Messages::WebPageProxy::GetToolbarsAreVisible::Reply(toolbarsAreVisible), m_page.pageID()))
316         return true;
317
318     return toolbarsAreVisible;
319 }
320
321 void WebChromeClient::setStatusbarVisible(bool statusBarIsVisible)
322 {
323     m_page.send(Messages::WebPageProxy::SetStatusBarIsVisible(statusBarIsVisible));
324 }
325
326 bool WebChromeClient::statusbarVisible()
327 {
328     API::InjectedBundle::PageUIClient::UIElementVisibility statusbarVisibility = m_page.injectedBundleUIClient().statusBarIsVisible(&m_page);
329     if (statusbarVisibility != API::InjectedBundle::PageUIClient::UIElementVisibility::Unknown)
330         return statusbarVisibility == API::InjectedBundle::PageUIClient::UIElementVisibility::Visible;
331
332     bool statusBarIsVisible = true;
333     if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetStatusBarIsVisible(), Messages::WebPageProxy::GetStatusBarIsVisible::Reply(statusBarIsVisible), m_page.pageID()))
334         return true;
335
336     return statusBarIsVisible;
337 }
338
339 void WebChromeClient::setScrollbarsVisible(bool)
340 {
341     notImplemented();
342 }
343
344 bool WebChromeClient::scrollbarsVisible()
345 {
346     notImplemented();
347     return true;
348 }
349
350 void WebChromeClient::setMenubarVisible(bool menuBarVisible)
351 {
352     m_page.send(Messages::WebPageProxy::SetMenuBarIsVisible(menuBarVisible));
353 }
354
355 bool WebChromeClient::menubarVisible()
356 {
357     API::InjectedBundle::PageUIClient::UIElementVisibility menubarVisibility = m_page.injectedBundleUIClient().menuBarIsVisible(&m_page);
358     if (menubarVisibility != API::InjectedBundle::PageUIClient::UIElementVisibility::Unknown)
359         return menubarVisibility == API::InjectedBundle::PageUIClient::UIElementVisibility::Visible;
360     
361     bool menuBarIsVisible = true;
362     if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetMenuBarIsVisible(), Messages::WebPageProxy::GetMenuBarIsVisible::Reply(menuBarIsVisible), m_page.pageID()))
363         return true;
364
365     return menuBarIsVisible;
366 }
367
368 void WebChromeClient::setResizable(bool resizable)
369 {
370     m_page.send(Messages::WebPageProxy::SetIsResizable(resizable));
371 }
372
373 void WebChromeClient::addMessageToConsole(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceID)
374 {
375     // Notify the bundle client.
376     m_page.injectedBundleUIClient().willAddMessageToConsole(&m_page, source, level, message, lineNumber, columnNumber, sourceID);
377 }
378
379 bool WebChromeClient::canRunBeforeUnloadConfirmPanel()
380 {
381     return m_page.canRunBeforeUnloadConfirmPanel();
382 }
383
384 bool WebChromeClient::runBeforeUnloadConfirmPanel(const String& message, Frame& frame)
385 {
386     WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
387
388     bool shouldClose = false;
389
390     HangDetectionDisabler hangDetectionDisabler;
391
392     if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::RunBeforeUnloadConfirmPanel(webFrame->frameID(), SecurityOriginData::fromFrame(&frame), message), Messages::WebPageProxy::RunBeforeUnloadConfirmPanel::Reply(shouldClose), m_page.pageID(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend))
393         return false;
394
395     return shouldClose;
396 }
397
398 void WebChromeClient::closeWindowSoon()
399 {
400     // FIXME: This code assumes that the client will respond to a close page
401     // message by actually closing the page. Safari does this, but there is
402     // no guarantee that other applications will, which will leave this page
403     // half detached. This approach is an inherent limitation making parts of
404     // a close execute synchronously as part of window.close, but other parts
405     // later on.
406
407     m_page.corePage()->setGroupName(String());
408
409     if (WebFrame* frame = m_page.mainWebFrame()) {
410         if (Frame* coreFrame = frame->coreFrame())
411             coreFrame->loader().stopForUserCancel();
412     }
413
414     m_page.sendClose();
415 }
416
417 static bool shouldSuppressJavaScriptDialogs(Frame& frame)
418 {
419     if (frame.loader().opener() && frame.loader().stateMachine().isDisplayingInitialEmptyDocument() && frame.loader().provisionalDocumentLoader())
420         return true;
421
422     return false;
423 }
424
425 void WebChromeClient::runJavaScriptAlert(Frame& frame, const String& alertText)
426 {
427     if (shouldSuppressJavaScriptDialogs(frame))
428         return;
429
430     WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
431     ASSERT(webFrame);
432
433     // Notify the bundle client.
434     m_page.injectedBundleUIClient().willRunJavaScriptAlert(&m_page, alertText, webFrame);
435
436     HangDetectionDisabler hangDetectionDisabler;
437
438     WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::RunJavaScriptAlert(webFrame->frameID(), SecurityOriginData::fromFrame(&frame), alertText), Messages::WebPageProxy::RunJavaScriptAlert::Reply(), m_page.pageID(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend);
439 }
440
441 bool WebChromeClient::runJavaScriptConfirm(Frame& frame, const String& message)
442 {
443     if (shouldSuppressJavaScriptDialogs(frame))
444         return false;
445
446     WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
447     ASSERT(webFrame);
448
449     // Notify the bundle client.
450     m_page.injectedBundleUIClient().willRunJavaScriptConfirm(&m_page, message, webFrame);
451
452     HangDetectionDisabler hangDetectionDisabler;
453
454     bool result = false;
455     if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::RunJavaScriptConfirm(webFrame->frameID(), SecurityOriginData::fromFrame(&frame), message), Messages::WebPageProxy::RunJavaScriptConfirm::Reply(result), m_page.pageID(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend))
456         return false;
457
458     return result;
459 }
460
461 bool WebChromeClient::runJavaScriptPrompt(Frame& frame, const String& message, const String& defaultValue, String& result)
462 {
463     if (shouldSuppressJavaScriptDialogs(frame))
464         return false;
465
466     WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
467     ASSERT(webFrame);
468
469     // Notify the bundle client.
470     m_page.injectedBundleUIClient().willRunJavaScriptPrompt(&m_page, message, defaultValue, webFrame);
471
472     HangDetectionDisabler hangDetectionDisabler;
473
474     if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::RunJavaScriptPrompt(webFrame->frameID(), SecurityOriginData::fromFrame(&frame), message, defaultValue), Messages::WebPageProxy::RunJavaScriptPrompt::Reply(result), m_page.pageID(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend))
475         return false;
476
477     return !result.isNull();
478 }
479
480 void WebChromeClient::setStatusbarText(const String& statusbarText)
481 {
482     // Notify the bundle client.
483     m_page.injectedBundleUIClient().willSetStatusbarText(&m_page, statusbarText);
484
485     m_page.send(Messages::WebPageProxy::SetStatusText(statusbarText));
486 }
487
488 KeyboardUIMode WebChromeClient::keyboardUIMode()
489 {
490     return m_page.keyboardUIMode();
491 }
492
493 #if ENABLE(POINTER_LOCK)
494
495 bool WebChromeClient::requestPointerLock()
496 {
497     m_page.send(Messages::WebPageProxy::RequestPointerLock());
498     return true;
499 }
500
501 void WebChromeClient::requestPointerUnlock()
502 {
503     m_page.send(Messages::WebPageProxy::RequestPointerUnlock());
504 }
505
506 #endif
507
508 void WebChromeClient::invalidateRootView(const IntRect&)
509 {
510     // Do nothing here, there's no concept of invalidating the window in the web process.
511 }
512
513 void WebChromeClient::invalidateContentsAndRootView(const IntRect& rect)
514 {
515     if (Document* document = m_page.corePage()->mainFrame().document()) {
516         if (document->printing())
517             return;
518     }
519
520     m_page.drawingArea()->setNeedsDisplayInRect(rect);
521 }
522
523 void WebChromeClient::invalidateContentsForSlowScroll(const IntRect& rect)
524 {
525     if (Document* document = m_page.corePage()->mainFrame().document()) {
526         if (document->printing())
527             return;
528     }
529
530     m_page.pageDidScroll();
531 #if USE(COORDINATED_GRAPHICS)
532     FrameView* frameView = m_page.mainFrame()->view();
533     if (frameView && frameView->delegatesScrolling()) {
534         m_page.drawingArea()->scroll(rect, IntSize());
535         return;
536     }
537 #endif
538     m_page.drawingArea()->setNeedsDisplayInRect(rect);
539 }
540
541 void WebChromeClient::scroll(const IntSize& scrollDelta, const IntRect& scrollRect, const IntRect& clipRect)
542 {
543     m_page.pageDidScroll();
544     m_page.drawingArea()->scroll(intersection(scrollRect, clipRect), scrollDelta);
545 }
546
547 #if USE(COORDINATED_GRAPHICS)
548 void WebChromeClient::delegatedScrollRequested(const IntPoint& scrollOffset)
549 {
550     m_page.pageDidRequestScroll(scrollOffset);
551 }
552
553 void WebChromeClient::resetUpdateAtlasForTesting()
554 {
555     m_page.drawingArea()->resetUpdateAtlasForTesting();
556 }
557 #endif
558
559 IntPoint WebChromeClient::screenToRootView(const IntPoint& point) const
560 {
561     return m_page.screenToRootView(point);
562 }
563
564 IntRect WebChromeClient::rootViewToScreen(const IntRect& rect) const
565 {
566     return m_page.rootViewToScreen(rect);
567 }
568     
569 #if PLATFORM(IOS)
570 IntPoint WebChromeClient::accessibilityScreenToRootView(const IntPoint& point) const
571 {
572     return m_page.accessibilityScreenToRootView(point);
573 }
574
575 IntRect WebChromeClient::rootViewToAccessibilityScreen(const IntRect& rect) const
576 {
577     return m_page.rootViewToAccessibilityScreen(rect);
578 }
579 #endif
580
581 PlatformPageClient WebChromeClient::platformPageClient() const
582 {
583     notImplemented();
584     return 0;
585 }
586
587 void WebChromeClient::contentsSizeChanged(Frame& frame, const IntSize& size) const
588 {
589     FrameView* frameView = frame.view();
590
591     if (frameView && frameView->effectiveFrameFlattening() == FrameFlattening::Disabled) {
592         WebFrame* largestFrame = findLargestFrameInFrameSet(m_page);
593         if (largestFrame != m_cachedFrameSetLargestFrame.get()) {
594             m_cachedFrameSetLargestFrame = largestFrame;
595             m_page.send(Messages::WebPageProxy::FrameSetLargestFrameChanged(largestFrame ? largestFrame->frameID() : 0));
596         }
597     }
598
599     if (&frame.page()->mainFrame() != &frame)
600         return;
601
602     m_page.send(Messages::WebPageProxy::DidChangeContentSize(size));
603
604     m_page.drawingArea()->mainFrameContentSizeChanged(size);
605
606     if (frameView && !frameView->delegatesScrolling())  {
607         bool hasHorizontalScrollbar = frameView->horizontalScrollbar();
608         bool hasVerticalScrollbar = frameView->verticalScrollbar();
609
610         if (hasHorizontalScrollbar != m_cachedMainFrameHasHorizontalScrollbar || hasVerticalScrollbar != m_cachedMainFrameHasVerticalScrollbar) {
611             m_page.send(Messages::WebPageProxy::DidChangeScrollbarsForMainFrame(hasHorizontalScrollbar, hasVerticalScrollbar));
612
613             m_cachedMainFrameHasHorizontalScrollbar = hasHorizontalScrollbar;
614             m_cachedMainFrameHasVerticalScrollbar = hasVerticalScrollbar;
615         }
616     }
617 }
618
619 void WebChromeClient::scrollRectIntoView(const IntRect&) const
620 {
621     notImplemented();
622 }
623
624 bool WebChromeClient::shouldUnavailablePluginMessageBeButton(RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
625 {
626     switch (pluginUnavailabilityReason) {
627     case RenderEmbeddedObject::PluginMissing:
628         // FIXME: <rdar://problem/8794397> We should only return true when there is a
629         // missingPluginButtonClicked callback defined on the Page UI client.
630     case RenderEmbeddedObject::InsecurePluginVersion:
631         return true;
632
633
634     case RenderEmbeddedObject::PluginCrashed:
635     case RenderEmbeddedObject::PluginBlockedByContentSecurityPolicy:
636         return false;
637     }
638
639     ASSERT_NOT_REACHED();
640     return false;
641 }
642     
643 void WebChromeClient::unavailablePluginButtonClicked(Element& element, RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
644 {
645 #if ENABLE(NETSCAPE_PLUGIN_API)
646     ASSERT(element.hasTagName(objectTag) || element.hasTagName(embedTag) || element.hasTagName(appletTag));
647     ASSERT(pluginUnavailabilityReason == RenderEmbeddedObject::PluginMissing || pluginUnavailabilityReason == RenderEmbeddedObject::InsecurePluginVersion || pluginUnavailabilityReason);
648
649     auto& pluginElement = downcast<HTMLPlugInImageElement>(element);
650
651     String frameURLString = pluginElement.document().frame()->loader().documentLoader()->responseURL().string();
652     String pageURLString = m_page.mainFrame()->loader().documentLoader()->responseURL().string();
653     String pluginURLString = pluginElement.document().completeURL(pluginElement.url()).string();
654     URL pluginspageAttributeURL = pluginElement.document().completeURL(stripLeadingAndTrailingHTMLSpaces(pluginElement.attributeWithoutSynchronization(pluginspageAttr)));
655     if (!pluginspageAttributeURL.protocolIsInHTTPFamily())
656         pluginspageAttributeURL = URL();
657     m_page.send(Messages::WebPageProxy::UnavailablePluginButtonClicked(pluginUnavailabilityReason, pluginElement.serviceType(), pluginURLString, pluginspageAttributeURL.string(), frameURLString, pageURLString));
658 #else
659     UNUSED_PARAM(element);
660     UNUSED_PARAM(pluginUnavailabilityReason);
661 #endif // ENABLE(NETSCAPE_PLUGIN_API)
662 }
663
664 void WebChromeClient::mouseDidMoveOverElement(const HitTestResult& hitTestResult, unsigned modifierFlags)
665 {
666     RefPtr<API::Object> userData;
667
668     // Notify the bundle client.
669     m_page.injectedBundleUIClient().mouseDidMoveOverElement(&m_page, hitTestResult, static_cast<WebEvent::Modifiers>(modifierFlags), userData);
670
671     // Notify the UIProcess.
672     WebHitTestResultData webHitTestResultData(hitTestResult);
673     m_page.send(Messages::WebPageProxy::MouseDidMoveOverElement(webHitTestResultData, modifierFlags, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
674 }
675
676 void WebChromeClient::setToolTip(const String& toolTip, TextDirection)
677 {
678     // Only send a tool tip to the WebProcess if it has changed since the last time this function was called.
679
680     if (toolTip == m_cachedToolTip)
681         return;
682     m_cachedToolTip = toolTip;
683
684     m_page.send(Messages::WebPageProxy::SetToolTip(m_cachedToolTip));
685 }
686
687 void WebChromeClient::print(Frame& frame)
688 {
689     WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
690     ASSERT(webFrame);
691
692 #if PLATFORM(GTK) && HAVE(GTK_UNIX_PRINTING)
693     // When printing synchronously in GTK+ we need to make sure that we have a list of Printers before starting the print operation.
694     // Getting the list of printers is done synchronously by GTK+, but using a nested main loop that might process IPC messages
695     // comming from the UI process like EndPrinting. When the EndPriting message is received while the printer list is being populated,
696     // the print operation is finished unexpectely and the web process crashes, see https://bugs.webkit.org/show_bug.cgi?id=126979.
697     // The PrinterListGtk class gets the list of printers in the constructor so we just need to ensure there's an instance alive
698     // during the synchronous print operation.
699     RefPtr<PrinterListGtk> printerList = PrinterListGtk::getOrCreate();
700     if (!printerList) {
701         // PrinterListGtk::getOrCreate() returns nullptr when called while a printers enumeration is ongoing.
702         // This can happen if a synchronous print is started by a JavaScript and another one is inmeditaley started
703         // from a JavaScript event listener. The second print operation is handled by the nested main loop used by GTK+
704         // to enumerate the printers, and we end up here trying to get a reference of an object that is being constructed.
705         // It's very unlikely that the user wants to print twice in a row, and other browsers don't do two print operations
706         // in this particular case either. So, the safest solution is to return early here and ignore the second print.
707         // See https://bugs.webkit.org/show_bug.cgi?id=141035
708         return;
709     }
710 #endif
711
712     m_page.sendSync(Messages::WebPageProxy::PrintFrame(webFrame->frameID()), Messages::WebPageProxy::PrintFrame::Reply(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend);
713 }
714
715 void WebChromeClient::exceededDatabaseQuota(Frame& frame, const String& databaseName, DatabaseDetails details)
716 {
717     WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
718     ASSERT(webFrame);
719     
720     auto& origin = frame.document()->securityOrigin();
721     auto originData = SecurityOriginData::fromSecurityOrigin(origin);
722     auto& tracker = DatabaseTracker::singleton();
723     auto currentQuota = tracker.quota(originData);
724     auto currentOriginUsage = tracker.usage(originData);
725     uint64_t newQuota = 0;
726     RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(SecurityOriginData::fromDatabaseIdentifier(SecurityOriginData::fromSecurityOrigin(origin).databaseIdentifier())->securityOrigin());
727     newQuota = m_page.injectedBundleUIClient().didExceedDatabaseQuota(&m_page, securityOrigin.get(), databaseName, details.displayName(), currentQuota, currentOriginUsage, details.currentUsage(), details.expectedUsage());
728
729     if (!newQuota) {
730         WebProcess::singleton().parentProcessConnection()->sendSync(
731             Messages::WebPageProxy::ExceededDatabaseQuota(webFrame->frameID(), SecurityOriginData::fromSecurityOrigin(origin).databaseIdentifier(), databaseName, details.displayName(), currentQuota, currentOriginUsage, details.currentUsage(), details.expectedUsage()),
732             Messages::WebPageProxy::ExceededDatabaseQuota::Reply(newQuota), m_page.pageID(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend);
733     }
734
735     tracker.setQuota(originData, newQuota);
736 }
737
738 void WebChromeClient::reachedMaxAppCacheSize(int64_t)
739 {
740     notImplemented();
741 }
742
743 void WebChromeClient::reachedApplicationCacheOriginQuota(SecurityOrigin& origin, int64_t totalBytesNeeded)
744 {
745     RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::createFromString(origin.toString());
746     if (m_page.injectedBundleUIClient().didReachApplicationCacheOriginQuota(&m_page, securityOrigin.get(), totalBytesNeeded))
747         return;
748
749     auto& cacheStorage = m_page.corePage()->applicationCacheStorage();
750     int64_t currentQuota = 0;
751     if (!cacheStorage.calculateQuotaForOrigin(origin, currentQuota))
752         return;
753
754     uint64_t newQuota = 0;
755     WebProcess::singleton().parentProcessConnection()->sendSync(
756         Messages::WebPageProxy::ReachedApplicationCacheOriginQuota(SecurityOriginData::fromSecurityOrigin(origin).databaseIdentifier(), currentQuota, totalBytesNeeded),
757         Messages::WebPageProxy::ReachedApplicationCacheOriginQuota::Reply(newQuota), m_page.pageID(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend);
758
759     cacheStorage.storeUpdatedQuotaForOrigin(&origin, newQuota);
760 }
761
762 #if ENABLE(DASHBOARD_SUPPORT)
763
764 void WebChromeClient::annotatedRegionsChanged()
765 {
766     notImplemented();
767 }
768
769 #endif
770
771 bool WebChromeClient::shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename)
772 {
773     generatedFilename = m_page.injectedBundleUIClient().shouldGenerateFileForUpload(&m_page, path);
774     return !generatedFilename.isNull();
775 }
776
777 String WebChromeClient::generateReplacementFile(const String& path)
778 {
779     return m_page.injectedBundleUIClient().generateFileForUpload(&m_page, path);
780 }
781
782 #if ENABLE(INPUT_TYPE_COLOR)
783
784 std::unique_ptr<ColorChooser> WebChromeClient::createColorChooser(ColorChooserClient& client, const Color& initialColor)
785 {
786     return std::make_unique<WebColorChooser>(&m_page, &client, initialColor);
787 }
788
789 #endif
790
791 void WebChromeClient::runOpenPanel(Frame& frame, FileChooser& fileChooser)
792 {
793     if (m_page.activeOpenPanelResultListener())
794         return;
795
796     m_page.setActiveOpenPanelResultListener(WebOpenPanelResultListener::create(m_page, fileChooser));
797
798     auto* webFrame = WebFrame::fromCoreFrame(frame);
799     ASSERT(webFrame);
800     m_page.send(Messages::WebPageProxy::RunOpenPanel(webFrame->frameID(), SecurityOriginData::fromFrame(&frame), fileChooser.settings()));
801 }
802
803 void WebChromeClient::loadIconForFiles(const Vector<String>& filenames, FileIconLoader& loader)
804 {
805     loader.iconLoaded(createIconForFiles(filenames));
806 }
807
808 #if !PLATFORM(IOS)
809
810 void WebChromeClient::setCursor(const Cursor& cursor)
811 {
812     m_page.send(Messages::WebPageProxy::SetCursor(cursor));
813 }
814
815 void WebChromeClient::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
816 {
817     m_page.send(Messages::WebPageProxy::SetCursorHiddenUntilMouseMoves(hiddenUntilMouseMoves));
818 }
819
820 RefPtr<Icon> WebChromeClient::createIconForFiles(const Vector<String>& filenames)
821 {
822     return Icon::createIconForFiles(filenames);
823 }
824
825 #endif
826
827 void WebChromeClient::didAssociateFormControls(const Vector<RefPtr<Element>>& elements)
828 {
829     return m_page.injectedBundleFormClient().didAssociateFormControls(&m_page, elements);
830 }
831
832 bool WebChromeClient::shouldNotifyOnFormChanges()
833 {
834     return m_page.injectedBundleFormClient().shouldNotifyOnFormChanges(&m_page);
835 }
836
837 bool WebChromeClient::selectItemWritingDirectionIsNatural()
838 {
839     return false;
840 }
841
842 bool WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection()
843 {
844     return true;
845 }
846
847 RefPtr<PopupMenu> WebChromeClient::createPopupMenu(PopupMenuClient& client) const
848 {
849     return WebPopupMenu::create(&m_page, &client);
850 }
851
852 RefPtr<SearchPopupMenu> WebChromeClient::createSearchPopupMenu(PopupMenuClient& client) const
853 {
854     return WebSearchPopupMenu::create(&m_page, &client);
855 }
856
857 GraphicsLayerFactory* WebChromeClient::graphicsLayerFactory() const
858 {
859     if (auto drawingArea = m_page.drawingArea())
860         return drawingArea->graphicsLayerFactory();
861     return nullptr;
862 }
863
864 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
865
866 RefPtr<DisplayRefreshMonitor> WebChromeClient::createDisplayRefreshMonitor(PlatformDisplayID displayID) const
867 {
868     return m_page.drawingArea()->createDisplayRefreshMonitor(displayID);
869 }
870
871 #endif
872
873 void WebChromeClient::attachRootGraphicsLayer(Frame&, GraphicsLayer* layer)
874 {
875     if (layer)
876         m_page.enterAcceleratedCompositingMode(layer);
877     else
878         m_page.exitAcceleratedCompositingMode();
879 }
880
881 void WebChromeClient::attachViewOverlayGraphicsLayer(Frame& frame, GraphicsLayer* graphicsLayer)
882 {
883     if (auto drawingArea = m_page.drawingArea())
884         drawingArea->attachViewOverlayGraphicsLayer(&frame, graphicsLayer);
885 }
886
887 void WebChromeClient::setNeedsOneShotDrawingSynchronization()
888 {
889     notImplemented();
890 }
891
892 void WebChromeClient::scheduleCompositingLayerFlush()
893 {
894     if (m_page.drawingArea())
895         m_page.drawingArea()->scheduleCompositingLayerFlush();
896 }
897
898 void WebChromeClient::contentRuleListNotification(const URL& url, const HashSet<std::pair<String, String>>& notificationPairs)
899 {
900     Vector<String> identifiers;
901     Vector<String> notifications;
902     identifiers.reserveInitialCapacity(notificationPairs.size());
903     notifications.reserveInitialCapacity(notificationPairs.size());
904     for (auto& notification : notificationPairs) {
905         identifiers.uncheckedAppend(notification.first);
906         notifications.uncheckedAppend(notification.second);
907     }
908
909     m_page.send(Messages::WebPageProxy::ContentRuleListNotification(url, identifiers, notifications));
910 }
911
912 bool WebChromeClient::adjustLayerFlushThrottling(LayerFlushThrottleState::Flags flags)
913 {
914     return m_page.drawingArea() && m_page.drawingArea()->adjustLayerFlushThrottling(flags);
915 }
916
917 bool WebChromeClient::layerTreeStateIsFrozen() const
918 {
919     if (m_page.drawingArea())
920         return m_page.drawingArea()->layerTreeStateIsFrozen();
921
922     return false;
923 }
924
925 #if ENABLE(ASYNC_SCROLLING)
926
927 RefPtr<ScrollingCoordinator> WebChromeClient::createScrollingCoordinator(Page& page) const
928 {
929     ASSERT_UNUSED(page, m_page.corePage() == &page);
930     if (m_page.drawingArea()->type() != DrawingAreaTypeRemoteLayerTree)
931         return nullptr;
932     return RemoteScrollingCoordinator::create(&m_page);
933 }
934
935 #endif
936
937 #if (PLATFORM(IOS) && HAVE(AVKIT)) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
938
939 bool WebChromeClient::supportsVideoFullscreen(HTMLMediaElementEnums::VideoFullscreenMode mode)
940 {
941     return m_page.videoFullscreenManager().supportsVideoFullscreen(mode);
942 }
943
944 void WebChromeClient::setUpPlaybackControlsManager(HTMLMediaElement& mediaElement)
945 {
946     m_page.playbackSessionManager().setUpPlaybackControlsManager(mediaElement);
947 }
948
949 void WebChromeClient::clearPlaybackControlsManager()
950 {
951     m_page.playbackSessionManager().clearPlaybackControlsManager();
952 }
953
954 void WebChromeClient::enterVideoFullscreenForVideoElement(HTMLVideoElement& videoElement, HTMLMediaElementEnums::VideoFullscreenMode mode)
955 {
956     ASSERT(mode != HTMLMediaElementEnums::VideoFullscreenModeNone);
957     m_page.videoFullscreenManager().enterVideoFullscreenForVideoElement(videoElement, mode);
958 }
959
960 void WebChromeClient::exitVideoFullscreenForVideoElement(HTMLVideoElement& videoElement)
961 {
962     m_page.videoFullscreenManager().exitVideoFullscreenForVideoElement(videoElement);
963 }
964
965 #endif
966
967 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
968
969 void WebChromeClient::exitVideoFullscreenToModeWithoutAnimation(HTMLVideoElement& videoElement, HTMLMediaElementEnums::VideoFullscreenMode targetMode)
970 {
971     m_page.videoFullscreenManager().exitVideoFullscreenToModeWithoutAnimation(videoElement, targetMode);
972 }
973
974 #endif
975
976 #if ENABLE(FULLSCREEN_API)
977
978 bool WebChromeClient::supportsFullScreenForElement(const Element&, bool withKeyboard)
979 {
980     return m_page.fullScreenManager()->supportsFullScreen(withKeyboard);
981 }
982
983 void WebChromeClient::enterFullScreenForElement(Element& element)
984 {
985     m_page.fullScreenManager()->enterFullScreenForElement(&element);
986 }
987
988 void WebChromeClient::exitFullScreenForElement(Element* element)
989 {
990     m_page.fullScreenManager()->exitFullScreenForElement(element);
991 }
992
993 #endif
994
995 #if PLATFORM(IOS)
996
997 FloatSize WebChromeClient::screenSize() const
998 {
999     return m_page.screenSize();
1000 }
1001
1002 FloatSize WebChromeClient::availableScreenSize() const
1003 {
1004     return m_page.availableScreenSize();
1005 }
1006
1007 #endif
1008
1009 void WebChromeClient::dispatchViewportPropertiesDidChange(const ViewportArguments& viewportArguments) const
1010 {
1011     m_page.viewportPropertiesDidChange(viewportArguments);
1012 }
1013
1014 void WebChromeClient::notifyScrollerThumbIsVisibleInRect(const IntRect& scrollerThumb)
1015 {
1016     m_page.send(Messages::WebPageProxy::NotifyScrollerThumbIsVisibleInRect(scrollerThumb));
1017 }
1018
1019 void WebChromeClient::recommendedScrollbarStyleDidChange(ScrollbarStyle newStyle)
1020 {
1021     m_page.send(Messages::WebPageProxy::RecommendedScrollbarStyleDidChange(static_cast<int32_t>(newStyle)));
1022 }
1023
1024 std::optional<ScrollbarOverlayStyle> WebChromeClient::preferredScrollbarOverlayStyle()
1025 {
1026     return m_page.scrollbarOverlayStyle();
1027 }
1028
1029 Color WebChromeClient::underlayColor() const
1030 {
1031     return m_page.underlayColor();
1032 }
1033
1034 void WebChromeClient::pageExtendedBackgroundColorDidChange(Color backgroundColor) const
1035 {
1036 #if PLATFORM(MAC)
1037     m_page.send(Messages::WebPageProxy::PageExtendedBackgroundColorDidChange(backgroundColor));
1038 #else
1039     UNUSED_PARAM(backgroundColor);
1040 #endif
1041 }
1042
1043 void WebChromeClient::wheelEventHandlersChanged(bool hasHandlers)
1044 {
1045     m_page.wheelEventHandlersChanged(hasHandlers);
1046 }
1047
1048 String WebChromeClient::plugInStartLabelTitle(const String& mimeType) const
1049 {
1050     return m_page.injectedBundleUIClient().plugInStartLabelTitle(mimeType);
1051 }
1052
1053 String WebChromeClient::plugInStartLabelSubtitle(const String& mimeType) const
1054 {
1055     return m_page.injectedBundleUIClient().plugInStartLabelSubtitle(mimeType);
1056 }
1057
1058 String WebChromeClient::plugInExtraStyleSheet() const
1059 {
1060     return m_page.injectedBundleUIClient().plugInExtraStyleSheet();
1061 }
1062
1063 String WebChromeClient::plugInExtraScript() const
1064 {
1065     return m_page.injectedBundleUIClient().plugInExtraScript();
1066 }
1067
1068 void WebChromeClient::enableSuddenTermination()
1069 {
1070     m_page.send(Messages::WebProcessProxy::EnableSuddenTermination());
1071 }
1072
1073 void WebChromeClient::disableSuddenTermination()
1074 {
1075     m_page.send(Messages::WebProcessProxy::DisableSuddenTermination());
1076 }
1077
1078 void WebChromeClient::didAddHeaderLayer(GraphicsLayer& headerParent)
1079 {
1080 #if ENABLE(RUBBER_BANDING)
1081     if (PageBanner* banner = m_page.headerPageBanner())
1082         banner->didAddParentLayer(&headerParent);
1083 #else
1084     UNUSED_PARAM(headerParent);
1085 #endif
1086 }
1087
1088 void WebChromeClient::didAddFooterLayer(GraphicsLayer& footerParent)
1089 {
1090 #if ENABLE(RUBBER_BANDING)
1091     if (PageBanner* banner = m_page.footerPageBanner())
1092         banner->didAddParentLayer(&footerParent);
1093 #else
1094     UNUSED_PARAM(footerParent);
1095 #endif
1096 }
1097
1098 bool WebChromeClient::shouldUseTiledBackingForFrameView(const FrameView& frameView) const
1099 {
1100     return m_page.drawingArea()->shouldUseTiledBackingForFrameView(frameView);
1101 }
1102
1103 void WebChromeClient::isPlayingMediaDidChange(MediaProducer::MediaStateFlags state, uint64_t sourceElementID)
1104 {
1105     m_page.send(Messages::WebPageProxy::IsPlayingMediaDidChange(state, sourceElementID));
1106 }
1107
1108 void WebChromeClient::handleAutoplayEvent(AutoplayEvent event, OptionSet<AutoplayEventFlags> flags)
1109 {
1110     m_page.send(Messages::WebPageProxy::HandleAutoplayEvent(event, flags));
1111 }
1112
1113 #if ENABLE(MEDIA_SESSION)
1114
1115 void WebChromeClient::hasMediaSessionWithActiveMediaElementsDidChange(bool state)
1116 {
1117     m_page.send(Messages::WebPageProxy::HasMediaSessionWithActiveMediaElementsDidChange(state));
1118 }
1119
1120 void WebChromeClient::mediaSessionMetadataDidChange(const MediaSessionMetadata& metadata)
1121 {
1122     m_page.send(Messages::WebPageProxy::MediaSessionMetadataDidChange(metadata));
1123 }
1124
1125 void WebChromeClient::focusedContentMediaElementDidChange(uint64_t elementID)
1126 {
1127     m_page.send(Messages::WebPageProxy::FocusedContentMediaElementDidChange(elementID));
1128 }
1129
1130 #endif
1131
1132 #if ENABLE(SUBTLE_CRYPTO)
1133
1134 bool WebChromeClient::wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) const
1135 {
1136     bool succeeded;
1137     if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::WrapCryptoKey(key), Messages::WebPageProxy::WrapCryptoKey::Reply(succeeded, wrappedKey), m_page.pageID()))
1138         return false;
1139     return succeeded;
1140 }
1141
1142 bool WebChromeClient::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) const
1143 {
1144     bool succeeded;
1145     if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::UnwrapCryptoKey(wrappedKey), Messages::WebPageProxy::UnwrapCryptoKey::Reply(succeeded, key), m_page.pageID()))
1146         return false;
1147     return succeeded;
1148 }
1149
1150 #endif
1151
1152 #if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
1153
1154 void WebChromeClient::handleTelephoneNumberClick(const String& number, const IntPoint& point)
1155 {
1156     m_page.handleTelephoneNumberClick(number, point);
1157 }
1158
1159 #endif
1160
1161 #if ENABLE(SERVICE_CONTROLS)
1162
1163 void WebChromeClient::handleSelectionServiceClick(FrameSelection& selection, const Vector<String>& telephoneNumbers, const IntPoint& point)
1164 {
1165     m_page.handleSelectionServiceClick(selection, telephoneNumbers, point);
1166 }
1167
1168 bool WebChromeClient::hasRelevantSelectionServices(bool isTextOnly) const
1169 {
1170     return (isTextOnly && WebProcess::singleton().hasSelectionServices()) || WebProcess::singleton().hasRichContentServices();
1171 }
1172
1173 #endif
1174
1175 bool WebChromeClient::shouldDispatchFakeMouseMoveEvents() const
1176 {
1177     return m_page.shouldDispatchFakeMouseMoveEvents();
1178 }
1179
1180 void WebChromeClient::handleAutoFillButtonClick(HTMLInputElement& inputElement)
1181 {
1182     RefPtr<API::Object> userData;
1183
1184     // Notify the bundle client.
1185     auto nodeHandle = InjectedBundleNodeHandle::getOrCreate(inputElement);
1186     m_page.injectedBundleUIClient().didClickAutoFillButton(m_page, nodeHandle.get(), userData);
1187
1188     // Notify the UIProcess.
1189     m_page.send(Messages::WebPageProxy::HandleAutoFillButtonClick(UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
1190 }
1191
1192 void WebChromeClient::handleAlternativePresentationButtonClick(Node& node)
1193 {
1194     RefPtr<API::Object> userData;
1195
1196     // Notify the bundle client.
1197     auto nodeHandle = InjectedBundleNodeHandle::getOrCreate(node);
1198     m_page.injectedBundleUIClient().didClickAlternativePresentationButton(m_page, nodeHandle.get(), userData);
1199
1200     // Notify the UIProcess.
1201     m_page.send(Messages::WebPageProxy::HandleAlternativePresentationButtonClick(UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
1202 }
1203
1204 #if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
1205
1206 void WebChromeClient::addPlaybackTargetPickerClient(uint64_t contextId)
1207 {
1208     m_page.send(Messages::WebPageProxy::AddPlaybackTargetPickerClient(contextId));
1209 }
1210
1211 void WebChromeClient::removePlaybackTargetPickerClient(uint64_t contextId)
1212 {
1213     m_page.send(Messages::WebPageProxy::RemovePlaybackTargetPickerClient(contextId));
1214 }
1215
1216 void WebChromeClient::showPlaybackTargetPicker(uint64_t contextId, const IntPoint& position, bool isVideo)
1217 {
1218     FrameView* frameView = m_page.mainFrame()->view();
1219     FloatRect rect(frameView->contentsToRootView(frameView->windowToContents(position)), FloatSize());
1220     m_page.send(Messages::WebPageProxy::ShowPlaybackTargetPicker(contextId, rect, isVideo));
1221 }
1222
1223 void WebChromeClient::playbackTargetPickerClientStateDidChange(uint64_t contextId, MediaProducer::MediaStateFlags state)
1224 {
1225     m_page.send(Messages::WebPageProxy::PlaybackTargetPickerClientStateDidChange(contextId, state));
1226 }
1227
1228 void WebChromeClient::setMockMediaPlaybackTargetPickerEnabled(bool enabled)
1229 {
1230     m_page.send(Messages::WebPageProxy::SetMockMediaPlaybackTargetPickerEnabled(enabled));
1231 }
1232
1233 void WebChromeClient::setMockMediaPlaybackTargetPickerState(const String& name, MediaPlaybackTargetContext::State state)
1234 {
1235     m_page.send(Messages::WebPageProxy::SetMockMediaPlaybackTargetPickerState(name, state));
1236 }
1237
1238 #endif
1239
1240 void WebChromeClient::imageOrMediaDocumentSizeChanged(const IntSize& newSize)
1241 {
1242     m_page.imageOrMediaDocumentSizeChanged(newSize);
1243 }
1244
1245 #if ENABLE(VIDEO) && USE(GSTREAMER)
1246
1247 void WebChromeClient::requestInstallMissingMediaPlugins(const String& details, const String& description, MediaPlayerRequestInstallMissingPluginsCallback& callback)
1248 {
1249     m_page.requestInstallMissingMediaPlugins(details, description, callback);
1250 }
1251
1252 #endif
1253
1254 void WebChromeClient::didInvalidateDocumentMarkerRects()
1255 {
1256     m_page.findController().didInvalidateDocumentMarkerRects();
1257 }
1258
1259 void WebChromeClient::hasStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, WTF::CompletionHandler<void (bool)>&& callback)
1260 {
1261     m_page.hasStorageAccess(WTFMove(subFrameHost), WTFMove(topFrameHost), frameID, pageID, WTFMove(callback));
1262 }
1263
1264 void WebChromeClient::requestStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, WTF::CompletionHandler<void (bool)>&& callback)
1265 {
1266     m_page.requestStorageAccess(WTFMove(subFrameHost), WTFMove(topFrameHost), frameID, pageID, WTFMove(callback));
1267 }
1268
1269 } // namespace WebKit