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

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

Issue 2557103004: Add chrome://site-tiles-internals/ (Closed)
Patch Set: Address review comments 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 "chrome/browser/ui/webui/site_tiles_internals_ui.h"
6
7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h"
9 #include "chrome/browser/favicon/favicon_service_factory.h"
10 #include "chrome/browser/history/top_sites_factory.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/search/suggestions/image_decoder_impl.h"
13 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
14 #include "chrome/browser/search_engines/template_url_service_factory.h"
15 #include "chrome/common/url_constants.h"
16 #include "components/grit/components_resources.h"
17 #include "components/history/core/browser/top_sites.h"
18 #include "components/image_fetcher/image_fetcher_impl.h"
19 #include "components/ntp_tiles/icon_cacher.h"
20 #include "components/ntp_tiles/most_visited_sites.h"
21 #include "components/ntp_tiles/webui/site_tiles_internals_message_handler.h"
22 #include "components/ntp_tiles/webui/site_tiles_internals_message_handler_client .h"
23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/web_ui.h"
25 #include "content/public/browser/web_ui_data_source.h"
26 #include "content/public/browser/web_ui_message_handler.h"
27
28 #if defined(OS_ANDROID)
29 #include "chrome/browser/android/ntp/popular_sites.h"
30 #endif
31
32 namespace {
33
34 // The implementation for the chrome://site-tiles-internals page.
35 class ChromeSiteTilesInternalsMessageHandlerClient
36 : public content::WebUIMessageHandler,
37 public ntp_tiles::SiteTilesInternalsMessageHandlerClient {
38 public:
39 ChromeSiteTilesInternalsMessageHandlerClient() {}
40
41 private:
42 // content::WebUIMessageHandler:
43 void RegisterMessages() override;
44
45 // ntp_tiles::SiteTilesInternalsMessageHandlerClient
46 base::SequencedWorkerPool* GetBlockingPool() override;
47 bool IsSourceEnabled(ntp_tiles::NTPTileSource source) override;
48 std::unique_ptr<ntp_tiles::MostVisitedSites> MakeMostVisitedSites() override;
49 std::unique_ptr<ntp_tiles::PopularSites> MakePopularSites() override;
50 PrefService* GetPrefs() override;
51 void RegisterMessageCallback(
52 const std::string& message,
53 const base::Callback<void(const base::ListValue*)>& callback) override;
54 void CallJavascriptFunctionVector(
55 const std::string& name,
56 const std::vector<const base::Value*>& values) override;
57
58 ntp_tiles::SiteTilesInternalsMessageHandler handler_;
59
60 DISALLOW_COPY_AND_ASSIGN(ChromeSiteTilesInternalsMessageHandlerClient);
61 };
62
63 void ChromeSiteTilesInternalsMessageHandlerClient::RegisterMessages() {
64 handler_.RegisterMessages(this);
65 }
66
67 base::SequencedWorkerPool*
68 ChromeSiteTilesInternalsMessageHandlerClient::GetBlockingPool() {
69 return content::BrowserThread::GetBlockingPool();
70 }
71
72 bool ChromeSiteTilesInternalsMessageHandlerClient::IsSourceEnabled(
73 ntp_tiles::NTPTileSource source) {
74 switch (source) {
75 case ntp_tiles::NTPTileSource::TOP_SITES:
76 case ntp_tiles::NTPTileSource::SUGGESTIONS_SERVICE:
77 #if defined(OS_ANDROID)
78 case ntp_tiles::NTPTileSource::POPULAR:
79 #endif
Marc Treib 2016/12/09 10:52:11 I think this needs an "#else"? The enum entry exis
sfiera 2016/12/09 17:35:28 Ah, right, this is wrong now that the WHITELIST ca
Marc Treib 2016/12/12 09:42:18 SG
80 return true;
81 case ntp_tiles::NTPTileSource::WHITELIST:
82 // TODO(sfiera): support WHITELIST.
83 return false;
84 }
85 NOTREACHED();
86 return false;
87 }
88
89 std::unique_ptr<ntp_tiles::MostVisitedSites>
90 ChromeSiteTilesInternalsMessageHandlerClient::MakeMostVisitedSites() {
91 // TODO(sfiera): share with Android and Instant in a factory.
92 auto* profile = Profile::FromWebUI(web_ui());
93 return base::MakeUnique<ntp_tiles::MostVisitedSites>(
94 GetPrefs(), TopSitesFactory::GetForProfile(profile),
95 suggestions::SuggestionsServiceFactory::GetForProfile(profile),
96 MakePopularSites(),
97 base::MakeUnique<ntp_tiles::IconCacher>(
98 FaviconServiceFactory::GetForProfile(
99 profile, ServiceAccessType::IMPLICIT_ACCESS),
100 base::MakeUnique<image_fetcher::ImageFetcherImpl>(
101 base::MakeUnique<suggestions::ImageDecoderImpl>(),
102 profile->GetRequestContext())),
103 /*supervisor=*/nullptr);
104 }
105
106 std::unique_ptr<ntp_tiles::PopularSites>
107 ChromeSiteTilesInternalsMessageHandlerClient::MakePopularSites() {
108 #if defined(OS_ANDROID)
109 return ChromePopularSites::NewForProfile(Profile::FromWebUI(web_ui()));
110 #else
111 return nullptr;
112 #endif
113 }
114
115 PrefService* ChromeSiteTilesInternalsMessageHandlerClient::GetPrefs() {
116 return Profile::FromWebUI(web_ui())->GetPrefs();
117 }
118
119 void ChromeSiteTilesInternalsMessageHandlerClient::RegisterMessageCallback(
120 const std::string& message,
121 const base::Callback<void(const base::ListValue*)>& callback) {
122 web_ui()->RegisterMessageCallback(message, callback);
123 }
124
125 void ChromeSiteTilesInternalsMessageHandlerClient::CallJavascriptFunctionVector(
126 const std::string& name,
127 const std::vector<const base::Value*>& values) {
128 web_ui()->CallJavascriptFunctionUnsafe(name, values);
129 }
130
131 content::WebUIDataSource* CreateSiteTilesInternalsHTMLSource() {
132 content::WebUIDataSource* source =
133 content::WebUIDataSource::Create(chrome::kChromeUISiteTilesInternalsHost);
134
135 source->AddResourcePath("site_tiles_internals.js",
136 IDR_SITE_TILES_INTERNALS_JS);
137 source->AddResourcePath("site_tiles_internals.css",
138 IDR_SITE_TILES_INTERNALS_CSS);
139 source->SetDefaultResource(IDR_SITE_TILES_INTERNALS_HTML);
140 return source;
141 }
142
143 } // namespace
144
145 SiteTilesInternalsUI::SiteTilesInternalsUI(content::WebUI* web_ui)
146 : WebUIController(web_ui) {
147 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui),
148 CreateSiteTilesInternalsHTMLSource());
149 web_ui->AddMessageHandler(new ChromeSiteTilesInternalsMessageHandlerClient);
150 }
151
152 SiteTilesInternalsUI::~SiteTilesInternalsUI() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698