Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 /* |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 // found in the LICENSE file. | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 4 | 30 |
| 5 #include "config.h" | 31 #include "config.h" |
| 32 #include "ChromeClientImpl.h" | |
| 6 | 33 |
| 7 #include "AccessibilityObject.h" | 34 #include "AccessibilityObject.h" |
| 8 #include "AXObjectCache.h" | 35 #include "AXObjectCache.h" |
| 9 #include "CharacterNames.h" | 36 #include "CharacterNames.h" |
| 10 #include "Console.h" | 37 #include "Console.h" |
| 11 #include "Cursor.h" | 38 #include "Cursor.h" |
| 12 #include "Document.h" | 39 #include "Document.h" |
| 13 #include "DocumentLoader.h" | 40 #include "DocumentLoader.h" |
| 14 #include "DatabaseTracker.h" | 41 #include "DatabaseTracker.h" |
| 15 #include "FloatRect.h" | 42 #include "FloatRect.h" |
| 16 #include "FileChooser.h" | 43 #include "FileChooser.h" |
| 17 #include "FrameLoadRequest.h" | 44 #include "FrameLoadRequest.h" |
| 18 #include "FrameView.h" | 45 #include "FrameView.h" |
| 19 #include "HitTestResult.h" | 46 #include "HitTestResult.h" |
| 20 #include "IntRect.h" | 47 #include "IntRect.h" |
| 21 #include "Node.h" | 48 #include "Node.h" |
| 49 #include "NotificationPresenterImpl.h" | |
| 22 #include "Page.h" | 50 #include "Page.h" |
| 23 #include "PopupMenuChromium.h" | 51 #include "PopupMenuChromium.h" |
| 24 #include "ScriptController.h" | 52 #include "ScriptController.h" |
| 25 #include "WindowFeatures.h" | |
| 26 #if USE(V8) | 53 #if USE(V8) |
| 27 #include "V8Proxy.h" | 54 #include "V8Proxy.h" |
| 28 #endif | 55 #endif |
| 29 #undef LOG | 56 #include "WebAccessibilityObject.h" |
| 30 | 57 #include "WebConsoleMessage.h" |
| 31 #include "webkit/api/public/WebAccessibilityObject.h" | 58 #include "WebCursorInfo.h" |
| 32 #include "webkit/api/public/WebConsoleMessage.h" | 59 #include "WebFileChooserCompletion.h" |
| 33 #include "webkit/api/public/WebCursorInfo.h" | 60 #include "WebFrameClient.h" |
| 34 #include "webkit/api/public/WebFileChooserCompletion.h" | 61 #include "WebInputEvent.h" |
| 35 #include "webkit/api/public/WebFrameClient.h" | 62 #include "WebKit.h" |
| 36 #include "webkit/api/public/WebInputEvent.h" | 63 #include "WebPopupMenuInfo.h" |
| 37 #include "webkit/api/public/WebKit.h" | 64 #include "WebRect.h" |
| 38 #include "webkit/api/public/WebPopupMenuInfo.h" | 65 #include "WebTextDirection.h" |
| 39 #include "webkit/api/public/WebRect.h" | 66 #include "WebURLRequest.h" |
| 40 #include "webkit/api/public/WebTextDirection.h" | 67 #include "WebViewClient.h" |
| 41 #include "webkit/api/public/WebURLRequest.h" | 68 #include "WebFileChooserCompletionImpl.h" |
| 42 #include "webkit/api/public/WebViewClient.h" | 69 #include "WebPopupMenuImpl.h" |
| 43 #include "webkit/api/src/NotificationPresenterImpl.h" | 70 #include "WindowFeatures.h" |
| 44 #include "webkit/api/src/WebFileChooserCompletionImpl.h" | 71 #include "WrappedResourceRequest.h" |
| 45 #include "webkit/api/src/WrappedResourceRequest.h" | 72 |
| 46 #include "webkit/glue/chrome_client_impl.h" | 73 // FIXME: Remove these once they move out of glue/. |
| 47 #include "webkit/glue/glue_util.h" | |
| 48 #include "webkit/glue/webframe_impl.h" | 74 #include "webkit/glue/webframe_impl.h" |
| 49 #include "webkit/glue/webpopupmenu_impl.h" | |
| 50 #include "webkit/glue/webview_impl.h" | 75 #include "webkit/glue/webview_impl.h" |
| 51 | 76 |
| 52 using WebCore::PopupContainer; | 77 using namespace WebCore; |
| 53 using WebCore::PopupItem; | 78 |
| 54 | 79 namespace WebKit { |
| 55 using WebKit::WebAccessibilityObject; | 80 |
| 56 using WebKit::WebConsoleMessage; | 81 ChromeClientImpl::ChromeClientImpl(WebViewImpl* webView) |
| 57 using WebKit::WebCursorInfo; | 82 : m_webView(webView) |
| 58 using WebKit::WebFileChooserCompletionImpl; | 83 , m_toolbarsVisible(true) |
| 59 using WebKit::WebInputEvent; | 84 , m_statusbarVisible(true) |
| 60 using WebKit::WebMouseEvent; | 85 , m_scrollbarsVisible(true) |
| 61 using WebKit::WebNavigationPolicy; | 86 , m_menubarVisible(true) |
| 62 using WebKit::WebPopupMenuInfo; | 87 , m_resizable(true) |
| 63 using WebKit::WebRect; | 88 , m_ignoreNextSetCursor(false) |
| 64 using WebKit::WebString; | 89 { |
| 65 using WebKit::WebTextDirection; | 90 } |
| 66 using WebKit::WebURL; | 91 |
| 67 using WebKit::WebURLRequest; | 92 ChromeClientImpl::~ChromeClientImpl() |
| 68 using WebKit::WebVector; | 93 { |
| 69 using WebKit::WebViewClient; | 94 } |
| 70 using WebKit::WebWidget; | 95 |
| 71 using WebKit::WrappedResourceRequest; | 96 void ChromeClientImpl::chromeDestroyed() |
| 72 | 97 { |
| 73 using webkit_glue::AccessibilityObjectToWebAccessibilityObject; | 98 // Our lifetime is bound to the WebViewImpl. |
| 74 | 99 } |
| 75 ChromeClientImpl::ChromeClientImpl(WebViewImpl* webview) | 100 |
| 76 : webview_(webview), | 101 void ChromeClientImpl::setWindowRect(const FloatRect& r) |
| 77 toolbars_visible_(true), | 102 { |
| 78 statusbar_visible_(true), | 103 if (m_webView->client()) |
| 79 scrollbars_visible_(true), | 104 m_webView->client()->setWindowRect(IntRect(r)); |
| 80 menubar_visible_(true), | 105 } |
| 81 resizable_(true), | 106 |
| 82 ignore_next_set_cursor_(false) { | 107 FloatRect ChromeClientImpl::windowRect() |
| 83 } | 108 { |
| 84 | 109 WebRect rect; |
| 85 ChromeClientImpl::~ChromeClientImpl() { | 110 if (m_webView->client()) |
| 86 } | 111 rect = m_webView->client()->rootWindowRect(); |
| 87 | 112 else { |
| 88 void ChromeClientImpl::chromeDestroyed() { | 113 // These numbers will be fairly wrong. The window's x/y coordinates will |
| 89 // Our lifetime is bound to the WebViewImpl. | 114 // be the top left corner of the screen and the size will be the content |
| 90 } | 115 // size instead of the window size. |
| 91 | 116 rect.width = m_webView->size().width; |
| 92 void ChromeClientImpl::setWindowRect(const WebCore::FloatRect& r) { | 117 rect.height = m_webView->size().height; |
| 93 if (webview_->client()) { | 118 } |
| 94 webview_->client()->setWindowRect( | 119 return FloatRect(rect); |
| 95 webkit_glue::IntRectToWebRect(WebCore::IntRect(r))); | 120 } |
| 96 } | 121 |
| 97 } | 122 FloatRect ChromeClientImpl::pageRect() |
| 98 | 123 { |
| 99 WebCore::FloatRect ChromeClientImpl::windowRect() { | 124 // We hide the details of the window's border thickness from the web page by |
| 100 WebRect rect; | 125 // simple re-using the window position here. So, from the point-of-view of |
| 101 if (webview_->client()) { | 126 // the web page, the window has no border. |
| 102 rect = webview_->client()->rootWindowRect(); | 127 return windowRect(); |
| 103 } else { | 128 } |
| 104 // These numbers will be fairly wrong. The window's x/y coordinates will | 129 |
| 105 // be the top left corner of the screen and the size will be the content | 130 float ChromeClientImpl::scaleFactor() |
| 106 // size instead of the window size. | 131 { |
| 107 rect.width = webview_->size().width; | 132 // This is supposed to return the scale factor of the web page. It looks like |
| 108 rect.height = webview_->size().height; | 133 // the implementor of the graphics layer is responsible for doing most of the |
| 109 } | 134 // operations associated with scaling. However, this value is used ins some |
| 110 return WebCore::FloatRect(webkit_glue::WebRectToIntRect(rect)); | 135 // cases by WebCore. For example, this is used as a scaling factor in canvas |
| 111 } | 136 // so that things drawn in it are scaled just like the web page is. |
| 112 | 137 // |
| 113 WebCore::FloatRect ChromeClientImpl::pageRect() { | 138 // We don't currently implement scaling, so just return 1.0 (no scaling). |
| 114 // We hide the details of the window's border thickness from the web page by | 139 return 1.0; |
| 115 // simple re-using the window position here. So, from the point-of-view of | 140 } |
| 116 // the web page, the window has no border. | 141 |
| 117 return windowRect(); | 142 void ChromeClientImpl::focus() |
| 118 } | 143 { |
| 119 | 144 if (!m_webView->client()) |
| 120 float ChromeClientImpl::scaleFactor() { | 145 return; |
| 121 // This is supposed to return the scale factor of the web page. It looks like | 146 |
| 122 // the implementor of the graphics layer is responsible for doing most of the | 147 m_webView->client()->didFocus(); |
| 123 // operations associated with scaling. However, this value is used ins some | 148 |
| 124 // cases by WebCore. For example, this is used as a scaling factor in canvas | 149 // If accessibility is enabled, we should notify assistive technology that |
| 125 // so that things drawn in it are scaled just like the web page is. | 150 // the active AccessibilityObject changed. |
| 126 // | 151 const Frame* frame = m_webView->GetFocusedWebCoreFrame(); |
| 127 // We don't currently implement scaling, so just return 1.0 (no scaling). | 152 if (!frame) |
| 128 return 1.0; | 153 return; |
| 129 } | 154 |
| 130 | 155 Document* doc = frame->document(); |
| 131 void ChromeClientImpl::focus() { | 156 |
| 132 if (!webview_->client()) | 157 if (doc && doc->axObjectCache()->accessibilityEnabled()) { |
| 133 return; | 158 Node* focusedNode = m_webView->GetFocusedNode(); |
| 134 | 159 |
| 135 webview_->client()->didFocus(); | 160 if (!focusedNode) { |
| 136 | 161 // Could not retrieve focused Node. |
| 137 // If accessibility is enabled, we should notify assistive technology that | 162 return; |
| 138 // the active AccessibilityObject changed. | 163 } |
| 139 const WebCore::Frame* frame = webview_->GetFocusedWebCoreFrame(); | 164 |
| 140 if (!frame) | 165 // Retrieve the focused AccessibilityObject. |
| 141 return; | 166 AccessibilityObject* focusedAccObj = |
| 142 | 167 doc->axObjectCache()->getOrCreate(focusedNode->renderer()); |
| 143 WebCore::Document* doc = frame->document(); | 168 |
| 144 | 169 // Alert assistive technology that focus changed. |
| 145 if (doc && doc->axObjectCache()->accessibilityEnabled()) { | 170 if (focusedAccObj) |
| 146 WebCore::Node* focused_node = webview_->GetFocusedNode(); | 171 m_webView->client()->focusAccessibilityObject(WebAccessibilityObject(focusedAccObj)); |
| 147 | 172 } |
| 148 if (!focused_node) { | 173 } |
| 149 // Could not retrieve focused Node. | 174 |
| 150 return; | 175 void ChromeClientImpl::unfocus() |
| 151 } | 176 { |
| 152 | 177 if (m_webView->client()) |
| 153 // Retrieve the focused AccessibilityObject. | 178 m_webView->client()->didBlur(); |
| 154 WebCore::AccessibilityObject* focused_acc_obj = | 179 } |
| 155 doc->axObjectCache()->getOrCreate(focused_node->renderer()); | 180 |
| 156 | 181 bool ChromeClientImpl::canTakeFocus(FocusDirection) |
| 157 // Alert assistive technology that focus changed. | 182 { |
| 158 if (focused_acc_obj) { | 183 // For now the browser can always take focus if we're not running layout |
| 159 webview_->client()->focusAccessibilityObject( | 184 // tests. |
| 160 AccessibilityObjectToWebAccessibilityObject(focused_acc_obj)); | 185 return !layoutTestMode(); |
| 161 } | 186 } |
| 162 } | 187 |
| 163 } | 188 void ChromeClientImpl::takeFocus(FocusDirection direction) |
| 164 | 189 { |
| 165 void ChromeClientImpl::unfocus() { | 190 if (!m_webView->client()) |
| 166 if (webview_->client()) | 191 return; |
| 167 webview_->client()->didBlur(); | 192 if (direction == FocusDirectionBackward) |
| 168 } | 193 m_webView->client()->focusPrevious(); |
| 169 | 194 else |
| 170 bool ChromeClientImpl::canTakeFocus(WebCore::FocusDirection) { | 195 m_webView->client()->focusNext(); |
| 171 // For now the browser can always take focus if we're not running layout | 196 } |
| 172 // tests. | 197 |
| 173 return !WebKit::layoutTestMode(); | 198 Page* ChromeClientImpl::createWindow( |
| 174 } | 199 Frame* frame, const FrameLoadRequest& r, const WindowFeatures& features) |
| 175 | 200 { |
| 176 void ChromeClientImpl::takeFocus(WebCore::FocusDirection direction) { | 201 if (!m_webView->client()) |
| 177 if (!webview_->client()) | 202 return 0; |
| 178 return; | 203 |
| 179 if (direction == WebCore::FocusDirectionBackward) { | 204 WebViewImpl* newView = static_cast<WebViewImpl*>( |
| 180 webview_->client()->focusPrevious(); | 205 m_webView->client()->createView(WebFrameImpl::FromFrame(frame))); |
| 181 } else { | 206 if (!newView) |
| 182 webview_->client()->focusNext(); | 207 return 0; |
| 183 } | 208 |
| 184 } | 209 // The request is empty when we are just being asked to open a blank window. |
| 185 | 210 // This corresponds to window.open(""), for example. |
| 186 WebCore::Page* ChromeClientImpl::createWindow( | 211 if (!r.resourceRequest().isEmpty()) { |
| 187 WebCore::Frame* frame, const WebCore::FrameLoadRequest& r, | 212 WrappedResourceRequest request(r.resourceRequest()); |
| 188 const WebCore::WindowFeatures& features) { | 213 newView->main_frame()->loadRequest(request); |
| 189 if (!webview_->client()) | 214 } |
| 190 return NULL; | 215 |
| 191 | 216 return newView->page(); |
| 192 WebViewImpl* new_view = static_cast<WebViewImpl*>( | 217 } |
| 193 webview_->client()->createView(WebFrameImpl::FromFrame(frame))); | 218 |
| 194 if (!new_view) | 219 static inline bool CurrentEventShouldCauseBackgroundTab(const WebInputEvent* inputEvent) |
| 195 return NULL; | 220 { |
| 196 | 221 if (!inputEvent) |
| 197 // The request is empty when we are just being asked to open a blank window. | 222 return false; |
| 198 // This corresponds to window.open(""), for example. | 223 |
| 199 if (!r.resourceRequest().isEmpty()) { | 224 if (inputEvent->type != WebInputEvent::MouseUp) |
| 200 WrappedResourceRequest request(r.resourceRequest()); | 225 return false; |
| 201 new_view->main_frame()->loadRequest(request); | 226 |
| 202 } | 227 const WebMouseEvent* mouseEvent = static_cast<const WebMouseEvent*>(inputEvent); |
| 203 | 228 |
| 204 return new_view->page(); | 229 WebNavigationPolicy policy; |
| 205 } | 230 unsigned short buttonNumber; |
| 206 | 231 switch (mouseEvent->button) { |
| 207 static inline bool CurrentEventShouldCauseBackgroundTab( | 232 case WebMouseEvent::ButtonLeft: |
| 208 const WebInputEvent* input_event) { | 233 buttonNumber = 0; |
| 209 if (!input_event) | 234 break; |
| 235 case WebMouseEvent::ButtonMiddle: | |
| 236 buttonNumber = 1; | |
| 237 break; | |
| 238 case WebMouseEvent::ButtonRight: | |
| 239 buttonNumber = 2; | |
| 240 break; | |
| 241 default: | |
| 242 return false; | |
| 243 } | |
| 244 bool ctrl = mouseEvent->modifiers & WebMouseEvent::ControlKey; | |
| 245 bool shift = mouseEvent->modifiers & WebMouseEvent::ShiftKey; | |
| 246 bool alt = mouseEvent->modifiers & WebMouseEvent::AltKey; | |
| 247 bool meta = mouseEvent->modifiers & WebMouseEvent::MetaKey; | |
| 248 | |
| 249 if (!WebViewImpl::NavigationPolicyFromMouseEvent(buttonNumber, ctrl, shift, alt, meta, &policy)) | |
| 250 return false; | |
| 251 | |
| 252 return policy == WebNavigationPolicyNewBackgroundTab; | |
| 253 } | |
| 254 | |
| 255 void ChromeClientImpl::show() | |
| 256 { | |
| 257 if (!m_webView->client()) | |
| 258 return; | |
| 259 | |
| 260 // If our default configuration was modified by a script or wasn't | |
| 261 // created by a user gesture, then show as a popup. Else, let this | |
| 262 // new window be opened as a toplevel window. | |
| 263 bool asPopup = | |
| 264 !m_toolbarsVisible || | |
| 265 !m_statusbarVisible || | |
| 266 !m_scrollbarsVisible || | |
| 267 !m_menubarVisible || | |
| 268 !m_resizable; | |
| 269 | |
| 270 WebNavigationPolicy policy = WebNavigationPolicyNewForegroundTab; | |
| 271 if (asPopup) | |
| 272 policy = WebNavigationPolicyNewPopup; | |
| 273 if (CurrentEventShouldCauseBackgroundTab(WebViewImpl::current_input_event())) | |
| 274 policy = WebNavigationPolicyNewBackgroundTab; | |
| 275 | |
| 276 m_webView->client()->show(policy); | |
| 277 } | |
| 278 | |
| 279 bool ChromeClientImpl::canRunModal() | |
| 280 { | |
| 281 return m_webView->client() != 0; | |
| 282 } | |
| 283 | |
| 284 void ChromeClientImpl::runModal() | |
| 285 { | |
| 286 if (m_webView->client()) | |
| 287 m_webView->client()->runModal(); | |
| 288 } | |
| 289 | |
| 290 void ChromeClientImpl::setToolbarsVisible(bool value) | |
| 291 { | |
| 292 m_toolbarsVisible = value; | |
| 293 } | |
| 294 | |
| 295 bool ChromeClientImpl::toolbarsVisible() | |
| 296 { | |
| 297 return m_toolbarsVisible; | |
| 298 } | |
| 299 | |
| 300 void ChromeClientImpl::setStatusbarVisible(bool value) | |
| 301 { | |
| 302 m_statusbarVisible = value; | |
| 303 } | |
| 304 | |
| 305 bool ChromeClientImpl::statusbarVisible() | |
| 306 { | |
| 307 return m_statusbarVisible; | |
| 308 } | |
| 309 | |
| 310 void ChromeClientImpl::setScrollbarsVisible(bool value) | |
| 311 { | |
| 312 m_scrollbarsVisible = value; | |
| 313 WebFrameImpl* web_frame = static_cast<WebFrameImpl*>(m_webView->mainFrame()); | |
| 314 if (web_frame) | |
| 315 web_frame->SetAllowsScrolling(value); | |
| 316 } | |
| 317 | |
| 318 bool ChromeClientImpl::scrollbarsVisible() | |
| 319 { | |
| 320 return m_scrollbarsVisible; | |
| 321 } | |
| 322 | |
| 323 void ChromeClientImpl::setMenubarVisible(bool value) | |
| 324 { | |
| 325 m_menubarVisible = value; | |
| 326 } | |
| 327 | |
| 328 bool ChromeClientImpl::menubarVisible() | |
| 329 { | |
| 330 return m_menubarVisible; | |
| 331 } | |
| 332 | |
| 333 void ChromeClientImpl::setResizable(bool value) | |
| 334 { | |
| 335 m_resizable = value; | |
| 336 } | |
| 337 | |
| 338 void ChromeClientImpl::addMessageToConsole(MessageSource source, | |
| 339 MessageType type, | |
| 340 MessageLevel level, | |
| 341 const String& message, | |
| 342 unsigned lineNumber, | |
| 343 const String& sourceID) | |
| 344 { | |
| 345 if (m_webView->client()) { | |
| 346 m_webView->client()->didAddMessageToConsole( | |
| 347 WebConsoleMessage(static_cast<WebConsoleMessage::Level>(level), message), | |
| 348 sourceID, | |
| 349 lineNumber); | |
| 350 } | |
| 351 } | |
| 352 | |
| 353 bool ChromeClientImpl::canRunBeforeUnloadConfirmPanel() | |
| 354 { | |
| 355 return m_webView->client() != 0; | |
| 356 } | |
| 357 | |
| 358 bool ChromeClientImpl::runBeforeUnloadConfirmPanel(const String& message, Frame* frame) | |
| 359 { | |
| 360 if (m_webView->client()) { | |
| 361 return m_webView->client()->runModalBeforeUnloadDialog( | |
| 362 WebFrameImpl::FromFrame(frame), message); | |
| 363 } | |
| 210 return false; | 364 return false; |
| 211 | 365 } |
| 212 if (input_event->type != WebInputEvent::MouseUp) | 366 |
| 367 void ChromeClientImpl::closeWindowSoon() | |
| 368 { | |
| 369 // Make sure this Page can no longer be found by JS. | |
| 370 m_webView->page()->setGroupName(String()); | |
| 371 | |
| 372 // Make sure that all loading is stopped. Ensures that JS stops executing! | |
| 373 m_webView->mainFrame()->stopLoading(); | |
| 374 | |
| 375 if (m_webView->client()) | |
| 376 m_webView->client()->closeWidgetSoon(); | |
| 377 } | |
| 378 | |
| 379 // Although a Frame is passed in, we don't actually use it, since we | |
| 380 // already know our own m_webView. | |
| 381 void ChromeClientImpl::runJavaScriptAlert(Frame* frame, const String& message) | |
| 382 { | |
| 383 if (m_webView->client()) { | |
| 384 #if USE(V8) | |
| 385 // Before showing the JavaScript dialog, we give the proxy implementation | |
| 386 // a chance to process any pending console messages. | |
| 387 V8Proxy::processConsoleMessages(); | |
| 388 #endif | |
| 389 m_webView->client()->runModalAlertDialog( | |
| 390 WebFrameImpl::FromFrame(frame), message); | |
| 391 } | |
| 392 } | |
| 393 | |
| 394 // See comments for runJavaScriptAlert(). | |
| 395 bool ChromeClientImpl::runJavaScriptConfirm(Frame* frame, const String& message) | |
| 396 { | |
| 397 if (m_webView->client()) { | |
| 398 return m_webView->client()->runModalConfirmDialog( | |
| 399 WebFrameImpl::FromFrame(frame), message); | |
| 400 } | |
| 213 return false; | 401 return false; |
| 214 | 402 } |
| 215 const WebMouseEvent* mouse_event = | 403 |
| 216 static_cast<const WebMouseEvent*>(input_event); | 404 // See comments for runJavaScriptAlert(). |
| 217 | 405 bool ChromeClientImpl::runJavaScriptPrompt(Frame* frame, |
| 218 WebNavigationPolicy policy; | 406 const String& message, |
| 219 unsigned short button_number; | 407 const String& defaultValue, |
| 220 switch (mouse_event->button) { | 408 String& result) |
| 221 case WebMouseEvent::ButtonLeft: | 409 { |
| 222 button_number = 0; | 410 if (m_webView->client()) { |
| 223 break; | 411 WebString actualValue; |
| 224 case WebMouseEvent::ButtonMiddle: | 412 bool ok = m_webView->client()->runModalPromptDialog( |
| 225 button_number = 1; | 413 WebFrameImpl::FromFrame(frame), |
| 226 break; | 414 message, |
| 227 case WebMouseEvent::ButtonRight: | 415 defaultValue, |
| 228 button_number = 2; | 416 &actualValue); |
| 229 break; | 417 if (ok) |
| 230 default: | 418 result = actualValue; |
| 231 return false; | 419 return ok; |
| 232 } | 420 } |
| 233 bool ctrl = mouse_event->modifiers & WebMouseEvent::ControlKey; | |
| 234 bool shift = mouse_event->modifiers & WebMouseEvent::ShiftKey; | |
| 235 bool alt = mouse_event->modifiers & WebMouseEvent::AltKey; | |
| 236 bool meta = mouse_event->modifiers & WebMouseEvent::MetaKey; | |
| 237 | |
| 238 if (!WebViewImpl::NavigationPolicyFromMouseEvent(button_number, ctrl, | |
| 239 shift, alt, meta, &policy)) | |
| 240 return false; | 421 return false; |
| 241 | 422 } |
| 242 return policy == WebKit::WebNavigationPolicyNewBackgroundTab; | 423 |
| 243 } | 424 void ChromeClientImpl::setStatusbarText(const String& message) |
| 244 | 425 { |
| 245 void ChromeClientImpl::show() { | 426 if (m_webView->client()) |
| 246 if (!webview_->client()) | 427 m_webView->client()->setStatusText(message); |
| 247 return; | 428 } |
| 248 | 429 |
| 249 // If our default configuration was modified by a script or wasn't | 430 bool ChromeClientImpl::shouldInterruptJavaScript() |
| 250 // created by a user gesture, then show as a popup. Else, let this | 431 { |
| 251 // new window be opened as a toplevel window. | 432 // FIXME: implement me |
| 252 bool as_popup = | 433 return false; |
| 253 !toolbars_visible_ || | 434 } |
| 254 !statusbar_visible_ || | 435 |
| 255 !scrollbars_visible_ || | 436 bool ChromeClientImpl::tabsToLinks() const |
| 256 !menubar_visible_ || | 437 { |
| 257 !resizable_; | 438 // Returns true if anchors should accept keyboard focus with the tab key. |
| 258 | 439 // This method is used in a convoluted fashion by EventHandler::tabsToLinks. |
| 259 WebNavigationPolicy policy = WebKit::WebNavigationPolicyNewForegroundTab; | 440 // It's a twisted path (self-evident, but more complicated than seems |
| 260 if (as_popup) | 441 // necessary), but the net result is that returning true from here, on a |
| 261 policy = WebKit::WebNavigationPolicyNewPopup; | 442 // platform other than MAC or QT, lets anchors get keyboard focus. |
| 262 if (CurrentEventShouldCauseBackgroundTab( | 443 return m_webView->tabsToLinks(); |
| 263 WebViewImpl::current_input_event())) | 444 } |
| 264 policy = WebKit::WebNavigationPolicyNewBackgroundTab; | 445 |
| 265 | 446 IntRect ChromeClientImpl::windowResizerRect() const |
| 266 webview_->client()->show(policy); | 447 { |
| 267 } | 448 IntRect result; |
| 268 | 449 if (m_webView->client()) |
| 269 bool ChromeClientImpl::canRunModal() { | 450 result = m_webView->client()->windowResizerRect(); |
| 270 return webview_->client() != NULL; | 451 return result; |
| 271 } | 452 } |
| 272 | 453 |
| 273 void ChromeClientImpl::runModal() { | 454 void ChromeClientImpl::repaint( |
| 274 if (webview_->client()) | 455 const IntRect& paintRect, bool contentChanged, bool immediate, |
| 275 webview_->client()->runModal(); | 456 bool repaintContentOnly) |
| 276 } | 457 { |
| 277 | 458 // Ignore spurious calls. |
| 278 void ChromeClientImpl::setToolbarsVisible(bool value) { | 459 if (!contentChanged || paintRect.isEmpty()) |
| 279 toolbars_visible_ = value; | 460 return; |
| 280 } | 461 if (m_webView->client()) |
| 281 | 462 m_webView->client()->didInvalidateRect(paintRect); |
| 282 bool ChromeClientImpl::toolbarsVisible() { | 463 } |
| 283 return toolbars_visible_; | 464 |
| 284 } | 465 void ChromeClientImpl::scroll( |
| 285 | 466 const IntSize& scrollDelta, const IntRect& scrollRect, |
| 286 void ChromeClientImpl::setStatusbarVisible(bool value) { | 467 const IntRect& clipRect) |
| 287 statusbar_visible_ = value; | 468 { |
| 288 } | 469 if (m_webView->client()) { |
| 289 | 470 int dx = scrollDelta.width(); |
| 290 bool ChromeClientImpl::statusbarVisible() { | 471 int dy = scrollDelta.height(); |
| 291 return statusbar_visible_; | 472 m_webView->client()->didScrollRect(dx, dy, clipRect); |
| 292 } | 473 } |
| 293 | 474 } |
| 294 void ChromeClientImpl::setScrollbarsVisible(bool value) { | 475 |
| 295 scrollbars_visible_ = value; | 476 IntPoint ChromeClientImpl::screenToWindow(const IntPoint&) const |
| 296 WebFrameImpl* web_frame = static_cast<WebFrameImpl*>(webview_->mainFrame()); | 477 { |
| 297 if (web_frame) | 478 notImplemented(); |
| 298 web_frame->SetAllowsScrolling(value); | 479 return IntPoint(); |
| 299 } | 480 } |
| 300 | 481 |
| 301 bool ChromeClientImpl::scrollbarsVisible() { | 482 IntRect ChromeClientImpl::windowToScreen(const IntRect& rect) const { |
| 302 return scrollbars_visible_; | 483 IntRect screenRect(rect); |
| 303 } | 484 |
| 304 | 485 if (m_webView->client()) { |
| 305 void ChromeClientImpl::setMenubarVisible(bool value) { | 486 WebRect windowRect = m_webView->client()->windowRect(); |
| 306 menubar_visible_ = value; | 487 screenRect.move(windowRect.x, windowRect.y); |
| 307 } | 488 } |
| 308 | 489 |
| 309 bool ChromeClientImpl::menubarVisible() { | 490 return screenRect; |
| 310 return menubar_visible_; | 491 } |
| 311 } | 492 |
| 312 | 493 void ChromeClientImpl::contentsSizeChanged(Frame* frame, const IntSize& size) const |
| 313 void ChromeClientImpl::setResizable(bool value) { | 494 { |
| 314 resizable_ = value; | 495 WebFrameImpl* webframe = WebFrameImpl::FromFrame(frame); |
| 315 } | 496 if (webframe->client()) |
| 316 | 497 webframe->client()->didChangeContentsSize(webframe, size); |
| 317 void ChromeClientImpl::addMessageToConsole(WebCore::MessageSource source, | 498 } |
| 318 WebCore::MessageType type, | 499 |
| 319 WebCore::MessageLevel level, | 500 void ChromeClientImpl::scrollbarsModeDidChange() const |
| 320 const WebCore::String& message, | 501 { |
| 321 unsigned int line_no, | 502 } |
| 322 const WebCore::String& source_id) { | 503 |
| 323 if (webview_->client()) { | 504 void ChromeClientImpl::mouseDidMoveOverElement( |
| 324 webview_->client()->didAddMessageToConsole( | 505 const HitTestResult& result, unsigned modifierFlags) |
| 325 WebConsoleMessage(static_cast<WebConsoleMessage::Level>(level), | 506 { |
| 326 webkit_glue::StringToWebString(message)), | 507 if (!m_webView->client()) |
| 327 webkit_glue::StringToWebString(source_id), | 508 return; |
| 328 line_no); | 509 // Find out if the mouse is over a link, and if so, let our UI know... |
| 329 } | 510 if (result.isLiveLink() && !result.absoluteLinkURL().string().isEmpty()) |
| 330 } | 511 m_webView->client()->setMouseOverURL(result.absoluteLinkURL()); |
| 331 | 512 else |
| 332 bool ChromeClientImpl::canRunBeforeUnloadConfirmPanel() { | 513 m_webView->client()->setMouseOverURL(WebURL()); |
| 333 return webview_->client() != NULL; | 514 } |
| 334 } | 515 |
| 335 | 516 void ChromeClientImpl::setToolTip(const String& tooltipText, TextDirection dir) |
| 336 bool ChromeClientImpl::runBeforeUnloadConfirmPanel( | 517 { |
| 337 const WebCore::String& message, | 518 if (!m_webView->client()) |
| 338 WebCore::Frame* frame) { | 519 return; |
| 339 if (webview_->client()) { | 520 WebTextDirection textDirection = (dir == RTL) ? |
| 340 return webview_->client()->runModalBeforeUnloadDialog( | 521 WebTextDirectionRightToLeft : |
| 341 WebFrameImpl::FromFrame(frame), | 522 WebTextDirectionLeftToRight; |
| 342 webkit_glue::StringToWebString(message)); | 523 m_webView->client()->setToolTipText( |
| 343 } | 524 tooltipText, textDirection); |
| 344 return false; | 525 } |
| 345 } | 526 |
| 346 | 527 void ChromeClientImpl::print(Frame* frame) |
| 347 void ChromeClientImpl::closeWindowSoon() { | 528 { |
| 348 // Make sure this Page can no longer be found by JS. | 529 if (m_webView->client()) |
| 349 webview_->page()->setGroupName(WebCore::String()); | 530 m_webView->client()->printPage(WebFrameImpl::FromFrame(frame)); |
| 350 | 531 } |
| 351 // Make sure that all loading is stopped. Ensures that JS stops executing! | 532 |
| 352 webview_->mainFrame()->stopLoading(); | 533 void ChromeClientImpl::exceededDatabaseQuota(Frame* frame, const String& databaseName) |
| 353 | 534 { |
| 354 if (webview_->client()) | 535 // set a reasonable quota for now -- 5Mb should be enough for anybody |
| 355 webview_->client()->closeWidgetSoon(); | 536 // TODO(dglazkov): this should be configurable |
| 356 } | 537 SecurityOrigin* origin = frame->document()->securityOrigin(); |
| 357 | 538 DatabaseTracker::tracker().setQuota(origin, 1024 * 1024 * 5); |
| 358 // Although a WebCore::Frame is passed in, we don't actually use it, since we | 539 } |
| 359 // already know our own webview_. | 540 |
| 360 void ChromeClientImpl::runJavaScriptAlert(WebCore::Frame* frame, | 541 #if ENABLE(OFFLINE_WEB_APPLICATIONS) |
| 361 const WebCore::String& message) { | 542 void ChromeClientImpl::reachedMaxAppCacheSize(int64_t spaceNeeded) |
| 362 if (webview_->client()) { | 543 { |
| 363 #if USE(V8) | 544 ASSERT_NOT_REACHED(); |
| 364 // Before showing the JavaScript dialog, we give the proxy implementation | 545 } |
| 365 // a chance to process any pending console messages. | |
| 366 WebCore::V8Proxy::processConsoleMessages(); | |
| 367 #endif | 546 #endif |
| 368 webview_->client()->runModalAlertDialog( | 547 |
| 369 WebFrameImpl::FromFrame(frame), | 548 void ChromeClientImpl::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> fileChooser) |
| 370 webkit_glue::StringToWebString(message)); | 549 { |
| 371 } | 550 WebViewClient* client = m_webView->client(); |
| 372 } | 551 if (!client) |
| 373 | 552 return; |
| 374 // See comments for runJavaScriptAlert(). | 553 |
| 375 bool ChromeClientImpl::runJavaScriptConfirm(WebCore::Frame* frame, | 554 bool multipleFiles = fileChooser->allowsMultipleFiles(); |
| 376 const WebCore::String& message) { | 555 |
| 377 if (webview_->client()) { | 556 WebString suggestion; |
| 378 return webview_->client()->runModalConfirmDialog( | 557 if (fileChooser->filenames().size() > 0) |
| 379 WebFrameImpl::FromFrame(frame), | 558 suggestion = fileChooser->filenames()[0]; |
| 380 webkit_glue::StringToWebString(message)); | 559 |
| 381 } | 560 WebFileChooserCompletionImpl* chooserCompletion = |
| 382 return false; | 561 new WebFileChooserCompletionImpl(fileChooser); |
| 383 } | 562 bool ok = client->runFileChooser(multipleFiles, |
| 384 | 563 WebString(), |
| 385 // See comments for runJavaScriptAlert(). | 564 suggestion, |
| 386 bool ChromeClientImpl::runJavaScriptPrompt(WebCore::Frame* frame, | 565 chooserCompletion); |
| 387 const WebCore::String& message, | 566 if (!ok) { |
| 388 const WebCore::String& default_value, | 567 // Choosing failed, so do callback with an empty list. |
| 389 WebCore::String& result) { | 568 chooserCompletion->didChooseFile(WebVector<WebString>()); |
|
yaar
2009/10/27 18:48:34
nit: 4 space indent
| |
| 390 if (webview_->client()) { | 569 } |
| 391 WebString actual_value; | 570 } |
| 392 bool ok = webview_->client()->runModalPromptDialog( | 571 |
| 393 WebFrameImpl::FromFrame(frame), | 572 void ChromeClientImpl::popupOpened(PopupContainer* popupContainer, |
| 394 webkit_glue::StringToWebString(message), | 573 const IntRect& bounds, |
| 395 webkit_glue::StringToWebString(default_value), | 574 bool activatable, |
| 396 &actual_value); | 575 bool handleExternally) |
| 397 if (ok) | 576 { |
| 398 result = webkit_glue::WebStringToString(actual_value); | 577 if (!m_webView->client()) |
| 399 return ok; | 578 return; |
| 400 } | 579 |
| 401 return false; | 580 WebWidget* webwidget; |
| 402 } | 581 if (handleExternally) { |
| 403 | 582 WebPopupMenuInfo popupInfo; |
| 404 void ChromeClientImpl::setStatusbarText(const WebCore::String& message) { | 583 getPopupMenuInfo(popupContainer, &popupInfo); |
| 405 if (webview_->client()) { | 584 webwidget = m_webView->client()->createPopupMenu(popupInfo); |
| 406 webview_->client()->setStatusText( | 585 } else |
| 407 webkit_glue::StringToWebString(message)); | 586 webwidget = m_webView->client()->createPopupMenu(activatable); |
| 408 } | 587 |
| 409 } | 588 static_cast<WebPopupMenuImpl*>(webwidget)->Init(popupContainer, bounds); |
| 410 | 589 } |
| 411 bool ChromeClientImpl::shouldInterruptJavaScript() { | 590 |
| 412 // TODO(mbelshe): implement me | 591 void ChromeClientImpl::setCursor(const WebCursorInfo& cursor) |
| 413 return false; | 592 { |
| 414 } | 593 if (m_ignoreNextSetCursor) { |
| 415 | 594 m_ignoreNextSetCursor = false; |
| 416 bool ChromeClientImpl::tabsToLinks() const { | 595 return; |
| 417 return webview_->tabsToLinks(); | 596 } |
| 418 } | 597 |
| 419 | 598 if (m_webView->client()) |
| 420 WebCore::IntRect ChromeClientImpl::windowResizerRect() const { | 599 m_webView->client()->didChangeCursor(cursor); |
| 421 WebCore::IntRect result; | 600 } |
| 422 if (webview_->client()) { | 601 |
| 423 result = webkit_glue::WebRectToIntRect( | 602 void ChromeClientImpl::setCursorForPlugin(const WebCursorInfo& cursor) |
| 424 webview_->client()->windowResizerRect()); | 603 { |
| 425 } | 604 setCursor(cursor); |
| 426 return result; | 605 |
| 427 } | 606 // Currently, Widget::setCursor is always called after this function in |
| 428 | 607 // EventHandler.cpp and since we don't want that we set a flag indicating |
| 429 void ChromeClientImpl::repaint( | 608 // that the next SetCursor call is to be ignored. |
| 430 const WebCore::IntRect& paint_rect, bool content_changed, bool immediate, | 609 m_ignoreNextSetCursor = true; |
| 431 bool repaint_content_only) { | 610 } |
| 432 // Ignore spurious calls. | 611 |
| 433 if (!content_changed || paint_rect.isEmpty()) | 612 void ChromeClientImpl::formStateDidChange(const Node* node) |
| 434 return; | 613 { |
| 435 if (webview_->client()) { | 614 // The current history item is not updated yet. That happens lazily when |
| 436 webview_->client()->didInvalidateRect( | 615 // WebFrame::currentHistoryItem is requested. |
| 437 webkit_glue::IntRectToWebRect(paint_rect)); | 616 WebFrameImpl* webframe = WebFrameImpl::FromFrame(node->document()->frame()); |
| 438 } | 617 if (webframe->client()) |
| 439 } | 618 webframe->client()->didUpdateCurrentHistoryItem(webframe); |
| 440 | 619 } |
| 441 void ChromeClientImpl::scroll( | 620 |
| 442 const WebCore::IntSize& scroll_delta, const WebCore::IntRect& scroll_rect, | 621 void ChromeClientImpl::getPopupMenuInfo(PopupContainer* popupContainer, |
| 443 const WebCore::IntRect& clip_rect) { | 622 WebPopupMenuInfo* info) |
| 444 if (webview_->client()) { | 623 { |
| 445 int dx = scroll_delta.width(); | 624 const Vector<PopupItem*>& inputItems = popupContainer->popupData(); |
| 446 int dy = scroll_delta.height(); | 625 |
| 447 webview_->client()->didScrollRect( | 626 WebVector<WebPopupMenuInfo::Item> outputItems(inputItems.size()); |
| 448 dx, dy, webkit_glue::IntRectToWebRect(clip_rect)); | 627 |
| 449 } | 628 for (size_t i = 0; i < inputItems.size(); ++i) { |
| 450 } | 629 const PopupItem& inputItem = *inputItems[i]; |
| 451 | 630 WebPopupMenuInfo::Item& outputItem = outputItems[i]; |
| 452 WebCore::IntPoint ChromeClientImpl::screenToWindow( | 631 |
| 453 const WebCore::IntPoint&) const { | 632 outputItem.label = inputItem.label; |
| 454 notImplemented(); | 633 outputItem.enabled = inputItem.enabled; |
| 455 return WebCore::IntPoint(); | 634 |
| 456 } | 635 switch (inputItem.type) { |
| 457 | 636 case PopupItem::TypeOption: |
| 458 WebCore::IntRect ChromeClientImpl::windowToScreen( | 637 outputItem.type = WebPopupMenuInfo::Item::Option; |
| 459 const WebCore::IntRect& rect) const { | 638 break; |
| 460 WebCore::IntRect screen_rect(rect); | 639 case PopupItem::TypeGroup: |
| 461 | 640 outputItem.type = WebPopupMenuInfo::Item::Group; |
| 462 if (webview_->client()) { | 641 break; |
| 463 WebRect window_rect = webview_->client()->windowRect(); | 642 case PopupItem::TypeSeparator: |
| 464 screen_rect.move(window_rect.x, window_rect.y); | 643 outputItem.type = WebPopupMenuInfo::Item::Separator; |
| 465 } | 644 break; |
| 466 | 645 default: |
| 467 return screen_rect; | 646 ASSERT_NOT_REACHED(); |
| 468 } | 647 } |
| 469 | 648 } |
| 470 void ChromeClientImpl::contentsSizeChanged(WebCore::Frame* frame, const | 649 |
| 471 WebCore::IntSize& size) const { | 650 info->itemHeight = popupContainer->menuItemHeight(); |
| 472 WebFrameImpl* webframe = WebFrameImpl::FromFrame(frame); | 651 info->selectedIndex = popupContainer->selectedIndex(); |
| 473 if (webframe->client()) { | 652 info->items.swap(outputItems); |
| 474 webframe->client()->didChangeContentsSize( | 653 } |
| 475 webframe, webkit_glue::IntSizeToWebSize(size)); | 654 |
| 476 } | 655 #if ENABLE(NOTIFICATIONS) |
| 477 } | 656 NotificationPresenter* ChromeClientImpl::notificationPresenter() const |
| 478 | 657 { |
| 479 void ChromeClientImpl::scrollbarsModeDidChange() const { | 658 return m_webView->GetNotificationPresenter(); |
| 480 } | |
| 481 | |
| 482 void ChromeClientImpl::mouseDidMoveOverElement( | |
| 483 const WebCore::HitTestResult& result, unsigned modifier_flags) { | |
| 484 if (!webview_->client()) | |
| 485 return; | |
| 486 // Find out if the mouse is over a link, and if so, let our UI know... | |
| 487 if (result.isLiveLink() && !result.absoluteLinkURL().string().isEmpty()) { | |
| 488 webview_->client()->setMouseOverURL( | |
| 489 webkit_glue::KURLToWebURL(result.absoluteLinkURL())); | |
| 490 } else { | |
| 491 webview_->client()->setMouseOverURL(WebURL()); | |
| 492 } | |
| 493 } | |
| 494 | |
| 495 void ChromeClientImpl::setToolTip(const WebCore::String& tooltip_text, | |
| 496 WebCore::TextDirection dir) { | |
| 497 if (!webview_->client()) | |
| 498 return; | |
| 499 WebTextDirection text_direction = (dir == WebCore::RTL) ? | |
| 500 WebKit::WebTextDirectionRightToLeft : | |
| 501 WebKit::WebTextDirectionLeftToRight; | |
| 502 webview_->client()->setToolTipText( | |
| 503 webkit_glue::StringToWebString(tooltip_text), text_direction); | |
| 504 } | |
| 505 | |
| 506 void ChromeClientImpl::print(WebCore::Frame* frame) { | |
| 507 if (webview_->client()) | |
| 508 webview_->client()->printPage(WebFrameImpl::FromFrame(frame)); | |
| 509 } | |
| 510 | |
| 511 void ChromeClientImpl::exceededDatabaseQuota(WebCore::Frame* frame, | |
| 512 const WebCore::String& databaseName) { | |
| 513 // set a reasonable quota for now -- 5Mb should be enough for anybody | |
| 514 // TODO(dglazkov): this should be configurable | |
| 515 WebCore::SecurityOrigin* origin = frame->document()->securityOrigin(); | |
| 516 WebCore::DatabaseTracker::tracker().setQuota(origin, 1024 * 1024 * 5); | |
| 517 } | |
| 518 | |
| 519 #if ENABLE(OFFLINE_WEB_APPLICATIONS) | |
| 520 void ChromeClientImpl::reachedMaxAppCacheSize(int64_t space_needed) { | |
| 521 ASSERT_NOT_REACHED(); | |
| 522 } | 659 } |
| 523 #endif | 660 #endif |
| 524 | 661 |
| 525 void ChromeClientImpl::runOpenPanel(WebCore::Frame* frame, | 662 } // namespace WebKit |
| 526 PassRefPtr<WebCore::FileChooser> file_chooser) { | |
| 527 WebViewClient* client = webview_->client(); | |
| 528 if (!client) | |
| 529 return; | |
| 530 | |
| 531 bool multiple_files = file_chooser->allowsMultipleFiles(); | |
| 532 | |
| 533 WebString suggestion; | |
| 534 if (file_chooser->filenames().size() > 0) | |
| 535 suggestion = webkit_glue::StringToWebString(file_chooser->filenames()[0]); | |
| 536 | |
| 537 WebFileChooserCompletionImpl* chooser_completion = | |
| 538 new WebFileChooserCompletionImpl(file_chooser); | |
| 539 bool ok = client->runFileChooser(multiple_files, | |
| 540 WebString(), | |
| 541 suggestion, | |
| 542 chooser_completion); | |
| 543 if (!ok) { | |
| 544 // Choosing failed, so do callback with an empty list. | |
| 545 chooser_completion->didChooseFile(WebVector<WebString>()); | |
| 546 } | |
| 547 } | |
| 548 | |
| 549 void ChromeClientImpl::popupOpened(PopupContainer* popup_container, | |
| 550 const WebCore::IntRect& bounds, | |
| 551 bool activatable, | |
| 552 bool handle_externally) { | |
| 553 if (!webview_->client()) | |
| 554 return; | |
| 555 | |
| 556 WebWidget* webwidget; | |
| 557 if (handle_externally) { | |
| 558 WebPopupMenuInfo popup_info; | |
| 559 GetPopupMenuInfo(popup_container, &popup_info); | |
| 560 webwidget = webview_->client()->createPopupMenu(popup_info); | |
| 561 } else { | |
| 562 webwidget = webview_->client()->createPopupMenu(activatable); | |
| 563 } | |
| 564 | |
| 565 static_cast<WebPopupMenuImpl*>(webwidget)->Init( | |
| 566 popup_container, webkit_glue::IntRectToWebRect(bounds)); | |
| 567 } | |
| 568 | |
| 569 void ChromeClientImpl::SetCursor(const WebCursorInfo& cursor) { | |
| 570 if (ignore_next_set_cursor_) { | |
| 571 ignore_next_set_cursor_ = false; | |
| 572 return; | |
| 573 } | |
| 574 | |
| 575 if (webview_->client()) | |
| 576 webview_->client()->didChangeCursor(cursor); | |
| 577 } | |
| 578 | |
| 579 void ChromeClientImpl::SetCursorForPlugin(const WebCursorInfo& cursor) { | |
| 580 SetCursor(cursor); | |
| 581 // Currently, Widget::setCursor is always called after this function in | |
| 582 // EventHandler.cpp and since we don't want that we set a flag indicating | |
| 583 // that the next SetCursor call is to be ignored. | |
| 584 ignore_next_set_cursor_ = true; | |
| 585 } | |
| 586 | |
| 587 void ChromeClientImpl::formStateDidChange(const WebCore::Node* node) { | |
| 588 // The current history item is not updated yet. That happens lazily when | |
| 589 // WebFrame::currentHistoryItem is requested. | |
| 590 WebFrameImpl* webframe = WebFrameImpl::FromFrame(node->document()->frame()); | |
| 591 if (webframe->client()) | |
| 592 webframe->client()->didUpdateCurrentHistoryItem(webframe); | |
| 593 } | |
| 594 | |
| 595 void ChromeClientImpl::GetPopupMenuInfo(PopupContainer* popup_container, | |
| 596 WebPopupMenuInfo* info) { | |
| 597 const Vector<PopupItem*>& input_items = popup_container->popupData(); | |
| 598 | |
| 599 WebVector<WebPopupMenuInfo::Item> output_items(input_items.size()); | |
| 600 | |
| 601 for (size_t i = 0; i < input_items.size(); ++i) { | |
| 602 const PopupItem& input_item = *input_items[i]; | |
| 603 WebPopupMenuInfo::Item& output_item = output_items[i]; | |
| 604 | |
| 605 output_item.label = webkit_glue::StringToWebString(input_item.label); | |
| 606 output_item.enabled = input_item.enabled; | |
| 607 | |
| 608 switch (input_item.type) { | |
| 609 case PopupItem::TypeOption: | |
| 610 output_item.type = WebPopupMenuInfo::Item::Option; | |
| 611 break; | |
| 612 case PopupItem::TypeGroup: | |
| 613 output_item.type = WebPopupMenuInfo::Item::Group; | |
| 614 break; | |
| 615 case PopupItem::TypeSeparator: | |
| 616 output_item.type = WebPopupMenuInfo::Item::Separator; | |
| 617 break; | |
| 618 default: | |
| 619 ASSERT_NOT_REACHED(); | |
| 620 } | |
| 621 } | |
| 622 | |
| 623 info->itemHeight = popup_container->menuItemHeight(); | |
| 624 info->selectedIndex = popup_container->selectedIndex(); | |
| 625 info->items.swap(output_items); | |
| 626 } | |
| 627 | |
| 628 #if ENABLE(NOTIFICATIONS) | |
| 629 WebCore::NotificationPresenter* ChromeClientImpl::notificationPresenter() const { | |
| 630 return webview_->GetNotificationPresenter(); | |
| 631 } | |
| 632 #endif | |
| OLD | NEW |