Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / win8 / delegate_execute / command_execute_impl.h
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 EXTERN_C const GUID CLSID_CommandExecuteImpl;
19
20 // 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")
29     CommandExecuteImpl
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 {
38  public:
39   CommandExecuteImpl();
40
41   DECLARE_REGISTRY_RESOURCEID(IDR_COMMANDEXECUTEIMPL)
42
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)
50   END_COM_MAP()
51
52   DECLARE_PROTECT_FINAL_CONSTRUCT()
53
54   HRESULT FinalConstruct() {
55     return S_OK;
56   }
57
58   void FinalRelease() {
59   }
60
61  public:
62   // IExecuteCommand
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);
70
71   // IInitializeCommand
72   STDMETHOD(Initialize)(LPCWSTR name, IPropertyBag* bag);
73
74   // IObjectWithSelection
75   STDMETHOD(SetSelection)(IShellItemArray* item_array);
76   STDMETHOD(GetSelection)(REFIID riid, void** selection);
77
78   // IExecuteCommandApplicationHostEnvironment
79   STDMETHOD(GetValue)(enum AHE_TYPE* pahe);
80
81   // IForegroundTransfer
82   STDMETHOD(AllowForegroundTransfer)(void* reserved);
83
84   static bool FindChromeExe(base::FilePath* chrome_exe);
85
86  private:
87
88   static bool path_provider_initialized_;
89
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();
94
95   CComPtr<IShellItemArray> item_array_;
96   base::CommandLine parameters_;
97   base::FilePath chrome_exe_;
98   STARTUPINFO start_info_;
99   base::string16 verb_;
100   base::string16 display_name_;
101   INTERNET_SCHEME launch_scheme_;
102
103   base::IntegrityLevel integrity_level_;
104 };
105
106 OBJECT_ENTRY_AUTO(__uuidof(CommandExecuteImpl), CommandExecuteImpl)