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 "content/public/app/content_main_runner.h" | 5 #include "content/public/app/content_main_runner.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/debug/debugger.h" | 12 #include "base/debug/debugger.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/i18n/icu_util.h" | 15 #include "base/i18n/icu_util.h" |
16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/metrics/stats_table.h" | 19 #include "base/metrics/stats_table.h" |
20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
21 #include "base/process_util.h" | 21 #include "base/process_util.h" |
22 #include "base/profiler/alternate_timer.h" | 22 #include "base/profiler/alternate_timer.h" |
| 23 #include "base/string_util.h" |
23 #include "base/stringprintf.h" | 24 #include "base/stringprintf.h" |
24 #include "base/string_number_conversions.h" | 25 #include "base/string_number_conversions.h" |
25 #include "content/browser/browser_main.h" | 26 #include "content/browser/browser_main.h" |
26 #include "content/common/set_process_title.h" | 27 #include "content/common/set_process_title.h" |
27 #include "content/common/url_schemes.h" | 28 #include "content/common/url_schemes.h" |
28 #include "content/public/app/content_main_delegate.h" | 29 #include "content/public/app/content_main_delegate.h" |
29 #include "content/public/app/startup_helper_win.h" | 30 #include "content/public/app/startup_helper_win.h" |
30 #include "content/public/browser/content_browser_client.h" | 31 #include "content/public/browser/content_browser_client.h" |
31 #include "content/public/common/content_client.h" | 32 #include "content/public/common/content_client.h" |
32 #include "content/public/common/content_constants.h" | 33 #include "content/public/common/content_constants.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 extern int RendererMain(const content::MainFunctionParams&); | 89 extern int RendererMain(const content::MainFunctionParams&); |
89 extern int WorkerMain(const content::MainFunctionParams&); | 90 extern int WorkerMain(const content::MainFunctionParams&); |
90 extern int UtilityMain(const content::MainFunctionParams&); | 91 extern int UtilityMain(const content::MainFunctionParams&); |
91 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 92 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
92 namespace content { | 93 namespace content { |
93 extern int ZygoteMain(const MainFunctionParams&, | 94 extern int ZygoteMain(const MainFunctionParams&, |
94 ZygoteForkDelegate* forkdelegate); | 95 ZygoteForkDelegate* forkdelegate); |
95 } // namespace content | 96 } // namespace content |
96 #endif | 97 #endif |
97 | 98 |
| 99 namespace { |
| 100 #if defined(OS_WIN) |
| 101 // In order to have Theme support, we need to connect to the theme service. |
| 102 // This needs to be done before we lock down the process. Officially this |
| 103 // can be done with OpenThemeData() but it fails unless you pass a valid |
| 104 // window at least the first time. Interestingly, the very act of creating a |
| 105 // window also sets the connection to the theme service. |
| 106 void EnableThemeSupportOnAllWindowStations() { |
| 107 HDESK desktop_handle = ::OpenInputDesktop(0, FALSE, READ_CONTROL); |
| 108 if (desktop_handle) { |
| 109 // This means we are running in an input desktop, which implies WinSta0. |
| 110 ::CloseDesktop(desktop_handle); |
| 111 return; |
| 112 } |
| 113 |
| 114 HWINSTA current_station = ::GetProcessWindowStation(); |
| 115 DCHECK(current_station); |
| 116 |
| 117 HWINSTA winsta0 = ::OpenWindowStationA("WinSta0", FALSE, GENERIC_READ); |
| 118 if (!winsta0 || !::SetProcessWindowStation(winsta0)) { |
| 119 // Could not set the alternate window station. There is a possibility |
| 120 // that the theme wont be correctly initialized. |
| 121 NOTREACHED() << "Unable to switch to WinSta0, we: "<< ::GetLastError(); |
| 122 } |
| 123 |
| 124 HWND window = ::CreateWindowExW(0, L"Static", L"", WS_POPUP | WS_DISABLED, |
| 125 CW_USEDEFAULT, 0, 0, 0, HWND_MESSAGE, NULL, |
| 126 ::GetModuleHandleA(NULL), NULL); |
| 127 if (!window) { |
| 128 DLOG(WARNING) << "failed to enable theme support"; |
| 129 } else { |
| 130 ::DestroyWindow(window); |
| 131 window = NULL; |
| 132 } |
| 133 |
| 134 // Revert the window station. |
| 135 if (!::SetProcessWindowStation(current_station)) { |
| 136 // We failed to switch back to the secure window station. This might |
| 137 // confuse the process enough that we should kill it now. |
| 138 LOG(FATAL) << "Failed to restore alternate window station"; |
| 139 } |
| 140 |
| 141 if (!::CloseWindowStation(winsta0)) { |
| 142 // We might be leaking a winsta0 handle. This is a security risk, but |
| 143 // since we allow fail over to no desktop protection in low memory |
| 144 // condition, this is not a big risk. |
| 145 NOTREACHED(); |
| 146 } |
| 147 } |
| 148 #endif // defined(OS_WIN) |
| 149 } // namespace |
| 150 |
98 namespace content { | 151 namespace content { |
99 | 152 |
100 base::LazyInstance<ContentBrowserClient> | 153 base::LazyInstance<ContentBrowserClient> |
101 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; | 154 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; |
102 base::LazyInstance<ContentPluginClient> | 155 base::LazyInstance<ContentPluginClient> |
103 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER; | 156 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER; |
104 base::LazyInstance<ContentRendererClient> | 157 base::LazyInstance<ContentRendererClient> |
105 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; | 158 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; |
106 base::LazyInstance<ContentUtilityClient> | 159 base::LazyInstance<ContentUtilityClient> |
107 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; | 160 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 (delegate && | 609 (delegate && |
557 delegate->ProcessRegistersWithSystemProcess(process_type))) { | 610 delegate->ProcessRegistersWithSystemProcess(process_type))) { |
558 base::SystemMonitor::AllocateSystemIOPorts(); | 611 base::SystemMonitor::AllocateSystemIOPorts(); |
559 } | 612 } |
560 | 613 |
561 if (!process_type.empty() && | 614 if (!process_type.empty() && |
562 (!delegate || delegate->ShouldSendMachPort(process_type))) { | 615 (!delegate || delegate->ShouldSendMachPort(process_type))) { |
563 SendTaskPortToParentProcess(); | 616 SendTaskPortToParentProcess(); |
564 } | 617 } |
565 #elif defined(OS_WIN) | 618 #elif defined(OS_WIN) |
| 619 // This must be done early enough since some helper functions like |
| 620 // IsTouchEnanbled, needed to load resources, may call into the theme dll. |
| 621 EnableThemeSupportOnAllWindowStations(); |
566 #if defined(ENABLE_HIDPI) | 622 #if defined(ENABLE_HIDPI) |
567 ui::EnableHighDPISupport(); | 623 ui::EnableHighDPISupport(); |
568 #endif | 624 #endif |
569 SetupCRT(command_line); | 625 SetupCRT(command_line); |
570 #endif | 626 #endif |
571 | 627 |
572 #if defined(OS_POSIX) | 628 #if defined(OS_POSIX) |
573 if (!process_type.empty()) { | 629 if (!process_type.empty()) { |
574 // When you hit Ctrl-C in a terminal running the browser | 630 // When you hit Ctrl-C in a terminal running the browser |
575 // process, a SIGINT is delivered to the entire process group. | 631 // process, a SIGINT is delivered to the entire process group. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 | 765 |
710 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 766 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
711 }; | 767 }; |
712 | 768 |
713 // static | 769 // static |
714 ContentMainRunner* ContentMainRunner::Create() { | 770 ContentMainRunner* ContentMainRunner::Create() { |
715 return new ContentMainRunnerImpl(); | 771 return new ContentMainRunnerImpl(); |
716 } | 772 } |
717 | 773 |
718 } // namespace content | 774 } // namespace content |
OLD | NEW |