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