Chromium Code Reviews| 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/fullscreen_controller.h" | 5 #include "chrome/browser/ui/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.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 11 #include "chrome/browser/download/download_shelf.h" | 11 #include "chrome/browser/download/download_shelf.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/extensions/extension.h" | |
| 18 #include "content/browser/renderer_host/render_view_host.h" | 19 #include "content/browser/renderer_host/render_view_host.h" |
| 19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 22 | 23 |
| 23 using content::UserMetricsAction; | 24 using content::UserMetricsAction; |
| 24 using content::WebContents; | 25 using content::WebContents; |
| 25 | 26 |
| 26 FullscreenController::FullscreenController(BrowserWindow* window, | 27 FullscreenController::FullscreenController(BrowserWindow* window, |
| 27 Profile* profile, | 28 Profile* profile, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); | 104 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); |
| 104 #else | 105 #else |
| 105 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); | 106 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); |
| 106 #endif | 107 #endif |
| 107 | 108 |
| 108 if (enter_fullscreen) { | 109 if (enter_fullscreen) { |
| 109 fullscreened_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); | 110 fullscreened_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); |
| 110 if (!in_browser_or_tab_fullscreen_mode) { | 111 if (!in_browser_or_tab_fullscreen_mode) { |
| 111 tab_caused_fullscreen_ = true; | 112 tab_caused_fullscreen_ = true; |
| 112 #if defined(OS_MACOSX) | 113 #if defined(OS_MACOSX) |
| 113 TogglePresentationMode(true); | 114 TogglePresentationModeInternal(true); |
| 114 #else | 115 #else |
| 115 ToggleFullscreenMode(true); | 116 ToggleFullscreenModeInternal(true); |
| 116 #endif | 117 #endif |
| 117 } else { | 118 } else { |
| 118 // We need to update the fullscreen exit bubble, e.g., going from browser | 119 // We need to update the fullscreen exit bubble, e.g., going from browser |
| 119 // fullscreen to tab fullscreen will need to show different content. | 120 // fullscreen to tab fullscreen will need to show different content. |
| 120 const GURL& url = tab->GetURL(); | 121 const GURL& url = tab->GetURL(); |
| 121 if (!tab_fullscreen_accepted_) { | 122 if (!tab_fullscreen_accepted_) { |
| 122 tab_fullscreen_accepted_ = | 123 tab_fullscreen_accepted_ = |
| 123 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | 124 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
| 124 } | 125 } |
| 125 UpdateFullscreenExitBubbleContent(); | 126 UpdateFullscreenExitBubbleContent(); |
| 126 } | 127 } |
| 127 } else { | 128 } else { |
| 128 if (in_browser_or_tab_fullscreen_mode) { | 129 if (in_browser_or_tab_fullscreen_mode) { |
| 129 if (tab_caused_fullscreen_) { | 130 if (tab_caused_fullscreen_) { |
| 130 #if defined(OS_MACOSX) | 131 #if defined(OS_MACOSX) |
| 131 TogglePresentationMode(true); | 132 TogglePresentationModeInternal(true); |
| 132 #else | 133 #else |
| 133 ToggleFullscreenMode(true); | 134 ToggleFullscreenModeInternal(true); |
| 134 #endif | 135 #endif |
| 135 } else { | 136 } else { |
| 136 // If currently there is a tab in "tab fullscreen" mode and fullscreen | 137 // If currently there is a tab in "tab fullscreen" mode and fullscreen |
| 137 // was not caused by it (i.e., previously it was in "browser fullscreen" | 138 // was not caused by it (i.e., previously it was in "browser fullscreen" |
| 138 // mode), we need to switch back to "browser fullscreen" mode. In this | 139 // mode), we need to switch back to "browser fullscreen" mode. In this |
| 139 // case, all we have to do is notifying the tab that it has exited "tab | 140 // case, all we have to do is notifying the tab that it has exited "tab |
| 140 // fullscreen" mode. | 141 // fullscreen" mode. |
| 141 NotifyTabOfFullscreenExitIfNecessary(); | 142 NotifyTabOfFullscreenExitIfNecessary(); |
| 142 } | 143 } |
| 143 } | 144 } |
| 144 } | 145 } |
| 145 } | 146 } |
| 146 | 147 |
| 147 #if defined(OS_MACOSX) | 148 #if defined(OS_MACOSX) |
| 148 void FullscreenController::TogglePresentationMode(bool for_tab) { | 149 void FullscreenController::TogglePresentationMode() { |
| 150 TogglePresentationModeInternal(false); | |
| 151 } | |
| 152 | |
| 153 void FullscreenController::TogglePresentationModeInternal(bool for_tab) { | |
| 149 bool entering_fullscreen = !window_->InPresentationMode(); | 154 bool entering_fullscreen = !window_->InPresentationMode(); |
| 150 GURL url; | 155 GURL url; |
| 151 if (for_tab) { | 156 if (for_tab) { |
| 152 url = browser_->GetSelectedWebContents()->GetURL(); | 157 url = browser_->GetSelectedWebContents()->GetURL(); |
| 153 tab_fullscreen_accepted_ = entering_fullscreen && | 158 tab_fullscreen_accepted_ = entering_fullscreen && |
| 154 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | 159 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
| 155 } | 160 } |
| 156 if (entering_fullscreen) | 161 if (entering_fullscreen) |
| 157 window_->EnterPresentationMode(url, GetFullscreenExitBubbleType()); | 162 window_->EnterPresentationMode(url, GetFullscreenExitBubbleType()); |
| 158 else | 163 else |
| 159 window_->ExitPresentationMode(); | 164 window_->ExitPresentationMode(); |
| 160 WindowFullscreenStateChanged(); | 165 WindowFullscreenStateChanged(); |
| 161 } | 166 } |
| 162 #endif | 167 #endif |
| 163 | 168 |
| 169 void FullscreenController::ToggleFullscreenMode() { | |
|
Ben Goodger (Google)
2012/02/09 19:32:49
In adding these functions you've made the order of
hashimoto
2012/02/10 05:09:32
Sorry, fixed.
| |
| 170 extension_caused_fullscreen_ = NULL; | |
| 171 ToggleFullscreenModeInternal(false); | |
| 172 } | |
| 173 | |
| 174 void FullscreenController::ToggleFullscreenModeWithExtension( | |
| 175 const Extension& extension) { | |
| 176 extension_caused_fullscreen_ = &extension; | |
| 177 ToggleFullscreenModeInternal(false); | |
| 178 } | |
| 179 | |
| 164 // TODO(koz): Change |for_tab| to an enum. | 180 // TODO(koz): Change |for_tab| to an enum. |
| 165 void FullscreenController::ToggleFullscreenMode(bool for_tab) { | 181 void FullscreenController::ToggleFullscreenModeInternal(bool for_tab) { |
| 166 bool entering_fullscreen = !window_->IsFullscreen(); | 182 bool entering_fullscreen = !window_->IsFullscreen(); |
| 167 | 183 |
| 168 #if !defined(OS_MACOSX) | 184 #if !defined(OS_MACOSX) |
| 169 // In kiosk mode, we always want to be fullscreen. When the browser first | 185 // In kiosk mode, we always want to be fullscreen. When the browser first |
| 170 // starts we're not yet fullscreen, so let the initial toggle go through. | 186 // starts we're not yet fullscreen, so let the initial toggle go through. |
| 171 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && | 187 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && |
| 172 window_->IsFullscreen()) | 188 window_->IsFullscreen()) |
| 173 return; | 189 return; |
| 174 #endif | 190 #endif |
| 175 | 191 |
| 176 GURL url; | 192 GURL url; |
| 177 if (for_tab) { | 193 if (for_tab) { |
| 178 url = browser_->GetSelectedWebContents()->GetURL(); | 194 url = browser_->GetSelectedWebContents()->GetURL(); |
| 179 tab_fullscreen_accepted_ = entering_fullscreen && | 195 tab_fullscreen_accepted_ = entering_fullscreen && |
| 180 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | 196 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
| 181 } else { | 197 } else { |
| 198 if (extension_caused_fullscreen_) | |
| 199 url = extension_caused_fullscreen_->url(); | |
| 182 content::RecordAction(UserMetricsAction("ToggleFullscreen")); | 200 content::RecordAction(UserMetricsAction("ToggleFullscreen")); |
| 183 } | 201 } |
| 184 if (entering_fullscreen) | 202 if (entering_fullscreen) { |
| 185 window_->EnterFullscreen(url, GetFullscreenExitBubbleType()); | 203 window_->EnterFullscreen(url, GetFullscreenExitBubbleType()); |
| 186 else | 204 } else { |
| 187 window_->ExitFullscreen(); | 205 window_->ExitFullscreen(); |
| 206 extension_caused_fullscreen_ = NULL; | |
| 207 } | |
| 188 | 208 |
| 189 // Once the window has become fullscreen it'll call back to | 209 // Once the window has become fullscreen it'll call back to |
| 190 // WindowFullscreenStateChanged(). We don't do this immediately as | 210 // WindowFullscreenStateChanged(). We don't do this immediately as |
| 191 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 211 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
| 192 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 212 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
| 193 | 213 |
| 194 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates | 214 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates |
| 195 // the necessary state of the frame. | 215 // the necessary state of the frame. |
| 196 #if defined(OS_MACOSX) | 216 #if defined(OS_MACOSX) |
| 197 WindowFullscreenStateChanged(); | 217 WindowFullscreenStateChanged(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 fullscreened_tab_ = NULL; | 327 fullscreened_tab_ = NULL; |
| 308 tab_caused_fullscreen_ = false; | 328 tab_caused_fullscreen_ = false; |
| 309 tab_fullscreen_accepted_ = false; | 329 tab_fullscreen_accepted_ = false; |
| 310 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 330 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| 311 | 331 |
| 312 UpdateFullscreenExitBubbleContent(); | 332 UpdateFullscreenExitBubbleContent(); |
| 313 } | 333 } |
| 314 | 334 |
| 315 void FullscreenController::ExitTabbedFullscreenModeIfNecessary() { | 335 void FullscreenController::ExitTabbedFullscreenModeIfNecessary() { |
| 316 if (tab_caused_fullscreen_) | 336 if (tab_caused_fullscreen_) |
| 317 ToggleFullscreenMode(false); | 337 ToggleFullscreenMode(); |
| 318 else | 338 else |
| 319 NotifyTabOfFullscreenExitIfNecessary(); | 339 NotifyTabOfFullscreenExitIfNecessary(); |
| 320 } | 340 } |
| 321 | 341 |
| 322 void FullscreenController::UpdateFullscreenExitBubbleContent() { | 342 void FullscreenController::UpdateFullscreenExitBubbleContent() { |
| 323 GURL url; | 343 GURL url; |
| 324 if (fullscreened_tab_) | 344 if (fullscreened_tab_) |
| 325 url = fullscreened_tab_->web_contents()->GetURL(); | 345 url = fullscreened_tab_->web_contents()->GetURL(); |
| 346 else if (extension_caused_fullscreen_) | |
| 347 url = extension_caused_fullscreen_->url(); | |
| 326 | 348 |
| 327 window_->UpdateFullscreenExitBubbleContent(url, | 349 window_->UpdateFullscreenExitBubbleContent(url, |
| 328 GetFullscreenExitBubbleType()); | 350 GetFullscreenExitBubbleType()); |
| 329 } | 351 } |
| 330 | 352 |
| 331 void FullscreenController::NotifyFullscreenChange() { | 353 void FullscreenController::NotifyFullscreenChange() { |
| 332 content::NotificationService::current()->Notify( | 354 content::NotificationService::current()->Notify( |
| 333 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 355 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| 334 content::Source<FullscreenController>(this), | 356 content::Source<FullscreenController>(this), |
| 335 content::NotificationService::NoDetails()); | 357 content::NotificationService::NoDetails()); |
| 336 } | 358 } |
| 337 | 359 |
| 338 FullscreenExitBubbleType | 360 FullscreenExitBubbleType FullscreenController::GetFullscreenExitBubbleType() |
| 339 FullscreenController::GetFullscreenExitBubbleType() const { | 361 const { |
| 340 if (!fullscreened_tab_) { | 362 if (!fullscreened_tab_) { |
| 341 DCHECK_EQ(MOUSELOCK_NOT_REQUESTED, mouse_lock_state_); | 363 DCHECK_EQ(MOUSELOCK_NOT_REQUESTED, mouse_lock_state_); |
| 342 return FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | 364 return extension_caused_fullscreen_ ? |
| 365 FEB_TYPE_BROWSER_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION : | |
| 366 FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | |
| 343 } | 367 } |
| 344 if (fullscreened_tab_ && !tab_fullscreen_accepted_) { | 368 if (fullscreened_tab_ && !tab_fullscreen_accepted_) { |
| 345 DCHECK_NE(MOUSELOCK_ACCEPTED, mouse_lock_state_); | 369 DCHECK_NE(MOUSELOCK_ACCEPTED, mouse_lock_state_); |
| 346 return mouse_lock_state_ == MOUSELOCK_REQUESTED ? | 370 return mouse_lock_state_ == MOUSELOCK_REQUESTED ? |
| 347 FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS : FEB_TYPE_FULLSCREEN_BUTTONS; | 371 FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS : FEB_TYPE_FULLSCREEN_BUTTONS; |
| 348 } | 372 } |
| 349 if (mouse_lock_state_ == MOUSELOCK_REQUESTED) | 373 if (mouse_lock_state_ == MOUSELOCK_REQUESTED) |
| 350 return FEB_TYPE_MOUSELOCK_BUTTONS; | 374 return FEB_TYPE_MOUSELOCK_BUTTONS; |
| 351 return mouse_lock_state_ == MOUSELOCK_ACCEPTED ? | 375 return mouse_lock_state_ == MOUSELOCK_ACCEPTED ? |
| 352 FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION : | 376 FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION : |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 365 | 389 |
| 366 ContentSetting | 390 ContentSetting |
| 367 FullscreenController::GetMouseLockSetting(const GURL& url) const { | 391 FullscreenController::GetMouseLockSetting(const GURL& url) const { |
| 368 if (url.SchemeIsFile()) | 392 if (url.SchemeIsFile()) |
| 369 return CONTENT_SETTING_ALLOW; | 393 return CONTENT_SETTING_ALLOW; |
| 370 | 394 |
| 371 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 395 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); |
| 372 return settings_map->GetContentSetting(url, url, | 396 return settings_map->GetContentSetting(url, url, |
| 373 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); | 397 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); |
| 374 } | 398 } |
| OLD | NEW |