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.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents.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 "chrome/common/extensions/extension.h" |
| 19 #include "content/public/browser/navigation_details.h" | |
| 20 #include "content/public/browser/navigation_entry.h" | |
| 19 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/render_widget_host_view.h" | 23 #include "content/public/browser/render_widget_host_view.h" |
| 22 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 23 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 24 | 26 |
| 25 using content::RenderViewHost; | 27 using content::RenderViewHost; |
| 26 using content::UserMetricsAction; | 28 using content::UserMetricsAction; |
| 27 using content::WebContents; | 29 using content::WebContents; |
| 28 | 30 |
| 29 FullscreenController::FullscreenController(BrowserWindow* window, | 31 FullscreenController::FullscreenController(BrowserWindow* window, |
| 30 Profile* profile, | 32 Profile* profile, |
| 31 Browser* browser) | 33 Browser* browser) |
| 32 : window_(window), | 34 : window_(window), |
| 33 profile_(profile), | 35 profile_(profile), |
| 34 browser_(browser), | 36 browser_(browser), |
| 35 fullscreened_tab_(NULL), | 37 fullscreened_tab_(NULL), |
| 36 tab_caused_fullscreen_(false), | 38 tab_caused_fullscreen_(false), |
| 37 tab_fullscreen_accepted_(false), | 39 tab_fullscreen_accepted_(false), |
| 38 toggled_into_fullscreen_(false), | 40 toggled_into_fullscreen_(false), |
| 39 mouse_lock_tab_(NULL), | 41 mouse_lock_tab_(NULL), |
| 40 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED) { | 42 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED), |
| 43 cancel_fullscreen_on_navigate_mode_(false) { | |
| 44 } | |
| 45 | |
| 46 void FullscreenController::Observe(int type, | |
| 47 const content::NotificationSource& source, | |
| 48 const content::NotificationDetails& details) { | |
| 49 switch (type) { | |
| 50 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: | |
| 51 if (content::Details<content::LoadCommittedDetails>(details)-> | |
| 52 is_navigation_to_different_page()) { | |
| 53 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 54 } | |
| 55 break; | |
| 56 | |
| 57 default: | |
| 58 NOTREACHED() << "Got a notification we didn't register for."; | |
| 59 } | |
| 41 } | 60 } |
| 42 | 61 |
| 43 bool FullscreenController::IsFullscreenForBrowser() const { | 62 bool FullscreenController::IsFullscreenForBrowser() const { |
| 44 return window_->IsFullscreen() && !tab_caused_fullscreen_; | 63 return window_->IsFullscreen() && !tab_caused_fullscreen_; |
| 45 } | 64 } |
| 46 | 65 |
| 47 bool FullscreenController::IsFullscreenForTabOrPending() const { | 66 bool FullscreenController::IsFullscreenForTabOrPending() const { |
| 48 return fullscreened_tab_ != NULL; | 67 return fullscreened_tab_ != NULL; |
| 49 } | 68 } |
| 50 | 69 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 return; | 150 return; |
| 132 | 151 |
| 133 bool in_browser_or_tab_fullscreen_mode; | 152 bool in_browser_or_tab_fullscreen_mode; |
| 134 #if defined(OS_MACOSX) | 153 #if defined(OS_MACOSX) |
| 135 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); | 154 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); |
| 136 #else | 155 #else |
| 137 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); | 156 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); |
| 138 #endif | 157 #endif |
| 139 | 158 |
| 140 if (enter_fullscreen) { | 159 if (enter_fullscreen) { |
| 141 fullscreened_tab_ = TabContents::FromWebContents(web_contents); | 160 fullscreened_tab_ = TabContents::FromWebContents(web_contents); |
|
sky
2012/06/15 15:01:08
Do we know when we get here fullscreened_tab_ is a
koz (OOO until 15th September)
2012/06/18 02:28:10
I'm not sure. scheib, or yzshen would probably be
scheib
2012/06/18 03:58:09
As far as I can tell by inspection last Friday: I
| |
| 142 if (!in_browser_or_tab_fullscreen_mode) { | 161 if (!in_browser_or_tab_fullscreen_mode) { |
| 162 EnterCancelFullscreenOnNavigateMode(); | |
| 143 tab_caused_fullscreen_ = true; | 163 tab_caused_fullscreen_ = true; |
| 144 #if defined(OS_MACOSX) | 164 #if defined(OS_MACOSX) |
| 145 TogglePresentationModeInternal(true); | 165 TogglePresentationModeInternal(true); |
| 146 #else | 166 #else |
| 147 ToggleFullscreenModeInternal(true); | 167 ToggleFullscreenModeInternal(true); |
| 148 #endif | 168 #endif |
| 149 } else { | 169 } else { |
| 170 ExitCancelFullscreenOnNavigateMode(); | |
|
scheib
2012/06/15 16:12:31
Are you certain that we only want to be in CancelF
koz (OOO until 15th September)
2012/06/18 02:28:10
Ah yes, good point. Wouldn't I want to move the Ex
scheib
2012/06/18 03:58:09
Line 180 sounds right -- mis-reading of the } else
| |
| 150 // We need to update the fullscreen exit bubble, e.g., going from browser | 171 // We need to update the fullscreen exit bubble, e.g., going from browser |
| 151 // fullscreen to tab fullscreen will need to show different content. | 172 // fullscreen to tab fullscreen will need to show different content. |
| 152 const GURL& url = web_contents->GetURL(); | 173 const GURL& url = web_contents->GetURL(); |
| 153 if (!tab_fullscreen_accepted_) { | 174 if (!tab_fullscreen_accepted_) { |
| 154 tab_fullscreen_accepted_ = | 175 tab_fullscreen_accepted_ = |
| 155 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | 176 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
| 156 } | 177 } |
| 157 UpdateFullscreenExitBubbleContent(); | 178 UpdateFullscreenExitBubbleContent(); |
| 158 } | 179 } |
| 159 } else { | 180 } else { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 return true; | 347 return true; |
| 327 } | 348 } |
| 328 | 349 |
| 329 return false; | 350 return false; |
| 330 } | 351 } |
| 331 | 352 |
| 332 FullscreenController::~FullscreenController() {} | 353 FullscreenController::~FullscreenController() {} |
| 333 | 354 |
| 334 void FullscreenController::NotifyTabOfExitIfNecessary() { | 355 void FullscreenController::NotifyTabOfExitIfNecessary() { |
| 335 if (fullscreened_tab_) { | 356 if (fullscreened_tab_) { |
| 357 ExitCancelFullscreenOnNavigateMode(); | |
| 336 RenderViewHost* rvh = | 358 RenderViewHost* rvh = |
| 337 fullscreened_tab_->web_contents()->GetRenderViewHost(); | 359 fullscreened_tab_->web_contents()->GetRenderViewHost(); |
| 338 fullscreened_tab_ = NULL; | 360 fullscreened_tab_ = NULL; |
| 339 tab_caused_fullscreen_ = false; | 361 tab_caused_fullscreen_ = false; |
| 340 tab_fullscreen_accepted_ = false; | 362 tab_fullscreen_accepted_ = false; |
| 341 if (rvh) | 363 if (rvh) |
| 342 rvh->ExitFullscreen(); | 364 rvh->ExitFullscreen(); |
| 343 } | 365 } |
| 344 | 366 |
| 345 if (mouse_lock_tab_) { | 367 if (mouse_lock_tab_) { |
| 346 WebContents* web_contents = mouse_lock_tab_->web_contents(); | 368 WebContents* web_contents = mouse_lock_tab_->web_contents(); |
| 347 if (IsMouseLockRequested()) { | 369 if (IsMouseLockRequested()) { |
| 348 web_contents->GotResponseToLockMouseRequest(false); | 370 web_contents->GotResponseToLockMouseRequest(false); |
| 349 } else if (web_contents->GetRenderViewHost() && | 371 } else if (web_contents->GetRenderViewHost() && |
| 350 web_contents->GetRenderViewHost()->GetView()) { | 372 web_contents->GetRenderViewHost()->GetView()) { |
| 351 web_contents->GetRenderViewHost()->GetView()->UnlockMouse(); | 373 web_contents->GetRenderViewHost()->GetView()->UnlockMouse(); |
| 352 } | 374 } |
| 353 mouse_lock_tab_ = NULL; | 375 mouse_lock_tab_ = NULL; |
| 354 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 376 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| 355 } | 377 } |
| 356 | 378 |
| 357 UpdateFullscreenExitBubbleContent(); | 379 UpdateFullscreenExitBubbleContent(); |
| 358 } | 380 } |
| 359 | 381 |
| 382 void FullscreenController::EnterCancelFullscreenOnNavigateMode() { | |
| 383 if (cancel_fullscreen_on_navigate_mode_) | |
| 384 return; | |
| 385 cancel_fullscreen_on_navigate_mode_ = true; | |
| 386 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 387 content::Source<content::NavigationController>( | |
| 388 &fullscreened_tab_->web_contents()->GetController())); | |
| 389 } | |
| 390 | |
| 391 void FullscreenController::ExitCancelFullscreenOnNavigateMode() { | |
| 392 if (!cancel_fullscreen_on_navigate_mode_) | |
| 393 return; | |
| 394 cancel_fullscreen_on_navigate_mode_ = false; | |
| 395 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
|
sky
2012/06/15 15:01:08
I think you should removeall here. Less error pron
koz (OOO until 15th September)
2012/06/18 02:28:10
Done.
| |
| 396 content::Source<content::NavigationController>( | |
| 397 &fullscreened_tab_->web_contents()->GetController())); | |
| 398 } | |
| 399 | |
| 400 | |
| 360 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { | 401 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { |
| 361 if (tab_caused_fullscreen_) | 402 if (tab_caused_fullscreen_) |
| 362 ToggleFullscreenMode(); | 403 ToggleFullscreenMode(); |
| 363 else | 404 else |
| 364 NotifyTabOfExitIfNecessary(); | 405 NotifyTabOfExitIfNecessary(); |
| 365 } | 406 } |
| 366 | 407 |
| 367 void FullscreenController::UpdateFullscreenExitBubbleContent() { | 408 void FullscreenController::UpdateFullscreenExitBubbleContent() { |
| 368 GURL url; | 409 GURL url; |
| 369 if (fullscreened_tab_) | 410 if (fullscreened_tab_) |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 window_->ExitFullscreen(); | 559 window_->ExitFullscreen(); |
| 519 extension_caused_fullscreen_ = GURL(); | 560 extension_caused_fullscreen_ = GURL(); |
| 520 } | 561 } |
| 521 UpdateFullscreenExitBubbleContent(); | 562 UpdateFullscreenExitBubbleContent(); |
| 522 | 563 |
| 523 // Once the window has become fullscreen it'll call back to | 564 // Once the window has become fullscreen it'll call back to |
| 524 // WindowFullscreenStateChanged(). We don't do this immediately as | 565 // WindowFullscreenStateChanged(). We don't do this immediately as |
| 525 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 566 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
| 526 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 567 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
| 527 } | 568 } |
| OLD | NEW |