OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "chrome/browser/ui/exclusive_access/mouse_lock_controller.h" | 5 #include "chrome/browser/ui/exclusive_access/mouse_lock_controller.h" |
6 | 6 |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
| 11 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 12 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
11 #include "components/content_settings/core/browser/host_content_settings_map.h" | 13 #include "components/content_settings/core/browser/host_content_settings_map.h" |
12 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
13 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/render_widget_host_view.h" | 16 #include "content/public/browser/render_widget_host_view.h" |
15 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
16 | 18 |
17 using content::RenderViewHost; | 19 using content::RenderViewHost; |
18 using content::WebContents; | 20 using content::WebContents; |
19 | 21 |
20 MouseLockController::MouseLockController(ExclusiveAccessManager* manager, | 22 MouseLockController::MouseLockController(ExclusiveAccessManager* manager) |
21 Browser* browser) | 23 : ExclusiveAccessControllerBase(manager), |
22 : ExclusiveAccessControllerBase(manager, browser), | |
23 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED) { | 24 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED) { |
24 } | 25 } |
25 | 26 |
26 MouseLockController::~MouseLockController() { | 27 MouseLockController::~MouseLockController() { |
27 } | 28 } |
28 | 29 |
29 bool MouseLockController::IsMouseLocked() const { | 30 bool MouseLockController::IsMouseLocked() const { |
30 return mouse_lock_state_ == MOUSELOCK_ACCEPTED || | 31 return mouse_lock_state_ == MOUSELOCK_ACCEPTED || |
31 mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY; | 32 mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY; |
32 } | 33 } |
(...skipping 27 matching lines...) Expand all Loading... |
60 case CONTENT_SETTING_ALLOW: | 61 case CONTENT_SETTING_ALLOW: |
61 // If bubble already displaying buttons we must not lock the mouse yet, | 62 // If bubble already displaying buttons we must not lock the mouse yet, |
62 // or it would prevent pressing those buttons. Instead, merge the request. | 63 // or it would prevent pressing those buttons. Instead, merge the request. |
63 if (!exclusive_access_manager() | 64 if (!exclusive_access_manager() |
64 ->fullscreen_controller() | 65 ->fullscreen_controller() |
65 ->IsPrivilegedFullscreenForTab() && | 66 ->IsPrivilegedFullscreenForTab() && |
66 exclusive_access_bubble::ShowButtonsForType(bubble_type)) { | 67 exclusive_access_bubble::ShowButtonsForType(bubble_type)) { |
67 mouse_lock_state_ = MOUSELOCK_REQUESTED; | 68 mouse_lock_state_ = MOUSELOCK_REQUESTED; |
68 } else { | 69 } else { |
69 // Lock mouse. | 70 // Lock mouse. |
70 if (web_contents->GotResponseToLockMouseRequest(true)) { | 71 ExclusiveAccessContext* context = |
| 72 exclusive_access_manager()->exclusive_access_context(); |
| 73 if ((context->UseCallbackForMouseLock() && |
| 74 context->MouseLockCallback(true)) || |
| 75 web_contents->GotResponseToLockMouseRequest(true)) { |
71 if (last_unlocked_by_target) { | 76 if (last_unlocked_by_target) { |
72 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY; | 77 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY; |
73 } else { | 78 } else { |
74 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | 79 mouse_lock_state_ = MOUSELOCK_ACCEPTED; |
75 } | 80 } |
76 } else { | 81 } else { |
77 SetTabWithExclusiveAccess(nullptr); | 82 SetTabWithExclusiveAccess(nullptr); |
78 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 83 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
79 } | 84 } |
80 } | 85 } |
81 break; | 86 break; |
82 case CONTENT_SETTING_BLOCK: | 87 case CONTENT_SETTING_BLOCK: |
83 web_contents->GotResponseToLockMouseRequest(false); | 88 web_contents->GotResponseToLockMouseRequest(false); |
84 SetTabWithExclusiveAccess(nullptr); | 89 SetTabWithExclusiveAccess(nullptr); |
85 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 90 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
86 break; | 91 break; |
87 case CONTENT_SETTING_ASK: | 92 case CONTENT_SETTING_ASK: |
88 mouse_lock_state_ = MOUSELOCK_REQUESTED; | 93 mouse_lock_state_ = MOUSELOCK_REQUESTED; |
89 break; | 94 break; |
90 default: | 95 default: |
91 NOTREACHED(); | 96 NOTREACHED(); |
92 } | 97 } |
| 98 |
93 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); | 99 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); |
94 } | 100 } |
95 | 101 |
96 void MouseLockController::ExitExclusiveAccessIfNecessary() { | 102 void MouseLockController::ExitExclusiveAccessIfNecessary() { |
97 NotifyTabExclusiveAccessLost(); | 103 NotifyTabExclusiveAccessLost(); |
98 } | 104 } |
99 | 105 |
100 void MouseLockController::NotifyTabExclusiveAccessLost() { | 106 void MouseLockController::NotifyTabExclusiveAccessLost() { |
101 WebContents* tab = exclusive_access_tab(); | 107 WebContents* tab = exclusive_access_tab(); |
102 if (tab) { | 108 if (tab) { |
(...skipping 26 matching lines...) Expand all Loading... |
129 ExclusiveAccessBubbleType bubble_type = | 135 ExclusiveAccessBubbleType bubble_type = |
130 exclusive_access_manager()->GetExclusiveAccessExitBubbleType(); | 136 exclusive_access_manager()->GetExclusiveAccessExitBubbleType(); |
131 bool mouse_lock = false; | 137 bool mouse_lock = false; |
132 exclusive_access_bubble::PermissionRequestedByType(bubble_type, nullptr, | 138 exclusive_access_bubble::PermissionRequestedByType(bubble_type, nullptr, |
133 &mouse_lock); | 139 &mouse_lock); |
134 DCHECK(!(mouse_lock && IsMouseLocked())); | 140 DCHECK(!(mouse_lock && IsMouseLocked())); |
135 | 141 |
136 if (mouse_lock && !IsMouseLocked()) { | 142 if (mouse_lock && !IsMouseLocked()) { |
137 DCHECK(IsMouseLockRequested()); | 143 DCHECK(IsMouseLockRequested()); |
138 | 144 |
139 HostContentSettingsMap* settings_map = | 145 HostContentSettingsMap* settings_map = exclusive_access_manager() |
140 profile()->GetHostContentSettingsMap(); | 146 ->exclusive_access_context() |
| 147 ->GetProfile() |
| 148 ->GetHostContentSettingsMap(); |
141 | 149 |
142 GURL url = GetExclusiveAccessBubbleURL(); | 150 GURL url = GetExclusiveAccessBubbleURL(); |
143 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); | 151 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); |
144 | 152 |
145 // TODO(markusheintz): We should allow patterns for all possible URLs here. | 153 // TODO(markusheintz): We should allow patterns for all possible URLs here. |
146 // | 154 // |
147 // Do not store preference on file:// URLs, they don't have a clean | 155 // Do not store preference on file:// URLs, they don't have a clean |
148 // origin policy. | 156 // origin policy. |
149 // TODO(estark): Revisit this when crbug.com/455882 is fixed. | 157 // TODO(estark): Revisit this when crbug.com/455882 is fixed. |
150 if (!url.SchemeIsFile() && pattern.IsValid()) { | 158 if (!url.SchemeIsFile() && pattern.IsValid()) { |
151 settings_map->SetContentSetting(pattern, | 159 settings_map->SetContentSetting(pattern, |
152 ContentSettingsPattern::Wildcard(), | 160 ContentSettingsPattern::Wildcard(), |
153 CONTENT_SETTINGS_TYPE_MOUSELOCK, | 161 CONTENT_SETTINGS_TYPE_MOUSELOCK, |
154 std::string(), CONTENT_SETTING_ALLOW); | 162 std::string(), CONTENT_SETTING_ALLOW); |
155 } | 163 } |
156 | 164 |
| 165 ExclusiveAccessContext* context = |
| 166 exclusive_access_manager()->exclusive_access_context(); |
157 WebContents* tab = exclusive_access_tab(); | 167 WebContents* tab = exclusive_access_tab(); |
158 if (tab && tab->GotResponseToLockMouseRequest(true)) { | 168 if (context->UseCallbackForMouseLock()) { |
159 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | 169 if (tab && context->MouseLockCallback(true)) { |
| 170 mouse_lock_state_ = MOUSELOCK_ACCEPTED; |
| 171 } else { |
| 172 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| 173 SetTabWithExclusiveAccess(nullptr); |
| 174 } |
160 } else { | 175 } else { |
161 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 176 if (tab && tab->GotResponseToLockMouseRequest(true)) { |
162 SetTabWithExclusiveAccess(nullptr); | 177 mouse_lock_state_ = MOUSELOCK_ACCEPTED; |
| 178 } else { |
| 179 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| 180 SetTabWithExclusiveAccess(nullptr); |
| 181 } |
163 } | 182 } |
164 NotifyMouseLockChange(); | 183 NotifyMouseLockChange(); |
165 return true; | 184 return true; |
166 } | 185 } |
167 | 186 |
168 return false; | 187 return false; |
169 } | 188 } |
170 | 189 |
171 bool MouseLockController::OnDenyExclusiveAccessPermission() { | 190 bool MouseLockController::OnDenyExclusiveAccessPermission() { |
172 WebContents* tab = exclusive_access_tab(); | 191 WebContents* tab = exclusive_access_tab(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 // decision stick for a particular origin. | 249 // decision stick for a particular origin. |
231 // TODO(estark): Revisit this when crbug.com/455882 is fixed. | 250 // TODO(estark): Revisit this when crbug.com/455882 is fixed. |
232 if (url.SchemeIsFile()) | 251 if (url.SchemeIsFile()) |
233 return CONTENT_SETTING_ASK; | 252 return CONTENT_SETTING_ASK; |
234 | 253 |
235 if (exclusive_access_manager() | 254 if (exclusive_access_manager() |
236 ->fullscreen_controller() | 255 ->fullscreen_controller() |
237 ->IsPrivilegedFullscreenForTab()) | 256 ->IsPrivilegedFullscreenForTab()) |
238 return CONTENT_SETTING_ALLOW; | 257 return CONTENT_SETTING_ALLOW; |
239 | 258 |
240 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); | 259 HostContentSettingsMap* settings_map = exclusive_access_manager() |
241 return settings_map->GetContentSetting( | 260 ->exclusive_access_context() |
| 261 ->GetProfile() |
| 262 ->GetHostContentSettingsMap(); |
| 263 ContentSetting setting = settings_map->GetContentSetting( |
242 url, url, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); | 264 url, url, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); |
| 265 return setting; |
243 } | 266 } |
OLD | NEW |