| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // TODO(port): the ifdefs in here are a first step towards trying to determine | 5 // TODO(port): the ifdefs in here are a first step towards trying to determine |
| 6 // the correct abstraction for all the OS functionality required at this | 6 // the correct abstraction for all the OS functionality required at this |
| 7 // stage of process initialization. It should not be taken as a final | 7 // stage of process initialization. It should not be taken as a final |
| 8 // abstraction. | 8 // abstraction. |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // Get the breakpad pointer from chrome.exe | 117 // Get the breakpad pointer from chrome.exe |
| 118 typedef void (__stdcall *DumpProcessFunction)(); | 118 typedef void (__stdcall *DumpProcessFunction)(); |
| 119 DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>( | 119 DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>( |
| 120 ::GetProcAddress(::GetModuleHandle(L"chrome.exe"), "DumpProcess")); | 120 ::GetProcAddress(::GetModuleHandle(L"chrome.exe"), "DumpProcess")); |
| 121 if (DumpProcess) | 121 if (DumpProcess) |
| 122 DumpProcess(); | 122 DumpProcess(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 #pragma optimize("", on) | 125 #pragma optimize("", on) |
| 126 | 126 |
| 127 // Early versions of Chrome incorrectly registered a chromehtml: URL handler. | 127 // Early versions of Chrome incorrectly registered a chromehtml: URL handler, |
| 128 // Later versions fixed the registration but in some cases (e.g. Vista and non- | 128 // which gives us nothing but trouble. Avoid launching chrome this way since |
| 129 // admin installs) the fix could not be applied. This prevents Chrome to be | 129 // some apps fail to properly escape arguments. |
| 130 // launched with the incorrect format. | 130 bool HasDeprecatedArguments(const std::wstring& command_line) { |
| 131 // CORRECT: <broser.exe> -- "chromehtml:<url>" | 131 const wchar_t kChromeHtml[] = L"chromehtml:"; |
| 132 // INVALID: <broser.exe> "chromehtml:<url>" | |
| 133 bool IncorrectChromeHtmlArguments(const std::wstring& command_line) { | |
| 134 const wchar_t kChromeHtml[] = L"-- \"chromehtml:"; | |
| 135 const wchar_t kOffset = 5; // Where chromehtml: starts in above | |
| 136 std::wstring command_line_lower = command_line; | 132 std::wstring command_line_lower = command_line; |
| 137 | |
| 138 // We are only searching for ASCII characters so this is OK. | 133 // We are only searching for ASCII characters so this is OK. |
| 139 StringToLowerASCII(&command_line_lower); | 134 StringToLowerASCII(&command_line_lower); |
| 140 | 135 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); |
| 141 std::wstring::size_type pos = command_line_lower.find( | 136 return (pos != std::wstring::npos); |
| 142 kChromeHtml + kOffset); | |
| 143 | |
| 144 if (pos == std::wstring::npos) | |
| 145 return false; | |
| 146 | |
| 147 // The browser is being launched with chromehtml: somewhere on the command | |
| 148 // line. We will not launch unless it's preceded by the -- switch terminator. | |
| 149 if (pos >= kOffset) { | |
| 150 if (equal(kChromeHtml, kChromeHtml + arraysize(kChromeHtml) - 1, | |
| 151 command_line_lower.begin() + pos - kOffset)) { | |
| 152 return false; | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 return true; | |
| 157 } | 137 } |
| 158 | 138 |
| 159 #endif // OS_WIN | 139 #endif // OS_WIN |
| 160 | 140 |
| 161 #if defined(OS_LINUX) | 141 #if defined(OS_LINUX) |
| 162 static void GtkFatalLogHandler(const gchar* log_domain, | 142 static void GtkFatalLogHandler(const gchar* log_domain, |
| 163 GLogLevelFlags log_level, | 143 GLogLevelFlags log_level, |
| 164 const gchar* message, | 144 const gchar* message, |
| 165 gpointer userdata) { | 145 gpointer userdata) { |
| 166 if (!log_domain) | 146 if (!log_domain) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 // Initialize the command line. | 249 // Initialize the command line. |
| 270 #if defined(OS_WIN) | 250 #if defined(OS_WIN) |
| 271 CommandLine::Init(0, NULL); | 251 CommandLine::Init(0, NULL); |
| 272 #else | 252 #else |
| 273 CommandLine::Init(argc, argv); | 253 CommandLine::Init(argc, argv); |
| 274 #endif | 254 #endif |
| 275 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 255 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 276 | 256 |
| 277 #if defined(OS_WIN) | 257 #if defined(OS_WIN) |
| 278 // Must do this before any other usage of command line! | 258 // Must do this before any other usage of command line! |
| 279 if (::IncorrectChromeHtmlArguments(parsed_command_line.command_line_string())) | 259 if (HasDeprecatedArguments(parsed_command_line.command_line_string())) |
| 280 return 1; | 260 return 1; |
| 281 #endif | 261 #endif |
| 282 | 262 |
| 283 int browser_pid; | 263 int browser_pid; |
| 284 std::wstring process_type = | 264 std::wstring process_type = |
| 285 parsed_command_line.GetSwitchValue(switches::kProcessType); | 265 parsed_command_line.GetSwitchValue(switches::kProcessType); |
| 286 if (process_type.empty()) { | 266 if (process_type.empty()) { |
| 287 browser_pid = base::GetCurrentProcId(); | 267 browser_pid = base::GetCurrentProcId(); |
| 288 } else { | 268 } else { |
| 289 std::wstring channel_name = | 269 std::wstring channel_name = |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 _CrtDumpMemoryLeaks(); | 410 _CrtDumpMemoryLeaks(); |
| 431 #endif // _CRTDBG_MAP_ALLOC | 411 #endif // _CRTDBG_MAP_ALLOC |
| 432 | 412 |
| 433 _Module.Term(); | 413 _Module.Term(); |
| 434 #endif | 414 #endif |
| 435 | 415 |
| 436 logging::CleanupChromeLogging(); | 416 logging::CleanupChromeLogging(); |
| 437 | 417 |
| 438 return rv; | 418 return rv; |
| 439 } | 419 } |
| OLD | NEW |