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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 160 |
142 bool in_browser_or_tab_fullscreen_mode; | 161 bool in_browser_or_tab_fullscreen_mode; |
143 #if defined(OS_MACOSX) | 162 #if defined(OS_MACOSX) |
144 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); | 163 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); |
145 #else | 164 #else |
146 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); | 165 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); |
147 #endif | 166 #endif |
148 | 167 |
149 if (enter_fullscreen) { | 168 if (enter_fullscreen) { |
150 fullscreened_tab_ = TabContents::FromWebContents(web_contents); | 169 fullscreened_tab_ = TabContents::FromWebContents(web_contents); |
| 170 EnterCancelFullscreenOnNavigateMode(); |
151 if (!in_browser_or_tab_fullscreen_mode) { | 171 if (!in_browser_or_tab_fullscreen_mode) { |
152 tab_caused_fullscreen_ = true; | 172 tab_caused_fullscreen_ = true; |
153 #if defined(OS_MACOSX) | 173 #if defined(OS_MACOSX) |
154 TogglePresentationModeInternal(true); | 174 TogglePresentationModeInternal(true); |
155 #else | 175 #else |
156 ToggleFullscreenModeInternal(true); | 176 ToggleFullscreenModeInternal(true); |
157 #endif | 177 #endif |
158 } else { | 178 } else { |
159 // We need to update the fullscreen exit bubble, e.g., going from browser | 179 // We need to update the fullscreen exit bubble, e.g., going from browser |
160 // fullscreen to tab fullscreen will need to show different content. | 180 // fullscreen to tab fullscreen will need to show different content. |
161 const GURL& url = web_contents->GetURL(); | 181 const GURL& url = web_contents->GetURL(); |
162 if (!tab_fullscreen_accepted_) { | 182 if (!tab_fullscreen_accepted_) { |
163 tab_fullscreen_accepted_ = | 183 tab_fullscreen_accepted_ = |
164 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | 184 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
165 } | 185 } |
166 UpdateFullscreenExitBubbleContent(); | 186 UpdateFullscreenExitBubbleContent(); |
167 } | 187 } |
168 } else { | 188 } else { |
| 189 ExitCancelFullscreenOnNavigateMode(); |
169 if (in_browser_or_tab_fullscreen_mode) { | 190 if (in_browser_or_tab_fullscreen_mode) { |
170 if (tab_caused_fullscreen_) { | 191 if (tab_caused_fullscreen_) { |
171 #if defined(OS_MACOSX) | 192 #if defined(OS_MACOSX) |
172 TogglePresentationModeInternal(true); | 193 TogglePresentationModeInternal(true); |
173 #else | 194 #else |
174 ToggleFullscreenModeInternal(true); | 195 ToggleFullscreenModeInternal(true); |
175 #endif | 196 #endif |
176 } else { | 197 } else { |
177 // If currently there is a tab in "tab fullscreen" mode and fullscreen | 198 // If currently there is a tab in "tab fullscreen" mode and fullscreen |
178 // was not caused by it (i.e., previously it was in "browser fullscreen" | 199 // 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... |
335 return true; | 356 return true; |
336 } | 357 } |
337 | 358 |
338 return false; | 359 return false; |
339 } | 360 } |
340 | 361 |
341 FullscreenController::~FullscreenController() {} | 362 FullscreenController::~FullscreenController() {} |
342 | 363 |
343 void FullscreenController::NotifyTabOfExitIfNecessary() { | 364 void FullscreenController::NotifyTabOfExitIfNecessary() { |
344 if (fullscreened_tab_) { | 365 if (fullscreened_tab_) { |
| 366 ExitCancelFullscreenOnNavigateMode(); |
345 RenderViewHost* rvh = | 367 RenderViewHost* rvh = |
346 fullscreened_tab_->web_contents()->GetRenderViewHost(); | 368 fullscreened_tab_->web_contents()->GetRenderViewHost(); |
347 fullscreened_tab_ = NULL; | 369 fullscreened_tab_ = NULL; |
348 tab_caused_fullscreen_ = false; | 370 tab_caused_fullscreen_ = false; |
349 tab_fullscreen_accepted_ = false; | 371 tab_fullscreen_accepted_ = false; |
350 if (rvh) | 372 if (rvh) |
351 rvh->ExitFullscreen(); | 373 rvh->ExitFullscreen(); |
352 } | 374 } |
353 | 375 |
354 if (mouse_lock_tab_) { | 376 if (mouse_lock_tab_) { |
355 WebContents* web_contents = mouse_lock_tab_->web_contents(); | 377 WebContents* web_contents = mouse_lock_tab_->web_contents(); |
356 if (IsMouseLockRequested()) { | 378 if (IsMouseLockRequested()) { |
357 web_contents->GotResponseToLockMouseRequest(false); | 379 web_contents->GotResponseToLockMouseRequest(false); |
358 } else if (web_contents->GetRenderViewHost() && | 380 } else if (web_contents->GetRenderViewHost() && |
359 web_contents->GetRenderViewHost()->GetView()) { | 381 web_contents->GetRenderViewHost()->GetView()) { |
360 web_contents->GetRenderViewHost()->GetView()->UnlockMouse(); | 382 web_contents->GetRenderViewHost()->GetView()->UnlockMouse(); |
361 } | 383 } |
362 mouse_lock_tab_ = NULL; | 384 mouse_lock_tab_ = NULL; |
363 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 385 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
364 } | 386 } |
365 | 387 |
366 UpdateFullscreenExitBubbleContent(); | 388 UpdateFullscreenExitBubbleContent(); |
367 } | 389 } |
368 | 390 |
| 391 void FullscreenController::EnterCancelFullscreenOnNavigateMode() { |
| 392 if (cancel_fullscreen_on_navigate_mode_) |
| 393 return; |
| 394 cancel_fullscreen_on_navigate_mode_ = true; |
| 395 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 396 content::Source<content::NavigationController>( |
| 397 &fullscreened_tab_->web_contents()->GetController())); |
| 398 } |
| 399 |
| 400 void FullscreenController::ExitCancelFullscreenOnNavigateMode() { |
| 401 if (!cancel_fullscreen_on_navigate_mode_) |
| 402 return; |
| 403 cancel_fullscreen_on_navigate_mode_ = false; |
| 404 registrar_.RemoveAll(); |
| 405 } |
| 406 |
| 407 |
369 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { | 408 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { |
370 if (tab_caused_fullscreen_) | 409 if (tab_caused_fullscreen_) |
371 ToggleFullscreenMode(); | 410 ToggleFullscreenMode(); |
372 else | 411 else |
373 NotifyTabOfExitIfNecessary(); | 412 NotifyTabOfExitIfNecessary(); |
374 } | 413 } |
375 | 414 |
376 void FullscreenController::UpdateFullscreenExitBubbleContent() { | 415 void FullscreenController::UpdateFullscreenExitBubbleContent() { |
377 GURL url; | 416 GURL url; |
378 if (fullscreened_tab_) | 417 if (fullscreened_tab_) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 window_->ExitFullscreen(); | 565 window_->ExitFullscreen(); |
527 extension_caused_fullscreen_ = GURL(); | 566 extension_caused_fullscreen_ = GURL(); |
528 } | 567 } |
529 UpdateFullscreenExitBubbleContent(); | 568 UpdateFullscreenExitBubbleContent(); |
530 | 569 |
531 // Once the window has become fullscreen it'll call back to | 570 // Once the window has become fullscreen it'll call back to |
532 // WindowFullscreenStateChanged(). We don't do this immediately as | 571 // WindowFullscreenStateChanged(). We don't do this immediately as |
533 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 572 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
534 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 573 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
535 } | 574 } |
OLD | NEW |