Commit ae5109c1 authored by Nick Alexander's avatar Nick Alexander
Browse files

Bug 1788960 - Part 1: Round trip `name` for privileged alerts through Firefox restart. r=nrishel

On Windows, when an alert is privileged and `name` is non-empty, round
trip its `name` (as `privilegedName`) through the Windows notification
mechanism, and provide it to the "relaunch" callback.

Differential Revision: https://phabricator.services.mozilla.com/D156636
parent 0aa272d8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -763,6 +763,7 @@ const MESSAGES = () => [
        },
        { action: "callback", title: "Callback" },
      ],
      tag: "test_toast_notification",
    },
    groups: ["panel-test-provider"],
    targeting: "!hasActiveEnterprisePolicies",
+4 −1
Original line number Diff line number Diff line
@@ -16,9 +16,12 @@ interface nsIUnknownWindowsTagListener : nsISupports
   *
   * @param {AString} aWindowsTag the tag
   * @param {AString} aLaunchURL associated launch URL, or null.
   * @param {AString} aPrivilegedName associated alert name if this is a chrome
   *                                  privileged alert, or null.
   */
  void handleUnknownWindowsTag(in AString aWindowsTag,
                               in AString aLaunchURL);
                               in AString aLaunchURL,
                               in AString aPrivilegedName);
};

[scriptable, uuid(e01c8066-fb4b-4304-b9c9-ab6ed4a8322c)]
+9 −6
Original line number Diff line number Diff line
@@ -563,13 +563,16 @@ ToastNotification::HandleWindowsTag(const nsAString& aWindowsTag,

  MOZ_LOG(sWASLog, LogLevel::Debug, ("aListener [%p]", aListener));
  if (aListener) {
    bool foundTag;
    nsAutoString launchUrl;
    MOZ_TRY(ToastNotificationHandler::FindLaunchURLForWindowsTag(
        aWindowsTag, mAumid.ref(), launchUrl));

    MOZ_LOG(sWASLog, LogLevel::Debug,
            ("Found launchUrl [%s]", NS_ConvertUTF16toUTF8(launchUrl).get()));
    aListener->HandleUnknownWindowsTag(aWindowsTag, launchUrl);
    nsAutoString privilegedName;
    MOZ_TRY(
        ToastNotificationHandler::FindLaunchURLAndPrivilegedNameForWindowsTag(
            aWindowsTag, mAumid.ref(), foundTag, launchUrl, privilegedName));

    // The tag should always be found, so invoke the callback (even just for
    // logging).
    aListener->HandleUnknownWindowsTag(aWindowsTag, launchUrl, privilegedName);
  }

  return NS_OK;
+30 −7
Original line number Diff line number Diff line
@@ -230,6 +230,11 @@ Result<nsString, nsresult> ToastNotificationHandler::GetLaunchArgument() {
    launchArg += u"\nlaunchUrl\n"_ns + mLaunchUrl;
  }

  if (mIsSystemPrincipal && !mName.IsEmpty()) {
    // Privileged alerts include any provided name for metrics.
    launchArg += u"\nprivilegedName\n"_ns + mName;
  }

  // `windowsTag` argument.
  launchArg += u"\nwindowsTag\n"_ns + mWindowsTag;

@@ -847,19 +852,24 @@ ToastNotificationHandler::FindNotificationByTag(const nsAString& aWindowsTag,
  return E_FAIL;
}

/* static */ nsresult ToastNotificationHandler::FindLaunchURLForWindowsTag(
    const nsAString& aWindowsTag, const nsAString& aAumid,
    nsAString& aLaunchUrl) {
/* static */ nsresult
ToastNotificationHandler::FindLaunchURLAndPrivilegedNameForWindowsTag(
    const nsAString& aWindowsTag, const nsAString& aAumid, bool& aFoundTag,
    nsAString& aLaunchUrl, nsAString& aPrivilegedName) {
  aFoundTag = false;
  aLaunchUrl.Truncate();
  aPrivilegedName.Truncate();

  ComPtr<IToastNotification> toast =
      ToastNotificationHandler::FindNotificationByTag(aWindowsTag, aAumid);
  MOZ_LOG(sWASLog, LogLevel::Debug, ("Found toast [%p]", toast.Get()));

  if (!toast) {
    return NS_ERROR_FAILURE;
    return NS_OK;
  }

  aFoundTag = true;

  HRESULT hr = ToastNotificationHandler::GetLaunchArgumentValueForKey(
      toast, u"launchUrl"_ns, aLaunchUrl);

@@ -867,11 +877,24 @@ ToastNotificationHandler::FindNotificationByTag(const nsAString& aWindowsTag,
    MOZ_LOG(sWASLog, LogLevel::Debug,
            ("Did not find launchUrl [hr=0x%08lX]", hr));
    aLaunchUrl.SetIsVoid(true);
    return NS_OK;
  } else {
    MOZ_LOG(sWASLog, LogLevel::Debug,
            ("Found launchUrl [%s]", NS_ConvertUTF16toUTF8(aLaunchUrl).get()));
  }

  hr = ToastNotificationHandler::GetLaunchArgumentValueForKey(
      toast, u"privilegedName"_ns, aPrivilegedName);

  if (!SUCCEEDED(hr)) {
    MOZ_LOG(sWASLog, LogLevel::Debug,
          ("Found launchUrl [%s]", NS_ConvertUTF16toUTF8(aLaunchUrl).get()));
            ("Did not find privilegedName [hr=0x%08lX]", hr));
    aPrivilegedName.SetIsVoid(true);
  } else {
    MOZ_LOG(sWASLog, LogLevel::Debug,
            ("Found privilegedName [%s]",
             NS_ConvertUTF16toUTF8(aPrivilegedName).get()));
  }

  return NS_OK;
}

+3 −3
Original line number Diff line number Diff line
@@ -62,9 +62,9 @@ class ToastNotificationHandler final
  nsresult SetWindowsTag(const nsAString& aWindowsTag);

  // Exposed for consumption by `ToastNotification.cpp`.
  static nsresult FindLaunchURLForWindowsTag(const nsAString& aWindowsTag,
                                             const nsAString& aAumid,
                                             nsAString& aLaunchUrl);
  static nsresult FindLaunchURLAndPrivilegedNameForWindowsTag(
      const nsAString& aWindowsTag, const nsAString& aAumid, bool& aFoundTag,
      nsAString& aLaunchUrl, nsAString& aPrivilegedName);

 protected:
  virtual ~ToastNotificationHandler();
Loading