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") ...@@ -7,7 +7,10 @@ import("//tools/polymer/polymer.gni")
group("closure_compile") { group("closure_compile") {
deps = [ "sync_confirmation:closure_compile" ] deps = [ "sync_confirmation:closure_compile" ]
if (!is_chromeos) { 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 @@ ...@@ -2,63 +2,58 @@
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */ * found in the LICENSE file. */
cr.define('signin.error', function() { (function() {
'use strict'; function initialize() {
document.addEventListener('keydown', onKeyDown);
function initialize() { $('confirmButton').addEventListener('click', onConfirm);
document.addEventListener('keydown', onKeyDown); $('closeButton').addEventListener('click', onConfirm);
$('confirmButton').addEventListener('click', onConfirm); $('switchButton').addEventListener('click', onSwitchToExistingProfile);
$('closeButton').addEventListener('click', onConfirm); $('learnMoreLink').addEventListener('click', onLearnMore);
$('switchButton').addEventListener('click', onSwitchToExistingProfile); if (loadTimeData.getBoolean('isSystemProfile')) {
$('learnMoreLink').addEventListener('click', onLearnMore); $('learnMoreLink').hidden = true;
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 onConfirm(e) { cr.addWebUIListener('clear-focus', clearFocus);
chrome.send('confirm'); 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) { function onConfirm(e) {
chrome.send('switchToExistingProfile'); chrome.send('confirm');
} }
function onLearnMore(e) { function onSwitchToExistingProfile(e) {
chrome.send('learnMore'); chrome.send('switchToExistingProfile');
} }
function clearFocus() { function onLearnMore(e) {
document.activeElement.blur(); chrome.send('learnMore');
} }
function removeSwitchButton() { function clearFocus() {
$('switchButton').hidden = true; document.activeElement.blur();
$('closeButton').hidden = true; }
$('confirmButton').hidden = false;
}
return { function removeSwitchButton() {
initialize: initialize, $('switchButton').hidden = true;
clearFocus: clearFocus, $('closeButton').hidden = true;
removeSwitchButton: removeSwitchButton $('confirmButton').hidden = false;
}; }
});
document.addEventListener('DOMContentLoaded', signin.error.initialize); document.addEventListener('DOMContentLoaded', initialize);
})();
...@@ -86,7 +86,7 @@ void SigninErrorHandler::HandleInitializedWithSize( ...@@ -86,7 +86,7 @@ void SigninErrorHandler::HandleInitializedWithSize(
const base::ListValue* args) { const base::ListValue* args) {
AllowJavascript(); AllowJavascript();
if (duplicate_profile_path_.empty()) if (duplicate_profile_path_.empty())
CallJavascriptFunction("signin.error.removeSwitchButton"); FireWebUIListener("switch-button-unavailable");
signin::SetInitializedModalHeight(browser_, web_ui(), args); signin::SetInitializedModalHeight(browser_, web_ui(), args);
...@@ -95,7 +95,7 @@ void SigninErrorHandler::HandleInitializedWithSize( ...@@ -95,7 +95,7 @@ void SigninErrorHandler::HandleInitializedWithSize(
// TODO(anthonyvd): Figure out why this is needed on Mac and not other // 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 // platforms and if there's a way to start unfocused while avoiding this
// workaround. // workaround.
CallJavascriptFunction("signin.error.clearFocus"); FireWebUIListener("clear-focus");
} }
void SigninErrorHandler::CloseDialog() { 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