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

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

Issue 2591783003: Implement pointer lock across outer/inner WebContents. (Closed)
Patch Set: rebase Created 3 years, 11 months 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 1905 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 1916
1917 return delegate_ ? delegate_->GetDisplayMode(this) 1917 return delegate_ ? delegate_->GetDisplayMode(this)
1918 : blink::WebDisplayModeBrowser; 1918 : blink::WebDisplayModeBrowser;
1919 } 1919 }
1920 1920
1921 void WebContentsImpl::RequestToLockMouse( 1921 void WebContentsImpl::RequestToLockMouse(
1922 RenderWidgetHostImpl* render_widget_host, 1922 RenderWidgetHostImpl* render_widget_host,
1923 bool user_gesture, 1923 bool user_gesture,
1924 bool last_unlocked_by_target, 1924 bool last_unlocked_by_target,
1925 bool privileged) { 1925 bool privileged) {
1926 if (mouse_lock_widget_) { 1926 for (WebContentsImpl* current = this; current;
1927 render_widget_host->GotResponseToLockMouseRequest(false); 1927 current = current->GetOuterWebContents()) {
1928 return; 1928 if (current->mouse_lock_widget_) {
1929 render_widget_host->GotResponseToLockMouseRequest(false);
1930 return;
1931 }
1929 } 1932 }
1930 1933
1931 if (privileged) { 1934 if (privileged) {
1935 DCHECK(!GetOuterWebContents());
1932 mouse_lock_widget_ = render_widget_host; 1936 mouse_lock_widget_ = render_widget_host;
1933 render_widget_host->GotResponseToLockMouseRequest(true); 1937 render_widget_host->GotResponseToLockMouseRequest(true);
1934 return; 1938 return;
1935 } 1939 }
1936 1940
1937 bool widget_in_frame_tree = false; 1941 bool widget_in_frame_tree = false;
1938 for (FrameTreeNode* node : frame_tree_.Nodes()) { 1942 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1939 if (node->current_frame_host()->GetRenderWidgetHost() == 1943 if (node->current_frame_host()->GetRenderWidgetHost() ==
1940 render_widget_host) { 1944 render_widget_host) {
1941 widget_in_frame_tree = true; 1945 widget_in_frame_tree = true;
1942 break; 1946 break;
1943 } 1947 }
1944 } 1948 }
1945 1949
1946 if (widget_in_frame_tree && delegate_) { 1950 if (widget_in_frame_tree && delegate_) {
1947 mouse_lock_widget_ = render_widget_host; 1951 for (WebContentsImpl* current = this; current;
1952 current = current->GetOuterWebContents()) {
1953 current->mouse_lock_widget_ = render_widget_host;
1954 }
1955
1948 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); 1956 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
1949 } else { 1957 } else {
1950 render_widget_host->GotResponseToLockMouseRequest(false); 1958 render_widget_host->GotResponseToLockMouseRequest(false);
1951 } 1959 }
1952 } 1960 }
1953 1961
1954 void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) { 1962 void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
1955 CHECK(mouse_lock_widget_); 1963 CHECK(mouse_lock_widget_);
1964
1965 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this)
1966 return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host);
1967
1956 mouse_lock_widget_->SendMouseLockLost(); 1968 mouse_lock_widget_->SendMouseLockLost();
1957 mouse_lock_widget_ = nullptr; 1969 for (WebContentsImpl* current = this; current;
1970 current = current->GetOuterWebContents()) {
1971 current->mouse_lock_widget_ = nullptr;
1972 }
1958 1973
1959 if (delegate_) 1974 if (delegate_)
1960 delegate_->LostMouseLock(); 1975 delegate_->LostMouseLock();
1961 } 1976 }
1962 1977
1963 bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) { 1978 bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) {
1964 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be 1979 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be
1965 // assigned to the widget that requested the mouse lock, and the top-level 1980 // assigned to the widget that requested the mouse lock, and the top-level
1966 // platform RenderWidgetHostView needs to hold the mouse lock from the OS. 1981 // platform RenderWidgetHostView needs to hold the mouse lock from the OS.
1967 return mouse_lock_widget_ == render_widget_host && 1982 return mouse_lock_widget_ == render_widget_host &&
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
3063 void WebContentsImpl::SetPageScale(float page_scale_factor) { 3078 void WebContentsImpl::SetPageScale(float page_scale_factor) {
3064 Send(new ViewMsg_SetPageScale(GetRenderViewHost()->GetRoutingID(), 3079 Send(new ViewMsg_SetPageScale(GetRenderViewHost()->GetRoutingID(),
3065 page_scale_factor)); 3080 page_scale_factor));
3066 } 3081 }
3067 3082
3068 gfx::Size WebContentsImpl::GetPreferredSize() const { 3083 gfx::Size WebContentsImpl::GetPreferredSize() const {
3069 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_; 3084 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
3070 } 3085 }
3071 3086
3072 bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) { 3087 bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
3073 if (GetBrowserPluginGuest()) 3088 if (!GuestMode::IsCrossProcessFrameGuest(GetWebContents()) &&
3089 GetBrowserPluginGuest())
3074 return GetBrowserPluginGuest()->LockMouse(allowed); 3090 return GetBrowserPluginGuest()->LockMouse(allowed);
3075 3091
3076 if (mouse_lock_widget_ && 3092 if (mouse_lock_widget_) {
3077 mouse_lock_widget_->GotResponseToLockMouseRequest(allowed)) 3093 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) {
3078 return true; 3094 return mouse_lock_widget_->delegate()
3095 ->GetAsWebContents()
3096 ->GotResponseToLockMouseRequest(allowed);
3097 }
3079 3098
3080 mouse_lock_widget_ = nullptr; 3099 if (mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
3100 return true;
3101 }
3102
3103 for (WebContentsImpl* current = this; current;
3104 current = current->GetOuterWebContents()) {
3105 current->mouse_lock_widget_ = nullptr;
3106 }
3107
3081 return false; 3108 return false;
3082 } 3109 }
3083 3110
3084 bool WebContentsImpl::HasOpener() const { 3111 bool WebContentsImpl::HasOpener() const {
3085 return GetOpener() != NULL; 3112 return GetOpener() != NULL;
3086 } 3113 }
3087 3114
3088 WebContentsImpl* WebContentsImpl::GetOpener() const { 3115 WebContentsImpl* WebContentsImpl::GetOpener() const {
3089 FrameTreeNode* opener_ftn = frame_tree_.root()->opener(); 3116 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
3090 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr; 3117 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
(...skipping 2300 matching lines...) Expand 10 before | Expand all | Expand 10 after
5391 GetMainFrame()->AddMessageToConsole( 5418 GetMainFrame()->AddMessageToConsole(
5392 content::CONSOLE_MESSAGE_LEVEL_WARNING, 5419 content::CONSOLE_MESSAGE_LEVEL_WARNING,
5393 base::StringPrintf("This site does not have a valid SSL " 5420 base::StringPrintf("This site does not have a valid SSL "
5394 "certificate! Without SSL, your site's and " 5421 "certificate! Without SSL, your site's and "
5395 "visitors' data is vulnerable to theft and " 5422 "visitors' data is vulnerable to theft and "
5396 "tampering. Get a valid SSL certificate before" 5423 "tampering. Get a valid SSL certificate before"
5397 " releasing your website to the public.")); 5424 " releasing your website to the public."));
5398 } 5425 }
5399 5426
5400 } // namespace content 5427 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698