Commit d89eb5a7 authored by Utkarsh Patankar's avatar Utkarsh Patankar Committed by Chromium LUCI CQ

Add separate registry location for Native Messaging for Chromium

Chromium and Google Chrome should use separate registry locations to
specify the native messaging host manifest file. Chromium and Chrome
already use separate locations on platforms other than Windows. This CL
separates it for Windows too.

All native messaging extensions that currently work with Chromium use
the Chrome registry location. So, retain the Chrome registry location as
fallback option for Chromium to maintain backward compatibility.

Bug: 1106717
Change-Id: I8889efbfdf238b798d0956812fa73d48b15f14dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2569168
Auto-Submit: Utkarsh Patankar <utkpat@microsoft.com>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836926}
parent 0b8372cd
...@@ -17,32 +17,53 @@ ...@@ -17,32 +17,53 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/win/registry.h" #include "base/win/registry.h"
#include "base/win/scoped_handle.h" #include "base/win/scoped_handle.h"
#include "build/branding_buildflags.h"
#include "crypto/random.h" #include "crypto/random.h"
namespace extensions { namespace extensions {
const wchar_t kNativeMessagingRegistryKey[] = const wchar_t kChromeNativeMessagingRegistryKey[] =
L"SOFTWARE\\Google\\Chrome\\NativeMessagingHosts"; L"SOFTWARE\\Google\\Chrome\\NativeMessagingHosts";
#if BUILDFLAG(CHROMIUM_BRANDING)
const wchar_t kChromiumNativeMessagingRegistryKey[] =
L"SOFTWARE\\Chromium\\NativeMessagingHosts";
#endif
namespace { 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 base::string16& host_name,
base::string16* 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 // Reads path to the native messaging host manifest from the registry. Returns
// false if the path isn't found. // false if the path isn't found.
bool GetManifestPathWithFlags(HKEY root_key, bool GetManifestPathWithFlags(HKEY root_key,
DWORD flags, DWORD flags,
const base::string16& host_name, const base::string16& host_name,
base::string16* result) { base::string16* result) {
base::win::RegKey key; #if BUILDFLAG(CHROMIUM_BRANDING)
// Try to read the path using the Chromium-specific registry for Chromium.
if (key.Open(root_key, kNativeMessagingRegistryKey, // If that fails, fallback to Chrome-specific registry key below.
KEY_QUERY_VALUE | flags) != ERROR_SUCCESS || if (GetManifestPathWithFlagsFromSubkey(root_key, flags,
key.OpenKey(host_name.c_str(), kChromiumNativeMessagingRegistryKey,
KEY_QUERY_VALUE | flags) != ERROR_SUCCESS || host_name, result)) {
key.ReadValue(NULL, result) != ERROR_SUCCESS) { return true;
return false;
} }
#endif
return true; return GetManifestPathWithFlagsFromSubkey(
root_key, flags, kChromeNativeMessagingRegistryKey, host_name, result);
} }
bool GetManifestPath(HKEY root_key, bool GetManifestPath(HKEY root_key,
......
...@@ -73,11 +73,24 @@ following fields: ...@@ -73,11 +73,24 @@ following fields:
<p id="native-messaging-host-location-windows"> <p id="native-messaging-host-location-windows">
On <b>Windows</b>, the manifest file can be located anywhere in the file system. On <b>Windows</b>, the manifest file can be located anywhere in the file system.
The application installer must create registry key The application installer must create a registry key and set default value of
<code>HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts\<em>com.my_company.my_application</em></code> that key to the full path to the manifest file. The registry key varies by the
or browser (Google Chrome or Chromium). If the registry key specific to Chromium
<code>HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts\<em>com.my_company.my_application</em></code>, is absent, the registry key for Google Chrome is used as fallback in Chromium.
and set default value of that key to the full path to the manifest file.
<dl>
<dt>System-wide:
<dd>Google Chrome: <code>HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts\
<em>com.my_company.my_application</em></code>
<dd>Chromium: <code>HKEY_LOCAL_MACHINE\SOFTWARE\Chromium\NativeMessagingHosts\
<em>com.my_company.my_application</em></code>
<dt>User-level:
<dd>Google Chrome: <code>HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts\
<em>com.my_company.my_application</em></code>
<dd>Chromium: <code>HKEY_CURRENT_USER\SOFTWARE\Chromium\NativeMessagingHosts\
<em>com.my_company.my_application</em></code>
</dl>
For example, using the following command:<br> For example, using the following command:<br>
<pre> <pre>
REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\<em>com.my_company.my_application</em>" /ve /t REG_SZ /d "C:\path\to\nmh-manifest.json" /f REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\<em>com.my_company.my_application</em>" /ve /t REG_SZ /d "C:\path\to\nmh-manifest.json" /f
...@@ -96,7 +109,7 @@ On <b>OS X</b> and <b>Linux</b>, the location of the native messaging host's ...@@ -96,7 +109,7 @@ On <b>OS X</b> and <b>Linux</b>, the location of the native messaging host's
manifest file varies by the browser (Google Chrome or Chromium). manifest file varies by the browser (Google Chrome or Chromium).
The system-wide native messaging hosts are looked up at a fixed location, The system-wide native messaging hosts are looked up at a fixed location,
while the user-level native messaging hosts are looked up in a subdirectory within the while the user-level native messaging hosts are looked up in a subdirectory within the
<a href="https://www.chromium.org/user-experience/user-data-directory">user profile directory</a> <a href="https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md">user profile directory</a>
called <code>NativeMessagingHosts</code>. called <code>NativeMessagingHosts</code>.
<dl> <dl>
......
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