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

Side by Side Diff: chrome/app_shim/app_shim_win.cc

Issue 179223003: Adding app_shim executable on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup and copyright notice. Created 6 years, 2 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
OLDNEW
(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
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;
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
49 // somehow, instead of taking it as a command-line argument.
Matt Giuca 2014/10/24 09:45:46 I've left this TODO in so maybe we can have a disc
jackhou1 2014/10/26 23:16:43 Yeah that's a good point. The only problem I can t
Matt Giuca 2014/10/27 00:16:16 SECURITY: Can you comment on whether it is safe to
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698