OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 <shellapi.h> |
| 9 |
| 10 #include "base/at_exit.h" |
| 11 #include "base/command_line.h" |
| 12 #include "base/file_path.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/path_service.h" |
| 15 #include "base/stringprintf.h" |
| 16 #include "win8/test/test_registrar_constants.h" |
| 17 #include "win8/test/test_registrar_resource.h" |
| 18 |
| 19 namespace { |
| 20 |
| 21 const wchar_t kDelegateExecuteCLSID[] = |
| 22 L"{FC0064A6-D1DE-4A83-92D2-5BB4EEBB70B5}"; |
| 23 |
| 24 void InitializeCommandLineDefaultValues() { |
| 25 CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 26 |
| 27 if (!command_line.HasSwitch(win8::test::kTestAppUserModelId)) |
| 28 command_line.AppendSwitchNative(win8::test::kTestAppUserModelId, |
| 29 win8::test::kDefaultTestAppUserModelId); |
| 30 |
| 31 if (!command_line.HasSwitch(win8::test::kTestExeName)) |
| 32 command_line.AppendSwitchNative(win8::test::kTestExeName, |
| 33 win8::test::kDefaultTestExeName); |
| 34 |
| 35 if (!command_line.HasSwitch(win8::test::kTestExePath)) { |
| 36 base::FilePath exe_path; |
| 37 PathService::Get(base::DIR_EXE, &exe_path); |
| 38 exe_path = exe_path.Append(win8::test::kDefaultTestExePath); |
| 39 |
| 40 command_line.AppendSwitchNative(win8::test::kTestExePath, |
| 41 exe_path.value()); |
| 42 } |
| 43 |
| 44 if (!command_line.HasSwitch(win8::test::kTestProgId)) |
| 45 command_line.AppendSwitchNative(win8::test::kTestProgId, |
| 46 win8::test::kDefaultTestProgId); |
| 47 } |
| 48 |
| 49 } // namespace |
| 50 |
| 51 // Implementation of an ATL module that provides the necessary replacement |
| 52 // values for the default browser .rgs script. |
| 53 class TestDelegateExecuteModule |
| 54 : public ATL::CAtlExeModuleT< TestDelegateExecuteModule > { |
| 55 public : |
| 56 typedef ATL::CAtlExeModuleT<TestDelegateExecuteModule> ParentClass; |
| 57 |
| 58 DECLARE_REGISTRY_RESOURCEID(IDR_TESTDELEGATEEXECUTE); |
| 59 |
| 60 HRESULT RegisterServer(BOOL reg_type_lib) { |
| 61 return ParentClass::RegisterServer(FALSE); |
| 62 } |
| 63 |
| 64 virtual HRESULT AddCommonRGSReplacements(IRegistrarBase* registrar) throw() { |
| 65 AtlTrace(L"In %hs\n", __FUNCTION__); |
| 66 HRESULT hr = ParentClass::AddCommonRGSReplacements(registrar); |
| 67 if (FAILED(hr)) |
| 68 return hr; |
| 69 |
| 70 registrar->AddReplacement(L"DELEGATE_EXECUTE_CLSID", kDelegateExecuteCLSID); |
| 71 |
| 72 CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 73 |
| 74 registrar->AddReplacement(L"APP_USER_MODEL_ID", |
| 75 command_line.GetSwitchValueNative( |
| 76 win8::test::kTestAppUserModelId).c_str()); |
| 77 registrar->AddReplacement(L"EXE_NAME", |
| 78 command_line.GetSwitchValueNative( |
| 79 win8::test::kTestExeName).c_str()); |
| 80 registrar->AddReplacement(L"PROG_ID", |
| 81 command_line.GetSwitchValueNative( |
| 82 win8::test::kTestProgId).c_str()); |
| 83 |
| 84 string16 exe_path( |
| 85 command_line.GetSwitchValueNative(win8::test::kTestExePath)); |
| 86 |
| 87 string16 exe_open_command(base::StringPrintf(L"\"%ls\" -- %%*", |
| 88 exe_path.c_str())); |
| 89 registrar->AddReplacement(L"EXE_OPEN_COMMAND", exe_open_command.c_str()); |
| 90 |
| 91 string16 exe_icon(base::StringPrintf(L"%ls,0", exe_path.c_str())); |
| 92 registrar->AddReplacement(L"EXE_ICON", exe_icon.c_str()); |
| 93 |
| 94 string16 prog_id_open_command(base::StringPrintf(L"\"%ls\" -- \"%%1\"", |
| 95 exe_path.c_str())); |
| 96 registrar->AddReplacement(L"PROG_ID_OPEN_COMMAND", |
| 97 prog_id_open_command.c_str()); |
| 98 |
| 99 ATLASSERT(SUCCEEDED(hr)); |
| 100 return hr; |
| 101 } |
| 102 }; |
| 103 |
| 104 TestDelegateExecuteModule _AtlModule; |
| 105 |
| 106 EXTERN_C const GUID CLSID_TestDefaultBrowserRegistrar; |
| 107 class ATL_NO_VTABLE DECLSPEC_UUID("FC0064A6-D1DE-4A83-92D2-5BB4EEBB70B5") |
| 108 TestDefaultBrowserRegistrar |
| 109 : public CComObjectRootEx<CComSingleThreadModel>, |
| 110 public CComCoClass<TestDefaultBrowserRegistrar, |
| 111 &CLSID_TestDefaultBrowserRegistrar> { |
| 112 public: |
| 113 DECLARE_REGISTRY_RESOURCEID(IDR_TESTDELEGATEEXECUTE); |
| 114 |
| 115 BEGIN_COM_MAP(TestDefaultBrowserRegistrar) |
| 116 END_COM_MAP() |
| 117 }; |
| 118 |
| 119 extern "C" int WINAPI _tWinMain(HINSTANCE , HINSTANCE, LPTSTR, int nShowCmd) { |
| 120 base::AtExitManager exit_manager; |
| 121 CommandLine::Init(0, NULL); |
| 122 InitializeCommandLineDefaultValues(); |
| 123 |
| 124 HRESULT ret_code = _AtlModule.WinMain(nShowCmd); |
| 125 |
| 126 return ret_code; |
| 127 } |
| 128 |
| 129 OBJECT_ENTRY_AUTO(__uuidof(TestDefaultBrowserRegistrar), |
| 130 TestDefaultBrowserRegistrar); |
OLD | NEW |