summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/extensions/api/messaging
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-05-20 09:47:09 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-06-07 11:15:42 +0000
commit189d4fd8fad9e3c776873be51938cd31a42b6177 (patch)
tree6497caeff5e383937996768766ab3bb2081a40b2 /chromium/chrome/browser/extensions/api/messaging
parent8bc75099d364490b22f43a7ce366b366c08f4164 (diff)
BASELINE: Update Chromium to 90.0.4430.221
Change-Id: Iff4d9d18d2fcf1a576f3b1f453010f744a232920 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/chrome/browser/extensions/api/messaging')
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/DIR_METADATA3
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/OWNERS2
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc4
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.h2
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/incognito_connectability.cc54
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/incognito_connectability.h18
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/incognito_connectability_infobar_delegate.cc20
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/incognito_connectability_infobar_delegate.h9
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/native_message_process_host.cc11
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc11
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/native_messaging_apitest.cc32
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/native_messaging_test_util.cc4
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/native_process_launcher.cc76
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/native_process_launcher.h14
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/native_process_launcher_posix.cc5
-rw-r--r--chromium/chrome/browser/extensions/api/messaging/native_process_launcher_win.cc61
16 files changed, 175 insertions, 151 deletions
diff --git a/chromium/chrome/browser/extensions/api/messaging/DIR_METADATA b/chromium/chrome/browser/extensions/api/messaging/DIR_METADATA
new file mode 100644
index 00000000000..637eb4dc771
--- /dev/null
+++ b/chromium/chrome/browser/extensions/api/messaging/DIR_METADATA
@@ -0,0 +1,3 @@
+monorail {
+ component: "Platform>Extensions>API"
+}
diff --git a/chromium/chrome/browser/extensions/api/messaging/OWNERS b/chromium/chrome/browser/extensions/api/messaging/OWNERS
index 8e55ee8768b..13300d5991c 100644
--- a/chromium/chrome/browser/extensions/api/messaging/OWNERS
+++ b/chromium/chrome/browser/extensions/api/messaging/OWNERS
@@ -3,5 +3,3 @@ rdevlin.cronin@chromium.org
# For native messaging.
sergeyu@chromium.org
-
-# COMPONENT: Platform>Extensions>API
diff --git a/chromium/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc b/chromium/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc
index 96b5419458b..221c6c4171d 100644
--- a/chromium/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc
+++ b/chromium/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc
@@ -155,10 +155,10 @@ void ChromeMessagingDelegate::QueryIncognitoConnectability(
const Extension* target_extension,
content::WebContents* source_contents,
const GURL& source_url,
- const base::Callback<void(bool)>& callback) {
+ base::OnceCallback<void(bool)> callback) {
DCHECK(context->IsOffTheRecord());
IncognitoConnectability::Get(context)->Query(
- target_extension, source_contents, source_url, callback);
+ target_extension, source_contents, source_url, std::move(callback));
}
} // namespace extensions
diff --git a/chromium/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.h b/chromium/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.h
index 050786e4951..83108e87d8e 100644
--- a/chromium/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.h
+++ b/chromium/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.h
@@ -44,7 +44,7 @@ class ChromeMessagingDelegate : public MessagingDelegate {
const Extension* extension,
content::WebContents* web_contents,
const GURL& url,
- const base::Callback<void(bool)>& callback) override;
+ base::OnceCallback<void(bool)> callback) override;
private:
DISALLOW_COPY_AND_ASSIGN(ChromeMessagingDelegate);
diff --git a/chromium/chrome/browser/extensions/api/messaging/incognito_connectability.cc b/chromium/chrome/browser/extensions/api/messaging/incognito_connectability.cc
index 2851891a952..b720b713497 100644
--- a/chromium/chrome/browser/extensions/api/messaging/incognito_connectability.cc
+++ b/chromium/chrome/browser/extensions/api/messaging/incognito_connectability.cc
@@ -60,24 +60,23 @@ IncognitoConnectability* IncognitoConnectability::Get(
return BrowserContextKeyedAPIFactory<IncognitoConnectability>::Get(context);
}
-void IncognitoConnectability::Query(
- const Extension* extension,
- content::WebContents* web_contents,
- const GURL& url,
- const base::Callback<void(bool)>& callback) {
+void IncognitoConnectability::Query(const Extension* extension,
+ content::WebContents* web_contents,
+ const GURL& url,
+ base::OnceCallback<void(bool)> callback) {
GURL origin = url.GetOrigin();
if (origin.is_empty()) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
if (IsInMap(extension, origin, allowed_origins_)) {
- callback.Run(true);
+ std::move(callback).Run(true);
return;
}
if (IsInMap(extension, origin, disallowed_origins_)) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
@@ -86,7 +85,7 @@ void IncognitoConnectability::Query(
InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents);
TabContext& tab_context = pending_origin[infobar_service];
- tab_context.callbacks.push_back(callback);
+ tab_context.callbacks.push_back(std::move(callback));
if (tab_context.infobar) {
// This tab is already displaying an infobar for this extension and origin.
return;
@@ -107,9 +106,9 @@ void IncognitoConnectability::Query(
l10n_util::GetStringFUTF16(template_id,
base::UTF8ToUTF16(origin.spec()),
base::UTF8ToUTF16(extension->name())),
- base::Bind(&IncognitoConnectability::OnInteractiveResponse,
- weak_factory_.GetWeakPtr(), extension->id(), origin,
- infobar_service));
+ base::BindOnce(&IncognitoConnectability::OnInteractiveResponse,
+ weak_factory_.GetWeakPtr(), extension->id(), origin,
+ infobar_service));
break;
}
@@ -125,11 +124,7 @@ void IncognitoConnectability::Query(
IncognitoConnectability::TabContext::TabContext() : infobar(nullptr) {
}
-IncognitoConnectability::TabContext::TabContext(const TabContext& other) =
- default;
-
-IncognitoConnectability::TabContext::~TabContext() {
-}
+IncognitoConnectability::TabContext::~TabContext() = default;
void IncognitoConnectability::OnInteractiveResponse(
const std::string& extension_id,
@@ -149,12 +144,13 @@ void IncognitoConnectability::OnInteractiveResponse(
break;
}
- DCHECK(base::Contains(pending_origins_, make_pair(extension_id, origin)));
- PendingOrigin& pending_origin =
- pending_origins_[make_pair(extension_id, origin)];
+ PendingOriginMap::iterator origin_it =
+ pending_origins_.find(make_pair(extension_id, origin));
+ DCHECK(origin_it != pending_origins_.end());
+ PendingOrigin& pending_origin = origin_it->second;
DCHECK(base::Contains(pending_origin, infobar_service));
- std::vector<base::Callback<void(bool)>> callbacks;
+ std::vector<base::OnceCallback<void(bool)>> callbacks;
if (response == ScopedAlertTracker::INTERACTIVE) {
// No definitive answer for this extension and origin. Execute only the
// callbacks associated with this tab.
@@ -164,9 +160,9 @@ void IncognitoConnectability::OnInteractiveResponse(
} else {
// We have a definitive answer for this extension and origin. Close all
// other infobars and answer all the callbacks.
- for (const auto& map_entry : pending_origin) {
+ for (auto& map_entry : pending_origin) {
InfoBarService* other_infobar_service = map_entry.first;
- const TabContext& other_tab_context = map_entry.second;
+ TabContext& other_tab_context = map_entry.second;
if (other_infobar_service != infobar_service) {
// Disarm the delegate so that it doesn't think the infobar has been
// dismissed.
@@ -176,15 +172,17 @@ void IncognitoConnectability::OnInteractiveResponse(
delegate->set_answered();
other_infobar_service->RemoveInfoBar(other_tab_context.infobar);
}
- callbacks.insert(callbacks.end(), other_tab_context.callbacks.begin(),
- other_tab_context.callbacks.end());
+ callbacks.insert(
+ callbacks.end(),
+ std::make_move_iterator(other_tab_context.callbacks.begin()),
+ std::make_move_iterator(other_tab_context.callbacks.end()));
}
- pending_origins_.erase(make_pair(extension_id, origin));
+ pending_origins_.erase(origin_it);
}
DCHECK(!callbacks.empty());
- for (const auto& callback : callbacks) {
- callback.Run(response == ScopedAlertTracker::ALWAYS_ALLOW);
+ for (auto& callback : callbacks) {
+ std::move(callback).Run(response == ScopedAlertTracker::ALWAYS_ALLOW);
}
}
diff --git a/chromium/chrome/browser/extensions/api/messaging/incognito_connectability.h b/chromium/chrome/browser/extensions/api/messaging/incognito_connectability.h
index f0fe400ca9f..3dbf249eb59 100644
--- a/chromium/chrome/browser/extensions/api/messaging/incognito_connectability.h
+++ b/chromium/chrome/browser/extensions/api/messaging/incognito_connectability.h
@@ -66,20 +66,24 @@ class IncognitoConnectability : public BrowserContextKeyedAPI {
void Query(const Extension* extension,
content::WebContents* web_contents,
const GURL& url,
- const base::Callback<void(bool)>& callback);
+ base::OnceCallback<void(bool)> callback);
private:
struct TabContext {
TabContext();
- TabContext(const TabContext& other);
~TabContext();
+ // TabContext can't be copied since the callbacks are OnceCallback (and
+ // hence, move-only).
+ TabContext(const TabContext& other) = delete;
+ TabContext& operator=(const TabContext&) = delete;
+
// The infobar being shown in a given tab. The InfoBarService maintains
// ownership of this object. This struct must always be destroyed before the
// infobar it tracks.
infobars::InfoBar* infobar;
// Connectability queries outstanding on this infobar.
- std::vector<base::Callback<void(bool)>> callbacks;
+ std::vector<base::OnceCallback<void(bool)>> callbacks;
};
friend class BrowserContextKeyedAPIFactory<IncognitoConnectability>;
@@ -87,10 +91,10 @@ class IncognitoConnectability : public BrowserContextKeyedAPI {
explicit IncognitoConnectability(content::BrowserContext* context);
~IncognitoConnectability() override;
- typedef std::map<std::string, std::set<GURL> > ExtensionToOriginsMap;
- typedef std::pair<std::string, GURL> ExtensionOriginPair;
- typedef std::map<InfoBarService*, TabContext> PendingOrigin;
- typedef std::map<ExtensionOriginPair, PendingOrigin> PendingOriginMap;
+ using ExtensionToOriginsMap = std::map<std::string, std::set<GURL>>;
+ using ExtensionOriginPair = std::pair<std::string, GURL>;
+ using PendingOrigin = std::map<InfoBarService*, TabContext>;
+ using PendingOriginMap = std::map<ExtensionOriginPair, PendingOrigin>;
// Called with the user's selection from the infobar.
// |response == INTERACTIVE| indicates that the user closed the infobar
diff --git a/chromium/chrome/browser/extensions/api/messaging/incognito_connectability_infobar_delegate.cc b/chromium/chrome/browser/extensions/api/messaging/incognito_connectability_infobar_delegate.cc
index 9cb9f98e5e7..e4ef6184982 100644
--- a/chromium/chrome/browser/extensions/api/messaging/incognito_connectability_infobar_delegate.cc
+++ b/chromium/chrome/browser/extensions/api/messaging/incognito_connectability_infobar_delegate.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/extensions/api/messaging/incognito_connectability_infobar_delegate.h"
+#include <utility>
+
#include "chrome/browser/infobars/infobar_service.h"
#include "components/infobars/core/infobar.h"
#include "components/strings/grit/components_strings.h"
@@ -15,16 +17,17 @@ namespace extensions {
infobars::InfoBar* IncognitoConnectabilityInfoBarDelegate::Create(
InfoBarService* infobar_service,
const base::string16& message,
- const IncognitoConnectabilityInfoBarDelegate::InfoBarCallback& callback) {
+ IncognitoConnectabilityInfoBarDelegate::InfoBarCallback callback) {
return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
std::unique_ptr<ConfirmInfoBarDelegate>(
- new IncognitoConnectabilityInfoBarDelegate(message, callback))));
+ new IncognitoConnectabilityInfoBarDelegate(message,
+ std::move(callback)))));
}
IncognitoConnectabilityInfoBarDelegate::IncognitoConnectabilityInfoBarDelegate(
const base::string16& message,
- const InfoBarCallback& callback)
- : message_(message), answered_(false), callback_(callback) {}
+ InfoBarCallback callback)
+ : message_(message), answered_(false), callback_(std::move(callback)) {}
IncognitoConnectabilityInfoBarDelegate::
~IncognitoConnectabilityInfoBarDelegate() {
@@ -32,7 +35,8 @@ IncognitoConnectabilityInfoBarDelegate::
// The infobar has closed without the user expressing an explicit
// preference. The current request should be denied but further requests
// should show an interactive prompt.
- callback_.Run(IncognitoConnectability::ScopedAlertTracker::INTERACTIVE);
+ std::move(callback_).Run(
+ IncognitoConnectability::ScopedAlertTracker::INTERACTIVE);
}
}
@@ -52,13 +56,15 @@ base::string16 IncognitoConnectabilityInfoBarDelegate::GetButtonLabel(
}
bool IncognitoConnectabilityInfoBarDelegate::Accept() {
- callback_.Run(IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW);
+ std::move(callback_).Run(
+ IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW);
answered_ = true;
return true;
}
bool IncognitoConnectabilityInfoBarDelegate::Cancel() {
- callback_.Run(IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY);
+ std::move(callback_).Run(
+ IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY);
answered_ = true;
return true;
}
diff --git a/chromium/chrome/browser/extensions/api/messaging/incognito_connectability_infobar_delegate.h b/chromium/chrome/browser/extensions/api/messaging/incognito_connectability_infobar_delegate.h
index 002dfe9c733..2630f0f6c20 100644
--- a/chromium/chrome/browser/extensions/api/messaging/incognito_connectability_infobar_delegate.h
+++ b/chromium/chrome/browser/extensions/api/messaging/incognito_connectability_infobar_delegate.h
@@ -16,15 +16,14 @@ namespace extensions {
class IncognitoConnectabilityInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
- typedef base::Callback<void(
- IncognitoConnectability::ScopedAlertTracker::Mode)>
- InfoBarCallback;
+ using InfoBarCallback = base::OnceCallback<void(
+ IncognitoConnectability::ScopedAlertTracker::Mode)>;
// Creates a confirmation infobar and delegate and adds the infobar to
// |infobar_service|.
static infobars::InfoBar* Create(InfoBarService* infobar_service,
const base::string16& message,
- const InfoBarCallback& callback);
+ InfoBarCallback callback);
// Marks the infobar as answered so that the callback is not executed when the
// delegate is destroyed.
@@ -32,7 +31,7 @@ class IncognitoConnectabilityInfoBarDelegate : public ConfirmInfoBarDelegate {
private:
IncognitoConnectabilityInfoBarDelegate(const base::string16& message,
- const InfoBarCallback& callback);
+ InfoBarCallback callback);
~IncognitoConnectabilityInfoBarDelegate() override;
// ConfirmInfoBarDelegate:
diff --git a/chromium/chrome/browser/extensions/api/messaging/native_message_process_host.cc b/chromium/chrome/browser/extensions/api/messaging/native_message_process_host.cc
index 27e2ca60e06..ba0419d4514 100644
--- a/chromium/chrome/browser/extensions/api/messaging/native_message_process_host.cc
+++ b/chromium/chrome/browser/extensions/api/messaging/native_message_process_host.cc
@@ -126,9 +126,10 @@ void NativeMessageProcessHost::LaunchHostProcess() {
DCHECK(task_runner_->BelongsToCurrentThread());
GURL origin(std::string(kExtensionScheme) + "://" + source_extension_id_);
- launcher_->Launch(origin, native_host_name_,
- base::Bind(&NativeMessageProcessHost::OnHostProcessLaunched,
- weak_factory_.GetWeakPtr()));
+ launcher_->Launch(
+ origin, native_host_name_,
+ base::BindOnce(&NativeMessageProcessHost::OnHostProcessLaunched,
+ weak_factory_.GetWeakPtr()));
}
void NativeMessageProcessHost::OnHostProcessLaunched(
@@ -230,8 +231,8 @@ void NativeMessageProcessHost::WaitRead() {
#if defined(OS_POSIX)
if (!read_controller_) {
read_controller_ = base::FileDescriptorWatcher::WatchReadable(
- read_file_,
- base::Bind(&NativeMessageProcessHost::DoRead, base::Unretained(this)));
+ read_file_, base::BindRepeating(&NativeMessageProcessHost::DoRead,
+ base::Unretained(this)));
}
#else // defined(OS_POSIX)
DoRead();
diff --git a/chromium/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc b/chromium/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc
index 3acc436a7ea..0da7603918e 100644
--- a/chromium/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc
+++ b/chromium/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc
@@ -99,9 +99,10 @@ class FakeLauncher : public NativeProcessLauncher {
void Launch(const GURL& origin,
const std::string& native_host_name,
- const LaunchedCallback& callback) const override {
- callback.Run(NativeProcessLauncher::RESULT_SUCCESS, base::Process(),
- std::move(read_file_), std::move(write_file_));
+ LaunchedCallback callback) const override {
+ std::move(callback).Run(NativeProcessLauncher::RESULT_SUCCESS,
+ base::Process(), std::move(read_file_),
+ std::move(write_file_));
}
private:
@@ -222,7 +223,7 @@ TEST_F(NativeMessagingTest, SingleSendMessageWrite) {
base::File read_file;
#if defined(OS_WIN)
- base::string16 pipe_name = base::StringPrintf(
+ std::wstring pipe_name = base::StringPrintf(
L"\\\\.\\pipe\\chrome.nativeMessaging.out.%llx", base::RandUint64());
base::File write_handle =
base::File(base::ScopedPlatformFile(CreateNamedPipeW(
@@ -357,7 +358,7 @@ TEST_F(NativeMessagingTest, MAYBE_ReconnectArgs) {
for (auto& arg : args_value->GetList()) {
ASSERT_TRUE(arg.is_string());
#if defined(OS_WIN)
- args.push_back(base::UTF8ToUTF16(arg.GetString()));
+ args.push_back(base::UTF8ToWide(arg.GetString()));
#else
args.push_back(arg.GetString());
#endif
diff --git a/chromium/chrome/browser/extensions/api/messaging/native_messaging_apitest.cc b/chromium/chrome/browser/extensions/api/messaging/native_messaging_apitest.cc
index b9409e86f31..c3fdd232e04 100644
--- a/chromium/chrome/browser/extensions/api/messaging/native_messaging_apitest.cc
+++ b/chromium/chrome/browser/extensions/api/messaging/native_messaging_apitest.cc
@@ -9,6 +9,7 @@
#include "base/strings/string_util.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
+#include "build/chromeos_buildflags.h"
#include "chrome/browser/background/background_mode_manager.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/messaging/native_messaging_launch_from_native.h"
@@ -24,7 +25,6 @@
#include "components/keep_alive_registry/keep_alive_types.h"
#include "content/public/test/browser_test.h"
#include "extensions/browser/process_manager.h"
-#include "extensions/common/scoped_worker_based_extensions_channel.h"
#include "extensions/test/result_catcher.h"
namespace extensions {
@@ -51,34 +51,20 @@ IN_PROC_BROWSER_TEST_F(NativeMessagingApiTest, UserLevelNativeMessaging) {
class NativeMessagingLazyApiTest
: public NativeMessagingApiTest,
public testing::WithParamInterface<ContextType> {
- public:
- NativeMessagingLazyApiTest() {
- // Service Workers are currently only available on certain channels, so set
- // the channel for those tests.
- if (GetParam() == ContextType::kServiceWorker)
- current_channel_ = std::make_unique<ScopedWorkerBasedExtensionsChannel>();
- }
-
protected:
bool RunLazyTest(const std::string& extension_name) {
- if (GetParam() == ContextType::kEventPage) {
- return RunExtensionTest(extension_name);
- }
- return RunExtensionTestWithFlags(
- extension_name, kFlagRunAsServiceWorkerBasedExtension, kFlagNone);
+ return RunExtensionTest(
+ {.name = extension_name.c_str()},
+ {.load_as_service_worker = GetParam() == ContextType::kServiceWorker});
}
-
- std::unique_ptr<ScopedWorkerBasedExtensionsChannel> current_channel_;
};
INSTANTIATE_TEST_SUITE_P(EventPage,
NativeMessagingLazyApiTest,
::testing::Values(ContextType::kEventPage));
-// Service Worker versions of these tests are flaky.
-// See http://crbug.com/1111536 and http://crbug.com/1111337.
-// INSTANTIATE_TEST_SUITE_P(ServiceWorker,
-// NativeMessagingLazyApiTest,
-// ::testing::Values(ContextType::kServiceWorker));
+INSTANTIATE_TEST_SUITE_P(ServiceWorker,
+ NativeMessagingLazyApiTest,
+ ::testing::Values(ContextType::kServiceWorker));
IN_PROC_BROWSER_TEST_P(NativeMessagingLazyApiTest, NativeMessagingBasic) {
ASSERT_NO_FATAL_FAILURE(test_host_.RegisterTestHost(false));
@@ -90,7 +76,7 @@ IN_PROC_BROWSER_TEST_P(NativeMessagingLazyApiTest, UserLevelNativeMessaging) {
ASSERT_TRUE(RunLazyTest("native_messaging_lazy")) << message_;
}
-#if !defined(OS_CHROMEOS)
+#if !BUILDFLAG(IS_CHROMEOS_ASH)
class TestProcessManagerObserver : public ProcessManagerObserver {
public:
@@ -444,7 +430,7 @@ IN_PROC_BROWSER_TEST_F(NativeMessagingLaunchBackgroundModeApiTest,
ASSERT_NO_FATAL_FAILURE(TestKeepAliveStateObserver().WaitForNoKeepAlive());
}
-#endif // !defined(OS_CHROMEOS)
+#endif // !BUILDFLAG(IS_CHROMEOS_ASH)
} // namespace
} // namespace extensions
diff --git a/chromium/chrome/browser/extensions/api/messaging/native_messaging_test_util.cc b/chromium/chrome/browser/extensions/api/messaging/native_messaging_test_util.cc
index 0a6b2022c0c..5335f0310e7 100644
--- a/chromium/chrome/browser/extensions/api/messaging/native_messaging_test_util.cc
+++ b/chromium/chrome/browser/extensions/api/messaging/native_messaging_test_util.cc
@@ -51,8 +51,8 @@ void WriteTestNativeHostManifest(const base::FilePath& target_dir,
#if defined(OS_WIN)
HKEY root_key = user_level ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
- base::string16 key = L"SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\" +
- base::UTF8ToUTF16(host_name);
+ std::wstring key = L"SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\" +
+ base::UTF8ToWide(host_name);
base::win::RegKey manifest_key(
root_key, key.c_str(),
KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK);
diff --git a/chromium/chrome/browser/extensions/api/messaging/native_process_launcher.cc b/chromium/chrome/browser/extensions/api/messaging/native_process_launcher.cc
index 439e74947e0..2a1d664775f 100644
--- a/chromium/chrome/browser/extensions/api/messaging/native_process_launcher.cc
+++ b/chromium/chrome/browser/extensions/api/messaging/native_process_launcher.cc
@@ -23,6 +23,7 @@
#include "base/path_service.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
+#include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool.h"
#include "base/values.h"
#include "build/build_config.h"
@@ -55,7 +56,7 @@ class NativeProcessLauncherImpl : public NativeProcessLauncher {
void Launch(const GURL& origin,
const std::string& native_host_name,
- const LaunchedCallback& callback) const override;
+ LaunchedCallback callback) const override;
private:
class Core : public base::RefCountedThreadSafe<Core> {
@@ -68,7 +69,7 @@ class NativeProcessLauncherImpl : public NativeProcessLauncher {
const std::string& error_arg);
void Launch(const GURL& origin,
const std::string& native_host_name,
- const LaunchedCallback& callback);
+ LaunchedCallback callback);
void Detach();
private:
@@ -77,13 +78,13 @@ class NativeProcessLauncherImpl : public NativeProcessLauncher {
void DoLaunchOnThreadPool(const GURL& origin,
const std::string& native_host_name,
- const LaunchedCallback& callback);
- void PostErrorResult(const LaunchedCallback& callback, LaunchResult error);
- void PostResult(const LaunchedCallback& callback,
+ LaunchedCallback callback);
+ void PostErrorResult(LaunchedCallback callback, LaunchResult error);
+ void PostResult(LaunchedCallback callback,
base::Process process,
base::File read_file,
base::File write_file);
- void CallCallbackOnIOThread(const LaunchedCallback& callback,
+ void CallCallbackOnIOThread(LaunchedCallback callback,
LaunchResult result,
base::Process process,
base::File read_file,
@@ -144,19 +145,19 @@ void NativeProcessLauncherImpl::Core::Detach() {
void NativeProcessLauncherImpl::Core::Launch(
const GURL& origin,
const std::string& native_host_name,
- const LaunchedCallback& callback) {
+ LaunchedCallback callback) {
base::ThreadPool::PostTask(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
base::BindOnce(&Core::DoLaunchOnThreadPool, this, origin,
- native_host_name, callback));
+ native_host_name, std::move(callback)));
}
void NativeProcessLauncherImpl::Core::DoLaunchOnThreadPool(
const GURL& origin,
const std::string& native_host_name,
- const LaunchedCallback& callback) {
+ LaunchedCallback callback) {
if (!NativeMessagingHostManifest::IsValidName(native_host_name)) {
- PostErrorResult(callback, RESULT_INVALID_NAME);
+ PostErrorResult(std::move(callback), RESULT_INVALID_NAME);
return;
}
@@ -167,7 +168,7 @@ void NativeProcessLauncherImpl::Core::DoLaunchOnThreadPool(
if (manifest_path.empty()) {
LOG(WARNING) << "Can't find manifest for native messaging host "
<< native_host_name;
- PostErrorResult(callback, RESULT_NOT_FOUND);
+ PostErrorResult(std::move(callback), RESULT_NOT_FOUND);
return;
}
@@ -177,7 +178,7 @@ void NativeProcessLauncherImpl::Core::DoLaunchOnThreadPool(
if (!manifest) {
LOG(WARNING) << "Failed to load manifest for native messaging host "
<< native_host_name << ": " << error_message;
- PostErrorResult(callback, RESULT_NOT_FOUND);
+ PostErrorResult(std::move(callback), RESULT_NOT_FOUND);
return;
}
@@ -185,19 +186,19 @@ void NativeProcessLauncherImpl::Core::DoLaunchOnThreadPool(
LOG(WARNING) << "Failed to load manifest for native messaging host "
<< native_host_name
<< ": Invalid name specified in the manifest.";
- PostErrorResult(callback, RESULT_NOT_FOUND);
+ PostErrorResult(std::move(callback), RESULT_NOT_FOUND);
return;
}
if (!manifest->allowed_origins().MatchesSecurityOrigin(origin)) {
// Not an allowed origin.
- PostErrorResult(callback, RESULT_FORBIDDEN);
+ PostErrorResult(std::move(callback), RESULT_FORBIDDEN);
return;
}
if (require_native_initiated_connections_ &&
!manifest->supports_native_initiated_connections()) {
- PostErrorResult(callback, RESULT_FORBIDDEN);
+ PostErrorResult(std::move(callback), RESULT_FORBIDDEN);
return;
}
@@ -210,7 +211,7 @@ void NativeProcessLauncherImpl::Core::DoLaunchOnThreadPool(
#else // defined(OS_WIN)
LOG(WARNING) << "Native messaging host path must be absolute for "
<< native_host_name;
- PostErrorResult(callback, RESULT_NOT_FOUND);
+ PostErrorResult(std::move(callback), RESULT_NOT_FOUND);
return;
#endif // !defined(OS_WIN)
}
@@ -222,7 +223,7 @@ void NativeProcessLauncherImpl::Core::DoLaunchOnThreadPool(
<< "Found manifest, but not the binary for native messaging host "
<< native_host_name << ". Host path specified in the manifest: "
<< host_path.AsUTF8Unsafe();
- PostErrorResult(callback, RESULT_NOT_FOUND);
+ PostErrorResult(std::move(callback), RESULT_NOT_FOUND);
return;
}
@@ -267,7 +268,11 @@ void NativeProcessLauncherImpl::Core::DoLaunchOnThreadPool(
#endif
base::Value args(base::Value::Type::LIST);
for (const auto& arg : reconnect_command_line.argv()) {
+#if defined(OS_WIN)
+ args.Append(base::WideToUTF8(arg));
+#else
args.Append(arg);
+#endif
}
std::string encoded_reconnect_command;
bool success =
@@ -288,15 +293,15 @@ void NativeProcessLauncherImpl::Core::DoLaunchOnThreadPool(
base::File write_file;
if (NativeProcessLauncher::LaunchNativeProcess(
command_line, &process, &read_file, &write_file)) {
- PostResult(callback, std::move(process), std::move(read_file),
+ PostResult(std::move(callback), std::move(process), std::move(read_file),
std::move(write_file));
} else {
- PostErrorResult(callback, RESULT_FAILED_TO_START);
+ PostErrorResult(std::move(callback), RESULT_FAILED_TO_START);
}
}
void NativeProcessLauncherImpl::Core::CallCallbackOnIOThread(
- const LaunchedCallback& callback,
+ LaunchedCallback callback,
LaunchResult result,
base::Process process,
base::File read_file,
@@ -305,30 +310,29 @@ void NativeProcessLauncherImpl::Core::CallCallbackOnIOThread(
if (detached_)
return;
- callback.Run(result, std::move(process), std::move(read_file),
- std::move(write_file));
+ std::move(callback).Run(result, std::move(process), std::move(read_file),
+ std::move(write_file));
}
-void NativeProcessLauncherImpl::Core::PostErrorResult(
- const LaunchedCallback& callback,
- LaunchResult error) {
+void NativeProcessLauncherImpl::Core::PostErrorResult(LaunchedCallback callback,
+ LaunchResult error) {
content::GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&NativeProcessLauncherImpl::Core::CallCallbackOnIOThread,
- this, callback, error, base::Process(), base::File(),
- base::File()));
+ this, std::move(callback), error, base::Process(),
+ base::File(), base::File()));
}
-void NativeProcessLauncherImpl::Core::PostResult(
- const LaunchedCallback& callback,
- base::Process process,
- base::File read_file,
- base::File write_file) {
+void NativeProcessLauncherImpl::Core::PostResult(LaunchedCallback callback,
+ base::Process process,
+ base::File read_file,
+ base::File write_file) {
content::GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&NativeProcessLauncherImpl::Core::CallCallbackOnIOThread,
- this, callback, RESULT_SUCCESS, std::move(process),
- std::move(read_file), std::move(write_file)));
+ this, std::move(callback), RESULT_SUCCESS,
+ std::move(process), std::move(read_file),
+ std::move(write_file)));
}
NativeProcessLauncherImpl::NativeProcessLauncherImpl(
@@ -351,8 +355,8 @@ NativeProcessLauncherImpl::~NativeProcessLauncherImpl() {
void NativeProcessLauncherImpl::Launch(const GURL& origin,
const std::string& native_host_name,
- const LaunchedCallback& callback) const {
- core_->Launch(origin, native_host_name, callback);
+ LaunchedCallback callback) const {
+ core_->Launch(origin, native_host_name, std::move(callback));
}
} // namespace
diff --git a/chromium/chrome/browser/extensions/api/messaging/native_process_launcher.h b/chromium/chrome/browser/extensions/api/messaging/native_process_launcher.h
index 3d971fda199..b8bfbd2a210 100644
--- a/chromium/chrome/browser/extensions/api/messaging/native_process_launcher.h
+++ b/chromium/chrome/browser/extensions/api/messaging/native_process_launcher.h
@@ -35,10 +35,10 @@ class NativeProcessLauncher {
// Callback that's called after the process has been launched. |result| is set
// to false in case of a failure. Handler must take ownership of the IO
// handles.
- typedef base::Callback<void(LaunchResult result,
- base::Process process,
- base::File read_file,
- base::File write_file)> LaunchedCallback;
+ using LaunchedCallback = base::OnceCallback<void(LaunchResult result,
+ base::Process process,
+ base::File read_file,
+ base::File write_file)>;
// Creates default launcher for the current OS. |native_view| refers to the
// window that contains calling page. Can be nullptr, e.g. for background
@@ -57,8 +57,8 @@ class NativeProcessLauncher {
const std::string& connect_id,
const std::string& error_arg);
- NativeProcessLauncher() {}
- virtual ~NativeProcessLauncher() {}
+ NativeProcessLauncher() = default;
+ virtual ~NativeProcessLauncher() = default;
// Finds native messaging host with the specified name and launches it
// asynchronously. Also checks that the specified |origin| is permitted to
@@ -68,7 +68,7 @@ class NativeProcessLauncher {
// closing IO pipes).
virtual void Launch(const GURL& origin,
const std::string& native_host_name,
- const LaunchedCallback& callback) const = 0;
+ LaunchedCallback callback) const = 0;
protected:
// The following two methods are platform specific and are implemented in
diff --git a/chromium/chrome/browser/extensions/api/messaging/native_process_launcher_posix.cc b/chromium/chrome/browser/extensions/api/messaging/native_process_launcher_posix.cc
index 7afd31723d5..27398beca00 100644
--- a/chromium/chrome/browser/extensions/api/messaging/native_process_launcher_posix.cc
+++ b/chromium/chrome/browser/extensions/api/messaging/native_process_launcher_posix.cc
@@ -14,6 +14,7 @@
#include "base/posix/eintr_wrapper.h"
#include "base/process/launch.h"
#include "build/build_config.h"
+#include "build/chromeos_buildflags.h"
#include "chrome/common/chrome_paths.h"
namespace extensions {
@@ -79,7 +80,9 @@ bool NativeProcessLauncher::LaunchNativeProcess(
options.current_directory = command_line.GetProgram().DirName();
-#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
+// of lacros-chrome is complete.
+#if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
// Don't use no_new_privs mode, e.g. in case the host needs to use sudo.
options.allow_new_privs = true;
#endif
diff --git a/chromium/chrome/browser/extensions/api/messaging/native_process_launcher_win.cc b/chromium/chrome/browser/extensions/api/messaging/native_process_launcher_win.cc
index 5b55b0c6437..78e53631a16 100644
--- a/chromium/chrome/browser/extensions/api/messaging/native_process_launcher_win.cc
+++ b/chromium/chrome/browser/extensions/api/messaging/native_process_launcher_win.cc
@@ -17,37 +17,58 @@
#include "base/strings/utf_string_conversions.h"
#include "base/win/registry.h"
#include "base/win/scoped_handle.h"
+#include "build/branding_buildflags.h"
#include "crypto/random.h"
namespace extensions {
-const wchar_t kNativeMessagingRegistryKey[] =
+const wchar_t kChromeNativeMessagingRegistryKey[] =
L"SOFTWARE\\Google\\Chrome\\NativeMessagingHosts";
+#if BUILDFLAG(CHROMIUM_BRANDING)
+const wchar_t kChromiumNativeMessagingRegistryKey[] =
+ L"SOFTWARE\\Chromium\\NativeMessagingHosts";
+#endif
namespace {
+// Reads path to the native messaging host manifest from a specific subkey in
+// the registry. Returns false if the path isn't found.
+bool GetManifestPathWithFlagsFromSubkey(HKEY root_key,
+ DWORD flags,
+ const wchar_t* subkey,
+ const std::wstring& host_name,
+ std::wstring* result) {
+ base::win::RegKey key;
+
+ return key.Open(root_key, subkey, KEY_QUERY_VALUE | flags) == ERROR_SUCCESS &&
+ key.OpenKey(host_name.c_str(), KEY_QUERY_VALUE | flags) ==
+ ERROR_SUCCESS &&
+ key.ReadValue(nullptr, result) == ERROR_SUCCESS;
+}
+
// Reads path to the native messaging host manifest from the registry. Returns
// false if the path isn't found.
bool GetManifestPathWithFlags(HKEY root_key,
DWORD flags,
- const base::string16& host_name,
- base::string16* result) {
- base::win::RegKey key;
-
- if (key.Open(root_key, kNativeMessagingRegistryKey,
- KEY_QUERY_VALUE | flags) != ERROR_SUCCESS ||
- key.OpenKey(host_name.c_str(),
- KEY_QUERY_VALUE | flags) != ERROR_SUCCESS ||
- key.ReadValue(NULL, result) != ERROR_SUCCESS) {
- return false;
+ const std::wstring& host_name,
+ std::wstring* result) {
+#if BUILDFLAG(CHROMIUM_BRANDING)
+ // Try to read the path using the Chromium-specific registry for Chromium.
+ // If that fails, fallback to Chrome-specific registry key below.
+ if (GetManifestPathWithFlagsFromSubkey(root_key, flags,
+ kChromiumNativeMessagingRegistryKey,
+ host_name, result)) {
+ return true;
}
+#endif
- return true;
+ return GetManifestPathWithFlagsFromSubkey(
+ root_key, flags, kChromeNativeMessagingRegistryKey, host_name, result);
}
bool GetManifestPath(HKEY root_key,
- const base::string16& host_name,
- base::string16* result) {
+ const std::wstring& host_name,
+ std::wstring* result) {
// First check 32-bit registry and then try 64-bit.
return GetManifestPathWithFlags(
root_key, KEY_WOW64_32KEY, host_name, result) ||
@@ -62,11 +83,11 @@ base::FilePath NativeProcessLauncher::FindManifest(
const std::string& host_name,
bool allow_user_level_hosts,
std::string* error_message) {
- base::string16 host_name_wide = base::UTF8ToUTF16(host_name);
+ std::wstring host_name_wide = base::UTF8ToWide(host_name);
// If permitted, look in HKEY_CURRENT_USER first. If the manifest isn't found
// there, then try HKEY_LOCAL_MACHINE. https://crbug.com/1034919#c6
- base::string16 path_str;
+ std::wstring path_str;
bool found = false;
if (allow_user_level_hosts)
found = GetManifestPath(HKEY_CURRENT_USER, host_name_wide, &path_str);
@@ -108,9 +129,9 @@ bool NativeProcessLauncher::LaunchNativeProcess(
uint64_t pipe_name_token;
crypto::RandBytes(&pipe_name_token, sizeof(pipe_name_token));
- base::string16 out_pipe_name = base::StringPrintf(
+ std::wstring out_pipe_name = base::StringPrintf(
L"\\\\.\\pipe\\chrome.nativeMessaging.out.%llx", pipe_name_token);
- base::string16 in_pipe_name = base::StringPrintf(
+ std::wstring in_pipe_name = base::StringPrintf(
L"\\\\.\\pipe\\chrome.nativeMessaging.in.%llx", pipe_name_token);
// Create the pipes to read and write from.
@@ -144,9 +165,9 @@ bool NativeProcessLauncher::LaunchNativeProcess(
std::unique_ptr<wchar_t[]> comspec(new wchar_t[comspec_length]);
::GetEnvironmentVariable(L"COMSPEC", comspec.get(), comspec_length);
- base::string16 command_line_string = command_line.GetCommandLineString();
+ std::wstring command_line_string = command_line.GetCommandLineString();
- base::string16 command = base::StringPrintf(
+ std::wstring command = base::StringPrintf(
L"%ls /d /c %ls < %ls > %ls", comspec.get(), command_line_string.c_str(),
in_pipe_name.c_str(), out_pipe_name.c_str());