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

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

Issue 10261011: Windowed mode mouse lock addded to fullscreen controller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 7 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"
(...skipping 16 matching lines...) Expand all
27 27
28 FullscreenController::FullscreenController(BrowserWindow* window, 28 FullscreenController::FullscreenController(BrowserWindow* window,
29 Profile* profile, 29 Profile* profile,
30 Browser* browser) 30 Browser* browser)
31 : window_(window), 31 : window_(window),
32 profile_(profile), 32 profile_(profile),
33 browser_(browser), 33 browser_(browser),
34 fullscreened_tab_(NULL), 34 fullscreened_tab_(NULL),
35 tab_caused_fullscreen_(false), 35 tab_caused_fullscreen_(false),
36 tab_fullscreen_accepted_(false), 36 tab_fullscreen_accepted_(false),
37 in_or_entering_fullscreen_(false),
38 mouse_lock_tab_(NULL),
37 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED) { 39 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED) {
38 } 40 }
39 41
40 bool FullscreenController::IsFullscreenForBrowser() const { 42 bool FullscreenController::IsFullscreenForBrowser() const {
41 return window_->IsFullscreen() && !tab_caused_fullscreen_; 43 return window_->IsFullscreen() && !tab_caused_fullscreen_;
42 } 44 }
43 45
44 bool FullscreenController::IsFullscreenForTabOrPending() const { 46 bool FullscreenController::IsFullscreenForTabOrPending() const {
45 return fullscreened_tab_ != NULL; 47 return fullscreened_tab_ != NULL;
46 } 48 }
(...skipping 10 matching lines...) Expand all
57 59
58 bool FullscreenController::IsMouseLockRequested() const { 60 bool FullscreenController::IsMouseLockRequested() const {
59 return mouse_lock_state_ == MOUSELOCK_REQUESTED; 61 return mouse_lock_state_ == MOUSELOCK_REQUESTED;
60 } 62 }
61 63
62 bool FullscreenController::IsMouseLocked() const { 64 bool FullscreenController::IsMouseLocked() const {
63 return mouse_lock_state_ == MOUSELOCK_ACCEPTED; 65 return mouse_lock_state_ == MOUSELOCK_ACCEPTED;
64 } 66 }
65 67
66 void FullscreenController::RequestToLockMouse(WebContents* tab, 68 void FullscreenController::RequestToLockMouse(WebContents* tab,
67 bool /* user_gesture */) { 69 bool user_gesture) {
68 // TODO(scheib) user_gesture required for Mouse Lock in Windowed Mode. 70 DCHECK(!IsMouseLocked());
69 // See http://crbug.com/107013, which will land in multiple patches. 71 MessageLoop::current()->PostTask(FROM_HERE,
72 base::Bind(&FullscreenController::NotifyMouseLockChange, this));
yzshen1 2012/04/30 19:32:40 Is it sufficient to send chrome::NOTIFICATION_MOUS
scheib 2012/05/01 03:27:07 Tests are the reason this notification exists. A t
70 73
71 DCHECK(!IsMouseLocked()); 74 // Must have a user gesture, or we must already be in tab fullscreen.
72 75 if (!user_gesture && !IsFullscreenForTabOrPending(tab)) {
73 // Mouse Lock is only permitted when browser is in tab fullscreen.
74 if (!IsFullscreenForTabOrPending(tab)) {
75 tab->GotResponseToLockMouseRequest(false); 76 tab->GotResponseToLockMouseRequest(false);
76 return; 77 return;
77 } 78 }
78 79
80 mouse_lock_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab);
81 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType();
82
79 switch (GetMouseLockSetting(tab->GetURL())) { 83 switch (GetMouseLockSetting(tab->GetURL())) {
80 case CONTENT_SETTING_ALLOW: 84 case CONTENT_SETTING_ALLOW:
81 if (tab_fullscreen_accepted_) { 85 // If bubble already displaying buttons, merge mouse lock request.
82 if (tab->GotResponseToLockMouseRequest(true)) 86 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) {
83 mouse_lock_state_ = MOUSELOCK_ACCEPTED;
84 } else {
85 mouse_lock_state_ = MOUSELOCK_REQUESTED; 87 mouse_lock_state_ = MOUSELOCK_REQUESTED;
yzshen1 2012/04/30 19:32:40 Please add more comment about why we need to merge
scheib 2012/05/01 03:27:07 Done.
88 break;
yzshen1 2012/04/30 19:32:40 You could use an "else" on line 89 instead of two
scheib 2012/05/01 03:27:07 Done.
86 } 89 }
90
91 // Lock mouse.
92 if (tab->GotResponseToLockMouseRequest(true))
93 mouse_lock_state_ = MOUSELOCK_ACCEPTED;
94 else
95 mouse_lock_tab_ = NULL;
yzshen1 2012/04/30 19:32:40 Shall we explicitly set mouse_lock_state_ to not r
scheib 2012/05/01 03:27:07 Done.
87 break; 96 break;
88 case CONTENT_SETTING_BLOCK: 97 case CONTENT_SETTING_BLOCK:
89 tab->GotResponseToLockMouseRequest(false); 98 tab->GotResponseToLockMouseRequest(false);
99 mouse_lock_tab_ = NULL;
yzshen1 2012/04/30 19:32:40 Shall we set mouse_lock_state_ to not requested in
scheib 2012/05/01 03:27:07 Done.
90 break; 100 break;
91 case CONTENT_SETTING_ASK: 101 case CONTENT_SETTING_ASK:
92 mouse_lock_state_ = MOUSELOCK_REQUESTED; 102 mouse_lock_state_ = MOUSELOCK_REQUESTED;
93 break; 103 break;
94 default: 104 default:
95 NOTREACHED(); 105 NOTREACHED();
96 } 106 }
97 UpdateFullscreenExitBubbleContent(); 107 UpdateFullscreenExitBubbleContent();
98 } 108 }
99 109
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 TogglePresentationModeInternal(true); 145 TogglePresentationModeInternal(true);
136 #else 146 #else
137 ToggleFullscreenModeInternal(true); 147 ToggleFullscreenModeInternal(true);
138 #endif 148 #endif
139 } else { 149 } else {
140 // If currently there is a tab in "tab fullscreen" mode and fullscreen 150 // If currently there is a tab in "tab fullscreen" mode and fullscreen
141 // was not caused by it (i.e., previously it was in "browser fullscreen" 151 // was not caused by it (i.e., previously it was in "browser fullscreen"
142 // mode), we need to switch back to "browser fullscreen" mode. In this 152 // mode), we need to switch back to "browser fullscreen" mode. In this
143 // case, all we have to do is notifying the tab that it has exited "tab 153 // case, all we have to do is notifying the tab that it has exited "tab
144 // fullscreen" mode. 154 // fullscreen" mode.
145 NotifyTabOfFullscreenExitIfNecessary(); 155 NotifyTabOfExitIfNecessary();
146 } 156 }
147 } 157 }
148 } 158 }
149 } 159 }
150 160
151 #if defined(OS_MACOSX) 161 #if defined(OS_MACOSX)
152 void FullscreenController::TogglePresentationMode() { 162 void FullscreenController::TogglePresentationMode() {
153 TogglePresentationModeInternal(false); 163 TogglePresentationModeInternal(false);
154 } 164 }
155 #endif 165 #endif
156 166
157 void FullscreenController::ToggleFullscreenMode() { 167 void FullscreenController::ToggleFullscreenMode() {
158 extension_caused_fullscreen_ = GURL(); 168 extension_caused_fullscreen_ = GURL();
159 ToggleFullscreenModeInternal(false); 169 ToggleFullscreenModeInternal(false);
160 } 170 }
161 171
162 void FullscreenController::ToggleFullscreenModeWithExtension( 172 void FullscreenController::ToggleFullscreenModeWithExtension(
163 const GURL& extension_url) { 173 const GURL& extension_url) {
164 // |extension_caused_fullscreen_| will be reset if this causes fullscreen to 174 // |extension_caused_fullscreen_| will be reset if this causes fullscreen to
165 // exit. 175 // exit.
166 extension_caused_fullscreen_ = extension_url; 176 extension_caused_fullscreen_ = extension_url;
167 ToggleFullscreenModeInternal(false); 177 ToggleFullscreenModeInternal(false);
168 } 178 }
169 179
170 void FullscreenController::LostMouseLock() { 180 void FullscreenController::LostMouseLock() {
171 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; 181 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
182 MessageLoop::current()->PostTask(FROM_HERE,
183 base::Bind(&FullscreenController::NotifyMouseLockChange, this));
172 UpdateFullscreenExitBubbleContent(); 184 UpdateFullscreenExitBubbleContent();
173 } 185 }
174 186
175 void FullscreenController::OnTabClosing(WebContents* web_contents) { 187 void FullscreenController::OnTabClosing(WebContents* web_contents) {
176 if (IsFullscreenForTabOrPending(web_contents)) { 188 if (IsFullscreenForTabOrPending(web_contents)) {
177 ExitTabbedFullscreenModeIfNecessary(); 189 ExitTabbedFullscreenModeIfNecessary();
178 // The call to exit fullscreen may result in asynchronous notification of 190 // The call to exit fullscreen may result in asynchronous notification of
179 // fullscreen state change (e.g., on Linux). We don't want to rely on it 191 // fullscreen state change (e.g., on Linux). We don't want to rely on it
180 // to call NotifyTabOfFullscreenExitIfNecessary(), because at that point 192 // to call NotifyTabOfExitIfNecessary(), because at that point
181 // |fullscreen_tab_| may not be valid. Instead, we call it here to clean up 193 // |fullscreen_tab_| may not be valid. Instead, we call it here to clean up
182 // tab fullscreen related state. 194 // tab fullscreen related state.
183 NotifyTabOfFullscreenExitIfNecessary(); 195 NotifyTabOfExitIfNecessary();
184 } 196 }
185 } 197 }
186 198
187 void FullscreenController::OnTabDeactivated(TabContentsWrapper* contents) { 199 void FullscreenController::OnTabDeactivated(TabContentsWrapper* contents) {
188 if (contents == fullscreened_tab_) 200 if (contents == fullscreened_tab_)
189 ExitTabbedFullscreenModeIfNecessary(); 201 ExitTabbedFullscreenModeIfNecessary();
190 } 202 }
191 203
192 void FullscreenController::OnAcceptFullscreenPermission( 204 void FullscreenController::OnAcceptFullscreenPermission(
193 const GURL& url, 205 const GURL& url,
194 FullscreenExitBubbleType bubble_type) { 206 FullscreenExitBubbleType bubble_type) {
195 bool mouse_lock = false; 207 bool mouse_lock = false;
196 bool fullscreen = false; 208 bool fullscreen = false;
197 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, 209 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen,
198 &mouse_lock); 210 &mouse_lock);
199 DCHECK(fullscreened_tab_); 211 DCHECK(!(fullscreen && tab_fullscreen_accepted_));
200 DCHECK_NE(tab_fullscreen_accepted_, fullscreen); 212 DCHECK(!(mouse_lock && IsMouseLocked()));
201 213
202 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); 214 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap();
203 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); 215 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url);
204 if (mouse_lock) { 216
217 if (mouse_lock && !IsMouseLocked()) {
205 DCHECK(IsMouseLockRequested()); 218 DCHECK(IsMouseLockRequested());
206 // TODO(markusheintz): We should allow patterns for all possible URLs here. 219 // TODO(markusheintz): We should allow patterns for all possible URLs here.
207 if (pattern.IsValid()) { 220 if (pattern.IsValid()) {
208 settings_map->SetContentSetting( 221 settings_map->SetContentSetting(
209 pattern, ContentSettingsPattern::Wildcard(), 222 pattern, ContentSettingsPattern::Wildcard(),
210 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), 223 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(),
211 CONTENT_SETTING_ALLOW); 224 CONTENT_SETTING_ALLOW);
212 } 225 }
213 mouse_lock_state_ = 226
214 fullscreened_tab_->web_contents()->GotResponseToLockMouseRequest(true) ? 227 if (mouse_lock_tab_ &&
215 MOUSELOCK_ACCEPTED : MOUSELOCK_NOT_REQUESTED; 228 mouse_lock_tab_->web_contents() &&
229 mouse_lock_tab_->web_contents()->GotResponseToLockMouseRequest(true)) {
230 mouse_lock_state_ = MOUSELOCK_ACCEPTED;
231 } else {
232 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
233 mouse_lock_tab_ = NULL;
234 }
235
236 MessageLoop::current()->PostTask(FROM_HERE,
237 base::Bind(&FullscreenController::NotifyMouseLockChange, this));
216 } 238 }
217 if (!tab_fullscreen_accepted_) { 239
240 if (fullscreen && !tab_fullscreen_accepted_) {
241 DCHECK(fullscreened_tab_);
218 if (pattern.IsValid()) { 242 if (pattern.IsValid()) {
219 settings_map->SetContentSetting( 243 settings_map->SetContentSetting(
220 pattern, ContentSettingsPattern::Wildcard(), 244 pattern, ContentSettingsPattern::Wildcard(),
221 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(), 245 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(),
222 CONTENT_SETTING_ALLOW); 246 CONTENT_SETTING_ALLOW);
223 } 247 }
224 tab_fullscreen_accepted_ = true; 248 tab_fullscreen_accepted_ = true;
225 } 249 }
226 UpdateFullscreenExitBubbleContent(); 250 UpdateFullscreenExitBubbleContent();
227 } 251 }
228 252
229 void FullscreenController::OnDenyFullscreenPermission( 253 void FullscreenController::OnDenyFullscreenPermission(
230 FullscreenExitBubbleType bubble_type) { 254 FullscreenExitBubbleType bubble_type) {
231 bool mouse_lock = false; 255 bool mouse_lock = false;
232 bool fullscreen = false; 256 bool fullscreen = false;
233 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, 257 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen,
234 &mouse_lock); 258 &mouse_lock);
235 DCHECK(fullscreened_tab_); 259 DCHECK(fullscreened_tab_ || mouse_lock_tab_);
236 DCHECK_NE(tab_fullscreen_accepted_, fullscreen); 260 DCHECK(!(fullscreen && tab_fullscreen_accepted_));
261 DCHECK(!(mouse_lock && IsMouseLocked()));
237 262
238 if (mouse_lock) { 263 if (mouse_lock) {
239 DCHECK(IsMouseLockRequested()); 264 DCHECK(IsMouseLockRequested());
240 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; 265 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
241 fullscreened_tab_->web_contents()->GotResponseToLockMouseRequest(false); 266 if (mouse_lock_tab_ && mouse_lock_tab_->web_contents())
242 if (!fullscreen) 267 mouse_lock_tab_->web_contents()->GotResponseToLockMouseRequest(false);
243 UpdateFullscreenExitBubbleContent(); 268 mouse_lock_tab_ = NULL;
269 MessageLoop::current()->PostTask(FROM_HERE,
270 base::Bind(&FullscreenController::NotifyMouseLockChange, this));
244 } 271 }
245 272
246 if (fullscreen) 273 if (fullscreen)
247 ExitTabbedFullscreenModeIfNecessary(); 274 ExitTabbedFullscreenModeIfNecessary();
275
276 UpdateFullscreenExitBubbleContent();
yzshen1 2012/04/30 19:32:40 nit: It is previously in the "if (mouse_lock)" blo
scheib 2012/05/01 03:27:07 Done. -- Reverted to previous code; added comment
248 } 277 }
249 278
250 void FullscreenController::WindowFullscreenStateChanged() { 279 void FullscreenController::WindowFullscreenStateChanged() {
251 MessageLoop::current()->PostTask(FROM_HERE, 280 MessageLoop::current()->PostTask(FROM_HERE,
252 base::Bind(&FullscreenController::NotifyFullscreenChange, this)); 281 base::Bind(&FullscreenController::NotifyFullscreenChange, this));
253 bool exiting_fullscreen; 282 bool exiting_fullscreen;
254 #if defined(OS_MACOSX) 283 #if defined(OS_MACOSX)
255 exiting_fullscreen = !window_->InPresentationMode(); 284 exiting_fullscreen = !window_->InPresentationMode();
256 #else 285 #else
257 exiting_fullscreen = !window_->IsFullscreen(); 286 exiting_fullscreen = !window_->IsFullscreen();
258 #endif 287 #endif
259 if (exiting_fullscreen) 288 if (exiting_fullscreen)
260 NotifyTabOfFullscreenExitIfNecessary(); 289 NotifyTabOfExitIfNecessary();
261 #if !defined(OS_CHROMEOS) 290 #if !defined(OS_CHROMEOS)
262 if (exiting_fullscreen) 291 if (exiting_fullscreen)
263 window_->GetDownloadShelf()->Unhide(); 292 window_->GetDownloadShelf()->Unhide();
264 else 293 else
265 window_->GetDownloadShelf()->Hide(); 294 window_->GetDownloadShelf()->Hide();
266 #endif 295 #endif
267 } 296 }
268 297
269 bool FullscreenController::HandleUserPressedEscape() { 298 bool FullscreenController::HandleUserPressedEscape() {
270 if (!IsFullscreenForTabOrPending()) 299 if (IsFullscreenForTabOrPending() ||
271 return false; 300 IsMouseLocked() || IsMouseLockRequested()) {
272 ExitTabbedFullscreenModeIfNecessary(); 301 ExitTabbedFullscreenModeIfNecessary();
yzshen1 2012/04/30 19:32:40 I don't get it: in windowed mouse lock mode, why d
scheib 2012/05/01 03:27:07 Done: Renamed to ExitTabFullscreenOrMouseLockIfNec
273 return true; 302 return true;
303 }
304
305 return false;
274 } 306 }
275 307
276 FullscreenController::~FullscreenController() {} 308 FullscreenController::~FullscreenController() {}
277 309
278 void FullscreenController::NotifyTabOfFullscreenExitIfNecessary() { 310 void FullscreenController::NotifyTabOfExitIfNecessary() {
279 if (fullscreened_tab_) { 311 if (fullscreened_tab_) {
280 RenderViewHost* rvh = 312 RenderViewHost* rvh =
281 fullscreened_tab_->web_contents()->GetRenderViewHost(); 313 fullscreened_tab_->web_contents()->GetRenderViewHost();
282 fullscreened_tab_ = NULL; 314 fullscreened_tab_ = NULL;
283 tab_caused_fullscreen_ = false; 315 tab_caused_fullscreen_ = false;
284 tab_fullscreen_accepted_ = false; 316 tab_fullscreen_accepted_ = false;
285 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
286 if (rvh) 317 if (rvh)
287 rvh->ExitFullscreen(); 318 rvh->ExitFullscreen();
288 } else { 319 }
289 DCHECK_EQ(mouse_lock_state_, MOUSELOCK_NOT_REQUESTED); 320
321 if (mouse_lock_tab_) {
322 WebContents* web_contents = mouse_lock_tab_->web_contents();
323 mouse_lock_tab_ = NULL;
324 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
325 if (web_contents)
326 web_contents->GotResponseToLockMouseRequest(false);
yzshen1 2012/04/30 19:32:40 If in ACCEPTED mode, we shouldn't call GotResponse
scheib 2012/05/01 03:27:07 Done. Changed to calling RVHV::UnlockMouse() when
327 MessageLoop::current()->PostTask(FROM_HERE,
328 base::Bind(&FullscreenController::NotifyMouseLockChange, this));
290 } 329 }
291 330
292 UpdateFullscreenExitBubbleContent(); 331 UpdateFullscreenExitBubbleContent();
293 } 332 }
294 333
295 void FullscreenController::ExitTabbedFullscreenModeIfNecessary() { 334 void FullscreenController::ExitTabbedFullscreenModeIfNecessary() {
296 if (tab_caused_fullscreen_) 335 if (tab_caused_fullscreen_)
297 ToggleFullscreenMode(); 336 ToggleFullscreenMode();
298 else 337 else
299 NotifyTabOfFullscreenExitIfNecessary(); 338 NotifyTabOfExitIfNecessary();
300 } 339 }
301 340
302 void FullscreenController::UpdateFullscreenExitBubbleContent() { 341 void FullscreenController::UpdateFullscreenExitBubbleContent() {
303 GURL url; 342 GURL url;
304 if (fullscreened_tab_) 343 if (fullscreened_tab_)
305 url = fullscreened_tab_->web_contents()->GetURL(); 344 url = fullscreened_tab_->web_contents()->GetURL();
306 else if (!extension_caused_fullscreen_.is_empty()) 345 else if (!extension_caused_fullscreen_.is_empty())
307 url = extension_caused_fullscreen_; 346 url = extension_caused_fullscreen_;
347 else if (mouse_lock_tab_)
yzshen1 2012/04/30 19:32:40 Is this order right? Consider the following two se
scheib 2012/05/01 03:27:07 I've moved the logic for using the extension url l
348 url = mouse_lock_tab_->web_contents()->GetURL();
308 349
309 window_->UpdateFullscreenExitBubbleContent(url, 350 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType();
310 GetFullscreenExitBubbleType()); 351
352 // If bubble displays buttons, unlock mouse to allow pressing them.
353 if (fullscreen_bubble::ShowButtonsForType(bubble_type)
354 && IsMouseLocked()
yzshen1 2012/04/30 19:32:40 && at the end of the previous line, please.
scheib 2012/05/01 03:27:07 Done.
355 && mouse_lock_tab_->web_contents()) {
356 mouse_lock_tab_->web_contents()->GotResponseToLockMouseRequest(false);
yzshen1 2012/04/30 19:32:40 GotResponseToLockMouseRequest() should only be cal
scheib 2012/05/01 03:27:07 Done. Changed to calling RVHV::UnlockMouse().
357 MessageLoop::current()->PostTask(FROM_HERE,
358 base::Bind(&FullscreenController::NotifyMouseLockChange, this));
359 }
360
361 window_->UpdateFullscreenExitBubbleContent(url, bubble_type);
311 } 362 }
312 363
313 void FullscreenController::NotifyFullscreenChange() { 364 void FullscreenController::NotifyFullscreenChange() {
314 content::NotificationService::current()->Notify( 365 content::NotificationService::current()->Notify(
315 chrome::NOTIFICATION_FULLSCREEN_CHANGED, 366 chrome::NOTIFICATION_FULLSCREEN_CHANGED,
316 content::Source<FullscreenController>(this), 367 content::Source<FullscreenController>(this),
317 content::NotificationService::NoDetails()); 368 content::NotificationService::NoDetails());
318 } 369 }
319 370
371 void FullscreenController::NotifyMouseLockChange() {
372 content::NotificationService::current()->Notify(
373 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
374 content::Source<FullscreenController>(this),
375 content::NotificationService::NoDetails());
376 }
377
320 FullscreenExitBubbleType FullscreenController::GetFullscreenExitBubbleType() 378 FullscreenExitBubbleType FullscreenController::GetFullscreenExitBubbleType()
321 const { 379 const {
322 if (!fullscreened_tab_) { 380 if (fullscreened_tab_) {
323 DCHECK_EQ(MOUSELOCK_NOT_REQUESTED, mouse_lock_state_); 381 if (tab_fullscreen_accepted_) {
324 return !extension_caused_fullscreen_.is_empty() ? 382 if (IsMouseLocked()) {
325 FEB_TYPE_BROWSER_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION : 383 return FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION;
326 FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; 384 } else if (IsMouseLockRequested()) {
385 return FEB_TYPE_MOUSELOCK_BUTTONS;
386 } else {
387 return FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION;
388 }
389 } else { // Full screen not yet accepted.
390 if (IsMouseLockRequested())
391 return FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS;
392 else
393 return FEB_TYPE_FULLSCREEN_BUTTONS;
394 }
395 } else if (!extension_caused_fullscreen_.is_empty()) {
396 return FEB_TYPE_BROWSER_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION;
yzshen1 2012/04/30 19:32:40 Here: what if the mouse lock is requested, etc.?
scheib 2012/05/01 03:27:07 Done. This should be used similar to Browser mode
397 } else { // Not a full screen tab.
398 if (IsMouseLocked()) {
399 return FEB_TYPE_MOUSELOCK_EXIT_INSTRUCTION;
400 } else if (IsMouseLockRequested()) {
401 return FEB_TYPE_MOUSELOCK_BUTTONS;
402 } else {
403 if (in_or_entering_fullscreen_) {
404 return FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION;
405 } else {
406 return FEB_TYPE_NONE;
407 }
408 }
327 } 409 }
328 if (fullscreened_tab_ && !tab_fullscreen_accepted_) { 410 NOTREACHED();
329 DCHECK_NE(MOUSELOCK_ACCEPTED, mouse_lock_state_); 411 return FEB_TYPE_NONE;
330 return mouse_lock_state_ == MOUSELOCK_REQUESTED ?
331 FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS : FEB_TYPE_FULLSCREEN_BUTTONS;
332 }
333 if (mouse_lock_state_ == MOUSELOCK_REQUESTED)
334 return FEB_TYPE_MOUSELOCK_BUTTONS;
335 return mouse_lock_state_ == MOUSELOCK_ACCEPTED ?
336 FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION :
337 FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION;
338 } 412 }
339 413
340 ContentSetting 414 ContentSetting
341 FullscreenController::GetFullscreenSetting(const GURL& url) const { 415 FullscreenController::GetFullscreenSetting(const GURL& url) const {
342 if (url.SchemeIsFile()) 416 if (url.SchemeIsFile())
343 return CONTENT_SETTING_ALLOW; 417 return CONTENT_SETTING_ALLOW;
344 418
345 return profile_->GetHostContentSettingsMap()->GetContentSetting(url, url, 419 return profile_->GetHostContentSettingsMap()->GetContentSetting(url, url,
346 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); 420 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string());
347 421
348 } 422 }
349 423
350 ContentSetting 424 ContentSetting
351 FullscreenController::GetMouseLockSetting(const GURL& url) const { 425 FullscreenController::GetMouseLockSetting(const GURL& url) const {
352 if (url.SchemeIsFile()) 426 if (url.SchemeIsFile())
353 return CONTENT_SETTING_ALLOW; 427 return CONTENT_SETTING_ALLOW;
354 428
355 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); 429 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap();
356 return settings_map->GetContentSetting(url, url, 430 return settings_map->GetContentSetting(url, url,
357 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); 431 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string());
358 } 432 }
359 433
360 #if defined(OS_MACOSX) 434 #if defined(OS_MACOSX)
361 void FullscreenController::TogglePresentationModeInternal(bool for_tab) { 435 void FullscreenController::TogglePresentationModeInternal(bool for_tab) {
362 bool entering_fullscreen = !window_->InPresentationMode(); 436 in_or_entering_fullscreen_ = !window_->InPresentationMode();
363 GURL url; 437 GURL url;
364 if (for_tab) { 438 if (for_tab) {
365 url = browser_->GetSelectedWebContents()->GetURL(); 439 url = browser_->GetSelectedWebContents()->GetURL();
366 tab_fullscreen_accepted_ = entering_fullscreen && 440 tab_fullscreen_accepted_ = in_or_entering_fullscreen_ &&
367 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; 441 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW;
368 } 442 }
369 if (entering_fullscreen) 443 if (in_or_entering_fullscreen_)
370 window_->EnterPresentationMode(url, GetFullscreenExitBubbleType()); 444 window_->EnterPresentationMode(url, GetFullscreenExitBubbleType());
371 else 445 else
372 window_->ExitPresentationMode(); 446 window_->ExitPresentationMode();
373 WindowFullscreenStateChanged(); 447 WindowFullscreenStateChanged();
374 } 448 }
375 #endif 449 #endif
376 450
377 // TODO(koz): Change |for_tab| to an enum. 451 // TODO(koz): Change |for_tab| to an enum.
378 void FullscreenController::ToggleFullscreenModeInternal(bool for_tab) { 452 void FullscreenController::ToggleFullscreenModeInternal(bool for_tab) {
379 bool entering_fullscreen = !window_->IsFullscreen(); 453 in_or_entering_fullscreen_ = !window_->IsFullscreen();
yzshen1 2012/04/30 19:32:40 Is it possible that there are paths to change full
scheib 2012/05/01 03:27:07 Closing a tab does call Toggle, and this state is
380 454
381 #if !defined(OS_MACOSX) 455 #if !defined(OS_MACOSX)
382 // In kiosk mode, we always want to be fullscreen. When the browser first 456 // In kiosk mode, we always want to be fullscreen. When the browser first
383 // starts we're not yet fullscreen, so let the initial toggle go through. 457 // starts we're not yet fullscreen, so let the initial toggle go through.
384 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && 458 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) &&
385 window_->IsFullscreen()) 459 window_->IsFullscreen())
386 return; 460 return;
387 #endif 461 #endif
388 462
389 GURL url; 463 GURL url;
390 if (for_tab) { 464 if (for_tab) {
391 url = browser_->GetSelectedWebContents()->GetURL(); 465 url = browser_->GetSelectedWebContents()->GetURL();
392 tab_fullscreen_accepted_ = entering_fullscreen && 466 tab_fullscreen_accepted_ = in_or_entering_fullscreen_ &&
393 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; 467 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW;
394 } else { 468 } else {
395 if (!extension_caused_fullscreen_.is_empty()) 469 if (!extension_caused_fullscreen_.is_empty())
396 url = extension_caused_fullscreen_; 470 url = extension_caused_fullscreen_;
397 content::RecordAction(UserMetricsAction("ToggleFullscreen")); 471 content::RecordAction(UserMetricsAction("ToggleFullscreen"));
398 } 472 }
399 if (entering_fullscreen) { 473 if (in_or_entering_fullscreen_) {
400 window_->EnterFullscreen(url, GetFullscreenExitBubbleType()); 474 window_->EnterFullscreen(url, GetFullscreenExitBubbleType());
401 } else { 475 } else {
402 window_->ExitFullscreen(); 476 window_->ExitFullscreen();
403 extension_caused_fullscreen_ = GURL(); 477 extension_caused_fullscreen_ = GURL();
404 } 478 }
479 UpdateFullscreenExitBubbleContent();
405 480
406 // Once the window has become fullscreen it'll call back to 481 // Once the window has become fullscreen it'll call back to
407 // WindowFullscreenStateChanged(). We don't do this immediately as 482 // WindowFullscreenStateChanged(). We don't do this immediately as
408 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let 483 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let
409 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. 484 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate.
410 485
411 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates 486 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates
412 // the necessary state of the frame. 487 // the necessary state of the frame.
413 #if defined(OS_MACOSX) 488 #if defined(OS_MACOSX)
414 WindowFullscreenStateChanged(); 489 WindowFullscreenStateChanged();
415 #endif 490 #endif
416 } 491 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698