| 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" |
| 15 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" | 16 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" |
| 16 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 17 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 17 #include "chrome/browser/chromeos/options/network_config_view.h" | 18 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 19 #include "chrome/browser/chromeos/set_time_dialog.h" | 20 #include "chrome/browser/chromeos/set_time_dialog.h" |
| 20 #include "chrome/browser/chromeos/system/system_clock.h" | 21 #include "chrome/browser/chromeos/system/system_clock.h" |
| 21 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" | 22 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" |
| 22 #include "chrome/browser/lifetime/application_lifetime.h" | 23 #include "chrome/browser/lifetime/application_lifetime.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/ui/ash/ash_util.h" | 25 #include "chrome/browser/ui/ash/ash_util.h" |
| 25 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h" | 26 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h" |
| 26 #include "chrome/browser/ui/chrome_pages.h" | 27 #include "chrome/browser/ui/chrome_pages.h" |
| 27 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 28 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 28 #include "chrome/browser/ui/singleton_tabs.h" | 29 #include "chrome/browser/ui/singleton_tabs.h" |
| 30 #include "chrome/browser/upgrade_detector.h" |
| 29 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 30 #include "chromeos/dbus/dbus_thread_manager.h" | 32 #include "chromeos/dbus/dbus_thread_manager.h" |
| 31 #include "chromeos/dbus/session_manager_client.h" | 33 #include "chromeos/dbus/session_manager_client.h" |
| 32 #include "chromeos/login/login_state.h" | 34 #include "chromeos/login/login_state.h" |
| 33 #include "components/user_manager/user_manager.h" | 35 #include "components/user_manager/user_manager.h" |
| 36 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/user_metrics.h" | 37 #include "content/public/browser/user_metrics.h" |
| 35 #include "content/public/common/service_manager_connection.h" | 38 #include "content/public/common/service_manager_connection.h" |
| 36 #include "extensions/browser/api/vpn_provider/vpn_service.h" | 39 #include "extensions/browser/api/vpn_provider/vpn_service.h" |
| 37 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h" | 40 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h" |
| 38 #include "net/base/escape.h" | 41 #include "net/base/escape.h" |
| 39 #include "services/service_manager/public/cpp/connector.h" | 42 #include "services/service_manager/public/cpp/connector.h" |
| 40 #include "services/ui/public/cpp/property_type_converters.h" | 43 #include "services/ui/public/cpp/property_type_converters.h" |
| 41 #include "services/ui/public/interfaces/window_manager.mojom.h" | 44 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 42 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" | 45 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" |
| 43 #include "ui/views/widget/widget.h" | 46 #include "ui/views/widget/widget.h" |
| 44 #include "ui/views/window/dialog_delegate.h" | 47 #include "ui/views/window/dialog_delegate.h" |
| 45 | 48 |
| 46 using chromeos::DBusThreadManager; | 49 using chromeos::DBusThreadManager; |
| 47 using chromeos::LoginState; | 50 using chromeos::LoginState; |
| 48 using views::Widget; | 51 using views::Widget; |
| 49 | 52 |
| 50 namespace { | 53 namespace { |
| 51 | 54 |
| 52 const char kDisplaySettingsSubPageName[] = "display"; | 55 const char kDisplaySettingsSubPageName[] = "display"; |
| 53 const char kPaletteSettingsSubPageName[] = "stylus-overlay"; | 56 const char kPaletteSettingsSubPageName[] = "stylus-overlay"; |
| 54 | 57 |
| 55 SystemTrayClient* g_instance = nullptr; | 58 SystemTrayClient* g_instance = nullptr; |
| 56 | 59 |
| 57 void ShowSettingsSubPageForActiveUser(const std::string& sub_page) { | 60 void ShowSettingsSubPageForActiveUser(const std::string& sub_page) { |
| 58 chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(), | 61 chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(), |
| 59 sub_page); | 62 sub_page); |
| 60 } | 63 } |
| 61 | 64 |
| 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 |
| 62 } // namespace | 85 } // namespace |
| 63 | 86 |
| 64 SystemTrayClient::SystemTrayClient() : binding_(this) { | 87 SystemTrayClient::SystemTrayClient() : binding_(this) { |
| 65 content::ServiceManagerConnection::GetForProcess() | 88 content::ServiceManagerConnection::GetForProcess() |
| 66 ->GetConnector() | 89 ->GetConnector() |
| 67 ->ConnectToInterface(ash_util::GetAshServiceName(), &system_tray_); | 90 ->ConnectToInterface(ash_util::GetAshServiceName(), &system_tray_); |
| 68 // Register this object as the client interface implementation. | 91 // Register this object as the client interface implementation. |
| 69 system_tray_->SetClient(binding_.CreateInterfacePtrAndBind()); | 92 system_tray_->SetClient(binding_.CreateInterfacePtrAndBind()); |
| 70 | 93 |
| 71 // If this observes clock setting changes before ash comes up the IPCs will | 94 // If this observes clock setting changes before ash comes up the IPCs will |
| 72 // be queued on |system_tray_|. | 95 // be queued on |system_tray_|. |
| 73 g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); | 96 g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); |
| 74 | 97 |
| 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 |
| 75 DCHECK(!g_instance); | 105 DCHECK(!g_instance); |
| 76 g_instance = this; | 106 g_instance = this; |
| 77 } | 107 } |
| 78 | 108 |
| 79 SystemTrayClient::~SystemTrayClient() { | 109 SystemTrayClient::~SystemTrayClient() { |
| 80 DCHECK_EQ(this, g_instance); | 110 DCHECK_EQ(this, g_instance); |
| 81 g_instance = nullptr; | 111 g_instance = nullptr; |
| 82 | 112 |
| 83 g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this); | 113 g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this); |
| 84 } | 114 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 mojo::ConvertTo<std::vector<uint8_t>>(container_id); | 190 mojo::ConvertTo<std::vector<uint8_t>>(container_id); |
| 161 } else { | 191 } else { |
| 162 params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(), | 192 params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(), |
| 163 container_id); | 193 container_id); |
| 164 } | 194 } |
| 165 Widget* widget = new Widget; // Owned by native widget. | 195 Widget* widget = new Widget; // Owned by native widget. |
| 166 widget->Init(params); | 196 widget->Init(params); |
| 167 return widget; | 197 return widget; |
| 168 } | 198 } |
| 169 | 199 |
| 200 void SystemTrayClient::SetFlashUpdateAvailable() { |
| 201 flash_update_available_ = true; |
| 202 HandleUpdateAvailable(); |
| 203 } |
| 204 |
| 170 //////////////////////////////////////////////////////////////////////////////// | 205 //////////////////////////////////////////////////////////////////////////////// |
| 171 // ash::mojom::SystemTrayClient: | 206 // ash::mojom::SystemTrayClient: |
| 172 | 207 |
| 173 void SystemTrayClient::ShowSettings() { | 208 void SystemTrayClient::ShowSettings() { |
| 174 ShowSettingsSubPageForActiveUser(std::string()); | 209 ShowSettingsSubPageForActiveUser(std::string()); |
| 175 } | 210 } |
| 176 | 211 |
| 177 void SystemTrayClient::ShowDateSettings() { | 212 void SystemTrayClient::ShowDateSettings() { |
| 178 content::RecordAction(base::UserMetricsAction("ShowDateOptions")); | 213 content::RecordAction(base::UserMetricsAction("ShowDateOptions")); |
| 179 // Everybody can change the time zone (even though it is a device setting). | 214 // 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... |
| 302 CHECK(!login_state->IsUserLoggedIn() || | 337 CHECK(!login_state->IsUserLoggedIn() || |
| 303 login_state->GetLoggedInUserType() == LoginState::LOGGED_IN_USER_NONE); | 338 login_state->GetLoggedInUserType() == LoginState::LOGGED_IN_USER_NONE); |
| 304 chromeos::LoginDisplayHost::default_host()->OpenProxySettings(); | 339 chromeos::LoginDisplayHost::default_host()->OpenProxySettings(); |
| 305 } | 340 } |
| 306 | 341 |
| 307 void SystemTrayClient::SignOut() { | 342 void SystemTrayClient::SignOut() { |
| 308 chrome::AttemptUserExit(); | 343 chrome::AttemptUserExit(); |
| 309 } | 344 } |
| 310 | 345 |
| 311 void SystemTrayClient::RequestRestartForUpdate() { | 346 void SystemTrayClient::RequestRestartForUpdate() { |
| 312 bool component_update = false; | 347 // Flash updates on Chrome OS require device reboot. |
| 313 chromeos::SystemTrayDelegateChromeOS* tray = | 348 const chrome::RebootPolicy reboot_policy = |
| 314 chromeos::SystemTrayDelegateChromeOS::instance(); | 349 flash_update_available_ ? chrome::RebootPolicy::kForceReboot |
| 315 if (tray) | 350 : chrome::RebootPolicy::kOptionalReboot; |
| 316 component_update = tray->GetFlashUpdateAvailable(); | |
| 317 | |
| 318 chrome::RebootPolicy reboot_policy = | |
| 319 component_update ? chrome::RebootPolicy::kForceReboot | |
| 320 : chrome::RebootPolicy::kOptionalReboot; | |
| 321 | 351 |
| 322 chrome::NotifyAndTerminate(true /* fast_path */, reboot_policy); | 352 chrome::NotifyAndTerminate(true /* fast_path */, reboot_policy); |
| 323 } | 353 } |
| 324 | 354 |
| 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 |
| 325 //////////////////////////////////////////////////////////////////////////////// | 370 //////////////////////////////////////////////////////////////////////////////// |
| 326 // chromeos::system::SystemClockObserver: | 371 // chromeos::system::SystemClockObserver: |
| 327 | 372 |
| 328 void SystemTrayClient::OnSystemClockChanged( | 373 void SystemTrayClient::OnSystemClockChanged( |
| 329 chromeos::system::SystemClock* clock) { | 374 chromeos::system::SystemClock* clock) { |
| 330 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); | 375 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); |
| 331 } | 376 } |
| 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 |