OLD | NEW |
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()->context()->IsFullscreen() && |
| 54 !IsFullscreenCausedByTab(); |
56 } | 55 } |
57 | 56 |
58 void FullscreenController::ToggleBrowserFullscreenMode() { | 57 void FullscreenController::ToggleBrowserFullscreenMode() { |
59 extension_caused_fullscreen_ = GURL(); | 58 extension_caused_fullscreen_ = GURL(); |
60 ToggleFullscreenModeInternal(BROWSER); | 59 ToggleFullscreenModeInternal(BROWSER); |
61 } | 60 } |
62 | 61 |
63 void FullscreenController::ToggleBrowserFullscreenWithToolbar() { | 62 void FullscreenController::ToggleBrowserFullscreenWithToolbar() { |
64 ToggleFullscreenModeInternal(BROWSER_WITH_TOOLBAR); | 63 ToggleFullscreenModeInternal(BROWSER_WITH_TOOLBAR); |
65 } | 64 } |
(...skipping 19 matching lines...) Expand all Loading... |
85 } | 84 } |
86 | 85 |
87 bool FullscreenController::IsUserAcceptedFullscreen() const { | 86 bool FullscreenController::IsUserAcceptedFullscreen() const { |
88 return tab_fullscreen_accepted_; | 87 return tab_fullscreen_accepted_; |
89 } | 88 } |
90 | 89 |
91 bool FullscreenController::IsFullscreenForTabOrPending( | 90 bool FullscreenController::IsFullscreenForTabOrPending( |
92 const WebContents* web_contents) const { | 91 const WebContents* web_contents) const { |
93 if (web_contents == exclusive_access_tab()) { | 92 if (web_contents == exclusive_access_tab()) { |
94 DCHECK(web_contents == | 93 DCHECK(web_contents == |
95 browser()->tab_strip_model()->GetActiveWebContents()); | 94 exclusive_access_manager()->context()->GetActiveWebContents()); |
96 DCHECK(web_contents->GetCapturerCount() == 0); | 95 DCHECK(web_contents->GetCapturerCount() == 0); |
97 return true; | 96 return true; |
98 } | 97 } |
99 return IsFullscreenForCapturedTab(web_contents); | 98 return IsFullscreenForCapturedTab(web_contents); |
100 } | 99 } |
101 | 100 |
102 bool FullscreenController::IsFullscreenCausedByTab() const { | 101 bool FullscreenController::IsFullscreenCausedByTab() const { |
103 return state_prior_to_tab_fullscreen_ == STATE_NORMAL; | 102 return state_prior_to_tab_fullscreen_ == STATE_NORMAL; |
104 } | 103 } |
105 | 104 |
106 void FullscreenController::EnterFullscreenModeForTab(WebContents* web_contents, | 105 void FullscreenController::EnterFullscreenModeForTab(WebContents* web_contents, |
107 const GURL& origin) { | 106 const GURL& origin) { |
108 DCHECK(web_contents); | 107 DCHECK(web_contents); |
109 | 108 |
110 if (MaybeToggleFullscreenForCapturedTab(web_contents, true)) { | 109 if (MaybeToggleFullscreenForCapturedTab(web_contents, true)) { |
111 // During tab capture of fullscreen-within-tab views, the browser window | 110 // During tab capture of fullscreen-within-tab views, the browser window |
112 // fullscreen state is unchanged, so return now. | 111 // fullscreen state is unchanged, so return now. |
113 return; | 112 return; |
114 } | 113 } |
115 | 114 |
116 if (web_contents != browser()->tab_strip_model()->GetActiveWebContents() || | 115 if (web_contents != |
| 116 exclusive_access_manager()->context()->GetActiveWebContents() || |
117 IsWindowFullscreenForTabOrPending()) { | 117 IsWindowFullscreenForTabOrPending()) { |
118 return; | 118 return; |
119 } | 119 } |
120 | 120 |
121 #if defined(OS_WIN) | 121 #if defined(OS_WIN) |
122 // For now, avoid breaking when initiating full screen tab mode while in | 122 // For now, avoid breaking when initiating full screen tab mode while in |
123 // a metro snap. | 123 // a metro snap. |
124 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen | 124 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen |
125 // modes with metro snap. | 125 // modes with metro snap. |
126 if (IsInMetroSnapMode()) | 126 if (IsInMetroSnapMode()) |
127 return; | 127 return; |
128 #endif | 128 #endif |
129 | 129 |
130 SetTabWithExclusiveAccess(web_contents); | 130 SetTabWithExclusiveAccess(web_contents); |
131 fullscreened_origin_ = origin; | 131 fullscreened_origin_ = origin; |
132 | 132 |
133 BrowserWindow* window = browser()->window(); | 133 ExclusiveAccessContext* exclusive_access_context = |
| 134 exclusive_access_manager()->context(); |
134 | 135 |
135 if (!window->IsFullscreen()) { | 136 if (!exclusive_access_context->IsFullscreen()) { |
136 // Normal -> Tab Fullscreen. | 137 // Normal -> Tab Fullscreen. |
137 state_prior_to_tab_fullscreen_ = STATE_NORMAL; | 138 state_prior_to_tab_fullscreen_ = STATE_NORMAL; |
138 ToggleFullscreenModeInternal(TAB); | 139 ToggleFullscreenModeInternal(TAB); |
139 return; | 140 return; |
140 } | 141 } |
141 | 142 |
142 if (window->IsFullscreenWithToolbar()) { | 143 if (exclusive_access_context->IsFullscreenWithToolbar()) { |
143 // Browser Fullscreen with Toolbar -> Tab Fullscreen (no toolbar). | 144 // Browser Fullscreen with Toolbar -> Tab Fullscreen (no toolbar). |
144 window->UpdateFullscreenWithToolbar(false); | 145 exclusive_access_context->UpdateFullscreenWithToolbar(false); |
145 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR; | 146 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR; |
146 } else { | 147 } else { |
147 // Browser Fullscreen without Toolbar -> Tab Fullscreen. | 148 // Browser Fullscreen without Toolbar -> Tab Fullscreen. |
148 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_TOOLBAR; | 149 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_TOOLBAR; |
149 } | 150 } |
150 | 151 |
151 // We need to update the fullscreen exit bubble, e.g., going from browser | 152 // We need to update the fullscreen exit bubble, e.g., going from browser |
152 // fullscreen to tab fullscreen will need to show different content. | 153 // fullscreen to tab fullscreen will need to show different content. |
153 if (!tab_fullscreen_accepted_) { | 154 if (!tab_fullscreen_accepted_) { |
154 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW; | 155 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW; |
(...skipping 19 matching lines...) Expand all Loading... |
174 | 175 |
175 #if defined(OS_WIN) | 176 #if defined(OS_WIN) |
176 // For now, avoid breaking when initiating full screen tab mode while in | 177 // For now, avoid breaking when initiating full screen tab mode while in |
177 // a metro snap. | 178 // a metro snap. |
178 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen | 179 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen |
179 // modes with metro snap. | 180 // modes with metro snap. |
180 if (IsInMetroSnapMode()) | 181 if (IsInMetroSnapMode()) |
181 return; | 182 return; |
182 #endif | 183 #endif |
183 | 184 |
184 BrowserWindow* window = browser()->window(); | 185 ExclusiveAccessContext* exclusive_access_context = |
185 if (!window->IsFullscreen()) | 186 exclusive_access_manager()->context(); |
| 187 |
| 188 if (!exclusive_access_context->IsFullscreen()) |
186 return; | 189 return; |
187 | 190 |
188 if (IsFullscreenCausedByTab()) { | 191 if (IsFullscreenCausedByTab()) { |
189 // Tab Fullscreen -> Normal. | 192 // Tab Fullscreen -> Normal. |
190 ToggleFullscreenModeInternal(TAB); | 193 ToggleFullscreenModeInternal(TAB); |
191 return; | 194 return; |
192 } | 195 } |
193 | 196 |
194 // Tab Fullscreen -> Browser Fullscreen (with or without toolbar). | 197 // Tab Fullscreen -> Browser Fullscreen (with or without toolbar). |
195 if (state_prior_to_tab_fullscreen_ == STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR) { | 198 if (state_prior_to_tab_fullscreen_ == STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR) { |
196 // Tab Fullscreen (no toolbar) -> Browser Fullscreen with Toolbar. | 199 // Tab Fullscreen (no toolbar) -> Browser Fullscreen with Toolbar. |
197 window->UpdateFullscreenWithToolbar(true); | 200 exclusive_access_context->UpdateFullscreenWithToolbar(true); |
198 } | 201 } |
199 | 202 |
200 #if defined(OS_MACOSX) | 203 #if defined(OS_MACOSX) |
201 // Clear the bubble URL, which forces the Mac UI to redraw. | 204 // Clear the bubble URL, which forces the Mac UI to redraw. |
202 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); | 205 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); |
203 #endif // defined(OS_MACOSX) | 206 #endif // defined(OS_MACOSX) |
204 | 207 |
205 // If currently there is a tab in "tab fullscreen" mode and fullscreen | 208 // 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" | 209 // 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 | 210 // 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 | 211 // case, all we have to do is notifying the tab that it has exited "tab |
209 // fullscreen" mode. | 212 // fullscreen" mode. |
210 NotifyTabExclusiveAccessLost(); | 213 NotifyTabExclusiveAccessLost(); |
211 | 214 |
212 // This is only a change between Browser and Tab fullscreen. We generate | 215 // This is only a change between Browser and Tab fullscreen. We generate |
213 // a fullscreen notification now because there is no window change. | 216 // a fullscreen notification now because there is no window change. |
214 PostFullscreenChangeNotification(true); | 217 PostFullscreenChangeNotification(true); |
215 } | 218 } |
216 | 219 |
| 220 #if defined(OS_WIN) |
217 bool FullscreenController::IsInMetroSnapMode() { | 221 bool FullscreenController::IsInMetroSnapMode() { |
218 #if defined(OS_WIN) | 222 return exclusive_access_manager()->context()->IsInMetroSnapMode(); |
219 return browser()->window()->IsInMetroSnapMode(); | |
220 #else | |
221 return false; | |
222 #endif | |
223 } | 223 } |
224 | 224 |
225 #if defined(OS_WIN) | |
226 void FullscreenController::SetMetroSnapMode(bool enable) { | 225 void FullscreenController::SetMetroSnapMode(bool enable) { |
227 reentrant_window_state_change_call_check_ = false; | 226 reentrant_window_state_change_call_check_ = false; |
228 | 227 |
229 toggled_into_fullscreen_ = false; | 228 toggled_into_fullscreen_ = false; |
230 browser()->window()->SetMetroSnapMode(enable); | 229 exclusive_access_manager()->context()->SetMetroSnapMode(enable); |
231 | 230 |
232 // FullscreenController unit tests for metro snap assume that on Windows calls | 231 // FullscreenController unit tests for metro snap assume that on Windows calls |
233 // to WindowFullscreenStateChanged are reentrant. If that assumption is | 232 // to WindowFullscreenStateChanged are reentrant. If that assumption is |
234 // invalidated, the tests must be updated to maintain coverage. | 233 // invalidated, the tests must be updated to maintain coverage. |
235 CHECK(reentrant_window_state_change_call_check_); | 234 CHECK(reentrant_window_state_change_call_check_); |
236 } | 235 } |
237 #endif // defined(OS_WIN) | 236 #endif // defined(OS_WIN) |
238 | 237 |
239 void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) { | 238 void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) { |
240 if (!IsFullscreenForCapturedTab(old_contents)) | 239 if (!IsFullscreenForCapturedTab(old_contents)) |
(...skipping 30 matching lines...) Expand all Loading... |
271 void FullscreenController::OnTabClosing(WebContents* web_contents) { | 270 void FullscreenController::OnTabClosing(WebContents* web_contents) { |
272 if (IsFullscreenForCapturedTab(web_contents)) { | 271 if (IsFullscreenForCapturedTab(web_contents)) { |
273 web_contents->ExitFullscreen(); | 272 web_contents->ExitFullscreen(); |
274 } else { | 273 } else { |
275 ExclusiveAccessControllerBase::OnTabClosing(web_contents); | 274 ExclusiveAccessControllerBase::OnTabClosing(web_contents); |
276 } | 275 } |
277 } | 276 } |
278 | 277 |
279 void FullscreenController::WindowFullscreenStateChanged() { | 278 void FullscreenController::WindowFullscreenStateChanged() { |
280 reentrant_window_state_change_call_check_ = true; | 279 reentrant_window_state_change_call_check_ = true; |
281 | 280 ExclusiveAccessContext* const exclusive_access_context = |
282 BrowserWindow* const window = browser()->window(); | 281 exclusive_access_manager()->context(); |
283 bool exiting_fullscreen = !window->IsFullscreen(); | 282 bool exiting_fullscreen = !exclusive_access_context->IsFullscreen(); |
284 | 283 |
285 PostFullscreenChangeNotification(!exiting_fullscreen); | 284 PostFullscreenChangeNotification(!exiting_fullscreen); |
286 if (exiting_fullscreen) { | 285 if (exiting_fullscreen) { |
287 toggled_into_fullscreen_ = false; | 286 toggled_into_fullscreen_ = false; |
288 extension_caused_fullscreen_ = GURL(); | 287 extension_caused_fullscreen_ = GURL(); |
289 NotifyTabExclusiveAccessLost(); | 288 NotifyTabExclusiveAccessLost(); |
290 } | 289 exclusive_access_context->UnhideDownloadShelf(); |
291 if (exiting_fullscreen) { | |
292 window->GetDownloadShelf()->Unhide(); | |
293 } else { | 290 } else { |
294 window->GetDownloadShelf()->Hide(); | 291 exclusive_access_context->HideDownloadShelf(); |
295 if (window->GetStatusBubble()) | |
296 window->GetStatusBubble()->Hide(); | |
297 } | 292 } |
298 } | 293 } |
299 | 294 |
300 bool FullscreenController::HandleUserPressedEscape() { | 295 bool FullscreenController::HandleUserPressedEscape() { |
301 WebContents* const active_web_contents = | 296 WebContents* const active_web_contents = |
302 browser()->tab_strip_model()->GetActiveWebContents(); | 297 exclusive_access_manager()->context()->GetActiveWebContents(); |
303 if (IsFullscreenForCapturedTab(active_web_contents)) { | 298 if (IsFullscreenForCapturedTab(active_web_contents)) { |
304 active_web_contents->ExitFullscreen(); | 299 active_web_contents->ExitFullscreen(); |
305 return true; | 300 return true; |
306 } else if (IsWindowFullscreenForTabOrPending()) { | 301 } else if (IsWindowFullscreenForTabOrPending()) { |
307 ExitExclusiveAccessIfNecessary(); | 302 ExitExclusiveAccessIfNecessary(); |
308 return true; | 303 return true; |
309 } | 304 } |
310 | 305 |
311 return false; | 306 return false; |
312 } | 307 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 ContentSettingsPattern::FromURLNoWildcard(embedder); | 343 ContentSettingsPattern::FromURLNoWildcard(embedder); |
349 | 344 |
350 // ContentSettings requires valid patterns and the patterns might be invalid | 345 // ContentSettings requires valid patterns and the patterns might be invalid |
351 // in some edge cases like if the current frame is about:blank. | 346 // in some edge cases like if the current frame is about:blank. |
352 // | 347 // |
353 // Do not store preference on file:// URLs, they don't have a clean | 348 // Do not store preference on file:// URLs, they don't have a clean |
354 // origin policy. | 349 // origin policy. |
355 // TODO(estark): Revisit this when crbug.com/455882 is fixed. | 350 // TODO(estark): Revisit this when crbug.com/455882 is fixed. |
356 if (!requester.SchemeIsFile() && !embedder.SchemeIsFile() && | 351 if (!requester.SchemeIsFile() && !embedder.SchemeIsFile() && |
357 primary_pattern.IsValid() && secondary_pattern.IsValid()) { | 352 primary_pattern.IsValid() && secondary_pattern.IsValid()) { |
358 HostContentSettingsMap* settings_map = | 353 HostContentSettingsMap* settings_map = exclusive_access_manager() |
359 profile()->GetHostContentSettingsMap(); | 354 ->context() |
| 355 ->GetProfile() |
| 356 ->GetHostContentSettingsMap(); |
360 settings_map->SetContentSetting( | 357 settings_map->SetContentSetting( |
361 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_FULLSCREEN, | 358 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_FULLSCREEN, |
362 std::string(), CONTENT_SETTING_ALLOW); | 359 std::string(), CONTENT_SETTING_ALLOW); |
363 } | 360 } |
364 tab_fullscreen_accepted_ = true; | 361 tab_fullscreen_accepted_ = true; |
365 return true; | 362 return true; |
366 } | 363 } |
367 | 364 |
368 return false; | 365 return false; |
369 } | 366 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 } | 416 } |
420 | 417 |
421 void FullscreenController::ToggleFullscreenModeInternal( | 418 void FullscreenController::ToggleFullscreenModeInternal( |
422 FullscreenInternalOption option) { | 419 FullscreenInternalOption option) { |
423 #if defined(OS_WIN) | 420 #if defined(OS_WIN) |
424 // When in Metro snap mode, toggling in and out of fullscreen is prevented. | 421 // When in Metro snap mode, toggling in and out of fullscreen is prevented. |
425 if (IsInMetroSnapMode()) | 422 if (IsInMetroSnapMode()) |
426 return; | 423 return; |
427 #endif | 424 #endif |
428 | 425 |
429 BrowserWindow* const window = browser()->window(); | 426 ExclusiveAccessContext* const exclusive_access_context = |
430 bool enter_fullscreen = !window->IsFullscreen(); | 427 exclusive_access_manager()->context(); |
| 428 bool enter_fullscreen = !exclusive_access_context->IsFullscreen(); |
431 | 429 |
432 // When a Mac user requests a toggle they may be toggling between | 430 // When a Mac user requests a toggle they may be toggling between |
433 // FullscreenWithoutChrome and FullscreenWithToolbar. | 431 // FullscreenWithoutChrome and FullscreenWithToolbar. |
434 if (window->IsFullscreen() && !IsWindowFullscreenForTabOrPending() && | 432 if (exclusive_access_context->IsFullscreen() && |
435 window->SupportsFullscreenWithToolbar()) { | 433 !IsWindowFullscreenForTabOrPending() && |
| 434 exclusive_access_context->SupportsFullscreenWithToolbar()) { |
436 if (option == BROWSER_WITH_TOOLBAR) { | 435 if (option == BROWSER_WITH_TOOLBAR) { |
437 enter_fullscreen = enter_fullscreen || !window->IsFullscreenWithToolbar(); | 436 enter_fullscreen = enter_fullscreen || |
| 437 !exclusive_access_context->IsFullscreenWithToolbar(); |
438 } else { | 438 } else { |
439 enter_fullscreen = enter_fullscreen || window->IsFullscreenWithToolbar(); | 439 enter_fullscreen = enter_fullscreen || |
| 440 exclusive_access_context->IsFullscreenWithToolbar(); |
440 } | 441 } |
441 } | 442 } |
442 | 443 |
443 // In kiosk mode, we always want to be fullscreen. When the browser first | 444 // In kiosk mode, we always want to be fullscreen. When the browser first |
444 // starts we're not yet fullscreen, so let the initial toggle go through. | 445 // starts we're not yet fullscreen, so let the initial toggle go through. |
445 if (chrome::IsRunningInAppMode() && window->IsFullscreen()) | 446 if (chrome::IsRunningInAppMode() && exclusive_access_context->IsFullscreen()) |
446 return; | 447 return; |
447 | 448 |
448 #if !defined(OS_MACOSX) | 449 #if !defined(OS_MACOSX) |
449 // Do not enter fullscreen mode if disallowed by pref. This prevents the user | 450 // Do not enter fullscreen mode if disallowed by pref. This prevents the user |
450 // from manually entering fullscreen mode and also disables kiosk mode on | 451 // from manually entering fullscreen mode and also disables kiosk mode on |
451 // desktop platforms. | 452 // desktop platforms. |
452 if (enter_fullscreen && | 453 if (enter_fullscreen && |
453 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) { | 454 !exclusive_access_context->GetProfile()->GetPrefs()->GetBoolean( |
| 455 prefs::kFullscreenAllowed)) { |
454 return; | 456 return; |
455 } | 457 } |
456 #endif | 458 #endif |
457 | 459 |
458 if (enter_fullscreen) | 460 if (enter_fullscreen) |
459 EnterFullscreenModeInternal(option); | 461 EnterFullscreenModeInternal(option); |
460 else | 462 else |
461 ExitFullscreenModeInternal(); | 463 ExitFullscreenModeInternal(); |
462 } | 464 } |
463 | 465 |
464 void FullscreenController::EnterFullscreenModeInternal( | 466 void FullscreenController::EnterFullscreenModeInternal( |
465 FullscreenInternalOption option) { | 467 FullscreenInternalOption option) { |
466 toggled_into_fullscreen_ = true; | 468 toggled_into_fullscreen_ = true; |
467 GURL url; | 469 GURL url; |
468 if (option == TAB) { | 470 if (option == TAB) { |
469 url = GetRequestingOrigin(); | 471 url = GetRequestingOrigin(); |
470 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW; | 472 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW; |
471 } else { | 473 } else { |
472 if (!extension_caused_fullscreen_.is_empty()) | 474 if (!extension_caused_fullscreen_.is_empty()) |
473 url = extension_caused_fullscreen_; | 475 url = extension_caused_fullscreen_; |
474 } | 476 } |
475 | 477 |
476 if (option == BROWSER) | 478 if (option == BROWSER) |
477 content::RecordAction(UserMetricsAction("ToggleFullscreen")); | 479 content::RecordAction(UserMetricsAction("ToggleFullscreen")); |
478 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions | 480 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions |
479 // from tab fullscreen out to browser with toolbar. | 481 // from tab fullscreen out to browser with toolbar. |
480 | 482 |
481 browser()->window()->EnterFullscreen( | 483 exclusive_access_manager()->context()->EnterFullscreen( |
482 url, exclusive_access_manager()->GetExclusiveAccessExitBubbleType(), | 484 url, exclusive_access_manager()->GetExclusiveAccessExitBubbleType(), |
483 option == BROWSER_WITH_TOOLBAR); | 485 option == BROWSER_WITH_TOOLBAR); |
484 | 486 |
485 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); | 487 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); |
486 | 488 |
487 // Once the window has become fullscreen it'll call back to | 489 // Once the window has become fullscreen it'll call back to |
488 // WindowFullscreenStateChanged(). We don't do this immediately as | 490 // WindowFullscreenStateChanged(). We don't do this immediately as |
489 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 491 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
490 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 492 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
491 } | 493 } |
492 | 494 |
493 void FullscreenController::ExitFullscreenModeInternal() { | 495 void FullscreenController::ExitFullscreenModeInternal() { |
494 toggled_into_fullscreen_ = false; | 496 toggled_into_fullscreen_ = false; |
495 #if defined(OS_MACOSX) | 497 #if defined(OS_MACOSX) |
496 // Mac windows report a state change instantly, and so we must also clear | 498 // Mac windows report a state change instantly, and so we must also clear |
497 // state_prior_to_tab_fullscreen_ to match them else other logic using | 499 // state_prior_to_tab_fullscreen_ to match them else other logic using |
498 // state_prior_to_tab_fullscreen_ will be incorrect. | 500 // state_prior_to_tab_fullscreen_ will be incorrect. |
499 NotifyTabExclusiveAccessLost(); | 501 NotifyTabExclusiveAccessLost(); |
500 #endif | 502 #endif |
501 browser()->window()->ExitFullscreen(); | 503 exclusive_access_manager()->context()->ExitFullscreen(); |
502 extension_caused_fullscreen_ = GURL(); | 504 extension_caused_fullscreen_ = GURL(); |
503 | 505 |
504 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); | 506 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); |
505 } | 507 } |
506 | 508 |
507 ContentSetting FullscreenController::GetFullscreenSetting() const { | 509 ContentSetting FullscreenController::GetFullscreenSetting() const { |
508 DCHECK(exclusive_access_tab()); | 510 DCHECK(exclusive_access_tab()); |
509 | 511 |
510 GURL url = GetRequestingOrigin(); | 512 GURL url = GetRequestingOrigin(); |
511 | 513 |
512 // Always ask on file:// URLs, since we can't meaningfully make the | 514 // Always ask on file:// URLs, since we can't meaningfully make the |
513 // decision stick for a particular origin. | 515 // decision stick for a particular origin. |
514 // TODO(estark): Revisit this when crbug.com/455882 is fixed. | 516 // TODO(estark): Revisit this when crbug.com/455882 is fixed. |
515 if (url.SchemeIsFile()) | 517 if (url.SchemeIsFile()) |
516 return CONTENT_SETTING_ASK; | 518 return CONTENT_SETTING_ASK; |
517 | 519 |
518 if (IsPrivilegedFullscreenForTab()) | 520 if (IsPrivilegedFullscreenForTab()) |
519 return CONTENT_SETTING_ALLOW; | 521 return CONTENT_SETTING_ALLOW; |
520 | 522 |
521 // If the permission was granted to the website with no embedder, it should | 523 // If the permission was granted to the website with no embedder, it should |
522 // always be allowed, even if embedded. | 524 // always be allowed, even if embedded. |
523 if (profile()->GetHostContentSettingsMap()->GetContentSetting( | 525 if (exclusive_access_manager() |
524 url, url, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()) == | 526 ->context() |
525 CONTENT_SETTING_ALLOW) { | 527 ->GetProfile() |
| 528 ->GetHostContentSettingsMap() |
| 529 ->GetContentSetting(url, url, CONTENT_SETTINGS_TYPE_FULLSCREEN, |
| 530 std::string()) == CONTENT_SETTING_ALLOW) { |
526 return CONTENT_SETTING_ALLOW; | 531 return CONTENT_SETTING_ALLOW; |
527 } | 532 } |
528 | 533 |
529 // See the comment above the call to |SetContentSetting()| for how the | 534 // See the comment above the call to |SetContentSetting()| for how the |
530 // requesting and embedding origins interact with each other wrt permissions. | 535 // requesting and embedding origins interact with each other wrt permissions. |
531 return profile()->GetHostContentSettingsMap()->GetContentSetting( | 536 return exclusive_access_manager() |
532 url, GetEmbeddingOrigin(), CONTENT_SETTINGS_TYPE_FULLSCREEN, | 537 ->context() |
533 std::string()); | 538 ->GetProfile() |
| 539 ->GetHostContentSettingsMap() |
| 540 ->GetContentSetting(url, GetEmbeddingOrigin(), |
| 541 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); |
534 } | 542 } |
535 | 543 |
536 bool FullscreenController::IsPrivilegedFullscreenForTab() const { | 544 bool FullscreenController::IsPrivilegedFullscreenForTab() const { |
537 const bool embedded_widget_present = | 545 const bool embedded_widget_present = |
538 exclusive_access_tab() && | 546 exclusive_access_tab() && |
539 exclusive_access_tab()->GetFullscreenRenderWidgetHostView(); | 547 exclusive_access_tab()->GetFullscreenRenderWidgetHostView(); |
540 return embedded_widget_present || is_privileged_fullscreen_for_testing_; | 548 return embedded_widget_present || is_privileged_fullscreen_for_testing_; |
541 } | 549 } |
542 | 550 |
543 void FullscreenController::SetPrivilegedFullscreenForTesting( | 551 void FullscreenController::SetPrivilegedFullscreenForTesting( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 return fullscreened_origin_; | 594 return fullscreened_origin_; |
587 | 595 |
588 return exclusive_access_tab()->GetLastCommittedURL(); | 596 return exclusive_access_tab()->GetLastCommittedURL(); |
589 } | 597 } |
590 | 598 |
591 GURL FullscreenController::GetEmbeddingOrigin() const { | 599 GURL FullscreenController::GetEmbeddingOrigin() const { |
592 DCHECK(exclusive_access_tab()); | 600 DCHECK(exclusive_access_tab()); |
593 | 601 |
594 return exclusive_access_tab()->GetLastCommittedURL(); | 602 return exclusive_access_tab()->GetLastCommittedURL(); |
595 } | 603 } |
OLD | NEW |