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 27 matching lines...) Expand all Loading... |
435 #if defined(ENABLE_P2P_APIS) | 468 #if defined(ENABLE_P2P_APIS) |
436 if (!p2p_socket_dispatcher_) | 469 if (!p2p_socket_dispatcher_) |
437 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this); | 470 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this); |
438 #endif | 471 #endif |
439 | 472 |
440 new MHTMLGenerator(this); | 473 new MHTMLGenerator(this); |
441 #if defined(OS_MACOSX) | 474 #if defined(OS_MACOSX) |
442 new TextInputClientObserver(this); | 475 new TextInputClientObserver(this); |
443 #endif // defined(OS_MACOSX) | 476 #endif // defined(OS_MACOSX) |
444 | 477 |
| 478 // The next group of objects all implement RenderViewObserver, so are deleted |
| 479 // along with the RenderView automatically. |
445 devtools_agent_ = new DevToolsAgent(this); | 480 devtools_agent_ = new DevToolsAgent(this); |
446 | |
447 renderer_accessibility_ = new RendererAccessibility(this); | 481 renderer_accessibility_ = new RendererAccessibility(this); |
| 482 mouse_lock_dispatcher_ = new MouseLockDispatcher(this); |
448 | 483 |
449 new IdleUserDetector(this); | 484 new IdleUserDetector(this); |
450 | 485 |
451 content::GetContentClient()->renderer()->RenderViewCreated(this); | 486 content::GetContentClient()->renderer()->RenderViewCreated(this); |
452 } | 487 } |
453 | 488 |
454 RenderViewImpl::~RenderViewImpl() { | 489 RenderViewImpl::~RenderViewImpl() { |
455 history_page_ids_.clear(); | 490 history_page_ids_.clear(); |
456 | 491 |
457 if (decrement_shared_popup_at_destruction_) | 492 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. | 748 // TODO(viettrungluu): Move to a separate message filter. |
714 #if defined(ENABLE_FLAPPER_HACKS) | 749 #if defined(ENABLE_FLAPPER_HACKS) |
715 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK) | 750 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK) |
716 #endif | 751 #endif |
717 #if defined(OS_MACOSX) | 752 #if defined(OS_MACOSX) |
718 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) | 753 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
719 #endif | 754 #endif |
720 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, | 755 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
721 OnSetHistoryLengthAndPrune) | 756 OnSetHistoryLengthAndPrune) |
722 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) | 757 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) | 758 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
726 | 759 |
727 // Have the super handle all other messages. | 760 // Have the super handle all other messages. |
728 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) | 761 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
729 IPC_END_MESSAGE_MAP() | 762 IPC_END_MESSAGE_MAP() |
730 | 763 |
731 if (!msg_is_ok) { | 764 if (!msg_is_ok) { |
732 // The message had a handler, but its deserialization failed. | 765 // The message had a handler, but its deserialization failed. |
733 // Kill the renderer to avoid potential spoofing attacks. | 766 // Kill the renderer to avoid potential spoofing attacks. |
734 CHECK(false) << "Unable to deserialize message in RenderViewImpl."; | 767 CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1918 | 1951 |
1919 bool RenderViewImpl::enterFullScreen() { | 1952 bool RenderViewImpl::enterFullScreen() { |
1920 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); | 1953 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
1921 return true; | 1954 return true; |
1922 } | 1955 } |
1923 | 1956 |
1924 void RenderViewImpl::exitFullScreen() { | 1957 void RenderViewImpl::exitFullScreen() { |
1925 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); | 1958 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
1926 } | 1959 } |
1927 | 1960 |
| 1961 bool RenderViewImpl::requestPointerLock() { |
| 1962 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 1963 } |
| 1964 |
| 1965 void RenderViewImpl::requestPointerUnlock() { |
| 1966 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 1967 } |
| 1968 |
| 1969 bool RenderViewImpl::isPointerLocked() { |
| 1970 return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 1971 webwidget_mouse_lock_target_.get()); |
| 1972 } |
| 1973 |
1928 // WebKit::WebFrameClient ----------------------------------------------------- | 1974 // WebKit::WebFrameClient ----------------------------------------------------- |
1929 | 1975 |
1930 WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, | 1976 WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, |
1931 const WebPluginParams& params) { | 1977 const WebPluginParams& params) { |
1932 WebPlugin* plugin = NULL; | 1978 WebPlugin* plugin = NULL; |
1933 if (content::GetContentClient()->renderer()->OverrideCreatePlugin( | 1979 if (content::GetContentClient()->renderer()->OverrideCreatePlugin( |
1934 this, frame, params, &plugin)) { | 1980 this, frame, params, &plugin)) { |
1935 return plugin; | 1981 return plugin; |
1936 } | 1982 } |
1937 | 1983 |
(...skipping 2438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4376 WebView* doomed = webview(); | 4422 WebView* doomed = webview(); |
4377 RenderWidget::Close(); | 4423 RenderWidget::Close(); |
4378 g_view_map.Get().erase(doomed); | 4424 g_view_map.Get().erase(doomed); |
4379 } | 4425 } |
4380 | 4426 |
4381 void RenderViewImpl::DidHandleKeyEvent() { | 4427 void RenderViewImpl::DidHandleKeyEvent() { |
4382 edit_commands_.clear(); | 4428 edit_commands_.clear(); |
4383 } | 4429 } |
4384 | 4430 |
4385 bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 4431 bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
4386 return pepper_delegate_.HandleMouseEvent(event); | 4432 pepper_delegate_.WillHandleMouseEvent(); |
| 4433 |
| 4434 // If the mouse is locked, only the current owner of the mouse lock can |
| 4435 // process mouse events. |
| 4436 return mouse_lock_dispatcher_->WillHandleMouseEvent(event); |
4387 } | 4437 } |
4388 | 4438 |
4389 void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 4439 void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
4390 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); | 4440 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
4391 } | 4441 } |
4392 | 4442 |
4393 void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { | 4443 void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
4394 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); | 4444 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
4395 } | 4445 } |
4396 | 4446 |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4885 | 4935 |
4886 void RenderViewImpl::OnEnableViewSourceMode() { | 4936 void RenderViewImpl::OnEnableViewSourceMode() { |
4887 if (!webview()) | 4937 if (!webview()) |
4888 return; | 4938 return; |
4889 WebFrame* main_frame = webview()->mainFrame(); | 4939 WebFrame* main_frame = webview()->mainFrame(); |
4890 if (!main_frame) | 4940 if (!main_frame) |
4891 return; | 4941 return; |
4892 main_frame->enableViewSourceMode(true); | 4942 main_frame->enableViewSourceMode(true); |
4893 } | 4943 } |
4894 | 4944 |
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 { | 4945 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
4913 return !!RenderThreadImpl::current()->compositor_thread(); | 4946 return !!RenderThreadImpl::current()->compositor_thread(); |
4914 } | 4947 } |
4915 | 4948 |
4916 void RenderViewImpl::OnJavaBridgeInit() { | 4949 void RenderViewImpl::OnJavaBridgeInit() { |
4917 DCHECK(!java_bridge_dispatcher_.get()); | 4950 DCHECK(!java_bridge_dispatcher_.get()); |
4918 #if defined(ENABLE_JAVA_BRIDGE) | 4951 #if defined(ENABLE_JAVA_BRIDGE) |
4919 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); | 4952 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); |
4920 #endif | 4953 #endif |
4921 } | 4954 } |
OLD | NEW |