diff options
Diffstat (limited to 'win8')
-rw-r--r-- | win8/delegate_execute/delegate_execute.cc | 2 | ||||
-rw-r--r-- | win8/test/metro_registration_helper.cc | 78 | ||||
-rw-r--r-- | win8/test/metro_registration_helper.h | 27 | ||||
-rw-r--r-- | win8/test/test_registrar.cc | 141 | ||||
-rw-r--r-- | win8/test/test_registrar.rc | 50 | ||||
-rw-r--r-- | win8/test/test_registrar.rgs | 99 | ||||
-rw-r--r-- | win8/test/test_registrar_constants.cc | 31 | ||||
-rw-r--r-- | win8/test/test_registrar_constants.h | 24 | ||||
-rw-r--r-- | win8/test/test_registrar_resource.h | 7 | ||||
-rw-r--r-- | win8/win8.gyp | 37 |
10 files changed, 495 insertions, 1 deletions
diff --git a/win8/delegate_execute/delegate_execute.cc b/win8/delegate_execute/delegate_execute.cc index f153db5..770b8e8 100644 --- a/win8/delegate_execute/delegate_execute.cc +++ b/win8/delegate_execute/delegate_execute.cc @@ -18,7 +18,7 @@ #include "base/win/scoped_handle.h" #include "breakpad/src/client/windows/handler/exception_handler.h" #include "chrome/common/chrome_switches.h" -#include "command_execute_impl.h" +#include "win8/delegate_execute/command_execute_impl.h" #include "win8/delegate_execute/crash_server_init.h" #include "win8/delegate_execute/delegate_execute_operation.h" #include "win8/delegate_execute/resource.h" diff --git a/win8/test/metro_registration_helper.cc b/win8/test/metro_registration_helper.cc new file mode 100644 index 0000000..79e19d4 --- /dev/null +++ b/win8/test/metro_registration_helper.cc @@ -0,0 +1,78 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "win8/test/metro_registration_helper.h" + +#include "base/command_line.h" +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/logging.h" +#include "base/path_service.h" +#include "base/process.h" +#include "base/process_util.h" +#include "base/win/scoped_handle.h" +#include "win8/test/test_registrar_constants.h" + +namespace { + +const int kRegistrationTimeoutSeconds = 30; + +// Copied from util_constants.cc to avoid taking a dependency on installer_util. +const wchar_t kChromeExe[] = L"chrome.exe"; +const wchar_t kRegistrar[] = L"test_registrar.exe"; + +} + +namespace win8 { + +bool RegisterTestDefaultBrowser(const string16& app_user_model_id, + const string16& viewer_process_name) { + FilePath dir; + if (!PathService::Get(base::DIR_EXE, &dir)) + return false; + + FilePath chrome_exe(dir.Append(kChromeExe)); + FilePath registrar(dir.Append(kRegistrar)); + + if (!file_util::PathExists(chrome_exe) || !file_util::PathExists(registrar)) { + LOG(ERROR) << "Could not locate " << kChromeExe << " or " << kRegistrar; + return false; + } + + // Perform the registration by invoking test_registrar.exe with the + // necessary flags: + // test_registrar.exe /RegServer --appid=<appid> --exe-name=<name> + CommandLine register_command(registrar); + register_command.AppendArg("/RegServer"); + register_command.AppendSwitchNative(win8::test::kTestAppUserModelId, + app_user_model_id); + register_command.AppendSwitchNative(win8::test::kTestExeName, + viewer_process_name); + + base::win::ScopedHandle register_handle; + if (base::LaunchProcess(register_command, base::LaunchOptions(), + register_handle.Receive())) { + int ret = 0; + if (base::WaitForExitCodeWithTimeout( + register_handle, &ret, + base::TimeDelta::FromSeconds(kRegistrationTimeoutSeconds))) { + if (ret == 0) { + return true; + } else { + LOG(ERROR) << "Win8 registration using " + << register_command.GetCommandLineString() + << " failed with error code " << ret; + } + } else { + LOG(ERROR) << "Win8 registration using " + << register_command.GetCommandLineString() << " timed out."; + } + } + + PLOG(ERROR) << "Failed to launch Win8 registration utility using " + << register_command.GetCommandLineString(); + return false; +} + +} // namespace win8 diff --git a/win8/test/metro_registration_helper.h b/win8/test/metro_registration_helper.h new file mode 100644 index 0000000..86f0015 --- /dev/null +++ b/win8/test/metro_registration_helper.h @@ -0,0 +1,27 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WIN8_TEST_METRO_REGISTRATION_HELPER_H_ +#define WIN8_TEST_METRO_REGISTRATION_HELPER_H_ + +#include "base/string16.h" + +namespace win8 { + +// Registers a viewer process as a potential Win8 default browser. Intended to +// be used by a test binary in the build output directory and assumes the +// presence of test_registrar.exe, a viewer process and all needed DLLs in the +// same directory as the calling module. The viewer process is then subsequently +// set as THE default Win8 browser, is activatable using the AppUserModelId in +// |app_user_model_id| and will show up in the default browser selection dialog +// as |viewer_process_name|. +// +// See also open_with_dialog_controller.h for a mechanism for setting THE +// default Win8 browser. +bool RegisterTestDefaultBrowser(const string16& app_user_model_id, + const string16& viewer_process_name); + +} // namespace win8 + +#endif // WIN8_TEST_METRO_REGISTRATION_HELPER_H_ diff --git a/win8/test/test_registrar.cc b/win8/test/test_registrar.cc new file mode 100644 index 0000000..04c2ec9 --- /dev/null +++ b/win8/test/test_registrar.cc @@ -0,0 +1,141 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Win8 default browser registration utility. +// +// This tool can register and unregister a given exe as a potential default +// metro browser on Win8. It does not make the exe become THE default browser, +// for a mechnism to do this please see open_with_dialog_controller.h. +// +// TODO(robertshield): By default, this creates a run-time dependency on +// chrome.exe since it's the only thing we have right now that works as a +// default viewer process. Investigate extracting the metro init code and +// building them into a standalone viewer process. + +#include <atlbase.h> +#include <atlcom.h> +#include <atlctl.h> +#include <shellapi.h> + +#include "base/at_exit.h" +#include "base/command_line.h" +#include "base/file_path.h" +#include "base/memory/scoped_ptr.h" +#include "base/path_service.h" +#include "base/stringprintf.h" +#include "win8/test/test_registrar_constants.h" +#include "win8/test/test_registrar_resource.h" + +namespace { + +const wchar_t kDelegateExecuteCLSID[] = + L"{FC0064A6-D1DE-4A83-92D2-5BB4EEBB70B5}"; + +void InitializeCommandLineDefaultValues() { + CommandLine& command_line = *CommandLine::ForCurrentProcess(); + + if (!command_line.HasSwitch(win8::test::kTestAppUserModelId)) + command_line.AppendSwitchNative(win8::test::kTestAppUserModelId, + win8::test::kDefaultTestAppUserModelId); + + if (!command_line.HasSwitch(win8::test::kTestExeName)) + command_line.AppendSwitchNative(win8::test::kTestExeName, + win8::test::kDefaultTestExeName); + + if (!command_line.HasSwitch(win8::test::kTestExePath)) { + base::FilePath exe_path; + PathService::Get(base::DIR_EXE, &exe_path); + exe_path = exe_path.Append(win8::test::kDefaultTestExePath); + + command_line.AppendSwitchNative(win8::test::kTestExePath, + exe_path.value()); + } + + if (!command_line.HasSwitch(win8::test::kTestProgId)) + command_line.AppendSwitchNative(win8::test::kTestProgId, + win8::test::kDefaultTestProgId); +} + +} // namespace + +// Implementation of an ATL module that provides the necessary replacement +// values for the default browser .rgs script. +class TestDelegateExecuteModule + : public ATL::CAtlExeModuleT< TestDelegateExecuteModule > { + public : + typedef ATL::CAtlExeModuleT<TestDelegateExecuteModule> ParentClass; + + DECLARE_REGISTRY_RESOURCEID(IDR_TESTDELEGATEEXECUTE); + + HRESULT RegisterServer(BOOL reg_type_lib) { + return ParentClass::RegisterServer(FALSE); + } + + virtual HRESULT AddCommonRGSReplacements(IRegistrarBase* registrar) throw() { + AtlTrace(L"In %hs\n", __FUNCTION__); + HRESULT hr = ParentClass::AddCommonRGSReplacements(registrar); + if (FAILED(hr)) + return hr; + + registrar->AddReplacement(L"DELEGATE_EXECUTE_CLSID", kDelegateExecuteCLSID); + + CommandLine& command_line = *CommandLine::ForCurrentProcess(); + + registrar->AddReplacement(L"APP_USER_MODEL_ID", + command_line.GetSwitchValueNative( + win8::test::kTestAppUserModelId).c_str()); + registrar->AddReplacement(L"EXE_NAME", + command_line.GetSwitchValueNative( + win8::test::kTestExeName).c_str()); + registrar->AddReplacement(L"PROG_ID", + command_line.GetSwitchValueNative( + win8::test::kTestProgId).c_str()); + + string16 exe_path( + command_line.GetSwitchValueNative(win8::test::kTestExePath)); + + string16 exe_open_command(base::StringPrintf(L"\"%ls\" -- %%*", + exe_path.c_str())); + registrar->AddReplacement(L"EXE_OPEN_COMMAND", exe_open_command.c_str()); + + string16 exe_icon(base::StringPrintf(L"%ls,0", exe_path.c_str())); + registrar->AddReplacement(L"EXE_ICON", exe_icon.c_str()); + + string16 prog_id_open_command(base::StringPrintf(L"\"%ls\" -- \"%%1\"", + exe_path.c_str())); + registrar->AddReplacement(L"PROG_ID_OPEN_COMMAND", + prog_id_open_command.c_str()); + + ATLASSERT(SUCCEEDED(hr)); + return hr; + } +}; + +TestDelegateExecuteModule _AtlModule; + +EXTERN_C const GUID CLSID_TestDefaultBrowserRegistrar; +class ATL_NO_VTABLE DECLSPEC_UUID("FC0064A6-D1DE-4A83-92D2-5BB4EEBB70B5") + TestDefaultBrowserRegistrar + : public CComObjectRootEx<CComSingleThreadModel>, + public CComCoClass<TestDefaultBrowserRegistrar, + &CLSID_TestDefaultBrowserRegistrar> { + public: + DECLARE_REGISTRY_RESOURCEID(IDR_TESTDELEGATEEXECUTE); + + BEGIN_COM_MAP(TestDefaultBrowserRegistrar) + END_COM_MAP() +}; + +extern "C" int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int nShowCmd) { + base::AtExitManager exit_manager; + CommandLine::Init(0, NULL); + InitializeCommandLineDefaultValues(); + + HRESULT ret_code = _AtlModule.WinMain(nShowCmd); + + return ret_code; +} + +OBJECT_ENTRY_AUTO(__uuidof(TestDefaultBrowserRegistrar), + TestDefaultBrowserRegistrar); diff --git a/win8/test/test_registrar.rc b/win8/test/test_registrar.rc new file mode 100644 index 0000000..062338c --- /dev/null +++ b/win8/test/test_registrar.rc @@ -0,0 +1,50 @@ +// Resource script for test_registrar.exe. +// +#include "test_registrar_resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" +#include "verrsrc.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "#include ""verrsrc.h""\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// +// +// REGISTRY +// + +IDR_TESTDELEGATEEXECUTE REGISTRY "test_registrar.rgs" + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// diff --git a/win8/test/test_registrar.rgs b/win8/test/test_registrar.rgs new file mode 100644 index 0000000..d638592 --- /dev/null +++ b/win8/test/test_registrar.rgs @@ -0,0 +1,99 @@ +HKCU { + NoRemove Software { + NoRemove Classes { + ForceRemove '%APP_USER_MODEL_ID%' { + ForceRemove .exe { + ForceRemove shell = s 'open' { + ForceRemove open { + command = s '%EXE_OPEN_COMMAND%' { + val DelegateExecute = s '%DELEGATE_EXECUTE_CLSID%' + } + val CommandId = s 'Browser.Launch' + } + ForceRemove opennewwindow = s 'New Window' { + command = s '%EXE_OPEN_COMMAND%' { + val DelegateExecute = s '%DELEGATE_EXECUTE_CLSID%' + } + val CommandId = s 'Browser.Launch' + } + } + } + } + } + } +} + +HKCU { + NoRemove Software { + NoRemove Classes { + ForceRemove '%PROG_ID%' = s 'Test Delegate Execute ProgId' { + val AppUserModelId = s '%APP_USER_MODEL_ID%' + val 'URL Protocol' = s '' + ForceRemove Application { + val ApplicationName = s '%EXE_NAME%' + val ApplicationCompany = s 'Google Inc.' + val ApplicationDescription = s 'Test Description' + val ApplicationIcon = s '%EXE_ICON%' + val AppUserModelId = s '%APP_USER_MODEL_ID%' + } + ForceRemove DefaultIcon = s '%EXE_ICON%' { + } + ForceRemove shell { + ForceRemove open { + ForceRemove command = s '%PROG_ID_OPEN_COMMAND%' { + val DelegateExecute = s '%DELEGATE_EXECUTE_CLSID%' + } + } + } + } + } + } +} + +HKCU { + NoRemove Software { + NoRemove Classes { + NoRemove CLSID { + ForceRemove '%DELEGATE_EXECUTE_CLSID%' = s 'Test CommandExecuteImpl Class' { + ForceRemove Programmable + LocalServer32 = s '%MODULE%' { + val ServerExecutable = s '%MODULE_RAW%' + } + } + } + } + } +} + +HKCU { + NoRemove Software { + NoRemove Clients { + NoRemove StartMenuInternet { + ForceRemove '%APP_USER_MODEL_ID%' = s '%EXE_NAME%' { + ForceRemove Capabilities { + val ApplicationDescription = s 'Test Description' + val ApplicationIcon = s '%EXE_ICON%' + val ApplicationName = s '%EXE_NAME%' + ForceRemove Startmenu { + val StartMenuInternet = s '%APP_USER_MODEL_ID%' + } + ForceRemove URLAssociations { + val http = s '%PROG_ID%' + val https = s '%PROG_ID%' + } + } + } + } + } + } +} + +HKCU { + NoRemove Software { + NoRemove RegisteredApplications { + val '%APP_USER_MODEL_ID%' = s 'Software\Clients\StartMenuInternet\%APP_USER_MODEL_ID%\Capabilities' + } + } +} + + diff --git a/win8/test/test_registrar_constants.cc b/win8/test/test_registrar_constants.cc new file mode 100644 index 0000000..f15cd1c --- /dev/null +++ b/win8/test/test_registrar_constants.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "win8/test/test_registrar_constants.h" + +namespace win8 { +namespace test { + +// The AppUserModelId value to use during default browser registration. +const char kTestAppUserModelId[] = "appid"; + +// Allows the caller to override the visible name given to the exe being +// registered as the default browser. +const char kTestExeName[] = "exe-name"; + +// Specifies the path to the executable being registered as the default +// browser. +const char kTestExePath[] = "exe-path"; + +// The AppUserModelId value to use during default browser registration. +const char kTestProgId[] = "progid"; + +// Default values for the above flags. +const wchar_t kDefaultTestAppUserModelId[] = L"Chrome.test"; +const wchar_t kDefaultTestExeName[] = L"Test Runner"; +const wchar_t kDefaultTestExePath[] = L"chrome.exe"; +const wchar_t kDefaultTestProgId[] = L"ChromeTestProgId"; + +} // namespace test +} // namespace win8 diff --git a/win8/test/test_registrar_constants.h b/win8/test/test_registrar_constants.h new file mode 100644 index 0000000..14afd72 --- /dev/null +++ b/win8/test/test_registrar_constants.h @@ -0,0 +1,24 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WIN8_TEST_TEST_REGISTRAR_CONSTANTS_H__ +#define WIN8_TEST_TEST_REGISTRAR_CONSTANTS_H__ + +namespace win8 { +namespace test { + +extern const char kTestAppUserModelId[]; +extern const char kTestExeName[]; +extern const char kTestExePath[]; +extern const char kTestProgId[]; + +extern const wchar_t kDefaultTestAppUserModelId[]; +extern const wchar_t kDefaultTestExeName[]; +extern const wchar_t kDefaultTestExePath[]; +extern const wchar_t kDefaultTestProgId[]; + +} // namespace test +} // namespace win8 + +#endif // WIN8_TEST_TEST_REGISTRAR_CONSTANTS_H__ diff --git a/win8/test/test_registrar_resource.h b/win8/test/test_registrar_resource.h new file mode 100644 index 0000000..a489c13 --- /dev/null +++ b/win8/test/test_registrar_resource.h @@ -0,0 +1,7 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#define IDR_TESTDELEGATEEXECUTE 101 + + diff --git a/win8/win8.gyp b/win8/win8.gyp index 5790940..0d3bc816 100644 --- a/win8/win8.gyp +++ b/win8/win8.gyp @@ -51,8 +51,11 @@ 'type': 'static_library', 'dependencies': [ '../base/base.gyp:base', + 'test_registrar_constants', ], 'sources': [ + 'test/metro_registration_helper.cc', + 'test/metro_registration_helper.h', 'test/open_with_dialog_async.cc', 'test/open_with_dialog_async.h', 'test/open_with_dialog_controller.cc', @@ -61,5 +64,39 @@ 'test/ui_automation_client.h', ], }, + { + 'target_name': 'test_registrar', + 'type': 'executable', + 'dependencies': [ + '../base/base.gyp:base', + # Chrome is the default viewer process currently used by the tests. + # TODO(robertshield): Investigate building a standalone metro viewer + # process. + '../chrome/chrome.gyp:chrome', + 'test_registrar_constants', + ], + 'sources': [ + 'test/test_registrar.cc', + 'test/test_registrar.rc', + 'test/test_registrar.rgs', + 'test/test_registrar_resource.h', + ], + 'msvs_settings': { + 'VCLinkerTool': { + 'SubSystem': '2', # Set /SUBSYSTEM:WINDOWS + }, + }, + }, + { + 'target_name': 'test_registrar_constants', + 'type': 'static_library', + 'include_dirs': [ + '..', + ], + 'sources': [ + 'test/test_registrar_constants.cc', + 'test/test_registrar_constants.h', + ], + }, ], } |