diff --git a/browser/components/BrowserContentHandler.sys.mjs b/browser/components/BrowserContentHandler.sys.mjs index 2bf92f41acbf..e72feb538c0d 100644 --- a/browser/components/BrowserContentHandler.sys.mjs +++ b/browser/components/BrowserContentHandler.sys.mjs @@ -1394,16 +1394,11 @@ nsDefaultCommandLineHandler.prototype = { // window to perform the action in. let winForAction; - // Fall back to launchUrl to not break notifications opened from - // previous builds after browser updates, as such notification would - // still have the old field. - let origin = notificationData?.origin ?? notificationData?.launchUrl; - - if (!tagWasHandled && origin && !opaqueRelaunchData) { - let originPrincipal = - Services.scriptSecurityManager.createContentPrincipalFromOrigin( - origin - ); + if ( + !tagWasHandled && + notificationData?.launchUrl && + !opaqueRelaunchData + ) { // Unprivileged Web Notifications contain a launch URL and are // handled slightly differently than privileged notifications with // actions. If the tag was not handled, then the notification was @@ -1411,9 +1406,7 @@ nsDefaultCommandLineHandler.prototype = { // fallback behavior. let { uri, principal } = resolveURIInternal( cmdLine, - // TODO(krosylight): We should handle origin suffix to open the - // relevant container. See bug 1945501. - originPrincipal.originNoSuffix + notificationData.launchUrl ); if (cmdLine.state != Ci.nsICommandLine.STATE_INITIAL_LAUNCH) { // Try to find an existing window and load our URI into the current diff --git a/browser/components/tests/browser/browser.toml b/browser/components/tests/browser/browser.toml index a9b8b36883c9..0cb4fe542d64 100644 --- a/browser/components/tests/browser/browser.toml +++ b/browser/components/tests/browser/browser.toml @@ -36,9 +36,6 @@ run-if = ["os == 'win'"] ["browser_forced_colors.js"] -["browser_handle_notification.js"] -run-if = ["os == 'win'"] - ["browser_initial_tab_remoteType.js"] https_first_disabled = true diff --git a/browser/components/tests/browser/browser_handle_notification.js b/browser/components/tests/browser/browser_handle_notification.js deleted file mode 100644 index 18114beb4077..000000000000 --- a/browser/components/tests/browser/browser_handle_notification.js +++ /dev/null @@ -1,127 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. -http://creativecommons.org/publicdomain/zero/1.0/ */ -"use strict"; - -function createCmdLine(tag, action, state) { - return Cu.createCommandLine( - [ - "--notification-windowsTag", - tag, - "--notification-windowsAction", - JSON.stringify(action), - ], - null, - state - ); -} - -function runCmdLine(cmdLine) { - let cmdLineHandler = Cc["@mozilla.org/browser/final-clh;1"].getService( - Ci.nsICommandLineHandler - ); - cmdLineHandler.handle(cmdLine); -} - -function simulateNotificationClickWithExistingWindow(action) { - let cmdLine = createCmdLine( - "dummyTag", - action, - Ci.nsICommandLine.STATE_REMOTE_AUTO - ); - runCmdLine(cmdLine); -} - -function simulateNotificationClickWithNewWindow(action) { - let cmdLine = createCmdLine( - "dummyTag", - action, - Ci.nsICommandLine.STATE_INITIAL_LAUNCH - ); - runCmdLine(cmdLine); -} - -add_task(async function test_basic() { - let newTabPromise = BrowserTestUtils.waitForNewTab( - gBrowser, - "https://example.com/" - ); - - simulateNotificationClickWithExistingWindow({ - action: "", - origin: "https://example.com", - }); - - let newTab = await newTabPromise; - ok(newTab, "New tab should be opened."); - BrowserTestUtils.removeTab(newTab); -}); - -// launchUrl was used pre-140, we can remove it when we are confident enough -// that there's no old notification with launchUrl lying around anymore -add_task(async function test_legacy_launchUrl() { - let newTabPromise = BrowserTestUtils.waitForNewTab( - gBrowser, - "https://example.com/" - ); - - simulateNotificationClickWithExistingWindow({ - action: "", - launchUrl: "https://example.com", - }); - - let newTab = await newTabPromise; - ok(newTab, "New tab should be opened."); - BrowserTestUtils.removeTab(newTab); -}); - -add_task(async function test_invalid_origin_with_path() { - let newTabPromise = BrowserTestUtils.waitForNewTab( - gBrowser, - "https://example.com/" - ); - - simulateNotificationClickWithExistingWindow({ - action: "", - origin: "https://example.com/example/", - }); - - let newTab = await newTabPromise; - ok(newTab, "New tab should be opened."); - BrowserTestUtils.removeTab(newTab); -}); - -add_task(async function test_user_context() { - let newTabPromise = BrowserTestUtils.waitForNewTab( - gBrowser, - "https://example.com/" - ); - - simulateNotificationClickWithExistingWindow({ - action: "", - origin: "https://example.com^userContextId=1", - }); - - let newTab = await newTabPromise; - registerCleanupFunction(() => BrowserTestUtils.removeTab(newTab)); - ok(newTab, "New tab should be opened."); - - // TODO(krosylight): We want to make sure this opens on the right container. - // See bug 1945501. - is(newTab.userContextId, 0, "The default user context ID is used (for now)."); -}); - -add_task(async function test_basic_initial_load() { - let newWinPromise = BrowserTestUtils.waitForNewWindow({ - url: "https://example.com/", - anyWindow: true, - }); - - simulateNotificationClickWithNewWindow({ - action: "", - origin: "https://example.com", - }); - - let newWin = await newWinPromise; - ok(newWin, "New window should be opened."); - BrowserTestUtils.closeWindow(newWin); -}); diff --git a/toolkit/components/alerts/AlertNotification.cpp b/toolkit/components/alerts/AlertNotification.cpp index bec229fe0e66..98a093d7aea9 100644 --- a/toolkit/components/alerts/AlertNotification.cpp +++ b/toolkit/components/alerts/AlertNotification.cpp @@ -238,11 +238,6 @@ AlertNotification::GetSource(nsAString& aSource) { return NS_OK; } -NS_IMETHODIMP -AlertNotification::GetOrigin(nsACString& aOrigin) { - return nsAlertsUtils::GetOrigin(mPrincipal, aOrigin); -} - NS_IMETHODIMP AlertNotification::GetOpaqueRelaunchData(nsAString& aOpaqueRelaunchData) { aOpaqueRelaunchData = mOpaqueRelaunchData; diff --git a/toolkit/components/alerts/nsAlertsUtils.cpp b/toolkit/components/alerts/nsAlertsUtils.cpp index 8dc25137c2d5..b63b368c75a3 100644 --- a/toolkit/components/alerts/nsAlertsUtils.cpp +++ b/toolkit/components/alerts/nsAlertsUtils.cpp @@ -19,7 +19,6 @@ bool nsAlertsUtils::IsActionablePrincipal(nsIPrincipal* aPrincipal) { /* static */ void nsAlertsUtils::GetSourceHostPort(nsIPrincipal* aPrincipal, nsAString& aHostPort) { - aHostPort.Truncate(); if (!IsActionablePrincipal(aPrincipal)) { return; } @@ -29,13 +28,3 @@ void nsAlertsUtils::GetSourceHostPort(nsIPrincipal* aPrincipal, } CopyUTF8toUTF16(hostPort, aHostPort); } - -/* static */ -nsresult nsAlertsUtils::GetOrigin(nsIPrincipal* aPrincipal, - nsACString& aOrigin) { - aOrigin.Truncate(); - if (!IsActionablePrincipal(aPrincipal)) { - return NS_ERROR_NOT_AVAILABLE; - } - return aPrincipal->GetOrigin(aOrigin); -} diff --git a/toolkit/components/alerts/nsAlertsUtils.h b/toolkit/components/alerts/nsAlertsUtils.h index e06bdeb48a65..c126769de7f9 100644 --- a/toolkit/components/alerts/nsAlertsUtils.h +++ b/toolkit/components/alerts/nsAlertsUtils.h @@ -25,11 +25,5 @@ class nsAlertsUtils final { * empty string if |aPrincipal| is not actionable. */ static void GetSourceHostPort(nsIPrincipal* aPrincipal, nsAString& aHostPort); - - /** - * Sets |aOrigin| to the origin from |aPrincipal|, or an error if |aPrincipal| - * is not actionable. - */ - static nsresult GetOrigin(nsIPrincipal* aPrincipal, nsACString& aOrigin); }; #endif /* nsAlertsUtils_h */ diff --git a/toolkit/components/alerts/nsIAlertsService.idl b/toolkit/components/alerts/nsIAlertsService.idl index 3bde689de91a..68d003816566 100644 --- a/toolkit/components/alerts/nsIAlertsService.idl +++ b/toolkit/components/alerts/nsIAlertsService.idl @@ -219,12 +219,6 @@ interface nsIAlertNotification : nsISupports */ readonly attribute AString source; - /** - * The origin of the originating page, or an empty string if the alert is not - * actionable. This corresponds to `nsIPrincipal.origin`. - */ - readonly attribute ACString origin; - /** * On Windows, chrome-privileged notifications -- i.e., those with a * non-actionable principal -- can have `opaqueRelaunchData`. This data will diff --git a/widget/windows/ToastNotificationHandler.cpp b/widget/windows/ToastNotificationHandler.cpp index 9325a01fc9ae..e4cd609feb33 100644 --- a/widget/windows/ToastNotificationHandler.cpp +++ b/widget/windows/ToastNotificationHandler.cpp @@ -342,10 +342,8 @@ nsString ToastNotificationHandler::ActionArgsJSONString( w.StringProperty("privilegedName", NS_ConvertUTF16toUTF8(mName)); } } else { - nsAutoCString origin; - nsresult rv = mAlertNotification->GetOrigin(origin); - if (NS_SUCCEEDED(rv)) { - w.StringProperty("origin", origin); + if (!mHostPort.IsEmpty()) { + w.StringProperty("launchUrl", NS_ConvertUTF16toUTF8(mHostPort)); } } diff --git a/widget/windows/tests/unit/test_windows_alert_service.js b/widget/windows/tests/unit/test_windows_alert_service.js index 5b2acd2ba021..0ba0d2a4d4a1 100644 --- a/widget/windows/tests/unit/test_windows_alert_service.js +++ b/widget/windows/tests/unit/test_windows_alert_service.js @@ -195,7 +195,7 @@ function testAlert(when, { serverEnabled, profD, isBackgroundTaskMode } = {}) { ? "" : ``; - let parsedSettingsAction = origin => { + let parsedSettingsAction = hostport => { if (isBackgroundTaskMode) { return []; } @@ -209,8 +209,8 @@ function testAlert(when, { serverEnabled, profD, isBackgroundTaskMode } = {}) { { action: "settings", }, - origin && { - origin, + hostport && { + launchUrl: hostport, } ) ), @@ -219,7 +219,7 @@ function testAlert(when, { serverEnabled, profD, isBackgroundTaskMode } = {}) { ]; }; - let parsedSnoozeAction = (hostport, origin) => { + let parsedSnoozeAction = hostport => { let content = `Disable notifications from ${hostport}`; return [ content, @@ -230,8 +230,8 @@ function testAlert(when, { serverEnabled, profD, isBackgroundTaskMode } = {}) { { action: "snooze", }, - origin && { - origin, + hostport && { + launchUrl: hostport, } ) ), @@ -414,8 +414,8 @@ function testAlert(when, { serverEnabled, profD, isBackgroundTaskMode } = {}) { ); // But content unprivileged alerts can't use `windowsSystemActivationType`. - let path = "https://example.com/foo/bar.html"; - const principaluri = Services.io.newURI(path); + let launchUrl = "https://example.com/foo/bar.html"; + const principaluri = Services.io.newURI(launchUrl); const principal = Services.scriptSecurityManager.createContentPrincipal( principaluri, {} @@ -436,19 +436,19 @@ function testAlert(when, { serverEnabled, profD, isBackgroundTaskMode } = {}) { { launch: parsedArgumentString({ action: "", - origin: principal.origin, + launchUrl: principaluri.hostPort, }), actions: Object.fromEntries( [ - parsedSnoozeAction(principal.hostPort, principal.origin), - parsedSettingsAction(principal.origin), + parsedSnoozeAction(principaluri.hostPort), + parsedSettingsAction(principaluri.hostPort), [ "dismissTitle", { content: "dismissTitle", arguments: parsedArgumentString({ action: "dismiss", - origin: principal.origin, + launchUrl: principaluri.hostPort, }), }, ], @@ -458,7 +458,7 @@ function testAlert(when, { serverEnabled, profD, isBackgroundTaskMode } = {}) { content: "snoozeTitle", arguments: parsedArgumentString({ action: "snooze", - origin: principal.origin, + launchUrl: principaluri.hostPort, }), }, ], @@ -514,12 +514,12 @@ function testAlert(when, { serverEnabled, profD, isBackgroundTaskMode } = {}) { { launch: parsedArgumentString({ action: "", - origin: principal.origin, + launchUrl: principaluri.hostPort, }), actions: Object.fromEntries( [ - parsedSnoozeAction(principal.hostPort, principal.origin), - parsedSettingsAction(principal.origin), + parsedSnoozeAction(principaluri.hostPort), + parsedSettingsAction(principaluri.hostPort), ].filter(x => x.length) ), },