| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 | |
| 7 #include "AccessibilityObject.h" | |
| 8 #include "AXObjectCache.h" | |
| 9 #include "CharacterNames.h" | |
| 10 #include "Console.h" | |
| 11 #include "Cursor.h" | |
| 12 #include "Document.h" | |
| 13 #include "DocumentLoader.h" | |
| 14 #include "DatabaseTracker.h" | |
| 15 #include "FloatRect.h" | |
| 16 #include "FileChooser.h" | |
| 17 #include "FrameLoadRequest.h" | |
| 18 #include "FrameView.h" | |
| 19 #include "HitTestResult.h" | |
| 20 #include "IntRect.h" | |
| 21 #include "Node.h" | |
| 22 #include "Page.h" | |
| 23 #include "PopupMenuChromium.h" | |
| 24 #include "ScriptController.h" | |
| 25 #include "WindowFeatures.h" | |
| 26 #if USE(V8) | |
| 27 #include "V8Proxy.h" | |
| 28 #endif | |
| 29 #undef LOG | |
| 30 | |
| 31 #include "webkit/api/public/WebAccessibilityObject.h" | |
| 32 #include "webkit/api/public/WebConsoleMessage.h" | |
| 33 #include "webkit/api/public/WebCursorInfo.h" | |
| 34 #include "webkit/api/public/WebFileChooserCompletion.h" | |
| 35 #include "webkit/api/public/WebFrameClient.h" | |
| 36 #include "webkit/api/public/WebInputEvent.h" | |
| 37 #include "webkit/api/public/WebKit.h" | |
| 38 #include "webkit/api/public/WebPopupMenuInfo.h" | |
| 39 #include "webkit/api/public/WebRect.h" | |
| 40 #include "webkit/api/public/WebTextDirection.h" | |
| 41 #include "webkit/api/public/WebURLRequest.h" | |
| 42 #include "webkit/api/public/WebViewClient.h" | |
| 43 #include "webkit/api/src/NotificationPresenterImpl.h" | |
| 44 #include "webkit/api/src/WebFileChooserCompletionImpl.h" | |
| 45 #include "webkit/api/src/WrappedResourceRequest.h" | |
| 46 #include "webkit/glue/chrome_client_impl.h" | |
| 47 #include "webkit/glue/glue_util.h" | |
| 48 #include "webkit/glue/webframe_impl.h" | |
| 49 #include "webkit/glue/webpopupmenu_impl.h" | |
| 50 #include "webkit/glue/webview_impl.h" | |
| 51 | |
| 52 using WebCore::PopupContainer; | |
| 53 using WebCore::PopupItem; | |
| 54 | |
| 55 using WebKit::WebAccessibilityObject; | |
| 56 using WebKit::WebConsoleMessage; | |
| 57 using WebKit::WebCursorInfo; | |
| 58 using WebKit::WebFileChooserCompletionImpl; | |
| 59 using WebKit::WebInputEvent; | |
| 60 using WebKit::WebMouseEvent; | |
| 61 using WebKit::WebNavigationPolicy; | |
| 62 using WebKit::WebPopupMenuInfo; | |
| 63 using WebKit::WebRect; | |
| 64 using WebKit::WebString; | |
| 65 using WebKit::WebTextDirection; | |
| 66 using WebKit::WebURL; | |
| 67 using WebKit::WebURLRequest; | |
| 68 using WebKit::WebVector; | |
| 69 using WebKit::WebViewClient; | |
| 70 using WebKit::WebWidget; | |
| 71 using WebKit::WrappedResourceRequest; | |
| 72 | |
| 73 using webkit_glue::AccessibilityObjectToWebAccessibilityObject; | |
| 74 | |
| 75 ChromeClientImpl::ChromeClientImpl(WebViewImpl* webview) | |
| 76 : webview_(webview), | |
| 77 toolbars_visible_(true), | |
| 78 statusbar_visible_(true), | |
| 79 scrollbars_visible_(true), | |
| 80 menubar_visible_(true), | |
| 81 resizable_(true), | |
| 82 ignore_next_set_cursor_(false) { | |
| 83 } | |
| 84 | |
| 85 ChromeClientImpl::~ChromeClientImpl() { | |
| 86 } | |
| 87 | |
| 88 void ChromeClientImpl::chromeDestroyed() { | |
| 89 // Our lifetime is bound to the WebViewImpl. | |
| 90 } | |
| 91 | |
| 92 void ChromeClientImpl::setWindowRect(const WebCore::FloatRect& r) { | |
| 93 if (webview_->client()) { | |
| 94 webview_->client()->setWindowRect( | |
| 95 webkit_glue::IntRectToWebRect(WebCore::IntRect(r))); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 WebCore::FloatRect ChromeClientImpl::windowRect() { | |
| 100 WebRect rect; | |
| 101 if (webview_->client()) { | |
| 102 rect = webview_->client()->rootWindowRect(); | |
| 103 } else { | |
| 104 // These numbers will be fairly wrong. The window's x/y coordinates will | |
| 105 // be the top left corner of the screen and the size will be the content | |
| 106 // size instead of the window size. | |
| 107 rect.width = webview_->size().width; | |
| 108 rect.height = webview_->size().height; | |
| 109 } | |
| 110 return WebCore::FloatRect(webkit_glue::WebRectToIntRect(rect)); | |
| 111 } | |
| 112 | |
| 113 WebCore::FloatRect ChromeClientImpl::pageRect() { | |
| 114 // We hide the details of the window's border thickness from the web page by | |
| 115 // simple re-using the window position here. So, from the point-of-view of | |
| 116 // the web page, the window has no border. | |
| 117 return windowRect(); | |
| 118 } | |
| 119 | |
| 120 float ChromeClientImpl::scaleFactor() { | |
| 121 // This is supposed to return the scale factor of the web page. It looks like | |
| 122 // the implementor of the graphics layer is responsible for doing most of the | |
| 123 // operations associated with scaling. However, this value is used ins some | |
| 124 // cases by WebCore. For example, this is used as a scaling factor in canvas | |
| 125 // so that things drawn in it are scaled just like the web page is. | |
| 126 // | |
| 127 // We don't currently implement scaling, so just return 1.0 (no scaling). | |
| 128 return 1.0; | |
| 129 } | |
| 130 | |
| 131 void ChromeClientImpl::focus() { | |
| 132 if (!webview_->client()) | |
| 133 return; | |
| 134 | |
| 135 webview_->client()->didFocus(); | |
| 136 | |
| 137 // If accessibility is enabled, we should notify assistive technology that | |
| 138 // the active AccessibilityObject changed. | |
| 139 const WebCore::Frame* frame = webview_->GetFocusedWebCoreFrame(); | |
| 140 if (!frame) | |
| 141 return; | |
| 142 | |
| 143 WebCore::Document* doc = frame->document(); | |
| 144 | |
| 145 if (doc && doc->axObjectCache()->accessibilityEnabled()) { | |
| 146 WebCore::Node* focused_node = webview_->GetFocusedNode(); | |
| 147 | |
| 148 if (!focused_node) { | |
| 149 // Could not retrieve focused Node. | |
| 150 return; | |
| 151 } | |
| 152 | |
| 153 // Retrieve the focused AccessibilityObject. | |
| 154 WebCore::AccessibilityObject* focused_acc_obj = | |
| 155 doc->axObjectCache()->getOrCreate(focused_node->renderer()); | |
| 156 | |
| 157 // Alert assistive technology that focus changed. | |
| 158 if (focused_acc_obj) { | |
| 159 webview_->client()->focusAccessibilityObject( | |
| 160 AccessibilityObjectToWebAccessibilityObject(focused_acc_obj)); | |
| 161 } | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 void ChromeClientImpl::unfocus() { | |
| 166 if (webview_->client()) | |
| 167 webview_->client()->didBlur(); | |
| 168 } | |
| 169 | |
| 170 bool ChromeClientImpl::canTakeFocus(WebCore::FocusDirection) { | |
| 171 // For now the browser can always take focus if we're not running layout | |
| 172 // tests. | |
| 173 return !WebKit::layoutTestMode(); | |
| 174 } | |
| 175 | |
| 176 void ChromeClientImpl::takeFocus(WebCore::FocusDirection direction) { | |
| 177 if (!webview_->client()) | |
| 178 return; | |
| 179 if (direction == WebCore::FocusDirectionBackward) { | |
| 180 webview_->client()->focusPrevious(); | |
| 181 } else { | |
| 182 webview_->client()->focusNext(); | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 WebCore::Page* ChromeClientImpl::createWindow( | |
| 187 WebCore::Frame* frame, const WebCore::FrameLoadRequest& r, | |
| 188 const WebCore::WindowFeatures& features) { | |
| 189 if (!webview_->client()) | |
| 190 return NULL; | |
| 191 | |
| 192 WebViewImpl* new_view = static_cast<WebViewImpl*>( | |
| 193 webview_->client()->createView(WebFrameImpl::FromFrame(frame))); | |
| 194 if (!new_view) | |
| 195 return NULL; | |
| 196 | |
| 197 // The request is empty when we are just being asked to open a blank window. | |
| 198 // This corresponds to window.open(""), for example. | |
| 199 if (!r.resourceRequest().isEmpty()) { | |
| 200 WrappedResourceRequest request(r.resourceRequest()); | |
| 201 new_view->main_frame()->loadRequest(request); | |
| 202 } | |
| 203 | |
| 204 return new_view->page(); | |
| 205 } | |
| 206 | |
| 207 static inline bool CurrentEventShouldCauseBackgroundTab( | |
| 208 const WebInputEvent* input_event) { | |
| 209 if (!input_event) | |
| 210 return false; | |
| 211 | |
| 212 if (input_event->type != WebInputEvent::MouseUp) | |
| 213 return false; | |
| 214 | |
| 215 const WebMouseEvent* mouse_event = | |
| 216 static_cast<const WebMouseEvent*>(input_event); | |
| 217 | |
| 218 WebNavigationPolicy policy; | |
| 219 unsigned short button_number; | |
| 220 switch (mouse_event->button) { | |
| 221 case WebMouseEvent::ButtonLeft: | |
| 222 button_number = 0; | |
| 223 break; | |
| 224 case WebMouseEvent::ButtonMiddle: | |
| 225 button_number = 1; | |
| 226 break; | |
| 227 case WebMouseEvent::ButtonRight: | |
| 228 button_number = 2; | |
| 229 break; | |
| 230 default: | |
| 231 return false; | |
| 232 } | |
| 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; | |
| 241 | |
| 242 return policy == WebKit::WebNavigationPolicyNewBackgroundTab; | |
| 243 } | |
| 244 | |
| 245 void ChromeClientImpl::show() { | |
| 246 if (!webview_->client()) | |
| 247 return; | |
| 248 | |
| 249 // If our default configuration was modified by a script or wasn't | |
| 250 // created by a user gesture, then show as a popup. Else, let this | |
| 251 // new window be opened as a toplevel window. | |
| 252 bool as_popup = | |
| 253 !toolbars_visible_ || | |
| 254 !statusbar_visible_ || | |
| 255 !scrollbars_visible_ || | |
| 256 !menubar_visible_ || | |
| 257 !resizable_; | |
| 258 | |
| 259 WebNavigationPolicy policy = WebKit::WebNavigationPolicyNewForegroundTab; | |
| 260 if (as_popup) | |
| 261 policy = WebKit::WebNavigationPolicyNewPopup; | |
| 262 if (CurrentEventShouldCauseBackgroundTab( | |
| 263 WebViewImpl::current_input_event())) | |
| 264 policy = WebKit::WebNavigationPolicyNewBackgroundTab; | |
| 265 | |
| 266 webview_->client()->show(policy); | |
| 267 } | |
| 268 | |
| 269 bool ChromeClientImpl::canRunModal() { | |
| 270 return webview_->client() != NULL; | |
| 271 } | |
| 272 | |
| 273 void ChromeClientImpl::runModal() { | |
| 274 if (webview_->client()) | |
| 275 webview_->client()->runModal(); | |
| 276 } | |
| 277 | |
| 278 void ChromeClientImpl::setToolbarsVisible(bool value) { | |
| 279 toolbars_visible_ = value; | |
| 280 } | |
| 281 | |
| 282 bool ChromeClientImpl::toolbarsVisible() { | |
| 283 return toolbars_visible_; | |
| 284 } | |
| 285 | |
| 286 void ChromeClientImpl::setStatusbarVisible(bool value) { | |
| 287 statusbar_visible_ = value; | |
| 288 } | |
| 289 | |
| 290 bool ChromeClientImpl::statusbarVisible() { | |
| 291 return statusbar_visible_; | |
| 292 } | |
| 293 | |
| 294 void ChromeClientImpl::setScrollbarsVisible(bool value) { | |
| 295 scrollbars_visible_ = value; | |
| 296 WebFrameImpl* web_frame = static_cast<WebFrameImpl*>(webview_->mainFrame()); | |
| 297 if (web_frame) | |
| 298 web_frame->SetAllowsScrolling(value); | |
| 299 } | |
| 300 | |
| 301 bool ChromeClientImpl::scrollbarsVisible() { | |
| 302 return scrollbars_visible_; | |
| 303 } | |
| 304 | |
| 305 void ChromeClientImpl::setMenubarVisible(bool value) { | |
| 306 menubar_visible_ = value; | |
| 307 } | |
| 308 | |
| 309 bool ChromeClientImpl::menubarVisible() { | |
| 310 return menubar_visible_; | |
| 311 } | |
| 312 | |
| 313 void ChromeClientImpl::setResizable(bool value) { | |
| 314 resizable_ = value; | |
| 315 } | |
| 316 | |
| 317 void ChromeClientImpl::addMessageToConsole(WebCore::MessageSource source, | |
| 318 WebCore::MessageType type, | |
| 319 WebCore::MessageLevel level, | |
| 320 const WebCore::String& message, | |
| 321 unsigned int line_no, | |
| 322 const WebCore::String& source_id) { | |
| 323 if (webview_->client()) { | |
| 324 webview_->client()->didAddMessageToConsole( | |
| 325 WebConsoleMessage(static_cast<WebConsoleMessage::Level>(level), | |
| 326 webkit_glue::StringToWebString(message)), | |
| 327 webkit_glue::StringToWebString(source_id), | |
| 328 line_no); | |
| 329 } | |
| 330 } | |
| 331 | |
| 332 bool ChromeClientImpl::canRunBeforeUnloadConfirmPanel() { | |
| 333 return webview_->client() != NULL; | |
| 334 } | |
| 335 | |
| 336 bool ChromeClientImpl::runBeforeUnloadConfirmPanel( | |
| 337 const WebCore::String& message, | |
| 338 WebCore::Frame* frame) { | |
| 339 if (webview_->client()) { | |
| 340 return webview_->client()->runModalBeforeUnloadDialog( | |
| 341 WebFrameImpl::FromFrame(frame), | |
| 342 webkit_glue::StringToWebString(message)); | |
| 343 } | |
| 344 return false; | |
| 345 } | |
| 346 | |
| 347 void ChromeClientImpl::closeWindowSoon() { | |
| 348 // Make sure this Page can no longer be found by JS. | |
| 349 webview_->page()->setGroupName(WebCore::String()); | |
| 350 | |
| 351 // Make sure that all loading is stopped. Ensures that JS stops executing! | |
| 352 webview_->mainFrame()->stopLoading(); | |
| 353 | |
| 354 if (webview_->client()) | |
| 355 webview_->client()->closeWidgetSoon(); | |
| 356 } | |
| 357 | |
| 358 // Although a WebCore::Frame is passed in, we don't actually use it, since we | |
| 359 // already know our own webview_. | |
| 360 void ChromeClientImpl::runJavaScriptAlert(WebCore::Frame* frame, | |
| 361 const WebCore::String& message) { | |
| 362 if (webview_->client()) { | |
| 363 #if USE(V8) | |
| 364 // Before showing the JavaScript dialog, we give the proxy implementation | |
| 365 // a chance to process any pending console messages. | |
| 366 WebCore::V8Proxy::processConsoleMessages(); | |
| 367 #endif | |
| 368 webview_->client()->runModalAlertDialog( | |
| 369 WebFrameImpl::FromFrame(frame), | |
| 370 webkit_glue::StringToWebString(message)); | |
| 371 } | |
| 372 } | |
| 373 | |
| 374 // See comments for runJavaScriptAlert(). | |
| 375 bool ChromeClientImpl::runJavaScriptConfirm(WebCore::Frame* frame, | |
| 376 const WebCore::String& message) { | |
| 377 if (webview_->client()) { | |
| 378 return webview_->client()->runModalConfirmDialog( | |
| 379 WebFrameImpl::FromFrame(frame), | |
| 380 webkit_glue::StringToWebString(message)); | |
| 381 } | |
| 382 return false; | |
| 383 } | |
| 384 | |
| 385 // See comments for runJavaScriptAlert(). | |
| 386 bool ChromeClientImpl::runJavaScriptPrompt(WebCore::Frame* frame, | |
| 387 const WebCore::String& message, | |
| 388 const WebCore::String& default_value, | |
| 389 WebCore::String& result) { | |
| 390 if (webview_->client()) { | |
| 391 WebString actual_value; | |
| 392 bool ok = webview_->client()->runModalPromptDialog( | |
| 393 WebFrameImpl::FromFrame(frame), | |
| 394 webkit_glue::StringToWebString(message), | |
| 395 webkit_glue::StringToWebString(default_value), | |
| 396 &actual_value); | |
| 397 if (ok) | |
| 398 result = webkit_glue::WebStringToString(actual_value); | |
| 399 return ok; | |
| 400 } | |
| 401 return false; | |
| 402 } | |
| 403 | |
| 404 void ChromeClientImpl::setStatusbarText(const WebCore::String& message) { | |
| 405 if (webview_->client()) { | |
| 406 webview_->client()->setStatusText( | |
| 407 webkit_glue::StringToWebString(message)); | |
| 408 } | |
| 409 } | |
| 410 | |
| 411 bool ChromeClientImpl::shouldInterruptJavaScript() { | |
| 412 // TODO(mbelshe): implement me | |
| 413 return false; | |
| 414 } | |
| 415 | |
| 416 bool ChromeClientImpl::tabsToLinks() const { | |
| 417 return webview_->tabsToLinks(); | |
| 418 } | |
| 419 | |
| 420 WebCore::IntRect ChromeClientImpl::windowResizerRect() const { | |
| 421 WebCore::IntRect result; | |
| 422 if (webview_->client()) { | |
| 423 result = webkit_glue::WebRectToIntRect( | |
| 424 webview_->client()->windowResizerRect()); | |
| 425 } | |
| 426 return result; | |
| 427 } | |
| 428 | |
| 429 void ChromeClientImpl::repaint( | |
| 430 const WebCore::IntRect& paint_rect, bool content_changed, bool immediate, | |
| 431 bool repaint_content_only) { | |
| 432 // Ignore spurious calls. | |
| 433 if (!content_changed || paint_rect.isEmpty()) | |
| 434 return; | |
| 435 if (webview_->client()) { | |
| 436 webview_->client()->didInvalidateRect( | |
| 437 webkit_glue::IntRectToWebRect(paint_rect)); | |
| 438 } | |
| 439 } | |
| 440 | |
| 441 void ChromeClientImpl::scroll( | |
| 442 const WebCore::IntSize& scroll_delta, const WebCore::IntRect& scroll_rect, | |
| 443 const WebCore::IntRect& clip_rect) { | |
| 444 if (webview_->client()) { | |
| 445 int dx = scroll_delta.width(); | |
| 446 int dy = scroll_delta.height(); | |
| 447 webview_->client()->didScrollRect( | |
| 448 dx, dy, webkit_glue::IntRectToWebRect(clip_rect)); | |
| 449 } | |
| 450 } | |
| 451 | |
| 452 WebCore::IntPoint ChromeClientImpl::screenToWindow( | |
| 453 const WebCore::IntPoint&) const { | |
| 454 notImplemented(); | |
| 455 return WebCore::IntPoint(); | |
| 456 } | |
| 457 | |
| 458 WebCore::IntRect ChromeClientImpl::windowToScreen( | |
| 459 const WebCore::IntRect& rect) const { | |
| 460 WebCore::IntRect screen_rect(rect); | |
| 461 | |
| 462 if (webview_->client()) { | |
| 463 WebRect window_rect = webview_->client()->windowRect(); | |
| 464 screen_rect.move(window_rect.x, window_rect.y); | |
| 465 } | |
| 466 | |
| 467 return screen_rect; | |
| 468 } | |
| 469 | |
| 470 void ChromeClientImpl::contentsSizeChanged(WebCore::Frame* frame, const | |
| 471 WebCore::IntSize& size) const { | |
| 472 WebFrameImpl* webframe = WebFrameImpl::FromFrame(frame); | |
| 473 if (webframe->client()) { | |
| 474 webframe->client()->didChangeContentsSize( | |
| 475 webframe, webkit_glue::IntSizeToWebSize(size)); | |
| 476 } | |
| 477 } | |
| 478 | |
| 479 void ChromeClientImpl::scrollbarsModeDidChange() const { | |
| 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 } | |
| 523 #endif | |
| 524 | |
| 525 void ChromeClientImpl::runOpenPanel(WebCore::Frame* frame, | |
| 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 |