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/FullscreenElementStack.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/RenderPart.h"
56 #include "core/rendering/RenderWidget.h"
57 #include "platform/ColorChooser.h"
58 #include "platform/ColorChooserClient.h"
59 #include "platform/Cursor.h"
60 #include "platform/DateTimeChooser.h"
61 #include "platform/FileChooser.h"
62 #include "platform/NotImplemented.h"
63 #include "platform/PlatformScreen.h"
64 #include "platform/RuntimeEnabledFeatures.h"
65 #include "platform/exported/WrappedResourceRequest.h"
66 #include "platform/geometry/FloatRect.h"
67 #include "platform/geometry/IntRect.h"
68 #include "platform/graphics/GraphicsLayer.h"
69 #include "platform/weborigin/SecurityOrigin.h"
70 #include "public/platform/Platform.h"
71 #include "public/platform/WebCursorInfo.h"
72 #include "public/platform/WebRect.h"
73 #include "public/platform/WebURLRequest.h"
74 #include "public/web/WebAXObject.h"
75 #include "public/web/WebAutofillClient.h"
76 #include "public/web/WebColorChooser.h"
77 #include "public/web/WebColorSuggestion.h"
78 #include "public/web/WebConsoleMessage.h"
79 #include "public/web/WebFrameClient.h"
80 #include "public/web/WebInputElement.h"
81 #include "public/web/WebInputEvent.h"
82 #include "public/web/WebKit.h"
83 #include "public/web/WebNode.h"
84 #include "public/web/WebPlugin.h"
85 #include "public/web/WebPopupMenuInfo.h"
86 #include "public/web/WebSettings.h"
87 #include "public/web/WebTextDirection.h"
88 #include "public/web/WebTouchAction.h"
89 #include "public/web/WebUserGestureIndicator.h"
90 #include "public/web/WebUserGestureToken.h"
91 #include "public/web/WebViewClient.h"
92 #include "public/web/WebWindowFeatures.h"
93 #include "web/ColorChooserPopupUIController.h"
94 #include "web/ColorChooserUIController.h"
95 #include "web/DateTimeChooserImpl.h"
96 #include "web/ExternalDateTimeChooser.h"
97 #include "web/ExternalPopupMenu.h"
98 #include "web/PopupMenuChromium.h"
99 #include "web/WebFileChooserCompletionImpl.h"
100 #include "web/WebInputEventConversion.h"
101 #include "web/WebLocalFrameImpl.h"
102 #include "web/WebPluginContainerImpl.h"
103 #include "web/WebPopupMenuImpl.h"
104 #include "web/WebSettingsImpl.h"
105 #include "web/WebViewImpl.h"
106 #include "wtf/text/CString.h"
107 #include "wtf/text/StringBuilder.h"
108 #include "wtf/text/StringConcatenate.h"
109 #include "wtf/unicode/CharacterNames.h"
113 // Converts a AXObjectCache::AXNotification to a WebAXEvent
114 static WebAXEvent toWebAXEvent(AXObjectCache::AXNotification notification)
116 // These enums have the same values; enforced in AssertMatchingEnums.cpp.
117 return static_cast<WebAXEvent>(notification);
120 ChromeClientImpl::ChromeClientImpl(WebViewImpl* webView)
122 , m_toolbarsVisible(true)
123 , m_statusbarVisible(true)
124 , m_scrollbarsVisible(true)
125 , m_menubarVisible(true)
127 , m_pagePopupDriver(webView)
131 ChromeClientImpl::~ChromeClientImpl()
135 void* ChromeClientImpl::webView() const
137 return static_cast<void*>(m_webView);
140 void ChromeClientImpl::chromeDestroyed()
142 // Our lifetime is bound to the WebViewImpl.
145 void ChromeClientImpl::setWindowRect(const FloatRect& r)
147 if (m_webView->client())
148 m_webView->client()->setWindowRect(IntRect(r));
151 FloatRect ChromeClientImpl::windowRect()
154 if (m_webView->client())
155 rect = m_webView->client()->rootWindowRect();
157 // These numbers will be fairly wrong. The window's x/y coordinates will
158 // be the top left corner of the screen and the size will be the content
159 // size instead of the window size.
160 rect.width = m_webView->size().width;
161 rect.height = m_webView->size().height;
163 return FloatRect(rect);
166 FloatRect ChromeClientImpl::pageRect()
168 // We hide the details of the window's border thickness from the web page by
169 // simple re-using the window position here. So, from the point-of-view of
170 // the web page, the window has no border.
174 void ChromeClientImpl::focus()
176 if (m_webView->client())
177 m_webView->client()->didFocus();
180 bool ChromeClientImpl::canTakeFocus(FocusType)
182 // For now the browser can always take focus if we're not running layout
184 return !layoutTestMode();
187 void ChromeClientImpl::takeFocus(FocusType type)
189 if (!m_webView->client())
191 if (type == FocusTypeBackward)
192 m_webView->client()->focusPrevious();
194 m_webView->client()->focusNext();
197 void ChromeClientImpl::focusedNodeChanged(Node* node)
199 m_webView->client()->focusedNodeChanged(WebNode(node));
202 if (node && node->isElementNode() && toElement(node)->isLiveLink())
203 focusURL = toElement(node)->hrefURL();
204 m_webView->client()->setKeyboardFocusURL(focusURL);
207 void ChromeClientImpl::focusedFrameChanged(LocalFrame* frame)
209 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
210 if (webframe && webframe->client())
211 webframe->client()->frameFocused();
214 Page* ChromeClientImpl::createWindow(LocalFrame* frame, const FrameLoadRequest& r, const WindowFeatures& features,
215 NavigationPolicy navigationPolicy, ShouldSendReferrer shouldSendReferrer)
217 if (!m_webView->client())
220 WebNavigationPolicy policy = static_cast<WebNavigationPolicy>(navigationPolicy);
221 if (policy == WebNavigationPolicyIgnore)
222 policy = getNavigationPolicy();
224 ASSERT(frame->document());
225 FullscreenElementStack::from(*frame->document()).fullyExitFullscreen();
227 WebViewImpl* newView = toWebViewImpl(
228 m_webView->client()->createView(WebLocalFrameImpl::fromFrame(frame), WrappedResourceRequest(r.resourceRequest()), features, r.frameName(), policy, shouldSendReferrer == NeverSendReferrer));
231 return newView->page();
234 static inline void updatePolicyForEvent(const WebInputEvent* inputEvent, NavigationPolicy* policy)
236 if (!inputEvent || inputEvent->type != WebInputEvent::MouseUp)
239 const WebMouseEvent* mouseEvent = static_cast<const WebMouseEvent*>(inputEvent);
241 unsigned short buttonNumber;
242 switch (mouseEvent->button) {
243 case WebMouseEvent::ButtonLeft:
246 case WebMouseEvent::ButtonMiddle:
249 case WebMouseEvent::ButtonRight:
255 bool ctrl = mouseEvent->modifiers & WebMouseEvent::ControlKey;
256 bool shift = mouseEvent->modifiers & WebMouseEvent::ShiftKey;
257 bool alt = mouseEvent->modifiers & WebMouseEvent::AltKey;
258 bool meta = mouseEvent->modifiers & WebMouseEvent::MetaKey;
260 NavigationPolicy userPolicy = *policy;
261 navigationPolicyFromMouseEvent(buttonNumber, ctrl, shift, alt, meta, &userPolicy);
262 // User and app agree that we want a new window; let the app override the decorations.
263 if (userPolicy == NavigationPolicyNewWindow && *policy == NavigationPolicyNewPopup)
265 *policy = userPolicy;
268 WebNavigationPolicy ChromeClientImpl::getNavigationPolicy()
270 // If our default configuration was modified by a script or wasn't
271 // created by a user gesture, then show as a popup. Else, let this
272 // new window be opened as a toplevel window.
273 bool asPopup = !m_toolbarsVisible
274 || !m_statusbarVisible
275 || !m_scrollbarsVisible
279 NavigationPolicy policy = NavigationPolicyNewForegroundTab;
281 policy = NavigationPolicyNewPopup;
282 updatePolicyForEvent(WebViewImpl::currentInputEvent(), &policy);
284 return static_cast<WebNavigationPolicy>(policy);
287 void ChromeClientImpl::show(NavigationPolicy navigationPolicy)
289 if (!m_webView->client())
292 WebNavigationPolicy policy = static_cast<WebNavigationPolicy>(navigationPolicy);
293 if (policy == WebNavigationPolicyIgnore)
294 policy = getNavigationPolicy();
295 m_webView->client()->show(policy);
298 bool ChromeClientImpl::canRunModal()
300 return !!m_webView->client();
303 void ChromeClientImpl::runModal()
305 if (m_webView->client())
306 m_webView->client()->runModal();
309 void ChromeClientImpl::setToolbarsVisible(bool value)
311 m_toolbarsVisible = value;
314 bool ChromeClientImpl::toolbarsVisible()
316 return m_toolbarsVisible;
319 void ChromeClientImpl::setStatusbarVisible(bool value)
321 m_statusbarVisible = value;
324 bool ChromeClientImpl::statusbarVisible()
326 return m_statusbarVisible;
329 void ChromeClientImpl::setScrollbarsVisible(bool value)
331 m_scrollbarsVisible = value;
332 WebLocalFrameImpl* webFrame = toWebLocalFrameImpl(m_webView->mainFrame());
334 webFrame->setCanHaveScrollbars(value);
337 bool ChromeClientImpl::scrollbarsVisible()
339 return m_scrollbarsVisible;
342 void ChromeClientImpl::setMenubarVisible(bool value)
344 m_menubarVisible = value;
347 bool ChromeClientImpl::menubarVisible()
349 return m_menubarVisible;
352 void ChromeClientImpl::setResizable(bool value)
357 bool ChromeClientImpl::shouldReportDetailedMessageForSource(const String& url)
359 WebLocalFrameImpl* webframe = m_webView->localFrameRootTemporary();
360 return webframe->client() && webframe->client()->shouldReportDetailedMessageForSource(url);
363 void ChromeClientImpl::addMessageToConsole(LocalFrame* localFrame, MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID, const String& stackTrace)
365 WebLocalFrameImpl* frame = WebLocalFrameImpl::fromFrame(localFrame);
366 if (frame && frame->client()) {
367 frame->client()->didAddMessageToConsole(
368 WebConsoleMessage(static_cast<WebConsoleMessage::Level>(level), message),
375 bool ChromeClientImpl::canRunBeforeUnloadConfirmPanel()
377 return !!m_webView->client();
380 bool ChromeClientImpl::runBeforeUnloadConfirmPanel(const String& message, LocalFrame* frame)
382 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
384 bool isReload = false;
385 WebDataSource* ds = webframe->provisionalDataSource();
387 isReload = (ds->navigationType() == WebNavigationTypeReload);
389 if (webframe->client())
390 return webframe->client()->runModalBeforeUnloadDialog(isReload, message);
394 void ChromeClientImpl::closeWindowSoon()
396 // Make sure this Page can no longer be found by JS.
397 Page::ordinaryPages().remove(m_webView->page());
399 // Make sure that all loading is stopped. Ensures that JS stops executing!
400 m_webView->mainFrame()->stopLoading();
402 if (m_webView->client())
403 m_webView->client()->closeWidgetSoon();
406 // Although a LocalFrame is passed in, we don't actually use it, since we
407 // already know our own m_webView.
408 void ChromeClientImpl::runJavaScriptAlert(LocalFrame* frame, const String& message)
410 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
411 if (webframe->client()) {
412 if (WebUserGestureIndicator::isProcessingUserGesture())
413 WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
414 webframe->client()->runModalAlertDialog(message);
418 // See comments for runJavaScriptAlert().
419 bool ChromeClientImpl::runJavaScriptConfirm(LocalFrame* frame, const String& message)
421 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
422 if (webframe->client()) {
423 if (WebUserGestureIndicator::isProcessingUserGesture())
424 WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
425 return webframe->client()->runModalConfirmDialog(message);
430 // See comments for runJavaScriptAlert().
431 bool ChromeClientImpl::runJavaScriptPrompt(LocalFrame* frame,
432 const String& message,
433 const String& defaultValue,
436 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
437 if (webframe->client()) {
438 if (WebUserGestureIndicator::isProcessingUserGesture())
439 WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
440 WebString actualValue;
441 bool ok = webframe->client()->runModalPromptDialog(
446 result = actualValue;
452 void ChromeClientImpl::setStatusbarText(const String& message)
454 if (m_webView->client())
455 m_webView->client()->setStatusText(message);
458 bool ChromeClientImpl::tabsToLinks()
460 return m_webView->tabsToLinks();
463 IntRect ChromeClientImpl::windowResizerRect() const
466 if (m_webView->client())
467 result = m_webView->client()->windowResizerRect();
471 void ChromeClientImpl::invalidateContentsAndRootView(const IntRect& updateRect)
473 if (updateRect.isEmpty())
475 m_webView->invalidateRect(updateRect);
478 void ChromeClientImpl::invalidateContentsForSlowScroll(const IntRect& updateRect)
480 invalidateContentsAndRootView(updateRect);
483 void ChromeClientImpl::scheduleAnimation()
485 m_webView->scheduleAnimation();
488 void ChromeClientImpl::scroll()
490 if (m_webView->isAcceleratedCompositingActive())
491 m_webView->scrollRootLayer();
494 IntRect ChromeClientImpl::rootViewToScreen(const IntRect& rect) const
496 IntRect screenRect(rect);
498 if (m_webView->client()) {
499 WebRect windowRect = m_webView->client()->windowRect();
500 screenRect.move(windowRect.x, windowRect.y);
506 WebScreenInfo ChromeClientImpl::screenInfo() const
508 return m_webView->client() ? m_webView->client()->screenInfo() : WebScreenInfo();
511 void ChromeClientImpl::contentsSizeChanged(LocalFrame* frame, const IntSize& size) const
513 m_webView->didChangeContentsSize();
515 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
516 webframe->didChangeContentsSize(size);
518 frame->loader().restoreScrollPositionAndViewState();
521 void ChromeClientImpl::deviceOrPageScaleFactorChanged() const
523 m_webView->deviceOrPageScaleFactorChanged();
526 void ChromeClientImpl::layoutUpdated(LocalFrame* frame) const
528 m_webView->layoutUpdated(WebLocalFrameImpl::fromFrame(frame));
531 void ChromeClientImpl::mouseDidMoveOverElement(
532 const HitTestResult& result, unsigned modifierFlags)
534 if (!m_webView->client())
538 // Find out if the mouse is over a link, and if so, let our UI know...
539 if (result.isLiveLink() && !result.absoluteLinkURL().string().isEmpty()) {
540 url = result.absoluteLinkURL();
541 } else if (result.innerNonSharedNode()
542 && (isHTMLObjectElement(*result.innerNonSharedNode())
543 || isHTMLEmbedElement(*result.innerNonSharedNode()))) {
544 RenderObject* object = result.innerNonSharedNode()->renderer();
545 if (object && object->isWidget()) {
546 Widget* widget = toRenderWidget(object)->widget();
547 if (widget && widget->isPluginContainer()) {
548 WebPluginContainerImpl* plugin = toWebPluginContainerImpl(widget);
549 url = plugin->plugin()->linkAtPosition(result.roundedPointInInnerNodeFrame());
554 m_webView->client()->setMouseOverURL(url);
557 void ChromeClientImpl::setToolTip(const String& tooltipText, TextDirection dir)
559 if (m_webView->client())
560 m_webView->client()->setToolTipText(tooltipText, toWebTextDirection(dir));
563 void ChromeClientImpl::dispatchViewportPropertiesDidChange(const ViewportDescription& description) const
565 m_webView->updatePageDefinedViewportConstraints(description);
568 void ChromeClientImpl::print(LocalFrame* frame)
570 if (m_webView->client())
571 m_webView->client()->printPage(WebLocalFrameImpl::fromFrame(frame));
574 PassOwnPtr<ColorChooser> ChromeClientImpl::createColorChooser(LocalFrame* frame, ColorChooserClient* chooserClient, const Color&)
576 OwnPtr<ColorChooserUIController> controller;
577 if (RuntimeEnabledFeatures::pagePopupEnabled())
578 controller = adoptPtr(new ColorChooserPopupUIController(frame, this, chooserClient));
580 controller = adoptPtr(new ColorChooserUIController(frame, chooserClient));
581 controller->openUI();
582 return controller.release();
585 PassRefPtrWillBeRawPtr<DateTimeChooser> ChromeClientImpl::openDateTimeChooser(DateTimeChooserClient* pickerClient, const DateTimeChooserParameters& parameters)
587 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
588 return DateTimeChooserImpl::create(this, pickerClient, parameters);
590 return ExternalDateTimeChooser::create(this, m_webView->client(), pickerClient, parameters);
594 void ChromeClientImpl::runOpenPanel(LocalFrame* frame, PassRefPtr<FileChooser> fileChooser)
596 WebViewClient* client = m_webView->client();
600 WebFileChooserParams params;
601 params.multiSelect = fileChooser->settings().allowsMultipleFiles;
602 params.directory = fileChooser->settings().allowsDirectoryUpload;
603 params.acceptTypes = fileChooser->settings().acceptTypes();
604 params.selectedFiles = fileChooser->settings().selectedFiles;
605 if (params.selectedFiles.size() > 0)
606 params.initialValue = params.selectedFiles[0];
607 params.useMediaCapture = fileChooser->settings().useMediaCapture;
609 WebFileChooserCompletionImpl* chooserCompletion =
610 new WebFileChooserCompletionImpl(fileChooser);
612 if (client->runFileChooser(params, chooserCompletion))
615 // Choosing failed, so do callback with an empty list.
616 chooserCompletion->didChooseFile(WebVector<WebString>());
619 void ChromeClientImpl::enumerateChosenDirectory(FileChooser* fileChooser)
621 WebViewClient* client = m_webView->client();
625 WebFileChooserCompletionImpl* chooserCompletion =
626 new WebFileChooserCompletionImpl(fileChooser);
628 ASSERT(fileChooser && fileChooser->settings().selectedFiles.size());
630 // If the enumeration can't happen, call the callback with an empty list.
631 if (!client->enumerateChosenDirectory(fileChooser->settings().selectedFiles[0], chooserCompletion))
632 chooserCompletion->didChooseFile(WebVector<WebString>());
635 void ChromeClientImpl::setCursor(const Cursor& cursor)
637 setCursor(WebCursorInfo(cursor));
640 void ChromeClientImpl::setCursor(const WebCursorInfo& cursor)
643 // On Mac the mousemove event propagates to both the popup and main window.
644 // If a popup is open we don't want the main window to change the cursor.
645 if (m_webView->hasOpenedPopup())
648 if (m_webView->client())
649 m_webView->client()->didChangeCursor(cursor);
652 void ChromeClientImpl::setCursorForPlugin(const WebCursorInfo& cursor)
657 void ChromeClientImpl::postAccessibilityNotification(AXObject* obj, AXObjectCache::AXNotification notification)
659 // Alert assistive technology about the accessibility object notification.
662 if (m_webView->client())
663 m_webView->client()->postAccessibilityEvent(WebAXObject(obj), toWebAXEvent(notification));
666 String ChromeClientImpl::acceptLanguages()
668 return m_webView->client()->acceptLanguages();
671 bool ChromeClientImpl::paintCustomOverhangArea(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
673 LocalFrame* frame = m_webView->mainFrameImpl()->frame();
674 WebPluginContainerImpl* pluginContainer = WebLocalFrameImpl::pluginContainerFromFrame(frame);
676 return pluginContainer->paintCustomOverhangArea(context, horizontalOverhangArea, verticalOverhangArea, dirtyRect);
680 GraphicsLayerFactory* ChromeClientImpl::graphicsLayerFactory() const
682 return m_webView->graphicsLayerFactory();
685 void ChromeClientImpl::attachRootGraphicsLayer(GraphicsLayer* rootLayer)
687 m_webView->setRootGraphicsLayer(rootLayer);
690 void ChromeClientImpl::enterFullScreenForElement(Element* element)
692 m_webView->enterFullScreenForElement(element);
695 void ChromeClientImpl::exitFullScreenForElement(Element* element)
697 m_webView->exitFullScreenForElement(element);
700 void ChromeClientImpl::clearCompositedSelectionBounds()
702 m_webView->clearCompositedSelectionBounds();
705 bool ChromeClientImpl::hasOpenedPopup() const
707 return m_webView->hasOpenedPopup();
710 PassRefPtr<PopupMenu> ChromeClientImpl::createPopupMenu(LocalFrame& frame, PopupMenuClient* client) const
712 if (WebViewImpl::useExternalPopupMenus())
713 return adoptRef(new ExternalPopupMenu(frame, client, *m_webView));
715 return adoptRef(new PopupMenuChromium(frame, client));
718 PagePopup* ChromeClientImpl::openPagePopup(PagePopupClient* client, const IntRect& originBoundsInRootView)
720 ASSERT(m_pagePopupDriver);
721 return m_pagePopupDriver->openPagePopup(client, originBoundsInRootView);
724 void ChromeClientImpl::closePagePopup(PagePopup* popup)
726 ASSERT(m_pagePopupDriver);
727 m_pagePopupDriver->closePagePopup(popup);
730 void ChromeClientImpl::setPagePopupDriver(PagePopupDriver* driver)
733 m_pagePopupDriver = driver;
736 void ChromeClientImpl::resetPagePopupDriver()
738 m_pagePopupDriver = m_webView;
741 bool ChromeClientImpl::shouldRunModalDialogDuringPageDismissal(const DialogType& dialogType, const String& dialogMessage, Document::PageDismissalType dismissalType) const
743 const char* kDialogs[] = {"alert", "confirm", "prompt", "showModalDialog"};
744 int dialog = static_cast<int>(dialogType);
745 ASSERT_WITH_SECURITY_IMPLICATION(0 <= dialog && dialog < static_cast<int>(arraysize(kDialogs)));
747 const char* kDismissals[] = {"beforeunload", "pagehide", "unload"};
748 int dismissal = static_cast<int>(dismissalType) - 1; // Exclude NoDismissal.
749 ASSERT_WITH_SECURITY_IMPLICATION(0 <= dismissal && dismissal < static_cast<int>(arraysize(kDismissals)));
751 Platform::current()->histogramEnumeration("Renderer.ModalDialogsDuringPageDismissal", dismissal * arraysize(kDialogs) + dialog, arraysize(kDialogs) * arraysize(kDismissals));
753 String message = String("Blocked ") + kDialogs[dialog] + "('" + dialogMessage + "') during " + kDismissals[dismissal] + ".";
754 m_webView->mainFrame()->addMessageToConsole(WebConsoleMessage(WebConsoleMessage::LevelError, message));
759 void ChromeClientImpl::needTouchEvents(bool needsTouchEvents)
761 m_webView->hasTouchEventHandlers(needsTouchEvents);
764 void ChromeClientImpl::setTouchAction(TouchAction touchAction)
766 if (WebViewClient* client = m_webView->client()) {
767 WebTouchAction webTouchAction = static_cast<WebTouchAction>(touchAction);
768 client->setTouchAction(webTouchAction);
772 bool ChromeClientImpl::requestPointerLock()
774 return m_webView->requestPointerLock();
777 void ChromeClientImpl::requestPointerUnlock()
779 return m_webView->requestPointerUnlock();
782 void ChromeClientImpl::annotatedRegionsChanged()
784 WebViewClient* client = m_webView->client();
786 client->draggableRegionsChanged();
789 void ChromeClientImpl::didAssociateFormControls(const WillBeHeapVector<RefPtrWillBeMember<Element> >& elements)
791 if (m_webView->autofillClient())
792 m_webView->autofillClient()->didAssociateFormControls(elements);
795 void ChromeClientImpl::didCancelCompositionOnSelectionChange()
797 if (m_webView->client())
798 m_webView->client()->didCancelCompositionOnSelectionChange();
801 void ChromeClientImpl::willSetInputMethodState()
803 if (m_webView->client())
804 m_webView->client()->resetInputMethod();
807 void ChromeClientImpl::didUpdateTextOfFocusedElementByNonUserInput()
809 if (m_webView->client())
810 m_webView->client()->didUpdateTextOfFocusedElementByNonUserInput();
813 void ChromeClientImpl::showImeIfNeeded()
815 if (m_webView->client())
816 m_webView->client()->showImeIfNeeded();
819 void ChromeClientImpl::handleKeyboardEventOnTextField(HTMLInputElement& inputElement, KeyboardEvent& event)
821 if (!m_webView->autofillClient())
823 m_webView->autofillClient()->textFieldDidReceiveKeyDown(WebInputElement(&inputElement), WebKeyboardEventBuilder(event));
826 // FIXME: Remove this code once we have input routing in the browser
827 // process. See http://crbug.com/339659.
828 void ChromeClientImpl::forwardInputEvent(
829 Frame* frame, Event* event)
831 // FIXME: Input event forwarding to out-of-process frames is broken until
832 // WebRemoteFrameImpl has a WebFrameClient.
833 if (frame->isRemoteFrame())
836 WebLocalFrameImpl* webFrame = WebLocalFrameImpl::fromFrame(toLocalFrame(frame));
838 // This is only called when we have out-of-process iframes, which
839 // need to forward input events across processes.
840 // FIXME: Add a check for out-of-process iframes enabled.
841 if (event->isKeyboardEvent()) {
842 WebKeyboardEventBuilder webEvent(*static_cast<KeyboardEvent*>(event));
843 webFrame->client()->forwardInputEvent(&webEvent);
844 } else if (event->isMouseEvent()) {
845 WebMouseEventBuilder webEvent(webFrame->frameView(), frame->ownerRenderer(), *static_cast<MouseEvent*>(event));
846 // Internal Blink events should not be forwarded.
847 if (webEvent.type == WebInputEvent::Undefined)
850 webFrame->client()->forwardInputEvent(&webEvent);
851 } else if (event->isWheelEvent()) {
852 WebMouseWheelEventBuilder webEvent(webFrame->frameView(), frame->ownerRenderer(), *static_cast<WheelEvent*>(event));
853 if (webEvent.type == WebInputEvent::Undefined)
855 webFrame->client()->forwardInputEvent(&webEvent);
859 void ChromeClientImpl::didChangeValueInTextField(HTMLFormControlElement& element)
861 if (!m_webView->autofillClient())
863 m_webView->autofillClient()->textFieldDidChange(WebFormControlElement(&element));
866 void ChromeClientImpl::didEndEditingOnTextField(HTMLInputElement& inputElement)
868 if (m_webView->autofillClient())
869 m_webView->autofillClient()->textFieldDidEndEditing(WebInputElement(&inputElement));
872 void ChromeClientImpl::openTextDataListChooser(HTMLInputElement& input)
874 if (m_webView->autofillClient())
875 m_webView->autofillClient()->openTextDataListChooser(WebInputElement(&input));