| 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 "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/web_ui.h" | 14 #include "content/public/browser/web_ui.h" |
| 12 #include "content/public/browser/web_ui_data_source.h" | 15 #include "content/public/browser/web_ui_data_source.h" |
| 16 #include "content/public/browser/web_ui_message_handler.h" |
| 17 |
| 18 namespace { |
| 19 |
| 20 // The implementation for the chrome://popular-sites-internals page. |
| 21 class ChromePopularSitesInternalsMessageHandlerBridge |
| 22 : public content::WebUIMessageHandler, |
| 23 public ntp_tiles::PopularSitesInternalsMessageHandlerClient { |
| 24 public: |
| 25 ChromePopularSitesInternalsMessageHandlerBridge() : handler_(this) {} |
| 26 |
| 27 private: |
| 28 // content::WebUIMessageHandler: |
| 29 void RegisterMessages() override; |
| 30 |
| 31 // ntp_tiles::PopularSitesInternalsMessageHandlerClient |
| 32 base::SequencedWorkerPool* GetBlockingPool() override; |
| 33 std::unique_ptr<ntp_tiles::PopularSites> MakePopularSites() override; |
| 34 PrefService* GetPrefs() override; |
| 35 void RegisterMessageCallback( |
| 36 const std::string& message, |
| 37 const base::Callback<void(const base::ListValue*)>& callback) override; |
| 38 void CallJavascriptFunctionVector( |
| 39 const std::string& name, |
| 40 const std::vector<const base::Value*>& values) override; |
| 41 |
| 42 ntp_tiles::PopularSitesInternalsMessageHandler handler_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(ChromePopularSitesInternalsMessageHandlerBridge); |
| 45 }; |
| 46 |
| 47 void ChromePopularSitesInternalsMessageHandlerBridge::RegisterMessages() { |
| 48 handler_.RegisterMessages(); |
| 49 } |
| 50 |
| 51 base::SequencedWorkerPool* |
| 52 ChromePopularSitesInternalsMessageHandlerBridge::GetBlockingPool() { |
| 53 return content::BrowserThread::GetBlockingPool(); |
| 54 } |
| 55 |
| 56 std::unique_ptr<ntp_tiles::PopularSites> |
| 57 ChromePopularSitesInternalsMessageHandlerBridge::MakePopularSites() { |
| 58 return ChromePopularSites::NewForProfile(Profile::FromWebUI(web_ui())); |
| 59 } |
| 60 |
| 61 PrefService* ChromePopularSitesInternalsMessageHandlerBridge::GetPrefs() { |
| 62 return Profile::FromWebUI(web_ui())->GetPrefs(); |
| 63 } |
| 64 |
| 65 void ChromePopularSitesInternalsMessageHandlerBridge::RegisterMessageCallback( |
| 66 const std::string& message, |
| 67 const base::Callback<void(const base::ListValue*)>& callback) { |
| 68 web_ui()->RegisterMessageCallback(message, callback); |
| 69 } |
| 70 |
| 71 void ChromePopularSitesInternalsMessageHandlerBridge:: |
| 72 CallJavascriptFunctionVector( |
| 73 const std::string& name, |
| 74 const std::vector<const base::Value*>& values) { |
| 75 web_ui()->CallJavascriptFunctionUnsafe(name, values); |
| 76 } |
| 77 |
| 78 } // namespace |
| 13 | 79 |
| 14 content::WebUIDataSource* CreatePopularSitesInternalsHTMLSource() { | 80 content::WebUIDataSource* CreatePopularSitesInternalsHTMLSource() { |
| 15 content::WebUIDataSource* source = content::WebUIDataSource::Create( | 81 content::WebUIDataSource* source = content::WebUIDataSource::Create( |
| 16 chrome::kChromeUIPopularSitesInternalsHost); | 82 chrome::kChromeUIPopularSitesInternalsHost); |
| 17 | 83 |
| 18 source->AddResourcePath("popular_sites_internals.js", | 84 source->AddResourcePath("popular_sites_internals.js", |
| 19 IDR_POPULAR_SITES_INTERNALS_JS); | 85 IDR_POPULAR_SITES_INTERNALS_JS); |
| 20 source->AddResourcePath("popular_sites_internals.css", | 86 source->AddResourcePath("popular_sites_internals.css", |
| 21 IDR_POPULAR_SITES_INTERNALS_CSS); | 87 IDR_POPULAR_SITES_INTERNALS_CSS); |
| 22 source->SetDefaultResource(IDR_POPULAR_SITES_INTERNALS_HTML); | 88 source->SetDefaultResource(IDR_POPULAR_SITES_INTERNALS_HTML); |
| 23 source->DisableI18nAndUseGzipForAllPaths(); | |
| 24 return source; | 89 return source; |
| 25 } | 90 } |
| 26 | 91 |
| 27 PopularSitesInternalsUI::PopularSitesInternalsUI(content::WebUI* web_ui) | 92 PopularSitesInternalsUI::PopularSitesInternalsUI(content::WebUI* web_ui) |
| 28 : WebUIController(web_ui) { | 93 : WebUIController(web_ui) { |
| 29 Profile* profile = Profile::FromWebUI(web_ui); | 94 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| 30 content::WebUIDataSource::Add(profile, | |
| 31 CreatePopularSitesInternalsHTMLSource()); | 95 CreatePopularSitesInternalsHTMLSource()); |
| 32 | 96 web_ui->AddMessageHandler( |
| 33 web_ui->AddMessageHandler(new PopularSitesInternalsMessageHandler); | 97 new ChromePopularSitesInternalsMessageHandlerBridge); |
| 34 } | 98 } |
| 35 | 99 |
| 36 PopularSitesInternalsUI::~PopularSitesInternalsUI() {} | 100 PopularSitesInternalsUI::~PopularSitesInternalsUI() {} |
| OLD | NEW |