Commit 4c5e2d15 authored by dpapad's avatar dpapad Committed by Commit Bot

Replace CallJavascriptFunction with FireWebUIListener in sync-confirmation.

This is in preparation of migrating this UI to Polymer3/JS Modules, in which
global namespaces like sync.confirmation will not exist.

Bug: 1012533
Change-Id: I7fb3f6f3767a760d09c827acec133ef3f2c020f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1853804
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarThomas Tangl <tangltom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705013}
parent 31819d24
...@@ -6,6 +6,7 @@ cr.define('sync.confirmation', function() { ...@@ -6,6 +6,7 @@ cr.define('sync.confirmation', function() {
'use strict'; 'use strict';
function initialize() { function initialize() {
cr.addWebUIListener('clear-focus', clearFocus);
const syncConfirmationBrowserProxy = const syncConfirmationBrowserProxy =
sync.confirmation.SyncConfirmationBrowserProxyImpl.getInstance(); sync.confirmation.SyncConfirmationBrowserProxyImpl.getInstance();
// Prefer using |document.body.offsetHeight| instead of // Prefer using |document.body.offsetHeight| instead of
...@@ -24,7 +25,6 @@ cr.define('sync.confirmation', function() { ...@@ -24,7 +25,6 @@ cr.define('sync.confirmation', function() {
} }
return { return {
clearFocus: clearFocus,
initialize: initialize, initialize: initialize,
}; };
}); });
......
...@@ -43,6 +43,7 @@ cr.define('sync.confirmation', function() { ...@@ -43,6 +43,7 @@ cr.define('sync.confirmation', function() {
} }
function initialize() { function initialize() {
cr.addWebUIListener('clear-focus', clearFocus);
document.addEventListener('keydown', onKeyDown); document.addEventListener('keydown', onKeyDown);
$('confirmButton').addEventListener('click', onConfirm); $('confirmButton').addEventListener('click', onConfirm);
$('undoButton').addEventListener('click', onUndo); $('undoButton').addEventListener('click', onUndo);
...@@ -67,11 +68,7 @@ cr.define('sync.confirmation', function() { ...@@ -67,11 +68,7 @@ cr.define('sync.confirmation', function() {
} }
} }
// TODO(tangltom): clearFocus is called directly by the C++ handler. return {initialize: initialize};
// C++ handlers should not be calling JS functions by name anymore. They
// should be firing events with FireWebuiListener and have the page itself
// decide whether to listen or not listen to the event.
return {clearFocus: clearFocus, initialize: initialize};
}); });
document.addEventListener('DOMContentLoaded', sync.confirmation.initialize); document.addEventListener('DOMContentLoaded', sync.confirmation.initialize);
...@@ -211,6 +211,8 @@ void SyncConfirmationHandler::CloseModalSigninWindow( ...@@ -211,6 +211,8 @@ void SyncConfirmationHandler::CloseModalSigninWindow(
void SyncConfirmationHandler::HandleInitializedWithSize( void SyncConfirmationHandler::HandleInitializedWithSize(
const base::ListValue* args) { const base::ListValue* args) {
AllowJavascript();
if (!browser_) if (!browser_)
return; return;
...@@ -237,5 +239,5 @@ void SyncConfirmationHandler::HandleInitializedWithSize( ...@@ -237,5 +239,5 @@ void SyncConfirmationHandler::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.
web_ui()->CallJavascriptFunctionUnsafe("sync.confirmation.clearFocus"); FireWebUIListener("clear-focus");
} }
...@@ -225,8 +225,9 @@ TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReady) { ...@@ -225,8 +225,9 @@ TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReady) {
handler()->HandleInitializedWithSize(&args); handler()->HandleInitializedWithSize(&args);
ExpectAccountImageChanged(*web_ui()->call_data()[0]); ExpectAccountImageChanged(*web_ui()->call_data()[0]);
EXPECT_EQ("sync.confirmation.clearFocus", EXPECT_EQ("cr.webUIListenerCallback",
web_ui()->call_data()[1]->function_name()); web_ui()->call_data()[1]->function_name());
EXPECT_EQ("clear-focus", web_ui()->call_data()[1]->arg1()->GetString());
} }
TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReadyLater) { TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReadyLater) {
...@@ -236,8 +237,9 @@ TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReadyLater) { ...@@ -236,8 +237,9 @@ TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReadyLater) {
EXPECT_EQ(2U, web_ui()->call_data().size()); EXPECT_EQ(2U, web_ui()->call_data().size());
ExpectAccountImageChanged(*web_ui()->call_data()[0]); ExpectAccountImageChanged(*web_ui()->call_data()[0]);
EXPECT_EQ("sync.confirmation.clearFocus", EXPECT_EQ("cr.webUIListenerCallback",
web_ui()->call_data()[1]->function_name()); web_ui()->call_data()[1]->function_name());
EXPECT_EQ("clear-focus", web_ui()->call_data()[1]->arg1()->GetString());
identity_test_env()->SimulateSuccessfulFetchOfAccountInfo( identity_test_env()->SimulateSuccessfulFetchOfAccountInfo(
account_info_.account_id, account_info_.email, account_info_.gaia, "", account_info_.account_id, account_info_.email, account_info_.gaia, "",
......
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