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

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

Issue 877413004: Refactor away the Browser* dependency in exclusive_access (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove Browser* dependency from ExclusiveAccess* in Cocoa. Created 5 years, 10 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"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/download/download_shelf.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
15 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
16 #include "chrome/browser/ui/exclusive_access/fullscreen_within_tab_helper.h" 15 #include "chrome/browser/ui/exclusive_access/fullscreen_within_tab_helper.h"
17 #include "chrome/browser/ui/status_bubble.h" 16 #include "chrome/browser/ui/status_bubble.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/browser/ui/web_contents_sizer.h" 18 #include "chrome/browser/ui/web_contents_sizer.h"
20 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
21 #include "components/content_settings/core/browser/host_content_settings_map.h" 20 #include "components/content_settings/core/browser/host_content_settings_map.h"
22 #include "content/public/browser/navigation_details.h" 21 #include "content/public/browser/navigation_details.h"
23 #include "content/public/browser/navigation_entry.h" 22 #include "content/public/browser/navigation_entry.h"
24 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/render_widget_host_view.h" 25 #include "content/public/browser/render_widget_host_view.h"
27 #include "content/public/browser/user_metrics.h" 26 #include "content/public/browser/user_metrics.h"
28 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
29 #include "extensions/common/extension.h" 28 #include "extensions/common/extension.h"
30 29
31 #if !defined(OS_MACOSX) 30 #if !defined(OS_MACOSX)
32 #include "base/prefs/pref_service.h" 31 #include "base/prefs/pref_service.h"
33 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
34 #endif 33 #endif
35 34
36 using base::UserMetricsAction; 35 using base::UserMetricsAction;
37 using content::RenderViewHost; 36 using content::RenderViewHost;
38 using content::WebContents; 37 using content::WebContents;
39 38
40 FullscreenController::FullscreenController(ExclusiveAccessManager* manager, 39 FullscreenController::FullscreenController(ExclusiveAccessManager* manager)
41 Browser* browser) 40 : ExclusiveAccessControllerBase(manager),
42 : ExclusiveAccessControllerBase(manager, browser),
43 state_prior_to_tab_fullscreen_(STATE_INVALID), 41 state_prior_to_tab_fullscreen_(STATE_INVALID),
44 tab_fullscreen_accepted_(false), 42 tab_fullscreen_accepted_(false),
45 toggled_into_fullscreen_(false), 43 toggled_into_fullscreen_(false),
46 reentrant_window_state_change_call_check_(false), 44 reentrant_window_state_change_call_check_(false),
47 is_privileged_fullscreen_for_testing_(false), 45 is_privileged_fullscreen_for_testing_(false),
48 ptr_factory_(this) { 46 ptr_factory_(this) {
49 } 47 }
50 48
51 FullscreenController::~FullscreenController() { 49 FullscreenController::~FullscreenController() {
52 } 50 }
53 51
54 bool FullscreenController::IsFullscreenForBrowser() const { 52 bool FullscreenController::IsFullscreenForBrowser() const {
55 return browser()->window()->IsFullscreen() && !IsFullscreenCausedByTab(); 53 return exclusive_access_manager()
54 ->exclusive_access_context()
55 ->IsFullscreen() &&
56 !IsFullscreenCausedByTab();
56 } 57 }
57 58
58 void FullscreenController::ToggleBrowserFullscreenMode() { 59 void FullscreenController::ToggleBrowserFullscreenMode() {
59 extension_caused_fullscreen_ = GURL(); 60 extension_caused_fullscreen_ = GURL();
60 ToggleFullscreenModeInternal(BROWSER); 61 ToggleFullscreenModeInternal(BROWSER);
61 } 62 }
62 63
63 void FullscreenController::ToggleBrowserFullscreenWithToolbar() { 64 void FullscreenController::ToggleBrowserFullscreenWithToolbar() {
64 ToggleFullscreenModeInternal(BROWSER_WITH_TOOLBAR); 65 ToggleFullscreenModeInternal(BROWSER_WITH_TOOLBAR);
65 } 66 }
(...skipping 19 matching lines...) Expand all
85 } 86 }
86 87
87 bool FullscreenController::IsUserAcceptedFullscreen() const { 88 bool FullscreenController::IsUserAcceptedFullscreen() const {
88 return tab_fullscreen_accepted_; 89 return tab_fullscreen_accepted_;
89 } 90 }
90 91
91 bool FullscreenController::IsFullscreenForTabOrPending( 92 bool FullscreenController::IsFullscreenForTabOrPending(
92 const WebContents* web_contents) const { 93 const WebContents* web_contents) const {
93 if (web_contents == exclusive_access_tab()) { 94 if (web_contents == exclusive_access_tab()) {
94 DCHECK(web_contents == 95 DCHECK(web_contents ==
95 browser()->tab_strip_model()->GetActiveWebContents()); 96 exclusive_access_manager()
97 ->exclusive_access_context()
98 ->GetActiveWebContents());
96 DCHECK(web_contents->GetCapturerCount() == 0); 99 DCHECK(web_contents->GetCapturerCount() == 0);
97 return true; 100 return true;
98 } 101 }
99 return IsFullscreenForCapturedTab(web_contents); 102 return IsFullscreenForCapturedTab(web_contents);
100 } 103 }
101 104
102 bool FullscreenController::IsFullscreenCausedByTab() const { 105 bool FullscreenController::IsFullscreenCausedByTab() const {
103 return state_prior_to_tab_fullscreen_ == STATE_NORMAL; 106 return state_prior_to_tab_fullscreen_ == STATE_NORMAL;
104 } 107 }
105 108
106 void FullscreenController::EnterFullscreenModeForTab(WebContents* web_contents, 109 void FullscreenController::EnterFullscreenModeForTab(WebContents* web_contents,
107 const GURL& origin) { 110 const GURL& origin) {
108 DCHECK(web_contents); 111 DCHECK(web_contents);
109 112
110 if (MaybeToggleFullscreenForCapturedTab(web_contents, true)) { 113 if (MaybeToggleFullscreenForCapturedTab(web_contents, true)) {
111 // During tab capture of fullscreen-within-tab views, the browser window 114 // During tab capture of fullscreen-within-tab views, the browser window
112 // fullscreen state is unchanged, so return now. 115 // fullscreen state is unchanged, so return now.
113 return; 116 return;
114 } 117 }
115 118
116 if (web_contents != browser()->tab_strip_model()->GetActiveWebContents() || 119 if (web_contents !=
120 exclusive_access_manager()
121 ->exclusive_access_context()
122 ->GetActiveWebContents() ||
117 IsWindowFullscreenForTabOrPending()) { 123 IsWindowFullscreenForTabOrPending()) {
118 return; 124 return;
119 } 125 }
120 126
121 #if defined(OS_WIN) 127 #if defined(OS_WIN)
122 // For now, avoid breaking when initiating full screen tab mode while in 128 // For now, avoid breaking when initiating full screen tab mode while in
123 // a metro snap. 129 // a metro snap.
124 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen 130 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen
125 // modes with metro snap. 131 // modes with metro snap.
126 if (IsInMetroSnapMode()) 132 if (IsInMetroSnapMode())
127 return; 133 return;
128 #endif 134 #endif
129 135
130 SetTabWithExclusiveAccess(web_contents); 136 SetTabWithExclusiveAccess(web_contents);
131 fullscreened_origin_ = origin; 137 fullscreened_origin_ = origin;
132 138
133 BrowserWindow* window = browser()->window(); 139 ExclusiveAccessContext* exclusive_access_context =
140 exclusive_access_manager()->exclusive_access_context();
134 141
135 if (!window->IsFullscreen()) { 142 if (!exclusive_access_context->IsFullscreen()) {
136 // Normal -> Tab Fullscreen. 143 // Normal -> Tab Fullscreen.
137 state_prior_to_tab_fullscreen_ = STATE_NORMAL; 144 state_prior_to_tab_fullscreen_ = STATE_NORMAL;
138 ToggleFullscreenModeInternal(TAB); 145 ToggleFullscreenModeInternal(TAB);
139 return; 146 return;
140 } 147 }
141 148
142 if (window->IsFullscreenWithToolbar()) { 149 if (exclusive_access_context->IsFullscreenWithToolbar()) {
143 // Browser Fullscreen with Toolbar -> Tab Fullscreen (no toolbar). 150 // Browser Fullscreen with Toolbar -> Tab Fullscreen (no toolbar).
144 window->UpdateFullscreenWithToolbar(false); 151 exclusive_access_context->UpdateFullscreenWithToolbar(false);
145 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR; 152 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR;
146 } else { 153 } else {
147 // Browser Fullscreen without Toolbar -> Tab Fullscreen. 154 // Browser Fullscreen without Toolbar -> Tab Fullscreen.
148 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_TOOLBAR; 155 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_TOOLBAR;
149 } 156 }
150 157
151 // We need to update the fullscreen exit bubble, e.g., going from browser 158 // We need to update the fullscreen exit bubble, e.g., going from browser
152 // fullscreen to tab fullscreen will need to show different content. 159 // fullscreen to tab fullscreen will need to show different content.
153 if (!tab_fullscreen_accepted_) { 160 if (!tab_fullscreen_accepted_) {
154 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW; 161 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW;
(...skipping 19 matching lines...) Expand all
174 181
175 #if defined(OS_WIN) 182 #if defined(OS_WIN)
176 // For now, avoid breaking when initiating full screen tab mode while in 183 // For now, avoid breaking when initiating full screen tab mode while in
177 // a metro snap. 184 // a metro snap.
178 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen 185 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen
179 // modes with metro snap. 186 // modes with metro snap.
180 if (IsInMetroSnapMode()) 187 if (IsInMetroSnapMode())
181 return; 188 return;
182 #endif 189 #endif
183 190
184 BrowserWindow* window = browser()->window(); 191 ExclusiveAccessContext* exclusive_access_context =
185 if (!window->IsFullscreen()) 192 exclusive_access_manager()->exclusive_access_context();
193
194 if (!exclusive_access_context->IsFullscreen())
186 return; 195 return;
187 196
188 if (IsFullscreenCausedByTab()) { 197 if (IsFullscreenCausedByTab()) {
189 // Tab Fullscreen -> Normal. 198 // Tab Fullscreen -> Normal.
190 ToggleFullscreenModeInternal(TAB); 199 ToggleFullscreenModeInternal(TAB);
191 return; 200 return;
192 } 201 }
193 202
194 // Tab Fullscreen -> Browser Fullscreen (with or without toolbar). 203 // Tab Fullscreen -> Browser Fullscreen (with or without toolbar).
195 if (state_prior_to_tab_fullscreen_ == STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR) { 204 if (state_prior_to_tab_fullscreen_ == STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR) {
196 // Tab Fullscreen (no toolbar) -> Browser Fullscreen with Toolbar. 205 // Tab Fullscreen (no toolbar) -> Browser Fullscreen with Toolbar.
197 window->UpdateFullscreenWithToolbar(true); 206 exclusive_access_context->UpdateFullscreenWithToolbar(true);
198 } 207 }
199 208
200 #if defined(OS_MACOSX) 209 #if defined(OS_MACOSX)
201 // Clear the bubble URL, which forces the Mac UI to redraw. 210 // Clear the bubble URL, which forces the Mac UI to redraw.
202 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); 211 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent();
203 #endif // defined(OS_MACOSX) 212 #endif // defined(OS_MACOSX)
204 213
205 // If currently there is a tab in "tab fullscreen" mode and fullscreen 214 // If currently there is a tab in "tab fullscreen" mode and fullscreen
206 // was not caused by it (i.e., previously it was in "browser fullscreen" 215 // was not caused by it (i.e., previously it was in "browser fullscreen"
207 // mode), we need to switch back to "browser fullscreen" mode. In this 216 // mode), we need to switch back to "browser fullscreen" mode. In this
208 // case, all we have to do is notifying the tab that it has exited "tab 217 // case, all we have to do is notifying the tab that it has exited "tab
209 // fullscreen" mode. 218 // fullscreen" mode.
210 NotifyTabExclusiveAccessLost(); 219 NotifyTabExclusiveAccessLost();
211 220
212 // This is only a change between Browser and Tab fullscreen. We generate 221 // This is only a change between Browser and Tab fullscreen. We generate
213 // a fullscreen notification now because there is no window change. 222 // a fullscreen notification now because there is no window change.
214 PostFullscreenChangeNotification(true); 223 PostFullscreenChangeNotification(true);
215 } 224 }
216 225
217 bool FullscreenController::IsInMetroSnapMode() { 226 bool FullscreenController::IsInMetroSnapMode() {
218 #if defined(OS_WIN) 227 return exclusive_access_manager()
219 return browser()->window()->IsInMetroSnapMode(); 228 ->exclusive_access_context()
220 #else 229 ->IsInMetroSnapMode();
221 return false;
222 #endif
223 } 230 }
224 231
225 #if defined(OS_WIN) 232 #if defined(OS_WIN)
226 void FullscreenController::SetMetroSnapMode(bool enable) { 233 void FullscreenController::SetMetroSnapMode(bool enable) {
227 reentrant_window_state_change_call_check_ = false; 234 reentrant_window_state_change_call_check_ = false;
228 235
229 toggled_into_fullscreen_ = false; 236 toggled_into_fullscreen_ = false;
230 browser()->window()->SetMetroSnapMode(enable); 237 exclusive_access_manager()->exclusive_access_context()->SetMetroSnapMode(
238 enable);
231 239
232 // FullscreenController unit tests for metro snap assume that on Windows calls 240 // FullscreenController unit tests for metro snap assume that on Windows calls
233 // to WindowFullscreenStateChanged are reentrant. If that assumption is 241 // to WindowFullscreenStateChanged are reentrant. If that assumption is
234 // invalidated, the tests must be updated to maintain coverage. 242 // invalidated, the tests must be updated to maintain coverage.
235 CHECK(reentrant_window_state_change_call_check_); 243 CHECK(reentrant_window_state_change_call_check_);
236 } 244 }
237 #endif // defined(OS_WIN) 245 #endif // defined(OS_WIN)
238 246
239 void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) { 247 void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) {
240 if (!IsFullscreenForCapturedTab(old_contents)) 248 if (!IsFullscreenForCapturedTab(old_contents))
(...skipping 30 matching lines...) Expand all
271 void FullscreenController::OnTabClosing(WebContents* web_contents) { 279 void FullscreenController::OnTabClosing(WebContents* web_contents) {
272 if (IsFullscreenForCapturedTab(web_contents)) { 280 if (IsFullscreenForCapturedTab(web_contents)) {
273 web_contents->ExitFullscreen(); 281 web_contents->ExitFullscreen();
274 } else { 282 } else {
275 ExclusiveAccessControllerBase::OnTabClosing(web_contents); 283 ExclusiveAccessControllerBase::OnTabClosing(web_contents);
276 } 284 }
277 } 285 }
278 286
279 void FullscreenController::WindowFullscreenStateChanged() { 287 void FullscreenController::WindowFullscreenStateChanged() {
280 reentrant_window_state_change_call_check_ = true; 288 reentrant_window_state_change_call_check_ = true;
281 289 ExclusiveAccessContext* const exclusive_access_context =
282 BrowserWindow* const window = browser()->window(); 290 exclusive_access_manager()->exclusive_access_context();
283 bool exiting_fullscreen = !window->IsFullscreen(); 291 bool exiting_fullscreen = !exclusive_access_context->IsFullscreen();
284 292
285 PostFullscreenChangeNotification(!exiting_fullscreen); 293 PostFullscreenChangeNotification(!exiting_fullscreen);
286 if (exiting_fullscreen) { 294 if (exiting_fullscreen) {
287 toggled_into_fullscreen_ = false; 295 toggled_into_fullscreen_ = false;
288 extension_caused_fullscreen_ = GURL(); 296 extension_caused_fullscreen_ = GURL();
289 NotifyTabExclusiveAccessLost(); 297 NotifyTabExclusiveAccessLost();
290 } 298 }
291 if (exiting_fullscreen) { 299 exclusive_access_context->UpdateDownloadShelf(exiting_fullscreen);
292 window->GetDownloadShelf()->Unhide();
293 } else {
294 window->GetDownloadShelf()->Hide();
295 if (window->GetStatusBubble())
296 window->GetStatusBubble()->Hide();
297 }
298 } 300 }
299 301
300 bool FullscreenController::HandleUserPressedEscape() { 302 bool FullscreenController::HandleUserPressedEscape() {
301 WebContents* const active_web_contents = 303 WebContents* const active_web_contents = exclusive_access_manager()
302 browser()->tab_strip_model()->GetActiveWebContents(); 304 ->exclusive_access_context()
305 ->GetActiveWebContents();
303 if (IsFullscreenForCapturedTab(active_web_contents)) { 306 if (IsFullscreenForCapturedTab(active_web_contents)) {
304 active_web_contents->ExitFullscreen(); 307 active_web_contents->ExitFullscreen();
305 return true; 308 return true;
306 } else if (IsWindowFullscreenForTabOrPending()) { 309 } else if (IsWindowFullscreenForTabOrPending()) {
307 ExitExclusiveAccessIfNecessary(); 310 ExitExclusiveAccessIfNecessary();
308 return true; 311 return true;
309 } 312 }
310 313
311 return false; 314 return false;
312 } 315 }
(...skipping 28 matching lines...) Expand all
341 // is visited and user selects ALLOW. Later user visits example.com which 344 // is visited and user selects ALLOW. Later user visits example.com which
342 // embeds youtube.com in an iframe, which is then ALLOWED to go fullscreen. 345 // embeds youtube.com in an iframe, which is then ALLOWED to go fullscreen.
343 ContentSettingsPattern primary_pattern = 346 ContentSettingsPattern primary_pattern =
344 ContentSettingsPattern::FromURLNoWildcard(GetRequestingOrigin()); 347 ContentSettingsPattern::FromURLNoWildcard(GetRequestingOrigin());
345 ContentSettingsPattern secondary_pattern = 348 ContentSettingsPattern secondary_pattern =
346 ContentSettingsPattern::FromURLNoWildcard(GetEmbeddingOrigin()); 349 ContentSettingsPattern::FromURLNoWildcard(GetEmbeddingOrigin());
347 350
348 // ContentSettings requires valid patterns and the patterns might be invalid 351 // ContentSettings requires valid patterns and the patterns might be invalid
349 // in some edge cases like if the current frame is about:blank. 352 // in some edge cases like if the current frame is about:blank.
350 if (primary_pattern.IsValid() && secondary_pattern.IsValid()) { 353 if (primary_pattern.IsValid() && secondary_pattern.IsValid()) {
351 HostContentSettingsMap* settings_map = 354 HostContentSettingsMap* settings_map = exclusive_access_manager()
352 profile()->GetHostContentSettingsMap(); 355 ->exclusive_access_context()
356 ->GetProfile()
357 ->GetHostContentSettingsMap();
353 settings_map->SetContentSetting( 358 settings_map->SetContentSetting(
354 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_FULLSCREEN, 359 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_FULLSCREEN,
355 std::string(), CONTENT_SETTING_ALLOW); 360 std::string(), CONTENT_SETTING_ALLOW);
356 } 361 }
357 tab_fullscreen_accepted_ = true; 362 tab_fullscreen_accepted_ = true;
358 return true; 363 return true;
359 } 364 }
360 365
361 return false; 366 return false;
362 } 367 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 417 }
413 418
414 void FullscreenController::ToggleFullscreenModeInternal( 419 void FullscreenController::ToggleFullscreenModeInternal(
415 FullscreenInternalOption option) { 420 FullscreenInternalOption option) {
416 #if defined(OS_WIN) 421 #if defined(OS_WIN)
417 // When in Metro snap mode, toggling in and out of fullscreen is prevented. 422 // When in Metro snap mode, toggling in and out of fullscreen is prevented.
418 if (IsInMetroSnapMode()) 423 if (IsInMetroSnapMode())
419 return; 424 return;
420 #endif 425 #endif
421 426
422 BrowserWindow* const window = browser()->window(); 427 ExclusiveAccessContext* const exclusive_access_context =
423 bool enter_fullscreen = !window->IsFullscreen(); 428 exclusive_access_manager()->exclusive_access_context();
429 bool enter_fullscreen = !exclusive_access_context->IsFullscreen();
424 430
425 // When a Mac user requests a toggle they may be toggling between 431 // When a Mac user requests a toggle they may be toggling between
426 // FullscreenWithoutChrome and FullscreenWithToolbar. 432 // FullscreenWithoutChrome and FullscreenWithToolbar.
427 if (window->IsFullscreen() && !IsWindowFullscreenForTabOrPending() && 433 if (exclusive_access_context->IsFullscreen() &&
428 window->SupportsFullscreenWithToolbar()) { 434 !IsWindowFullscreenForTabOrPending() &&
435 exclusive_access_context->SupportsFullscreenWithToolbar()) {
429 if (option == BROWSER_WITH_TOOLBAR) { 436 if (option == BROWSER_WITH_TOOLBAR) {
430 enter_fullscreen = enter_fullscreen || !window->IsFullscreenWithToolbar(); 437 enter_fullscreen = enter_fullscreen ||
438 !exclusive_access_context->IsFullscreenWithToolbar();
431 } else { 439 } else {
432 enter_fullscreen = enter_fullscreen || window->IsFullscreenWithToolbar(); 440 enter_fullscreen = enter_fullscreen ||
441 exclusive_access_context->IsFullscreenWithToolbar();
433 } 442 }
434 } 443 }
435 444
436 // In kiosk mode, we always want to be fullscreen. When the browser first 445 // In kiosk mode, we always want to be fullscreen. When the browser first
437 // starts we're not yet fullscreen, so let the initial toggle go through. 446 // starts we're not yet fullscreen, so let the initial toggle go through.
438 if (chrome::IsRunningInAppMode() && window->IsFullscreen()) 447 if (chrome::IsRunningInAppMode() && exclusive_access_context->IsFullscreen())
439 return; 448 return;
440 449
441 #if !defined(OS_MACOSX) 450 #if !defined(OS_MACOSX)
442 // Do not enter fullscreen mode if disallowed by pref. This prevents the user 451 // Do not enter fullscreen mode if disallowed by pref. This prevents the user
443 // from manually entering fullscreen mode and also disables kiosk mode on 452 // from manually entering fullscreen mode and also disables kiosk mode on
444 // desktop platforms. 453 // desktop platforms.
445 if (enter_fullscreen && 454 if (enter_fullscreen &&
446 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) { 455 !exclusive_access_context->GetProfile()->GetPrefs()->GetBoolean(
456 prefs::kFullscreenAllowed)) {
447 return; 457 return;
448 } 458 }
449 #endif 459 #endif
450 460
451 if (enter_fullscreen) 461 if (enter_fullscreen)
452 EnterFullscreenModeInternal(option); 462 EnterFullscreenModeInternal(option);
453 else 463 else
454 ExitFullscreenModeInternal(); 464 ExitFullscreenModeInternal();
455 } 465 }
456 466
457 void FullscreenController::EnterFullscreenModeInternal( 467 void FullscreenController::EnterFullscreenModeInternal(
458 FullscreenInternalOption option) { 468 FullscreenInternalOption option) {
459 toggled_into_fullscreen_ = true; 469 toggled_into_fullscreen_ = true;
460 GURL url; 470 GURL url;
461 if (option == TAB) { 471 if (option == TAB) {
462 url = GetRequestingOrigin(); 472 url = GetRequestingOrigin();
463 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW; 473 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW;
464 } else { 474 } else {
465 if (!extension_caused_fullscreen_.is_empty()) 475 if (!extension_caused_fullscreen_.is_empty())
466 url = extension_caused_fullscreen_; 476 url = extension_caused_fullscreen_;
467 } 477 }
468 478
469 if (option == BROWSER) 479 if (option == BROWSER)
470 content::RecordAction(UserMetricsAction("ToggleFullscreen")); 480 content::RecordAction(UserMetricsAction("ToggleFullscreen"));
471 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions 481 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions
472 // from tab fullscreen out to browser with toolbar. 482 // from tab fullscreen out to browser with toolbar.
473 483
474 browser()->window()->EnterFullscreen( 484 exclusive_access_manager()->exclusive_access_context()->EnterFullscreen(
475 url, exclusive_access_manager()->GetExclusiveAccessExitBubbleType(), 485 url, exclusive_access_manager()->GetExclusiveAccessExitBubbleType(),
476 option == BROWSER_WITH_TOOLBAR); 486 option == BROWSER_WITH_TOOLBAR);
477 487
478 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); 488 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent();
479 489
480 // Once the window has become fullscreen it'll call back to 490 // Once the window has become fullscreen it'll call back to
481 // WindowFullscreenStateChanged(). We don't do this immediately as 491 // WindowFullscreenStateChanged(). We don't do this immediately as
482 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let 492 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let
483 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. 493 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate.
484 } 494 }
485 495
486 void FullscreenController::ExitFullscreenModeInternal() { 496 void FullscreenController::ExitFullscreenModeInternal() {
487 toggled_into_fullscreen_ = false; 497 toggled_into_fullscreen_ = false;
488 #if defined(OS_MACOSX) 498 #if defined(OS_MACOSX)
489 // Mac windows report a state change instantly, and so we must also clear 499 // Mac windows report a state change instantly, and so we must also clear
490 // state_prior_to_tab_fullscreen_ to match them else other logic using 500 // state_prior_to_tab_fullscreen_ to match them else other logic using
491 // state_prior_to_tab_fullscreen_ will be incorrect. 501 // state_prior_to_tab_fullscreen_ will be incorrect.
492 NotifyTabExclusiveAccessLost(); 502 NotifyTabExclusiveAccessLost();
493 #endif 503 #endif
494 browser()->window()->ExitFullscreen(); 504 exclusive_access_manager()->exclusive_access_context()->ExitFullscreen();
495 extension_caused_fullscreen_ = GURL(); 505 extension_caused_fullscreen_ = GURL();
496 506
497 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); 507 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent();
498 } 508 }
499 509
500 ContentSetting FullscreenController::GetFullscreenSetting() const { 510 ContentSetting FullscreenController::GetFullscreenSetting() const {
501 DCHECK(exclusive_access_tab()); 511 DCHECK(exclusive_access_tab());
502 512
503 GURL url = GetRequestingOrigin(); 513 GURL url = GetRequestingOrigin();
504 514
505 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) 515 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile())
506 return CONTENT_SETTING_ALLOW; 516 return CONTENT_SETTING_ALLOW;
507 517
508 // If the permission was granted to the website with no embedder, it should 518 // If the permission was granted to the website with no embedder, it should
509 // always be allowed, even if embedded. 519 // always be allowed, even if embedded.
510 if (profile()->GetHostContentSettingsMap()->GetContentSetting( 520 if (exclusive_access_manager()
511 url, url, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()) == 521 ->exclusive_access_context()
512 CONTENT_SETTING_ALLOW) { 522 ->GetProfile()
523 ->GetHostContentSettingsMap()
524 ->GetContentSetting(url, url, CONTENT_SETTINGS_TYPE_FULLSCREEN,
525 std::string()) == CONTENT_SETTING_ALLOW) {
513 return CONTENT_SETTING_ALLOW; 526 return CONTENT_SETTING_ALLOW;
514 } 527 }
515 528
516 // See the comment above the call to |SetContentSetting()| for how the 529 // See the comment above the call to |SetContentSetting()| for how the
517 // requesting and embedding origins interact with each other wrt permissions. 530 // requesting and embedding origins interact with each other wrt permissions.
518 return profile()->GetHostContentSettingsMap()->GetContentSetting( 531 return exclusive_access_manager()
519 url, GetEmbeddingOrigin(), CONTENT_SETTINGS_TYPE_FULLSCREEN, 532 ->exclusive_access_context()
520 std::string()); 533 ->GetProfile()
534 ->GetHostContentSettingsMap()
535 ->GetContentSetting(url, GetEmbeddingOrigin(),
536 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string());
521 } 537 }
522 538
523 bool FullscreenController::IsPrivilegedFullscreenForTab() const { 539 bool FullscreenController::IsPrivilegedFullscreenForTab() const {
524 const bool embedded_widget_present = 540 const bool embedded_widget_present =
525 exclusive_access_tab() && 541 exclusive_access_tab() &&
526 exclusive_access_tab()->GetFullscreenRenderWidgetHostView(); 542 exclusive_access_tab()->GetFullscreenRenderWidgetHostView();
527 return embedded_widget_present || is_privileged_fullscreen_for_testing_; 543 return embedded_widget_present || is_privileged_fullscreen_for_testing_;
528 } 544 }
529 545
530 void FullscreenController::SetPrivilegedFullscreenForTesting( 546 void FullscreenController::SetPrivilegedFullscreenForTesting(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 return fullscreened_origin_; 589 return fullscreened_origin_;
574 590
575 return exclusive_access_tab()->GetLastCommittedURL(); 591 return exclusive_access_tab()->GetLastCommittedURL();
576 } 592 }
577 593
578 GURL FullscreenController::GetEmbeddingOrigin() const { 594 GURL FullscreenController::GetEmbeddingOrigin() const {
579 DCHECK(exclusive_access_tab()); 595 DCHECK(exclusive_access_tab());
580 596
581 return exclusive_access_tab()->GetLastCommittedURL(); 597 return exclusive_access_tab()->GetLastCommittedURL();
582 } 598 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698