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

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

Issue 2557103004: Add chrome://site-tiles-internals/ (Closed)
Patch Set: Support iOS Created 4 years 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/site_tiles_internals_ui.h"
6
7 #include "components/grit/components_resources.h"
8 #include "components/ntp_tiles/field_trial.h"
9 #include "components/ntp_tiles/most_visited_sites.h"
10 #include "components/ntp_tiles/popular_sites.h"
11 #include "components/ntp_tiles/webui/site_tiles_internals_message_handler.h"
12 #include "components/ntp_tiles/webui/site_tiles_internals_message_handler_client .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_most_visited_sites_factory.h"
16 #include "ios/chrome/browser/ntp_tiles/ios_popular_sites_factory.h"
17 #include "ios/web/public/web_thread.h"
18 #include "ios/web/public/web_ui_ios_data_source.h"
19 #include "ios/web/public/webui/web_ui_ios.h"
20 #include "ios/web/public/webui/web_ui_ios_message_handler.h"
21
22 namespace {
23
24 // The implementation for the chrome://popular-sites-internals page.
25 class IOSSiteTilesInternalsMessageHandlerBridge
26 : public web::WebUIIOSMessageHandler,
27 public ntp_tiles::SiteTilesInternalsMessageHandlerClient {
28 public:
29 IOSSiteTilesInternalsMessageHandlerBridge() : handler_(this) {}
30
31 private:
32 // web::WebUIIOSMessageHandler:
33 void RegisterMessages() override;
34
35 // ntp_tiles::SiteTilesInternalsMessageHandlerClient
36 base::SequencedWorkerPool* GetBlockingPool() override;
37 bool IsSourceEnabled(ntp_tiles::NTPTileSource source) override;
38 std::unique_ptr<ntp_tiles::MostVisitedSites> MakeMostVisitedSites() override;
39 std::unique_ptr<ntp_tiles::PopularSites> MakePopularSites() override;
40 PrefService* GetPrefs() override;
41 void RegisterMessageCallback(
42 const std::string& message,
43 const base::Callback<void(const base::ListValue*)>& callback) override;
44 void CallJavascriptFunctionVector(
45 const std::string& name,
46 const std::vector<const base::Value*>& values) override;
47
48 ntp_tiles::SiteTilesInternalsMessageHandler handler_;
49
50 DISALLOW_COPY_AND_ASSIGN(IOSSiteTilesInternalsMessageHandlerBridge);
51 };
52
53 void IOSSiteTilesInternalsMessageHandlerBridge::RegisterMessages() {
54 handler_.RegisterMessages();
55 }
56
57 base::SequencedWorkerPool*
58 IOSSiteTilesInternalsMessageHandlerBridge::GetBlockingPool() {
59 return web::WebThread::GetBlockingPool();
60 }
61
62 bool IOSSiteTilesInternalsMessageHandlerBridge::IsSourceEnabled(
63 ntp_tiles::NTPTileSource source) {
64 switch (source) {
65 case ntp_tiles::NTPTileSource::TOP_SITES:
66 case ntp_tiles::NTPTileSource::SUGGESTIONS_SERVICE:
67 return true;
68 case ntp_tiles::NTPTileSource::POPULAR:
69 return ntp_tiles::ShouldShowPopularSites();
70 default:
71 return false;
72 }
73 }
74
75 std::unique_ptr<ntp_tiles::MostVisitedSites>
76 IOSSiteTilesInternalsMessageHandlerBridge::MakeMostVisitedSites() {
77 return IOSMostVisitedSitesFactory::NewForBrowserState(
78 ios::ChromeBrowserState::FromWebUIIOS(web_ui()));
79 }
80
81 std::unique_ptr<ntp_tiles::PopularSites>
82 IOSSiteTilesInternalsMessageHandlerBridge::MakePopularSites() {
83 return IOSPopularSitesFactory::NewForBrowserState(
84 ios::ChromeBrowserState::FromWebUIIOS(web_ui()));
85 }
86
87 PrefService* IOSSiteTilesInternalsMessageHandlerBridge::GetPrefs() {
88 return ios::ChromeBrowserState::FromWebUIIOS(web_ui())->GetPrefs();
89 }
90
91 void IOSSiteTilesInternalsMessageHandlerBridge::RegisterMessageCallback(
92 const std::string& message,
93 const base::Callback<void(const base::ListValue*)>& callback) {
94 web_ui()->RegisterMessageCallback(message, callback);
95 }
96
97 void IOSSiteTilesInternalsMessageHandlerBridge::CallJavascriptFunctionVector(
98 const std::string& name,
99 const std::vector<const base::Value*>& values) {
100 web_ui()->CallJavascriptFunction(name, values);
101 }
102
103 } // namespace
104
105 web::WebUIIOSDataSource* CreateSiteTilesInternalsHTMLSource() {
106 web::WebUIIOSDataSource* source =
107 web::WebUIIOSDataSource::Create(kChromeUISiteTilesInternalsHost);
108
109 source->AddResourcePath("site_tiles_internals.js",
110 IDR_SITE_TILES_INTERNALS_JS);
111 source->AddResourcePath("site_tiles_internals.css",
112 IDR_SITE_TILES_INTERNALS_CSS);
113 source->SetDefaultResource(IDR_SITE_TILES_INTERNALS_HTML);
114 return source;
115 }
116
117 SiteTilesInternalsUI::SiteTilesInternalsUI(web::WebUIIOS* web_ui)
118 : web::WebUIIOSController(web_ui) {
119 web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui),
120 CreateSiteTilesInternalsHTMLSource());
121 web_ui->AddMessageHandler(new IOSSiteTilesInternalsMessageHandlerBridge);
122 }
123
124 SiteTilesInternalsUI::~SiteTilesInternalsUI() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698