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

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

Powered by Google App Engine
This is Rietveld 408576698