Browse Source

fix: calculate a hash for the Tag property of ToastNotification. (#42272)

* fix: calculate a hash for the Tag property of ToastNotification.

Co-authored-by: bill.shen <[email protected]>

* fix: calculate a hash for the Tag property of ToastNotification.

Co-authored-by: bill.shen <[email protected]>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: bill.shen <[email protected]>
trop[bot] 10 months ago
parent
commit
6b86fb4bbb
1 changed files with 7 additions and 2 deletions
  1. 7 2
      shell/browser/notifications/win/windows_toast_notification.cc

+ 7 - 2
shell/browser/notifications/win/windows_toast_notification.cc

@@ -14,6 +14,7 @@
 #include <wrl\wrappers\corewrappers.h>
 
 #include "base/environment.h"
+#include "base/hash/hash.h"
 #include "base/logging.h"
 #include "base/strings/strcat.h"
 #include "base/strings/string_number_conversions.h"
@@ -71,6 +72,10 @@ void DebugLog(std::string_view log_msg) {
     LOG(INFO) << log_msg;
 }
 
+std::wstring GetTag(const std::string& notification_id) {
+  return base::NumberToWString(base::Hash(notification_id));
+}
+
 }  // namespace
 
 // static
@@ -146,7 +151,7 @@ void WindowsToastNotification::Remove() {
     return;
 
   ScopedHString group(kGroup);
-  ScopedHString tag(base::as_wcstr(base::UTF8ToUTF16(notification_id())));
+  ScopedHString tag(GetTag(notification_id()));
   notification_history->RemoveGroupedTagWithId(tag, group, app_id);
 }
 
@@ -199,7 +204,7 @@ HRESULT WindowsToastNotification::ShowInternal(
   REPORT_AND_RETURN_IF_FAILED(toast2->put_Group(group),
                               "WinAPI: Setting group failed");
 
-  ScopedHString tag(base::as_wcstr(base::UTF8ToUTF16(notification_id())));
+  ScopedHString tag(GetTag(notification_id()));
   REPORT_AND_RETURN_IF_FAILED(toast2->put_Tag(tag),
                               "WinAPI: Setting tag failed");