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.
5 // Makes a given program ("Google Chrome" by default) the default handler for
6 // some URL protocol ("http" by default) on Windows 8. These defaults can be
7 // overridden via the --program and --protocol command line switches.
11 #include "base/at_exit.h"
12 #include "base/command_line.h"
13 #include "base/logging.h"
14 #include "base/strings/string16.h"
15 #include "base/strings/string_util.h"
16 #include "ui/base/win/atl_module.h"
17 #include "win8/test/open_with_dialog_controller.h"
21 const char kSwitchProgram
[] = "program";
22 const char kSwitchProtocol
[] = "protocol";
23 const wchar_t kDefaultProgram
[] = L
"Google Chrome";
24 const wchar_t kDefaultProtocol
[] = L
"http";
29 int wmain(int argc
, wchar_t* argv
[]) {
30 // Initialize the commandline singleton from the environment.
31 base::CommandLine::Init(0, NULL
);
32 // The exit manager is in charge of calling the dtors of singletons.
33 base::AtExitManager exit_manager
;
34 logging::LoggingSettings settings
;
35 settings
.logging_dest
= logging::LOG_TO_SYSTEM_DEBUG_LOG
;
36 logging::InitLogging(settings
);
37 logging::SetMinLogLevel(logging::LOG_VERBOSE
);
39 ui::win::CreateATLModuleIfNeeded();
41 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
42 base::string16
protocol(command_line
->GetSwitchValueNative(kSwitchProtocol
));
44 protocol
= kDefaultProtocol
;
46 base::string16
program(command_line
->GetSwitchValueNative(kSwitchProgram
));
48 program
= kDefaultProgram
;
50 std::vector
<base::string16
> choices
;
51 HRESULT result
= S_OK
;
52 win8::OpenWithDialogController controller
;
53 result
= controller
.RunSynchronously(NULL
, protocol
, program
, &choices
);
55 if (SUCCEEDED(result
)) {
57 } else if (!choices
.empty()) {
58 printf("failed to set program. possible choices: %ls\n",
59 JoinString(choices
, L
", ").c_str());
61 printf("failed with HRESULT: %0x08X\n", result
);
64 return FAILED(result
);