Chromium Code Reviews| 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/session/session_state_delegate.h" | |
| 8 #include "ash/common/wm_shell.h" | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/browser_process_platform_part.h" | 13 #include "chrome/browser/browser_process_platform_part.h" |
| 12 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" | 14 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" |
| 13 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 15 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 14 #include "chrome/browser/chromeos/system/system_clock.h" | 16 #include "chrome/browser/chromeos/system/system_clock.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/ui/ash/ash_util.h" | 18 #include "chrome/browser/ui/ash/ash_util.h" |
| 17 #include "chrome/browser/ui/chrome_pages.h" | 19 #include "chrome/browser/ui/chrome_pages.h" |
| 18 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 20 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 19 #include "chrome/browser/ui/singleton_tabs.h" | 21 #include "chrome/browser/ui/singleton_tabs.h" |
| 20 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| 22 #include "chromeos/login/login_state.h" | 24 #include "chromeos/login/login_state.h" |
| 23 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
| 24 #include "content/public/common/mojo_shell_connection.h" | 26 #include "content/public/common/mojo_shell_connection.h" |
| 27 #include "net/base/escape.h" | |
| 25 #include "services/shell/public/cpp/connector.h" | 28 #include "services/shell/public/cpp/connector.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 27 | 30 |
| 28 using chromeos::LoginState; | 31 using chromeos::LoginState; |
| 29 | 32 |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 const char kPaletteSettingsSubPageName[] = "stylus-overlay"; | 35 const char kPaletteSettingsSubPageName[] = "stylus-overlay"; |
| 33 | 36 |
| 34 SystemTrayClient* g_instance = nullptr; | 37 SystemTrayClient* g_instance = nullptr; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 59 g_instance = nullptr; | 62 g_instance = nullptr; |
| 60 | 63 |
| 61 g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this); | 64 g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this); |
| 62 } | 65 } |
| 63 | 66 |
| 64 // static | 67 // static |
| 65 SystemTrayClient* SystemTrayClient::Get() { | 68 SystemTrayClient* SystemTrayClient::Get() { |
| 66 return g_instance; | 69 return g_instance; |
| 67 } | 70 } |
| 68 | 71 |
| 69 void SystemTrayClient::ConnectToSystemTray() { | |
| 70 if (system_tray_.is_bound()) | |
| 71 return; | |
| 72 | |
| 73 shell::Connector* connector = | |
| 74 content::MojoShellConnection::GetForProcess()->GetConnector(); | |
| 75 // Under mash the SystemTray interface is in the ash process. In classic ash | |
| 76 // we provide it to ourself. | |
| 77 if (chrome::IsRunningInMash()) | |
| 78 connector->ConnectToInterface("mojo:ash", &system_tray_); | |
| 79 else | |
| 80 connector->ConnectToInterface("exe:content_browser", &system_tray_); | |
| 81 | |
| 82 // Tolerate ash crashing and coming back up. | |
| 83 system_tray_.set_connection_error_handler(base::Bind( | |
| 84 &SystemTrayClient::OnClientConnectionError, base::Unretained(this))); | |
| 85 } | |
| 86 | |
| 87 void SystemTrayClient::OnClientConnectionError() { | |
| 88 system_tray_.reset(); | |
| 89 } | |
| 90 | |
| 91 //////////////////////////////////////////////////////////////////////////////// | 72 //////////////////////////////////////////////////////////////////////////////// |
| 92 // ash::mojom::SystemTrayClient: | 73 // ash::mojom::SystemTrayClient: |
| 93 | 74 |
| 94 void SystemTrayClient::ShowSettings() { | 75 void SystemTrayClient::ShowSettings() { |
| 95 ShowSettingsSubPageForActiveUser(std::string()); | 76 ShowSettingsSubPageForActiveUser(std::string()); |
| 96 } | 77 } |
| 97 | 78 |
| 98 void SystemTrayClient::ShowDateSettings() { | 79 void SystemTrayClient::ShowDateSettings() { |
| 99 content::RecordAction(base::UserMetricsAction("ShowDateOptions")); | 80 content::RecordAction(base::UserMetricsAction("ShowDateOptions")); |
| 100 std::string sub_page = | 81 std::string sub_page = |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 content::RecordAction(base::UserMetricsAction("ShowPaletteOptions")); | 137 content::RecordAction(base::UserMetricsAction("ShowPaletteOptions")); |
| 157 ShowSettingsSubPageForActiveUser(kPaletteSettingsSubPageName); | 138 ShowSettingsSubPageForActiveUser(kPaletteSettingsSubPageName); |
| 158 } | 139 } |
| 159 | 140 |
| 160 void SystemTrayClient::ShowPublicAccountInfo() { | 141 void SystemTrayClient::ShowPublicAccountInfo() { |
| 161 chrome::ScopedTabbedBrowserDisplayer displayer( | 142 chrome::ScopedTabbedBrowserDisplayer displayer( |
| 162 ProfileManager::GetActiveUserProfile()); | 143 ProfileManager::GetActiveUserProfile()); |
| 163 chrome::ShowPolicy(displayer.browser()); | 144 chrome::ShowPolicy(displayer.browser()); |
| 164 } | 145 } |
| 165 | 146 |
| 147 void SystemTrayClient::ShowNetworkSettings(const std::string& network_id) { | |
| 148 if (!LoginState::Get()->IsUserLoggedIn()) | |
| 149 return; | |
| 150 | |
| 151 // TODO(mash): Need replacement for SessionStateDelegate. crbug.com/648964 | |
|
msw
2016/10/05 22:56:36
bummer, but yeah...
| |
| 152 if (!chrome::IsRunningInMash() && | |
| 153 ash::WmShell::Get() | |
| 154 ->GetSessionStateDelegate() | |
| 155 ->IsInSecondaryLoginScreen()) | |
| 156 return; | |
| 157 | |
| 158 std::string page = chrome::kInternetOptionsSubPage; | |
| 159 if (!network_id.empty()) | |
| 160 page += "?guid=" + net::EscapeUrlEncodedData(network_id, true); | |
| 161 content::RecordAction(base::UserMetricsAction("OpenInternetOptionsDialog")); | |
| 162 ShowSettingsSubPageForActiveUser(page); | |
| 163 } | |
| 164 | |
| 166 void SystemTrayClient::ShowProxySettings() { | 165 void SystemTrayClient::ShowProxySettings() { |
| 167 LoginState* login_state = LoginState::Get(); | 166 LoginState* login_state = LoginState::Get(); |
| 168 // User is not logged in. | 167 // User is not logged in. |
| 169 CHECK(!login_state->IsUserLoggedIn() || | 168 CHECK(!login_state->IsUserLoggedIn() || |
| 170 login_state->GetLoggedInUserType() == LoginState::LOGGED_IN_USER_NONE); | 169 login_state->GetLoggedInUserType() == LoginState::LOGGED_IN_USER_NONE); |
| 171 chromeos::LoginDisplayHost::default_host()->OpenProxySettings(); | 170 chromeos::LoginDisplayHost::default_host()->OpenProxySettings(); |
| 172 } | 171 } |
| 173 | 172 |
| 174 //////////////////////////////////////////////////////////////////////////////// | 173 //////////////////////////////////////////////////////////////////////////////// |
| 175 // chromeos::system::SystemClockObserver: | 174 // chromeos::system::SystemClockObserver: |
| 176 | 175 |
| 177 void SystemTrayClient::OnSystemClockChanged( | 176 void SystemTrayClient::OnSystemClockChanged( |
| 178 chromeos::system::SystemClock* clock) { | 177 chromeos::system::SystemClock* clock) { |
| 179 ConnectToSystemTray(); | 178 ConnectToSystemTray(); |
| 180 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); | 179 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); |
| 181 } | 180 } |
| 181 | |
| 182 void SystemTrayClient::ConnectToSystemTray() { | |
| 183 if (system_tray_.is_bound()) | |
| 184 return; | |
| 185 | |
| 186 shell::Connector* connector = | |
| 187 content::MojoShellConnection::GetForProcess()->GetConnector(); | |
| 188 // Under mash the SystemTray interface is in the ash process. In classic ash | |
| 189 // we provide it to ourself. | |
| 190 if (chrome::IsRunningInMash()) | |
| 191 connector->ConnectToInterface("mojo:ash", &system_tray_); | |
| 192 else | |
| 193 connector->ConnectToInterface("exe:content_browser", &system_tray_); | |
| 194 | |
| 195 // Tolerate ash crashing and coming back up. | |
| 196 system_tray_.set_connection_error_handler(base::Bind( | |
| 197 &SystemTrayClient::OnClientConnectionError, base::Unretained(this))); | |
| 198 } | |
| 199 | |
| 200 void SystemTrayClient::OnClientConnectionError() { | |
| 201 system_tray_.reset(); | |
| 202 } | |
| OLD | NEW |