OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <string> | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/files/file_path.h" | |
9 #include "base/logging.h" | |
10 #include "base/process/launch.h" | |
11 | |
12 #include <windows.h> | |
13 | |
14 namespace { | |
15 | |
16 // Return codes. | |
17 const int kOK = 0; | |
18 const int kNoProgram = 1; | |
19 const int kLaunchFailure = 2; | |
20 | |
21 } // namespace | |
22 | |
23 // This program takes a full Windows command line as command-line arguments, and | |
jackhou1
2014/10/26 22:56:09
I remember discussing this a while back and saying
Matt Giuca
2014/10/27 00:16:16
SECURITY: Do you think it is necessary to restrict
Will Harris
2014/10/27 16:09:31
+robertshield
The concern I have is that malware
robertshield
2014/10/27 17:30:50
I'd be much less worried if PATH_TO_CHROME_EXE sto
Matt Giuca
2014/10/30 06:39:05
OK I'm using the registry to get the Chrome binary
robertshield
2014/10/31 16:58:29
Awesome, thanks!
| |
24 // executes it. It terminates as soon as the program is launched. It is intended | |
25 // as a small shim for running chrome.exe; in particular, so that file types can | |
26 // be associated with Chrome apps, with a custom name (and in some cases, icon) | |
27 // rather than simply the name of the Chrome binary. | |
28 // | |
29 // Usage: win_app_shim -- PATH_TO_CHROME_EXE [CHROME_ARGS...] | |
30 // | |
31 // The -- is required if switches are to be passed to Chrome; any switches | |
32 // before the -- will be interpreted by win_app_shim, and not passed to Chrome. | |
33 int WINAPI WinMain(HINSTANCE instance, | |
34 HINSTANCE prev_instance, | |
35 char* /*command_line*/, | |
36 int show_command) { | |
37 CommandLine::Init(0, nullptr); | |
38 | |
39 // Log to stderr. Otherwise it will log to a file by default. | |
40 logging::LoggingSettings logging_settings; | |
41 logging_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
jackhou1
2014/10/26 22:56:09
I was under the impression stderr doesn't work on
Matt Giuca
2014/10/27 00:16:16
This is really only used to log the usage message
| |
42 logging::InitLogging(logging_settings); | |
43 | |
44 // Get the command line for the subprocess, consisting of the arguments (but | |
45 // not switches) to this binary. This gets everything after the "--". The | |
46 // first argument should be the location of the binary to run (full path to | |
47 // chrome.exe). | |
48 // TODO(mgiuca): Consider implicitly finding chrome.exe through the registry | |
jackhou1
2014/10/26 22:56:09
Code to do this is here:
https://code.google.com/
Matt Giuca
2014/10/27 00:16:16
Acknowledged.
| |
49 // somehow, instead of taking it as a command-line argument. | |
50 CommandLine command_line(CommandLine::ForCurrentProcess()->GetArgs()); | |
51 if (command_line.GetProgram().empty()) { | |
52 std::string basename = CommandLine::ForCurrentProcess() | |
53 ->GetProgram() | |
54 .BaseName() | |
55 .AsUTF8Unsafe(); | |
56 LOG(ERROR) << "Usage: " << basename << " -- PATH_TO_CHROME_EXE [ARGS...]"; | |
57 return kNoProgram; | |
58 } | |
59 | |
60 base::LaunchOptions options; | |
61 if (!base::LaunchProcess(command_line, options, nullptr)) | |
62 return kLaunchFailure; | |
63 | |
64 return kOK; | |
65 } | |
OLD | NEW |