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