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

Unified Diff: ios/chrome/browser/ui/webui/popular_sites_internals_ui.cc

Issue 2457033003: Add chrome://popular-sites-internals/ to iOS. (Closed)
Patch Set: Break out ...Client. Created 4 years, 1 month 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
« no previous file with comments | « ios/chrome/browser/ui/webui/popular_sites_internals_ui.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/webui/popular_sites_internals_ui.cc
diff --git a/ios/chrome/browser/ui/webui/popular_sites_internals_ui.cc b/ios/chrome/browser/ui/webui/popular_sites_internals_ui.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c22c471567b4b28c593cad618dfb0c3b0e0a304b
--- /dev/null
+++ b/ios/chrome/browser/ui/webui/popular_sites_internals_ui.cc
@@ -0,0 +1,100 @@
+// Copyright 2016 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 "ios/chrome/browser/ui/webui/popular_sites_internals_ui.h"
+
+#include "components/grit/components_resources.h"
+#include "components/ntp_tiles/popular_sites.h"
+#include "components/ntp_tiles/webui/popular_sites_internals_message_handler.h"
+#include "components/ntp_tiles/webui/popular_sites_internals_message_handler_client.h"
+#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
+#include "ios/chrome/browser/chrome_url_constants.h"
+#include "ios/chrome/browser/ntp_tiles/ios_popular_sites_factory.h"
+#include "ios/web/public/web_thread.h"
+#include "ios/web/public/web_ui_ios_data_source.h"
+#include "ios/web/public/webui/web_ui_ios.h"
+#include "ios/web/public/webui/web_ui_ios_message_handler.h"
+
+namespace {
+
+// The implementation for the chrome://popular-sites-internals page.
+class IOSPopularSitesInternalsMessageHandlerBridge
+ : public web::WebUIIOSMessageHandler,
+ public ntp_tiles::PopularSitesInternalsMessageHandlerClient {
+ public:
+ IOSPopularSitesInternalsMessageHandlerBridge() : handler_(this) {}
+
+ private:
+ // web::WebUIIOSMessageHandler:
+ void RegisterMessages() override;
+
+ // ntp_tiles::PopularSitesInternalsMessageHandlerClient
+ base::SequencedWorkerPool* GetBlockingPool() override;
+ std::unique_ptr<ntp_tiles::PopularSites> MakePopularSites() override;
+ PrefService* GetPrefs() override;
+ void RegisterMessageCallback(
+ const std::string& message,
+ const base::Callback<void(const base::ListValue*)>& callback) override;
+ void CallJavascriptFunctionVector(
+ const std::string& name,
+ const std::vector<const base::Value*>& values) override;
+
+ ntp_tiles::PopularSitesInternalsMessageHandler handler_;
+
+ DISALLOW_COPY_AND_ASSIGN(IOSPopularSitesInternalsMessageHandlerBridge);
+};
+
+void IOSPopularSitesInternalsMessageHandlerBridge::RegisterMessages() {
+ handler_.RegisterMessages();
+}
+
+base::SequencedWorkerPool*
+IOSPopularSitesInternalsMessageHandlerBridge::GetBlockingPool() {
+ return web::WebThread::GetBlockingPool();
+}
+
+std::unique_ptr<ntp_tiles::PopularSites>
+IOSPopularSitesInternalsMessageHandlerBridge::MakePopularSites() {
+ return IOSPopularSitesFactory::NewForBrowserState(
+ ios::ChromeBrowserState::FromWebUIIOS(web_ui()));
+}
+
+PrefService* IOSPopularSitesInternalsMessageHandlerBridge::GetPrefs() {
+ return ios::ChromeBrowserState::FromWebUIIOS(web_ui())->GetPrefs();
+}
+
+void IOSPopularSitesInternalsMessageHandlerBridge::RegisterMessageCallback(
+ const std::string& message,
+ const base::Callback<void(const base::ListValue*)>& callback) {
+ web_ui()->RegisterMessageCallback(message, callback);
+}
+
+void IOSPopularSitesInternalsMessageHandlerBridge::CallJavascriptFunctionVector(
+ const std::string& name,
+ const std::vector<const base::Value*>& values) {
+ web_ui()->CallJavascriptFunction(name, values);
+}
+
+} // namespace
+
+web::WebUIIOSDataSource* CreatePopularSitesInternalsHTMLSource() {
+ web::WebUIIOSDataSource* source =
+ web::WebUIIOSDataSource::Create(kChromeUIPopularSitesInternalsHost);
+
+ source->AddResourcePath("popular_sites_internals.js",
+ IDR_POPULAR_SITES_INTERNALS_JS);
+ source->AddResourcePath("popular_sites_internals.css",
+ IDR_POPULAR_SITES_INTERNALS_CSS);
+ source->SetDefaultResource(IDR_POPULAR_SITES_INTERNALS_HTML);
+ return source;
+}
+
+PopularSitesInternalsUI::PopularSitesInternalsUI(web::WebUIIOS* web_ui)
+ : web::WebUIIOSController(web_ui) {
+ web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui),
+ CreatePopularSitesInternalsHTMLSource());
+ web_ui->AddMessageHandler(new IOSPopularSitesInternalsMessageHandlerBridge);
+}
+
+PopularSitesInternalsUI::~PopularSitesInternalsUI() {}
« no previous file with comments | « ios/chrome/browser/ui/webui/popular_sites_internals_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698