OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 5 #include "chrome/browser/ui/exclusive_access/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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 DCHECK(web_contents->GetCapturerCount() == 0); | 89 DCHECK(web_contents->GetCapturerCount() == 0); |
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::EnterFullscreenModeForTab(WebContents* web_contents, |
100 bool enter_fullscreen) { | 100 const GURL& origin) { |
101 if (MaybeToggleFullscreenForCapturedTab(web_contents, enter_fullscreen)) { | 101 DCHECK(web_contents); |
| 102 |
| 103 if (MaybeToggleFullscreenForCapturedTab(web_contents, true)) { |
102 // During tab capture of fullscreen-within-tab views, the browser window | 104 // During tab capture of fullscreen-within-tab views, the browser window |
103 // fullscreen state is unchanged, so return now. | 105 // fullscreen state is unchanged, so return now. |
104 return; | 106 return; |
105 } | 107 } |
106 if (fullscreened_tab_) { | 108 |
107 if (web_contents != fullscreened_tab_) | 109 if (web_contents != browser_->tab_strip_model()->GetActiveWebContents() || |
| 110 IsWindowFullscreenForTabOrPending()) { |
108 return; | 111 return; |
109 } else if ( | |
110 web_contents != browser_->tab_strip_model()->GetActiveWebContents()) { | |
111 return; | |
112 } | 112 } |
113 if (IsWindowFullscreenForTabOrPending() == enter_fullscreen) | |
114 return; | |
115 | 113 |
116 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
117 // For now, avoid breaking when initiating full screen tab mode while in | 115 // For now, avoid breaking when initiating full screen tab mode while in |
| 116 // a metro snap. |
| 117 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen |
| 118 // modes with metro snap. |
| 119 if (IsInMetroSnapMode()) |
| 120 return; |
| 121 #endif |
| 122 |
| 123 SetFullscreenedTab(web_contents, origin); |
| 124 |
| 125 if (!window_->IsFullscreen()) { |
| 126 // Normal -> Tab Fullscreen. |
| 127 state_prior_to_tab_fullscreen_ = STATE_NORMAL; |
| 128 ToggleFullscreenModeInternal(TAB); |
| 129 return; |
| 130 } |
| 131 |
| 132 if (window_->IsFullscreenWithToolbar()) { |
| 133 // Browser Fullscreen with Toolbar -> Tab Fullscreen (no toolbar). |
| 134 window_->UpdateFullscreenWithToolbar(false); |
| 135 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR; |
| 136 } else { |
| 137 // Browser Fullscreen without Toolbar -> Tab Fullscreen. |
| 138 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_TOOLBAR; |
| 139 } |
| 140 |
| 141 // We need to update the fullscreen exit bubble, e.g., going from browser |
| 142 // fullscreen to tab fullscreen will need to show different content. |
| 143 if (!tab_fullscreen_accepted_) { |
| 144 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW; |
| 145 } |
| 146 UpdateFullscreenExitBubbleContent(); |
| 147 |
| 148 // This is only a change between Browser and Tab fullscreen. We generate |
| 149 // a fullscreen notification now because there is no window change. |
| 150 PostFullscreenChangeNotification(true); |
| 151 } |
| 152 |
| 153 void FullscreenController::ExitFullscreenModeForTab(WebContents* web_contents) { |
| 154 if (MaybeToggleFullscreenForCapturedTab(web_contents, false)) { |
| 155 // During tab capture of fullscreen-within-tab views, the browser window |
| 156 // fullscreen state is unchanged, so return now. |
| 157 return; |
| 158 } |
| 159 |
| 160 if (!IsWindowFullscreenForTabOrPending() || |
| 161 web_contents != fullscreened_tab_) { |
| 162 return; |
| 163 } |
| 164 |
| 165 #if defined(OS_WIN) |
| 166 // For now, avoid breaking when initiating full screen tab mode while in |
118 // a metro snap. | 167 // a metro snap. |
119 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen | 168 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen |
120 // modes with metro snap. | 169 // modes with metro snap. |
121 if (IsInMetroSnapMode()) | 170 if (IsInMetroSnapMode()) |
122 return; | 171 return; |
123 #endif | 172 #endif |
124 | 173 |
125 bool in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); | 174 if (!window_->IsFullscreen()) |
| 175 return; |
126 | 176 |
127 if (enter_fullscreen) { | 177 if (IsFullscreenCausedByTab()) { |
128 SetFullscreenedTab(web_contents); | 178 // Tab Fullscreen -> Normal. |
129 if (!in_browser_or_tab_fullscreen_mode) { | 179 ToggleFullscreenModeInternal(TAB); |
130 // Normal -> Tab Fullscreen. | 180 return; |
131 state_prior_to_tab_fullscreen_ = STATE_NORMAL; | 181 } |
132 ToggleFullscreenModeInternal(TAB); | |
133 } else { | |
134 if (window_->IsFullscreenWithToolbar()) { | |
135 // Browser Fullscreen with Toolbar -> Tab Fullscreen (no toolbar). | |
136 window_->UpdateFullscreenWithToolbar(false); | |
137 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR; | |
138 } else { | |
139 // Browser Fullscreen without Toolbar -> Tab Fullscreen. | |
140 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_TOOLBAR; | |
141 } | |
142 | 182 |
143 // We need to update the fullscreen exit bubble, e.g., going from browser | 183 // Tab Fullscreen -> Browser Fullscreen (with or without toolbar). |
144 // fullscreen to tab fullscreen will need to show different content. | 184 if (state_prior_to_tab_fullscreen_ == STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR) { |
145 const GURL& url = web_contents->GetURL(); | 185 // Tab Fullscreen (no toolbar) -> Browser Fullscreen with Toolbar. |
146 if (!tab_fullscreen_accepted_) { | 186 window_->UpdateFullscreenWithToolbar(true); |
147 tab_fullscreen_accepted_ = | 187 } |
148 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | |
149 } | |
150 UpdateFullscreenExitBubbleContent(); | |
151 | |
152 // This is only a change between Browser and Tab fullscreen. We generate | |
153 // a fullscreen notification now because there is no window change. | |
154 PostFullscreenChangeNotification(true); | |
155 } | |
156 } else { | |
157 if (in_browser_or_tab_fullscreen_mode) { | |
158 if (IsFullscreenCausedByTab()) { | |
159 // Tab Fullscreen -> Normal. | |
160 ToggleFullscreenModeInternal(TAB); | |
161 } else { | |
162 // Tab Fullscreen -> Browser Fullscreen (with or without toolbar). | |
163 if (state_prior_to_tab_fullscreen_ == | |
164 STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR) { | |
165 // Tab Fullscreen (no toolbar) -> Browser Fullscreen with Toolbar. | |
166 window_->UpdateFullscreenWithToolbar(true); | |
167 } | |
168 | 188 |
169 #if defined(OS_MACOSX) | 189 #if defined(OS_MACOSX) |
170 // Clear the bubble URL, which forces the Mac UI to redraw. | 190 // Clear the bubble URL, which forces the Mac UI to redraw. |
171 UpdateFullscreenExitBubbleContent(); | 191 UpdateFullscreenExitBubbleContent(); |
172 #endif // defined(OS_MACOSX) | 192 #endif // defined(OS_MACOSX) |
173 | 193 |
174 // If currently there is a tab in "tab fullscreen" mode and fullscreen | 194 // If currently there is a tab in "tab fullscreen" mode and fullscreen |
175 // was not caused by it (i.e., previously it was in "browser fullscreen" | 195 // was not caused by it (i.e., previously it was in "browser fullscreen" |
176 // mode), we need to switch back to "browser fullscreen" mode. In this | 196 // mode), we need to switch back to "browser fullscreen" mode. In this |
177 // case, all we have to do is notifying the tab that it has exited "tab | 197 // case, all we have to do is notifying the tab that it has exited "tab |
178 // fullscreen" mode. | 198 // fullscreen" mode. |
179 NotifyTabOfExitIfNecessary(); | 199 NotifyTabOfExitIfNecessary(); |
180 | 200 |
181 // This is only a change between Browser and Tab fullscreen. We generate | 201 // This is only a change between Browser and Tab fullscreen. We generate |
182 // a fullscreen notification now because there is no window change. | 202 // a fullscreen notification now because there is no window change. |
183 PostFullscreenChangeNotification(true); | 203 PostFullscreenChangeNotification(true); |
184 } | |
185 } | |
186 } | |
187 } | 204 } |
188 | 205 |
189 bool FullscreenController::IsInMetroSnapMode() { | 206 bool FullscreenController::IsInMetroSnapMode() { |
190 #if defined(OS_WIN) | 207 #if defined(OS_WIN) |
191 return window_->IsInMetroSnapMode(); | 208 return window_->IsInMetroSnapMode(); |
192 #else | 209 #else |
193 return false; | 210 return false; |
194 #endif | 211 #endif |
195 } | 212 } |
196 | 213 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 319 |
303 content::RenderWidgetHostView* const current_fs_view = | 320 content::RenderWidgetHostView* const current_fs_view = |
304 old_contents->GetFullscreenRenderWidgetHostView(); | 321 old_contents->GetFullscreenRenderWidgetHostView(); |
305 if (current_fs_view) | 322 if (current_fs_view) |
306 current_fs_view->SetSize(old_contents->GetPreferredSize()); | 323 current_fs_view->SetSize(old_contents->GetPreferredSize()); |
307 ResizeWebContents(old_contents, old_contents->GetPreferredSize()); | 324 ResizeWebContents(old_contents, old_contents->GetPreferredSize()); |
308 } | 325 } |
309 | 326 |
310 void FullscreenController::OnTabClosing(WebContents* web_contents) { | 327 void FullscreenController::OnTabClosing(WebContents* web_contents) { |
311 if (IsFullscreenForCapturedTab(web_contents)) { | 328 if (IsFullscreenForCapturedTab(web_contents)) { |
312 RenderViewHost* const rvh = web_contents->GetRenderViewHost(); | 329 web_contents->ExitFullscreen(); |
313 if (rvh) | |
314 rvh->ExitFullscreen(); | |
315 } else if (web_contents == fullscreened_tab_ || | 330 } else if (web_contents == fullscreened_tab_ || |
316 web_contents == mouse_lock_tab_) { | 331 web_contents == mouse_lock_tab_) { |
317 ExitTabFullscreenOrMouseLockIfNecessary(); | 332 ExitTabFullscreenOrMouseLockIfNecessary(); |
318 // The call to exit fullscreen may result in asynchronous notification of | 333 // The call to exit fullscreen may result in asynchronous notification of |
319 // fullscreen state change (e.g., on Linux). We don't want to rely on it | 334 // fullscreen state change (e.g., on Linux). We don't want to rely on it |
320 // to call NotifyTabOfExitIfNecessary(), because at that point | 335 // to call NotifyTabOfExitIfNecessary(), because at that point |
321 // |fullscreened_tab_| may not be valid. Instead, we call it here to clean | 336 // |fullscreened_tab_| may not be valid. Instead, we call it here to clean |
322 // up tab fullscreen related state. | 337 // up tab fullscreen related state. |
323 NotifyTabOfExitIfNecessary(); | 338 NotifyTabOfExitIfNecessary(); |
324 } | 339 } |
(...skipping 16 matching lines...) Expand all Loading... |
341 window_->GetDownloadShelf()->Hide(); | 356 window_->GetDownloadShelf()->Hide(); |
342 if (window_->GetStatusBubble()) | 357 if (window_->GetStatusBubble()) |
343 window_->GetStatusBubble()->Hide(); | 358 window_->GetStatusBubble()->Hide(); |
344 } | 359 } |
345 } | 360 } |
346 | 361 |
347 bool FullscreenController::HandleUserPressedEscape() { | 362 bool FullscreenController::HandleUserPressedEscape() { |
348 WebContents* const active_web_contents = | 363 WebContents* const active_web_contents = |
349 browser_->tab_strip_model()->GetActiveWebContents(); | 364 browser_->tab_strip_model()->GetActiveWebContents(); |
350 if (IsFullscreenForCapturedTab(active_web_contents)) { | 365 if (IsFullscreenForCapturedTab(active_web_contents)) { |
351 RenderViewHost* const rvh = active_web_contents->GetRenderViewHost(); | 366 active_web_contents->ExitFullscreen(); |
352 if (rvh) | |
353 rvh->ExitFullscreen(); | |
354 return true; | 367 return true; |
355 } else if (IsWindowFullscreenForTabOrPending() || | 368 } else if (IsWindowFullscreenForTabOrPending() || |
356 IsMouseLocked() || IsMouseLockRequested()) { | 369 IsMouseLocked() || IsMouseLockRequested()) { |
357 ExitTabFullscreenOrMouseLockIfNecessary(); | 370 ExitTabFullscreenOrMouseLockIfNecessary(); |
358 return true; | 371 return true; |
359 } | 372 } |
360 | 373 |
361 return false; | 374 return false; |
362 } | 375 } |
363 | 376 |
364 void FullscreenController::ExitTabOrBrowserFullscreenToPreviousState() { | 377 void FullscreenController::ExitTabOrBrowserFullscreenToPreviousState() { |
365 if (IsWindowFullscreenForTabOrPending()) | 378 if (IsWindowFullscreenForTabOrPending()) |
366 ExitTabFullscreenOrMouseLockIfNecessary(); | 379 ExitTabFullscreenOrMouseLockIfNecessary(); |
367 else if (IsFullscreenForBrowser()) | 380 else if (IsFullscreenForBrowser()) |
368 ExitFullscreenModeInternal(); | 381 ExitFullscreenModeInternal(); |
369 } | 382 } |
370 | 383 |
371 void FullscreenController::OnAcceptFullscreenPermission() { | 384 void FullscreenController::OnAcceptFullscreenPermission() { |
372 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); | 385 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); |
373 bool mouse_lock = false; | 386 bool mouse_lock = false; |
374 bool fullscreen = false; | 387 bool fullscreen = false; |
375 exclusive_access_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | 388 exclusive_access_bubble::PermissionRequestedByType(bubble_type, &fullscreen, |
376 &mouse_lock); | 389 &mouse_lock); |
377 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); | 390 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); |
378 DCHECK(!(mouse_lock && IsMouseLocked())); | 391 DCHECK(!(mouse_lock && IsMouseLocked())); |
379 | 392 |
380 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 393 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); |
381 | 394 |
382 GURL url = GetFullscreenExitBubbleURL(); | |
383 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); | |
384 | |
385 if (mouse_lock && !IsMouseLocked()) { | 395 if (mouse_lock && !IsMouseLocked()) { |
386 DCHECK(IsMouseLockRequested()); | 396 DCHECK(IsMouseLockRequested()); |
| 397 |
| 398 GURL url = GetFullscreenExitBubbleURL(); |
| 399 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); |
| 400 |
387 // TODO(markusheintz): We should allow patterns for all possible URLs here. | 401 // TODO(markusheintz): We should allow patterns for all possible URLs here. |
388 if (pattern.IsValid()) { | 402 if (pattern.IsValid()) { |
389 settings_map->SetContentSetting( | 403 settings_map->SetContentSetting( |
390 pattern, ContentSettingsPattern::Wildcard(), | 404 pattern, ContentSettingsPattern::Wildcard(), |
391 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), | 405 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), |
392 CONTENT_SETTING_ALLOW); | 406 CONTENT_SETTING_ALLOW); |
393 } | 407 } |
394 | 408 |
395 if (mouse_lock_tab_ && | 409 if (mouse_lock_tab_ && |
396 mouse_lock_tab_->GotResponseToLockMouseRequest(true)) { | 410 mouse_lock_tab_->GotResponseToLockMouseRequest(true)) { |
397 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | 411 mouse_lock_state_ = MOUSELOCK_ACCEPTED; |
398 } else { | 412 } else { |
399 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 413 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
400 SetMouseLockTab(NULL); | 414 SetMouseLockTab(NULL); |
401 } | 415 } |
402 NotifyMouseLockChange(); | 416 NotifyMouseLockChange(); |
403 } | 417 } |
404 | 418 |
405 if (fullscreen && !tab_fullscreen_accepted_) { | 419 if (fullscreen && !tab_fullscreen_accepted_) { |
406 DCHECK(fullscreened_tab_); | 420 DCHECK(fullscreened_tab_); |
407 if (pattern.IsValid()) { | 421 // Origins can enter fullscreen even when embedded in other origins. |
| 422 // Permission is tracked based on the combinations of requester and |
| 423 // embedder. Thus, even if a requesting origin has been previously approved |
| 424 // for embedder A, it will not be approved when embedded in a different |
| 425 // origin B. |
| 426 // |
| 427 // However, an exception is made when a requester and an embedder are the |
| 428 // same origin. In other words, if the requester is the top-level frame. If |
| 429 // that combination is ALLOWED, then future requests from that origin will |
| 430 // succeed no matter what the embedder is. For example, if youtube.com |
| 431 // is visited and user selects ALLOW. Later user visits example.com which |
| 432 // embeds youtube.com in an iframe, which is then ALLOWED to go fullscreen. |
| 433 ContentSettingsPattern primary_pattern = |
| 434 ContentSettingsPattern::FromURLNoWildcard(GetRequestingOrigin()); |
| 435 ContentSettingsPattern secondary_pattern = |
| 436 ContentSettingsPattern::FromURLNoWildcard(GetEmbeddingOrigin()); |
| 437 |
| 438 // ContentSettings requires valid patterns and the patterns might be invalid |
| 439 // in some edge cases like if the current frame is about:blank. |
| 440 if (primary_pattern.IsValid() && secondary_pattern.IsValid()) { |
408 settings_map->SetContentSetting( | 441 settings_map->SetContentSetting( |
409 pattern, ContentSettingsPattern::Wildcard(), | 442 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_FULLSCREEN, |
410 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(), | 443 std::string(), CONTENT_SETTING_ALLOW); |
411 CONTENT_SETTING_ALLOW); | |
412 } | 444 } |
413 tab_fullscreen_accepted_ = true; | 445 tab_fullscreen_accepted_ = true; |
414 } | 446 } |
415 UpdateFullscreenExitBubbleContent(); | 447 UpdateFullscreenExitBubbleContent(); |
416 } | 448 } |
417 | 449 |
418 void FullscreenController::OnDenyFullscreenPermission() { | 450 void FullscreenController::OnDenyFullscreenPermission() { |
419 if (!fullscreened_tab_ && !mouse_lock_tab_) | 451 if (!fullscreened_tab_ && !mouse_lock_tab_) |
420 return; | 452 return; |
421 | 453 |
(...skipping 26 matching lines...) Expand all Loading... |
448 const content::NotificationSource& source, | 480 const content::NotificationSource& source, |
449 const content::NotificationDetails& details) { | 481 const content::NotificationDetails& details) { |
450 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); | 482 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); |
451 if (content::Details<content::LoadCommittedDetails>(details)-> | 483 if (content::Details<content::LoadCommittedDetails>(details)-> |
452 is_navigation_to_different_page()) | 484 is_navigation_to_different_page()) |
453 ExitTabFullscreenOrMouseLockIfNecessary(); | 485 ExitTabFullscreenOrMouseLockIfNecessary(); |
454 } | 486 } |
455 | 487 |
456 GURL FullscreenController::GetFullscreenExitBubbleURL() const { | 488 GURL FullscreenController::GetFullscreenExitBubbleURL() const { |
457 if (fullscreened_tab_) | 489 if (fullscreened_tab_) |
458 return fullscreened_tab_->GetURL(); | 490 return GetRequestingOrigin(); |
459 if (mouse_lock_tab_) | 491 if (mouse_lock_tab_) |
460 return mouse_lock_tab_->GetURL(); | 492 return mouse_lock_tab_->GetURL(); |
461 return extension_caused_fullscreen_; | 493 return extension_caused_fullscreen_; |
462 } | 494 } |
463 | 495 |
464 ExclusiveAccessBubbleType FullscreenController::GetExclusiveAccessBubbleType() | 496 ExclusiveAccessBubbleType FullscreenController::GetExclusiveAccessBubbleType() |
465 const { | 497 const { |
466 // In kiosk and exclusive app mode we always want to be fullscreen and do not | 498 // 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. | 499 // want to show exit instructions for browser mode fullscreen. |
468 bool app_mode = false; | 500 bool app_mode = false; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 | 557 |
526 void FullscreenController::NotifyFullscreenChange(bool is_fullscreen) { | 558 void FullscreenController::NotifyFullscreenChange(bool is_fullscreen) { |
527 content::NotificationService::current()->Notify( | 559 content::NotificationService::current()->Notify( |
528 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 560 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
529 content::Source<FullscreenController>(this), | 561 content::Source<FullscreenController>(this), |
530 content::Details<bool>(&is_fullscreen)); | 562 content::Details<bool>(&is_fullscreen)); |
531 } | 563 } |
532 | 564 |
533 void FullscreenController::NotifyTabOfExitIfNecessary() { | 565 void FullscreenController::NotifyTabOfExitIfNecessary() { |
534 if (fullscreened_tab_) { | 566 if (fullscreened_tab_) { |
535 RenderViewHost* rvh = fullscreened_tab_->GetRenderViewHost(); | 567 WebContents* web_contents = fullscreened_tab_; |
536 SetFullscreenedTab(NULL); | 568 // This call will set |fullscreened_tab_| to nullptr. |
| 569 SetFullscreenedTab(nullptr, GURL()); |
537 state_prior_to_tab_fullscreen_ = STATE_INVALID; | 570 state_prior_to_tab_fullscreen_ = STATE_INVALID; |
538 tab_fullscreen_accepted_ = false; | 571 tab_fullscreen_accepted_ = false; |
539 if (rvh) | 572 web_contents->ExitFullscreen(); |
540 rvh->ExitFullscreen(); | |
541 } | 573 } |
542 | 574 |
543 if (mouse_lock_tab_) { | 575 if (mouse_lock_tab_) { |
544 if (IsMouseLockRequested()) { | 576 if (IsMouseLockRequested()) { |
545 mouse_lock_tab_->GotResponseToLockMouseRequest(false); | 577 mouse_lock_tab_->GotResponseToLockMouseRequest(false); |
546 NotifyMouseLockChange(); | 578 NotifyMouseLockChange(); |
547 } else { | 579 } else { |
548 UnlockMouse(); | 580 UnlockMouse(); |
549 } | 581 } |
550 SetMouseLockTab(NULL); | 582 SetMouseLockTab(NULL); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 EnterFullscreenModeInternal(option); | 635 EnterFullscreenModeInternal(option); |
604 else | 636 else |
605 ExitFullscreenModeInternal(); | 637 ExitFullscreenModeInternal(); |
606 } | 638 } |
607 | 639 |
608 void FullscreenController::EnterFullscreenModeInternal( | 640 void FullscreenController::EnterFullscreenModeInternal( |
609 FullscreenInternalOption option) { | 641 FullscreenInternalOption option) { |
610 toggled_into_fullscreen_ = true; | 642 toggled_into_fullscreen_ = true; |
611 GURL url; | 643 GURL url; |
612 if (option == TAB) { | 644 if (option == TAB) { |
613 url = browser_->tab_strip_model()->GetActiveWebContents()->GetURL(); | 645 url = GetRequestingOrigin(); |
614 tab_fullscreen_accepted_ = | 646 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW; |
615 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | |
616 } else { | 647 } else { |
617 if (!extension_caused_fullscreen_.is_empty()) | 648 if (!extension_caused_fullscreen_.is_empty()) |
618 url = extension_caused_fullscreen_; | 649 url = extension_caused_fullscreen_; |
619 } | 650 } |
620 | 651 |
621 if (option == BROWSER) | 652 if (option == BROWSER) |
622 content::RecordAction(UserMetricsAction("ToggleFullscreen")); | 653 content::RecordAction(UserMetricsAction("ToggleFullscreen")); |
623 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions | 654 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions |
624 // from tab fullscreen out to browser with toolbar. | 655 // from tab fullscreen out to browser with toolbar. |
625 | 656 |
(...skipping 15 matching lines...) Expand all Loading... |
641 // state_prior_to_tab_fullscreen_ to match them else other logic using | 672 // state_prior_to_tab_fullscreen_ to match them else other logic using |
642 // state_prior_to_tab_fullscreen_ will be incorrect. | 673 // state_prior_to_tab_fullscreen_ will be incorrect. |
643 NotifyTabOfExitIfNecessary(); | 674 NotifyTabOfExitIfNecessary(); |
644 #endif | 675 #endif |
645 window_->ExitFullscreen(); | 676 window_->ExitFullscreen(); |
646 extension_caused_fullscreen_ = GURL(); | 677 extension_caused_fullscreen_ = GURL(); |
647 | 678 |
648 UpdateFullscreenExitBubbleContent(); | 679 UpdateFullscreenExitBubbleContent(); |
649 } | 680 } |
650 | 681 |
651 void FullscreenController::SetFullscreenedTab(WebContents* tab) { | 682 void FullscreenController::SetFullscreenedTab(WebContents* tab, |
| 683 const GURL& origin) { |
652 fullscreened_tab_ = tab; | 684 fullscreened_tab_ = tab; |
| 685 fullscreened_origin_ = origin; |
653 UpdateNotificationRegistrations(); | 686 UpdateNotificationRegistrations(); |
654 } | 687 } |
655 | 688 |
656 void FullscreenController::SetMouseLockTab(WebContents* tab) { | 689 void FullscreenController::SetMouseLockTab(WebContents* tab) { |
657 mouse_lock_tab_ = tab; | 690 mouse_lock_tab_ = tab; |
658 UpdateNotificationRegistrations(); | 691 UpdateNotificationRegistrations(); |
659 } | 692 } |
660 | 693 |
661 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { | 694 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { |
662 if (IsWindowFullscreenForTabOrPending()) | 695 if (IsWindowFullscreenForTabOrPending()) |
663 ToggleFullscreenModeForTab(fullscreened_tab_, false); | 696 ExitFullscreenModeForTab(fullscreened_tab_); |
664 else | 697 else |
665 NotifyTabOfExitIfNecessary(); | 698 NotifyTabOfExitIfNecessary(); |
666 } | 699 } |
667 | 700 |
668 void FullscreenController::UpdateFullscreenExitBubbleContent() { | 701 void FullscreenController::UpdateFullscreenExitBubbleContent() { |
669 GURL url = GetFullscreenExitBubbleURL(); | 702 GURL url = GetFullscreenExitBubbleURL(); |
670 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); | 703 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); |
671 | 704 |
672 // If bubble displays buttons, unlock mouse to allow pressing them. | 705 // If bubble displays buttons, unlock mouse to allow pressing them. |
673 if (exclusive_access_bubble::ShowButtonsForType(bubble_type) && | 706 if (exclusive_access_bubble::ShowButtonsForType(bubble_type) && |
674 IsMouseLocked()) | 707 IsMouseLocked()) |
675 UnlockMouse(); | 708 UnlockMouse(); |
676 | 709 |
677 window_->UpdateFullscreenExitBubbleContent(url, bubble_type); | 710 window_->UpdateFullscreenExitBubbleContent(url, bubble_type); |
678 } | 711 } |
679 | 712 |
680 ContentSetting | 713 ContentSetting FullscreenController::GetFullscreenSetting() const { |
681 FullscreenController::GetFullscreenSetting(const GURL& url) const { | 714 DCHECK(fullscreened_tab_); |
| 715 |
| 716 GURL url = GetRequestingOrigin(); |
| 717 |
682 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) | 718 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) |
683 return CONTENT_SETTING_ALLOW; | 719 return CONTENT_SETTING_ALLOW; |
684 | 720 |
685 return profile_->GetHostContentSettingsMap()->GetContentSetting(url, url, | 721 // If the permission was granted to the website with no embedder, it should |
686 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); | 722 // always be allowed, even if embedded. |
| 723 if (profile_->GetHostContentSettingsMap()->GetContentSetting( |
| 724 url, url, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()) == |
| 725 CONTENT_SETTING_ALLOW) { |
| 726 return CONTENT_SETTING_ALLOW; |
| 727 } |
| 728 |
| 729 // See the comment above the call to |SetContentSetting()| for how the |
| 730 // requesting and embedding origins interact with each other wrt permissions. |
| 731 return profile_->GetHostContentSettingsMap()->GetContentSetting( |
| 732 url, GetEmbeddingOrigin(), CONTENT_SETTINGS_TYPE_FULLSCREEN, |
| 733 std::string()); |
687 } | 734 } |
688 | 735 |
689 ContentSetting | 736 ContentSetting |
690 FullscreenController::GetMouseLockSetting(const GURL& url) const { | 737 FullscreenController::GetMouseLockSetting(const GURL& url) const { |
691 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) | 738 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) |
692 return CONTENT_SETTING_ALLOW; | 739 return CONTENT_SETTING_ALLOW; |
693 | 740 |
694 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 741 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); |
695 return settings_map->GetContentSetting(url, url, | 742 return settings_map->GetContentSetting(url, url, |
696 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); | 743 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ? | 794 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ? |
748 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL; | 795 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL; |
749 if (!mouse_lock_view) { | 796 if (!mouse_lock_view) { |
750 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost(); | 797 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost(); |
751 if (rvh) | 798 if (rvh) |
752 mouse_lock_view = rvh->GetView(); | 799 mouse_lock_view = rvh->GetView(); |
753 } | 800 } |
754 if (mouse_lock_view) | 801 if (mouse_lock_view) |
755 mouse_lock_view->UnlockMouse(); | 802 mouse_lock_view->UnlockMouse(); |
756 } | 803 } |
| 804 |
| 805 GURL FullscreenController::GetRequestingOrigin() const { |
| 806 DCHECK(fullscreened_tab_); |
| 807 |
| 808 if (!fullscreened_origin_.is_empty()) |
| 809 return fullscreened_origin_; |
| 810 |
| 811 return fullscreened_tab_->GetLastCommittedURL(); |
| 812 } |
| 813 |
| 814 GURL FullscreenController::GetEmbeddingOrigin() const { |
| 815 DCHECK(fullscreened_tab_); |
| 816 |
| 817 return fullscreened_tab_->GetLastCommittedURL(); |
| 818 } |
OLD | NEW |