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