| 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/policy_ui.h" | 5 #include "chrome/browser/ui/webui/policy_ui.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 210 |
| 211 void ExtractDomainFromUsername(base::DictionaryValue* dict) { | 211 void ExtractDomainFromUsername(base::DictionaryValue* dict) { |
| 212 std::string username; | 212 std::string username; |
| 213 dict->GetString("username", &username); | 213 dict->GetString("username", &username); |
| 214 if (!username.empty()) | 214 if (!username.empty()) |
| 215 dict->SetString("domain", gaia::ExtractDomainName(username)); | 215 dict->SetString("domain", gaia::ExtractDomainName(username)); |
| 216 } | 216 } |
| 217 | 217 |
| 218 // Utility function that returns a JSON serialization of the given |dict|. | 218 // Utility function that returns a JSON serialization of the given |dict|. |
| 219 scoped_ptr<base::StringValue> DictionaryToJSONString( | 219 scoped_ptr<base::StringValue> DictionaryToJSONString( |
| 220 const base::DictionaryValue* dict) { | 220 const base::DictionaryValue& dict) { |
| 221 std::string json_string; | 221 std::string json_string; |
| 222 base::JSONWriter::WriteWithOptions(dict, | 222 base::JSONWriter::WriteWithOptions(dict, |
| 223 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 223 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 224 &json_string); | 224 &json_string); |
| 225 return make_scoped_ptr(new base::StringValue(json_string)); | 225 return make_scoped_ptr(new base::StringValue(json_string)); |
| 226 } | 226 } |
| 227 | 227 |
| 228 // Returns a copy of |value| with some values converted to a representation that | 228 // Returns a copy of |value| with some values converted to a representation that |
| 229 // i18n_template.js will display in a nicer way. | 229 // i18n_template.js will display in a nicer way. |
| 230 scoped_ptr<base::Value> CopyAndConvert(const base::Value* value) { | 230 scoped_ptr<base::Value> CopyAndConvert(const base::Value* value) { |
| 231 const base::DictionaryValue* dict = NULL; | 231 const base::DictionaryValue* dict = NULL; |
| 232 if (value->GetAsDictionary(&dict)) | 232 if (value->GetAsDictionary(&dict)) |
| 233 return DictionaryToJSONString(dict); | 233 return DictionaryToJSONString(*dict); |
| 234 | 234 |
| 235 scoped_ptr<base::Value> copy(value->DeepCopy()); | 235 scoped_ptr<base::Value> copy(value->DeepCopy()); |
| 236 base::ListValue* list = NULL; | 236 base::ListValue* list = NULL; |
| 237 if (copy->GetAsList(&list)) { | 237 if (copy->GetAsList(&list)) { |
| 238 for (size_t i = 0; i < list->GetSize(); ++i) { | 238 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 239 if (list->GetDictionary(i, &dict)) | 239 if (list->GetDictionary(i, &dict)) |
| 240 list->Set(i, DictionaryToJSONString(dict).release()); | 240 list->Set(i, DictionaryToJSONString(*dict).release()); |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 return copy.Pass(); | 244 return copy.Pass(); |
| 245 } | 245 } |
| 246 | 246 |
| 247 } // namespace | 247 } // namespace |
| 248 | 248 |
| 249 // An interface for querying the status of cloud policy. | 249 // An interface for querying the status of cloud policy. |
| 250 class CloudPolicyStatusProvider { | 250 class CloudPolicyStatusProvider { |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 } | 836 } |
| 837 | 837 |
| 838 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 838 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 839 web_ui->AddMessageHandler(new PolicyUIHandler); | 839 web_ui->AddMessageHandler(new PolicyUIHandler); |
| 840 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | 840 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| 841 CreatePolicyUIHTMLSource()); | 841 CreatePolicyUIHTMLSource()); |
| 842 } | 842 } |
| 843 | 843 |
| 844 PolicyUI::~PolicyUI() { | 844 PolicyUI::~PolicyUI() { |
| 845 } | 845 } |
| OLD | NEW |