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

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

Issue 10546106: TabContentsWrapper -> TabContents, part 53. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months 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 | Annotate | Revision Log
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_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_wrapper.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/notification_service.h" 19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/render_view_host.h" 20 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/render_widget_host_view.h" 21 #include "content/public/browser/render_widget_host_view.h"
22 #include "content/public/browser/user_metrics.h" 22 #include "content/public/browser/user_metrics.h"
23 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
24 24
25 using content::RenderViewHost; 25 using content::RenderViewHost;
(...skipping 16 matching lines...) Expand all
42 42
43 bool FullscreenController::IsFullscreenForBrowser() const { 43 bool FullscreenController::IsFullscreenForBrowser() const {
44 return window_->IsFullscreen() && !tab_caused_fullscreen_; 44 return window_->IsFullscreen() && !tab_caused_fullscreen_;
45 } 45 }
46 46
47 bool FullscreenController::IsFullscreenForTabOrPending() const { 47 bool FullscreenController::IsFullscreenForTabOrPending() const {
48 return fullscreened_tab_ != NULL; 48 return fullscreened_tab_ != NULL;
49 } 49 }
50 50
51 bool FullscreenController::IsFullscreenForTabOrPending( 51 bool FullscreenController::IsFullscreenForTabOrPending(
52 const WebContents* tab) const { 52 const WebContents* web_contents) const {
53 const TabContentsWrapper* wrapper = 53 const TabContents* tab_contents =
54 TabContentsWrapper::GetCurrentWrapperForContents(tab); 54 TabContents::FromWebContents(web_contents);
55 if (!wrapper || (wrapper != fullscreened_tab_)) 55 if (!tab_contents || (tab_contents != fullscreened_tab_))
56 return false; 56 return false;
57 DCHECK(tab == browser_->GetSelectedWebContents()); 57 DCHECK(web_contents == browser_->GetActiveWebContents());
58 return true; 58 return true;
59 } 59 }
60 60
61 bool FullscreenController::IsMouseLockRequested() const { 61 bool FullscreenController::IsMouseLockRequested() const {
62 return mouse_lock_state_ == MOUSELOCK_REQUESTED; 62 return mouse_lock_state_ == MOUSELOCK_REQUESTED;
63 } 63 }
64 64
65 bool FullscreenController::IsMouseLocked() const { 65 bool FullscreenController::IsMouseLocked() const {
66 return mouse_lock_state_ == MOUSELOCK_ACCEPTED || 66 return mouse_lock_state_ == MOUSELOCK_ACCEPTED ||
67 mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY; 67 mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY;
68 } 68 }
69 69
70 void FullscreenController::RequestToLockMouse(WebContents* tab, 70 void FullscreenController::RequestToLockMouse(WebContents* web_contents,
71 bool user_gesture, 71 bool user_gesture,
72 bool last_unlocked_by_target) { 72 bool last_unlocked_by_target) {
73 DCHECK(!IsMouseLocked()); 73 DCHECK(!IsMouseLocked());
74 NotifyMouseLockChange(); 74 NotifyMouseLockChange();
75 75
76 // Must have a user gesture to prevent misbehaving sites from constantly 76 // Must have a user gesture to prevent misbehaving sites from constantly
77 // re-locking the mouse. Exceptions are when the page has unlocked 77 // re-locking the mouse. Exceptions are when the page has unlocked
78 // (i.e. not the user), or if we're in tab fullscreen (user gesture required 78 // (i.e. not the user), or if we're in tab fullscreen (user gesture required
79 // for that) 79 // for that)
80 if (!last_unlocked_by_target && !user_gesture && 80 if (!last_unlocked_by_target && !user_gesture &&
81 !IsFullscreenForTabOrPending(tab)) { 81 !IsFullscreenForTabOrPending(web_contents)) {
82 tab->GotResponseToLockMouseRequest(false); 82 web_contents->GotResponseToLockMouseRequest(false);
83 return; 83 return;
84 } 84 }
85 mouse_lock_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); 85 mouse_lock_tab_ = TabContents::FromWebContents(web_contents);
86 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); 86 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType();
87 87
88 switch (GetMouseLockSetting(tab->GetURL())) { 88 switch (GetMouseLockSetting(web_contents->GetURL())) {
89 case CONTENT_SETTING_ALLOW: 89 case CONTENT_SETTING_ALLOW:
90 // If bubble already displaying buttons we must not lock the mouse yet, 90 // If bubble already displaying buttons we must not lock the mouse yet,
91 // or it would prevent pressing those buttons. Instead, merge the request. 91 // or it would prevent pressing those buttons. Instead, merge the request.
92 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { 92 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) {
93 mouse_lock_state_ = MOUSELOCK_REQUESTED; 93 mouse_lock_state_ = MOUSELOCK_REQUESTED;
94 } else { 94 } else {
95 // Lock mouse. 95 // Lock mouse.
96 if (tab->GotResponseToLockMouseRequest(true)) { 96 if (web_contents->GotResponseToLockMouseRequest(true)) {
97 if (last_unlocked_by_target) { 97 if (last_unlocked_by_target) {
98 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY; 98 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY;
99 } else { 99 } else {
100 mouse_lock_state_ = MOUSELOCK_ACCEPTED; 100 mouse_lock_state_ = MOUSELOCK_ACCEPTED;
101 } 101 }
102 } else { 102 } else {
103 mouse_lock_tab_ = NULL; 103 mouse_lock_tab_ = NULL;
104 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; 104 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
105 } 105 }
106 } 106 }
107 break; 107 break;
108 case CONTENT_SETTING_BLOCK: 108 case CONTENT_SETTING_BLOCK:
109 tab->GotResponseToLockMouseRequest(false); 109 web_contents->GotResponseToLockMouseRequest(false);
110 mouse_lock_tab_ = NULL; 110 mouse_lock_tab_ = NULL;
111 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; 111 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
112 break; 112 break;
113 case CONTENT_SETTING_ASK: 113 case CONTENT_SETTING_ASK:
114 mouse_lock_state_ = MOUSELOCK_REQUESTED; 114 mouse_lock_state_ = MOUSELOCK_REQUESTED;
115 break; 115 break;
116 default: 116 default:
117 NOTREACHED(); 117 NOTREACHED();
118 } 118 }
119 UpdateFullscreenExitBubbleContent(); 119 UpdateFullscreenExitBubbleContent();
120 } 120 }
121 121
122 void FullscreenController::ToggleFullscreenModeForTab(WebContents* tab, 122 void FullscreenController::ToggleFullscreenModeForTab(WebContents* web_contents,
123 bool enter_fullscreen) { 123 bool enter_fullscreen) {
124 if (tab != browser_->GetSelectedWebContents()) 124 if (web_contents != browser_->GetActiveWebContents())
125 return; 125 return;
126 126
127 bool in_browser_or_tab_fullscreen_mode; 127 bool in_browser_or_tab_fullscreen_mode;
128 #if defined(OS_MACOSX) 128 #if defined(OS_MACOSX)
129 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); 129 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode();
130 #else 130 #else
131 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); 131 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen();
132 #endif 132 #endif
133 133
134 if (enter_fullscreen) { 134 if (enter_fullscreen) {
135 fullscreened_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); 135 fullscreened_tab_ = TabContents::FromWebContents(web_contents);
136 if (!in_browser_or_tab_fullscreen_mode) { 136 if (!in_browser_or_tab_fullscreen_mode) {
137 tab_caused_fullscreen_ = true; 137 tab_caused_fullscreen_ = true;
138 #if defined(OS_MACOSX) 138 #if defined(OS_MACOSX)
139 TogglePresentationModeInternal(true); 139 TogglePresentationModeInternal(true);
140 #else 140 #else
141 ToggleFullscreenModeInternal(true); 141 ToggleFullscreenModeInternal(true);
142 #endif 142 #endif
143 } else { 143 } else {
144 // We need to update the fullscreen exit bubble, e.g., going from browser 144 // We need to update the fullscreen exit bubble, e.g., going from browser
145 // fullscreen to tab fullscreen will need to show different content. 145 // fullscreen to tab fullscreen will need to show different content.
146 const GURL& url = tab->GetURL(); 146 const GURL& url = web_contents->GetURL();
147 if (!tab_fullscreen_accepted_) { 147 if (!tab_fullscreen_accepted_) {
148 tab_fullscreen_accepted_ = 148 tab_fullscreen_accepted_ =
149 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; 149 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW;
150 } 150 }
151 UpdateFullscreenExitBubbleContent(); 151 UpdateFullscreenExitBubbleContent();
152 } 152 }
153 } else { 153 } else {
154 if (in_browser_or_tab_fullscreen_mode) { 154 if (in_browser_or_tab_fullscreen_mode) {
155 if (tab_caused_fullscreen_) { 155 if (tab_caused_fullscreen_) {
156 #if defined(OS_MACOSX) 156 #if defined(OS_MACOSX)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 ExitTabFullscreenOrMouseLockIfNecessary(); 201 ExitTabFullscreenOrMouseLockIfNecessary();
202 // The call to exit fullscreen may result in asynchronous notification of 202 // The call to exit fullscreen may result in asynchronous notification of
203 // fullscreen state change (e.g., on Linux). We don't want to rely on it 203 // fullscreen state change (e.g., on Linux). We don't want to rely on it
204 // to call NotifyTabOfExitIfNecessary(), because at that point 204 // to call NotifyTabOfExitIfNecessary(), because at that point
205 // |fullscreened_tab_| may not be valid. Instead, we call it here to clean 205 // |fullscreened_tab_| may not be valid. Instead, we call it here to clean
206 // up tab fullscreen related state. 206 // up tab fullscreen related state.
207 NotifyTabOfExitIfNecessary(); 207 NotifyTabOfExitIfNecessary();
208 } 208 }
209 } 209 }
210 210
211 void FullscreenController::OnTabDeactivated(TabContentsWrapper* contents) { 211 void FullscreenController::OnTabDeactivated(TabContents* contents) {
212 if (contents == fullscreened_tab_) 212 if (contents == fullscreened_tab_)
213 ExitTabFullscreenOrMouseLockIfNecessary(); 213 ExitTabFullscreenOrMouseLockIfNecessary();
214 } 214 }
215 215
216 void FullscreenController::OnAcceptFullscreenPermission( 216 void FullscreenController::OnAcceptFullscreenPermission(
217 const GURL& url, 217 const GURL& url,
218 FullscreenExitBubbleType bubble_type) { 218 FullscreenExitBubbleType bubble_type) {
219 bool mouse_lock = false; 219 bool mouse_lock = false;
220 bool fullscreen = false; 220 bool fullscreen = false;
221 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, 221 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen,
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); 456 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap();
457 return settings_map->GetContentSetting(url, url, 457 return settings_map->GetContentSetting(url, url,
458 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); 458 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string());
459 } 459 }
460 460
461 #if defined(OS_MACOSX) 461 #if defined(OS_MACOSX)
462 void FullscreenController::TogglePresentationModeInternal(bool for_tab) { 462 void FullscreenController::TogglePresentationModeInternal(bool for_tab) {
463 toggled_into_fullscreen_ = !window_->InPresentationMode(); 463 toggled_into_fullscreen_ = !window_->InPresentationMode();
464 GURL url; 464 GURL url;
465 if (for_tab) { 465 if (for_tab) {
466 url = browser_->GetSelectedWebContents()->GetURL(); 466 url = browser_->GetActiveWebContents()->GetURL();
467 tab_fullscreen_accepted_ = toggled_into_fullscreen_ && 467 tab_fullscreen_accepted_ = toggled_into_fullscreen_ &&
468 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; 468 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW;
469 } 469 }
470 if (toggled_into_fullscreen_) 470 if (toggled_into_fullscreen_)
471 window_->EnterPresentationMode(url, GetFullscreenExitBubbleType()); 471 window_->EnterPresentationMode(url, GetFullscreenExitBubbleType());
472 else 472 else
473 window_->ExitPresentationMode(); 473 window_->ExitPresentationMode();
474 UpdateFullscreenExitBubbleContent(); 474 UpdateFullscreenExitBubbleContent();
475 475
476 // WindowFullscreenStateChanged will be called by BrowserWindowController 476 // WindowFullscreenStateChanged will be called by BrowserWindowController
477 // when the transition completes. 477 // when the transition completes.
478 } 478 }
479 #endif 479 #endif
480 480
481 // TODO(koz): Change |for_tab| to an enum. 481 // TODO(koz): Change |for_tab| to an enum.
482 void FullscreenController::ToggleFullscreenModeInternal(bool for_tab) { 482 void FullscreenController::ToggleFullscreenModeInternal(bool for_tab) {
483 toggled_into_fullscreen_ = !window_->IsFullscreen(); 483 toggled_into_fullscreen_ = !window_->IsFullscreen();
484 484
485 // In kiosk mode, we always want to be fullscreen. When the browser first 485 // In kiosk mode, we always want to be fullscreen. When the browser first
486 // starts we're not yet fullscreen, so let the initial toggle go through. 486 // starts we're not yet fullscreen, so let the initial toggle go through.
487 #if !defined(OS_MACOSX) // Kiosk mode not available on Mac. 487 #if !defined(OS_MACOSX) // Kiosk mode not available on Mac.
488 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && 488 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) &&
489 window_->IsFullscreen()) 489 window_->IsFullscreen())
490 return; 490 return;
491 #endif 491 #endif
492 492
493 GURL url; 493 GURL url;
494 if (for_tab) { 494 if (for_tab) {
495 url = browser_->GetSelectedWebContents()->GetURL(); 495 url = browser_->GetActiveWebContents()->GetURL();
496 tab_fullscreen_accepted_ = toggled_into_fullscreen_ && 496 tab_fullscreen_accepted_ = toggled_into_fullscreen_ &&
497 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; 497 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW;
498 } else { 498 } else {
499 if (!extension_caused_fullscreen_.is_empty()) 499 if (!extension_caused_fullscreen_.is_empty())
500 url = extension_caused_fullscreen_; 500 url = extension_caused_fullscreen_;
501 content::RecordAction(UserMetricsAction("ToggleFullscreen")); 501 content::RecordAction(UserMetricsAction("ToggleFullscreen"));
502 } 502 }
503 if (toggled_into_fullscreen_) { 503 if (toggled_into_fullscreen_) {
504 window_->EnterFullscreen(url, GetFullscreenExitBubbleType()); 504 window_->EnterFullscreen(url, GetFullscreenExitBubbleType());
505 } else { 505 } else {
506 window_->ExitFullscreen(); 506 window_->ExitFullscreen();
507 extension_caused_fullscreen_ = GURL(); 507 extension_caused_fullscreen_ = GURL();
508 } 508 }
509 UpdateFullscreenExitBubbleContent(); 509 UpdateFullscreenExitBubbleContent();
510 510
511 // Once the window has become fullscreen it'll call back to 511 // Once the window has become fullscreen it'll call back to
512 // WindowFullscreenStateChanged(). We don't do this immediately as 512 // WindowFullscreenStateChanged(). We don't do this immediately as
513 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let 513 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let
514 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. 514 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate.
515 } 515 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/fullscreen_controller.h ('k') | chrome/browser/ui/fullscreen_controller_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698