OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 #include "content/renderer/websharedworker_proxy.h" | 79 #include "content/renderer/websharedworker_proxy.h" |
80 #include "media/base/filter_collection.h" | 80 #include "media/base/filter_collection.h" |
81 #include "media/base/media_switches.h" | 81 #include "media/base/media_switches.h" |
82 #include "media/base/message_loop_factory_impl.h" | 82 #include "media/base/message_loop_factory_impl.h" |
83 #include "net/base/escape.h" | 83 #include "net/base/escape.h" |
84 #include "net/base/net_errors.h" | 84 #include "net/base/net_errors.h" |
85 #include "net/http/http_util.h" | 85 #include "net/http/http_util.h" |
86 #include "ppapi/c/private/ppb_flash_net_connector.h" | 86 #include "ppapi/c/private/ppb_flash_net_connector.h" |
87 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObjec t.h" | 87 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObjec t.h" |
88 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h " | 88 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h " |
89 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | |
89 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 90 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
90 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 91 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
91 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData. h" | 92 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData. h" |
92 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 93 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
93 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams. h" | 94 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams. h" |
94 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback s.h" | 95 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback s.h" |
95 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h" | 96 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h" |
96 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement .h" | 97 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement .h" |
97 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 98 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
98 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 99 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 speech_input_dispatcher_(NULL), | 360 speech_input_dispatcher_(NULL), |
360 device_orientation_dispatcher_(NULL), | 361 device_orientation_dispatcher_(NULL), |
361 p2p_socket_dispatcher_(NULL), | 362 p2p_socket_dispatcher_(NULL), |
362 devtools_agent_(NULL), | 363 devtools_agent_(NULL), |
363 renderer_accessibility_(NULL), | 364 renderer_accessibility_(NULL), |
364 session_storage_namespace_id_(session_storage_namespace_id), | 365 session_storage_namespace_id_(session_storage_namespace_id), |
365 handling_select_range_(false), | 366 handling_select_range_(false), |
366 #if defined(OS_WIN) | 367 #if defined(OS_WIN) |
367 focused_plugin_id_(-1), | 368 focused_plugin_id_(-1), |
368 #endif | 369 #endif |
369 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { | 370 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), |
371 mouse_locked_(false), | |
372 pending_lock_request_(false), | |
373 pending_unlock_request_(false), | |
374 mouse_lock_webwidget_owner_(NULL), | |
375 mouse_lock_pinstance_owner_(NULL) { | |
370 routing_id_ = routing_id; | 376 routing_id_ = routing_id; |
371 if (opener_id != MSG_ROUTING_NONE) | 377 if (opener_id != MSG_ROUTING_NONE) |
372 opener_id_ = opener_id; | 378 opener_id_ = opener_id; |
373 | 379 |
374 #if defined(ENABLE_NOTIFICATIONS) | 380 #if defined(ENABLE_NOTIFICATIONS) |
375 notification_provider_ = new NotificationProvider(this); | 381 notification_provider_ = new NotificationProvider(this); |
376 #else | 382 #else |
377 notification_provider_ = NULL; | 383 notification_provider_ = NULL; |
378 #endif | 384 #endif |
379 | 385 |
(...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1871 | 1877 |
1872 bool RenderViewImpl::enterFullScreen() { | 1878 bool RenderViewImpl::enterFullScreen() { |
1873 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); | 1879 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
1874 return true; | 1880 return true; |
1875 } | 1881 } |
1876 | 1882 |
1877 void RenderViewImpl::exitFullScreen() { | 1883 void RenderViewImpl::exitFullScreen() { |
1878 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); | 1884 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
1879 } | 1885 } |
1880 | 1886 |
1887 void RenderViewImpl::lockPointer() { | |
1888 // HACK | |
1889 bool succeeded = true; | |
1890 mouse_locked_ = succeeded; | |
1891 if (webview()) { | |
1892 fprintf(stderr, "RenderViewImpl::lockPointer() webview()->lockPointerAck();\ n"); | |
1893 webview()->OnLockMouseACK2(succeeded); | |
1894 } else { | |
1895 fprintf(stderr, "RenderViewImpl::lockPointer() NULL webview();\n"); | |
1896 } | |
1897 } | |
1898 | |
1899 void RenderViewImpl::unlockPointer() { | |
1900 // HACK | |
1901 OnMouseLockLost(); | |
1902 } | |
1903 | |
1904 bool RenderViewImpl::isPointerLocked() { | |
1905 fprintf(stderr, "RenderViewImpl::isPointerLocked()\n"); | |
1906 return mouse_locked_; | |
1907 } | |
1908 | |
1881 // WebKit::WebFrameClient ----------------------------------------------------- | 1909 // WebKit::WebFrameClient ----------------------------------------------------- |
1882 | 1910 |
1883 WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, | 1911 WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, |
1884 const WebPluginParams& params) { | 1912 const WebPluginParams& params) { |
1885 WebPlugin* plugin = NULL; | 1913 WebPlugin* plugin = NULL; |
1886 if (content::GetContentClient()->renderer()->OverrideCreatePlugin( | 1914 if (content::GetContentClient()->renderer()->OverrideCreatePlugin( |
1887 this, frame, params, &plugin)) { | 1915 this, frame, params, &plugin)) { |
1888 return plugin; | 1916 return plugin; |
1889 } | 1917 } |
1890 | 1918 |
(...skipping 2385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4276 WebView* doomed = webview(); | 4304 WebView* doomed = webview(); |
4277 RenderWidget::Close(); | 4305 RenderWidget::Close(); |
4278 g_view_map.Get().erase(doomed); | 4306 g_view_map.Get().erase(doomed); |
4279 } | 4307 } |
4280 | 4308 |
4281 void RenderViewImpl::DidHandleKeyEvent() { | 4309 void RenderViewImpl::DidHandleKeyEvent() { |
4282 edit_commands_.clear(); | 4310 edit_commands_.clear(); |
4283 } | 4311 } |
4284 | 4312 |
4285 bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 4313 bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
4286 return pepper_delegate_.HandleMouseEvent(event); | 4314 pepper_delegate_.WillHandleMouseEvent(); |
4315 | |
4316 if (mouse_locked_) { | |
4317 // |cursor_info| is ignored since it is hidden when the mouse is locked. | |
4318 WebKit::WebCursorInfo cursor_info; | |
4319 | |
4320 DCHECK(!mouse_lock_webwidget_owner_ || !mouse_lock_pinstance_owner_); | |
4321 if (mouse_lock_webwidget_owner_) | |
4322 mouse_lock_webwidget_owner_->HandleMouseLockedInputEvent(event); | |
4323 if (mouse_lock_pinstance_owner_) | |
4324 mouse_lock_pinstance_owner_->HandleMouseLockedInputEvent(event); | |
4325 | |
4326 // If the mouse is locked, only the current owner of the mouse lock can | |
4327 // process mouse events. | |
4328 return true; | |
4329 } | |
4330 return false; | |
4287 } | 4331 } |
4288 | 4332 |
4289 void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 4333 void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
4290 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); | 4334 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
4291 } | 4335 } |
4292 | 4336 |
4293 void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { | 4337 void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
4294 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); | 4338 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
4295 } | 4339 } |
4296 | 4340 |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4764 | 4808 |
4765 void RenderViewImpl::OnEnableViewSourceMode() { | 4809 void RenderViewImpl::OnEnableViewSourceMode() { |
4766 if (!webview()) | 4810 if (!webview()) |
4767 return; | 4811 return; |
4768 WebFrame* main_frame = webview()->mainFrame(); | 4812 WebFrame* main_frame = webview()->mainFrame(); |
4769 if (!main_frame) | 4813 if (!main_frame) |
4770 return; | 4814 return; |
4771 main_frame->enableViewSourceMode(true); | 4815 main_frame->enableViewSourceMode(true); |
4772 } | 4816 } |
4773 | 4817 |
4818 bool RenderViewImpl::LockMouseInternal(WebKit::WebWidget* webwidget, | |
4819 webkit::ppapi::PluginInstance* pinstance) { | |
4820 DCHECK(!(webwidget && pinstance)); // Only one mouse lock target at a time. | |
4821 fprintf(stderr, "RenderViewImpl::LockMouseInternal(%s, %s) ", webwidget ? "we bwidget" : "NULL", pinstance ? "pinstance" : "NULL"); | |
4822 | |
4823 if (MouseLockedOrPendingAction()) | |
4824 { | |
4825 fprintf(stderr, "return false; // (locked or pending)\n"); | |
4826 return false; | |
4827 } | |
4828 | |
4829 pending_lock_request_ = true; | |
4830 DCHECK(!mouse_lock_webwidget_owner_ && !mouse_lock_pinstance_owner_); | |
4831 mouse_lock_webwidget_owner_ = webwidget; | |
4832 mouse_lock_pinstance_owner_ = pinstance; | |
4833 | |
4834 Send(new ViewHostMsg_LockMouse(routing_id())); | |
4835 fprintf(stderr, "return true;\n"); | |
4836 return true; | |
4837 } | |
4838 | |
4839 void RenderViewImpl::UnlockMouseInternal(WebKit::WebWidget* webwidget, | |
4840 webkit::ppapi::PluginInstance* pinstance) { | |
4841 fprintf(stderr, "RenderViewImpl::UnlockMouseInternal(%s, %s) \n", webwidget ? "webwidget" : "NULL", pinstance ? "pinstance" : "NULL"); | |
4842 if (!MouseLockedOrPendingAction()) | |
4843 { | |
4844 fprintf(stderr, "RenderViewImpl::LockMouseInternal() if (!MouseLockedOrPend ingAction()) return\n"); | |
4845 return; | |
4846 } | |
4847 if (pending_unlock_request_) | |
yzshen1
2012/01/04 00:50:00
nit: It seems better to put this in the if-block o
| |
4848 { | |
4849 fprintf(stderr, "RenderViewImpl::LockMouseInternal() if (pending_unlock_req uest_) return\n"); | |
4850 return; | |
4851 } | |
4852 | |
4853 // Ignore unless the unlock request is for the current lock holder. | |
4854 if (webwidget == mouse_lock_webwidget_owner_ || | |
4855 pinstance == mouse_lock_pinstance_owner_) { | |
4856 pending_unlock_request_ = true; | |
4857 Send(new ViewHostMsg_UnlockMouse(routing_id())); | |
4858 } | |
4859 else | |
4860 { | |
4861 fprintf(stderr, "RenderViewImpl::LockMouseInternal() not the current target \n"); | |
4862 } | |
4863 } | |
4864 | |
4774 void RenderViewImpl::OnLockMouseACK(bool succeeded) { | 4865 void RenderViewImpl::OnLockMouseACK(bool succeeded) { |
4775 // Mouse Lock removes the system cursor and provides all mouse motion as | 4866 // Mouse Lock removes the system cursor and provides all mouse motion as |
4776 // .movementX/Y values on events all sent to a fixed target. This requires | 4867 // .movementX/Y values on events all sent to a fixed target. This requires |
4777 // content to specifically request the mode to be entered. | 4868 // content to specifically request the mode to be entered. |
4778 // Mouse Capture is implicitly given for the duration of a drag event, and | 4869 // Mouse Capture is implicitly given for the duration of a drag event, and |
4779 // sends all mouse events to the initial target of the drag. | 4870 // sends all mouse events to the initial target of the drag. |
4780 // If Lock is entered it supercedes any in progress Capture. | 4871 // If Lock is entered it supercedes any in progress Capture. |
4781 if (succeeded) | 4872 if (succeeded) |
4782 OnMouseCaptureLost(); | 4873 OnMouseCaptureLost(); |
4783 | 4874 |
4784 pepper_delegate_.OnLockMouseACK(succeeded); | 4875 //scheibXXX |
4876 // was: pepper_delegate_.OnLockMouseACK(succeeded); | |
4877 DCHECK(!mouse_locked_ && pending_lock_request_); | |
4878 | |
4879 mouse_locked_ = succeeded; | |
4880 pending_lock_request_ = false; | |
4881 if (pending_unlock_request_ && !succeeded) { | |
4882 // We have sent an unlock request after the lock request. However, since | |
4883 // the lock request has failed, the unlock request will be ignored by the | |
4884 // browser side and there won't be any response to it. | |
4885 pending_unlock_request_ = false; | |
4886 } | |
4887 | |
4888 if (mouse_lock_webwidget_owner_ || mouse_lock_pinstance_owner_) { | |
4889 WebKit::WebWidget* last_webwidget_owner = mouse_lock_webwidget_owner_; | |
4890 webkit::ppapi::PluginInstance* last_pinstance_owner = | |
4891 mouse_lock_pinstance_owner_; | |
4892 | |
4893 if (!succeeded) { | |
4894 // Reset mouse lock owner to NULL before calling OnLockMouseACK(), so | |
4895 // that if OnLockMouseACK() results in calls to any mouse lock method | |
4896 // (e.g., LockMouse()), the method will see consistent internal state. | |
4897 mouse_lock_webwidget_owner_ = NULL; | |
4898 mouse_lock_pinstance_owner_ = NULL; | |
4899 } | |
4900 | |
4901 DCHECK(!mouse_lock_webwidget_owner_ || !mouse_lock_pinstance_owner_); | |
4902 if (last_webwidget_owner) | |
4903 last_webwidget_owner->OnLockMouseACK2(succeeded); | |
4904 if (last_pinstance_owner) | |
4905 last_pinstance_owner->OnLockMouseACK2(succeeded); | |
4906 } | |
4907 //scheibXXX | |
4908 // end was: pepper_delegate_.OnLockMouseACK(succeeded); | |
4785 } | 4909 } |
4786 | 4910 |
4787 void RenderViewImpl::OnMouseLockLost() { | 4911 void RenderViewImpl::OnMouseLockLost() { |
4788 pepper_delegate_.OnMouseLockLost(); | 4912 DCHECK(mouse_locked_ && !pending_lock_request_); |
4913 | |
4914 mouse_locked_ = false; | |
4915 pending_unlock_request_ = false; | |
4916 if (mouse_lock_webwidget_owner_ || mouse_lock_pinstance_owner_) { | |
4917 WebKit::WebWidget* last_webwidget_owner = mouse_lock_webwidget_owner_; | |
4918 webkit::ppapi::PluginInstance* last_pinstance_owner = | |
4919 mouse_lock_pinstance_owner_; | |
4920 | |
4921 // Reset mouse lock owner to NULL before calling OnLockMouseACK(), so | |
4922 // that if OnLockMouseACK() results in calls to any mouse lock method | |
4923 // (e.g., LockMouse()), the method will see consistent internal state. | |
4924 mouse_lock_webwidget_owner_ = NULL; | |
4925 mouse_lock_pinstance_owner_ = NULL; | |
4926 | |
4927 DCHECK(!mouse_lock_webwidget_owner_ || !mouse_lock_pinstance_owner_); | |
4928 if (last_webwidget_owner) | |
4929 last_webwidget_owner->OnMouseLockLost2(); | |
4930 if (last_pinstance_owner) | |
4931 last_pinstance_owner->OnMouseLockLost2(); | |
4932 } | |
4789 } | 4933 } |
4790 | 4934 |
4791 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { | 4935 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
4792 return !!RenderThreadImpl::current()->compositor_thread(); | 4936 return !!RenderThreadImpl::current()->compositor_thread(); |
4793 } | 4937 } |
4794 | 4938 |
4795 void RenderViewImpl::OnJavaBridgeInit( | 4939 void RenderViewImpl::OnJavaBridgeInit( |
4796 const IPC::ChannelHandle& channel_handle) { | 4940 const IPC::ChannelHandle& channel_handle) { |
4797 DCHECK(!java_bridge_dispatcher_.get()); | 4941 DCHECK(!java_bridge_dispatcher_.get()); |
4798 #if defined(ENABLE_JAVA_BRIDGE) | 4942 #if defined(ENABLE_JAVA_BRIDGE) |
4799 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this, channel_handle)); | 4943 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this, channel_handle)); |
4800 #endif | 4944 #endif |
4801 } | 4945 } |
OLD | NEW |