diff options
author | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-28 06:58:33 +0000 |
---|---|---|
committer | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-28 06:58:33 +0000 |
commit | 3e5dd57d47cf3ad1c819401fcc9c751530858a12 (patch) | |
tree | 3d96efd02984ca5d496f0724908b590e8cfce227 /chrome_frame/chrome_launcher.cc | |
parent | d076fc23882f58997ae657c356b82a83eece4561 (diff) | |
download | chromium_src-3e5dd57d47cf3ad1c819401fcc9c751530858a12.zip chromium_src-3e5dd57d47cf3ad1c819401fcc9c751530858a12.tar.gz chromium_src-3e5dd57d47cf3ad1c819401fcc9c751530858a12.tar.bz2 |
Adding policy support to Chrome Frame's launcher so that additional parameters can be passed to Chrome via Group Policy.
BUG=116783
TEST=See information in comment #5 of the issue.
Review URL: https://chromiumcodereview.appspot.com/9836037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129384 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/chrome_launcher.cc')
-rw-r--r-- | chrome_frame/chrome_launcher.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/chrome_frame/chrome_launcher.cc b/chrome_frame/chrome_launcher.cc index f1a9733..88fc0da 100644 --- a/chrome_frame/chrome_launcher.cc +++ b/chrome_frame/chrome_launcher.cc @@ -8,6 +8,8 @@ #include <shellapi.h> #include <shlwapi.h> +#include "policy/policy_constants.h" + // Herein lies stuff selectively stolen from Chrome. We don't pull it in // directly because all of it results in many things we don't want being // included as well. @@ -140,6 +142,57 @@ bool IsValidCommandLine(const wchar_t* command_line) { return success; } +// Looks up optionally configured launch parameters for Chrome that may have +// been set via group policy. +void AppendAdditionalLaunchParameters(std::wstring* command_line) { + static const HKEY kRootKeys[] = { + HKEY_LOCAL_MACHINE, + HKEY_CURRENT_USER + }; + + std::wstring launch_params_value_name( + &policy::key::kAdditionalLaunchParameters[0], + &policy::key::kAdditionalLaunchParameters[ + lstrlenA(policy::key::kAdditionalLaunchParameters)]); + + // Used for basic checks since CreateProcess doesn't support command lines + // longer than 0x8000 characters. If we surpass that length, we do not add the + // additional parameters. Because we need to add a space before the + // extra parameters, we use 0x7fff and not 0x8000. + const size_t kMaxChars = 0x7FFF - command_line->size(); + HKEY key; + LONG result; + bool found = false; + for (int i = 0; !found && i < arraysize(kRootKeys); ++i) { + result = ::RegOpenKeyExW(kRootKeys[i], policy::kRegistryMandatorySubKey, 0, + KEY_QUERY_VALUE, &key); + if (result == ERROR_SUCCESS) { + DWORD size = 0; + DWORD type = 0; + result = RegQueryValueExW(key, launch_params_value_name.c_str(), + 0, &type, NULL, &size); + if (result == ERROR_SUCCESS && type == REG_SZ && size > 0 && + (size / sizeof(wchar_t)) < kMaxChars) { + // This size includes any terminating null character or characters + // unless the data was stored without them, so for safety we allocate + // one extra char and zero out the buffer. + wchar_t* value = new wchar_t[(size / sizeof(wchar_t)) + 1]; + memset(value, 0, size + sizeof(wchar_t)); + result = RegQueryValueExW(key, launch_params_value_name.c_str(), 0, + &type, reinterpret_cast<BYTE*>(&value[0]), + &size); + if (result == ERROR_SUCCESS) { + *command_line += L' '; + *command_line += value; + found = true; + } + delete [] value; + } + ::RegCloseKey(key); + } + } +} + bool SanitizeAndLaunchChrome(const wchar_t* command_line) { bool success = false; if (IsValidCommandLine(command_line)) { @@ -157,6 +210,9 @@ bool SanitizeAndLaunchChrome(const wchar_t* command_line) { command_line += args; } + // Append parameters that might be set by group policy. + AppendAdditionalLaunchParameters(&command_line); + STARTUPINFO startup_info = {0}; startup_info.cb = sizeof(startup_info); startup_info.dwFlags = STARTF_USESHOWWINDOW; |