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/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/DocumentFullscreen.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/loader/DocumentLoader.h"
50 #include "core/loader/FrameLoadRequest.h"
51 #include "core/page/Page.h"
52 #include "core/page/PagePopupDriver.h"
53 #include "core/page/WindowFeatures.h"
54 #include "core/rendering/HitTestResult.h"
55 #include "core/rendering/RenderWidget.h"
56 #include "platform/ColorChooser.h"
57 #include "platform/ColorChooserClient.h"
58 #include "platform/Cursor.h"
59 #include "platform/DateTimeChooser.h"
60 #include "platform/FileChooser.h"
61 #include "platform/NotImplemented.h"
62 #include "platform/PlatformScreen.h"
63 #include "platform/RuntimeEnabledFeatures.h"
64 #include "platform/exported/WrappedResourceRequest.h"
65 #include "platform/geometry/FloatRect.h"
66 #include "platform/geometry/IntRect.h"
67 #include "platform/graphics/GraphicsLayer.h"
68 #include "platform/weborigin/SecurityOrigin.h"
69 #include "public/platform/Platform.h"
70 #include "public/platform/WebCursorInfo.h"
71 #include "public/platform/WebRect.h"
72 #include "public/platform/WebURLRequest.h"
73 #include "public/web/WebAXObject.h"
74 #include "public/web/WebAutofillClient.h"
75 #include "public/web/WebColorChooser.h"
76 #include "public/web/WebColorSuggestion.h"
77 #include "public/web/WebConsoleMessage.h"
78 #include "public/web/WebFrameClient.h"
79 #include "public/web/WebInputElement.h"
80 #include "public/web/WebInputEvent.h"
81 #include "public/web/WebKit.h"
82 #include "public/web/WebNode.h"
83 #include "public/web/WebPlugin.h"
84 #include "public/web/WebPopupMenuInfo.h"
85 #include "public/web/WebSettings.h"
86 #include "public/web/WebTextDirection.h"
87 #include "public/web/WebTouchAction.h"
88 #include "public/web/WebUserGestureIndicator.h"
89 #include "public/web/WebUserGestureToken.h"
90 #include "public/web/WebViewClient.h"
91 #include "public/web/WebWindowFeatures.h"
92 #include "web/ColorChooserPopupUIController.h"
93 #include "web/ColorChooserUIController.h"
94 #include "web/DateTimeChooserImpl.h"
95 #include "web/ExternalDateTimeChooser.h"
96 #include "web/ExternalPopupMenu.h"
97 #include "web/PopupMenuChromium.h"
98 #include "web/WebFileChooserCompletionImpl.h"
99 #include "web/WebInputEventConversion.h"
100 #include "web/WebLocalFrameImpl.h"
101 #include "web/WebPluginContainerImpl.h"
102 #include "web/WebPopupMenuImpl.h"
103 #include "web/WebSettingsImpl.h"
104 #include "web/WebViewImpl.h"
105 #include "wtf/text/CString.h"
106 #include "wtf/text/StringBuilder.h"
107 #include "wtf/text/StringConcatenate.h"
108 #include "wtf/unicode/CharacterNames.h"
110 using namespace WebCore;
114 // Converts a WebCore::AXObjectCache::AXNotification to a blink::WebAXEvent
115 static WebAXEvent toWebAXEvent(AXObjectCache::AXNotification notification)
117 // These enums have the same values; enforced in AssertMatchingEnums.cpp.
118 return static_cast<WebAXEvent>(notification);
121 ChromeClientImpl::ChromeClientImpl(WebViewImpl* webView)
123 , m_toolbarsVisible(true)
124 , m_statusbarVisible(true)
125 , m_scrollbarsVisible(true)
126 , m_menubarVisible(true)
128 , m_pagePopupDriver(webView)
132 ChromeClientImpl::~ChromeClientImpl()
136 void* ChromeClientImpl::webView() const
138 return static_cast<void*>(m_webView);
141 void ChromeClientImpl::chromeDestroyed()
143 // Our lifetime is bound to the WebViewImpl.
146 void ChromeClientImpl::setWindowRect(const FloatRect& r)
148 if (m_webView->client())
149 m_webView->client()->setWindowRect(IntRect(r));
152 FloatRect ChromeClientImpl::windowRect()
155 if (m_webView->client())
156 rect = m_webView->client()->rootWindowRect();
158 // These numbers will be fairly wrong. The window's x/y coordinates will
159 // be the top left corner of the screen and the size will be the content
160 // size instead of the window size.
161 rect.width = m_webView->size().width;
162 rect.height = m_webView->size().height;
164 return FloatRect(rect);
167 FloatRect ChromeClientImpl::pageRect()
169 // We hide the details of the window's border thickness from the web page by
170 // simple re-using the window position here. So, from the point-of-view of
171 // the web page, the window has no border.
175 void ChromeClientImpl::focus()
177 if (m_webView->client())
178 m_webView->client()->didFocus();
181 bool ChromeClientImpl::canTakeFocus(FocusType)
183 // For now the browser can always take focus if we're not running layout
185 return !layoutTestMode();
188 void ChromeClientImpl::takeFocus(FocusType type)
190 if (!m_webView->client())
192 if (type == FocusTypeBackward)
193 m_webView->client()->focusPrevious();
195 m_webView->client()->focusNext();
198 void ChromeClientImpl::focusedNodeChanged(Node* node)
200 m_webView->client()->focusedNodeChanged(WebNode(node));
203 if (node && node->isLink()) {
204 // This HitTestResult hack is the easiest way to get a link URL out of a
206 HitTestResult hitTest(IntPoint(0, 0));
207 // This cast must be valid because of the isLink() check.
208 hitTest.setURLElement(toElement(node));
209 if (hitTest.isLiveLink())
210 focusURL = hitTest.absoluteLinkURL();
212 m_webView->client()->setKeyboardFocusURL(focusURL);
215 void ChromeClientImpl::focusedFrameChanged(WebCore::LocalFrame* frame)
217 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
218 if (webframe && webframe->client())
219 webframe->client()->frameFocused();
222 Page* ChromeClientImpl::createWindow(LocalFrame* frame, const FrameLoadRequest& r, const WindowFeatures& features,
223 NavigationPolicy navigationPolicy, ShouldSendReferrer shouldSendReferrer)
225 if (!m_webView->client())
228 WebNavigationPolicy policy = static_cast<WebNavigationPolicy>(navigationPolicy);
229 if (policy == WebNavigationPolicyIgnore)
230 policy = getNavigationPolicy();
232 ASSERT(frame->document());
233 DocumentFullscreen::webkitCancelFullScreen(*frame->document());
235 WebViewImpl* newView = toWebViewImpl(
236 m_webView->client()->createView(WebLocalFrameImpl::fromFrame(frame), WrappedResourceRequest(r.resourceRequest()), features, r.frameName(), policy, shouldSendReferrer == NeverSendReferrer));
239 return newView->page();
242 static inline void updatePolicyForEvent(const WebInputEvent* inputEvent, NavigationPolicy* policy)
244 if (!inputEvent || inputEvent->type != WebInputEvent::MouseUp)
247 const WebMouseEvent* mouseEvent = static_cast<const WebMouseEvent*>(inputEvent);
249 unsigned short buttonNumber;
250 switch (mouseEvent->button) {
251 case WebMouseEvent::ButtonLeft:
254 case WebMouseEvent::ButtonMiddle:
257 case WebMouseEvent::ButtonRight:
263 bool ctrl = mouseEvent->modifiers & WebMouseEvent::ControlKey;
264 bool shift = mouseEvent->modifiers & WebMouseEvent::ShiftKey;
265 bool alt = mouseEvent->modifiers & WebMouseEvent::AltKey;
266 bool meta = mouseEvent->modifiers & WebMouseEvent::MetaKey;
268 NavigationPolicy userPolicy = *policy;
269 navigationPolicyFromMouseEvent(buttonNumber, ctrl, shift, alt, meta, &userPolicy);
270 // User and app agree that we want a new window; let the app override the decorations.
271 if (userPolicy == NavigationPolicyNewWindow && *policy == NavigationPolicyNewPopup)
273 *policy = userPolicy;
276 WebNavigationPolicy ChromeClientImpl::getNavigationPolicy()
278 // If our default configuration was modified by a script or wasn't
279 // created by a user gesture, then show as a popup. Else, let this
280 // new window be opened as a toplevel window.
281 bool asPopup = !m_toolbarsVisible
282 || !m_statusbarVisible
283 || !m_scrollbarsVisible
287 NavigationPolicy policy = NavigationPolicyNewForegroundTab;
289 policy = NavigationPolicyNewPopup;
290 updatePolicyForEvent(WebViewImpl::currentInputEvent(), &policy);
292 return static_cast<WebNavigationPolicy>(policy);
295 void ChromeClientImpl::show(NavigationPolicy navigationPolicy)
297 if (!m_webView->client())
300 WebNavigationPolicy policy = static_cast<WebNavigationPolicy>(navigationPolicy);
301 if (policy == WebNavigationPolicyIgnore)
302 policy = getNavigationPolicy();
303 m_webView->client()->show(policy);
306 bool ChromeClientImpl::canRunModal()
308 return !!m_webView->client();
311 void ChromeClientImpl::runModal()
313 if (m_webView->client())
314 m_webView->client()->runModal();
317 void ChromeClientImpl::setToolbarsVisible(bool value)
319 m_toolbarsVisible = value;
322 bool ChromeClientImpl::toolbarsVisible()
324 return m_toolbarsVisible;
327 void ChromeClientImpl::setStatusbarVisible(bool value)
329 m_statusbarVisible = value;
332 bool ChromeClientImpl::statusbarVisible()
334 return m_statusbarVisible;
337 void ChromeClientImpl::setScrollbarsVisible(bool value)
339 m_scrollbarsVisible = value;
340 WebLocalFrameImpl* webFrame = toWebLocalFrameImpl(m_webView->mainFrame());
342 webFrame->setCanHaveScrollbars(value);
345 bool ChromeClientImpl::scrollbarsVisible()
347 return m_scrollbarsVisible;
350 void ChromeClientImpl::setMenubarVisible(bool value)
352 m_menubarVisible = value;
355 bool ChromeClientImpl::menubarVisible()
357 return m_menubarVisible;
360 void ChromeClientImpl::setResizable(bool value)
365 bool ChromeClientImpl::shouldReportDetailedMessageForSource(const String& url)
367 WebLocalFrameImpl* webframe = m_webView->mainFrameImpl();
368 return webframe->client() && webframe->client()->shouldReportDetailedMessageForSource(url);
371 void ChromeClientImpl::addMessageToConsole(LocalFrame* localFrame, MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID, const String& stackTrace)
373 WebLocalFrameImpl* frame = WebLocalFrameImpl::fromFrame(localFrame);
374 if (frame && frame->client()) {
375 frame->client()->didAddMessageToConsole(
376 WebConsoleMessage(static_cast<WebConsoleMessage::Level>(level), message),
383 bool ChromeClientImpl::canRunBeforeUnloadConfirmPanel()
385 return !!m_webView->client();
388 bool ChromeClientImpl::runBeforeUnloadConfirmPanel(const String& message, LocalFrame* frame)
390 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
392 bool isReload = false;
393 WebDataSource* ds = webframe->provisionalDataSource();
395 isReload = (ds->navigationType() == blink::WebNavigationTypeReload);
397 if (webframe->client())
398 return webframe->client()->runModalBeforeUnloadDialog(isReload, message);
402 void ChromeClientImpl::closeWindowSoon()
404 // Make sure this Page can no longer be found by JS.
405 Page::ordinaryPages().remove(m_webView->page());
407 // Make sure that all loading is stopped. Ensures that JS stops executing!
408 m_webView->mainFrame()->stopLoading();
410 if (m_webView->client())
411 m_webView->client()->closeWidgetSoon();
414 // Although a LocalFrame is passed in, we don't actually use it, since we
415 // already know our own m_webView.
416 void ChromeClientImpl::runJavaScriptAlert(LocalFrame* frame, const String& message)
418 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
419 if (webframe->client()) {
420 if (WebUserGestureIndicator::isProcessingUserGesture())
421 WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
422 webframe->client()->runModalAlertDialog(message);
426 // See comments for runJavaScriptAlert().
427 bool ChromeClientImpl::runJavaScriptConfirm(LocalFrame* frame, const String& message)
429 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
430 if (webframe->client()) {
431 if (WebUserGestureIndicator::isProcessingUserGesture())
432 WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
433 return webframe->client()->runModalConfirmDialog(message);
438 // See comments for runJavaScriptAlert().
439 bool ChromeClientImpl::runJavaScriptPrompt(LocalFrame* frame,
440 const String& message,
441 const String& defaultValue,
444 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
445 if (webframe->client()) {
446 if (WebUserGestureIndicator::isProcessingUserGesture())
447 WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
448 WebString actualValue;
449 bool ok = webframe->client()->runModalPromptDialog(
454 result = actualValue;
460 void ChromeClientImpl::setStatusbarText(const String& message)
462 if (m_webView->client())
463 m_webView->client()->setStatusText(message);
466 bool ChromeClientImpl::tabsToLinks()
468 return m_webView->tabsToLinks();
471 IntRect ChromeClientImpl::windowResizerRect() const
474 if (m_webView->client())
475 result = m_webView->client()->windowResizerRect();
479 void ChromeClientImpl::invalidateContentsAndRootView(const IntRect& updateRect)
481 if (updateRect.isEmpty())
483 m_webView->invalidateRect(updateRect);
486 void ChromeClientImpl::invalidateContentsForSlowScroll(const IntRect& updateRect)
488 invalidateContentsAndRootView(updateRect);
491 void ChromeClientImpl::scheduleAnimation()
493 m_webView->scheduleAnimation();
496 void ChromeClientImpl::scroll(
497 const IntSize& scrollDelta, const IntRect& scrollRect,
498 const IntRect& clipRect)
500 if (!m_webView->isAcceleratedCompositingActive()) {
501 if (m_webView->client()) {
502 int dx = scrollDelta.width();
503 int dy = scrollDelta.height();
504 m_webView->client()->didScrollRect(dx, dy, intersection(scrollRect, clipRect));
507 m_webView->scrollRootLayer();
511 IntRect ChromeClientImpl::rootViewToScreen(const IntRect& rect) const
513 IntRect screenRect(rect);
515 if (m_webView->client()) {
516 WebRect windowRect = m_webView->client()->windowRect();
517 screenRect.move(windowRect.x, windowRect.y);
523 WebScreenInfo ChromeClientImpl::screenInfo() const
525 return m_webView->client() ? m_webView->client()->screenInfo() : WebScreenInfo();
528 void ChromeClientImpl::contentsSizeChanged(LocalFrame* frame, const IntSize& size) const
530 m_webView->didChangeContentsSize();
532 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
533 webframe->didChangeContentsSize(size);
535 frame->loader().restoreScrollPositionAndViewState();
538 void ChromeClientImpl::deviceOrPageScaleFactorChanged() const
540 m_webView->deviceOrPageScaleFactorChanged();
543 void ChromeClientImpl::layoutUpdated(LocalFrame* frame) const
545 m_webView->layoutUpdated(WebLocalFrameImpl::fromFrame(frame));
548 void ChromeClientImpl::mouseDidMoveOverElement(
549 const HitTestResult& result, unsigned modifierFlags)
551 if (!m_webView->client())
555 // Find out if the mouse is over a link, and if so, let our UI know...
556 if (result.isLiveLink() && !result.absoluteLinkURL().string().isEmpty()) {
557 url = result.absoluteLinkURL();
558 } else if (result.innerNonSharedNode()
559 && (isHTMLObjectElement(*result.innerNonSharedNode())
560 || isHTMLEmbedElement(*result.innerNonSharedNode()))) {
561 RenderObject* object = result.innerNonSharedNode()->renderer();
562 if (object && object->isWidget()) {
563 Widget* widget = toRenderWidget(object)->widget();
564 if (widget && widget->isPluginContainer()) {
565 WebPluginContainerImpl* plugin = toWebPluginContainerImpl(widget);
566 url = plugin->plugin()->linkAtPosition(result.roundedPointInInnerNodeFrame());
571 m_webView->client()->setMouseOverURL(url);
574 void ChromeClientImpl::setToolTip(const String& tooltipText, TextDirection dir)
576 if (!m_webView->client())
578 WebTextDirection textDirection = (dir == RTL) ?
579 WebTextDirectionRightToLeft :
580 WebTextDirectionLeftToRight;
581 m_webView->client()->setToolTipText(
582 tooltipText, textDirection);
585 void ChromeClientImpl::dispatchViewportPropertiesDidChange(const ViewportDescription& description) const
587 m_webView->updatePageDefinedViewportConstraints(description);
590 void ChromeClientImpl::print(LocalFrame* frame)
592 if (m_webView->client())
593 m_webView->client()->printPage(WebLocalFrameImpl::fromFrame(frame));
596 PassOwnPtr<ColorChooser> ChromeClientImpl::createColorChooser(LocalFrame* frame, ColorChooserClient* chooserClient, const Color&)
598 OwnPtr<ColorChooserUIController> controller;
599 if (RuntimeEnabledFeatures::pagePopupEnabled())
600 controller = adoptPtr(new ColorChooserPopupUIController(frame, this, chooserClient));
602 controller = adoptPtr(new ColorChooserUIController(frame, chooserClient));
603 controller->openUI();
604 return controller.release();
607 PassRefPtrWillBeRawPtr<DateTimeChooser> ChromeClientImpl::openDateTimeChooser(DateTimeChooserClient* pickerClient, const DateTimeChooserParameters& parameters)
609 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
610 return DateTimeChooserImpl::create(this, pickerClient, parameters);
612 return ExternalDateTimeChooser::create(this, m_webView->client(), pickerClient, parameters);
616 void ChromeClientImpl::runOpenPanel(LocalFrame* frame, PassRefPtr<FileChooser> fileChooser)
618 WebViewClient* client = m_webView->client();
622 WebFileChooserParams params;
623 params.multiSelect = fileChooser->settings().allowsMultipleFiles;
624 params.directory = fileChooser->settings().allowsDirectoryUpload;
625 params.acceptTypes = fileChooser->settings().acceptTypes();
626 params.selectedFiles = fileChooser->settings().selectedFiles;
627 if (params.selectedFiles.size() > 0)
628 params.initialValue = params.selectedFiles[0];
629 #if ENABLE(MEDIA_CAPTURE)
630 params.useMediaCapture = fileChooser->settings().useMediaCapture;
632 WebFileChooserCompletionImpl* chooserCompletion =
633 new WebFileChooserCompletionImpl(fileChooser);
635 if (client->runFileChooser(params, chooserCompletion))
638 // Choosing failed, so do callback with an empty list.
639 chooserCompletion->didChooseFile(WebVector<WebString>());
642 void ChromeClientImpl::enumerateChosenDirectory(FileChooser* fileChooser)
644 WebViewClient* client = m_webView->client();
648 WebFileChooserCompletionImpl* chooserCompletion =
649 new WebFileChooserCompletionImpl(fileChooser);
651 ASSERT(fileChooser && fileChooser->settings().selectedFiles.size());
653 // If the enumeration can't happen, call the callback with an empty list.
654 if (!client->enumerateChosenDirectory(fileChooser->settings().selectedFiles[0], chooserCompletion))
655 chooserCompletion->didChooseFile(WebVector<WebString>());
658 void ChromeClientImpl::setCursor(const WebCore::Cursor& cursor)
660 setCursor(WebCursorInfo(cursor));
663 void ChromeClientImpl::setCursor(const WebCursorInfo& cursor)
666 // On Mac the mousemove event propagates to both the popup and main window.
667 // If a popup is open we don't want the main window to change the cursor.
668 if (m_webView->hasOpenedPopup())
671 if (m_webView->client())
672 m_webView->client()->didChangeCursor(cursor);
675 void ChromeClientImpl::setCursorForPlugin(const WebCursorInfo& cursor)
680 void ChromeClientImpl::postAccessibilityNotification(AXObject* obj, AXObjectCache::AXNotification notification)
682 // Alert assistive technology about the accessibility object notification.
685 if (m_webView->client())
686 m_webView->client()->postAccessibilityEvent(WebAXObject(obj), toWebAXEvent(notification));
689 String ChromeClientImpl::acceptLanguages()
691 return m_webView->client()->acceptLanguages();
694 bool ChromeClientImpl::paintCustomOverhangArea(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
696 LocalFrame* frame = m_webView->mainFrameImpl()->frame();
697 WebPluginContainerImpl* pluginContainer = WebLocalFrameImpl::pluginContainerFromFrame(frame);
699 return pluginContainer->paintCustomOverhangArea(context, horizontalOverhangArea, verticalOverhangArea, dirtyRect);
703 GraphicsLayerFactory* ChromeClientImpl::graphicsLayerFactory() const
705 return m_webView->graphicsLayerFactory();
708 void ChromeClientImpl::attachRootGraphicsLayer(GraphicsLayer* rootLayer)
710 m_webView->setRootGraphicsLayer(rootLayer);
713 void ChromeClientImpl::enterFullScreenForElement(Element* element)
715 m_webView->enterFullScreenForElement(element);
718 void ChromeClientImpl::exitFullScreenForElement(Element* element)
720 m_webView->exitFullScreenForElement(element);
723 bool ChromeClientImpl::hasOpenedPopup() const
725 return m_webView->hasOpenedPopup();
728 PassRefPtr<PopupMenu> ChromeClientImpl::createPopupMenu(LocalFrame& frame, PopupMenuClient* client) const
730 if (WebViewImpl::useExternalPopupMenus())
731 return adoptRef(new ExternalPopupMenu(frame, client, *m_webView));
733 return adoptRef(new PopupMenuChromium(frame, client));
736 PagePopup* ChromeClientImpl::openPagePopup(PagePopupClient* client, const IntRect& originBoundsInRootView)
738 ASSERT(m_pagePopupDriver);
739 return m_pagePopupDriver->openPagePopup(client, originBoundsInRootView);
742 void ChromeClientImpl::closePagePopup(PagePopup* popup)
744 ASSERT(m_pagePopupDriver);
745 m_pagePopupDriver->closePagePopup(popup);
748 void ChromeClientImpl::setPagePopupDriver(PagePopupDriver* driver)
751 m_pagePopupDriver = driver;
754 void ChromeClientImpl::resetPagePopupDriver()
756 m_pagePopupDriver = m_webView;
759 bool ChromeClientImpl::shouldRunModalDialogDuringPageDismissal(const DialogType& dialogType, const String& dialogMessage, Document::PageDismissalType dismissalType) const
761 const char* kDialogs[] = {"alert", "confirm", "prompt", "showModalDialog"};
762 int dialog = static_cast<int>(dialogType);
763 ASSERT_WITH_SECURITY_IMPLICATION(0 <= dialog && dialog < static_cast<int>(arraysize(kDialogs)));
765 const char* kDismissals[] = {"beforeunload", "pagehide", "unload"};
766 int dismissal = static_cast<int>(dismissalType) - 1; // Exclude NoDismissal.
767 ASSERT_WITH_SECURITY_IMPLICATION(0 <= dismissal && dismissal < static_cast<int>(arraysize(kDismissals)));
769 blink::Platform::current()->histogramEnumeration("Renderer.ModalDialogsDuringPageDismissal", dismissal * arraysize(kDialogs) + dialog, arraysize(kDialogs) * arraysize(kDismissals));
771 String message = String("Blocked ") + kDialogs[dialog] + "('" + dialogMessage + "') during " + kDismissals[dismissal] + ".";
772 m_webView->mainFrame()->addMessageToConsole(WebConsoleMessage(WebConsoleMessage::LevelError, message));
777 void ChromeClientImpl::needTouchEvents(bool needsTouchEvents)
779 m_webView->hasTouchEventHandlers(needsTouchEvents);
782 void ChromeClientImpl::setTouchAction(TouchAction touchAction)
784 if (WebViewClient* client = m_webView->client()) {
785 WebTouchAction webTouchAction = static_cast<WebTouchAction>(touchAction);
786 client->setTouchAction(webTouchAction);
790 bool ChromeClientImpl::requestPointerLock()
792 return m_webView->requestPointerLock();
795 void ChromeClientImpl::requestPointerUnlock()
797 return m_webView->requestPointerUnlock();
800 void ChromeClientImpl::annotatedRegionsChanged()
802 WebViewClient* client = m_webView->client();
804 client->draggableRegionsChanged();
807 void ChromeClientImpl::didAssociateFormControls(const WillBeHeapVector<RefPtrWillBeMember<Element> >& elements)
809 if (m_webView->autofillClient())
810 m_webView->autofillClient()->didAssociateFormControls(elements);
813 void ChromeClientImpl::didCancelCompositionOnSelectionChange()
815 if (m_webView->client())
816 m_webView->client()->didCancelCompositionOnSelectionChange();
819 void ChromeClientImpl::willSetInputMethodState()
821 if (m_webView->client())
822 m_webView->client()->resetInputMethod();
825 void ChromeClientImpl::didUpdateTextOfFocusedElementByNonUserInput()
827 if (m_webView->client())
828 m_webView->client()->didUpdateTextOfFocusedElementByNonUserInput();
831 void ChromeClientImpl::handleKeyboardEventOnTextField(HTMLInputElement& inputElement, KeyboardEvent& event)
833 if (!m_webView->autofillClient())
835 m_webView->autofillClient()->textFieldDidReceiveKeyDown(WebInputElement(&inputElement), WebKeyboardEventBuilder(event));
838 // FIXME: Remove this code once we have input routing in the browser
839 // process. See http://crbug.com/339659.
840 void ChromeClientImpl::forwardInputEvent(
841 WebCore::Frame* frame, WebCore::Event* event)
843 WebLocalFrameImpl* webFrame = WebLocalFrameImpl::fromFrame(toLocalFrameTemporary(frame));
845 // This is only called when we have out-of-process iframes, which
846 // need to forward input events across processes.
847 // FIXME: Add a check for out-of-process iframes enabled.
848 if (event->isKeyboardEvent()) {
849 WebKeyboardEventBuilder webEvent(*static_cast<WebCore::KeyboardEvent*>(event));
850 webFrame->client()->forwardInputEvent(&webEvent);
851 } else if (event->isMouseEvent()) {
852 WebMouseEventBuilder webEvent(webFrame->frameView(), frame->ownerRenderer(), *static_cast<WebCore::MouseEvent*>(event));
853 // Internal Blink events should not be forwarded.
854 if (webEvent.type == WebInputEvent::Undefined)
857 webFrame->client()->forwardInputEvent(&webEvent);
858 } else if (event->isWheelEvent()) {
859 WebMouseWheelEventBuilder webEvent(webFrame->frameView(), frame->ownerRenderer(), *static_cast<WebCore::WheelEvent*>(event));
860 if (webEvent.type == WebInputEvent::Undefined)
862 webFrame->client()->forwardInputEvent(&webEvent);
866 void ChromeClientImpl::didChangeValueInTextField(HTMLFormControlElement& element)
868 if (!m_webView->autofillClient())
870 m_webView->autofillClient()->textFieldDidChange(WebFormControlElement(&element));
873 void ChromeClientImpl::didEndEditingOnTextField(HTMLInputElement& inputElement)
875 if (m_webView->autofillClient())
876 m_webView->autofillClient()->textFieldDidEndEditing(WebInputElement(&inputElement));
879 void ChromeClientImpl::openTextDataListChooser(HTMLInputElement& input)
881 if (m_webView->autofillClient())
882 m_webView->autofillClient()->openTextDataListChooser(WebInputElement(&input));
885 bool ChromeClientImpl::usesGpuRasterization()
887 return m_webView->layerTreeView()->usesGpuRasterization();