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 #include <algorithm> | 5 #include <algorithm> |
6 #include <atlbase.h> | 6 #include <atlbase.h> |
7 #include <atlapp.h> | 7 #include <atlapp.h> |
8 #include <malloc.h> | 8 #include <malloc.h> |
9 #include <new.h> | 9 #include <new.h> |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // Get the breakpad pointer from chrome.exe | 80 // Get the breakpad pointer from chrome.exe |
81 typedef void (__stdcall *DumpProcessFunction)(); | 81 typedef void (__stdcall *DumpProcessFunction)(); |
82 DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>( | 82 DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>( |
83 ::GetProcAddress(::GetModuleHandle(L"chrome.exe"), "DumpProcess")); | 83 ::GetProcAddress(::GetModuleHandle(L"chrome.exe"), "DumpProcess")); |
84 if (DumpProcess) | 84 if (DumpProcess) |
85 DumpProcess(); | 85 DumpProcess(); |
86 } | 86 } |
87 | 87 |
88 #pragma optimize("", on) | 88 #pragma optimize("", on) |
89 | 89 |
90 // Early versions of Chrome incorrectly registered a chromehtml: URL handler. | 90 // Early versions of Chrome incorrectly registered a chromehtml: URL handler, |
91 // Later versions fixed the registration but in some cases (e.g. Vista and non- | 91 // which gives us nothing but trouble. Avoid launching chrome this way since |
92 // admin installs) the fix could not be applied. This prevents Chrome to be | 92 // some apps fail to properly escape arguments. |
93 // launched with the incorrect format. | 93 bool HasDeprecatedArguments(const std::wstring& command_line) { |
94 // CORRECT: <broser.exe> -- "chromehtml:<url>" | 94 const wchar_t kChromeHtml[] = L"chromehtml:"; |
95 // INVALID: <broser.exe> "chromehtml:<url>" | |
96 bool IncorrectChromeHtmlArguments(const std::wstring& command_line) { | |
97 const wchar_t kChromeHtml[] = L"-- \"chromehtml:"; | |
98 const wchar_t kOffset = 5; // Where chromehtml: starts in above | |
99 std::wstring command_line_lower = command_line; | 95 std::wstring command_line_lower = command_line; |
100 | |
101 // We are only searching for ASCII characters so this is OK. | 96 // We are only searching for ASCII characters so this is OK. |
102 StringToLowerASCII(&command_line_lower); | 97 StringToLowerASCII(&command_line_lower); |
103 | 98 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); |
104 std::wstring::size_type pos = command_line_lower.find( | 99 return (pos != std::wstring::npos); |
105 kChromeHtml + kOffset); | |
106 | |
107 if (pos == std::wstring::npos) | |
108 return false; | |
109 | |
110 // The browser is being launched with chromehtml: somewhere on the command | |
111 // line. We will not launch unless it's preceded by the -- switch terminator. | |
112 if (pos >= kOffset) { | |
113 if (equal(kChromeHtml, kChromeHtml + arraysize(kChromeHtml) - 1, | |
114 command_line_lower.begin() + pos - kOffset)) { | |
115 return false; | |
116 } | |
117 } | |
118 | |
119 return true; | |
120 } | 100 } |
121 | 101 |
122 } // namespace | 102 } // namespace |
123 | 103 |
124 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, | 104 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, |
125 sandbox::SandboxInterfaceInfo* sandbox_info, | 105 sandbox::SandboxInterfaceInfo* sandbox_info, |
126 TCHAR* command_line, int show_command) { | 106 TCHAR* command_line, int show_command) { |
127 // Register the invalid param handler and pure call handler to be able to | 107 // Register the invalid param handler and pure call handler to be able to |
128 // notify breakpad when it happens. | 108 // notify breakpad when it happens. |
129 _set_invalid_parameter_handler(InvalidParameter); | 109 _set_invalid_parameter_handler(InvalidParameter); |
130 _set_purecall_handler(PureCall); | 110 _set_purecall_handler(PureCall); |
131 // Gather allocation failure. | 111 // Gather allocation failure. |
132 _set_new_handler(&OnNoMemory); | 112 _set_new_handler(&OnNoMemory); |
133 // Make sure malloc() calls the new handler too. | 113 // Make sure malloc() calls the new handler too. |
134 _set_new_mode(1); | 114 _set_new_mode(1); |
135 | 115 |
136 // The exit manager is in charge of calling the dtors of singleton objects. | 116 // The exit manager is in charge of calling the dtors of singleton objects. |
137 base::AtExitManager exit_manager; | 117 base::AtExitManager exit_manager; |
138 | 118 |
139 // Initialize the command line. | 119 // Initialize the command line. |
140 CommandLine parsed_command_line; | 120 CommandLine parsed_command_line; |
141 | 121 |
142 // Must do this before any other usage of command line! | 122 // Must do this before any other usage of command line! |
143 if (::IncorrectChromeHtmlArguments(parsed_command_line.command_line_string())) | 123 if (HasDeprecatedArguments(parsed_command_line.command_line_string())) |
144 return 1; | 124 return 1; |
145 | 125 |
146 #ifdef _CRTDBG_MAP_ALLOC | 126 #ifdef _CRTDBG_MAP_ALLOC |
147 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); | 127 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
148 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); | 128 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); |
149 #else | 129 #else |
150 if (!parsed_command_line.HasSwitch(switches::kDisableBreakpad)) { | 130 if (!parsed_command_line.HasSwitch(switches::kDisableBreakpad)) { |
151 _CrtSetReportMode(_CRT_ASSERT, 0); | 131 _CrtSetReportMode(_CRT_ASSERT, 0); |
152 } | 132 } |
153 #endif | 133 #endif |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 _CrtDumpMemoryLeaks(); | 253 _CrtDumpMemoryLeaks(); |
274 #endif // _CRTDBG_MAP_ALLOC | 254 #endif // _CRTDBG_MAP_ALLOC |
275 | 255 |
276 _Module.Term(); | 256 _Module.Term(); |
277 | 257 |
278 logging::CleanupChromeLogging(); | 258 logging::CleanupChromeLogging(); |
279 | 259 |
280 return rv; | 260 return rv; |
281 } | 261 } |
282 | 262 |
OLD | NEW |