OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "content/app/content_main.h" | 5 #include "content/app/content_main.h" |
6 | 6 |
| 7 #include "content/shell/shell.h" |
7 #include "content/shell/shell_main_delegate.h" | 8 #include "content/shell/shell_main_delegate.h" |
8 #include "sandbox/src/sandbox_types.h" | 9 #include "sandbox/src/sandbox_types.h" |
9 | 10 |
10 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
11 #include "content/public/app/startup_helper_win.h" | 12 #include "content/public/app/startup_helper_win.h" |
12 #endif | 13 #endif |
13 | 14 |
| 15 #if defined(TEST_EMBEDDED_MESSAGE_LOOP) |
| 16 #include "content/app/content_main_runner.h" |
| 17 #endif |
| 18 |
14 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
15 | 20 |
16 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { | 21 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { |
17 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 22 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
18 content::InitializeSandboxInfo(&sandbox_info); | 23 content::InitializeSandboxInfo(&sandbox_info); |
| 24 |
| 25 // The main delegate object that will outlive the content runner. |
19 ShellMainDelegate delegate; | 26 ShellMainDelegate delegate; |
| 27 |
| 28 #if defined(TEST_EMBEDDED_MESSAGE_LOOP) |
| 29 // Retrieve the requested process type. |
| 30 std::string process_type = content::GetProcessType(0, NULL); |
| 31 if (!process_type.empty()) { |
| 32 // For non-browser processes use the default implementation. |
| 33 return content::ContentMain(instance, &sandbox_info, &delegate); |
| 34 } |
| 35 |
| 36 // Use our own content runner for the browser process. |
| 37 scoped_ptr<content::ContentMainRunner> content_runner( |
| 38 content::ContentMainRunner::CreateMainRunner()); |
| 39 |
| 40 // Initialize the content runner. |
| 41 int exit_code = content_runner->Initialize(instance, &sandbox_info, |
| 42 &delegate); |
| 43 if (exit_code >= 0) |
| 44 return exit_code; |
| 45 |
| 46 // Run the process. Results in a call to ShellMainDelegate::RunKnownProcess() |
| 47 // which will create the browser runner and message loop without blocking. |
| 48 exit_code = content_runner->Run(); |
| 49 |
| 50 MSG msg; |
| 51 |
| 52 // Run the application message loop. |
| 53 while (GetMessage(&msg, NULL, 0, 0)) { |
| 54 TranslateMessage(&msg); |
| 55 DispatchMessage(&msg); |
| 56 |
| 57 // Perform a single iteration of browser message loop work. |
| 58 delegate.DoBrowserMessageLoopWork(); |
| 59 } |
| 60 |
| 61 // Shut down the browser runner. |
| 62 delegate.ShutdownBrowser(); |
| 63 |
| 64 // Shut down the content runner. |
| 65 content_runner->Shutdown(); |
| 66 |
| 67 return exit_code; |
| 68 #else // !TEST_EMBEDDED_MESSAGE_LOOP |
20 return content::ContentMain(instance, &sandbox_info, &delegate); | 69 return content::ContentMain(instance, &sandbox_info, &delegate); |
| 70 #endif // !TEST_EMBEDDED_MESSAGE_LOOP |
21 } | 71 } |
| 72 |
22 #endif | 73 #endif |
23 | 74 |
24 #if defined(OS_POSIX) | 75 #if defined(OS_POSIX) |
25 | 76 |
26 #if defined(OS_MACOSX) | 77 #if defined(OS_MACOSX) |
27 __attribute__((visibility("default"))) | 78 __attribute__((visibility("default"))) |
28 int main(int argc, const char* argv[]) { | 79 int main(int argc, const char* argv[]) { |
29 #else | 80 #else |
30 int main(int argc, const char** argv) { | 81 int main(int argc, const char** argv) { |
31 #endif // OS_MACOSX | 82 #endif // OS_MACOSX |
32 | 83 |
33 ShellMainDelegate delegate; | 84 ShellMainDelegate delegate; |
34 return content::ContentMain(argc, argv, &delegate); | 85 return content::ContentMain(argc, argv, &delegate); |
35 } | 86 } |
36 | 87 |
37 #endif // OS_POSIX | 88 #endif // OS_POSIX |
OLD | NEW |