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

Side by Side Diff: chrome/browser/ui/exclusive_access/fullscreen_controller.cc

Issue 836933005: Refactor fullscreen_controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build break Created 5 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 "chrome/browser/ui/exclusive_access/fullscreen_controller.h" 5 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/app_mode/app_mode_utils.h" 10 #include "chrome/browser/app_mode/app_mode_utils.h"
(...skipping 19 matching lines...) Expand all
30 30
31 #if !defined(OS_MACOSX) 31 #if !defined(OS_MACOSX)
32 #include "base/prefs/pref_service.h" 32 #include "base/prefs/pref_service.h"
33 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
34 #endif 34 #endif
35 35
36 using base::UserMetricsAction; 36 using base::UserMetricsAction;
37 using content::RenderViewHost; 37 using content::RenderViewHost;
38 using content::WebContents; 38 using content::WebContents;
39 39
40 FullscreenController::FullscreenController(Browser* browser) 40 FullscreenController::FullscreenController(ExclusiveAccessManager* manager,
41 : browser_(browser), 41 Browser* browser)
42 window_(browser->window()), 42 : ExclusiveAccessControllerBase(manager, browser),
43 profile_(browser->profile()),
44 fullscreened_tab_(NULL),
45 state_prior_to_tab_fullscreen_(STATE_INVALID), 43 state_prior_to_tab_fullscreen_(STATE_INVALID),
46 tab_fullscreen_accepted_(false), 44 tab_fullscreen_accepted_(false),
47 toggled_into_fullscreen_(false), 45 toggled_into_fullscreen_(false),
48 mouse_lock_tab_(NULL),
49 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED),
50 reentrant_window_state_change_call_check_(false), 46 reentrant_window_state_change_call_check_(false),
51 is_privileged_fullscreen_for_testing_(false), 47 is_privileged_fullscreen_for_testing_(false),
52 ptr_factory_(this) { 48 ptr_factory_(this) {
53 DCHECK(window_);
54 DCHECK(profile_);
55 } 49 }
56 50
57 FullscreenController::~FullscreenController() { 51 FullscreenController::~FullscreenController() {
58 } 52 }
59 53
60 bool FullscreenController::IsFullscreenForBrowser() const { 54 bool FullscreenController::IsFullscreenForBrowser() const {
61 return window_->IsFullscreen() && !IsFullscreenCausedByTab(); 55 return GetWindow()->IsFullscreen() && !IsFullscreenCausedByTab();
62 } 56 }
63 57
64 void FullscreenController::ToggleBrowserFullscreenMode() { 58 void FullscreenController::ToggleBrowserFullscreenMode() {
65 extension_caused_fullscreen_ = GURL(); 59 extension_caused_fullscreen_ = GURL();
66 ToggleFullscreenModeInternal(BROWSER); 60 ToggleFullscreenModeInternal(BROWSER);
67 } 61 }
68 62
69 void FullscreenController::ToggleBrowserFullscreenWithToolbar() { 63 void FullscreenController::ToggleBrowserFullscreenWithToolbar() {
70 ToggleFullscreenModeInternal(BROWSER_WITH_TOOLBAR); 64 ToggleFullscreenModeInternal(BROWSER_WITH_TOOLBAR);
71 } 65 }
72 66
73 void FullscreenController::ToggleBrowserFullscreenModeWithExtension( 67 void FullscreenController::ToggleBrowserFullscreenModeWithExtension(
74 const GURL& extension_url) { 68 const GURL& extension_url) {
75 // |extension_caused_fullscreen_| will be reset if this causes fullscreen to 69 // |extension_caused_fullscreen_| will be reset if this causes fullscreen to
76 // exit. 70 // exit.
77 extension_caused_fullscreen_ = extension_url; 71 extension_caused_fullscreen_ = extension_url;
78 ToggleFullscreenModeInternal(BROWSER); 72 ToggleFullscreenModeInternal(BROWSER);
79 } 73 }
80 74
81 bool FullscreenController::IsWindowFullscreenForTabOrPending() const { 75 bool FullscreenController::IsWindowFullscreenForTabOrPending() const {
82 return fullscreened_tab_ != NULL; 76 return GetExclusiveAccessTab() != nullptr;
77 }
78
79 bool FullscreenController::IsExtensionFullscreenOrPending() const {
80 return !extension_caused_fullscreen_.is_empty();
81 }
82
83 bool FullscreenController::IsControllerInitiatedFullscreen() const {
84 return toggled_into_fullscreen_;
85 }
86
87 bool FullscreenController::IsUserAcceptedFullscreen() const {
88 return tab_fullscreen_accepted_;
83 } 89 }
84 90
85 bool FullscreenController::IsFullscreenForTabOrPending( 91 bool FullscreenController::IsFullscreenForTabOrPending(
86 const WebContents* web_contents) const { 92 const WebContents* web_contents) const {
87 if (web_contents == fullscreened_tab_) { 93 if (web_contents == GetExclusiveAccessTab()) {
88 DCHECK(web_contents == browser_->tab_strip_model()->GetActiveWebContents()); 94 DCHECK(web_contents ==
95 GetBrowser()->tab_strip_model()->GetActiveWebContents());
89 DCHECK(web_contents->GetCapturerCount() == 0); 96 DCHECK(web_contents->GetCapturerCount() == 0);
90 return true; 97 return true;
91 } 98 }
92 return IsFullscreenForCapturedTab(web_contents); 99 return IsFullscreenForCapturedTab(web_contents);
93 } 100 }
94 101
95 bool FullscreenController::IsFullscreenCausedByTab() const { 102 bool FullscreenController::IsFullscreenCausedByTab() const {
96 return state_prior_to_tab_fullscreen_ == STATE_NORMAL; 103 return state_prior_to_tab_fullscreen_ == STATE_NORMAL;
97 } 104 }
98 105
99 void FullscreenController::ToggleFullscreenModeForTab(WebContents* web_contents, 106 void FullscreenController::ToggleFullscreenModeForTab(WebContents* web_contents,
100 bool enter_fullscreen) { 107 bool enter_fullscreen) {
101 if (MaybeToggleFullscreenForCapturedTab(web_contents, enter_fullscreen)) { 108 if (MaybeToggleFullscreenForCapturedTab(web_contents, enter_fullscreen)) {
102 // During tab capture of fullscreen-within-tab views, the browser window 109 // During tab capture of fullscreen-within-tab views, the browser window
103 // fullscreen state is unchanged, so return now. 110 // fullscreen state is unchanged, so return now.
104 return; 111 return;
105 } 112 }
106 if (fullscreened_tab_) { 113 if (GetExclusiveAccessTab()) {
107 if (web_contents != fullscreened_tab_) 114 if (web_contents != GetExclusiveAccessTab())
108 return; 115 return;
109 } else if ( 116 } else if (web_contents !=
110 web_contents != browser_->tab_strip_model()->GetActiveWebContents()) { 117 GetBrowser()->tab_strip_model()->GetActiveWebContents()) {
111 return; 118 return;
112 } 119 }
113 if (IsWindowFullscreenForTabOrPending() == enter_fullscreen) 120 if (IsWindowFullscreenForTabOrPending() == enter_fullscreen)
114 return; 121 return;
115 122
116 #if defined(OS_WIN) 123 #if defined(OS_WIN)
117 // For now, avoid breaking when initiating full screen tab mode while in 124 // For now, avoid breaking when initiating full screen tab mode while in
118 // a metro snap. 125 // a metro snap.
119 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen 126 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen
120 // modes with metro snap. 127 // modes with metro snap.
121 if (IsInMetroSnapMode()) 128 if (IsInMetroSnapMode())
122 return; 129 return;
123 #endif 130 #endif
124 131
125 bool in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); 132 bool in_browser_or_tab_fullscreen_mode = GetWindow()->IsFullscreen();
126 133
127 if (enter_fullscreen) { 134 if (enter_fullscreen) {
128 SetFullscreenedTab(web_contents); 135 SetTabWithExclusiveAccess(web_contents);
129 if (!in_browser_or_tab_fullscreen_mode) { 136 if (!in_browser_or_tab_fullscreen_mode) {
130 // Normal -> Tab Fullscreen. 137 // Normal -> Tab Fullscreen.
131 state_prior_to_tab_fullscreen_ = STATE_NORMAL; 138 state_prior_to_tab_fullscreen_ = STATE_NORMAL;
132 ToggleFullscreenModeInternal(TAB); 139 ToggleFullscreenModeInternal(TAB);
133 } else { 140 } else {
134 if (window_->IsFullscreenWithToolbar()) { 141 if (GetWindow()->IsFullscreenWithToolbar()) {
135 // Browser Fullscreen with Toolbar -> Tab Fullscreen (no toolbar). 142 // Browser Fullscreen with Toolbar -> Tab Fullscreen (no toolbar).
136 window_->UpdateFullscreenWithToolbar(false); 143 GetWindow()->UpdateFullscreenWithToolbar(false);
137 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR; 144 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR;
138 } else { 145 } else {
139 // Browser Fullscreen without Toolbar -> Tab Fullscreen. 146 // Browser Fullscreen without Toolbar -> Tab Fullscreen.
140 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_TOOLBAR; 147 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_TOOLBAR;
141 } 148 }
142 149
143 // We need to update the fullscreen exit bubble, e.g., going from browser 150 // We need to update the fullscreen exit bubble, e.g., going from browser
144 // fullscreen to tab fullscreen will need to show different content. 151 // fullscreen to tab fullscreen will need to show different content.
145 const GURL& url = web_contents->GetURL(); 152 const GURL& url = web_contents->GetURL();
146 if (!tab_fullscreen_accepted_) { 153 if (!tab_fullscreen_accepted_) {
147 tab_fullscreen_accepted_ = 154 tab_fullscreen_accepted_ =
148 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; 155 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW;
149 } 156 }
150 UpdateFullscreenExitBubbleContent(); 157 GetManager()->UpdateExclusiveAccessExitBubbleContent();
151 158
152 // This is only a change between Browser and Tab fullscreen. We generate 159 // This is only a change between Browser and Tab fullscreen. We generate
153 // a fullscreen notification now because there is no window change. 160 // a fullscreen notification now because there is no window change.
154 PostFullscreenChangeNotification(true); 161 PostFullscreenChangeNotification(true);
155 } 162 }
156 } else { 163 } else {
157 if (in_browser_or_tab_fullscreen_mode) { 164 if (in_browser_or_tab_fullscreen_mode) {
158 if (IsFullscreenCausedByTab()) { 165 if (IsFullscreenCausedByTab()) {
159 // Tab Fullscreen -> Normal. 166 // Tab Fullscreen -> Normal.
160 ToggleFullscreenModeInternal(TAB); 167 ToggleFullscreenModeInternal(TAB);
161 } else { 168 } else {
162 // Tab Fullscreen -> Browser Fullscreen (with or without toolbar). 169 // Tab Fullscreen -> Browser Fullscreen (with or without toolbar).
163 if (state_prior_to_tab_fullscreen_ == 170 if (state_prior_to_tab_fullscreen_ ==
164 STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR) { 171 STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR) {
165 // Tab Fullscreen (no toolbar) -> Browser Fullscreen with Toolbar. 172 // Tab Fullscreen (no toolbar) -> Browser Fullscreen with Toolbar.
166 window_->UpdateFullscreenWithToolbar(true); 173 GetWindow()->UpdateFullscreenWithToolbar(true);
167 } 174 }
168 175
169 #if defined(OS_MACOSX) 176 #if defined(OS_MACOSX)
170 // Clear the bubble URL, which forces the Mac UI to redraw. 177 // Clear the bubble URL, which forces the Mac UI to redraw.
171 UpdateFullscreenExitBubbleContent(); 178 GetManager()->UpdateExclusiveAccessExitBubbleContent();
172 #endif // defined(OS_MACOSX) 179 #endif // defined(OS_MACOSX)
173 180
174 // If currently there is a tab in "tab fullscreen" mode and fullscreen 181 // If currently there is a tab in "tab fullscreen" mode and fullscreen
175 // was not caused by it (i.e., previously it was in "browser fullscreen" 182 // was not caused by it (i.e., previously it was in "browser fullscreen"
176 // mode), we need to switch back to "browser fullscreen" mode. In this 183 // mode), we need to switch back to "browser fullscreen" mode. In this
177 // case, all we have to do is notifying the tab that it has exited "tab 184 // case, all we have to do is notifying the tab that it has exited "tab
178 // fullscreen" mode. 185 // fullscreen" mode.
179 NotifyTabOfExitIfNecessary(); 186 NotifyTabOfExclusiveAccessChange();
180 187
181 // This is only a change between Browser and Tab fullscreen. We generate 188 // This is only a change between Browser and Tab fullscreen. We generate
182 // a fullscreen notification now because there is no window change. 189 // a fullscreen notification now because there is no window change.
183 PostFullscreenChangeNotification(true); 190 PostFullscreenChangeNotification(true);
184 } 191 }
185 } 192 }
186 } 193 }
187 } 194 }
188 195
189 bool FullscreenController::IsInMetroSnapMode() { 196 bool FullscreenController::IsInMetroSnapMode() {
190 #if defined(OS_WIN) 197 #if defined(OS_WIN)
191 return window_->IsInMetroSnapMode(); 198 return GetWindow()->IsInMetroSnapMode();
192 #else 199 #else
193 return false; 200 return false;
194 #endif 201 #endif
195 } 202 }
196 203
197 #if defined(OS_WIN) 204 #if defined(OS_WIN)
198 void FullscreenController::SetMetroSnapMode(bool enable) { 205 void FullscreenController::SetMetroSnapMode(bool enable) {
199 reentrant_window_state_change_call_check_ = false; 206 reentrant_window_state_change_call_check_ = false;
200 207
201 toggled_into_fullscreen_ = false; 208 toggled_into_fullscreen_ = false;
202 window_->SetMetroSnapMode(enable); 209 GetWindow()->SetMetroSnapMode(enable);
203 210
204 // FullscreenController unit tests for metro snap assume that on Windows calls 211 // FullscreenController unit tests for metro snap assume that on Windows calls
205 // to WindowFullscreenStateChanged are reentrant. If that assumption is 212 // to WindowFullscreenStateChanged are reentrant. If that assumption is
206 // invalidated, the tests must be updated to maintain coverage. 213 // invalidated, the tests must be updated to maintain coverage.
207 CHECK(reentrant_window_state_change_call_check_); 214 CHECK(reentrant_window_state_change_call_check_);
208 } 215 }
209 #endif // defined(OS_WIN) 216 #endif // defined(OS_WIN)
210 217
211 bool FullscreenController::IsMouseLockRequested() const {
212 return mouse_lock_state_ == MOUSELOCK_REQUESTED;
213 }
214
215 bool FullscreenController::IsMouseLocked() const {
216 return mouse_lock_state_ == MOUSELOCK_ACCEPTED ||
217 mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY;
218 }
219
220 void FullscreenController::RequestToLockMouse(WebContents* web_contents,
221 bool user_gesture,
222 bool last_unlocked_by_target) {
223 DCHECK(!IsMouseLocked());
224 NotifyMouseLockChange();
225
226 // Must have a user gesture to prevent misbehaving sites from constantly
227 // re-locking the mouse. Exceptions are when the page has unlocked
228 // (i.e. not the user), or if we're in tab fullscreen (user gesture required
229 // for that)
230 if (!last_unlocked_by_target && !user_gesture &&
231 !IsFullscreenForTabOrPending(web_contents)) {
232 web_contents->GotResponseToLockMouseRequest(false);
233 return;
234 }
235 SetMouseLockTab(web_contents);
236 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType();
237
238 switch (GetMouseLockSetting(web_contents->GetURL())) {
239 case CONTENT_SETTING_ALLOW:
240 // If bubble already displaying buttons we must not lock the mouse yet,
241 // or it would prevent pressing those buttons. Instead, merge the request.
242 if (!IsPrivilegedFullscreenForTab() &&
243 exclusive_access_bubble::ShowButtonsForType(bubble_type)) {
244 mouse_lock_state_ = MOUSELOCK_REQUESTED;
245 } else {
246 // Lock mouse.
247 if (web_contents->GotResponseToLockMouseRequest(true)) {
248 if (last_unlocked_by_target) {
249 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY;
250 } else {
251 mouse_lock_state_ = MOUSELOCK_ACCEPTED;
252 }
253 } else {
254 SetMouseLockTab(NULL);
255 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
256 }
257 }
258 break;
259 case CONTENT_SETTING_BLOCK:
260 web_contents->GotResponseToLockMouseRequest(false);
261 SetMouseLockTab(NULL);
262 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
263 break;
264 case CONTENT_SETTING_ASK:
265 mouse_lock_state_ = MOUSELOCK_REQUESTED;
266 break;
267 default:
268 NOTREACHED();
269 }
270 UpdateFullscreenExitBubbleContent();
271 }
272
273 void FullscreenController::OnTabDeactivated(WebContents* web_contents) {
274 if (web_contents == fullscreened_tab_ || web_contents == mouse_lock_tab_)
275 ExitTabFullscreenOrMouseLockIfNecessary();
276 }
277
278 void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) { 218 void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) {
279 if (!IsFullscreenForCapturedTab(old_contents)) 219 if (!IsFullscreenForCapturedTab(old_contents))
280 return; 220 return;
281 221
282 // A fullscreen-within-tab view undergoing screen capture has been detached 222 // A fullscreen-within-tab view undergoing screen capture has been detached
283 // and is no longer visible to the user. Set it to exactly the WebContents' 223 // and is no longer visible to the user. Set it to exactly the WebContents'
284 // preferred size. See 'FullscreenWithinTab Note'. 224 // preferred size. See 'FullscreenWithinTab Note'.
285 // 225 //
286 // When the user later selects the tab to show |old_contents| again, UI code 226 // When the user later selects the tab to show |old_contents| again, UI code
287 // elsewhere (e.g., views::WebView) will resize the view to fit within the 227 // elsewhere (e.g., views::WebView) will resize the view to fit within the
(...skipping 17 matching lines...) Expand all
305 if (current_fs_view) 245 if (current_fs_view)
306 current_fs_view->SetSize(old_contents->GetPreferredSize()); 246 current_fs_view->SetSize(old_contents->GetPreferredSize());
307 ResizeWebContents(old_contents, old_contents->GetPreferredSize()); 247 ResizeWebContents(old_contents, old_contents->GetPreferredSize());
308 } 248 }
309 249
310 void FullscreenController::OnTabClosing(WebContents* web_contents) { 250 void FullscreenController::OnTabClosing(WebContents* web_contents) {
311 if (IsFullscreenForCapturedTab(web_contents)) { 251 if (IsFullscreenForCapturedTab(web_contents)) {
312 RenderViewHost* const rvh = web_contents->GetRenderViewHost(); 252 RenderViewHost* const rvh = web_contents->GetRenderViewHost();
313 if (rvh) 253 if (rvh)
314 rvh->ExitFullscreen(); 254 rvh->ExitFullscreen();
315 } else if (web_contents == fullscreened_tab_ || 255 } else {
316 web_contents == mouse_lock_tab_) { 256 ExclusiveAccessControllerBase::OnTabClosing(web_contents);
317 ExitTabFullscreenOrMouseLockIfNecessary();
318 // The call to exit fullscreen may result in asynchronous notification of
319 // fullscreen state change (e.g., on Linux). We don't want to rely on it
320 // to call NotifyTabOfExitIfNecessary(), because at that point
321 // |fullscreened_tab_| may not be valid. Instead, we call it here to clean
322 // up tab fullscreen related state.
323 NotifyTabOfExitIfNecessary();
324 } 257 }
325 } 258 }
326 259
327 void FullscreenController::WindowFullscreenStateChanged() { 260 void FullscreenController::WindowFullscreenStateChanged() {
328 reentrant_window_state_change_call_check_ = true; 261 reentrant_window_state_change_call_check_ = true;
329 262
330 bool exiting_fullscreen = !window_->IsFullscreen(); 263 bool exiting_fullscreen = !GetWindow()->IsFullscreen();
331 264
332 PostFullscreenChangeNotification(!exiting_fullscreen); 265 PostFullscreenChangeNotification(!exiting_fullscreen);
333 if (exiting_fullscreen) { 266 if (exiting_fullscreen) {
334 toggled_into_fullscreen_ = false; 267 toggled_into_fullscreen_ = false;
335 extension_caused_fullscreen_ = GURL(); 268 extension_caused_fullscreen_ = GURL();
336 NotifyTabOfExitIfNecessary(); 269 NotifyTabOfExclusiveAccessChange();
337 } 270 }
338 if (exiting_fullscreen) { 271 if (exiting_fullscreen) {
339 window_->GetDownloadShelf()->Unhide(); 272 GetWindow()->GetDownloadShelf()->Unhide();
340 } else { 273 } else {
341 window_->GetDownloadShelf()->Hide(); 274 GetWindow()->GetDownloadShelf()->Hide();
342 if (window_->GetStatusBubble()) 275 if (GetWindow()->GetStatusBubble())
343 window_->GetStatusBubble()->Hide(); 276 GetWindow()->GetStatusBubble()->Hide();
344 } 277 }
345 } 278 }
346 279
347 bool FullscreenController::HandleUserPressedEscape() { 280 bool FullscreenController::HandleUserPressedEscape() {
348 WebContents* const active_web_contents = 281 WebContents* const active_web_contents =
349 browser_->tab_strip_model()->GetActiveWebContents(); 282 GetBrowser()->tab_strip_model()->GetActiveWebContents();
350 if (IsFullscreenForCapturedTab(active_web_contents)) { 283 if (IsFullscreenForCapturedTab(active_web_contents)) {
351 RenderViewHost* const rvh = active_web_contents->GetRenderViewHost(); 284 RenderViewHost* const rvh = active_web_contents->GetRenderViewHost();
352 if (rvh) 285 if (rvh)
353 rvh->ExitFullscreen(); 286 rvh->ExitFullscreen();
354 return true; 287 return true;
355 } else if (IsWindowFullscreenForTabOrPending() || 288 } else if (IsWindowFullscreenForTabOrPending()) {
356 IsMouseLocked() || IsMouseLockRequested()) { 289 ExitExclusiveAccessIfNecessary();
357 ExitTabFullscreenOrMouseLockIfNecessary();
358 return true; 290 return true;
359 } 291 }
360 292
361 return false; 293 return false;
362 } 294 }
363 295
364 void FullscreenController::ExitTabOrBrowserFullscreenToPreviousState() { 296 void FullscreenController::ExitExclusiveAccessToPreviousState() {
365 if (IsWindowFullscreenForTabOrPending()) 297 if (IsWindowFullscreenForTabOrPending())
366 ExitTabFullscreenOrMouseLockIfNecessary(); 298 ToggleFullscreenModeForTab(GetExclusiveAccessTab(), false);
367 else if (IsFullscreenForBrowser()) 299 else if (IsFullscreenForBrowser())
368 ExitFullscreenModeInternal(); 300 ExitFullscreenModeInternal();
369 } 301 }
370 302
371 void FullscreenController::OnAcceptFullscreenPermission() { 303 bool FullscreenController::OnAcceptExclusiveAccessPermission() {
372 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); 304 ExclusiveAccessBubbleType bubble_type =
373 bool mouse_lock = false; 305 GetManager()->GetExclusiveAccessExitBubbleType();
374 bool fullscreen = false; 306 bool fullscreen = false;
375 exclusive_access_bubble::PermissionRequestedByType(bubble_type, &fullscreen, 307 exclusive_access_bubble::PermissionRequestedByType(bubble_type, &fullscreen,
376 &mouse_lock); 308 nullptr);
377 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); 309 DCHECK(!(fullscreen && tab_fullscreen_accepted_));
378 DCHECK(!(mouse_lock && IsMouseLocked()));
379 310
380 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); 311 if (fullscreen && !tab_fullscreen_accepted_) {
312 DCHECK(GetExclusiveAccessTab());
381 313
382 GURL url = GetFullscreenExitBubbleURL(); 314 HostContentSettingsMap* settings_map =
383 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); 315 GetProfile()->GetHostContentSettingsMap();
384 316
385 if (mouse_lock && !IsMouseLocked()) { 317 GURL url = GetExclusiveAccessBubbleURL();
386 DCHECK(IsMouseLockRequested()); 318 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url);
387 // TODO(markusheintz): We should allow patterns for all possible URLs here. 319
388 if (pattern.IsValid()) { 320 if (pattern.IsValid()) {
389 settings_map->SetContentSetting( 321 settings_map->SetContentSetting(
390 pattern, ContentSettingsPattern::Wildcard(), 322 pattern, ContentSettingsPattern::Wildcard(),
391 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(),
392 CONTENT_SETTING_ALLOW);
393 }
394
395 if (mouse_lock_tab_ &&
396 mouse_lock_tab_->GotResponseToLockMouseRequest(true)) {
397 mouse_lock_state_ = MOUSELOCK_ACCEPTED;
398 } else {
399 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
400 SetMouseLockTab(NULL);
401 }
402 NotifyMouseLockChange();
403 }
404
405 if (fullscreen && !tab_fullscreen_accepted_) {
406 DCHECK(fullscreened_tab_);
407 if (pattern.IsValid()) {
408 settings_map->SetContentSetting(
409 pattern, ContentSettingsPattern::Wildcard(),
410 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(), 323 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(),
411 CONTENT_SETTING_ALLOW); 324 CONTENT_SETTING_ALLOW);
412 } 325 }
413 tab_fullscreen_accepted_ = true; 326 tab_fullscreen_accepted_ = true;
327 return true;
414 } 328 }
415 UpdateFullscreenExitBubbleContent(); 329
330 return false;
416 } 331 }
417 332
418 void FullscreenController::OnDenyFullscreenPermission() { 333 bool FullscreenController::OnDenyExclusiveAccessPermission() {
419 if (!fullscreened_tab_ && !mouse_lock_tab_) 334 if (IsWindowFullscreenForTabOrPending()) {
420 return; 335 ExitExclusiveAccessIfNecessary();
421 336 return true;
422 if (IsMouseLockRequested()) {
423 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
424 if (mouse_lock_tab_)
425 mouse_lock_tab_->GotResponseToLockMouseRequest(false);
426 SetMouseLockTab(NULL);
427 NotifyMouseLockChange();
428
429 // UpdateFullscreenExitBubbleContent() must be called, but to avoid
430 // duplicate calls we do so only if not adjusting the fullscreen state
431 // below, which also calls UpdateFullscreenExitBubbleContent().
432 if (!IsWindowFullscreenForTabOrPending())
433 UpdateFullscreenExitBubbleContent();
434 } 337 }
435 338
436 if (IsWindowFullscreenForTabOrPending()) 339 return false;
437 ExitTabFullscreenOrMouseLockIfNecessary();
438 } 340 }
439 341
440 void FullscreenController::LostMouseLock() { 342 GURL FullscreenController::GetURLForExclusiveAccessBubble() const {
441 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; 343 if (GetExclusiveAccessTab())
442 SetMouseLockTab(NULL); 344 return GetExclusiveAccessTab()->GetURL();
443 NotifyMouseLockChange();
444 UpdateFullscreenExitBubbleContent();
445 }
446
447 void FullscreenController::Observe(int type,
448 const content::NotificationSource& source,
449 const content::NotificationDetails& details) {
450 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type);
451 if (content::Details<content::LoadCommittedDetails>(details)->
452 is_navigation_to_different_page())
453 ExitTabFullscreenOrMouseLockIfNecessary();
454 }
455
456 GURL FullscreenController::GetFullscreenExitBubbleURL() const {
457 if (fullscreened_tab_)
458 return fullscreened_tab_->GetURL();
459 if (mouse_lock_tab_)
460 return mouse_lock_tab_->GetURL();
461 return extension_caused_fullscreen_; 345 return extension_caused_fullscreen_;
462 } 346 }
463 347
464 ExclusiveAccessBubbleType FullscreenController::GetExclusiveAccessBubbleType() 348 void FullscreenController::ExitExclusiveAccessIfNecessary() {
465 const { 349 if (IsWindowFullscreenForTabOrPending())
466 // In kiosk and exclusive app mode we always want to be fullscreen and do not 350 ToggleFullscreenModeForTab(GetExclusiveAccessTab(), false);
467 // want to show exit instructions for browser mode fullscreen. 351 else
468 bool app_mode = false; 352 NotifyTabOfExclusiveAccessChange();
469 #if !defined(OS_MACOSX) // App mode (kiosk) is not available on Mac yet.
470 app_mode = chrome::IsRunningInAppMode();
471 #endif
472
473 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY)
474 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE;
475
476 if (!fullscreened_tab_) {
477 if (IsMouseLocked())
478 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION;
479 if (IsMouseLockRequested())
480 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS;
481 if (!extension_caused_fullscreen_.is_empty())
482 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION;
483 if (toggled_into_fullscreen_ && !app_mode)
484 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION;
485 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE;
486 }
487
488 if (tab_fullscreen_accepted_) {
489 if (IsPrivilegedFullscreenForTab())
490 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE;
491 if (IsMouseLocked())
492 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION;
493 if (IsMouseLockRequested())
494 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS;
495 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION;
496 }
497
498 if (IsMouseLockRequested())
499 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS;
500 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS;
501 }
502
503 void FullscreenController::UpdateNotificationRegistrations() {
504 if (fullscreened_tab_ && mouse_lock_tab_)
505 DCHECK(fullscreened_tab_ == mouse_lock_tab_);
506
507 WebContents* tab = fullscreened_tab_ ? fullscreened_tab_ : mouse_lock_tab_;
508
509 if (tab && registrar_.IsEmpty()) {
510 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
511 content::Source<content::NavigationController>(&tab->GetController()));
512 } else if (!tab && !registrar_.IsEmpty()) {
513 registrar_.RemoveAll();
514 }
515 } 353 }
516 354
517 void FullscreenController::PostFullscreenChangeNotification( 355 void FullscreenController::PostFullscreenChangeNotification(
518 bool is_fullscreen) { 356 bool is_fullscreen) {
519 base::MessageLoop::current()->PostTask( 357 base::MessageLoop::current()->PostTask(
520 FROM_HERE, 358 FROM_HERE,
521 base::Bind(&FullscreenController::NotifyFullscreenChange, 359 base::Bind(&FullscreenController::NotifyFullscreenChange,
522 ptr_factory_.GetWeakPtr(), 360 ptr_factory_.GetWeakPtr(),
523 is_fullscreen)); 361 is_fullscreen));
524 } 362 }
525 363
526 void FullscreenController::NotifyFullscreenChange(bool is_fullscreen) { 364 void FullscreenController::NotifyFullscreenChange(bool is_fullscreen) {
527 content::NotificationService::current()->Notify( 365 content::NotificationService::current()->Notify(
528 chrome::NOTIFICATION_FULLSCREEN_CHANGED, 366 chrome::NOTIFICATION_FULLSCREEN_CHANGED,
529 content::Source<FullscreenController>(this), 367 content::Source<FullscreenController>(this),
530 content::Details<bool>(&is_fullscreen)); 368 content::Details<bool>(&is_fullscreen));
531 } 369 }
532 370
533 void FullscreenController::NotifyTabOfExitIfNecessary() { 371 void FullscreenController::NotifyTabOfExclusiveAccessChange() {
534 if (fullscreened_tab_) { 372 if (GetExclusiveAccessTab()) {
535 RenderViewHost* rvh = fullscreened_tab_->GetRenderViewHost(); 373 RenderViewHost* rvh = GetExclusiveAccessTab()->GetRenderViewHost();
536 SetFullscreenedTab(NULL); 374 SetTabWithExclusiveAccess(nullptr);
537 state_prior_to_tab_fullscreen_ = STATE_INVALID; 375 state_prior_to_tab_fullscreen_ = STATE_INVALID;
538 tab_fullscreen_accepted_ = false; 376 tab_fullscreen_accepted_ = false;
539 if (rvh) 377 if (rvh)
540 rvh->ExitFullscreen(); 378 rvh->ExitFullscreen();
379 GetManager()->UpdateExclusiveAccessExitBubbleContent();
541 } 380 }
542
543 if (mouse_lock_tab_) {
544 if (IsMouseLockRequested()) {
545 mouse_lock_tab_->GotResponseToLockMouseRequest(false);
546 NotifyMouseLockChange();
547 } else {
548 UnlockMouse();
549 }
550 SetMouseLockTab(NULL);
551 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
552 }
553
554 UpdateFullscreenExitBubbleContent();
555 }
556
557 void FullscreenController::NotifyMouseLockChange() {
558 content::NotificationService::current()->Notify(
559 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
560 content::Source<FullscreenController>(this),
561 content::NotificationService::NoDetails());
562 } 381 }
563 382
564 void FullscreenController::ToggleFullscreenModeInternal( 383 void FullscreenController::ToggleFullscreenModeInternal(
565 FullscreenInternalOption option) { 384 FullscreenInternalOption option) {
566 #if defined(OS_WIN) 385 #if defined(OS_WIN)
567 // When in Metro snap mode, toggling in and out of fullscreen is prevented. 386 // When in Metro snap mode, toggling in and out of fullscreen is prevented.
568 if (IsInMetroSnapMode()) 387 if (IsInMetroSnapMode())
569 return; 388 return;
570 #endif 389 #endif
571 390
572 bool enter_fullscreen = !window_->IsFullscreen(); 391 bool enter_fullscreen = !GetWindow()->IsFullscreen();
573 392
574 // When a Mac user requests a toggle they may be toggling between 393 // When a Mac user requests a toggle they may be toggling between
575 // FullscreenWithoutChrome and FullscreenWithToolbar. 394 // FullscreenWithoutChrome and FullscreenWithToolbar.
576 if (window_->IsFullscreen() && 395 if (GetWindow()->IsFullscreen() && !IsWindowFullscreenForTabOrPending() &&
577 !IsWindowFullscreenForTabOrPending() && 396 GetWindow()->SupportsFullscreenWithToolbar()) {
578 window_->SupportsFullscreenWithToolbar()) {
579 if (option == BROWSER_WITH_TOOLBAR) { 397 if (option == BROWSER_WITH_TOOLBAR) {
580 enter_fullscreen = 398 enter_fullscreen =
581 enter_fullscreen || !window_->IsFullscreenWithToolbar(); 399 enter_fullscreen || !GetWindow()->IsFullscreenWithToolbar();
582 } else { 400 } else {
583 enter_fullscreen = enter_fullscreen || window_->IsFullscreenWithToolbar(); 401 enter_fullscreen =
402 enter_fullscreen || GetWindow()->IsFullscreenWithToolbar();
584 } 403 }
585 } 404 }
586 405
587 // In kiosk mode, we always want to be fullscreen. When the browser first 406 // In kiosk mode, we always want to be fullscreen. When the browser first
588 // starts we're not yet fullscreen, so let the initial toggle go through. 407 // starts we're not yet fullscreen, so let the initial toggle go through.
589 if (chrome::IsRunningInAppMode() && window_->IsFullscreen()) 408 if (chrome::IsRunningInAppMode() && GetWindow()->IsFullscreen())
590 return; 409 return;
591 410
592 #if !defined(OS_MACOSX) 411 #if !defined(OS_MACOSX)
593 // Do not enter fullscreen mode if disallowed by pref. This prevents the user 412 // Do not enter fullscreen mode if disallowed by pref. This prevents the user
594 // from manually entering fullscreen mode and also disables kiosk mode on 413 // from manually entering fullscreen mode and also disables kiosk mode on
595 // desktop platforms. 414 // desktop platforms.
596 if (enter_fullscreen && 415 if (enter_fullscreen &&
597 !profile_->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) { 416 !GetProfile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) {
598 return; 417 return;
599 } 418 }
600 #endif 419 #endif
601 420
602 if (enter_fullscreen) 421 if (enter_fullscreen)
603 EnterFullscreenModeInternal(option); 422 EnterFullscreenModeInternal(option);
604 else 423 else
605 ExitFullscreenModeInternal(); 424 ExitFullscreenModeInternal();
606 } 425 }
607 426
608 void FullscreenController::EnterFullscreenModeInternal( 427 void FullscreenController::EnterFullscreenModeInternal(
609 FullscreenInternalOption option) { 428 FullscreenInternalOption option) {
610 toggled_into_fullscreen_ = true; 429 toggled_into_fullscreen_ = true;
611 GURL url; 430 GURL url;
612 if (option == TAB) { 431 if (option == TAB) {
613 url = browser_->tab_strip_model()->GetActiveWebContents()->GetURL(); 432 url = GetBrowser()->tab_strip_model()->GetActiveWebContents()->GetURL();
614 tab_fullscreen_accepted_ = 433 tab_fullscreen_accepted_ =
615 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; 434 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW;
616 } else { 435 } else {
617 if (!extension_caused_fullscreen_.is_empty()) 436 if (!extension_caused_fullscreen_.is_empty())
618 url = extension_caused_fullscreen_; 437 url = extension_caused_fullscreen_;
619 } 438 }
620 439
621 if (option == BROWSER) 440 if (option == BROWSER)
622 content::RecordAction(UserMetricsAction("ToggleFullscreen")); 441 content::RecordAction(UserMetricsAction("ToggleFullscreen"));
623 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions 442 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions
624 // from tab fullscreen out to browser with toolbar. 443 // from tab fullscreen out to browser with toolbar.
625 444
626 window_->EnterFullscreen(url, GetExclusiveAccessBubbleType(), 445 GetWindow()->EnterFullscreen(url,
627 option == BROWSER_WITH_TOOLBAR); 446 GetManager()->GetExclusiveAccessExitBubbleType(),
447 option == BROWSER_WITH_TOOLBAR);
628 448
629 UpdateFullscreenExitBubbleContent(); 449 GetManager()->UpdateExclusiveAccessExitBubbleContent();
630 450
631 // Once the window has become fullscreen it'll call back to 451 // Once the window has become fullscreen it'll call back to
632 // WindowFullscreenStateChanged(). We don't do this immediately as 452 // WindowFullscreenStateChanged(). We don't do this immediately as
633 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let 453 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let
634 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. 454 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate.
635 } 455 }
636 456
637 void FullscreenController::ExitFullscreenModeInternal() { 457 void FullscreenController::ExitFullscreenModeInternal() {
638 toggled_into_fullscreen_ = false; 458 toggled_into_fullscreen_ = false;
639 #if defined(OS_MACOSX) 459 #if defined(OS_MACOSX)
640 // Mac windows report a state change instantly, and so we must also clear 460 // Mac windows report a state change instantly, and so we must also clear
641 // state_prior_to_tab_fullscreen_ to match them else other logic using 461 // state_prior_to_tab_fullscreen_ to match them else other logic using
642 // state_prior_to_tab_fullscreen_ will be incorrect. 462 // state_prior_to_tab_fullscreen_ will be incorrect.
643 NotifyTabOfExitIfNecessary(); 463 NotifyTabOfExclusiveAccessChange();
644 #endif 464 #endif
645 window_->ExitFullscreen(); 465 GetWindow()->ExitFullscreen();
646 extension_caused_fullscreen_ = GURL(); 466 extension_caused_fullscreen_ = GURL();
647 467
648 UpdateFullscreenExitBubbleContent(); 468 GetManager()->UpdateExclusiveAccessExitBubbleContent();
649 }
650
651 void FullscreenController::SetFullscreenedTab(WebContents* tab) {
652 fullscreened_tab_ = tab;
653 UpdateNotificationRegistrations();
654 }
655
656 void FullscreenController::SetMouseLockTab(WebContents* tab) {
657 mouse_lock_tab_ = tab;
658 UpdateNotificationRegistrations();
659 }
660
661 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() {
662 if (IsWindowFullscreenForTabOrPending())
663 ToggleFullscreenModeForTab(fullscreened_tab_, false);
664 else
665 NotifyTabOfExitIfNecessary();
666 }
667
668 void FullscreenController::UpdateFullscreenExitBubbleContent() {
669 GURL url = GetFullscreenExitBubbleURL();
670 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType();
671
672 // If bubble displays buttons, unlock mouse to allow pressing them.
673 if (exclusive_access_bubble::ShowButtonsForType(bubble_type) &&
674 IsMouseLocked())
675 UnlockMouse();
676
677 window_->UpdateFullscreenExitBubbleContent(url, bubble_type);
678 } 469 }
679 470
680 ContentSetting 471 ContentSetting
681 FullscreenController::GetFullscreenSetting(const GURL& url) const { 472 FullscreenController::GetFullscreenSetting(const GURL& url) const {
682 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) 473 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile())
683 return CONTENT_SETTING_ALLOW; 474 return CONTENT_SETTING_ALLOW;
684 475
685 return profile_->GetHostContentSettingsMap()->GetContentSetting(url, url, 476 return GetProfile()->GetHostContentSettingsMap()->GetContentSetting(
686 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); 477 url, url, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string());
687 }
688
689 ContentSetting
690 FullscreenController::GetMouseLockSetting(const GURL& url) const {
691 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile())
692 return CONTENT_SETTING_ALLOW;
693
694 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap();
695 return settings_map->GetContentSetting(url, url,
696 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string());
697 } 478 }
698 479
699 bool FullscreenController::IsPrivilegedFullscreenForTab() const { 480 bool FullscreenController::IsPrivilegedFullscreenForTab() const {
700 const bool embedded_widget_present = 481 const bool embedded_widget_present =
701 fullscreened_tab_ && 482 GetExclusiveAccessTab() &&
702 fullscreened_tab_->GetFullscreenRenderWidgetHostView(); 483 GetExclusiveAccessTab()->GetFullscreenRenderWidgetHostView();
703 return embedded_widget_present || is_privileged_fullscreen_for_testing_; 484 return embedded_widget_present || is_privileged_fullscreen_for_testing_;
704 } 485 }
705 486
706 void FullscreenController::SetPrivilegedFullscreenForTesting( 487 void FullscreenController::SetPrivilegedFullscreenForTesting(
707 bool is_privileged) { 488 bool is_privileged) {
708 is_privileged_fullscreen_for_testing_ = is_privileged; 489 is_privileged_fullscreen_for_testing_ = is_privileged;
709 } 490 }
710 491
711 bool FullscreenController::MaybeToggleFullscreenForCapturedTab( 492 bool FullscreenController::MaybeToggleFullscreenForCapturedTab(
712 WebContents* web_contents, bool enter_fullscreen) { 493 WebContents* web_contents, bool enter_fullscreen) {
713 if (enter_fullscreen) { 494 if (enter_fullscreen) {
714 if (web_contents->GetCapturerCount() > 0) { 495 if (web_contents->GetCapturerCount() > 0) {
715 FullscreenWithinTabHelper::CreateForWebContents(web_contents); 496 FullscreenWithinTabHelper::CreateForWebContents(web_contents);
716 FullscreenWithinTabHelper::FromWebContents(web_contents)-> 497 FullscreenWithinTabHelper::FromWebContents(web_contents)->
717 SetIsFullscreenForCapturedTab(true); 498 SetIsFullscreenForCapturedTab(true);
718 return true; 499 return true;
719 } 500 }
720 } else { 501 } else {
721 if (IsFullscreenForCapturedTab(web_contents)) { 502 if (IsFullscreenForCapturedTab(web_contents)) {
722 FullscreenWithinTabHelper::RemoveForWebContents(web_contents); 503 FullscreenWithinTabHelper::RemoveForWebContents(web_contents);
723 return true; 504 return true;
724 } 505 }
725 } 506 }
726 507
727 return false; 508 return false;
728 } 509 }
729 510
730 bool FullscreenController::IsFullscreenForCapturedTab( 511 bool FullscreenController::IsFullscreenForCapturedTab(
731 const WebContents* web_contents) const { 512 const WebContents* web_contents) const {
732 // Note: On Mac, some of the OnTabXXX() methods get called with a NULL value 513 // Note: On Mac, some of the OnTabXXX() methods get called with a nullptr
514 // value
733 // for web_contents. Check for that here. 515 // for web_contents. Check for that here.
734 const FullscreenWithinTabHelper* const helper = web_contents ? 516 const FullscreenWithinTabHelper* const helper =
735 FullscreenWithinTabHelper::FromWebContents(web_contents) : NULL; 517 web_contents ? FullscreenWithinTabHelper::FromWebContents(web_contents)
518 : nullptr;
736 if (helper && helper->is_fullscreen_for_captured_tab()) { 519 if (helper && helper->is_fullscreen_for_captured_tab()) {
737 DCHECK_NE(fullscreened_tab_, web_contents); 520 DCHECK_NE(GetExclusiveAccessTab(), web_contents);
738 return true; 521 return true;
739 } 522 }
740 return false; 523 return false;
741 } 524 }
742 525
743 void FullscreenController::UnlockMouse() {
744 if (!mouse_lock_tab_)
745 return;
746 content::RenderWidgetHostView* mouse_lock_view =
747 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ?
748 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL;
749 if (!mouse_lock_view) {
750 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost();
751 if (rvh)
752 mouse_lock_view = rvh->GetView();
753 }
754 if (mouse_lock_view)
755 mouse_lock_view->UnlockMouse();
756 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698