#include "ash/webui/annotator/untrusted_annotator_ui.h"
#include "ash/webui/grit/ash_annotator_untrusted_resources.h"
#include "ash/webui/grit/ash_annotator_untrusted_resources_map.h"
#include "ash/webui/grit/ash_projector_common_resources.h"
#include "ash/webui/grit/ash_projector_common_resources_map.h"
#include "ash/webui/media_app_ui/buildflags.h"
#include "ash/webui/projector_app/public/cpp/projector_app_constants.h"
#include "ash/webui/annotator/untrusted_annotator_page_handler_impl.h"
#include "chromeos/grit/chromeos_projector_app_bundle_resources.h"
#include "chromeos/grit/chromeos_projector_app_bundle_resources_map.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/common/url_constants.h"
#include "url/gurl.h"
#if BUILDFLAG(ENABLE_CROS_MEDIA_APP)
#include "chromeos/grit/chromeos_media_app_bundle_resources.h"
#endif
namespace ash {
namespace {
void CreateAndAddAnnotatorHTMLSource(content::WebUI* web_ui) {
content::WebUIDataSource* source = content::WebUIDataSource::CreateAndAdd(
web_ui->GetWebContents()->GetBrowserContext(),
kChromeUIUntrustedAnnotatorUrl);
source->AddResourcePaths(kAshAnnotatorUntrustedResources);
source->AddResourcePaths(kChromeosProjectorAppBundleResources);
source->AddResourcePaths(kAshProjectorCommonResources);
source->AddResourcePath("",
IDR_ASH_ANNOTATOR_UNTRUSTED_ANNOTATOR_HTML);
#if BUILDFLAG(ENABLE_CROS_MEDIA_APP)
source->AddResourcePath("ink_engine_ink.wasm",
IDR_MEDIA_APP_INK_ENGINE_INK_WASM);
source->AddResourcePath("ink.js", IDR_MEDIA_APP_INK_JS);
#endif
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src 'self' 'wasm-eval' chrome-untrusted://resources;");
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::WorkerSrc, "worker-src 'self';");
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::StyleSrc,
"style-src 'self' 'unsafe-inline';");
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ImgSrc, "img-src blob: data: 'self';");
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ConnectSrc, "connect-src 'self';");
source->OverrideCrossOriginOpenerPolicy("same-origin");
source->OverrideCrossOriginEmbedderPolicy("require-corp");
source->OverrideCrossOriginResourcePolicy("cross-origin");
source->DisableTrustedTypesCSP();
source->UseStringsJs();
}
}
UntrustedAnnotatorUI::UntrustedAnnotatorUI(content::WebUI* web_ui)
: UntrustedWebUIController(web_ui) {
CreateAndAddAnnotatorHTMLSource(web_ui);
}
UntrustedAnnotatorUI::~UntrustedAnnotatorUI() = default;
void UntrustedAnnotatorUI::BindInterface(
mojo::PendingReceiver<
annotator::mojom::UntrustedAnnotatorPageHandlerFactory> factory) {
if (receiver_.is_bound()) {
receiver_.reset();
}
receiver_.Bind(std::move(factory));
}
void UntrustedAnnotatorUI::Create(
mojo::PendingReceiver<annotator::mojom::UntrustedAnnotatorPageHandler>
annotator_handler,
mojo::PendingRemote<annotator::mojom::UntrustedAnnotatorPage> annotator) {
handler_ = std::make_unique<UntrustedAnnotatorPageHandlerImpl>(
std::move(annotator_handler), std::move(annotator), web_ui());
}
WEB_UI_CONTROLLER_TYPE_IMPL(UntrustedAnnotatorUI)
}