blob: 09d0d158e68ae58cf4f04a567c6ddc6328d437db [file] [log] [blame]
// Copyright 2020 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 "chrome/browser/ui/webui/signin/dice_web_signin_intercept_ui.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/webui/signin/dice_web_signin_intercept_handler.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "services/network/public/mojom/content_security_policy.mojom.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/resources/grit/webui_generated_resources.h"
#include "ui/resources/grit/webui_resources.h"
DiceWebSigninInterceptUI::DiceWebSigninInterceptUI(content::WebUI* web_ui)
: content::WebUIController(web_ui) {
content::WebUIDataSource* source = content::WebUIDataSource::Create(
chrome::kChromeUIDiceWebSigninInterceptHost);
source->SetDefaultResource(IDR_SIGNIN_DICE_WEB_INTERCEPT_HTML);
source->AddResourcePath("dice_web_signin_intercept_app.js",
IDR_SIGNIN_DICE_WEB_INTERCEPT_APP_JS);
source->AddResourcePath("dice_web_signin_intercept_browser_proxy.js",
IDR_SIGNIN_DICE_WEB_INTERCEPT_BROWSER_PROXY_JS);
source->AddResourcePath("signin_shared_css.js", IDR_SIGNIN_SHARED_CSS_JS);
source->AddResourcePath("signin_vars_css.js", IDR_SIGNIN_VARS_CSS_JS);
source->AddLocalizedString("guestLink",
IDS_SIGNIN_DICE_WEB_INTERCEPT_BUBBLE_GUEST_LINK);
source->UseStringsJs();
// Resources for testing.
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src chrome://resources chrome://test 'self';");
source->DisableTrustedTypesCSP();
source->AddResourcePath("test_loader.js", IDR_WEBUI_JS_TEST_LOADER_JS);
source->AddResourcePath("test_loader.html", IDR_WEBUI_HTML_TEST_LOADER_HTML);
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
}
DiceWebSigninInterceptUI::~DiceWebSigninInterceptUI() = default;
void DiceWebSigninInterceptUI::Initialize(
const DiceWebSigninInterceptor::Delegate::BubbleParameters&
bubble_parameters,
base::OnceCallback<void(SigninInterceptionUserChoice)> callback) {
web_ui()->AddMessageHandler(std::make_unique<DiceWebSigninInterceptHandler>(
bubble_parameters, std::move(callback)));
}
WEB_UI_CONTROLLER_TYPE_IMPL(DiceWebSigninInterceptUI)