Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: chrome/browser/ui/fullscreen_controller.cc

Issue 9353010: Add FullscreenController::ToggleFullscreenModeWithExtension (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Show "An extension triggered full screen." when the extension's name is not available. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "content/browser/renderer_host/render_view_host.h" 19 #include "content/browser/renderer_host/render_view_host.h"
19 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/user_metrics.h" 21 #include "content/public/browser/user_metrics.h"
21 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
22 23
23 using content::UserMetricsAction; 24 using content::UserMetricsAction;
24 using content::WebContents; 25 using content::WebContents;
25 26
26 FullscreenController::FullscreenController(BrowserWindow* window, 27 FullscreenController::FullscreenController(BrowserWindow* window,
27 Profile* profile, 28 Profile* profile,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); 104 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode();
104 #else 105 #else
105 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); 106 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen();
106 #endif 107 #endif
107 108
108 if (enter_fullscreen) { 109 if (enter_fullscreen) {
109 fullscreened_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); 110 fullscreened_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab);
110 if (!in_browser_or_tab_fullscreen_mode) { 111 if (!in_browser_or_tab_fullscreen_mode) {
111 tab_caused_fullscreen_ = true; 112 tab_caused_fullscreen_ = true;
112 #if defined(OS_MACOSX) 113 #if defined(OS_MACOSX)
113 TogglePresentationMode(true); 114 TogglePresentationModeInternal(true);
114 #else 115 #else
115 ToggleFullscreenMode(true); 116 ToggleFullscreenModeInternal(true);
116 #endif 117 #endif
117 } else { 118 } else {
118 // We need to update the fullscreen exit bubble, e.g., going from browser 119 // We need to update the fullscreen exit bubble, e.g., going from browser
119 // fullscreen to tab fullscreen will need to show different content. 120 // fullscreen to tab fullscreen will need to show different content.
120 const GURL& url = tab->GetURL(); 121 const GURL& url = tab->GetURL();
121 if (!tab_fullscreen_accepted_) { 122 if (!tab_fullscreen_accepted_) {
122 tab_fullscreen_accepted_ = 123 tab_fullscreen_accepted_ =
123 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; 124 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW;
124 } 125 }
125 UpdateFullscreenExitBubbleContent(); 126 UpdateFullscreenExitBubbleContent();
126 } 127 }
127 } else { 128 } else {
128 if (in_browser_or_tab_fullscreen_mode) { 129 if (in_browser_or_tab_fullscreen_mode) {
129 if (tab_caused_fullscreen_) { 130 if (tab_caused_fullscreen_) {
130 #if defined(OS_MACOSX) 131 #if defined(OS_MACOSX)
131 TogglePresentationMode(true); 132 TogglePresentationModeInternal(true);
132 #else 133 #else
133 ToggleFullscreenMode(true); 134 ToggleFullscreenModeInternal(true);
134 #endif 135 #endif
135 } else { 136 } else {
136 // If currently there is a tab in "tab fullscreen" mode and fullscreen 137 // If currently there is a tab in "tab fullscreen" mode and fullscreen
137 // was not caused by it (i.e., previously it was in "browser fullscreen" 138 // was not caused by it (i.e., previously it was in "browser fullscreen"
138 // mode), we need to switch back to "browser fullscreen" mode. In this 139 // mode), we need to switch back to "browser fullscreen" mode. In this
139 // case, all we have to do is notifying the tab that it has exited "tab 140 // case, all we have to do is notifying the tab that it has exited "tab
140 // fullscreen" mode. 141 // fullscreen" mode.
141 NotifyTabOfFullscreenExitIfNecessary(); 142 NotifyTabOfFullscreenExitIfNecessary();
142 } 143 }
143 } 144 }
144 } 145 }
145 } 146 }
146 147
147 #if defined(OS_MACOSX) 148 #if defined(OS_MACOSX)
148 void FullscreenController::TogglePresentationMode(bool for_tab) { 149 void FullscreenController::TogglePresentationMode() {
149 bool entering_fullscreen = !window_->InPresentationMode(); 150 TogglePresentationModeInternal(false);
150 GURL url;
151 if (for_tab) {
152 url = browser_->GetSelectedWebContents()->GetURL();
153 tab_fullscreen_accepted_ = entering_fullscreen &&
154 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW;
155 }
156 if (entering_fullscreen)
157 window_->EnterPresentationMode(url, GetFullscreenExitBubbleType());
158 else
159 window_->ExitPresentationMode();
160 WindowFullscreenStateChanged();
161 } 151 }
162 #endif 152 #endif
163 153
164 // TODO(koz): Change |for_tab| to an enum. 154 void FullscreenController::ToggleFullscreenMode() {
165 void FullscreenController::ToggleFullscreenMode(bool for_tab) { 155 extension_caused_fullscreen_ = GURL();
166 bool entering_fullscreen = !window_->IsFullscreen(); 156 ToggleFullscreenModeInternal(false);
157 }
167 158
168 #if !defined(OS_MACOSX) 159 void FullscreenController::ToggleFullscreenModeWithExtension(
169 // In kiosk mode, we always want to be fullscreen. When the browser first 160 const Extension& extension) {
170 // starts we're not yet fullscreen, so let the initial toggle go through. 161 // |extension_caused_fullscreen_| will be reset if this causes fullscreen to
171 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && 162 // exit.
172 window_->IsFullscreen()) 163 extension_caused_fullscreen_ = extension.url();
173 return; 164 ToggleFullscreenModeInternal(false);
174 #endif
175
176 GURL url;
177 if (for_tab) {
178 url = browser_->GetSelectedWebContents()->GetURL();
179 tab_fullscreen_accepted_ = entering_fullscreen &&
180 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW;
181 } else {
182 content::RecordAction(UserMetricsAction("ToggleFullscreen"));
183 }
184 if (entering_fullscreen)
185 window_->EnterFullscreen(url, GetFullscreenExitBubbleType());
186 else
187 window_->ExitFullscreen();
188
189 // Once the window has become fullscreen it'll call back to
190 // WindowFullscreenStateChanged(). We don't do this immediately as
191 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let
192 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate.
193
194 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates
195 // the necessary state of the frame.
196 #if defined(OS_MACOSX)
197 WindowFullscreenStateChanged();
198 #endif
199 } 165 }
200 166
201 void FullscreenController::LostMouseLock() { 167 void FullscreenController::LostMouseLock() {
202 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; 168 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
203 UpdateFullscreenExitBubbleContent(); 169 UpdateFullscreenExitBubbleContent();
204 } 170 }
205 171
206 void FullscreenController::OnTabClosing(WebContents* web_contents) { 172 void FullscreenController::OnTabClosing(WebContents* web_contents) {
207 if (IsFullscreenForTab(web_contents)) { 173 if (IsFullscreenForTab(web_contents)) {
208 ExitTabbedFullscreenModeIfNecessary(); 174 ExitTabbedFullscreenModeIfNecessary();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 fullscreened_tab_ = NULL; 281 fullscreened_tab_ = NULL;
316 tab_caused_fullscreen_ = false; 282 tab_caused_fullscreen_ = false;
317 tab_fullscreen_accepted_ = false; 283 tab_fullscreen_accepted_ = false;
318 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; 284 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED;
319 285
320 UpdateFullscreenExitBubbleContent(); 286 UpdateFullscreenExitBubbleContent();
321 } 287 }
322 288
323 void FullscreenController::ExitTabbedFullscreenModeIfNecessary() { 289 void FullscreenController::ExitTabbedFullscreenModeIfNecessary() {
324 if (tab_caused_fullscreen_) 290 if (tab_caused_fullscreen_)
325 ToggleFullscreenMode(false); 291 ToggleFullscreenMode();
326 else 292 else
327 NotifyTabOfFullscreenExitIfNecessary(); 293 NotifyTabOfFullscreenExitIfNecessary();
328 } 294 }
329 295
330 void FullscreenController::UpdateFullscreenExitBubbleContent() { 296 void FullscreenController::UpdateFullscreenExitBubbleContent() {
331 GURL url; 297 GURL url;
332 if (fullscreened_tab_) 298 if (fullscreened_tab_)
333 url = fullscreened_tab_->web_contents()->GetURL(); 299 url = fullscreened_tab_->web_contents()->GetURL();
300 else if (!extension_caused_fullscreen_.is_empty())
301 url = extension_caused_fullscreen_;
334 302
335 window_->UpdateFullscreenExitBubbleContent(url, 303 window_->UpdateFullscreenExitBubbleContent(url,
336 GetFullscreenExitBubbleType()); 304 GetFullscreenExitBubbleType());
337 } 305 }
338 306
339 void FullscreenController::NotifyFullscreenChange() { 307 void FullscreenController::NotifyFullscreenChange() {
340 content::NotificationService::current()->Notify( 308 content::NotificationService::current()->Notify(
341 chrome::NOTIFICATION_FULLSCREEN_CHANGED, 309 chrome::NOTIFICATION_FULLSCREEN_CHANGED,
342 content::Source<FullscreenController>(this), 310 content::Source<FullscreenController>(this),
343 content::NotificationService::NoDetails()); 311 content::NotificationService::NoDetails());
344 } 312 }
345 313
346 FullscreenExitBubbleType 314 FullscreenExitBubbleType FullscreenController::GetFullscreenExitBubbleType()
347 FullscreenController::GetFullscreenExitBubbleType() const { 315 const {
348 if (!fullscreened_tab_) { 316 if (!fullscreened_tab_) {
349 DCHECK_EQ(MOUSELOCK_NOT_REQUESTED, mouse_lock_state_); 317 DCHECK_EQ(MOUSELOCK_NOT_REQUESTED, mouse_lock_state_);
350 return FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; 318 return !extension_caused_fullscreen_.is_empty() ?
319 FEB_TYPE_BROWSER_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION :
320 FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION;
351 } 321 }
352 if (fullscreened_tab_ && !tab_fullscreen_accepted_) { 322 if (fullscreened_tab_ && !tab_fullscreen_accepted_) {
353 DCHECK_NE(MOUSELOCK_ACCEPTED, mouse_lock_state_); 323 DCHECK_NE(MOUSELOCK_ACCEPTED, mouse_lock_state_);
354 return mouse_lock_state_ == MOUSELOCK_REQUESTED ? 324 return mouse_lock_state_ == MOUSELOCK_REQUESTED ?
355 FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS : FEB_TYPE_FULLSCREEN_BUTTONS; 325 FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS : FEB_TYPE_FULLSCREEN_BUTTONS;
356 } 326 }
357 if (mouse_lock_state_ == MOUSELOCK_REQUESTED) 327 if (mouse_lock_state_ == MOUSELOCK_REQUESTED)
358 return FEB_TYPE_MOUSELOCK_BUTTONS; 328 return FEB_TYPE_MOUSELOCK_BUTTONS;
359 return mouse_lock_state_ == MOUSELOCK_ACCEPTED ? 329 return mouse_lock_state_ == MOUSELOCK_ACCEPTED ?
360 FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION : 330 FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION :
(...skipping 12 matching lines...) Expand all
373 343
374 ContentSetting 344 ContentSetting
375 FullscreenController::GetMouseLockSetting(const GURL& url) const { 345 FullscreenController::GetMouseLockSetting(const GURL& url) const {
376 if (url.SchemeIsFile()) 346 if (url.SchemeIsFile())
377 return CONTENT_SETTING_ALLOW; 347 return CONTENT_SETTING_ALLOW;
378 348
379 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); 349 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap();
380 return settings_map->GetContentSetting(url, url, 350 return settings_map->GetContentSetting(url, url,
381 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); 351 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string());
382 } 352 }
353
354 #if defined(OS_MACOSX)
355 void FullscreenController::TogglePresentationModeInternal(bool for_tab) {
356 bool entering_fullscreen = !window_->InPresentationMode();
357 GURL url;
358 if (for_tab) {
359 url = browser_->GetSelectedWebContents()->GetURL();
360 tab_fullscreen_accepted_ = entering_fullscreen &&
361 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW;
362 }
363 if (entering_fullscreen)
364 window_->EnterPresentationMode(url, GetFullscreenExitBubbleType());
365 else
366 window_->ExitPresentationMode();
367 WindowFullscreenStateChanged();
368 }
369 #endif
370
371 // TODO(koz): Change |for_tab| to an enum.
372 void FullscreenController::ToggleFullscreenModeInternal(bool for_tab) {
373 bool entering_fullscreen = !window_->IsFullscreen();
374
375 #if !defined(OS_MACOSX)
376 // In kiosk mode, we always want to be fullscreen. When the browser first
377 // starts we're not yet fullscreen, so let the initial toggle go through.
378 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) &&
379 window_->IsFullscreen())
380 return;
381 #endif
382
383 GURL url;
384 if (for_tab) {
385 url = browser_->GetSelectedWebContents()->GetURL();
386 tab_fullscreen_accepted_ = entering_fullscreen &&
387 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW;
388 } else {
389 if (!extension_caused_fullscreen_.is_empty())
390 url = extension_caused_fullscreen_;
391 content::RecordAction(UserMetricsAction("ToggleFullscreen"));
392 }
393 if (entering_fullscreen) {
394 window_->EnterFullscreen(url, GetFullscreenExitBubbleType());
395 } else {
396 window_->ExitFullscreen();
397 extension_caused_fullscreen_ = GURL();
398 }
399
400 // Once the window has become fullscreen it'll call back to
401 // WindowFullscreenStateChanged(). We don't do this immediately as
402 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let
403 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate.
404
405 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates
406 // the necessary state of the frame.
407 #if defined(OS_MACOSX)
408 WindowFullscreenStateChanged();
409 #endif
410 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/fullscreen_controller.h ('k') | chrome/browser/ui/fullscreen_exit_bubble_type.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698