OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ash/chrome_shell_delegate.h" | 5 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" |
6 | 6 |
7 #include "ash/keyboard_overlay/keyboard_overlay_view.h" | 7 #include "ash/keyboard_overlay/keyboard_overlay_view.h" |
8 #include "ash/system/chromeos/network/network_observer.h" | 8 #include "ash/system/chromeos/network/network_observer.h" |
9 #include "ash/system/tray/system_tray_notifier.h" | 9 #include "ash/system/tray/system_tray_notifier.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| 11 #include "base/chromeos/chromeos_version.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" | 15 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" |
15 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | 16 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
16 #include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h" | 17 #include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h" |
17 #include "chrome/browser/chromeos/cros/cros_library.h" | 18 #include "chrome/browser/chromeos/cros/cros_library.h" |
18 #include "chrome/browser/chromeos/cros/network_library.h" | 19 #include "chrome/browser/chromeos/cros/network_library.h" |
19 #include "chrome/browser/chromeos/display/display_preferences.h" | 20 #include "chrome/browser/chromeos/display/display_preferences.h" |
20 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" | 21 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" |
21 #include "chrome/browser/chromeos/extensions/media_player_api.h" | 22 #include "chrome/browser/chromeos/extensions/media_player_api.h" |
22 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" | 23 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" |
23 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 24 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
24 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 25 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
25 #include "chrome/browser/chromeos/login/screen_locker.h" | 26 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 27 #include "chrome/browser/chromeos/login/user_manager.h" |
26 #include "chrome/browser/chromeos/login/webui_login_display_host.h" | 28 #include "chrome/browser/chromeos/login/webui_login_display_host.h" |
27 #include "chrome/browser/chromeos/system/ash_system_tray_delegate.h" | 29 #include "chrome/browser/chromeos/system/ash_system_tray_delegate.h" |
28 #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h" | 30 #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h" |
29 #include "chrome/browser/profiles/profile_manager.h" | 31 #include "chrome/browser/profiles/profile_manager.h" |
30 #include "chrome/browser/ui/ash/caps_lock_delegate_chromeos.h" | 32 #include "chrome/browser/ui/ash/caps_lock_delegate_chromeos.h" |
31 #include "chrome/browser/ui/ash/window_positioner.h" | 33 #include "chrome/browser/ui/ash/window_positioner.h" |
32 #include "chrome/browser/ui/browser.h" | 34 #include "chrome/browser/ui/browser.h" |
33 #include "chrome/browser/ui/browser_finder.h" | 35 #include "chrome/browser/ui/browser_finder.h" |
34 #include "chrome/browser/ui/browser_window.h" | 36 #include "chrome/browser/ui/browser_window.h" |
35 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" | 37 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" |
36 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 38 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
37 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" | 39 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" |
38 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
39 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
40 #include "chrome/common/url_constants.h" | 42 #include "chrome/common/url_constants.h" |
41 #include "chromeos/chromeos_switches.h" | 43 #include "chromeos/chromeos_switches.h" |
42 #include "chromeos/dbus/dbus_thread_manager.h" | 44 #include "chromeos/dbus/dbus_thread_manager.h" |
43 #include "chromeos/dbus/power_manager_client.h" | 45 #include "chromeos/dbus/power_manager_client.h" |
| 46 #include "chromeos/dbus/session_manager_client.h" |
44 #include "content/public/browser/user_metrics.h" | 47 #include "content/public/browser/user_metrics.h" |
45 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
46 #include "content/public/browser/web_contents_view.h" | 49 #include "content/public/browser/web_contents_view.h" |
47 #include "grit/generated_resources.h" | 50 #include "grit/generated_resources.h" |
48 #include "ui/base/l10n/l10n_util.h" | 51 #include "ui/base/l10n/l10n_util.h" |
49 | 52 |
| 53 bool ChromeShellDelegate::IsUserLoggedIn() const { |
| 54 // When running a Chrome OS build outside of a device (i.e. on a developer's |
| 55 // workstation) and not running as login-manager, pretend like we're always |
| 56 // logged in. |
| 57 if (!base::chromeos::IsRunningOnChromeOS() && |
| 58 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 59 chromeos::switches::kLoginManager)) { |
| 60 return true; |
| 61 } |
| 62 |
| 63 return chromeos::UserManager::Get()->IsUserLoggedIn(); |
| 64 } |
| 65 |
| 66 bool ChromeShellDelegate::IsSessionStarted() const { |
| 67 // Returns true if we're logged in and browser has been started |
| 68 return chromeos::UserManager::Get()->IsSessionStarted(); |
| 69 } |
| 70 |
| 71 bool ChromeShellDelegate::IsGuestSession() const { |
| 72 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 73 chromeos::switches::kGuestSession); |
| 74 } |
| 75 |
50 bool ChromeShellDelegate::IsFirstRunAfterBoot() const { | 76 bool ChromeShellDelegate::IsFirstRunAfterBoot() const { |
51 return CommandLine::ForCurrentProcess()->HasSwitch( | 77 return CommandLine::ForCurrentProcess()->HasSwitch( |
52 chromeos::switches::kFirstBoot); | 78 chromeos::switches::kFirstBoot); |
53 } | 79 } |
54 | 80 |
| 81 bool ChromeShellDelegate::CanLockScreen() const { |
| 82 return chromeos::UserManager::Get()->CanCurrentUserLock(); |
| 83 } |
| 84 |
| 85 void ChromeShellDelegate::LockScreen() { |
| 86 if (CanLockScreen()) { |
| 87 // TODO(antrim) : additional logging for crbug/173178 |
| 88 LOG(WARNING) << "Requesting screen lock from ChromeShellDelegate"; |
| 89 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
| 90 RequestLockScreen(); |
| 91 } |
| 92 } |
| 93 |
| 94 bool ChromeShellDelegate::IsScreenLocked() const { |
| 95 if (!chromeos::ScreenLocker::default_screen_locker()) |
| 96 return false; |
| 97 return chromeos::ScreenLocker::default_screen_locker()->locked(); |
| 98 } |
| 99 |
55 void ChromeShellDelegate::PreInit() { | 100 void ChromeShellDelegate::PreInit() { |
56 chromeos::LoadDisplayPreferences(IsFirstRunAfterBoot()); | 101 chromeos::LoadDisplayPreferences(IsFirstRunAfterBoot()); |
57 } | 102 } |
58 | 103 |
59 void ChromeShellDelegate::Shutdown() { | 104 void ChromeShellDelegate::Shutdown() { |
60 content::RecordAction(content::UserMetricsAction("Shutdown")); | 105 content::RecordAction(content::UserMetricsAction("Shutdown")); |
61 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 106 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
62 RequestShutdown(); | 107 RequestShutdown(); |
63 } | 108 } |
64 | 109 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 void ChromeShellDelegate::ShowKeyboardOverlay() { | 240 void ChromeShellDelegate::ShowKeyboardOverlay() { |
196 // TODO(mazda): Move the show logic to ash (http://crbug.com/124222). | 241 // TODO(mazda): Move the show logic to ash (http://crbug.com/124222). |
197 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | 242 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
198 std::string url(chrome::kChromeUIKeyboardOverlayURL); | 243 std::string url(chrome::kChromeUIKeyboardOverlayURL); |
199 ash::KeyboardOverlayView::ShowDialog(profile, | 244 ash::KeyboardOverlayView::ShowDialog(profile, |
200 new ChromeWebContentsHandler, | 245 new ChromeWebContentsHandler, |
201 GURL(url)); | 246 GURL(url)); |
202 } | 247 } |
203 | 248 |
204 bool ChromeShellDelegate::ShouldAlwaysShowAccessibilityMenu() const { | 249 bool ChromeShellDelegate::ShouldAlwaysShowAccessibilityMenu() const { |
| 250 if (!IsUserLoggedIn()) |
| 251 return true; |
| 252 |
205 Profile* profile = ProfileManager::GetDefaultProfile(); | 253 Profile* profile = ProfileManager::GetDefaultProfile(); |
206 if (!profile) | 254 if (!profile) |
207 return false; | 255 return false; |
208 | 256 |
209 PrefService* user_pref_service = profile->GetPrefs(); | 257 PrefService* user_pref_service = profile->GetPrefs(); |
210 return user_pref_service && | 258 return user_pref_service && |
211 user_pref_service->GetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu); | 259 user_pref_service->GetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu); |
212 } | 260 } |
213 | 261 |
214 ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate() { | 262 ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 301 } |
254 | 302 |
255 void ChromeShellDelegate::PlatformInit() { | 303 void ChromeShellDelegate::PlatformInit() { |
256 registrar_.Add(this, | 304 registrar_.Add(this, |
257 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 305 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
258 content::NotificationService::AllSources()); | 306 content::NotificationService::AllSources()); |
259 registrar_.Add(this, | 307 registrar_.Add(this, |
260 chrome::NOTIFICATION_SESSION_STARTED, | 308 chrome::NOTIFICATION_SESSION_STARTED, |
261 content::NotificationService::AllSources()); | 309 content::NotificationService::AllSources()); |
262 } | 310 } |
OLD | NEW |