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

Side by Side Diff: chrome/app/chrome_main_delegate.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 | « no previous file | chrome/app/chrome_main_mac.mm » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/app/chrome_main_delegate.h" 5 #include "chrome/app/chrome_main_delegate.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/metrics/stats_counters.h" 11 #include "base/metrics/stats_counters.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/process_util.h" 13 #include "base/process_util.h"
14 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "chrome/browser/chrome_content_browser_client.h" 17 #include "chrome/browser/chrome_content_browser_client.h"
18 #include "chrome/browser/defaults.h" 18 #include "chrome/browser/defaults.h"
19 #include "chrome/browser/diagnostics/diagnostics_main.h" 19 #include "chrome/browser/diagnostics/diagnostics_main.h"
20 #include "chrome/browser/policy/policy_path_parser.h"
20 #include "chrome/common/chrome_constants.h" 21 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/chrome_content_client.h" 22 #include "chrome/common/chrome_content_client.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_paths_internal.h" 24 #include "chrome/common/chrome_paths_internal.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/chrome_version_info.h" 26 #include "chrome/common/chrome_version_info.h"
26 #include "chrome/common/logging_chrome.h" 27 #include "chrome/common/logging_chrome.h"
27 #include "chrome/common/profiling.h" 28 #include "chrome/common/profiling.h"
28 #include "chrome/common/startup_metric_utils.h" 29 #include "chrome/common/startup_metric_utils.h"
29 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
30 #include "chrome/plugin/chrome_content_plugin_client.h" 31 #include "chrome/plugin/chrome_content_plugin_client.h"
31 #include "chrome/renderer/chrome_content_renderer_client.h" 32 #include "chrome/renderer/chrome_content_renderer_client.h"
32 #include "chrome/utility/chrome_content_utility_client.h" 33 #include "chrome/utility/chrome_content_utility_client.h"
33 #include "content/public/common/content_client.h" 34 #include "content/public/common/content_client.h"
34 #include "content/public/common/content_paths.h" 35 #include "content/public/common/content_paths.h"
35 #include "content/public/common/content_switches.h" 36 #include "content/public/common/content_switches.h"
36 #include "ui/base/ui_base_switches.h" 37 #include "ui/base/ui_base_switches.h"
37 38
38 #if defined(OS_WIN) 39 #if defined(OS_WIN)
39 #include <algorithm> 40 #include <algorithm>
40 #include <atlbase.h> 41 #include <atlbase.h>
41 #include <malloc.h> 42 #include <malloc.h>
42 #include "base/string_util.h" 43 #include "base/string_util.h"
43 #include "base/win/registry.h"
44 #include "chrome/browser/policy/policy_path_parser.h"
45 #include "policy/policy_constants.h"
46 #include "sandbox/win/src/sandbox.h" 44 #include "sandbox/win/src/sandbox.h"
47 #include "tools/memory_watcher/memory_watcher.h" 45 #include "tools/memory_watcher/memory_watcher.h"
48 #include "ui/base/resource/resource_bundle_win.h" 46 #include "ui/base/resource/resource_bundle_win.h"
49 #endif 47 #endif
50 48
51 #if defined(OS_MACOSX) 49 #if defined(OS_MACOSX)
52 #include "base/mac/mac_util.h" 50 #include "base/mac/mac_util.h"
53 #include "base/mac/os_crash_dumps.h" 51 #include "base/mac/os_crash_dumps.h"
54 #include "chrome/app/breakpad_mac.h" 52 #include "chrome/app/breakpad_mac.h"
55 #include "chrome/app/chrome_main_mac.h" 53 #include "chrome/app/chrome_main_mac.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // some apps fail to properly escape arguments. 116 // some apps fail to properly escape arguments.
119 bool HasDeprecatedArguments(const std::wstring& command_line) { 117 bool HasDeprecatedArguments(const std::wstring& command_line) {
120 const wchar_t kChromeHtml[] = L"chromehtml:"; 118 const wchar_t kChromeHtml[] = L"chromehtml:";
121 std::wstring command_line_lower = command_line; 119 std::wstring command_line_lower = command_line;
122 // We are only searching for ASCII characters so this is OK. 120 // We are only searching for ASCII characters so this is OK.
123 StringToLowerASCII(&command_line_lower); 121 StringToLowerASCII(&command_line_lower);
124 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); 122 std::wstring::size_type pos = command_line_lower.find(kChromeHtml);
125 return (pos != std::wstring::npos); 123 return (pos != std::wstring::npos);
126 } 124 }
127 125
128 // Checks if the registry key exists in the given hive and expands any
129 // variables in the string.
130 bool LoadUserDataDirPolicyFromRegistry(HKEY hive,
131 const std::wstring& key_name,
132 base::FilePath* user_data_dir) {
133 std::wstring value;
134
135 base::win::RegKey policy_key(hive,
136 policy::kRegistryMandatorySubKey,
137 KEY_READ);
138 if (policy_key.ReadValue(key_name.c_str(), &value) == ERROR_SUCCESS) {
139 *user_data_dir =
140 base::FilePath(policy::path_parser::ExpandPathVariables(value));
141 return true;
142 }
143 return false;
144 }
145
146 void CheckUserDataDirPolicy(base::FilePath* user_data_dir) {
147 DCHECK(user_data_dir);
148 // We are running as Chrome Frame if we were invoked with user-data-dir,
149 // chrome-frame, and automation-channel switches.
150 CommandLine* command_line = CommandLine::ForCurrentProcess();
151 const bool is_chrome_frame =
152 !user_data_dir->empty() &&
153 command_line->HasSwitch(switches::kChromeFrame) &&
154 command_line->HasSwitch(switches::kAutomationClientChannelID);
155
156 // In the case of Chrome Frame, the last path component of the user-data-dir
157 // provided on the command line must be preserved since it is specific to
158 // CF's host.
159 base::FilePath cf_host_dir;
160 if (is_chrome_frame)
161 cf_host_dir = user_data_dir->BaseName();
162
163 // Policy from the HKLM hive has precedence over HKCU so if we have one here
164 // we don't have to try to load HKCU.
165 const char* key_name_ascii = (is_chrome_frame ? policy::key::kGCFUserDataDir :
166 policy::key::kUserDataDir);
167 std::wstring key_name(ASCIIToWide(key_name_ascii));
168 if (LoadUserDataDirPolicyFromRegistry(HKEY_LOCAL_MACHINE, key_name,
169 user_data_dir) ||
170 LoadUserDataDirPolicyFromRegistry(HKEY_CURRENT_USER, key_name,
171 user_data_dir)) {
172 // A Group Policy value was loaded. Append the Chrome Frame host directory
173 // if relevant.
174 if (is_chrome_frame)
175 *user_data_dir = user_data_dir->Append(cf_host_dir);
176 }
177 }
178
179 // If we try to access a path that is not currently available, we want the call 126 // If we try to access a path that is not currently available, we want the call
180 // to fail rather than show an error dialog. 127 // to fail rather than show an error dialog.
181 void SuppressWindowsErrorDialogs() { 128 void SuppressWindowsErrorDialogs() {
182 UINT new_flags = SEM_FAILCRITICALERRORS | 129 UINT new_flags = SEM_FAILCRITICALERRORS |
183 SEM_NOOPENFILEERRORBOX; 130 SEM_NOOPENFILEERRORBOX;
184 131
185 // Preserve existing error mode. 132 // Preserve existing error mode.
186 UINT existing_flags = SetErrorMode(new_flags); 133 UINT existing_flags = SetErrorMode(new_flags);
187 SetErrorMode(existing_flags | new_flags); 134 SetErrorMode(existing_flags | new_flags);
188 } 135 }
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 chrome::GetVersionedDirectory(). 485 chrome::GetVersionedDirectory().
539 Append(chrome::kHelperProcessExecutablePath)); 486 Append(chrome::kHelperProcessExecutablePath));
540 487
541 InitMacCrashReporter(command_line, process_type); 488 InitMacCrashReporter(command_line, process_type);
542 #endif 489 #endif
543 490
544 // Notice a user data directory override if any 491 // Notice a user data directory override if any
545 base::FilePath user_data_dir = 492 base::FilePath user_data_dir =
546 command_line.GetSwitchValuePath(switches::kUserDataDir); 493 command_line.GetSwitchValuePath(switches::kUserDataDir);
547 #if defined(OS_MACOSX) || defined(OS_WIN) 494 #if defined(OS_MACOSX) || defined(OS_WIN)
548 CheckUserDataDirPolicy(&user_data_dir); 495 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
549 #endif 496 #endif
550 if (!user_data_dir.empty()) { 497 if (!user_data_dir.empty()) {
551 CHECK(PathService::OverrideAndCreateIfNeeded( 498 CHECK(PathService::OverrideAndCreateIfNeeded(
552 chrome::DIR_USER_DATA, 499 chrome::DIR_USER_DATA,
553 user_data_dir, 500 user_data_dir,
554 chrome::ProcessNeedsProfileDir(process_type))); 501 chrome::ProcessNeedsProfileDir(process_type)));
555 } 502 }
556 503
557 stats_counter_timer_.reset(new base::StatsCounterTimer("Chrome.Init")); 504 stats_counter_timer_.reset(new base::StatsCounterTimer("Chrome.Init"));
558 startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer> 505 startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer>
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 713
767 content::ContentRendererClient* 714 content::ContentRendererClient*
768 ChromeMainDelegate::CreateContentRendererClient() { 715 ChromeMainDelegate::CreateContentRendererClient() {
769 return &g_chrome_content_renderer_client.Get(); 716 return &g_chrome_content_renderer_client.Get();
770 } 717 }
771 718
772 content::ContentUtilityClient* 719 content::ContentUtilityClient*
773 ChromeMainDelegate::CreateContentUtilityClient() { 720 ChromeMainDelegate::CreateContentUtilityClient() {
774 return &g_chrome_content_utility_client.Get(); 721 return &g_chrome_content_utility_client.Get();
775 } 722 }
OLDNEW
« no previous file with comments | « no previous file | chrome/app/chrome_main_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698