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

Unified Diff: chrome/app_shim/win/app_shim_main.cc

Issue 179223003: Adding app_shim executable on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Alphabetical order. Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/app_shim/win/app_shim.exe.manifest ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/app_shim/win/app_shim_main.cc
diff --git a/chrome/app_shim/win/app_shim_main.cc b/chrome/app_shim/win/app_shim_main.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5c6c863d079ba1320eda8a50521ef52fc651d8a6
--- /dev/null
+++ b/chrome/app_shim/win/app_shim_main.cc
@@ -0,0 +1,80 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <windows.h>
+
+#include <string>
+
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/logging.h"
+#include "base/process/launch.h"
+#include "chrome/installer/launcher_support/chrome_launcher_support.h"
+
+namespace {
+
+// Return codes.
+const int kOK = 0;
+const int kNoProgram = 1;
+const int kLaunchFailure = 2;
+
+// Command-line switches.
+const char kChromeSxS[] = "chrome-sxs";
+
+base::FilePath GetChromeExePath(bool is_canary) {
+ return is_canary ? chrome_launcher_support::GetAnyChromeSxSPath()
+ : chrome_launcher_support::GetAnyChromePath();
+}
+
+} // namespace
+
+// This program runs chrome.exe, passing its arguments on to the Chrome binary.
+// It uses the Windows registry to find chrome.exe (and hence it only works if
+// Chrome/Chromium has been properly installed). It terminates as soon as the
+// program is launched. It is intended to allow file types to be associated with
+// Chrome apps, with a custom name (and in some cases, icon) rather than simply
+// the name of the Chrome binary.
+//
+// Usage: app_shim_win [--chrome-sxs] -- [CHROME_ARGS...]
+//
+// The -- is required if switches are to be passed to Chrome; any switches
+// before the -- will be interpreted by app_shim_win, and not passed to Chrome.
+//
+// If --chrome-sxs is specified, looks for the SxS (Canary) build of Chrome.
+// This will always fail for Chromium.
+int WINAPI wWinMain(HINSTANCE instance,
+ HINSTANCE prev_instance,
+ wchar_t* /*command_line*/,
+ int show_command) {
+ CommandLine::Init(0, nullptr);
+
+ // Log to stderr. Otherwise it will log to a file by default.
+ logging::LoggingSettings logging_settings;
+ logging_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
+ logging::InitLogging(logging_settings);
+
+ // Get the command-line for the Chrome binary.
+ // --chrome-sxs on the command line means we should run the canary binary.
+ bool is_canary =
+ base::CommandLine::ForCurrentProcess()->HasSwitch(kChromeSxS);
+ base::FilePath chrome_path = GetChromeExePath(is_canary);
+ if (chrome_path.empty()) {
+ LOG(ERROR) << "Could not find chrome.exe path in the registry.";
+ return kNoProgram;
+ }
+ CommandLine command_line(chrome_path);
+
+ // Get the command-line arguments for the subprocess, consisting of the
+ // arguments (but not switches) to this binary. This gets everything after the
+ // "--".
+ for (const auto& arg : CommandLine::ForCurrentProcess()->GetArgs())
+ command_line.AppendArgNative(arg);
+
+ if (!base::LaunchProcess(command_line, base::LaunchOptions(), nullptr)) {
+ LOG(ERROR) << "Could not run chrome.exe.";
+ return kLaunchFailure;
+ }
+
+ return kOK;
+}
« no previous file with comments | « chrome/app_shim/win/app_shim.exe.manifest ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698