| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include "omaha/goopdate/oneclick_process_launcher.h" | |
| 17 | |
| 18 #include "base/scoped_ptr.h" | |
| 19 #include "omaha/base/scoped_ptr_address.h" | |
| 20 #include "omaha/goopdate/app_command.h" | |
| 21 | |
| 22 namespace omaha { | |
| 23 | |
| 24 OneClickProcessLauncher::OneClickProcessLauncher() {} | |
| 25 | |
| 26 OneClickProcessLauncher::~OneClickProcessLauncher() {} | |
| 27 | |
| 28 STDMETHODIMP OneClickProcessLauncher::LaunchAppCommand( | |
| 29 const WCHAR* app_guid, const WCHAR* cmd_id) { | |
| 30 ASSERT1(app_guid); | |
| 31 ASSERT1(cmd_id); | |
| 32 | |
| 33 if (!app_guid || !cmd_id) { | |
| 34 return E_INVALIDARG; | |
| 35 } | |
| 36 | |
| 37 CORE_LOG(L3, (_T("[OneClickProcessLauncher::LaunchAppCommand]") | |
| 38 _T("[app %s][cmd %s]"), app_guid, cmd_id)); | |
| 39 | |
| 40 // Allocate a session ID for the ping that this call will generate. | |
| 41 // TODO(omaha3): Are there any situations where this control can be | |
| 42 // instantiated outside of the context of an Update3Web/OneClick | |
| 43 // webpage? If not, we should consider adding a function to | |
| 44 // OneClickProcessLauncher() to modify the session ID it uses. | |
| 45 CString session_id; | |
| 46 GetGuid(&session_id); | |
| 47 | |
| 48 scoped_ptr<AppCommand> app_command; | |
| 49 HRESULT hr = AppCommand::Load(app_guid, | |
| 50 is_machine(), | |
| 51 cmd_id, | |
| 52 session_id, | |
| 53 address(app_command)); | |
| 54 if (FAILED(hr)) { | |
| 55 CORE_LOG(LE, (_T("[failed to load command configuration][0x%x]"), hr)); | |
| 56 return hr; | |
| 57 } | |
| 58 | |
| 59 if (!app_command->is_web_accessible()) { | |
| 60 return E_ACCESSDENIED; | |
| 61 } | |
| 62 | |
| 63 if (!is_machine()) { | |
| 64 // Execute directly at medium integrity for user-level mode | |
| 65 scoped_process process; | |
| 66 return app_command->Execute(address(process)); | |
| 67 } | |
| 68 | |
| 69 // Elevate to high integrity for machine-level mode | |
| 70 CComPtr<IProcessLauncher> process_launcher; | |
| 71 hr = process_launcher.CoCreateInstance(__uuidof(ProcessLauncherClass)); | |
| 72 if (FAILED(hr)) { | |
| 73 return hr; | |
| 74 } | |
| 75 | |
| 76 ULONG_PTR phandle = NULL; | |
| 77 DWORD process_id = ::GetCurrentProcessId(); | |
| 78 | |
| 79 hr = process_launcher->LaunchCmdElevated( | |
| 80 app_guid, cmd_id, process_id, &phandle); | |
| 81 | |
| 82 if (SUCCEEDED(hr)) { | |
| 83 ::CloseHandle(reinterpret_cast<HANDLE>(phandle)); | |
| 84 } | |
| 85 | |
| 86 return hr; | |
| 87 } | |
| 88 | |
| 89 } // namespace omaha | |
| OLD | NEW |