From 5ca29b004c5a5efce17fb9278416ba58c83d46e6 Mon Sep 17 00:00:00 2001 From: Jan Henning Date: Thu, 7 Feb 2019 20:41:16 +0000 Subject: [PATCH] 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 --- mobile/android/chrome/geckoview/geckoview.js | 26 +++++++++++++++++++ .../modules/{ => geckoview}/DelayedInit.jsm | 0 mobile/android/modules/geckoview/moz.build | 1 + mobile/android/modules/moz.build | 1 - 4 files changed, 27 insertions(+), 1 deletion(-) rename mobile/android/modules/{ => geckoview}/DelayedInit.jsm (100%) diff --git a/mobile/android/chrome/geckoview/geckoview.js b/mobile/android/chrome/geckoview/geckoview.js index e2375d75066d..23d3fbe45f0e 100644 --- a/mobile/android/chrome/geckoview/geckoview.js +++ b/mobile/android/chrome/geckoview/geckoview.js @@ -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(); diff --git a/mobile/android/modules/DelayedInit.jsm b/mobile/android/modules/geckoview/DelayedInit.jsm similarity index 100% rename from mobile/android/modules/DelayedInit.jsm rename to mobile/android/modules/geckoview/DelayedInit.jsm diff --git a/mobile/android/modules/geckoview/moz.build b/mobile/android/modules/geckoview/moz.build index c65db65177d4..c00380403955 100644 --- a/mobile/android/modules/geckoview/moz.build +++ b/mobile/android/modules/geckoview/moz.build @@ -7,6 +7,7 @@ EXTRA_JS_MODULES += [ 'AndroidLog.jsm', 'ContentCrashHandler.jsm', + 'DelayedInit.jsm', 'GeckoViewAccessibility.jsm', 'GeckoViewAutoFill.jsm', 'GeckoViewChildModule.jsm', diff --git a/mobile/android/modules/moz.build b/mobile/android/modules/moz.build index a15e1ee2886b..2208905283e4 100644 --- a/mobile/android/modules/moz.build +++ b/mobile/android/modules/moz.build @@ -24,7 +24,6 @@ EXTRA_JS_MODULES += [ 'ActionBarHandler.jsm', 'BrowserActions.jsm', 'dbg-browser-actors.js', - 'DelayedInit.jsm', 'DownloadNotifications.jsm', 'FormAssistant.jsm', 'FxAccountsWebChannel.jsm',