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/fullscreen_controller.h" | 5 #include "chrome/browser/ui/fullscreen/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_tabstrip.h" | 14 #include "chrome/browser/ui/browser_tabstrip.h" |
15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.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" | 19 #include "content/public/browser/navigation_details.h" |
20 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
23 #include "content/public/browser/render_widget_host_view.h" | 23 #include "content/public/browser/render_widget_host_view.h" |
24 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
26 | 26 |
| 27 #if defined(OS_MACOSX) |
| 28 #include "base/mac/mac_util.h" |
| 29 #endif |
| 30 |
27 using content::RenderViewHost; | 31 using content::RenderViewHost; |
28 using content::UserMetricsAction; | 32 using content::UserMetricsAction; |
29 using content::WebContents; | 33 using content::WebContents; |
30 | 34 |
31 FullscreenController::FullscreenController(Browser* browser) | 35 FullscreenController::FullscreenController(Browser* browser) |
32 : ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 36 : ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
33 browser_(browser), | 37 browser_(browser), |
34 window_(browser->window()), | 38 window_(browser->window()), |
35 profile_(browser->profile()), | 39 profile_(browser->profile()), |
36 fullscreened_tab_(NULL), | 40 fullscreened_tab_(NULL), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 #if defined(OS_WIN) | 80 #if defined(OS_WIN) |
77 // For now, avoid breaking when initiating full screen tab mode while in | 81 // For now, avoid breaking when initiating full screen tab mode while in |
78 // a metro snap. | 82 // a metro snap. |
79 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen | 83 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen |
80 // modes with metro snap. | 84 // modes with metro snap. |
81 if (IsInMetroSnapMode()) | 85 if (IsInMetroSnapMode()) |
82 return; | 86 return; |
83 #endif | 87 #endif |
84 | 88 |
85 bool in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); | 89 bool in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); |
86 #if defined(OS_MACOSX) | |
87 in_browser_or_tab_fullscreen_mode |= window_->InPresentationMode(); | |
88 #endif | |
89 | 90 |
90 if (enter_fullscreen) { | 91 if (enter_fullscreen) { |
91 SetFullscreenedTab(web_contents); | 92 SetFullscreenedTab(web_contents); |
92 if (!in_browser_or_tab_fullscreen_mode) { | 93 if (!in_browser_or_tab_fullscreen_mode) { |
93 tab_caused_fullscreen_ = true; | 94 tab_caused_fullscreen_ = true; |
94 #if defined(OS_MACOSX) | 95 #if defined(OS_MACOSX) |
95 TogglePresentationModeInternal(true); | 96 TogglePresentationModeInternal(true); |
96 #else | 97 #else |
97 ToggleFullscreenModeInternal(true); | 98 ToggleFullscreenModeInternal(true); |
98 #endif | 99 #endif |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // |fullscreened_tab_| may not be valid. Instead, we call it here to clean | 246 // |fullscreened_tab_| may not be valid. Instead, we call it here to clean |
246 // up tab fullscreen related state. | 247 // up tab fullscreen related state. |
247 NotifyTabOfExitIfNecessary(); | 248 NotifyTabOfExitIfNecessary(); |
248 } | 249 } |
249 } | 250 } |
250 | 251 |
251 void FullscreenController::WindowFullscreenStateChanged() { | 252 void FullscreenController::WindowFullscreenStateChanged() { |
252 reentrant_window_state_change_call_check_ = true; | 253 reentrant_window_state_change_call_check_ = true; |
253 | 254 |
254 bool exiting_fullscreen = !window_->IsFullscreen(); | 255 bool exiting_fullscreen = !window_->IsFullscreen(); |
255 #if defined(OS_MACOSX) | 256 |
256 exiting_fullscreen &= !window_->InPresentationMode(); | |
257 #endif | |
258 PostFullscreenChangeNotification(!exiting_fullscreen); | 257 PostFullscreenChangeNotification(!exiting_fullscreen); |
259 if (exiting_fullscreen) | 258 if (exiting_fullscreen) |
260 NotifyTabOfExitIfNecessary(); | 259 NotifyTabOfExitIfNecessary(); |
261 if (exiting_fullscreen) | 260 if (exiting_fullscreen) |
262 window_->GetDownloadShelf()->Unhide(); | 261 window_->GetDownloadShelf()->Unhide(); |
263 else | 262 else |
264 window_->GetDownloadShelf()->Hide(); | 263 window_->GetDownloadShelf()->Hide(); |
265 } | 264 } |
266 | 265 |
267 bool FullscreenController::HandleUserPressedEscape() { | 266 bool FullscreenController::HandleUserPressedEscape() { |
268 if (IsFullscreenForTabOrPending() || | 267 if (IsFullscreenForTabOrPending() || |
269 IsMouseLocked() || IsMouseLockRequested()) { | 268 IsMouseLocked() || IsMouseLockRequested()) { |
270 ExitTabFullscreenOrMouseLockIfNecessary(); | 269 ExitTabFullscreenOrMouseLockIfNecessary(); |
271 return true; | 270 return true; |
272 } | 271 } |
273 | 272 |
274 return false; | 273 return false; |
275 } | 274 } |
276 | 275 |
277 void FullscreenController::ExitTabOrBrowserFullscreenToPreviousState() { | 276 void FullscreenController::ExitTabOrBrowserFullscreenToPreviousState() { |
278 if (IsFullscreenForTabOrPending()) | 277 if (IsFullscreenForTabOrPending()) { |
279 ExitTabFullscreenOrMouseLockIfNecessary(); | 278 ExitTabFullscreenOrMouseLockIfNecessary(); |
280 else if (IsFullscreenForBrowser()) | 279 } else if (IsFullscreenForBrowser()) { |
| 280 #if defined(OS_MACOSX) |
| 281 TogglePresentationMode(); |
| 282 #else |
281 ToggleFullscreenMode(); | 283 ToggleFullscreenMode(); |
| 284 #endif |
| 285 } |
282 } | 286 } |
283 | 287 |
284 void FullscreenController::OnAcceptFullscreenPermission() { | 288 void FullscreenController::OnAcceptFullscreenPermission() { |
285 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); | 289 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); |
286 bool mouse_lock = false; | 290 bool mouse_lock = false; |
287 bool fullscreen = false; | 291 bool fullscreen = false; |
288 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | 292 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, |
289 &mouse_lock); | 293 &mouse_lock); |
290 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); | 294 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); |
291 DCHECK(!(mouse_lock && IsMouseLocked())); | 295 DCHECK(!(mouse_lock && IsMouseLocked())); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 | 498 |
495 // TODO(koz): Change |for_tab| to an enum. | 499 // TODO(koz): Change |for_tab| to an enum. |
496 void FullscreenController::ToggleFullscreenModeInternal(bool for_tab) { | 500 void FullscreenController::ToggleFullscreenModeInternal(bool for_tab) { |
497 #if defined(OS_WIN) | 501 #if defined(OS_WIN) |
498 // When in Metro snap mode, toggling in and out of fullscreen is prevented. | 502 // When in Metro snap mode, toggling in and out of fullscreen is prevented. |
499 if (IsInMetroSnapMode()) | 503 if (IsInMetroSnapMode()) |
500 return; | 504 return; |
501 #endif | 505 #endif |
502 | 506 |
503 toggled_into_fullscreen_ = !window_->IsFullscreen(); | 507 toggled_into_fullscreen_ = !window_->IsFullscreen(); |
| 508 #if defined(OS_MACOSX) |
| 509 // When a Mac user requests a toggle they may be transitioning from |
| 510 // FullscreenWithoutChrome to FullscreenWithChrome. |
| 511 if (!IsFullscreenForTabOrPending()) |
| 512 toggled_into_fullscreen_ |= window_->IsFullscreenWithoutChrome(); |
| 513 #endif |
504 | 514 |
505 // In kiosk mode, we always want to be fullscreen. When the browser first | 515 // In kiosk mode, we always want to be fullscreen. When the browser first |
506 // starts we're not yet fullscreen, so let the initial toggle go through. | 516 // starts we're not yet fullscreen, so let the initial toggle go through. |
507 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && | 517 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && |
508 !toggled_into_fullscreen_) | 518 !toggled_into_fullscreen_) |
509 return; | 519 return; |
510 | 520 |
511 GURL url; | 521 GURL url; |
512 if (for_tab) { | 522 if (for_tab) { |
513 url = chrome::GetActiveWebContents(browser_)->GetURL(); | 523 url = chrome::GetActiveWebContents(browser_)->GetURL(); |
514 tab_fullscreen_accepted_ = toggled_into_fullscreen_ && | 524 tab_fullscreen_accepted_ = toggled_into_fullscreen_ && |
515 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | 525 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
516 } else { | 526 } else { |
517 if (!extension_caused_fullscreen_.is_empty()) | 527 if (!extension_caused_fullscreen_.is_empty()) |
518 url = extension_caused_fullscreen_; | 528 url = extension_caused_fullscreen_; |
519 content::RecordAction(UserMetricsAction("ToggleFullscreen")); | 529 content::RecordAction(UserMetricsAction("ToggleFullscreen")); |
520 } | 530 } |
521 if (toggled_into_fullscreen_) { | 531 if (toggled_into_fullscreen_) { |
| 532 #if defined(OS_MACOSX) |
| 533 CHECK(!for_tab); // EnterFullscreenWithChrome invalid for tab fullscreen. |
| 534 CHECK(base::mac::IsOSLionOrLater()); |
| 535 window_->EnterFullscreenWithChrome(); |
| 536 #else |
522 window_->EnterFullscreen(url, GetFullscreenExitBubbleType()); | 537 window_->EnterFullscreen(url, GetFullscreenExitBubbleType()); |
| 538 #endif |
523 } else { | 539 } else { |
524 #if defined(OS_MACOSX) | 540 #if defined(OS_MACOSX) |
525 // Mac windows report a state change instantly, and so we must also clear | 541 // Mac windows report a state change instantly, and so we must also clear |
526 // tab_caused_fullscreen_ to match them else other logic using | 542 // tab_caused_fullscreen_ to match them else other logic using |
527 // tab_caused_fullscreen_ will be incorrect. | 543 // tab_caused_fullscreen_ will be incorrect. |
528 NotifyTabOfExitIfNecessary(); | 544 NotifyTabOfExitIfNecessary(); |
529 | |
530 if (window_->InPresentationMode() && !for_tab) | |
531 window_->ExitPresentationMode(); | |
532 else | |
533 #endif | 545 #endif |
534 window_->ExitFullscreen(); | 546 window_->ExitFullscreen(); |
535 extension_caused_fullscreen_ = GURL(); | 547 extension_caused_fullscreen_ = GURL(); |
536 } | 548 } |
537 UpdateFullscreenExitBubbleContent(); | 549 UpdateFullscreenExitBubbleContent(); |
538 | 550 |
539 // Once the window has become fullscreen it'll call back to | 551 // Once the window has become fullscreen it'll call back to |
540 // WindowFullscreenStateChanged(). We don't do this immediately as | 552 // WindowFullscreenStateChanged(). We don't do this immediately as |
541 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 553 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
542 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 554 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
543 } | 555 } |
544 | 556 |
545 #if defined(OS_MACOSX) | 557 #if defined(OS_MACOSX) |
546 void FullscreenController::TogglePresentationModeInternal(bool for_tab) { | 558 void FullscreenController::TogglePresentationModeInternal(bool for_tab) { |
547 toggled_into_fullscreen_ = !window_->InPresentationMode(); | 559 toggled_into_fullscreen_ = !window_->IsFullscreenWithoutChrome(); |
548 GURL url; | 560 GURL url; |
549 if (for_tab) { | 561 if (for_tab) { |
550 url = chrome::GetActiveWebContents(browser_)->GetURL(); | 562 url = chrome::GetActiveWebContents(browser_)->GetURL(); |
551 tab_fullscreen_accepted_ = toggled_into_fullscreen_ && | 563 tab_fullscreen_accepted_ = toggled_into_fullscreen_ && |
552 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | 564 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
553 } | 565 } |
554 if (!window_->InPresentationMode()) { | 566 if (!window_->IsFullscreenWithoutChrome()) { |
555 window_->EnterPresentationMode(url, GetFullscreenExitBubbleType()); | 567 window_->EnterFullscreen(url, GetFullscreenExitBubbleType()); |
556 } else { | 568 } else { |
557 window_->ExitFullscreen(); | 569 window_->ExitFullscreen(); |
558 | 570 |
559 // Mac windows report a state change instantly, and so we must also clear | 571 // Mac windows report a state change instantly, and so we must also clear |
560 // tab_caused_fullscreen_ to match them else other logic using | 572 // tab_caused_fullscreen_ to match them else other logic using |
561 // tab_caused_fullscreen_ will be incorrect. | 573 // tab_caused_fullscreen_ will be incorrect. |
562 NotifyTabOfExitIfNecessary(); | 574 NotifyTabOfExitIfNecessary(); |
563 } | 575 } |
564 UpdateFullscreenExitBubbleContent(); | 576 UpdateFullscreenExitBubbleContent(); |
565 | 577 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 | 624 |
613 ContentSetting | 625 ContentSetting |
614 FullscreenController::GetMouseLockSetting(const GURL& url) const { | 626 FullscreenController::GetMouseLockSetting(const GURL& url) const { |
615 if (url.SchemeIsFile()) | 627 if (url.SchemeIsFile()) |
616 return CONTENT_SETTING_ALLOW; | 628 return CONTENT_SETTING_ALLOW; |
617 | 629 |
618 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 630 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); |
619 return settings_map->GetContentSetting(url, url, | 631 return settings_map->GetContentSetting(url, url, |
620 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); | 632 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); |
621 } | 633 } |
OLD | NEW |