Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 15 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
| 16 #include "components/variations/pref_names.h" | |
| 16 #include "content/public/browser/web_ui.h" | 17 #include "content/public/browser/web_ui.h" |
| 17 #include "content/public/browser/web_ui_controller.h" | 18 #include "content/public/browser/web_ui_controller.h" |
| 18 #include "content/public/browser/web_ui_data_source.h" | 19 #include "content/public/browser/web_ui_data_source.h" |
| 19 #include "content/public/browser/web_ui_message_handler.h" | 20 #include "content/public/browser/web_ui_message_handler.h" |
| 20 #include "grit/browser_resources.h" | 21 #include "grit/browser_resources.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // UI Handler for chrome://local-state. Displays the Local State file as JSON. | 25 // UI Handler for chrome://local-state. Displays the Local State file as JSON. |
| 25 class LocalStateUIHandler : public content::WebUIMessageHandler { | 26 class LocalStateUIHandler : public content::WebUIMessageHandler { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 44 LocalStateUIHandler::~LocalStateUIHandler() { | 45 LocalStateUIHandler::~LocalStateUIHandler() { |
| 45 } | 46 } |
| 46 | 47 |
| 47 void LocalStateUIHandler::RegisterMessages() { | 48 void LocalStateUIHandler::RegisterMessages() { |
| 48 web_ui()->RegisterMessageCallback( | 49 web_ui()->RegisterMessageCallback( |
| 49 "requestJson", base::Bind(&LocalStateUIHandler::HandleRequestJson, | 50 "requestJson", base::Bind(&LocalStateUIHandler::HandleRequestJson, |
| 50 base::Unretained(this))); | 51 base::Unretained(this))); |
| 51 } | 52 } |
| 52 | 53 |
| 53 void LocalStateUIHandler::HandleRequestJson(const base::ListValue* args) { | 54 void LocalStateUIHandler::HandleRequestJson(const base::ListValue* args) { |
| 54 #if !defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
| 56 std::vector<std::string> whitelisted_prefixes = { | |
| 57 "variations", "user_experience_metrics", "uninstall_metrics"}; | |
| 58 std::unique_ptr<base::DictionaryValue> local_state_values( | |
| 59 g_browser_process->local_state() | |
| 60 ->GetWhitelistedPreferenceValuesOmitDefaults(whitelisted_prefixes)); | |
|
Bernhard Bauer
2016/04/22 18:24:38
Couldn't we just do the whitelisting here? We woul
hamelphi
2016/04/22 20:31:28
I was on the fence between doing the filtering her
| |
| 61 #else | |
| 55 std::unique_ptr<base::DictionaryValue> local_state_values( | 62 std::unique_ptr<base::DictionaryValue> local_state_values( |
| 56 g_browser_process->local_state()->GetPreferenceValuesOmitDefaults()); | 63 g_browser_process->local_state()->GetPreferenceValuesOmitDefaults()); |
| 57 | 64 #endif // !defined(OS_CHROMEOS) |
| 58 std::string json; | 65 std::string json; |
| 59 JSONStringValueSerializer serializer(&json); | 66 JSONStringValueSerializer serializer(&json); |
| 60 serializer.set_pretty_print(true); | 67 serializer.set_pretty_print(true); |
| 61 bool result = serializer.Serialize(*local_state_values); | 68 bool result = serializer.Serialize(*local_state_values); |
| 62 if (!result) | 69 if (!result) |
| 63 json = "Error loading Local State file."; | 70 json = "Error loading Local State file."; |
| 64 | 71 |
| 65 web_ui()->CallJavascriptFunction("localState.setLocalState", | 72 web_ui()->CallJavascriptFunction("localState.setLocalState", |
| 66 base::StringValue(json)); | 73 base::StringValue(json)); |
| 67 #endif // !defined(OS_CHROMEOS) | |
| 68 } | 74 } |
| 69 | 75 |
| 70 } // namespace | 76 } // namespace |
| 71 | 77 |
| 72 LocalStateUI::LocalStateUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 78 LocalStateUI::LocalStateUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 73 // Set up the chrome://local-state source. | 79 // Set up the chrome://local-state source. |
| 74 content::WebUIDataSource* html_source = | 80 content::WebUIDataSource* html_source = |
| 75 content::WebUIDataSource::Create(chrome::kChromeUILocalStateHost); | 81 content::WebUIDataSource::Create(chrome::kChromeUILocalStateHost); |
| 76 html_source->SetDefaultResource(IDR_LOCAL_STATE_HTML); | 82 html_source->SetDefaultResource(IDR_LOCAL_STATE_HTML); |
| 77 html_source->AddResourcePath("local_state.js", IDR_LOCAL_STATE_JS); | 83 html_source->AddResourcePath("local_state.js", IDR_LOCAL_STATE_JS); |
| 78 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); | 84 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| 79 | 85 |
| 80 // AddMessageHandler takes ownership of LocalStateUIHandler. | 86 // AddMessageHandler takes ownership of LocalStateUIHandler. |
| 81 web_ui->AddMessageHandler(new LocalStateUIHandler); | 87 web_ui->AddMessageHandler(new LocalStateUIHandler); |
| 82 } | 88 } |
| 83 | 89 |
| 84 LocalStateUI::~LocalStateUI() { | 90 LocalStateUI::~LocalStateUI() { |
| 85 } | 91 } |
| OLD | NEW |