diff options
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/BUILD.gn | 30 | ||||
-rw-r--r-- | pdf/Info.plist | 44 | ||||
-rw-r--r-- | pdf/pdf.cc | 157 | ||||
-rw-r--r-- | pdf/pdf.def | 7 | ||||
-rw-r--r-- | pdf/pdf.gyp | 127 | ||||
-rw-r--r-- | pdf/pdf.h | 89 | ||||
-rw-r--r-- | pdf/pdf.rc | 104 |
7 files changed, 126 insertions, 432 deletions
diff --git a/pdf/BUILD.gn b/pdf/BUILD.gn index b028290..4ecd961 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 9f3dfdf..0000000 --- a/pdf/Info.plist +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> -<plist version="1.0"> -<dict> - <key>CFBundleDevelopmentRegion</key> - <string>English</string> - <key>CFBundleExecutable</key> - <string>${EXECUTABLE_NAME}</string> - <key>CFBundleIdentifier</key> - <string>org.chromium.pdf_plugin</string> - <key>CFBundleInfoDictionaryVersion</key> - <string>6.0</string> - <key>CFBundleName</key> - <string>${PRODUCT_NAME}</string> - <key>CFBundlePackageType</key> - <string>BRPL</string> - <key>CFBundleShortVersionString</key> - <string>1.0</string> - <key>CFBundleSignature</key> - <string>????</string> - <key>CFBundleVersion</key> - <string>1.0</string> - <key>CFPlugInDynamicRegisterFunction</key> - <string></string> - <key>CFPlugInDynamicRegistration</key> - <string>NO</string> - <key>WebPluginDescription</key> - <string>Chrome PDF Viewer</string> - <key>WebPluginMIMETypes</key> - <dict> - <key>application/pdf</key> - <dict> - <key>WebPluginExtensions</key> - <array> - <string>pdf</string> - </array> - <key>WebPluginTypeDescription</key> - <string>Acrobat Portable Document Format</string> - </dict> - </dict> - <key>WebPluginName</key> - <string>Chrome PDF Viewer</string> -</dict> -</plist> @@ -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<chrome_pdf::PDFEngineExports> 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 b36918b..0000000 --- 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 0225921..d49a0f1 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 - ], } @@ -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 50cb295..0000000 --- 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 - |