Index: content/ppapi_plugin/ppapi_thread.cc |
diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc |
index 59edaaf168441002eec37fc05324a0712ca9a05a..ac212e1fd4c2d351fb6878f87dd8e016a0d5875c 100644 |
--- a/content/ppapi_plugin/ppapi_thread.cc |
+++ b/content/ppapi_plugin/ppapi_thread.cc |
@@ -42,10 +42,12 @@ |
#include "ppapi/proxy/plugin_message_filter.h" |
#include "ppapi/proxy/ppapi_messages.h" |
#include "ppapi/proxy/resource_reply_thread_registrar.h" |
+#include "ppapi/shared_impl/proxy_lock.h" |
#include "third_party/WebKit/public/web/WebKit.h" |
#include "ui/base/ui_base_switches.h" |
#if defined(OS_WIN) |
+#include "base/win/iat_patch_function.h" |
#include "base/win/win_util.h" |
#include "base/win/windows_version.h" |
#include "sandbox/win/src/sandbox.h" |
@@ -91,6 +93,50 @@ static void WarmupWindowsLocales(const ppapi::PpapiPermissions& permissions) { |
} |
} |
} |
+ |
+// TODO(scottmg): http://crbug.com/448473. This code should be removed from the |
+// renderer once PDF is always OOP and/or PDF is made to use Skia instead of GDI |
ananta
2015/01/15 02:31:22
Move the once PDF is always OOP comment portion to
scottmg
2015/01/15 02:35:38
Done.
|
+// directly. |
+const wchar_t kPdfFileName[] = L"pdf.dll"; |
+ |
+static base::win::IATPatchFunction g_iat_patch_createdca; |
+HDC WINAPI CreateDCAPatch(LPCSTR driver_name, |
+ LPCSTR device_name, |
+ LPCSTR output, |
+ const void* init_data) { |
+ DCHECK(std::string("DISPLAY") == std::string(driver_name)); |
+ DCHECK(!device_name); |
+ DCHECK(!output); |
+ DCHECK(!init_data); |
+ |
+ // CreateDC fails behind the sandbox, but not CreateCompatibleDC. |
+ return CreateCompatibleDC(NULL); |
+} |
+ |
+static base::win::IATPatchFunction g_iat_patch_get_font_data; |
+DWORD WINAPI GetFontDataPatch(HDC hdc, |
+ DWORD table, |
+ DWORD offset, |
+ LPVOID buffer, |
+ DWORD length) { |
+ int rv = GetFontData(hdc, table, offset, buffer, length); |
+ if (rv == GDI_ERROR && hdc) { |
+ HFONT font = static_cast<HFONT>(GetCurrentObject(hdc, OBJ_FONT)); |
+ |
+ LOGFONT logfont; |
+ if (GetObject(font, sizeof(LOGFONT), &logfont)) { |
+ std::vector<char> font_data; |
+ { |
+ ppapi::ProxyAutoLock lock; |
+ ppapi::proxy::PluginGlobals::Get()->PreCacheFontForFlash( |
+ reinterpret_cast<const void*>(&logfont)); |
+ } |
+ rv = GetFontData(hdc, table, offset, buffer, length); |
+ } |
+ } |
+ return rv; |
+} |
+ |
#else |
extern void* g_target_services; |
#endif |
@@ -325,6 +371,15 @@ void PpapiThread::OnLoadPlugin(const base::FilePath& path, |
// otherwise these would be silent terminations and fly under the radar). |
base::win::SetAbortBehaviorForCrashReporting(); |
+ // Need to patch a few functions for font loading to work correctly. This can |
+ // be removed once we switch PDF to use Skia. |
ananta
2015/01/15 02:31:22
Some commentary which explains this voodoo to get
scottmg
2015/01/15 02:35:38
Done, above at the PreCache... call.
|
+ if (GetModuleHandle(kPdfFileName)) { |
+ g_iat_patch_createdca.Patch(kPdfFileName, "gdi32.dll", "CreateDCA", |
+ CreateDCAPatch); |
+ g_iat_patch_get_font_data.Patch(kPdfFileName, "gdi32.dll", "GetFontData", |
+ GetFontDataPatch); |
+ } |
+ |
// Once we lower the token the sandbox is locked down and no new modules |
// can be loaded. TODO(cpu): consider changing to the loading style of |
// regular plugins. |