Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(501)

Side by Side Diff: chrome/browser/policy/policy_path_parser_win.cc

Issue 12277002: Make sure ShellIntegration::CommandLineArgsForLauncher respects the UserDataDir policy. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: More documentation. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/policy/policy_path_parser_mac.mm ('k') | chrome/browser/shell_integration.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <shlobj.h> 5 #include <shlobj.h>
6 #include <wtsapi32.h> 6 #include <wtsapi32.h>
7 #pragma comment(lib, "wtsapi32.lib") 7 #pragma comment(lib, "wtsapi32.lib")
8 8
9 #include "chrome/browser/policy/policy_path_parser.h" 9 #include "chrome/browser/policy/policy_path_parser.h"
10 10
11 #include "base/command_line.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/utf_string_conversions.h"
14 #include "base/win/registry.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "policy/policy_constants.h"
12 17
13 namespace policy { 18 namespace {
14 19
15 namespace path_parser { 20 // Checks if the registry key exists in the given hive and expands any
21 // variables in the string.
22 bool LoadUserDataDirPolicyFromRegistry(HKEY hive,
23 const std::wstring& key_name,
24 base::FilePath* user_data_dir) {
25 std::wstring value;
26
27 base::win::RegKey policy_key(hive,
28 policy::kRegistryMandatorySubKey,
29 KEY_READ);
30 if (policy_key.ReadValue(key_name.c_str(), &value) == ERROR_SUCCESS) {
31 *user_data_dir =
32 base::FilePath(policy::path_parser::ExpandPathVariables(value));
33 return true;
34 }
35 return false;
36 }
16 37
17 const WCHAR* kMachineNamePolicyVarName = L"${machine_name}"; 38 const WCHAR* kMachineNamePolicyVarName = L"${machine_name}";
18 const WCHAR* kUserNamePolicyVarName = L"${user_name}"; 39 const WCHAR* kUserNamePolicyVarName = L"${user_name}";
19 const WCHAR* kWinDocumentsFolderVarName = L"${documents}"; 40 const WCHAR* kWinDocumentsFolderVarName = L"${documents}";
20 const WCHAR* kWinLocalAppDataFolderVarName = L"${local_app_data}"; 41 const WCHAR* kWinLocalAppDataFolderVarName = L"${local_app_data}";
21 const WCHAR* kWinRoamingAppDataFolderVarName = L"${roaming_app_data}"; 42 const WCHAR* kWinRoamingAppDataFolderVarName = L"${roaming_app_data}";
22 const WCHAR* kWinProfileFolderVarName = L"${profile}"; 43 const WCHAR* kWinProfileFolderVarName = L"${profile}";
23 const WCHAR* kWinProgramDataFolderVarName = L"${global_app_data}"; 44 const WCHAR* kWinProgramDataFolderVarName = L"${global_app_data}";
24 const WCHAR* kWinProgramFilesFolderVarName = L"${program_files}"; 45 const WCHAR* kWinProgramFilesFolderVarName = L"${program_files}";
25 const WCHAR* kWinWindowsFolderVarName = L"${windows}"; 46 const WCHAR* kWinWindowsFolderVarName = L"${windows}";
26 const WCHAR* kWinClientName = L"${client_name}"; 47 const WCHAR* kWinClientName = L"${client_name}";
27 48
28 struct WinFolderNamesToCSIDLMapping { 49 struct WinFolderNamesToCSIDLMapping {
29 const WCHAR* name; 50 const WCHAR* name;
30 int id; 51 int id;
31 }; 52 };
32 53
33 // Mapping from variable names to Windows CSIDL ids. 54 // Mapping from variable names to Windows CSIDL ids.
34 const WinFolderNamesToCSIDLMapping win_folder_mapping[] = { 55 const WinFolderNamesToCSIDLMapping win_folder_mapping[] = {
35 { kWinWindowsFolderVarName, CSIDL_WINDOWS}, 56 { kWinWindowsFolderVarName, CSIDL_WINDOWS},
36 { kWinProgramFilesFolderVarName, CSIDL_PROGRAM_FILES}, 57 { kWinProgramFilesFolderVarName, CSIDL_PROGRAM_FILES},
37 { kWinProgramDataFolderVarName, CSIDL_COMMON_APPDATA}, 58 { kWinProgramDataFolderVarName, CSIDL_COMMON_APPDATA},
38 { kWinProfileFolderVarName, CSIDL_PROFILE}, 59 { kWinProfileFolderVarName, CSIDL_PROFILE},
39 { kWinLocalAppDataFolderVarName, CSIDL_LOCAL_APPDATA}, 60 { kWinLocalAppDataFolderVarName, CSIDL_LOCAL_APPDATA},
40 { kWinRoamingAppDataFolderVarName, CSIDL_APPDATA}, 61 { kWinRoamingAppDataFolderVarName, CSIDL_APPDATA},
41 { kWinDocumentsFolderVarName, CSIDL_PERSONAL} 62 { kWinDocumentsFolderVarName, CSIDL_PERSONAL}
42 }; 63 };
43 64
65 } // namespace
66
67 namespace policy {
68
69 namespace path_parser {
70
44 // Replaces all variable occurances in the policy string with the respective 71 // Replaces all variable occurances in the policy string with the respective
45 // system settings values. 72 // system settings values.
46 base::FilePath::StringType ExpandPathVariables( 73 base::FilePath::StringType ExpandPathVariables(
47 const base::FilePath::StringType& untranslated_string) { 74 const base::FilePath::StringType& untranslated_string) {
48 base::FilePath::StringType result(untranslated_string); 75 base::FilePath::StringType result(untranslated_string);
49 if (result.length() == 0) 76 if (result.length() == 0)
50 return result; 77 return result;
51 // Sanitize quotes in case of any around the whole string. 78 // Sanitize quotes in case of any around the whole string.
52 if (result.length() > 1 && 79 if (result.length() > 1 &&
53 ((result[0] == L'"' && result[result.length() - 1] == L'"') || 80 ((result[0] == L'"' && result[result.length() - 1] == L'"') ||
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 &buffer, &buffer_length)) { 126 &buffer, &buffer_length)) {
100 std::wstring clientname_string(buffer); 127 std::wstring clientname_string(buffer);
101 result.replace(position, wcslen(kWinClientName), clientname_string); 128 result.replace(position, wcslen(kWinClientName), clientname_string);
102 ::WTSFreeMemory(buffer); 129 ::WTSFreeMemory(buffer);
103 } 130 }
104 } 131 }
105 132
106 return result; 133 return result;
107 } 134 }
108 135
136 void CheckUserDataDirPolicy(base::FilePath* user_data_dir) {
137 DCHECK(user_data_dir);
138 // We are running as Chrome Frame if we were invoked with user-data-dir,
139 // chrome-frame, and automation-channel switches.
140 CommandLine* command_line = CommandLine::ForCurrentProcess();
141 const bool is_chrome_frame =
142 !user_data_dir->empty() &&
143 command_line->HasSwitch(switches::kChromeFrame) &&
144 command_line->HasSwitch(switches::kAutomationClientChannelID);
145
146 // In the case of Chrome Frame, the last path component of the user-data-dir
147 // provided on the command line must be preserved since it is specific to
148 // CF's host.
149 base::FilePath cf_host_dir;
150 if (is_chrome_frame)
151 cf_host_dir = user_data_dir->BaseName();
152
153 // Policy from the HKLM hive has precedence over HKCU so if we have one here
154 // we don't have to try to load HKCU.
155 const char* key_name_ascii = (is_chrome_frame ? policy::key::kGCFUserDataDir :
156 policy::key::kUserDataDir);
157 std::wstring key_name(ASCIIToWide(key_name_ascii));
158 if (LoadUserDataDirPolicyFromRegistry(HKEY_LOCAL_MACHINE, key_name,
159 user_data_dir) ||
160 LoadUserDataDirPolicyFromRegistry(HKEY_CURRENT_USER, key_name,
161 user_data_dir)) {
162 // A Group Policy value was loaded. Append the Chrome Frame host directory
163 // if relevant.
164 if (is_chrome_frame)
165 *user_data_dir = user_data_dir->Append(cf_host_dir);
166 }
167 }
168
109 } // namespace path_parser 169 } // namespace path_parser
110 170
111 } // namespace policy 171 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_path_parser_mac.mm ('k') | chrome/browser/shell_integration.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698