Home | History | Annotate | Download | only in delegate_execute
      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 
     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 
     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   bool GetLaunchScheme(string16* display_name, INTERNET_SCHEME* scheme);
     92   HRESULT LaunchDesktopChrome();
     93   // Returns the launch mode, i.e. desktop launch/metro launch, etc.
     94   EC_HOST_UI_MODE GetLaunchMode();
     95 
     96   CComPtr<IShellItemArray> item_array_;
     97   CommandLine parameters_;
     98   base::FilePath chrome_exe_;
     99   STARTUPINFO start_info_;
    100   string16 verb_;
    101   string16 display_name_;
    102   INTERNET_SCHEME launch_scheme_;
    103 
    104   base::IntegrityLevel integrity_level_;
    105   EC_HOST_UI_MODE chrome_mode_;
    106 };
    107 
    108 OBJECT_ENTRY_AUTO(__uuidof(CommandExecuteImpl), CommandExecuteImpl)
    109