Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5626)

Unified Diff: chrome/browser/ui/webui/popular_sites_internals_message_handler.cc

Issue 1340493002: Add initial version of chrome://popular-sites-internals page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@finch_country_version
Patch Set: review3 Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/popular_sites_internals_message_handler.cc
diff --git a/chrome/browser/ui/webui/popular_sites_internals_message_handler.cc b/chrome/browser/ui/webui/popular_sites_internals_message_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f14927049d26fb19811580e3632148d7290098e9
--- /dev/null
+++ b/chrome/browser/ui/webui/popular_sites_internals_message_handler.cc
@@ -0,0 +1,81 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/popular_sites_internals_message_handler.h"
+
+#include "base/bind.h"
+#include "base/memory/ref_counted.h"
+#include "base/values.h"
+#include "chrome/browser/android/popular_sites.h"
+#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/web_ui.h"
+
+PopularSitesInternalsMessageHandler::PopularSitesInternalsMessageHandler() {
+}
+
+PopularSitesInternalsMessageHandler::~PopularSitesInternalsMessageHandler() {}
+
+void PopularSitesInternalsMessageHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback("registerForEvents",
+ base::Bind(&PopularSitesInternalsMessageHandler::HandleRegisterForEvents,
+ base::Unretained(this)));
+
+ web_ui()->RegisterMessageCallback("download",
+ base::Bind(&PopularSitesInternalsMessageHandler::HandleDownload,
+ base::Unretained(this)));
+}
+
+void PopularSitesInternalsMessageHandler::HandleRegisterForEvents(
+ const base::ListValue* args) {
+ DCHECK(args->empty());
+
+ std::string country;
+ std::string version;
+ popular_sites_.reset(new PopularSites(
+ Profile::FromWebUI(web_ui()), country, version, std::string(), false,
+ base::Bind(&PopularSitesInternalsMessageHandler::OnPopularSitesAvailable,
+ base::Unretained(this), false)));
+}
+
+void PopularSitesInternalsMessageHandler::HandleDownload(
+ const base::ListValue* args) {
+ DCHECK_EQ(2u, args->GetSize());
+
+ std::string country;
+ args->GetString(0, &country);
+ std::string version;
+ args->GetString(1, &version);
+ popular_sites_.reset(new PopularSites(
+ Profile::FromWebUI(web_ui()), country, version, std::string(), true,
+ base::Bind(&PopularSitesInternalsMessageHandler::OnPopularSitesAvailable,
+ base::Unretained(this), true)));
+}
+
+void PopularSitesInternalsMessageHandler::SendDownloadResult(bool success) {
+ base::StringValue result(success ? "Success" : "Fail");
+ web_ui()->CallJavascriptFunction(
+ "chrome.popular_sites_internals.receiveDownloadResult", result);
+}
+
+void PopularSitesInternalsMessageHandler::SendSites() {
+ scoped_ptr<base::ListValue> sites_list(new base::ListValue);
+ for (const PopularSites::Site& site : popular_sites_->sites()) {
+ scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
+ entry->SetString("title", site.title);
+ entry->SetString("url", site.url.spec());
+ sites_list->Append(entry.Pass());
+ }
+
+ base::DictionaryValue result;
+ result.Set("sites", sites_list.Pass());
+ web_ui()->CallJavascriptFunction(
+ "chrome.popular_sites_internals.receiveSites", result);
+}
+
+void PopularSitesInternalsMessageHandler::OnPopularSitesAvailable(
+ bool explicit_request, bool success) {
+ if (explicit_request)
+ SendDownloadResult(success);
+ SendSites();
+}

Powered by Google App Engine
This is Rietveld 408576698