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

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

Issue 2557103004: Add chrome://site-tiles-internals/ (Closed)
Patch Set: rebase 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
« no previous file with comments | « ios/chrome/browser/ui/webui/ntp_tiles_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/ntp_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/ntp_tiles_internals_message_handler.h"
12 #include "components/ntp_tiles/webui/ntp_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://ntp-tiles-internals page.
25 class IOSNTPTilesInternalsMessageHandlerBridge
26 : public web::WebUIIOSMessageHandler,
27 public ntp_tiles::NTPTilesInternalsMessageHandlerClient {
28 public:
29 IOSNTPTilesInternalsMessageHandlerBridge() {}
30
31 private:
32 // web::WebUIIOSMessageHandler:
33 void RegisterMessages() override;
34
35 // ntp_tiles::NTPTilesInternalsMessageHandlerClient
36 bool DoesSourceExist(ntp_tiles::NTPTileSource source) override;
37 std::unique_ptr<ntp_tiles::MostVisitedSites> MakeMostVisitedSites() 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 ntp_tiles::NTPTilesInternalsMessageHandler handler_;
48
49 DISALLOW_COPY_AND_ASSIGN(IOSNTPTilesInternalsMessageHandlerBridge);
50 };
51
52 void IOSNTPTilesInternalsMessageHandlerBridge::RegisterMessages() {
53 handler_.RegisterMessages(this);
54 }
55
56 bool IOSNTPTilesInternalsMessageHandlerBridge::DoesSourceExist(
57 ntp_tiles::NTPTileSource source) {
58 switch (source) {
59 case ntp_tiles::NTPTileSource::TOP_SITES:
60 case ntp_tiles::NTPTileSource::SUGGESTIONS_SERVICE:
61 case ntp_tiles::NTPTileSource::POPULAR:
62 return true;
63 case ntp_tiles::NTPTileSource::WHITELIST:
64 return false;
65 }
66 NOTREACHED();
67 return false;
68 }
69
70 std::unique_ptr<ntp_tiles::MostVisitedSites>
71 IOSNTPTilesInternalsMessageHandlerBridge::MakeMostVisitedSites() {
72 return IOSMostVisitedSitesFactory::NewForBrowserState(
73 ios::ChromeBrowserState::FromWebUIIOS(web_ui()));
74 }
75
76 std::unique_ptr<ntp_tiles::PopularSites>
77 IOSNTPTilesInternalsMessageHandlerBridge::MakePopularSites() {
78 return IOSPopularSitesFactory::NewForBrowserState(
79 ios::ChromeBrowserState::FromWebUIIOS(web_ui()));
80 }
81
82 PrefService* IOSNTPTilesInternalsMessageHandlerBridge::GetPrefs() {
83 return ios::ChromeBrowserState::FromWebUIIOS(web_ui())->GetPrefs();
84 }
85
86 void IOSNTPTilesInternalsMessageHandlerBridge::RegisterMessageCallback(
87 const std::string& message,
88 const base::Callback<void(const base::ListValue*)>& callback) {
89 web_ui()->RegisterMessageCallback(message, callback);
90 }
91
92 void IOSNTPTilesInternalsMessageHandlerBridge::CallJavascriptFunctionVector(
93 const std::string& name,
94 const std::vector<const base::Value*>& values) {
95 web_ui()->CallJavascriptFunction(name, values);
96 }
97
98 } // namespace
99
100 web::WebUIIOSDataSource* CreateNTPTilesInternalsHTMLSource() {
101 web::WebUIIOSDataSource* source =
102 web::WebUIIOSDataSource::Create(kChromeUINTPTilesInternalsHost);
103
104 source->AddResourcePath("ntp_tiles_internals.js", IDR_NTP_TILES_INTERNALS_JS);
105 source->AddResourcePath("ntp_tiles_internals.css",
106 IDR_NTP_TILES_INTERNALS_CSS);
107 source->SetDefaultResource(IDR_NTP_TILES_INTERNALS_HTML);
108 return source;
109 }
110
111 NTPTilesInternalsUI::NTPTilesInternalsUI(web::WebUIIOS* web_ui)
112 : web::WebUIIOSController(web_ui) {
113 web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui),
114 CreateNTPTilesInternalsHTMLSource());
115 web_ui->AddMessageHandler(new IOSNTPTilesInternalsMessageHandlerBridge);
116 }
117
118 NTPTilesInternalsUI::~NTPTilesInternalsUI() {}
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/webui/ntp_tiles_internals_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698