Commit da40ea37 authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

Win Native Notifications: Fix window activation (2nd attempt).

This fixes the issue with window activation not functioning correctly
when notifications are activated while Chrome is running but in the
background.

Bug: 837796, 734095
Change-Id: I69f5c358ba55fa997e1c3859d653638131f1394c
Reviewed-on: https://chromium-review.googlesource.com/1051708
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557949}
parent 25f03011
...@@ -259,6 +259,9 @@ TEST_F(NotificationHelperLaunchesChrome, ChromeLaunchTest) { ...@@ -259,6 +259,9 @@ TEST_F(NotificationHelperLaunchesChrome, ChromeLaunchTest) {
IID_PPV_ARGS(&notification_activator))); IID_PPV_ARGS(&notification_activator)));
ASSERT_TRUE(notification_activator); ASSERT_TRUE(notification_activator);
ASSERT_HRESULT_SUCCEEDED(
::CoAllowSetForegroundWindow(notification_activator.Get(), nullptr));
// The notification_helper server is now invoked upon the request of creating // The notification_helper server is now invoked upon the request of creating
// the object instance. The server module now holds a reference of the // the object instance. The server module now holds a reference of the
// instance object, the notification_helper.exe process is alive waiting for // instance object, the notification_helper.exe process is alive waiting for
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <shellapi.h> #include <shellapi.h>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/process/process.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/win/windows_types.h" #include "base/win/windows_types.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
...@@ -77,7 +78,8 @@ HRESULT NotificationActivator::Activate( ...@@ -77,7 +78,8 @@ HRESULT NotificationActivator::Activate(
SHELLEXECUTEINFO info; SHELLEXECUTEINFO info;
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
info.cbSize = sizeof(info); info.cbSize = sizeof(info);
info.fMask = SEE_MASK_NOASYNC | SEE_MASK_FLAG_LOG_USAGE; info.fMask =
SEE_MASK_NOASYNC | SEE_MASK_FLAG_LOG_USAGE | SEE_MASK_NOCLOSEPROCESS;
info.lpFile = chrome_exe_path.value().c_str(); info.lpFile = chrome_exe_path.value().c_str();
info.lpParameters = params.c_str(); info.lpParameters = params.c_str();
info.nShow = SW_SHOWNORMAL; info.nShow = SW_SHOWNORMAL;
...@@ -88,6 +90,17 @@ HRESULT NotificationActivator::Activate( ...@@ -88,6 +90,17 @@ HRESULT NotificationActivator::Activate(
return HRESULT_FROM_WIN32(error_code); return HRESULT_FROM_WIN32(error_code);
} }
if (info.hProcess != nullptr) {
base::Process process(info.hProcess);
DWORD pid = ::GetProcessId(process.Handle());
if (!::AllowSetForegroundWindow(pid)) {
DWORD error_code = ::GetLastError();
Trace(L"Unable to forward activation privilege; error: 0x%08X\n",
error_code);
return HRESULT_FROM_WIN32(error_code);
}
}
return S_OK; return S_OK;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment