OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Makes a given program ("Google Chrome" by default) the default handler for | 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 | 6 // some URL protocol ("http" by default) on Windows 8. These defaults can be |
7 // overridden via the --program and --protocol command line switches. | 7 // overridden via the --program and --protocol command line switches. |
8 | 8 |
9 #include <windows.h> | 9 #include <windows.h> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 const char kSwitchProgram[] = "program"; | 21 const char kSwitchProgram[] = "program"; |
22 const char kSwitchProtocol[] = "protocol"; | 22 const char kSwitchProtocol[] = "protocol"; |
23 const wchar_t kDefaultProgram[] = L"Google Chrome"; | 23 const wchar_t kDefaultProgram[] = L"Google Chrome"; |
24 const wchar_t kDefaultProtocol[] = L"http"; | 24 const wchar_t kDefaultProtocol[] = L"http"; |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 extern "C" | 28 extern "C" |
29 int wmain(int argc, wchar_t* argv[]) { | 29 int wmain(int argc, wchar_t* argv[]) { |
30 // Initialize the commandline singleton from the environment. | 30 // Initialize the commandline singleton from the environment. |
31 CommandLine::Init(0, NULL); | 31 base::CommandLine::Init(0, NULL); |
32 // The exit manager is in charge of calling the dtors of singletons. | 32 // The exit manager is in charge of calling the dtors of singletons. |
33 base::AtExitManager exit_manager; | 33 base::AtExitManager exit_manager; |
34 logging::LoggingSettings settings; | 34 logging::LoggingSettings settings; |
35 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 35 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
36 logging::InitLogging(settings); | 36 logging::InitLogging(settings); |
37 logging::SetMinLogLevel(logging::LOG_VERBOSE); | 37 logging::SetMinLogLevel(logging::LOG_VERBOSE); |
38 | 38 |
39 ui::win::CreateATLModuleIfNeeded(); | 39 ui::win::CreateATLModuleIfNeeded(); |
40 | 40 |
41 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 41 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
42 base::string16 protocol(command_line->GetSwitchValueNative(kSwitchProtocol)); | 42 base::string16 protocol(command_line->GetSwitchValueNative(kSwitchProtocol)); |
43 if (protocol.empty()) | 43 if (protocol.empty()) |
44 protocol = kDefaultProtocol; | 44 protocol = kDefaultProtocol; |
45 | 45 |
46 base::string16 program(command_line->GetSwitchValueNative(kSwitchProgram)); | 46 base::string16 program(command_line->GetSwitchValueNative(kSwitchProgram)); |
47 if (program.empty()) | 47 if (program.empty()) |
48 program = kDefaultProgram; | 48 program = kDefaultProgram; |
49 | 49 |
50 std::vector<base::string16> choices; | 50 std::vector<base::string16> choices; |
51 HRESULT result = S_OK; | 51 HRESULT result = S_OK; |
52 win8::OpenWithDialogController controller; | 52 win8::OpenWithDialogController controller; |
53 result = controller.RunSynchronously(NULL, protocol, program, &choices); | 53 result = controller.RunSynchronously(NULL, protocol, program, &choices); |
54 | 54 |
55 if (SUCCEEDED(result)) { | 55 if (SUCCEEDED(result)) { |
56 printf("success\n"); | 56 printf("success\n"); |
57 } else if (!choices.empty()) { | 57 } else if (!choices.empty()) { |
58 printf("failed to set program. possible choices: %ls\n", | 58 printf("failed to set program. possible choices: %ls\n", |
59 JoinString(choices, L", ").c_str()); | 59 JoinString(choices, L", ").c_str()); |
60 } else { | 60 } else { |
61 printf("failed with HRESULT: %0x08X\n", result); | 61 printf("failed with HRESULT: %0x08X\n", result); |
62 } | 62 } |
63 | 63 |
64 return FAILED(result); | 64 return FAILED(result); |
65 } | 65 } |
OLD | NEW |