Commit 1b2a2c18 authored by David Roger's avatar David Roger Committed by Commit Bot

[signin] Implement basic functionality for signin interception bubble

This CL adds strings and buttons to the signin interception WebUI bubble

Screenshot with this CL:
https://drive.google.com/file/d/1dpWiA-o3ktL5eRaYqMt2kMd2h7IC09t_/view?usp=sharing

Mock:
https://drive.google.com/file/d/134DKn6B_QIX2rJ91kSWS4zpRpm3XUmy5/view?usp=sharing

Bug: 1076880
Change-Id: Ib0d4d2e3768bf2cbcb92beb335de8e87cd6f8c9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2279751
Commit-Queue: David Roger <droger@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarAlex Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789423}
parent 2de0b2cf
...@@ -701,6 +701,13 @@ Chromium is unable to recover your settings. ...@@ -701,6 +701,13 @@ Chromium is unable to recover your settings.
</message> </message>
</if> </if>
<!-- Dice Web Signin Interception Bubble-->
<if expr="not chromeos and not is_android">
<message name="IDS_SIGNIN_DICE_WEB_INTERCEPT_ENTERPRISE_BUBBLE_DESC" desc="Body of the web signin interception bubble">
You signed in with a work account. Would you like to create a new Chromium Profile for Work to keep your data separate?
</message>
</if>
<!-- Chrome Cleanup prompt. <!-- Chrome Cleanup prompt.
Note: these strings should only be used by Google Chrome, but Note: these strings should only be used by Google Chrome, but
omitting them brings up a hash collision error. --> omitting them brings up a hash collision error. -->
......
5b9b6af71c9cb4fced7472e927c8a4e695a34e62
\ No newline at end of file
...@@ -7745,6 +7745,18 @@ the Bookmarks menu."> ...@@ -7745,6 +7745,18 @@ the Bookmarks menu.">
Cancel sign in Cancel sign in
</message> </message>
<!-- Dice Web Signin Interception Bubble-->
<if expr="not chromeos and not is_android">
<message name="IDS_SIGNIN_DICE_WEB_INTERCEPT_ENTERPRISE_BUBBLE_TITLE" desc="Title of the web signin interception bubble">
Create Work Profile?
</message>
<message name="IDS_SIGNIN_DICE_WEB_INTERCEPT_BUBBLE_NEW_PROFILE_BUTTON_LABEL" desc="Label of the confirmation button in the web signin interception bubble">
New Profile
</message>
<message name="IDS_SIGNIN_DICE_WEB_INTERCEPT_BUBBLE_CANCEL_BUTTON_LABEL" desc="Label of the cancel button in the web signin interception bubble">
Cancel
</message>
</if>
<!-- Signin Error tab modal dialog --> <!-- Signin Error tab modal dialog -->
<message name="IDS_SIGNIN_ERROR_TITLE" desc="Title of the signin error tab modal dialog."> <message name="IDS_SIGNIN_ERROR_TITLE" desc="Title of the signin error tab modal dialog.">
......
5b9b6af71c9cb4fced7472e927c8a4e695a34e62
\ No newline at end of file
5b9b6af71c9cb4fced7472e927c8a4e695a34e62
\ No newline at end of file
...@@ -708,6 +708,13 @@ Google Chrome is unable to recover your settings. ...@@ -708,6 +708,13 @@ Google Chrome is unable to recover your settings.
</message> </message>
</if> </if>
<!-- Dice Web Signin Interception Bubble-->
<if expr="not chromeos and not is_android">
<message name="IDS_SIGNIN_DICE_WEB_INTERCEPT_ENTERPRISE_BUBBLE_DESC" desc="Body of the web signin interception bubble">
You signed in with a work account. Would you like to create a new Chrome Profile for Work to keep your data separate?
</message>
</if>
<!-- Chrome Cleanup prompt --> <!-- Chrome Cleanup prompt -->
<if expr="is_win"> <if expr="is_win">
<message name="IDS_CHROME_CLEANUP_PROMPT_EXPLANATION" desc="Description in the Chrome Cleanup dialog that Chrome browser shows when unwanted software, like ad injectors or software that changes the user's settings without their knowledge, is found on the user's computer. Appears under the title asking 'Remove harmful software?' Actor is Chrome; we are asking, Do you want Chrome to remove harmful software? 'it' is harmful software. User has the option of clicking 'Remove' to proceed with a cleanup, or 'Details' to see more details. The description is also shown on the Chrome Cleanup section of the Settings page, under 'Remove harmful software' title. Preferrably, the translation for this string should parallel IDS_SETTINGS_RESET_CLEANUP_EXPLANATION_CURRENTLY_REMOVING."> <message name="IDS_CHROME_CLEANUP_PROMPT_EXPLANATION" desc="Description in the Chrome Cleanup dialog that Chrome browser shows when unwanted software, like ad injectors or software that changes the user's settings without their knowledge, is found on the user's computer. Appears under the title asking 'Remove harmful software?' Actor is Chrome; we are asking, Do you want Chrome to remove harmful software? 'it' is harmful software. User has the option of clicking 'Remove' to proceed with a cleanup, or 'Details' to see more details. The description is also shown on the Chrome Cleanup section of the Settings page, under 'Remove harmful software' title. Preferrably, the translation for this string should parallel IDS_SETTINGS_RESET_CLEANUP_EXPLANATION_CURRENTLY_REMOVING.">
......
5b9b6af71c9cb4fced7472e927c8a4e695a34e62
\ No newline at end of file
...@@ -191,6 +191,8 @@ ...@@ -191,6 +191,8 @@
</if> </if>
<if expr="is_win or is_macosx or desktop_linux"> <if expr="is_win or is_macosx or desktop_linux">
<include name="IDR_SIGNIN_DICE_WEB_INTERCEPT_HTML" file="resources\signin\dice_web_signin_intercept\dice_web_signin_intercept.html" type="BINDATA" /> <include name="IDR_SIGNIN_DICE_WEB_INTERCEPT_HTML" file="resources\signin\dice_web_signin_intercept\dice_web_signin_intercept.html" type="BINDATA" />
<include name="IDR_SIGNIN_DICE_WEB_INTERCEPT_APP_JS" file="${root_gen_dir}\chrome\browser\resources\signin\dice_web_signin_intercept\dice_web_signin_intercept_app.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_SIGNIN_DICE_WEB_INTERCEPT_BROWSER_PROXY_JS" file="resources/signin/dice_web_signin_intercept/dice_web_signin_intercept_browser_proxy.js" type="BINDATA" />
<include name="IDR_SIGNIN_EMAIL_CONFIRMATION_HTML" file="resources\signin\signin_email_confirmation\signin_email_confirmation.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_SIGNIN_EMAIL_CONFIRMATION_HTML" file="resources\signin\signin_email_confirmation\signin_email_confirmation.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_SIGNIN_EMAIL_CONFIRMATION_APP_JS" file="${root_gen_dir}\chrome\browser\resources\signin\signin_email_confirmation\signin_email_confirmation_app.js" use_base_dir="false" preprocess="true" type="BINDATA" /> <include name="IDR_SIGNIN_EMAIL_CONFIRMATION_APP_JS" file="${root_gen_dir}\chrome\browser\resources\signin\signin_email_confirmation\signin_email_confirmation_app.js" use_base_dir="false" preprocess="true" type="BINDATA" />
<include name="IDR_SIGNIN_ERROR_HTML" file="resources\signin\signin_error\signin_error.html" type="BINDATA" /> <include name="IDR_SIGNIN_ERROR_HTML" file="resources\signin\signin_error\signin_error.html" type="BINDATA" />
......
...@@ -8,6 +8,7 @@ group("closure_compile") { ...@@ -8,6 +8,7 @@ group("closure_compile") {
deps = [ "sync_confirmation:closure_compile" ] deps = [ "sync_confirmation:closure_compile" ]
if (!is_chromeos) { if (!is_chromeos) {
deps += [ deps += [
"dice_web_signin_intercept:closure_compile",
"profile_picker:closure_compile", "profile_picker:closure_compile",
"signin_email_confirmation:closure_compile", "signin_email_confirmation:closure_compile",
"signin_error:closure_compile", "signin_error:closure_compile",
...@@ -23,6 +24,7 @@ group("web_components") { ...@@ -23,6 +24,7 @@ group("web_components") {
] ]
if (!is_chromeos) { if (!is_chromeos) {
public_deps += [ public_deps += [
"dice_web_signin_intercept:web_components",
"signin_email_confirmation:web_components", "signin_email_confirmation:web_components",
"signin_error:web_components", "signin_error:web_components",
"signin_reauth:web_components", "signin_reauth:web_components",
......
# 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.
import("//third_party/closure_compiler/compile_js.gni")
import("//tools/polymer/html_to_js.gni")
js_type_check("closure_compile") {
is_polymer3 = true
deps = [
":dice_web_signin_intercept_app",
":dice_web_signin_intercept_browser_proxy",
]
}
js_library("dice_web_signin_intercept_app") {
deps = [
":dice_web_signin_intercept_browser_proxy",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
]
}
js_library("dice_web_signin_intercept_browser_proxy") {
deps = [ "//ui/webui/resources/js:cr.m" ]
externs_list = [ "$externs_path/chrome_send.js" ]
}
html_to_js("web_components") {
js_files = [ "dice_web_signin_intercept_app.js" ]
}
...@@ -4,5 +4,7 @@ ...@@ -4,5 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
</head> </head>
<body> <body>
<dice-web-signin-intercept-app></dice-web-signin-intercept-app>
<script type="module" src="dice_web_signin_intercept_app.js"></script>
</body> </body>
</html> </html>
<div>
<h1>$i18n{diceWebSigninInterceptTitle}</h1>
<div>$i18n{diceWebSigninInterceptDesc}</div>
</div>
<div>
<cr-button id="cancelButton" on-click="onCancel_">
$i18n{diceWebSigninInterceptCancelLabel}
</cr-button>
<cr-button id="acceptButton" class="action-button" on-click="onAccept_"
autofocus>
$i18n{diceWebSigninInterceptAcceptLabel}
</cr-button>
</div>
// 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.
import 'chrome://resources/cr_elements/cr_button/cr_button.m.js';
import './strings.m.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {DiceWebSigninInterceptBrowserProxy, DiceWebSigninInterceptBrowserProxyImpl} from './dice_web_signin_intercept_browser_proxy.js';
Polymer({
is: 'dice-web-signin-intercept-app',
_template: html`{__html_template__}`,
/** @private {?DiceWebSigninInterceptBrowserProxy} */
diceWebSigninInterceptBrowserProxy_: null,
/** @override */
attached() {
this.diceWebSigninInterceptBrowserProxy_ =
DiceWebSigninInterceptBrowserProxyImpl.getInstance();
},
/** @private */
onAccept_() {
this.diceWebSigninInterceptBrowserProxy_.accept();
},
/** @private */
onCancel_() {
this.diceWebSigninInterceptBrowserProxy_.cancel();
},
});
// 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.
/**
* @fileoverview A helper object used by the dice web signin intercept bubble to
* interact with the browser.
*/
import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';
/** @interface */
export class DiceWebSigninInterceptBrowserProxy {
/** Called when the user accepts the interception bubble. */
accept() {}
/** Called when the user cancels the interception. */
cancel() {}
}
/** @implements {DiceWebSigninInterceptBrowserProxy} */
export class DiceWebSigninInterceptBrowserProxyImpl {
/** @override */
accept() {
chrome.send('accept');
}
/** @override */
cancel() {
chrome.send('cancel');
}
}
addSingletonGetter(DiceWebSigninInterceptBrowserProxyImpl);
...@@ -2707,6 +2707,8 @@ static_library("ui") { ...@@ -2707,6 +2707,8 @@ static_library("ui") {
"webui/signin/dice_turn_sync_on_helper.h", "webui/signin/dice_turn_sync_on_helper.h",
"webui/signin/dice_turn_sync_on_helper_delegate_impl.cc", "webui/signin/dice_turn_sync_on_helper_delegate_impl.cc",
"webui/signin/dice_turn_sync_on_helper_delegate_impl.h", "webui/signin/dice_turn_sync_on_helper_delegate_impl.h",
"webui/signin/dice_web_signin_intercept_handler.cc",
"webui/signin/dice_web_signin_intercept_handler.h",
"webui/signin/dice_web_signin_intercept_ui.cc", "webui/signin/dice_web_signin_intercept_ui.cc",
"webui/signin/dice_web_signin_intercept_ui.h", "webui/signin/dice_web_signin_intercept_ui.h",
] ]
......
// 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_handler.h"
#include "base/bind.h"
#include "content/public/browser/web_ui.h"
DiceWebSigninInterceptHandler::DiceWebSigninInterceptHandler(
base::OnceCallback<void(bool)> callback)
: callback_(std::move(callback)) {
DCHECK(callback_);
}
DiceWebSigninInterceptHandler::~DiceWebSigninInterceptHandler() = default;
void DiceWebSigninInterceptHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"accept",
base::BindRepeating(&DiceWebSigninInterceptHandler::HandleAccept,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"cancel",
base::BindRepeating(&DiceWebSigninInterceptHandler::HandleCancel,
base::Unretained(this)));
}
void DiceWebSigninInterceptHandler::HandleAccept(const base::ListValue* args) {
if (callback_)
std::move(callback_).Run(true);
}
void DiceWebSigninInterceptHandler::HandleCancel(const base::ListValue* args) {
if (callback_)
std::move(callback_).Run(false);
}
// 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.
#ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_DICE_WEB_SIGNIN_INTERCEPT_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SIGNIN_DICE_WEB_SIGNIN_INTERCEPT_HANDLER_H_
#include "content/public/browser/web_ui_message_handler.h"
#include "base/callback.h"
namespace base {
class ListValue;
}
// WebUI message handler for the Dice web signin intercept bubble.
class DiceWebSigninInterceptHandler : public content::WebUIMessageHandler {
public:
explicit DiceWebSigninInterceptHandler(
base::OnceCallback<void(bool)> callback);
~DiceWebSigninInterceptHandler() override;
DiceWebSigninInterceptHandler(const DiceWebSigninInterceptHandler&) = delete;
DiceWebSigninInterceptHandler& operator=(
const DiceWebSigninInterceptHandler&) = delete;
// content::WebUIMessageHandler:
void RegisterMessages() override;
private:
void HandleAccept(const base::ListValue* args);
void HandleCancel(const base::ListValue* args);
base::OnceCallback<void(bool)> callback_;
};
#endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_DICE_WEB_SIGNIN_INTERCEPT_HANDLER_H_
...@@ -5,23 +5,59 @@ ...@@ -5,23 +5,59 @@
#include "chrome/browser/ui/webui/signin/dice_web_signin_intercept_ui.h" #include "chrome/browser/ui/webui/signin/dice_web_signin_intercept_ui.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/signin/dice_web_signin_intercept_handler.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
#include "chrome/grit/browser_resources.h" #include "chrome/grit/browser_resources.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "services/network/public/mojom/content_security_policy.mojom.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/resources/grit/webui_resources.h"
DiceWebSigninInterceptUI::DiceWebSigninInterceptUI(content::WebUI* web_ui) DiceWebSigninInterceptUI::DiceWebSigninInterceptUI(content::WebUI* web_ui)
: content::WebUIController(web_ui) { : content::WebUIController(web_ui) {
content::WebUIDataSource* html_source = content::WebUIDataSource::Create( content::WebUIDataSource* source = content::WebUIDataSource::Create(
chrome::kChromeUIDiceWebSigninInterceptHost); chrome::kChromeUIDiceWebSigninInterceptHost);
html_source->SetDefaultResource(IDR_SIGNIN_DICE_WEB_INTERCEPT_HTML); source->SetDefaultResource(IDR_SIGNIN_DICE_WEB_INTERCEPT_HTML);
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); 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);
// Localized strings.
source->UseStringsJs();
source->EnableReplaceI18nInJS();
static constexpr webui::LocalizedString kLocalizedStrings[] = {
{"diceWebSigninInterceptTitle",
IDS_SIGNIN_DICE_WEB_INTERCEPT_ENTERPRISE_BUBBLE_TITLE},
{"diceWebSigninInterceptDesc",
IDS_SIGNIN_DICE_WEB_INTERCEPT_ENTERPRISE_BUBBLE_DESC},
{"diceWebSigninInterceptAcceptLabel",
IDS_SIGNIN_DICE_WEB_INTERCEPT_BUBBLE_NEW_PROFILE_BUTTON_LABEL},
{"diceWebSigninInterceptCancelLabel",
IDS_SIGNIN_DICE_WEB_INTERCEPT_BUBBLE_CANCEL_BUTTON_LABEL},
};
webui::AddLocalizedStringsBulk(source, kLocalizedStrings);
// Resources for testing.
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src chrome://resources chrome://test 'self';");
source->AddResourcePath("test_loader.js", IDR_WEBUI_JS_TEST_LOADER);
source->AddResourcePath("test_loader.html", IDR_WEBUI_HTML_TEST_LOADER);
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
} }
DiceWebSigninInterceptUI::~DiceWebSigninInterceptUI() = default; DiceWebSigninInterceptUI::~DiceWebSigninInterceptUI() = default;
void DiceWebSigninInterceptUI::Initialize( void DiceWebSigninInterceptUI::Initialize(
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
// TODO(droger): add a handler and call the callback based on user action. web_ui()->AddMessageHandler(
std::make_unique<DiceWebSigninInterceptHandler>(std::move(callback)));
} }
WEB_UI_CONTROLLER_TYPE_IMPL(DiceWebSigninInterceptUI) WEB_UI_CONTROLLER_TYPE_IMPL(DiceWebSigninInterceptUI)
// 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.
import 'chrome://signin-dice-web-intercept/dice_web_signin_intercept_app.js';
import {DiceWebSigninInterceptBrowserProxyImpl} from 'chrome://signin-dice-web-intercept/dice_web_signin_intercept_browser_proxy.js';
import {isVisible} from '../test_util.m.js';
import {TestDiceWebSigninInterceptBrowserProxy} from './test_dice_web_signin_intercept_browser_proxy.js';
suite('DiceWebSigninInterceptTest', function() {
/** @type {DiceWebSigninInterceptAppElement} */
let app;
/** @type {TestDiceWebSigninInterceptBrowserProxy} */
let browserProxy;
setup(function() {
browserProxy = new TestDiceWebSigninInterceptBrowserProxy();
DiceWebSigninInterceptBrowserProxyImpl.instance_ = browserProxy;
document.body.innerHTML = '';
app = document.createElement('dice-web-signin-intercept-app');
document.body.append(app);
});
test('ClickAccept', function() {
assertTrue(isVisible(app.$.acceptButton));
app.$.acceptButton.click();
return browserProxy.whenCalled('accept');
});
test('ClickCancel', function() {
assertTrue(isVisible(app.$.cancelButton));
app.$.cancelButton.click();
return browserProxy.whenCalled('cancel');
});
});
...@@ -66,3 +66,20 @@ var SigninReauthTest = class extends SigninBrowserTest { ...@@ -66,3 +66,20 @@ var SigninReauthTest = class extends SigninBrowserTest {
TEST_F('SigninReauthTest', 'Dialog', function() { TEST_F('SigninReauthTest', 'Dialog', function() {
mocha.run(); mocha.run();
}); });
/**
* Test fixture for
* chrome/browser/resources/signin/dice_web_signin_intercept/dice_web_signin_intercept.html.
* This has to be declared as a variable for TEST_F to find it correctly.
*/
// eslint-disable-next-line no-var
var DiceWebSigninInterceptTest = class extends SigninBrowserTest {
/** @override */
get browsePreload() {
return 'chrome://signin-dice-web-intercept/test_loader.html?module=signin/dice_web_signin_intercept_test.js';
}
};
TEST_F('DiceWebSigninInterceptTest', 'Bubble', function() {
mocha.run();
});
// 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.
import {TestBrowserProxy} from 'chrome://test/test_browser_proxy.m.js';
/** @implements {DiceWebSigninInterceptBrowserProxy} */
export class TestDiceWebSigninInterceptBrowserProxy extends TestBrowserProxy {
constructor() {
super(['accept', 'cancel']);
}
/** @override */
accept() {
this.methodCalled('accept');
}
/** @override */
cancel() {
this.methodCalled('cancel');
}
}
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