| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/popular_sites_internals_message_handler.h" | 5 #include "chrome/browser/ui/webui/popular_sites_internals_message_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 base::Bind(&PopularSitesInternalsMessageHandler::SendJson, | 124 base::Bind(&PopularSitesInternalsMessageHandler::SendJson, |
| 125 weak_ptr_factory_.GetWeakPtr())); | 125 weak_ptr_factory_.GetWeakPtr())); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void PopularSitesInternalsMessageHandler::SendOverrides() { | 128 void PopularSitesInternalsMessageHandler::SendOverrides() { |
| 129 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 129 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 130 std::string country = | 130 std::string country = |
| 131 prefs->GetString(ntp_tiles::prefs::kPopularSitesOverrideCountry); | 131 prefs->GetString(ntp_tiles::prefs::kPopularSitesOverrideCountry); |
| 132 std::string version = | 132 std::string version = |
| 133 prefs->GetString(ntp_tiles::prefs::kPopularSitesOverrideVersion); | 133 prefs->GetString(ntp_tiles::prefs::kPopularSitesOverrideVersion); |
| 134 web_ui()->CallJavascriptFunction( | 134 web_ui()->CallJavascriptFunctionUnsafe( |
| 135 "chrome.popular_sites_internals.receiveOverrides", | 135 "chrome.popular_sites_internals.receiveOverrides", |
| 136 base::StringValue(country), base::StringValue(version)); | 136 base::StringValue(country), base::StringValue(version)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void PopularSitesInternalsMessageHandler::SendDownloadResult(bool success) { | 139 void PopularSitesInternalsMessageHandler::SendDownloadResult(bool success) { |
| 140 base::StringValue result(success ? "Success" : "Fail"); | 140 base::StringValue result(success ? "Success" : "Fail"); |
| 141 web_ui()->CallJavascriptFunction( | 141 web_ui()->CallJavascriptFunctionUnsafe( |
| 142 "chrome.popular_sites_internals.receiveDownloadResult", result); | 142 "chrome.popular_sites_internals.receiveDownloadResult", result); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void PopularSitesInternalsMessageHandler::SendSites() { | 145 void PopularSitesInternalsMessageHandler::SendSites() { |
| 146 std::unique_ptr<base::ListValue> sites_list(new base::ListValue); | 146 std::unique_ptr<base::ListValue> sites_list(new base::ListValue); |
| 147 for (const PopularSites::Site& site : popular_sites_->sites()) { | 147 for (const PopularSites::Site& site : popular_sites_->sites()) { |
| 148 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 148 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
| 149 entry->SetString("title", site.title); | 149 entry->SetString("title", site.title); |
| 150 entry->SetString("url", site.url.spec()); | 150 entry->SetString("url", site.url.spec()); |
| 151 sites_list->Append(std::move(entry)); | 151 sites_list->Append(std::move(entry)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 base::DictionaryValue result; | 154 base::DictionaryValue result; |
| 155 result.Set("sites", std::move(sites_list)); | 155 result.Set("sites", std::move(sites_list)); |
| 156 result.SetString("country", popular_sites_->GetCountry()); | 156 result.SetString("country", popular_sites_->GetCountry()); |
| 157 result.SetString("version", popular_sites_->GetVersion()); | 157 result.SetString("version", popular_sites_->GetVersion()); |
| 158 web_ui()->CallJavascriptFunction( | 158 web_ui()->CallJavascriptFunctionUnsafe( |
| 159 "chrome.popular_sites_internals.receiveSites", result); | 159 "chrome.popular_sites_internals.receiveSites", result); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void PopularSitesInternalsMessageHandler::SendJson(const std::string& json) { | 162 void PopularSitesInternalsMessageHandler::SendJson(const std::string& json) { |
| 163 web_ui()->CallJavascriptFunction("chrome.popular_sites_internals.receiveJson", | 163 web_ui()->CallJavascriptFunctionUnsafe( |
| 164 base::StringValue(json)); | 164 "chrome.popular_sites_internals.receiveJson", base::StringValue(json)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void PopularSitesInternalsMessageHandler::OnPopularSitesAvailable( | 167 void PopularSitesInternalsMessageHandler::OnPopularSitesAvailable( |
| 168 bool explicit_request, bool success) { | 168 bool explicit_request, bool success) { |
| 169 if (explicit_request) | 169 if (explicit_request) |
| 170 SendDownloadResult(success); | 170 SendDownloadResult(success); |
| 171 SendSites(); | 171 SendSites(); |
| 172 } | 172 } |
| OLD | NEW |