1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/extensions/info_private_api.h"
#include <stddef.h>
#include "base/sys_info.h"
#include "base/values.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/system/timezone_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "chromeos/network/device_state.h"
#include "chromeos/network/network_handler.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/settings/cros_settings_names.h"
#include "chromeos/system/statistics_provider.h"
#include "components/metrics/metrics_service.h"
#include "components/prefs/pref_service.h"
#include "components/user_manager/user_manager.h"
#include "extensions/common/error_utils.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
using chromeos::NetworkHandler;
namespace extensions {
namespace {
// Key which corresponds to the HWID setting.
const char kPropertyHWID[] = "hwid";
// Key which corresponds to the customization ID setting.
const char kPropertyCustomizationID[] = "customizationId";
// Key which corresponds to the home provider property.
const char kPropertyHomeProvider[] = "homeProvider";
// Key which corresponds to the initial_locale property.
const char kPropertyInitialLocale[] = "initialLocale";
// Key which corresponds to the board property in JS.
const char kPropertyBoard[] = "board";
// Key which corresponds to the isOwner property in JS.
const char kPropertyOwner[] = "isOwner";
// Key which corresponds to the clientId property in JS.
const char kPropertyClientId[] = "clientId";
// Key which corresponds to the timezone property in JS.
const char kPropertyTimezone[] = "timezone";
// Key which corresponds to the timezone property in JS.
const char kPropertySupportedTimezones[] = "supportedTimezones";
// Key which corresponds to the large cursor A11Y property in JS.
const char kPropertyLargeCursorEnabled[] = "a11yLargeCursorEnabled";
// Key which corresponds to the sticky keys A11Y property in JS.
const char kPropertyStickyKeysEnabled[] = "a11yStickyKeysEnabled";
// Key which corresponds to the spoken feedback A11Y property in JS.
const char kPropertySpokenFeedbackEnabled[] = "a11ySpokenFeedbackEnabled";
// Key which corresponds to the high contrast mode A11Y property in JS.
const char kPropertyHighContrastEnabled[] = "a11yHighContrastEnabled";
// Key which corresponds to the screen magnifier A11Y property in JS.
const char kPropertyScreenMagnifierEnabled[] = "a11yScreenMagnifierEnabled";
// Key which corresponds to the auto click A11Y property in JS.
const char kPropertyAutoclickEnabled[] = "a11yAutoClickEnabled";
// Key which corresponds to the auto click A11Y property in JS.
const char kPropertyVirtualKeyboardEnabled[] = "a11yVirtualKeyboardEnabled";
// Key which corresponds to the send-function-keys property in JS.
const char kPropertySendFunctionsKeys[] = "sendFunctionKeys";
// Property not found error message.
const char kPropertyNotFound[] = "Property '*' does not exist.";
const struct {
const char* api_name;
const char* preference_name;
} kPreferencesMap[] = {
{kPropertyLargeCursorEnabled, prefs::kAccessibilityLargeCursorEnabled},
{kPropertyStickyKeysEnabled, prefs::kAccessibilityStickyKeysEnabled},
{kPropertySpokenFeedbackEnabled,
prefs::kAccessibilitySpokenFeedbackEnabled},
{kPropertyHighContrastEnabled, prefs::kAccessibilityHighContrastEnabled},
{kPropertyScreenMagnifierEnabled,
prefs::kAccessibilityScreenMagnifierEnabled},
{kPropertyAutoclickEnabled, prefs::kAccessibilityAutoclickEnabled},
{kPropertyVirtualKeyboardEnabled,
prefs::kAccessibilityVirtualKeyboardEnabled},
{kPropertySendFunctionsKeys, prefs::kLanguageSendFunctionKeys}};
const char* GetBoolPrefNameForApiProperty(const char* api_name) {
for (size_t i = 0;
i < (sizeof(kPreferencesMap)/sizeof(*kPreferencesMap));
i++) {
if (strcmp(kPreferencesMap[i].api_name, api_name) == 0)
return kPreferencesMap[i].preference_name;
}
return NULL;
}
bool IsEnterpriseKiosk() {
if (!chrome::IsRunningInForcedAppMode())
return false;
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
return connector->IsEnterpriseManaged();
}
std::string GetClientId() {
return IsEnterpriseKiosk()
? g_browser_process->metrics_service()->GetClientId()
: std::string();
}
} // namespace
ChromeosInfoPrivateGetFunction::ChromeosInfoPrivateGetFunction() {
}
ChromeosInfoPrivateGetFunction::~ChromeosInfoPrivateGetFunction() {
}
bool ChromeosInfoPrivateGetFunction::RunAsync() {
base::ListValue* list = NULL;
EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &list));
scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
for (size_t i = 0; i < list->GetSize(); ++i) {
std::string property_name;
EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name));
base::Value* value = GetValue(property_name);
if (value)
result->Set(property_name, value);
}
SetResult(result.release());
SendResponse(true);
return true;
}
base::Value* ChromeosInfoPrivateGetFunction::GetValue(
const std::string& property_name) {
if (property_name == kPropertyHWID) {
std::string hwid;
chromeos::system::StatisticsProvider* provider =
chromeos::system::StatisticsProvider::GetInstance();
provider->GetMachineStatistic(chromeos::system::kHardwareClassKey, &hwid);
return new base::StringValue(hwid);
} else if (property_name == kPropertyCustomizationID) {
std::string customization_id;
chromeos::system::StatisticsProvider* provider =
chromeos::system::StatisticsProvider::GetInstance();
provider->GetMachineStatistic(chromeos::system::kCustomizationIdKey,
&customization_id);
return new base::StringValue(customization_id);
} else if (property_name == kPropertyHomeProvider) {
const chromeos::DeviceState* cellular_device =
NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType(
chromeos::NetworkTypePattern::Cellular());
std::string home_provider_id;
if (cellular_device)
home_provider_id = cellular_device->home_provider_id();
return new base::StringValue(home_provider_id);
} else if (property_name == kPropertyInitialLocale) {
return new base::StringValue(
chromeos::StartupUtils::GetInitialLocale());
} else if (property_name == kPropertyBoard) {
return new base::StringValue(base::SysInfo::GetLsbReleaseBoard());
} else if (property_name == kPropertyOwner) {
return new base::FundamentalValue(
user_manager::UserManager::Get()->IsCurrentUserOwner());
} else if (property_name == kPropertyClientId) {
return new base::StringValue(GetClientId());
} else if (property_name == kPropertyTimezone) {
return chromeos::CrosSettings::Get()->GetPref(
chromeos::kSystemTimezone)->DeepCopy();
} else if (property_name == kPropertySupportedTimezones) {
scoped_ptr<base::ListValue> values = chromeos::system::GetTimezoneList();
return values.release();
} else {
const char* pref_name =
GetBoolPrefNameForApiProperty(property_name.c_str());
if (pref_name) {
return new base::FundamentalValue(
Profile::FromBrowserContext(context_)->GetPrefs()->GetBoolean(
pref_name));
}
}
DLOG(ERROR) << "Unknown property request: " << property_name;
return NULL;
}
ChromeosInfoPrivateSetFunction::ChromeosInfoPrivateSetFunction() {
}
ChromeosInfoPrivateSetFunction::~ChromeosInfoPrivateSetFunction() {
}
bool ChromeosInfoPrivateSetFunction::RunSync() {
std::string param_name;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, ¶m_name));
if (param_name == kPropertyTimezone) {
std::string param_value;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, ¶m_value));
chromeos::CrosSettings::Get()->Set(chromeos::kSystemTimezone,
base::StringValue(param_value));
} else {
const char* pref_name = GetBoolPrefNameForApiProperty(param_name.c_str());
if (pref_name) {
bool param_value;
EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, ¶m_value));
Profile::FromBrowserContext(context_)->GetPrefs()->SetBoolean(
pref_name,
param_value);
} else {
error_ = ErrorUtils::FormatErrorMessage(kPropertyNotFound, param_name);
return false;
}
}
return true;
}
} // namespace extensions
|