Bug 1810141 - fix replaceUrlInTab webextension utility to deal with loadURI changes, r=rpl

Depends on D168392

Differential Revision: https://phabricator.services.mozilla.com/D168393
This commit is contained in:
Gijs Kruitbosch
2023-02-13 23:50:39 +00:00
parent 96e3b61974
commit 64b3d90475
3 changed files with 10 additions and 6 deletions

View File

@@ -127,9 +127,9 @@ global.waitForTabLoaded = (tab, url) => {
});
};
global.replaceUrlInTab = (gBrowser, tab, url) => {
let loaded = waitForTabLoaded(tab, url);
gBrowser.loadURI(url, {
global.replaceUrlInTab = (gBrowser, tab, uri) => {
let loaded = waitForTabLoaded(tab, uri.spec);
gBrowser.loadURI(uri, {
flags: Ci.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY,
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), // This is safe from this functions usage however it would be preferred not to dot his.
});

View File

@@ -66,7 +66,7 @@ XPCOMUtils.defineLazyGetter(this, "homepagePopup", () => {
// 3. Trigger the browser's homepage method
let gBrowser = win.gBrowser;
let tab = gBrowser.selectedTab;
await replaceUrlInTab(gBrowser, tab, "about:blank");
await replaceUrlInTab(gBrowser, tab, Services.io.newURI("about:blank"));
Services.prefs.addObserver(HOMEPAGE_PREF, async function prefObserver() {
Services.prefs.removeObserver(HOMEPAGE_PREF, prefObserver);
let loaded = waitForTabLoaded(tab);

View File

@@ -58,11 +58,15 @@ XPCOMUtils.defineLazyGetter(this, "newTabPopup", () => {
// 3. Once the New Tab URL has changed, replace the tab's URL with the new New Tab URL
let gBrowser = win.gBrowser;
let tab = gBrowser.selectedTab;
await replaceUrlInTab(gBrowser, tab, "about:blank");
await replaceUrlInTab(gBrowser, tab, Services.io.newURI("about:blank"));
Services.obs.addObserver(
{
async observe() {
await replaceUrlInTab(gBrowser, tab, AboutNewTab.newTabURL);
await replaceUrlInTab(
gBrowser,
tab,
Services.io.newURI(AboutNewTab.newTabURL)
);
// Now that the New Tab is loading, try to open the popup again. This
// will only open the popup if a new extension is controlling the New Tab.
popup.open();