Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / ChromeClientImpl.cpp
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
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
14  * distribution.
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.
18  *
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.
30  */
31
32 #include "config.h"
33 #include "web/ChromeClientImpl.h"
34
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"
110
111 namespace blink {
112
113 // Converts a AXObjectCache::AXNotification to a WebAXEvent
114 static WebAXEvent toWebAXEvent(AXObjectCache::AXNotification notification)
115 {
116     // These enums have the same values; enforced in AssertMatchingEnums.cpp.
117     return static_cast<WebAXEvent>(notification);
118 }
119
120 ChromeClientImpl::ChromeClientImpl(WebViewImpl* webView)
121     : m_webView(webView)
122     , m_toolbarsVisible(true)
123     , m_statusbarVisible(true)
124     , m_scrollbarsVisible(true)
125     , m_menubarVisible(true)
126     , m_resizable(true)
127     , m_pagePopupDriver(webView)
128 {
129 }
130
131 ChromeClientImpl::~ChromeClientImpl()
132 {
133 }
134
135 void* ChromeClientImpl::webView() const
136 {
137     return static_cast<void*>(m_webView);
138 }
139
140 void ChromeClientImpl::chromeDestroyed()
141 {
142     // Our lifetime is bound to the WebViewImpl.
143 }
144
145 void ChromeClientImpl::setWindowRect(const FloatRect& r)
146 {
147     if (m_webView->client())
148         m_webView->client()->setWindowRect(IntRect(r));
149 }
150
151 FloatRect ChromeClientImpl::windowRect()
152 {
153     WebRect rect;
154     if (m_webView->client())
155         rect = m_webView->client()->rootWindowRect();
156     else {
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;
162     }
163     return FloatRect(rect);
164 }
165
166 FloatRect ChromeClientImpl::pageRect()
167 {
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.
171     return windowRect();
172 }
173
174 void ChromeClientImpl::focus()
175 {
176     if (m_webView->client())
177         m_webView->client()->didFocus();
178 }
179
180 bool ChromeClientImpl::canTakeFocus(FocusType)
181 {
182     // For now the browser can always take focus if we're not running layout
183     // tests.
184     return !layoutTestMode();
185 }
186
187 void ChromeClientImpl::takeFocus(FocusType type)
188 {
189     if (!m_webView->client())
190         return;
191     if (type == FocusTypeBackward)
192         m_webView->client()->focusPrevious();
193     else
194         m_webView->client()->focusNext();
195 }
196
197 void ChromeClientImpl::focusedNodeChanged(Node* node)
198 {
199     m_webView->client()->focusedNodeChanged(WebNode(node));
200
201     WebURL focusURL;
202     if (node && node->isElementNode() && toElement(node)->isLiveLink())
203         focusURL = toElement(node)->hrefURL();
204     m_webView->client()->setKeyboardFocusURL(focusURL);
205 }
206
207 void ChromeClientImpl::focusedFrameChanged(LocalFrame* frame)
208 {
209     WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
210     if (webframe && webframe->client())
211         webframe->client()->frameFocused();
212 }
213
214 Page* ChromeClientImpl::createWindow(LocalFrame* frame, const FrameLoadRequest& r, const WindowFeatures& features,
215     NavigationPolicy navigationPolicy, ShouldSendReferrer shouldSendReferrer)
216 {
217     if (!m_webView->client())
218         return 0;
219
220     WebNavigationPolicy policy = static_cast<WebNavigationPolicy>(navigationPolicy);
221     if (policy == WebNavigationPolicyIgnore)
222         policy = getNavigationPolicy();
223
224     ASSERT(frame->document());
225     FullscreenElementStack::from(*frame->document()).fullyExitFullscreen();
226
227     WebViewImpl* newView = toWebViewImpl(
228         m_webView->client()->createView(WebLocalFrameImpl::fromFrame(frame), WrappedResourceRequest(r.resourceRequest()), features, r.frameName(), policy, shouldSendReferrer == NeverSendReferrer));
229     if (!newView)
230         return 0;
231     return newView->page();
232 }
233
234 static inline void updatePolicyForEvent(const WebInputEvent* inputEvent, NavigationPolicy* policy)
235 {
236     if (!inputEvent || inputEvent->type != WebInputEvent::MouseUp)
237         return;
238
239     const WebMouseEvent* mouseEvent = static_cast<const WebMouseEvent*>(inputEvent);
240
241     unsigned short buttonNumber;
242     switch (mouseEvent->button) {
243     case WebMouseEvent::ButtonLeft:
244         buttonNumber = 0;
245         break;
246     case WebMouseEvent::ButtonMiddle:
247         buttonNumber = 1;
248         break;
249     case WebMouseEvent::ButtonRight:
250         buttonNumber = 2;
251         break;
252     default:
253         return;
254     }
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;
259
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)
264         return;
265     *policy = userPolicy;
266 }
267
268 WebNavigationPolicy ChromeClientImpl::getNavigationPolicy()
269 {
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
276         || !m_menubarVisible
277         || !m_resizable;
278
279     NavigationPolicy policy = NavigationPolicyNewForegroundTab;
280     if (asPopup)
281         policy = NavigationPolicyNewPopup;
282     updatePolicyForEvent(WebViewImpl::currentInputEvent(), &policy);
283
284     return static_cast<WebNavigationPolicy>(policy);
285 }
286
287 void ChromeClientImpl::show(NavigationPolicy navigationPolicy)
288 {
289     if (!m_webView->client())
290         return;
291
292     WebNavigationPolicy policy = static_cast<WebNavigationPolicy>(navigationPolicy);
293     if (policy == WebNavigationPolicyIgnore)
294         policy = getNavigationPolicy();
295     m_webView->client()->show(policy);
296 }
297
298 bool ChromeClientImpl::canRunModal()
299 {
300     return !!m_webView->client();
301 }
302
303 void ChromeClientImpl::runModal()
304 {
305     if (m_webView->client())
306         m_webView->client()->runModal();
307 }
308
309 void ChromeClientImpl::setToolbarsVisible(bool value)
310 {
311     m_toolbarsVisible = value;
312 }
313
314 bool ChromeClientImpl::toolbarsVisible()
315 {
316     return m_toolbarsVisible;
317 }
318
319 void ChromeClientImpl::setStatusbarVisible(bool value)
320 {
321     m_statusbarVisible = value;
322 }
323
324 bool ChromeClientImpl::statusbarVisible()
325 {
326     return m_statusbarVisible;
327 }
328
329 void ChromeClientImpl::setScrollbarsVisible(bool value)
330 {
331     m_scrollbarsVisible = value;
332     WebLocalFrameImpl* webFrame = toWebLocalFrameImpl(m_webView->mainFrame());
333     if (webFrame)
334         webFrame->setCanHaveScrollbars(value);
335 }
336
337 bool ChromeClientImpl::scrollbarsVisible()
338 {
339     return m_scrollbarsVisible;
340 }
341
342 void ChromeClientImpl::setMenubarVisible(bool value)
343 {
344     m_menubarVisible = value;
345 }
346
347 bool ChromeClientImpl::menubarVisible()
348 {
349     return m_menubarVisible;
350 }
351
352 void ChromeClientImpl::setResizable(bool value)
353 {
354     m_resizable = value;
355 }
356
357 bool ChromeClientImpl::shouldReportDetailedMessageForSource(const String& url)
358 {
359     WebLocalFrameImpl* webframe = m_webView->localFrameRootTemporary();
360     return webframe->client() && webframe->client()->shouldReportDetailedMessageForSource(url);
361 }
362
363 void ChromeClientImpl::addMessageToConsole(LocalFrame* localFrame, MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID, const String& stackTrace)
364 {
365     WebLocalFrameImpl* frame = WebLocalFrameImpl::fromFrame(localFrame);
366     if (frame && frame->client()) {
367         frame->client()->didAddMessageToConsole(
368             WebConsoleMessage(static_cast<WebConsoleMessage::Level>(level), message),
369             sourceID,
370             lineNumber,
371             stackTrace);
372     }
373 }
374
375 bool ChromeClientImpl::canRunBeforeUnloadConfirmPanel()
376 {
377     return !!m_webView->client();
378 }
379
380 bool ChromeClientImpl::runBeforeUnloadConfirmPanel(const String& message, LocalFrame* frame)
381 {
382     WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
383
384     bool isReload = false;
385     WebDataSource* ds = webframe->provisionalDataSource();
386     if (ds)
387         isReload = (ds->navigationType() == WebNavigationTypeReload);
388
389     if (webframe->client())
390         return webframe->client()->runModalBeforeUnloadDialog(isReload, message);
391     return false;
392 }
393
394 void ChromeClientImpl::closeWindowSoon()
395 {
396     // Make sure this Page can no longer be found by JS.
397     Page::ordinaryPages().remove(m_webView->page());
398
399     // Make sure that all loading is stopped.  Ensures that JS stops executing!
400     m_webView->mainFrame()->stopLoading();
401
402     if (m_webView->client())
403         m_webView->client()->closeWidgetSoon();
404 }
405
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)
409 {
410     WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
411     if (webframe->client()) {
412         if (WebUserGestureIndicator::isProcessingUserGesture())
413             WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
414         webframe->client()->runModalAlertDialog(message);
415     }
416 }
417
418 // See comments for runJavaScriptAlert().
419 bool ChromeClientImpl::runJavaScriptConfirm(LocalFrame* frame, const String& message)
420 {
421     WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
422     if (webframe->client()) {
423         if (WebUserGestureIndicator::isProcessingUserGesture())
424             WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
425         return webframe->client()->runModalConfirmDialog(message);
426     }
427     return false;
428 }
429
430 // See comments for runJavaScriptAlert().
431 bool ChromeClientImpl::runJavaScriptPrompt(LocalFrame* frame,
432                                            const String& message,
433                                            const String& defaultValue,
434                                            String& result)
435 {
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(
442             message,
443             defaultValue,
444             &actualValue);
445         if (ok)
446             result = actualValue;
447         return ok;
448     }
449     return false;
450 }
451
452 void ChromeClientImpl::setStatusbarText(const String& message)
453 {
454     if (m_webView->client())
455         m_webView->client()->setStatusText(message);
456 }
457
458 bool ChromeClientImpl::tabsToLinks()
459 {
460     return m_webView->tabsToLinks();
461 }
462
463 IntRect ChromeClientImpl::windowResizerRect() const
464 {
465     IntRect result;
466     if (m_webView->client())
467         result = m_webView->client()->windowResizerRect();
468     return result;
469 }
470
471 void ChromeClientImpl::invalidateContentsAndRootView(const IntRect& updateRect)
472 {
473     if (updateRect.isEmpty())
474         return;
475     m_webView->invalidateRect(updateRect);
476 }
477
478 void ChromeClientImpl::invalidateContentsForSlowScroll(const IntRect& updateRect)
479 {
480     invalidateContentsAndRootView(updateRect);
481 }
482
483 void ChromeClientImpl::scheduleAnimation()
484 {
485     m_webView->scheduleAnimation();
486 }
487
488 void ChromeClientImpl::scroll()
489 {
490     if (m_webView->isAcceleratedCompositingActive())
491         m_webView->scrollRootLayer();
492 }
493
494 IntRect ChromeClientImpl::rootViewToScreen(const IntRect& rect) const
495 {
496     IntRect screenRect(rect);
497
498     if (m_webView->client()) {
499         WebRect windowRect = m_webView->client()->windowRect();
500         screenRect.move(windowRect.x, windowRect.y);
501     }
502
503     return screenRect;
504 }
505
506 WebScreenInfo ChromeClientImpl::screenInfo() const
507 {
508     return m_webView->client() ? m_webView->client()->screenInfo() : WebScreenInfo();
509 }
510
511 void ChromeClientImpl::contentsSizeChanged(LocalFrame* frame, const IntSize& size) const
512 {
513     m_webView->didChangeContentsSize();
514
515     WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
516     webframe->didChangeContentsSize(size);
517
518     frame->loader().restoreScrollPositionAndViewState();
519 }
520
521 void ChromeClientImpl::deviceOrPageScaleFactorChanged() const
522 {
523     m_webView->deviceOrPageScaleFactorChanged();
524 }
525
526 void ChromeClientImpl::layoutUpdated(LocalFrame* frame) const
527 {
528     m_webView->layoutUpdated(WebLocalFrameImpl::fromFrame(frame));
529 }
530
531 void ChromeClientImpl::mouseDidMoveOverElement(
532     const HitTestResult& result, unsigned modifierFlags)
533 {
534     if (!m_webView->client())
535         return;
536
537     WebURL url;
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());
550             }
551         }
552     }
553
554     m_webView->client()->setMouseOverURL(url);
555 }
556
557 void ChromeClientImpl::setToolTip(const String& tooltipText, TextDirection dir)
558 {
559     if (m_webView->client())
560         m_webView->client()->setToolTipText(tooltipText, toWebTextDirection(dir));
561 }
562
563 void ChromeClientImpl::dispatchViewportPropertiesDidChange(const ViewportDescription& description) const
564 {
565     m_webView->updatePageDefinedViewportConstraints(description);
566 }
567
568 void ChromeClientImpl::print(LocalFrame* frame)
569 {
570     if (m_webView->client())
571         m_webView->client()->printPage(WebLocalFrameImpl::fromFrame(frame));
572 }
573
574 PassOwnPtr<ColorChooser> ChromeClientImpl::createColorChooser(LocalFrame* frame, ColorChooserClient* chooserClient, const Color&)
575 {
576     OwnPtr<ColorChooserUIController> controller;
577     if (RuntimeEnabledFeatures::pagePopupEnabled())
578         controller = adoptPtr(new ColorChooserPopupUIController(frame, this, chooserClient));
579     else
580         controller = adoptPtr(new ColorChooserUIController(frame, chooserClient));
581     controller->openUI();
582     return controller.release();
583 }
584
585 PassRefPtrWillBeRawPtr<DateTimeChooser> ChromeClientImpl::openDateTimeChooser(DateTimeChooserClient* pickerClient, const DateTimeChooserParameters& parameters)
586 {
587 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
588     return DateTimeChooserImpl::create(this, pickerClient, parameters);
589 #else
590     return ExternalDateTimeChooser::create(this, m_webView->client(), pickerClient, parameters);
591 #endif
592 }
593
594 void ChromeClientImpl::runOpenPanel(LocalFrame* frame, PassRefPtr<FileChooser> fileChooser)
595 {
596     WebViewClient* client = m_webView->client();
597     if (!client)
598         return;
599
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;
608
609     WebFileChooserCompletionImpl* chooserCompletion =
610         new WebFileChooserCompletionImpl(fileChooser);
611
612     if (client->runFileChooser(params, chooserCompletion))
613         return;
614
615     // Choosing failed, so do callback with an empty list.
616     chooserCompletion->didChooseFile(WebVector<WebString>());
617 }
618
619 void ChromeClientImpl::enumerateChosenDirectory(FileChooser* fileChooser)
620 {
621     WebViewClient* client = m_webView->client();
622     if (!client)
623         return;
624
625     WebFileChooserCompletionImpl* chooserCompletion =
626         new WebFileChooserCompletionImpl(fileChooser);
627
628     ASSERT(fileChooser && fileChooser->settings().selectedFiles.size());
629
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>());
633 }
634
635 void ChromeClientImpl::setCursor(const Cursor& cursor)
636 {
637     setCursor(WebCursorInfo(cursor));
638 }
639
640 void ChromeClientImpl::setCursor(const WebCursorInfo& cursor)
641 {
642 #if OS(MACOSX)
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())
646         return;
647 #endif
648     if (m_webView->client())
649         m_webView->client()->didChangeCursor(cursor);
650 }
651
652 void ChromeClientImpl::setCursorForPlugin(const WebCursorInfo& cursor)
653 {
654     setCursor(cursor);
655 }
656
657 void ChromeClientImpl::postAccessibilityNotification(AXObject* obj, AXObjectCache::AXNotification notification)
658 {
659     // Alert assistive technology about the accessibility object notification.
660     if (!obj)
661         return;
662     if (m_webView->client())
663         m_webView->client()->postAccessibilityEvent(WebAXObject(obj), toWebAXEvent(notification));
664 }
665
666 String ChromeClientImpl::acceptLanguages()
667 {
668     return m_webView->client()->acceptLanguages();
669 }
670
671 bool ChromeClientImpl::paintCustomOverhangArea(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
672 {
673     LocalFrame* frame = m_webView->mainFrameImpl()->frame();
674     WebPluginContainerImpl* pluginContainer = WebLocalFrameImpl::pluginContainerFromFrame(frame);
675     if (pluginContainer)
676         return pluginContainer->paintCustomOverhangArea(context, horizontalOverhangArea, verticalOverhangArea, dirtyRect);
677     return false;
678 }
679
680 GraphicsLayerFactory* ChromeClientImpl::graphicsLayerFactory() const
681 {
682     return m_webView->graphicsLayerFactory();
683 }
684
685 void ChromeClientImpl::attachRootGraphicsLayer(GraphicsLayer* rootLayer)
686 {
687     m_webView->setRootGraphicsLayer(rootLayer);
688 }
689
690 void ChromeClientImpl::enterFullScreenForElement(Element* element)
691 {
692     m_webView->enterFullScreenForElement(element);
693 }
694
695 void ChromeClientImpl::exitFullScreenForElement(Element* element)
696 {
697     m_webView->exitFullScreenForElement(element);
698 }
699
700 void ChromeClientImpl::clearCompositedSelectionBounds()
701 {
702     m_webView->clearCompositedSelectionBounds();
703 }
704
705 bool ChromeClientImpl::hasOpenedPopup() const
706 {
707     return m_webView->hasOpenedPopup();
708 }
709
710 PassRefPtr<PopupMenu> ChromeClientImpl::createPopupMenu(LocalFrame& frame, PopupMenuClient* client) const
711 {
712     if (WebViewImpl::useExternalPopupMenus())
713         return adoptRef(new ExternalPopupMenu(frame, client, *m_webView));
714
715     return adoptRef(new PopupMenuChromium(frame, client));
716 }
717
718 PagePopup* ChromeClientImpl::openPagePopup(PagePopupClient* client, const IntRect& originBoundsInRootView)
719 {
720     ASSERT(m_pagePopupDriver);
721     return m_pagePopupDriver->openPagePopup(client, originBoundsInRootView);
722 }
723
724 void ChromeClientImpl::closePagePopup(PagePopup* popup)
725 {
726     ASSERT(m_pagePopupDriver);
727     m_pagePopupDriver->closePagePopup(popup);
728 }
729
730 void ChromeClientImpl::setPagePopupDriver(PagePopupDriver* driver)
731 {
732     ASSERT(driver);
733     m_pagePopupDriver = driver;
734 }
735
736 void ChromeClientImpl::resetPagePopupDriver()
737 {
738     m_pagePopupDriver = m_webView;
739 }
740
741 bool ChromeClientImpl::shouldRunModalDialogDuringPageDismissal(const DialogType& dialogType, const String& dialogMessage, Document::PageDismissalType dismissalType) const
742 {
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)));
746
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)));
750
751     Platform::current()->histogramEnumeration("Renderer.ModalDialogsDuringPageDismissal", dismissal * arraysize(kDialogs) + dialog, arraysize(kDialogs) * arraysize(kDismissals));
752
753     String message = String("Blocked ") + kDialogs[dialog] + "('" + dialogMessage + "') during " + kDismissals[dismissal] + ".";
754     m_webView->mainFrame()->addMessageToConsole(WebConsoleMessage(WebConsoleMessage::LevelError, message));
755
756     return false;
757 }
758
759 void ChromeClientImpl::needTouchEvents(bool needsTouchEvents)
760 {
761     m_webView->hasTouchEventHandlers(needsTouchEvents);
762 }
763
764 void ChromeClientImpl::setTouchAction(TouchAction touchAction)
765 {
766     if (WebViewClient* client = m_webView->client()) {
767         WebTouchAction webTouchAction = static_cast<WebTouchAction>(touchAction);
768         client->setTouchAction(webTouchAction);
769     }
770 }
771
772 bool ChromeClientImpl::requestPointerLock()
773 {
774     return m_webView->requestPointerLock();
775 }
776
777 void ChromeClientImpl::requestPointerUnlock()
778 {
779     return m_webView->requestPointerUnlock();
780 }
781
782 void ChromeClientImpl::annotatedRegionsChanged()
783 {
784     WebViewClient* client = m_webView->client();
785     if (client)
786         client->draggableRegionsChanged();
787 }
788
789 void ChromeClientImpl::didAssociateFormControls(const WillBeHeapVector<RefPtrWillBeMember<Element> >& elements)
790 {
791     if (m_webView->autofillClient())
792         m_webView->autofillClient()->didAssociateFormControls(elements);
793 }
794
795 void ChromeClientImpl::didCancelCompositionOnSelectionChange()
796 {
797     if (m_webView->client())
798         m_webView->client()->didCancelCompositionOnSelectionChange();
799 }
800
801 void ChromeClientImpl::willSetInputMethodState()
802 {
803     if (m_webView->client())
804         m_webView->client()->resetInputMethod();
805 }
806
807 void ChromeClientImpl::didUpdateTextOfFocusedElementByNonUserInput()
808 {
809     if (m_webView->client())
810         m_webView->client()->didUpdateTextOfFocusedElementByNonUserInput();
811 }
812
813 void ChromeClientImpl::showImeIfNeeded()
814 {
815     if (m_webView->client())
816         m_webView->client()->showImeIfNeeded();
817 }
818
819 void ChromeClientImpl::handleKeyboardEventOnTextField(HTMLInputElement& inputElement, KeyboardEvent& event)
820 {
821     if (!m_webView->autofillClient())
822         return;
823     m_webView->autofillClient()->textFieldDidReceiveKeyDown(WebInputElement(&inputElement), WebKeyboardEventBuilder(event));
824 }
825
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)
830 {
831     // FIXME: Input event forwarding to out-of-process frames is broken until
832     // WebRemoteFrameImpl has a WebFrameClient.
833     if (frame->isRemoteFrame())
834         return;
835
836     WebLocalFrameImpl* webFrame = WebLocalFrameImpl::fromFrame(toLocalFrame(frame));
837
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)
848             return;
849
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)
854             return;
855         webFrame->client()->forwardInputEvent(&webEvent);
856     }
857 }
858
859 void ChromeClientImpl::didChangeValueInTextField(HTMLFormControlElement& element)
860 {
861     if (!m_webView->autofillClient())
862         return;
863     m_webView->autofillClient()->textFieldDidChange(WebFormControlElement(&element));
864 }
865
866 void ChromeClientImpl::didEndEditingOnTextField(HTMLInputElement& inputElement)
867 {
868     if (m_webView->autofillClient())
869         m_webView->autofillClient()->textFieldDidEndEditing(WebInputElement(&inputElement));
870 }
871
872 void ChromeClientImpl::openTextDataListChooser(HTMLInputElement& input)
873 {
874     if (m_webView->autofillClient())
875         m_webView->autofillClient()->openTextDataListChooser(WebInputElement(&input));
876 }
877
878 } // namespace blink