| 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 private: |
| 364 WebKit::WebWidget* webwidget_; |
| 365 }; |
| 366 |
| 367 } // namespace |
| 368 |
| 338 RenderViewImpl::RenderViewImpl( | 369 RenderViewImpl::RenderViewImpl( |
| 339 gfx::NativeViewId parent_hwnd, | 370 gfx::NativeViewId parent_hwnd, |
| 340 int32 opener_id, | 371 int32 opener_id, |
| 341 const content::RendererPreferences& renderer_prefs, | 372 const content::RendererPreferences& renderer_prefs, |
| 342 const WebPreferences& webkit_prefs, | 373 const WebPreferences& webkit_prefs, |
| 343 SharedRenderViewCounter* counter, | 374 SharedRenderViewCounter* counter, |
| 344 int32 routing_id, | 375 int32 routing_id, |
| 345 int32 surface_id, | 376 int32 surface_id, |
| 346 int64 session_storage_namespace_id, | 377 int64 session_storage_namespace_id, |
| 347 const string16& frame_name, | 378 const string16& frame_name, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 367 cached_has_main_frame_horizontal_scrollbar_(false), | 398 cached_has_main_frame_horizontal_scrollbar_(false), |
| 368 cached_has_main_frame_vertical_scrollbar_(false), | 399 cached_has_main_frame_vertical_scrollbar_(false), |
| 369 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), | 400 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
| 370 geolocation_dispatcher_(NULL), | 401 geolocation_dispatcher_(NULL), |
| 371 speech_input_dispatcher_(NULL), | 402 speech_input_dispatcher_(NULL), |
| 372 device_orientation_dispatcher_(NULL), | 403 device_orientation_dispatcher_(NULL), |
| 373 media_stream_dispatcher_(NULL), | 404 media_stream_dispatcher_(NULL), |
| 374 p2p_socket_dispatcher_(NULL), | 405 p2p_socket_dispatcher_(NULL), |
| 375 devtools_agent_(NULL), | 406 devtools_agent_(NULL), |
| 376 renderer_accessibility_(NULL), | 407 renderer_accessibility_(NULL), |
| 408 mouse_lock_dispatcher_(NULL), |
| 377 session_storage_namespace_id_(session_storage_namespace_id), | 409 session_storage_namespace_id_(session_storage_namespace_id), |
| 378 handling_select_range_(false), | 410 handling_select_range_(false), |
| 379 #if defined(OS_WIN) | 411 #if defined(OS_WIN) |
| 380 focused_plugin_id_(-1), | 412 focused_plugin_id_(-1), |
| 381 #endif | 413 #endif |
| 382 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { | 414 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { |
| 383 routing_id_ = routing_id; | 415 routing_id_ = routing_id; |
| 384 surface_id_ = surface_id; | 416 surface_id_ = surface_id; |
| 385 if (opener_id != MSG_ROUTING_NONE) | 417 if (opener_id != MSG_ROUTING_NONE) |
| 386 opener_id_ = opener_id; | 418 opener_id_ = opener_id; |
| 387 | 419 |
| 388 // Ensure we start with a valid next_page_id_ from the browser. | 420 // Ensure we start with a valid next_page_id_ from the browser. |
| 389 DCHECK_GE(next_page_id_, 0); | 421 DCHECK_GE(next_page_id_, 0); |
| 390 | 422 |
| 391 #if defined(ENABLE_NOTIFICATIONS) | 423 #if defined(ENABLE_NOTIFICATIONS) |
| 392 notification_provider_ = new NotificationProvider(this); | 424 notification_provider_ = new NotificationProvider(this); |
| 393 #else | 425 #else |
| 394 notification_provider_ = NULL; | 426 notification_provider_ = NULL; |
| 395 #endif | 427 #endif |
| 396 | 428 |
| 397 webwidget_ = WebView::create(this); | 429 webwidget_ = WebView::create(this); |
| 430 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); |
| 398 | 431 |
| 399 if (counter) { | 432 if (counter) { |
| 400 shared_popup_counter_ = counter; | 433 shared_popup_counter_ = counter; |
| 401 shared_popup_counter_->data++; | 434 shared_popup_counter_->data++; |
| 402 decrement_shared_popup_at_destruction_ = true; | 435 decrement_shared_popup_at_destruction_ = true; |
| 403 } else { | 436 } else { |
| 404 shared_popup_counter_ = new SharedRenderViewCounter(0); | 437 shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 405 decrement_shared_popup_at_destruction_ = false; | 438 decrement_shared_popup_at_destruction_ = false; |
| 406 } | 439 } |
| 407 | 440 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 438 #endif | 471 #endif |
| 439 | 472 |
| 440 if (!media_stream_dispatcher_) | 473 if (!media_stream_dispatcher_) |
| 441 media_stream_dispatcher_ = new MediaStreamDispatcher(this); | 474 media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
| 442 | 475 |
| 443 new MHTMLGenerator(this); | 476 new MHTMLGenerator(this); |
| 444 #if defined(OS_MACOSX) | 477 #if defined(OS_MACOSX) |
| 445 new TextInputClientObserver(this); | 478 new TextInputClientObserver(this); |
| 446 #endif // defined(OS_MACOSX) | 479 #endif // defined(OS_MACOSX) |
| 447 | 480 |
| 481 // The next group of objects all implement RenderViewObserver, so are deleted |
| 482 // along with the RenderView automatically. |
| 448 devtools_agent_ = new DevToolsAgent(this); | 483 devtools_agent_ = new DevToolsAgent(this); |
| 449 | |
| 450 renderer_accessibility_ = new RendererAccessibility(this); | 484 renderer_accessibility_ = new RendererAccessibility(this); |
| 485 mouse_lock_dispatcher_ = new MouseLockDispatcher(this); |
| 451 | 486 |
| 452 new IdleUserDetector(this); | 487 new IdleUserDetector(this); |
| 453 | 488 |
| 454 content::GetContentClient()->renderer()->RenderViewCreated(this); | 489 content::GetContentClient()->renderer()->RenderViewCreated(this); |
| 455 } | 490 } |
| 456 | 491 |
| 457 RenderViewImpl::~RenderViewImpl() { | 492 RenderViewImpl::~RenderViewImpl() { |
| 458 history_page_ids_.clear(); | 493 history_page_ids_.clear(); |
| 459 | 494 |
| 460 if (decrement_shared_popup_at_destruction_) | 495 if (decrement_shared_popup_at_destruction_) |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 // TODO(viettrungluu): Move to a separate message filter. | 751 // TODO(viettrungluu): Move to a separate message filter. |
| 717 #if defined(ENABLE_FLAPPER_HACKS) | 752 #if defined(ENABLE_FLAPPER_HACKS) |
| 718 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK) | 753 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK) |
| 719 #endif | 754 #endif |
| 720 #if defined(OS_MACOSX) | 755 #if defined(OS_MACOSX) |
| 721 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) | 756 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 722 #endif | 757 #endif |
| 723 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, | 758 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 724 OnSetHistoryLengthAndPrune) | 759 OnSetHistoryLengthAndPrune) |
| 725 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) | 760 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
| 726 IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK) | |
| 727 IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost) | |
| 728 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) | 761 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
| 729 | 762 |
| 730 // Have the super handle all other messages. | 763 // Have the super handle all other messages. |
| 731 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) | 764 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
| 732 IPC_END_MESSAGE_MAP() | 765 IPC_END_MESSAGE_MAP() |
| 733 | 766 |
| 734 if (!msg_is_ok) { | 767 if (!msg_is_ok) { |
| 735 // The message had a handler, but its deserialization failed. | 768 // The message had a handler, but its deserialization failed. |
| 736 // Kill the renderer to avoid potential spoofing attacks. | 769 // Kill the renderer to avoid potential spoofing attacks. |
| 737 CHECK(false) << "Unable to deserialize message in RenderViewImpl."; | 770 CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
| (...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1921 | 1954 |
| 1922 bool RenderViewImpl::enterFullScreen() { | 1955 bool RenderViewImpl::enterFullScreen() { |
| 1923 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); | 1956 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
| 1924 return true; | 1957 return true; |
| 1925 } | 1958 } |
| 1926 | 1959 |
| 1927 void RenderViewImpl::exitFullScreen() { | 1960 void RenderViewImpl::exitFullScreen() { |
| 1928 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); | 1961 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
| 1929 } | 1962 } |
| 1930 | 1963 |
| 1964 bool RenderViewImpl::requestPointerLock() { |
| 1965 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 1966 } |
| 1967 |
| 1968 void RenderViewImpl::requestPointerUnlock() { |
| 1969 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 1970 } |
| 1971 |
| 1972 bool RenderViewImpl::isPointerLocked() { |
| 1973 return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 1974 webwidget_mouse_lock_target_.get()); |
| 1975 } |
| 1976 |
| 1931 // WebKit::WebFrameClient ----------------------------------------------------- | 1977 // WebKit::WebFrameClient ----------------------------------------------------- |
| 1932 | 1978 |
| 1933 WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, | 1979 WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, |
| 1934 const WebPluginParams& params) { | 1980 const WebPluginParams& params) { |
| 1935 WebPlugin* plugin = NULL; | 1981 WebPlugin* plugin = NULL; |
| 1936 if (content::GetContentClient()->renderer()->OverrideCreatePlugin( | 1982 if (content::GetContentClient()->renderer()->OverrideCreatePlugin( |
| 1937 this, frame, params, &plugin)) { | 1983 this, frame, params, &plugin)) { |
| 1938 return plugin; | 1984 return plugin; |
| 1939 } | 1985 } |
| 1940 | 1986 |
| (...skipping 2438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4379 WebView* doomed = webview(); | 4425 WebView* doomed = webview(); |
| 4380 RenderWidget::Close(); | 4426 RenderWidget::Close(); |
| 4381 g_view_map.Get().erase(doomed); | 4427 g_view_map.Get().erase(doomed); |
| 4382 } | 4428 } |
| 4383 | 4429 |
| 4384 void RenderViewImpl::DidHandleKeyEvent() { | 4430 void RenderViewImpl::DidHandleKeyEvent() { |
| 4385 edit_commands_.clear(); | 4431 edit_commands_.clear(); |
| 4386 } | 4432 } |
| 4387 | 4433 |
| 4388 bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 4434 bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
| 4389 return pepper_delegate_.HandleMouseEvent(event); | 4435 pepper_delegate_.WillHandleMouseEvent(); |
| 4436 |
| 4437 // If the mouse is locked, only the current owner of the mouse lock can |
| 4438 // process mouse events. |
| 4439 return mouse_lock_dispatcher_->WillHandleMouseEvent(event); |
| 4390 } | 4440 } |
| 4391 | 4441 |
| 4392 void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 4442 void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
| 4393 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); | 4443 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
| 4394 } | 4444 } |
| 4395 | 4445 |
| 4396 void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { | 4446 void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
| 4397 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); | 4447 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
| 4398 } | 4448 } |
| 4399 | 4449 |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4888 | 4938 |
| 4889 void RenderViewImpl::OnEnableViewSourceMode() { | 4939 void RenderViewImpl::OnEnableViewSourceMode() { |
| 4890 if (!webview()) | 4940 if (!webview()) |
| 4891 return; | 4941 return; |
| 4892 WebFrame* main_frame = webview()->mainFrame(); | 4942 WebFrame* main_frame = webview()->mainFrame(); |
| 4893 if (!main_frame) | 4943 if (!main_frame) |
| 4894 return; | 4944 return; |
| 4895 main_frame->enableViewSourceMode(true); | 4945 main_frame->enableViewSourceMode(true); |
| 4896 } | 4946 } |
| 4897 | 4947 |
| 4898 void RenderViewImpl::OnLockMouseACK(bool succeeded) { | |
| 4899 // Mouse Lock removes the system cursor and provides all mouse motion as | |
| 4900 // .movementX/Y values on events all sent to a fixed target. This requires | |
| 4901 // content to specifically request the mode to be entered. | |
| 4902 // Mouse Capture is implicitly given for the duration of a drag event, and | |
| 4903 // sends all mouse events to the initial target of the drag. | |
| 4904 // If Lock is entered it supercedes any in progress Capture. | |
| 4905 if (succeeded) | |
| 4906 OnMouseCaptureLost(); | |
| 4907 | |
| 4908 pepper_delegate_.OnLockMouseACK(succeeded); | |
| 4909 } | |
| 4910 | |
| 4911 void RenderViewImpl::OnMouseLockLost() { | |
| 4912 pepper_delegate_.OnMouseLockLost(); | |
| 4913 } | |
| 4914 | |
| 4915 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { | 4948 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
| 4916 return !!RenderThreadImpl::current()->compositor_thread(); | 4949 return !!RenderThreadImpl::current()->compositor_thread(); |
| 4917 } | 4950 } |
| 4918 | 4951 |
| 4919 void RenderViewImpl::OnJavaBridgeInit() { | 4952 void RenderViewImpl::OnJavaBridgeInit() { |
| 4920 DCHECK(!java_bridge_dispatcher_.get()); | 4953 DCHECK(!java_bridge_dispatcher_.get()); |
| 4921 #if defined(ENABLE_JAVA_BRIDGE) | 4954 #if defined(ENABLE_JAVA_BRIDGE) |
| 4922 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); | 4955 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); |
| 4923 #endif | 4956 #endif |
| 4924 } | 4957 } |
| OLD | NEW |