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

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: Inline message handler impl. 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 "base/bind.h"
8 #include "components/grit/components_resources.h"
9 #include "components/ntp_tiles/popular_sites.h"
10 #include "components/ntp_tiles/webui/popular_sites_handler.h"
11 #include "ios/chrome/browser/application_context.h"
12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
13 #include "ios/chrome/browser/chrome_url_constants.h"
14 #include "ios/chrome/browser/ntp_tiles/ios_popular_sites_factory.h"
15 #include "ios/web/public/web_thread.h"
16 #include "ios/web/public/web_ui_ios_data_source.h"
17 #include "ios/web/public/webui/web_ui_ios.h"
18 #include "ios/web/public/webui/web_ui_ios_message_handler.h"
19
20 using ntp_tiles::PopularSitesInternalsMessageHandlerImpl;
21
22 namespace {
23
24 class PopularSitesInternalsMessageHandler
25 : public web::WebUIIOSMessageHandler,
26 public ntp_tiles::PopularSitesInternalsMessageHandlerInterface {
27 public:
28 PopularSitesInternalsMessageHandler();
29 ~PopularSitesInternalsMessageHandler() override = default;
30
31 private:
32 // web::WebUIIOSMessageHandler:
33 void RegisterMessages() override;
34
35 // ntp_tiles::PopularSitesInternalsMessageHandlerInterface
36 base::SequencedWorkerPool* GetBlockingPool() override;
37 std::unique_ptr<ntp_tiles::PopularSites> MakePopularSites() override;
38 PrefService* GetPrefs() override;
39 void RegisterMessageCallback(
40 const std::string& message,
41 const base::Callback<void(const base::ListValue*)>& callback) override;
42 void CallJavascriptFunctionVector(
43 const std::string& name,
44 const std::vector<const base::Value*>& values) override;
45
46 std::unique_ptr<PopularSitesInternalsMessageHandlerImpl> handler_;
47
48 DISALLOW_COPY_AND_ASSIGN(PopularSitesInternalsMessageHandler);
49 };
50
51 PopularSitesInternalsMessageHandler::PopularSitesInternalsMessageHandler()
52 : handler_(new PopularSitesInternalsMessageHandlerImpl(this)) {}
sdefresne 2016/10/28 13:34:03 Use base::MakeUnique<>
sfiera 2016/10/28 14:12:43 Done.
53
54 void PopularSitesInternalsMessageHandler::RegisterMessages() {
55 handler_->RegisterMessages();
56 }
57
58 base::SequencedWorkerPool*
59 PopularSitesInternalsMessageHandler::GetBlockingPool() {
60 return web::WebThread::GetBlockingPool();
61 }
62
63 std::unique_ptr<ntp_tiles::PopularSites>
64 PopularSitesInternalsMessageHandler::MakePopularSites() {
65 return IOSPopularSitesFactory::NewForBrowserState(
66 ios::ChromeBrowserState::FromWebUIIOS(web_ui()));
67 }
68
69 PrefService* PopularSitesInternalsMessageHandler::GetPrefs() {
70 return ios::ChromeBrowserState::FromWebUIIOS(web_ui())->GetPrefs();
71 }
72
73 void PopularSitesInternalsMessageHandler::RegisterMessageCallback(
74 const std::string& message,
75 const base::Callback<void(const base::ListValue*)>& callback) {
76 return web_ui()->RegisterMessageCallback(message, callback);
77 }
78
79 void PopularSitesInternalsMessageHandler::CallJavascriptFunctionVector(
80 const std::string& name,
81 const std::vector<const base::Value*>& values) {
82 return web_ui()->CallJavascriptFunction(name, values);
83 }
84
85 } // namespace
86
87 PopularSitesInternalsUI::PopularSitesInternalsUI(web::WebUIIOS* web_ui)
88 : web::WebUIIOSController(web_ui) {
89 web_ui->AddMessageHandler(new PopularSitesInternalsMessageHandler);
90
91 web::WebUIIOSDataSource* source =
92 web::WebUIIOSDataSource::Create(kChromeUIPopularSitesInternalsHost);
93 source->AddResourcePath("popular_sites_internals.js",
94 IDR_POPULAR_SITES_INTERNALS_JS);
95 source->AddResourcePath("popular_sites_internals.css",
96 IDR_POPULAR_SITES_INTERNALS_CSS);
97 source->SetDefaultResource(IDR_POPULAR_SITES_INTERNALS_HTML);
98
99 web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui),
100 source);
101 }
102
103 PopularSitesInternalsUI::~PopularSitesInternalsUI() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698