diff options
Diffstat (limited to 'chrome')
24 files changed, 137 insertions, 386 deletions
diff --git a/chrome/BUILD.gn b/chrome/BUILD.gn index 2f4ed9e..6deb300 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 9c95992..e014b07 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 608d513..7a84022 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 974b34a..7384caf 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 3841dba..2ee4816 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 1075f61..ad996d3 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 367a92d..f6a9321 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<PDFPageToBitmapProc>( - pdf_lib_.GetFunctionPointer("RenderPDFPageToBitmap")); - - pdf_doc_info_func_ = - reinterpret_cast<GetPDFDocInfoProc>( - pdf_lib_.GetFunctionPointer("GetPDFDocInfo")); - - pdf_page_size_func_ = - reinterpret_cast<GetPDFPageSizeByIndexProc>( - 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<uint8_t> 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<PrintPreviewObserver> 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 6a56a91..d89c474 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 ac17072..338403c 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<LPCWSTR>(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 9ebce29..64ae230 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 024f34d..0885668 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 c522f2f..dd01c01 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 46c84f9..2713e9b 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 fcc837a..5a2a068 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 b96db22..1f17749 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 587b2aa..21df9e0 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<content::PepperPluginInfo>* 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 968db7c..fd00d31 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 aeda534..f0a59f8 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 af56236..9537376 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 a22600e..34c85fb 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 4389f3e..1c24f05 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 e06aebc..843b1f3 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 3dd8e92..9e282ad 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<RenderPDFPageToBitmapProc>( - pdf_lib_.GetFunctionPointer("RenderPDFPageToBitmap")); - LOG_IF(WARNING, !render_pdf_to_bitmap_func_) << - "Missing RenderPDFPageToBitmap"; - - get_pdf_doc_info_func_ = - reinterpret_cast<GetPDFDocInfoProc>( - 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<RenderPDFPageToDCProc>( - 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<PdfFunctions> 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<int>::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<int>::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 cc490ba..341a358 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; |