Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/render_view_impl.h" | 5 #include "content/renderer/render_view_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 #include "content/renderer/web_intents_host.h" | 57 #include "content/renderer/web_intents_host.h" |
| 58 #include "content/renderer/java/java_bridge_dispatcher.h" | 58 #include "content/renderer/java/java_bridge_dispatcher.h" |
| 59 #include "content/renderer/load_progress_tracker.h" | 59 #include "content/renderer/load_progress_tracker.h" |
| 60 #include "content/renderer/media/audio_message_filter.h" | 60 #include "content/renderer/media/audio_message_filter.h" |
| 61 #include "content/renderer/media/audio_renderer_impl.h" | 61 #include "content/renderer/media/audio_renderer_impl.h" |
| 62 #include "content/renderer/media/media_stream_dependency_factory.h" | 62 #include "content/renderer/media/media_stream_dependency_factory.h" |
| 63 #include "content/renderer/media/media_stream_dispatcher.h" | 63 #include "content/renderer/media/media_stream_dispatcher.h" |
| 64 #include "content/renderer/media/media_stream_impl.h" | 64 #include "content/renderer/media/media_stream_impl.h" |
| 65 #include "content/renderer/media/render_media_log.h" | 65 #include "content/renderer/media/render_media_log.h" |
| 66 #include "content/renderer/mhtml_generator.h" | 66 #include "content/renderer/mhtml_generator.h" |
| 67 #include "content/renderer/mouse_lock_dispatcher.h" | |
| 67 #include "content/renderer/notification_provider.h" | 68 #include "content/renderer/notification_provider.h" |
| 68 #include "content/renderer/p2p/socket_dispatcher.h" | 69 #include "content/renderer/p2p/socket_dispatcher.h" |
| 69 #include "content/renderer/plugin_channel_host.h" | 70 #include "content/renderer/plugin_channel_host.h" |
| 70 #include "content/renderer/render_audiosourceprovider.h" | 71 #include "content/renderer/render_audiosourceprovider.h" |
| 71 #include "content/renderer/render_process.h" | 72 #include "content/renderer/render_process.h" |
| 72 #include "content/renderer/render_thread_impl.h" | 73 #include "content/renderer/render_thread_impl.h" |
| 73 #include "content/renderer/render_widget_fullscreen_pepper.h" | 74 #include "content/renderer/render_widget_fullscreen_pepper.h" |
| 74 #include "content/renderer/renderer_accessibility.h" | 75 #include "content/renderer/renderer_accessibility.h" |
| 75 #include "content/renderer/renderer_gpu_video_decoder_factories.h" | 76 #include "content/renderer/renderer_gpu_video_decoder_factories.h" |
| 76 #include "content/renderer/renderer_webapplicationcachehost_impl.h" | 77 #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 struct RenderViewImpl::PendingFileChooser { | 329 struct RenderViewImpl::PendingFileChooser { |
| 329 PendingFileChooser(const content::FileChooserParams& p, | 330 PendingFileChooser(const content::FileChooserParams& p, |
| 330 WebFileChooserCompletion* c) | 331 WebFileChooserCompletion* c) |
| 331 : params(p), | 332 : params(p), |
| 332 completion(c) { | 333 completion(c) { |
| 333 } | 334 } |
| 334 content::FileChooserParams params; | 335 content::FileChooserParams params; |
| 335 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. | 336 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 336 }; | 337 }; |
| 337 | 338 |
| 339 namespace { | |
| 340 | |
| 341 class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget { | |
| 342 public: | |
| 343 WebWidgetLockTarget (WebKit::WebWidget* webwidget) | |
| 344 : webwidget_(webwidget) {} | |
| 345 | |
| 346 virtual void OnLockMouseACK(bool succeeded) OVERRIDE { | |
| 347 if (succeeded) | |
| 348 webwidget_->didAcquirePointerLock(); | |
| 349 else | |
| 350 webwidget_->didNotAcquirePointerLock(); | |
| 351 } | |
| 352 | |
| 353 virtual void OnMouseLockLost() OVERRIDE { | |
| 354 webwidget_->didLosePointerLock(); | |
| 355 } | |
| 356 | |
| 357 virtual bool HandleMouseLockedInputEvent( | |
| 358 const WebKit::WebMouseEvent &event) OVERRIDE { | |
| 359 // The WebWidget handles mouse lock in WebKit's handleInputEvent(). | |
| 360 return false; | |
| 361 } | |
| 362 | |
| 363 WebKit::WebWidget* webwidget_; | |
|
yzshen1
2012/01/25 18:10:01
private, please.
scheib
2012/01/26 01:37:59
Done.
| |
| 364 }; | |
| 365 | |
| 366 } // namespace | |
| 367 | |
| 338 RenderViewImpl::RenderViewImpl( | 368 RenderViewImpl::RenderViewImpl( |
| 339 gfx::NativeViewId parent_hwnd, | 369 gfx::NativeViewId parent_hwnd, |
| 340 int32 opener_id, | 370 int32 opener_id, |
| 341 const content::RendererPreferences& renderer_prefs, | 371 const content::RendererPreferences& renderer_prefs, |
| 342 const WebPreferences& webkit_prefs, | 372 const WebPreferences& webkit_prefs, |
| 343 SharedRenderViewCounter* counter, | 373 SharedRenderViewCounter* counter, |
| 344 int32 routing_id, | 374 int32 routing_id, |
| 345 int32 surface_id, | 375 int32 surface_id, |
| 346 int64 session_storage_namespace_id, | 376 int64 session_storage_namespace_id, |
| 347 const string16& frame_name, | 377 const string16& frame_name, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 367 cached_has_main_frame_horizontal_scrollbar_(false), | 397 cached_has_main_frame_horizontal_scrollbar_(false), |
| 368 cached_has_main_frame_vertical_scrollbar_(false), | 398 cached_has_main_frame_vertical_scrollbar_(false), |
| 369 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), | 399 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
| 370 geolocation_dispatcher_(NULL), | 400 geolocation_dispatcher_(NULL), |
| 371 speech_input_dispatcher_(NULL), | 401 speech_input_dispatcher_(NULL), |
| 372 device_orientation_dispatcher_(NULL), | 402 device_orientation_dispatcher_(NULL), |
| 373 media_stream_dispatcher_(NULL), | 403 media_stream_dispatcher_(NULL), |
| 374 p2p_socket_dispatcher_(NULL), | 404 p2p_socket_dispatcher_(NULL), |
| 375 devtools_agent_(NULL), | 405 devtools_agent_(NULL), |
| 376 renderer_accessibility_(NULL), | 406 renderer_accessibility_(NULL), |
| 407 mouse_lock_dispatcher_(NULL), | |
| 377 session_storage_namespace_id_(session_storage_namespace_id), | 408 session_storage_namespace_id_(session_storage_namespace_id), |
| 378 handling_select_range_(false), | 409 handling_select_range_(false), |
| 379 #if defined(OS_WIN) | 410 #if defined(OS_WIN) |
| 380 focused_plugin_id_(-1), | 411 focused_plugin_id_(-1), |
| 381 #endif | 412 #endif |
| 382 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { | 413 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { |
| 383 routing_id_ = routing_id; | 414 routing_id_ = routing_id; |
| 384 surface_id_ = surface_id; | 415 surface_id_ = surface_id; |
| 385 if (opener_id != MSG_ROUTING_NONE) | 416 if (opener_id != MSG_ROUTING_NONE) |
| 386 opener_id_ = opener_id; | 417 opener_id_ = opener_id; |
| 387 | 418 |
| 388 // Ensure we start with a valid next_page_id_ from the browser. | 419 // Ensure we start with a valid next_page_id_ from the browser. |
| 389 DCHECK_GE(next_page_id_, 0); | 420 DCHECK_GE(next_page_id_, 0); |
| 390 | 421 |
| 391 #if defined(ENABLE_NOTIFICATIONS) | 422 #if defined(ENABLE_NOTIFICATIONS) |
| 392 notification_provider_ = new NotificationProvider(this); | 423 notification_provider_ = new NotificationProvider(this); |
| 393 #else | 424 #else |
| 394 notification_provider_ = NULL; | 425 notification_provider_ = NULL; |
| 395 #endif | 426 #endif |
| 396 | 427 |
| 397 webwidget_ = WebView::create(this); | 428 webwidget_ = WebView::create(this); |
| 429 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); | |
| 398 | 430 |
| 399 if (counter) { | 431 if (counter) { |
| 400 shared_popup_counter_ = counter; | 432 shared_popup_counter_ = counter; |
| 401 shared_popup_counter_->data++; | 433 shared_popup_counter_->data++; |
| 402 decrement_shared_popup_at_destruction_ = true; | 434 decrement_shared_popup_at_destruction_ = true; |
| 403 } else { | 435 } else { |
| 404 shared_popup_counter_ = new SharedRenderViewCounter(0); | 436 shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 405 decrement_shared_popup_at_destruction_ = false; | 437 decrement_shared_popup_at_destruction_ = false; |
| 406 } | 438 } |
| 407 | 439 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 435 #if defined(ENABLE_P2P_APIS) | 467 #if defined(ENABLE_P2P_APIS) |
| 436 if (!p2p_socket_dispatcher_) | 468 if (!p2p_socket_dispatcher_) |
| 437 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this); | 469 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this); |
| 438 #endif | 470 #endif |
| 439 | 471 |
| 440 new MHTMLGenerator(this); | 472 new MHTMLGenerator(this); |
| 441 #if defined(OS_MACOSX) | 473 #if defined(OS_MACOSX) |
| 442 new TextInputClientObserver(this); | 474 new TextInputClientObserver(this); |
| 443 #endif // defined(OS_MACOSX) | 475 #endif // defined(OS_MACOSX) |
| 444 | 476 |
| 477 // The next group of objects all implement RenderViewObserver, so are deleted | |
| 478 // along with the RenderView automatically. | |
| 445 devtools_agent_ = new DevToolsAgent(this); | 479 devtools_agent_ = new DevToolsAgent(this); |
| 446 | |
| 447 renderer_accessibility_ = new RendererAccessibility(this); | 480 renderer_accessibility_ = new RendererAccessibility(this); |
| 481 mouse_lock_dispatcher_ = new MouseLockDispatcher(this); | |
| 448 | 482 |
| 449 new IdleUserDetector(this); | 483 new IdleUserDetector(this); |
| 450 | 484 |
| 451 content::GetContentClient()->renderer()->RenderViewCreated(this); | 485 content::GetContentClient()->renderer()->RenderViewCreated(this); |
| 452 } | 486 } |
| 453 | 487 |
| 454 RenderViewImpl::~RenderViewImpl() { | 488 RenderViewImpl::~RenderViewImpl() { |
| 455 history_page_ids_.clear(); | 489 history_page_ids_.clear(); |
| 456 | 490 |
| 457 if (decrement_shared_popup_at_destruction_) | 491 if (decrement_shared_popup_at_destruction_) |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 // TODO(viettrungluu): Move to a separate message filter. | 747 // TODO(viettrungluu): Move to a separate message filter. |
| 714 #if defined(ENABLE_FLAPPER_HACKS) | 748 #if defined(ENABLE_FLAPPER_HACKS) |
| 715 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK) | 749 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK) |
| 716 #endif | 750 #endif |
| 717 #if defined(OS_MACOSX) | 751 #if defined(OS_MACOSX) |
| 718 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) | 752 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 719 #endif | 753 #endif |
| 720 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, | 754 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 721 OnSetHistoryLengthAndPrune) | 755 OnSetHistoryLengthAndPrune) |
| 722 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) | 756 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
| 723 IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK) | |
| 724 IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost) | |
| 725 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) | 757 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
| 726 | 758 |
| 727 // Have the super handle all other messages. | 759 // Have the super handle all other messages. |
| 728 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) | 760 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
| 729 IPC_END_MESSAGE_MAP() | 761 IPC_END_MESSAGE_MAP() |
| 730 | 762 |
| 731 if (!msg_is_ok) { | 763 if (!msg_is_ok) { |
| 732 // The message had a handler, but its deserialization failed. | 764 // The message had a handler, but its deserialization failed. |
| 733 // Kill the renderer to avoid potential spoofing attacks. | 765 // Kill the renderer to avoid potential spoofing attacks. |
| 734 CHECK(false) << "Unable to deserialize message in RenderViewImpl."; | 766 CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
| (...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1918 | 1950 |
| 1919 bool RenderViewImpl::enterFullScreen() { | 1951 bool RenderViewImpl::enterFullScreen() { |
| 1920 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); | 1952 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
| 1921 return true; | 1953 return true; |
| 1922 } | 1954 } |
| 1923 | 1955 |
| 1924 void RenderViewImpl::exitFullScreen() { | 1956 void RenderViewImpl::exitFullScreen() { |
| 1925 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); | 1957 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
| 1926 } | 1958 } |
| 1927 | 1959 |
| 1960 bool RenderViewImpl::requestPointerLock() { | |
| 1961 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); | |
| 1962 } | |
| 1963 | |
| 1964 void RenderViewImpl::requestPointerUnlock() { | |
| 1965 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); | |
| 1966 } | |
| 1967 | |
| 1968 bool RenderViewImpl::isPointerLocked() { | |
| 1969 return mouse_lock_dispatcher_->IsMouseLockedTo( | |
| 1970 webwidget_mouse_lock_target_.get()); | |
| 1971 } | |
| 1972 | |
| 1928 // WebKit::WebFrameClient ----------------------------------------------------- | 1973 // WebKit::WebFrameClient ----------------------------------------------------- |
| 1929 | 1974 |
| 1930 WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, | 1975 WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, |
| 1931 const WebPluginParams& params) { | 1976 const WebPluginParams& params) { |
| 1932 WebPlugin* plugin = NULL; | 1977 WebPlugin* plugin = NULL; |
| 1933 if (content::GetContentClient()->renderer()->OverrideCreatePlugin( | 1978 if (content::GetContentClient()->renderer()->OverrideCreatePlugin( |
| 1934 this, frame, params, &plugin)) { | 1979 this, frame, params, &plugin)) { |
| 1935 return plugin; | 1980 return plugin; |
| 1936 } | 1981 } |
| 1937 | 1982 |
| (...skipping 2438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4376 WebView* doomed = webview(); | 4421 WebView* doomed = webview(); |
| 4377 RenderWidget::Close(); | 4422 RenderWidget::Close(); |
| 4378 g_view_map.Get().erase(doomed); | 4423 g_view_map.Get().erase(doomed); |
| 4379 } | 4424 } |
| 4380 | 4425 |
| 4381 void RenderViewImpl::DidHandleKeyEvent() { | 4426 void RenderViewImpl::DidHandleKeyEvent() { |
| 4382 edit_commands_.clear(); | 4427 edit_commands_.clear(); |
| 4383 } | 4428 } |
| 4384 | 4429 |
| 4385 bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 4430 bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
| 4386 return pepper_delegate_.HandleMouseEvent(event); | 4431 pepper_delegate_.WillHandleMouseEvent(); |
| 4432 | |
| 4433 // If the mouse is locked, only the current owner of the mouse lock can | |
| 4434 // process mouse events. | |
| 4435 return mouse_lock_dispatcher_->WillHandleMouseEvent(event); | |
| 4387 } | 4436 } |
| 4388 | 4437 |
| 4389 void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 4438 void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
| 4390 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); | 4439 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
| 4391 } | 4440 } |
| 4392 | 4441 |
| 4393 void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { | 4442 void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
| 4394 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); | 4443 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
| 4395 } | 4444 } |
| 4396 | 4445 |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4885 | 4934 |
| 4886 void RenderViewImpl::OnEnableViewSourceMode() { | 4935 void RenderViewImpl::OnEnableViewSourceMode() { |
| 4887 if (!webview()) | 4936 if (!webview()) |
| 4888 return; | 4937 return; |
| 4889 WebFrame* main_frame = webview()->mainFrame(); | 4938 WebFrame* main_frame = webview()->mainFrame(); |
| 4890 if (!main_frame) | 4939 if (!main_frame) |
| 4891 return; | 4940 return; |
| 4892 main_frame->enableViewSourceMode(true); | 4941 main_frame->enableViewSourceMode(true); |
| 4893 } | 4942 } |
| 4894 | 4943 |
| 4895 void RenderViewImpl::OnLockMouseACK(bool succeeded) { | |
| 4896 // Mouse Lock removes the system cursor and provides all mouse motion as | |
| 4897 // .movementX/Y values on events all sent to a fixed target. This requires | |
| 4898 // content to specifically request the mode to be entered. | |
| 4899 // Mouse Capture is implicitly given for the duration of a drag event, and | |
| 4900 // sends all mouse events to the initial target of the drag. | |
| 4901 // If Lock is entered it supercedes any in progress Capture. | |
| 4902 if (succeeded) | |
| 4903 OnMouseCaptureLost(); | |
| 4904 | |
| 4905 pepper_delegate_.OnLockMouseACK(succeeded); | |
| 4906 } | |
| 4907 | |
| 4908 void RenderViewImpl::OnMouseLockLost() { | |
| 4909 pepper_delegate_.OnMouseLockLost(); | |
| 4910 } | |
| 4911 | |
| 4912 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { | 4944 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
| 4913 return !!RenderThreadImpl::current()->compositor_thread(); | 4945 return !!RenderThreadImpl::current()->compositor_thread(); |
| 4914 } | 4946 } |
| 4915 | 4947 |
| 4916 void RenderViewImpl::OnJavaBridgeInit() { | 4948 void RenderViewImpl::OnJavaBridgeInit() { |
| 4917 DCHECK(!java_bridge_dispatcher_.get()); | 4949 DCHECK(!java_bridge_dispatcher_.get()); |
| 4918 #if defined(ENABLE_JAVA_BRIDGE) | 4950 #if defined(ENABLE_JAVA_BRIDGE) |
| 4919 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); | 4951 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); |
| 4920 #endif | 4952 #endif |
| 4921 } | 4953 } |
| OLD | NEW |