Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / info_private_api.cc
blob14ed5ecc267915419ab56a23747288303dade92e
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/extensions/info_private_api.h"
7 #include "base/sys_info.h"
8 #include "base/values.h"
9 #include "chrome/browser/chromeos/login/startup_utils.h"
10 #include "chrome/browser/chromeos/login/user_manager.h"
11 #include "chrome/browser/chromeos/settings/cros_settings.h"
12 #include "chrome/browser/chromeos/system/timezone_util.h"
13 #include "chromeos/network/device_state.h"
14 #include "chromeos/network/network_handler.h"
15 #include "chromeos/network/network_state_handler.h"
16 #include "chromeos/network/shill_property_util.h"
17 #include "chromeos/settings/cros_settings_names.h"
18 #include "chromeos/system/statistics_provider.h"
19 #include "extensions/common/error_utils.h"
20 #include "third_party/cros_system_api/dbus/service_constants.h"
22 using chromeos::NetworkHandler;
24 namespace extensions {
26 namespace {
28 // Key which corresponds to the HWID setting.
29 const char kPropertyHWID[] = "hwid";
31 // Key which corresponds to the home provider property.
32 const char kPropertyHomeProvider[] = "homeProvider";
34 // Key which corresponds to the initial_locale property.
35 const char kPropertyInitialLocale[] = "initialLocale";
37 // Key which corresponds to the board property in JS.
38 const char kPropertyBoard[] = "board";
40 // Key which corresponds to the board property in JS.
41 const char kPropertyOwner[] = "isOwner";
43 // Key which corresponds to the timezone property in JS.
44 const char kPropertyTimezone[] = "timezone";
46 // Key which corresponds to the timezone property in JS.
47 const char kPropertySupportedTimezones[] = "supportedTimezones";
49 // Property not found error message.
50 const char kPropertyNotFound[] = "Property '*' does not exist.";
52 } // namespace
54 ChromeosInfoPrivateGetFunction::ChromeosInfoPrivateGetFunction() {
57 ChromeosInfoPrivateGetFunction::~ChromeosInfoPrivateGetFunction() {
60 bool ChromeosInfoPrivateGetFunction::RunImpl() {
61 base::ListValue* list = NULL;
62 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &list));
63 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
64 for (size_t i = 0; i < list->GetSize(); ++i) {
65 std::string property_name;
66 EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name));
67 base::Value* value = GetValue(property_name);
68 if (value)
69 result->Set(property_name, value);
71 SetResult(result.release());
72 SendResponse(true);
73 return true;
76 base::Value* ChromeosInfoPrivateGetFunction::GetValue(
77 const std::string& property_name) {
78 if (property_name == kPropertyHWID) {
79 std::string hwid;
80 chromeos::system::StatisticsProvider* provider =
81 chromeos::system::StatisticsProvider::GetInstance();
82 provider->GetMachineStatistic(chromeos::system::kHardwareClassKey, &hwid);
83 return new base::StringValue(hwid);
84 } else if (property_name == kPropertyHomeProvider) {
85 const chromeos::DeviceState* cellular_device =
86 NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType(
87 chromeos::NetworkTypePattern::Cellular());
88 std::string home_provider_id;
89 if (cellular_device)
90 home_provider_id = cellular_device->home_provider_id();
91 return new base::StringValue(home_provider_id);
92 } else if (property_name == kPropertyInitialLocale) {
93 return new base::StringValue(
94 chromeos::StartupUtils::GetInitialLocale());
95 } else if (property_name == kPropertyBoard) {
96 return new base::StringValue(base::SysInfo::GetLsbReleaseBoard());
97 } else if (property_name == kPropertyOwner) {
98 return base::Value::CreateBooleanValue(
99 chromeos::UserManager::Get()->IsCurrentUserOwner());
100 } else if (property_name == kPropertyTimezone) {
101 return chromeos::CrosSettings::Get()->GetPref(
102 chromeos::kSystemTimezone)->DeepCopy();
103 } else if (property_name == kPropertySupportedTimezones) {
104 scoped_ptr<base::ListValue> values = chromeos::system::GetTimezoneList();
105 return values.release();
108 DLOG(ERROR) << "Unknown property request: " << property_name;
109 return NULL;
113 ChromeosInfoPrivateSetFunction::ChromeosInfoPrivateSetFunction() {
116 ChromeosInfoPrivateSetFunction::~ChromeosInfoPrivateSetFunction() {
119 bool ChromeosInfoPrivateSetFunction::RunImpl() {
120 std::string param_name;
121 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &param_name));
122 if (param_name == kPropertyTimezone) {
123 std::string param_value;
124 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &param_value));
125 chromeos::CrosSettings::Get()->Set(chromeos::kSystemTimezone,
126 base::StringValue(param_value));
127 } else {
128 error_ = ErrorUtils::FormatErrorMessage(kPropertyNotFound, param_name);
129 return false;
132 return true;
135 } // namespace extensions