| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/popular_sites_internals_ui.h" | 5 #include "chrome/browser/ui/webui/popular_sites_internals_ui.h" |
| 6 | 6 |
| 7 #include "chrome/browser/android/ntp/popular_sites.h" |
| 7 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/webui/popular_sites_internals_message_handler.h" | |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 #include "chrome/grit/browser_resources.h" | 10 #include "components/grit/components_resources.h" |
| 11 #include "components/ntp_tiles/popular_sites.h" |
| 12 #include "components/ntp_tiles/webui/popular_sites_internals_message_handler.h" |
| 13 #include "components/ntp_tiles/webui/popular_sites_internals_message_handler_cli
ent.h" |
| 14 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
| 12 #include "content/public/browser/web_ui_data_source.h" | 16 #include "content/public/browser/web_ui_data_source.h" |
| 17 #include "content/public/browser/web_ui_message_handler.h" |
| 18 |
| 19 namespace { |
| 20 |
| 21 // The implementation for the chrome://popular-sites-internals page. |
| 22 class ChromePopularSitesInternalsMessageHandlerBridge |
| 23 : public content::WebUIMessageHandler, |
| 24 public ntp_tiles::PopularSitesInternalsMessageHandlerClient { |
| 25 public: |
| 26 ChromePopularSitesInternalsMessageHandlerBridge() : handler_(this) {} |
| 27 |
| 28 private: |
| 29 // content::WebUIMessageHandler: |
| 30 void RegisterMessages() override; |
| 31 |
| 32 // ntp_tiles::PopularSitesInternalsMessageHandlerClient |
| 33 base::SequencedWorkerPool* GetBlockingPool() override; |
| 34 std::unique_ptr<ntp_tiles::PopularSites> MakePopularSites() override; |
| 35 PrefService* GetPrefs() override; |
| 36 void RegisterMessageCallback( |
| 37 const std::string& message, |
| 38 const base::Callback<void(const base::ListValue*)>& callback) override; |
| 39 void CallJavascriptFunctionVector( |
| 40 const std::string& name, |
| 41 const std::vector<const base::Value*>& values) override; |
| 42 |
| 43 ntp_tiles::PopularSitesInternalsMessageHandler handler_; |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(ChromePopularSitesInternalsMessageHandlerBridge); |
| 46 }; |
| 47 |
| 48 void ChromePopularSitesInternalsMessageHandlerBridge::RegisterMessages() { |
| 49 handler_.RegisterMessages(); |
| 50 } |
| 51 |
| 52 base::SequencedWorkerPool* |
| 53 ChromePopularSitesInternalsMessageHandlerBridge::GetBlockingPool() { |
| 54 return content::BrowserThread::GetBlockingPool(); |
| 55 } |
| 56 |
| 57 std::unique_ptr<ntp_tiles::PopularSites> |
| 58 ChromePopularSitesInternalsMessageHandlerBridge::MakePopularSites() { |
| 59 return ChromePopularSites::NewForProfile(Profile::FromWebUI(web_ui())); |
| 60 } |
| 61 |
| 62 PrefService* ChromePopularSitesInternalsMessageHandlerBridge::GetPrefs() { |
| 63 return Profile::FromWebUI(web_ui())->GetPrefs(); |
| 64 } |
| 65 |
| 66 void ChromePopularSitesInternalsMessageHandlerBridge::RegisterMessageCallback( |
| 67 const std::string& message, |
| 68 const base::Callback<void(const base::ListValue*)>& callback) { |
| 69 web_ui()->RegisterMessageCallback(message, callback); |
| 70 } |
| 71 |
| 72 void ChromePopularSitesInternalsMessageHandlerBridge:: |
| 73 CallJavascriptFunctionVector( |
| 74 const std::string& name, |
| 75 const std::vector<const base::Value*>& values) { |
| 76 web_ui()->CallJavascriptFunctionUnsafe(name, values); |
| 77 } |
| 78 |
| 79 } // namespace |
| 13 | 80 |
| 14 content::WebUIDataSource* CreatePopularSitesInternalsHTMLSource() { | 81 content::WebUIDataSource* CreatePopularSitesInternalsHTMLSource() { |
| 15 content::WebUIDataSource* source = content::WebUIDataSource::Create( | 82 content::WebUIDataSource* source = content::WebUIDataSource::Create( |
| 16 chrome::kChromeUIPopularSitesInternalsHost); | 83 chrome::kChromeUIPopularSitesInternalsHost); |
| 17 | 84 |
| 18 source->AddResourcePath("popular_sites_internals.js", | 85 source->AddResourcePath("popular_sites_internals.js", |
| 19 IDR_POPULAR_SITES_INTERNALS_JS); | 86 IDR_POPULAR_SITES_INTERNALS_JS); |
| 20 source->AddResourcePath("popular_sites_internals.css", | 87 source->AddResourcePath("popular_sites_internals.css", |
| 21 IDR_POPULAR_SITES_INTERNALS_CSS); | 88 IDR_POPULAR_SITES_INTERNALS_CSS); |
| 22 source->SetDefaultResource(IDR_POPULAR_SITES_INTERNALS_HTML); | 89 source->SetDefaultResource(IDR_POPULAR_SITES_INTERNALS_HTML); |
| 23 source->DisableI18nAndUseGzipForAllPaths(); | |
| 24 return source; | 90 return source; |
| 25 } | 91 } |
| 26 | 92 |
| 27 PopularSitesInternalsUI::PopularSitesInternalsUI(content::WebUI* web_ui) | 93 PopularSitesInternalsUI::PopularSitesInternalsUI(content::WebUI* web_ui) |
| 28 : WebUIController(web_ui) { | 94 : WebUIController(web_ui) { |
| 29 Profile* profile = Profile::FromWebUI(web_ui); | 95 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| 30 content::WebUIDataSource::Add(profile, | |
| 31 CreatePopularSitesInternalsHTMLSource()); | 96 CreatePopularSitesInternalsHTMLSource()); |
| 32 | 97 web_ui->AddMessageHandler( |
| 33 web_ui->AddMessageHandler(new PopularSitesInternalsMessageHandler); | 98 new ChromePopularSitesInternalsMessageHandlerBridge); |
| 34 } | 99 } |
| 35 | 100 |
| 36 PopularSitesInternalsUI::~PopularSitesInternalsUI() {} | 101 PopularSitesInternalsUI::~PopularSitesInternalsUI() {} |
| OLD | NEW |