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

Side by Side Diff: chrome/utility/printing_handler.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, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/utility/printing_handler.h" 5 #include "chrome/utility/printing_handler.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/scoped_native_library.h" 10 #include "base/scoped_native_library.h"
11 #include "chrome/common/chrome_paths.h" 11 #include "chrome/common/chrome_paths.h"
12 #include "chrome/common/chrome_utility_printing_messages.h" 12 #include "chrome/common/chrome_utility_printing_messages.h"
13 #include "chrome/utility/cloud_print/bitmap_image.h" 13 #include "chrome/utility/cloud_print/bitmap_image.h"
14 #include "chrome/utility/cloud_print/pwg_encoder.h" 14 #include "chrome/utility/cloud_print/pwg_encoder.h"
15 #include "content/public/utility/utility_thread.h" 15 #include "content/public/utility/utility_thread.h"
16 #include "printing/page_range.h" 16 #include "printing/page_range.h"
17 #include "printing/pdf_render_settings.h" 17 #include "printing/pdf_render_settings.h"
18 18
19 #if defined(OS_WIN) 19 #if defined(OS_WIN)
20 #include "base/win/iat_patch_function.h"
21 #include "printing/emf_win.h" 20 #include "printing/emf_win.h"
22 #include "ui/gfx/gdi_util.h" 21 #include "ui/gfx/gdi_util.h"
23 #endif 22 #endif
24 23
25 #if defined(ENABLE_PRINT_PREVIEW) 24 #if defined(ENABLE_PRINT_PREVIEW)
26 #include "chrome/common/crash_keys.h" 25 #include "chrome/common/crash_keys.h"
27 #include "printing/backend/print_backend.h" 26 #include "printing/backend/print_backend.h"
28 #endif 27 #endif
29 28
30 namespace { 29 namespace {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 double* max_page_width); 130 double* max_page_width);
132 131
133 RenderPDFPageToBitmapProc render_pdf_to_bitmap_func_; 132 RenderPDFPageToBitmapProc render_pdf_to_bitmap_func_;
134 GetPDFDocInfoProc get_pdf_doc_info_func_; 133 GetPDFDocInfoProc get_pdf_doc_info_func_;
135 134
136 base::ScopedNativeLibrary pdf_lib_; 135 base::ScopedNativeLibrary pdf_lib_;
137 DISALLOW_COPY_AND_ASSIGN(PdfFunctionsBase); 136 DISALLOW_COPY_AND_ASSIGN(PdfFunctionsBase);
138 }; 137 };
139 138
140 #if defined(OS_WIN) 139 #if defined(OS_WIN)
141 // The 2 below IAT patch functions are almost identical to the code in
142 // render_process_impl.cc. This is needed to work around specific Windows APIs
143 // used by the Chrome PDF plugin that will fail in the sandbox.
144 static base::win::IATPatchFunction g_iat_patch_createdca;
145 HDC WINAPI UtilityProcess_CreateDCAPatch(LPCSTR driver_name,
146 LPCSTR device_name,
147 LPCSTR output,
148 const DEVMODEA* init_data) {
149 if (driver_name && (std::string("DISPLAY") == driver_name)) {
150 // CreateDC fails behind the sandbox, but not CreateCompatibleDC.
151 return CreateCompatibleDC(NULL);
152 }
153
154 NOTREACHED();
155 return CreateDCA(driver_name, device_name, output, init_data);
156 }
157
158 static base::win::IATPatchFunction g_iat_patch_get_font_data;
159 DWORD WINAPI UtilityProcess_GetFontDataPatch(
160 HDC hdc, DWORD table, DWORD offset, LPVOID buffer, DWORD length) {
161 int rv = GetFontData(hdc, table, offset, buffer, length);
162 if (rv == GDI_ERROR && hdc) {
163 HFONT font = static_cast<HFONT>(GetCurrentObject(hdc, OBJ_FONT));
164
165 LOGFONT logfont;
166 if (GetObject(font, sizeof(LOGFONT), &logfont)) {
167 content::UtilityThread::Get()->PreCacheFont(logfont);
168 rv = GetFontData(hdc, table, offset, buffer, length);
169 content::UtilityThread::Get()->ReleaseCachedFonts();
170 }
171 }
172 return rv;
173 }
174 140
175 class PdfFunctionsWin : public PdfFunctionsBase { 141 class PdfFunctionsWin : public PdfFunctionsBase {
176 public: 142 public:
177 PdfFunctionsWin() : render_pdf_to_dc_func_(NULL) { 143 PdfFunctionsWin() : render_pdf_to_dc_func_(NULL) {
178 } 144 }
179 145
180 bool PlatformInit( 146 bool PlatformInit(
181 const base::FilePath& pdf_module_path, 147 const base::FilePath& pdf_module_path,
182 const base::ScopedNativeLibrary& pdf_lib) override { 148 const base::ScopedNativeLibrary& pdf_lib) override {
183 // Patch the IAT for handling specific APIs known to fail in the sandbox.
scottmg 2015/02/03 17:52:06 There's no (useful) test for any of this stuff bec
184 if (!g_iat_patch_createdca.is_patched()) {
185 g_iat_patch_createdca.Patch(pdf_module_path.value().c_str(),
186 "gdi32.dll", "CreateDCA",
187 UtilityProcess_CreateDCAPatch);
188 }
189
190 if (!g_iat_patch_get_font_data.is_patched()) {
191 g_iat_patch_get_font_data.Patch(pdf_module_path.value().c_str(),
192 "gdi32.dll", "GetFontData",
193 UtilityProcess_GetFontDataPatch);
194 }
195 render_pdf_to_dc_func_ = 149 render_pdf_to_dc_func_ =
196 reinterpret_cast<RenderPDFPageToDCProc>( 150 reinterpret_cast<RenderPDFPageToDCProc>(
197 pdf_lib.GetFunctionPointer("RenderPDFPageToDC")); 151 pdf_lib.GetFunctionPointer("RenderPDFPageToDC"));
198 LOG_IF(WARNING, !render_pdf_to_dc_func_) << "Missing RenderPDFPageToDC"; 152 LOG_IF(WARNING, !render_pdf_to_dc_func_) << "Missing RenderPDFPageToDC";
199 153
200 return render_pdf_to_dc_func_ != NULL; 154 return render_pdf_to_dc_func_ != NULL;
201 } 155 }
202 156
203 bool RenderPDFPageToDC(const void* pdf_buffer, 157 bool RenderPDFPageToDC(const void* pdf_buffer,
204 int buffer_size, 158 int buffer_size,
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 &printer_info)) { 474 &printer_info)) {
521 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded( 475 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded(
522 printer_name, printer_info)); 476 printer_name, printer_info));
523 } else { 477 } else {
524 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed( 478 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed(
525 printer_name)); 479 printer_name));
526 } 480 }
527 ReleaseProcessIfNeeded(); 481 ReleaseProcessIfNeeded();
528 } 482 }
529 #endif // ENABLE_PRINT_PREVIEW 483 #endif // ENABLE_PRINT_PREVIEW
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698