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