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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
| 161 EnterCancelFullscreenOnNavigateMode(); |
142 if (!in_browser_or_tab_fullscreen_mode) { | 162 if (!in_browser_or_tab_fullscreen_mode) { |
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 { |
150 // We need to update the fullscreen exit bubble, e.g., going from browser | 170 // We need to update the fullscreen exit bubble, e.g., going from browser |
151 // fullscreen to tab fullscreen will need to show different content. | 171 // fullscreen to tab fullscreen will need to show different content. |
152 const GURL& url = web_contents->GetURL(); | 172 const GURL& url = web_contents->GetURL(); |
153 if (!tab_fullscreen_accepted_) { | 173 if (!tab_fullscreen_accepted_) { |
154 tab_fullscreen_accepted_ = | 174 tab_fullscreen_accepted_ = |
155 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | 175 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
156 } | 176 } |
157 UpdateFullscreenExitBubbleContent(); | 177 UpdateFullscreenExitBubbleContent(); |
158 } | 178 } |
159 } else { | 179 } else { |
| 180 ExitCancelFullscreenOnNavigateMode(); |
160 if (in_browser_or_tab_fullscreen_mode) { | 181 if (in_browser_or_tab_fullscreen_mode) { |
161 if (tab_caused_fullscreen_) { | 182 if (tab_caused_fullscreen_) { |
162 #if defined(OS_MACOSX) | 183 #if defined(OS_MACOSX) |
163 TogglePresentationModeInternal(true); | 184 TogglePresentationModeInternal(true); |
164 #else | 185 #else |
165 ToggleFullscreenModeInternal(true); | 186 ToggleFullscreenModeInternal(true); |
166 #endif | 187 #endif |
167 } else { | 188 } else { |
168 // If currently there is a tab in "tab fullscreen" mode and fullscreen | 189 // If currently there is a tab in "tab fullscreen" mode and fullscreen |
169 // was not caused by it (i.e., previously it was in "browser fullscreen" | 190 // was not caused by it (i.e., previously it was in "browser fullscreen" |
(...skipping 156 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_.RemoveAll(); |
| 396 } |
| 397 |
| 398 |
360 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { | 399 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { |
361 if (tab_caused_fullscreen_) | 400 if (tab_caused_fullscreen_) |
362 ToggleFullscreenMode(); | 401 ToggleFullscreenMode(); |
363 else | 402 else |
364 NotifyTabOfExitIfNecessary(); | 403 NotifyTabOfExitIfNecessary(); |
365 } | 404 } |
366 | 405 |
367 void FullscreenController::UpdateFullscreenExitBubbleContent() { | 406 void FullscreenController::UpdateFullscreenExitBubbleContent() { |
368 GURL url; | 407 GURL url; |
369 if (fullscreened_tab_) | 408 if (fullscreened_tab_) |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 window_->ExitFullscreen(); | 557 window_->ExitFullscreen(); |
519 extension_caused_fullscreen_ = GURL(); | 558 extension_caused_fullscreen_ = GURL(); |
520 } | 559 } |
521 UpdateFullscreenExitBubbleContent(); | 560 UpdateFullscreenExitBubbleContent(); |
522 | 561 |
523 // Once the window has become fullscreen it'll call back to | 562 // Once the window has become fullscreen it'll call back to |
524 // WindowFullscreenStateChanged(). We don't do this immediately as | 563 // WindowFullscreenStateChanged(). We don't do this immediately as |
525 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 564 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
526 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 565 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
527 } | 566 } |
OLD | NEW |