| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <objidl.h> | 9 #include <objidl.h> |
| 10 #include <mlang.h> | 10 #include <mlang.h> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include "content/renderer/render_process_impl.h" | 13 #include "content/renderer/render_process_impl.h" |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/file_util.h" | |
| 19 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 20 #include "base/metrics/histogram.h" | |
| 21 #include "base/path_service.h" | |
| 22 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
| 23 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 24 #include "crypto/nss_util.h" | 21 #include "content/common/content_switches.h" |
| 25 #include "chrome/common/chrome_switches.h" | |
| 26 #include "chrome/common/chrome_paths.h" | |
| 27 #include "chrome/common/render_messages.h" | |
| 28 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
| 23 #include "content/renderer/content_renderer_client.h" |
| 29 #include "content/renderer/render_thread.h" | 24 #include "content/renderer/render_thread.h" |
| 30 #include "content/renderer/render_view.h" | 25 #include "content/renderer/render_view.h" |
| 31 #include "ipc/ipc_channel.h" | 26 #include "ipc/ipc_channel.h" |
| 32 #include "ipc/ipc_message_utils.h" | 27 #include "ipc/ipc_message_utils.h" |
| 33 #include "media/base/media.h" | 28 #include "media/base/media.h" |
| 34 #include "media/base/media_switches.h" | 29 #include "media/base/media_switches.h" |
| 35 #include "skia/ext/platform_canvas.h" | 30 #include "skia/ext/platform_canvas.h" |
| 36 #include "ui/gfx/surface/transport_dib.h" | 31 #include "ui/gfx/surface/transport_dib.h" |
| 37 #include "webkit/plugins/npapi/plugin_instance.h" | 32 #include "webkit/plugins/npapi/plugin_instance.h" |
| 38 #include "webkit/plugins/npapi/plugin_lib.h" | 33 #include "webkit/plugins/npapi/plugin_lib.h" |
| 39 #include "webkit/glue/webkit_glue.h" | 34 #include "webkit/glue/webkit_glue.h" |
| 40 | 35 |
| 41 #if defined(OS_MACOSX) | 36 #if defined(OS_MACOSX) |
| 42 #include "base/mac/mac_util.h" | 37 #include "base/mac/mac_util.h" |
| 43 #elif defined(OS_WIN) | |
| 44 #include "app/win/iat_patch_function.h" | |
| 45 #endif | 38 #endif |
| 46 | 39 |
| 47 #if defined(OS_LINUX) | 40 #if defined(OS_LINUX) |
| 48 #include "content/renderer/renderer_sandbox_support_linux.h" | 41 #include "content/renderer/renderer_sandbox_support_linux.h" |
| 49 #endif | 42 #endif |
| 50 | 43 |
| 51 #if defined(OS_WIN) | |
| 52 | |
| 53 static app::win::IATPatchFunction g_iat_patch_createdca; | |
| 54 HDC WINAPI CreateDCAPatch(LPCSTR driver_name, | |
| 55 LPCSTR device_name, | |
| 56 LPCSTR output, | |
| 57 const void* init_data) { | |
| 58 DCHECK(std::string("DISPLAY") == std::string(driver_name)); | |
| 59 DCHECK(!device_name); | |
| 60 DCHECK(!output); | |
| 61 DCHECK(!init_data); | |
| 62 | |
| 63 // CreateDC fails behind the sandbox, but not CreateCompatibleDC. | |
| 64 return CreateCompatibleDC(NULL); | |
| 65 } | |
| 66 | |
| 67 static app::win::IATPatchFunction g_iat_patch_get_font_data; | |
| 68 DWORD WINAPI GetFontDataPatch(HDC hdc, | |
| 69 DWORD table, | |
| 70 DWORD offset, | |
| 71 LPVOID buffer, | |
| 72 DWORD length) { | |
| 73 int rv = GetFontData(hdc, table, offset, buffer, length); | |
| 74 if (rv == GDI_ERROR && hdc) { | |
| 75 HFONT font = static_cast<HFONT>(GetCurrentObject(hdc, OBJ_FONT)); | |
| 76 | |
| 77 LOGFONT logfont; | |
| 78 if (GetObject(font, sizeof(LOGFONT), &logfont)) { | |
| 79 std::vector<char> font_data; | |
| 80 if (RenderThread::current()->Send(new ViewHostMsg_PreCacheFont(logfont))) | |
| 81 rv = GetFontData(hdc, table, offset, buffer, length); | |
| 82 } | |
| 83 } | |
| 84 return rv; | |
| 85 } | |
| 86 | |
| 87 #endif | |
| 88 | |
| 89 RenderProcessImpl::RenderProcessImpl() | 44 RenderProcessImpl::RenderProcessImpl() |
| 90 : ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_( | 45 : ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_( |
| 91 base::TimeDelta::FromSeconds(5), | 46 base::TimeDelta::FromSeconds(5), |
| 92 this, &RenderProcessImpl::ClearTransportDIBCache)), | 47 this, &RenderProcessImpl::ClearTransportDIBCache)), |
| 93 transport_dib_next_sequence_number_(0) { | 48 transport_dib_next_sequence_number_(0) { |
| 94 in_process_plugins_ = InProcessPlugins(); | 49 in_process_plugins_ = InProcessPlugins(); |
| 95 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) | 50 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) |
| 96 shared_mem_cache_[i] = NULL; | 51 shared_mem_cache_[i] = NULL; |
| 97 | 52 |
| 98 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 117 "--debugger-auto-break" | 72 "--debugger-auto-break" |
| 118 // Enable lazy in-memory profiling. | 73 // Enable lazy in-memory profiling. |
| 119 " --prof --prof-lazy --logfile=*"); | 74 " --prof --prof-lazy --logfile=*"); |
| 120 | 75 |
| 121 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 76 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 122 if (command_line.HasSwitch(switches::kJavaScriptFlags)) { | 77 if (command_line.HasSwitch(switches::kJavaScriptFlags)) { |
| 123 webkit_glue::SetJavaScriptFlags( | 78 webkit_glue::SetJavaScriptFlags( |
| 124 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags)); | 79 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags)); |
| 125 } | 80 } |
| 126 | 81 |
| 127 if (command_line.HasSwitch(switches::kEnableWatchdog)) { | |
| 128 // TODO(JAR): Need to implement renderer IO msgloop watchdog. | |
| 129 } | |
| 130 | |
| 131 if (command_line.HasSwitch(switches::kDumpHistogramsOnExit)) { | |
| 132 base::StatisticsRecorder::set_dump_on_exit(true); | |
| 133 } | |
| 134 | |
| 135 // Note that under Linux, the media library will normally already have | 82 // Note that under Linux, the media library will normally already have |
| 136 // been initialized by the Zygote before this instance became a Renderer. | 83 // been initialized by the Zygote before this instance became a Renderer. |
| 137 FilePath media_path; | 84 FilePath media_path = |
| 138 if (PathService::Get(chrome::DIR_MEDIA_LIBS, &media_path)) | 85 content::GetContentClient()->renderer()->GetMediaLibraryPath(); |
| 86 if (!media_path.empty()) |
| 139 media::InitializeMediaLibrary(media_path); | 87 media::InitializeMediaLibrary(media_path); |
| 140 | 88 |
| 141 #if !defined(OS_MACOSX) | 89 #if !defined(OS_MACOSX) |
| 142 // TODO(hclam): Add more checks here. Currently this is not used. | 90 // TODO(hclam): Add more checks here. Currently this is not used. |
| 143 if (media::IsMediaLibraryInitialized() && | 91 if (media::IsMediaLibraryInitialized() && |
| 144 CommandLine::ForCurrentProcess()->HasSwitch( | 92 CommandLine::ForCurrentProcess()->HasSwitch( |
| 145 switches::kEnableOpenMax)) { | 93 switches::kEnableOpenMax)) { |
| 146 media::InitializeOpenMaxLibrary(media_path); | 94 media::InitializeOpenMaxLibrary(media_path); |
| 147 } | 95 } |
| 148 #endif | 96 #endif |
| 149 | |
| 150 #if defined(OS_WIN) | |
| 151 // Need to patch a few functions for font loading to work correctly. | |
| 152 FilePath pdf; | |
| 153 if (PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) && | |
| 154 file_util::PathExists(pdf)) { | |
| 155 g_iat_patch_createdca.Patch( | |
| 156 pdf.value().c_str(), "gdi32.dll", "CreateDCA", CreateDCAPatch); | |
| 157 g_iat_patch_get_font_data.Patch( | |
| 158 pdf.value().c_str(), "gdi32.dll", "GetFontData", GetFontDataPatch); | |
| 159 } | |
| 160 #endif | |
| 161 | |
| 162 #if defined(OS_LINUX) | |
| 163 // Remoting requires NSS to function properly. | |
| 164 | |
| 165 if (!command_line.HasSwitch(switches::kSingleProcess) && | |
| 166 command_line.HasSwitch(switches::kEnableRemoting)) { | |
| 167 #if defined(USE_NSS) | |
| 168 // We are going to fork to engage the sandbox and we have not loaded | |
| 169 // any security modules so it is safe to disable the fork check in NSS. | |
| 170 crypto::DisableNSSForkCheck(); | |
| 171 crypto::ForceNSSNoDBInit(); | |
| 172 crypto::EnsureNSSInit(); | |
| 173 #else | |
| 174 // TODO(bulach): implement openssl support. | |
| 175 NOTREACHED() << "Remoting is not supported for openssl"; | |
| 176 #endif | |
| 177 } | |
| 178 #endif | |
| 179 } | 97 } |
| 180 | 98 |
| 181 RenderProcessImpl::~RenderProcessImpl() { | 99 RenderProcessImpl::~RenderProcessImpl() { |
| 182 // TODO(port): Try and limit what we pull in for our non-Win unit test bundle. | 100 // TODO(port): Try and limit what we pull in for our non-Win unit test bundle. |
| 183 #ifndef NDEBUG | 101 #ifndef NDEBUG |
| 184 // log important leaked objects | 102 // log important leaked objects |
| 185 webkit_glue::CheckForLeaks(); | 103 webkit_glue::CheckForLeaks(); |
| 186 #endif | 104 #endif |
| 187 | 105 |
| 188 GetShutDownEvent()->Signal(); | 106 GetShutDownEvent()->Signal(); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 256 } |
| 339 | 257 |
| 340 void RenderProcessImpl::ClearTransportDIBCache() { | 258 void RenderProcessImpl::ClearTransportDIBCache() { |
| 341 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) { | 259 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) { |
| 342 if (shared_mem_cache_[i]) { | 260 if (shared_mem_cache_[i]) { |
| 343 FreeTransportDIB(shared_mem_cache_[i]); | 261 FreeTransportDIB(shared_mem_cache_[i]); |
| 344 shared_mem_cache_[i] = NULL; | 262 shared_mem_cache_[i] = NULL; |
| 345 } | 263 } |
| 346 } | 264 } |
| 347 } | 265 } |
| OLD | NEW |