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 3 // found in the LICENSE file. 4 5 #include <atlbase.h> 6 #include <atlcom.h> 7 #include <atlctl.h> 8 #include <ShObjIdl.h> 9 #include <WinInet.h> 10 11 #include <string> 12 13 #include "base/command_line.h" 14 #include "base/files/file_path.h" 15 #include "base/process/process_handle.h" 16 #include "win8/delegate_execute/resource.h" // main symbols 17 18 using namespace ATL; 19 20 EXTERN_C const GUID CLSID_CommandExecuteImpl; 21 22 // CommandExecuteImpl 23 // This class implements the IExecuteCommand and related interfaces for 24 // handling ShellExecute launches of the Chrome browser, i.e. whether to 25 // launch Chrome in metro mode or desktop mode. 26 #if defined(GOOGLE_CHROME_BUILD) 27 class ATL_NO_VTABLE DECLSPEC_UUID("5C65F4B0-3651-4514-B207-D10CB699B14B") 28 CommandExecuteImpl 29 #else // GOOGLE_CHROME_BUILD 30 class ATL_NO_VTABLE DECLSPEC_UUID("A2DF06F9-A21A-44A8-8A99-8B9C84F29160") 31 CommandExecuteImpl 32 #endif // GOOGLE_CHROME_BUILD 33 : public CComObjectRootEx<CComSingleThreadModel>, 34 public CComCoClass<CommandExecuteImpl, &CLSID_CommandExecuteImpl>, 35 public IExecuteCommand, 36 public IObjectWithSiteImpl<CommandExecuteImpl>, 37 public IInitializeCommand, 38 public IObjectWithSelection, 39 public IExecuteCommandApplicationHostEnvironment, 40 public IForegroundTransfer { 41 public: 42 CommandExecuteImpl(); 43 44 DECLARE_REGISTRY_RESOURCEID(IDR_COMMANDEXECUTEIMPL) 45 46 BEGIN_COM_MAP(CommandExecuteImpl) 47 COM_INTERFACE_ENTRY(IExecuteCommand) 48 COM_INTERFACE_ENTRY(IObjectWithSite) 49 COM_INTERFACE_ENTRY(IInitializeCommand) 50 COM_INTERFACE_ENTRY(IObjectWithSelection) 51 COM_INTERFACE_ENTRY(IExecuteCommandApplicationHostEnvironment) 52 COM_INTERFACE_ENTRY(IForegroundTransfer) 53 END_COM_MAP() 54 55 DECLARE_PROTECT_FINAL_CONSTRUCT() 56 57 HRESULT FinalConstruct() { 58 return S_OK; 59 } 60 61 void FinalRelease() { 62 } 63 64 public: 65 // IExecuteCommand 66 STDMETHOD(SetKeyState)(DWORD key_state); 67 STDMETHOD(SetParameters)(LPCWSTR params); 68 STDMETHOD(SetPosition)(POINT pt); 69 STDMETHOD(SetShowWindow)(int show); 70 STDMETHOD(SetNoShowUI)(BOOL no_show_ui); 71 STDMETHOD(SetDirectory)(LPCWSTR directory); 72 STDMETHOD(Execute)(void); 73 74 // IInitializeCommand 75 STDMETHOD(Initialize)(LPCWSTR name, IPropertyBag* bag); 76 77 // IObjectWithSelection 78 STDMETHOD(SetSelection)(IShellItemArray* item_array); 79 STDMETHOD(GetSelection)(REFIID riid, void** selection); 80 81 // IExecuteCommandApplicationHostEnvironment 82 STDMETHOD(GetValue)(enum AHE_TYPE* pahe); 83 84 // IForegroundTransfer 85 STDMETHOD(AllowForegroundTransfer)(void* reserved); 86 87 private: 88 static bool FindChromeExe(base::FilePath* chrome_exe); 89 90 static bool path_provider_initialized_; 91 92 bool GetLaunchScheme(string16* display_name, INTERNET_SCHEME* scheme); 93 HRESULT LaunchDesktopChrome(); 94 // Returns the launch mode, i.e. desktop launch/metro launch, etc. 95 EC_HOST_UI_MODE GetLaunchMode(); 96 97 CComPtr<IShellItemArray> item_array_; 98 CommandLine parameters_; 99 base::FilePath chrome_exe_; 100 STARTUPINFO start_info_; 101 string16 verb_; 102 string16 display_name_; 103 INTERNET_SCHEME launch_scheme_; 104 105 base::IntegrityLevel integrity_level_; 106 EC_HOST_UI_MODE chrome_mode_; 107 }; 108 109 OBJECT_ENTRY_AUTO(__uuidof(CommandExecuteImpl), CommandExecuteImpl) 110