Update To 11.40.268.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/Fullscreen.h"
41 #include "core/dom/Node.h"
42 #include "core/frame/Console.h"
43 #include "core/frame/FrameView.h"
44 #include "core/frame/Settings.h"
45 #include "core/html/HTMLInputElement.h"
46 #include "core/html/forms/ColorChooser.h"
47 #include "core/html/forms/ColorChooserClient.h"
48 #include "core/html/forms/DateTimeChooser.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/compositing/CompositedSelectionBound.h"
57 #include "platform/Cursor.h"
58 #include "platform/FileChooser.h"
59 #include "platform/PlatformScreen.h"
60 #include "platform/RuntimeEnabledFeatures.h"
61 #include "platform/exported/WrappedResourceRequest.h"
62 #include "platform/geometry/FloatRect.h"
63 #include "platform/geometry/IntRect.h"
64 #include "platform/graphics/GraphicsLayer.h"
65 #include "platform/weborigin/SecurityOrigin.h"
66 #include "public/platform/Platform.h"
67 #include "public/platform/WebCursorInfo.h"
68 #include "public/platform/WebRect.h"
69 #include "public/platform/WebSelectionBound.h"
70 #include "public/platform/WebURLRequest.h"
71 #include "public/web/WebAXObject.h"
72 #include "public/web/WebAutofillClient.h"
73 #include "public/web/WebColorChooser.h"
74 #include "public/web/WebColorSuggestion.h"
75 #include "public/web/WebConsoleMessage.h"
76 #include "public/web/WebFrameClient.h"
77 #include "public/web/WebInputElement.h"
78 #include "public/web/WebInputEvent.h"
79 #include "public/web/WebKit.h"
80 #include "public/web/WebNode.h"
81 #include "public/web/WebPlugin.h"
82 #include "public/web/WebPopupMenuInfo.h"
83 #include "public/web/WebSettings.h"
84 #include "public/web/WebTextDirection.h"
85 #include "public/web/WebTouchAction.h"
86 #include "public/web/WebUserGestureIndicator.h"
87 #include "public/web/WebUserGestureToken.h"
88 #include "public/web/WebViewClient.h"
89 #include "public/web/WebWindowFeatures.h"
90 #include "web/ColorChooserPopupUIController.h"
91 #include "web/ColorChooserUIController.h"
92 #include "web/DateTimeChooserImpl.h"
93 #include "web/ExternalDateTimeChooser.h"
94 #include "web/ExternalPopupMenu.h"
95 #include "web/PopupMenuChromium.h"
96 #include "web/WebFileChooserCompletionImpl.h"
97 #include "web/WebInputEventConversion.h"
98 #include "web/WebLocalFrameImpl.h"
99 #include "web/WebPluginContainerImpl.h"
100 #include "web/WebPopupMenuImpl.h"
101 #include "web/WebSettingsImpl.h"
102 #include "web/WebViewImpl.h"
103 #include "wtf/text/CString.h"
104 #include "wtf/text/StringBuilder.h"
105 #include "wtf/text/StringConcatenate.h"
106 #include "wtf/unicode/CharacterNames.h"
107
108 namespace blink {
109
110 // Converts a AXObjectCache::AXNotification to a WebAXEvent
111 static WebAXEvent toWebAXEvent(AXObjectCache::AXNotification notification)
112 {
113     // These enums have the same values; enforced in AssertMatchingEnums.cpp.
114     return static_cast<WebAXEvent>(notification);
115 }
116
117 static WebSelectionBound toWebSelectionBound(const CompositedSelectionBound& bound)
118 {
119     ASSERT(bound.layer);
120
121     // These enums have the same values; enforced in AssertMatchingEnums.cpp.
122     WebSelectionBound result(static_cast<WebSelectionBound::Type>(bound.type));
123     result.layerId = bound.layer->platformLayer()->id();
124     result.edgeTopInLayer = roundedIntPoint(bound.edgeTopInLayer);
125     result.edgeBottomInLayer = roundedIntPoint(bound.edgeBottomInLayer);
126     return result;
127 }
128
129 ChromeClientImpl::ChromeClientImpl(WebViewImpl* webView)
130     : m_webView(webView)
131     , m_toolbarsVisible(true)
132     , m_statusbarVisible(true)
133     , m_scrollbarsVisible(true)
134     , m_menubarVisible(true)
135     , m_resizable(true)
136     , m_pagePopupDriver(webView)
137 {
138 }
139
140 ChromeClientImpl::~ChromeClientImpl()
141 {
142 }
143
144 void* ChromeClientImpl::webView() const
145 {
146     return static_cast<void*>(m_webView);
147 }
148
149 void ChromeClientImpl::chromeDestroyed()
150 {
151     // Our lifetime is bound to the WebViewImpl.
152 }
153
154 void ChromeClientImpl::setWindowRect(const FloatRect& r)
155 {
156     if (m_webView->client())
157         m_webView->client()->setWindowRect(IntRect(r));
158 }
159
160 FloatRect ChromeClientImpl::windowRect()
161 {
162     WebRect rect;
163     if (m_webView->client())
164         rect = m_webView->client()->rootWindowRect();
165     else {
166         // These numbers will be fairly wrong. The window's x/y coordinates will
167         // be the top left corner of the screen and the size will be the content
168         // size instead of the window size.
169         rect.width = m_webView->size().width;
170         rect.height = m_webView->size().height;
171     }
172     return FloatRect(rect);
173 }
174
175 FloatRect ChromeClientImpl::pageRect()
176 {
177     // We hide the details of the window's border thickness from the web page by
178     // simple re-using the window position here.  So, from the point-of-view of
179     // the web page, the window has no border.
180     return windowRect();
181 }
182
183 void ChromeClientImpl::focus()
184 {
185     if (m_webView->client())
186         m_webView->client()->didFocus();
187 }
188
189 bool ChromeClientImpl::canTakeFocus(FocusType)
190 {
191     // For now the browser can always take focus if we're not running layout
192     // tests.
193     return !layoutTestMode();
194 }
195
196 void ChromeClientImpl::takeFocus(FocusType type)
197 {
198     if (!m_webView->client())
199         return;
200     if (type == FocusTypeBackward)
201         m_webView->client()->focusPrevious();
202     else
203         m_webView->client()->focusNext();
204 }
205
206 void ChromeClientImpl::focusedNodeChanged(Node* node)
207 {
208     m_webView->client()->focusedNodeChanged(WebNode(node));
209
210     WebURL focusURL;
211     if (node && node->isElementNode() && toElement(node)->isLiveLink())
212         focusURL = toElement(node)->hrefURL();
213     m_webView->client()->setKeyboardFocusURL(focusURL);
214 }
215
216 void ChromeClientImpl::focusedFrameChanged(LocalFrame* frame)
217 {
218     WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
219     if (webframe && webframe->client())
220         webframe->client()->frameFocused();
221 }
222
223 Page* ChromeClientImpl::createWindow(LocalFrame* frame, const FrameLoadRequest& r, const WindowFeatures& features,
224     NavigationPolicy navigationPolicy, ShouldSendReferrer shouldSendReferrer)
225 {
226     if (!m_webView->client())
227         return 0;
228
229     WebNavigationPolicy policy = static_cast<WebNavigationPolicy>(navigationPolicy);
230     if (policy == WebNavigationPolicyIgnore)
231         policy = getNavigationPolicy();
232
233     ASSERT(frame->document());
234     Fullscreen::fullyExitFullscreen(*frame->document());
235
236     WebViewImpl* newView = toWebViewImpl(
237         m_webView->client()->createView(WebLocalFrameImpl::fromFrame(frame), WrappedResourceRequest(r.resourceRequest()), features, r.frameName(), policy, shouldSendReferrer == NeverSendReferrer));
238     if (!newView)
239         return 0;
240     return newView->page();
241 }
242
243 static inline void updatePolicyForEvent(const WebInputEvent* inputEvent, NavigationPolicy* policy)
244 {
245     if (!inputEvent || inputEvent->type != WebInputEvent::MouseUp)
246         return;
247
248     const WebMouseEvent* mouseEvent = static_cast<const WebMouseEvent*>(inputEvent);
249
250     unsigned short buttonNumber;
251     switch (mouseEvent->button) {
252     case WebMouseEvent::ButtonLeft:
253         buttonNumber = 0;
254         break;
255     case WebMouseEvent::ButtonMiddle:
256         buttonNumber = 1;
257         break;
258     case WebMouseEvent::ButtonRight:
259         buttonNumber = 2;
260         break;
261     default:
262         return;
263     }
264     bool ctrl = mouseEvent->modifiers & WebMouseEvent::ControlKey;
265     bool shift = mouseEvent->modifiers & WebMouseEvent::ShiftKey;
266     bool alt = mouseEvent->modifiers & WebMouseEvent::AltKey;
267     bool meta = mouseEvent->modifiers & WebMouseEvent::MetaKey;
268
269     NavigationPolicy userPolicy = *policy;
270     navigationPolicyFromMouseEvent(buttonNumber, ctrl, shift, alt, meta, &userPolicy);
271     // User and app agree that we want a new window; let the app override the decorations.
272     if (userPolicy == NavigationPolicyNewWindow && *policy == NavigationPolicyNewPopup)
273         return;
274     *policy = userPolicy;
275 }
276
277 WebNavigationPolicy ChromeClientImpl::getNavigationPolicy()
278 {
279     // If our default configuration was modified by a script or wasn't
280     // created by a user gesture, then show as a popup. Else, let this
281     // new window be opened as a toplevel window.
282     bool asPopup = !m_toolbarsVisible
283         || !m_statusbarVisible
284         || !m_scrollbarsVisible
285         || !m_menubarVisible
286         || !m_resizable;
287
288     NavigationPolicy policy = NavigationPolicyNewForegroundTab;
289     if (asPopup)
290         policy = NavigationPolicyNewPopup;
291     updatePolicyForEvent(WebViewImpl::currentInputEvent(), &policy);
292
293     return static_cast<WebNavigationPolicy>(policy);
294 }
295
296 void ChromeClientImpl::show(NavigationPolicy navigationPolicy)
297 {
298     if (!m_webView->client())
299         return;
300
301     WebNavigationPolicy policy = static_cast<WebNavigationPolicy>(navigationPolicy);
302     if (policy == WebNavigationPolicyIgnore)
303         policy = getNavigationPolicy();
304     m_webView->client()->show(policy);
305 }
306
307 bool ChromeClientImpl::canRunModal()
308 {
309     return !!m_webView->client();
310 }
311
312 void ChromeClientImpl::runModal()
313 {
314     if (m_webView->client())
315         m_webView->client()->runModal();
316 }
317
318 void ChromeClientImpl::setToolbarsVisible(bool value)
319 {
320     m_toolbarsVisible = value;
321 }
322
323 bool ChromeClientImpl::toolbarsVisible()
324 {
325     return m_toolbarsVisible;
326 }
327
328 void ChromeClientImpl::setStatusbarVisible(bool value)
329 {
330     m_statusbarVisible = value;
331 }
332
333 bool ChromeClientImpl::statusbarVisible()
334 {
335     return m_statusbarVisible;
336 }
337
338 void ChromeClientImpl::setScrollbarsVisible(bool value)
339 {
340     m_scrollbarsVisible = value;
341     WebLocalFrameImpl* webFrame = toWebLocalFrameImpl(m_webView->mainFrame());
342     if (webFrame)
343         webFrame->setCanHaveScrollbars(value);
344 }
345
346 bool ChromeClientImpl::scrollbarsVisible()
347 {
348     return m_scrollbarsVisible;
349 }
350
351 void ChromeClientImpl::setMenubarVisible(bool value)
352 {
353     m_menubarVisible = value;
354 }
355
356 bool ChromeClientImpl::menubarVisible()
357 {
358     return m_menubarVisible;
359 }
360
361 void ChromeClientImpl::setResizable(bool value)
362 {
363     m_resizable = value;
364 }
365
366 bool ChromeClientImpl::shouldReportDetailedMessageForSource(const String& url)
367 {
368     WebLocalFrameImpl* webframe = m_webView->localFrameRootTemporary();
369     return webframe->client() && webframe->client()->shouldReportDetailedMessageForSource(url);
370 }
371
372 void ChromeClientImpl::addMessageToConsole(LocalFrame* localFrame, MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID, const String& stackTrace)
373 {
374     WebLocalFrameImpl* frame = WebLocalFrameImpl::fromFrame(localFrame);
375     if (frame && frame->client()) {
376         frame->client()->didAddMessageToConsole(
377             WebConsoleMessage(static_cast<WebConsoleMessage::Level>(level), message),
378             sourceID,
379             lineNumber,
380             stackTrace);
381     }
382 }
383
384 bool ChromeClientImpl::canRunBeforeUnloadConfirmPanel()
385 {
386     return !!m_webView->client();
387 }
388
389 bool ChromeClientImpl::runBeforeUnloadConfirmPanel(const String& message, LocalFrame* frame)
390 {
391     WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
392
393     bool isReload = false;
394     WebDataSource* ds = webframe->provisionalDataSource();
395     if (ds)
396         isReload = (ds->navigationType() == WebNavigationTypeReload);
397
398     if (webframe->client())
399         return webframe->client()->runModalBeforeUnloadDialog(isReload, message);
400     return false;
401 }
402
403 void ChromeClientImpl::closeWindowSoon()
404 {
405     // Make sure this Page can no longer be found by JS.
406     Page::ordinaryPages().remove(m_webView->page());
407
408     // Make sure that all loading is stopped.  Ensures that JS stops executing!
409     m_webView->mainFrame()->stopLoading();
410
411     if (m_webView->client())
412         m_webView->client()->closeWidgetSoon();
413 }
414
415 // Although a LocalFrame is passed in, we don't actually use it, since we
416 // already know our own m_webView.
417 void ChromeClientImpl::runJavaScriptAlert(LocalFrame* frame, const String& message)
418 {
419     WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
420     if (webframe->client()) {
421         if (WebUserGestureIndicator::isProcessingUserGesture())
422             WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
423         webframe->client()->runModalAlertDialog(message);
424     }
425 }
426
427 // See comments for runJavaScriptAlert().
428 bool ChromeClientImpl::runJavaScriptConfirm(LocalFrame* frame, const String& message)
429 {
430     WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
431     if (webframe->client()) {
432         if (WebUserGestureIndicator::isProcessingUserGesture())
433             WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
434         return webframe->client()->runModalConfirmDialog(message);
435     }
436     return false;
437 }
438
439 // See comments for runJavaScriptAlert().
440 bool ChromeClientImpl::runJavaScriptPrompt(LocalFrame* frame,
441                                            const String& message,
442                                            const String& defaultValue,
443                                            String& result)
444 {
445     WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
446     if (webframe->client()) {
447         if (WebUserGestureIndicator::isProcessingUserGesture())
448             WebUserGestureIndicator::currentUserGestureToken().setJavascriptPrompt();
449         WebString actualValue;
450         bool ok = webframe->client()->runModalPromptDialog(
451             message,
452             defaultValue,
453             &actualValue);
454         if (ok)
455             result = actualValue;
456         return ok;
457     }
458     return false;
459 }
460
461 void ChromeClientImpl::setStatusbarText(const String& message)
462 {
463     if (m_webView->client())
464         m_webView->client()->setStatusText(message);
465 }
466
467 bool ChromeClientImpl::tabsToLinks()
468 {
469     return m_webView->tabsToLinks();
470 }
471
472 IntRect ChromeClientImpl::windowResizerRect() const
473 {
474     IntRect result;
475     if (m_webView->client())
476         result = m_webView->client()->windowResizerRect();
477     return result;
478 }
479
480 void ChromeClientImpl::invalidateContentsAndRootView(const IntRect& updateRect)
481 {
482     if (updateRect.isEmpty())
483         return;
484     m_webView->invalidateRect(updateRect);
485 }
486
487 void ChromeClientImpl::invalidateContentsForSlowScroll(const IntRect& updateRect)
488 {
489     invalidateContentsAndRootView(updateRect);
490 }
491
492 void ChromeClientImpl::scheduleAnimation()
493 {
494     m_webView->scheduleAnimation();
495 }
496
497 IntRect ChromeClientImpl::rootViewToScreen(const IntRect& rect) const
498 {
499     IntRect screenRect(rect);
500
501     if (m_webView->client()) {
502         WebRect windowRect = m_webView->client()->windowRect();
503         screenRect.move(windowRect.x, windowRect.y);
504     }
505
506     return screenRect;
507 }
508
509 WebScreenInfo ChromeClientImpl::screenInfo() const
510 {
511     return m_webView->client() ? m_webView->client()->screenInfo() : WebScreenInfo();
512 }
513
514 void ChromeClientImpl::contentsSizeChanged(LocalFrame* frame, const IntSize& size) const
515 {
516     m_webView->didChangeContentsSize();
517
518     WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(frame);
519     webframe->didChangeContentsSize(size);
520
521     frame->loader().restoreScrollPositionAndViewState();
522 }
523
524 void ChromeClientImpl::deviceOrPageScaleFactorChanged() const
525 {
526     m_webView->deviceOrPageScaleFactorChanged();
527 }
528
529 void ChromeClientImpl::layoutUpdated(LocalFrame* frame) const
530 {
531     m_webView->layoutUpdated(WebLocalFrameImpl::fromFrame(frame));
532 }
533
534 void ChromeClientImpl::mouseDidMoveOverElement(
535     const HitTestResult& result, unsigned modifierFlags)
536 {
537     if (!m_webView->client())
538         return;
539
540     WebURL url;
541     // Find out if the mouse is over a link, and if so, let our UI know...
542     if (result.isLiveLink() && !result.absoluteLinkURL().string().isEmpty()) {
543         url = result.absoluteLinkURL();
544     } else if (result.innerNonSharedNode()
545         && (isHTMLObjectElement(*result.innerNonSharedNode())
546             || isHTMLEmbedElement(*result.innerNonSharedNode()))) {
547         RenderObject* object = result.innerNonSharedNode()->renderer();
548         if (object && object->isRenderPart()) {
549             Widget* widget = toRenderPart(object)->widget();
550             if (widget && widget->isPluginContainer()) {
551                 WebPluginContainerImpl* plugin = toWebPluginContainerImpl(widget);
552                 url = plugin->plugin()->linkAtPosition(result.roundedPointInInnerNodeFrame());
553             }
554         }
555     }
556
557     m_webView->client()->setMouseOverURL(url);
558 }
559
560 void ChromeClientImpl::setToolTip(const String& tooltipText, TextDirection dir)
561 {
562     if (m_webView->client())
563         m_webView->client()->setToolTipText(tooltipText, toWebTextDirection(dir));
564 }
565
566 void ChromeClientImpl::dispatchViewportPropertiesDidChange(const ViewportDescription& description) const
567 {
568     m_webView->updatePageDefinedViewportConstraints(description);
569 }
570
571 void ChromeClientImpl::print(LocalFrame* frame)
572 {
573     if (m_webView->client())
574         m_webView->client()->printPage(WebLocalFrameImpl::fromFrame(frame));
575 }
576
577 PassOwnPtrWillBeRawPtr<ColorChooser> ChromeClientImpl::createColorChooser(LocalFrame* frame, ColorChooserClient* chooserClient, const Color&)
578 {
579     OwnPtrWillBeRawPtr<ColorChooserUIController> controller = nullptr;
580     if (RuntimeEnabledFeatures::pagePopupEnabled())
581         controller = ColorChooserPopupUIController::create(frame, this, chooserClient);
582     else
583         controller = ColorChooserUIController::create(frame, chooserClient);
584     controller->openUI();
585     return controller.release();
586 }
587
588 PassRefPtr<DateTimeChooser> ChromeClientImpl::openDateTimeChooser(DateTimeChooserClient* pickerClient, const DateTimeChooserParameters& parameters)
589 {
590 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
591     return DateTimeChooserImpl::create(this, pickerClient, parameters);
592 #else
593     return ExternalDateTimeChooser::create(this, m_webView->client(), pickerClient, parameters);
594 #endif
595 }
596
597 void ChromeClientImpl::runOpenPanel(LocalFrame* frame, PassRefPtr<FileChooser> fileChooser)
598 {
599     WebViewClient* client = m_webView->client();
600     if (!client)
601         return;
602
603     WebFileChooserParams params;
604     params.multiSelect = fileChooser->settings().allowsMultipleFiles;
605     params.directory = fileChooser->settings().allowsDirectoryUpload;
606     params.acceptTypes = fileChooser->settings().acceptTypes();
607     params.selectedFiles = fileChooser->settings().selectedFiles;
608     if (params.selectedFiles.size() > 0)
609         params.initialValue = params.selectedFiles[0];
610     params.useMediaCapture = fileChooser->settings().useMediaCapture;
611     params.needLocalPath = fileChooser->settings().allowsDirectoryUpload;
612
613     WebFileChooserCompletionImpl* chooserCompletion =
614         new WebFileChooserCompletionImpl(fileChooser);
615
616     if (client->runFileChooser(params, chooserCompletion))
617         return;
618
619     // Choosing failed, so do callback with an empty list.
620     chooserCompletion->didChooseFile(WebVector<WebString>());
621 }
622
623 void ChromeClientImpl::enumerateChosenDirectory(FileChooser* fileChooser)
624 {
625     WebViewClient* client = m_webView->client();
626     if (!client)
627         return;
628
629     WebFileChooserCompletionImpl* chooserCompletion =
630         new WebFileChooserCompletionImpl(fileChooser);
631
632     ASSERT(fileChooser && fileChooser->settings().selectedFiles.size());
633
634     // If the enumeration can't happen, call the callback with an empty list.
635     if (!client->enumerateChosenDirectory(fileChooser->settings().selectedFiles[0], chooserCompletion))
636         chooserCompletion->didChooseFile(WebVector<WebString>());
637 }
638
639 void ChromeClientImpl::setCursor(const Cursor& cursor)
640 {
641     setCursor(WebCursorInfo(cursor));
642 }
643
644 void ChromeClientImpl::setCursor(const WebCursorInfo& cursor)
645 {
646 #if OS(MACOSX)
647     // On Mac the mousemove event propagates to both the popup and main window.
648     // If a popup is open we don't want the main window to change the cursor.
649     if (m_webView->hasOpenedPopup())
650         return;
651 #endif
652     if (m_webView->client())
653         m_webView->client()->didChangeCursor(cursor);
654 }
655
656 void ChromeClientImpl::setCursorForPlugin(const WebCursorInfo& cursor)
657 {
658     setCursor(cursor);
659 }
660
661 void ChromeClientImpl::postAccessibilityNotification(AXObject* obj, AXObjectCache::AXNotification notification)
662 {
663     // Alert assistive technology about the accessibility object notification.
664     if (!obj || !obj->document())
665         return;
666
667     WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(obj->document()->axObjectCacheOwner().frame());
668     if (webframe && webframe->client())
669         webframe->client()->postAccessibilityEvent(WebAXObject(obj), toWebAXEvent(notification));
670
671     // FIXME: delete these lines once Chrome only uses the frame client interface, above.
672     if (m_webView->client())
673         m_webView->client()->postAccessibilityEvent(WebAXObject(obj), toWebAXEvent(notification));
674 }
675
676 String ChromeClientImpl::acceptLanguages()
677 {
678     return m_webView->client()->acceptLanguages();
679 }
680
681 bool ChromeClientImpl::paintCustomOverhangArea(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
682 {
683     LocalFrame* frame = m_webView->mainFrameImpl()->frame();
684     WebPluginContainerImpl* pluginContainer = WebLocalFrameImpl::pluginContainerFromFrame(frame);
685     if (pluginContainer)
686         return pluginContainer->paintCustomOverhangArea(context, horizontalOverhangArea, verticalOverhangArea, dirtyRect);
687     return false;
688 }
689
690 GraphicsLayerFactory* ChromeClientImpl::graphicsLayerFactory() const
691 {
692     return m_webView->graphicsLayerFactory();
693 }
694
695 void ChromeClientImpl::attachRootGraphicsLayer(GraphicsLayer* rootLayer)
696 {
697     m_webView->setRootGraphicsLayer(rootLayer);
698 }
699
700 void ChromeClientImpl::enterFullScreenForElement(Element* element)
701 {
702     m_webView->enterFullScreenForElement(element);
703 }
704
705 void ChromeClientImpl::exitFullScreenForElement(Element* element)
706 {
707     m_webView->exitFullScreenForElement(element);
708 }
709
710 void ChromeClientImpl::clearCompositedSelectionBounds()
711 {
712     m_webView->clearCompositedSelectionBounds();
713 }
714
715 void ChromeClientImpl::updateCompositedSelectionBounds(const CompositedSelectionBound& anchor, const CompositedSelectionBound& focus)
716 {
717     m_webView->updateCompositedSelectionBounds(toWebSelectionBound(anchor), toWebSelectionBound(focus));
718 }
719
720 bool ChromeClientImpl::hasOpenedPopup() const
721 {
722     return m_webView->hasOpenedPopup();
723 }
724
725 PassRefPtrWillBeRawPtr<PopupMenu> ChromeClientImpl::createPopupMenu(LocalFrame& frame, PopupMenuClient* client) const
726 {
727     if (WebViewImpl::useExternalPopupMenus())
728         return adoptRefWillBeNoop(new ExternalPopupMenu(frame, client, *m_webView));
729
730     return adoptRefWillBeNoop(new PopupMenuChromium(frame, client));
731 }
732
733 PagePopup* ChromeClientImpl::openPagePopup(PagePopupClient* client, const IntRect& originBoundsInRootView)
734 {
735     ASSERT(m_pagePopupDriver);
736     return m_pagePopupDriver->openPagePopup(client, originBoundsInRootView);
737 }
738
739 void ChromeClientImpl::closePagePopup(PagePopup* popup)
740 {
741     ASSERT(m_pagePopupDriver);
742     m_pagePopupDriver->closePagePopup(popup);
743 }
744
745 void ChromeClientImpl::setPagePopupDriver(PagePopupDriver* driver)
746 {
747     ASSERT(driver);
748     m_pagePopupDriver = driver;
749 }
750
751 void ChromeClientImpl::resetPagePopupDriver()
752 {
753     m_pagePopupDriver = m_webView;
754 }
755
756 bool ChromeClientImpl::shouldRunModalDialogDuringPageDismissal(const DialogType& dialogType, const String& dialogMessage, Document::PageDismissalType dismissalType) const
757 {
758     const char* kDialogs[] = {"alert", "confirm", "prompt", "showModalDialog"};
759     int dialog = static_cast<int>(dialogType);
760     ASSERT_WITH_SECURITY_IMPLICATION(0 <= dialog && dialog < static_cast<int>(arraysize(kDialogs)));
761
762     const char* kDismissals[] = {"beforeunload", "pagehide", "unload"};
763     int dismissal = static_cast<int>(dismissalType) - 1; // Exclude NoDismissal.
764     ASSERT_WITH_SECURITY_IMPLICATION(0 <= dismissal && dismissal < static_cast<int>(arraysize(kDismissals)));
765
766     Platform::current()->histogramEnumeration("Renderer.ModalDialogsDuringPageDismissal", dismissal * arraysize(kDialogs) + dialog, arraysize(kDialogs) * arraysize(kDismissals));
767
768     String message = String("Blocked ") + kDialogs[dialog] + "('" + dialogMessage + "') during " + kDismissals[dismissal] + ".";
769     m_webView->mainFrame()->addMessageToConsole(WebConsoleMessage(WebConsoleMessage::LevelError, message));
770
771     return false;
772 }
773
774 void ChromeClientImpl::needTouchEvents(bool needsTouchEvents)
775 {
776     m_webView->hasTouchEventHandlers(needsTouchEvents);
777 }
778
779 void ChromeClientImpl::setTouchAction(TouchAction touchAction)
780 {
781     if (WebViewClient* client = m_webView->client()) {
782         WebTouchAction webTouchAction = static_cast<WebTouchAction>(touchAction);
783         client->setTouchAction(webTouchAction);
784     }
785 }
786
787 bool ChromeClientImpl::requestPointerLock()
788 {
789     return m_webView->requestPointerLock();
790 }
791
792 void ChromeClientImpl::requestPointerUnlock()
793 {
794     return m_webView->requestPointerUnlock();
795 }
796
797 void ChromeClientImpl::annotatedRegionsChanged()
798 {
799     WebViewClient* client = m_webView->client();
800     if (client)
801         client->draggableRegionsChanged();
802 }
803
804 void ChromeClientImpl::didAssociateFormControls(const WillBeHeapVector<RefPtrWillBeMember<Element> >& elements)
805 {
806     if (m_webView->autofillClient())
807         m_webView->autofillClient()->didAssociateFormControls(elements);
808 }
809
810 void ChromeClientImpl::didCancelCompositionOnSelectionChange()
811 {
812     if (m_webView->client())
813         m_webView->client()->didCancelCompositionOnSelectionChange();
814 }
815
816 void ChromeClientImpl::willSetInputMethodState()
817 {
818     if (m_webView->client())
819         m_webView->client()->resetInputMethod();
820 }
821
822 void ChromeClientImpl::didUpdateTextOfFocusedElementByNonUserInput()
823 {
824     if (m_webView->client())
825         m_webView->client()->didUpdateTextOfFocusedElementByNonUserInput();
826 }
827
828 void ChromeClientImpl::showImeIfNeeded()
829 {
830     if (m_webView->client())
831         m_webView->client()->showImeIfNeeded();
832 }
833
834 void ChromeClientImpl::handleKeyboardEventOnTextField(HTMLInputElement& inputElement, KeyboardEvent& event)
835 {
836     if (!m_webView->autofillClient())
837         return;
838     m_webView->autofillClient()->textFieldDidReceiveKeyDown(WebInputElement(&inputElement), WebKeyboardEventBuilder(event));
839 }
840
841 void ChromeClientImpl::didChangeValueInTextField(HTMLFormControlElement& element)
842 {
843     if (!m_webView->autofillClient())
844         return;
845     m_webView->autofillClient()->textFieldDidChange(WebFormControlElement(&element));
846 }
847
848 void ChromeClientImpl::didEndEditingOnTextField(HTMLInputElement& inputElement)
849 {
850     if (m_webView->autofillClient())
851         m_webView->autofillClient()->textFieldDidEndEditing(WebInputElement(&inputElement));
852 }
853
854 void ChromeClientImpl::openTextDataListChooser(HTMLInputElement& input)
855 {
856     if (m_webView->autofillClient())
857         m_webView->autofillClient()->openTextDataListChooser(WebInputElement(&input));
858 }
859
860 } // namespace blink