| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "ios/chrome/browser/ui/webui/ntp_tiles_internals_ui.h" | 5 #include "ios/chrome/browser/ui/webui/ntp_tiles_internals_ui.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "components/grit/components_resources.h" | 8 #include "components/grit/components_resources.h" |
| 9 #include "components/keyed_service/core/service_access_type.h" |
| 9 #include "components/ntp_tiles/field_trial.h" | 10 #include "components/ntp_tiles/field_trial.h" |
| 10 #include "components/ntp_tiles/most_visited_sites.h" | 11 #include "components/ntp_tiles/most_visited_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.h" |
| 12 #include "components/ntp_tiles/webui/ntp_tiles_internals_message_handler_client.
h" | 13 #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/browser_state/chrome_browser_state.h" |
| 14 #include "ios/chrome/browser/chrome_url_constants.h" | 15 #include "ios/chrome/browser/chrome_url_constants.h" |
| 16 #include "ios/chrome/browser/favicon/favicon_service_factory.h" |
| 15 #include "ios/chrome/browser/ntp_tiles/ios_most_visited_sites_factory.h" | 17 #include "ios/chrome/browser/ntp_tiles/ios_most_visited_sites_factory.h" |
| 16 #include "ios/chrome/browser/ntp_tiles/ios_popular_sites_factory.h" | 18 #include "ios/chrome/browser/ntp_tiles/ios_popular_sites_factory.h" |
| 17 #include "ios/web/public/web_thread.h" | 19 #include "ios/web/public/web_thread.h" |
| 18 #include "ios/web/public/web_ui_ios_data_source.h" | 20 #include "ios/web/public/web_ui_ios_data_source.h" |
| 19 #include "ios/web/public/webui/web_ui_ios.h" | 21 #include "ios/web/public/webui/web_ui_ios.h" |
| 20 #include "ios/web/public/webui/web_ui_ios_message_handler.h" | 22 #include "ios/web/public/webui/web_ui_ios_message_handler.h" |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 // The implementation for the chrome://ntp-tiles-internals page. | 26 // The implementation for the chrome://ntp-tiles-internals page. |
| 25 class IOSNTPTilesInternalsMessageHandlerBridge | 27 class IOSNTPTilesInternalsMessageHandlerBridge |
| 26 : public web::WebUIIOSMessageHandler, | 28 : public web::WebUIIOSMessageHandler, |
| 27 public ntp_tiles::NTPTilesInternalsMessageHandlerClient { | 29 public ntp_tiles::NTPTilesInternalsMessageHandlerClient { |
| 28 public: | 30 public: |
| 29 IOSNTPTilesInternalsMessageHandlerBridge() {} | 31 // |favicon_service| must not be null and must outlive this object. |
| 32 explicit IOSNTPTilesInternalsMessageHandlerBridge( |
| 33 favicon::FaviconService* favicon_service) |
| 34 : handler_(favicon_service) {} |
| 30 | 35 |
| 31 private: | 36 private: |
| 32 // web::WebUIIOSMessageHandler: | 37 // web::WebUIIOSMessageHandler: |
| 33 void RegisterMessages() override; | 38 void RegisterMessages() override; |
| 34 | 39 |
| 35 // ntp_tiles::NTPTilesInternalsMessageHandlerClient | 40 // ntp_tiles::NTPTilesInternalsMessageHandlerClient |
| 36 bool SupportsNTPTiles() override; | 41 bool SupportsNTPTiles() override; |
| 37 bool DoesSourceExist(ntp_tiles::TileSource source) override; | 42 bool DoesSourceExist(ntp_tiles::TileSource source) override; |
| 38 std::unique_ptr<ntp_tiles::MostVisitedSites> MakeMostVisitedSites() override; | 43 std::unique_ptr<ntp_tiles::MostVisitedSites> MakeMostVisitedSites() override; |
| 39 PrefService* GetPrefs() override; | 44 PrefService* GetPrefs() override; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 source->AddResourcePath("ntp_tiles_internals.css", | 107 source->AddResourcePath("ntp_tiles_internals.css", |
| 103 IDR_NTP_TILES_INTERNALS_CSS); | 108 IDR_NTP_TILES_INTERNALS_CSS); |
| 104 source->SetDefaultResource(IDR_NTP_TILES_INTERNALS_HTML); | 109 source->SetDefaultResource(IDR_NTP_TILES_INTERNALS_HTML); |
| 105 return source; | 110 return source; |
| 106 } | 111 } |
| 107 | 112 |
| 108 } // namespace | 113 } // namespace |
| 109 | 114 |
| 110 NTPTilesInternalsUI::NTPTilesInternalsUI(web::WebUIIOS* web_ui) | 115 NTPTilesInternalsUI::NTPTilesInternalsUI(web::WebUIIOS* web_ui) |
| 111 : web::WebUIIOSController(web_ui) { | 116 : web::WebUIIOSController(web_ui) { |
| 112 web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui), | 117 ios::ChromeBrowserState* browser_state = |
| 118 ios::ChromeBrowserState::FromWebUIIOS(web_ui); |
| 119 web::WebUIIOSDataSource::Add(browser_state, |
| 113 CreateNTPTilesInternalsHTMLSource()); | 120 CreateNTPTilesInternalsHTMLSource()); |
| 114 web_ui->AddMessageHandler( | 121 web_ui->AddMessageHandler( |
| 115 base::MakeUnique<IOSNTPTilesInternalsMessageHandlerBridge>()); | 122 base::MakeUnique<IOSNTPTilesInternalsMessageHandlerBridge>( |
| 123 ios::FaviconServiceFactory::GetForBrowserState( |
| 124 browser_state, ServiceAccessType::EXPLICIT_ACCESS))); |
| 116 } | 125 } |
| 117 | 126 |
| 118 NTPTilesInternalsUI::~NTPTilesInternalsUI() {} | 127 NTPTilesInternalsUI::~NTPTilesInternalsUI() {} |
| OLD | NEW |