| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/mouse_lock_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/message_loop/message_loop.h" | |
| 10 #include "chrome/browser/app_mode/app_mode_utils.h" | |
| 11 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/download/download_shelf.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 16 #include "chrome/browser/ui/exclusive_access/fullscreen_within_tab_helper.h" | |
| 17 #include "chrome/browser/ui/status_bubble.h" | |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 19 #include "chrome/browser/ui/web_contents_sizer.h" | |
| 20 #include "chrome/common/chrome_switches.h" | |
| 21 #include "components/content_settings/core/browser/host_content_settings_map.h" | 11 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 22 #include "content/public/browser/navigation_details.h" | |
| 23 #include "content/public/browser/navigation_entry.h" | |
| 24 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/browser/render_widget_host_view.h" | 14 #include "content/public/browser/render_widget_host_view.h" |
| 27 #include "content/public/browser/user_metrics.h" | |
| 28 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 29 #include "extensions/common/extension.h" | |
| 30 | 16 |
| 31 #if !defined(OS_MACOSX) | |
| 32 #include "base/prefs/pref_service.h" | |
| 33 #include "chrome/common/pref_names.h" | |
| 34 #endif | |
| 35 | |
| 36 using base::UserMetricsAction; | |
| 37 using content::RenderViewHost; | 17 using content::RenderViewHost; |
| 38 using content::WebContents; | 18 using content::WebContents; |
| 39 | 19 |
| 40 FullscreenController::FullscreenController(Browser* browser) | 20 MouseLockController::MouseLockController(ExclusiveAccessManager* manager, |
| 41 : browser_(browser), | 21 Browser* browser) |
| 42 window_(browser->window()), | 22 : ExclusiveAccessControllerBase(manager, browser), |
| 43 profile_(browser->profile()), | 23 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED) { |
| 44 fullscreened_tab_(NULL), | |
| 45 state_prior_to_tab_fullscreen_(STATE_INVALID), | |
| 46 tab_fullscreen_accepted_(false), | |
| 47 toggled_into_fullscreen_(false), | |
| 48 mouse_lock_tab_(NULL), | |
| 49 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED), | |
| 50 reentrant_window_state_change_call_check_(false), | |
| 51 is_privileged_fullscreen_for_testing_(false), | |
| 52 ptr_factory_(this) { | |
| 53 DCHECK(window_); | |
| 54 DCHECK(profile_); | |
| 55 } | 24 } |
| 56 | 25 |
| 57 FullscreenController::~FullscreenController() { | 26 MouseLockController::~MouseLockController() { |
| 58 } | 27 } |
| 59 | 28 |
| 60 bool FullscreenController::IsFullscreenForBrowser() const { | 29 bool MouseLockController::IsMouseLocked() const { |
| 61 return window_->IsFullscreen() && !IsFullscreenCausedByTab(); | |
| 62 } | |
| 63 | |
| 64 void FullscreenController::ToggleBrowserFullscreenMode() { | |
| 65 extension_caused_fullscreen_ = GURL(); | |
| 66 ToggleFullscreenModeInternal(BROWSER); | |
| 67 } | |
| 68 | |
| 69 void FullscreenController::ToggleBrowserFullscreenWithToolbar() { | |
| 70 ToggleFullscreenModeInternal(BROWSER_WITH_TOOLBAR); | |
| 71 } | |
| 72 | |
| 73 void FullscreenController::ToggleBrowserFullscreenModeWithExtension( | |
| 74 const GURL& extension_url) { | |
| 75 // |extension_caused_fullscreen_| will be reset if this causes fullscreen to | |
| 76 // exit. | |
| 77 extension_caused_fullscreen_ = extension_url; | |
| 78 ToggleFullscreenModeInternal(BROWSER); | |
| 79 } | |
| 80 | |
| 81 bool FullscreenController::IsWindowFullscreenForTabOrPending() const { | |
| 82 return fullscreened_tab_ != NULL; | |
| 83 } | |
| 84 | |
| 85 bool FullscreenController::IsFullscreenForTabOrPending( | |
| 86 const WebContents* web_contents) const { | |
| 87 if (web_contents == fullscreened_tab_) { | |
| 88 DCHECK(web_contents == browser_->tab_strip_model()->GetActiveWebContents()); | |
| 89 DCHECK(web_contents->GetCapturerCount() == 0); | |
| 90 return true; | |
| 91 } | |
| 92 return IsFullscreenForCapturedTab(web_contents); | |
| 93 } | |
| 94 | |
| 95 bool FullscreenController::IsFullscreenCausedByTab() const { | |
| 96 return state_prior_to_tab_fullscreen_ == STATE_NORMAL; | |
| 97 } | |
| 98 | |
| 99 void FullscreenController::EnterFullscreenModeForTab(WebContents* web_contents, | |
| 100 const GURL& origin) { | |
| 101 DCHECK(web_contents); | |
| 102 | |
| 103 if (MaybeToggleFullscreenForCapturedTab(web_contents, true)) { | |
| 104 // During tab capture of fullscreen-within-tab views, the browser window | |
| 105 // fullscreen state is unchanged, so return now. | |
| 106 return; | |
| 107 } | |
| 108 | |
| 109 if (web_contents != browser_->tab_strip_model()->GetActiveWebContents() || | |
| 110 IsWindowFullscreenForTabOrPending()) { | |
| 111 return; | |
| 112 } | |
| 113 | |
| 114 #if defined(OS_WIN) | |
| 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 | |
| 167 // a metro snap. | |
| 168 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen | |
| 169 // modes with metro snap. | |
| 170 if (IsInMetroSnapMode()) | |
| 171 return; | |
| 172 #endif | |
| 173 | |
| 174 if (!window_->IsFullscreen()) | |
| 175 return; | |
| 176 | |
| 177 if (IsFullscreenCausedByTab()) { | |
| 178 // Tab Fullscreen -> Normal. | |
| 179 ToggleFullscreenModeInternal(TAB); | |
| 180 return; | |
| 181 } | |
| 182 | |
| 183 // Tab Fullscreen -> Browser Fullscreen (with or without toolbar). | |
| 184 if (state_prior_to_tab_fullscreen_ == STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR) { | |
| 185 // Tab Fullscreen (no toolbar) -> Browser Fullscreen with Toolbar. | |
| 186 window_->UpdateFullscreenWithToolbar(true); | |
| 187 } | |
| 188 | |
| 189 #if defined(OS_MACOSX) | |
| 190 // Clear the bubble URL, which forces the Mac UI to redraw. | |
| 191 UpdateFullscreenExitBubbleContent(); | |
| 192 #endif // defined(OS_MACOSX) | |
| 193 | |
| 194 // If currently there is a tab in "tab fullscreen" mode and fullscreen | |
| 195 // was not caused by it (i.e., previously it was in "browser fullscreen" | |
| 196 // mode), we need to switch back to "browser fullscreen" mode. In this | |
| 197 // case, all we have to do is notifying the tab that it has exited "tab | |
| 198 // fullscreen" mode. | |
| 199 NotifyTabOfExitIfNecessary(); | |
| 200 | |
| 201 // This is only a change between Browser and Tab fullscreen. We generate | |
| 202 // a fullscreen notification now because there is no window change. | |
| 203 PostFullscreenChangeNotification(true); | |
| 204 } | |
| 205 | |
| 206 bool FullscreenController::IsInMetroSnapMode() { | |
| 207 #if defined(OS_WIN) | |
| 208 return window_->IsInMetroSnapMode(); | |
| 209 #else | |
| 210 return false; | |
| 211 #endif | |
| 212 } | |
| 213 | |
| 214 #if defined(OS_WIN) | |
| 215 void FullscreenController::SetMetroSnapMode(bool enable) { | |
| 216 reentrant_window_state_change_call_check_ = false; | |
| 217 | |
| 218 toggled_into_fullscreen_ = false; | |
| 219 window_->SetMetroSnapMode(enable); | |
| 220 | |
| 221 // FullscreenController unit tests for metro snap assume that on Windows calls | |
| 222 // to WindowFullscreenStateChanged are reentrant. If that assumption is | |
| 223 // invalidated, the tests must be updated to maintain coverage. | |
| 224 CHECK(reentrant_window_state_change_call_check_); | |
| 225 } | |
| 226 #endif // defined(OS_WIN) | |
| 227 | |
| 228 bool FullscreenController::IsMouseLockRequested() const { | |
| 229 return mouse_lock_state_ == MOUSELOCK_REQUESTED; | |
| 230 } | |
| 231 | |
| 232 bool FullscreenController::IsMouseLocked() const { | |
| 233 return mouse_lock_state_ == MOUSELOCK_ACCEPTED || | 30 return mouse_lock_state_ == MOUSELOCK_ACCEPTED || |
| 234 mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY; | 31 mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY; |
| 235 } | 32 } |
| 236 | 33 |
| 237 void FullscreenController::RequestToLockMouse(WebContents* web_contents, | 34 bool MouseLockController::IsMouseLockSilentlyAccepted() const { |
| 238 bool user_gesture, | 35 return mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY; |
| 239 bool last_unlocked_by_target) { | 36 } |
| 37 |
| 38 void MouseLockController::RequestToLockMouse(WebContents* web_contents, |
| 39 bool user_gesture, |
| 40 bool last_unlocked_by_target) { |
| 240 DCHECK(!IsMouseLocked()); | 41 DCHECK(!IsMouseLocked()); |
| 241 NotifyMouseLockChange(); | 42 NotifyMouseLockChange(); |
| 242 | 43 |
| 243 // Must have a user gesture to prevent misbehaving sites from constantly | 44 // Must have a user gesture to prevent misbehaving sites from constantly |
| 244 // re-locking the mouse. Exceptions are when the page has unlocked | 45 // re-locking the mouse. Exceptions are when the page has unlocked |
| 245 // (i.e. not the user), or if we're in tab fullscreen (user gesture required | 46 // (i.e. not the user), or if we're in tab fullscreen (user gesture required |
| 246 // for that) | 47 // for that) |
| 247 if (!last_unlocked_by_target && !user_gesture && | 48 if (!last_unlocked_by_target && !user_gesture && |
| 248 !IsFullscreenForTabOrPending(web_contents)) { | 49 !exclusive_access_manager() |
| 50 ->fullscreen_controller() |
| 51 ->IsFullscreenForTabOrPending(web_contents)) { |
| 249 web_contents->GotResponseToLockMouseRequest(false); | 52 web_contents->GotResponseToLockMouseRequest(false); |
| 250 return; | 53 return; |
| 251 } | 54 } |
| 252 SetMouseLockTab(web_contents); | 55 SetTabWithExclusiveAccess(web_contents); |
| 253 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); | 56 ExclusiveAccessBubbleType bubble_type = |
| 57 exclusive_access_manager()->GetExclusiveAccessExitBubbleType(); |
| 254 | 58 |
| 255 switch (GetMouseLockSetting(web_contents->GetURL())) { | 59 switch (GetMouseLockSetting(web_contents->GetURL())) { |
| 256 case CONTENT_SETTING_ALLOW: | 60 case CONTENT_SETTING_ALLOW: |
| 257 // If bubble already displaying buttons we must not lock the mouse yet, | 61 // If bubble already displaying buttons we must not lock the mouse yet, |
| 258 // or it would prevent pressing those buttons. Instead, merge the request. | 62 // or it would prevent pressing those buttons. Instead, merge the request. |
| 259 if (!IsPrivilegedFullscreenForTab() && | 63 if (!exclusive_access_manager() |
| 64 ->fullscreen_controller() |
| 65 ->IsPrivilegedFullscreenForTab() && |
| 260 exclusive_access_bubble::ShowButtonsForType(bubble_type)) { | 66 exclusive_access_bubble::ShowButtonsForType(bubble_type)) { |
| 261 mouse_lock_state_ = MOUSELOCK_REQUESTED; | 67 mouse_lock_state_ = MOUSELOCK_REQUESTED; |
| 262 } else { | 68 } else { |
| 263 // Lock mouse. | 69 // Lock mouse. |
| 264 if (web_contents->GotResponseToLockMouseRequest(true)) { | 70 if (web_contents->GotResponseToLockMouseRequest(true)) { |
| 265 if (last_unlocked_by_target) { | 71 if (last_unlocked_by_target) { |
| 266 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY; | 72 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY; |
| 267 } else { | 73 } else { |
| 268 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | 74 mouse_lock_state_ = MOUSELOCK_ACCEPTED; |
| 269 } | 75 } |
| 270 } else { | 76 } else { |
| 271 SetMouseLockTab(NULL); | 77 SetTabWithExclusiveAccess(nullptr); |
| 272 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 78 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| 273 } | 79 } |
| 274 } | 80 } |
| 275 break; | 81 break; |
| 276 case CONTENT_SETTING_BLOCK: | 82 case CONTENT_SETTING_BLOCK: |
| 277 web_contents->GotResponseToLockMouseRequest(false); | 83 web_contents->GotResponseToLockMouseRequest(false); |
| 278 SetMouseLockTab(NULL); | 84 SetTabWithExclusiveAccess(nullptr); |
| 279 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 85 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| 280 break; | 86 break; |
| 281 case CONTENT_SETTING_ASK: | 87 case CONTENT_SETTING_ASK: |
| 282 mouse_lock_state_ = MOUSELOCK_REQUESTED; | 88 mouse_lock_state_ = MOUSELOCK_REQUESTED; |
| 283 break; | 89 break; |
| 284 default: | 90 default: |
| 285 NOTREACHED(); | 91 NOTREACHED(); |
| 286 } | 92 } |
| 287 UpdateFullscreenExitBubbleContent(); | 93 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); |
| 288 } | 94 } |
| 289 | 95 |
| 290 void FullscreenController::OnTabDeactivated(WebContents* web_contents) { | 96 void MouseLockController::ExitExclusiveAccessIfNecessary() { |
| 291 if (web_contents == fullscreened_tab_ || web_contents == mouse_lock_tab_) | 97 NotifyTabOfExclusiveAccessChange(); |
| 292 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 293 } | 98 } |
| 294 | 99 |
| 295 void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) { | 100 void MouseLockController::NotifyTabOfExclusiveAccessChange() { |
| 296 if (!IsFullscreenForCapturedTab(old_contents)) | 101 WebContents* tab = exclusive_access_tab(); |
| 297 return; | 102 if (tab) { |
| 298 | 103 if (IsMouseLockRequested()) { |
| 299 // A fullscreen-within-tab view undergoing screen capture has been detached | 104 tab->GotResponseToLockMouseRequest(false); |
| 300 // and is no longer visible to the user. Set it to exactly the WebContents' | 105 NotifyMouseLockChange(); |
| 301 // preferred size. See 'FullscreenWithinTab Note'. | 106 } else { |
| 302 // | 107 UnlockMouse(); |
| 303 // When the user later selects the tab to show |old_contents| again, UI code | 108 } |
| 304 // elsewhere (e.g., views::WebView) will resize the view to fit within the | 109 SetTabWithExclusiveAccess(nullptr); |
| 305 // browser window once again. | 110 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| 306 | 111 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); |
| 307 // If the view has been detached from the browser window (e.g., to drag a tab | |
| 308 // off into a new browser window), return immediately to avoid an unnecessary | |
| 309 // resize. | |
| 310 if (!old_contents->GetDelegate()) | |
| 311 return; | |
| 312 | |
| 313 // Do nothing if tab capture ended after toggling fullscreen, or a preferred | |
| 314 // size was never specified by the capturer. | |
| 315 if (old_contents->GetCapturerCount() == 0 || | |
| 316 old_contents->GetPreferredSize().IsEmpty()) { | |
| 317 return; | |
| 318 } | |
| 319 | |
| 320 content::RenderWidgetHostView* const current_fs_view = | |
| 321 old_contents->GetFullscreenRenderWidgetHostView(); | |
| 322 if (current_fs_view) | |
| 323 current_fs_view->SetSize(old_contents->GetPreferredSize()); | |
| 324 ResizeWebContents(old_contents, old_contents->GetPreferredSize()); | |
| 325 } | |
| 326 | |
| 327 void FullscreenController::OnTabClosing(WebContents* web_contents) { | |
| 328 if (IsFullscreenForCapturedTab(web_contents)) { | |
| 329 web_contents->ExitFullscreen(); | |
| 330 } else if (web_contents == fullscreened_tab_ || | |
| 331 web_contents == mouse_lock_tab_) { | |
| 332 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 333 // The call to exit fullscreen may result in asynchronous notification of | |
| 334 // fullscreen state change (e.g., on Linux). We don't want to rely on it | |
| 335 // to call NotifyTabOfExitIfNecessary(), because at that point | |
| 336 // |fullscreened_tab_| may not be valid. Instead, we call it here to clean | |
| 337 // up tab fullscreen related state. | |
| 338 NotifyTabOfExitIfNecessary(); | |
| 339 } | 112 } |
| 340 } | 113 } |
| 341 | 114 |
| 342 void FullscreenController::WindowFullscreenStateChanged() { | 115 bool MouseLockController::HandleUserPressedEscape() { |
| 343 reentrant_window_state_change_call_check_ = true; | 116 if (IsMouseLocked() || IsMouseLockRequested()) { |
| 344 | 117 ExitExclusiveAccessIfNecessary(); |
| 345 bool exiting_fullscreen = !window_->IsFullscreen(); | |
| 346 | |
| 347 PostFullscreenChangeNotification(!exiting_fullscreen); | |
| 348 if (exiting_fullscreen) { | |
| 349 toggled_into_fullscreen_ = false; | |
| 350 extension_caused_fullscreen_ = GURL(); | |
| 351 NotifyTabOfExitIfNecessary(); | |
| 352 } | |
| 353 if (exiting_fullscreen) { | |
| 354 window_->GetDownloadShelf()->Unhide(); | |
| 355 } else { | |
| 356 window_->GetDownloadShelf()->Hide(); | |
| 357 if (window_->GetStatusBubble()) | |
| 358 window_->GetStatusBubble()->Hide(); | |
| 359 } | |
| 360 } | |
| 361 | |
| 362 bool FullscreenController::HandleUserPressedEscape() { | |
| 363 WebContents* const active_web_contents = | |
| 364 browser_->tab_strip_model()->GetActiveWebContents(); | |
| 365 if (IsFullscreenForCapturedTab(active_web_contents)) { | |
| 366 active_web_contents->ExitFullscreen(); | |
| 367 return true; | |
| 368 } else if (IsWindowFullscreenForTabOrPending() || | |
| 369 IsMouseLocked() || IsMouseLockRequested()) { | |
| 370 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 371 return true; | 118 return true; |
| 372 } | 119 } |
| 373 | 120 |
| 374 return false; | 121 return false; |
| 375 } | 122 } |
| 376 | 123 |
| 377 void FullscreenController::ExitTabOrBrowserFullscreenToPreviousState() { | 124 void MouseLockController::ExitExclusiveAccessToPreviousState() { |
| 378 if (IsWindowFullscreenForTabOrPending()) | 125 // Nothing to do for mouse lock. |
| 379 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 380 else if (IsFullscreenForBrowser()) | |
| 381 ExitFullscreenModeInternal(); | |
| 382 } | 126 } |
| 383 | 127 |
| 384 void FullscreenController::OnAcceptFullscreenPermission() { | 128 bool MouseLockController::OnAcceptExclusiveAccessPermission() { |
| 385 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); | 129 ExclusiveAccessBubbleType bubble_type = |
| 130 exclusive_access_manager()->GetExclusiveAccessExitBubbleType(); |
| 386 bool mouse_lock = false; | 131 bool mouse_lock = false; |
| 387 bool fullscreen = false; | 132 exclusive_access_bubble::PermissionRequestedByType(bubble_type, nullptr, |
| 388 exclusive_access_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | |
| 389 &mouse_lock); | 133 &mouse_lock); |
| 390 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); | |
| 391 DCHECK(!(mouse_lock && IsMouseLocked())); | 134 DCHECK(!(mouse_lock && IsMouseLocked())); |
| 392 | 135 |
| 393 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | |
| 394 | |
| 395 if (mouse_lock && !IsMouseLocked()) { | 136 if (mouse_lock && !IsMouseLocked()) { |
| 396 DCHECK(IsMouseLockRequested()); | 137 DCHECK(IsMouseLockRequested()); |
| 397 | 138 |
| 398 GURL url = GetFullscreenExitBubbleURL(); | 139 HostContentSettingsMap* settings_map = |
| 140 profile()->GetHostContentSettingsMap(); |
| 141 |
| 142 GURL url = GetExclusiveAccessBubbleURL(); |
| 399 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); | 143 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); |
| 400 | 144 |
| 401 // TODO(markusheintz): We should allow patterns for all possible URLs here. | 145 // TODO(markusheintz): We should allow patterns for all possible URLs here. |
| 402 if (pattern.IsValid()) { | 146 if (pattern.IsValid()) { |
| 403 settings_map->SetContentSetting( | 147 settings_map->SetContentSetting(pattern, |
| 404 pattern, ContentSettingsPattern::Wildcard(), | 148 ContentSettingsPattern::Wildcard(), |
| 405 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), | 149 CONTENT_SETTINGS_TYPE_MOUSELOCK, |
| 406 CONTENT_SETTING_ALLOW); | 150 std::string(), CONTENT_SETTING_ALLOW); |
| 407 } | 151 } |
| 408 | 152 |
| 409 if (mouse_lock_tab_ && | 153 WebContents* tab = exclusive_access_tab(); |
| 410 mouse_lock_tab_->GotResponseToLockMouseRequest(true)) { | 154 if (tab && tab->GotResponseToLockMouseRequest(true)) { |
| 411 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | 155 mouse_lock_state_ = MOUSELOCK_ACCEPTED; |
| 412 } else { | 156 } else { |
| 413 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 157 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| 414 SetMouseLockTab(NULL); | 158 SetTabWithExclusiveAccess(nullptr); |
| 415 } | 159 } |
| 416 NotifyMouseLockChange(); | 160 NotifyMouseLockChange(); |
| 417 } | 161 return true; |
| 418 | |
| 419 if (fullscreen && !tab_fullscreen_accepted_) { | |
| 420 DCHECK(fullscreened_tab_); | |
| 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()) { | |
| 441 settings_map->SetContentSetting( | |
| 442 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_FULLSCREEN, | |
| 443 std::string(), CONTENT_SETTING_ALLOW); | |
| 444 } | |
| 445 tab_fullscreen_accepted_ = true; | |
| 446 } | |
| 447 UpdateFullscreenExitBubbleContent(); | |
| 448 } | |
| 449 | |
| 450 void FullscreenController::OnDenyFullscreenPermission() { | |
| 451 if (!fullscreened_tab_ && !mouse_lock_tab_) | |
| 452 return; | |
| 453 | |
| 454 if (IsMouseLockRequested()) { | |
| 455 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 456 if (mouse_lock_tab_) | |
| 457 mouse_lock_tab_->GotResponseToLockMouseRequest(false); | |
| 458 SetMouseLockTab(NULL); | |
| 459 NotifyMouseLockChange(); | |
| 460 | |
| 461 // UpdateFullscreenExitBubbleContent() must be called, but to avoid | |
| 462 // duplicate calls we do so only if not adjusting the fullscreen state | |
| 463 // below, which also calls UpdateFullscreenExitBubbleContent(). | |
| 464 if (!IsWindowFullscreenForTabOrPending()) | |
| 465 UpdateFullscreenExitBubbleContent(); | |
| 466 } | |
| 467 | |
| 468 if (IsWindowFullscreenForTabOrPending()) | |
| 469 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 470 } | |
| 471 | |
| 472 void FullscreenController::LostMouseLock() { | |
| 473 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 474 SetMouseLockTab(NULL); | |
| 475 NotifyMouseLockChange(); | |
| 476 UpdateFullscreenExitBubbleContent(); | |
| 477 } | |
| 478 | |
| 479 void FullscreenController::Observe(int type, | |
| 480 const content::NotificationSource& source, | |
| 481 const content::NotificationDetails& details) { | |
| 482 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); | |
| 483 if (content::Details<content::LoadCommittedDetails>(details)-> | |
| 484 is_navigation_to_different_page()) | |
| 485 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 486 } | |
| 487 | |
| 488 GURL FullscreenController::GetFullscreenExitBubbleURL() const { | |
| 489 if (fullscreened_tab_) | |
| 490 return GetRequestingOrigin(); | |
| 491 if (mouse_lock_tab_) | |
| 492 return mouse_lock_tab_->GetURL(); | |
| 493 return extension_caused_fullscreen_; | |
| 494 } | |
| 495 | |
| 496 ExclusiveAccessBubbleType FullscreenController::GetExclusiveAccessBubbleType() | |
| 497 const { | |
| 498 // In kiosk and exclusive app mode we always want to be fullscreen and do not | |
| 499 // want to show exit instructions for browser mode fullscreen. | |
| 500 bool app_mode = false; | |
| 501 #if !defined(OS_MACOSX) // App mode (kiosk) is not available on Mac yet. | |
| 502 app_mode = chrome::IsRunningInAppMode(); | |
| 503 #endif | |
| 504 | |
| 505 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY) | |
| 506 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; | |
| 507 | |
| 508 if (!fullscreened_tab_) { | |
| 509 if (IsMouseLocked()) | |
| 510 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION; | |
| 511 if (IsMouseLockRequested()) | |
| 512 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS; | |
| 513 if (!extension_caused_fullscreen_.is_empty()) | |
| 514 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION; | |
| 515 if (toggled_into_fullscreen_ && !app_mode) | |
| 516 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | |
| 517 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; | |
| 518 } | |
| 519 | |
| 520 if (tab_fullscreen_accepted_) { | |
| 521 if (IsPrivilegedFullscreenForTab()) | |
| 522 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; | |
| 523 if (IsMouseLocked()) | |
| 524 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; | |
| 525 if (IsMouseLockRequested()) | |
| 526 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS; | |
| 527 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION; | |
| 528 } | |
| 529 | |
| 530 if (IsMouseLockRequested()) | |
| 531 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; | |
| 532 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS; | |
| 533 } | |
| 534 | |
| 535 void FullscreenController::UpdateNotificationRegistrations() { | |
| 536 if (fullscreened_tab_ && mouse_lock_tab_) | |
| 537 DCHECK(fullscreened_tab_ == mouse_lock_tab_); | |
| 538 | |
| 539 WebContents* tab = fullscreened_tab_ ? fullscreened_tab_ : mouse_lock_tab_; | |
| 540 | |
| 541 if (tab && registrar_.IsEmpty()) { | |
| 542 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 543 content::Source<content::NavigationController>(&tab->GetController())); | |
| 544 } else if (!tab && !registrar_.IsEmpty()) { | |
| 545 registrar_.RemoveAll(); | |
| 546 } | |
| 547 } | |
| 548 | |
| 549 void FullscreenController::PostFullscreenChangeNotification( | |
| 550 bool is_fullscreen) { | |
| 551 base::MessageLoop::current()->PostTask( | |
| 552 FROM_HERE, | |
| 553 base::Bind(&FullscreenController::NotifyFullscreenChange, | |
| 554 ptr_factory_.GetWeakPtr(), | |
| 555 is_fullscreen)); | |
| 556 } | |
| 557 | |
| 558 void FullscreenController::NotifyFullscreenChange(bool is_fullscreen) { | |
| 559 content::NotificationService::current()->Notify( | |
| 560 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
| 561 content::Source<FullscreenController>(this), | |
| 562 content::Details<bool>(&is_fullscreen)); | |
| 563 } | |
| 564 | |
| 565 void FullscreenController::NotifyTabOfExitIfNecessary() { | |
| 566 if (fullscreened_tab_) { | |
| 567 WebContents* web_contents = fullscreened_tab_; | |
| 568 // This call will set |fullscreened_tab_| to nullptr. | |
| 569 SetFullscreenedTab(nullptr, GURL()); | |
| 570 state_prior_to_tab_fullscreen_ = STATE_INVALID; | |
| 571 tab_fullscreen_accepted_ = false; | |
| 572 web_contents->ExitFullscreen(); | |
| 573 } | |
| 574 | |
| 575 if (mouse_lock_tab_) { | |
| 576 if (IsMouseLockRequested()) { | |
| 577 mouse_lock_tab_->GotResponseToLockMouseRequest(false); | |
| 578 NotifyMouseLockChange(); | |
| 579 } else { | |
| 580 UnlockMouse(); | |
| 581 } | |
| 582 SetMouseLockTab(NULL); | |
| 583 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 584 } | |
| 585 | |
| 586 UpdateFullscreenExitBubbleContent(); | |
| 587 } | |
| 588 | |
| 589 void FullscreenController::NotifyMouseLockChange() { | |
| 590 content::NotificationService::current()->Notify( | |
| 591 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, | |
| 592 content::Source<FullscreenController>(this), | |
| 593 content::NotificationService::NoDetails()); | |
| 594 } | |
| 595 | |
| 596 void FullscreenController::ToggleFullscreenModeInternal( | |
| 597 FullscreenInternalOption option) { | |
| 598 #if defined(OS_WIN) | |
| 599 // When in Metro snap mode, toggling in and out of fullscreen is prevented. | |
| 600 if (IsInMetroSnapMode()) | |
| 601 return; | |
| 602 #endif | |
| 603 | |
| 604 bool enter_fullscreen = !window_->IsFullscreen(); | |
| 605 | |
| 606 // When a Mac user requests a toggle they may be toggling between | |
| 607 // FullscreenWithoutChrome and FullscreenWithToolbar. | |
| 608 if (window_->IsFullscreen() && | |
| 609 !IsWindowFullscreenForTabOrPending() && | |
| 610 window_->SupportsFullscreenWithToolbar()) { | |
| 611 if (option == BROWSER_WITH_TOOLBAR) { | |
| 612 enter_fullscreen = | |
| 613 enter_fullscreen || !window_->IsFullscreenWithToolbar(); | |
| 614 } else { | |
| 615 enter_fullscreen = enter_fullscreen || window_->IsFullscreenWithToolbar(); | |
| 616 } | |
| 617 } | |
| 618 | |
| 619 // In kiosk mode, we always want to be fullscreen. When the browser first | |
| 620 // starts we're not yet fullscreen, so let the initial toggle go through. | |
| 621 if (chrome::IsRunningInAppMode() && window_->IsFullscreen()) | |
| 622 return; | |
| 623 | |
| 624 #if !defined(OS_MACOSX) | |
| 625 // Do not enter fullscreen mode if disallowed by pref. This prevents the user | |
| 626 // from manually entering fullscreen mode and also disables kiosk mode on | |
| 627 // desktop platforms. | |
| 628 if (enter_fullscreen && | |
| 629 !profile_->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) { | |
| 630 return; | |
| 631 } | |
| 632 #endif | |
| 633 | |
| 634 if (enter_fullscreen) | |
| 635 EnterFullscreenModeInternal(option); | |
| 636 else | |
| 637 ExitFullscreenModeInternal(); | |
| 638 } | |
| 639 | |
| 640 void FullscreenController::EnterFullscreenModeInternal( | |
| 641 FullscreenInternalOption option) { | |
| 642 toggled_into_fullscreen_ = true; | |
| 643 GURL url; | |
| 644 if (option == TAB) { | |
| 645 url = GetRequestingOrigin(); | |
| 646 tab_fullscreen_accepted_ = GetFullscreenSetting() == CONTENT_SETTING_ALLOW; | |
| 647 } else { | |
| 648 if (!extension_caused_fullscreen_.is_empty()) | |
| 649 url = extension_caused_fullscreen_; | |
| 650 } | |
| 651 | |
| 652 if (option == BROWSER) | |
| 653 content::RecordAction(UserMetricsAction("ToggleFullscreen")); | |
| 654 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions | |
| 655 // from tab fullscreen out to browser with toolbar. | |
| 656 | |
| 657 window_->EnterFullscreen(url, GetExclusiveAccessBubbleType(), | |
| 658 option == BROWSER_WITH_TOOLBAR); | |
| 659 | |
| 660 UpdateFullscreenExitBubbleContent(); | |
| 661 | |
| 662 // Once the window has become fullscreen it'll call back to | |
| 663 // WindowFullscreenStateChanged(). We don't do this immediately as | |
| 664 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | |
| 665 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | |
| 666 } | |
| 667 | |
| 668 void FullscreenController::ExitFullscreenModeInternal() { | |
| 669 toggled_into_fullscreen_ = false; | |
| 670 #if defined(OS_MACOSX) | |
| 671 // Mac windows report a state change instantly, and so we must also clear | |
| 672 // state_prior_to_tab_fullscreen_ to match them else other logic using | |
| 673 // state_prior_to_tab_fullscreen_ will be incorrect. | |
| 674 NotifyTabOfExitIfNecessary(); | |
| 675 #endif | |
| 676 window_->ExitFullscreen(); | |
| 677 extension_caused_fullscreen_ = GURL(); | |
| 678 | |
| 679 UpdateFullscreenExitBubbleContent(); | |
| 680 } | |
| 681 | |
| 682 void FullscreenController::SetFullscreenedTab(WebContents* tab, | |
| 683 const GURL& origin) { | |
| 684 fullscreened_tab_ = tab; | |
| 685 fullscreened_origin_ = origin; | |
| 686 UpdateNotificationRegistrations(); | |
| 687 } | |
| 688 | |
| 689 void FullscreenController::SetMouseLockTab(WebContents* tab) { | |
| 690 mouse_lock_tab_ = tab; | |
| 691 UpdateNotificationRegistrations(); | |
| 692 } | |
| 693 | |
| 694 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { | |
| 695 if (IsWindowFullscreenForTabOrPending()) | |
| 696 ExitFullscreenModeForTab(fullscreened_tab_); | |
| 697 else | |
| 698 NotifyTabOfExitIfNecessary(); | |
| 699 } | |
| 700 | |
| 701 void FullscreenController::UpdateFullscreenExitBubbleContent() { | |
| 702 GURL url = GetFullscreenExitBubbleURL(); | |
| 703 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); | |
| 704 | |
| 705 // If bubble displays buttons, unlock mouse to allow pressing them. | |
| 706 if (exclusive_access_bubble::ShowButtonsForType(bubble_type) && | |
| 707 IsMouseLocked()) | |
| 708 UnlockMouse(); | |
| 709 | |
| 710 window_->UpdateFullscreenExitBubbleContent(url, bubble_type); | |
| 711 } | |
| 712 | |
| 713 ContentSetting FullscreenController::GetFullscreenSetting() const { | |
| 714 DCHECK(fullscreened_tab_); | |
| 715 | |
| 716 GURL url = GetRequestingOrigin(); | |
| 717 | |
| 718 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) | |
| 719 return CONTENT_SETTING_ALLOW; | |
| 720 | |
| 721 // If the permission was granted to the website with no embedder, it should | |
| 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()); | |
| 734 } | |
| 735 | |
| 736 ContentSetting | |
| 737 FullscreenController::GetMouseLockSetting(const GURL& url) const { | |
| 738 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) | |
| 739 return CONTENT_SETTING_ALLOW; | |
| 740 | |
| 741 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | |
| 742 return settings_map->GetContentSetting(url, url, | |
| 743 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); | |
| 744 } | |
| 745 | |
| 746 bool FullscreenController::IsPrivilegedFullscreenForTab() const { | |
| 747 const bool embedded_widget_present = | |
| 748 fullscreened_tab_ && | |
| 749 fullscreened_tab_->GetFullscreenRenderWidgetHostView(); | |
| 750 return embedded_widget_present || is_privileged_fullscreen_for_testing_; | |
| 751 } | |
| 752 | |
| 753 void FullscreenController::SetPrivilegedFullscreenForTesting( | |
| 754 bool is_privileged) { | |
| 755 is_privileged_fullscreen_for_testing_ = is_privileged; | |
| 756 } | |
| 757 | |
| 758 bool FullscreenController::MaybeToggleFullscreenForCapturedTab( | |
| 759 WebContents* web_contents, bool enter_fullscreen) { | |
| 760 if (enter_fullscreen) { | |
| 761 if (web_contents->GetCapturerCount() > 0) { | |
| 762 FullscreenWithinTabHelper::CreateForWebContents(web_contents); | |
| 763 FullscreenWithinTabHelper::FromWebContents(web_contents)-> | |
| 764 SetIsFullscreenForCapturedTab(true); | |
| 765 return true; | |
| 766 } | |
| 767 } else { | |
| 768 if (IsFullscreenForCapturedTab(web_contents)) { | |
| 769 FullscreenWithinTabHelper::RemoveForWebContents(web_contents); | |
| 770 return true; | |
| 771 } | |
| 772 } | 162 } |
| 773 | 163 |
| 774 return false; | 164 return false; |
| 775 } | 165 } |
| 776 | 166 |
| 777 bool FullscreenController::IsFullscreenForCapturedTab( | 167 bool MouseLockController::OnDenyExclusiveAccessPermission() { |
| 778 const WebContents* web_contents) const { | 168 WebContents* tab = exclusive_access_tab(); |
| 779 // Note: On Mac, some of the OnTabXXX() methods get called with a NULL value | 169 |
| 780 // for web_contents. Check for that here. | 170 if (tab && IsMouseLockRequested()) { |
| 781 const FullscreenWithinTabHelper* const helper = web_contents ? | 171 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| 782 FullscreenWithinTabHelper::FromWebContents(web_contents) : NULL; | 172 tab->GotResponseToLockMouseRequest(false); |
| 783 if (helper && helper->is_fullscreen_for_captured_tab()) { | 173 SetTabWithExclusiveAccess(nullptr); |
| 784 DCHECK_NE(fullscreened_tab_, web_contents); | 174 NotifyMouseLockChange(); |
| 785 return true; | 175 return true; |
| 786 } | 176 } |
| 177 |
| 787 return false; | 178 return false; |
| 788 } | 179 } |
| 789 | 180 |
| 790 void FullscreenController::UnlockMouse() { | 181 void MouseLockController::LostMouseLock() { |
| 791 if (!mouse_lock_tab_) | 182 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| 183 SetTabWithExclusiveAccess(nullptr); |
| 184 NotifyMouseLockChange(); |
| 185 exclusive_access_manager()->UpdateExclusiveAccessExitBubbleContent(); |
| 186 } |
| 187 |
| 188 bool MouseLockController::IsMouseLockRequested() const { |
| 189 return mouse_lock_state_ == MOUSELOCK_REQUESTED; |
| 190 } |
| 191 |
| 192 void MouseLockController::NotifyMouseLockChange() { |
| 193 content::NotificationService::current()->Notify( |
| 194 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 195 content::Source<MouseLockController>(this), |
| 196 content::NotificationService::NoDetails()); |
| 197 } |
| 198 |
| 199 void MouseLockController::UnlockMouse() { |
| 200 WebContents* tab = exclusive_access_tab(); |
| 201 |
| 202 if (!tab) |
| 792 return; | 203 return; |
| 793 content::RenderWidgetHostView* mouse_lock_view = | 204 |
| 794 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ? | 205 content::RenderWidgetHostView* mouse_lock_view = nullptr; |
| 795 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL; | 206 FullscreenController* fullscreen_controller = |
| 207 exclusive_access_manager()->fullscreen_controller(); |
| 208 if ((fullscreen_controller->exclusive_access_tab() == tab) && |
| 209 fullscreen_controller->IsPrivilegedFullscreenForTab()) { |
| 210 mouse_lock_view = |
| 211 exclusive_access_tab()->GetFullscreenRenderWidgetHostView(); |
| 212 } |
| 213 |
| 796 if (!mouse_lock_view) { | 214 if (!mouse_lock_view) { |
| 797 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost(); | 215 RenderViewHost* const rvh = exclusive_access_tab()->GetRenderViewHost(); |
| 798 if (rvh) | 216 if (rvh) |
| 799 mouse_lock_view = rvh->GetView(); | 217 mouse_lock_view = rvh->GetView(); |
| 800 } | 218 } |
| 219 |
| 801 if (mouse_lock_view) | 220 if (mouse_lock_view) |
| 802 mouse_lock_view->UnlockMouse(); | 221 mouse_lock_view->UnlockMouse(); |
| 803 } | 222 } |
| 804 | 223 |
| 805 GURL FullscreenController::GetRequestingOrigin() const { | 224 ContentSetting MouseLockController::GetMouseLockSetting(const GURL& url) const { |
| 806 DCHECK(fullscreened_tab_); | 225 if (exclusive_access_manager() |
| 226 ->fullscreen_controller() |
| 227 ->IsPrivilegedFullscreenForTab() || |
| 228 url.SchemeIsFile()) |
| 229 return CONTENT_SETTING_ALLOW; |
| 807 | 230 |
| 808 if (!fullscreened_origin_.is_empty()) | 231 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); |
| 809 return fullscreened_origin_; | 232 return settings_map->GetContentSetting( |
| 810 | 233 url, url, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); |
| 811 return fullscreened_tab_->GetLastCommittedURL(); | |
| 812 } | 234 } |
| 813 | |
| 814 GURL FullscreenController::GetEmbeddingOrigin() const { | |
| 815 DCHECK(fullscreened_tab_); | |
| 816 | |
| 817 return fullscreened_tab_->GetLastCommittedURL(); | |
| 818 } | |
| OLD | NEW |