| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // Implementation of the CommandExecuteImpl class which implements the | 4 // Implementation of the CommandExecuteImpl class which implements the |
| 5 // IExecuteCommand and related interfaces for handling ShellExecute based | 5 // IExecuteCommand and related interfaces for handling ShellExecute based |
| 6 // launches of the Chrome browser. | 6 // launches of the Chrome browser. |
| 7 | 7 |
| 8 #include "win8/delegate_execute/command_execute_impl.h" | 8 #include "win8/delegate_execute/command_execute_impl.h" |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/win/registry.h" | 13 #include "base/win/registry.h" |
| 14 #include "base/win/scoped_co_mem.h" | 14 #include "base/win/scoped_co_mem.h" |
| 15 #include "base/win/scoped_handle.h" | 15 #include "base/win/scoped_handle.h" |
| 16 #include "base/win/scoped_process_information.h" |
| 16 #include "base/win/win_util.h" | 17 #include "base/win/win_util.h" |
| 17 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
| 18 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/installer/util/util_constants.h" | 21 #include "chrome/installer/util/util_constants.h" |
| 21 #include "win8/delegate_execute/chrome_util.h" | 22 #include "win8/delegate_execute/chrome_util.h" |
| 23 #include "win8/delegate_execute/delegate_execute_util.h" |
| 22 | 24 |
| 23 // CommandExecuteImpl is resposible for activating chrome in Windows 8. The | 25 // CommandExecuteImpl is resposible for activating chrome in Windows 8. The |
| 24 // flow is complicated and this tries to highlight the important events. | 26 // flow is complicated and this tries to highlight the important events. |
| 25 // The current approach is to have a single instance of chrome either | 27 // The current approach is to have a single instance of chrome either |
| 26 // running in desktop or metro mode. If there is no current instance then | 28 // running in desktop or metro mode. If there is no current instance then |
| 27 // the desktop shortcut launches desktop chrome and the metro tile or search | 29 // the desktop shortcut launches desktop chrome and the metro tile or search |
| 28 // charm launches metro chrome. | 30 // charm launches metro chrome. |
| 29 // If chrome is running then focus/activation is given to the existing one | 31 // If chrome is running then focus/activation is given to the existing one |
| 30 // regarless of what launch point the user used. | 32 // regarless of what launch point the user used. |
| 31 // | 33 // |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // | 71 // |
| 70 // Note that if a command line --force-xxx is present we write that launch mode | 72 // Note that if a command line --force-xxx is present we write that launch mode |
| 71 // in the registry so next time the logic reaches 5c-ii it will use the same | 73 // in the registry so next time the logic reaches 5c-ii it will use the same |
| 72 // mode again. | 74 // mode again. |
| 73 // | 75 // |
| 74 // Also note that if we are not the default browser and IsMachineATablet() | 76 // Also note that if we are not the default browser and IsMachineATablet() |
| 75 // returns true, launching chrome can go all the way to 7c, which might be | 77 // returns true, launching chrome can go all the way to 7c, which might be |
| 76 // a slow way to start chrome. | 78 // a slow way to start chrome. |
| 77 // | 79 // |
| 78 CommandExecuteImpl::CommandExecuteImpl() | 80 CommandExecuteImpl::CommandExecuteImpl() |
| 79 : integrity_level_(base::INTEGRITY_UNKNOWN), | 81 : parameters_(CommandLine::NO_PROGRAM), |
| 80 launch_scheme_(INTERNET_SCHEME_DEFAULT), | 82 launch_scheme_(INTERNET_SCHEME_DEFAULT), |
| 83 integrity_level_(base::INTEGRITY_UNKNOWN), |
| 81 chrome_mode_(ECHUIM_SYSTEM_LAUNCHER) { | 84 chrome_mode_(ECHUIM_SYSTEM_LAUNCHER) { |
| 82 memset(&start_info_, 0, sizeof(start_info_)); | 85 memset(&start_info_, 0, sizeof(start_info_)); |
| 83 start_info_.cb = sizeof(start_info_); | 86 start_info_.cb = sizeof(start_info_); |
| 84 // We need to query the user data dir of chrome so we need chrome's | 87 // We need to query the user data dir of chrome so we need chrome's |
| 85 // path provider. | 88 // path provider. |
| 86 chrome::RegisterPathProvider(); | 89 chrome::RegisterPathProvider(); |
| 87 } | 90 } |
| 88 | 91 |
| 89 // CommandExecuteImpl | 92 // CommandExecuteImpl |
| 90 STDMETHODIMP CommandExecuteImpl::SetKeyState(DWORD key_state) { | 93 STDMETHODIMP CommandExecuteImpl::SetKeyState(DWORD key_state) { |
| 91 AtlTrace("In %hs\n", __FUNCTION__); | 94 AtlTrace("In %hs\n", __FUNCTION__); |
| 92 return S_OK; | 95 return S_OK; |
| 93 } | 96 } |
| 94 | 97 |
| 95 STDMETHODIMP CommandExecuteImpl::SetParameters(LPCWSTR params) { | 98 STDMETHODIMP CommandExecuteImpl::SetParameters(LPCWSTR params) { |
| 96 AtlTrace("In %hs [%S]\n", __FUNCTION__, params); | 99 AtlTrace("In %hs [%S]\n", __FUNCTION__, params); |
| 97 if (params) { | 100 parameters_ = delegate_execute::CommandLineFromParameters(params); |
| 98 parameters_ = params; | |
| 99 } | |
| 100 return S_OK; | 101 return S_OK; |
| 101 } | 102 } |
| 102 | 103 |
| 103 STDMETHODIMP CommandExecuteImpl::SetPosition(POINT pt) { | 104 STDMETHODIMP CommandExecuteImpl::SetPosition(POINT pt) { |
| 104 AtlTrace("In %hs\n", __FUNCTION__); | 105 AtlTrace("In %hs\n", __FUNCTION__); |
| 105 return S_OK; | 106 return S_OK; |
| 106 } | 107 } |
| 107 | 108 |
| 108 STDMETHODIMP CommandExecuteImpl::SetShowWindow(int show) { | 109 STDMETHODIMP CommandExecuteImpl::SetShowWindow(int show) { |
| 109 AtlTrace("In %hs show=%d\n", __FUNCTION__, show); | 110 AtlTrace("In %hs show=%d\n", __FUNCTION__, show); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // chrome is the default we should treat it as a parameter to be passed | 346 // chrome is the default we should treat it as a parameter to be passed |
| 346 // to chrome. | 347 // to chrome. |
| 347 if (display_name.find(installer::kChromeExe) != string16::npos) | 348 if (display_name.find(installer::kChromeExe) != string16::npos) |
| 348 display_name.clear(); | 349 display_name.clear(); |
| 349 break; | 350 break; |
| 350 | 351 |
| 351 default: | 352 default: |
| 352 break; | 353 break; |
| 353 } | 354 } |
| 354 | 355 |
| 355 string16 command_line = L"\""; | 356 CommandLine chrome( |
| 356 command_line += chrome_exe_.value(); | 357 delegate_execute::MakeChromeCommandLine(chrome_exe_, parameters_, |
| 357 command_line += L"\""; | 358 display_name)); |
| 358 | 359 string16 command_line(chrome.GetCommandLineString()); |
| 359 if (!parameters_.empty()) { | |
| 360 AtlTrace("Adding parameters %ls to command line\n", parameters_.c_str()); | |
| 361 command_line += L" "; | |
| 362 command_line += parameters_.c_str(); | |
| 363 } | |
| 364 | |
| 365 if (!display_name.empty()) { | |
| 366 command_line += L" -- "; | |
| 367 command_line += display_name; | |
| 368 } | |
| 369 | 360 |
| 370 AtlTrace("Formatted command line is %ls\n", command_line.c_str()); | 361 AtlTrace("Formatted command line is %ls\n", command_line.c_str()); |
| 371 | 362 |
| 372 PROCESS_INFORMATION proc_info = {0}; | 363 base::win::ScopedProcessInformation proc_info; |
| 373 BOOL ret = CreateProcess(NULL, const_cast<LPWSTR>(command_line.c_str()), | 364 BOOL ret = CreateProcess(chrome_exe_.value().c_str(), |
| 365 const_cast<LPWSTR>(command_line.c_str()), |
| 374 NULL, NULL, FALSE, 0, NULL, NULL, &start_info_, | 366 NULL, NULL, FALSE, 0, NULL, NULL, &start_info_, |
| 375 &proc_info); | 367 proc_info.Receive()); |
| 376 if (ret) { | 368 if (ret) { |
| 377 AtlTrace("Process id is %d\n", proc_info.dwProcessId); | 369 AtlTrace("Process id is %d\n", proc_info.process_id()); |
| 378 AllowSetForegroundWindow(proc_info.dwProcessId); | 370 AllowSetForegroundWindow(proc_info.process_id()); |
| 379 CloseHandle(proc_info.hProcess); | |
| 380 CloseHandle(proc_info.hThread); | |
| 381 } else { | 371 } else { |
| 382 AtlTrace("Process launch failed, error %d\n", ::GetLastError()); | 372 AtlTrace("Process launch failed, error %d\n", ::GetLastError()); |
| 383 } | 373 } |
| 384 | 374 |
| 385 return S_OK; | 375 return S_OK; |
| 386 } | 376 } |
| 387 | 377 |
| 388 EC_HOST_UI_MODE CommandExecuteImpl::GetLaunchMode() { | 378 EC_HOST_UI_MODE CommandExecuteImpl::GetLaunchMode() { |
| 389 // See the header file for an explanation of the mode selection logic. | 379 // See the header file for an explanation of the mode selection logic. |
| 390 static bool launch_mode_determined = false; | 380 static bool launch_mode_determined = false; |
| 391 static EC_HOST_UI_MODE launch_mode = ECHUIM_DESKTOP; | 381 static EC_HOST_UI_MODE launch_mode = ECHUIM_DESKTOP; |
| 392 | 382 |
| 393 const char* modes[] = { "Desktop", "Immersive", "SysLauncher", "??" }; | 383 const char* modes[] = { "Desktop", "Immersive", "SysLauncher", "??" }; |
| 394 | 384 |
| 395 if (launch_mode_determined) | 385 if (launch_mode_determined) |
| 396 return launch_mode; | 386 return launch_mode; |
| 397 | 387 |
| 398 if (chrome_mode_ != ECHUIM_SYSTEM_LAUNCHER) { | 388 if (chrome_mode_ != ECHUIM_SYSTEM_LAUNCHER) { |
| 399 launch_mode = chrome_mode_; | 389 launch_mode = chrome_mode_; |
| 400 AtlTrace("Launch mode is that of chrome, %s\n", modes[launch_mode]); | 390 AtlTrace("Launch mode is that of chrome, %s\n", modes[launch_mode]); |
| 401 launch_mode_determined = true; | 391 launch_mode_determined = true; |
| 402 return launch_mode; | 392 return launch_mode; |
| 403 } | 393 } |
| 404 | 394 |
| 405 if (parameters_ == ASCIIToWide(switches::kForceImmersive)) { | 395 if (parameters_.HasSwitch(switches::kForceImmersive)) { |
| 406 launch_mode = ECHUIM_IMMERSIVE; | 396 launch_mode = ECHUIM_IMMERSIVE; |
| 407 launch_mode_determined = true; | 397 launch_mode_determined = true; |
| 408 parameters_.clear(); | 398 parameters_ = CommandLine(CommandLine::NO_PROGRAM); |
| 409 } else if (parameters_ == ASCIIToWide(switches::kForceDesktop)) { | 399 } else if (parameters_.HasSwitch(switches::kForceDesktop)) { |
| 410 launch_mode = ECHUIM_DESKTOP; | 400 launch_mode = ECHUIM_DESKTOP; |
| 411 launch_mode_determined = true; | 401 launch_mode_determined = true; |
| 412 parameters_.clear(); | 402 parameters_ = CommandLine(CommandLine::NO_PROGRAM); |
| 413 } | 403 } |
| 414 | 404 |
| 415 base::win::RegKey reg_key; | 405 base::win::RegKey reg_key; |
| 416 LONG key_result = reg_key.Create(HKEY_CURRENT_USER, | 406 LONG key_result = reg_key.Create(HKEY_CURRENT_USER, |
| 417 chrome::kMetroRegistryPath, | 407 chrome::kMetroRegistryPath, |
| 418 KEY_ALL_ACCESS); | 408 KEY_ALL_ACCESS); |
| 419 if (key_result != ERROR_SUCCESS) { | 409 if (key_result != ERROR_SUCCESS) { |
| 420 AtlTrace("Failed to open HKCU %ls key, error 0x%x\n", | 410 AtlTrace("Failed to open HKCU %ls key, error 0x%x\n", |
| 421 chrome::kMetroRegistryPath, | 411 chrome::kMetroRegistryPath, |
| 422 key_result); | 412 key_result); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 444 AtlTrace("Invalid registry launch mode value %u\n", reg_value); | 434 AtlTrace("Invalid registry launch mode value %u\n", reg_value); |
| 445 launch_mode = ECHUIM_DESKTOP; | 435 launch_mode = ECHUIM_DESKTOP; |
| 446 } else { | 436 } else { |
| 447 AtlTrace("Launch mode forced by registry to %s\n", modes[launch_mode]); | 437 AtlTrace("Launch mode forced by registry to %s\n", modes[launch_mode]); |
| 448 launch_mode = static_cast<EC_HOST_UI_MODE>(reg_value); | 438 launch_mode = static_cast<EC_HOST_UI_MODE>(reg_value); |
| 449 } | 439 } |
| 450 | 440 |
| 451 launch_mode_determined = true; | 441 launch_mode_determined = true; |
| 452 return launch_mode; | 442 return launch_mode; |
| 453 } | 443 } |
| OLD | NEW |