| 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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 internal::FilterPrefs(whitelisted_prefixes, local_state_values.get()); | 69 internal::FilterPrefs(whitelisted_prefixes, local_state_values.get()); |
| 70 } | 70 } |
| 71 std::string json; | 71 std::string json; |
| 72 JSONStringValueSerializer serializer(&json); | 72 JSONStringValueSerializer serializer(&json); |
| 73 serializer.set_pretty_print(true); | 73 serializer.set_pretty_print(true); |
| 74 bool result = serializer.Serialize(*local_state_values); | 74 bool result = serializer.Serialize(*local_state_values); |
| 75 if (!result) | 75 if (!result) |
| 76 json = "Error loading Local State file."; | 76 json = "Error loading Local State file."; |
| 77 | 77 |
| 78 web_ui()->CallJavascriptFunctionUnsafe("localState.setLocalState", | 78 web_ui()->CallJavascriptFunctionUnsafe("localState.setLocalState", |
| 79 base::StringValue(json)); | 79 base::Value(json)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Returns true if |pref_name| starts with one of the |valid_prefixes|. | 82 // Returns true if |pref_name| starts with one of the |valid_prefixes|. |
| 83 bool HasValidPrefix(const std::string& pref_name, | 83 bool HasValidPrefix(const std::string& pref_name, |
| 84 const std::vector<std::string> valid_prefixes) { | 84 const std::vector<std::string> valid_prefixes) { |
| 85 for (const std::string& prefix : valid_prefixes) { | 85 for (const std::string& prefix : valid_prefixes) { |
| 86 if (base::StartsWith(pref_name, prefix, base::CompareCase::SENSITIVE)) | 86 if (base::StartsWith(pref_name, prefix, base::CompareCase::SENSITIVE)) |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 return false; | 89 return false; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 115 content::WebUIDataSource* html_source = | 115 content::WebUIDataSource* html_source = |
| 116 content::WebUIDataSource::Create(chrome::kChromeUILocalStateHost); | 116 content::WebUIDataSource::Create(chrome::kChromeUILocalStateHost); |
| 117 html_source->SetDefaultResource(IDR_LOCAL_STATE_HTML); | 117 html_source->SetDefaultResource(IDR_LOCAL_STATE_HTML); |
| 118 html_source->AddResourcePath("local_state.js", IDR_LOCAL_STATE_JS); | 118 html_source->AddResourcePath("local_state.js", IDR_LOCAL_STATE_JS); |
| 119 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); | 119 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| 120 web_ui->AddMessageHandler(base::MakeUnique<LocalStateUIHandler>()); | 120 web_ui->AddMessageHandler(base::MakeUnique<LocalStateUIHandler>()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 LocalStateUI::~LocalStateUI() { | 123 LocalStateUI::~LocalStateUI() { |
| 124 } | 124 } |
| OLD | NEW |