OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "stdafx.h" | 5 #include "stdafx.h" |
6 #include "win8/metro_driver/metro_driver.h" | 6 #include "win8/metro_driver/metro_driver.h" |
7 | 7 |
8 #include <roerrorapi.h> | 8 #include <roerrorapi.h> |
9 #include <shobjidl.h> | 9 #include <shobjidl.h> |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/logging_win.h" | 14 #include "base/logging_win.h" |
15 #include "base/win/scoped_comptr.h" | 15 #include "base/win/scoped_comptr.h" |
| 16 #include "base/win/windows_version.h" |
16 #include "win8/metro_driver/winrt_utils.h" | 17 #include "win8/metro_driver/winrt_utils.h" |
17 | 18 |
18 // TODO(siggi): Move this to GYP. | |
19 #pragma comment(lib, "runtimeobject.lib") | |
20 | |
21 namespace { | 19 namespace { |
22 | 20 |
23 LONG WINAPI ErrorReportingHandler(EXCEPTION_POINTERS* ex_info) { | 21 LONG WINAPI ErrorReportingHandler(EXCEPTION_POINTERS* ex_info) { |
24 // See roerrorapi.h for a description of the | 22 // See roerrorapi.h for a description of the |
25 // exception codes and parameters. | 23 // exception codes and parameters. |
26 DWORD code = ex_info->ExceptionRecord->ExceptionCode; | 24 DWORD code = ex_info->ExceptionRecord->ExceptionCode; |
27 ULONG_PTR* info = ex_info->ExceptionRecord->ExceptionInformation; | 25 ULONG_PTR* info = ex_info->ExceptionRecord->ExceptionInformation; |
28 if (code == EXCEPTION_RO_ORIGINATEERROR) { | 26 if (code == EXCEPTION_RO_ORIGINATEERROR) { |
29 base::string16 msg(reinterpret_cast<wchar_t*>(info[2]), info[1]); | 27 base::string16 msg(reinterpret_cast<wchar_t*>(info[2]), info[1]); |
30 LOG(ERROR) << "VEH: Metro error 0x" << std::hex << info[0] << ": " << msg; | 28 LOG(ERROR) << "VEH: Metro error 0x" << std::hex << info[0] << ": " << msg; |
31 } else if (code == EXCEPTION_RO_TRANSFORMERROR) { | 29 } else if (code == EXCEPTION_RO_TRANSFORMERROR) { |
32 base::string16 msg(reinterpret_cast<wchar_t*>(info[3]), info[2]); | 30 base::string16 msg(reinterpret_cast<wchar_t*>(info[3]), info[2]); |
33 LOG(ERROR) << "VEH: Metro old error 0x" << std::hex << info[0] | 31 LOG(ERROR) << "VEH: Metro old error 0x" << std::hex << info[0] |
34 << " new error 0x" << info[1] << ": " << msg; | 32 << " new error 0x" << info[1] << ": " << msg; |
35 } | 33 } |
36 | 34 |
37 return EXCEPTION_CONTINUE_SEARCH; | 35 return EXCEPTION_CONTINUE_SEARCH; |
38 } | 36 } |
39 | 37 |
| 38 void SetMetroReportingFlags() { |
| 39 #if !defined(NDEBUG) |
| 40 // Set the error reporting flags to always raise an exception, |
| 41 // which is then processed by our vectored exception handling |
| 42 // above to log the error message. |
| 43 winfoundtn::Diagnostics::SetErrorReportingFlags( |
| 44 winfoundtn::Diagnostics::UseSetErrorInfo | |
| 45 winfoundtn::Diagnostics::ForceExceptions); |
| 46 #endif |
| 47 } |
| 48 |
40 // TODO(robertshield): This GUID is hard-coded in a bunch of places that | 49 // TODO(robertshield): This GUID is hard-coded in a bunch of places that |
41 // don't allow explicit includes. Find a single place for it to live. | 50 // don't allow explicit includes. Find a single place for it to live. |
42 // {7FE69228-633E-4f06-80C1-527FEA23E3A7} | 51 // {7FE69228-633E-4f06-80C1-527FEA23E3A7} |
43 const GUID kChromeTraceProviderName = { | 52 const GUID kChromeTraceProviderName = { |
44 0x7fe69228, 0x633e, 0x4f06, | 53 0x7fe69228, 0x633e, 0x4f06, |
45 { 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } }; | 54 { 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } }; |
46 | 55 |
47 } | 56 } // namespace |
48 | 57 |
49 #if !defined(COMPONENT_BUILD) | 58 #if !defined(COMPONENT_BUILD) |
50 // Required for base initialization. | 59 // Required for base initialization. |
51 // TODO(siggi): This should be handled better, as this way our at exit | 60 // TODO(siggi): This should be handled better, as this way our at exit |
52 // registrations will run under the loader's lock. However, | 61 // registrations will run under the loader's lock. However, |
53 // once metro_driver is merged into Chrome.dll, this will go away anyhow. | 62 // once metro_driver is merged into Chrome.dll, this will go away anyhow. |
54 base::AtExitManager at_exit; | 63 base::AtExitManager at_exit; |
55 #endif | 64 #endif |
56 | 65 |
| 66 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows8() { |
| 67 SetMetroReportingFlags(); |
| 68 HRESULT hr = ::Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); |
| 69 if (FAILED(hr)) |
| 70 CHECK(false); |
| 71 mswr::ComPtr<winapp::Core::ICoreApplication> core_app; |
| 72 hr = winrt_utils::CreateActivationFactory( |
| 73 RuntimeClass_Windows_ApplicationModel_Core_CoreApplication, |
| 74 core_app.GetAddressOf()); |
| 75 if (FAILED(hr)) |
| 76 CHECK(false); |
| 77 return core_app; |
| 78 } |
| 79 |
| 80 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7(); |
| 81 |
57 extern "C" __declspec(dllexport) | 82 extern "C" __declspec(dllexport) |
58 int InitMetro() { | 83 int InitMetro() { |
| 84 // Metro mode or its emulation is not supported in Vista or XP. |
| 85 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 86 return 1; |
59 // Initialize the command line. | 87 // Initialize the command line. |
60 CommandLine::Init(0, NULL); | 88 CommandLine::Init(0, NULL); |
| 89 // Initialize the logging system. |
61 logging::LoggingSettings settings; | 90 logging::LoggingSettings settings; |
62 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 91 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
63 logging::InitLogging(settings); | 92 logging::InitLogging(settings); |
64 | |
65 #if defined(NDEBUG) | 93 #if defined(NDEBUG) |
66 logging::SetMinLogLevel(logging::LOG_ERROR); | 94 logging::SetMinLogLevel(logging::LOG_ERROR); |
67 #else | 95 #else |
68 logging::SetMinLogLevel(logging::LOG_VERBOSE); | 96 logging::SetMinLogLevel(logging::LOG_VERBOSE); |
69 // Set the error reporting flags to always raise an exception, | 97 HANDLE registration = |
70 // which is then processed by our vectored exception handling | |
71 // above to log the error message. | |
72 winfoundtn::Diagnostics::SetErrorReportingFlags( | |
73 winfoundtn::Diagnostics::UseSetErrorInfo | | |
74 winfoundtn::Diagnostics::ForceExceptions); | |
75 | |
76 HANDLE registration = | |
77 ::AddVectoredExceptionHandler(TRUE, ErrorReportingHandler); | 98 ::AddVectoredExceptionHandler(TRUE, ErrorReportingHandler); |
78 #endif | 99 #endif |
79 | |
80 // Enable trace control and transport through event tracing for Windows. | 100 // Enable trace control and transport through event tracing for Windows. |
81 logging::LogEventProvider::Initialize(kChromeTraceProviderName); | 101 logging::LogEventProvider::Initialize(kChromeTraceProviderName); |
82 | |
83 DVLOG(1) << "InitMetro"; | 102 DVLOG(1) << "InitMetro"; |
84 | 103 |
85 mswrw::RoInitializeWrapper ro_initializer(RO_INIT_MULTITHREADED); | 104 // OS specific initialization. |
86 CheckHR(ro_initializer, "RoInitialize failed"); | |
87 | |
88 mswr::ComPtr<winapp::Core::ICoreApplication> core_app; | 105 mswr::ComPtr<winapp::Core::ICoreApplication> core_app; |
89 HRESULT hr = winrt_utils::CreateActivationFactory( | 106 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
90 RuntimeClass_Windows_ApplicationModel_Core_CoreApplication, | 107 core_app = InitWindows7(); |
91 core_app.GetAddressOf()); | 108 else |
92 CheckHR(hr, "Failed to create app factory"); | 109 core_app = InitWindows8(); |
93 if (FAILED(hr)) | |
94 return 1; | |
95 | 110 |
96 auto view_factory = mswr::Make<ChromeAppViewFactory>(core_app.Get()); | 111 auto view_factory = mswr::Make<ChromeAppViewFactory>(core_app.Get()); |
97 hr = core_app->Run(view_factory.Get()); | 112 HRESULT hr = core_app->Run(view_factory.Get()); |
98 DVLOG(1) << "exiting InitMetro, hr=" << hr; | 113 DVLOG(1) << "exiting InitMetro, hr=" << hr; |
99 | 114 |
100 #if !defined(NDEBUG) | 115 #if !defined(NDEBUG) |
101 ::RemoveVectoredExceptionHandler(registration); | 116 ::RemoveVectoredExceptionHandler(registration); |
102 #endif | 117 #endif |
103 | |
104 return hr; | 118 return hr; |
105 } | 119 } |
106 | 120 |
107 // Activates the application known by |app_id|. Returns, among other things, | 121 // Activates the application known by |app_id|. Returns, among other things, |
108 // E_APPLICATION_NOT_REGISTERED if |app_id| identifies Chrome and Chrome is not | 122 // E_APPLICATION_NOT_REGISTERED if |app_id| identifies Chrome and Chrome is not |
109 // the default browser. | 123 // the default browser. |
110 extern "C" __declspec(dllexport) | 124 extern "C" __declspec(dllexport) |
111 HRESULT ActivateApplication(const wchar_t* app_id) { | 125 HRESULT ActivateApplication(const wchar_t* app_id) { |
112 base::win::ScopedComPtr<IApplicationActivationManager> activator; | 126 base::win::ScopedComPtr<IApplicationActivationManager> activator; |
113 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); | 127 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); |
114 if (SUCCEEDED(hr)) { | 128 if (SUCCEEDED(hr)) { |
115 DWORD pid = 0; | 129 DWORD pid = 0; |
116 hr = activator->ActivateApplication(app_id, L"", AO_NONE, &pid); | 130 hr = activator->ActivateApplication(app_id, L"", AO_NONE, &pid); |
117 } | 131 } |
118 return hr; | 132 return hr; |
119 } | 133 } |
OLD | NEW |