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