Storage Access API: Make DocumentLoader::willSendRequest() and WebFrameLoaderClient...
[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 bool WebChromeClient::supportsVideoFullscreenStandby()
945 {
946     return m_page.videoFullscreenManager().supportsVideoFullscreenStandby();
947 }
948
949 void WebChromeClient::setUpPlaybackControlsManager(HTMLMediaElement& mediaElement)
950 {
951     m_page.playbackSessionManager().setUpPlaybackControlsManager(mediaElement);
952 }
953
954 void WebChromeClient::clearPlaybackControlsManager()
955 {
956     m_page.playbackSessionManager().clearPlaybackControlsManager();
957 }
958
959 void WebChromeClient::enterVideoFullscreenForVideoElement(HTMLVideoElement& videoElement, HTMLMediaElementEnums::VideoFullscreenMode mode, bool standby)
960 {
961 #if ENABLE(FULLSCREEN_API) && PLATFORM(IOS)
962     ASSERT(standby || mode != HTMLMediaElementEnums::VideoFullscreenModeNone);
963 #else
964     ASSERT(mode != HTMLMediaElementEnums::VideoFullscreenModeNone);
965 #endif
966     m_page.videoFullscreenManager().enterVideoFullscreenForVideoElement(videoElement, mode, standby);
967 }
968
969 void WebChromeClient::exitVideoFullscreenForVideoElement(HTMLVideoElement& videoElement)
970 {
971     m_page.videoFullscreenManager().exitVideoFullscreenForVideoElement(videoElement);
972 }
973
974 #endif
975
976 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
977
978 void WebChromeClient::exitVideoFullscreenToModeWithoutAnimation(HTMLVideoElement& videoElement, HTMLMediaElementEnums::VideoFullscreenMode targetMode)
979 {
980     m_page.videoFullscreenManager().exitVideoFullscreenToModeWithoutAnimation(videoElement, targetMode);
981 }
982
983 #endif
984
985 #if ENABLE(FULLSCREEN_API)
986
987 bool WebChromeClient::supportsFullScreenForElement(const Element&, bool withKeyboard)
988 {
989     return m_page.fullScreenManager()->supportsFullScreen(withKeyboard);
990 }
991
992 void WebChromeClient::enterFullScreenForElement(Element& element)
993 {
994     m_page.fullScreenManager()->enterFullScreenForElement(&element);
995 }
996
997 void WebChromeClient::exitFullScreenForElement(Element* element)
998 {
999     m_page.fullScreenManager()->exitFullScreenForElement(element);
1000 }
1001
1002 #endif
1003
1004 #if PLATFORM(IOS)
1005
1006 FloatSize WebChromeClient::screenSize() const
1007 {
1008     return m_page.screenSize();
1009 }
1010
1011 FloatSize WebChromeClient::availableScreenSize() const
1012 {
1013     return m_page.availableScreenSize();
1014 }
1015
1016 #endif
1017
1018 void WebChromeClient::dispatchViewportPropertiesDidChange(const ViewportArguments& viewportArguments) const
1019 {
1020     m_page.viewportPropertiesDidChange(viewportArguments);
1021 }
1022
1023 void WebChromeClient::notifyScrollerThumbIsVisibleInRect(const IntRect& scrollerThumb)
1024 {
1025     m_page.send(Messages::WebPageProxy::NotifyScrollerThumbIsVisibleInRect(scrollerThumb));
1026 }
1027
1028 void WebChromeClient::recommendedScrollbarStyleDidChange(ScrollbarStyle newStyle)
1029 {
1030     m_page.send(Messages::WebPageProxy::RecommendedScrollbarStyleDidChange(static_cast<int32_t>(newStyle)));
1031 }
1032
1033 std::optional<ScrollbarOverlayStyle> WebChromeClient::preferredScrollbarOverlayStyle()
1034 {
1035     return m_page.scrollbarOverlayStyle();
1036 }
1037
1038 Color WebChromeClient::underlayColor() const
1039 {
1040     return m_page.underlayColor();
1041 }
1042
1043 void WebChromeClient::pageExtendedBackgroundColorDidChange(Color backgroundColor) const
1044 {
1045 #if PLATFORM(MAC)
1046     m_page.send(Messages::WebPageProxy::PageExtendedBackgroundColorDidChange(backgroundColor));
1047 #else
1048     UNUSED_PARAM(backgroundColor);
1049 #endif
1050 }
1051
1052 void WebChromeClient::wheelEventHandlersChanged(bool hasHandlers)
1053 {
1054     m_page.wheelEventHandlersChanged(hasHandlers);
1055 }
1056
1057 String WebChromeClient::plugInStartLabelTitle(const String& mimeType) const
1058 {
1059     return m_page.injectedBundleUIClient().plugInStartLabelTitle(mimeType);
1060 }
1061
1062 String WebChromeClient::plugInStartLabelSubtitle(const String& mimeType) const
1063 {
1064     return m_page.injectedBundleUIClient().plugInStartLabelSubtitle(mimeType);
1065 }
1066
1067 String WebChromeClient::plugInExtraStyleSheet() const
1068 {
1069     return m_page.injectedBundleUIClient().plugInExtraStyleSheet();
1070 }
1071
1072 String WebChromeClient::plugInExtraScript() const
1073 {
1074     return m_page.injectedBundleUIClient().plugInExtraScript();
1075 }
1076
1077 void WebChromeClient::enableSuddenTermination()
1078 {
1079     m_page.send(Messages::WebProcessProxy::EnableSuddenTermination());
1080 }
1081
1082 void WebChromeClient::disableSuddenTermination()
1083 {
1084     m_page.send(Messages::WebProcessProxy::DisableSuddenTermination());
1085 }
1086
1087 void WebChromeClient::didAddHeaderLayer(GraphicsLayer& headerParent)
1088 {
1089 #if ENABLE(RUBBER_BANDING)
1090     if (PageBanner* banner = m_page.headerPageBanner())
1091         banner->didAddParentLayer(&headerParent);
1092 #else
1093     UNUSED_PARAM(headerParent);
1094 #endif
1095 }
1096
1097 void WebChromeClient::didAddFooterLayer(GraphicsLayer& footerParent)
1098 {
1099 #if ENABLE(RUBBER_BANDING)
1100     if (PageBanner* banner = m_page.footerPageBanner())
1101         banner->didAddParentLayer(&footerParent);
1102 #else
1103     UNUSED_PARAM(footerParent);
1104 #endif
1105 }
1106
1107 bool WebChromeClient::shouldUseTiledBackingForFrameView(const FrameView& frameView) const
1108 {
1109     return m_page.drawingArea()->shouldUseTiledBackingForFrameView(frameView);
1110 }
1111
1112 void WebChromeClient::isPlayingMediaDidChange(MediaProducer::MediaStateFlags state, uint64_t sourceElementID)
1113 {
1114     m_page.send(Messages::WebPageProxy::IsPlayingMediaDidChange(state, sourceElementID));
1115 }
1116
1117 void WebChromeClient::handleAutoplayEvent(AutoplayEvent event, OptionSet<AutoplayEventFlags> flags)
1118 {
1119     m_page.send(Messages::WebPageProxy::HandleAutoplayEvent(event, flags));
1120 }
1121
1122 #if ENABLE(MEDIA_SESSION)
1123
1124 void WebChromeClient::hasMediaSessionWithActiveMediaElementsDidChange(bool state)
1125 {
1126     m_page.send(Messages::WebPageProxy::HasMediaSessionWithActiveMediaElementsDidChange(state));
1127 }
1128
1129 void WebChromeClient::mediaSessionMetadataDidChange(const MediaSessionMetadata& metadata)
1130 {
1131     m_page.send(Messages::WebPageProxy::MediaSessionMetadataDidChange(metadata));
1132 }
1133
1134 void WebChromeClient::focusedContentMediaElementDidChange(uint64_t elementID)
1135 {
1136     m_page.send(Messages::WebPageProxy::FocusedContentMediaElementDidChange(elementID));
1137 }
1138
1139 #endif
1140
1141 #if ENABLE(SUBTLE_CRYPTO)
1142
1143 bool WebChromeClient::wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) const
1144 {
1145     bool succeeded;
1146     if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::WrapCryptoKey(key), Messages::WebPageProxy::WrapCryptoKey::Reply(succeeded, wrappedKey), m_page.pageID()))
1147         return false;
1148     return succeeded;
1149 }
1150
1151 bool WebChromeClient::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) const
1152 {
1153     bool succeeded;
1154     if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::UnwrapCryptoKey(wrappedKey), Messages::WebPageProxy::UnwrapCryptoKey::Reply(succeeded, key), m_page.pageID()))
1155         return false;
1156     return succeeded;
1157 }
1158
1159 #endif
1160
1161 #if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
1162
1163 void WebChromeClient::handleTelephoneNumberClick(const String& number, const IntPoint& point)
1164 {
1165     m_page.handleTelephoneNumberClick(number, point);
1166 }
1167
1168 #endif
1169
1170 #if ENABLE(SERVICE_CONTROLS)
1171
1172 void WebChromeClient::handleSelectionServiceClick(FrameSelection& selection, const Vector<String>& telephoneNumbers, const IntPoint& point)
1173 {
1174     m_page.handleSelectionServiceClick(selection, telephoneNumbers, point);
1175 }
1176
1177 bool WebChromeClient::hasRelevantSelectionServices(bool isTextOnly) const
1178 {
1179     return (isTextOnly && WebProcess::singleton().hasSelectionServices()) || WebProcess::singleton().hasRichContentServices();
1180 }
1181
1182 #endif
1183
1184 bool WebChromeClient::shouldDispatchFakeMouseMoveEvents() const
1185 {
1186     return m_page.shouldDispatchFakeMouseMoveEvents();
1187 }
1188
1189 void WebChromeClient::handleAutoFillButtonClick(HTMLInputElement& inputElement)
1190 {
1191     RefPtr<API::Object> userData;
1192
1193     // Notify the bundle client.
1194     auto nodeHandle = InjectedBundleNodeHandle::getOrCreate(inputElement);
1195     m_page.injectedBundleUIClient().didClickAutoFillButton(m_page, nodeHandle.get(), userData);
1196
1197     // Notify the UIProcess.
1198     m_page.send(Messages::WebPageProxy::HandleAutoFillButtonClick(UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
1199 }
1200
1201 #if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
1202
1203 void WebChromeClient::addPlaybackTargetPickerClient(uint64_t contextId)
1204 {
1205     m_page.send(Messages::WebPageProxy::AddPlaybackTargetPickerClient(contextId));
1206 }
1207
1208 void WebChromeClient::removePlaybackTargetPickerClient(uint64_t contextId)
1209 {
1210     m_page.send(Messages::WebPageProxy::RemovePlaybackTargetPickerClient(contextId));
1211 }
1212
1213 void WebChromeClient::showPlaybackTargetPicker(uint64_t contextId, const IntPoint& position, bool isVideo)
1214 {
1215     FrameView* frameView = m_page.mainFrame()->view();
1216     FloatRect rect(frameView->contentsToRootView(frameView->windowToContents(position)), FloatSize());
1217     m_page.send(Messages::WebPageProxy::ShowPlaybackTargetPicker(contextId, rect, isVideo));
1218 }
1219
1220 void WebChromeClient::playbackTargetPickerClientStateDidChange(uint64_t contextId, MediaProducer::MediaStateFlags state)
1221 {
1222     m_page.send(Messages::WebPageProxy::PlaybackTargetPickerClientStateDidChange(contextId, state));
1223 }
1224
1225 void WebChromeClient::setMockMediaPlaybackTargetPickerEnabled(bool enabled)
1226 {
1227     m_page.send(Messages::WebPageProxy::SetMockMediaPlaybackTargetPickerEnabled(enabled));
1228 }
1229
1230 void WebChromeClient::setMockMediaPlaybackTargetPickerState(const String& name, MediaPlaybackTargetContext::State state)
1231 {
1232     m_page.send(Messages::WebPageProxy::SetMockMediaPlaybackTargetPickerState(name, state));
1233 }
1234
1235 #endif
1236
1237 void WebChromeClient::imageOrMediaDocumentSizeChanged(const IntSize& newSize)
1238 {
1239     m_page.imageOrMediaDocumentSizeChanged(newSize);
1240 }
1241
1242 #if ENABLE(VIDEO) && USE(GSTREAMER)
1243
1244 void WebChromeClient::requestInstallMissingMediaPlugins(const String& details, const String& description, MediaPlayerRequestInstallMissingPluginsCallback& callback)
1245 {
1246     m_page.requestInstallMissingMediaPlugins(details, description, callback);
1247 }
1248
1249 #endif
1250
1251 void WebChromeClient::didInvalidateDocumentMarkerRects()
1252 {
1253     m_page.findController().didInvalidateDocumentMarkerRects();
1254 }
1255
1256 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
1257 void WebChromeClient::hasStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, WTF::CompletionHandler<void (bool)>&& callback)
1258 {
1259     m_page.hasStorageAccess(WTFMove(subFrameHost), WTFMove(topFrameHost), frameID, pageID, WTFMove(callback));
1260 }
1261
1262 void WebChromeClient::requestStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, WTF::CompletionHandler<void (bool)>&& callback)
1263 {
1264     m_page.requestStorageAccess(WTFMove(subFrameHost), WTFMove(topFrameHost), frameID, pageID, WTFMove(callback));
1265 }
1266 #endif
1267
1268 } // namespace WebKit