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