Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: win8/delegate_execute/command_execute_impl.cc

Issue 10928172: Implement the persistent metro mode setting (win8) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/scoped_co_mem.h" 14 #include "base/win/scoped_co_mem.h"
14 #include "base/win/scoped_handle.h" 15 #include "base/win/scoped_handle.h"
15 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_constants.h"
16 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
18 #include "win8/delegate_execute/chrome_util.h" 19 #include "win8/delegate_execute/chrome_util.h"
19 20
20 // CommandExecuteImpl is resposible for activating chrome in Windows 8. The 21 // CommandExecuteImpl is resposible for activating chrome in Windows 8. The
21 // flow is complicated and this tries to highlight the important events. 22 // flow is complicated and this tries to highlight the important events.
22 // The current approach is to have a single instance of chrome either 23 // The current approach is to have a single instance of chrome either
(...skipping 15 matching lines...) Expand all
38 // CommandExecuteImpl::SetParameter 39 // CommandExecuteImpl::SetParameter
39 // CommandExecuteImpl::SetNoShowUI 40 // CommandExecuteImpl::SetNoShowUI
40 // CommandExecuteImpl::SetSelection 41 // CommandExecuteImpl::SetSelection
41 // CommandExecuteImpl::Initialize 42 // CommandExecuteImpl::Initialize
42 // Up to this point the code basically just gathers values passed in, like 43 // Up to this point the code basically just gathers values passed in, like
43 // the launch scheme (or url) and the activation verb. 44 // the launch scheme (or url) and the activation verb.
44 // 5- Windows calls CommandExecuteImpl::Getvalue() 45 // 5- Windows calls CommandExecuteImpl::Getvalue()
45 // Here we need to return AHE_IMMERSIVE or AHE_DESKTOP. That depends on: 46 // Here we need to return AHE_IMMERSIVE or AHE_DESKTOP. That depends on:
46 // a) if run in high-integrity return AHE_DESKTOP 47 // a) if run in high-integrity return AHE_DESKTOP
47 // b) if chrome is running return the AHE_ mode of chrome 48 // b) if chrome is running return the AHE_ mode of chrome
48 // c) if the current process is inmmersive return AHE_IMMERSIVE 49 // c) else we return what GetLaunchMode() tells us, which is:
49 // d) if the protocol is file and IExecuteCommandHost::GetUIMode() is not 50 // i) if the command line --force-xxx is present return that
50 // ECHUIM_DESKTOP then return AHE_IMMERSIVE 51 // ii) if the registry 'launch_mode' exists return that
51 // e) if none of the above return AHE_DESKTOP 52 // iii) if IsMachineATablet() is true return AHE_IMMERSIVE
53 // iv) else return AHE_DESKTOP
52 // 6- If we returned AHE_DESKTOP in step 5 then CommandExecuteImpl::Execute() 54 // 6- If we returned AHE_DESKTOP in step 5 then CommandExecuteImpl::Execute()
53 // is called, here we call GetLaunchMode() which: 55 // is called, here we call GetLaunchMode() which returns the cached answer
54 // a) if chrome is running return the mode of chrome or 56 // computed at step 5c.
55 // b) return IExecuteCommandHost::GetUIMode()
56 // 7- If GetLaunchMode() returns 57 // 7- If GetLaunchMode() returns
57 // a) ECHUIM_DESKTOP we call LaunchDestopChrome() that calls ::CreateProcess 58 // a) ECHUIM_DESKTOP we call LaunchDestopChrome() that calls ::CreateProcess
58 // b) else we call one of the IApplicationActivationManager activation 59 // b) else we call one of the IApplicationActivationManager activation
59 // functions depending on the parameters passed in step 4. 60 // functions depending on the parameters passed in step 4.
60 // 61 //
61 // Some examples will help clarify the common cases. 62 // Note that if a command line --force-xxx is present we write that launch mode
62 // 63 // in the registry so next time the logic reaches 5c-ii it will use the same
63 // I - No chrome running, taskbar icon launch: 64 // mode again.
64 // a) Scheme is 'file', Verb is 'open'
65 // b) GetValue() returns at e) step : AHE_DESKTOP
66 // c) Execute() calls LaunchDestopChrome()
67 // --> desktop chrome runs
68 // II- No chrome running, tile activation launch:
69 // a) Scheme is 'file', Verb is 'open'
70 // b) GetValue() returns at d) step : AHE_IMMERSIVE
71 // c) Windows does not call us back and just activates chrome
72 // --> metro chrome runs
73 // III- No chrome running, url link click on metro app:
74 // a) Scheme is 'http', Verb is 'open'
75 // b) Getvalue() returns at e) step : AHE_DESKTOP
76 // c) Execute() calls IApplicationActivationManager::ActivateForProtocol
77 // --> metro chrome runs
78 // 65 //
79 CommandExecuteImpl::CommandExecuteImpl() 66 CommandExecuteImpl::CommandExecuteImpl()
80 : integrity_level_(base::INTEGRITY_UNKNOWN), 67 : integrity_level_(base::INTEGRITY_UNKNOWN),
81 launch_scheme_(INTERNET_SCHEME_DEFAULT), 68 launch_scheme_(INTERNET_SCHEME_DEFAULT),
82 chrome_mode_(ECHUIM_SYSTEM_LAUNCHER) { 69 chrome_mode_(ECHUIM_SYSTEM_LAUNCHER) {
83 memset(&start_info_, 0, sizeof(start_info_)); 70 memset(&start_info_, 0, sizeof(start_info_));
84 start_info_.cb = sizeof(start_info_); 71 start_info_.cb = sizeof(start_info_);
85 // We need to query the user data dir of chrome so we need chrome's 72 // We need to query the user data dir of chrome so we need chrome's
86 // path provider. 73 // path provider.
87 chrome::RegisterPathProvider(); 74 chrome::RegisterPathProvider();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 chrome_mode_ = ECHUIM_IMMERSIVE; 157 chrome_mode_ = ECHUIM_IMMERSIVE;
171 *pahe = AHE_IMMERSIVE; 158 *pahe = AHE_IMMERSIVE;
172 } else { 159 } else {
173 AtlTrace("Chrome [%d] is Desktop, AHE_DESKTOP\n"); 160 AtlTrace("Chrome [%d] is Desktop, AHE_DESKTOP\n");
174 chrome_mode_ = ECHUIM_DESKTOP; 161 chrome_mode_ = ECHUIM_DESKTOP;
175 *pahe = AHE_DESKTOP; 162 *pahe = AHE_DESKTOP;
176 } 163 }
177 return S_OK; 164 return S_OK;
178 } 165 }
179 166
180 if (IsImmersiveProcess(GetCurrentProcess())) { 167 EC_HOST_UI_MODE mode = GetLaunchMode();
181 AtlTrace("Current process is inmmersive, AHE_IMMERSIVE\n"); 168 *pahe = (mode == ECHUIM_DESKTOP) ? AHE_DESKTOP : AHE_IMMERSIVE;
182 *pahe = AHE_IMMERSIVE;
183 return S_OK;
184 }
185
186 if ((launch_scheme_ == INTERNET_SCHEME_FILE) &&
187 (GetLaunchMode() != ECHUIM_DESKTOP)) {
188 AtlTrace("INTERNET_SCHEME_FILE, mode != ECHUIM_DESKTOP, AHE_IMMERSIVE\n");
189 *pahe = AHE_IMMERSIVE;
190 return S_OK;
191 }
192
193 AtlTrace("Fallback is AHE_DESKTOP\n");
194 *pahe = AHE_DESKTOP;
195 return S_OK; 169 return S_OK;
196 } 170 }
197 171
198 STDMETHODIMP CommandExecuteImpl::Execute() { 172 STDMETHODIMP CommandExecuteImpl::Execute() {
199 AtlTrace("In %hs\n", __FUNCTION__); 173 AtlTrace("In %hs\n", __FUNCTION__);
200 174
201 if (integrity_level_ == base::HIGH_INTEGRITY) 175 if (integrity_level_ == base::HIGH_INTEGRITY)
202 return LaunchDesktopChrome(); 176 return LaunchDesktopChrome();
203 177
204 EC_HOST_UI_MODE mode = GetLaunchMode(); 178 EC_HOST_UI_MODE mode = GetLaunchMode();
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 CloseHandle(proc_info.hProcess); 366 CloseHandle(proc_info.hProcess);
393 CloseHandle(proc_info.hThread); 367 CloseHandle(proc_info.hThread);
394 } else { 368 } else {
395 AtlTrace("Process launch failed, error %d\n", ::GetLastError()); 369 AtlTrace("Process launch failed, error %d\n", ::GetLastError());
396 } 370 }
397 371
398 return S_OK; 372 return S_OK;
399 } 373 }
400 374
401 EC_HOST_UI_MODE CommandExecuteImpl::GetLaunchMode() { 375 EC_HOST_UI_MODE CommandExecuteImpl::GetLaunchMode() {
402 // We are to return chrome's mode if chrome exists else we query our embedder 376 // See the header file for an explanation of the mode selection logic.
403 // IServiceProvider and learn the mode from them.
404 static bool launch_mode_determined = false; 377 static bool launch_mode_determined = false;
405 static EC_HOST_UI_MODE launch_mode = ECHUIM_DESKTOP; 378 static EC_HOST_UI_MODE launch_mode = ECHUIM_DESKTOP;
406 379
407 const char* modes[] = { "Desktop", "Inmmersive", "SysLauncher", "??" }; 380 const char* modes[] = { "Desktop", "Inmmersive", "SysLauncher", "??" };
408 381
409 if (launch_mode_determined) 382 if (launch_mode_determined)
410 return launch_mode; 383 return launch_mode;
411 384
412 if (chrome_mode_ != ECHUIM_SYSTEM_LAUNCHER) { 385 if (chrome_mode_ != ECHUIM_SYSTEM_LAUNCHER) {
413 launch_mode = chrome_mode_; 386 launch_mode = chrome_mode_;
414 AtlTrace("Launch mode is that of chrome, %s\n", modes[launch_mode]); 387 AtlTrace("Launch mode is that of chrome, %s\n", modes[launch_mode]);
415 launch_mode_determined = true; 388 launch_mode_determined = true;
416 return launch_mode; 389 return launch_mode;
417 } 390 }
418 391
419 if (parameters_ == ASCIIToWide(switches::kForceImmersive)) { 392 if (parameters_ == ASCIIToWide(switches::kForceImmersive)) {
420 launch_mode = ECHUIM_IMMERSIVE; 393 launch_mode = ECHUIM_IMMERSIVE;
421 launch_mode_determined = true; 394 launch_mode_determined = true;
395 parameters_.clear();
422 } else if (parameters_ == ASCIIToWide(switches::kForceDesktop)) { 396 } else if (parameters_ == ASCIIToWide(switches::kForceDesktop)) {
423 launch_mode = ECHUIM_DESKTOP; 397 launch_mode = ECHUIM_DESKTOP;
424 launch_mode_determined = true; 398 launch_mode_determined = true;
399 parameters_.clear();
400 }
401
402 base::win::RegKey reg_key;
403 if (reg_key.Create(HKEY_CURRENT_USER,
404 chrome::kMetroRegistryPath,
405 KEY_ALL_ACCESS) != 0) {
grt (UTC plus 2) 2012/09/13 04:33:16 please use ERROR_SUCCESS rather than 0 for consist
cpu_(ooo_6.6-7.5) 2012/09/13 20:56:56 Done.
406 AtlTrace("Failed to open HKCU %ls key\n", chrome::kMetroRegistryPath);
grt (UTC plus 2) 2012/09/13 04:33:16 might be helpful to log the result of reg_key.Crea
cpu_(ooo_6.6-7.5) 2012/09/13 20:56:56 Done.
407 if (!launch_mode_determined) {
408 launch_mode = ECHUIM_DESKTOP;
409 launch_mode_determined = true;
410 }
411 return launch_mode;
425 } 412 }
426 413
427 if (launch_mode_determined) { 414 if (launch_mode_determined) {
428 parameters_.clear(); 415 AtlTrace("Launch mode forced by cmdline to %s\n", modes[launch_mode]);
429 AtlTrace("Launch mode forced to %s\n", modes[launch_mode]); 416 reg_key.WriteValue(chrome::kLaunchModeValue,
grt (UTC plus 2) 2012/09/13 04:33:16 please add code to chrome/installer/setup/uninstal
417 static_cast<DWORD>(launch_mode));
430 return launch_mode; 418 return launch_mode;
431 } 419 }
432 420
433 CComPtr<IExecuteCommandHost> host; 421 DWORD reg_value;
434 CComQIPtr<IServiceProvider> service_provider = m_spUnkSite; 422 if (reg_key.ReadValueDW(chrome::kLaunchModeValue, &reg_value) != 0) {
grt (UTC plus 2) 2012/09/13 04:33:16 please use ERROR_SUCCESS rather than 0
cpu_(ooo_6.6-7.5) 2012/09/13 20:56:56 Done.
435 if (service_provider) { 423 launch_mode = delegate_execute::IsMachineATablet() ?
grt (UTC plus 2) 2012/09/13 04:33:16 i'm curious: is this ever called when chrome isn't
cpu_(ooo_6.6-7.5) 2012/09/13 20:56:56 I'' see if it does.
436 service_provider->QueryService(IID_IExecuteCommandHost, &host); 424 ECHUIM_IMMERSIVE : ECHUIM_DESKTOP;
437 if (host) { 425 AtlTrace("Launch mode forced by heuristics to %s\n", modes[launch_mode]);
438 host->GetUIMode(&launch_mode); 426 } else if (reg_value > ECHUIM_SYSTEM_LAUNCHER) {
grt (UTC plus 2) 2012/09/13 04:33:16 should this be >=? is it valid for the launch mod
cpu_(ooo_6.6-7.5) 2012/09/13 20:56:56 I was thinking on using it experimentally but I'll
439 } else { 427 AtlTrace("Invalid registry launch mode value %u\n", reg_value);
440 AtlTrace("Failed to get IID_IExecuteCommandHost. Assuming desktop\n"); 428 launch_mode = ECHUIM_DESKTOP;
441 }
442 } else { 429 } else {
443 AtlTrace("Failed to get IServiceProvider. Assuming desktop mode\n"); 430 AtlTrace("Launch mode forced by registry to %s\n", modes[launch_mode]);
431 launch_mode = static_cast<EC_HOST_UI_MODE>(reg_value);
444 } 432 }
445 AtlTrace("Launch mode is %s\n", modes[launch_mode]); 433
446 launch_mode_determined = true; 434 launch_mode_determined = true;
447 return launch_mode; 435 return launch_mode;
448 } 436 }
OLDNEW
« chrome/common/chrome_constants.cc ('K') | « win8/delegate_execute/chrome_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698