Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: content/app/content_main_runner.cc

Issue 10914119: Prime the Windows theme DLL earlier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/renderer/renderer_main_platform_delegate_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
48 49
49 #if defined(USE_TCMALLOC) 50 #if defined(USE_TCMALLOC)
50 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" 51 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h"
51 #endif 52 #endif
52 53
53 #if defined(OS_WIN) 54 #if defined(OS_WIN)
54 #include <cstring> 55 #include <cstring>
55 #include <atlbase.h> 56 #include <atlbase.h>
56 #include <atlapp.h> 57 #include <atlapp.h>
57 #include <malloc.h> 58 #include <malloc.h>
59 #include <string>
58 #elif defined(OS_MACOSX) 60 #elif defined(OS_MACOSX)
59 #include "base/mac/scoped_nsautorelease_pool.h" 61 #include "base/mac/scoped_nsautorelease_pool.h"
60 #include "base/mach_ipc_mac.h" 62 #include "base/mach_ipc_mac.h"
61 #include "base/system_monitor/system_monitor.h" 63 #include "base/system_monitor/system_monitor.h"
62 #include "content/browser/mach_broker_mac.h" 64 #include "content/browser/mach_broker_mac.h"
63 #include "content/common/sandbox_init_mac.h" 65 #include "content/common/sandbox_init_mac.h"
64 #endif // OS_WIN 66 #endif // OS_WIN
65 67
66 #if defined(OS_POSIX) 68 #if defined(OS_POSIX)
67 #include <signal.h> 69 #include <signal.h>
(...skipping 20 matching lines...) Expand all
88 extern int RendererMain(const content::MainFunctionParams&); 90 extern int RendererMain(const content::MainFunctionParams&);
89 extern int WorkerMain(const content::MainFunctionParams&); 91 extern int WorkerMain(const content::MainFunctionParams&);
90 extern int UtilityMain(const content::MainFunctionParams&); 92 extern int UtilityMain(const content::MainFunctionParams&);
91 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 93 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
92 namespace content { 94 namespace content {
93 extern int ZygoteMain(const MainFunctionParams&, 95 extern int ZygoteMain(const MainFunctionParams&,
94 ZygoteForkDelegate* forkdelegate); 96 ZygoteForkDelegate* forkdelegate);
95 } // namespace content 97 } // namespace content
96 #endif 98 #endif
97 99
100 namespace {
101 #if defined(OS_WIN)
102 // In order to have Theme support, we need to connect to the theme service.
103 // This needs to be done before we lock down the renderer. Officially this
104 // can be done with OpenThemeData() but it fails unless you pass a valid
105 // window at least the first time. Interestingly, the very act of creating a
106 // window also sets the connection to the theme service.
107 void EnableThemeSupportForRenderer() {
108 HWINSTA current_station = ::GetProcessWindowStation();
109 static const size_t kStaticBufferLength = 32;
110 char static_buffer[kStaticBufferLength];
111 static_buffer[0] = '\0';
robertshield 2012/09/06 18:35:56 char static_buffer[kStaticBufferLength] = "";
MAD 2012/09/06 23:57:53 Done.
112 const char * current_station_name = static_buffer;
robertshield 2012/09/06 18:35:56 nit: const char* current_station_name = static_buf
MAD 2012/09/06 23:57:53 Done.
113 // In case our static buffer isn't big enough, we'll use this dynamic one that
114 // will be holding on the allocated char buffer long enough.
115 std::string dynamic_buffer;
robertshield 2012/09/06 18:35:56 Couldn't we simplify this by always using dynamic_
MAD 2012/09/06 23:57:53 Done.
116 DWORD needed_length = 0;
117 if (!::GetUserObjectInformationA(current_station,
118 UOI_NAME,
119 static_buffer,
120 kStaticBufferLength,
121 &needed_length)) {
122 DCHECK(needed_length > kStaticBufferLength) << " Windows error: "
123 << ::GetLastError();
124 dynamic_buffer.resize(needed_length);
125 if (!::GetUserObjectInformationA(
126 current_station,
127 UOI_NAME,
128 const_cast<char*>(dynamic_buffer.c_str()),
rvargas (doing something else) 2012/09/06 23:19:21 WriteInto ?
129 needed_length,
130 &needed_length)) {
131 NOTREACHED() << "Windows error: " << ::GetLastError();
132 }
133 current_station_name = dynamic_buffer.c_str();
134 }
135
136 if (base::strncasecmp(current_station_name, "WinSta0", 7)) {
137 HWINSTA winsta0 = NULL;
138 winsta0 = ::OpenWindowStationA("WinSta0", FALSE, GENERIC_READ);
robertshield 2012/09/06 18:35:56 shorten this to HWINSTA winsta0 = ::OpenWindowStat
MAD 2012/09/06 23:57:53 Done.
139 if (!winsta0 || !::SetProcessWindowStation(winsta0)) {
140 // Could not set the alternate window station. There is a possibility
141 // that the theme wont be correctly initialized.
142 NOTREACHED() << "Unable to switch to WinSta0, we: "<< ::GetLastError();
143 }
144
145 HWND window = ::CreateWindowExW(0, L"Static", L"", WS_POPUP | WS_DISABLED,
146 CW_USEDEFAULT, 0, 0, 0, HWND_MESSAGE, NULL,
147 ::GetModuleHandleA(NULL), NULL);
148 if (!window) {
149 DLOG(WARNING) << "failed to enable theme support";
150 } else {
151 ::DestroyWindow(window);
152 window = NULL;
153 }
154
155 // Revert the window station.
156 if (!current_station || !::SetProcessWindowStation(current_station)) {
robertshield 2012/09/06 18:35:56 is it possible to get here if current_station is N
MAD 2012/09/06 23:57:53 Done.
157 // We failed to switch back to the secure window station. This might
158 // confuse the renderer enough that we should kill it now.
159 LOG(FATAL) << "Failed to restore alternate window station";
160 }
161
162 if (!::CloseWindowStation(winsta0)) {
163 // We might be leaking a winsta0 handle. This is a security risk, but
164 // since we allow fail over to no desktop protection in low memory
165 // condition, this is not a big risk.
166 NOTREACHED();
167 }
168 }
169 }
170 #endif // defined(OS_WIN)
171 } // namespace
172
98 namespace content { 173 namespace content {
99 174
100 base::LazyInstance<ContentBrowserClient> 175 base::LazyInstance<ContentBrowserClient>
101 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; 176 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER;
102 base::LazyInstance<ContentPluginClient> 177 base::LazyInstance<ContentPluginClient>
103 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER; 178 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER;
104 base::LazyInstance<ContentRendererClient> 179 base::LazyInstance<ContentRendererClient>
105 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; 180 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER;
106 base::LazyInstance<ContentUtilityClient> 181 base::LazyInstance<ContentUtilityClient>
107 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; 182 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER;
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 (delegate && 631 (delegate &&
557 delegate->ProcessRegistersWithSystemProcess(process_type))) { 632 delegate->ProcessRegistersWithSystemProcess(process_type))) {
558 base::SystemMonitor::AllocateSystemIOPorts(); 633 base::SystemMonitor::AllocateSystemIOPorts();
559 } 634 }
560 635
561 if (!process_type.empty() && 636 if (!process_type.empty() &&
562 (!delegate || delegate->ShouldSendMachPort(process_type))) { 637 (!delegate || delegate->ShouldSendMachPort(process_type))) {
563 SendTaskPortToParentProcess(); 638 SendTaskPortToParentProcess();
564 } 639 }
565 #elif defined(OS_WIN) 640 #elif defined(OS_WIN)
641 // This must be done early enough since some helper functions like
642 // IsTouchEnanble, needed to load ressources, may call into the theme dll.
robertshield 2012/09/06 18:35:56 *IsTouchEnabled, *resources
MAD 2012/09/06 23:57:53 Done.
643 if (process_type == switches::kRendererProcess)
644 EnableThemeSupportForRenderer();
566 #if defined(ENABLE_HIDPI) 645 #if defined(ENABLE_HIDPI)
567 ui::EnableHighDPISupport(); 646 ui::EnableHighDPISupport();
568 #endif 647 #endif
569 SetupCRT(command_line); 648 SetupCRT(command_line);
570 #endif 649 #endif
571 650
572 #if defined(OS_POSIX) 651 #if defined(OS_POSIX)
573 if (!process_type.empty()) { 652 if (!process_type.empty()) {
574 // When you hit Ctrl-C in a terminal running the browser 653 // When you hit Ctrl-C in a terminal running the browser
575 // process, a SIGINT is delivered to the entire process group. 654 // process, a SIGINT is delivered to the entire process group.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 788
710 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 789 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
711 }; 790 };
712 791
713 // static 792 // static
714 ContentMainRunner* ContentMainRunner::Create() { 793 ContentMainRunner* ContentMainRunner::Create() {
715 return new ContentMainRunnerImpl(); 794 return new ContentMainRunnerImpl();
716 } 795 }
717 796
718 } // namespace content 797 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/renderer_main_platform_delegate_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698