Files
electron/shell/browser/win/scoped_hstring.h
Samuel Attard c9a1cff273 fix: dispatch toast action and reply events from WinRT activation path (#51397)
fix: dispatch toast action and reply events from WinRT activation path (#51286)

* fix: dispatch toast action and reply events from WinRT activation path

ToastEventHandler::Invoke previously returned S_OK without dispatching
whenever the activation arguments looked structured (type=action,
type=reply, or contained &tag=), on the assumption that the COM
INotificationActivationCallback::Activate path would deliver the event
instead. That assumption only holds when Windows actually invokes the
COM activator — which it does for MSIX-packaged apps launched cold, and
for unpackaged apps with a properly-registered CLSID when the app is
not already running. For non-MSIX apps with activationType="foreground"
while the app is running (the common case), Windows raises only the
in-process WinRT Activated event, so action and reply were silently
dropped.

Dispatch structured activations through the same HandleToastActivation
the COM path uses. User input (reply text, selection values) is pulled
from IToastActivatedEventArgs2::UserInput, which carries the data the
COM callback would otherwise have received via
NOTIFICATION_USER_INPUT_DATA.

Also drop the &tag= term from the structured-args check. Plain clicks
in Electron-generated XML don't carry tag=, and a custom toast_xml that
puts tag= on a click argument should now dispatch as a click rather
than being silently dropped.

* fix: release HSTRING out-params from toast activation

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2026-04-29 23:58:36 -05:00

53 lines
1.3 KiB
C++

// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-CHROMIUM file.
#ifndef ELECTRON_SHELL_BROWSER_WIN_SCOPED_HSTRING_H_
#define ELECTRON_SHELL_BROWSER_WIN_SCOPED_HSTRING_H_
#include <hstring.h>
#include <windows.h>
#include <string>
namespace electron {
class ScopedHString {
public:
// Copy from |source|.
explicit ScopedHString(const wchar_t* source);
explicit ScopedHString(const std::wstring& source);
// Create empty string.
ScopedHString();
~ScopedHString();
// disable copy
ScopedHString(const ScopedHString&) = delete;
ScopedHString& operator=(const ScopedHString&) = delete;
// Sets to |source|.
void Reset();
void Reset(const wchar_t* source);
void Reset(const std::wstring& source);
// Returns string.
operator HSTRING() const { return str_; }
// Resets and returns the address for use as an out-parameter. The returned
// HSTRING will be released via WindowsDeleteString on destruction.
HSTRING* Receive() {
Reset();
return &str_;
}
// Whether there is a string created.
bool success() const { return str_; }
private:
HSTRING str_ = nullptr;
};
} // namespace electron
#endif // ELECTRON_SHELL_BROWSER_WIN_SCOPED_HSTRING_H_