Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 2591783003: Implement pointer lock across outer/inner WebContents. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/web_contents/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <utility> 10 #include <utility>
(...skipping 1898 matching lines...) Expand 10 before | Expand all | Expand 10 after
1909 1909
1910 return delegate_ ? delegate_->GetDisplayMode(this) 1910 return delegate_ ? delegate_->GetDisplayMode(this)
1911 : blink::WebDisplayModeBrowser; 1911 : blink::WebDisplayModeBrowser;
1912 } 1912 }
1913 1913
1914 void WebContentsImpl::RequestToLockMouse( 1914 void WebContentsImpl::RequestToLockMouse(
1915 RenderWidgetHostImpl* render_widget_host, 1915 RenderWidgetHostImpl* render_widget_host,
1916 bool user_gesture, 1916 bool user_gesture,
1917 bool last_unlocked_by_target, 1917 bool last_unlocked_by_target,
1918 bool privileged) { 1918 bool privileged) {
1919 if (mouse_lock_widget_) { 1919 for (WebContentsImpl* current = this; current;
1920 render_widget_host->GotResponseToLockMouseRequest(false); 1920 current = current->GetOuterWebContents()) {
1921 return; 1921 if (current->mouse_lock_widget_) {
ncarter (slow) 2016/12/22 00:01:07 I'm wondering if we should contemplate having some
lfg 2016/12/22 19:23:55 I thought about that a bit, but for a single point
1922 render_widget_host->GotResponseToLockMouseRequest(false);
1923 return;
1924 }
1922 } 1925 }
1923 1926
1924 if (privileged) { 1927 if (privileged) {
1928 DCHECK(!GetOuterWebContents());
1925 mouse_lock_widget_ = render_widget_host; 1929 mouse_lock_widget_ = render_widget_host;
1926 render_widget_host->GotResponseToLockMouseRequest(true); 1930 render_widget_host->GotResponseToLockMouseRequest(true);
1927 return; 1931 return;
1928 } 1932 }
1929 1933
1930 bool widget_in_frame_tree = false; 1934 bool widget_in_frame_tree = false;
1931 for (FrameTreeNode* node : frame_tree_.Nodes()) { 1935 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1932 if (node->current_frame_host()->GetRenderWidgetHost() == 1936 if (node->current_frame_host()->GetRenderWidgetHost() ==
1933 render_widget_host) { 1937 render_widget_host) {
1934 widget_in_frame_tree = true; 1938 widget_in_frame_tree = true;
1935 break; 1939 break;
1936 } 1940 }
1937 } 1941 }
1938 1942
1939 if (widget_in_frame_tree && delegate_) { 1943 if (widget_in_frame_tree && delegate_) {
1940 mouse_lock_widget_ = render_widget_host; 1944 for (WebContentsImpl* current = this; current;
1945 current = current->GetOuterWebContents()) {
1946 current->mouse_lock_widget_ = render_widget_host;
1947 }
1948
1941 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); 1949 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
1942 } else { 1950 } else {
1943 render_widget_host->GotResponseToLockMouseRequest(false); 1951 render_widget_host->GotResponseToLockMouseRequest(false);
1944 } 1952 }
1945 } 1953 }
1946 1954
1947 void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) { 1955 void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
1948 CHECK(mouse_lock_widget_); 1956 CHECK(mouse_lock_widget_);
1957
1958 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this)
1959 return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host);
1960
1949 mouse_lock_widget_->SendMouseLockLost(); 1961 mouse_lock_widget_->SendMouseLockLost();
1950 mouse_lock_widget_ = nullptr; 1962 for (WebContentsImpl* current = this; current;
1963 current = current->GetOuterWebContents()) {
1964 current->mouse_lock_widget_ = nullptr;
1965 }
1951 1966
1952 if (delegate_) 1967 if (delegate_)
1953 delegate_->LostMouseLock(); 1968 delegate_->LostMouseLock();
1954 } 1969 }
1955 1970
1956 bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) { 1971 bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) {
1957 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be 1972 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be
1958 // assigned to the widget that requested the mouse lock, and the top-level 1973 // assigned to the widget that requested the mouse lock, and the top-level
1959 // platform RenderWidgetHostView needs to hold the mouse lock from the OS. 1974 // platform RenderWidgetHostView needs to hold the mouse lock from the OS.
1960 return mouse_lock_widget_ == render_widget_host && 1975 return mouse_lock_widget_ == render_widget_host &&
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
3056 void WebContentsImpl::SetPageScale(float page_scale_factor) { 3071 void WebContentsImpl::SetPageScale(float page_scale_factor) {
3057 Send(new ViewMsg_SetPageScale(GetRenderViewHost()->GetRoutingID(), 3072 Send(new ViewMsg_SetPageScale(GetRenderViewHost()->GetRoutingID(),
3058 page_scale_factor)); 3073 page_scale_factor));
3059 } 3074 }
3060 3075
3061 gfx::Size WebContentsImpl::GetPreferredSize() const { 3076 gfx::Size WebContentsImpl::GetPreferredSize() const {
3062 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_; 3077 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
3063 } 3078 }
3064 3079
3065 bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) { 3080 bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
3066 if (GetBrowserPluginGuest()) 3081 if (!GuestMode::IsCrossProcessFrameGuest(GetWebContents()) &&
3082 GetBrowserPluginGuest())
3067 return GetBrowserPluginGuest()->LockMouse(allowed); 3083 return GetBrowserPluginGuest()->LockMouse(allowed);
3068 3084
3069 if (mouse_lock_widget_ && 3085 if (mouse_lock_widget_) {
3070 mouse_lock_widget_->GotResponseToLockMouseRequest(allowed)) 3086 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) {
ncarter (slow) 2016/12/22 00:01:07 When does this case happen? From what I can tell,
lfg 2016/12/22 19:23:55 GotResponseToLockMouseRequest is a poor name for t
3071 return true; 3087 return mouse_lock_widget_->delegate()
3088 ->GetAsWebContents()
3089 ->GotResponseToLockMouseRequest(allowed);
3090 }
3072 3091
3073 mouse_lock_widget_ = nullptr; 3092 if (mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
3093 return true;
3094 }
3095
3096 for (WebContentsImpl* current = this; current;
3097 current = current->GetOuterWebContents()) {
3098 current->mouse_lock_widget_ = nullptr;
3099 }
3100
3074 return false; 3101 return false;
3075 } 3102 }
3076 3103
3077 bool WebContentsImpl::HasOpener() const { 3104 bool WebContentsImpl::HasOpener() const {
3078 return GetOpener() != NULL; 3105 return GetOpener() != NULL;
3079 } 3106 }
3080 3107
3081 WebContentsImpl* WebContentsImpl::GetOpener() const { 3108 WebContentsImpl* WebContentsImpl::GetOpener() const {
3082 FrameTreeNode* opener_ftn = frame_tree_.root()->opener(); 3109 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
3083 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr; 3110 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
(...skipping 2248 matching lines...) Expand 10 before | Expand all | Expand 10 after
5332 GetMainFrame()->AddMessageToConsole( 5359 GetMainFrame()->AddMessageToConsole(
5333 content::CONSOLE_MESSAGE_LEVEL_WARNING, 5360 content::CONSOLE_MESSAGE_LEVEL_WARNING,
5334 base::StringPrintf("This site does not have a valid SSL " 5361 base::StringPrintf("This site does not have a valid SSL "
5335 "certificate! Without SSL, your site's and " 5362 "certificate! Without SSL, your site's and "
5336 "visitors' data is vulnerable to theft and " 5363 "visitors' data is vulnerable to theft and "
5337 "tampering. Get a valid SSL certificate before" 5364 "tampering. Get a valid SSL certificate before"
5338 " releasing your website to the public.")); 5365 " releasing your website to the public."));
5339 } 5366 }
5340 5367
5341 } // namespace content 5368 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698