Mall: Embed Mall iframe into Mall SWA
Bug: b:336648972
Change-Id: I1dff5f5c69c51af5750fa9cfbc54fcc598963b5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5568912
Reviewed-by: Alan Cutter <alancutter@chromium.org>
Auto-Submit: Tim Sergeant <tsergeant@chromium.org>
Commit-Queue: Tim Sergeant <tsergeant@chromium.org>
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1306229}
diff --git a/ash/webui/mall/mall_ui.cc b/ash/webui/mall/mall_ui.cc
index 3ccdab6..6c9988b 100644
--- a/ash/webui/mall/mall_ui.cc
+++ b/ash/webui/mall/mall_ui.cc
@@ -6,7 +6,9 @@
#include "ash/webui/grit/ash_mall_cros_app_resources.h"
#include "ash/webui/mall/url_constants.h"
+#include "base/strings/strcat.h"
#include "chromeos/constants/chromeos_features.h"
+#include "chromeos/constants/url_constants.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui_controller.h"
#include "content/public/browser/web_ui_data_source.h"
@@ -24,8 +26,17 @@
web_ui->GetWebContents()->GetBrowserContext(), ash::kChromeUIMallHost);
source->SetDefaultResource(IDR_ASH_MALL_CROS_APP_INDEX_HTML);
+ source->AddResourcePath("index.js", IDR_ASH_MALL_CROS_APP_INDEX_JS);
source->AddResourcePath("mall_icon_192.png",
IDR_ASH_MALL_CROS_APP_IMAGES_MALL_ICON_192_PNG);
+
+ // We need a CSP override to be able to embed the Mall website, and to handle
+ // cros-apps:// links to install apps.
+ std::string csp = base::StrCat({"frame-src ", chromeos::kAppMallBaseUrl, " ",
+ chromeos::kAppInstallUriScheme, ": ",
+ chromeos::kLegacyAppInstallUriScheme, ":;"});
+ source->OverrideContentSecurityPolicy(
+ network::mojom::CSPDirectiveName::FrameSrc, csp);
}
WEB_UI_CONTROLLER_TYPE_IMPL(MallUI)
diff --git a/ash/webui/mall/resources/index.html b/ash/webui/mall/resources/index.html
index 0d9c537..a29a3e0 100644
--- a/ash/webui/mall/resources/index.html
+++ b/ash/webui/mall/resources/index.html
@@ -1 +1,21 @@
-<h1>Get Apps and Games :-)</h1>
\ No newline at end of file
+<!-- Copyright 2024 The Chromium Authors
+ Use of this source code is governed by a BSD-style license that can be
+ found in the LICENSE file. -->
+
+<style>
+ body {
+ height: 100vh;
+ margin: 0;
+ overflow: hidden;
+ }
+
+ /* index.ts appends a guest iframe to the document. */
+ iframe {
+ border: 0;
+ display: block;
+ height: 100%;
+ width: 100%;
+ }
+</style>
+
+<script src="/index.js" type="module"></script>
\ No newline at end of file
diff --git a/ash/webui/mall/resources/index.ts b/ash/webui/mall/resources/index.ts
index 1705c7a..2dfb5e5 100644
--- a/ash/webui/mall/resources/index.ts
+++ b/ash/webui/mall/resources/index.ts
@@ -1,3 +1,10 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+
+// TODO(b/342057600): Fetch iframe target from the browser process.
+const MALL_ORIGIN = 'https://discover.apps.chrome/';
+
+const mallFrame = document.createElement('iframe');
+mallFrame.src = MALL_ORIGIN;
+document.body.appendChild(mallFrame);