OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/intsafe_workaround.h" | 5 #include "build/intsafe_workaround.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlcom.h> | 8 #include <atlcom.h> |
9 #include <atlctl.h> | 9 #include <atlctl.h> |
10 #include <initguid.h> | 10 #include <initguid.h> |
11 #include <shellapi.h> | 11 #include <shellapi.h> |
12 | 12 |
13 #include "base/at_exit.h" | 13 #include "base/at_exit.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/process/kill.h" | 17 #include "base/process/kill.h" |
18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
19 #include "base/win/scoped_com_initializer.h" | 19 #include "base/win/scoped_com_initializer.h" |
| 20 #include "base/win/scoped_comptr.h" |
20 #include "base/win/scoped_handle.h" | 21 #include "base/win/scoped_handle.h" |
21 #include "breakpad/src/client/windows/handler/exception_handler.h" | 22 #include "breakpad/src/client/windows/handler/exception_handler.h" |
22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/installer/util/browser_distribution.h" |
23 #include "win8/delegate_execute/command_execute_impl.h" | 25 #include "win8/delegate_execute/command_execute_impl.h" |
24 #include "win8/delegate_execute/crash_server_init.h" | 26 #include "win8/delegate_execute/crash_server_init.h" |
25 #include "win8/delegate_execute/delegate_execute_operation.h" | 27 #include "win8/delegate_execute/delegate_execute_operation.h" |
26 #include "win8/delegate_execute/resource.h" | 28 #include "win8/delegate_execute/resource.h" |
27 | 29 |
28 using namespace ATL; | 30 using namespace ATL; |
29 | 31 |
| 32 // Usually classes derived from CAtlExeModuleT, or other types of ATL |
| 33 // COM module classes statically define their CLSID at compile time through |
| 34 // the use of various macros, and ATL internals takes care of creating the |
| 35 // class objects and registering them. However, we need to register the same |
| 36 // object with different CLSIDs depending on a runtime setting, so we handle |
| 37 // that logic here, before the main ATL message loop runs. |
30 class DelegateExecuteModule | 38 class DelegateExecuteModule |
31 : public ATL::CAtlExeModuleT< DelegateExecuteModule > { | 39 : public ATL::CAtlExeModuleT< DelegateExecuteModule > { |
32 public : | 40 public : |
33 typedef ATL::CAtlExeModuleT<DelegateExecuteModule> ParentClass; | 41 typedef ATL::CAtlExeModuleT<DelegateExecuteModule> ParentClass; |
| 42 typedef CComObject<CommandExecuteImpl> ImplType; |
34 | 43 |
35 HRESULT RegisterServer(BOOL reg_type_lib) { | 44 DelegateExecuteModule() |
36 return ParentClass::RegisterServer(FALSE); | 45 : registration_token_(0) { |
37 } | 46 } |
38 | 47 |
39 virtual HRESULT AddCommonRGSReplacements(IRegistrarBase* registrar) throw() { | 48 HRESULT PreMessageLoop(int nShowCmd) { |
40 AtlTrace(L"In %hs\n", __FUNCTION__); | 49 HRESULT hr = S_OK; |
41 HRESULT hr = ParentClass::AddCommonRGSReplacements(registrar); | 50 string16 clsid_string; |
| 51 GUID clsid; |
| 52 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 53 if (!dist->GetCommandExecuteImplClsid(&clsid_string)) |
| 54 return E_FAIL; |
| 55 hr = ::CLSIDFromString(clsid_string.c_str(), &clsid); |
42 if (FAILED(hr)) | 56 if (FAILED(hr)) |
43 return hr; | 57 return hr; |
44 | 58 |
45 wchar_t delegate_execute_clsid[MAX_PATH] = {0}; | 59 // We use the same class creation logic as ATL itself. See |
46 if (!StringFromGUID2(__uuidof(CommandExecuteImpl), delegate_execute_clsid, | 60 // _ATL_OBJMAP_ENTRY::RegisterClassObject() in atlbase.h |
47 ARRAYSIZE(delegate_execute_clsid))) { | 61 hr = ImplType::_ClassFactoryCreatorClass::CreateInstance( |
48 ATLASSERT(false); | 62 ImplType::_CreatorClass::CreateInstance, IID_IUnknown, |
49 return E_FAIL; | 63 instance_.ReceiveVoid()); |
| 64 if (FAILED(hr)) |
| 65 return hr; |
| 66 hr = ::CoRegisterClassObject(clsid, instance_, CLSCTX_LOCAL_SERVER, |
| 67 REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED, ®istration_token_); |
| 68 if (FAILED(hr)) |
| 69 return hr; |
| 70 |
| 71 return ParentClass::PreMessageLoop(nShowCmd); |
| 72 } |
| 73 |
| 74 HRESULT PostMessageLoop() { |
| 75 if (registration_token_ != 0) { |
| 76 ::CoRevokeClassObject(registration_token_); |
| 77 registration_token_ = 0; |
50 } | 78 } |
51 | 79 |
52 hr = registrar->AddReplacement(L"DELEGATE_EXECUTE_CLSID", | 80 instance_.Release(); |
53 delegate_execute_clsid); | 81 |
54 ATLASSERT(SUCCEEDED(hr)); | 82 return ParentClass::PostMessageLoop(); |
55 return hr; | |
56 } | 83 } |
| 84 |
| 85 private: |
| 86 base::win::ScopedComPtr<IUnknown> instance_; |
| 87 DWORD registration_token_; |
57 }; | 88 }; |
58 | 89 |
59 DelegateExecuteModule _AtlModule; | 90 DelegateExecuteModule _AtlModule; |
60 | 91 |
61 using delegate_execute::DelegateExecuteOperation; | 92 using delegate_execute::DelegateExecuteOperation; |
62 using base::win::ScopedHandle; | 93 using base::win::ScopedHandle; |
63 | 94 |
64 int RelaunchChrome(const DelegateExecuteOperation& operation) { | 95 int RelaunchChrome(const DelegateExecuteOperation& operation) { |
65 AtlTrace("Relaunching [%ls] with flags [%s]\n", | 96 AtlTrace("Relaunching [%ls] with flags [%s]\n", |
66 operation.mutex().c_str(), operation.relaunch_flags()); | 97 operation.mutex().c_str(), operation.relaunch_flags()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 case DelegateExecuteOperation::RELAUNCH_CHROME: | 156 case DelegateExecuteOperation::RELAUNCH_CHROME: |
126 ret_code = RelaunchChrome(operation); | 157 ret_code = RelaunchChrome(operation); |
127 break; | 158 break; |
128 default: | 159 default: |
129 NOTREACHED(); | 160 NOTREACHED(); |
130 } | 161 } |
131 } | 162 } |
132 AtlTrace("delegate_execute exit, code = %d\n", ret_code); | 163 AtlTrace("delegate_execute exit, code = %d\n", ret_code); |
133 return ret_code; | 164 return ret_code; |
134 } | 165 } |
OLD | NEW |