| 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/system_tray_delegate_chromeos.h" | 5 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "base/metrics/user_metrics.h" | 29 #include "base/metrics/user_metrics.h" |
| 30 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
| 31 #include "base/sys_info.h" | 31 #include "base/sys_info.h" |
| 32 #include "base/time/time.h" | 32 #include "base/time/time.h" |
| 33 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
| 34 #include "chrome/browser/chrome_notification_types.h" | 34 #include "chrome/browser/chrome_notification_types.h" |
| 35 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | 35 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
| 36 #include "chrome/browser/chromeos/events/system_key_event_listener.h" | 36 #include "chrome/browser/chromeos/events/system_key_event_listener.h" |
| 37 #include "chrome/browser/chromeos/input_method/input_method_switch_recorder.h" | 37 #include "chrome/browser/chromeos/input_method/input_method_switch_recorder.h" |
| 38 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 38 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 39 #include "chrome/browser/chromeos/login/help_app_launcher.h" | |
| 40 #include "chrome/browser/chromeos/login/login_wizard.h" | 39 #include "chrome/browser/chromeos/login/login_wizard.h" |
| 41 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 40 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 42 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 43 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | |
| 44 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h" | 41 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h" |
| 45 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 42 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 46 #include "chrome/browser/profiles/profile_manager.h" | 43 #include "chrome/browser/profiles/profile_manager.h" |
| 47 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 44 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 48 #include "chrome/browser/ui/ash/networking_config_delegate_chromeos.h" | 45 #include "chrome/browser/ui/ash/networking_config_delegate_chromeos.h" |
| 49 #include "chrome/browser/ui/ash/system_tray_client.h" | 46 #include "chrome/browser/ui/ash/system_tray_client.h" |
| 50 #include "chrome/browser/ui/browser.h" | 47 #include "chrome/browser/ui/browser.h" |
| 51 #include "chrome/browser/ui/browser_list.h" | 48 #include "chrome/browser/ui/browser_list.h" |
| 52 #include "chrome/browser/ui/chrome_pages.h" | 49 #include "chrome/browser/ui/chrome_pages.h" |
| 53 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | |
| 54 #include "chrome/browser/ui/singleton_tabs.h" | |
| 55 #include "chrome/common/chrome_switches.h" | 50 #include "chrome/common/chrome_switches.h" |
| 56 #include "chrome/common/features.h" | 51 #include "chrome/common/features.h" |
| 57 #include "chrome/common/pref_names.h" | 52 #include "chrome/common/pref_names.h" |
| 58 #include "chrome/common/url_constants.h" | |
| 59 #include "chrome/grit/generated_resources.h" | 53 #include "chrome/grit/generated_resources.h" |
| 60 #include "chrome/grit/locale_settings.h" | 54 #include "chrome/grit/locale_settings.h" |
| 61 #include "chromeos/login/login_state.h" | 55 #include "chromeos/login/login_state.h" |
| 62 #include "chromeos/network/portal_detector/network_portal_detector.h" | 56 #include "chromeos/network/portal_detector/network_portal_detector.h" |
| 63 #include "components/google/core/browser/google_util.h" | 57 #include "components/google/core/browser/google_util.h" |
| 64 #include "components/policy/core/common/cloud/cloud_policy_store.h" | |
| 65 #include "components/prefs/pref_service.h" | 58 #include "components/prefs/pref_service.h" |
| 66 #include "components/session_manager/core/session_manager.h" | 59 #include "components/session_manager/core/session_manager.h" |
| 67 #include "components/user_manager/user.h" | 60 #include "components/user_manager/user.h" |
| 68 #include "components/user_manager/user_manager.h" | 61 #include "components/user_manager/user_manager.h" |
| 69 #include "components/user_manager/user_type.h" | 62 #include "components/user_manager/user_type.h" |
| 70 #include "content/public/browser/notification_observer.h" | 63 #include "content/public/browser/notification_observer.h" |
| 71 #include "content/public/browser/notification_service.h" | 64 #include "content/public/browser/notification_service.h" |
| 72 #include "ui/base/ime/chromeos/extension_ime_util.h" | 65 #include "ui/base/ime/chromeos/extension_ime_util.h" |
| 73 #include "ui/base/ime/chromeos/input_method_manager.h" | 66 #include "ui/base/ime/chromeos/input_method_manager.h" |
| 74 #include "ui/base/l10n/l10n_util.h" | 67 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 96 info->short_name = util.GetInputMethodShortName(ime); | 89 info->short_name = util.GetInputMethodShortName(ime); |
| 97 info->third_party = extension_ime_util::IsExtensionIME(ime.id()); | 90 info->third_party = extension_ime_util::IsExtensionIME(ime.id()); |
| 98 } | 91 } |
| 99 | 92 |
| 100 void OnAcceptMultiprofilesIntro(bool no_show_again) { | 93 void OnAcceptMultiprofilesIntro(bool no_show_again) { |
| 101 PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); | 94 PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); |
| 102 prefs->SetBoolean(prefs::kMultiProfileNeverShowIntro, no_show_again); | 95 prefs->SetBoolean(prefs::kMultiProfileNeverShowIntro, no_show_again); |
| 103 UserAddingScreen::Get()->Start(); | 96 UserAddingScreen::Get()->Start(); |
| 104 } | 97 } |
| 105 | 98 |
| 106 bool IsSessionInSecondaryLoginScreen() { | |
| 107 return session_manager::SessionManager::Get()->IsInSecondaryLoginScreen(); | |
| 108 } | |
| 109 | |
| 110 } // namespace | 99 } // namespace |
| 111 | 100 |
| 112 SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS() | 101 SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS() |
| 113 : networking_config_delegate_( | 102 : networking_config_delegate_( |
| 114 base::MakeUnique<NetworkingConfigDelegateChromeos>()) { | 103 base::MakeUnique<NetworkingConfigDelegateChromeos>()) { |
| 115 // Register notifications on construction so that events such as | 104 // Register notifications on construction so that events such as |
| 116 // PROFILE_CREATED do not get missed if they happen before Initialize(). | 105 // PROFILE_CREATED do not get missed if they happen before Initialize(). |
| 117 registrar_.reset(new content::NotificationRegistrar); | 106 registrar_.reset(new content::NotificationRegistrar); |
| 118 if (GetUserLoginStatus() == ash::LoginStatus::NOT_LOGGED_IN) { | 107 if (GetUserLoginStatus() == ash::LoginStatus::NOT_LOGGED_IN) { |
| 119 registrar_->Add(this, | 108 registrar_->Add(this, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 148 UpdateSessionLengthLimit(); | 137 UpdateSessionLengthLimit(); |
| 149 | 138 |
| 150 local_state_registrar_->Add( | 139 local_state_registrar_->Add( |
| 151 prefs::kSessionStartTime, | 140 prefs::kSessionStartTime, |
| 152 base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionStartTime, | 141 base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionStartTime, |
| 153 base::Unretained(this))); | 142 base::Unretained(this))); |
| 154 local_state_registrar_->Add( | 143 local_state_registrar_->Add( |
| 155 prefs::kSessionLengthLimit, | 144 prefs::kSessionLengthLimit, |
| 156 base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionLengthLimit, | 145 base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionLengthLimit, |
| 157 base::Unretained(this))); | 146 base::Unretained(this))); |
| 158 | |
| 159 policy::BrowserPolicyConnectorChromeOS* policy_connector = | |
| 160 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 161 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = | |
| 162 policy_connector->GetDeviceCloudPolicyManager(); | |
| 163 if (policy_manager) | |
| 164 policy_manager->core()->store()->AddObserver(this); | |
| 165 UpdateEnterpriseDomain(); | |
| 166 } | 147 } |
| 167 | 148 |
| 168 SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() { | 149 SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() { |
| 169 // Unregister PrefChangeRegistrars. | 150 // Unregister PrefChangeRegistrars. |
| 170 local_state_registrar_.reset(); | 151 local_state_registrar_.reset(); |
| 171 user_pref_registrar_.reset(); | 152 user_pref_registrar_.reset(); |
| 172 | 153 |
| 173 // Unregister content notifications before destroying any components. | 154 // Unregister content notifications before destroying any components. |
| 174 registrar_.reset(); | 155 registrar_.reset(); |
| 175 | 156 |
| 176 // Unregister a11y status subscription. | 157 // Unregister a11y status subscription. |
| 177 accessibility_subscription_.reset(); | 158 accessibility_subscription_.reset(); |
| 178 | 159 |
| 179 input_method::InputMethodManager::Get()->RemoveObserver(this); | 160 input_method::InputMethodManager::Get()->RemoveObserver(this); |
| 180 ui::ime::InputMethodMenuManager::GetInstance()->RemoveObserver(this); | 161 ui::ime::InputMethodMenuManager::GetInstance()->RemoveObserver(this); |
| 181 | 162 |
| 182 BrowserList::RemoveObserver(this); | 163 BrowserList::RemoveObserver(this); |
| 183 StopObservingAppWindowRegistry(); | 164 StopObservingAppWindowRegistry(); |
| 184 | |
| 185 policy::BrowserPolicyConnectorChromeOS* connector = | |
| 186 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 187 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = | |
| 188 connector->GetDeviceCloudPolicyManager(); | |
| 189 if (policy_manager) | |
| 190 policy_manager->core()->store()->RemoveObserver(this); | |
| 191 } | 165 } |
| 192 | 166 |
| 193 ash::LoginStatus SystemTrayDelegateChromeOS::GetUserLoginStatus() const { | 167 ash::LoginStatus SystemTrayDelegateChromeOS::GetUserLoginStatus() const { |
| 194 return SystemTrayClient::GetUserLoginStatus(); | 168 return SystemTrayClient::GetUserLoginStatus(); |
| 195 } | 169 } |
| 196 | 170 |
| 197 std::string SystemTrayDelegateChromeOS::GetEnterpriseDomain() const { | |
| 198 return enterprise_domain_; | |
| 199 } | |
| 200 | |
| 201 base::string16 SystemTrayDelegateChromeOS::GetEnterpriseMessage() const { | |
| 202 if (is_active_directory_managed_) | |
| 203 return l10n_util::GetStringUTF16(IDS_DEVICE_ENTERPRISE_MANAGED_NOTICE); | |
| 204 if (!GetEnterpriseDomain().empty()) { | |
| 205 return l10n_util::GetStringFUTF16(IDS_DEVICE_OWNED_BY_NOTICE, | |
| 206 base::UTF8ToUTF16(GetEnterpriseDomain())); | |
| 207 } | |
| 208 return base::string16(); | |
| 209 } | |
| 210 | |
| 211 void SystemTrayDelegateChromeOS::ShowEnterpriseInfo() { | |
| 212 // TODO(mash): Refactor out SessionStateDelegate and move to SystemTrayClient. | |
| 213 ash::LoginStatus status = GetUserLoginStatus(); | |
| 214 if (status == ash::LoginStatus::NOT_LOGGED_IN || | |
| 215 status == ash::LoginStatus::LOCKED || IsSessionInSecondaryLoginScreen()) { | |
| 216 scoped_refptr<chromeos::HelpAppLauncher> help_app( | |
| 217 new chromeos::HelpAppLauncher(nullptr /* parent_window */)); | |
| 218 help_app->ShowHelpTopic(chromeos::HelpAppLauncher::HELP_ENTERPRISE); | |
| 219 } else { | |
| 220 chrome::ScopedTabbedBrowserDisplayer displayer( | |
| 221 ProfileManager::GetActiveUserProfile()); | |
| 222 chrome::ShowSingletonTab(displayer.browser(), | |
| 223 GURL(chrome::kLearnMoreEnterpriseURL)); | |
| 224 } | |
| 225 } | |
| 226 | |
| 227 void SystemTrayDelegateChromeOS::ShowUserLogin() { | 171 void SystemTrayDelegateChromeOS::ShowUserLogin() { |
| 228 if (!ash::Shell::Get()->shell_delegate()->IsMultiProfilesEnabled()) | 172 if (!ash::Shell::Get()->shell_delegate()->IsMultiProfilesEnabled()) |
| 229 return; | 173 return; |
| 230 | 174 |
| 231 // Only regular non-supervised users could add other users to current session. | 175 // Only regular non-supervised users could add other users to current session. |
| 232 if (user_manager::UserManager::Get()->GetActiveUser()->GetType() != | 176 if (user_manager::UserManager::Get()->GetActiveUser()->GetType() != |
| 233 user_manager::USER_TYPE_REGULAR) { | 177 user_manager::USER_TYPE_REGULAR) { |
| 234 return; | 178 return; |
| 235 } | 179 } |
| 236 | 180 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 bool show_message) { | 493 bool show_message) { |
| 550 GetSystemTrayNotifier()->NotifyRefreshIME(); | 494 GetSystemTrayNotifier()->NotifyRefreshIME(); |
| 551 } | 495 } |
| 552 | 496 |
| 553 // Overridden from InputMethodMenuManager::Observer. | 497 // Overridden from InputMethodMenuManager::Observer. |
| 554 void SystemTrayDelegateChromeOS::InputMethodMenuItemChanged( | 498 void SystemTrayDelegateChromeOS::InputMethodMenuItemChanged( |
| 555 ui::ime::InputMethodMenuManager* manager) { | 499 ui::ime::InputMethodMenuManager* manager) { |
| 556 GetSystemTrayNotifier()->NotifyRefreshIME(); | 500 GetSystemTrayNotifier()->NotifyRefreshIME(); |
| 557 } | 501 } |
| 558 | 502 |
| 559 void SystemTrayDelegateChromeOS::UpdateEnterpriseDomain() { | |
| 560 policy::BrowserPolicyConnectorChromeOS* connector = | |
| 561 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 562 std::string old_enterprise_domain(std::move(enterprise_domain_)); | |
| 563 enterprise_domain_ = connector->GetEnterpriseDomain(); | |
| 564 bool old_is_active_directory_managed = is_active_directory_managed_; | |
| 565 is_active_directory_managed_ = connector->IsActiveDirectoryManaged(); | |
| 566 if ((!is_active_directory_managed_ && | |
| 567 enterprise_domain_ != old_enterprise_domain) || | |
| 568 (is_active_directory_managed_ != old_is_active_directory_managed)) { | |
| 569 GetSystemTrayNotifier()->NotifyEnterpriseDomainChanged(); | |
| 570 } | |
| 571 } | |
| 572 | |
| 573 // Overridden from CloudPolicyStore::Observer | |
| 574 void SystemTrayDelegateChromeOS::OnStoreLoaded( | |
| 575 policy::CloudPolicyStore* store) { | |
| 576 UpdateEnterpriseDomain(); | |
| 577 } | |
| 578 | |
| 579 void SystemTrayDelegateChromeOS::OnStoreError(policy::CloudPolicyStore* store) { | |
| 580 UpdateEnterpriseDomain(); | |
| 581 } | |
| 582 | |
| 583 // Overridden from chrome::BrowserListObserver. | 503 // Overridden from chrome::BrowserListObserver. |
| 584 void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser* browser) { | 504 void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser* browser) { |
| 585 NotifyIfLastWindowClosed(); | 505 NotifyIfLastWindowClosed(); |
| 586 } | 506 } |
| 587 | 507 |
| 588 // Overridden from extensions::AppWindowRegistry::Observer. | 508 // Overridden from extensions::AppWindowRegistry::Observer. |
| 589 void SystemTrayDelegateChromeOS::OnAppWindowRemoved( | 509 void SystemTrayDelegateChromeOS::OnAppWindowRemoved( |
| 590 extensions::AppWindow* app_window) { | 510 extensions::AppWindow* app_window) { |
| 591 NotifyIfLastWindowClosed(); | 511 NotifyIfLastWindowClosed(); |
| 592 } | 512 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 607 | 527 |
| 608 void SystemTrayDelegateChromeOS::ImeMenuItemsChanged( | 528 void SystemTrayDelegateChromeOS::ImeMenuItemsChanged( |
| 609 const std::string& engine_id, | 529 const std::string& engine_id, |
| 610 const std::vector<input_method::InputMethodManager::MenuItem>& items) {} | 530 const std::vector<input_method::InputMethodManager::MenuItem>& items) {} |
| 611 | 531 |
| 612 ash::SystemTrayDelegate* CreateSystemTrayDelegate() { | 532 ash::SystemTrayDelegate* CreateSystemTrayDelegate() { |
| 613 return new SystemTrayDelegateChromeOS(); | 533 return new SystemTrayDelegateChromeOS(); |
| 614 } | 534 } |
| 615 | 535 |
| 616 } // namespace chromeos | 536 } // namespace chromeos |
| OLD | NEW |