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.
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
18 EXTERN_C const GUID CLSID_CommandExecuteImpl;
21 // This class implements the IExecuteCommand and related interfaces for
22 // handling ShellExecute launches of the Chrome browser, i.e. whether to
23 // launch Chrome in metro mode or desktop mode.
24 // The CLSID here is a dummy CLSID not used for anything, since we register
25 // the class with a dynamic CLSID. However, a static CLSID is necessary
26 // so that we can force at least one entry into ATL's object map (it will
27 // treat a 0-element object map as an initialization failure case).
28 class ATL_NO_VTABLE DECLSPEC_UUID("071BB5F2-85A4-424F-BFE7-5F1609BE4C2C")
30 : public CComObjectRootEx<CComSingleThreadModel>,
31 public CComCoClass<CommandExecuteImpl, &CLSID_CommandExecuteImpl>,
32 public IExecuteCommand,
33 public IObjectWithSiteImpl<CommandExecuteImpl>,
34 public IInitializeCommand,
35 public IObjectWithSelection,
36 public IExecuteCommandApplicationHostEnvironment,
37 public IForegroundTransfer {
41 DECLARE_REGISTRY_RESOURCEID(IDR_COMMANDEXECUTEIMPL)
43 BEGIN_COM_MAP(CommandExecuteImpl)
44 COM_INTERFACE_ENTRY(IExecuteCommand)
45 COM_INTERFACE_ENTRY(IObjectWithSite)
46 COM_INTERFACE_ENTRY(IInitializeCommand)
47 COM_INTERFACE_ENTRY(IObjectWithSelection)
48 COM_INTERFACE_ENTRY(IExecuteCommandApplicationHostEnvironment)
49 COM_INTERFACE_ENTRY(IForegroundTransfer)
52 DECLARE_PROTECT_FINAL_CONSTRUCT()
54 HRESULT FinalConstruct() {
63 STDMETHOD(SetKeyState)(DWORD key_state);
64 STDMETHOD(SetParameters)(LPCWSTR params);
65 STDMETHOD(SetPosition)(POINT pt);
66 STDMETHOD(SetShowWindow)(int show);
67 STDMETHOD(SetNoShowUI)(BOOL no_show_ui);
68 STDMETHOD(SetDirectory)(LPCWSTR directory);
69 STDMETHOD(Execute)(void);
72 STDMETHOD(Initialize)(LPCWSTR name, IPropertyBag* bag);
74 // IObjectWithSelection
75 STDMETHOD(SetSelection)(IShellItemArray* item_array);
76 STDMETHOD(GetSelection)(REFIID riid, void** selection);
78 // IExecuteCommandApplicationHostEnvironment
79 STDMETHOD(GetValue)(enum AHE_TYPE* pahe);
81 // IForegroundTransfer
82 STDMETHOD(AllowForegroundTransfer)(void* reserved);
84 static bool FindChromeExe(base::FilePath* chrome_exe);
88 static bool path_provider_initialized_;
90 bool GetLaunchScheme(base::string16* display_name, INTERNET_SCHEME* scheme);
91 HRESULT LaunchDesktopChrome();
92 // Returns the launch mode, i.e. desktop launch/metro launch, etc.
93 EC_HOST_UI_MODE GetLaunchMode();
95 CComPtr<IShellItemArray> item_array_;
96 base::CommandLine parameters_;
97 base::FilePath chrome_exe_;
98 STARTUPINFO start_info_;
100 base::string16 display_name_;
101 INTERNET_SCHEME launch_scheme_;
103 base::IntegrityLevel integrity_level_;
106 OBJECT_ENTRY_AUTO(__uuidof(CommandExecuteImpl), CommandExecuteImpl)