Chromium Code Reviews| Index: chrome_frame/chrome_launcher.cc |
| diff --git a/chrome_frame/chrome_launcher.cc b/chrome_frame/chrome_launcher.cc |
| index f1a973309502a1b6b2acbd3fc721eb09aaeb5b2c..4379fe7a337b24e3b96a9250f2791186f3e2cb2c 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_READ, &key); |
|
grt (UTC plus 2)
2012/03/27 20:00:43
nit: you could use KEY_QUERY_VALUE here to request
|
| + 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; |