OLD | NEW |
---|---|
(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 IsSourceEnabled(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::IsSourceEnabled( | |
57 ntp_tiles::NTPTileSource source) { | |
58 switch (source) { | |
59 case ntp_tiles::NTPTileSource::TOP_SITES: | |
60 case ntp_tiles::NTPTileSource::SUGGESTIONS_SERVICE: | |
61 return true; | |
noyau (Ping after 24h)
2016/12/12 11:47:40
The name suggestion service here is highly confusi
Marc Treib
2016/12/12 12:03:25
I don't think so - this methods really just return
sfiera
2016/12/12 12:15:38
Yes. Would you have expected MOST_LIKELY? This enu
Marc Treib
2016/12/12 12:18:45
I think those places are now (mostly?) gone :D
But
sfiera
2016/12/12 12:29:26
They're in the histogram names, right? Those feel
Marc Treib
2016/12/12 12:34:51
Ah, I thought you were referring to the old NTPLog
| |
62 case ntp_tiles::NTPTileSource::POPULAR: | |
63 return ntp_tiles::ShouldShowPopularSites(); | |
64 case ntp_tiles::NTPTileSource::WHITELIST: | |
65 return false; | |
66 } | |
67 NOTREACHED(); | |
68 return false; | |
69 } | |
70 | |
71 std::unique_ptr<ntp_tiles::MostVisitedSites> | |
72 IOSNTPTilesInternalsMessageHandlerBridge::MakeMostVisitedSites() { | |
73 return IOSMostVisitedSitesFactory::NewForBrowserState( | |
74 ios::ChromeBrowserState::FromWebUIIOS(web_ui())); | |
75 } | |
76 | |
77 std::unique_ptr<ntp_tiles::PopularSites> | |
78 IOSNTPTilesInternalsMessageHandlerBridge::MakePopularSites() { | |
79 return IOSPopularSitesFactory::NewForBrowserState( | |
80 ios::ChromeBrowserState::FromWebUIIOS(web_ui())); | |
81 } | |
82 | |
83 PrefService* IOSNTPTilesInternalsMessageHandlerBridge::GetPrefs() { | |
84 return ios::ChromeBrowserState::FromWebUIIOS(web_ui())->GetPrefs(); | |
85 } | |
86 | |
87 void IOSNTPTilesInternalsMessageHandlerBridge::RegisterMessageCallback( | |
88 const std::string& message, | |
89 const base::Callback<void(const base::ListValue*)>& callback) { | |
90 web_ui()->RegisterMessageCallback(message, callback); | |
91 } | |
92 | |
93 void IOSNTPTilesInternalsMessageHandlerBridge::CallJavascriptFunctionVector( | |
94 const std::string& name, | |
95 const std::vector<const base::Value*>& values) { | |
96 web_ui()->CallJavascriptFunction(name, values); | |
97 } | |
98 | |
99 } // namespace | |
100 | |
101 web::WebUIIOSDataSource* CreateNTPTilesInternalsHTMLSource() { | |
102 web::WebUIIOSDataSource* source = | |
103 web::WebUIIOSDataSource::Create(kChromeUINTPTilesInternalsHost); | |
104 | |
105 source->AddResourcePath("ntp_tiles_internals.js", IDR_NTP_TILES_INTERNALS_JS); | |
106 source->AddResourcePath("ntp_tiles_internals.css", | |
107 IDR_NTP_TILES_INTERNALS_CSS); | |
108 source->SetDefaultResource(IDR_NTP_TILES_INTERNALS_HTML); | |
109 return source; | |
110 } | |
111 | |
112 NTPTilesInternalsUI::NTPTilesInternalsUI(web::WebUIIOS* web_ui) | |
113 : web::WebUIIOSController(web_ui) { | |
114 web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui), | |
115 CreateNTPTilesInternalsHTMLSource()); | |
116 web_ui->AddMessageHandler(new IOSNTPTilesInternalsMessageHandlerBridge); | |
117 } | |
118 | |
119 NTPTilesInternalsUI::~NTPTilesInternalsUI() {} | |
OLD | NEW |