Commit 31d809c9 authored by mgiuca's avatar mgiuca Committed by Commit bot

Adding app_shim executable on Windows.

This is a small binary that runs Chrome with the given command-line
arguments. It is intended for use with Chrome apps, so that file types
can be associated with the shim, having a custom name (and in some
cases, icon) rather than simply the name of the Chrome binary.

BUG=130455

Review URL: https://codereview.chromium.org/179223003

Cr-Commit-Position: refs/heads/master@{#302749}
parent f971997e
include_rules = [ include_rules = [
"+chrome/grit/generated_resources.h", "+chrome/grit/generated_resources.h",
"+chrome/installer/launcher_support",
] ]
# 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.
{
'targets': [
# This is the app shim on Windows. It is a small binary that simply runs
# Chrome, passing along any command-line arguments.
{
'target_name': 'app_shim',
'type': 'executable',
'dependencies': [
'launcher_support',
'../base/base.gyp:base',
],
'sources': [
'win/app_shim.rc',
'win/app_shim_main.cc',
],
'msvs_settings': {
'VCLinkerTool': {
'SubSystem': '2', # Set /SUBSYSTEM:WINDOWS
},
'VCManifestTool': {
'AdditionalManifestFiles': [
'app_shim/win/app_shim.exe.manifest',
],
},
},
},
], # targets
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<!--The compatibility section will be merged from build/win/compatibility.manifest -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
IDR_MAINFRAME ICON "..\\..\\chrome\\app\\theme\\chromium\\win\\webstore.ico"
// 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;
}
...@@ -511,6 +511,7 @@ ...@@ -511,6 +511,7 @@
}, },
], # 'targets' ], # 'targets'
'includes': [ 'includes': [
'app_shim/app_shim_win.gypi',
'chrome_process_finder.gypi', 'chrome_process_finder.gypi',
'metro_utils.gypi', 'metro_utils.gypi',
], ],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment