Matt Jones | 348d977 | 2023-04-17 14:19:08 | [diff] [blame] | 1 | // Copyright 2023 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Matt Jones | 348d977 | 2023-04-17 14:19:08 | [diff] [blame] | 5 | #import "components/commerce/ios/browser/commerce_internals_ui.h" |
| 6 | |
| 7 | #import "components/commerce/core/commerce_constants.h" |
| 8 | #import "components/commerce/core/shopping_service.h" |
| 9 | #import "components/grit/commerce_internals_resources.h" |
| 10 | #import "components/grit/commerce_internals_resources_map.h" |
| 11 | #import "ios/web/public/browser_state.h" |
| 12 | #import "ios/web/public/web_state.h" |
| 13 | #import "ios/web/public/webui/web_ui_ios.h" |
| 14 | #import "ios/web/public/webui/web_ui_ios_data_source.h" |
| 15 | #import "ui/base/webui/resource_path.h" |
| 16 | |
Matt Jones | 348d977 | 2023-04-17 14:19:08 | [diff] [blame] | 17 | namespace commerce { |
| 18 | |
| 19 | CommerceInternalsUI::CommerceInternalsUI(web::WebUIIOS* web_ui, |
| 20 | const std::string& host, |
| 21 | ShoppingService* shopping_service) |
| 22 | : CommerceInternalsUIBase(shopping_service), |
| 23 | web::WebUIIOSController(web_ui, host) { |
| 24 | web::BrowserState* browser_state = web_ui->GetWebState()->GetBrowserState(); |
| 25 | |
| 26 | web::WebUIIOSDataSource* source = |
| 27 | web::WebUIIOSDataSource::Create(kChromeUICommerceInternalsHost); |
| 28 | source->SetDefaultResource(IDR_COMMERCE_INTERNALS_COMMERCE_INTERNALS_HTML); |
| 29 | source->UseStringsJs(); |
Lei Zhang | 09983f4 | 2025-05-22 18:06:07 | [diff] [blame] | 30 | for (const auto& resource : kCommerceInternalsResources) { |
Matt Jones | 348d977 | 2023-04-17 14:19:08 | [diff] [blame] | 31 | source->AddResourcePath(resource.path, resource.id); |
| 32 | } |
| 33 | |
| 34 | web::WebUIIOSDataSource::Add(browser_state, source); |
| 35 | web_ui->GetWebState()->GetInterfaceBinderForMainFrame()->AddInterface( |
| 36 | base::BindRepeating(&CommerceInternalsUI::BindInterface, |
Matt Jones | 845bbf83 | 2024-06-26 16:30:15 | [diff] [blame] | 37 | weak_factory_.GetWeakPtr())); |
Matt Jones | 348d977 | 2023-04-17 14:19:08 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | CommerceInternalsUI::~CommerceInternalsUI() { |
| 41 | web_ui()->GetWebState()->GetInterfaceBinderForMainFrame()->RemoveInterface( |
| 42 | "commerce_internals.mojom.CommerceInternalsHandlerFactory"); |
| 43 | } |
| 44 | |
| 45 | } // namespace commerce |