Bug 1496684 - Dispatch commonly expected startup notifications when opening a GeckoView window. r=snorp

Once a webextension using a blocking WebRequest listener has started loading,
all network connections covered by the extension's manifest are held until the
extension is ready the process them.
One condition for the extension being ready apparently includes browser startup
having progressed far enough, as signified by "browser-delayed-startup-finished"
having been dispatched.
Therefore, we have to start sending that notification when opening a new Gecko-
View window, too, and copy Fennec's InitLater() system for that.

Unlike Fennec, we cannot tie registration of those InitLater() runnables to the
initial content load having progressed far enough because of
a) e10s, which makes that approach neither easily possible nor really sensible,
   as content will load in a different process in that case, and
b) because we're racing with extension startup here - if extensions are loaded
   quick enough to block even the initial page load, we'd be deadlocked: We
   cannot send the notification until the page finishes loading, but the page
   cannot load until we send the notification. Fennec isn't affected by the
   latter problem because "sessionstore-windows-restored", which Fennec will
   send in any case, serves as an alternative pathway for completing extension
   startup.

And unlike Desktop, we don't really have any chrome content to paint, so we
cannot tie delayed initialisation to a paint listener for that, either.

Therefore, we simply fire off a runnable at the *end* of geckoview.js's
startup() method, which should give more pressing initialisation tasks enough of
a headstart.

For completeness, we're also adding the "browser-idle-startup-tasks-finished"
notification and thereby solve bug 1465832 as well, allowing the ScriptPreloader
to detect which scripts are commonly loaded during GeckoView startup and to
start caching and pre-parsing them.

Differential Revision: https://phabricator.services.mozilla.com/D18865

--HG--
rename : mobile/android/modules/DelayedInit.jsm => mobile/android/modules/geckoview/DelayedInit.jsm
extra : moz-landing-system : lando
This commit is contained in:
Jan Henning 2019-02-07 20:41:16 +00:00
Родитель 574677d5a2
Коммит 5ca29b004c
4 изменённых файлов: 27 добавлений и 1 удалений

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

@ -4,6 +4,7 @@
"use strict";
var {DelayedInit} = ChromeUtils.import("resource://gre/modules/DelayedInit.jsm");
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
@ -392,6 +393,10 @@ function createBrowser() {
return browser;
}
function InitLater(fn, object, name) {
return DelayedInit.schedule(fn, object, name, 15000 /* 15s max wait */);
}
function startup() {
GeckoViewUtils.initLogging("XUL", window);
@ -453,6 +458,27 @@ function startup() {
},
}]);
Services.tm.dispatchToMainThread(() => {
// This should always be the first thing we do here - any additional delayed
// initialisation tasks should be added between "browser-delayed-startup-finished"
// and "browser-idle-startup-tasks-finished".
// Bug 1496684: Various bits of platform stuff depend on this notification
// to learn when a browser window has finished its initial (chrome)
// initialisation, especially with regards to the very first window that is
// created. Therefore, GeckoView "windows" need to send this, too.
InitLater(() => Services.obs.notifyObservers(window, "browser-delayed-startup-finished"));
// This should always go last, since the idle tasks (except for the ones with
// timeouts) should execute in order. Note that this observer notification is
// not guaranteed to fire, since the window could close before we get here.
// This notification in particular signals the ScriptPreloader that we have
// finished startup, so it can now stop recording script usage and start
// updating the startup cache for faster script loading.
InitLater(() => Services.obs.notifyObservers(window, "browser-idle-startup-tasks-finished"));
});
// Move focus to the content window at the end of startup,
// so things like text selection can work properly.
browser.focus();

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

@ -7,6 +7,7 @@
EXTRA_JS_MODULES += [
'AndroidLog.jsm',
'ContentCrashHandler.jsm',
'DelayedInit.jsm',
'GeckoViewAccessibility.jsm',
'GeckoViewAutoFill.jsm',
'GeckoViewChildModule.jsm',

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

@ -24,7 +24,6 @@ EXTRA_JS_MODULES += [
'ActionBarHandler.jsm',
'BrowserActions.jsm',
'dbg-browser-actors.js',
'DelayedInit.jsm',
'DownloadNotifications.jsm',
'FormAssistant.jsm',
'FxAccountsWebChannel.jsm',