1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
// Copyright 2019 The Chromium Authors
// 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/ash/account_manager/account_migration_welcome_ui.h"
#include <memory>
#include <string>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/strings/utf_string_conversions.h"
#include "build/branding_buildflags.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/signin/ash/inline_login_dialog.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h"
#include "components/account_manager_core/account_manager_facade.h"
#include "components/account_manager_core/chromeos/account_manager_facade_factory.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui_data_source.h"
#include "net/base/url_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/web_dialogs/web_dialog_delegate.h"
#include "ui/webui/webui_util.h"
namespace ash {
namespace {
class MigrationMessageHandler : public content::WebUIMessageHandler {
public:
explicit MigrationMessageHandler(base::RepeatingClosure close_dialog_closure)
: close_dialog_closure_(close_dialog_closure) {}
MigrationMessageHandler(const MigrationMessageHandler&) = delete;
MigrationMessageHandler& operator=(const MigrationMessageHandler&) = delete;
~MigrationMessageHandler() override = default;
private:
void RegisterMessages() override {
web_ui()->RegisterMessageCallback(
"reauthenticateAccount",
base::BindRepeating(
&MigrationMessageHandler::HandleReauthenticateAccount,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"closeDialog",
base::BindRepeating(&MigrationMessageHandler::HandleCloseDialog,
base::Unretained(this)));
}
// WebUI "reauthenticateAccount" message callback.
void HandleReauthenticateAccount(const base::Value::List& args) {
AllowJavascript();
CHECK(!args.empty());
const std::string& account_email = args[0].GetString();
Profile* profile = Profile::FromWebUI(web_ui());
::GetAccountManagerFacade(profile->GetPath().value())
->ShowReauthAccountDialog(
account_manager::AccountManagerFacade::AccountAdditionSource::
kAccountManagerMigrationWelcomeScreen,
account_email, base::DoNothing());
HandleCloseDialog(args);
}
void HandleCloseDialog(const base::Value::List& args) {
AllowJavascript();
close_dialog_closure_.Run();
}
base::RepeatingClosure close_dialog_closure_;
};
} // namespace
AccountMigrationWelcomeUI::AccountMigrationWelcomeUI(content::WebUI* web_ui)
: ui::WebDialogUI(web_ui) {
content::WebUIDataSource* html_source =
content::WebUIDataSource::CreateAndAdd(
Profile::FromWebUI(web_ui),
chrome::kChromeUIAccountMigrationWelcomeHost);
webui::SetJSModuleDefaults(html_source);
webui::EnableTrustedTypesCSP(html_source);
// Add localized strings.
html_source->AddLocalizedString("welcomePageTitle",
IDS_ACCOUNT_MIGRATION_WELCOME_PAGE_TITLE);
html_source->AddLocalizedString("welcomeTitle",
IDS_ACCOUNT_MIGRATION_WELCOME_TITLE);
html_source->AddLocalizedString("welcomeMessage",
IDS_ACCOUNT_MIGRATION_WELCOME_TEXT);
html_source->AddLocalizedString("cancelButton", IDS_APP_CANCEL);
html_source->AddLocalizedString("migrateButton",
IDS_ACCOUNT_MIGRATION_UPDATE_BUTTON);
html_source->AddString("accountManagerLearnMoreUrl",
chrome::kAccountManagerLearnMoreURL);
// Add required resources.
html_source->AddResourcePath("account_migration_welcome_app.js",
IDR_ACCOUNT_MIGRATION_WELCOME_APP_JS);
html_source->AddResourcePath("account_migration_welcome_app.html.js",
IDR_ACCOUNT_MIGRATION_WELCOME_APP_HTML_JS);
html_source->AddResourcePath("account_manager_shared.css.js",
IDR_ACCOUNT_MANAGER_SHARED_CSS_JS);
html_source->AddResourcePath("account_manager_browser_proxy.js",
IDR_ACCOUNT_MANAGER_BROWSER_PROXY_JS);
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
html_source->AddResourcePath("account_manager_welcome_1x.png",
IDR_ACCOUNT_MANAGER_WELCOME_1X_PNG);
html_source->AddResourcePath("account_manager_welcome_2x.png",
IDR_ACCOUNT_MANAGER_WELCOME_2X_PNG);
html_source->AddResourcePath("googleg.svg",
IDR_ACCOUNT_MANAGER_WELCOME_GOOGLE_LOGO_SVG);
#endif
html_source->SetDefaultResource(IDR_ACCOUNT_MIGRATION_WELCOME_HTML);
web_ui->AddMessageHandler(std::make_unique<MigrationMessageHandler>(
base::BindRepeating(&WebDialogUI::CloseDialog, weak_factory_.GetWeakPtr(),
base::Value::List() /* args */)));
}
AccountMigrationWelcomeUI::~AccountMigrationWelcomeUI() = default;
} // namespace ash
|