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/ui/webui/options2/chromeos/core_chromeos_options_handle
r.h" | 5 #include "chrome/browser/ui/webui/options2/chromeos/core_chromeos_options_handle
r.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 const char* kNonOwnerSettings[] = { | 37 const char* kNonOwnerSettings[] = { |
38 kSystemTimezone | 38 kSystemTimezone |
39 }; | 39 }; |
40 | 40 |
41 // Returns true if |pref| should be only available to the owner. | 41 // Returns true if |pref| should be only available to the owner. |
42 bool IsSettingOwnerOnly(const std::string& pref) { | 42 bool IsSettingOwnerOnly(const std::string& pref) { |
43 const char** end = kNonOwnerSettings + arraysize(kNonOwnerSettings); | 43 const char** end = kNonOwnerSettings + arraysize(kNonOwnerSettings); |
44 return std::find(kNonOwnerSettings, end, pref) == end; | 44 return std::find(kNonOwnerSettings, end, pref) == end; |
45 } | 45 } |
46 | 46 |
47 // Create a settings value with "managed" and "disabled" property. | |
48 // "managed" property is true if the setting is managed by administrator. | |
49 // "disabled" property is true if the UI for the setting should be disabled. | |
50 base::Value* CreateSettingsValue(base::Value *value, | |
51 bool managed, | |
52 bool disabled) { | |
53 DictionaryValue* dict = new DictionaryValue; | |
54 dict->Set("value", value); | |
55 dict->Set("managed", base::Value::CreateBooleanValue(managed)); | |
56 dict->Set("disabled", base::Value::CreateBooleanValue(disabled)); | |
57 return dict; | |
58 } | |
59 | |
60 // Returns true if |username| is the logged-in owner. | 47 // Returns true if |username| is the logged-in owner. |
61 bool IsLoggedInOwner(const std::string& username) { | 48 bool IsLoggedInOwner(const std::string& username) { |
62 UserManager* user_manager = UserManager::Get(); | 49 UserManager* user_manager = UserManager::Get(); |
63 return user_manager->IsCurrentUserOwner() && | 50 return user_manager->IsCurrentUserOwner() && |
64 user_manager->GetLoggedInUser().email() == username; | 51 user_manager->GetLoggedInUser().email() == username; |
65 } | 52 } |
66 | 53 |
67 // Creates a user info dictionary to be stored in the |ListValue| that is | 54 // Creates a user info dictionary to be stored in the |ListValue| that is |
68 // passed to Javascript for the |kAccountsPrefUsers| preference. | 55 // passed to Javascript for the |kAccountsPrefUsers| preference. |
69 base::DictionaryValue* CreateUserInfo(const std::string& username, | 56 base::DictionaryValue* CreateUserInfo(const std::string& username, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 pref_service->FindPreference(prefs::kProxy); | 137 pref_service->FindPreference(prefs::kProxy); |
151 return CreateValueForPref(pref, controlling_pref); | 138 return CreateValueForPref(pref, controlling_pref); |
152 } | 139 } |
153 return ::options2::CoreOptionsHandler::FetchPref(pref_name); | 140 return ::options2::CoreOptionsHandler::FetchPref(pref_name); |
154 } | 141 } |
155 | 142 |
156 const base::Value* pref_value = CrosSettings::Get()->GetPref(pref_name); | 143 const base::Value* pref_value = CrosSettings::Get()->GetPref(pref_name); |
157 if (!pref_value) | 144 if (!pref_value) |
158 return base::Value::CreateNullValue(); | 145 return base::Value::CreateNullValue(); |
159 | 146 |
160 // Lists don't get the standard pref decoration. | 147 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does. |
161 if (pref_value->GetType() == base::Value::TYPE_LIST) { | 148 DictionaryValue* dict = new DictionaryValue; |
162 if (pref_name == kAccountsPrefUsers) | 149 if (pref_name == kAccountsPrefUsers) |
163 return CreateUsersWhitelist(pref_value); | 150 dict->Set("value", CreateUsersWhitelist(pref_value)); |
164 // Return a copy because the UI will take ownership of this object. | 151 else |
165 return pref_value->DeepCopy(); | 152 dict->Set("value", pref_value->DeepCopy()); |
166 } | 153 if (g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) |
167 // All other prefs are decorated the same way. | 154 dict->SetString("controlledBy", "policy"); |
168 bool enabled = (UserManager::Get()->IsCurrentUserOwner() || | 155 dict->SetBoolean("disabled", |
169 !IsSettingOwnerOnly(pref_name)); | 156 IsSettingOwnerOnly(pref_name) && |
170 return CreateSettingsValue( | 157 !UserManager::Get()->IsCurrentUserOwner()); |
171 pref_value->DeepCopy(), // The copy will be owned by the dictionary. | 158 return dict; |
172 g_browser_process->browser_policy_connector()->IsEnterpriseManaged(), | |
173 !enabled); | |
174 } | 159 } |
175 | 160 |
176 void CoreChromeOSOptionsHandler::ObservePref(const std::string& pref_name) { | 161 void CoreChromeOSOptionsHandler::ObservePref(const std::string& pref_name) { |
177 if (proxy_cros_settings_parser::IsProxyPref(pref_name)) { | 162 if (proxy_cros_settings_parser::IsProxyPref(pref_name)) { |
178 // We observe those all the time. | 163 // We observe those all the time. |
179 return; | 164 return; |
180 } | 165 } |
181 if (!CrosSettings::IsCrosSettings(pref_name)) | 166 if (!CrosSettings::IsCrosSettings(pref_name)) |
182 return ::options2::CoreOptionsHandler::ObservePref(pref_name); | 167 return ::options2::CoreOptionsHandler::ObservePref(pref_name); |
183 CrosSettings::Get()->AddSettingsObserver(pref_name.c_str(), this); | 168 CrosSettings::Get()->AddSettingsObserver(pref_name.c_str(), this); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 proxy_cros_settings_parser::GetProxyPrefValue( | 245 proxy_cros_settings_parser::GetProxyPrefValue( |
261 Profile::FromWebUI(web_ui()), kProxySettings[i], &value); | 246 Profile::FromWebUI(web_ui()), kProxySettings[i], &value); |
262 DCHECK(value); | 247 DCHECK(value); |
263 scoped_ptr<base::Value> ptr(value); | 248 scoped_ptr<base::Value> ptr(value); |
264 DispatchPrefChangeNotification(kProxySettings[i], ptr.Pass()); | 249 DispatchPrefChangeNotification(kProxySettings[i], ptr.Pass()); |
265 } | 250 } |
266 } | 251 } |
267 | 252 |
268 } // namespace options2 | 253 } // namespace options2 |
269 } // namespace chromeos | 254 } // namespace chromeos |
OLD | NEW |