Bug 1674317 - Load about:home scripts via the subscript loader when hitting the about:home startup cache. r=k88hudson

Using the subscript loader is currently our best way of getting the loaded scripts recorded for entry
in the ScriptPreloader which is used to cache startup-related JavaScript within the startup window.

Originally, we were using <script> tags to load those scripts, but unfortunately, that loading mechanism
does not qualify for being noted by the ScriptPreloader.

This is a workaround until the Stencil project by the SpiderMonkey team Phase 2 is complete (see bug 1663956),
which should allow us to more easily note scripts to cache at runtime.

Differential Revision: https://phabricator.services.mozilla.com/D95407
This commit is contained in:
Mike Conley 2020-11-03 20:54:55 +00:00
Родитель 374fd58ddd
Коммит e5905f10e5
5 изменённых файлов: 14 добавлений и 23 удалений

Просмотреть файл

@ -48,17 +48,6 @@ class AboutNewTabChild extends JSWindowActorChild {
return;
}
// In the event that the document that was loaded here was the cached
// about:home document, then there's nothing further to do - the page
// will load its scripts itself.
//
// Note that it's okay to waive the xray wrappers here since this actor
// is registered to only run in the privileged about content process from
// about:home, about:newtab and about:welcome.
if (ChromeUtils.waiveXrays(this.contentWindow).__FROM_STARTUP_CACHE__) {
return;
}
const debug = !AppConstants.RELEASE_OR_BETA && ACTIVITY_STREAM_DEBUG;
const debugString = debug ? "-dev" : "";

Просмотреть файл

@ -38,16 +38,6 @@
{{ MARKUP }}
</div>
<div id="footer-asrouter-container" role="presentation"></div>
<script src="chrome://browser/content/contentSearchUI.js"></script>
<script src="chrome://browser/content/contentSearchHandoffUI.js"></script>
<script src="chrome://browser/content/contentTheme.js"></script>
<script src="resource://activity-stream/vendor/react.js"></script>
<script src="resource://activity-stream/vendor/react-dom.js"></script>
<script src="resource://activity-stream/vendor/prop-types.js"></script>
<script src="resource://activity-stream/vendor/redux.js"></script>
<script src="resource://activity-stream/vendor/react-redux.js"></script>
<script src="resource://activity-stream/vendor/react-transition-group.js"></script>
<script src="resource://activity-stream/data/content/activity-stream.bundle.js"></script>
<script src="about:home?jscache"></script>
</body>
</html>

Просмотреть файл

@ -15,4 +15,5 @@
#
#endif
window.__FROM_STARTUP_CACHE__ = true;
window.NewtabRenderUtils.renderCache({{ STATE }});
window.__STARTUP_STATE__ = {{ STATE }};

Просмотреть файл

@ -4,4 +4,8 @@
"use strict";
// exported by activity-stream.bundle.js
window.NewtabRenderUtils.renderWithoutState();
if (window.__FROM_STARTUP_CACHE__) {
window.NewtabRenderUtils.renderCache(window.__STARTUP_STATE__);
} else {
window.NewtabRenderUtils.renderWithoutState();
}

Просмотреть файл

@ -40,6 +40,8 @@ ChromeUtils.defineModuleGetter(
XPCOMUtils.defineLazyGlobalGetters(this, ["DOMParser"]);
const CACHE_WORKER_URL = "resource://activity-stream/lib/cache-worker.js";
const NEWTAB_RENDER_URL =
"resource://activity-stream/data/content/newtab-render.js";
/**
* In order to make this test less brittle, much of Activity Stream is
@ -175,6 +177,11 @@ add_task(async function test_cache_worker() {
},
};
Cu.evalInSandbox(script, sandbox);
// The NEWTAB_RENDER_URL script is what ultimately causes the state
// to be passed into the renderCache function.
Services.scriptloader.loadSubScript(NEWTAB_RENDER_URL, sandbox);
equal(
sandbox.window.__FROM_STARTUP_CACHE__,
true,