From 7decdccbdcc8f8c9e96477e08031de9911868b6b Mon Sep 17 00:00:00 2001 From: Butkovits Atila Date: Thu, 28 Jan 2021 07:15:59 +0200 Subject: [PATCH] Backed out 12 changesets (bug 1685801) for causing failures on browser_fission_maxOrigins.js. CLOSED TREE Backed out changeset 0d7153110519 (bug 1685801) Backed out changeset 5175062925c7 (bug 1685801) Backed out changeset 2c1250e786f0 (bug 1685801) Backed out changeset 0ce3c773ba74 (bug 1685801) Backed out changeset 9d51c6e24dee (bug 1685801) Backed out changeset 3f4dc6349441 (bug 1685801) Backed out changeset a80de9abb9f8 (bug 1685801) Backed out changeset 30786893a5e7 (bug 1685801) Backed out changeset 8007b12d6e32 (bug 1685801) Backed out changeset fa814f4b7125 (bug 1685801) Backed out changeset 14e4e47ee99f (bug 1685801) Backed out changeset d9f1feba9454 (bug 1685801) --- browser/actors/ClickHandlerChild.jsm | 10 +- browser/actors/ContextMenuChild.jsm | 10 +- browser/actors/EncryptedMediaParent.jsm | 6 +- browser/actors/FormValidationChild.jsm | 6 +- browser/actors/PluginChild.jsm | 38 +- browser/actors/PluginParent.jsm | 38 +- browser/base/content/browser-addons.js | 2 +- browser/base/content/browser-places.js | 2 +- browser/base/content/browser.js | 12 +- browser/base/content/nsContextMenu.js | 6 +- browser/base/content/tabbrowser-tab.js | 2 +- browser/components/BrowserGlue.jsm | 4 +- .../customizableui/CustomizeMode.jsm | 6 +- .../extensions/ExtensionControlledPopup.jsm | 6 +- .../components/extensions/parent/ext-tabs.js | 6 +- .../browser/browser_favicon_firstParty.js | 6 +- browser/components/pocket/content/Pocket.jsm | 6 +- .../pocket/content/SaveToPocket.jsm | 6 +- .../browser_privatebrowsing_favicon.js | 4 +- .../sessionstore/test/browser_522545.js | 2 +- browser/components/urlbar/UrlbarInput.jsm | 29 +- browser/components/urlbar/UrlbarResult.jsm | 4 +- browser/components/urlbar/UrlbarUtils.jsm | 4 +- .../urlbar/tests/UrlbarTestUtils.jsm | 4 +- .../browser/browser_UrlbarInput_trimURLs.js | 2 +- .../tests/browser/browser_edit_invalid_url.js | 2 +- .../urlbar/tests/browser/browser_stop.js | 6 +- .../tests/browser/browser_valueOnTabSwitch.js | 2 +- browser/modules/BrowserUIUtils.jsm | 204 ---- browser/modules/BrowserUsageTelemetry.jsm | 4 +- browser/modules/moz.build | 1 - .../themes/shared/toolbarbutton-icons.inc.css | 2 +- caps/nsIScriptSecurityManager.idl | 25 +- caps/nsScriptSecurityManager.cpp | 45 - caps/tests/mochitest/browser_checkloaduri.js | 8 +- .../test/general/test_bug1277803.xhtml | 53 +- .../modules/geckoview/GeckoViewProgress.jsm | 4 +- toolkit/actors/AutoCompleteChild.jsm | 6 +- toolkit/actors/DateTimePickerChild.jsm | 6 +- toolkit/actors/SelectChild.jsm | 6 +- toolkit/components/places/UnifiedComplete.jsm | 4 +- toolkit/components/prompts/src/Prompter.jsm | 5 +- .../components/prompts/test/prompt_common.js | 18 +- .../components/thumbnails/PageThumbUtils.jsm | 2 +- toolkit/content/contentAreaUtils.js | 20 +- toolkit/modules/BrowserTelemetryUtils.jsm | 199 ---- toolkit/modules/BrowserUtils.jsm | 931 +++++++++++++++++- toolkit/modules/Finder.jsm | 15 +- toolkit/modules/KeywordUtils.jsm | 94 -- toolkit/modules/LayoutUtils.jsm | 86 -- toolkit/modules/SelectionUtils.jsm | 160 --- toolkit/modules/moz.build | 4 - .../tests/browser/browser_BrowserUtils.js | 10 +- 53 files changed, 1091 insertions(+), 1052 deletions(-) delete mode 100644 browser/modules/BrowserUIUtils.jsm delete mode 100644 toolkit/modules/BrowserTelemetryUtils.jsm delete mode 100644 toolkit/modules/KeywordUtils.jsm delete mode 100644 toolkit/modules/LayoutUtils.jsm delete mode 100644 toolkit/modules/SelectionUtils.jsm diff --git a/browser/actors/ClickHandlerChild.jsm b/browser/actors/ClickHandlerChild.jsm index 49aa06a7f43c..d5f7f31f3280 100644 --- a/browser/actors/ClickHandlerChild.jsm +++ b/browser/actors/ClickHandlerChild.jsm @@ -7,6 +7,11 @@ var EXPORTED_SYMBOLS = ["ClickHandlerChild"]; const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); +ChromeUtils.defineModuleGetter( + this, + "BrowserUtils", + "resource://gre/modules/BrowserUtils.jsm" +); ChromeUtils.defineModuleGetter( this, "PrivateBrowsingUtils", @@ -97,10 +102,7 @@ class ClickHandlerChild extends JSWindowActorChild { if (href) { try { - Services.scriptSecurityManager.checkLoadURIStrWithPrincipal( - principal, - href - ); + BrowserUtils.urlSecurityCheck(href, principal); } catch (e) { return; } diff --git a/browser/actors/ContextMenuChild.jsm b/browser/actors/ContextMenuChild.jsm index e4df8f49e890..2b2635fb6d8e 100644 --- a/browser/actors/ContextMenuChild.jsm +++ b/browser/actors/ContextMenuChild.jsm @@ -17,11 +17,11 @@ XPCOMUtils.defineLazyGlobalGetters(this, ["URL"]); XPCOMUtils.defineLazyModuleGetters(this, { E10SUtils: "resource://gre/modules/E10SUtils.jsm", + BrowserUtils: "resource://gre/modules/BrowserUtils.jsm", SpellCheckHelper: "resource://gre/modules/InlineSpellChecker.jsm", LoginManagerChild: "resource://gre/modules/LoginManagerChild.jsm", WebNavigationFrames: "resource://gre/modules/WebNavigationFrames.jsm", PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm", - SelectionUtils: "resource://gre/modules/SelectionUtils.jsm", InlineSpellCheckerContent: "resource://gre/modules/InlineSpellCheckerContent.jsm", ContentDOMReference: "resource://gre/modules/ContentDOMReference.jsm", @@ -237,9 +237,9 @@ class ContextMenuChild extends JSWindowActorChild { if (!disable) { try { - Services.scriptSecurityManager.checkLoadURIWithPrincipal( - target.ownerDocument.nodePrincipal, - target.currentURI + BrowserUtils.urlSecurityCheck( + target.currentURI.spec, + target.ownerDocument.nodePrincipal ); let canvas = this.document.createElement("canvas"); canvas.width = target.naturalWidth; @@ -614,7 +614,7 @@ class ContextMenuChild extends JSWindowActorChild { } catch (e) {} } - let selectionInfo = SelectionUtils.getSelectionDetails(this.contentWindow); + let selectionInfo = BrowserUtils.getSelectionDetails(this.contentWindow); let loadContext = this.docShell.QueryInterface(Ci.nsILoadContext); let userContextId = loadContext.originAttributes.userContextId; diff --git a/browser/actors/EncryptedMediaParent.jsm b/browser/actors/EncryptedMediaParent.jsm index a0394a088888..ddddda997b09 100644 --- a/browser/actors/EncryptedMediaParent.jsm +++ b/browser/actors/EncryptedMediaParent.jsm @@ -14,8 +14,8 @@ const { XPCOMUtils } = ChromeUtils.import( ChromeUtils.defineModuleGetter( this, - "BrowserUIUtils", - "resource:///modules/BrowserUIUtils.jsm" + "BrowserUtils", + "resource://gre/modules/BrowserUtils.jsm" ); XPCOMUtils.defineLazyGetter(this, "gBrandBundle", function() { @@ -73,7 +73,7 @@ class EncryptedMediaParent extends JSWindowActorParent { let link = document.createXULElement("label", { is: "text-link" }); link.setAttribute("href", baseURL + "drm-content"); link.textContent = text; - return BrowserUIUtils.getLocalizedFragment(document, mainMessage, link); + return BrowserUtils.getLocalizedFragment(document, mainMessage, link); } getMessageWithBrandName(aNotificationId) { diff --git a/browser/actors/FormValidationChild.jsm b/browser/actors/FormValidationChild.jsm index 787aec54e723..180e79fc93ae 100644 --- a/browser/actors/FormValidationChild.jsm +++ b/browser/actors/FormValidationChild.jsm @@ -10,8 +10,8 @@ var EXPORTED_SYMBOLS = ["FormValidationChild"]; -const { LayoutUtils } = ChromeUtils.import( - "resource://gre/modules/LayoutUtils.jsm" +const { BrowserUtils } = ChromeUtils.import( + "resource://gre/modules/BrowserUtils.jsm" ); const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); @@ -154,7 +154,7 @@ class FormValidationChild extends JSWindowActorChild { panelData.message = this._validationMessage; - panelData.screenRect = LayoutUtils.getElementBoundingScreenRect(aElement); + panelData.screenRect = BrowserUtils.getElementBoundingScreenRect(aElement); // We want to show the popup at the middle of checkbox and radio buttons // and where the content begin for the other elements. diff --git a/browser/actors/PluginChild.jsm b/browser/actors/PluginChild.jsm index 76dd5f58fd18..7210c0a88c8a 100644 --- a/browser/actors/PluginChild.jsm +++ b/browser/actors/PluginChild.jsm @@ -9,6 +9,9 @@ var EXPORTED_SYMBOLS = ["PluginChild"]; const { AppConstants } = ChromeUtils.import( "resource://gre/modules/AppConstants.jsm" ); +const { BrowserUtils } = ChromeUtils.import( + "resource://gre/modules/BrowserUtils.jsm" +); const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); const { XPCOMUtils } = ChromeUtils.import( "resource://gre/modules/XPCOMUtils.jsm" @@ -41,37 +44,6 @@ const OVERLAY_DISPLAY = { // definition. const kSubmitMsg = "PluginParent:NPAPIPluginCrashReportSubmitted"; -/** - * Map the plugin's name to a filtered version more suitable for UI. - * - * N.B. This should be completely dead code at this point. - * - * @param aName The full-length name string of the plugin. - * @return the simplified name string. - */ -function makeNicePluginName(aName) { - if (aName == "Shockwave Flash") { - return "Adobe Flash"; - } - // Regex checks if aName begins with "Java" + non-letter char - if (/^Java\W/.test(aName)) { - return "Java"; - } - - // Clean up the plugin name by stripping off parenthetical clauses, - // trailing version numbers or "plugin". - // EG, "Foo Bar (Linux) Plugin 1.23_02" --> "Foo Bar" - // Do this by first stripping the numbers, etc. off the end, and then - // removing "Plugin" (and then trimming to get rid of any whitespace). - // (Otherwise, something like "Java(TM) Plug-in 1.7.0_07" gets mangled) - let newName = aName - .replace(/\(.*?\)/g, "") - .replace(/[\s\d\.\-\_\(\)]+$/, "") - .replace(/\bplug-?in\b/i, "") - .trim(); - return newName; -} - class PluginChild extends JSWindowActorChild { constructor() { super(); @@ -167,7 +139,7 @@ class PluginChild extends JSWindowActorChild { _getPluginInfo(pluginElement) { if (this.isKnownPlugin(pluginElement)) { let pluginTag = gPluginHost.getPluginTagForType(pluginElement.actualType); - let pluginName = makeNicePluginName(pluginTag.name); + let pluginName = BrowserUtils.makeNicePluginName(pluginTag.name); let fallbackType = pluginElement.defaultFallbackType; let permissionString = gPluginHost.getPermissionStringForType( pluginElement.actualType @@ -197,7 +169,7 @@ class PluginChild extends JSWindowActorChild { // nsIObjectLoadingContent to check. let fallbackType = Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY; if (pluginTag) { - let pluginName = makeNicePluginName(pluginTag.name); + let pluginName = BrowserUtils.makeNicePluginName(pluginTag.name); let permissionString = gPluginHost.getPermissionStringForTag(pluginTag); return { pluginTag, pluginName, permissionString, fallbackType }; } diff --git a/browser/actors/PluginParent.jsm b/browser/actors/PluginParent.jsm index 9aa6588d076f..05f8936cc336 100644 --- a/browser/actors/PluginParent.jsm +++ b/browser/actors/PluginParent.jsm @@ -22,6 +22,11 @@ XPCOMUtils.defineLazyServiceGetter( "nsIPluginHost" ); +ChromeUtils.defineModuleGetter( + this, + "BrowserUtils", + "resource://gre/modules/BrowserUtils.jsm" +); ChromeUtils.defineModuleGetter( this, "CrashSubmit", @@ -42,37 +47,6 @@ const { PLUGIN_CLICK_TO_PLAY_QUIET, } = Ci.nsIObjectLoadingContent; -/** - * Map the plugin's name to a filtered version more suitable for UI. - * - * N.B. This should be completely dead code at this point. - * - * @param aName The full-length name string of the plugin. - * @return the simplified name string. - */ -function makeNicePluginName(aName) { - if (aName == "Shockwave Flash") { - return "Adobe Flash"; - } - // Regex checks if aName begins with "Java" + non-letter char - if (/^Java\W/.test(aName)) { - return "Java"; - } - - // Clean up the plugin name by stripping off parenthetical clauses, - // trailing version numbers or "plugin". - // EG, "Foo Bar (Linux) Plugin 1.23_02" --> "Foo Bar" - // Do this by first stripping the numbers, etc. off the end, and then - // removing "Plugin" (and then trimming to get rid of any whitespace). - // (Otherwise, something like "Java(TM) Plug-in 1.7.0_07" gets mangled) - let newName = aName - .replace(/\(.*?\)/g, "") - .replace(/[\s\d\.\-\_\(\)]+$/, "") - .replace(/\bplug-?in\b/i, "") - .trim(); - return newName; -} - const PluginManager = { _initialized: false, @@ -155,7 +129,7 @@ const PluginManager = { let runID = propertyBag.getPropertyAsUint32("runID"); let uglyPluginName = propertyBag.getPropertyAsAString("pluginName"); - let pluginName = makeNicePluginName(uglyPluginName); + let pluginName = BrowserUtils.makeNicePluginName(uglyPluginName); let pluginDumpID = propertyBag.getPropertyAsAString("pluginDumpID"); let state; diff --git a/browser/base/content/browser-addons.js b/browser/base/content/browser-addons.js index 0afcdcef9d62..78b94a68d6eb 100644 --- a/browser/base/content/browser-addons.js +++ b/browser/base/content/browser-addons.js @@ -631,7 +631,7 @@ var gXPInstallObserver = { ); let b = doc.createElementNS("http://www.w3.org/1999/xhtml", "b"); b.textContent = options.name; - let fragment = BrowserUIUtils.getLocalizedFragment(doc, text, b); + let fragment = BrowserUtils.getLocalizedFragment(doc, text, b); message.appendChild(fragment); } else { message.textContent = gNavigatorBundle.getString( diff --git a/browser/base/content/browser-places.js b/browser/base/content/browser-places.js index 62ea03141829..83ac8763c8fe 100644 --- a/browser/base/content/browser-places.js +++ b/browser/base/content/browser-places.js @@ -2188,7 +2188,7 @@ var BookmarkingUI = { ) { let isBookmarked = this._itemGuids.size > 0; if (!isBookmarked) { - BrowserUIUtils.setToolbarButtonHeightProperty(this.star); + BrowserUtils.setToolbarButtonHeightProperty(this.star); // there are no other animations on this element, so we can simply // listen for animationend with the "once" option to clean up let animatableBox = document.getElementById( diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 86d2383121c5..36c730e64b73 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -22,8 +22,6 @@ XPCOMUtils.defineLazyModuleGetters(this, { NewTabPagePreloading: "resource:///modules/NewTabPagePreloading.jsm", BrowserSearchTelemetry: "resource:///modules/BrowserSearchTelemetry.jsm", BrowserUsageTelemetry: "resource:///modules/BrowserUsageTelemetry.jsm", - BrowserTelemetryUtils: "resource://gre/modules/BrowserTelemetryUtils.jsm", - BrowserUIUtils: "resource:///modules/BrowserUIUtils.jsm", BrowserUtils: "resource://gre/modules/BrowserUtils.jsm", BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm", CFRPageActions: "resource://activity-stream/lib/CFRPageActions.jsm", @@ -4933,7 +4931,7 @@ var XULBrowserWindow = { ); if (UrlbarPrefs.get("trimURLs")) { - url = BrowserUIUtils.trimURL(url); + url = BrowserUtils.trimURL(url); } } @@ -5122,7 +5120,7 @@ var XULBrowserWindow = { aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT; if ( (location == "about:blank" && - BrowserUIUtils.checkEmptyPageOrigin(gBrowser.selectedBrowser)) || + BrowserUtils.checkEmptyPageOrigin(gBrowser.selectedBrowser)) || location == "" ) { // Second condition is for new tabs, otherwise @@ -5585,7 +5583,7 @@ var CombinedStopReload = { this._cancelTransition(); if (shouldAnimate) { - BrowserUIUtils.setToolbarButtonHeightProperty(this.stopReloadContainer); + BrowserUtils.setToolbarButtonHeightProperty(this.stopReloadContainer); this.stopReloadContainer.setAttribute("animate", "true"); } else { this.stopReloadContainer.removeAttribute("animate"); @@ -5608,7 +5606,7 @@ var CombinedStopReload = { this.stopReloadContainer.closest("#nav-bar-customization-target"); if (shouldAnimate) { - BrowserUIUtils.setToolbarButtonHeightProperty(this.stopReloadContainer); + BrowserUtils.setToolbarButtonHeightProperty(this.stopReloadContainer); this.stopReloadContainer.setAttribute("animate", "true"); } else { this.stopReloadContainer.removeAttribute("animate"); @@ -5719,7 +5717,7 @@ var TabsProgressListener = { ) { if (recordLoadTelemetry) { TelemetryStopwatch.finish(histogram, aBrowser); - BrowserTelemetryUtils.recordSiteOriginTelemetry(browserWindows()); + BrowserUtils.recordSiteOriginTelemetry(browserWindows()); } } } else if ( diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js index ec0a03e6ba83..8599c52a2b6b 100644 --- a/browser/base/content/nsContextMenu.js +++ b/browser/base/content/nsContextMenu.js @@ -255,12 +255,8 @@ class nsContextMenu { this.selectionInfo = this.contentData.selectionInfo; this.actor = this.contentData.actor; } else { - const { SelectionUtils } = ChromeUtils.import( - "resource://gre/modules/SelectionUtils.jsm" - ); - this.browser = this.ownerDoc.defaultView.docShell.chromeEventHandler; - this.selectionInfo = SelectionUtils.getSelectionDetails(window); + this.selectionInfo = BrowserUtils.getSelectionDetails(window); this.actor = this.browser.browsingContext.currentWindowGlobal.getActor( "ContextMenu" ); diff --git a/browser/base/content/tabbrowser-tab.js b/browser/base/content/tabbrowser-tab.js index 9b36d5721b7e..e8322329933e 100644 --- a/browser/base/content/tabbrowser-tab.js +++ b/browser/base/content/tabbrowser-tab.js @@ -227,7 +227,7 @@ return false; } - if (!BrowserUIUtils.checkEmptyPageOrigin(browser)) { + if (!BrowserUtils.checkEmptyPageOrigin(browser)) { return false; } diff --git a/browser/components/BrowserGlue.jsm b/browser/components/BrowserGlue.jsm index e8f1638cc279..c0650b2c72e9 100644 --- a/browser/components/BrowserGlue.jsm +++ b/browser/components/BrowserGlue.jsm @@ -31,7 +31,7 @@ XPCOMUtils.defineLazyModuleGetters(this, { BookmarkJSONUtils: "resource://gre/modules/BookmarkJSONUtils.jsm", BrowserSearchTelemetry: "resource:///modules/BrowserSearchTelemetry.jsm", BrowserUsageTelemetry: "resource:///modules/BrowserUsageTelemetry.jsm", - BrowserUIUtils: "resource:///modules/BrowserUIUtils.jsm", + BrowserUtils: "resource://gre/modules/BrowserUtils.jsm", BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm", ContextualIdentityService: "resource://gre/modules/ContextualIdentityService.jsm", @@ -3950,7 +3950,7 @@ BrowserGlue.prototype = { // same way that the url bar would. body = URIs[0].uri.replace(/([?#]).*$/, "$1"); let wasTruncated = body.length < URIs[0].uri.length; - body = BrowserUIUtils.trimURL(body); + body = BrowserUtils.trimURL(body); if (wasTruncated) { body = bundle.formatStringFromName( "singleTabArrivingWithTruncatedURL.body", diff --git a/browser/components/customizableui/CustomizeMode.jsm b/browser/components/customizableui/CustomizeMode.jsm index 7b97b88e79b1..16b33ae73bf5 100644 --- a/browser/components/customizableui/CustomizeMode.jsm +++ b/browser/components/customizableui/CustomizeMode.jsm @@ -52,8 +52,8 @@ ChromeUtils.defineModuleGetter( ); ChromeUtils.defineModuleGetter( this, - "BrowserUIUtils", - "resource:///modules/BrowserUIUtils.jsm" + "BrowserUtils", + "resource://gre/modules/BrowserUtils.jsm" ); ChromeUtils.defineModuleGetter( this, @@ -791,7 +791,7 @@ CustomizeMode.prototype = { } if (!this.window.gReduceMotion) { let overflowButton = this.$("nav-bar-overflow-button"); - BrowserUIUtils.setToolbarButtonHeightProperty(overflowButton).then(() => { + BrowserUtils.setToolbarButtonHeightProperty(overflowButton).then(() => { overflowButton.setAttribute("animate", "true"); overflowButton.addEventListener("animationend", function onAnimationEnd( event diff --git a/browser/components/extensions/ExtensionControlledPopup.jsm b/browser/components/extensions/ExtensionControlledPopup.jsm index 2f61c75bada3..8bd63c6c1001 100644 --- a/browser/components/extensions/ExtensionControlledPopup.jsm +++ b/browser/components/extensions/ExtensionControlledPopup.jsm @@ -34,8 +34,8 @@ ChromeUtils.defineModuleGetter( ); ChromeUtils.defineModuleGetter( this, - "BrowserUIUtils", - "resource:///modules/BrowserUIUtils.jsm" + "BrowserUtils", + "resource://gre/modules/BrowserUtils.jsm" ); ChromeUtils.defineModuleGetter( this, @@ -367,7 +367,7 @@ class ExtensionControlledPopup { ); } else { description.appendChild( - BrowserUIUtils.getLocalizedFragment(doc, message, addonDetails) + BrowserUtils.getLocalizedFragment(doc, message, addonDetails) ); } diff --git a/browser/components/extensions/parent/ext-tabs.js b/browser/components/extensions/parent/ext-tabs.js index e05522d4e110..c88d35dc516e 100644 --- a/browser/components/extensions/parent/ext-tabs.js +++ b/browser/components/extensions/parent/ext-tabs.js @@ -8,8 +8,8 @@ ChromeUtils.defineModuleGetter( this, - "BrowserUIUtils", - "resource:///modules/BrowserUIUtils.jsm" + "BrowserUtils", + "resource://gre/modules/BrowserUtils.jsm" ); ChromeUtils.defineModuleGetter( this, @@ -64,7 +64,7 @@ XPCOMUtils.defineLazyGetter(this, "tabHidePopup", () => { getLocalizedDescription: (doc, message, addonDetails) => { let image = doc.createXULElement("image"); image.setAttribute("class", "extension-controlled-icon alltabs-icon"); - return BrowserUIUtils.getLocalizedFragment( + return BrowserUtils.getLocalizedFragment( doc, message, addonDetails, diff --git a/browser/components/originattributes/test/browser/browser_favicon_firstParty.js b/browser/components/originattributes/test/browser/browser_favicon_firstParty.js index cd9867eebee6..a6ec99e0d722 100644 --- a/browser/components/originattributes/test/browser/browser_favicon_firstParty.js +++ b/browser/components/originattributes/test/browser/browser_favicon_firstParty.js @@ -42,6 +42,8 @@ const ICON_DATA = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABH0lEQVRYw2P8////f4YBBEwMAwxGHcBCUMX/91DGOSj/BpT/DkpzQChGBSjfBErLQsVZhmoI/L8LpRdD6X1QietQGhYy7FB5aAgwmkLpBKi4BZTPMThDgBGjHIDF+f9mKD0fKvGBRKNdoF7sgPL1saaJwZgGDkJ9vpZMn8PAHqg5G9FyifBgD4H/W9HyOWrU/f+DIzHhkoeZxxgzZEIAVtJ9RxX+Q6DAxCmP3byhXxkxshAs5odqbcioAY3UC1CBLyTGOTqAmsfAOWRCwBvqxV0oIUB2OQAzDy3/D+a6wB7q8mCU2vD/nw94GziYIQOtDRn9oXz+IZMGBKGMbCjNh9Ii+v8HR4uIAUeLiEEbb9twELaIRlqrmHG0bzjiHQAA1LVfww8jwM4AAAAASUVORK5CYII="; let systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal(); +let makeURI = ChromeUtils.import("resource://gre/modules/BrowserUtils.jsm", {}) + .BrowserUtils.makeURI; function clearAllImageCaches() { let tools = SpecialPowers.Cc["@mozilla.org/image/tools;1"].getService( @@ -242,8 +244,8 @@ function assertIconIsData(item) { } async function doTest(aTestPage, aExpectedCookies, aFaviconURL) { - let firstPageURI = Services.io.newURI(TEST_SITE_ONE + aTestPage); - let secondPageURI = Services.io.newURI(TEST_SITE_TWO + aTestPage); + let firstPageURI = makeURI(TEST_SITE_ONE + aTestPage); + let secondPageURI = makeURI(TEST_SITE_TWO + aTestPage); // Start to observe the event of that favicon has been fully loaded. let promiseFaviconLoaded = waitOnFaviconLoaded(aFaviconURL); diff --git a/browser/components/pocket/content/Pocket.jsm b/browser/components/pocket/content/Pocket.jsm index de4d4958f7be..5b8c4a1c492f 100644 --- a/browser/components/pocket/content/Pocket.jsm +++ b/browser/components/pocket/content/Pocket.jsm @@ -10,8 +10,8 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); ChromeUtils.defineModuleGetter( this, - "BrowserUIUtils", - "resource:///modules/BrowserUIUtils.jsm" + "BrowserUtils", + "resource://gre/modules/BrowserUtils.jsm" ); var Pocket = { @@ -46,7 +46,7 @@ var Pocket = { let libraryButton = document.getElementById("library-button"); if (libraryButton) { - BrowserUIUtils.setToolbarButtonHeightProperty(libraryButton); + BrowserUtils.setToolbarButtonHeightProperty(libraryButton); } let urlToSave = Pocket._urlToSave; diff --git a/browser/components/pocket/content/SaveToPocket.jsm b/browser/components/pocket/content/SaveToPocket.jsm index 09e4aed67019..efb944fd38c0 100644 --- a/browser/components/pocket/content/SaveToPocket.jsm +++ b/browser/components/pocket/content/SaveToPocket.jsm @@ -11,8 +11,8 @@ const { XPCOMUtils } = ChromeUtils.import( const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); ChromeUtils.defineModuleGetter( this, - "BrowserUIUtils", - "resource:///modules/BrowserUIUtils.jsm" + "BrowserUtils", + "resource://gre/modules/BrowserUtils.jsm" ); ChromeUtils.defineModuleGetter( this, @@ -76,7 +76,7 @@ var PocketPageAction = { return; } - BrowserUIUtils.setToolbarButtonHeightProperty(urlbarNode); + BrowserUtils.setToolbarButtonHeightProperty(urlbarNode); PocketPageAction.urlbarNode = urlbarNode; PocketPageAction.urlbarNode.setAttribute("open", "true"); diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_favicon.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_favicon.js index b455a60fab5d..c0e671ce34ed 100644 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_favicon.js +++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_favicon.js @@ -15,6 +15,8 @@ const FAVICON_URI = TEST_SITE + TEST_DIRECTORY + "file_favicon.png"; const FAVICON_CACHE_URI = TEST_CACHE_SITE + TEST_DIRECTORY + "file_favicon.png"; let systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal(); +let makeURI = ChromeUtils.import("resource://gre/modules/BrowserUtils.jsm", {}) + .BrowserUtils.makeURI; function clearAllImageCaches() { let tools = SpecialPowers.Cc["@mozilla.org/image/tools;1"].getService( @@ -203,7 +205,7 @@ add_task(async function test_favicon_privateBrowsing() { let privateWindow = await BrowserTestUtils.openNewBrowserWindow({ private: true, }); - let pageURI = Services.io.newURI(TEST_PAGE); + let pageURI = makeURI(TEST_PAGE); // Generate two random cookies for non-private window and private window // respectively. diff --git a/browser/components/sessionstore/test/browser_522545.js b/browser/components/sessionstore/test/browser_522545.js index 3761b160ec0d..9955eb75875d 100644 --- a/browser/components/sessionstore/test/browser_522545.js +++ b/browser/components/sessionstore/test/browser_522545.js @@ -396,7 +396,7 @@ function test() { ); is( gURLBar.value, - BrowserUIUtils.trimURL("http://example.com/"), + BrowserUtils.trimURL("http://example.com/"), "Address bar's value set after loading URI" ); runNextTest(); diff --git a/browser/components/urlbar/UrlbarInput.jsm b/browser/components/urlbar/UrlbarInput.jsm index 488af5a64428..ba414758c67f 100644 --- a/browser/components/urlbar/UrlbarInput.jsm +++ b/browser/components/urlbar/UrlbarInput.jsm @@ -13,7 +13,7 @@ const { XPCOMUtils } = ChromeUtils.import( XPCOMUtils.defineLazyModuleGetters(this, { AppConstants: "resource://gre/modules/AppConstants.jsm", BrowserSearchTelemetry: "resource:///modules/BrowserSearchTelemetry.jsm", - BrowserUIUtils: "resource:///modules/BrowserUIUtils.jsm", + BrowserUtils: "resource://gre/modules/BrowserUtils.jsm", ExtensionSearchHandler: "resource://gre/modules/ExtensionSearchHandler.jsm", ObjectUtils: "resource://gre/modules/ObjectUtils.jsm", PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm", @@ -330,7 +330,7 @@ class UrlbarInput { // only if there's no opener (bug 370555). if ( this.window.isInitialPage(uri) && - BrowserUIUtils.checkEmptyPageOrigin( + BrowserUtils.checkEmptyPageOrigin( this.window.gBrowser.selectedBrowser, uri ) @@ -349,7 +349,7 @@ class UrlbarInput { !this.window.isBlankPageURL(uri.spec) || uri.schemeIs("moz-extension"); } else if ( this.window.isInitialPage(value) && - BrowserUIUtils.checkEmptyPageOrigin(this.window.gBrowser.selectedBrowser) + BrowserUtils.checkEmptyPageOrigin(this.window.gBrowser.selectedBrowser) ) { value = ""; valid = true; @@ -1076,10 +1076,10 @@ class UrlbarInput { if ( result.type == UrlbarUtils.RESULT_TYPE.URL && UrlbarPrefs.get("trimURLs") && - result.payload.url.startsWith(BrowserUIUtils.trimURLProtocol) + result.payload.url.startsWith(BrowserUtils.trimURLProtocol) ) { let fixupInfo = this._getURIFixupInfo( - BrowserUIUtils.trimURL(result.payload.url) + BrowserUtils.trimURL(result.payload.url) ); if (fixupInfo?.keywordAsSent) { allowTrim = false; @@ -2089,12 +2089,12 @@ class UrlbarInput { // url. First check for a trimmed value. if ( - !selectedVal.startsWith(BrowserUIUtils.trimURLProtocol) && + !selectedVal.startsWith(BrowserUtils.trimURLProtocol) && // Note _trimValue may also trim a trailing slash, thus we can't just do // a straight string compare to tell if the protocol was trimmed. !displaySpec.startsWith(this._trimValue(displaySpec)) ) { - selectedVal = BrowserUIUtils.trimURLProtocol + selectedVal; + selectedVal = BrowserUtils.trimURLProtocol + selectedVal; } return selectedVal; @@ -2176,7 +2176,7 @@ class UrlbarInput { * The trimmed string */ _trimValue(val) { - return UrlbarPrefs.get("trimURLs") ? BrowserUIUtils.trimURL(val) : val; + return UrlbarPrefs.get("trimURLs") ? BrowserUtils.trimURL(val) : val; } /** @@ -3257,11 +3257,10 @@ function getDroppableData(event) { } try { - // If this throws, checkLoadURStrWithPrincipal would also throw, - // as that's what it does with things that don't pass the IO - // service's newURI constructor without fixup. It's conceivable we - // may want to relax this check in the future (so e.g. www.foo.com - // gets fixed up), but not right now. + // If this throws, urlSecurityCheck would also throw, as that's what it + // does with things that don't pass the IO service's newURI constructor + // without fixup. It's conceivable we may want to relax this check in + // the future (so e.g. www.foo.com gets fixed up), but not right now. let url = new URL(href); // If we succeed, try to pass security checks. If this works, return the // URL object. If the *security checks* fail, return null. @@ -3269,9 +3268,9 @@ function getDroppableData(event) { let principal = Services.droppedLinkHandler.getTriggeringPrincipal( event ); - Services.scriptSecurityManager.checkLoadURIStrWithPrincipal( + BrowserUtils.urlSecurityCheck( + url, principal, - url.href, Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL ); return url; diff --git a/browser/components/urlbar/UrlbarResult.jsm b/browser/components/urlbar/UrlbarResult.jsm index 5dd2f5a20392..fe333f74426f 100644 --- a/browser/components/urlbar/UrlbarResult.jsm +++ b/browser/components/urlbar/UrlbarResult.jsm @@ -18,7 +18,7 @@ const { XPCOMUtils } = ChromeUtils.import( "resource://gre/modules/XPCOMUtils.jsm" ); XPCOMUtils.defineLazyModuleGetters(this, { - BrowserUIUtils: "resource:///modules/BrowserUIUtils.jsm", + BrowserUtils: "resource://gre/modules/BrowserUtils.jsm", JsonSchemaValidator: "resource://gre/modules/components-utils/JsonSchemaValidator.jsm", Services: "resource://gre/modules/Services.jsm", @@ -226,7 +226,7 @@ class UrlbarResult { payloadInfo.displayUrl = [...payloadInfo.url]; let url = payloadInfo.displayUrl[0]; if (url && UrlbarPrefs.get("trimURLs")) { - url = BrowserUIUtils.removeSingleTrailingSlashFromURL(url); + url = BrowserUtils.removeSingleTrailingSlashFromURL(url); if (url.startsWith("https://")) { url = url.substring(8); if (url.startsWith("www.")) { diff --git a/browser/components/urlbar/UrlbarUtils.jsm b/browser/components/urlbar/UrlbarUtils.jsm index 1b6ac525fa39..8ad5e3e28dab 100644 --- a/browser/components/urlbar/UrlbarUtils.jsm +++ b/browser/components/urlbar/UrlbarUtils.jsm @@ -21,9 +21,9 @@ const { XPCOMUtils } = ChromeUtils.import( "resource://gre/modules/XPCOMUtils.jsm" ); XPCOMUtils.defineLazyModuleGetters(this, { + BrowserUtils: "resource://gre/modules/BrowserUtils.jsm", BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm", FormHistory: "resource://gre/modules/FormHistory.jsm", - KeywordUtils: "resource://gre/modules/KeywordUtils.jsm", Log: "resource://gre/modules/Log.jsm", PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm", PlacesUIUtils: "resource:///modules/PlacesUIUtils.jsm", @@ -308,7 +308,7 @@ var UrlbarUtils = { } try { - [url, postData] = await KeywordUtils.parseUrlAndPostData( + [url, postData] = await BrowserUtils.parseUrlAndPostData( entry.url.href, entry.postData, param diff --git a/browser/components/urlbar/tests/UrlbarTestUtils.jsm b/browser/components/urlbar/tests/UrlbarTestUtils.jsm index c4c1384f03a8..2150b5364ae2 100644 --- a/browser/components/urlbar/tests/UrlbarTestUtils.jsm +++ b/browser/components/urlbar/tests/UrlbarTestUtils.jsm @@ -13,7 +13,7 @@ XPCOMUtils.defineLazyModuleGetters(this, { AddonTestUtils: "resource://testing-common/AddonTestUtils.jsm", AppConstants: "resource://gre/modules/AppConstants.jsm", BrowserTestUtils: "resource://testing-common/BrowserTestUtils.jsm", - BrowserUIUtils: "resource:///modules/BrowserUIUtils.jsm", + BrowserUtils: "resource://gre/modules/BrowserUtils.jsm", BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm", FormHistoryTestUtils: "resource://testing-common/FormHistoryTestUtils.jsm", PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm", @@ -113,7 +113,7 @@ var UrlbarTestUtils = { window.gURLBar.inputField.focus(); // Using the value setter in some cases may trim and fetch unexpected // results, then pick an alternate path. - if (UrlbarPrefs.get("trimURLs") && value != BrowserUIUtils.trimURL(value)) { + if (UrlbarPrefs.get("trimURLs") && value != BrowserUtils.trimURL(value)) { window.gURLBar.inputField.value = value; fireInputEvent = true; } else { diff --git a/browser/components/urlbar/tests/browser/browser_UrlbarInput_trimURLs.js b/browser/components/urlbar/tests/browser/browser_UrlbarInput_trimURLs.js index bd22255bdec4..3c1f3ea8e4d9 100644 --- a/browser/components/urlbar/tests/browser/browser_UrlbarInput_trimURLs.js +++ b/browser/components/urlbar/tests/browser/browser_UrlbarInput_trimURLs.js @@ -102,7 +102,7 @@ function testVal(originalValue, targetValue) { gURLBar.value = originalValue; gURLBar.valueIsTyped = false; let trimmedValue = UrlbarPrefs.get("trimURLs") - ? BrowserUIUtils.trimURL(originalValue) + ? BrowserUtils.trimURL(originalValue) : originalValue; Assert.equal(gURLBar.value, trimmedValue, "url bar value set"); // Now focus the urlbar and check the inputField value is properly set. diff --git a/browser/components/urlbar/tests/browser/browser_edit_invalid_url.js b/browser/components/urlbar/tests/browser/browser_edit_invalid_url.js index a74196a129eb..bbebc0f94066 100644 --- a/browser/components/urlbar/tests/browser/browser_edit_invalid_url.js +++ b/browser/components/urlbar/tests/browser/browser_edit_invalid_url.js @@ -5,7 +5,7 @@ // modifies the selected url, or just closes the results pane, we do a visit // rather than searching for the trimmed string. -const url = BrowserUIUtils.trimURLProtocol + "invalid.somehost/mytest"; +const url = BrowserUtils.trimURLProtocol + "invalid.somehost/mytest"; add_task(async function setup() { await SpecialPowers.pushPrefEnv({ diff --git a/browser/components/urlbar/tests/browser/browser_stop.js b/browser/components/urlbar/tests/browser/browser_stop.js index db7f04fded03..1bc011a31c10 100644 --- a/browser/components/urlbar/tests/browser/browser_stop.js +++ b/browser/components/urlbar/tests/browser/browser_stop.js @@ -16,14 +16,14 @@ add_task(async function() { await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); is( gURLBar.value, - BrowserUIUtils.trimURL(goodURL), + BrowserUtils.trimURL(goodURL), "location bar reflects loaded page" ); await typeAndSubmitAndStop(badURL); is( gURLBar.value, - BrowserUIUtils.trimURL(goodURL), + BrowserUtils.trimURL(goodURL), "location bar reflects loaded page after stop()" ); gBrowser.removeCurrentTab(); @@ -34,7 +34,7 @@ add_task(async function() { await typeAndSubmitAndStop(badURL); is( gURLBar.value, - BrowserUIUtils.trimURL(badURL), + BrowserUtils.trimURL(badURL), "location bar reflects stopped page in an empty tab" ); gBrowser.removeCurrentTab(); diff --git a/browser/components/urlbar/tests/browser/browser_valueOnTabSwitch.js b/browser/components/urlbar/tests/browser/browser_valueOnTabSwitch.js index c8d9c3521f53..d1053dfc8e32 100644 --- a/browser/components/urlbar/tests/browser/browser_valueOnTabSwitch.js +++ b/browser/components/urlbar/tests/browser/browser_valueOnTabSwitch.js @@ -51,7 +51,7 @@ add_task(async function() { BrowserTestUtils.loadURI(partialURLTab.linkedBrowser, testURL); await Promise.all([loaded1, loaded2, loaded3]); - testURL = BrowserUIUtils.trimURL(testURL); + testURL = BrowserUtils.trimURL(testURL); testPartialURL = testURL.substr(0, testURL.length - charsToDelete); function cleanUp() { diff --git a/browser/modules/BrowserUIUtils.jsm b/browser/modules/BrowserUIUtils.jsm deleted file mode 100644 index 3f14c2eb0fbe..000000000000 --- a/browser/modules/BrowserUIUtils.jsm +++ /dev/null @@ -1,204 +0,0 @@ -/* -*- mode: js; indent-tabs-mode: nil; js-indent-level: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -"use strict"; - -var EXPORTED_SYMBOLS = ["BrowserUIUtils"]; - -var BrowserUIUtils = { - /** - * Check whether a page can be considered as 'empty', that its URI - * reflects its origin, and that if it's loaded in a tab, that tab - * could be considered 'empty' (e.g. like the result of opening - * a 'blank' new tab). - * - * We have to do more than just check the URI, because especially - * for things like about:blank, it is possible that the opener or - * some other page has control over the contents of the page. - * - * @param {Browser} browser - * The browser whose page we're checking. - * @param {nsIURI} [uri] - * The URI against which we're checking (the browser's currentURI - * if omitted). - * - * @return {boolean} false if the page was opened by or is controlled by - * arbitrary web content, unless that content corresponds with the URI. - * true if the page is blank and controlled by a principal matching - * that URI (or the system principal if the principal has no URI) - */ - checkEmptyPageOrigin(browser, uri = browser.currentURI) { - // If another page opened this page with e.g. window.open, this page might - // be controlled by its opener. - if (browser.hasContentOpener) { - return false; - } - let contentPrincipal = browser.contentPrincipal; - // Not all principals have URIs... - // There are two special-cases involving about:blank. One is where - // the user has manually loaded it and it got created with a null - // principal. The other involves the case where we load - // some other empty page in a browser and the current page is the - // initial about:blank page (which has that as its principal, not - // just URI in which case it could be web-based). Especially in - // e10s, we need to tackle that case specifically to avoid race - // conditions when updating the URL bar. - // - // Note that we check the documentURI here, since the currentURI on - // the browser might have been set by SessionStore in order to - // support switch-to-tab without having actually loaded the content - // yet. - let uriToCheck = browser.documentURI || uri; - if ( - (uriToCheck.spec == "about:blank" && contentPrincipal.isNullPrincipal) || - contentPrincipal.spec == "about:blank" - ) { - return true; - } - if (contentPrincipal.isContentPrincipal) { - return contentPrincipal.equalsURI(uri); - } - // ... so for those that don't have them, enforce that the page has the - // system principal (this matches e.g. on about:newtab). - return contentPrincipal.isSystemPrincipal; - }, - - /** - * Sets the --toolbarbutton-button-height CSS property on the closest - * toolbar to the provided element. Useful if you need to vertically - * center a position:absolute element within a toolbar that uses - * -moz-pack-align:stretch, and thus a height which is dependant on - * the font-size. - * - * @param element An element within the toolbar whose height is desired. - */ - async setToolbarButtonHeightProperty(element) { - let window = element.ownerGlobal; - let dwu = window.windowUtils; - let toolbarItem = element; - let urlBarContainer = element.closest("#urlbar-container"); - if (urlBarContainer) { - // The stop-reload-button, which is contained in #urlbar-container, - // needs to use #urlbar-container to calculate the bounds. - toolbarItem = urlBarContainer; - } - if (!toolbarItem) { - return; - } - let bounds = dwu.getBoundsWithoutFlushing(toolbarItem); - if (!bounds.height) { - await window.promiseDocumentFlushed(() => { - bounds = dwu.getBoundsWithoutFlushing(toolbarItem); - }); - } - if (bounds.height) { - toolbarItem.style.setProperty( - "--toolbarbutton-height", - bounds.height + "px" - ); - } - }, - - /** - * Generate a document fragment for a localized string that has DOM - * node replacements. This avoids using getFormattedString followed - * by assigning to innerHTML. Fluent can probably replace this when - * it is in use everywhere. - * - * @param {Document} doc - * @param {String} msg - * The string to put replacements in. Fetch from - * a stringbundle using getString or GetStringFromName, - * or even an inserted dtd string. - * @param {Node|String} nodesOrStrings - * The replacement items. Can be a mix of Nodes - * and Strings. However, for correct behaviour, the - * number of items provided needs to exactly match - * the number of replacement strings in the l10n string. - * @returns {DocumentFragment} - * A document fragment. In the trivial case (no - * replacements), this will simply be a fragment with 1 - * child, a text node containing the localized string. - */ - getLocalizedFragment(doc, msg, ...nodesOrStrings) { - // Ensure replacement points are indexed: - for (let i = 1; i <= nodesOrStrings.length; i++) { - if (!msg.includes("%" + i + "$S")) { - msg = msg.replace(/%S/, "%" + i + "$S"); - } - } - let numberOfInsertionPoints = msg.match(/%\d+\$S/g).length; - if (numberOfInsertionPoints != nodesOrStrings.length) { - Cu.reportError( - `Message has ${numberOfInsertionPoints} insertion points, ` + - `but got ${nodesOrStrings.length} replacement parameters!` - ); - } - - let fragment = doc.createDocumentFragment(); - let parts = [msg]; - let insertionPoint = 1; - for (let replacement of nodesOrStrings) { - let insertionString = "%" + insertionPoint++ + "$S"; - let partIndex = parts.findIndex( - part => typeof part == "string" && part.includes(insertionString) - ); - if (partIndex == -1) { - fragment.appendChild(doc.createTextNode(msg)); - return fragment; - } - - if (typeof replacement == "string") { - parts[partIndex] = parts[partIndex].replace( - insertionString, - replacement - ); - } else { - let [firstBit, lastBit] = parts[partIndex].split(insertionString); - parts.splice(partIndex, 1, firstBit, replacement, lastBit); - } - } - - // Put everything in a document fragment: - for (let part of parts) { - if (typeof part == "string") { - if (part) { - fragment.appendChild(doc.createTextNode(part)); - } - } else { - fragment.appendChild(part); - } - } - return fragment; - }, - - removeSingleTrailingSlashFromURL(aURL) { - // remove single trailing slash for http/https/ftp URLs - return aURL.replace(/^((?:http|https|ftp):\/\/[^/]+)\/$/, "$1"); - }, - - /** - * Returns a URL which has been trimmed by removing 'http://' and any - * trailing slash (in http/https/ftp urls). - * Note that a trimmed url may not load the same page as the original url, so - * before loading it, it must be passed through URIFixup, to check trimming - * doesn't change its destination. We don't run the URIFixup check here, - * because trimURL is in the page load path (see onLocationChange), so it - * must be fast and simple. - * - * @param {string} aURL The URL to trim. - * @returns {string} The trimmed string. - */ - get trimURLProtocol() { - return "http://"; - }, - trimURL(aURL) { - let url = this.removeSingleTrailingSlashFromURL(aURL); - // Remove "http://" prefix. - return url.startsWith(this.trimURLProtocol) - ? url.substring(this.trimURLProtocol.length) - : url; - }, -}; diff --git a/browser/modules/BrowserUsageTelemetry.jsm b/browser/modules/BrowserUsageTelemetry.jsm index e6e7a02dc925..3134c1fb1412 100644 --- a/browser/modules/BrowserUsageTelemetry.jsm +++ b/browser/modules/BrowserUsageTelemetry.jsm @@ -19,7 +19,7 @@ const { XPCOMUtils } = ChromeUtils.import( XPCOMUtils.defineLazyModuleGetters(this, { AppConstants: "resource://gre/modules/AppConstants.jsm", ClientID: "resource://gre/modules/ClientID.jsm", - BrowserTelemetryUtils: "resource://gre/modules/BrowserTelemetryUtils.jsm", + BrowserUtils: "resource://gre/modules/BrowserUtils.jsm", CustomizableUI: "resource:///modules/CustomizableUI.jsm", PageActions: "resource:///modules/PageActions.jsm", PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm", @@ -1208,7 +1208,7 @@ let BrowserUsageTelemetry = { } const { loadedTabCount } = getOpenTabsAndWinsCounts(); - const siteOrigins = BrowserTelemetryUtils.computeSiteOriginCount( + const siteOrigins = BrowserUtils.computeSiteOriginCount( Services.wm.getEnumerator("navigator:browser"), false ); diff --git a/browser/modules/moz.build b/browser/modules/moz.build index b069f1b641f7..06b809334b54 100644 --- a/browser/modules/moz.build +++ b/browser/modules/moz.build @@ -128,7 +128,6 @@ EXTRA_JS_MODULES += [ "AboutNewTab.jsm", "AppUpdater.jsm", "AsyncTabSwitcher.jsm", - "BrowserUIUtils.jsm", "BrowserUsageTelemetry.jsm", "BrowserWindowTracker.jsm", "ContentCrashHandlers.jsm", diff --git a/browser/themes/shared/toolbarbutton-icons.inc.css b/browser/themes/shared/toolbarbutton-icons.inc.css index 691e52b40957..379e9e7be733 100644 --- a/browser/themes/shared/toolbarbutton-icons.inc.css +++ b/browser/themes/shared/toolbarbutton-icons.inc.css @@ -36,7 +36,7 @@ toolbar[brighttext] { animation-iteration-count: 1; list-style-image: none; /* Height must be equal to height of toolbarbutton padding-box. --toolbarbutton-height - is calculated and set during runtime by BrowserUIUtils.setToolbarButtonHeightProperty() + is calculated and set during runtime by BrowserUtils.setToolbarButtonHeightProperty() before the animation begins. */ height: var(--toolbarbutton-height); } diff --git a/caps/nsIScriptSecurityManager.idl b/caps/nsIScriptSecurityManager.idl index e0497db33634..2cfb7b327165 100644 --- a/caps/nsIScriptSecurityManager.idl +++ b/caps/nsIScriptSecurityManager.idl @@ -113,20 +113,9 @@ interface nsIScriptSecurityManager : nsISupports * will only appear in the browser console, not window-associated * consoles like the web console. */ - [binaryname(CheckLoadURIWithPrincipal)] - void checkLoadURIWithPrincipalXPCOM(in nsIPrincipal aPrincipal, - in nsIURI uri, - in unsigned long flags, - [optional] in unsigned long long innerWindowID); - - /** - * Same as the above, but when called from JS, raises exceptions with more - * useful messages, including both the tested URI and the principal string. - */ - [implicit_jscontext, binaryname(CheckLoadURIWithPrincipalFromJS)] void checkLoadURIWithPrincipal(in nsIPrincipal aPrincipal, in nsIURI uri, - [optional] in unsigned long flags, + in unsigned long flags, [optional] in unsigned long long innerWindowID); /** @@ -138,19 +127,9 @@ interface nsIScriptSecurityManager : nsISupports * load as well); if any of the versions of this URI is not allowed, this * function will return error code NS_ERROR_DOM_BAD_URI. */ - [binaryname(CheckLoadURIStrWithPrincipal)] - void checkLoadURIStrWithPrincipalXPCOM(in nsIPrincipal aPrincipal, - in AUTF8String uri, - in unsigned long flags); - - /** - * Same as the above, but when called from JS, raises exceptions with more - * useful messages, including both the tested URI and the principal string. - */ - [implicit_jscontext, binaryname(CheckLoadURIStrWithPrincipalFromJS)] void checkLoadURIStrWithPrincipal(in nsIPrincipal aPrincipal, in AUTF8String uri, - [optional] in unsigned long flags); + in unsigned long flags); /** * Returns true if the URI is from a domain that is allow-listed through diff --git a/caps/nsScriptSecurityManager.cpp b/caps/nsScriptSecurityManager.cpp index 22090b91c1c3..03d58446988b 100644 --- a/caps/nsScriptSecurityManager.cpp +++ b/caps/nsScriptSecurityManager.cpp @@ -57,11 +57,9 @@ #include #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ContentParent.h" -#include "mozilla/dom/Exceptions.h" #include "mozilla/dom/nsCSPContext.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/ClearOnShutdown.h" -#include "mozilla/ResultExtensions.h" #include "mozilla/StaticPtr.h" #include "mozilla/dom/WorkerCommon.h" #include "mozilla/dom/WorkerPrivate.h" @@ -1118,49 +1116,6 @@ nsScriptSecurityManager::CheckLoadURIStrWithPrincipal( return rv; } -NS_IMETHODIMP -nsScriptSecurityManager::CheckLoadURIWithPrincipalFromJS(nsIPrincipal* aPrincipal, - nsIURI* aTargetURI, - uint32_t aFlags, - uint64_t aInnerWindowID, - JSContext* aCx) { - NS_ENSURE_ARG_POINTER(aTargetURI); - - nsresult rv = CheckLoadURIWithPrincipal(aPrincipal, - aTargetURI, - aFlags, - aInnerWindowID); - if (NS_FAILED(rv)) { - nsAutoCString uriStr; - Unused << aTargetURI->GetSpec(uriStr); - - nsAutoCString message("Load of "); - message.Append(uriStr); - - nsAutoCString principalStr; - Unused << aPrincipal->GetSpec(principalStr); - if (!principalStr.IsEmpty()) { - message.AppendPrintf(" from %s", principalStr.get()); - } - - message.Append(" denied"); - - dom::Throw(aCx, rv, message); - } - - return rv; -} - -NS_IMETHODIMP -nsScriptSecurityManager::CheckLoadURIStrWithPrincipalFromJS( - nsIPrincipal* aPrincipal, const nsACString& aTargetURIStr, - uint32_t aFlags, JSContext* aCx) { - nsCOMPtr targetURI; - MOZ_TRY(NS_NewURI(getter_AddRefs(targetURI), aTargetURIStr)); - - return CheckLoadURIWithPrincipalFromJS(aPrincipal, targetURI, aFlags, 0, aCx); -} - NS_IMETHODIMP nsScriptSecurityManager::InFileURIAllowlist(nsIURI* aUri, bool* aResult) { MOZ_ASSERT(aUri); diff --git a/caps/tests/mochitest/browser_checkloaduri.js b/caps/tests/mochitest/browser_checkloaduri.js index 3f114427335d..4607c802288e 100644 --- a/caps/tests/mochitest/browser_checkloaduri.js +++ b/caps/tests/mochitest/browser_checkloaduri.js @@ -254,7 +254,7 @@ function testURL( let threw = false; let targetURI; try { - targetURI = Services.io.newURI(target); + targetURI = makeURI(target); } catch (ex) { ok( !canCreate, @@ -300,7 +300,7 @@ add_task(async function() { if (sourceString.startsWith("about:test-chrome-privs")) { source = ssm.getSystemPrincipal(); } else { - source = ssm.createContentPrincipal(Services.io.newURI(sourceString), {}); + source = ssm.createContentPrincipal(makeURI(sourceString), {}); } for (let [ target, @@ -341,6 +341,10 @@ add_task(async function() { // eslint-disable-next-line no-shadow let baseFlags = ssm.STANDARD | ssm.DONT_REPORT_ERRORS; // eslint-disable-next-line no-unused-vars + let makeURI = ChromeUtils.import( + "resource://gre/modules/BrowserUtils.jsm", + {} + ).BrowserUtils.makeURI; let b = new content.Blob(["I am a blob"]); let contentBlobURI = content.URL.createObjectURL(b); let contentPrincipal = content.document.nodePrincipal; diff --git a/dom/security/test/general/test_bug1277803.xhtml b/dom/security/test/general/test_bug1277803.xhtml index 43afb1f1a355..482dd6b916ec 100644 --- a/dom/security/test/general/test_bug1277803.xhtml +++ b/dom/security/test/general/test_bug1277803.xhtml @@ -15,41 +15,46 @@