From dc0e4390c0364515fa360c5292a4389784580a48 Mon Sep 17 00:00:00 2001 From: jam Date: Wed, 4 Feb 2015 09:40:04 -0800 Subject: [PATCH] Combine PDF plugin into the Chromium binary. On Windows, this moves it to chrome_child.dll. Overall binary sizes is 4.5 MB smaller (chrome_child.dll gets 3.6 MB larger while we drop the 8.1 MB pdf.dll). On Mac, the binary is 6.6 MB smaller. On Linux, it's 7MB smaller. This is from official release builds, after stripping on Linux. The size savings are because we don't ship duplicate versions of V8, and also the PDF plugin uses some of base and net. This depends on OOP PDF, since otherwise the V8 isolates for the plugin and Blink interact badly. That got turned on a few weeks ago. BUG=453844 Review URL: https://codereview.chromium.org/799643004 Cr-Commit-Position: refs/heads/master@{#314575} --- build/all.gyp | 1 - chrome/BUILD.gn | 10 +- chrome/DEPS | 1 + chrome/app/chrome_main_delegate.cc | 11 + .../file_manager/open_with_browser.cc | 5 +- chrome/browser/extensions/component_loader.cc | 7 +- .../print_preview_dialog_controller.cc | 5 +- ...print_preview_pdf_generated_browsertest.cc | 103 ++------- .../resources/pdf/pdf_extension_test.cc | 5 - chrome/child/pdf_child_init.cc | 23 +- chrome/chrome.isolate | 2 - chrome/chrome_dll.gypi | 13 +- chrome/chrome_dll_bundle.gypi | 4 - chrome/chrome_exe.gypi | 19 +- chrome/chrome_tests.gypi | 1 - chrome/chrome_tests_unit.gypi | 3 + chrome/common/chrome_content_client.cc | 72 +++---- chrome/common/chrome_content_client.h | 8 + .../common/chrome_content_client_constants.cc | 6 + chrome/common/chrome_paths.cc | 15 -- chrome/common/chrome_paths.h | 1 - chrome/test/BUILD.gn | 2 +- .../utility/chrome_content_utility_client.cc | 4 - chrome/utility/printing_handler.cc | 201 ++---------------- chrome/utility/printing_handler.h | 2 - pdf/BUILD.gn | 30 +-- pdf/Info.plist | 44 ---- pdf/pdf.cc | 157 +++----------- pdf/pdf.def | 7 - pdf/pdf.gyp | 127 +---------- pdf/pdf.h | 89 ++++++++ pdf/pdf.rc | 104 --------- 32 files changed, 263 insertions(+), 819 deletions(-) delete mode 100644 pdf/Info.plist delete mode 100644 pdf/pdf.def delete mode 100644 pdf/pdf.rc diff --git a/build/all.gyp b/build/all.gyp index 90c01205f8f9b2..8556aa767f51bd 100644 --- a/build/all.gyp +++ b/build/all.gyp @@ -750,7 +750,6 @@ 'dependencies': [ '../chrome/chrome_syzygy.gyp:chrome_dll_syzygy', '../content/content_shell_and_tests.gyp:content_shell_syzyasan', - '../pdf/pdf.gyp:pdf_syzyasan', ], 'conditions': [ ['chrome_multiple_dll==1', { diff --git a/chrome/BUILD.gn b/chrome/BUILD.gn index 2f4ed9eb6f8fb1..6deb300898f0bb 100644 --- a/chrome/BUILD.gn +++ b/chrome/BUILD.gn @@ -154,10 +154,8 @@ if (!is_android && (!is_win || link_chrome_on_windows)) { # TODO(GYP) some stuff from GYP including chrome_multiple_dll. } - if (!is_mac) { - # On Mac this is done in chrome_dll.gypi. - datadeps += [ "//pdf" ] - # TODO(GYP) pdf linux symbols + if (enable_plugins) { + deps += [ "//pdf" ] } } } # !is_android @@ -241,6 +239,10 @@ if (!is_win || link_chrome_on_windows) { #}], # TODO(GYP) Lots of other stuff in the OS=="mac" block. } + + if (enable_plugins) { + deps += [ "//pdf" ] + } } } diff --git a/chrome/DEPS b/chrome/DEPS index 9c9599244f08dc..e014b07fb5ac51 100644 --- a/chrome/DEPS +++ b/chrome/DEPS @@ -2,6 +2,7 @@ include_rules = [ "+crypto", "+gpu", "+net", + "+pdf", "+printing", "+sql", # Browser, renderer, common and tests access V8 for various purposes. diff --git a/chrome/app/chrome_main_delegate.cc b/chrome/app/chrome_main_delegate.cc index 608d513c19c468..7a840221a2a8c9 100644 --- a/chrome/app/chrome_main_delegate.cc +++ b/chrome/app/chrome_main_delegate.cc @@ -119,6 +119,11 @@ #include "remoting/client/plugin/pepper_entrypoints.h" #endif +#if defined(ENABLE_PLUGINS) && (defined(CHROME_MULTIPLE_DLL_CHILD) || \ + !defined(CHROME_MULTIPLE_DLL_BROWSER)) +#include "pdf/pdf.h" +#endif + #if !defined(CHROME_MULTIPLE_DLL_BROWSER) #include "chrome/child/pdf_child_init.h" @@ -826,6 +831,12 @@ void ChromeMainDelegate::SandboxInitialized(const std::string& process_type) { nacl_plugin::PPP_InitializeModule, nacl_plugin::PPP_ShutdownModule); #endif +#if defined(ENABLE_PLUGINS) + ChromeContentClient::SetPDFEntryFunctions( + chrome_pdf::PPP_GetInterface, + chrome_pdf::PPP_InitializeModule, + chrome_pdf::PPP_ShutdownModule); +#endif #endif } diff --git a/chrome/browser/chromeos/file_manager/open_with_browser.cc b/chrome/browser/chromeos/file_manager/open_with_browser.cc index 974b34a02d618c..7384caf32085c2 100644 --- a/chrome/browser/chromeos/file_manager/open_with_browser.cc +++ b/chrome/browser/chromeos/file_manager/open_with_browser.cc @@ -21,6 +21,7 @@ #include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "content/public/browser/browser_thread.h" @@ -86,8 +87,8 @@ bool IsPepperPluginEnabled(Profile* profile, bool IsPdfPluginEnabled(Profile* profile) { DCHECK(profile); - base::FilePath plugin_path; - PathService::Get(chrome::FILE_PDF_PLUGIN, &plugin_path); + base::FilePath plugin_path = base::FilePath::FromUTF8Unsafe( + ChromeContentClient::kPDFPluginPath); return IsPepperPluginEnabled(profile, plugin_path); } diff --git a/chrome/browser/extensions/component_loader.cc b/chrome/browser/extensions/component_loader.cc index 3841dba2ef8347..2ee48167a4bf1d 100644 --- a/chrome/browser/extensions/component_loader.cc +++ b/chrome/browser/extensions/component_loader.cc @@ -626,12 +626,7 @@ void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages( #endif // defined(GOOGLE_CHROME_BUILD) #if defined(ENABLE_PLUGINS) - base::FilePath pdf_path; - content::PluginService* plugin_service = - content::PluginService::GetInstance(); - if (switches::OutOfProcessPdfEnabled() && - PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path) && - plugin_service->GetRegisteredPpapiPluginInfo(pdf_path)) { + if (switches::OutOfProcessPdfEnabled()) { if (switches::PdfMaterialUIEnabled()) Add(IDR_PDF_MANIFEST_MATERIAL, base::FilePath(FILE_PATH_LITERAL("pdf"))); else diff --git a/chrome/browser/printing/print_preview_dialog_controller.cc b/chrome/browser/printing/print_preview_dialog_controller.cc index 1075f61ad69c8e..ad996d32bce4f6 100644 --- a/chrome/browser/printing/print_preview_dialog_controller.cc +++ b/chrome/browser/printing/print_preview_dialog_controller.cc @@ -52,9 +52,8 @@ namespace { void EnableInternalPDFPluginForContents(WebContents* preview_dialog) { // Always enable the internal PDF plugin for the print preview page. - base::FilePath pdf_plugin_path; - if (!PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_plugin_path)) - return; + base::FilePath pdf_plugin_path = base::FilePath::FromUTF8Unsafe( + ChromeContentClient::kPDFPluginPath); content::WebPluginInfo pdf_plugin; if (!content::PluginService::GetInstance()->GetPluginInfoByPath( diff --git a/chrome/browser/printing/print_preview_pdf_generated_browsertest.cc b/chrome/browser/printing/print_preview_pdf_generated_browsertest.cc index 367a92d3f4b9b4..f6a93216df9a52 100644 --- a/chrome/browser/printing/print_preview_pdf_generated_browsertest.cc +++ b/chrome/browser/printing/print_preview_pdf_generated_browsertest.cc @@ -22,7 +22,6 @@ #include "base/memory/scoped_ptr.h" #include "base/path_service.h" #include "base/run_loop.h" -#include "base/scoped_native_library.h" #include "base/strings/string_split.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/printing/print_preview_dialog_controller.h" @@ -39,6 +38,7 @@ #include "content/public/test/browser_test_utils.h" #include "ipc/ipc_message_macros.h" #include "net/base/filename_util.h" +#include "pdf/pdf.h" #include "printing/pdf_render_settings.h" #include "printing/units.h" #include "ui/gfx/codec/png_codec.h" @@ -323,33 +323,6 @@ class PrintPreviewPdfGeneratedBrowserTest : public InProcessBrowserTest { ASSERT_TRUE(pdf_file.IsValid()); } - // Initializes function pointers from the PDF library. Called once when the - // test starts. The library is closed when the browser test ends. - void InitPdfFunctions() { - base::FilePath pdf_module_path; - - ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_module_path)); - ASSERT_TRUE(base::PathExists(pdf_module_path)); - pdf_lib_.Reset(base::LoadNativeLibrary(pdf_module_path, NULL)); - - ASSERT_TRUE(pdf_lib_.is_valid()); - pdf_to_bitmap_func_ = - reinterpret_cast( - pdf_lib_.GetFunctionPointer("RenderPDFPageToBitmap")); - - pdf_doc_info_func_ = - reinterpret_cast( - pdf_lib_.GetFunctionPointer("GetPDFDocInfo")); - - pdf_page_size_func_ = - reinterpret_cast( - pdf_lib_.GetFunctionPointer("GetPDFPageSizeByIndex")); - - ASSERT_TRUE(pdf_to_bitmap_func_); - ASSERT_TRUE(pdf_doc_info_func_); - ASSERT_TRUE(pdf_page_size_func_); - } - // Converts the PDF to a PNG file so that the layout test can do an image // diff on this image and a reference image. void PdfToPng() { @@ -360,10 +333,10 @@ class PrintPreviewPdfGeneratedBrowserTest : public InProcessBrowserTest { std::string pdf_data; ASSERT_TRUE(base::ReadFileToString(pdf_file_save_path_, &pdf_data)); - ASSERT_TRUE(pdf_doc_info_func_(pdf_data.data(), - pdf_data.size(), - &num_pages, - &max_width_in_points)); + ASSERT_TRUE(chrome_pdf::GetPDFDocInfo(pdf_data.data(), + pdf_data.size(), + &num_pages, + &max_width_in_points)); ASSERT_GT(num_pages, 0); double max_width_in_pixels = @@ -371,11 +344,11 @@ class PrintPreviewPdfGeneratedBrowserTest : public InProcessBrowserTest { for (int i = 0; i < num_pages; ++i) { double width_in_points, height_in_points; - ASSERT_TRUE(pdf_page_size_func_(pdf_data.data(), - pdf_data.size(), - i, - &width_in_points, - &height_in_points)); + ASSERT_TRUE(chrome_pdf::GetPDFPageSizeByIndex(pdf_data.data(), + pdf_data.size(), + i, + &width_in_points, + &height_in_points)); double width_in_pixels = ConvertUnitDouble( width_in_points, kPointsPerInch, kDpi); @@ -405,15 +378,15 @@ class PrintPreviewPdfGeneratedBrowserTest : public InProcessBrowserTest { std::vector page_bitmap_data( kColorChannels * settings.area().size().GetArea()); - ASSERT_TRUE(pdf_to_bitmap_func_(pdf_data.data(), - pdf_data.size(), - i, - page_bitmap_data.data(), - settings.area().size().width(), - settings.area().size().height(), - settings.dpi(), - settings.dpi(), - true)); + ASSERT_TRUE(chrome_pdf::RenderPDFPageToBitmap( + pdf_data.data(), + pdf_data.size(), + i, + page_bitmap_data.data(), + settings.area().size().width(), + settings.area().size().height(), + settings.dpi(), + true)); FillPng(&page_bitmap_data, width_in_pixels, max_width_in_pixels, @@ -572,41 +545,6 @@ class PrintPreviewPdfGeneratedBrowserTest : public InProcessBrowserTest { scoped_ptr print_preview_observer_; base::FilePath pdf_file_save_path_; - // These typedefs are function pointers to pdflib functions that give - // information about the PDF as a whole and about specific pages. - - // Converts the PDF to a bitmap. - typedef bool (*PDFPageToBitmapProc)(const void* pdf_buffer, - int pdf_buffer_size, - int page_number, - void* bitmap_buffer, - int bitmap_width, - int bitmap_height, - int dpi_x, - int dpi_y, - bool autorotate); - - // Gets the page count and maximum page width of the PDF in points. - typedef bool (*GetPDFDocInfoProc)(const void* pdf_buffer, - int buffer_size, - int* pages_count, - double* max_page_width); - - // Gets the dimensions of a specific page within a PDF. - typedef bool (*GetPDFPageSizeByIndexProc)(const void* pdf_buffer, - int buffer_size, - int index, - double* width, - double* height); - - // Instantiations of the function pointers described above. - PDFPageToBitmapProc pdf_to_bitmap_func_; - GetPDFDocInfoProc pdf_doc_info_func_; - GetPDFPageSizeByIndexProc pdf_page_size_func_; - - // Used to open up the pdf plugin, which contains the functions above. - base::ScopedNativeLibrary pdf_lib_; - // Vector for storing the PNG to be sent to the layout test framework. // TODO(ivandavid): Eventually change this to uint32_t and make everything // work with that. It might be a bit tricky to fix everything to work with @@ -641,8 +579,7 @@ IN_PROC_BROWSER_TEST_F(PrintPreviewPdfGeneratedBrowserTest, // to send data to the browser test. Writing "EOF\n" to |std::cout| indicates // that whatever block of data that the test was expecting has been completely // sent. Sometimes EOF is printed to stderr because the test will expect it - // from stderr in addition to stdout for certain blocks of data. - InitPdfFunctions(); + // from stderr in addition to stdout for certain blocks of data.= SetupStdinAndSavePath(); while (true) { diff --git a/chrome/browser/resources/pdf/pdf_extension_test.cc b/chrome/browser/resources/pdf/pdf_extension_test.cc index 6a56a91427ab27..d89c474cfd53d9 100644 --- a/chrome/browser/resources/pdf/pdf_extension_test.cc +++ b/chrome/browser/resources/pdf/pdf_extension_test.cc @@ -41,11 +41,6 @@ class PDFExtensionTest : public ExtensionApiTest { } void RunTestsInFile(std::string filename, std::string pdf_filename) { - base::FilePath pdf_path; - ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path)); - ASSERT_TRUE( - content::PluginService::GetInstance()->GetRegisteredPpapiPluginInfo( - pdf_path)); ExtensionService* service = extensions::ExtensionSystem::Get( profile())->extension_service(); service->component_loader()->Add(IDR_PDF_MANIFEST, diff --git a/chrome/child/pdf_child_init.cc b/chrome/child/pdf_child_init.cc index ac17072a22aa3e..338403cc71726c 100644 --- a/chrome/child/pdf_child_init.cc +++ b/chrome/child/pdf_child_init.cc @@ -59,15 +59,20 @@ 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 + HMODULE current_module = NULL; + wchar_t current_module_name[MAX_PATH]; + CHECK(GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, + reinterpret_cast(InitializePDF), + ¤t_module)); + DWORD result = GetModuleFileNameW(current_module, current_module_name, + MAX_PATH); + if (!result || result == MAX_PATH) + return; + g_iat_patch_createdca.Patch(current_module_name, "gdi32.dll", "CreateDCA", + CreateDCAPatch); + g_iat_patch_get_font_data.Patch(current_module_name, "gdi32.dll", + "GetFontData", GetFontDataPatch); +#endif // OS_WIN } } // namespace chrome diff --git a/chrome/chrome.isolate b/chrome/chrome.isolate index 9ebce299e77356..64ae23074e5d62 100644 --- a/chrome/chrome.isolate +++ b/chrome/chrome.isolate @@ -8,7 +8,6 @@ 'files': [ '<(PRODUCT_DIR)/libffmpegsumo.so', '<(PRODUCT_DIR)/libosmesa.so', - '<(PRODUCT_DIR)/libpdf.so', ], }, }], @@ -88,7 +87,6 @@ '<(PRODUCT_DIR)/ffmpegsumo.dll', '<(PRODUCT_DIR)/libexif.dll', '<(PRODUCT_DIR)/osmesa.dll', - '<(PRODUCT_DIR)/pdf.dll', ], }, }], diff --git a/chrome/chrome_dll.gypi b/chrome/chrome_dll.gypi index 024f34dbf3bcda..08856685b0ca10 100644 --- a/chrome/chrome_dll.gypi +++ b/chrome/chrome_dll.gypi @@ -256,6 +256,11 @@ '../content/content.gyp:content_app_browser', ], }], + ['chrome_multiple_dll==0 and enable_plugins==1', { + 'dependencies': [ + '../pdf/pdf.gyp:pdf', + ], + }], ['cld_version==1', { 'dependencies': [ '<(DEPTH)/third_party/cld/cld.gyp:cld', @@ -278,9 +283,6 @@ # sets -order_file. 'ORDER_FILE': 'app/framework.order', }, - 'dependencies': [ - '../pdf/pdf.gyp:pdf', - ], 'include_dirs': [ '<(grit_out_dir)', ], @@ -372,6 +374,11 @@ }], ] }], + ['enable_plugins==1', { + 'dependencies': [ + '../pdf/pdf.gyp:pdf', + ], + }], ], }, # target chrome_child_dll ], diff --git a/chrome/chrome_dll_bundle.gypi b/chrome/chrome_dll_bundle.gypi index c522f2f29e4386..dd01c0104ecf92 100644 --- a/chrome/chrome_dll_bundle.gypi +++ b/chrome/chrome_dll_bundle.gypi @@ -76,7 +76,6 @@ # Bring in pdfsqueeze and run it on all pdfs '../build/temp_gyp/pdfsqueeze.gyp:pdfsqueeze', '../crypto/crypto.gyp:crypto', - '../pdf/pdf.gyp:pdf', # On Mac, Flash gets put into the framework, so we need this # dependency here. flash_player.gyp will copy the Flash bundle # into PRODUCT_DIR. @@ -147,9 +146,6 @@ }, { 'destination': '<(PRODUCT_DIR)/$(CONTENTS_FOLDER_PATH)/Internet Plug-Ins', - 'files': [ - '<(PRODUCT_DIR)/PDF.plugin', - ], 'conditions': [ ['disable_nacl!=1', { 'conditions': [ diff --git a/chrome/chrome_exe.gypi b/chrome/chrome_exe.gypi index 46c84f9883347a..2713e9b16ced67 100644 --- a/chrome/chrome_exe.gypi +++ b/chrome/chrome_exe.gypi @@ -190,6 +190,11 @@ '../build/linux/system.gyp:xext', ], }], + ['enable_plugins==1', { + 'dependencies': [ + '../pdf/pdf.gyp:pdf', + ], + }], ], 'sources': [ 'app/chrome_dll_resource.h', @@ -428,20 +433,6 @@ # NOTE: chrome/app/theme/chromium/BRANDING and # chrome/app/theme/google_chrome/BRANDING have the short name # "chrome" etc.; should we try to extract from there instead? - - # CrOS does this in a separate build step. - ['OS=="linux" and chromeos==0 and linux_dump_symbols==1', { - 'dependencies': [ - '../pdf/pdf.gyp:pdf_linux_symbols', - ], - }], # OS=="linux" and chromeos==0 and linux_dump_symbols==1 - # Android doesn't use pdfium. - ['OS!="android"', { - 'dependencies': [ - # On Mac, this is done in chrome_dll.gypi. - '../pdf/pdf.gyp:pdf', - ], - }], # OS=="android" ], 'dependencies': [ '../components/components.gyp:startup_metric_utils', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index fcc837a493e92a..5a2a068e4fc127 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1451,7 +1451,6 @@ '../net/net.gyp:net', '../net/net.gyp:net_resources', '../net/net.gyp:net_test_support', - '../pdf/pdf.gyp:pdf', '../ppapi/ppapi_internal.gyp:ppapi_tests', '../skia/skia.gyp:skia', '../sync/sync.gyp:sync', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index b96db22cc944a6..1f17749be97284 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -1986,6 +1986,9 @@ 'test/ppapi/ppapi_test.cc', 'test/ppapi/ppapi_test.h', ], + 'dependencies': [ + '../pdf/pdf.gyp:pdf', + ], }], ['enable_plugins==1 and disable_nacl==0', { 'dependencies': [ diff --git a/chrome/common/chrome_content_client.cc b/chrome/common/chrome_content_client.cc index 587b2aaa95fbbf..21df9e0766b6c2 100644 --- a/chrome/common/chrome_content_client.cc +++ b/chrome/common/chrome_content_client.cc @@ -64,11 +64,8 @@ namespace { #if defined(ENABLE_PLUGINS) -const char kPDFPluginMimeType[] = "application/pdf"; const char kPDFPluginExtension[] = "pdf"; const char kPDFPluginDescription[] = "Portable Document Format"; -const char kPDFPluginPrintPreviewMimeType[] = - "application/x-google-chrome-print-preview-pdf"; const char kPDFPluginOutOfProcessMimeType[] = "application/x-google-chrome-pdf"; const uint32 kPDFPluginPermissions = ppapi::PERMISSION_PRIVATE | @@ -95,6 +92,10 @@ const char kGTalkPluginDescription[] = "Google Talk Plugin"; const uint32 kGTalkPluginPermissions = ppapi::PERMISSION_PRIVATE | ppapi::PERMISSION_DEV; +content::PepperPluginInfo::GetInterfaceFunc g_pdf_get_interface; +content::PepperPluginInfo::PPP_InitializeModuleFunc g_pdf_initialize_module; +content::PepperPluginInfo::PPP_ShutdownModuleFunc g_pdf_shutdown_module; + #if defined(ENABLE_REMOTING) content::PepperPluginInfo::GetInterfaceFunc g_remoting_get_interface; @@ -133,43 +134,25 @@ content::PepperPluginInfo::PPP_ShutdownModuleFunc g_nacl_shutdown_module; // not marked internal, aside from being automatically registered, they're just // regular plugins). void ComputeBuiltInPlugins(std::vector* plugins) { - // PDF. - // - // Once we're sandboxed, we can't know if the PDF plugin is available or not; - // but (on Linux) this function is always called once before we're sandboxed. - // So the first time through test if the file is available and then skip the - // check on subsequent calls if yes. - static bool skip_pdf_file_check = false; + content::PepperPluginInfo pdf_info; + pdf_info.is_internal = true; + pdf_info.is_out_of_process = true; + pdf_info.name = ChromeContentClient::kPDFPluginName; + pdf_info.description = kPDFPluginDescription; + pdf_info.path = base::FilePath::FromUTF8Unsafe( + ChromeContentClient::kPDFPluginPath); + content::WebPluginMimeType pdf_mime_type( + kPDFPluginOutOfProcessMimeType, + kPDFPluginExtension, + kPDFPluginDescription); + pdf_info.mime_types.push_back(pdf_mime_type); + pdf_info.internal_entry_points.get_interface = g_pdf_get_interface; + pdf_info.internal_entry_points.initialize_module = g_pdf_initialize_module; + pdf_info.internal_entry_points.shutdown_module = g_pdf_shutdown_module; + pdf_info.permissions = kPDFPluginPermissions; + plugins->push_back(pdf_info); + base::FilePath path; - if (PathService::Get(chrome::FILE_PDF_PLUGIN, &path)) { - if (skip_pdf_file_check || base::PathExists(path)) { - content::PepperPluginInfo pdf; - pdf.path = path; - pdf.name = ChromeContentClient::kPDFPluginName; - if (switches::OutOfProcessPdfEnabled()) { - pdf.is_out_of_process = true; - content::WebPluginMimeType pdf_mime_type(kPDFPluginOutOfProcessMimeType, - kPDFPluginExtension, - kPDFPluginDescription); - pdf.mime_types.push_back(pdf_mime_type); - // TODO(raymes): Make print preview work with out of process PDF. - } else { - content::WebPluginMimeType pdf_mime_type(kPDFPluginMimeType, - kPDFPluginExtension, - kPDFPluginDescription); - content::WebPluginMimeType print_preview_pdf_mime_type( - kPDFPluginPrintPreviewMimeType, - kPDFPluginExtension, - kPDFPluginDescription); - pdf.mime_types.push_back(pdf_mime_type); - pdf.mime_types.push_back(print_preview_pdf_mime_type); - } - pdf.permissions = kPDFPluginPermissions; - plugins->push_back(pdf); - - skip_pdf_file_check = true; - } - } #if !defined(DISABLE_NACL) // Handle Native Client just like the PDF plugin. This means that it is @@ -454,6 +437,17 @@ void ChromeContentClient::SetNaClEntryFunctions( } #endif +#if defined(ENABLE_PLUGINS) +void ChromeContentClient::SetPDFEntryFunctions( + content::PepperPluginInfo::GetInterfaceFunc get_interface, + content::PepperPluginInfo::PPP_InitializeModuleFunc initialize_module, + content::PepperPluginInfo::PPP_ShutdownModuleFunc shutdown_module) { + g_pdf_get_interface = get_interface; + g_pdf_initialize_module = initialize_module; + g_pdf_shutdown_module = shutdown_module; +} +#endif + void ChromeContentClient::SetActiveURL(const GURL& url) { base::debug::SetCrashKeyValue(crash_keys::kActiveURL, url.possibly_invalid_spec()); diff --git a/chrome/common/chrome_content_client.h b/chrome/common/chrome_content_client.h index 968db7c4571e78..fd00d31722aad9 100644 --- a/chrome/common/chrome_content_client.h +++ b/chrome/common/chrome_content_client.h @@ -22,6 +22,7 @@ std::string GetUserAgent(); class ChromeContentClient : public content::ContentClient { public: static const char* const kPDFPluginName; + static const char* const kPDFPluginPath; static const char* const kRemotingViewerPluginPath; // The methods below are called by child processes to set the function @@ -42,6 +43,13 @@ class ChromeContentClient : public content::ContentClient { content::PepperPluginInfo::PPP_ShutdownModuleFunc shutdown_module); #endif +#if defined(ENABLE_PLUGINS) + static void SetPDFEntryFunctions( + content::PepperPluginInfo::GetInterfaceFunc get_interface, + content::PepperPluginInfo::PPP_InitializeModuleFunc initialize_module, + content::PepperPluginInfo::PPP_ShutdownModuleFunc shutdown_module); +#endif + void SetActiveURL(const GURL& url) override; void SetGpuInfo(const gpu::GPUInfo& gpu_info) override; void AddPepperPlugins( diff --git a/chrome/common/chrome_content_client_constants.cc b/chrome/common/chrome_content_client_constants.cc index aeda5340e33fb6..f0a59f8782aab6 100644 --- a/chrome/common/chrome_content_client_constants.cc +++ b/chrome/common/chrome_content_client_constants.cc @@ -4,6 +4,12 @@ #include "chrome/common/chrome_content_client.h" +#if defined(GOOGLE_CHROME_BUILD) const char* const ChromeContentClient::kPDFPluginName = "Chrome PDF Viewer"; +#else +const char* const ChromeContentClient::kPDFPluginName = "Chromium PDF Viewer"; +#endif +const char* const ChromeContentClient::kPDFPluginPath = + "internal-pdf-viewer"; const char* const ChromeContentClient::kRemotingViewerPluginPath = "internal-remoting-viewer"; diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc index af56236b4ed642..9537376b47f4e2 100644 --- a/chrome/common/chrome_paths.cc +++ b/chrome/common/chrome_paths.cc @@ -50,16 +50,6 @@ const base::FilePath::CharType kPepperFlashDebuggerBaseDirectory[] = FILE_PATH_LITERAL("Macromed\\Flash"); #endif -// File name of the internal PDF plugin on different platforms. -const base::FilePath::CharType kInternalPDFPluginFileName[] = -#if defined(OS_WIN) - FILE_PATH_LITERAL("pdf.dll"); -#elif defined(OS_MACOSX) - FILE_PATH_LITERAL("PDF.plugin"); -#else // Linux and Chrome OS - FILE_PATH_LITERAL("libpdf.so"); -#endif - const base::FilePath::CharType kInternalNaClPluginFileName[] = FILE_PATH_LITERAL("internal-nacl-plugin"); @@ -294,11 +284,6 @@ bool PathProvider(int key, base::FilePath* result) { return false; cur = cur.Append(chrome::kPepperFlashPluginFilename); break; - case chrome::FILE_PDF_PLUGIN: - if (!GetInternalPluginsDirectory(&cur)) - return false; - cur = cur.Append(kInternalPDFPluginFileName); - break; case chrome::FILE_EFFECTS_PLUGIN: if (!GetInternalPluginsDirectory(&cur)) return false; diff --git a/chrome/common/chrome_paths.h b/chrome/common/chrome_paths.h index a22600edd83865..34c85fb454d60e 100644 --- a/chrome/common/chrome_paths.h +++ b/chrome/common/chrome_paths.h @@ -83,7 +83,6 @@ enum { // matter the file exists or not. FILE_PEPPER_FLASH_PLUGIN, // Full path to the bundled Pepper Flash plugin // file. - FILE_PDF_PLUGIN, // Full path to the internal PDF plugin file. FILE_NACL_PLUGIN, // Full path to the internal NaCl plugin file. DIR_PNACL_BASE, // Full path to the base dir for PNaCl. diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn index 4389f3e1446c1d..1c24f058180d40 100644 --- a/chrome/test/BUILD.gn +++ b/chrome/test/BUILD.gn @@ -176,6 +176,7 @@ source_set("test_support") { "ppapi/ppapi_test.cc", "ppapi/ppapi_test.h", ] + deps += [ "//pdf" ] } if (use_ash) { @@ -247,7 +248,6 @@ if (!is_android && (!is_win || link_chrome_on_windows)) { "//net", "//net:net_resources", "//net:test_support", - "//pdf", #"//ppapi:ppapi_tests", # TODO(GYP) this doesn't exist yet. "//skia", diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc index e06aebce71accb..843b1f37ea8803 100644 --- a/chrome/utility/chrome_content_utility_client.cc +++ b/chrome/utility/chrome_content_utility_client.cc @@ -166,10 +166,6 @@ void ChromeContentUtilityClient::PreSandboxStartup() { extensions::ExtensionsHandler::PreSandboxStartup(); #endif -#if defined(ENABLE_PRINT_PREVIEW) || defined(OS_WIN) - PrintingHandler::PreSandboxStartup(); -#endif - #if defined(ENABLE_MDNS) if (base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kUtilityProcessEnableMDns)) { diff --git a/chrome/utility/printing_handler.cc b/chrome/utility/printing_handler.cc index 3dd8e923b6c6e4..9e282adb467725 100644 --- a/chrome/utility/printing_handler.cc +++ b/chrome/utility/printing_handler.cc @@ -13,6 +13,7 @@ #include "chrome/utility/cloud_print/bitmap_image.h" #include "chrome/utility/cloud_print/pwg_encoder.h" #include "content/public/utility/utility_thread.h" +#include "pdf/pdf.h" #include "printing/page_range.h" #include "printing/pdf_render_settings.h" @@ -36,180 +37,12 @@ void ReleaseProcessIfNeeded() { content::UtilityThread::Get()->ReleaseProcessIfNeeded(); } -class PdfFunctionsBase { - public: - PdfFunctionsBase() : render_pdf_to_bitmap_func_(NULL), - get_pdf_doc_info_func_(NULL) {} - - bool Init() { - base::FilePath pdf_module_path; - if (!PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_module_path) || - !base::PathExists(pdf_module_path)) { - return false; - } - - pdf_lib_.Reset(base::LoadNativeLibrary(pdf_module_path, NULL)); - if (!pdf_lib_.is_valid()) { - LOG(WARNING) << "Couldn't load PDF plugin"; - return false; - } - - render_pdf_to_bitmap_func_ = - reinterpret_cast( - pdf_lib_.GetFunctionPointer("RenderPDFPageToBitmap")); - LOG_IF(WARNING, !render_pdf_to_bitmap_func_) << - "Missing RenderPDFPageToBitmap"; - - get_pdf_doc_info_func_ = - reinterpret_cast( - pdf_lib_.GetFunctionPointer("GetPDFDocInfo")); - LOG_IF(WARNING, !get_pdf_doc_info_func_) << "Missing GetPDFDocInfo"; - - if (!render_pdf_to_bitmap_func_ || !get_pdf_doc_info_func_ || - !PlatformInit(pdf_module_path, pdf_lib_)) { - Reset(); - } - - return IsValid(); - } - - bool IsValid() const { - return pdf_lib_.is_valid(); - } - - void Reset() { - pdf_lib_.Reset(NULL); - } - - bool RenderPDFPageToBitmap(const void* pdf_buffer, - int pdf_buffer_size, - int page_number, - void* bitmap_buffer, - int bitmap_width, - int bitmap_height, - int dpi_x, - int dpi_y, - bool autorotate) { - if (!render_pdf_to_bitmap_func_) - return false; - return render_pdf_to_bitmap_func_(pdf_buffer, pdf_buffer_size, page_number, - bitmap_buffer, bitmap_width, - bitmap_height, dpi_x, dpi_y, autorotate); - } - - bool GetPDFDocInfo(const void* pdf_buffer, - int buffer_size, - int* page_count, - double* max_page_width) { - if (!get_pdf_doc_info_func_) - return false; - return get_pdf_doc_info_func_(pdf_buffer, buffer_size, page_count, - max_page_width); - } - - protected: - virtual bool PlatformInit( - const base::FilePath& pdf_module_path, - const base::ScopedNativeLibrary& pdf_lib) { - return true; - } - - private: - // Exported by PDF plugin. - typedef bool (*RenderPDFPageToBitmapProc)(const void* pdf_buffer, - int pdf_buffer_size, - int page_number, - void* bitmap_buffer, - int bitmap_width, - int bitmap_height, - int dpi_x, - int dpi_y, - bool autorotate); - typedef bool (*GetPDFDocInfoProc)(const void* pdf_buffer, - int buffer_size, int* page_count, - double* max_page_width); - - RenderPDFPageToBitmapProc render_pdf_to_bitmap_func_; - GetPDFDocInfoProc get_pdf_doc_info_func_; - - base::ScopedNativeLibrary pdf_lib_; - DISALLOW_COPY_AND_ASSIGN(PdfFunctionsBase); -}; - -#if defined(OS_WIN) - -class PdfFunctionsWin : public PdfFunctionsBase { - public: - PdfFunctionsWin() : render_pdf_to_dc_func_(NULL) { - } - - bool PlatformInit( - const base::FilePath& pdf_module_path, - const base::ScopedNativeLibrary& pdf_lib) override { - render_pdf_to_dc_func_ = - reinterpret_cast( - pdf_lib.GetFunctionPointer("RenderPDFPageToDC")); - LOG_IF(WARNING, !render_pdf_to_dc_func_) << "Missing RenderPDFPageToDC"; - - return render_pdf_to_dc_func_ != NULL; - } - - bool RenderPDFPageToDC(const void* pdf_buffer, - int buffer_size, - int page_number, - HDC dc, - int dpi_x, - int dpi_y, - int bounds_origin_x, - int bounds_origin_y, - int bounds_width, - int bounds_height, - bool fit_to_bounds, - bool stretch_to_bounds, - bool keep_aspect_ratio, - bool center_in_bounds, - bool autorotate) { - if (!render_pdf_to_dc_func_) - return false; - return render_pdf_to_dc_func_(pdf_buffer, buffer_size, page_number, - dc, dpi_x, dpi_y, bounds_origin_x, - bounds_origin_y, bounds_width, bounds_height, - fit_to_bounds, stretch_to_bounds, - keep_aspect_ratio, center_in_bounds, - autorotate); - } - - private: - // Exported by PDF plugin. - typedef bool (*RenderPDFPageToDCProc)( - const void* pdf_buffer, int buffer_size, int page_number, HDC dc, - int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, - int bounds_width, int bounds_height, bool fit_to_bounds, - bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds, - bool autorotate); - RenderPDFPageToDCProc render_pdf_to_dc_func_; - - DISALLOW_COPY_AND_ASSIGN(PdfFunctionsWin); -}; - -typedef PdfFunctionsWin PdfFunctions; -#else // OS_WIN -typedef PdfFunctionsBase PdfFunctions; -#endif // OS_WIN - -base::LazyInstance g_pdf_lib = LAZY_INSTANCE_INITIALIZER; - } // namespace PrintingHandler::PrintingHandler() {} PrintingHandler::~PrintingHandler() {} -// static -void PrintingHandler::PreSandboxStartup() { - g_pdf_lib.Get().Init(); -} - bool PrintingHandler::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PrintingHandler, message) @@ -282,9 +115,6 @@ void PrintingHandler::OnRenderPDFPagesToPWGRaster( #if defined(OS_WIN) int PrintingHandler::LoadPDF(base::File pdf_file) { - if (!g_pdf_lib.Get().IsValid()) - return 0; - int64 length64 = pdf_file.GetLength(); if (length64 <= 0 || length64 > std::numeric_limits::max()) return 0; @@ -295,7 +125,7 @@ int PrintingHandler::LoadPDF(base::File pdf_file) { return 0; int total_page_count = 0; - if (!g_pdf_lib.Get().GetPDFDocInfo( + if (!chrome_pdf::GetPDFDocInfo( &pdf_data_.front(), pdf_data_.size(), &total_page_count, NULL)) { return 0; } @@ -324,13 +154,12 @@ bool PrintingHandler::RenderPdfPageToMetafile(int page_number, // The underlying metafile is of type Emf and ignores the arguments passed // to StartPage. metafile.StartPage(gfx::Size(), gfx::Rect(), 1); - if (!g_pdf_lib.Get().RenderPDFPageToDC( + if (!chrome_pdf::RenderPDFPageToDC( &pdf_data_.front(), pdf_data_.size(), page_number, metafile.context(), pdf_rendering_settings_.dpi(), - pdf_rendering_settings_.dpi(), pdf_rendering_settings_.area().x(), pdf_rendering_settings_.area().y(), pdf_rendering_settings_.area().width(), @@ -356,9 +185,6 @@ bool PrintingHandler::RenderPDFPagesToPWGRaster( const printing::PwgRasterSettings& bitmap_settings, base::File bitmap_file) { bool autoupdate = true; - if (!g_pdf_lib.Get().IsValid()) - return false; - base::File::Info info; if (!pdf_file.GetInfo(&info) || info.size <= 0 || info.size > std::numeric_limits::max()) @@ -370,8 +196,8 @@ bool PrintingHandler::RenderPDFPagesToPWGRaster( return false; int total_page_count = 0; - if (!g_pdf_lib.Get().GetPDFDocInfo(data.data(), data_size, - &total_page_count, NULL)) { + if (!chrome_pdf::GetPDFDocInfo(data.data(), data_size, + &total_page_count, NULL)) { return false; } @@ -392,15 +218,14 @@ bool PrintingHandler::RenderPDFPagesToPWGRaster( page_number = total_page_count - 1 - page_number; } - if (!g_pdf_lib.Get().RenderPDFPageToBitmap(data.data(), - data_size, - page_number, - image.pixel_data(), - image.size().width(), - image.size().height(), - settings.dpi(), - settings.dpi(), - autoupdate)) { + if (!chrome_pdf::RenderPDFPageToBitmap(data.data(), + data_size, + page_number, + image.pixel_data(), + image.size().width(), + image.size().height(), + settings.dpi(), + autoupdate)) { return false; } diff --git a/chrome/utility/printing_handler.h b/chrome/utility/printing_handler.h index cc490ba102625d..341a358c7ef859 100644 --- a/chrome/utility/printing_handler.h +++ b/chrome/utility/printing_handler.h @@ -27,8 +27,6 @@ class PrintingHandler : public UtilityMessageHandler { PrintingHandler(); ~PrintingHandler() override; - static void PreSandboxStartup(); - // IPC::Listener: bool OnMessageReceived(const IPC::Message& message) override; diff --git a/pdf/BUILD.gn b/pdf/BUILD.gn index b028290ba2dcb8..4ecd961fb9586e 100644 --- a/pdf/BUILD.gn +++ b/pdf/BUILD.gn @@ -4,8 +4,7 @@ pdf_engine = 0 # 0 PDFium -# TODO(GYP) need support for loadable modules -shared_library("pdf") { +static_library("pdf") { sources = [ "button.h", "button.cc", @@ -35,7 +34,6 @@ shared_library("pdf") { "paint_manager.h", "pdf.cc", "pdf.h", - "pdf.rc", "progress_control.cc", "progress_control.h", "pdf_engine.h", @@ -45,8 +43,6 @@ shared_library("pdf") { "resource_consts.h", "thumbnail_control.cc", "thumbnail_control.h", - "../components/ui/zoom/page_zoom_constants.cc", - "../content/common/page_zoom.cc", ] if (pdf_engine == 0) { @@ -68,33 +64,15 @@ shared_library("pdf") { } if (is_win) { - defines = [ "COMPILE_CONTENT_STATICALLY" ] cflags = [ "/wd4267" ] # TODO(jschuh) size_t to int truncations. } - if (is_mac) { - # TODO(GYP) - #'mac_bundle': 1, - #'product_name': 'PDF', - #'product_extension': 'plugin', - ## Strip the shipping binary of symbols so "Foxit" doesn't appear in - ## the binary. Symbols are stored in a separate .dSYM. - #'variables': { - # 'mac_real_dsym': 1, - #}, - #'sources+': [ - # 'Info.plist' - #] - #'xcode_settings': { - # 'INFOPLIST_FILE': 'Info.plist', - #}, - } - deps = [ "//base", + "//components/ui/zoom:ui_zoom", + "//content/public/common", "//net", - "//ppapi:ppapi_cpp", + "//ppapi:ppapi_internal_module", "//third_party/pdfium", ] } -# TODO(GYP) pdf_linux_symbols target. diff --git a/pdf/Info.plist b/pdf/Info.plist deleted file mode 100644 index 9f3dfdf834647c..00000000000000 --- a/pdf/Info.plist +++ /dev/null @@ -1,44 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIdentifier - org.chromium.pdf_plugin - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - BRPL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1.0 - CFPlugInDynamicRegisterFunction - - CFPlugInDynamicRegistration - NO - WebPluginDescription - Chrome PDF Viewer - WebPluginMIMETypes - - application/pdf - - WebPluginExtensions - - pdf - - WebPluginTypeDescription - Acrobat Portable Document Format - - - WebPluginName - Chrome PDF Viewer - - diff --git a/pdf/pdf.cc b/pdf/pdf.cc index d6c9863df7b1f3..7aba41229d3768 100644 --- a/pdf/pdf.cc +++ b/pdf/pdf.cc @@ -13,73 +13,12 @@ #include "pdf/instance.h" #include "pdf/out_of_process_instance.h" #include "ppapi/c/ppp.h" +#include "ppapi/cpp/private/internal_module.h" #include "ppapi/cpp/private/pdf.h" #include "v8/include/v8.h" bool g_sdk_initialized_via_pepper = false; -// The Mac release builds discard CreateModule and the entire PDFModule -// definition because they are not referenced here. This causes the Pepper -// exports (PPP_GetInterface etc) to not be exported. So we force the linker -// to include this code by using __attribute__((used)). -#if __GNUC__ >= 4 -#define PDF_USED __attribute__((used)) -#else -#define PDF_USED -#endif - -#if defined(OS_WIN) - -void HandleInvalidParameter(const wchar_t* expression, - const wchar_t* function, - const wchar_t* file, - unsigned int line, - uintptr_t reserved) { - // Do the same as Chrome's CHECK(false) which is undefined. - ::base::debug::BreakDebugger(); - return; -} - -void HandlePureVirtualCall() { - // Do the same as Chrome's CHECK(false) which is undefined. - ::base::debug::BreakDebugger(); - return; -} - - -BOOL APIENTRY DllMain(HMODULE module, DWORD reason_for_call, LPVOID reserved) { - if (reason_for_call == DLL_PROCESS_ATTACH) { - // On windows following handlers work only inside module. So breakpad in - // chrome.dll does not catch that. To avoid linking related code or - // duplication breakpad_win.cc::InitCrashReporter() just catch errors here - // and crash in a way interceptable by breakpad of parent module. - _set_invalid_parameter_handler(HandleInvalidParameter); - _set_purecall_handler(HandlePureVirtualCall); - -#if defined(ARCH_CPU_X86_64) && _MSC_VER <= 1800 - // VS2013's CRT only checks the existence of FMA3 instructions, not the - // enabled-ness of them at the OS level (this is fixed in VS2015). We force - // off usage of FMA3 instructions in the CRT to avoid using that path and - // hitting illegal instructions when running on CPUs that support FMA3, but - // OSs that don't. Because we use the static library CRT we have to call - // this function once in each DLL. - // See http://crbug.com/436603. - _set_FMA3_enable(0); -#endif // ARCH_CPU_X86_64 && _MSC_VER <= 1800 - } - return TRUE; -} - -#endif - -namespace pp { - -PDF_USED Module* CreateModule() { - return new chrome_pdf::PDFModule(); -} - -} // namespace pp - namespace chrome_pdf { PDFModule::PDFModule() { @@ -117,49 +56,37 @@ pp::Instance* PDFModule::CreateInstance(PP_Instance instance) { return new Instance(instance); } -} // namespace chrome_pdf -extern "C" { +// Implementation of Global PPP functions --------------------------------- +int32_t PPP_InitializeModule(PP_Module module_id, + PPB_GetInterface get_browser_interface) { + PDFModule* module = new PDFModule(); + if (!module->InternalInit(module_id, get_browser_interface)) { + delete module; + return PP_ERROR_FAILED; + } + + pp::InternalSetModuleSingleton(module); + return PP_OK; +} + +void PPP_ShutdownModule() { + delete pp::Module::Get(); + pp::InternalSetModuleSingleton(NULL); +} + +const void* PPP_GetInterface(const char* interface_name) { + if (!pp::Module::Get()) + return NULL; + return pp::Module::Get()->GetPluginInterface(interface_name); +} -// TODO(sanjeevr): It might make sense to provide more stateful wrappers over -// the internal PDF SDK (such as LoadDocument, LoadPage etc). Determine if we -// need to provide this. -// Wrapper exports over the PDF engine that can be used by an external module -// such as Chrome (since Chrome cannot directly pull in PDFium sources). #if defined(OS_WIN) -// |pdf_buffer| is the buffer that contains the entire PDF document to be -// rendered. -// |buffer_size| is the size of |pdf_buffer| in bytes. -// |page_number| is the 0-based index of the page to be rendered. -// |dc| is the device context to render into. -// |dpi_x| and |dpi_y| are the x and y resolutions respectively. If either -// value is -1, the dpi from the DC will be used. -// |bounds_origin_x|, |bounds_origin_y|, |bounds_width| and |bounds_height| -// specify a bounds rectangle within the DC in which to render the PDF -// page. -// |fit_to_bounds| specifies whether the output should be shrunk to fit the -// supplied bounds if the page size is larger than the bounds in any -// dimension. If this is false, parts of the PDF page that lie outside -// the bounds will be clipped. -// |stretch_to_bounds| specifies whether the output should be stretched to fit -// the supplied bounds if the page size is smaller than the bounds in any -// dimension. -// If both |fit_to_bounds| and |stretch_to_bounds| are true, then -// |fit_to_bounds| is honored first. -// |keep_aspect_ratio| If any scaling is to be done is true, this flag -// specifies whether the original aspect ratio of the page should be -// preserved while scaling. -// |center_in_bounds| specifies whether the final image (after any scaling is -// done) should be centered within the given bounds. -// |autorotate| specifies whether the final image should be rotated to match -// the output bound. -// Returns false if the document or the page number are not valid. -PP_EXPORT bool RenderPDFPageToDC(const void* pdf_buffer, +bool RenderPDFPageToDC(const void* pdf_buffer, int buffer_size, int page_number, HDC dc, - int dpi_x, - int dpi_y, + int dpi, int bounds_origin_x, int bounds_origin_y, int bounds_width, @@ -177,8 +104,8 @@ PP_EXPORT bool RenderPDFPageToDC(const void* pdf_buffer, scoped_ptr engine_exports( chrome_pdf::PDFEngineExports::Create()); chrome_pdf::PDFEngineExports::RenderingSettings settings( - dpi_x, dpi_y, pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, - bounds_height), + dpi, dpi, pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, + bounds_height), fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds, autorotate); bool ret = engine_exports->RenderPDFPageToDC(pdf_buffer, buffer_size, @@ -191,9 +118,6 @@ PP_EXPORT bool RenderPDFPageToDC(const void* pdf_buffer, #endif // OS_WIN -// |page_count| and |max_page_width| are optional and can be NULL. -// Returns false if the document is not valid. -PDF_USED PP_EXPORT bool GetPDFDocInfo(const void* pdf_buffer, int buffer_size, int* page_count, double* max_page_width) { @@ -211,16 +135,6 @@ bool GetPDFDocInfo(const void* pdf_buffer, return ret; } -// Gets the dimensions of a specific page in a document. -// |pdf_buffer| is the buffer that contains the entire PDF document to be -// rendered. -// |pdf_buffer_size| is the size of |pdf_buffer| in bytes. -// |page_number| is the page number that the function will get the dimensions -// of. -// |width| is the output for the width of the page in points. -// |height| is the output for the height of the page in points. -// Returns false if the document or the page number are not valid. -PDF_USED PP_EXPORT bool GetPDFPageSizeByIndex(const void* pdf_buffer, int pdf_buffer_size, int page_number, double* width, double* height) { @@ -237,19 +151,6 @@ bool GetPDFPageSizeByIndex(const void* pdf_buffer, return ret; } -// Renders PDF page into 4-byte per pixel BGRA color bitmap. -// |pdf_buffer| is the buffer that contains the entire PDF document to be -// rendered. -// |pdf_buffer_size| is the size of |pdf_buffer| in bytes. -// |page_number| is the 0-based index of the page to be rendered. -// |bitmap_buffer| is the output buffer for bitmap. -// |bitmap_width| is the width of the output bitmap. -// |bitmap_height| is the height of the output bitmap. -// |dpi| is the resolutions. -// |autorotate| specifies whether the final image should be rotated to match -// the output bound. -// Returns false if the document or the page number are not valid. -PDF_USED PP_EXPORT bool RenderPDFPageToBitmap(const void* pdf_buffer, int pdf_buffer_size, int page_number, @@ -275,4 +176,4 @@ bool RenderPDFPageToBitmap(const void* pdf_buffer, return ret; } -} // extern "C" +} // namespace chrome_pdf diff --git a/pdf/pdf.def b/pdf/pdf.def deleted file mode 100644 index b36918bb2799e0..00000000000000 --- a/pdf/pdf.def +++ /dev/null @@ -1,7 +0,0 @@ -LIBRARY pdf - -EXPORTS - NP_GetEntryPoints @1 - NP_Initialize @2 - NP_Shutdown @3 - diff --git a/pdf/pdf.gyp b/pdf/pdf.gyp index 022592153f048f..d49a0f1c62618e 100644 --- a/pdf/pdf.gyp +++ b/pdf/pdf.gyp @@ -3,28 +3,18 @@ 'chromium_code': 1, 'pdf_engine%': 0, # 0 PDFium }, - 'target_defaults': { - 'cflags': [ - '-fPIC', - ], - }, 'targets': [ { 'target_name': 'pdf', - 'type': 'loadable_module', - 'msvs_guid': '647863C0-C7A3-469A-B1ED-AD7283C34BED', + 'type': 'static_library', 'dependencies': [ '../base/base.gyp:base', + '../components/components.gyp:ui_zoom', + '../content/content.gyp:content_common', '../net/net.gyp:net', - '../ppapi/ppapi.gyp:ppapi_cpp', + '../ppapi/ppapi.gyp:ppapi_internal_module', '../third_party/pdfium/pdfium.gyp:pdfium', ], - 'xcode_settings': { - 'INFOPLIST_FILE': 'Info.plist', - }, - 'mac_framework_dirs': [ - '$(SDKROOT)/System/Library/Frameworks/ApplicationServices.framework/Frameworks', - ], 'ldflags': [ '-L<(PRODUCT_DIR)',], 'sources': [ 'button.h', @@ -55,7 +45,6 @@ 'paint_manager.h', 'pdf.cc', 'pdf.h', - 'pdf.rc', 'progress_control.cc', 'progress_control.h', 'pdf_engine.h', @@ -65,8 +54,6 @@ 'resource_consts.h', 'thumbnail_control.cc', 'thumbnail_control.h', - '../components/ui/zoom/page_zoom_constants.cc', - '../content/common/page_zoom.cc', ], 'conditions': [ ['pdf_engine==0', { @@ -86,117 +73,11 @@ 'pdfium/pdfium_range.h', ], }], - ['OS!="win"', { - 'sources!': [ - 'pdf.rc', - ], - }], - ['OS=="mac"', { - 'mac_bundle': 1, - 'product_name': 'PDF', - 'product_extension': 'plugin', - # Strip the shipping binary of symbols so "Foxit" doesn't appear in - # the binary. Symbols are stored in a separate .dSYM. - 'variables': { - 'mac_real_dsym': 1, - }, - 'sources+': [ - 'Info.plist' - ], - }], ['OS=="win"', { - 'defines': [ - 'COMPILE_CONTENT_STATICALLY', - ], # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. 'msvs_disabled_warnings': [ 4267, ], }], - ['OS=="linux"', { - 'configurations': { - 'Release_Base': { - #'cflags': [ '-fno-weak',], # get rid of symbols that strip doesn't remove. - # Don't do this for now since official builder will take care of it. That - # way symbols can still be uploaded to the crash server. - #'ldflags': [ '-s',], # strip local symbols from binary. - }, - }, - }], ], }, ], - 'conditions': [ - # CrOS has a separate step to do this. - ['OS=="linux" and chromeos==0', - { 'targets': [ - { - 'target_name': 'pdf_linux_symbols', - 'type': 'none', - 'conditions': [ - ['linux_dump_symbols==1', { - 'actions': [ - { - 'action_name': 'dump_symbols', - 'inputs': [ - '<(DEPTH)/build/linux/dump_app_syms', - '<(PRODUCT_DIR)/dump_syms', - '<(PRODUCT_DIR)/libpdf.so', - ], - 'outputs': [ - '<(PRODUCT_DIR)/libpdf.so.breakpad.<(target_arch)', - ], - 'action': ['<(DEPTH)/build/linux/dump_app_syms', - '<(PRODUCT_DIR)/dump_syms', - '<(linux_strip_binary)', - '<(PRODUCT_DIR)/libpdf.so', - '<@(_outputs)'], - 'message': 'Dumping breakpad symbols to <(_outputs)', - 'process_outputs_as_sources': 1, - }, - ], - 'dependencies': [ - 'pdf', - '../breakpad/breakpad.gyp:dump_syms', - ], - }], - ], - }, - ], - },], # OS=="linux" and chromeos==0 - ['OS=="win" and fastbuild==0 and target_arch=="ia32" and syzyasan==1', { - 'variables': { - 'dest_dir': '<(PRODUCT_DIR)/syzygy', - }, - 'targets': [ - { - 'target_name': 'pdf_syzyasan', - 'type': 'none', - 'sources' : [], - 'dependencies': [ - 'pdf', - ], - # Instrument PDFium with SyzyAsan. - 'actions': [ - { - 'action_name': 'Instrument PDFium with SyzyAsan', - 'inputs': [ - '<(PRODUCT_DIR)/pdf.dll', - ], - 'outputs': [ - '<(dest_dir)/pdf.dll', - '<(dest_dir)/pdf.dll.pdb', - ], - 'action': [ - 'python', - '<(DEPTH)/chrome/tools/build/win/syzygy/instrument.py', - '--mode', 'asan', - '--input_executable', '<(PRODUCT_DIR)/pdf.dll', - '--input_symbol', '<(PRODUCT_DIR)/pdf.dll.pdb', - '--destination_dir', '<(dest_dir)', - ], - }, - ], - }, - ], - }], # OS=="win" and fastbuild==0 and target_arch=="ia32" and syzyasan==1 - ], } diff --git a/pdf/pdf.h b/pdf/pdf.h index d797bbbaf52888..37e72e510be95c 100644 --- a/pdf/pdf.h +++ b/pdf/pdf.h @@ -5,6 +5,7 @@ #ifndef PDF_PDF_H_ #define PDF_PDF_H_ +#include "ppapi/c/ppb.h" #include "ppapi/cpp/module.h" namespace chrome_pdf { @@ -19,6 +20,94 @@ class PDFModule : public pp::Module { virtual pp::Instance* CreateInstance(PP_Instance instance); }; +int PPP_InitializeModule(PP_Module module_id, + PPB_GetInterface get_browser_interface); +void PPP_ShutdownModule(); +const void* PPP_GetInterface(const char* interface_name); + +#if defined(OS_WIN) +// |pdf_buffer| is the buffer that contains the entire PDF document to be +// rendered. +// |buffer_size| is the size of |pdf_buffer| in bytes. +// |page_number| is the 0-based index of the page to be rendered. +// |dc| is the device context to render into. +// |dpi| and |dpi_y| is the resolution. If the value is -1, the dpi from the DC +// will be used. +// |bounds_origin_x|, |bounds_origin_y|, |bounds_width| and |bounds_height| +// specify a bounds rectangle within the DC in which to render the PDF +// page. +// |fit_to_bounds| specifies whether the output should be shrunk to fit the +// supplied bounds if the page size is larger than the bounds in any +// dimension. If this is false, parts of the PDF page that lie outside +// the bounds will be clipped. +// |stretch_to_bounds| specifies whether the output should be stretched to fit +// the supplied bounds if the page size is smaller than the bounds in any +// dimension. +// If both |fit_to_bounds| and |stretch_to_bounds| are true, then +// |fit_to_bounds| is honored first. +// |keep_aspect_ratio| If any scaling is to be done is true, this flag +// specifies whether the original aspect ratio of the page should be +// preserved while scaling. +// |center_in_bounds| specifies whether the final image (after any scaling is +// done) should be centered within the given bounds. +// |autorotate| specifies whether the final image should be rotated to match +// the output bound. +// Returns false if the document or the page number are not valid. +bool RenderPDFPageToDC(const void* pdf_buffer, + int buffer_size, + int page_number, + HDC dc, + int dpi, + int bounds_origin_x, + int bounds_origin_y, + int bounds_width, + int bounds_height, + bool fit_to_bounds, + bool stretch_to_bounds, + bool keep_aspect_ratio, + bool center_in_bounds, + bool autorotate); +#endif +// |page_count| and |max_page_width| are optional and can be NULL. +// Returns false if the document is not valid. +bool GetPDFDocInfo(const void* pdf_buffer, + int buffer_size, int* page_count, + double* max_page_width); + +// Gets the dimensions of a specific page in a document. +// |pdf_buffer| is the buffer that contains the entire PDF document to be +// rendered. +// |pdf_buffer_size| is the size of |pdf_buffer| in bytes. +// |page_number| is the page number that the function will get the dimensions +// of. +// |width| is the output for the width of the page in points. +// |height| is the output for the height of the page in points. +// Returns false if the document or the page number are not valid. +bool GetPDFPageSizeByIndex(const void* pdf_buffer, + int pdf_buffer_size, int page_number, + double* width, double* height); + +// Renders PDF page into 4-byte per pixel BGRA color bitmap. +// |pdf_buffer| is the buffer that contains the entire PDF document to be +// rendered. +// |pdf_buffer_size| is the size of |pdf_buffer| in bytes. +// |page_number| is the 0-based index of the page to be rendered. +// |bitmap_buffer| is the output buffer for bitmap. +// |bitmap_width| is the width of the output bitmap. +// |bitmap_height| is the height of the output bitmap. +// |dpi| is the resolutions. +// |autorotate| specifies whether the final image should be rotated to match +// the output bound. +// Returns false if the document or the page number are not valid. +bool RenderPDFPageToBitmap(const void* pdf_buffer, + int pdf_buffer_size, + int page_number, + void* bitmap_buffer, + int bitmap_width, + int bitmap_height, + int dpi, + bool autorotate); + } // namespace chrome_pdf #endif // PDF_PDF_H_ diff --git a/pdf/pdf.rc b/pdf/pdf.rc deleted file mode 100644 index 50cb2957250767..00000000000000 --- a/pdf/pdf.rc +++ /dev/null @@ -1,104 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,0,1 - PRODUCTVERSION 1,0,0,1 - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904e4" - BEGIN - VALUE "FileDescription", "Chrome PDF Viewer" - VALUE "FileVersion", "1, 0, 0, 1" - VALUE "InternalName", "pdf" - VALUE "LegalCopyright", "Copyright (C) 2010" - VALUE "MIMEType", "application/pdf" - VALUE "FileExtents", "pdf" - VALUE "FileOpenName", "Acrobat Portable Document Format" - VALUE "OriginalFilename", "pdf.dll" - VALUE "ProductName", "Chrome PDF Viewer" - VALUE "ProductVersion", "1, 0, 0, 1" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1252 - END -END - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED -