Chromium Code Reviews| Index: win8/test/metro_registration_helper.cc |
| diff --git a/win8/test/metro_registration_helper.cc b/win8/test/metro_registration_helper.cc |
| index bfcfb29088333f865c46fad144b6448b6a30dbfb..69c7377b571a00b8afbf3c3dcb933118b78624d9 100644 |
| --- a/win8/test/metro_registration_helper.cc |
| +++ b/win8/test/metro_registration_helper.cc |
| @@ -4,6 +4,10 @@ |
| #include "win8/test/metro_registration_helper.h" |
| +#include <shlobj.h> |
| + |
| +#include <vector> |
| + |
| #include "base/command_line.h" |
| #include "base/file_util.h" |
| #include "base/files/file_path.h" |
| @@ -11,7 +15,12 @@ |
| #include "base/path_service.h" |
| #include "base/process.h" |
| #include "base/process_util.h" |
| +#include "base/string16.h" |
| +#include "base/win/scoped_co_mem.h" |
| +#include "base/win/scoped_comptr.h" |
| #include "base/win/scoped_handle.h" |
| +#include "ui/base/win/atl_module.h" |
| +#include "win8/test/open_with_dialog_controller.h" |
| #include "win8/test/test_registrar_constants.h" |
| namespace { |
| @@ -22,12 +31,12 @@ const int kRegistrationTimeoutSeconds = 30; |
| 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) { |
| +// Registers chrome.exe as a potential Win8 default browser. It will then show |
| +// up in the default browser selection dialog as |viewer_process_name|. Intended |
|
grt (UTC plus 2)
2013/05/27 16:11:14
please update comment (there is no |viewer_process
gab
2013/05/27 16:47:58
Done.
|
| +// 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 |
|
grt (UTC plus 2)
2013/05/27 16:11:14
nit: comma before " and"
gab
2013/05/27 16:47:58
Done.
|
| +// same directory as the calling module. |
| +bool RegisterTestDefaultBrowser() { |
| base::FilePath dir; |
| if (!PathService::Get(base::DIR_EXE, &dir)) |
| return false; |
| @@ -40,15 +49,9 @@ bool RegisterTestDefaultBrowser(const string16& app_user_model_id, |
| return false; |
| } |
| - // Perform the registration by invoking test_registrar.exe with the |
| - // necessary flags: |
| - // test_registrar.exe /RegServer --appid=<appid> --exe-name=<name> |
| + // Perform the registration by invoking test_registrar.exe. |
| CommandLine register_command(registrar); |
| register_command.AppendArg("/RegServer"); |
| - register_command.AppendSwitchNative(win8::test::kTestAppUserModelId, |
|
gab
2013/05/27 15:55:11
test_registrar already uses these as default value
grt (UTC plus 2)
2013/05/27 16:11:14
Thanks for clarifying. I was just about to ask tha
|
| - 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(), |
| @@ -75,4 +78,58 @@ bool RegisterTestDefaultBrowser(const string16& app_user_model_id, |
| return false; |
| } |
| +// Returns true if the test viewer's progid is the default handler for |
| +// |protocol|. |
| +bool IsTestDefaultForProtocol(const wchar_t protocol[]) { |
|
grt (UTC plus 2)
2013/05/27 16:11:14
const wchar_t* protocol
gab
2013/05/27 16:47:58
Done.
|
| + base::win::ScopedComPtr<IApplicationAssociationRegistration> registration; |
| + HRESULT hr = registration.CreateInstance( |
| + CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC); |
| + if (FAILED(hr)) { |
| + LOG(ERROR) << std::hex << hr; |
| + return false; |
| + } |
| + |
| + base::win::ScopedCoMem<wchar_t> current_app; |
| + hr = registration->QueryCurrentDefault(protocol, AT_URLPROTOCOL, |
| + AL_EFFECTIVE, ¤t_app); |
| + if (FAILED(hr)) { |
| + LOG(ERROR) << std::hex << hr; |
| + return false; |
| + } |
| + |
| + return string16(win8::test::kDefaultTestProgId).compare(current_app) == 0; |
| +} |
| + |
| +} // namespace |
| + |
| +namespace win8 { |
| + |
| +bool MakeTestDefaultBrowserSynchronously() { |
| + static const wchar_t kDefaultBrowserProtocol[] = L"http"; |
| + |
| + if (!RegisterTestDefaultBrowser()) { |
|
grt (UTC plus 2)
2013/05/27 16:11:14
nit: no braces
gab
2013/05/27 16:47:58
Done.
|
| + return false; |
| + } |
| + |
| + // Make sure the registration changes have been acknowledged by the shell |
| + // before querying for the current default. |
| + SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSH, NULL, NULL); |
| + |
| + // OpenWithDialogController will fail if the Test Runner is already default |
| + // since it will not show up verbatim in the dialog (e.g., in EN-US, it will |
| + // be prefixed by "Keep using"). |
|
grt (UTC plus 2)
2013/05/27 16:11:14
space after "using"? :-)
gab
2013/05/27 16:47:58
Done.
|
| + if (IsTestDefaultForProtocol(kDefaultBrowserProtocol)) |
| + return true; |
| + |
| + ui::win::CreateATLModuleIfNeeded(); |
|
grt (UTC plus 2)
2013/05/27 16:11:14
i don't this this should be done within a helper f
gab
2013/05/27 16:47:58
Ok, I'll take your word for it :)!
|
| + |
| + std::vector<base::string16> choices; |
| + OpenWithDialogController controller; |
| + HRESULT hr = controller.RunSynchronously( |
| + NULL, kDefaultBrowserProtocol, win8::test::kDefaultTestExeName, &choices); |
| + LOG_IF(ERROR, FAILED(hr)) << std::hex << hr; |
| + DCHECK(IsTestDefaultForProtocol(kDefaultBrowserProtocol)); |
| + return SUCCEEDED(hr); |
| +} |
| + |
| } // namespace win8 |