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 | |
Arthur Sonzogni | 041a604 | 2024-12-20 04:33:13 | [diff] [blame] | 5 | #ifdef UNSAFE_BUFFERS_BUILD |
| 6 | // TODO(crbug.com/40285824): Remove this and convert code to safer constructs. |
| 7 | #pragma allow_unsafe_buffers |
| 8 | #endif |
| 9 | |
Matt Jones | 348d977 | 2023-04-17 14:19:08 | [diff] [blame] | 10 | #import "components/commerce/ios/browser/commerce_internals_ui.h" |
| 11 | |
| 12 | #import "components/commerce/core/commerce_constants.h" |
| 13 | #import "components/commerce/core/shopping_service.h" |
| 14 | #import "components/grit/commerce_internals_resources.h" |
| 15 | #import "components/grit/commerce_internals_resources_map.h" |
| 16 | #import "ios/web/public/browser_state.h" |
| 17 | #import "ios/web/public/web_state.h" |
| 18 | #import "ios/web/public/webui/web_ui_ios.h" |
| 19 | #import "ios/web/public/webui/web_ui_ios_data_source.h" |
| 20 | #import "ui/base/webui/resource_path.h" |
| 21 | |
Matt Jones | 348d977 | 2023-04-17 14:19:08 | [diff] [blame] | 22 | namespace commerce { |
| 23 | |
| 24 | CommerceInternalsUI::CommerceInternalsUI(web::WebUIIOS* web_ui, |
| 25 | const std::string& host, |
| 26 | ShoppingService* shopping_service) |
| 27 | : CommerceInternalsUIBase(shopping_service), |
| 28 | web::WebUIIOSController(web_ui, host) { |
| 29 | web::BrowserState* browser_state = web_ui->GetWebState()->GetBrowserState(); |
| 30 | |
| 31 | web::WebUIIOSDataSource* source = |
| 32 | web::WebUIIOSDataSource::Create(kChromeUICommerceInternalsHost); |
| 33 | source->SetDefaultResource(IDR_COMMERCE_INTERNALS_COMMERCE_INTERNALS_HTML); |
| 34 | source->UseStringsJs(); |
Peter Kasting | d349e8c | 2024-12-02 09:49:14 | [diff] [blame] | 35 | const base::span<const webui::ResourcePath> resources( |
Matt Jones | 348d977 | 2023-04-17 14:19:08 | [diff] [blame] | 36 | kCommerceInternalsResources, kCommerceInternalsResourcesSize); |
| 37 | |
| 38 | for (const auto& resource : resources) { |
| 39 | source->AddResourcePath(resource.path, resource.id); |
| 40 | } |
| 41 | |
| 42 | web::WebUIIOSDataSource::Add(browser_state, source); |
| 43 | web_ui->GetWebState()->GetInterfaceBinderForMainFrame()->AddInterface( |
| 44 | base::BindRepeating(&CommerceInternalsUI::BindInterface, |
Matt Jones | 845bbf83 | 2024-06-26 16:30:15 | [diff] [blame] | 45 | weak_factory_.GetWeakPtr())); |
Matt Jones | 348d977 | 2023-04-17 14:19:08 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | CommerceInternalsUI::~CommerceInternalsUI() { |
| 49 | web_ui()->GetWebState()->GetInterfaceBinderForMainFrame()->RemoveInterface( |
| 50 | "commerce_internals.mojom.CommerceInternalsHandlerFactory"); |
| 51 | } |
| 52 | |
| 53 | } // namespace commerce |