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