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

Unified Diff: chrome/child/pdf_child_init.cc

Issue 897563002: Unify the three places that patch font loading for PDFium on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/child/pdf_child_init.cc
diff --git a/chrome/child/pdf_child_init.cc b/chrome/child/pdf_child_init.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ac17072a22aa3edc72ca11f75211c3ba6722c9a3
--- /dev/null
+++ b/chrome/child/pdf_child_init.cc
@@ -0,0 +1,73 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/child/pdf_child_init.h"
+
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/path_service.h"
+#include "chrome/common/chrome_paths.h"
+#include "content/public/child/child_thread.h"
+
+#if defined(OS_WIN)
+#include "base/win/iat_patch_function.h"
+#endif
+
+namespace chrome {
+namespace {
+#if defined(OS_WIN)
+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;
+ content::ChildThread::Get()->PreCacheFont(logfont);
+ rv = GetFontData(hdc, table, offset, buffer, length);
+ content::ChildThread::Get()->ReleaseCachedFonts();
+ }
+ }
+ return rv;
+}
+#endif // OS_WIN
+
+} // namespace
+
+void InitializePDF() {
+#if defined(OS_WIN)
+ // Need to patch a few functions for font loading to work correctly. This can
+ // be removed once we switch PDF to use Skia.
+ base::FilePath pdf;
+ if (PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) &&
+ base::PathExists(pdf)) {
+ g_iat_patch_createdca.Patch(pdf.value().c_str(), "gdi32.dll", "CreateDCA",
+ CreateDCAPatch);
+ g_iat_patch_get_font_data.Patch(pdf.value().c_str(), "gdi32.dll",
+ "GetFontData", GetFontDataPatch);
+ }
+#endif
+}
+
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698