Skip to content

Commit

Permalink
cleaning delegate execute of non-aura cruft
Browse files Browse the repository at this point in the history
BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245758 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
cpu@chromium.org committed Jan 18, 2014
1 parent a7a4061 commit 0d8435d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 117 deletions.
138 changes: 22 additions & 116 deletions win8/delegate_execute/command_execute_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "win8/viewer/metro_viewer_constants.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) {
Expand Down Expand Up @@ -66,7 +65,6 @@ HRESULT GetUrlFromShellItem(IShellItem* shell_item, base::string16* url) {
return S_OK;
}

#if defined(USE_AURA)
bool LaunchChromeBrowserProcess() {
base::FilePath delegate_exe_path;
if (!PathService::Get(base::FILE_EXE, &delegate_exe_path))
Expand Down Expand Up @@ -104,7 +102,6 @@ bool LaunchChromeBrowserProcess() {

return base::LaunchProcess(cl, launch_options, NULL);
}
#endif // defined(USE_AURA)

} // namespace

Expand Down Expand Up @@ -137,12 +134,10 @@ bool CommandExecuteImpl::path_provider_initialized_ = false;
// 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) if chrome is running return the AHE_ mode of chrome
// c) else we return what GetLaunchMode() tells us, which is:
// b) else we return what GetLaunchMode() tells us, which is:
// i) if the command line --force-xxx is present return that
// ii) if the registry 'launch_mode' exists return that
// iii) if IsTouchEnabledDevice() is true return AHE_IMMERSIVE
// iv) else return AHE_DESKTOP
// iii) 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.
Expand All @@ -161,15 +156,10 @@ bool CommandExecuteImpl::path_provider_initialized_ = false;
// in the registry so next time the logic reaches 5c-ii it will use the same
// mode again.
//
// Also note that if we are not the default browser and IsTouchEnabledDevice()
// returns true, launching chrome can go all the way to 7c, which might be
// a slow way to start chrome.
//
CommandExecuteImpl::CommandExecuteImpl()
: parameters_(CommandLine::NO_PROGRAM),
launch_scheme_(INTERNET_SCHEME_DEFAULT),
integrity_level_(base::INTEGRITY_UNKNOWN),
chrome_mode_(ECHUIM_SYSTEM_LAUNCHER) {
integrity_level_(base::INTEGRITY_UNKNOWN) {
memset(&start_info_, 0, sizeof(start_info_));
start_info_.cb = sizeof(start_info_);

Expand All @@ -184,127 +174,43 @@ CommandExecuteImpl::CommandExecuteImpl()

// CommandExecuteImpl
STDMETHODIMP CommandExecuteImpl::SetKeyState(DWORD key_state) {
AtlTrace("In %hs\n", __FUNCTION__);
return S_OK;
}

STDMETHODIMP CommandExecuteImpl::SetParameters(LPCWSTR params) {
AtlTrace("In %hs [%S]\n", __FUNCTION__, params);
parameters_ = delegate_execute::CommandLineFromParameters(params);
return S_OK;
}

STDMETHODIMP CommandExecuteImpl::SetPosition(POINT pt) {
AtlTrace("In %hs\n", __FUNCTION__);
return S_OK;
}

STDMETHODIMP CommandExecuteImpl::SetShowWindow(int show) {
AtlTrace("In %hs show=%d\n", __FUNCTION__, show);
start_info_.wShowWindow = show;
start_info_.dwFlags |= STARTF_USESHOWWINDOW;
return S_OK;
}

STDMETHODIMP CommandExecuteImpl::SetNoShowUI(BOOL no_show_ui) {
AtlTrace("In %hs no_show=%d\n", __FUNCTION__, no_show_ui);
return S_OK;
}

STDMETHODIMP CommandExecuteImpl::SetDirectory(LPCWSTR directory) {
AtlTrace("In %hs\n", __FUNCTION__);
return S_OK;
}

STDMETHODIMP CommandExecuteImpl::GetValue(enum AHE_TYPE* pahe) {
AtlTrace("In %hs\n", __FUNCTION__);

if (!GetLaunchScheme(&display_name_, &launch_scheme_)) {
AtlTrace("Failed to get scheme, E_FAIL\n");
return E_FAIL;
}

if (integrity_level_ == base::HIGH_INTEGRITY) {
// Metro mode apps don't work in high integrity mode.
AtlTrace("High integrity, AHE_DESKTOP\n");
*pahe = AHE_DESKTOP;
return S_OK;
}

if (GetAsyncKeyState(VK_SHIFT) && GetAsyncKeyState(VK_F11)) {
AtlTrace("Using Shift-F11 debug hook, returning AHE_IMMERSIVE\n");
*pahe = AHE_IMMERSIVE;

#if defined(USE_AURA)
// Launch the chrome browser process that metro chrome will connect to.
LaunchChromeBrowserProcess();
#endif

return S_OK;
}

if (GetAsyncKeyState(VK_SHIFT) && GetAsyncKeyState(VK_F12)) {
AtlTrace("Using Shift-F12 debug hook, returning AHE_DESKTOP\n");
*pahe = AHE_DESKTOP;
return S_OK;
}

base::FilePath user_data_dir;
if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
AtlTrace("Failed to get chrome's data dir path, E_FAIL\n");
return E_FAIL;
}

bool decision_made = false;

// New Aura/Ash world we don't want to go throgh FindWindow path
// and instead take decision based on launch mode.
#if !defined(USE_AURA)
HWND chrome_window = base::win::MessageWindow::FindWindow(
user_data_dir.value());
if (chrome_window) {
AtlTrace("Found chrome window %p\n", chrome_window);
// The failure cases below are deemed to happen due to the inherently racy
// procedure of going from chrome's window to process handle during which
// chrome might have exited. Failing here would probably just cause the
// user to retry at which point we would do the right thing.
DWORD chrome_pid = 0;
::GetWindowThreadProcessId(chrome_window, &chrome_pid);
if (!chrome_pid) {
AtlTrace("Failed to get chrome's PID, E_FAIL\n");
return E_FAIL;
}
base::win::ScopedHandle process(
::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, chrome_pid));
if (!process.IsValid()) {
AtlTrace("Failed to open chrome's process [%d], E_FAIL\n", chrome_pid);
return E_FAIL;
}

if (IsImmersiveProcess(process.Get())) {
AtlTrace("Chrome [%d] is inmmersive, AHE_IMMERSIVE\n", chrome_pid);
chrome_mode_ = ECHUIM_IMMERSIVE;
*pahe = AHE_IMMERSIVE;
} else {
AtlTrace("Chrome [%d] is Desktop, AHE_DESKTOP\n");
chrome_mode_ = ECHUIM_DESKTOP;
*pahe = AHE_DESKTOP;
}

decision_made = true;
}
#endif

if (!decision_made) {
EC_HOST_UI_MODE mode = GetLaunchMode();
*pahe = (mode == ECHUIM_DESKTOP) ? AHE_DESKTOP : AHE_IMMERSIVE;
}
EC_HOST_UI_MODE mode = GetLaunchMode();
*pahe = (mode == ECHUIM_DESKTOP) ? AHE_DESKTOP : AHE_IMMERSIVE;

#if defined(USE_AURA)
if (*pahe == AHE_IMMERSIVE && verb_ != win8::kMetroViewerConnectVerb)
LaunchChromeBrowserProcess();
#endif

return S_OK;
}

Expand Down Expand Up @@ -356,43 +262,36 @@ STDMETHODIMP CommandExecuteImpl::Execute() {

STDMETHODIMP CommandExecuteImpl::Initialize(LPCWSTR name,
IPropertyBag* bag) {
AtlTrace("In %hs\n", __FUNCTION__);
if (!FindChromeExe(&chrome_exe_))
return E_FAIL;
delegate_execute::UpdateChromeIfNeeded(chrome_exe_);

if (name) {
AtlTrace("Verb is %S\n", name);
verb_ = name;
}

base::GetProcessIntegrityLevel(base::GetCurrentProcessHandle(),
&integrity_level_);
if (integrity_level_ == base::HIGH_INTEGRITY) {
AtlTrace("Delegate execute launched in high integrity level\n");
}
return S_OK;
}

STDMETHODIMP CommandExecuteImpl::SetSelection(IShellItemArray* item_array) {
AtlTrace("In %hs\n", __FUNCTION__);
item_array_ = item_array;
return S_OK;
}

STDMETHODIMP CommandExecuteImpl::GetSelection(REFIID riid, void** selection) {
AtlTrace("In %hs\n", __FUNCTION__);
return S_OK;
}

STDMETHODIMP CommandExecuteImpl::AllowForegroundTransfer(void* reserved) {
AtlTrace("In %hs\n", __FUNCTION__);
return S_OK;
}

// Returns false if chrome.exe cannot be found.
// static
bool CommandExecuteImpl::FindChromeExe(base::FilePath* chrome_exe) {
AtlTrace("In %hs\n", __FUNCTION__);
// 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;
Expand All @@ -409,8 +308,6 @@ bool CommandExecuteImpl::FindChromeExe(base::FilePath* chrome_exe) {
return false;
}
}

AtlTrace("Got chrome exe path as %ls\n", chrome_exe->value().c_str());
return true;
}

Expand Down Expand Up @@ -445,8 +342,6 @@ bool CommandExecuteImpl::GetLaunchScheme(
return false;
}

AtlTrace("url [%ls]\n", display_name->c_str());

wchar_t scheme_name[16];
URL_COMPONENTS components = {0};
components.lpszScheme = scheme_name;
Expand All @@ -464,7 +359,6 @@ bool CommandExecuteImpl::GetLaunchScheme(
}

HRESULT CommandExecuteImpl::LaunchDesktopChrome() {
AtlTrace("In %hs\n", __FUNCTION__);
base::string16 display_name = display_name_;

switch (launch_scheme_) {
Expand Down Expand Up @@ -514,13 +408,22 @@ EC_HOST_UI_MODE CommandExecuteImpl::GetLaunchMode() {
if (launch_mode_determined)
return launch_mode;

if (chrome_mode_ != ECHUIM_SYSTEM_LAUNCHER) {
launch_mode = chrome_mode_;
AtlTrace("Launch mode is that of chrome, %s\n", modes[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;
}
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;
}

// From here on, if we can, we will write the outcome
// of this function to the registry.
if (parameters_.HasSwitch(switches::kForceImmersive)) {
launch_mode = ECHUIM_IMMERSIVE;
launch_mode_determined = true;
Expand All @@ -540,6 +443,8 @@ EC_HOST_UI_MODE CommandExecuteImpl::GetLaunchMode() {
chrome::kMetroRegistryPath,
key_result);
if (!launch_mode_determined) {
// If we cannot open the key and we don't know the
// launch mode we default to desktop mode.
launch_mode = ECHUIM_DESKTOP;
launch_mode_determined = true;
}
Expand All @@ -553,11 +458,12 @@ EC_HOST_UI_MODE CommandExecuteImpl::GetLaunchMode() {
return launch_mode;
}

// Use the previous mode if available. Else launch in desktop mode.
DWORD reg_value;
if (reg_key.ReadValueDW(chrome::kLaunchModeValue,
&reg_value) != ERROR_SUCCESS) {
launch_mode = ECHUIM_DESKTOP;
AtlTrace("Launch mode forced by heuristics to %s\n", modes[launch_mode]);
AtlTrace("Can't read registry, defaulting to %s\n", modes[launch_mode]);
} else if (reg_value >= ECHUIM_SYSTEM_LAUNCHER) {
AtlTrace("Invalid registry launch mode value %u\n", reg_value);
launch_mode = ECHUIM_DESKTOP;
Expand Down
1 change: 0 additions & 1 deletion win8/delegate_execute/command_execute_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ class ATL_NO_VTABLE DECLSPEC_UUID("071BB5F2-85A4-424F-BFE7-5F1609BE4C2C")
INTERNET_SCHEME launch_scheme_;

base::IntegrityLevel integrity_level_;
EC_HOST_UI_MODE chrome_mode_;
};

OBJECT_ENTRY_AUTO(__uuidof(CommandExecuteImpl), CommandExecuteImpl)

0 comments on commit 0d8435d

Please sign in to comment.