Commit d2d564df authored by dpapad's avatar dpapad Committed by Commit Bot

Enable JS type-checking for signin-error WebUI dialog.

Also removing calls to CallJavascriptFunctionUnsafe()
in the process, replacing with FireWebUIListener().

This is in preparation of migrating to Polymer 3.

Bug: 1012533
Change-Id: I01bd5afcac01db2a9827846b165be7d36d16b376
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2128972
Commit-Queue: David Roger <droger@chromium.org>
Auto-Submit: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754841}
parent 43a49df1
......@@ -7,7 +7,10 @@ import("//tools/polymer/polymer.gni")
group("closure_compile") {
deps = [ "sync_confirmation:closure_compile" ]
if (!is_chromeos) {
deps += [ "signin_email_confirmation:closure_compile" ]
deps += [
"signin_email_confirmation:closure_compile",
"signin_error:closure_compile",
]
}
}
......
# 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")
js_type_check("closure_compile") {
deps = [ ":signin_error" ]
}
js_library("signin_error") {
deps = [
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:load_time_data",
"//ui/webui/resources/js:util",
]
}
......@@ -2,63 +2,58 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */
cr.define('signin.error', function() {
'use strict';
function initialize() {
document.addEventListener('keydown', onKeyDown);
$('confirmButton').addEventListener('click', onConfirm);
$('closeButton').addEventListener('click', onConfirm);
$('switchButton').addEventListener('click', onSwitchToExistingProfile);
$('learnMoreLink').addEventListener('click', onLearnMore);
if (loadTimeData.getBoolean('isSystemProfile')) {
$('learnMoreLink').hidden = true;
}
// Prefer using |document.body.offsetHeight| instead of
// |document.body.scrollHeight| as it returns the correct height of the
// even when the page zoom in Chrome is different than 100%.
chrome.send('initializedWithSize', [document.body.offsetHeight]);
}
function onKeyDown(e) {
// If the currently focused element isn't something that performs an action
// on "enter" being pressed and the user hits "enter", perform the default
// action of the dialog, which is "OK".
if (e.key == 'Enter' &&
!/^(A|CR-BUTTON)$/.test(document.activeElement.tagName)) {
$('confirmButton').click();
e.preventDefault();
}
(function() {
function initialize() {
document.addEventListener('keydown', onKeyDown);
$('confirmButton').addEventListener('click', onConfirm);
$('closeButton').addEventListener('click', onConfirm);
$('switchButton').addEventListener('click', onSwitchToExistingProfile);
$('learnMoreLink').addEventListener('click', onLearnMore);
if (loadTimeData.getBoolean('isSystemProfile')) {
$('learnMoreLink').hidden = true;
}
function onConfirm(e) {
chrome.send('confirm');
cr.addWebUIListener('clear-focus', clearFocus);
cr.addWebUIListener('switch-button-unavailable', removeSwitchButton);
// Prefer using |document.body.offsetHeight| instead of
// |document.body.scrollHeight| as it returns the correct height of the
// even when the page zoom in Chrome is different than 100%.
chrome.send('initializedWithSize', [document.body.offsetHeight]);
}
function onKeyDown(e) {
// If the currently focused element isn't something that performs an action
// on "enter" being pressed and the user hits "enter", perform the default
// action of the dialog, which is "OK".
if (e.key == 'Enter' &&
!/^(A|CR-BUTTON)$/.test(document.activeElement.tagName)) {
$('confirmButton').click();
e.preventDefault();
}
}
function onSwitchToExistingProfile(e) {
chrome.send('switchToExistingProfile');
}
function onConfirm(e) {
chrome.send('confirm');
}
function onLearnMore(e) {
chrome.send('learnMore');
}
function onSwitchToExistingProfile(e) {
chrome.send('switchToExistingProfile');
}
function clearFocus() {
document.activeElement.blur();
}
function onLearnMore(e) {
chrome.send('learnMore');
}
function removeSwitchButton() {
$('switchButton').hidden = true;
$('closeButton').hidden = true;
$('confirmButton').hidden = false;
}
function clearFocus() {
document.activeElement.blur();
}
return {
initialize: initialize,
clearFocus: clearFocus,
removeSwitchButton: removeSwitchButton
};
});
function removeSwitchButton() {
$('switchButton').hidden = true;
$('closeButton').hidden = true;
$('confirmButton').hidden = false;
}
document.addEventListener('DOMContentLoaded', signin.error.initialize);
document.addEventListener('DOMContentLoaded', initialize);
})();
......@@ -86,7 +86,7 @@ void SigninErrorHandler::HandleInitializedWithSize(
const base::ListValue* args) {
AllowJavascript();
if (duplicate_profile_path_.empty())
CallJavascriptFunction("signin.error.removeSwitchButton");
FireWebUIListener("switch-button-unavailable");
signin::SetInitializedModalHeight(browser_, web_ui(), args);
......@@ -95,7 +95,7 @@ void SigninErrorHandler::HandleInitializedWithSize(
// TODO(anthonyvd): Figure out why this is needed on Mac and not other
// platforms and if there's a way to start unfocused while avoiding this
// workaround.
CallJavascriptFunction("signin.error.clearFocus");
FireWebUIListener("clear-focus");
}
void SigninErrorHandler::CloseDialog() {
......
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