Add infrastructure for an internals page for commerce
This patch adds the infra for a basic internals page that currently
just displays the current signed-in user's eligibility for the
shopping list feature. This functions on both content/ based builds
and iOS. The content/ side includes a browser test to ensure the
page actually loads.
Bug: b:274621159
Change-Id: I1ce5ec79b2dbb63981736eea1a28b5b8cf1478b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4389124
Reviewed-by: Colin Blundell <[email protected]>
Commit-Queue: Matthew Jones <[email protected]>
Reviewed-by: Sylvain Defresne <[email protected]>
Reviewed-by: Yue Zhang <[email protected]>
Reviewed-by: Zhiyuan Cai <[email protected]>
Reviewed-by: Dominic Farolino <[email protected]>
Reviewed-by: Dana Fried <[email protected]>
Reviewed-by: John Lee <[email protected]>
Code-Coverage: Findit <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1131205}
diff --git a/components/commerce/ios/browser/commerce_internals_ui.mm b/components/commerce/ios/browser/commerce_internals_ui.mm
new file mode 100644
index 0000000..5a6baf0
--- /dev/null
+++ b/components/commerce/ios/browser/commerce_internals_ui.mm
@@ -0,0 +1,52 @@
+// Copyright 2023 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "components/commerce/ios/browser/commerce_internals_ui.h"
+
+#import "components/commerce/core/commerce_constants.h"
+#import "components/commerce/core/shopping_service.h"
+#import "components/grit/commerce_internals_resources.h"
+#import "components/grit/commerce_internals_resources_map.h"
+#import "ios/web/public/browser_state.h"
+#import "ios/web/public/web_state.h"
+#import "ios/web/public/webui/web_ui_ios.h"
+#import "ios/web/public/webui/web_ui_ios_data_source.h"
+#import "ui/base/webui/resource_path.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+namespace commerce {
+
+CommerceInternalsUI::CommerceInternalsUI(web::WebUIIOS* web_ui,
+ const std::string& host,
+ ShoppingService* shopping_service)
+ : CommerceInternalsUIBase(shopping_service),
+ web::WebUIIOSController(web_ui, host) {
+ web::BrowserState* browser_state = web_ui->GetWebState()->GetBrowserState();
+
+ web::WebUIIOSDataSource* source =
+ web::WebUIIOSDataSource::Create(kChromeUICommerceInternalsHost);
+ source->SetDefaultResource(IDR_COMMERCE_INTERNALS_COMMERCE_INTERNALS_HTML);
+ source->UseStringsJs();
+ const base::span<const webui::ResourcePath> resources = base::make_span(
+ kCommerceInternalsResources, kCommerceInternalsResourcesSize);
+
+ for (const auto& resource : resources) {
+ source->AddResourcePath(resource.path, resource.id);
+ }
+
+ web::WebUIIOSDataSource::Add(browser_state, source);
+ web_ui->GetWebState()->GetInterfaceBinderForMainFrame()->AddInterface(
+ base::BindRepeating(&CommerceInternalsUI::BindInterface,
+ base::Unretained(this)));
+}
+
+CommerceInternalsUI::~CommerceInternalsUI() {
+ web_ui()->GetWebState()->GetInterfaceBinderForMainFrame()->RemoveInterface(
+ "commerce_internals.mojom.CommerceInternalsHandlerFactory");
+}
+
+} // namespace commerce