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

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

Powered by Google App Engine
This is Rietveld 408576698