2 * Copyright (C) 2009 Google 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 are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "web/ChromeClientImpl.h"
35 #include "bindings/core/v8/ScriptController.h"
36 #include "core/HTMLNames.h"
37 #include "core/accessibility/AXObject.h"
38 #include "core/accessibility/AXObjectCache.h"
39 #include "core/dom/Document.h"
40 #include "core/dom/Fullscreen.h"
41 #include "core/dom/Node.h"
42 #include "core/events/KeyboardEvent.h"
43 #include "core/events/MouseEvent.h"
44 #include "core/events/WheelEvent.h"
45 #include "core/frame/Console.h"
46 #include "core/frame/FrameView.h"
47 #include "core/frame/Settings.h"
48 #include "core/html/HTMLInputElement.h"
49 #include "core/html/forms/ColorChooser.h"
50 #include "core/html/forms/ColorChooserClient.h"
51 #include "core/html/forms/DateTimeChooser.h"
52 #include "core/loader/DocumentLoader.h"
53 #include "core/loader/FrameLoadRequest.h"
54 #include "core/page/Page.h"
55 #include "core/page/PagePopupDriver.h"
56 #include "core/page/WindowFeatures.h"
57 #include "core/rendering/HitTestResult.h"
58 #include "core/rendering/RenderPart.h"
59 #include "core/rendering/RenderWidget.h"
60 #include "core/rendering/compositing/CompositedSelectionBound.h"
61 #include "platform/Cursor.h"
62 #include "platform/FileChooser.h"
63 #include "platform/NotImplemented.h"
64 #include "platform/PlatformScreen.h"
65 #include "platform/RuntimeEnabledFeatures.h"
66 #include "platform/exported/WrappedResourceRequest.h"
67 #include "platform/geometry/FloatRect.h"
68 #include "platform/geometry/IntRect.h"
69 #include "platform/graphics/GraphicsLayer.h"
70 #include "platform/weborigin/SecurityOrigin.h"
71 #include "public/platform/Platform.h"
72 #include "public/platform/WebCursorInfo.h"
73 #include "public/platform/WebRect.h"
74 #include "public/platform/WebSelectionBound.h"
75 #include "public/platform/WebURLRequest.h"
76 #include "public/web/WebAXObject.h"
77 #include "public/web/WebAutofillClient.h"
78 #include "public/web/WebColorChooser.h"
79 #include "public/web/WebColorSuggestion.h"
80 #include "public/web/WebConsoleMessage.h"
81 #include "public/web/WebFrameClient.h"
82 #include "public/web/WebInputElement.h"
83 #include "public/web/WebInputEvent.h"
84 #include "public/web/WebKit.h"
85 #include "public/web/WebNode.h"
86 #include "public/web/WebPlugin.h"
87 #include "public/web/WebPopupMenuInfo.h"
88 #include "public/web/WebSettings.h"
89 #include "public/web/WebTextDirection.h"
90 #include "public/web/WebTouchAction.h"
91 #include "public/web/WebUserGestureIndicator.h"
92 #include "public/web/WebUserGestureToken.h"
93 #include "public/web/WebViewClient.h"
94 #include "public/web/WebWindowFeatures.h"
95 #include "web/ColorChooserPopupUIController.h"
96 #include "web/ColorChooserUIController.h"
97 #include "web/DateTimeChooserImpl.h"
98 #include "web/ExternalDateTimeChooser.h"
99 #include "web/ExternalPopupMenu.h"
100 #include "web/PopupMenuChromium.h"
101 #include "web/WebFileChooserCompletionImpl.h"
102 #include "web/WebInputEventConversion.h"
103 #include "web/WebLocalFrameImpl.h"
104 #include "web/WebPluginContainerImpl.h"
105 #include "web/WebPopupMenuImpl.h"
106 #include "web/WebSettingsImpl.h"
107 #include "web/WebViewImpl.h"
108 #include "wtf/text/CString.h"
109 #include "wtf/text/StringBuilder.h"
110 #include "wtf/text/StringConcatenate.h"
111 #include "wtf/unicode/CharacterNames.h"
115 // Converts a AXObjectCache::AXNotification to a WebAXEvent
116 static WebAXEvent toWebAXEvent(AXObjectCache::AXNotification notification)
118 // These enums have the same values; enforced in AssertMatchingEnums.cpp.
119 return static_cast<WebAXEvent>(notification);
122 static WebSelectionBound toWebSelectionBound(const CompositedSelectionBound& bound)
126 // These enums have the same values; enforced in AssertMatchingEnums.cpp.
127 WebSelectionBound result(static_cast<WebSelectionBound::Type>(bound.type));
128 result.layerId = bound.layer->platformLayer()->id();
129 result.edgeTopInLayer = roundedIntPoint(bound.edgeTopInLayer);
130 result.edgeBottomInLayer = roundedIntPoint(bound.edgeBottomInLayer);
134 ChromeClientImpl::ChromeClientImpl(WebViewImpl* webView)
136 , m_toolbarsVisible(true)
137 , m_statusbarVisible(true)
138 , m_scrollbarsVisible(true)
139 , m_menubarVisible(true)
141 , m_pagePopupDriver(webView)
145 ChromeClientImpl::~ChromeClientImpl()
149 void* ChromeClientImpl::webView() const
151 return static_cast<void*>(m_webView);
154 void ChromeClientImpl::chromeDestroyed()
156 // Our lifetime is bound to the WebViewImpl.
159 void ChromeClientImpl::setWindowRect(const FloatRect& r)
161 if (m_webView->client())
162 m_webView->client()->setWindowRect(IntRect(r));
165 FloatRect ChromeClientImpl::windowRect()
168 if (m_webView->client())
169 rect = m_webView->client()->rootWindowRect();
171 // These numbers will be fairly wrong. The window's x/y coordinates will
172 // be the top left corner of the screen and the size will be the content
173 // size instead of the window size.
174 rect.width = m_webView->size().width;
175 rect.height = m_webView->size().height;
177 return FloatRect(rect);
180 FloatRect ChromeClientImpl::pageRect()
182 // We hide the details of the window's border thickness from the web page by
183 // simple re-using the window position here. So, from the point-of-view of
184 // the web page, the window has no border.
188 void ChromeClientImpl::focus()
190 if (m_webView->client())
191 m_webView->client()->didFocus();
194 bool ChromeClientImpl::canTakeFocus(FocusType)
196 // For now the browser can always take focus if we're not running layout
198 return !layoutTestMode();
201 void ChromeClientImpl::takeFocus(FocusType type)
203 if (!m_webView->client())
205 if (type == FocusTypeBackward)
206 m_webView->client()->focusPrevious();
208 m_webView->client()->focusNext();
211 void ChromeClientImpl::focusedNodeChanged(Node* node)
213 m_webView->client()->focusedNodeChanged(WebNode(node));
216 if (node && node->isElementNode() && toElement(node)->isLiveLink())
217 focusURL = toElement(node)->hrefURL();
218 m_webView->client()->setKeyboardFocusURL(focusURL);
221 void ChromeClientImpl::focusedFrameChanged(LocalFrame* frame)
223 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
224 if (webframe && webframe->client())
225 webframe->client()->frameFocused();
228 Page* ChromeClientImpl::createWindow(LocalFrame* frame, const FrameLoadRequest& r, const WindowFeatures& features,
229 NavigationPolicy navigationPolicy, ShouldSendReferrer shouldSendReferrer)
231 if (!m_webView->client())
234 WebNavigationPolicy policy = static_cast<WebNavigationPolicy>(navigationPolicy);
235 if (policy == WebNavigationPolicyIgnore)
236 policy = getNavigationPolicy();
238 ASSERT(frame->document());
239 Fullscreen::fullyExitFullscreen(*frame->document());
241 WebViewImpl* newView = toWebViewImpl(
242 m_webView->client()->createView(WebLocalFrameImpl::fromFrame(frame), WrappedResourceRequest(r.resourceRequest()), features, r.frameName(), policy, shouldSendReferrer == NeverSendReferrer));
245 return newView->page();
248 static inline void updatePolicyForEvent(const WebInputEvent* inputEvent, NavigationPolicy* policy)
250 if (!inputEvent || inputEvent->type != WebInputEvent::MouseUp)
253 const WebMouseEvent* mouseEvent = static_cast<const WebMouseEvent*>(inputEvent);
255 unsigned short buttonNumber;
256 switch (mouseEvent->button) {
257 case WebMouseEvent::ButtonLeft:
260 case WebMouseEvent::ButtonMiddle:
263 case WebMouseEvent::ButtonRight:
269 bool ctrl = mouseEvent->modifiers & WebMouseEvent::ControlKey;
270 bool shift = mouseEvent->modifiers & WebMouseEvent::ShiftKey;
271 bool alt = mouseEvent->modifiers & WebMouseEvent::AltKey;
272 bool meta = mouseEvent->modifiers & WebMouseEvent::MetaKey;
274 NavigationPolicy userPolicy = *policy;
275 navigationPolicyFromMouseEvent(buttonNumber, ctrl, shift, alt, meta, &userPolicy);
276 // User and app agree that we want a new window; let the app override the decorations.
277 if (userPolicy == NavigationPolicyNewWindow && *policy == NavigationPolicyNewPopup)
279 *policy = userPolicy;
282 WebNavigationPolicy ChromeClientImpl::getNavigationPolicy()
284 // If our default configuration was modified by a script or wasn't
285 // created by a user gesture, then show as a popup. Else, let this
286 // new window be opened as a toplevel window.
287 bool asPopup = !m_toolbarsVisible
288 || !m_statusbarVisible
289 || !m_scrollbarsVisible
293 NavigationPolicy policy = NavigationPolicyNewForegroundTab;
295 policy = NavigationPolicyNewPopup;
296 updatePolicyForEvent(WebViewImpl::currentInputEvent(), &policy);
298 return static_cast<WebNavigationPolicy>(policy);
301 void ChromeClientImpl::show(NavigationPolicy navigationPolicy)
303 if (!m_webView->client())
306 WebNavigationPolicy policy = static_cast<WebNavigationPolicy>(navigationPolicy);
307 if (policy == WebNavigationPolicyIgnore)
308 policy = getNavigationPolicy();
309 m_webView->client()->show(policy);
312 bool ChromeClientImpl::canRunModal()
314 return !!m_webView->client();
317 void ChromeClientImpl::runModal()
319 if (m_webView->client())
320 m_webView->client()->runModal();
323 void ChromeClientImpl::setToolbarsVisible(bool value)
325 m_toolbarsVisible = value;
328 bool ChromeClientImpl::toolbarsVisible()
330 return m_toolbarsVisible;
333 void ChromeClientImpl::setStatusbarVisible(bool value)
335 m_statusbarVisible = value;
338 bool ChromeClientImpl::statusbarVisible()
340 return m_statusbarVisible;
343 void ChromeClientImpl::setScrollbarsVisible(bool value)
345 m_scrollbarsVisible = value;
346 WebLocalFrameImpl* webFrame = toWebLocalFrameImpl(m_webView->mainFrame());
348 webFrame->setCanHaveScrollbars(value);
351 bool ChromeClientImpl::scrollbarsVisible()
353 return m_scrollbarsVisible;
356 void ChromeClientImpl::setMenubarVisible(bool value)
358 m_menubarVisible = value;
361 bool ChromeClientImpl::menubarVisible()
363 return m_menubarVisible;
366 void ChromeClientImpl::setResizable(bool value)
371 bool ChromeClientImpl::shouldReportDetailedMessageForSource(const String& url)
373 WebLocalFrameImpl* webframe = m_webView->localFrameRootTemporary();
374 return webframe->client() && webframe->client()->shouldReportDetailedMessageForSource(url);
377 void ChromeClientImpl::addMessageToConsole(LocalFrame* localFrame, MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID, const String& stackTrace)
379 WebLocalFrameImpl* frame = WebLocalFrameImpl::fromFrame(localFrame);
380 if (frame && frame->client()) {
381 frame->client()->didAddMessageToConsole(
382 WebConsoleMessage(static_cast<WebConsoleMessage::Level>(level), message),
389 bool ChromeClientImpl::canRunBeforeUnloadConfirmPanel()
391 return !!m_webView->client();
394 bool ChromeClientImpl::runBeforeUnloadConfirmPanel(const String& message, LocalFrame* frame)
396 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
398 bool isReload = false;
399 WebDataSource* ds = webframe->provisionalDataSource();
401 isReload = (ds->navigationType() == WebNavigationTypeReload);
403 if (webframe->client())
404 return webframe->client()->runModalBeforeUnloadDialog(isReload, message);
408 void ChromeClientImpl::closeWindowSoon()
410 // Make sure this Page can no longer be found by JS.
411 Page::ordinaryPages().remove(m_webView->page());
413 // Make sure that all loading is stopped. Ensures that JS stops executing!
414 m_webView->mainFrame()->stopLoading();
416 if (m_webView->client())
417 m_webView->client()->closeWidgetSoon();
420 // Although a LocalFrame is passed in, we don't actually use it, since we
421 // already know our own m_webView.
422 void ChromeClientImpl::runJavaScriptAlert(LocalFrame* frame, const String& message)
424 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
425 if (webframe->client()) {
426 if (WebUserGestureIndicator::isProcessingUserGesture())
427 WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
428 webframe->client()->runModalAlertDialog(message);
432 // See comments for runJavaScriptAlert().
433 bool ChromeClientImpl::runJavaScriptConfirm(LocalFrame* frame, const String& message)
435 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
436 if (webframe->client()) {
437 if (WebUserGestureIndicator::isProcessingUserGesture())
438 WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
439 return webframe->client()->runModalConfirmDialog(message);
444 // See comments for runJavaScriptAlert().
445 bool ChromeClientImpl::runJavaScriptPrompt(LocalFrame* frame,
446 const String& message,
447 const String& defaultValue,
450 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
451 if (webframe->client()) {
452 if (WebUserGestureIndicator::isProcessingUserGesture())
453 WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
454 WebString actualValue;
455 bool ok = webframe->client()->runModalPromptDialog(
460 result = actualValue;
466 void ChromeClientImpl::setStatusbarText(const String& message)
468 if (m_webView->client())
469 m_webView->client()->setStatusText(message);
472 bool ChromeClientImpl::tabsToLinks()
474 return m_webView->tabsToLinks();
477 IntRect ChromeClientImpl::windowResizerRect() const
480 if (m_webView->client())
481 result = m_webView->client()->windowResizerRect();
485 void ChromeClientImpl::invalidateContentsAndRootView(const IntRect& updateRect)
487 if (updateRect.isEmpty())
489 m_webView->invalidateRect(updateRect);
492 void ChromeClientImpl::invalidateContentsForSlowScroll(const IntRect& updateRect)
494 invalidateContentsAndRootView(updateRect);
497 void ChromeClientImpl::scheduleAnimation()
499 m_webView->scheduleAnimation();
502 IntRect ChromeClientImpl::rootViewToScreen(const IntRect& rect) const
504 IntRect screenRect(rect);
506 if (m_webView->client()) {
507 WebRect windowRect = m_webView->client()->windowRect();
508 screenRect.move(windowRect.x, windowRect.y);
514 WebScreenInfo ChromeClientImpl::screenInfo() const
516 return m_webView->client() ? m_webView->client()->screenInfo() : WebScreenInfo();
519 void ChromeClientImpl::contentsSizeChanged(LocalFrame* frame, const IntSize& size) const
521 m_webView->didChangeContentsSize();
523 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
524 webframe->didChangeContentsSize(size);
526 frame->loader().restoreScrollPositionAndViewState();
529 void ChromeClientImpl::deviceOrPageScaleFactorChanged() const
531 m_webView->deviceOrPageScaleFactorChanged();
534 void ChromeClientImpl::layoutUpdated(LocalFrame* frame) const
536 m_webView->layoutUpdated(WebLocalFrameImpl::fromFrame(frame));
539 void ChromeClientImpl::mouseDidMoveOverElement(
540 const HitTestResult& result, unsigned modifierFlags)
542 if (!m_webView->client())
546 // Find out if the mouse is over a link, and if so, let our UI know...
547 if (result.isLiveLink() && !result.absoluteLinkURL().string().isEmpty()) {
548 url = result.absoluteLinkURL();
549 } else if (result.innerNonSharedNode()
550 && (isHTMLObjectElement(*result.innerNonSharedNode())
551 || isHTMLEmbedElement(*result.innerNonSharedNode()))) {
552 RenderObject* object = result.innerNonSharedNode()->renderer();
553 if (object && object->isWidget()) {
554 Widget* widget = toRenderWidget(object)->widget();
555 if (widget && widget->isPluginContainer()) {
556 WebPluginContainerImpl* plugin = toWebPluginContainerImpl(widget);
557 url = plugin->plugin()->linkAtPosition(result.roundedPointInInnerNodeFrame());
562 m_webView->client()->setMouseOverURL(url);
565 void ChromeClientImpl::setToolTip(const String& tooltipText, TextDirection dir)
567 if (m_webView->client())
568 m_webView->client()->setToolTipText(tooltipText, toWebTextDirection(dir));
571 void ChromeClientImpl::dispatchViewportPropertiesDidChange(const ViewportDescription& description) const
573 m_webView->updatePageDefinedViewportConstraints(description);
576 void ChromeClientImpl::print(LocalFrame* frame)
578 if (m_webView->client())
579 m_webView->client()->printPage(WebLocalFrameImpl::fromFrame(frame));
582 PassOwnPtr<ColorChooser> ChromeClientImpl::createColorChooser(LocalFrame* frame, ColorChooserClient* chooserClient, const Color&)
584 OwnPtr<ColorChooserUIController> controller;
585 if (RuntimeEnabledFeatures::pagePopupEnabled())
586 controller = adoptPtr(new ColorChooserPopupUIController(frame, this, chooserClient));
588 controller = adoptPtr(new ColorChooserUIController(frame, chooserClient));
589 controller->openUI();
590 return controller.release();
593 PassRefPtr<DateTimeChooser> ChromeClientImpl::openDateTimeChooser(DateTimeChooserClient* pickerClient, const DateTimeChooserParameters& parameters)
595 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
596 return DateTimeChooserImpl::create(this, pickerClient, parameters);
598 return ExternalDateTimeChooser::create(this, m_webView->client(), pickerClient, parameters);
602 void ChromeClientImpl::runOpenPanel(LocalFrame* frame, PassRefPtr<FileChooser> fileChooser)
604 WebViewClient* client = m_webView->client();
608 WebFileChooserParams params;
609 params.multiSelect = fileChooser->settings().allowsMultipleFiles;
610 params.directory = fileChooser->settings().allowsDirectoryUpload;
611 params.acceptTypes = fileChooser->settings().acceptTypes();
612 params.selectedFiles = fileChooser->settings().selectedFiles;
613 if (params.selectedFiles.size() > 0)
614 params.initialValue = params.selectedFiles[0];
615 params.useMediaCapture = fileChooser->settings().useMediaCapture;
617 WebFileChooserCompletionImpl* chooserCompletion =
618 new WebFileChooserCompletionImpl(fileChooser);
620 if (client->runFileChooser(params, chooserCompletion))
623 // Choosing failed, so do callback with an empty list.
624 chooserCompletion->didChooseFile(WebVector<WebString>());
627 void ChromeClientImpl::enumerateChosenDirectory(FileChooser* fileChooser)
629 WebViewClient* client = m_webView->client();
633 WebFileChooserCompletionImpl* chooserCompletion =
634 new WebFileChooserCompletionImpl(fileChooser);
636 ASSERT(fileChooser && fileChooser->settings().selectedFiles.size());
638 // If the enumeration can't happen, call the callback with an empty list.
639 if (!client->enumerateChosenDirectory(fileChooser->settings().selectedFiles[0], chooserCompletion))
640 chooserCompletion->didChooseFile(WebVector<WebString>());
643 void ChromeClientImpl::setCursor(const Cursor& cursor)
645 setCursor(WebCursorInfo(cursor));
648 void ChromeClientImpl::setCursor(const WebCursorInfo& cursor)
651 // On Mac the mousemove event propagates to both the popup and main window.
652 // If a popup is open we don't want the main window to change the cursor.
653 if (m_webView->hasOpenedPopup())
656 if (m_webView->client())
657 m_webView->client()->didChangeCursor(cursor);
660 void ChromeClientImpl::setCursorForPlugin(const WebCursorInfo& cursor)
665 void ChromeClientImpl::postAccessibilityNotification(AXObject* obj, AXObjectCache::AXNotification notification)
667 // Alert assistive technology about the accessibility object notification.
668 if (!obj || !obj->documentFrameView())
671 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(obj->documentFrameView()->frame());
672 if (webframe && webframe->client())
673 webframe->client()->postAccessibilityEvent(WebAXObject(obj), toWebAXEvent(notification));
675 // FIXME: delete these lines once Chrome only uses the frame client interface, above.
676 if (m_webView->client())
677 m_webView->client()->postAccessibilityEvent(WebAXObject(obj), toWebAXEvent(notification));
680 String ChromeClientImpl::acceptLanguages()
682 return m_webView->client()->acceptLanguages();
685 bool ChromeClientImpl::paintCustomOverhangArea(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
687 LocalFrame* frame = m_webView->mainFrameImpl()->frame();
688 WebPluginContainerImpl* pluginContainer = WebLocalFrameImpl::pluginContainerFromFrame(frame);
690 return pluginContainer->paintCustomOverhangArea(context, horizontalOverhangArea, verticalOverhangArea, dirtyRect);
694 GraphicsLayerFactory* ChromeClientImpl::graphicsLayerFactory() const
696 return m_webView->graphicsLayerFactory();
699 void ChromeClientImpl::attachRootGraphicsLayer(GraphicsLayer* rootLayer)
701 m_webView->setRootGraphicsLayer(rootLayer);
704 void ChromeClientImpl::enterFullScreenForElement(Element* element)
706 m_webView->enterFullScreenForElement(element);
709 void ChromeClientImpl::exitFullScreenForElement(Element* element)
711 m_webView->exitFullScreenForElement(element);
714 void ChromeClientImpl::clearCompositedSelectionBounds()
716 m_webView->clearCompositedSelectionBounds();
719 void ChromeClientImpl::updateCompositedSelectionBounds(const CompositedSelectionBound& anchor, const CompositedSelectionBound& focus)
721 m_webView->updateCompositedSelectionBounds(toWebSelectionBound(anchor), toWebSelectionBound(focus));
724 bool ChromeClientImpl::hasOpenedPopup() const
726 return m_webView->hasOpenedPopup();
729 PassRefPtrWillBeRawPtr<PopupMenu> ChromeClientImpl::createPopupMenu(LocalFrame& frame, PopupMenuClient* client) const
731 if (WebViewImpl::useExternalPopupMenus())
732 return adoptRefWillBeNoop(new ExternalPopupMenu(frame, client, *m_webView));
734 return adoptRefWillBeNoop(new PopupMenuChromium(frame, client));
737 PagePopup* ChromeClientImpl::openPagePopup(PagePopupClient* client, const IntRect& originBoundsInRootView)
739 ASSERT(m_pagePopupDriver);
740 return m_pagePopupDriver->openPagePopup(client, originBoundsInRootView);
743 void ChromeClientImpl::closePagePopup(PagePopup* popup)
745 ASSERT(m_pagePopupDriver);
746 m_pagePopupDriver->closePagePopup(popup);
749 void ChromeClientImpl::setPagePopupDriver(PagePopupDriver* driver)
752 m_pagePopupDriver = driver;
755 void ChromeClientImpl::resetPagePopupDriver()
757 m_pagePopupDriver = m_webView;
760 bool ChromeClientImpl::shouldRunModalDialogDuringPageDismissal(const DialogType& dialogType, const String& dialogMessage, Document::PageDismissalType dismissalType) const
762 const char* kDialogs[] = {"alert", "confirm", "prompt", "showModalDialog"};
763 int dialog = static_cast<int>(dialogType);
764 ASSERT_WITH_SECURITY_IMPLICATION(0 <= dialog && dialog < static_cast<int>(arraysize(kDialogs)));
766 const char* kDismissals[] = {"beforeunload", "pagehide", "unload"};
767 int dismissal = static_cast<int>(dismissalType) - 1; // Exclude NoDismissal.
768 ASSERT_WITH_SECURITY_IMPLICATION(0 <= dismissal && dismissal < static_cast<int>(arraysize(kDismissals)));
770 Platform::current()->histogramEnumeration("Renderer.ModalDialogsDuringPageDismissal", dismissal * arraysize(kDialogs) + dialog, arraysize(kDialogs) * arraysize(kDismissals));
772 String message = String("Blocked ") + kDialogs[dialog] + "('" + dialogMessage + "') during " + kDismissals[dismissal] + ".";
773 m_webView->mainFrame()->addMessageToConsole(WebConsoleMessage(WebConsoleMessage::LevelError, message));
778 void ChromeClientImpl::needTouchEvents(bool needsTouchEvents)
780 m_webView->hasTouchEventHandlers(needsTouchEvents);
783 void ChromeClientImpl::setTouchAction(TouchAction touchAction)
785 if (WebViewClient* client = m_webView->client()) {
786 WebTouchAction webTouchAction = static_cast<WebTouchAction>(touchAction);
787 client->setTouchAction(webTouchAction);
791 bool ChromeClientImpl::requestPointerLock()
793 return m_webView->requestPointerLock();
796 void ChromeClientImpl::requestPointerUnlock()
798 return m_webView->requestPointerUnlock();
801 void ChromeClientImpl::annotatedRegionsChanged()
803 WebViewClient* client = m_webView->client();
805 client->draggableRegionsChanged();
808 void ChromeClientImpl::didAssociateFormControls(const WillBeHeapVector<RefPtrWillBeMember<Element> >& elements)
810 if (m_webView->autofillClient())
811 m_webView->autofillClient()->didAssociateFormControls(elements);
814 void ChromeClientImpl::didCancelCompositionOnSelectionChange()
816 if (m_webView->client())
817 m_webView->client()->didCancelCompositionOnSelectionChange();
820 void ChromeClientImpl::willSetInputMethodState()
822 if (m_webView->client())
823 m_webView->client()->resetInputMethod();
826 void ChromeClientImpl::didUpdateTextOfFocusedElementByNonUserInput()
828 if (m_webView->client())
829 m_webView->client()->didUpdateTextOfFocusedElementByNonUserInput();
832 void ChromeClientImpl::showImeIfNeeded()
834 if (m_webView->client())
835 m_webView->client()->showImeIfNeeded();
838 void ChromeClientImpl::handleKeyboardEventOnTextField(HTMLInputElement& inputElement, KeyboardEvent& event)
840 if (!m_webView->autofillClient())
842 m_webView->autofillClient()->textFieldDidReceiveKeyDown(WebInputElement(&inputElement), WebKeyboardEventBuilder(event));
845 // FIXME: Remove this code once we have input routing in the browser
846 // process. See http://crbug.com/339659.
847 void ChromeClientImpl::forwardInputEvent(
848 Frame* frame, Event* event)
850 // FIXME: Input event forwarding to out-of-process frames is broken until
851 // WebRemoteFrameImpl has a WebFrameClient.
852 if (frame->isRemoteFrame())
855 WebLocalFrameImpl* webFrame = WebLocalFrameImpl::fromFrame(toLocalFrame(frame));
857 // This is only called when we have out-of-process iframes, which
858 // need to forward input events across processes.
859 // FIXME: Add a check for out-of-process iframes enabled.
860 if (event->isKeyboardEvent()) {
861 WebKeyboardEventBuilder webEvent(*static_cast<KeyboardEvent*>(event));
862 webFrame->client()->forwardInputEvent(&webEvent);
863 } else if (event->isMouseEvent()) {
864 WebMouseEventBuilder webEvent(webFrame->frameView(), frame->ownerRenderer(), *static_cast<MouseEvent*>(event));
865 // Internal Blink events should not be forwarded.
866 if (webEvent.type == WebInputEvent::Undefined)
869 webFrame->client()->forwardInputEvent(&webEvent);
870 } else if (event->isWheelEvent()) {
871 WebMouseWheelEventBuilder webEvent(webFrame->frameView(), frame->ownerRenderer(), *static_cast<WheelEvent*>(event));
872 if (webEvent.type == WebInputEvent::Undefined)
874 webFrame->client()->forwardInputEvent(&webEvent);
878 void ChromeClientImpl::didChangeValueInTextField(HTMLFormControlElement& element)
880 if (!m_webView->autofillClient())
882 m_webView->autofillClient()->textFieldDidChange(WebFormControlElement(&element));
885 void ChromeClientImpl::didEndEditingOnTextField(HTMLInputElement& inputElement)
887 if (m_webView->autofillClient())
888 m_webView->autofillClient()->textFieldDidEndEditing(WebInputElement(&inputElement));
891 void ChromeClientImpl::openTextDataListChooser(HTMLInputElement& input)
893 if (m_webView->autofillClient())
894 m_webView->autofillClient()->openTextDataListChooser(WebInputElement(&input));