| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // Get the breakpad pointer from chrome.exe | 118 // Get the breakpad pointer from chrome.exe |
| 119 typedef void (__stdcall *DumpProcessFunction)(); | 119 typedef void (__stdcall *DumpProcessFunction)(); |
| 120 DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>( | 120 DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>( |
| 121 ::GetProcAddress(::GetModuleHandle(L"chrome.exe"), "DumpProcess")); | 121 ::GetProcAddress(::GetModuleHandle(L"chrome.exe"), "DumpProcess")); |
| 122 if (DumpProcess) | 122 if (DumpProcess) |
| 123 DumpProcess(); | 123 DumpProcess(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 #pragma optimize("", on) | 126 #pragma optimize("", on) |
| 127 | 127 |
| 128 // Early versions of Chrome incorrectly registered a chromehtml: URL handler. | 128 // Early versions of Chrome incorrectly registered a chromehtml: URL handler, |
| 129 // Later versions fixed the registration but in some cases (e.g. Vista and non- | 129 // which gives us nothing but trouble. Avoid launching chrome this way since |
| 130 // admin installs) the fix could not be applied. This prevents Chrome to be | 130 // some apps fail to properly escape arguments. |
| 131 // launched with the incorrect format. | 131 bool HasDeprecatedArguments(const std::wstring& command_line) { |
| 132 // CORRECT: <broser.exe> -- "chromehtml:<url>" | 132 const wchar_t kChromeHtml[] = L"chromehtml:"; |
| 133 // INVALID: <broser.exe> "chromehtml:<url>" | |
| 134 bool IncorrectChromeHtmlArguments(const std::wstring& command_line) { | |
| 135 const wchar_t kChromeHtml[] = L"-- \"chromehtml:"; | |
| 136 const wchar_t kOffset = 5; // Where chromehtml: starts in above | |
| 137 std::wstring command_line_lower = command_line; | 133 std::wstring command_line_lower = command_line; |
| 138 | |
| 139 // We are only searching for ASCII characters so this is OK. | 134 // We are only searching for ASCII characters so this is OK. |
| 140 StringToLowerASCII(&command_line_lower); | 135 StringToLowerASCII(&command_line_lower); |
| 141 | 136 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); |
| 142 std::wstring::size_type pos = command_line_lower.find( | 137 return (pos != std::wstring::npos); |
| 143 kChromeHtml + kOffset); | |
| 144 | |
| 145 if (pos == std::wstring::npos) | |
| 146 return false; | |
| 147 | |
| 148 // The browser is being launched with chromehtml: somewhere on the command | |
| 149 // line. We will not launch unless it's preceded by the -- switch terminator. | |
| 150 if (pos >= kOffset) { | |
| 151 if (equal(kChromeHtml, kChromeHtml + arraysize(kChromeHtml) - 1, | |
| 152 command_line_lower.begin() + pos - kOffset)) { | |
| 153 return false; | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 return true; | |
| 158 } | 138 } |
| 159 | 139 |
| 160 #endif // OS_WIN | 140 #endif // OS_WIN |
| 161 | 141 |
| 162 #if defined(OS_LINUX) | 142 #if defined(OS_LINUX) |
| 163 static void GLibLogHandler(const gchar* log_domain, | 143 static void GLibLogHandler(const gchar* log_domain, |
| 164 GLogLevelFlags log_level, | 144 GLogLevelFlags log_level, |
| 165 const gchar* message, | 145 const gchar* message, |
| 166 gpointer userdata) { | 146 gpointer userdata) { |
| 167 if (!log_domain) | 147 if (!log_domain) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 // Initialize the command line. | 273 // Initialize the command line. |
| 294 #if defined(OS_WIN) | 274 #if defined(OS_WIN) |
| 295 CommandLine::Init(0, NULL); | 275 CommandLine::Init(0, NULL); |
| 296 #else | 276 #else |
| 297 CommandLine::Init(argc, argv); | 277 CommandLine::Init(argc, argv); |
| 298 #endif | 278 #endif |
| 299 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 279 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 300 | 280 |
| 301 #if defined(OS_WIN) | 281 #if defined(OS_WIN) |
| 302 // Must do this before any other usage of command line! | 282 // Must do this before any other usage of command line! |
| 303 if (::IncorrectChromeHtmlArguments(parsed_command_line.command_line_string())) | 283 if (HasDeprecatedArguments(parsed_command_line.command_line_string())) |
| 304 return 1; | 284 return 1; |
| 305 #endif | 285 #endif |
| 306 | 286 |
| 307 int browser_pid; | 287 int browser_pid; |
| 308 std::wstring process_type = | 288 std::wstring process_type = |
| 309 parsed_command_line.GetSwitchValue(switches::kProcessType); | 289 parsed_command_line.GetSwitchValue(switches::kProcessType); |
| 310 if (process_type.empty()) { | 290 if (process_type.empty()) { |
| 311 browser_pid = base::GetCurrentProcId(); | 291 browser_pid = base::GetCurrentProcId(); |
| 312 } else { | 292 } else { |
| 313 std::wstring channel_name = | 293 std::wstring channel_name = |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 _CrtDumpMemoryLeaks(); | 426 _CrtDumpMemoryLeaks(); |
| 447 #endif // _CRTDBG_MAP_ALLOC | 427 #endif // _CRTDBG_MAP_ALLOC |
| 448 | 428 |
| 449 _Module.Term(); | 429 _Module.Term(); |
| 450 #endif | 430 #endif |
| 451 | 431 |
| 452 logging::CleanupChromeLogging(); | 432 logging::CleanupChromeLogging(); |
| 453 | 433 |
| 454 return rv; | 434 return rv; |
| 455 } | 435 } |
| OLD | NEW |