2 * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
28 #include "WebChromeClient.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"
41 #include "WebColorChooser.h"
42 #include "WebCoreArgumentCoders.h"
44 #include "WebFrameLoaderClient.h"
45 #include "WebFullScreenManager.h"
46 #include "WebHitTestResultData.h"
48 #include "WebOpenPanelResultListener.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>
80 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
81 #include "PlaybackSessionManager.h"
82 #include "VideoFullscreenManager.h"
85 #if ENABLE(ASYNC_SCROLLING)
86 #include "RemoteScrollingCoordinator.h"
90 #include "PrinterListGtk.h"
93 using namespace WebCore;
94 using namespace HTMLNames;
98 static double area(WebFrame* frame)
100 IntSize size = frame->visibleContentBoundsExcludingScrollbars().size();
101 return static_cast<double>(size.height()) * size.width();
104 static WebFrame* findLargestFrameInFrameSet(WebPage& page)
106 // Approximate what a user could consider a default target frame for application menu operations.
108 WebFrame* mainFrame = page.mainWebFrame();
109 if (!mainFrame || !mainFrame->isFrameSet())
112 WebFrame* largestSoFar = nullptr;
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;
125 WebChromeClient::WebChromeClient(WebPage& page)
130 void WebChromeClient::didInsertMenuElement(HTMLMenuElement& element)
132 m_page.didInsertMenuElement(element);
135 void WebChromeClient::didRemoveMenuElement(HTMLMenuElement& element)
137 m_page.didRemoveMenuElement(element);
140 void WebChromeClient::didInsertMenuItemElement(HTMLMenuItemElement& element)
142 m_page.didInsertMenuItemElement(element);
145 void WebChromeClient::didRemoveMenuItemElement(HTMLMenuItemElement& element)
147 m_page.didRemoveMenuItemElement(element);
150 inline WebChromeClient::~WebChromeClient()
154 void WebChromeClient::chromeDestroyed()
159 void WebChromeClient::setWindowRect(const FloatRect& windowFrame)
161 m_page.sendSetWindowFrame(windowFrame);
164 FloatRect WebChromeClient::windowRect()
170 if (m_page.hasCachedWindowFrame())
171 return m_page.windowFrameInUnflippedScreenCoordinates();
174 FloatRect newWindowFrame;
176 if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetWindowFrame(), Messages::WebPageProxy::GetWindowFrame::Reply(newWindowFrame), m_page.pageID()))
179 return newWindowFrame;
183 FloatRect WebChromeClient::pageRect()
185 return FloatRect(FloatPoint(), m_page.size());
188 void WebChromeClient::focus()
190 m_page.send(Messages::WebPageProxy::SetFocus(true));
193 void WebChromeClient::unfocus()
195 m_page.send(Messages::WebPageProxy::SetFocus(false));
200 void WebChromeClient::elementDidFocus(Element& element)
202 m_page.elementDidFocus(&element);
205 void WebChromeClient::elementDidBlur(Element& element)
207 m_page.elementDidBlur(&element);
210 void WebChromeClient::makeFirstResponder()
212 m_page.send(Messages::WebPageProxy::MakeFirstResponder());
217 bool WebChromeClient::canTakeFocus(FocusDirection)
223 void WebChromeClient::takeFocus(FocusDirection direction)
225 m_page.send(Messages::WebPageProxy::TakeFocus(direction));
228 void WebChromeClient::focusedElementChanged(Element* element)
230 if (!is<HTMLInputElement>(element))
233 HTMLInputElement& inputElement = downcast<HTMLInputElement>(*element);
234 if (!inputElement.isText())
237 WebFrame* webFrame = WebFrame::fromCoreFrame(*element->document().frame());
239 m_page.injectedBundleFormClient().didFocusTextField(&m_page, &inputElement, webFrame);
242 void WebChromeClient::focusedFrameChanged(Frame* frame)
244 WebFrame* webFrame = frame ? WebFrame::fromCoreFrame(*frame) : nullptr;
246 WebProcess::singleton().parentProcessConnection()->send(Messages::WebPageProxy::FocusedFrameChanged(webFrame ? webFrame->frameID() : 0), m_page.pageID());
249 Page* WebChromeClient::createWindow(Frame& frame, const FrameLoadRequest& request, const WindowFeatures& windowFeatures, const NavigationAction& navigationAction)
251 #if ENABLE(FULLSCREEN_API)
252 if (frame.document() && frame.document()->webkitCurrentFullScreenElement())
253 frame.document()->webkitCancelFullScreen();
256 auto& webProcess = WebProcess::singleton();
258 NavigationActionData navigationActionData;
259 navigationActionData.navigationType = navigationAction.type();
260 navigationActionData.modifiers = InjectedBundleNavigationAction::modifiersForNavigationAction(navigationAction);
261 navigationActionData.mouseButton = InjectedBundleNavigationAction::mouseButtonForNavigationAction(navigationAction);
262 navigationActionData.syntheticClickType = InjectedBundleNavigationAction::syntheticClickTypeForNavigationAction(navigationAction);
263 navigationActionData.clickLocationInRootViewCoordinates = InjectedBundleNavigationAction::clickLocationInRootViewCoordinatesForNavigationAction(navigationAction);
264 navigationActionData.userGestureTokenIdentifier = webProcess.userGestureTokenIdentifier(navigationAction.userGestureToken());
265 navigationActionData.canHandleRequest = m_page.canHandleRequest(request.resourceRequest());
266 navigationActionData.shouldOpenExternalURLsPolicy = navigationAction.shouldOpenExternalURLsPolicy();
267 navigationActionData.downloadAttribute = navigationAction.downloadAttribute();
269 WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
271 uint64_t newPageID = 0;
272 WebPageCreationParameters parameters;
273 if (!webProcess.parentProcessConnection()->sendSync(Messages::WebPageProxy::CreateNewPage(webFrame->info(), webFrame->page()->pageID(), request.resourceRequest(), windowFeatures, navigationActionData), Messages::WebPageProxy::CreateNewPage::Reply(newPageID, parameters), m_page.pageID()))
279 webProcess.createWebPage(newPageID, WTFMove(parameters));
280 return webProcess.webPage(newPageID)->corePage();
283 void WebChromeClient::show()
288 bool WebChromeClient::canRunModal()
290 return m_page.canRunModal();
293 void WebChromeClient::runModal()
298 void WebChromeClient::reportProcessCPUTime(Seconds cpuTime, ActivityStateForCPUSampling activityState)
300 WebProcess::singleton().send(Messages::WebProcessPool::ReportWebContentCPUTime(cpuTime, static_cast<uint64_t>(activityState)), 0);
303 void WebChromeClient::setToolbarsVisible(bool toolbarsAreVisible)
305 m_page.send(Messages::WebPageProxy::SetToolbarsAreVisible(toolbarsAreVisible));
308 bool WebChromeClient::toolbarsVisible()
310 API::InjectedBundle::PageUIClient::UIElementVisibility toolbarsVisibility = m_page.injectedBundleUIClient().toolbarsAreVisible(&m_page);
311 if (toolbarsVisibility != API::InjectedBundle::PageUIClient::UIElementVisibility::Unknown)
312 return toolbarsVisibility == API::InjectedBundle::PageUIClient::UIElementVisibility::Visible;
314 bool toolbarsAreVisible = true;
315 if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetToolbarsAreVisible(), Messages::WebPageProxy::GetToolbarsAreVisible::Reply(toolbarsAreVisible), m_page.pageID()))
318 return toolbarsAreVisible;
321 void WebChromeClient::setStatusbarVisible(bool statusBarIsVisible)
323 m_page.send(Messages::WebPageProxy::SetStatusBarIsVisible(statusBarIsVisible));
326 bool WebChromeClient::statusbarVisible()
328 API::InjectedBundle::PageUIClient::UIElementVisibility statusbarVisibility = m_page.injectedBundleUIClient().statusBarIsVisible(&m_page);
329 if (statusbarVisibility != API::InjectedBundle::PageUIClient::UIElementVisibility::Unknown)
330 return statusbarVisibility == API::InjectedBundle::PageUIClient::UIElementVisibility::Visible;
332 bool statusBarIsVisible = true;
333 if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetStatusBarIsVisible(), Messages::WebPageProxy::GetStatusBarIsVisible::Reply(statusBarIsVisible), m_page.pageID()))
336 return statusBarIsVisible;
339 void WebChromeClient::setScrollbarsVisible(bool)
344 bool WebChromeClient::scrollbarsVisible()
350 void WebChromeClient::setMenubarVisible(bool menuBarVisible)
352 m_page.send(Messages::WebPageProxy::SetMenuBarIsVisible(menuBarVisible));
355 bool WebChromeClient::menubarVisible()
357 API::InjectedBundle::PageUIClient::UIElementVisibility menubarVisibility = m_page.injectedBundleUIClient().menuBarIsVisible(&m_page);
358 if (menubarVisibility != API::InjectedBundle::PageUIClient::UIElementVisibility::Unknown)
359 return menubarVisibility == API::InjectedBundle::PageUIClient::UIElementVisibility::Visible;
361 bool menuBarIsVisible = true;
362 if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetMenuBarIsVisible(), Messages::WebPageProxy::GetMenuBarIsVisible::Reply(menuBarIsVisible), m_page.pageID()))
365 return menuBarIsVisible;
368 void WebChromeClient::setResizable(bool resizable)
370 m_page.send(Messages::WebPageProxy::SetIsResizable(resizable));
373 void WebChromeClient::addMessageToConsole(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceID)
375 // Notify the bundle client.
376 m_page.injectedBundleUIClient().willAddMessageToConsole(&m_page, source, level, message, lineNumber, columnNumber, sourceID);
379 bool WebChromeClient::canRunBeforeUnloadConfirmPanel()
381 return m_page.canRunBeforeUnloadConfirmPanel();
384 bool WebChromeClient::runBeforeUnloadConfirmPanel(const String& message, Frame& frame)
386 WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
388 bool shouldClose = false;
390 HangDetectionDisabler hangDetectionDisabler;
392 if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::RunBeforeUnloadConfirmPanel(webFrame->frameID(), SecurityOriginData::fromFrame(&frame), message), Messages::WebPageProxy::RunBeforeUnloadConfirmPanel::Reply(shouldClose), m_page.pageID(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend))
398 void WebChromeClient::closeWindowSoon()
400 // FIXME: This code assumes that the client will respond to a close page
401 // message by actually closing the page. Safari does this, but there is
402 // no guarantee that other applications will, which will leave this page
403 // half detached. This approach is an inherent limitation making parts of
404 // a close execute synchronously as part of window.close, but other parts
407 m_page.corePage()->setGroupName(String());
409 if (WebFrame* frame = m_page.mainWebFrame()) {
410 if (Frame* coreFrame = frame->coreFrame())
411 coreFrame->loader().stopForUserCancel();
417 static bool shouldSuppressJavaScriptDialogs(Frame& frame)
419 if (frame.loader().opener() && frame.loader().stateMachine().isDisplayingInitialEmptyDocument() && frame.loader().provisionalDocumentLoader())
425 void WebChromeClient::runJavaScriptAlert(Frame& frame, const String& alertText)
427 if (shouldSuppressJavaScriptDialogs(frame))
430 WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
433 // Notify the bundle client.
434 m_page.injectedBundleUIClient().willRunJavaScriptAlert(&m_page, alertText, webFrame);
436 HangDetectionDisabler hangDetectionDisabler;
438 WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::RunJavaScriptAlert(webFrame->frameID(), SecurityOriginData::fromFrame(&frame), alertText), Messages::WebPageProxy::RunJavaScriptAlert::Reply(), m_page.pageID(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend);
441 bool WebChromeClient::runJavaScriptConfirm(Frame& frame, const String& message)
443 if (shouldSuppressJavaScriptDialogs(frame))
446 WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
449 // Notify the bundle client.
450 m_page.injectedBundleUIClient().willRunJavaScriptConfirm(&m_page, message, webFrame);
452 HangDetectionDisabler hangDetectionDisabler;
455 if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::RunJavaScriptConfirm(webFrame->frameID(), SecurityOriginData::fromFrame(&frame), message), Messages::WebPageProxy::RunJavaScriptConfirm::Reply(result), m_page.pageID(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend))
461 bool WebChromeClient::runJavaScriptPrompt(Frame& frame, const String& message, const String& defaultValue, String& result)
463 if (shouldSuppressJavaScriptDialogs(frame))
466 WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
469 // Notify the bundle client.
470 m_page.injectedBundleUIClient().willRunJavaScriptPrompt(&m_page, message, defaultValue, webFrame);
472 HangDetectionDisabler hangDetectionDisabler;
474 if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::RunJavaScriptPrompt(webFrame->frameID(), SecurityOriginData::fromFrame(&frame), message, defaultValue), Messages::WebPageProxy::RunJavaScriptPrompt::Reply(result), m_page.pageID(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend))
477 return !result.isNull();
480 void WebChromeClient::setStatusbarText(const String& statusbarText)
482 // Notify the bundle client.
483 m_page.injectedBundleUIClient().willSetStatusbarText(&m_page, statusbarText);
485 m_page.send(Messages::WebPageProxy::SetStatusText(statusbarText));
488 KeyboardUIMode WebChromeClient::keyboardUIMode()
490 return m_page.keyboardUIMode();
493 #if ENABLE(POINTER_LOCK)
495 bool WebChromeClient::requestPointerLock()
497 m_page.send(Messages::WebPageProxy::RequestPointerLock());
501 void WebChromeClient::requestPointerUnlock()
503 m_page.send(Messages::WebPageProxy::RequestPointerUnlock());
508 void WebChromeClient::invalidateRootView(const IntRect&)
510 // Do nothing here, there's no concept of invalidating the window in the web process.
513 void WebChromeClient::invalidateContentsAndRootView(const IntRect& rect)
515 if (Document* document = m_page.corePage()->mainFrame().document()) {
516 if (document->printing())
520 m_page.drawingArea()->setNeedsDisplayInRect(rect);
523 void WebChromeClient::invalidateContentsForSlowScroll(const IntRect& rect)
525 if (Document* document = m_page.corePage()->mainFrame().document()) {
526 if (document->printing())
530 m_page.pageDidScroll();
531 #if USE(COORDINATED_GRAPHICS)
532 FrameView* frameView = m_page.mainFrame()->view();
533 if (frameView && frameView->delegatesScrolling()) {
534 m_page.drawingArea()->scroll(rect, IntSize());
538 m_page.drawingArea()->setNeedsDisplayInRect(rect);
541 void WebChromeClient::scroll(const IntSize& scrollDelta, const IntRect& scrollRect, const IntRect& clipRect)
543 m_page.pageDidScroll();
544 m_page.drawingArea()->scroll(intersection(scrollRect, clipRect), scrollDelta);
547 #if USE(COORDINATED_GRAPHICS)
548 void WebChromeClient::delegatedScrollRequested(const IntPoint& scrollOffset)
550 m_page.pageDidRequestScroll(scrollOffset);
553 void WebChromeClient::resetUpdateAtlasForTesting()
555 m_page.drawingArea()->resetUpdateAtlasForTesting();
559 IntPoint WebChromeClient::screenToRootView(const IntPoint& point) const
561 return m_page.screenToRootView(point);
564 IntRect WebChromeClient::rootViewToScreen(const IntRect& rect) const
566 return m_page.rootViewToScreen(rect);
570 IntPoint WebChromeClient::accessibilityScreenToRootView(const IntPoint& point) const
572 return m_page.accessibilityScreenToRootView(point);
575 IntRect WebChromeClient::rootViewToAccessibilityScreen(const IntRect& rect) const
577 return m_page.rootViewToAccessibilityScreen(rect);
581 PlatformPageClient WebChromeClient::platformPageClient() const
587 void WebChromeClient::contentsSizeChanged(Frame& frame, const IntSize& size) const
589 FrameView* frameView = frame.view();
591 if (frameView && frameView->effectiveFrameFlattening() == FrameFlattening::Disabled) {
592 WebFrame* largestFrame = findLargestFrameInFrameSet(m_page);
593 if (largestFrame != m_cachedFrameSetLargestFrame.get()) {
594 m_cachedFrameSetLargestFrame = largestFrame;
595 m_page.send(Messages::WebPageProxy::FrameSetLargestFrameChanged(largestFrame ? largestFrame->frameID() : 0));
599 if (&frame.page()->mainFrame() != &frame)
602 m_page.send(Messages::WebPageProxy::DidChangeContentSize(size));
604 m_page.drawingArea()->mainFrameContentSizeChanged(size);
606 if (frameView && !frameView->delegatesScrolling()) {
607 bool hasHorizontalScrollbar = frameView->horizontalScrollbar();
608 bool hasVerticalScrollbar = frameView->verticalScrollbar();
610 if (hasHorizontalScrollbar != m_cachedMainFrameHasHorizontalScrollbar || hasVerticalScrollbar != m_cachedMainFrameHasVerticalScrollbar) {
611 m_page.send(Messages::WebPageProxy::DidChangeScrollbarsForMainFrame(hasHorizontalScrollbar, hasVerticalScrollbar));
613 m_cachedMainFrameHasHorizontalScrollbar = hasHorizontalScrollbar;
614 m_cachedMainFrameHasVerticalScrollbar = hasVerticalScrollbar;
619 void WebChromeClient::scrollRectIntoView(const IntRect&) const
624 bool WebChromeClient::shouldUnavailablePluginMessageBeButton(RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
626 switch (pluginUnavailabilityReason) {
627 case RenderEmbeddedObject::PluginMissing:
628 // FIXME: <rdar://problem/8794397> We should only return true when there is a
629 // missingPluginButtonClicked callback defined on the Page UI client.
630 case RenderEmbeddedObject::InsecurePluginVersion:
634 case RenderEmbeddedObject::PluginCrashed:
635 case RenderEmbeddedObject::PluginBlockedByContentSecurityPolicy:
639 ASSERT_NOT_REACHED();
643 void WebChromeClient::unavailablePluginButtonClicked(Element& element, RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
645 #if ENABLE(NETSCAPE_PLUGIN_API)
646 ASSERT(element.hasTagName(objectTag) || element.hasTagName(embedTag) || element.hasTagName(appletTag));
647 ASSERT(pluginUnavailabilityReason == RenderEmbeddedObject::PluginMissing || pluginUnavailabilityReason == RenderEmbeddedObject::InsecurePluginVersion || pluginUnavailabilityReason);
649 auto& pluginElement = downcast<HTMLPlugInImageElement>(element);
651 String frameURLString = pluginElement.document().frame()->loader().documentLoader()->responseURL().string();
652 String pageURLString = m_page.mainFrame()->loader().documentLoader()->responseURL().string();
653 String pluginURLString = pluginElement.document().completeURL(pluginElement.url()).string();
654 URL pluginspageAttributeURL = pluginElement.document().completeURL(stripLeadingAndTrailingHTMLSpaces(pluginElement.attributeWithoutSynchronization(pluginspageAttr)));
655 if (!pluginspageAttributeURL.protocolIsInHTTPFamily())
656 pluginspageAttributeURL = URL();
657 m_page.send(Messages::WebPageProxy::UnavailablePluginButtonClicked(pluginUnavailabilityReason, pluginElement.serviceType(), pluginURLString, pluginspageAttributeURL.string(), frameURLString, pageURLString));
659 UNUSED_PARAM(element);
660 UNUSED_PARAM(pluginUnavailabilityReason);
661 #endif // ENABLE(NETSCAPE_PLUGIN_API)
664 void WebChromeClient::mouseDidMoveOverElement(const HitTestResult& hitTestResult, unsigned modifierFlags)
666 RefPtr<API::Object> userData;
668 // Notify the bundle client.
669 m_page.injectedBundleUIClient().mouseDidMoveOverElement(&m_page, hitTestResult, static_cast<WebEvent::Modifiers>(modifierFlags), userData);
671 // Notify the UIProcess.
672 WebHitTestResultData webHitTestResultData(hitTestResult);
673 m_page.send(Messages::WebPageProxy::MouseDidMoveOverElement(webHitTestResultData, modifierFlags, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
676 void WebChromeClient::setToolTip(const String& toolTip, TextDirection)
678 // Only send a tool tip to the WebProcess if it has changed since the last time this function was called.
680 if (toolTip == m_cachedToolTip)
682 m_cachedToolTip = toolTip;
684 m_page.send(Messages::WebPageProxy::SetToolTip(m_cachedToolTip));
687 void WebChromeClient::print(Frame& frame)
689 WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
692 #if PLATFORM(GTK) && HAVE(GTK_UNIX_PRINTING)
693 // When printing synchronously in GTK+ we need to make sure that we have a list of Printers before starting the print operation.
694 // Getting the list of printers is done synchronously by GTK+, but using a nested main loop that might process IPC messages
695 // comming from the UI process like EndPrinting. When the EndPriting message is received while the printer list is being populated,
696 // the print operation is finished unexpectely and the web process crashes, see https://bugs.webkit.org/show_bug.cgi?id=126979.
697 // The PrinterListGtk class gets the list of printers in the constructor so we just need to ensure there's an instance alive
698 // during the synchronous print operation.
699 RefPtr<PrinterListGtk> printerList = PrinterListGtk::getOrCreate();
701 // PrinterListGtk::getOrCreate() returns nullptr when called while a printers enumeration is ongoing.
702 // This can happen if a synchronous print is started by a JavaScript and another one is inmeditaley started
703 // from a JavaScript event listener. The second print operation is handled by the nested main loop used by GTK+
704 // to enumerate the printers, and we end up here trying to get a reference of an object that is being constructed.
705 // It's very unlikely that the user wants to print twice in a row, and other browsers don't do two print operations
706 // in this particular case either. So, the safest solution is to return early here and ignore the second print.
707 // See https://bugs.webkit.org/show_bug.cgi?id=141035
712 m_page.sendSync(Messages::WebPageProxy::PrintFrame(webFrame->frameID()), Messages::WebPageProxy::PrintFrame::Reply(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend);
715 void WebChromeClient::exceededDatabaseQuota(Frame& frame, const String& databaseName, DatabaseDetails details)
717 WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
720 auto& origin = frame.document()->securityOrigin();
721 auto originData = SecurityOriginData::fromSecurityOrigin(origin);
722 auto& tracker = DatabaseTracker::singleton();
723 auto currentQuota = tracker.quota(originData);
724 auto currentOriginUsage = tracker.usage(originData);
725 uint64_t newQuota = 0;
726 RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(SecurityOriginData::fromDatabaseIdentifier(SecurityOriginData::fromSecurityOrigin(origin).databaseIdentifier())->securityOrigin());
727 newQuota = m_page.injectedBundleUIClient().didExceedDatabaseQuota(&m_page, securityOrigin.get(), databaseName, details.displayName(), currentQuota, currentOriginUsage, details.currentUsage(), details.expectedUsage());
730 WebProcess::singleton().parentProcessConnection()->sendSync(
731 Messages::WebPageProxy::ExceededDatabaseQuota(webFrame->frameID(), SecurityOriginData::fromSecurityOrigin(origin).databaseIdentifier(), databaseName, details.displayName(), currentQuota, currentOriginUsage, details.currentUsage(), details.expectedUsage()),
732 Messages::WebPageProxy::ExceededDatabaseQuota::Reply(newQuota), m_page.pageID(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend);
735 tracker.setQuota(originData, newQuota);
738 void WebChromeClient::reachedMaxAppCacheSize(int64_t)
743 void WebChromeClient::reachedApplicationCacheOriginQuota(SecurityOrigin& origin, int64_t totalBytesNeeded)
745 RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::createFromString(origin.toString());
746 if (m_page.injectedBundleUIClient().didReachApplicationCacheOriginQuota(&m_page, securityOrigin.get(), totalBytesNeeded))
749 auto& cacheStorage = m_page.corePage()->applicationCacheStorage();
750 int64_t currentQuota = 0;
751 if (!cacheStorage.calculateQuotaForOrigin(origin, currentQuota))
754 uint64_t newQuota = 0;
755 WebProcess::singleton().parentProcessConnection()->sendSync(
756 Messages::WebPageProxy::ReachedApplicationCacheOriginQuota(SecurityOriginData::fromSecurityOrigin(origin).databaseIdentifier(), currentQuota, totalBytesNeeded),
757 Messages::WebPageProxy::ReachedApplicationCacheOriginQuota::Reply(newQuota), m_page.pageID(), Seconds::infinity(), IPC::SendSyncOption::InformPlatformProcessWillSuspend);
759 cacheStorage.storeUpdatedQuotaForOrigin(&origin, newQuota);
762 #if ENABLE(DASHBOARD_SUPPORT)
764 void WebChromeClient::annotatedRegionsChanged()
771 bool WebChromeClient::shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename)
773 generatedFilename = m_page.injectedBundleUIClient().shouldGenerateFileForUpload(&m_page, path);
774 return !generatedFilename.isNull();
777 String WebChromeClient::generateReplacementFile(const String& path)
779 return m_page.injectedBundleUIClient().generateFileForUpload(&m_page, path);
782 #if ENABLE(INPUT_TYPE_COLOR)
784 std::unique_ptr<ColorChooser> WebChromeClient::createColorChooser(ColorChooserClient& client, const Color& initialColor)
786 return std::make_unique<WebColorChooser>(&m_page, &client, initialColor);
791 void WebChromeClient::runOpenPanel(Frame& frame, FileChooser& fileChooser)
793 if (m_page.activeOpenPanelResultListener())
796 m_page.setActiveOpenPanelResultListener(WebOpenPanelResultListener::create(m_page, fileChooser));
798 auto* webFrame = WebFrame::fromCoreFrame(frame);
800 m_page.send(Messages::WebPageProxy::RunOpenPanel(webFrame->frameID(), SecurityOriginData::fromFrame(&frame), fileChooser.settings()));
803 void WebChromeClient::loadIconForFiles(const Vector<String>& filenames, FileIconLoader& loader)
805 loader.iconLoaded(createIconForFiles(filenames));
810 void WebChromeClient::setCursor(const Cursor& cursor)
812 m_page.send(Messages::WebPageProxy::SetCursor(cursor));
815 void WebChromeClient::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
817 m_page.send(Messages::WebPageProxy::SetCursorHiddenUntilMouseMoves(hiddenUntilMouseMoves));
820 RefPtr<Icon> WebChromeClient::createIconForFiles(const Vector<String>& filenames)
822 return Icon::createIconForFiles(filenames);
827 void WebChromeClient::didAssociateFormControls(const Vector<RefPtr<Element>>& elements)
829 return m_page.injectedBundleFormClient().didAssociateFormControls(&m_page, elements);
832 bool WebChromeClient::shouldNotifyOnFormChanges()
834 return m_page.injectedBundleFormClient().shouldNotifyOnFormChanges(&m_page);
837 bool WebChromeClient::selectItemWritingDirectionIsNatural()
842 bool WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection()
847 RefPtr<PopupMenu> WebChromeClient::createPopupMenu(PopupMenuClient& client) const
849 return WebPopupMenu::create(&m_page, &client);
852 RefPtr<SearchPopupMenu> WebChromeClient::createSearchPopupMenu(PopupMenuClient& client) const
854 return WebSearchPopupMenu::create(&m_page, &client);
857 GraphicsLayerFactory* WebChromeClient::graphicsLayerFactory() const
859 if (auto drawingArea = m_page.drawingArea())
860 return drawingArea->graphicsLayerFactory();
864 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
866 RefPtr<DisplayRefreshMonitor> WebChromeClient::createDisplayRefreshMonitor(PlatformDisplayID displayID) const
868 return m_page.drawingArea()->createDisplayRefreshMonitor(displayID);
873 void WebChromeClient::attachRootGraphicsLayer(Frame&, GraphicsLayer* layer)
876 m_page.enterAcceleratedCompositingMode(layer);
878 m_page.exitAcceleratedCompositingMode();
881 void WebChromeClient::attachViewOverlayGraphicsLayer(Frame& frame, GraphicsLayer* graphicsLayer)
883 if (auto drawingArea = m_page.drawingArea())
884 drawingArea->attachViewOverlayGraphicsLayer(&frame, graphicsLayer);
887 void WebChromeClient::setNeedsOneShotDrawingSynchronization()
892 void WebChromeClient::scheduleCompositingLayerFlush()
894 if (m_page.drawingArea())
895 m_page.drawingArea()->scheduleCompositingLayerFlush();
898 void WebChromeClient::contentRuleListNotification(const URL& url, const HashSet<std::pair<String, String>>& notificationPairs)
900 Vector<String> identifiers;
901 Vector<String> notifications;
902 identifiers.reserveInitialCapacity(notificationPairs.size());
903 notifications.reserveInitialCapacity(notificationPairs.size());
904 for (auto& notification : notificationPairs) {
905 identifiers.uncheckedAppend(notification.first);
906 notifications.uncheckedAppend(notification.second);
909 m_page.send(Messages::WebPageProxy::ContentRuleListNotification(url, identifiers, notifications));
912 bool WebChromeClient::adjustLayerFlushThrottling(LayerFlushThrottleState::Flags flags)
914 return m_page.drawingArea() && m_page.drawingArea()->adjustLayerFlushThrottling(flags);
917 bool WebChromeClient::layerTreeStateIsFrozen() const
919 if (m_page.drawingArea())
920 return m_page.drawingArea()->layerTreeStateIsFrozen();
925 #if ENABLE(ASYNC_SCROLLING)
927 RefPtr<ScrollingCoordinator> WebChromeClient::createScrollingCoordinator(Page& page) const
929 ASSERT_UNUSED(page, m_page.corePage() == &page);
930 if (m_page.drawingArea()->type() != DrawingAreaTypeRemoteLayerTree)
932 return RemoteScrollingCoordinator::create(&m_page);
937 #if (PLATFORM(IOS) && HAVE(AVKIT)) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
939 bool WebChromeClient::supportsVideoFullscreen(HTMLMediaElementEnums::VideoFullscreenMode mode)
941 return m_page.videoFullscreenManager().supportsVideoFullscreen(mode);
944 void WebChromeClient::setUpPlaybackControlsManager(HTMLMediaElement& mediaElement)
946 m_page.playbackSessionManager().setUpPlaybackControlsManager(mediaElement);
949 void WebChromeClient::clearPlaybackControlsManager()
951 m_page.playbackSessionManager().clearPlaybackControlsManager();
954 void WebChromeClient::enterVideoFullscreenForVideoElement(HTMLVideoElement& videoElement, HTMLMediaElementEnums::VideoFullscreenMode mode)
956 ASSERT(mode != HTMLMediaElementEnums::VideoFullscreenModeNone);
957 m_page.videoFullscreenManager().enterVideoFullscreenForVideoElement(videoElement, mode);
960 void WebChromeClient::exitVideoFullscreenForVideoElement(HTMLVideoElement& videoElement)
962 m_page.videoFullscreenManager().exitVideoFullscreenForVideoElement(videoElement);
967 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
969 void WebChromeClient::exitVideoFullscreenToModeWithoutAnimation(HTMLVideoElement& videoElement, HTMLMediaElementEnums::VideoFullscreenMode targetMode)
971 m_page.videoFullscreenManager().exitVideoFullscreenToModeWithoutAnimation(videoElement, targetMode);
976 #if ENABLE(FULLSCREEN_API)
978 bool WebChromeClient::supportsFullScreenForElement(const Element&, bool withKeyboard)
980 return m_page.fullScreenManager()->supportsFullScreen(withKeyboard);
983 void WebChromeClient::enterFullScreenForElement(Element& element)
985 m_page.fullScreenManager()->enterFullScreenForElement(&element);
988 void WebChromeClient::exitFullScreenForElement(Element* element)
990 m_page.fullScreenManager()->exitFullScreenForElement(element);
997 FloatSize WebChromeClient::screenSize() const
999 return m_page.screenSize();
1002 FloatSize WebChromeClient::availableScreenSize() const
1004 return m_page.availableScreenSize();
1009 void WebChromeClient::dispatchViewportPropertiesDidChange(const ViewportArguments& viewportArguments) const
1011 m_page.viewportPropertiesDidChange(viewportArguments);
1014 void WebChromeClient::notifyScrollerThumbIsVisibleInRect(const IntRect& scrollerThumb)
1016 m_page.send(Messages::WebPageProxy::NotifyScrollerThumbIsVisibleInRect(scrollerThumb));
1019 void WebChromeClient::recommendedScrollbarStyleDidChange(ScrollbarStyle newStyle)
1021 m_page.send(Messages::WebPageProxy::RecommendedScrollbarStyleDidChange(static_cast<int32_t>(newStyle)));
1024 std::optional<ScrollbarOverlayStyle> WebChromeClient::preferredScrollbarOverlayStyle()
1026 return m_page.scrollbarOverlayStyle();
1029 Color WebChromeClient::underlayColor() const
1031 return m_page.underlayColor();
1034 void WebChromeClient::pageExtendedBackgroundColorDidChange(Color backgroundColor) const
1037 m_page.send(Messages::WebPageProxy::PageExtendedBackgroundColorDidChange(backgroundColor));
1039 UNUSED_PARAM(backgroundColor);
1043 void WebChromeClient::wheelEventHandlersChanged(bool hasHandlers)
1045 m_page.wheelEventHandlersChanged(hasHandlers);
1048 String WebChromeClient::plugInStartLabelTitle(const String& mimeType) const
1050 return m_page.injectedBundleUIClient().plugInStartLabelTitle(mimeType);
1053 String WebChromeClient::plugInStartLabelSubtitle(const String& mimeType) const
1055 return m_page.injectedBundleUIClient().plugInStartLabelSubtitle(mimeType);
1058 String WebChromeClient::plugInExtraStyleSheet() const
1060 return m_page.injectedBundleUIClient().plugInExtraStyleSheet();
1063 String WebChromeClient::plugInExtraScript() const
1065 return m_page.injectedBundleUIClient().plugInExtraScript();
1068 void WebChromeClient::enableSuddenTermination()
1070 m_page.send(Messages::WebProcessProxy::EnableSuddenTermination());
1073 void WebChromeClient::disableSuddenTermination()
1075 m_page.send(Messages::WebProcessProxy::DisableSuddenTermination());
1078 void WebChromeClient::didAddHeaderLayer(GraphicsLayer& headerParent)
1080 #if ENABLE(RUBBER_BANDING)
1081 if (PageBanner* banner = m_page.headerPageBanner())
1082 banner->didAddParentLayer(&headerParent);
1084 UNUSED_PARAM(headerParent);
1088 void WebChromeClient::didAddFooterLayer(GraphicsLayer& footerParent)
1090 #if ENABLE(RUBBER_BANDING)
1091 if (PageBanner* banner = m_page.footerPageBanner())
1092 banner->didAddParentLayer(&footerParent);
1094 UNUSED_PARAM(footerParent);
1098 bool WebChromeClient::shouldUseTiledBackingForFrameView(const FrameView& frameView) const
1100 return m_page.drawingArea()->shouldUseTiledBackingForFrameView(frameView);
1103 void WebChromeClient::isPlayingMediaDidChange(MediaProducer::MediaStateFlags state, uint64_t sourceElementID)
1105 m_page.send(Messages::WebPageProxy::IsPlayingMediaDidChange(state, sourceElementID));
1108 void WebChromeClient::handleAutoplayEvent(AutoplayEvent event, OptionSet<AutoplayEventFlags> flags)
1110 m_page.send(Messages::WebPageProxy::HandleAutoplayEvent(event, flags));
1113 #if ENABLE(MEDIA_SESSION)
1115 void WebChromeClient::hasMediaSessionWithActiveMediaElementsDidChange(bool state)
1117 m_page.send(Messages::WebPageProxy::HasMediaSessionWithActiveMediaElementsDidChange(state));
1120 void WebChromeClient::mediaSessionMetadataDidChange(const MediaSessionMetadata& metadata)
1122 m_page.send(Messages::WebPageProxy::MediaSessionMetadataDidChange(metadata));
1125 void WebChromeClient::focusedContentMediaElementDidChange(uint64_t elementID)
1127 m_page.send(Messages::WebPageProxy::FocusedContentMediaElementDidChange(elementID));
1132 #if ENABLE(SUBTLE_CRYPTO)
1134 bool WebChromeClient::wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) const
1137 if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::WrapCryptoKey(key), Messages::WebPageProxy::WrapCryptoKey::Reply(succeeded, wrappedKey), m_page.pageID()))
1142 bool WebChromeClient::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) const
1145 if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::UnwrapCryptoKey(wrappedKey), Messages::WebPageProxy::UnwrapCryptoKey::Reply(succeeded, key), m_page.pageID()))
1152 #if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
1154 void WebChromeClient::handleTelephoneNumberClick(const String& number, const IntPoint& point)
1156 m_page.handleTelephoneNumberClick(number, point);
1161 #if ENABLE(SERVICE_CONTROLS)
1163 void WebChromeClient::handleSelectionServiceClick(FrameSelection& selection, const Vector<String>& telephoneNumbers, const IntPoint& point)
1165 m_page.handleSelectionServiceClick(selection, telephoneNumbers, point);
1168 bool WebChromeClient::hasRelevantSelectionServices(bool isTextOnly) const
1170 return (isTextOnly && WebProcess::singleton().hasSelectionServices()) || WebProcess::singleton().hasRichContentServices();
1175 bool WebChromeClient::shouldDispatchFakeMouseMoveEvents() const
1177 return m_page.shouldDispatchFakeMouseMoveEvents();
1180 void WebChromeClient::handleAutoFillButtonClick(HTMLInputElement& inputElement)
1182 RefPtr<API::Object> userData;
1184 // Notify the bundle client.
1185 auto nodeHandle = InjectedBundleNodeHandle::getOrCreate(inputElement);
1186 m_page.injectedBundleUIClient().didClickAutoFillButton(m_page, nodeHandle.get(), userData);
1188 // Notify the UIProcess.
1189 m_page.send(Messages::WebPageProxy::HandleAutoFillButtonClick(UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
1192 void WebChromeClient::handleAlternativePresentationButtonClick(Node& node)
1194 RefPtr<API::Object> userData;
1196 // Notify the bundle client.
1197 auto nodeHandle = InjectedBundleNodeHandle::getOrCreate(node);
1198 m_page.injectedBundleUIClient().didClickAlternativePresentationButton(m_page, nodeHandle.get(), userData);
1200 // Notify the UIProcess.
1201 m_page.send(Messages::WebPageProxy::HandleAlternativePresentationButtonClick(UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
1204 #if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
1206 void WebChromeClient::addPlaybackTargetPickerClient(uint64_t contextId)
1208 m_page.send(Messages::WebPageProxy::AddPlaybackTargetPickerClient(contextId));
1211 void WebChromeClient::removePlaybackTargetPickerClient(uint64_t contextId)
1213 m_page.send(Messages::WebPageProxy::RemovePlaybackTargetPickerClient(contextId));
1216 void WebChromeClient::showPlaybackTargetPicker(uint64_t contextId, const IntPoint& position, bool isVideo)
1218 FrameView* frameView = m_page.mainFrame()->view();
1219 FloatRect rect(frameView->contentsToRootView(frameView->windowToContents(position)), FloatSize());
1220 m_page.send(Messages::WebPageProxy::ShowPlaybackTargetPicker(contextId, rect, isVideo));
1223 void WebChromeClient::playbackTargetPickerClientStateDidChange(uint64_t contextId, MediaProducer::MediaStateFlags state)
1225 m_page.send(Messages::WebPageProxy::PlaybackTargetPickerClientStateDidChange(contextId, state));
1228 void WebChromeClient::setMockMediaPlaybackTargetPickerEnabled(bool enabled)
1230 m_page.send(Messages::WebPageProxy::SetMockMediaPlaybackTargetPickerEnabled(enabled));
1233 void WebChromeClient::setMockMediaPlaybackTargetPickerState(const String& name, MediaPlaybackTargetContext::State state)
1235 m_page.send(Messages::WebPageProxy::SetMockMediaPlaybackTargetPickerState(name, state));
1240 void WebChromeClient::imageOrMediaDocumentSizeChanged(const IntSize& newSize)
1242 m_page.imageOrMediaDocumentSizeChanged(newSize);
1245 #if ENABLE(VIDEO) && USE(GSTREAMER)
1247 void WebChromeClient::requestInstallMissingMediaPlugins(const String& details, const String& description, MediaPlayerRequestInstallMissingPluginsCallback& callback)
1249 m_page.requestInstallMissingMediaPlugins(details, description, callback);
1254 void WebChromeClient::didInvalidateDocumentMarkerRects()
1256 m_page.findController().didInvalidateDocumentMarkerRects();
1259 void WebChromeClient::hasStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, WTF::CompletionHandler<void (bool)>&& callback)
1261 m_page.hasStorageAccess(WTFMove(subFrameHost), WTFMove(topFrameHost), frameID, pageID, WTFMove(callback));
1264 void WebChromeClient::requestStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, WTF::CompletionHandler<void (bool)>&& callback)
1266 m_page.requestStorageAccess(WTFMove(subFrameHost), WTFMove(topFrameHost), frameID, pageID, WTFMove(callback));
1269 } // namespace WebKit