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() |
| 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 Loading... |
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 Loading... |
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 Loading... |
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 29 matching lines...) Expand all Loading... |
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 GURL requester = GetRequestingOrigin(); | 346 GURL requester = GetRequestingOrigin(); |
344 GURL embedder = GetEmbeddingOrigin(); | 347 GURL embedder = GetEmbeddingOrigin(); |
345 ContentSettingsPattern primary_pattern = | 348 ContentSettingsPattern primary_pattern = |
346 ContentSettingsPattern::FromURLNoWildcard(requester); | 349 ContentSettingsPattern::FromURLNoWildcard(requester); |
347 ContentSettingsPattern secondary_pattern = | 350 ContentSettingsPattern secondary_pattern = |
348 ContentSettingsPattern::FromURLNoWildcard(embedder); | 351 ContentSettingsPattern::FromURLNoWildcard(embedder); |
349 | 352 |
350 // ContentSettings requires valid patterns and the patterns might be invalid | 353 // ContentSettings requires valid patterns and the patterns might be invalid |
351 // in some edge cases like if the current frame is about:blank. | 354 // in some edge cases like if the current frame is about:blank. |
352 // | |
353 // Do not store preference on file:// URLs, they don't have a clean | 355 // Do not store preference on file:// URLs, they don't have a clean |
354 // origin policy. | 356 // origin policy. |
355 // TODO(estark): Revisit this when crbug.com/455882 is fixed. | 357 // TODO(estark): Revisit this when crbug.com/455882 is fixed. |
356 if (!requester.SchemeIsFile() && !embedder.SchemeIsFile() && | 358 if (!requester.SchemeIsFile() && !embedder.SchemeIsFile() && |
357 primary_pattern.IsValid() && secondary_pattern.IsValid()) { | 359 primary_pattern.IsValid() && secondary_pattern.IsValid()) { |
358 HostContentSettingsMap* settings_map = | 360 HostContentSettingsMap* settings_map = exclusive_access_manager() |
359 profile()->GetHostContentSettingsMap(); | 361 ->exclusive_access_context() |
| 362 ->GetProfile() |
| 363 ->GetHostContentSettingsMap(); |
360 settings_map->SetContentSetting( | 364 settings_map->SetContentSetting( |
361 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_FULLSCREEN, | 365 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_FULLSCREEN, |
362 std::string(), CONTENT_SETTING_ALLOW); | 366 std::string(), CONTENT_SETTING_ALLOW); |
363 } | 367 } |
364 tab_fullscreen_accepted_ = true; | 368 tab_fullscreen_accepted_ = true; |
365 return true; | 369 return true; |
366 } | 370 } |
367 | 371 |
368 return false; | 372 return false; |
369 } | 373 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 } | 423 } |
420 | 424 |
421 void FullscreenController::ToggleFullscreenModeInternal( | 425 void FullscreenController::ToggleFullscreenModeInternal( |
422 FullscreenInternalOption option) { | 426 FullscreenInternalOption option) { |
423 #if defined(OS_WIN) | 427 #if defined(OS_WIN) |
424 // When in Metro snap mode, toggling in and out of fullscreen is prevented. | 428 // When in Metro snap mode, toggling in and out of fullscreen is prevented. |
425 if (IsInMetroSnapMode()) | 429 if (IsInMetroSnapMode()) |
426 return; | 430 return; |
427 #endif | 431 #endif |
428 | 432 |
429 BrowserWindow* const window = browser()->window(); | 433 ExclusiveAccessContext* const exclusive_access_context = |
430 bool enter_fullscreen = !window->IsFullscreen(); | 434 exclusive_access_manager()->exclusive_access_context(); |
| 435 bool enter_fullscreen = !exclusive_access_context->IsFullscreen(); |
431 | 436 |
432 // When a Mac user requests a toggle they may be toggling between | 437 // When a Mac user requests a toggle they may be toggling between |
433 // FullscreenWithoutChrome and FullscreenWithToolbar. | 438 // FullscreenWithoutChrome and FullscreenWithToolbar. |
434 if (window->IsFullscreen() && !IsWindowFullscreenForTabOrPending() && | 439 if (exclusive_access_context->IsFullscreen() && |
435 window->SupportsFullscreenWithToolbar()) { | 440 !IsWindowFullscreenForTabOrPending() && |
| 441 exclusive_access_context->SupportsFullscreenWithToolbar()) { |
436 if (option == BROWSER_WITH_TOOLBAR) { | 442 if (option == BROWSER_WITH_TOOLBAR) { |
437 enter_fullscreen = enter_fullscreen || !window->IsFullscreenWithToolbar(); | 443 enter_fullscreen = enter_fullscreen || |
| 444 !exclusive_access_context->IsFullscreenWithToolbar(); |
438 } else { | 445 } else { |
439 enter_fullscreen = enter_fullscreen || window->IsFullscreenWithToolbar(); | 446 enter_fullscreen = enter_fullscreen || |
| 447 exclusive_access_context->IsFullscreenWithToolbar(); |
440 } | 448 } |
441 } | 449 } |
442 | 450 |
443 // In kiosk mode, we always want to be fullscreen. When the browser first | 451 // 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. | 452 // starts we're not yet fullscreen, so let the initial toggle go through. |
445 if (chrome::IsRunningInAppMode() && window->IsFullscreen()) | 453 if (chrome::IsRunningInAppMode() && exclusive_access_context->IsFullscreen()) |
446 return; | 454 return; |
447 | 455 |
448 #if !defined(OS_MACOSX) | 456 #if !defined(OS_MACOSX) |
449 // Do not enter fullscreen mode if disallowed by pref. This prevents the user | 457 // 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 | 458 // from manually entering fullscreen mode and also disables kiosk mode on |
451 // desktop platforms. | 459 // desktop platforms. |
452 if (enter_fullscreen && | 460 if (enter_fullscreen && |
453 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) { | 461 !exclusive_access_context->GetProfile()->GetPrefs()->GetBoolean( |
| 462 prefs::kFullscreenAllowed)) { |
454 return; | 463 return; |
455 } | 464 } |
456 #endif | 465 #endif |
457 | 466 |
458 if (enter_fullscreen) | 467 if (enter_fullscreen) |
459 EnterFullscreenModeInternal(option); | 468 EnterFullscreenModeInternal(option); |
460 else | 469 else |
461 ExitFullscreenModeInternal(); | 470 ExitFullscreenModeInternal(); |
462 } | 471 } |
463 | 472 |
464 void FullscreenController::EnterFullscreenModeInternal( | 473 void FullscreenController::EnterFullscreenModeInternal( |
465 FullscreenInternalOption option) { | 474 FullscreenInternalOption option) { |
466 toggled_into_fullscreen_ = true; | 475 toggled_into_fullscreen_ = true; |
467 GURL url; | 476 GURL url; |
468 if (option == TAB) { | 477 if (option == TAB) { |
469 url = GetRequestingOrigin(); | 478 url = GetRequestingOrigin(); |
470 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW; | 479 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW; |
471 } else { | 480 } else { |
472 if (!extension_caused_fullscreen_.is_empty()) | 481 if (!extension_caused_fullscreen_.is_empty()) |
473 url = extension_caused_fullscreen_; | 482 url = extension_caused_fullscreen_; |
474 } | 483 } |
475 | 484 |
476 if (option == BROWSER) | 485 if (option == BROWSER) |
477 content::RecordAction(UserMetricsAction("ToggleFullscreen")); | 486 content::RecordAction(UserMetricsAction("ToggleFullscreen")); |
478 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions | 487 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions |
479 // from tab fullscreen out to browser with toolbar. | 488 // from tab fullscreen out to browser with toolbar. |
480 | 489 |
481 browser()->window()->EnterFullscreen( | 490 exclusive_access_manager()->exclusive_access_context()->EnterFullscreen( |
482 url, exclusive_access_manager()->GetExclusiveAccessExitBubbleType(), | 491 url, exclusive_access_manager()->GetExclusiveAccessExitBubbleType(), |
483 option == BROWSER_WITH_TOOLBAR); | 492 option == BROWSER_WITH_TOOLBAR); |
484 | 493 |
485 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); | 494 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); |
486 | 495 |
487 // Once the window has become fullscreen it'll call back to | 496 // Once the window has become fullscreen it'll call back to |
488 // WindowFullscreenStateChanged(). We don't do this immediately as | 497 // WindowFullscreenStateChanged(). We don't do this immediately as |
489 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 498 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
490 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 499 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
491 } | 500 } |
492 | 501 |
493 void FullscreenController::ExitFullscreenModeInternal() { | 502 void FullscreenController::ExitFullscreenModeInternal() { |
494 toggled_into_fullscreen_ = false; | 503 toggled_into_fullscreen_ = false; |
495 #if defined(OS_MACOSX) | 504 #if defined(OS_MACOSX) |
496 // Mac windows report a state change instantly, and so we must also clear | 505 // 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 | 506 // state_prior_to_tab_fullscreen_ to match them else other logic using |
498 // state_prior_to_tab_fullscreen_ will be incorrect. | 507 // state_prior_to_tab_fullscreen_ will be incorrect. |
499 NotifyTabExclusiveAccessLost(); | 508 NotifyTabExclusiveAccessLost(); |
500 #endif | 509 #endif |
501 browser()->window()->ExitFullscreen(); | 510 exclusive_access_manager()->exclusive_access_context()->ExitFullscreen(); |
502 extension_caused_fullscreen_ = GURL(); | 511 extension_caused_fullscreen_ = GURL(); |
503 | 512 |
504 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); | 513 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); |
505 } | 514 } |
506 | 515 |
507 ContentSetting FullscreenController::GetFullscreenSetting() const { | 516 ContentSetting FullscreenController::GetFullscreenSetting() const { |
508 DCHECK(exclusive_access_tab()); | 517 DCHECK(exclusive_access_tab()); |
509 | 518 |
510 GURL url = GetRequestingOrigin(); | 519 GURL url = GetRequestingOrigin(); |
511 | 520 |
512 // Always ask on file:// URLs, since we can't meaningfully make the | 521 // Always ask on file:// URLs, since we can't meaningfully make the |
513 // decision stick for a particular origin. | 522 // decision stick for a particular origin. |
514 // TODO(estark): Revisit this when crbug.com/455882 is fixed. | 523 // TODO(estark): Revisit this when crbug.com/455882 is fixed. |
515 if (url.SchemeIsFile()) | 524 if (url.SchemeIsFile()) |
516 return CONTENT_SETTING_ASK; | 525 return CONTENT_SETTING_ASK; |
517 | 526 |
518 if (IsPrivilegedFullscreenForTab()) | 527 if (IsPrivilegedFullscreenForTab()) |
519 return CONTENT_SETTING_ALLOW; | 528 return CONTENT_SETTING_ALLOW; |
520 | 529 |
521 // If the permission was granted to the website with no embedder, it should | 530 // If the permission was granted to the website with no embedder, it should |
522 // always be allowed, even if embedded. | 531 // always be allowed, even if embedded. |
523 if (profile()->GetHostContentSettingsMap()->GetContentSetting( | 532 if (exclusive_access_manager() |
524 url, url, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()) == | 533 ->exclusive_access_context() |
525 CONTENT_SETTING_ALLOW) { | 534 ->GetProfile() |
| 535 ->GetHostContentSettingsMap() |
| 536 ->GetContentSetting(url, url, CONTENT_SETTINGS_TYPE_FULLSCREEN, |
| 537 std::string()) == CONTENT_SETTING_ALLOW) { |
526 return CONTENT_SETTING_ALLOW; | 538 return CONTENT_SETTING_ALLOW; |
527 } | 539 } |
528 | 540 |
529 // See the comment above the call to |SetContentSetting()| for how the | 541 // See the comment above the call to |SetContentSetting()| for how the |
530 // requesting and embedding origins interact with each other wrt permissions. | 542 // requesting and embedding origins interact with each other wrt permissions. |
531 return profile()->GetHostContentSettingsMap()->GetContentSetting( | 543 return exclusive_access_manager() |
532 url, GetEmbeddingOrigin(), CONTENT_SETTINGS_TYPE_FULLSCREEN, | 544 ->exclusive_access_context() |
533 std::string()); | 545 ->GetProfile() |
| 546 ->GetHostContentSettingsMap() |
| 547 ->GetContentSetting(url, GetEmbeddingOrigin(), |
| 548 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); |
534 } | 549 } |
535 | 550 |
536 bool FullscreenController::IsPrivilegedFullscreenForTab() const { | 551 bool FullscreenController::IsPrivilegedFullscreenForTab() const { |
537 const bool embedded_widget_present = | 552 const bool embedded_widget_present = |
538 exclusive_access_tab() && | 553 exclusive_access_tab() && |
539 exclusive_access_tab()->GetFullscreenRenderWidgetHostView(); | 554 exclusive_access_tab()->GetFullscreenRenderWidgetHostView(); |
540 return embedded_widget_present || is_privileged_fullscreen_for_testing_; | 555 return embedded_widget_present || is_privileged_fullscreen_for_testing_; |
541 } | 556 } |
542 | 557 |
543 void FullscreenController::SetPrivilegedFullscreenForTesting( | 558 void FullscreenController::SetPrivilegedFullscreenForTesting( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 return fullscreened_origin_; | 601 return fullscreened_origin_; |
587 | 602 |
588 return exclusive_access_tab()->GetLastCommittedURL(); | 603 return exclusive_access_tab()->GetLastCommittedURL(); |
589 } | 604 } |
590 | 605 |
591 GURL FullscreenController::GetEmbeddingOrigin() const { | 606 GURL FullscreenController::GetEmbeddingOrigin() const { |
592 DCHECK(exclusive_access_tab()); | 607 DCHECK(exclusive_access_tab()); |
593 | 608 |
594 return exclusive_access_tab()->GetLastCommittedURL(); | 609 return exclusive_access_tab()->GetLastCommittedURL(); |
595 } | 610 } |
OLD | NEW |