| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/extensions/info_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/info_private_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" |
| 11 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chrome/browser/app_mode/app_mode_utils.h" | 14 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
| 15 #include "chrome/browser/chromeos/login/startup_utils.h" | 17 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 16 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 17 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 18 #include "chrome/browser/chromeos/system/timezone_util.h" | 20 #include "chrome/browser/chromeos/system/timezone_util.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 21 #include "chromeos/network/device_state.h" | 23 #include "chromeos/network/device_state.h" |
| 22 #include "chromeos/network/network_handler.h" | 24 #include "chromeos/network/network_handler.h" |
| 23 #include "chromeos/network/network_state_handler.h" | 25 #include "chromeos/network/network_state_handler.h" |
| 24 #include "chromeos/settings/cros_settings_names.h" | 26 #include "chromeos/settings/cros_settings_names.h" |
| 25 #include "chromeos/system/statistics_provider.h" | 27 #include "chromeos/system/statistics_provider.h" |
| 28 #include "components/arc/arc_bridge_service.h" |
| 26 #include "components/metrics/metrics_service.h" | 29 #include "components/metrics/metrics_service.h" |
| 27 #include "components/prefs/pref_service.h" | 30 #include "components/prefs/pref_service.h" |
| 28 #include "components/user_manager/user_manager.h" | 31 #include "components/user_manager/user_manager.h" |
| 32 #include "extensions/browser/extensions_browser_client.h" |
| 29 #include "extensions/common/error_utils.h" | 33 #include "extensions/common/error_utils.h" |
| 30 #include "third_party/cros_system_api/dbus/service_constants.h" | 34 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 31 | 35 |
| 32 using chromeos::NetworkHandler; | 36 using chromeos::NetworkHandler; |
| 33 | 37 |
| 34 namespace extensions { | 38 namespace extensions { |
| 35 | 39 |
| 36 namespace { | 40 namespace { |
| 37 | 41 |
| 38 // Key which corresponds to the HWID setting. | 42 // Key which corresponds to the HWID setting. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 101 |
| 98 // Key which corresponds to the switch access A11Y property in JS. | 102 // Key which corresponds to the switch access A11Y property in JS. |
| 99 const char kPropertySwitchAccessEnabled[] = "a11ySwitchAccessEnabled"; | 103 const char kPropertySwitchAccessEnabled[] = "a11ySwitchAccessEnabled"; |
| 100 | 104 |
| 101 // Key which corresponds to the send-function-keys property in JS. | 105 // Key which corresponds to the send-function-keys property in JS. |
| 102 const char kPropertySendFunctionsKeys[] = "sendFunctionKeys"; | 106 const char kPropertySendFunctionsKeys[] = "sendFunctionKeys"; |
| 103 | 107 |
| 104 // Property not found error message. | 108 // Property not found error message. |
| 105 const char kPropertyNotFound[] = "Property '*' does not exist."; | 109 const char kPropertyNotFound[] = "Property '*' does not exist."; |
| 106 | 110 |
| 111 // Key which corresponds to the sessionType property in JS. |
| 112 const char kPropertySessionType[] = "sessionType"; |
| 113 |
| 114 // Key which corresponds to the "kiosk" value of the SessionType enum in JS. |
| 115 const char kSessionTypeKiosk[] = "kiosk"; |
| 116 |
| 117 // Key which corresponds to the "public session" value of the SessionType enum |
| 118 // in JS. |
| 119 const char kSessionTypePublicSession[] = "public session"; |
| 120 |
| 121 // Key which corresponds to the "normal" value of the SessionType enum in JS. |
| 122 const char kSessionTypeNormal[] = "normal"; |
| 123 |
| 124 // Key which corresponds to the playStoreStatus property in JS. |
| 125 const char kPropertyPlayStoreStatus[] = "playStoreStatus"; |
| 126 |
| 127 // Key which corresponds to the "not available" value of the PlayStoreStatus |
| 128 // enum in JS. |
| 129 const char kPlayStoreStatusNotAvailable[] = "not available"; |
| 130 |
| 131 // Key which corresponds to the "available" value of the PlayStoreStatus enum in |
| 132 // JS. |
| 133 const char kPlayStoreStatusAvailable[] = "available"; |
| 134 |
| 135 // Key which corresponds to the "enabled" value of the PlayStoreStatus enum in |
| 136 // JS. |
| 137 const char kPlayStoreStatusEnabled[] = "enabled"; |
| 138 |
| 107 const struct { | 139 const struct { |
| 108 const char* api_name; | 140 const char* api_name; |
| 109 const char* preference_name; | 141 const char* preference_name; |
| 110 } kPreferencesMap[] = { | 142 } kPreferencesMap[] = { |
| 111 {kPropertyLargeCursorEnabled, prefs::kAccessibilityLargeCursorEnabled}, | 143 {kPropertyLargeCursorEnabled, prefs::kAccessibilityLargeCursorEnabled}, |
| 112 {kPropertyStickyKeysEnabled, prefs::kAccessibilityStickyKeysEnabled}, | 144 {kPropertyStickyKeysEnabled, prefs::kAccessibilityStickyKeysEnabled}, |
| 113 {kPropertySpokenFeedbackEnabled, | 145 {kPropertySpokenFeedbackEnabled, |
| 114 prefs::kAccessibilitySpokenFeedbackEnabled}, | 146 prefs::kAccessibilitySpokenFeedbackEnabled}, |
| 115 {kPropertyHighContrastEnabled, prefs::kAccessibilityHighContrastEnabled}, | 147 {kPropertyHighContrastEnabled, prefs::kAccessibilityHighContrastEnabled}, |
| 116 {kPropertyScreenMagnifierEnabled, | 148 {kPropertyScreenMagnifierEnabled, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 211 } |
| 180 | 212 |
| 181 base::Value* ChromeosInfoPrivateGetFunction::GetValue( | 213 base::Value* ChromeosInfoPrivateGetFunction::GetValue( |
| 182 const std::string& property_name) { | 214 const std::string& property_name) { |
| 183 if (property_name == kPropertyHWID) { | 215 if (property_name == kPropertyHWID) { |
| 184 std::string hwid; | 216 std::string hwid; |
| 185 chromeos::system::StatisticsProvider* provider = | 217 chromeos::system::StatisticsProvider* provider = |
| 186 chromeos::system::StatisticsProvider::GetInstance(); | 218 chromeos::system::StatisticsProvider::GetInstance(); |
| 187 provider->GetMachineStatistic(chromeos::system::kHardwareClassKey, &hwid); | 219 provider->GetMachineStatistic(chromeos::system::kHardwareClassKey, &hwid); |
| 188 return new base::StringValue(hwid); | 220 return new base::StringValue(hwid); |
| 189 } else if (property_name == kPropertyCustomizationID) { | 221 } |
| 222 |
| 223 if (property_name == kPropertyCustomizationID) { |
| 190 std::string customization_id; | 224 std::string customization_id; |
| 191 chromeos::system::StatisticsProvider* provider = | 225 chromeos::system::StatisticsProvider* provider = |
| 192 chromeos::system::StatisticsProvider::GetInstance(); | 226 chromeos::system::StatisticsProvider::GetInstance(); |
| 193 provider->GetMachineStatistic(chromeos::system::kCustomizationIdKey, | 227 provider->GetMachineStatistic(chromeos::system::kCustomizationIdKey, |
| 194 &customization_id); | 228 &customization_id); |
| 195 return new base::StringValue(customization_id); | 229 return new base::StringValue(customization_id); |
| 196 } else if (property_name == kPropertyHomeProvider) { | 230 } |
| 231 |
| 232 if (property_name == kPropertyHomeProvider) { |
| 197 const chromeos::DeviceState* cellular_device = | 233 const chromeos::DeviceState* cellular_device = |
| 198 NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType( | 234 NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType( |
| 199 chromeos::NetworkTypePattern::Cellular()); | 235 chromeos::NetworkTypePattern::Cellular()); |
| 200 std::string home_provider_id; | 236 std::string home_provider_id; |
| 201 if (cellular_device) | 237 if (cellular_device) |
| 202 home_provider_id = cellular_device->home_provider_id(); | 238 home_provider_id = cellular_device->home_provider_id(); |
| 203 return new base::StringValue(home_provider_id); | 239 return new base::StringValue(home_provider_id); |
| 204 } else if (property_name == kPropertyInitialLocale) { | 240 } |
| 241 |
| 242 if (property_name == kPropertyInitialLocale) { |
| 205 return new base::StringValue( | 243 return new base::StringValue( |
| 206 chromeos::StartupUtils::GetInitialLocale()); | 244 chromeos::StartupUtils::GetInitialLocale()); |
| 207 } else if (property_name == kPropertyBoard) { | 245 } |
| 246 |
| 247 if (property_name == kPropertyBoard) { |
| 208 return new base::StringValue(base::SysInfo::GetLsbReleaseBoard()); | 248 return new base::StringValue(base::SysInfo::GetLsbReleaseBoard()); |
| 209 } else if (property_name == kPropertyOwner) { | 249 } |
| 250 |
| 251 if (property_name == kPropertyOwner) { |
| 210 return new base::FundamentalValue( | 252 return new base::FundamentalValue( |
| 211 user_manager::UserManager::Get()->IsCurrentUserOwner()); | 253 user_manager::UserManager::Get()->IsCurrentUserOwner()); |
| 212 } else if (property_name == kPropertyClientId) { | 254 } |
| 255 |
| 256 if (property_name == kPropertySessionType) { |
| 257 if (ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode()) |
| 258 return new base::StringValue(kSessionTypeKiosk); |
| 259 if (ExtensionsBrowserClient::Get()->IsLoggedInAsPublicAccount()) |
| 260 return new base::StringValue(kSessionTypePublicSession); |
| 261 return new base::StringValue(kSessionTypeNormal); |
| 262 } |
| 263 |
| 264 if (property_name == kPropertyPlayStoreStatus) { |
| 265 if (arc::ArcAuthService::IsAllowedForProfile( |
| 266 Profile::FromBrowserContext(context_))) { |
| 267 return new base::StringValue(kPlayStoreStatusEnabled); |
| 268 } |
| 269 if (arc::ArcBridgeService::GetAvailable( |
| 270 base::CommandLine::ForCurrentProcess())) { |
| 271 return new base::StringValue(kPlayStoreStatusAvailable); |
| 272 } |
| 273 return new base::StringValue(kPlayStoreStatusNotAvailable); |
| 274 } |
| 275 |
| 276 if (property_name == kPropertyClientId) { |
| 213 return new base::StringValue(GetClientId()); | 277 return new base::StringValue(GetClientId()); |
| 214 } else if (property_name == kPropertyTimezone) { | 278 } |
| 279 |
| 280 if (property_name == kPropertyTimezone) { |
| 215 return chromeos::CrosSettings::Get()->GetPref( | 281 return chromeos::CrosSettings::Get()->GetPref( |
| 216 chromeos::kSystemTimezone)->DeepCopy(); | 282 chromeos::kSystemTimezone)->DeepCopy(); |
| 217 } else if (property_name == kPropertySupportedTimezones) { | 283 } |
| 284 |
| 285 if (property_name == kPropertySupportedTimezones) { |
| 218 std::unique_ptr<base::ListValue> values = | 286 std::unique_ptr<base::ListValue> values = |
| 219 chromeos::system::GetTimezoneList(); | 287 chromeos::system::GetTimezoneList(); |
| 220 return values.release(); | 288 return values.release(); |
| 221 } else { | 289 } |
| 222 const char* pref_name = | 290 |
| 223 GetBoolPrefNameForApiProperty(property_name.c_str()); | 291 const char* pref_name = GetBoolPrefNameForApiProperty(property_name.c_str()); |
| 224 if (pref_name) { | 292 if (pref_name) { |
| 225 return new base::FundamentalValue( | 293 return new base::FundamentalValue( |
| 226 Profile::FromBrowserContext(context_)->GetPrefs()->GetBoolean( | 294 Profile::FromBrowserContext(context_)->GetPrefs()->GetBoolean( |
| 227 pref_name)); | 295 pref_name)); |
| 228 } | |
| 229 } | 296 } |
| 230 | 297 |
| 231 DLOG(ERROR) << "Unknown property request: " << property_name; | 298 DLOG(ERROR) << "Unknown property request: " << property_name; |
| 232 return NULL; | 299 return NULL; |
| 233 } | 300 } |
| 234 | 301 |
| 235 ChromeosInfoPrivateSetFunction::ChromeosInfoPrivateSetFunction() { | 302 ChromeosInfoPrivateSetFunction::ChromeosInfoPrivateSetFunction() { |
| 236 } | 303 } |
| 237 | 304 |
| 238 ChromeosInfoPrivateSetFunction::~ChromeosInfoPrivateSetFunction() { | 305 ChromeosInfoPrivateSetFunction::~ChromeosInfoPrivateSetFunction() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 256 param_value); | 323 param_value); |
| 257 } else { | 324 } else { |
| 258 return RespondNow(Error(kPropertyNotFound, param_name)); | 325 return RespondNow(Error(kPropertyNotFound, param_name)); |
| 259 } | 326 } |
| 260 } | 327 } |
| 261 | 328 |
| 262 return RespondNow(NoArguments()); | 329 return RespondNow(NoArguments()); |
| 263 } | 330 } |
| 264 | 331 |
| 265 } // namespace extensions | 332 } // namespace extensions |
| OLD | NEW |