OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/child/pdf_child_init.h" |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" |
| 9 #include "base/path_service.h" |
| 10 #include "chrome/common/chrome_paths.h" |
| 11 #include "content/public/child/child_thread.h" |
| 12 |
| 13 #if defined(OS_WIN) |
| 14 #include "base/win/iat_patch_function.h" |
| 15 #endif |
| 16 |
| 17 namespace chrome { |
| 18 namespace { |
| 19 #if defined(OS_WIN) |
| 20 static base::win::IATPatchFunction g_iat_patch_createdca; |
| 21 HDC WINAPI CreateDCAPatch(LPCSTR driver_name, |
| 22 LPCSTR device_name, |
| 23 LPCSTR output, |
| 24 const void* init_data) { |
| 25 DCHECK(std::string("DISPLAY") == std::string(driver_name)); |
| 26 DCHECK(!device_name); |
| 27 DCHECK(!output); |
| 28 DCHECK(!init_data); |
| 29 |
| 30 // CreateDC fails behind the sandbox, but not CreateCompatibleDC. |
| 31 return CreateCompatibleDC(NULL); |
| 32 } |
| 33 |
| 34 static base::win::IATPatchFunction g_iat_patch_get_font_data; |
| 35 DWORD WINAPI GetFontDataPatch(HDC hdc, |
| 36 DWORD table, |
| 37 DWORD offset, |
| 38 LPVOID buffer, |
| 39 DWORD length) { |
| 40 int rv = GetFontData(hdc, table, offset, buffer, length); |
| 41 if (rv == GDI_ERROR && hdc) { |
| 42 HFONT font = static_cast<HFONT>(GetCurrentObject(hdc, OBJ_FONT)); |
| 43 |
| 44 LOGFONT logfont; |
| 45 if (GetObject(font, sizeof(LOGFONT), &logfont)) { |
| 46 std::vector<char> font_data; |
| 47 content::ChildThread::Get()->PreCacheFont(logfont); |
| 48 rv = GetFontData(hdc, table, offset, buffer, length); |
| 49 content::ChildThread::Get()->ReleaseCachedFonts(); |
| 50 } |
| 51 } |
| 52 return rv; |
| 53 } |
| 54 #endif // OS_WIN |
| 55 |
| 56 } // namespace |
| 57 |
| 58 void InitializePDF() { |
| 59 #if defined(OS_WIN) |
| 60 // Need to patch a few functions for font loading to work correctly. This can |
| 61 // be removed once we switch PDF to use Skia. |
| 62 base::FilePath pdf; |
| 63 if (PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) && |
| 64 base::PathExists(pdf)) { |
| 65 g_iat_patch_createdca.Patch(pdf.value().c_str(), "gdi32.dll", "CreateDCA", |
| 66 CreateDCAPatch); |
| 67 g_iat_patch_get_font_data.Patch(pdf.value().c_str(), "gdi32.dll", |
| 68 "GetFontData", GetFontDataPatch); |
| 69 } |
| 70 #endif |
| 71 } |
| 72 |
| 73 } // namespace chrome |
OLD | NEW |