| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/system_tray_client.h" | 5 #include "chrome/browser/ui/ash/system_tray_client.h" |
| 6 | 6 |
| 7 #include "ash/common/login_status.h" | 7 #include "ash/common/login_status.h" |
| 8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/wm_shell.h" | 9 #include "ash/common/wm_shell.h" |
| 10 #include "ash/public/cpp/shell_window_ids.h" | 10 #include "ash/public/cpp/shell_window_ids.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/browser_process_platform_part.h" | 14 #include "chrome/browser/browser_process_platform_part.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | |
| 16 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" | 15 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" |
| 17 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 16 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 18 #include "chrome/browser/chromeos/options/network_config_view.h" | 17 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 20 #include "chrome/browser/chromeos/set_time_dialog.h" | 19 #include "chrome/browser/chromeos/set_time_dialog.h" |
| 21 #include "chrome/browser/chromeos/system/system_clock.h" | 20 #include "chrome/browser/chromeos/system/system_clock.h" |
| 22 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" | 21 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" |
| 23 #include "chrome/browser/lifetime/application_lifetime.h" | 22 #include "chrome/browser/lifetime/application_lifetime.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/ui/ash/ash_util.h" | 24 #include "chrome/browser/ui/ash/ash_util.h" |
| 26 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h" | 25 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h" |
| 27 #include "chrome/browser/ui/chrome_pages.h" | 26 #include "chrome/browser/ui/chrome_pages.h" |
| 28 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 27 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 29 #include "chrome/browser/ui/singleton_tabs.h" | 28 #include "chrome/browser/ui/singleton_tabs.h" |
| 30 #include "chrome/browser/upgrade_detector.h" | |
| 31 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 32 #include "chromeos/dbus/dbus_thread_manager.h" | 30 #include "chromeos/dbus/dbus_thread_manager.h" |
| 33 #include "chromeos/dbus/session_manager_client.h" | 31 #include "chromeos/dbus/session_manager_client.h" |
| 34 #include "chromeos/login/login_state.h" | 32 #include "chromeos/login/login_state.h" |
| 35 #include "components/user_manager/user_manager.h" | 33 #include "components/user_manager/user_manager.h" |
| 36 #include "content/public/browser/notification_service.h" | |
| 37 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
| 38 #include "content/public/common/service_manager_connection.h" | 35 #include "content/public/common/service_manager_connection.h" |
| 39 #include "extensions/browser/api/vpn_provider/vpn_service.h" | 36 #include "extensions/browser/api/vpn_provider/vpn_service.h" |
| 40 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h" | 37 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h" |
| 41 #include "net/base/escape.h" | 38 #include "net/base/escape.h" |
| 42 #include "services/service_manager/public/cpp/connector.h" | 39 #include "services/service_manager/public/cpp/connector.h" |
| 43 #include "services/ui/public/cpp/property_type_converters.h" | 40 #include "services/ui/public/cpp/property_type_converters.h" |
| 44 #include "services/ui/public/interfaces/window_manager.mojom.h" | 41 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 45 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" | 42 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" |
| 46 #include "ui/views/widget/widget.h" | 43 #include "ui/views/widget/widget.h" |
| 47 #include "ui/views/window/dialog_delegate.h" | 44 #include "ui/views/window/dialog_delegate.h" |
| 48 | 45 |
| 49 using chromeos::DBusThreadManager; | 46 using chromeos::DBusThreadManager; |
| 50 using chromeos::LoginState; | 47 using chromeos::LoginState; |
| 51 using views::Widget; | 48 using views::Widget; |
| 52 | 49 |
| 53 namespace { | 50 namespace { |
| 54 | 51 |
| 55 const char kDisplaySettingsSubPageName[] = "display"; | 52 const char kDisplaySettingsSubPageName[] = "display"; |
| 56 const char kPaletteSettingsSubPageName[] = "stylus-overlay"; | 53 const char kPaletteSettingsSubPageName[] = "stylus-overlay"; |
| 57 | 54 |
| 58 SystemTrayClient* g_instance = nullptr; | 55 SystemTrayClient* g_instance = nullptr; |
| 59 | 56 |
| 60 void ShowSettingsSubPageForActiveUser(const std::string& sub_page) { | 57 void ShowSettingsSubPageForActiveUser(const std::string& sub_page) { |
| 61 chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(), | 58 chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(), |
| 62 sub_page); | 59 sub_page); |
| 63 } | 60 } |
| 64 | 61 |
| 65 // Returns the severity of a pending Chrome / Chrome OS update. | |
| 66 ash::mojom::UpdateSeverity GetUpdateSeverity(UpgradeDetector* detector) { | |
| 67 switch (detector->upgrade_notification_stage()) { | |
| 68 case UpgradeDetector::UPGRADE_ANNOYANCE_NONE: | |
| 69 return ash::mojom::UpdateSeverity::NONE; | |
| 70 case UpgradeDetector::UPGRADE_ANNOYANCE_LOW: | |
| 71 return ash::mojom::UpdateSeverity::LOW; | |
| 72 case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED: | |
| 73 return ash::mojom::UpdateSeverity::ELEVATED; | |
| 74 case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH: | |
| 75 return ash::mojom::UpdateSeverity::HIGH; | |
| 76 case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE: | |
| 77 return ash::mojom::UpdateSeverity::SEVERE; | |
| 78 case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL: | |
| 79 return ash::mojom::UpdateSeverity::CRITICAL; | |
| 80 } | |
| 81 NOTREACHED(); | |
| 82 return ash::mojom::UpdateSeverity::CRITICAL; | |
| 83 } | |
| 84 | |
| 85 } // namespace | 62 } // namespace |
| 86 | 63 |
| 87 SystemTrayClient::SystemTrayClient() : binding_(this) { | 64 SystemTrayClient::SystemTrayClient() : binding_(this) { |
| 88 content::ServiceManagerConnection::GetForProcess() | 65 content::ServiceManagerConnection::GetForProcess() |
| 89 ->GetConnector() | 66 ->GetConnector() |
| 90 ->ConnectToInterface(ash_util::GetAshServiceName(), &system_tray_); | 67 ->ConnectToInterface(ash_util::GetAshServiceName(), &system_tray_); |
| 91 // Register this object as the client interface implementation. | 68 // Register this object as the client interface implementation. |
| 92 system_tray_->SetClient(binding_.CreateInterfacePtrAndBind()); | 69 system_tray_->SetClient(binding_.CreateInterfacePtrAndBind()); |
| 93 | 70 |
| 94 // If this observes clock setting changes before ash comes up the IPCs will | 71 // If this observes clock setting changes before ash comes up the IPCs will |
| 95 // be queued on |system_tray_|. | 72 // be queued on |system_tray_|. |
| 96 g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); | 73 g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); |
| 97 | 74 |
| 98 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | |
| 99 content::NotificationService::AllSources()); | |
| 100 | |
| 101 // If an upgrade is available at startup then tell ash about it. | |
| 102 if (UpgradeDetector::GetInstance()->notify_upgrade()) | |
| 103 HandleUpdateAvailable(); | |
| 104 | |
| 105 DCHECK(!g_instance); | 75 DCHECK(!g_instance); |
| 106 g_instance = this; | 76 g_instance = this; |
| 107 } | 77 } |
| 108 | 78 |
| 109 SystemTrayClient::~SystemTrayClient() { | 79 SystemTrayClient::~SystemTrayClient() { |
| 110 DCHECK_EQ(this, g_instance); | 80 DCHECK_EQ(this, g_instance); |
| 111 g_instance = nullptr; | 81 g_instance = nullptr; |
| 112 | 82 |
| 113 g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this); | 83 g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this); |
| 114 } | 84 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 mojo::ConvertTo<std::vector<uint8_t>>(container_id); | 160 mojo::ConvertTo<std::vector<uint8_t>>(container_id); |
| 191 } else { | 161 } else { |
| 192 params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(), | 162 params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(), |
| 193 container_id); | 163 container_id); |
| 194 } | 164 } |
| 195 Widget* widget = new Widget; // Owned by native widget. | 165 Widget* widget = new Widget; // Owned by native widget. |
| 196 widget->Init(params); | 166 widget->Init(params); |
| 197 return widget; | 167 return widget; |
| 198 } | 168 } |
| 199 | 169 |
| 200 void SystemTrayClient::SetFlashUpdateAvailable() { | |
| 201 flash_update_available_ = true; | |
| 202 HandleUpdateAvailable(); | |
| 203 } | |
| 204 | |
| 205 //////////////////////////////////////////////////////////////////////////////// | 170 //////////////////////////////////////////////////////////////////////////////// |
| 206 // ash::mojom::SystemTrayClient: | 171 // ash::mojom::SystemTrayClient: |
| 207 | 172 |
| 208 void SystemTrayClient::ShowSettings() { | 173 void SystemTrayClient::ShowSettings() { |
| 209 ShowSettingsSubPageForActiveUser(std::string()); | 174 ShowSettingsSubPageForActiveUser(std::string()); |
| 210 } | 175 } |
| 211 | 176 |
| 212 void SystemTrayClient::ShowDateSettings() { | 177 void SystemTrayClient::ShowDateSettings() { |
| 213 content::RecordAction(base::UserMetricsAction("ShowDateOptions")); | 178 content::RecordAction(base::UserMetricsAction("ShowDateOptions")); |
| 214 // Everybody can change the time zone (even though it is a device setting). | 179 // Everybody can change the time zone (even though it is a device setting). |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 CHECK(!login_state->IsUserLoggedIn() || | 302 CHECK(!login_state->IsUserLoggedIn() || |
| 338 login_state->GetLoggedInUserType() == LoginState::LOGGED_IN_USER_NONE); | 303 login_state->GetLoggedInUserType() == LoginState::LOGGED_IN_USER_NONE); |
| 339 chromeos::LoginDisplayHost::default_host()->OpenProxySettings(); | 304 chromeos::LoginDisplayHost::default_host()->OpenProxySettings(); |
| 340 } | 305 } |
| 341 | 306 |
| 342 void SystemTrayClient::SignOut() { | 307 void SystemTrayClient::SignOut() { |
| 343 chrome::AttemptUserExit(); | 308 chrome::AttemptUserExit(); |
| 344 } | 309 } |
| 345 | 310 |
| 346 void SystemTrayClient::RequestRestartForUpdate() { | 311 void SystemTrayClient::RequestRestartForUpdate() { |
| 347 // Flash updates on Chrome OS require device reboot. | 312 bool component_update = false; |
| 348 const chrome::RebootPolicy reboot_policy = | 313 chromeos::SystemTrayDelegateChromeOS* tray = |
| 349 flash_update_available_ ? chrome::RebootPolicy::kForceReboot | 314 chromeos::SystemTrayDelegateChromeOS::instance(); |
| 350 : chrome::RebootPolicy::kOptionalReboot; | 315 if (tray) |
| 316 component_update = tray->GetFlashUpdateAvailable(); |
| 317 |
| 318 chrome::RebootPolicy reboot_policy = |
| 319 component_update ? chrome::RebootPolicy::kForceReboot |
| 320 : chrome::RebootPolicy::kOptionalReboot; |
| 351 | 321 |
| 352 chrome::NotifyAndTerminate(true /* fast_path */, reboot_policy); | 322 chrome::NotifyAndTerminate(true /* fast_path */, reboot_policy); |
| 353 } | 323 } |
| 354 | 324 |
| 355 void SystemTrayClient::HandleUpdateAvailable() { | |
| 356 // Show an update icon for Chrome updates and Flash component updates. | |
| 357 UpgradeDetector* detector = UpgradeDetector::GetInstance(); | |
| 358 DCHECK(detector->notify_upgrade() || flash_update_available_); | |
| 359 | |
| 360 // Get the Chrome update severity. | |
| 361 ash::mojom::UpdateSeverity severity = GetUpdateSeverity(detector); | |
| 362 | |
| 363 // Flash updates are elevated severity unless the Chrome severity is higher. | |
| 364 if (flash_update_available_) | |
| 365 severity = std::max(severity, ash::mojom::UpdateSeverity::ELEVATED); | |
| 366 | |
| 367 system_tray_->ShowUpdateIcon(severity, detector->is_factory_reset_required()); | |
| 368 } | |
| 369 | |
| 370 //////////////////////////////////////////////////////////////////////////////// | 325 //////////////////////////////////////////////////////////////////////////////// |
| 371 // chromeos::system::SystemClockObserver: | 326 // chromeos::system::SystemClockObserver: |
| 372 | 327 |
| 373 void SystemTrayClient::OnSystemClockChanged( | 328 void SystemTrayClient::OnSystemClockChanged( |
| 374 chromeos::system::SystemClock* clock) { | 329 chromeos::system::SystemClock* clock) { |
| 375 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); | 330 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); |
| 376 } | 331 } |
| 377 | |
| 378 void SystemTrayClient::Observe(int type, | |
| 379 const content::NotificationSource& source, | |
| 380 const content::NotificationDetails& details) { | |
| 381 DCHECK_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, type); | |
| 382 HandleUpdateAvailable(); | |
| 383 } | |
| OLD | NEW |