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