• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // The CLSID here is a dummy CLSID not used for anything, since we register
27 // the class with a dynamic CLSID.  However, a static CLSID is necessary
28 // so that we can force at least one entry into ATL's object map (it will
29 // treat a 0-element object map as an initialization failure case).
30 class ATL_NO_VTABLE DECLSPEC_UUID("071BB5F2-85A4-424F-BFE7-5F1609BE4C2C")
31     CommandExecuteImpl
32     : public CComObjectRootEx<CComSingleThreadModel>,
33       public CComCoClass<CommandExecuteImpl, &CLSID_CommandExecuteImpl>,
34       public IExecuteCommand,
35       public IObjectWithSiteImpl<CommandExecuteImpl>,
36       public IInitializeCommand,
37       public IObjectWithSelection,
38       public IExecuteCommandApplicationHostEnvironment,
39       public IForegroundTransfer {
40  public:
41   CommandExecuteImpl();
42 
43   DECLARE_REGISTRY_RESOURCEID(IDR_COMMANDEXECUTEIMPL)
44 
BEGIN_COM_MAP(CommandExecuteImpl)45   BEGIN_COM_MAP(CommandExecuteImpl)
46     COM_INTERFACE_ENTRY(IExecuteCommand)
47     COM_INTERFACE_ENTRY(IObjectWithSite)
48     COM_INTERFACE_ENTRY(IInitializeCommand)
49     COM_INTERFACE_ENTRY(IObjectWithSelection)
50     COM_INTERFACE_ENTRY(IExecuteCommandApplicationHostEnvironment)
51     COM_INTERFACE_ENTRY(IForegroundTransfer)
52   END_COM_MAP()
53 
54   DECLARE_PROTECT_FINAL_CONSTRUCT()
55 
56   HRESULT FinalConstruct() {
57     return S_OK;
58   }
59 
FinalRelease()60   void FinalRelease() {
61   }
62 
63  public:
64   // IExecuteCommand
65   STDMETHOD(SetKeyState)(DWORD key_state);
66   STDMETHOD(SetParameters)(LPCWSTR params);
67   STDMETHOD(SetPosition)(POINT pt);
68   STDMETHOD(SetShowWindow)(int show);
69   STDMETHOD(SetNoShowUI)(BOOL no_show_ui);
70   STDMETHOD(SetDirectory)(LPCWSTR directory);
71   STDMETHOD(Execute)(void);
72 
73   // IInitializeCommand
74   STDMETHOD(Initialize)(LPCWSTR name, IPropertyBag* bag);
75 
76   // IObjectWithSelection
77   STDMETHOD(SetSelection)(IShellItemArray* item_array);
78   STDMETHOD(GetSelection)(REFIID riid, void** selection);
79 
80   // IExecuteCommandApplicationHostEnvironment
81   STDMETHOD(GetValue)(enum AHE_TYPE* pahe);
82 
83   // IForegroundTransfer
84   STDMETHOD(AllowForegroundTransfer)(void* reserved);
85 
86  private:
87   static bool FindChromeExe(base::FilePath* chrome_exe);
88 
89   static bool path_provider_initialized_;
90 
91   void SetHighDPIRegistryKey(bool enable);
92 
93   bool GetLaunchScheme(base::string16* display_name, INTERNET_SCHEME* scheme);
94   HRESULT LaunchDesktopChrome();
95   // Returns the launch mode, i.e. desktop launch/metro launch, etc.
96   EC_HOST_UI_MODE GetLaunchMode();
97 
98   CComPtr<IShellItemArray> item_array_;
99   base::CommandLine parameters_;
100   base::FilePath chrome_exe_;
101   STARTUPINFO start_info_;
102   base::string16 verb_;
103   base::string16 display_name_;
104   INTERNET_SCHEME launch_scheme_;
105 
106   base::IntegrityLevel integrity_level_;
107 };
108 
109 OBJECT_ENTRY_AUTO(__uuidof(CommandExecuteImpl), CommandExecuteImpl)
110