OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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. | |
4 | |
5 #include "metro_driver_win.h" | |
6 | |
7 namespace { | |
8 // The windows 8 metro driver dll name and entry point. | |
9 const char kMetroDriverDll[] = "metro_driver.dll"; | |
10 // This environment variable controls the loading of the metro driver DLL. | |
11 const char* kMetroModeEnvVar = "CHROME_METRO_DLL"; | |
12 | |
13 typedef int (*InitMetro)(LPTHREAD_START_ROUTINE thread_proc, void* context); | |
14 | |
15 struct Context { | |
16 MetroDriver::MainFn fn; | |
17 HINSTANCE instance; | |
18 }; | |
19 | |
20 DWORD WINAPI MainThread(void* param) { | |
21 Context* context = reinterpret_cast<Context*>(param); | |
22 int rv = context->fn(context->instance); | |
23 delete context; | |
24 return rv; | |
25 } | |
26 | |
27 } // namespace | |
28 | |
29 MetroDriver::MetroDriver() : init_metro_fn_(NULL) { | |
30 if (0 != ::GetEnvironmentVariableA(kMetroModeEnvVar, NULL, 0)) | |
31 return; | |
32 // We haven't tried to load the metro driver, this probably means we are the | |
33 // browser. Find it or not we set the environment variable because we don't | |
34 // want to keep trying in the child processes. | |
35 HMODULE metro_dll = ::LoadLibraryA(kMetroDriverDll); | |
36 ::SetEnvironmentVariableA(kMetroModeEnvVar, metro_dll ? "1" : "0"); | |
37 if (!metro_dll) | |
38 return; | |
39 init_metro_fn_ = | |
40 ::GetProcAddress(::GetModuleHandleA(kMetroDriverDll), "InitMetro"); | |
41 } | |
42 | |
43 int MetroDriver::RunInMetro(HINSTANCE instance, MainFn main_fn) { | |
44 Context* context = new Context; | |
45 context->fn = main_fn; | |
46 context->instance = instance; | |
47 | |
48 return reinterpret_cast<InitMetro>(init_metro_fn_)(&MainThread, context); | |
49 } | |
OLD | NEW |