summaryrefslogtreecommitdiffstats
path: root/win8/test/test_registrar.cc
diff options
context:
space:
mode:
authorrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-13 18:25:43 +0000
committerrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-13 18:25:43 +0000
commit41168e2ab2cb1fd350ed79419676c9dfcf9c1c16 (patch)
tree02023bea1046efc779aa01f3b3055fdd8e8071fb /win8/test/test_registrar.cc
parentf94d6c664b5db155b7e0656c2739334b326cb425 (diff)
downloadchromium_src-41168e2ab2cb1fd350ed79419676c9dfcf9c1c16.zip
chromium_src-41168e2ab2cb1fd350ed79419676c9dfcf9c1c16.tar.gz
chromium_src-41168e2ab2cb1fd350ed79419676c9dfcf9c1c16.tar.bz2
Automatic Win8 default browser registration for the ash unittests.
Win8 default browser registration code is extracted into a fairly minimal .rgs script with a helper app that is then invoked by the ash unittests. A full ICommandExecuteImpl implementation turns out to not be needed as the ash tests activate the registered default browser directly by AppUserModelId which avoids the need for ICommandExecuteImpl and the other stuff in the production delegate_execute.exe. BUG=154081 TEST=ash_unittests, eventually. Review URL: https://chromiumcodereview.appspot.com/12096064 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182258 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'win8/test/test_registrar.cc')
-rw-r--r--win8/test/test_registrar.cc141
1 files changed, 141 insertions, 0 deletions
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);