Skip to content

Commit fbd2441

Browse files
committed
Bug 1817443 - remove openUILinkIn entirely and rename fromChrome, r=mossop,extension-reviewers,rpl
'fromChrome' really meant "force tabs to open in the foreground", so let's rename it accordingly. This removes the attempt to document arguments for openUILinkIn. I'll add documentation back on the end of this stack, for openLinkIn, when various bits are reorganized anyway. Differential Revision: https://phabricator.services.mozilla.com/D170384
1 parent 3e5d710 commit fbd2441

File tree

11 files changed

+50
-146
lines changed

11 files changed

+50
-146
lines changed

browser/base/content/browser-menubar.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@
504504
hidden="true"/>
505505
<menuitem id="helpPolicySupport"
506506
hidden="true"
507-
oncommand="openUILinkIn(Services.policies.getSupportMenu().URL.href, 'tab', {triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({})});"/>
507+
oncommand="openTrustedLinkIn(Services.policies.getSupportMenu().URL.href, 'tab');"/>
508508
</menupopup>
509509
</menu>
510510
</menubar>

browser/base/content/test/about/browser_aboutNewTab_bookmarksToolbarNewWindow.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ async function test_bookmarks_toolbar_visibility({ newTabEnabled }) {
3333
let newWindowOpened = BrowserTestUtils.domWindowOpened();
3434
let beforeShown = TestUtils.topicObserved("browser-window-before-show");
3535

36-
let triggeringPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
37-
openUILinkIn(url, "window", { triggeringPrincipal });
36+
openTrustedLinkIn(url, "window");
3837

3938
let newWin = await newWindowOpened;
4039
let slowSiteLoaded = BrowserTestUtils.firstBrowserLoaded(newWin, false);

browser/base/content/utilityOverlay.js

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -120,64 +120,12 @@ function whereToOpenLink(e, ignoreButton, ignoreAlt) {
120120
return BrowserUtils.whereToOpenLink(e, ignoreButton, ignoreAlt);
121121
}
122122

123-
/* openTrustedLinkIn will attempt to open the given URI using the SystemPrincipal
124-
* as the trigeringPrincipal, unless a more specific Principal is provided.
125-
*
126-
* See openUILinkIn for a discussion of parameters
127-
*/
128-
function openTrustedLinkIn(url, where, aParams) {
129-
var params = aParams;
130-
131-
if (!params) {
132-
params = {};
133-
}
134-
135-
if (!params.triggeringPrincipal) {
136-
params.triggeringPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
137-
}
138-
139-
openUILinkIn(url, where, params);
123+
function openTrustedLinkIn(url, where, params) {
124+
URILoadingHelper.openTrustedLinkIn(window, url, where, params);
140125
}
141126

142-
/* openWebLinkIn will attempt to open the given URI using the NullPrincipal
143-
* as the triggeringPrincipal, unless a more specific Principal is provided.
144-
*
145-
* See openUILinkIn for a discussion of parameters
146-
*/
147127
function openWebLinkIn(url, where, params) {
148-
if (!params) {
149-
params = {};
150-
}
151-
152-
if (!params.triggeringPrincipal) {
153-
params.triggeringPrincipal = Services.scriptSecurityManager.createNullPrincipal(
154-
{}
155-
);
156-
}
157-
if (params.triggeringPrincipal.isSystemPrincipal) {
158-
throw new Error(
159-
"System principal should never be passed into openWebLinkIn()"
160-
);
161-
}
162-
163-
openUILinkIn(url, where, params);
164-
}
165-
166-
function openUILinkIn(
167-
url,
168-
where,
169-
aAllowThirdPartyFixup,
170-
aPostData,
171-
aReferrerInfo
172-
) {
173-
return URILoadingHelper.openUILinkIn(
174-
window,
175-
url,
176-
where,
177-
aAllowThirdPartyFixup,
178-
aPostData,
179-
aReferrerInfo
180-
);
128+
URILoadingHelper.openWebLinkIn(window, url, where, params);
181129
}
182130

183131
function openLinkIn(url, where, params) {

browser/components/newtab/lib/PlacesFeed.jsm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class PlacesFeed {
233233
const params = {
234234
private: isPrivate,
235235
targetBrowser: action._target.browser,
236-
fromChrome: false, // This ensure we maintain user preference for how to open new tabs.
236+
forceForeground: false, // This ensure we maintain user preference for how to open new tabs.
237237
globalHistoryOptions: {
238238
triggeringSponsoredURL: action.data.sponsored_tile_id
239239
? action.data.url

browser/components/newtab/test/unit/lib/PlacesFeed.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ describe("PlacesFeed", () => {
282282
assert.equal(url, "https://foo.com");
283283
assert.equal(where, "window");
284284
assert.propertyVal(params, "private", false);
285-
assert.propertyVal(params, "fromChrome", false);
285+
assert.propertyVal(params, "forceForeground", false);
286286
});
287287
it("should call openTrustedLinkIn with the correct url, where, params and privacy args on OPEN_PRIVATE_WINDOW", () => {
288288
const openTrustedLinkIn = sinon.stub();
@@ -299,7 +299,7 @@ describe("PlacesFeed", () => {
299299
assert.equal(url, "https://foo.com");
300300
assert.equal(where, "window");
301301
assert.propertyVal(params, "private", true);
302-
assert.propertyVal(params, "fromChrome", false);
302+
assert.propertyVal(params, "forceForeground", false);
303303
});
304304
it("should call openTrustedLinkIn with the correct url, where and params on OPEN_LINK", () => {
305305
const openTrustedLinkIn = sinon.stub();
@@ -320,7 +320,7 @@ describe("PlacesFeed", () => {
320320
assert.equal(url, "https://foo.com");
321321
assert.equal(where, "current");
322322
assert.propertyVal(params, "private", false);
323-
assert.propertyVal(params, "fromChrome", false);
323+
assert.propertyVal(params, "forceForeground", false);
324324
});
325325
it("should open link with referrer on OPEN_LINK", () => {
326326
const openTrustedLinkIn = sinon.stub();

browser/components/places/PlacesUIUtils.sys.mjs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ export var PlacesUIUtils = {
11721172

11731173
/**
11741174
* Loads the node's URL in the appropriate tab or window.
1175-
* see also openUILinkIn
1175+
* see also URILoadingHelper's openWebLinkIn
11761176
*
11771177
* @param {object} aNode
11781178
* An uri result node.
@@ -1840,21 +1840,17 @@ export var PlacesUIUtils = {
18401840
);
18411841
break;
18421842
case "placesCmd_open:privatewindow":
1843-
window.openUILinkIn(this.triggerNode.link, "window", {
1844-
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
1843+
window.openTrustedLinkIn(this.triggerNode.link, "window", {
18451844
private: true,
18461845
});
18471846
break;
18481847
case "placesCmd_open:window":
1849-
window.openUILinkIn(this.triggerNode.link, "window", {
1850-
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
1848+
window.openTrustedLinkIn(this.triggerNode.link, "window", {
18511849
private: false,
18521850
});
18531851
break;
18541852
case "placesCmd_open:tab": {
1855-
window.openUILinkIn(this.triggerNode.link, "tab", {
1856-
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
1857-
});
1853+
window.openTrustedLinkIn(this.triggerNode.link, "tab");
18581854
}
18591855
}
18601856
},

browser/components/textrecognition/textrecognition.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class TextRecognitionModal {
139139
this.linkEl.addEventListener("click", event => {
140140
event.preventDefault();
141141
this.openLinkIn(this.linkEl.href, "tab", {
142-
fromChrome: true,
142+
forceForeground: true,
143143
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
144144
});
145145
});

browser/components/urlbar/QuickSuggest.sys.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,7 @@ class _QuickSuggest {
420420
switch (params.choice) {
421421
case ONBOARDING_CHOICE.LEARN_MORE_1:
422422
case ONBOARDING_CHOICE.LEARN_MORE_2:
423-
win.openTrustedLinkIn(this.HELP_URL, "tab", {
424-
fromChrome: true,
425-
});
423+
win.openTrustedLinkIn(this.HELP_URL, "tab");
426424
break;
427425
case ONBOARDING_CHOICE.ACCEPT_2:
428426
case ONBOARDING_CHOICE.REJECT_2:

browser/modules/URILoadingHelper.sys.mjs

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const URILoadingHelper = {
2929
return;
3030
}
3131

32-
var aFromChrome = params.fromChrome;
32+
var aForceForeground = params.forceForeground;
3333
var aAllowThirdPartyFixup = params.allowThirdPartyFixup;
3434
var aPostData = params.postData;
3535
var aCharset = params.charset;
@@ -326,7 +326,7 @@ export const URILoadingHelper = {
326326
// `where` is "tab" or "tabshifted", so we'll load the link in a new tab.
327327
loadInBackground = aInBackground;
328328
if (loadInBackground == null) {
329-
loadInBackground = aFromChrome
329+
loadInBackground = aForceForeground
330330
? false
331331
: Services.prefs.getBoolPref("browser.tabs.loadInBackground");
332332
}
@@ -506,7 +506,7 @@ export const URILoadingHelper = {
506506
* @param {Event | Object} event Event or JSON object representing an Event
507507
* @param {Boolean | Object} aIgnoreButton
508508
* Boolean or object with the same properties as
509-
* accepted by openUILinkIn, plus "ignoreButton"
509+
* accepted by openLinkIn, plus "ignoreButton"
510510
* and "ignoreAlt".
511511
* @param {Boolean} aIgnoreAlt
512512
* @param {Boolean} aAllowThirdPartyFixup
@@ -529,7 +529,7 @@ export const URILoadingHelper = {
529529
if (aIgnoreButton && typeof aIgnoreButton == "object") {
530530
params = aIgnoreButton;
531531

532-
// don't forward "ignoreButton" and "ignoreAlt" to openUILinkIn
532+
// don't forward "ignoreButton" and "ignoreAlt" to openLinkIn
533533
aIgnoreButton = params.ignoreButton;
534534
aIgnoreAlt = params.ignoreAlt;
535535
delete params.ignoreButton;
@@ -550,66 +550,43 @@ export const URILoadingHelper = {
550550
}
551551

552552
let where = BrowserUtils.whereToOpenLink(event, aIgnoreButton, aIgnoreAlt);
553-
this.openUILinkIn(window, url, where, params);
553+
params.forceForeground ??= true;
554+
this.openLinkIn(window, url, where, params);
554555
},
555556

556-
/* openUILinkIn opens a URL in a place specified by the parameter |where|.
557-
*
558-
* |where| can be:
559-
* "current" current tab (if there aren't any browser windows, then in a new window instead)
560-
* "tab" new tab (if there aren't any browser windows, then in a new window instead)
561-
* "tabshifted" same as "tab" but in background if default is to select new tabs, and vice versa
562-
* "window" new window
563-
* "save" save to disk (with no filename hint!)
564-
*
565-
* DEPRECATION WARNING:
566-
* USE -> openTrustedLinkIn(url, where, aParams) if the source is always
567-
* a user event on a user- or product-specified URL (as
568-
* opposed to URLs provided by a webpage)
569-
* USE -> openWebLinkIn(url, where, aParams) if the URI should be loaded
570-
* with a specific triggeringPrincipal, for instance, if
571-
* the url was supplied by web content.
572-
* DEPRECATED -> openUILinkIn(url, where, AllowThirdPartyFixup, aPostData, ...)
557+
/* openTrustedLinkIn will attempt to open the given URI using the SystemPrincipal
558+
* as the trigeringPrincipal, unless a more specific Principal is provided.
573559
*
574-
*
575-
* allowThirdPartyFixup controls whether third party services such as Google's
576-
* I Feel Lucky are allowed to interpret this URL. This parameter may be
577-
* undefined, which is treated as false.
578-
*
579-
* Instead of aAllowThirdPartyFixup, you may also pass an object with any of
580-
* these properties:
581-
* allowThirdPartyFixup (boolean)
582-
* fromChrome (boolean)
583-
* postData (nsIInputStream)
584-
* referrerInfo (nsIReferrerInfo)
585-
* relatedToCurrent (boolean)
586-
* skipTabAnimation (boolean)
587-
* allowPinnedTabHostChange (boolean)
588-
* allowPopups (boolean)
589-
* userContextId (unsigned int)
590-
* targetBrowser (XUL browser)
560+
* Otherwise, parameters are the same as openLinkIn, but we will set `forceForeground`
561+
* to true.
591562
*/
592-
openUILinkIn(
593-
window,
594-
url,
595-
where,
596-
aAllowThirdPartyFixup,
597-
aPostData,
598-
aReferrerInfo
599-
) {
600-
var params;
563+
openTrustedLinkIn(window, url, where, params = {}) {
564+
if (!params.triggeringPrincipal) {
565+
params.triggeringPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
566+
}
567+
568+
params.forceForeground ??= true;
569+
this.openLinkIn(window, url, where, params);
570+
},
601571

602-
if (typeof aAllowThirdPartyFixup == "object") {
603-
params = aAllowThirdPartyFixup;
572+
/* openWebLinkIn will attempt to open the given URI using the NullPrincipal
573+
* as the triggeringPrincipal, unless a more specific Principal is provided.
574+
*
575+
* Otherwise, parameters are the same as openLinkIn, but we will set `forceForeground`
576+
* to true.
577+
*/
578+
openWebLinkIn(window, url, where, params = {}) {
579+
if (!params.triggeringPrincipal) {
580+
params.triggeringPrincipal = Services.scriptSecurityManager.createNullPrincipal(
581+
{}
582+
);
604583
}
605-
if (!params || !params.triggeringPrincipal) {
584+
if (params.triggeringPrincipal.isSystemPrincipal) {
606585
throw new Error(
607-
"Required argument triggeringPrincipal missing within openUILinkIn"
586+
"System principal should never be passed into openWebLinkIn()"
608587
);
609588
}
610-
611-
params.fromChrome = params.fromChrome ?? true;
612-
589+
params.forceForeground ??= true;
613590
this.openLinkIn(window, url, where, params);
614591
},
615592
};

toolkit/modules/ResetProfile.sys.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ export var ResetProfile = {
9191
if (params.learnMore) {
9292
win.openTrustedLinkIn(
9393
"https://support.mozilla.org/kb/refresh-firefox-reset-add-ons-and-settings",
94-
"tab",
95-
{
96-
fromChrome: true,
97-
}
94+
"tab"
9895
);
9996
return;
10097
}

toolkit/mozapps/extensions/content/aboutaddons.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -698,12 +698,7 @@ class SearchAddons extends HTMLElement {
698698

699699
let browser = getBrowserElement();
700700
let chromewin = browser.ownerGlobal;
701-
chromewin.openLinkIn(url, "tab", {
702-
fromChrome: true,
703-
triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal(
704-
{}
705-
),
706-
});
701+
chromewin.openWebLinkIn(url, "tab");
707702

708703
AMTelemetry.recordLinkEvent({
709704
object: "aboutAddons",
@@ -2714,13 +2709,7 @@ class AddonCard extends HTMLElement {
27142709
break;
27152710
case "contribute":
27162711
this.recordActionEvent("contribute");
2717-
// prettier-ignore
2718-
windowRoot.ownerGlobal.openUILinkIn(addon.contributionURL, "tab", {
2719-
triggeringPrincipal:
2720-
Services.scriptSecurityManager.createNullPrincipal(
2721-
{}
2722-
),
2723-
});
2712+
windowRoot.ownerGlobal.openWebLinkIn(addon.contributionURL, "tab");
27242713
break;
27252714
case "preferences":
27262715
if (getOptionsType(addon) == "tab") {

0 commit comments

Comments
 (0)