Commit e8b27324 authored by Renato Silva's avatar Renato Silva Committed by Commit Bot

OOBE - Migrate to HTMLImports polyfill

Use the HTMLImports polyfill in OOBE to remove the dependence
on HTML imports until everything can be fully migrated to JS
modules/Polymer3.

Bug: 1111387
Change-Id: I3c760bdc5d41f57e44927363d47a5a193edd7c34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2522072
Commit-Queue: Renato Silva <rrsilva@google.com>
Auto-Submit: Renato Silva <rrsilva@google.com>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830571}
parent b88b3f35
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "google_apis/gaia/gaia_switches.h" #include "google_apis/gaia/gaia_switches.h"
...@@ -106,6 +107,12 @@ void OobeBaseTest::SetUpCommandLine(base::CommandLine* command_line) { ...@@ -106,6 +107,12 @@ void OobeBaseTest::SetUpCommandLine(base::CommandLine* command_line) {
command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); command_line->AppendSwitch(::switches::kDisableBackgroundNetworking);
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
// Blink features are controlled via a command line switch. Disable HTML
// imports which are deprecated. OOBE uses a polyfill for imports that will
// be replaced once the migration to JS modules is complete.
command_line->AppendSwitchASCII(::switches::kDisableBlinkFeatures,
"HTMLImports");
MixinBasedInProcessBrowserTest::SetUpCommandLine(command_line); MixinBasedInProcessBrowserTest::SetUpCommandLine(command_line);
} }
......
...@@ -31,6 +31,28 @@ cr.define('cr.ui', function() { ...@@ -31,6 +31,28 @@ cr.define('cr.ui', function() {
__proto__: DisplayManager.prototype, __proto__: DisplayManager.prototype,
}; };
/**
* OOBE initialization coordination. Used by tests to wait for OOBE
* to fully load when using the HTLImports polyfill.
* TODO(crbug.com/1111387) - Remove once migrated to JS modules.
* Remove spammy logging when closer to M89 branch point.
*/
Oobe.initializationComplete = false;
Oobe.initCallbacks = [];
Oobe.waitForOobeToLoad = function() {
return new Promise(function(resolve, reject) {
if (cr.ui.Oobe.initializationComplete) {
// TODO(crbug.com/1111387) - Remove excessive logging.
console.warn('OOBE is already initialized. Continuing...');
resolve();
} else {
// TODO(crbug.com/1111387) - Remove excessive logging.
console.warn('OOBE not loaded yet. Waiting...');
cr.ui.Oobe.initCallbacks.push(resolve);
}
});
};
/** /**
* Called when focus is returned from ash::SystemTray. * Called when focus is returned from ash::SystemTray.
* @param {boolean} reverse Is focus returned in reverse order? * @param {boolean} reverse Is focus returned in reverse order?
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="google" value="notranslate"> <meta name="google" value="notranslate">
<title i18n-content="title"></title> <title i18n-content="title"></title>
<script src="chrome://resources/polymer/v1_0/html-imports/html-imports.min.js"></script>
<!-- This must be the first import in all login pages. --> <!-- This must be the first import in all login pages. -->
<link rel="import" href="chrome://resources/html/polymer.html"> <link rel="import" href="chrome://resources/html/polymer.html">
......
...@@ -40,60 +40,61 @@ function ensurePinKeyboardLoaded(onLoaded) { ...@@ -40,60 +40,61 @@ function ensurePinKeyboardLoaded(onLoaded) {
setTimeout(onLoaded); setTimeout(onLoaded);
} }
cr.define('cr.ui.Oobe', function() { HTMLImports.whenReady(() => {
return { cr.define('cr.ui.Oobe', function() {
/** return {
* Initializes the OOBE flow. This will cause all C++ handlers to /**
* be invoked to do final setup. * Initializes the OOBE flow. This will cause all C++ handlers to
*/ * be invoked to do final setup.
initialize() { */
cr.ui.login.DisplayManager.initialize(); initialize() {
login.AccountPickerScreen.register(); cr.ui.login.DisplayManager.initialize();
login.AutolaunchScreen.register(); login.AccountPickerScreen.register();
login.ErrorMessageScreen.register(); login.AutolaunchScreen.register();
login.ArcTermsOfServiceScreen.register(); login.ErrorMessageScreen.register();
login.DiscoverScreen.register(); login.ArcTermsOfServiceScreen.register();
login.MultiDeviceSetupScreen.register(); login.DiscoverScreen.register();
login.MultiDeviceSetupScreen.register();
cr.ui.Bubble.decorate($('bubble-persistent'));
$('bubble-persistent').persistent = true; cr.ui.Bubble.decorate($('bubble-persistent'));
$('bubble-persistent').hideOnKeyPress = false; $('bubble-persistent').persistent = true;
$('bubble-persistent').hideOnKeyPress = false;
cr.ui.Bubble.decorate($('bubble'));
cr.ui.Bubble.decorate($('bubble'));
chrome.send('screenStateInitialize');
}, chrome.send('screenStateInitialize');
},
// Dummy Oobe functions not present with stripped login UI.
refreshA11yInfo(data) {}, // Dummy Oobe functions not present with stripped login UI.
reloadEulaContent(data) {}, refreshA11yInfo(data) {},
reloadEulaContent(data) {},
/**
* Reloads content of the page. /**
* @param {!Object} data New dictionary with i18n values. * Reloads content of the page.
*/ * @param {!Object} data New dictionary with i18n values.
reloadContent(data) { */
loadTimeData.overrideValues(data); reloadContent(data) {
i18nTemplate.process(document, loadTimeData); loadTimeData.overrideValues(data);
Oobe.getInstance().updateLocalizedContent_(); i18nTemplate.process(document, loadTimeData);
}, Oobe.getInstance().updateLocalizedContent_();
},
/**
* Updates "device in tablet mode" state when tablet mode is changed. /**
* @param {Boolean} isInTabletMode True when in tablet mode. * Updates "device in tablet mode" state when tablet mode is changed.
*/ * @param {Boolean} isInTabletMode True when in tablet mode.
setTabletModeState(isInTabletMode) { */
Oobe.getInstance().setTabletModeState_(isInTabletMode); setTabletModeState(isInTabletMode) {
}, Oobe.getInstance().setTabletModeState_(isInTabletMode);
},
/**
* Updates OOBE configuration when it is loaded. /**
* @param {!OobeTypes.OobeConfiguration} configuration OOBE configuration. * Updates OOBE configuration when it is loaded.
*/ * @param {!OobeTypes.OobeConfiguration} configuration OOBE configuration.
updateOobeConfiguration(configuration) { */
Oobe.getInstance().updateOobeConfiguration_(configuration); updateOobeConfiguration(configuration) {
}, Oobe.getInstance().updateOobeConfiguration_(configuration);
}; },
};
});
// <include src="oobe_initialization.js">
}); });
// <include src="oobe_initialization.js">
\ No newline at end of file
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="google" value="notranslate"> <meta name="google" value="notranslate">
<title i18n-content="title"></title> <title i18n-content="title"></title>
<script src="chrome://resources/polymer/v1_0/html-imports/html-imports.min.js"></script>
<!-- This must be the first import in all login pages. --> <!-- This must be the first import in all login pages. -->
<link rel="import" href="chrome://resources/html/polymer.html"> <link rel="import" href="chrome://resources/html/polymer.html">
......
...@@ -33,79 +33,80 @@ ...@@ -33,79 +33,80 @@
// <include src="multi_tap_detector.js"> // <include src="multi_tap_detector.js">
// <include src="web_view_helper.js"> // <include src="web_view_helper.js">
cr.define('cr.ui.Oobe', function() { HTMLImports.whenReady(() => {
return { cr.define('cr.ui.Oobe', function() {
/** return {
* Initializes the OOBE flow. This will cause all C++ handlers to /**
* be invoked to do final setup. * Initializes the OOBE flow. This will cause all C++ handlers to
*/ * be invoked to do final setup.
initialize() { */
cr.ui.login.DisplayManager.initialize(); initialize() {
login.AutoEnrollmentCheckScreen.register(); cr.ui.login.DisplayManager.initialize();
login.AutolaunchScreen.register(); login.AutoEnrollmentCheckScreen.register();
login.AccountPickerScreen.register(); login.AutolaunchScreen.register();
login.ErrorMessageScreen.register(); login.AccountPickerScreen.register();
login.ArcTermsOfServiceScreen.register(); login.ErrorMessageScreen.register();
login.DiscoverScreen.register(); login.ArcTermsOfServiceScreen.register();
login.MultiDeviceSetupScreen.register(); login.DiscoverScreen.register();
login.MultiDeviceSetupScreen.register();
cr.ui.Bubble.decorate($('bubble-persistent'));
$('bubble-persistent').persistent = true; cr.ui.Bubble.decorate($('bubble-persistent'));
$('bubble-persistent').hideOnKeyPress = false; $('bubble-persistent').persistent = true;
$('bubble-persistent').hideOnKeyPress = false;
cr.ui.Bubble.decorate($('bubble'));
cr.ui.Bubble.decorate($('bubble'));
chrome.send('screenStateInitialize');
}, chrome.send('screenStateInitialize');
},
/**
* Reloads content of the page (localized strings, options of the select /**
* controls). * Reloads content of the page (localized strings, options of the select
* @param {!Object} data New dictionary with i18n values. * controls).
*/ * @param {!Object} data New dictionary with i18n values.
reloadContent(data) { */
// Reload global local strings, process DOM tree again. reloadContent(data) {
loadTimeData.overrideValues(data); // Reload global local strings, process DOM tree again.
i18nTemplate.process(document, loadTimeData); loadTimeData.overrideValues(data);
i18nTemplate.process(document, loadTimeData);
// Update localized content of the screens.
Oobe.updateLocalizedContent(); // Update localized content of the screens.
}, Oobe.updateLocalizedContent();
},
/**
* Updates "device in tablet mode" state when tablet mode is changed. /**
* @param {Boolean} isInTabletMode True when in tablet mode. * Updates "device in tablet mode" state when tablet mode is changed.
*/ * @param {Boolean} isInTabletMode True when in tablet mode.
setTabletModeState(isInTabletMode) { */
Oobe.getInstance().setTabletModeState_(isInTabletMode); setTabletModeState(isInTabletMode) {
}, Oobe.getInstance().setTabletModeState_(isInTabletMode);
},
/**
* Reloads localized strings for the eula page. /**
* @param {!Object} data New dictionary with changed eula i18n values. * Reloads localized strings for the eula page.
*/ * @param {!Object} data New dictionary with changed eula i18n values.
reloadEulaContent(data) { */
loadTimeData.overrideValues(data); reloadEulaContent(data) {
i18nTemplate.process(document, loadTimeData); loadTimeData.overrideValues(data);
}, i18nTemplate.process(document, loadTimeData);
},
/**
* Updates localized content of the screens. /**
* Should be executed on language change. * Updates localized content of the screens.
*/ * Should be executed on language change.
updateLocalizedContent() { */
// Buttons, headers and links. updateLocalizedContent() {
Oobe.getInstance().updateLocalizedContent_(); // Buttons, headers and links.
}, Oobe.getInstance().updateLocalizedContent_();
},
/**
* Updates OOBE configuration when it is loaded. /**
* @param {!OobeTypes.OobeConfiguration} configuration OOBE configuration. * Updates OOBE configuration when it is loaded.
*/ * @param {!OobeTypes.OobeConfiguration} configuration OOBE configuration.
updateOobeConfiguration(configuration) { */
Oobe.getInstance().updateOobeConfiguration_(configuration); updateOobeConfiguration(configuration) {
}, Oobe.getInstance().updateOobeConfiguration_(configuration);
}; },
};
});
// <include src="oobe_initialization.js">
}); });
// <include src="oobe_initialization.js">
...@@ -28,6 +28,11 @@ function initializeOobe() { ...@@ -28,6 +28,11 @@ function initializeOobe() {
// readyForTesting even on failures, just to make test bots happy. // readyForTesting even on failures, just to make test bots happy.
Oobe.readyForTesting = true; Oobe.readyForTesting = true;
} }
// Mark initialization complete and wake any callers that might be waiting
// for OOBE to load.
cr.ui.Oobe.initializationComplete = true;
cr.ui.Oobe.initCallbacks.forEach(resolvePromise => resolvePromise());
} }
// Install a global error handler so stack traces are included in logs. // Install a global error handler so stack traces are included in logs.
...@@ -40,11 +45,18 @@ window.onerror = function(message, file, line, column, error) { ...@@ -40,11 +45,18 @@ window.onerror = function(message, file, line, column, error) {
console.warn('1082670 : cr_ui loaded'); console.warn('1082670 : cr_ui loaded');
/** /**
* Final initialization performed after DOM and all scripts have loaded. * Final initialization performed after HTML imports are loaded. Loads
* common elements used in OOBE (Custom Elements).
*/ */
if (document.readyState === 'loading') { HTMLImports.whenReady(() => {
document.addEventListener('DOMContentLoaded', initializeOobe); // TODO(crbug.com/1111387) - Remove excessive logging.
} else { console.warn('HTMLImports ready.');
initializeOobe(); loadCommonComponents();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initializeOobe);
} else {
initializeOobe();
}
});
})(); })();
...@@ -18,6 +18,15 @@ var PolymerSecurityTokenPinTest = class extends PolymerTest { ...@@ -18,6 +18,15 @@ var PolymerSecurityTokenPinTest = class extends PolymerTest {
return 'chrome://oobe/login'; return 'chrome://oobe/login';
} }
/** @override */
setUp() {
suiteSetup(async function() {
console.warn('Running suite setup..');
await cr.ui.Oobe.waitForOobeToLoad();
console.warn('OOBE has been loaded. Continuing with test.');
});
}
get extraLibraries() { get extraLibraries() {
return super.extraLibraries.concat(['components/oobe_types.js']); return super.extraLibraries.concat(['components/oobe_types.js']);
} }
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
// 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.
function loadCommonComponents() {
// TODO(crbug.com/1111387) - Remove excessive logging.
console.warn('loadCommonComponents() : Starting to load common components.');
// This inclusion is types-only. No actual code to execute. // This inclusion is types-only. No actual code to execute.
// <include src="../components/oobe_types.js"> // <include src="../components/oobe_types.js">
...@@ -51,3 +55,6 @@ ...@@ -51,3 +55,6 @@
// <include src="../screen_app_launch_splash.js"> // <include src="../screen_app_launch_splash.js">
// <include src="components_[OOBE].js"> // <include src="components_[OOBE].js">
// TODO(crbug.com/1111387) - Remove excessive logging.
console.warn('loadCommonComponents() : Common components have loaded.');
}
...@@ -1635,9 +1635,6 @@ bool ChromeContentRendererClient::RequiresHtmlImports(const GURL& url) { ...@@ -1635,9 +1635,6 @@ bool ChromeContentRendererClient::RequiresHtmlImports(const GURL& url) {
host_piece == chrome::kChromeUIMultiDeviceSetupHost || host_piece == chrome::kChromeUIMultiDeviceSetupHost ||
// TODO(crbug.com/1111852): Remove when migrated to Polymer3. // TODO(crbug.com/1111852): Remove when migrated to Polymer3.
host_piece == chrome::kChromeUINetworkHost || host_piece == chrome::kChromeUINetworkHost ||
// TODO(crbug.com/1111387): Remove when migrated away from HTML
// Imports.
host_piece == chrome::kChromeUIOobeHost ||
// TODO(crbug.com/1045266): Remove when migrated to Polymer3. // TODO(crbug.com/1045266): Remove when migrated to Polymer3.
host_piece == chrome::kChromeUIOSSettingsHost || host_piece == chrome::kChromeUIOSSettingsHost ||
// TODO(crbug.com/1022192): Remove when migrated to Polymer3. // TODO(crbug.com/1022192): Remove when migrated to Polymer3.
......
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