blob: ded3b29d7cfd0422994a1227c6bc00f6beaf5a37 [file] [log] [blame]
Matt Jones348d9772023-04-17 14:19:081// 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 Sonzogni041a6042024-12-20 04:33:135#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 Jones348d9772023-04-17 14:19:0810#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 Jones348d9772023-04-17 14:19:0822namespace commerce {
23
24CommerceInternalsUI::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 Kastingd349e8c2024-12-02 09:49:1435 const base::span<const webui::ResourcePath> resources(
Matt Jones348d9772023-04-17 14:19:0836 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 Jones845bbf832024-06-26 16:30:1545 weak_factory_.GetWeakPtr()));
Matt Jones348d9772023-04-17 14:19:0846}
47
48CommerceInternalsUI::~CommerceInternalsUI() {
49 web_ui()->GetWebState()->GetInterfaceBinderForMainFrame()->RemoveInterface(
50 "commerce_internals.mojom.CommerceInternalsHandlerFactory");
51}
52
53} // namespace commerce