Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1055)

Side by Side Diff: chrome/browser/ui/fullscreen/fullscreen_controller.cc

Issue 789533002: Fullscreen: make fullscreen requests come from RenderFrame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/app_mode/app_mode_utils.h" 10 #include "chrome/browser/app_mode/app_mode_utils.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 return true; 90 return true;
91 } 91 }
92 return IsFullscreenForCapturedTab(web_contents); 92 return IsFullscreenForCapturedTab(web_contents);
93 } 93 }
94 94
95 bool FullscreenController::IsFullscreenCausedByTab() const { 95 bool FullscreenController::IsFullscreenCausedByTab() const {
96 return state_prior_to_tab_fullscreen_ == STATE_NORMAL; 96 return state_prior_to_tab_fullscreen_ == STATE_NORMAL;
97 } 97 }
98 98
99 void FullscreenController::ToggleFullscreenModeForTab(WebContents* web_contents, 99 void FullscreenController::ToggleFullscreenModeForTab(WebContents* web_contents,
100 const GURL& origin,
100 bool enter_fullscreen) { 101 bool enter_fullscreen) {
101 if (MaybeToggleFullscreenForCapturedTab(web_contents, enter_fullscreen)) { 102 if (MaybeToggleFullscreenForCapturedTab(web_contents, enter_fullscreen)) {
102 // During tab capture of fullscreen-within-tab views, the browser window 103 // During tab capture of fullscreen-within-tab views, the browser window
103 // fullscreen state is unchanged, so return now. 104 // fullscreen state is unchanged, so return now.
104 return; 105 return;
105 } 106 }
106 if (fullscreened_tab_) { 107 if (fullscreened_tab_) {
107 if (web_contents != fullscreened_tab_) 108 if (web_contents != fullscreened_tab_)
108 return; 109 return;
109 } else if ( 110 } else if (
110 web_contents != browser_->tab_strip_model()->GetActiveWebContents()) { 111 web_contents != browser_->tab_strip_model()->GetActiveWebContents()) {
111 return; 112 return;
112 } 113 }
113 if (IsWindowFullscreenForTabOrPending() == enter_fullscreen) 114 if (IsWindowFullscreenForTabOrPending() == enter_fullscreen)
114 return; 115 return;
115 116
116 #if defined(OS_WIN) 117 #if defined(OS_WIN)
117 // For now, avoid breaking when initiating full screen tab mode while in 118 // For now, avoid breaking when initiating full screen tab mode while in
118 // a metro snap. 119 // a metro snap.
119 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen 120 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen
120 // modes with metro snap. 121 // modes with metro snap.
121 if (IsInMetroSnapMode()) 122 if (IsInMetroSnapMode())
122 return; 123 return;
123 #endif 124 #endif
124 125
125 bool in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); 126 bool in_browser_or_tab_fullscreen_mode = window_->IsFullscreen();
126 127
127 if (enter_fullscreen) { 128 if (enter_fullscreen) {
128 SetFullscreenedTab(web_contents); 129 SetFullscreenedTab(web_contents, origin);
129 if (!in_browser_or_tab_fullscreen_mode) { 130 if (!in_browser_or_tab_fullscreen_mode) {
130 // Normal -> Tab Fullscreen. 131 // Normal -> Tab Fullscreen.
131 state_prior_to_tab_fullscreen_ = STATE_NORMAL; 132 state_prior_to_tab_fullscreen_ = STATE_NORMAL;
132 ToggleFullscreenModeInternal(TAB); 133 ToggleFullscreenModeInternal(TAB);
133 } else { 134 } else {
134 if (window_->IsFullscreenWithToolbar()) { 135 if (window_->IsFullscreenWithToolbar()) {
135 // Browser Fullscreen with Toolbar -> Tab Fullscreen (no toolbar). 136 // Browser Fullscreen with Toolbar -> Tab Fullscreen (no toolbar).
136 window_->UpdateFullscreenWithToolbar(false); 137 window_->UpdateFullscreenWithToolbar(false);
137 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR; 138 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR;
138 } else { 139 } else {
139 // Browser Fullscreen without Toolbar -> Tab Fullscreen. 140 // Browser Fullscreen without Toolbar -> Tab Fullscreen.
140 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_TOOLBAR; 141 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_TOOLBAR;
141 } 142 }
142 143
143 // We need to update the fullscreen exit bubble, e.g., going from browser
144 // fullscreen to tab fullscreen will need to show different content.
145 const GURL& url = web_contents->GetURL();
146 if (!tab_fullscreen_accepted_) { 144 if (!tab_fullscreen_accepted_) {
147 tab_fullscreen_accepted_ = 145 tab_fullscreen_accepted_ =
148 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; 146 GetFullscreenSetting() == CONTENT_SETTING_ALLOW;
149 } 147 }
150 UpdateFullscreenExitBubbleContent(); 148 UpdateFullscreenExitBubbleContent();
151 149
152 // This is only a change between Browser and Tab fullscreen. We generate 150 // This is only a change between Browser and Tab fullscreen. We generate
153 // a fullscreen notification now because there is no window change. 151 // a fullscreen notification now because there is no window change.
154 PostFullscreenChangeNotification(true); 152 PostFullscreenChangeNotification(true);
155 } 153 }
156 } else { 154 } else {
157 if (in_browser_or_tab_fullscreen_mode) { 155 if (in_browser_or_tab_fullscreen_mode) {
158 if (IsFullscreenCausedByTab()) { 156 if (IsFullscreenCausedByTab()) {
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 const content::NotificationSource& source, 446 const content::NotificationSource& source,
449 const content::NotificationDetails& details) { 447 const content::NotificationDetails& details) {
450 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); 448 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type);
451 if (content::Details<content::LoadCommittedDetails>(details)-> 449 if (content::Details<content::LoadCommittedDetails>(details)->
452 is_navigation_to_different_page()) 450 is_navigation_to_different_page())
453 ExitTabFullscreenOrMouseLockIfNecessary(); 451 ExitTabFullscreenOrMouseLockIfNecessary();
454 } 452 }
455 453
456 GURL FullscreenController::GetFullscreenExitBubbleURL() const { 454 GURL FullscreenController::GetFullscreenExitBubbleURL() const {
457 if (fullscreened_tab_) 455 if (fullscreened_tab_)
458 return fullscreened_tab_->GetURL(); 456 return GetRequestingOrigin();
459 if (mouse_lock_tab_) 457 if (mouse_lock_tab_)
460 return mouse_lock_tab_->GetURL(); 458 return mouse_lock_tab_->GetURL();
461 return extension_caused_fullscreen_; 459 return extension_caused_fullscreen_;
462 } 460 }
463 461
464 FullscreenExitBubbleType FullscreenController::GetFullscreenExitBubbleType() 462 FullscreenExitBubbleType FullscreenController::GetFullscreenExitBubbleType()
465 const { 463 const {
466 // In kiosk and exclusive app mode we always want to be fullscreen and do not 464 // In kiosk and exclusive app mode we always want to be fullscreen and do not
467 // want to show exit instructions for browser mode fullscreen. 465 // want to show exit instructions for browser mode fullscreen.
468 bool app_mode = false; 466 bool app_mode = false;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 void FullscreenController::NotifyFullscreenChange(bool is_fullscreen) { 524 void FullscreenController::NotifyFullscreenChange(bool is_fullscreen) {
527 content::NotificationService::current()->Notify( 525 content::NotificationService::current()->Notify(
528 chrome::NOTIFICATION_FULLSCREEN_CHANGED, 526 chrome::NOTIFICATION_FULLSCREEN_CHANGED,
529 content::Source<FullscreenController>(this), 527 content::Source<FullscreenController>(this),
530 content::Details<bool>(&is_fullscreen)); 528 content::Details<bool>(&is_fullscreen));
531 } 529 }
532 530
533 void FullscreenController::NotifyTabOfExitIfNecessary() { 531 void FullscreenController::NotifyTabOfExitIfNecessary() {
534 if (fullscreened_tab_) { 532 if (fullscreened_tab_) {
535 RenderViewHost* rvh = fullscreened_tab_->GetRenderViewHost(); 533 RenderViewHost* rvh = fullscreened_tab_->GetRenderViewHost();
536 SetFullscreenedTab(NULL); 534 SetFullscreenedTab(nullptr, GURL());
537 state_prior_to_tab_fullscreen_ = STATE_INVALID; 535 state_prior_to_tab_fullscreen_ = STATE_INVALID;
538 tab_fullscreen_accepted_ = false; 536 tab_fullscreen_accepted_ = false;
539 if (rvh) 537 if (rvh)
540 rvh->ExitFullscreen(); 538 rvh->ExitFullscreen();
541 } 539 }
542 540
543 if (mouse_lock_tab_) { 541 if (mouse_lock_tab_) {
544 if (IsMouseLockRequested()) { 542 if (IsMouseLockRequested()) {
545 mouse_lock_tab_->GotResponseToLockMouseRequest(false); 543 mouse_lock_tab_->GotResponseToLockMouseRequest(false);
546 NotifyMouseLockChange(); 544 NotifyMouseLockChange();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 EnterFullscreenModeInternal(option); 601 EnterFullscreenModeInternal(option);
604 else 602 else
605 ExitFullscreenModeInternal(); 603 ExitFullscreenModeInternal();
606 } 604 }
607 605
608 void FullscreenController::EnterFullscreenModeInternal( 606 void FullscreenController::EnterFullscreenModeInternal(
609 FullscreenInternalOption option) { 607 FullscreenInternalOption option) {
610 toggled_into_fullscreen_ = true; 608 toggled_into_fullscreen_ = true;
611 GURL url; 609 GURL url;
612 if (option == TAB) { 610 if (option == TAB) {
613 url = browser_->tab_strip_model()->GetActiveWebContents()->GetURL(); 611 url = GetRequestingOrigin();
614 tab_fullscreen_accepted_ = 612 tab_fullscreen_accepted_ =
615 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; 613 GetFullscreenSetting() == CONTENT_SETTING_ALLOW;
616 } else { 614 } else {
617 if (!extension_caused_fullscreen_.is_empty()) 615 if (!extension_caused_fullscreen_.is_empty())
618 url = extension_caused_fullscreen_; 616 url = extension_caused_fullscreen_;
619 } 617 }
620 618
621 if (option == BROWSER) 619 if (option == BROWSER)
622 content::RecordAction(UserMetricsAction("ToggleFullscreen")); 620 content::RecordAction(UserMetricsAction("ToggleFullscreen"));
623 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions 621 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions
624 // from tab fullscreen out to browser with toolbar. 622 // from tab fullscreen out to browser with toolbar.
625 623
(...skipping 16 matching lines...) Expand all
642 // state_prior_to_tab_fullscreen_ to match them else other logic using 640 // state_prior_to_tab_fullscreen_ to match them else other logic using
643 // state_prior_to_tab_fullscreen_ will be incorrect. 641 // state_prior_to_tab_fullscreen_ will be incorrect.
644 NotifyTabOfExitIfNecessary(); 642 NotifyTabOfExitIfNecessary();
645 #endif 643 #endif
646 window_->ExitFullscreen(); 644 window_->ExitFullscreen();
647 extension_caused_fullscreen_ = GURL(); 645 extension_caused_fullscreen_ = GURL();
648 646
649 UpdateFullscreenExitBubbleContent(); 647 UpdateFullscreenExitBubbleContent();
650 } 648 }
651 649
652 void FullscreenController::SetFullscreenedTab(WebContents* tab) { 650 void FullscreenController::SetFullscreenedTab(WebContents* tab,
651 const GURL& origin) {
653 fullscreened_tab_ = tab; 652 fullscreened_tab_ = tab;
653 fullscreened_origin_ = origin;
654 UpdateNotificationRegistrations(); 654 UpdateNotificationRegistrations();
655 } 655 }
656 656
657 void FullscreenController::SetMouseLockTab(WebContents* tab) { 657 void FullscreenController::SetMouseLockTab(WebContents* tab) {
658 mouse_lock_tab_ = tab; 658 mouse_lock_tab_ = tab;
659 UpdateNotificationRegistrations(); 659 UpdateNotificationRegistrations();
660 } 660 }
661 661
662 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { 662 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() {
663 if (IsWindowFullscreenForTabOrPending()) 663 if (IsWindowFullscreenForTabOrPending())
664 ToggleFullscreenModeForTab(fullscreened_tab_, false); 664 ToggleFullscreenModeForTab(fullscreened_tab_, GURL(), false);
665 else 665 else
666 NotifyTabOfExitIfNecessary(); 666 NotifyTabOfExitIfNecessary();
667 } 667 }
668 668
669 void FullscreenController::UpdateFullscreenExitBubbleContent() { 669 void FullscreenController::UpdateFullscreenExitBubbleContent() {
670 GURL url = GetFullscreenExitBubbleURL(); 670 GURL url = GetFullscreenExitBubbleURL();
671 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); 671 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType();
672 672
673 // If bubble displays buttons, unlock mouse to allow pressing them. 673 // If bubble displays buttons, unlock mouse to allow pressing them.
674 if (fullscreen_bubble::ShowButtonsForType(bubble_type) && IsMouseLocked()) 674 if (fullscreen_bubble::ShowButtonsForType(bubble_type) && IsMouseLocked())
675 UnlockMouse(); 675 UnlockMouse();
676 676
677 window_->UpdateFullscreenExitBubbleContent(url, bubble_type); 677 window_->UpdateFullscreenExitBubbleContent(url, bubble_type);
678 } 678 }
679 679
680 ContentSetting 680 ContentSetting
681 FullscreenController::GetFullscreenSetting(const GURL& url) const { 681 FullscreenController::GetFullscreenSetting() const {
682 DCHECK(fullscreened_tab_);
683
684 GURL url = GetRequestingOrigin();
685
682 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) 686 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile())
683 return CONTENT_SETTING_ALLOW; 687 return CONTENT_SETTING_ALLOW;
684 688
685 return profile_->GetHostContentSettingsMap()->GetContentSetting(url, url, 689 return profile_->GetHostContentSettingsMap()->GetContentSetting(
686 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); 690 url,
691 GetEmbeddingOrigin(),
692 CONTENT_SETTINGS_TYPE_FULLSCREEN,
693 std::string());
687 } 694 }
688 695
689 ContentSetting 696 ContentSetting
690 FullscreenController::GetMouseLockSetting(const GURL& url) const { 697 FullscreenController::GetMouseLockSetting(const GURL& url) const {
691 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) 698 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile())
692 return CONTENT_SETTING_ALLOW; 699 return CONTENT_SETTING_ALLOW;
693 700
694 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); 701 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap();
695 return settings_map->GetContentSetting(url, url, 702 return settings_map->GetContentSetting(url, url,
696 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); 703 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ? 754 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ?
748 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL; 755 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL;
749 if (!mouse_lock_view) { 756 if (!mouse_lock_view) {
750 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost(); 757 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost();
751 if (rvh) 758 if (rvh)
752 mouse_lock_view = rvh->GetView(); 759 mouse_lock_view = rvh->GetView();
753 } 760 }
754 if (mouse_lock_view) 761 if (mouse_lock_view)
755 mouse_lock_view->UnlockMouse(); 762 mouse_lock_view->UnlockMouse();
756 } 763 }
764
765 GURL FullscreenController::GetRequestingOrigin() const {
766 DCHECK(fullscreened_tab_);
767
768 if (!fullscreened_origin_.is_empty())
769 return fullscreened_origin_;
770
771 return fullscreened_tab_->GetLastCommittedURL();
772 }
773
774 GURL FullscreenController::GetEmbeddingOrigin() const {
775 DCHECK(fullscreened_tab_);
776
777 return fullscreened_tab_->GetLastCommittedURL();
778 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698