Commit 511a873f authored by jackhou's avatar jackhou Committed by Commit bot

Move app_installer into chromium.

This code was previously in
https://chrome-internal.googlesource.com/chrome-app-installer.git

We're moving it to chromium with the goal of having it
eventually built as part of Chrome releases.

The third_party code is used to extract the tags added
by dl.google.com. Omaha uses this mechanism to tag their
meta-installers.

BUG=341353

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

Cr-Commit-Position: refs/heads/master@{#301492}
parent 4c112747
...@@ -333,6 +333,7 @@ v8.log ...@@ -333,6 +333,7 @@ v8.log
/third_party/mkl /third_party/mkl
/third_party/nacl_sdk_binaries/ /third_party/nacl_sdk_binaries/
/third_party/nss /third_party/nss
/third_party/omaha/src/omaha
/third_party/openmax_dl/ /third_party/openmax_dl/
/third_party/opus/src /third_party/opus/src
/third_party/ots /third_party/ots
......
...@@ -357,6 +357,10 @@ deps_os = { ...@@ -357,6 +357,10 @@ deps_os = {
# Binaries for nacl sdk. # Binaries for nacl sdk.
'src/third_party/nacl_sdk_binaries': 'src/third_party/nacl_sdk_binaries':
Var('chromium_git') + '/chromium/deps/nacl_sdk_binaries.git' + '@' + '759dfca03bdc774da7ecbf974f6e2b84f43699a5', Var('chromium_git') + '/chromium/deps/nacl_sdk_binaries.git' + '@' + '759dfca03bdc774da7ecbf974f6e2b84f43699a5',
# Omaha code for src/app_installer/.
'src/third_party/omaha/src/omaha':
Var('chromium_git') + '/external/omaha.git' + '@' + '098c7a3d157218dab4eed595e8f2fbe5a20a0bae',
}, },
'ios': { 'ios': {
'src/third_party/google_toolbox_for_mac/src': 'src/third_party/google_toolbox_for_mac/src':
......
...@@ -355,6 +355,7 @@ ...@@ -355,6 +355,7 @@
}], }],
['OS=="win"', { ['OS=="win"', {
'dependencies': [ 'dependencies': [
'../chrome/chrome.gyp:app_installer',
'../chrome/chrome.gyp:crash_service', '../chrome/chrome.gyp:crash_service',
'../chrome/chrome.gyp:installer_util_unittests', '../chrome/chrome.gyp:installer_util_unittests',
# ../chrome/test/mini_installer requires mini_installer. # ../chrome/test/mini_installer requires mini_installer.
...@@ -1180,6 +1181,9 @@ ...@@ -1180,6 +1181,9 @@
'type': 'none', 'type': 'none',
'dependencies': [ 'dependencies': [
'../base/base.gyp:base_unittests', '../base/base.gyp:base_unittests',
# TODO(jackhou): Ensure that app_installer builds on trybots
# and waterfall, then de-comment here.
#'../chrome/chrome.gyp:app_installer',
'../chrome/chrome.gyp:browser_tests', '../chrome/chrome.gyp:browser_tests',
'../chrome/chrome.gyp:sync_integration_tests', '../chrome/chrome.gyp:sync_integration_tests',
'../chrome/chrome.gyp:crash_service', '../chrome/chrome.gyp:crash_service',
......
include_rules = [
"+chrome/installer/launcher_support",
"+chrome/installer/util",
"+third_party/omaha",
]
benwells@chromium.org
jackhou@chromium.org
# 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.
{
'conditions': [
['OS=="win"', {
'targets': [
# TODO(jackhou): Add a version resource (using
# version_resource_rules.gypi).
{
'target_name': 'app_installer',
'type': 'executable',
'dependencies': [
'installer_util',
'installer_util_strings',
'launcher_support',
'common_constants.gyp:common_constants',
'../base/base.gyp:base',
'../third_party/omaha/omaha.gyp:omaha_extractor',
],
'include_dirs': [
'..',
'<(INTERMEDIATE_DIR)',
],
'sources': [
'win/app_installer_main.cc',
],
'msvs_settings': {
'VCLinkerTool': {
'SubSystem': '2', # Set /SUBSYSTEM:WINDOWS
},
'VCManifestTool': {
'AdditionalManifestFiles': [
'app_installer/win/app_installer.exe.manifest',
],
},
},
},
],
}],
],
}
<?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 -->
<ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
<ms_asmv2:security>
<ms_asmv2:requestedPrivileges>
<ms_asmv2:requestedExecutionLevel level="asInvoker" />
</ms_asmv2:requestedPrivileges>
</ms_asmv2:security>
</ms_asmv2:trustInfo>
</assembly>
// 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 <initguid.h>
#include <urlmon.h>
#pragma comment(lib, "urlmon.lib")
#include "base/at_exit.h"
#include "base/base_paths.h"
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/logging_win.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "base/strings/string16.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/installer/launcher_support/chrome_launcher_support.h"
#include "chrome/installer/util/google_update_util.h"
#include "chrome/installer/util/html_dialog.h"
#include "chrome/installer/util/util_constants.h"
#include "third_party/omaha/src/omaha/base/extractor.h"
namespace app_installer {
enum ExitCode {
SUCCESS = 0,
COULD_NOT_GET_FILE_PATH,
COULD_NOT_READ_TAG,
COULD_NOT_PARSE_TAG,
INVALID_APP_ID,
EULA_CANCELLED,
COULD_NOT_FIND_CHROME,
COULD_NOT_GET_TMP_FILE_PATH,
FAILED_TO_DOWNLOAD_CHROME_SETUP,
FAILED_TO_LAUNCH_CHROME_SETUP,
};
namespace {
// Log provider UUID. Required for logging to Sawbuck.
// {d82c3b59-bacd-4625-8282-4d570c4dad12}
DEFINE_GUID(kAppInstallerLogProvider,
0xd82c3b59,
0xbacd,
0x4625,
0x82, 0x82, 0x4d, 0x57, 0x0c, 0x4d, 0xad, 0x12);
const int kMaxTagLength = 4096;
const char kInstallChromeApp[] = "install-chrome-app";
const wchar_t kDownloadAndEulaPage[] =
L"https://tools.google.com/dlpage/chromeappinstaller";
const wchar_t kSxSDownloadAndEulaPage[] =
L"https://tools.google.com/dlpage/chromeappinstaller?sxs=true";
const wchar_t kDialogDimensions[] = L"dialogWidth:750px;dialogHeight:500px";
// This uses HTMLDialog to show a Chrome download page as a modal dialog.
// The page includes the EULA and returns a download URL.
class DownloadAndEulaHTMLDialog {
public:
explicit DownloadAndEulaHTMLDialog(bool is_canary) {
dialog_.reset(installer::CreateNativeHTMLDialog(
is_canary ? kSxSDownloadAndEulaPage : kDownloadAndEulaPage,
base::string16()));
}
~DownloadAndEulaHTMLDialog() {}
// Shows the dialog and blocks for user input. Returns the string passed back
// by the web page via |window.returnValue|.
base::string16 ShowModal() {
Customizer customizer;
dialog_->ShowModal(NULL, &customizer);
return dialog_->GetExtraResult();
}
private:
class Customizer : public installer::HTMLDialog::CustomizationCallback {
public:
void OnBeforeCreation(wchar_t** extra) override {
*extra = const_cast<wchar_t*>(kDialogDimensions);
}
void OnBeforeDisplay(void* window) override {
// Customize the window by removing the close button and replacing the
// existing 'e' icon with the standard informational icon.
if (!window)
return;
HWND top_window = static_cast<HWND>(window);
LONG_PTR style = GetWindowLongPtrW(top_window, GWL_STYLE);
SetWindowLongPtrW(top_window, GWL_STYLE, style & ~WS_SYSMENU);
HICON ico = LoadIcon(NULL, IDI_INFORMATION);
SendMessageW(
top_window, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(ico));
}
};
scoped_ptr<installer::HTMLDialog> dialog_;
DISALLOW_COPY_AND_ASSIGN(DownloadAndEulaHTMLDialog);
};
// Gets the tag attached to a file by dl.google.com. This uses the same format
// as Omaha. Returns the empty string on failure.
std::string GetTag(const base::FilePath& file_name_path) {
base::string16 file_name = file_name_path.value();
omaha::TagExtractor extractor;
if (!extractor.OpenFile(file_name.c_str()))
return std::string();
int tag_buffer_size = 0;
if (!extractor.ExtractTag(NULL, &tag_buffer_size) || tag_buffer_size <= 1)
return std::string();
if (tag_buffer_size - 1 > kMaxTagLength) {
LOG(ERROR) << "Tag length (" << tag_buffer_size - 1 << ") exceeds maximum ("
<< kMaxTagLength << ").";
return std::string();
}
scoped_ptr<char[]> tag_buffer(new char[tag_buffer_size]);
extractor.ExtractTag(tag_buffer.get(), &tag_buffer_size);
return std::string(tag_buffer.get(), tag_buffer_size - 1);
}
bool IsStringPrintable(const std::string& s) {
return std::find_if_not(s.begin(), s.end(), isprint) == s.end();
}
bool IsLegalDataKeyChar(int c) {
return isalnum(c) || c == '-' || c == '_' || c == '$';
}
bool IsDataKeyValid(const std::string& key) {
return std::find_if_not(key.begin(), key.end(), IsLegalDataKeyChar) ==
key.end();
}
// Parses |tag| as key-value pairs and overwrites |parsed_pairs| with
// the result. |tag| should be a '&'-delimited list of '='-separated
// key-value pairs, e.g. "key1=value1&key2=value2".
// Returns true if the data could be parsed.
bool ParseTag(const std::string& tag,
std::map<std::string, std::string>* parsed_pairs) {
DCHECK(parsed_pairs);
base::StringPairs kv_pairs;
if (!base::SplitStringIntoKeyValuePairs(tag, '=', '&', &kv_pairs)) {
LOG(ERROR) << "Failed to parse tag: " << tag;
return false;
}
parsed_pairs->clear();
for (const auto& pair : kv_pairs) {
const std::string& key(pair.first);
const std::string& value(pair.second);
if (IsDataKeyValid(key) && IsStringPrintable(value)) {
(*parsed_pairs)[key] = value;
} else {
LOG(ERROR) << "Illegal character found in tag.";
return false;
}
}
return true;
}
bool IsValidAppId(const std::string& app_id) {
if (app_id.size() != 32)
return false;
for (size_t i = 0; i < app_id.size(); ++i) {
char c = base::ToLowerASCII(app_id[i]);
if (c < 'a' || c > 'p')
return false;
}
return true;
}
base::FilePath GetChromeExePath(bool is_canary) {
return is_canary ? chrome_launcher_support::GetAnyChromeSxSPath()
: chrome_launcher_support::GetAnyChromePath();
}
ExitCode GetChrome(bool is_canary) {
// Show UI to install Chrome. The UI returns a download URL.
base::string16 download_url =
DownloadAndEulaHTMLDialog(is_canary).ShowModal();
if (download_url.empty())
return EULA_CANCELLED;
DVLOG(1) << "Chrome download url: " << download_url;
// Get a temporary file path.
base::FilePath setup_file;
if (!base::CreateTemporaryFile(&setup_file))
return COULD_NOT_GET_TMP_FILE_PATH;
// Download the Chrome installer.
HRESULT hr = URLDownloadToFile(
NULL, download_url.c_str(), setup_file.value().c_str(), 0, NULL);
if (FAILED(hr)) {
LOG(ERROR) << "Download failed: Error " << std::hex << hr << ". "
<< setup_file.value();
return FAILED_TO_DOWNLOAD_CHROME_SETUP;
}
// Install Chrome. Wait for the installer to finish before returning.
base::LaunchOptions options;
options.wait = true;
bool launch_success =
base::LaunchProcess(base::CommandLine(setup_file), options, NULL);
base::DeleteFile(setup_file, false);
return launch_success ? SUCCESS : FAILED_TO_LAUNCH_CHROME_SETUP;
}
} // namespace
extern "C"
int WINAPI wWinMain(HINSTANCE instance,
HINSTANCE prev_instance,
wchar_t* command_line,
int show_command) {
base::AtExitManager exit_manager;
base::CommandLine::Init(0, NULL);
logging::LogEventProvider::Initialize(kAppInstallerLogProvider);
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
logging::InitLogging(settings);
std::string app_id =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kAppId);
const char* sxs = installer::switches::kChromeSxS;
// --chrome-sxs on the command line takes precedence over chrome-sxs in the
// tag.
bool is_canary = base::CommandLine::ForCurrentProcess()->HasSwitch(sxs);
// --app-id on the command line inhibits tag parsing altogether.
if (app_id.empty()) {
base::FilePath current_exe;
if (!PathService::Get(base::FILE_EXE, &current_exe))
return COULD_NOT_GET_FILE_PATH;
// Get the tag added by dl.google.com. Note that this is passed in via URL
// parameters when requesting a file to download, so it must be validated
// before use.
std::string tag = GetTag(current_exe);
if (tag.empty())
return COULD_NOT_READ_TAG;
DVLOG(1) << "Tag: " << tag;
std::map<std::string, std::string> parsed_pairs;
if (!ParseTag(tag, &parsed_pairs))
return COULD_NOT_PARSE_TAG;
auto result = parsed_pairs.find(switches::kAppId);
if (result != parsed_pairs.end())
app_id = result->second;
if (!is_canary) {
result = parsed_pairs.find(sxs);
is_canary = result != parsed_pairs.end() && result->second == "1";
}
}
if (!IsValidAppId(app_id))
return INVALID_APP_ID;
base::FilePath chrome_path = GetChromeExePath(is_canary);
// If none found, show EULA, download, and install Chrome.
if (chrome_path.empty()) {
ExitCode get_chrome_result = GetChrome(is_canary);
if (get_chrome_result != SUCCESS)
return get_chrome_result;
chrome_path = GetChromeExePath(is_canary);
if (chrome_path.empty())
return COULD_NOT_FIND_CHROME;
}
base::CommandLine cmd(chrome_path);
cmd.AppendSwitchASCII(kInstallChromeApp, app_id);
DVLOG(1) << "Install command: " << cmd.GetCommandLineString();
bool launched = base::LaunchProcess(cmd, base::LaunchOptions(), NULL);
DVLOG(1) << "Launch " << (launched ? "success." : "failed.");
return SUCCESS;
}
} // namespace app_installer
...@@ -103,6 +103,7 @@ ...@@ -103,6 +103,7 @@
['OS!="ios"', { ['OS!="ios"', {
'includes': [ 'includes': [
'../apps/apps.gypi', '../apps/apps.gypi',
'app_installer/app_installer.gypi',
'chrome_debugger.gypi', 'chrome_debugger.gypi',
'chrome_dll.gypi', 'chrome_dll.gypi',
'chrome_exe.gypi', 'chrome_exe.gypi',
......
...@@ -25,6 +25,9 @@ const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; ...@@ -25,6 +25,9 @@ const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
// Copied from google_chrome_distribution.cc. // Copied from google_chrome_distribution.cc.
const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
// Copied frome google_chrome_sxs_distribution.cc.
const wchar_t kSxSBrowserAppGuid[] = L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}";
// Copied from util_constants.cc. // Copied from util_constants.cc.
const wchar_t kChromeExe[] = L"chrome.exe"; const wchar_t kChromeExe[] = L"chrome.exe";
const wchar_t kUninstallStringField[] = L"UninstallString"; const wchar_t kUninstallStringField[] = L"UninstallString";
...@@ -99,6 +102,13 @@ base::FilePath FindExeRelativeToSetupExe(const base::FilePath setup_exe_path, ...@@ -99,6 +102,13 @@ base::FilePath FindExeRelativeToSetupExe(const base::FilePath setup_exe_path,
return base::FilePath(); return base::FilePath();
} }
// Returns the path to an installed SxS chrome.exe at the specified level, if
// it can be found via Omaha client state.
base::FilePath GetChromeSxSPathForInstallationLevel(InstallationLevel level) {
return FindExeRelativeToSetupExe(
GetSetupExeFromRegistry(level, kSxSBrowserAppGuid), kChromeExe);
}
} // namespace } // namespace
base::FilePath GetChromePathForInstallationLevel(InstallationLevel level) { base::FilePath GetChromePathForInstallationLevel(InstallationLevel level) {
...@@ -115,4 +125,12 @@ base::FilePath GetAnyChromePath() { ...@@ -115,4 +125,12 @@ base::FilePath GetAnyChromePath() {
return chrome_path; return chrome_path;
} }
base::FilePath GetAnyChromeSxSPath() {
base::FilePath path =
GetChromeSxSPathForInstallationLevel(USER_LEVEL_INSTALLATION);
if (path.empty())
path = GetChromeSxSPathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
return path;
}
} // namespace chrome_launcher_support } // namespace chrome_launcher_support
...@@ -28,6 +28,12 @@ base::FilePath GetChromePathForInstallationLevel(InstallationLevel level); ...@@ -28,6 +28,12 @@ base::FilePath GetChromePathForInstallationLevel(InstallationLevel level);
// The file path returned (if any) is guaranteed to exist. // The file path returned (if any) is guaranteed to exist.
base::FilePath GetAnyChromePath(); base::FilePath GetAnyChromePath();
// Returns the path to an installed SxS chrome.exe, or an empty path. Prefers a
// user-level installation to a system-level installation. Uses Omaha client
// state to identify a Chrome Canary installation location.
// The file path returned (if any) is guaranteed to exist.
base::FilePath GetAnyChromeSxSPath();
} // namespace chrome_launcher_support } // namespace chrome_launcher_support
#endif // CHROME_INSTALLER_LAUNCHER_SUPPORT_CHROME_LAUNCHER_SUPPORT_H_ #endif // CHROME_INSTALLER_LAUNCHER_SUPPORT_CHROME_LAUNCHER_SUPPORT_H_
This diff is collapsed.
benwells@chromium.org
jackhou@chromium.org
Name: Omaha (Google Update)
Short Name: omaha
URL: https://code.google.com/p/omaha/
Version: 0
Date: 2013-09-16
Revision: r147
License: Apache 2.0
License File: LICENSE
Security Critical: yes
Description:
We use base/extractor from Omaha to extract tags from signed binaries.
Local Modifications:
Checks for security:
https://chromium.googlesource.com/external/omaha.git.
# 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': [
{
'target_name': 'omaha_extractor',
'type': 'static_library',
'sources': [
'src/omaha/base/extractor.cc',
'src/omaha/base/extractor.h',
],
'include_dirs': [
'../..',
'src',
],
},
],
}
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