| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/local_state/local_state_ui.h" | 5 #include "chrome/browser/ui/webui/local_state/local_state_ui.h" |
| 6 | 6 |
| 7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 "variations", "user_experience_metrics", "uninstall_metrics"}; | 67 "variations", "user_experience_metrics", "uninstall_metrics"}; |
| 68 internal::FilterPrefs(whitelisted_prefixes, local_state_values.get()); | 68 internal::FilterPrefs(whitelisted_prefixes, local_state_values.get()); |
| 69 } | 69 } |
| 70 std::string json; | 70 std::string json; |
| 71 JSONStringValueSerializer serializer(&json); | 71 JSONStringValueSerializer serializer(&json); |
| 72 serializer.set_pretty_print(true); | 72 serializer.set_pretty_print(true); |
| 73 bool result = serializer.Serialize(*local_state_values); | 73 bool result = serializer.Serialize(*local_state_values); |
| 74 if (!result) | 74 if (!result) |
| 75 json = "Error loading Local State file."; | 75 json = "Error loading Local State file."; |
| 76 | 76 |
| 77 web_ui()->CallJavascriptFunction("localState.setLocalState", | 77 web_ui()->CallJavascriptFunctionUnsafe("localState.setLocalState", |
| 78 base::StringValue(json)); | 78 base::StringValue(json)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Returns true if |pref_name| starts with one of the |valid_prefixes|. | 81 // Returns true if |pref_name| starts with one of the |valid_prefixes|. |
| 82 bool HasValidPrefix(const std::string& pref_name, | 82 bool HasValidPrefix(const std::string& pref_name, |
| 83 const std::vector<std::string> valid_prefixes) { | 83 const std::vector<std::string> valid_prefixes) { |
| 84 for (const std::string& prefix : valid_prefixes) { | 84 for (const std::string& prefix : valid_prefixes) { |
| 85 if (base::StartsWith(pref_name, prefix, base::CompareCase::SENSITIVE)) | 85 if (base::StartsWith(pref_name, prefix, base::CompareCase::SENSITIVE)) |
| 86 return true; | 86 return true; |
| 87 } | 87 } |
| 88 return false; | 88 return false; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 116 html_source->SetDefaultResource(IDR_LOCAL_STATE_HTML); | 116 html_source->SetDefaultResource(IDR_LOCAL_STATE_HTML); |
| 117 html_source->AddResourcePath("local_state.js", IDR_LOCAL_STATE_JS); | 117 html_source->AddResourcePath("local_state.js", IDR_LOCAL_STATE_JS); |
| 118 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); | 118 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| 119 | 119 |
| 120 // AddMessageHandler takes ownership of LocalStateUIHandler. | 120 // AddMessageHandler takes ownership of LocalStateUIHandler. |
| 121 web_ui->AddMessageHandler(new LocalStateUIHandler); | 121 web_ui->AddMessageHandler(new LocalStateUIHandler); |
| 122 } | 122 } |
| 123 | 123 |
| 124 LocalStateUI::~LocalStateUI() { | 124 LocalStateUI::~LocalStateUI() { |
| 125 } | 125 } |
| OLD | NEW |