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

Side by Side Diff: chrome/app/chrome_dll_main.cc

Issue 20469: Prevent chrome from launching with a chromehtml: argument... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 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"
11 11
12 #if defined(OS_WIN) 12 #if defined(OS_WIN)
13 #include <algorithm>
13 #include <atlbase.h> 14 #include <atlbase.h>
14 #include <atlapp.h> 15 #include <atlapp.h>
15 #include <malloc.h> 16 #include <malloc.h>
16 #include <new.h> 17 #include <new.h>
17 #endif 18 #endif
18 19
19 #if defined(OS_LINUX) 20 #if defined(OS_LINUX)
20 #include <gtk/gtk.h> 21 #include <gtk/gtk.h>
21 #endif 22 #endif
22 23
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // Get the breakpad pointer from chrome.exe 110 // Get the breakpad pointer from chrome.exe
110 typedef void (__stdcall *DumpProcessFunction)(); 111 typedef void (__stdcall *DumpProcessFunction)();
111 DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>( 112 DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>(
112 ::GetProcAddress(::GetModuleHandle(L"chrome.exe"), "DumpProcess")); 113 ::GetProcAddress(::GetModuleHandle(L"chrome.exe"), "DumpProcess"));
113 if (DumpProcess) 114 if (DumpProcess)
114 DumpProcess(); 115 DumpProcess();
115 } 116 }
116 117
117 #pragma optimize("", on) 118 #pragma optimize("", on)
118 119
120 // Early versions of Chrome incorrectly registered a chromehtml: URL handler.
121 // Later versions fixed the registration but in some cases (e.g. Vista and non-
122 // admin installs) the fix could not be applied. This prevents Chrome to be
123 // launched with the incorrect format.
124 // CORRECT: <broser.exe> -- "chromehtml:<url>"
125 // INVALID: <broser.exe> "chromehtml:<url>"
126 bool IncorrectChromeHtmlArguments(const std::wstring& command_line) {
127 const wchar_t kChromeHtml[] = L"-- \"chromehtml:";
128 const wchar_t kOffset = 5; // Where chromehtml: starts in above
129 std::wstring command_line_lower = command_line;
130
131 // We are only searching for ASCII characters so this is OK.
132 StringToLowerASCII(&command_line_lower);
133
134 std::wstring::size_type pos = command_line_lower.find(
135 kChromeHtml + kOffset);
136
137 if (pos == std::wstring::npos)
138 return false;
139
140 // The browser is being launched with chromehtml: somewhere on the command
141 // line. We will not launch unless it's preceded by the -- switch terminator.
142 if (pos >= kOffset) {
143 if (equal(kChromeHtml, kChromeHtml + arraysize(kChromeHtml) - 1,
144 command_line_lower.begin() + pos - kOffset)) {
145 return false;
146 }
147 }
148
149 return true;
150 }
151
119 #endif // OS_WIN 152 #endif // OS_WIN
120 153
121 // Register the invalid param handler and pure call handler to be able to 154 // Register the invalid param handler and pure call handler to be able to
122 // notify breakpad when it happens. 155 // notify breakpad when it happens.
123 void RegisterInvalidParamHandler() { 156 void RegisterInvalidParamHandler() {
124 #if defined(OS_WIN) 157 #if defined(OS_WIN)
125 _set_invalid_parameter_handler(InvalidParameter); 158 _set_invalid_parameter_handler(InvalidParameter);
126 _set_purecall_handler(PureCall); 159 _set_purecall_handler(PureCall);
127 // Gather allocation failure. 160 // Gather allocation failure.
128 _set_new_handler(&OnNoMemory); 161 _set_new_handler(&OnNoMemory);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 #endif 253 #endif
221 254
222 // Initialize the command line. 255 // Initialize the command line.
223 #if defined(OS_WIN) 256 #if defined(OS_WIN)
224 CommandLine::Init(0, NULL); 257 CommandLine::Init(0, NULL);
225 #else 258 #else
226 CommandLine::Init(argc, argv); 259 CommandLine::Init(argc, argv);
227 #endif 260 #endif
228 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 261 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
229 262
263 #if defined(OS_WIN)
264 // Must do this before any other usage of command line!
265 if (::IncorrectChromeHtmlArguments(parsed_command_line.command_line_string()))
266 return 1;
267 #endif
268
230 SetupCRT(parsed_command_line); 269 SetupCRT(parsed_command_line);
231 270
232 // Initialize the Chrome path provider. 271 // Initialize the Chrome path provider.
233 chrome::RegisterPathProvider(); 272 chrome::RegisterPathProvider();
234 273
235 // Initialize the Stats Counters table. With this initialized, 274 // Initialize the Stats Counters table. With this initialized,
236 // the StatsViewer can be utilized to read counters outside of 275 // the StatsViewer can be utilized to read counters outside of
237 // Chrome. These lines can be commented out to effectively turn 276 // Chrome. These lines can be commented out to effectively turn
238 // counters 'off'. The table is created and exists for the life 277 // counters 'off'. The table is created and exists for the life
239 // of the process. It is not cleaned up. 278 // of the process. It is not cleaned up.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 382
344 _Module.Term(); 383 _Module.Term();
345 #endif 384 #endif
346 385
347 logging::CleanupChromeLogging(); 386 logging::CleanupChromeLogging();
348 387
349 return rv; 388 return rv;
350 } 389 }
351 390
352 391
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698