blob: 26b1835b3ddb54b1fa3f27ed5856e694f2c9cbc7 [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
Matt Jones348d9772023-04-17 14:19:085#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 Jones348d9772023-04-17 14:19:0817namespace commerce {
18
19CommerceInternalsUI::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 Zhang09983f42025-05-22 18:06:0730 for (const auto& resource : kCommerceInternalsResources) {
Matt Jones348d9772023-04-17 14:19:0831 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 Jones845bbf832024-06-26 16:30:1537 weak_factory_.GetWeakPtr()));
Matt Jones348d9772023-04-17 14:19:0838}
39
40CommerceInternalsUI::~CommerceInternalsUI() {
41 web_ui()->GetWebState()->GetInterfaceBinderForMainFrame()->RemoveInterface(
42 "commerce_internals.mojom.CommerceInternalsHandlerFactory");
43}
44
45} // namespace commerce