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

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: 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/ntp_tiles/webui/popular_sites_internals_message_handler_cli ent.h"
11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
12 #include "ios/chrome/browser/chrome_url_constants.h"
13 #include "ios/chrome/browser/ntp_tiles/ios_popular_sites_factory.h"
14 #include "ios/web/public/web_thread.h"
15 #include "ios/web/public/web_ui_ios_data_source.h"
16 #include "ios/web/public/webui/web_ui_ios.h"
17 #include "ios/web/public/webui/web_ui_ios_message_handler.h"
18
19 namespace {
20
21 // The implementation for the chrome://popular-sites-internals page.
22 class IOSPopularSitesInternalsMessageHandlerBridge
23 : public web::WebUIIOSMessageHandler,
24 public ntp_tiles::PopularSitesInternalsMessageHandlerClient {
25 public:
26 IOSPopularSitesInternalsMessageHandlerBridge() : handler_(this) {}
27
28 private:
29 // web::WebUIIOSMessageHandler:
30 void RegisterMessages() override;
31
32 // ntp_tiles::PopularSitesInternalsMessageHandlerClient
33 base::SequencedWorkerPool* GetBlockingPool() override;
34 std::unique_ptr<ntp_tiles::PopularSites> MakePopularSites() override;
35 PrefService* GetPrefs() override;
36 void RegisterMessageCallback(
37 const std::string& message,
38 const base::Callback<void(const base::ListValue*)>& callback) override;
39 void CallJavascriptFunctionVector(
40 const std::string& name,
41 const std::vector<const base::Value*>& values) override;
42
43 ntp_tiles::PopularSitesInternalsMessageHandler handler_;
44
45 DISALLOW_COPY_AND_ASSIGN(IOSPopularSitesInternalsMessageHandlerBridge);
46 };
47
48 void IOSPopularSitesInternalsMessageHandlerBridge::RegisterMessages() {
49 handler_.RegisterMessages();
50 }
51
52 base::SequencedWorkerPool*
53 IOSPopularSitesInternalsMessageHandlerBridge::GetBlockingPool() {
54 return web::WebThread::GetBlockingPool();
55 }
56
57 std::unique_ptr<ntp_tiles::PopularSites>
58 IOSPopularSitesInternalsMessageHandlerBridge::MakePopularSites() {
59 return IOSPopularSitesFactory::NewForBrowserState(
60 ios::ChromeBrowserState::FromWebUIIOS(web_ui()));
61 }
62
63 PrefService* IOSPopularSitesInternalsMessageHandlerBridge::GetPrefs() {
64 return ios::ChromeBrowserState::FromWebUIIOS(web_ui())->GetPrefs();
65 }
66
67 void IOSPopularSitesInternalsMessageHandlerBridge::RegisterMessageCallback(
68 const std::string& message,
69 const base::Callback<void(const base::ListValue*)>& callback) {
70 web_ui()->RegisterMessageCallback(message, callback);
71 }
72
73 void IOSPopularSitesInternalsMessageHandlerBridge::CallJavascriptFunctionVector(
74 const std::string& name,
75 const std::vector<const base::Value*>& values) {
76 web_ui()->CallJavascriptFunction(name, values);
77 }
78
79 } // namespace
80
81 web::WebUIIOSDataSource* CreatePopularSitesInternalsHTMLSource() {
82 web::WebUIIOSDataSource* source =
83 web::WebUIIOSDataSource::Create(kChromeUIPopularSitesInternalsHost);
84
85 source->AddResourcePath("popular_sites_internals.js",
86 IDR_POPULAR_SITES_INTERNALS_JS);
87 source->AddResourcePath("popular_sites_internals.css",
88 IDR_POPULAR_SITES_INTERNALS_CSS);
89 source->SetDefaultResource(IDR_POPULAR_SITES_INTERNALS_HTML);
90 return source;
91 }
92
93 PopularSitesInternalsUI::PopularSitesInternalsUI(web::WebUIIOS* web_ui)
94 : web::WebUIIOSController(web_ui) {
95 web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui),
96 CreatePopularSitesInternalsHTMLSource());
97 web_ui->AddMessageHandler(new IOSPopularSitesInternalsMessageHandlerBridge);
98 }
99
100 PopularSitesInternalsUI::~PopularSitesInternalsUI() {}
OLDNEW
« 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