diff options
author | scottmg <scottmg@chromium.org> | 2016-03-18 11:28:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-18 18:30:13 +0000 |
commit | 78cb8fdac534cf66736ce4737f6ebff4f9988959 (patch) | |
tree | 31c37ea39921158cf8f23aca6d6ce6bda77d169d /win8 | |
parent | e425e3a8c5204d2d75f34c885c33f077372d1ff8 (diff) | |
download | chromium_src-78cb8fdac534cf66736ce4737f6ebff4f9988959.zip chromium_src-78cb8fdac534cf66736ce4737f6ebff4f9988959.tar.gz chromium_src-78cb8fdac534cf66736ce4737f6ebff4f9988959.tar.bz2 |
Remove delegate_execute
Dead code now.
TBR=sky@chromium.org
R=gab@chromium.org, grt@chromium.org
BUG=558054
Review URL: https://codereview.chromium.org/1811853005
Cr-Commit-Position: refs/heads/master@{#382019}
Diffstat (limited to 'win8')
19 files changed, 0 insertions, 1620 deletions
diff --git a/win8/delegate_execute/BUILD.gn b/win8/delegate_execute/BUILD.gn deleted file mode 100644 index 4b7d911..0000000 --- a/win8/delegate_execute/BUILD.gn +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright 2015 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. - -import("//build/config/chrome_build.gni") -import("//build/config/ui.gni") -import("//chrome/version.gni") -import("//testing/test.gni") - -executable("delegate_execute") { - sources = [ - "delegate_execute.cc", - "delegate_execute.rc", - ] - - configs -= [ "//build/config/win:console" ] - configs += [ "//build/config/win:windowed" ] - - deps = [ - ":lib", - ":version_resources", - "//base:base_static", - ] -} - -source_set("lib") { - visibility = [ ":*" ] - sources = [ - "chrome_util.cc", - "chrome_util.h", - "command_execute_impl.cc", - "command_execute_impl.h", - "command_execute_impl.rgs", - "crash_server_init.cc", - "crash_server_init.h", - "delegate_execute_operation.cc", - "delegate_execute_operation.h", - "delegate_execute_util.cc", - "delegate_execute_util.h", - "resource.h", - ] - - public_deps = [ - "//base", - "//breakpad:breakpad_handler", - "//chrome/common:constants", - "//chrome/installer/util:with_no_strings", - "//ui/base", - "//ui/gfx", - "//ui/gfx/geometry", - ] - - if (is_chrome_branded) { - public_deps += [ "//google_update" ] - } -} - -process_version("version_resources") { - visibility = [ ":*" ] - sources = [ - "delegate_execute_exe.ver", - ] - output = "$target_gen_dir/delegate_execute_exe.rc" - template_file = chrome_version_rc_template -} - -test("delegate_execute_unittests") { - sources = [ - "delegate_execute_util_unittest.cc", - ] - deps = [ - ":lib", - "//base/test:run_all_unittests", - "//testing/gtest", - ] -} diff --git a/win8/delegate_execute/chrome_util.cc b/win8/delegate_execute/chrome_util.cc deleted file mode 100644 index 0a4e177..0000000 --- a/win8/delegate_execute/chrome_util.cc +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (c) 2012 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 "win8/delegate_execute/chrome_util.h" - -#include <windows.h> -#include <atlbase.h> -#include <shlobj.h> -#include <stddef.h> - -#include <algorithm> -#include <limits> -#include <string> - -#include "base/files/file_path.h" -#include "base/files/file_util.h" -#include "base/macros.h" -#include "base/md5.h" -#include "base/process/kill.h" -#include "base/process/launch.h" -#include "base/process/process.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "base/win/registry.h" -#include "base/win/scoped_comptr.h" -#include "base/win/scoped_handle.h" -#include "base/win/win_util.h" -#include "chrome/installer/util/browser_distribution.h" -#include "chrome/installer/util/install_util.h" -#include "chrome/installer/util/util_constants.h" - -#if defined(GOOGLE_CHROME_BUILD) -#include "google_update/google_update_idl.h" // nogncheck -#endif - -namespace { - -#if defined(GOOGLE_CHROME_BUILD) - -// TODO(grt): These constants live in installer_util. Consider moving them -// into common_constants to allow for reuse. -const base::FilePath::CharType kNewChromeExe[] = - FILE_PATH_LITERAL("new_chrome.exe"); -const wchar_t kRenameCommandValue[] = L"cmd"; -const wchar_t kRegPathChromeClientBase[] = - L"Software\\Google\\Update\\Clients\\"; - -// Returns the name of the global event used to detect if |chrome_exe| is in -// use by a browser process. -// TODO(grt): Move this somewhere central so it can be used by both this -// IsBrowserRunning (below) and IsBrowserAlreadyRunning (browser_util_win.cc). -base::string16 GetEventName(const base::FilePath& chrome_exe) { - static wchar_t const kEventPrefix[] = L"Global\\"; - const size_t prefix_len = arraysize(kEventPrefix) - 1; - base::string16 name; - name.reserve(prefix_len + chrome_exe.value().size()); - name.assign(kEventPrefix, prefix_len); - name.append(chrome_exe.value()); - std::replace(name.begin() + prefix_len, name.end(), '\\', '!'); - std::transform(name.begin() + prefix_len, name.end(), - name.begin() + prefix_len, tolower); - return name; -} - -// Returns true if |chrome_exe| is in use by a browser process. In this case, -// "in use" means past ChromeBrowserMainParts::PreMainMessageLoopRunImpl. -bool IsBrowserRunning(const base::FilePath& chrome_exe) { - base::win::ScopedHandle handle(::OpenEvent( - SYNCHRONIZE, FALSE, GetEventName(chrome_exe).c_str())); - if (handle.IsValid()) - return true; - DWORD last_error = ::GetLastError(); - if (last_error != ERROR_FILE_NOT_FOUND) { - AtlTrace("%hs. Failed to open browser event; error %u.\n", __FUNCTION__, - last_error); - } - return false; -} - -// Returns true if the file new_chrome.exe exists in the same directory as -// |chrome_exe|. -bool NewChromeExeExists(const base::FilePath& chrome_exe) { - base::FilePath new_chrome_exe(chrome_exe.DirName().Append(kNewChromeExe)); - return base::PathExists(new_chrome_exe); -} - -bool GetUpdateCommand(bool is_per_user, base::string16* update_command) { - const HKEY root = is_per_user ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; - BrowserDistribution* dist = BrowserDistribution::GetDistribution(); - base::string16 reg_path_chrome_client = kRegPathChromeClientBase; - reg_path_chrome_client.append(dist->GetAppGuid()); - base::win::RegKey key(root, reg_path_chrome_client.c_str(), KEY_QUERY_VALUE); - - return key.ReadValue(kRenameCommandValue, update_command) == ERROR_SUCCESS; -} - -#endif // GOOGLE_CHROME_BUILD - -} // namespace - -namespace delegate_execute { - -void UpdateChromeIfNeeded(const base::FilePath& chrome_exe) { -#if defined(GOOGLE_CHROME_BUILD) - // Nothing to do if a browser is already running or if there's no - // new_chrome.exe. - if (IsBrowserRunning(chrome_exe) || !NewChromeExeExists(chrome_exe)) - return; - - base::Process process; - - if (InstallUtil::IsPerUserInstall(chrome_exe)) { - // Read the update command from the registry. - base::string16 update_command; - if (!GetUpdateCommand(true, &update_command)) { - AtlTrace("%hs. Failed to read update command from registry.\n", - __FUNCTION__); - } else { - // Run the update command. - base::LaunchOptions launch_options; - launch_options.start_hidden = true; - process = base::LaunchProcess(update_command, launch_options); - if (!process.IsValid()) { - AtlTrace("%hs. Failed to launch command to finalize update; " - "error %u.\n", __FUNCTION__, ::GetLastError()); - } - } - } else { - // Run the update command via Google Update. - HRESULT hr = S_OK; - base::win::ScopedComPtr<IProcessLauncher> process_launcher; - hr = process_launcher.CreateInstance(__uuidof(ProcessLauncherClass)); - if (FAILED(hr)) { - AtlTrace("%hs. Failed to Create ProcessLauncher; hr=0x%X.\n", - __FUNCTION__, hr); - } else { - ULONG_PTR handle = 0; - BrowserDistribution* dist = BrowserDistribution::GetDistribution(); - hr = process_launcher->LaunchCmdElevated( - dist->GetAppGuid().c_str(), kRenameCommandValue, - GetCurrentProcessId(), &handle); - if (FAILED(hr)) { - AtlTrace("%hs. Failed to launch command to finalize update; " - "hr=0x%X.\n", __FUNCTION__, hr); - } else { - process = base::Process(reinterpret_cast<base::ProcessHandle>(handle)); - } - } - } - - // Wait for the update to complete and report the results. - if (process.IsValid()) { - int exit_code = 0; - if (!process.WaitForExitWithTimeout( - base::TimeDelta::FromMilliseconds(INFINITE), &exit_code)) { - AtlTrace("%hs. Failed to get result when finalizing update.\n", - __FUNCTION__); - } else if (exit_code != installer::RENAME_SUCCESSFUL) { - AtlTrace("%hs. Failed to finalize update with exit code %d.\n", - __FUNCTION__, exit_code); - } else { - AtlTrace("%hs. Finalized pending update.\n", __FUNCTION__); - } - } -#endif -} - -} // delegate_execute diff --git a/win8/delegate_execute/chrome_util.h b/win8/delegate_execute/chrome_util.h deleted file mode 100644 index 6310c25..0000000 --- a/win8/delegate_execute/chrome_util.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef WIN8_DELEGATE_EXECUTE_CHROME_UTIL_H_ -#define WIN8_DELEGATE_EXECUTE_CHROME_UTIL_H_ - -#include "base/strings/string16.h" - -namespace base { -class FilePath; -} - -namespace delegate_execute { - -// Finalizes a previously updated installation. -void UpdateChromeIfNeeded(const base::FilePath& chrome_exe); - -} // namespace delegate_execute - -#endif // WIN8_DELEGATE_EXECUTE_CHROME_UTIL_H_ diff --git a/win8/delegate_execute/command_execute_impl.cc b/win8/delegate_execute/command_execute_impl.cc deleted file mode 100644 index e237336..0000000 --- a/win8/delegate_execute/command_execute_impl.cc +++ /dev/null @@ -1,417 +0,0 @@ -// Copyright (c) 2012 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. -// Implementation of the CommandExecuteImpl class which implements the -// IExecuteCommand and related interfaces for handling ShellExecute based -// launches of the Chrome browser. - -#include "win8/delegate_execute/command_execute_impl.h" - -#include <shlguid.h> - -#include "base/files/file_util.h" -#include "base/logging.h" -#include "base/path_service.h" -#include "base/process/launch.h" -#include "base/strings/utf_string_conversions.h" -#include "base/win/registry.h" -#include "base/win/scoped_co_mem.h" -#include "base/win/scoped_handle.h" -#include "base/win/scoped_process_information.h" -#include "base/win/win_util.h" -#include "base/win/windows_version.h" -#include "chrome/common/chrome_constants.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/installer/util/browser_distribution.h" -#include "chrome/installer/util/install_util.h" -#include "chrome/installer/util/shell_util.h" -#include "chrome/installer/util/util_constants.h" -#include "ui/base/clipboard/clipboard_util_win.h" -#include "ui/base/ui_base_switches.h" -#include "ui/gfx/win/dpi.h" -#include "win8/delegate_execute/chrome_util.h" -#include "win8/delegate_execute/delegate_execute_util.h" - -namespace { -// Helper function to retrieve the url from IShellItem interface passed in. -// Returns S_OK on success. -HRESULT GetUrlFromShellItem(IShellItem* shell_item, base::string16* url) { - DCHECK(shell_item); - DCHECK(url); - // First attempt to get the url from the underlying IDataObject if any. This - // ensures that we get the full url, i.e. including the anchor. - // If we fail to get the underlying IDataObject we retrieve the url via the - // IShellItem::GetDisplayName function. - CComPtr<IDataObject> object; - HRESULT hr = shell_item->BindToHandler(NULL, - BHID_DataObject, - IID_IDataObject, - reinterpret_cast<void**>(&object)); - if (SUCCEEDED(hr)) { - DCHECK(object); - if (ui::ClipboardUtil::GetPlainText(object, url)) - return S_OK; - } - - base::win::ScopedCoMem<wchar_t> name; - hr = shell_item->GetDisplayName(SIGDN_URL, &name); - if (hr != S_OK) { - AtlTrace("Failed to get display name\n"); - return hr; - } - - *url = static_cast<const wchar_t*>(name); - AtlTrace("Retrieved url from display name %ls\n", url->c_str()); - return S_OK; -} - -} // namespace - -bool CommandExecuteImpl::path_provider_initialized_ = false; - -// CommandExecuteImpl is responsible for activating chrome in Windows 8. The -// flow is complicated and this tries to highlight the important events. -// The current approach is to have a single instance of chrome either -// running in desktop or metro mode. If there is no current instance then -// the desktop shortcut launches desktop chrome and the metro tile or search -// charm launches metro chrome. -// If chrome is running then focus/activation is given to the existing one -// regardless of what launch point the user used. -// -// The general flow for activation is as follows: -// -// 1- User interacts with launch point (icon, tile, search, shellexec, etc) -// 2- Windows finds the appid for launch item and resolves it to chrome -// 3- Windows activates CommandExecuteImpl inside a surrogate process -// 4- Windows calls the following sequence of entry points: -// CommandExecuteImpl::SetShowWindow -// CommandExecuteImpl::SetPosition -// CommandExecuteImpl::SetDirectory -// CommandExecuteImpl::SetParameter -// CommandExecuteImpl::SetNoShowUI -// CommandExecuteImpl::SetSelection -// CommandExecuteImpl::Initialize -// Up to this point the code basically just gathers values passed in, like -// the launch scheme (or url) and the activation verb. -// 5- Windows calls CommandExecuteImpl::Getvalue() -// Here we need to return AHE_IMMERSIVE or AHE_DESKTOP. That depends on: -// a) if run in high-integrity return AHE_DESKTOP. -// b) else we return what GetLaunchMode() tells us, which is: -// i) if chrome is not the default browser, return AHE_DESKTOP -// ii) if the command line --force-xxx is present return that -// iii) if the registry 'launch_mode' exists return that -// iv) else return AHE_DESKTOP -// 6- If we returned AHE_IMMERSIVE in step 5 windows might not call us back -// and simply activate chrome in metro by itself, however in some cases -// it might proceed at step 7. -// As far as we know if we return AHE_DESKTOP then step 7 always happens. -// 7- Windows calls CommandExecuteImpl::Execute() -// Here we call GetLaunchMode() which returns the cached answer -// computed at step 5c. which can be: -// a) ECHUIM_DESKTOP then we call LaunchDesktopChrome() that calls -// ::CreateProcess and we exit at this point even on failure. -// b) else we call one of the IApplicationActivationManager activation -// functions depending on the parameters passed in step 4. -// c) If the activation returns E_APPLICATION_NOT_REGISTERED, then we fall -// back to launching chrome on the desktop via LaunchDestopChrome(). Note -// that this case can lead to strange behavior, because at this point we -// have pre-launched the browser with: -// --silent-launch --connect-to-metro-viewer. -// E_APPLICATION_NOT_REGISTERED is always returned if Chrome is not the -// default browser (this case will have already been checked for by -// GetLaunchMode() and AHE_DESKTOP returned), but we don't know if it can -// be returned for other reasons. -// -// Note that if a command line --force-xxx is present we write that launch mode -// in the registry so next time the logic reaches 5c-ii it will use the same -// mode again. -// -CommandExecuteImpl::CommandExecuteImpl() - : parameters_(base::CommandLine::NO_PROGRAM), - launch_scheme_(INTERNET_SCHEME_DEFAULT), - integrity_level_(base::INTEGRITY_UNKNOWN) { - memset(&start_info_, 0, sizeof(start_info_)); - start_info_.cb = sizeof(start_info_); - - // We need to query the user data dir of chrome so we need chrome's - // path provider. We can be created multiple times in a single instance - // however so make sure we do this only once. - if (!path_provider_initialized_) { - chrome::RegisterPathProvider(); - path_provider_initialized_ = true; - } -} - -CommandExecuteImpl::~CommandExecuteImpl() { -} - -// CommandExecuteImpl -STDMETHODIMP CommandExecuteImpl::SetKeyState(DWORD key_state) { - return S_OK; -} - -STDMETHODIMP CommandExecuteImpl::SetParameters(LPCWSTR params) { - parameters_ = delegate_execute::CommandLineFromParameters(params); - return S_OK; -} - -STDMETHODIMP CommandExecuteImpl::SetPosition(POINT pt) { - return S_OK; -} - -STDMETHODIMP CommandExecuteImpl::SetShowWindow(int show) { - start_info_.wShowWindow = show; - start_info_.dwFlags |= STARTF_USESHOWWINDOW; - return S_OK; -} - -STDMETHODIMP CommandExecuteImpl::SetNoShowUI(BOOL no_show_ui) { - return S_OK; -} - -STDMETHODIMP CommandExecuteImpl::SetDirectory(LPCWSTR directory) { - return S_OK; -} - -STDMETHODIMP CommandExecuteImpl::GetValue(enum AHE_TYPE* pahe) { - if (!GetLaunchScheme(&display_name_, &launch_scheme_)) { - AtlTrace("Failed to get scheme, E_FAIL\n"); - return E_FAIL; - } - - // TODO(scottmg): Can all go eventually https://crbug.com/558054. - *pahe = AHE_DESKTOP; - return S_OK; -} - -STDMETHODIMP CommandExecuteImpl::Execute() { - AtlTrace("In %hs\n", __FUNCTION__); - - if (integrity_level_ == base::HIGH_INTEGRITY) - return LaunchDesktopChrome(); - - EC_HOST_UI_MODE mode = GetLaunchMode(); - if (mode == ECHUIM_DESKTOP) - return LaunchDesktopChrome(); - - HRESULT hr = E_FAIL; - CComPtr<IApplicationActivationManager> activation_manager; - hr = activation_manager.CoCreateInstance(CLSID_ApplicationActivationManager); - if (!activation_manager) { - AtlTrace("Failed to get the activation manager, error 0x%x\n", hr); - return S_OK; - } - - BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); - bool is_per_user_install = InstallUtil::IsPerUserInstall(chrome_exe_); - base::string16 app_id = ShellUtil::GetBrowserModelId( - distribution, is_per_user_install); - - DWORD pid = 0; - if (launch_scheme_ == INTERNET_SCHEME_FILE && - display_name_.find(installer::kChromeExe) != base::string16::npos) { - AtlTrace("Activating for file\n"); - hr = activation_manager->ActivateApplication(app_id.c_str(), - verb_.c_str(), - AO_NONE, - &pid); - } else { - AtlTrace("Activating for protocol\n"); - hr = activation_manager->ActivateForProtocol(app_id.c_str(), - item_array_, - &pid); - } - if (hr == E_APPLICATION_NOT_REGISTERED) { - AtlTrace("Metro chrome is not registered, launching in desktop\n"); - return LaunchDesktopChrome(); - } - AtlTrace("Metro Chrome launch, pid=%d, returned 0x%x\n", pid, hr); - return S_OK; -} - -STDMETHODIMP CommandExecuteImpl::Initialize(LPCWSTR name, - IPropertyBag* bag) { - if (!FindChromeExe(&chrome_exe_)) - return E_FAIL; - delegate_execute::UpdateChromeIfNeeded(chrome_exe_); - - if (name) { - AtlTrace("Verb is %S\n", name); - verb_ = name; - } - - integrity_level_ = base::GetCurrentProcessIntegrityLevel(); - return S_OK; -} - -STDMETHODIMP CommandExecuteImpl::SetSelection(IShellItemArray* item_array) { - item_array_ = item_array; - return S_OK; -} - -STDMETHODIMP CommandExecuteImpl::GetSelection(REFIID riid, void** selection) { - return S_OK; -} - -STDMETHODIMP CommandExecuteImpl::AllowForegroundTransfer(void* reserved) { - return S_OK; -} - -// Returns false if chrome.exe cannot be found. -// static -bool CommandExecuteImpl::FindChromeExe(base::FilePath* chrome_exe) { - // Look for chrome.exe one folder above delegate_execute.exe (as expected in - // Chrome installs). Failing that, look for it alonside delegate_execute.exe. - base::FilePath dir_exe; - if (!PathService::Get(base::DIR_EXE, &dir_exe)) { - AtlTrace("Failed to get current exe path\n"); - return false; - } - - *chrome_exe = dir_exe.DirName().Append(chrome::kBrowserProcessExecutableName); - if (!base::PathExists(*chrome_exe)) { - *chrome_exe = dir_exe.Append(chrome::kBrowserProcessExecutableName); - if (!base::PathExists(*chrome_exe)) { - AtlTrace("Failed to find chrome exe file\n"); - return false; - } - } - return true; -} - -bool CommandExecuteImpl::GetLaunchScheme( - base::string16* display_name, INTERNET_SCHEME* scheme) { - if (!item_array_) - return false; - - ATLASSERT(display_name); - ATLASSERT(scheme); - - DWORD count = 0; - item_array_->GetCount(&count); - - if (count != 1) { - AtlTrace("Cannot handle %d elements in the IShellItemArray\n", count); - return false; - } - - CComPtr<IEnumShellItems> items; - item_array_->EnumItems(&items); - CComPtr<IShellItem> shell_item; - HRESULT hr = items->Next(1, &shell_item, &count); - if (hr != S_OK) { - AtlTrace("Failed to read element from the IShellItemsArray\n"); - return false; - } - - hr = GetUrlFromShellItem(shell_item, display_name); - if (FAILED(hr)) { - AtlTrace("Failed to get url. Error 0x%x\n", hr); - return false; - } - - wchar_t scheme_name[16]; - URL_COMPONENTS components = {0}; - components.lpszScheme = scheme_name; - components.dwSchemeLength = sizeof(scheme_name)/sizeof(scheme_name[0]); - - components.dwStructSize = sizeof(components); - if (!InternetCrackUrlW(display_name->c_str(), 0, 0, &components)) { - AtlTrace("Failed to crack url %ls\n", display_name->c_str()); - return false; - } - - AtlTrace("Launch scheme is [%ls] (%d)\n", scheme_name, components.nScheme); - *scheme = components.nScheme; - return true; -} - -HRESULT CommandExecuteImpl::LaunchDesktopChrome() { - base::string16 display_name = display_name_; - - switch (launch_scheme_) { - case INTERNET_SCHEME_FILE: - // If anything other than chrome.exe is passed in the display name we - // should honor it. For e.g. If the user clicks on a html file when - // chrome is the default we should treat it as a parameter to be passed - // to chrome. - if (display_name.find(installer::kChromeExe) != base::string16::npos) - display_name.clear(); - break; - - default: - break; - } - - base::CommandLine chrome(delegate_execute::MakeChromeCommandLine( - chrome_exe_, parameters_, display_name)); - base::string16 command_line(chrome.GetCommandLineString()); - - AtlTrace("Formatted command line is %ls\n", command_line.c_str()); - - PROCESS_INFORMATION temp_process_info = {}; - BOOL ret = CreateProcess(chrome_exe_.value().c_str(), - &command_line[0], - NULL, NULL, FALSE, 0, NULL, NULL, &start_info_, - &temp_process_info); - if (ret) { - base::win::ScopedProcessInformation proc_info(temp_process_info); - AtlTrace("Process id is %d\n", proc_info.process_id()); - AllowSetForegroundWindow(proc_info.process_id()); - } else { - AtlTrace("Process launch failed, error %d\n", ::GetLastError()); - } - - return S_OK; -} - -EC_HOST_UI_MODE CommandExecuteImpl::GetLaunchMode() { - // See the header file for an explanation of the mode selection logic. - static bool launch_mode_determined = false; - static EC_HOST_UI_MODE launch_mode = ECHUIM_DESKTOP; - - if (launch_mode_determined) - return launch_mode; - - if (integrity_level_ == base::HIGH_INTEGRITY) { - // Metro mode apps don't work in high integrity mode. - AtlTrace("High integrity: launching in desktop mode\n"); - launch_mode = ECHUIM_DESKTOP; - launch_mode_determined = true; - return launch_mode; - } - - base::FilePath chrome_exe; - if (!FindChromeExe(&chrome_exe) || - ShellUtil::GetChromeDefaultStateFromPath(chrome_exe) != - ShellUtil::IS_DEFAULT) { - AtlTrace("Chrome is not default: launching in desktop mode\n"); - launch_mode = ECHUIM_DESKTOP; - launch_mode_determined = true; - return launch_mode; - } - - if (GetAsyncKeyState(VK_SHIFT) && GetAsyncKeyState(VK_F11)) { - AtlTrace("Hotkey: launching in immersive mode\n"); - launch_mode = ECHUIM_IMMERSIVE; - launch_mode_determined = true; - return launch_mode; - } - - if (parameters_.HasSwitch(switches::kForceImmersive)) { - launch_mode = ECHUIM_IMMERSIVE; - launch_mode_determined = true; - parameters_ = base::CommandLine(base::CommandLine::NO_PROGRAM); - } else if (parameters_.HasSwitch(switches::kForceDesktop)) { - launch_mode = ECHUIM_DESKTOP; - launch_mode_determined = true; - parameters_ = base::CommandLine(base::CommandLine::NO_PROGRAM); - } - - if (!launch_mode_determined) { - launch_mode = ECHUIM_DESKTOP; - launch_mode_determined = true; - } - return launch_mode; -} diff --git a/win8/delegate_execute/command_execute_impl.h b/win8/delegate_execute/command_execute_impl.h deleted file mode 100644 index d7b60de..0000000 --- a/win8/delegate_execute/command_execute_impl.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) 2012 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 <atlbase.h> -#include <atlcom.h> -#include <atlctl.h> -#include <ShObjIdl.h> -#include <WinInet.h> - -#include <string> - -#include "base/command_line.h" -#include "base/files/file_path.h" -#include "base/process/process_info.h" -#include "win8/delegate_execute/resource.h" // main symbols - -EXTERN_C const GUID CLSID_CommandExecuteImpl; - -// CommandExecuteImpl -// This class implements the IExecuteCommand and related interfaces for -// handling ShellExecute launches of the Chrome browser, i.e. whether to -// launch Chrome in metro mode or desktop mode. -// The CLSID here is a dummy CLSID not used for anything, since we register -// the class with a dynamic CLSID. However, a static CLSID is necessary -// so that we can force at least one entry into ATL's object map (it will -// treat a 0-element object map as an initialization failure case). -class ATL_NO_VTABLE DECLSPEC_UUID("071BB5F2-85A4-424F-BFE7-5F1609BE4C2C") - CommandExecuteImpl - : public CComObjectRootEx<CComSingleThreadModel>, - public CComCoClass<CommandExecuteImpl, &CLSID_CommandExecuteImpl>, - public IExecuteCommand, - public IObjectWithSiteImpl<CommandExecuteImpl>, - public IInitializeCommand, - public IObjectWithSelection, - public IExecuteCommandApplicationHostEnvironment, - public IForegroundTransfer { - public: - CommandExecuteImpl(); - ~CommandExecuteImpl() override; - - DECLARE_REGISTRY_RESOURCEID(IDR_COMMANDEXECUTEIMPL) - - BEGIN_COM_MAP(CommandExecuteImpl) - COM_INTERFACE_ENTRY(IExecuteCommand) - COM_INTERFACE_ENTRY(IObjectWithSite) - COM_INTERFACE_ENTRY(IInitializeCommand) - COM_INTERFACE_ENTRY(IObjectWithSelection) - COM_INTERFACE_ENTRY(IExecuteCommandApplicationHostEnvironment) - COM_INTERFACE_ENTRY(IForegroundTransfer) - END_COM_MAP() - - DECLARE_PROTECT_FINAL_CONSTRUCT() - - HRESULT FinalConstruct() { - return S_OK; - } - - void FinalRelease() { - } - - public: - // IExecuteCommand - STDMETHOD(SetKeyState)(DWORD key_state) override; - STDMETHOD(SetParameters)(LPCWSTR params) override; - STDMETHOD(SetPosition)(POINT pt) override; - STDMETHOD(SetShowWindow)(int show) override; - STDMETHOD(SetNoShowUI)(BOOL no_show_ui) override; - STDMETHOD(SetDirectory)(LPCWSTR directory) override; - STDMETHOD(Execute)() override; - - // IInitializeCommand - STDMETHOD(Initialize)(LPCWSTR name, IPropertyBag * bag) override; - - // IObjectWithSelection - STDMETHOD(SetSelection)(IShellItemArray * item_array) override; - STDMETHOD(GetSelection)(REFIID riid, void** selection) override; - - // IExecuteCommandApplicationHostEnvironment - STDMETHOD(GetValue)(enum AHE_TYPE * pahe) override; - - // IForegroundTransfer - STDMETHOD(AllowForegroundTransfer)(void* reserved) override; - - static bool FindChromeExe(base::FilePath* chrome_exe); - - private: - bool GetLaunchScheme(base::string16* display_name, INTERNET_SCHEME* scheme); - HRESULT LaunchDesktopChrome(); - // Returns the launch mode, i.e. desktop launch/metro launch, etc. - EC_HOST_UI_MODE GetLaunchMode(); - - static bool path_provider_initialized_; - - CComPtr<IShellItemArray> item_array_; - base::CommandLine parameters_; - base::FilePath chrome_exe_; - STARTUPINFO start_info_; - base::string16 verb_; - base::string16 display_name_; - INTERNET_SCHEME launch_scheme_; - - base::IntegrityLevel integrity_level_; -}; - -OBJECT_ENTRY_AUTO(__uuidof(CommandExecuteImpl), CommandExecuteImpl) diff --git a/win8/delegate_execute/command_execute_impl.rgs b/win8/delegate_execute/command_execute_impl.rgs deleted file mode 100644 index 4f1aba3..0000000 --- a/win8/delegate_execute/command_execute_impl.rgs +++ /dev/null @@ -1,10 +0,0 @@ -HKCR { - NoRemove CLSID { - ForceRemove '%DELEGATE_EXECUTE_CLSID%' = s 'CommandExecuteImpl Class' { - ForceRemove Programmable - LocalServer32 = s '%MODULE%' { - val ServerExecutable = s '%MODULE_RAW%' - } - } - } -} diff --git a/win8/delegate_execute/crash_server_init.cc b/win8/delegate_execute/crash_server_init.cc deleted file mode 100644 index 859874d..0000000 --- a/win8/delegate_execute/crash_server_init.cc +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) 2012 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 "win8/delegate_execute/crash_server_init.h" - -#include <shlobj.h> -#include <windows.h> - -#include <cwchar> - -#include "base/file_version_info.h" -#include "base/memory/scoped_ptr.h" -#include "base/win/win_util.h" -#include "breakpad/src/client/windows/handler/exception_handler.h" - -const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\"; -const wchar_t kSystemPrincipalSid[] = L"S-1-5-18"; - -const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>( - MiniDumpWithProcessThreadData | // Get PEB and TEB. - MiniDumpWithUnloadedModules | // Get unloaded modules when available. - MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack. - -extern "C" IMAGE_DOS_HEADER __ImageBase; - -namespace { - -bool IsRunningSystemInstall() { - wchar_t exe_path[MAX_PATH * 2] = {0}; - GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase), - exe_path, - _countof(exe_path)); - - bool is_system = false; - - wchar_t program_files_path[MAX_PATH] = {0}; - if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, - SHGFP_TYPE_CURRENT, program_files_path))) { - if (wcsstr(exe_path, program_files_path) == exe_path) { - is_system = true; - } - } - - return is_system; -} - -google_breakpad::CustomClientInfo* GetCustomInfo() { - scoped_ptr<FileVersionInfo> version_info( - FileVersionInfo::CreateFileVersionInfoForModule(NULL)); - - static google_breakpad::CustomInfoEntry ver_entry( - L"ver", version_info->file_version().c_str()); - static google_breakpad::CustomInfoEntry prod_entry(L"prod", L"Chrome"); - static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32"); - static google_breakpad::CustomInfoEntry type_entry(L"ptype", - L"delegate_execute"); - static google_breakpad::CustomInfoEntry entries[] = { - ver_entry, prod_entry, plat_entry, type_entry }; - static google_breakpad::CustomClientInfo custom_info = { - entries, ARRAYSIZE(entries) }; - return &custom_info; -} - -} // namespace - -namespace delegate_execute { - -scoped_ptr<google_breakpad::ExceptionHandler> InitializeCrashReporting() { - wchar_t temp_path[MAX_PATH + 1] = {0}; - ::GetTempPath(MAX_PATH, temp_path); - - base::string16 pipe_name; - pipe_name = kGoogleUpdatePipeName; - if (IsRunningSystemInstall()) { - pipe_name += kSystemPrincipalSid; - } else { - base::string16 user_sid; - if (base::win::GetUserSidString(&user_sid)) { - pipe_name += user_sid; - } else { - // We don't think we're a system install, but we couldn't get the - // user SID. Try connecting to the system-level crash service as a - // last ditch effort. - pipe_name += kSystemPrincipalSid; - } - } - - return scoped_ptr<google_breakpad::ExceptionHandler>( - new google_breakpad::ExceptionHandler( - temp_path, NULL, NULL, NULL, - google_breakpad::ExceptionHandler::HANDLER_ALL, kLargerDumpType, - pipe_name.c_str(), GetCustomInfo())); -} - -} // namespace delegate_execute diff --git a/win8/delegate_execute/crash_server_init.h b/win8/delegate_execute/crash_server_init.h deleted file mode 100644 index 4173ef5..0000000 --- a/win8/delegate_execute/crash_server_init.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef WIN8_DELEGATE_EXECUTE_CRASH_SERVER_INIT_H_ -#define WIN8_DELEGATE_EXECUTE_CRASH_SERVER_INIT_H_ - -#include "base/memory/scoped_ptr.h" - -namespace google_breakpad { -class ExceptionHandler; -} - -namespace delegate_execute { - -// Initializes breakpad crash reporting and returns a pointer to a newly -// constructed ExceptionHandler object. It is the responsibility of the caller -// to delete this object which will shut down the crash reporting machinery. -scoped_ptr<google_breakpad::ExceptionHandler> InitializeCrashReporting(); - -} // namespace delegate_execute - -#endif // WIN8_DELEGATE_EXECUTE_CRASH_SERVER_INIT_H_ diff --git a/win8/delegate_execute/delegate_execute.cc b/win8/delegate_execute/delegate_execute.cc deleted file mode 100644 index 01e1fd4..0000000 --- a/win8/delegate_execute/delegate_execute.cc +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright (c) 2012 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 <atlbase.h> -#include <atlcom.h> -#include <atlctl.h> -#include <initguid.h> -#include <shellapi.h> - -#include "base/at_exit.h" -#include "base/command_line.h" -#include "base/files/file_util.h" -#include "base/memory/scoped_ptr.h" -#include "base/process/kill.h" -#include "base/strings/string16.h" -#include "base/win/scoped_com_initializer.h" -#include "base/win/scoped_comptr.h" -#include "base/win/scoped_handle.h" -#include "base/win/windows_version.h" -#include "breakpad/src/client/windows/handler/exception_handler.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/installer/util/browser_distribution.h" -#include "win8/delegate_execute/command_execute_impl.h" -#include "win8/delegate_execute/crash_server_init.h" -#include "win8/delegate_execute/delegate_execute_operation.h" -#include "win8/delegate_execute/resource.h" - -using namespace ATL; - -// Usually classes derived from CAtlExeModuleT, or other types of ATL -// COM module classes statically define their CLSID at compile time through -// the use of various macros, and ATL internals takes care of creating the -// class objects and registering them. However, we need to register the same -// object with different CLSIDs depending on a runtime setting, so we handle -// that logic here, before the main ATL message loop runs. -class DelegateExecuteModule - : public ATL::CAtlExeModuleT< DelegateExecuteModule > { - public : - typedef ATL::CAtlExeModuleT<DelegateExecuteModule> ParentClass; - typedef CComObject<CommandExecuteImpl> ImplType; - - DelegateExecuteModule() - : registration_token_(0) { - } - - HRESULT PreMessageLoop(int nShowCmd) { - HRESULT hr = S_OK; - GUID clsid; - BrowserDistribution* dist = BrowserDistribution::GetDistribution(); - const base::string16 clsid_string = dist->GetCommandExecuteImplClsid(); - if (clsid_string.empty()) - return E_FAIL; - hr = ::CLSIDFromString(clsid_string.c_str(), &clsid); - if (FAILED(hr)) - return hr; - - // We use the same class creation logic as ATL itself. See - // _ATL_OBJMAP_ENTRY::RegisterClassObject() in atlbase.h - hr = ImplType::_ClassFactoryCreatorClass::CreateInstance( - ImplType::_CreatorClass::CreateInstance, IID_IUnknown, - instance_.ReceiveVoid()); - if (FAILED(hr)) - return hr; - hr = ::CoRegisterClassObject(clsid, instance_.get(), CLSCTX_LOCAL_SERVER, - REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED, - ®istration_token_); - if (FAILED(hr)) - return hr; - - return ParentClass::PreMessageLoop(nShowCmd); - } - - HRESULT PostMessageLoop() { - if (registration_token_ != 0) { - ::CoRevokeClassObject(registration_token_); - registration_token_ = 0; - } - - instance_.Release(); - - return ParentClass::PostMessageLoop(); - } - - private: - base::win::ScopedComPtr<IUnknown> instance_; - DWORD registration_token_; -}; - -DelegateExecuteModule _AtlModule; - -using delegate_execute::DelegateExecuteOperation; -using base::win::ScopedHandle; - -int RelaunchChrome(const DelegateExecuteOperation& operation) { - AtlTrace("Relaunching [%ls] with flags [%ls]\n", - operation.mutex().c_str(), operation.relaunch_flags().c_str()); - ScopedHandle mutex(OpenMutexW(SYNCHRONIZE, FALSE, operation.mutex().c_str())); - if (mutex.IsValid()) { - const int kWaitSeconds = 5; - DWORD result = ::WaitForSingleObject(mutex.Get(), kWaitSeconds * 1000); - if (result == WAIT_ABANDONED) { - // This is the normal case. Chrome exits and windows marks the mutex as - // abandoned. - } else if (result == WAIT_OBJECT_0) { - // This is unexpected. Check if somebody is not closing the mutex on - // RelaunchChromehelper, the mutex should not be closed. - AtlTrace("Unexpected release of the relaunch mutex!!\n"); - } else if (result == WAIT_TIMEOUT) { - // This could mean that Chrome is hung. Proceed to exterminate. - base::Process process = operation.GetParent(); - AtlTrace("%ds timeout. Killing Chrome %d\n", kWaitSeconds, process.Pid()); - process.Terminate(0, false); - } else { - AtlTrace("Failed to wait for relaunch mutex, result is 0x%x\n", result); - } - } else { - // It is possible that chrome exits so fast that the mutex is not there. - AtlTrace("No relaunch mutex found\n"); - } - - // On Windows 8+ to launch Chrome we rely on Windows to use the - // IExecuteCommand interface exposed by delegate_execute to launch Chrome - // into Windows 8 metro mode or desktop. - // On Windows 7 we don't use delegate_execute and instead use plain vanilla - // ShellExecute to launch Chrome into ASH or desktop. - if (base::win::GetVersion() >= base::win::VERSION_WIN8) { - base::win::ScopedCOMInitializer com_initializer; - - base::string16 relaunch_flags(operation.relaunch_flags()); - SHELLEXECUTEINFO sei = { sizeof(sei) }; - sei.fMask = SEE_MASK_FLAG_LOG_USAGE; - sei.nShow = SW_SHOWNORMAL; - sei.lpFile = operation.shortcut().value().c_str(); - sei.lpParameters = relaunch_flags.c_str(); - - AtlTrace(L"Relaunching Chrome via shortcut [%ls]\n", sei.lpFile); - - if (!::ShellExecuteExW(&sei)) { - int error = HRESULT_FROM_WIN32(::GetLastError()); - AtlTrace("ShellExecute returned 0x%08X\n", error); - return error; - } - } else { - base::FilePath chrome_exe_path; - bool found_exe = CommandExecuteImpl::FindChromeExe(&chrome_exe_path); - DCHECK(found_exe); - if (found_exe) { - bool launch_ash = base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kForceImmersive); - if (launch_ash) { - AtlTrace(L"Relaunching Chrome into Windows ASH on Windows 7\n"); - } else { - AtlTrace(L"Relaunching Chrome into Desktop From ASH on Windows 7\n"); - } - SHELLEXECUTEINFO sei = { sizeof(sei) }; - sei.fMask = SEE_MASK_FLAG_LOG_USAGE; - sei.nShow = SW_SHOWNORMAL; - // No point in using the shortcut if we are launching into ASH as any - // additonal command line switches specified in the shortcut will be - // ignored. This is because we don't have a good way to send the command - // line switches from the viewer to the browser process. - sei.lpFile = (launch_ash || operation.shortcut().empty()) ? - chrome_exe_path.value().c_str() : - operation.shortcut().value().c_str(); - sei.lpParameters = - launch_ash ? L"-ServerName:DefaultBrowserServer" : NULL; - if (!::ShellExecuteExW(&sei)) { - int error = HRESULT_FROM_WIN32(::GetLastError()); - AtlTrace("ShellExecute returned 0x%08X\n", error); - return error; - } - } - } - return S_OK; -} - -extern "C" int WINAPI _tWinMain(HINSTANCE , HINSTANCE, LPTSTR, int nShowCmd) { - scoped_ptr<google_breakpad::ExceptionHandler> breakpad = - delegate_execute::InitializeCrashReporting(); - - base::AtExitManager exit_manager; - AtlTrace("delegate_execute enter\n"); - - base::CommandLine::Init(0, NULL); - HRESULT ret_code = E_UNEXPECTED; - DelegateExecuteOperation operation; - if (operation.Init(base::CommandLine::ForCurrentProcess())) { - switch (operation.operation_type()) { - case DelegateExecuteOperation::DELEGATE_EXECUTE: - ret_code = _AtlModule.WinMain(nShowCmd); - break; - case DelegateExecuteOperation::RELAUNCH_CHROME: - ret_code = RelaunchChrome(operation); - break; - default: - NOTREACHED(); - } - } - AtlTrace("delegate_execute exit, code = %d\n", ret_code); - return ret_code; -} diff --git a/win8/delegate_execute/delegate_execute.gyp b/win8/delegate_execute/delegate_execute.gyp deleted file mode 100644 index b863dc5..0000000 --- a/win8/delegate_execute/delegate_execute.gyp +++ /dev/null @@ -1,99 +0,0 @@ -# Copyright (c) 2012 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. -{ - 'variables': { - 'chromium_code': 1, - }, - 'includes': [ - '../../build/util/version.gypi', - '../../build/win_precompile.gypi', - ], - 'targets': [ - { - # GN version: //win8/delegate_execute:version_resources - 'target_name': 'delegate_execute_version_resources', - 'type': 'none', - 'conditions': [ - ['branding == "Chrome"', { - 'variables': { - 'branding_path': '../../chrome/app/theme/google_chrome/BRANDING', - }, - }, { # else branding!="Chrome" - 'variables': { - 'branding_path': '../../chrome/app/theme/chromium/BRANDING', - }, - }], - ], - 'variables': { - 'output_dir': 'delegate_execute', - 'template_input_path': '../../chrome/app/chrome_version.rc.version', - }, - 'sources': [ - 'delegate_execute_exe.ver', - ], - 'includes': [ - '../../chrome/version_resource_rules.gypi', - ], - }, - { - # GN version: //win8/delegate_execute - 'target_name': 'delegate_execute', - 'type': 'executable', - 'dependencies': [ - '../../base/base.gyp:base', - '../../breakpad/breakpad.gyp:breakpad_handler', - '../../chrome/chrome.gyp:installer_util', - '../../google_update/google_update.gyp:google_update', - '../../ui/base/ui_base.gyp:ui_base', - '../../ui/gfx/gfx.gyp:gfx', - '../../ui/gfx/gfx.gyp:gfx_geometry', - 'delegate_execute_version_resources', - ], - 'sources': [ - 'chrome_util.cc', - 'chrome_util.h', - 'command_execute_impl.cc', - 'command_execute_impl.h', - 'command_execute_impl.rgs', - 'crash_server_init.cc', - 'crash_server_init.h', - 'delegate_execute.cc', - 'delegate_execute.rc', - 'delegate_execute_operation.cc', - 'delegate_execute_operation.h', - 'delegate_execute_util.cc', - 'delegate_execute_util.h', - 'resource.h', - '<(SHARED_INTERMEDIATE_DIR)/delegate_execute/delegate_execute_exe_version.rc', - ], - 'msvs_settings': { - 'VCLinkerTool': { - 'SubSystem': '2', # Set /SUBSYSTEM:WINDOWS - }, - }, - 'conditions': [ - ['branding!="Chrome"', { - 'dependencies!': [ - '../../google_update/google_update.gyp:google_update', - ], - }], - ], - }, - { - # GN version: //win8/delegate_execute:delegate_execute_unittests - 'target_name': 'delegate_execute_unittests', - 'type': 'executable', - 'dependencies': [ - '../../base/base.gyp:base', - '../../base/base.gyp:run_all_unittests', - '../../testing/gtest.gyp:gtest', - ], - 'sources': [ - 'delegate_execute_util.cc', - 'delegate_execute_util.h', - 'delegate_execute_util_unittest.cc', - ], - }, - ], -} diff --git a/win8/delegate_execute/delegate_execute.rc b/win8/delegate_execute/delegate_execute.rc deleted file mode 100644 index 74a3cc4..0000000 --- a/win8/delegate_execute/delegate_execute.rc +++ /dev/null @@ -1,60 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "winres.h" -#include "verrsrc.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (United States) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""winres.h""\r\n" - "#include ""verrsrc.h""\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - -///////////////////////////////////////////////////////////////////////////// -// -// REGISTRY -// - -IDR_COMMANDEXECUTEIMPL REGISTRY "command_execute_impl.rgs" - -///////////////////////////////////////////////////////////////////////////// -// -// String Table -// - -STRINGTABLE -BEGIN - IDS_PROJNAME "DelegateExecute" -END - -#endif // English (United States) resources -///////////////////////////////////////////////////////////////////////////// diff --git a/win8/delegate_execute/delegate_execute_exe.ver b/win8/delegate_execute/delegate_execute_exe.ver deleted file mode 100644 index fb7fb12..0000000 --- a/win8/delegate_execute/delegate_execute_exe.ver +++ /dev/null @@ -1,2 +0,0 @@ -INTERNAL_NAME=delegate_execute_exe -ORIGINAL_FILENAME=delegate_execute.exe diff --git a/win8/delegate_execute/delegate_execute_operation.cc b/win8/delegate_execute/delegate_execute_operation.cc deleted file mode 100644 index 152e9a1..0000000 --- a/win8/delegate_execute/delegate_execute_operation.cc +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2012 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 "win8/delegate_execute/delegate_execute_operation.h" - -#include <stdint.h> - -#include "base/command_line.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_split.h" -#include "base/win/windows_version.h" -#include "chrome/common/chrome_switches.h" -#include "win8/delegate_execute/delegate_execute_util.h" - -namespace delegate_execute { - -DelegateExecuteOperation::DelegateExecuteOperation() - : operation_type_(DELEGATE_EXECUTE) { -} - -DelegateExecuteOperation::~DelegateExecuteOperation() { -} - -bool DelegateExecuteOperation::Init(const base::CommandLine* cmd_line) { - if (base::win::GetVersion() >= base::win::VERSION_WIN7) { - base::FilePath shortcut( - cmd_line->GetSwitchValuePath(switches::kRelaunchShortcut)); - // On Windows 7 the command line coming in may not have a path to the - // shortcut to launch Chrome. We ignore the shortcut and just do a regular - // ShellExecute of chrome.exe in this case. - if (shortcut.empty() && - base::win::GetVersion() >= base::win::VERSION_WIN8) { - operation_type_ = DELEGATE_EXECUTE; - return true; - } - relaunch_shortcut_ = shortcut; - } - mutex_ = cmd_line->GetSwitchValueNative(switches::kWaitForMutex); - if (mutex_.empty()) - return false; - // Add the mode forcing flags, if any. - const char* the_switch = NULL; - - if (cmd_line->HasSwitch(switches::kForceDesktop)) - the_switch = switches::kForceDesktop; - else if (cmd_line->HasSwitch(switches::kForceImmersive)) - the_switch = switches::kForceImmersive; - - relaunch_flags_ = ParametersFromSwitch(the_switch); - - operation_type_ = RELAUNCH_CHROME; - return true; -} - -base::Process DelegateExecuteOperation::GetParent() const { - std::vector<base::StringPiece16> parts = base::SplitStringPiece( - mutex_, L".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); - if (parts.size() != 3) - return base::Process(); - DWORD pid; - if (!base::StringToUint(parts[2], reinterpret_cast<uint32_t*>(&pid))) - return base::Process(); - return base::Process::Open(pid); -} - -} // namespace delegate_execute diff --git a/win8/delegate_execute/delegate_execute_operation.h b/win8/delegate_execute/delegate_execute_operation.h deleted file mode 100644 index 821515b..0000000 --- a/win8/delegate_execute/delegate_execute_operation.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef WIN8_DELEGATE_EXECUTE_DELEGATE_EXECUTE_OPERATION_H_ -#define WIN8_DELEGATE_EXECUTE_DELEGATE_EXECUTE_OPERATION_H_ - -#include <windows.h> -#include <atldef.h> - -#include "base/files/file_path.h" -#include "base/macros.h" -#include "base/process/process.h" -#include "base/strings/string16.h" - -namespace base { -class CommandLine; -} - -namespace delegate_execute { - -// Parses a portion of the DelegateExecute handler's command line to determine -// the desired operation. The operation type is decided by looking at the -// command line. The operations are: -// DELEGATE_EXECUTE: -// When the delegate_execute.exe is invoked by windows when a chrome -// activation via the shell, possibly using ShellExecute. Control must -// be given to ATLs WinMain. -// RELAUNCH_CHROME: -// When the delegate_execute.exe is launched by chrome, when chrome needs -// to re-launch itself. The required command line parameters are: -// --relaunch-shortcut=<PathToShortcut> -// --wait-for-mutex=<MutexNamePid> -// The PathToShortcut must be the fully qualified file name to the chrome -// shortcut that has the appId and other 'metro ready' parameters. -// The MutexNamePid is a mutex name that also encodes the process id and -// must follow the format <A>.<B>.<pid> where A and B are arbitray strings -// (usually chrome.relaunch) and pid is the process id of chrome. -class DelegateExecuteOperation { - public: - enum OperationType { - DELEGATE_EXECUTE, - RELAUNCH_CHROME, - }; - - DelegateExecuteOperation(); - ~DelegateExecuteOperation(); - - bool Init(const base::CommandLine* cmd_line); - - OperationType operation_type() const { - return operation_type_; - } - - const base::string16& relaunch_flags() const { - return relaunch_flags_; - } - - const base::string16& mutex() const { - return mutex_; - } - - // Returns the parent process. - base::Process GetParent() const; - - const base::FilePath& shortcut() const { - return relaunch_shortcut_; - } - - private: - OperationType operation_type_; - base::string16 relaunch_flags_; - base::FilePath relaunch_shortcut_; - base::string16 mutex_; - - DISALLOW_COPY_AND_ASSIGN(DelegateExecuteOperation); -}; - -} // namespace delegate_execute - -#endif // WIN8_DELEGATE_EXECUTE_DELEGATE_EXECUTE_OPERATION_H_ diff --git a/win8/delegate_execute/delegate_execute_util.cc b/win8/delegate_execute/delegate_execute_util.cc deleted file mode 100644 index 87a5fb6..0000000 --- a/win8/delegate_execute/delegate_execute_util.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2012 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 "win8/delegate_execute/delegate_execute_util.h" - -#include "base/files/file_path.h" -#include "base/strings/string_util.h" - -namespace delegate_execute { - -base::CommandLine CommandLineFromParameters(const wchar_t* params) { - base::CommandLine command_line(base::CommandLine::NO_PROGRAM); - - if (params) { - base::string16 command_string(L"noprogram.exe "); - command_string.append(params); - command_line.ParseFromString(command_string); - command_line.SetProgram(base::FilePath()); - } - - return command_line; -} - -base::CommandLine MakeChromeCommandLine(const base::FilePath& chrome_exe, - const base::CommandLine& params, - const base::string16& argument) { - base::CommandLine chrome_cmd(params); - chrome_cmd.SetProgram(chrome_exe); - - if (!argument.empty()) - chrome_cmd.AppendArgNative(argument); - - return chrome_cmd; -} - -base::string16 ParametersFromSwitch(const char* a_switch) { - if (!a_switch) - return base::string16(); - - base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM); - - cmd_line.AppendSwitch(a_switch); - - base::string16 command_string(cmd_line.GetCommandLineString()); - base::TrimWhitespace(command_string, base::TRIM_ALL, &command_string); - return command_string; -} - -} // namespace delegate_execute diff --git a/win8/delegate_execute/delegate_execute_util.h b/win8/delegate_execute/delegate_execute_util.h deleted file mode 100644 index eee033a..0000000 --- a/win8/delegate_execute/delegate_execute_util.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef WIN8_DELEGATE_EXECUTE_DELEGATE_EXECUTE_UTIL_H_ -#define WIN8_DELEGATE_EXECUTE_DELEGATE_EXECUTE_UTIL_H_ - -#include "base/command_line.h" -#include "base/strings/string16.h" - -namespace base { -class FilePath; -} - -namespace delegate_execute { - -// Returns a CommandLine with an empty program parsed from |params|. -base::CommandLine CommandLineFromParameters(const wchar_t* params); - -// Returns a CommandLine to launch |chrome_exe| with all switches and arguments -// from |params| plus an optional |argument|. -base::CommandLine MakeChromeCommandLine(const base::FilePath& chrome_exe, - const base::CommandLine& params, - const base::string16& argument); - -// Returns a properly quoted command-line string less the program (argv[0]) -// containing |switch|. -base::string16 ParametersFromSwitch(const char* a_switch); - -} // namespace delegate_execute - -#endif // WIN8_DELEGATE_EXECUTE_DELEGATE_EXECUTE_UTIL_H_ diff --git a/win8/delegate_execute/delegate_execute_util_unittest.cc b/win8/delegate_execute/delegate_execute_util_unittest.cc deleted file mode 100644 index 47916fd..0000000 --- a/win8/delegate_execute/delegate_execute_util_unittest.cc +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2012 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 "win8/delegate_execute/delegate_execute_util.h" - -#include <algorithm> - -#include "base/command_line.h" -#include "base/files/file_path.h" -#include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -static const char kSomeSwitch[] = "some-switch"; - -} // namespace - -TEST(DelegateExecuteUtil, CommandLineFromParametersTest) { - base::CommandLine cl(base::CommandLine::NO_PROGRAM); - - // Empty parameters means empty command-line string. - cl = delegate_execute::CommandLineFromParameters(NULL); - EXPECT_EQ(std::wstring(), cl.GetProgram().value()); - EXPECT_EQ(base::CommandLine::StringType(), cl.GetCommandLineString()); - - // Parameters with a switch are parsed properly. - cl = delegate_execute::CommandLineFromParameters( - base::StringPrintf(L"--%ls", - base::ASCIIToUTF16(kSomeSwitch).c_str()).c_str()); - EXPECT_EQ(std::wstring(), cl.GetProgram().value()); - EXPECT_TRUE(cl.HasSwitch(kSomeSwitch)); -} - -TEST(DelegateExecuteUtil, MakeChromeCommandLineTest) { - static const wchar_t kSomeArgument[] = L"http://some.url/"; - static const wchar_t kOtherArgument[] = L"http://some.other.url/"; - const base::FilePath this_exe( - base::CommandLine::ForCurrentProcess()->GetProgram()); - - base::CommandLine cl(base::CommandLine::NO_PROGRAM); - - // Empty params and argument contains only the exe. - cl = delegate_execute::MakeChromeCommandLine( - this_exe, - delegate_execute::CommandLineFromParameters(NULL), - base::string16()); - EXPECT_EQ(1u, cl.argv().size()); - EXPECT_EQ(this_exe.value(), cl.GetProgram().value()); - - // Empty params with arg contains the arg. - cl = delegate_execute::MakeChromeCommandLine( - this_exe, delegate_execute::CommandLineFromParameters(NULL), - base::string16(kSomeArgument)); - EXPECT_EQ(2u, cl.argv().size()); - EXPECT_EQ(this_exe.value(), cl.GetProgram().value()); - EXPECT_EQ(1u, cl.GetArgs().size()); - EXPECT_EQ(base::string16(kSomeArgument), cl.GetArgs()[0]); - - // Params with switchs and args plus arg contains the arg. - cl = delegate_execute::MakeChromeCommandLine( - this_exe, delegate_execute::CommandLineFromParameters( - base::StringPrintf(L"--%ls -- %ls", - base::ASCIIToUTF16(kSomeSwitch).c_str(), - kOtherArgument).c_str()), - base::string16(kSomeArgument)); - EXPECT_EQ(5u, cl.argv().size()); - EXPECT_EQ(this_exe.value(), cl.GetProgram().value()); - EXPECT_TRUE(cl.HasSwitch(kSomeSwitch)); - base::CommandLine::StringVector args(cl.GetArgs()); - EXPECT_EQ(2u, args.size()); - EXPECT_NE( - args.end(), - std::find(args.begin(), args.end(), base::string16(kOtherArgument))); - EXPECT_NE(args.end(), - std::find(args.begin(), args.end(), base::string16(kSomeArgument))); -} - -TEST(DelegateExecuteUtil, ParametersFromSwitchTest) { - EXPECT_EQ(base::string16(), delegate_execute::ParametersFromSwitch(NULL)); - EXPECT_EQ(base::string16(L"--some-switch"), - delegate_execute::ParametersFromSwitch(kSomeSwitch)); -} diff --git a/win8/delegate_execute/post_build.bat b/win8/delegate_execute/post_build.bat deleted file mode 100755 index 8aa9a76..0000000 --- a/win8/delegate_execute/post_build.bat +++ /dev/null @@ -1,3 +0,0 @@ -REM invoke as: post_build.bat OUTPUT_PATH_TO_EXE PATH_TO_CHROME_ROOT CONFIGURATION
-mkdir %2\build\%3
-copy %1 %2\build\%3\
diff --git a/win8/delegate_execute/resource.h b/win8/delegate_execute/resource.h deleted file mode 100644 index 971d6ae..0000000 --- a/win8/delegate_execute/resource.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2012 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. - -// {{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by DelegateExecute.rc -// -#define IDS_PROJNAME 100 -#define IDR_COMMANDEXECUTEIMPL 106 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 201 -#define _APS_NEXT_COMMAND_VALUE 32768 -#define _APS_NEXT_CONTROL_VALUE 201 -#define _APS_NEXT_SYMED_VALUE 107 -#endif -#endif |