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/ppapi_plugin/ppapi_thread.h" | 5 #include "content/ppapi_plugin/ppapi_thread.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/cpu.h" | 10 #include "base/cpu.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "ipc/ipc_sync_channel.h" | 35 #include "ipc/ipc_sync_channel.h" |
36 #include "ipc/ipc_sync_message_filter.h" | 36 #include "ipc/ipc_sync_message_filter.h" |
37 #include "ppapi/c/dev/ppp_network_state_dev.h" | 37 #include "ppapi/c/dev/ppp_network_state_dev.h" |
38 #include "ppapi/c/pp_errors.h" | 38 #include "ppapi/c/pp_errors.h" |
39 #include "ppapi/c/ppp.h" | 39 #include "ppapi/c/ppp.h" |
40 #include "ppapi/proxy/interface_list.h" | 40 #include "ppapi/proxy/interface_list.h" |
41 #include "ppapi/proxy/plugin_globals.h" | 41 #include "ppapi/proxy/plugin_globals.h" |
42 #include "ppapi/proxy/plugin_message_filter.h" | 42 #include "ppapi/proxy/plugin_message_filter.h" |
43 #include "ppapi/proxy/ppapi_messages.h" | 43 #include "ppapi/proxy/ppapi_messages.h" |
44 #include "ppapi/proxy/resource_reply_thread_registrar.h" | 44 #include "ppapi/proxy/resource_reply_thread_registrar.h" |
| 45 #include "ppapi/shared_impl/proxy_lock.h" |
45 #include "third_party/WebKit/public/web/WebKit.h" | 46 #include "third_party/WebKit/public/web/WebKit.h" |
46 #include "ui/base/ui_base_switches.h" | 47 #include "ui/base/ui_base_switches.h" |
47 | 48 |
48 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
| 50 #include "base/win/iat_patch_function.h" |
49 #include "base/win/win_util.h" | 51 #include "base/win/win_util.h" |
50 #include "base/win/windows_version.h" | 52 #include "base/win/windows_version.h" |
51 #include "sandbox/win/src/sandbox.h" | 53 #include "sandbox/win/src/sandbox.h" |
52 #elif defined(OS_MACOSX) | 54 #elif defined(OS_MACOSX) |
53 #include "content/common/sandbox_init_mac.h" | 55 #include "content/common/sandbox_init_mac.h" |
54 #endif | 56 #endif |
55 | 57 |
56 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
57 const char kWidevineCdmAdapterFileName[] = "widevinecdmadapter.dll"; | 59 const char kWidevineCdmAdapterFileName[] = "widevinecdmadapter.dll"; |
58 | 60 |
(...skipping 25 matching lines...) Expand all Loading... |
84 PfnEnumSystemLocalesEx enum_sys_locales_ex = | 86 PfnEnumSystemLocalesEx enum_sys_locales_ex = |
85 reinterpret_cast<PfnEnumSystemLocalesEx> | 87 reinterpret_cast<PfnEnumSystemLocalesEx> |
86 (GetProcAddress(handle_kern32, "EnumSystemLocalesEx")); | 88 (GetProcAddress(handle_kern32, "EnumSystemLocalesEx")); |
87 | 89 |
88 enum_sys_locales_ex(EnumLocalesProcEx, LOCALE_WINDOWS, 0, 0); | 90 enum_sys_locales_ex(EnumLocalesProcEx, LOCALE_WINDOWS, 0, 0); |
89 } else { | 91 } else { |
90 EnumSystemLocalesW(EnumLocalesProc, LCID_INSTALLED); | 92 EnumSystemLocalesW(EnumLocalesProc, LCID_INSTALLED); |
91 } | 93 } |
92 } | 94 } |
93 } | 95 } |
| 96 |
| 97 // TODO(scottmg): http://crbug.com/448473. This code should be removed from the |
| 98 // renderer once PDF is always OOP and/or PDF is made to use Skia instead of GDI |
| 99 // directly. |
| 100 const wchar_t kPdfFileName[] = L"pdf.dll"; |
| 101 |
| 102 static base::win::IATPatchFunction g_iat_patch_createdca; |
| 103 HDC WINAPI CreateDCAPatch(LPCSTR driver_name, |
| 104 LPCSTR device_name, |
| 105 LPCSTR output, |
| 106 const void* init_data) { |
| 107 DCHECK(std::string("DISPLAY") == std::string(driver_name)); |
| 108 DCHECK(!device_name); |
| 109 DCHECK(!output); |
| 110 DCHECK(!init_data); |
| 111 |
| 112 // CreateDC fails behind the sandbox, but not CreateCompatibleDC. |
| 113 return CreateCompatibleDC(NULL); |
| 114 } |
| 115 |
| 116 static base::win::IATPatchFunction g_iat_patch_get_font_data; |
| 117 DWORD WINAPI GetFontDataPatch(HDC hdc, |
| 118 DWORD table, |
| 119 DWORD offset, |
| 120 LPVOID buffer, |
| 121 DWORD length) { |
| 122 int rv = GetFontData(hdc, table, offset, buffer, length); |
| 123 if (rv == GDI_ERROR && hdc) { |
| 124 HFONT font = static_cast<HFONT>(GetCurrentObject(hdc, OBJ_FONT)); |
| 125 |
| 126 LOGFONT logfont; |
| 127 if (GetObject(font, sizeof(LOGFONT), &logfont)) { |
| 128 std::vector<char> font_data; |
| 129 { |
| 130 ppapi::ProxyAutoLock lock; |
| 131 // In the sandbox, font loading will fail. We ask the browser to load it |
| 132 // which causes it to be loaded by the kernel, which then makes the |
| 133 // subsequent call succeed. |
| 134 ppapi::proxy::PluginGlobals::Get()->PreCacheFontForFlash( |
| 135 reinterpret_cast<const void*>(&logfont)); |
| 136 } |
| 137 rv = GetFontData(hdc, table, offset, buffer, length); |
| 138 } |
| 139 } |
| 140 return rv; |
| 141 } |
| 142 |
94 #else | 143 #else |
95 extern void* g_target_services; | 144 extern void* g_target_services; |
96 #endif | 145 #endif |
97 | 146 |
98 namespace content { | 147 namespace content { |
99 | 148 |
100 typedef int32_t (*InitializeBrokerFunc) | 149 typedef int32_t (*InitializeBrokerFunc) |
101 (PP_ConnectInstance_Func* connect_instance_func); | 150 (PP_ConnectInstance_Func* connect_instance_func); |
102 | 151 |
103 PpapiThread::PpapiThread(const base::CommandLine& command_line, bool is_broker) | 152 PpapiThread::PpapiThread(const base::CommandLine& command_line, bool is_broker) |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 return; | 367 return; |
319 } | 368 } |
320 } | 369 } |
321 } | 370 } |
322 | 371 |
323 #if defined(OS_WIN) | 372 #if defined(OS_WIN) |
324 // If code subsequently tries to exit using abort(), force a crash (since | 373 // If code subsequently tries to exit using abort(), force a crash (since |
325 // otherwise these would be silent terminations and fly under the radar). | 374 // otherwise these would be silent terminations and fly under the radar). |
326 base::win::SetAbortBehaviorForCrashReporting(); | 375 base::win::SetAbortBehaviorForCrashReporting(); |
327 | 376 |
| 377 // Need to patch a few functions for font loading to work correctly. This can |
| 378 // be removed once we switch PDF to use Skia. |
| 379 if (GetModuleHandle(kPdfFileName)) { |
| 380 g_iat_patch_createdca.Patch(kPdfFileName, "gdi32.dll", "CreateDCA", |
| 381 CreateDCAPatch); |
| 382 g_iat_patch_get_font_data.Patch(kPdfFileName, "gdi32.dll", "GetFontData", |
| 383 GetFontDataPatch); |
| 384 } |
| 385 |
328 // Once we lower the token the sandbox is locked down and no new modules | 386 // Once we lower the token the sandbox is locked down and no new modules |
329 // can be loaded. TODO(cpu): consider changing to the loading style of | 387 // can be loaded. TODO(cpu): consider changing to the loading style of |
330 // regular plugins. | 388 // regular plugins. |
331 if (g_target_services) { | 389 if (g_target_services) { |
332 // Let Flash and Widevine CDM adapter load DXVA before lockdown on Vista+. | 390 // Let Flash and Widevine CDM adapter load DXVA before lockdown on Vista+. |
333 if (permissions.HasPermission(ppapi::PERMISSION_FLASH) || | 391 if (permissions.HasPermission(ppapi::PERMISSION_FLASH) || |
334 path.BaseName().MaybeAsASCII() == kWidevineCdmAdapterFileName) { | 392 path.BaseName().MaybeAsASCII() == kWidevineCdmAdapterFileName) { |
335 if (base::win::OSInfo::GetInstance()->version() >= | 393 if (base::win::OSInfo::GetInstance()->version() >= |
336 base::win::VERSION_VISTA) { | 394 base::win::VERSION_VISTA) { |
337 LoadLibraryA("dxva2.dll"); | 395 LoadLibraryA("dxva2.dll"); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 std::string("Plugin.Ppapi") + (is_broker_ ? "Broker" : "Plugin") + | 600 std::string("Plugin.Ppapi") + (is_broker_ ? "Broker" : "Plugin") + |
543 "LoadErrorCode_" + path.BaseName().MaybeAsASCII(); | 601 "LoadErrorCode_" + path.BaseName().MaybeAsASCII(); |
544 | 602 |
545 // For sparse histograms, we can use the macro, as it does not incorporate a | 603 // For sparse histograms, we can use the macro, as it does not incorporate a |
546 // static. | 604 // static. |
547 UMA_HISTOGRAM_SPARSE_SLOWLY(histogram_name, error.code); | 605 UMA_HISTOGRAM_SPARSE_SLOWLY(histogram_name, error.code); |
548 #endif | 606 #endif |
549 } | 607 } |
550 | 608 |
551 } // namespace content | 609 } // namespace content |
OLD | NEW |