Commit 0b203c85 authored by Rachel Carpenter's avatar Rachel Carpenter Committed by Commit Bot

Add guest ui to the Help App.

This allows our client code (coming) to load in a sandboxed iframe.

Bug: 1012578, b/144121590
Change-Id: I0e3a1442a9d2959652a36737b8b22abd4d633de9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1904552
Commit-Queue: Rachel Carpenter <carpenterr@google.com>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714727}
parent 060cd8bf
......@@ -8,6 +8,8 @@ assert(is_chromeos, "Help App is Chrome OS only")
static_library("help_app_ui") {
sources = [
"help_app_guest_ui.cc",
"help_app_guest_ui.h",
"help_app_ui.cc",
"help_app_ui.h",
"url_constants.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/components/help_app_ui/help_app_guest_ui.h"
#include "chromeos/components/help_app_ui/url_constants.h"
#include "chromeos/grit/chromeos_help_app_resources.h"
#include "content/public/browser/web_ui_data_source.h"
namespace chromeos {
// static
content::WebUIDataSource* CreateHelpAppGuestDataSource() {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(kChromeUIHelpAppGuestHost);
source->AddResourcePath("app.html", IDR_HELP_APP_APP_HTML);
source->AddResourcePath("js/bootstrap.js", IDR_HELP_APP_BOOTSTRAP_JS);
// TODO(crbug.com/1023700): Better solution before launch.
source->DisableDenyXFrameOptions();
return source;
}
} // namespace chromeos
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_HELP_APP_UI_HELP_APP_GUEST_UI_H_
#define CHROMEOS_COMPONENTS_HELP_APP_UI_HELP_APP_GUEST_UI_H_
namespace content {
class WebUIDataSource;
}
namespace chromeos {
// The data source creation for chrome://help-app-guest.
content::WebUIDataSource* CreateHelpAppGuestDataSource();
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_HELP_APP_UI_HELP_APP_GUEST_UI_H_
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "chromeos/components/help_app_ui/help_app_ui.h"
#include "chromeos/components/help_app_ui/help_app_guest_ui.h"
#include "chromeos/components/help_app_ui/url_constants.h"
#include "chromeos/grit/chromeos_help_app_resources.h"
......@@ -13,7 +14,7 @@
namespace chromeos {
namespace {
content::WebUIDataSource* CreateDataSource() {
content::WebUIDataSource* CreateHostDataSource() {
auto* source = content::WebUIDataSource::Create(kChromeUIHelpAppHost);
// TODO(crbug.com/1012578): This is a placeholder only, update with the
......@@ -27,8 +28,16 @@ content::WebUIDataSource* CreateDataSource() {
} // namespace
HelpAppUI::HelpAppUI(content::WebUI* web_ui) : MojoWebUIController(web_ui) {
content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(),
CreateDataSource());
content::BrowserContext* browser_context =
web_ui->GetWebContents()->GetBrowserContext();
content::WebUIDataSource* host_source = CreateHostDataSource();
content::WebUIDataSource::Add(browser_context, host_source);
// We need a CSP override to use the guest origin in the host.
std::string csp = std::string("frame-src ") + kChromeUIHelpAppGuestURL + ";";
host_source->OverrideContentSecurityPolicyChildSrc(csp);
content::WebUIDataSource* guest_source = CreateHelpAppGuestDataSource();
content::WebUIDataSource::Add(browser_context, guest_source);
}
HelpAppUI::~HelpAppUI() = default;
......
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<!DOCTYPE html>
<style>
body {
margin: 0;
}
</style>
<script src="/js/bootstrap.js"></script>
<!-- TODO(crbug/1012578): Include scripts to run in the <iframe> sandbox that
communicate via postMessage to scripts running in index.html -->
......@@ -14,6 +14,8 @@
<release seq="1">
<includes>
<!-- TODO(crbug.com/1012578): Add the run time resources .grdp here. -->
<include name="IDR_HELP_APP_APP_HTML" file="app.html"
type="BINDATA" />
<include name="IDR_HELP_APP_INDEX_HTML" file="index.html"
type="BINDATA" />
<include name="IDR_HELP_APP_PWA_HTML" file="pwa.html" type="BINDATA" />
......@@ -21,6 +23,9 @@
type="BINDATA" />
<include name="IDR_HELP_APP_ICON_192" file="app_icon_192.png"
type="BINDATA" />
<include name="IDR_HELP_APP_BOOTSTRAP_JS"
file="js/bootstrap.js"
type="BINDATA" />
</includes>
</release>
</grit>
......@@ -4,5 +4,21 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Help App</title>
<style>
body {
height: 100vh;
margin: 0;
overflow: hidden;
}
/*
* This is the <iframe> style set for sandboxed guests that use
* guest_view_iframe_container.js.
*/
iframe {
border: 0;
height: 100%;
width: 100%;
}
</style>
<script src="chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js"></script>
<!-- TODO(crbug/1012578): Add sandboxed guest with content in an iframe. -->
<iframe src="chrome://help-app-guest/app.html"></iframe>
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// TODO(crbug/1012578): Pull in resources for app correctly.
......@@ -9,6 +9,7 @@
GEN('#include "chromeos/constants/chromeos_features.h"');
const HOST_ORIGIN = 'chrome://help-app';
const GUEST_ORIGIN = 'chrome://help-app-guest';
var HelpAppUIBrowserTest = class extends testing.Test {
/** @override */
......@@ -29,5 +30,8 @@ var HelpAppUIBrowserTest = class extends testing.Test {
// Tests that chrome://help-app goes somewhere instead of 404ing or crashing.
TEST_F('HelpAppUIBrowserTest', 'HasChromeSchemeURL', () => {
const guest = document.querySelector('iframe');
assertEquals(document.location.origin, HOST_ORIGIN);
assertEquals(guest.src, GUEST_ORIGIN + "/app.html");
});
......@@ -8,5 +8,7 @@ namespace chromeos {
const char kChromeUIHelpAppHost[] = "help-app";
const char kChromeUIHelpAppURL[] = "chrome://help-app/";
const char kChromeUIHelpAppGuestHost[] = "help-app-guest";
const char kChromeUIHelpAppGuestURL[] = "chrome://help-app-guest/";
} // namespace chromeos
......@@ -9,6 +9,8 @@ namespace chromeos {
extern const char kChromeUIHelpAppHost[];
extern const char kChromeUIHelpAppURL[];
extern const char kChromeUIHelpAppGuestHost[];
extern const char kChromeUIHelpAppGuestURL[];
} // namespace chromeos
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment