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

Side by Side Diff: ios/chrome/browser/ui/webui/popular_sites_internals_ui.cc

Issue 2457033003: Add chrome://popular-sites-internals/ to iOS. (Closed)
Patch Set: Minimize ios/content diff. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ios/chrome/browser/ui/webui/popular_sites_internals_ui.h"
6
7 #include "components/grit/components_resources.h"
8 #include "components/ntp_tiles/popular_sites.h"
9 #include "components/ntp_tiles/webui/popular_sites_internals_message_handler.h"
10 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
11 #include "ios/chrome/browser/chrome_url_constants.h"
12 #include "ios/chrome/browser/ntp_tiles/ios_popular_sites_factory.h"
13 #include "ios/web/public/web_thread.h"
14 #include "ios/web/public/web_ui_ios_data_source.h"
15 #include "ios/web/public/webui/web_ui_ios.h"
16 #include "ios/web/public/webui/web_ui_ios_message_handler.h"
17
18 namespace {
19
20 // The implementation for the chrome://popular-sites-internals page.
21 class IOSPopularSitesInternalsMessageHandlerBridge
22 : public web::WebUIIOSMessageHandler,
23 public ntp_tiles::PopularSitesInternalsMessageHandlerClient {
24 public:
25 IOSPopularSitesInternalsMessageHandlerBridge() : handler_(this) {}
26
27 private:
28 // web::WebUIIOSMessageHandler:
29 void RegisterMessages() override;
30
31 // ntp_tiles::PopularSitesInternalsMessageHandlerClient
32 base::SequencedWorkerPool* GetBlockingPool() override;
33 std::unique_ptr<ntp_tiles::PopularSites> MakePopularSites() override;
34 PrefService* GetPrefs() override;
35 void RegisterMessageCallback(
36 const std::string& message,
37 const base::Callback<void(const base::ListValue*)>& callback) override;
38 void CallJavascriptFunctionVector(
39 const std::string& name,
40 const std::vector<const base::Value*>& values) override;
41
42 ntp_tiles::PopularSitesInternalsMessageHandler handler_;
43
44 DISALLOW_COPY_AND_ASSIGN(IOSPopularSitesInternalsMessageHandlerBridge);
45 };
46
47 void IOSPopularSitesInternalsMessageHandlerBridge::RegisterMessages() {
48 handler_.RegisterMessages();
49 }
50
51 base::SequencedWorkerPool*
52 IOSPopularSitesInternalsMessageHandlerBridge::GetBlockingPool() {
53 return web::WebThread::GetBlockingPool();
54 }
55
56 std::unique_ptr<ntp_tiles::PopularSites>
57 IOSPopularSitesInternalsMessageHandlerBridge::MakePopularSites() {
58 return IOSPopularSitesFactory::NewForBrowserState(
59 ios::ChromeBrowserState::FromWebUIIOS(web_ui()));
60 }
61
62 PrefService* IOSPopularSitesInternalsMessageHandlerBridge::GetPrefs() {
63 return ios::ChromeBrowserState::FromWebUIIOS(web_ui())->GetPrefs();
64 }
65
66 void IOSPopularSitesInternalsMessageHandlerBridge::RegisterMessageCallback(
67 const std::string& message,
68 const base::Callback<void(const base::ListValue*)>& callback) {
69 web_ui()->RegisterMessageCallback(message, callback);
70 }
71
72 void IOSPopularSitesInternalsMessageHandlerBridge::CallJavascriptFunctionVector(
73 const std::string& name,
74 const std::vector<const base::Value*>& values) {
75 web_ui()->CallJavascriptFunction(name, values);
76 }
77
78 } // namespace
79
80 web::WebUIIOSDataSource* CreatePopularSitesInternalsHTMLSource() {
81 web::WebUIIOSDataSource* source =
82 web::WebUIIOSDataSource::Create(kChromeUIPopularSitesInternalsHost);
83
84 source->AddResourcePath("popular_sites_internals.js",
85 IDR_POPULAR_SITES_INTERNALS_JS);
86 source->AddResourcePath("popular_sites_internals.css",
87 IDR_POPULAR_SITES_INTERNALS_CSS);
88 source->SetDefaultResource(IDR_POPULAR_SITES_INTERNALS_HTML);
89 return source;
90 }
91
92 PopularSitesInternalsUI::PopularSitesInternalsUI(web::WebUIIOS* web_ui)
93 : web::WebUIIOSController(web_ui) {
94 web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui),
95 CreatePopularSitesInternalsHTMLSource());
96 web_ui->AddMessageHandler(new IOSPopularSitesInternalsMessageHandlerBridge);
97 }
98
99 PopularSitesInternalsUI::~PopularSitesInternalsUI() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698