diff options
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/document_loader.h | 2 | ||||
-rw-r--r-- | pdf/out_of_process_instance.h | 5 | ||||
-rw-r--r-- | pdf/pdf.cc | 16 | ||||
-rw-r--r-- | pdf/pdf.h | 6 | ||||
-rw-r--r-- | pdf/pdf_engine.h | 5 | ||||
-rw-r--r-- | pdf/pdfium/pdfium_engine.cc | 14 | ||||
-rw-r--r-- | pdf/pdfium/pdfium_engine.h | 167 | ||||
-rw-r--r-- | pdf/preview_mode_client.h | 92 |
8 files changed, 156 insertions, 151 deletions
diff --git a/pdf/document_loader.h b/pdf/document_loader.h index e5e08d6..c9d355b 100644 --- a/pdf/document_loader.h +++ b/pdf/document_loader.h @@ -101,7 +101,7 @@ class DocumentLoader { // Number was chosen in crbug.com/78264#c8 enum { kDefaultRequestSize = 65536 }; - Client* client_; + Client* const client_; std::string url_; pp::URLLoader loader_; pp::CompletionCallbackFactory<DocumentLoader> loader_factory_; diff --git a/pdf/out_of_process_instance.h b/pdf/out_of_process_instance.h index 41fef65..f210d0a5 100644 --- a/pdf/out_of_process_instance.h +++ b/pdf/out_of_process_instance.h @@ -74,9 +74,8 @@ class OutOfProcessInstance : public pp::Instance, bool IsPrintScalingDisabled() override; // pp::Private implementation. - virtual pp::Var GetLinkAtPosition(const pp::Point& point); - virtual void GetPrintPresetOptionsFromDocument( - PP_PdfPrintPresetOptions_Dev* options); + pp::Var GetLinkAtPosition(const pp::Point& point); + void GetPrintPresetOptionsFromDocument(PP_PdfPrintPresetOptions_Dev* options); void FlushCallback(int32_t result); void DidOpen(int32_t result); @@ -104,8 +104,8 @@ bool RenderPDFPageToDC(const void* pdf_buffer, return false; } } - scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( - chrome_pdf::PDFEngineExports::Create()); + chrome_pdf::PDFEngineExports* engine_exports = + chrome_pdf::PDFEngineExports::Get(); chrome_pdf::PDFEngineExports::RenderingSettings settings( dpi, dpi, pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, bounds_height), @@ -128,8 +128,8 @@ bool GetPDFDocInfo(const void* pdf_buffer, if (!chrome_pdf::InitializeSDK()) return false; } - scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( - chrome_pdf::PDFEngineExports::Create()); + chrome_pdf::PDFEngineExports* engine_exports = + chrome_pdf::PDFEngineExports::Get(); bool ret = engine_exports->GetPDFDocInfo( pdf_buffer, buffer_size, page_count, max_page_width); if (!g_sdk_initialized_via_pepper) { @@ -145,8 +145,8 @@ bool GetPDFPageSizeByIndex(const void* pdf_buffer, if (!chrome_pdf::InitializeSDK()) return false; } - scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( - chrome_pdf::PDFEngineExports::Create()); + chrome_pdf::PDFEngineExports* engine_exports = + chrome_pdf::PDFEngineExports::Get(); bool ret = engine_exports->GetPDFPageSizeByIndex( pdf_buffer, pdf_buffer_size, page_number, width, height); if (!g_sdk_initialized_via_pepper) @@ -166,8 +166,8 @@ bool RenderPDFPageToBitmap(const void* pdf_buffer, if (!chrome_pdf::InitializeSDK()) return false; } - scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( - chrome_pdf::PDFEngineExports::Create()); + chrome_pdf::PDFEngineExports* engine_exports = + chrome_pdf::PDFEngineExports::Get(); chrome_pdf::PDFEngineExports::RenderingSettings settings( dpi, dpi, pp::Rect(bitmap_width, bitmap_height), true, false, true, true, autorotate); @@ -13,11 +13,11 @@ namespace chrome_pdf { class PDFModule : public pp::Module { public: PDFModule(); - virtual ~PDFModule(); + ~PDFModule() override; // pp::Module implementation. - virtual bool Init(); - virtual pp::Instance* CreateInstance(PP_Instance instance); + bool Init() override; + pp::Instance* CreateInstance(PP_Instance instance) override; }; int PPP_InitializeModule(PP_Module module_id, diff --git a/pdf/pdf_engine.h b/pdf/pdf_engine.h index aa74875..7df4bff2 100644 --- a/pdf/pdf_engine.h +++ b/pdf/pdf_engine.h @@ -61,6 +61,8 @@ class PDFEngine { // The interface that's provided to the rendering engine. class Client { public: + virtual ~Client() {} + // Informs the client about the document's size in pixels. virtual void DocumentSizeUpdated(const pp::Size& size) = 0; @@ -315,7 +317,8 @@ class PDFEngineExports { PDFEngineExports() {} virtual ~PDFEngineExports() {} - static PDFEngineExports* Create(); + static PDFEngineExports* Get(); + #if defined(OS_WIN) // See the definition of RenderPDFPageToDC in pdf.cc for details. virtual bool RenderPDFPageToDC(const void* pdf_buffer, diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc index 9bf10fb..90c4df5 100644 --- a/pdf/pdfium/pdfium_engine.cc +++ b/pdf/pdfium/pdfium_engine.cc @@ -11,6 +11,7 @@ #include "base/i18n/icu_encoding_detection.h" #include "base/i18n/icu_string_conversions.h" #include "base/json/json_writer.h" +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/macros.h" #include "base/memory/scoped_ptr.h" @@ -3777,12 +3778,11 @@ ScopedUnsupportedFeature::~ScopedUnsupportedFeature() { g_engine_for_unsupported = old_engine_; } -PDFEngineExports* PDFEngineExports::Create() { - return new PDFiumEngineExports; -} - namespace { +base::LazyInstance<PDFiumEngineExports>::Leaky g_pdf_engine_exports = + LAZY_INSTANCE_INITIALIZER; + int CalculatePosition(FPDF_PAGE page, const PDFiumEngineExports::RenderingSettings& settings, pp::Rect* dest) { @@ -3848,6 +3848,10 @@ int CalculatePosition(FPDF_PAGE page, } // namespace +PDFEngineExports* PDFEngineExports::Get() { + return g_pdf_engine_exports.Pointer(); +} + #if defined(OS_WIN) bool PDFiumEngineExports::RenderPDFPageToDC(const void* pdf_buffer, int buffer_size, @@ -3931,7 +3935,7 @@ bool PDFiumEngineExports::RenderPDFPageToDC(const void* pdf_buffer, FPDF_CloseDocument(doc); return true; } -#endif // OS_WIN +#endif // defined(OS_WIN) bool PDFiumEngineExports::RenderPDFPageToBitmap( const void* pdf_buffer, diff --git a/pdf/pdfium/pdfium_engine.h b/pdf/pdfium/pdfium_engine.h index 3ebe68f0..88a2575 100644 --- a/pdf/pdfium/pdfium_engine.h +++ b/pdf/pdfium/pdfium_engine.h @@ -47,71 +47,70 @@ class PDFiumEngine : public PDFEngine, public IFSDK_PAUSE { public: explicit PDFiumEngine(PDFEngine::Client* client); - virtual ~PDFiumEngine(); + ~PDFiumEngine() override; // PDFEngine implementation. - virtual bool New(const char* url, const char* headers); - virtual void PageOffsetUpdated(const pp::Point& page_offset); - virtual void PluginSizeUpdated(const pp::Size& size); - virtual void ScrolledToXPosition(int position); - virtual void ScrolledToYPosition(int position); - virtual void PrePaint(); - virtual void Paint(const pp::Rect& rect, - pp::ImageData* image_data, - std::vector<pp::Rect>* ready, - std::vector<pp::Rect>* pending); - virtual void PostPaint(); - virtual bool HandleDocumentLoad(const pp::URLLoader& loader); - virtual bool HandleEvent(const pp::InputEvent& event); - virtual uint32_t QuerySupportedPrintOutputFormats(); - virtual void PrintBegin(); - virtual pp::Resource PrintPages( - const PP_PrintPageNumberRange_Dev* page_ranges, - uint32_t page_range_count, - const PP_PrintSettings_Dev& print_settings); - virtual void PrintEnd(); - virtual void StartFind(const std::string& text, bool case_sensitive); - virtual bool SelectFindResult(bool forward); - virtual void StopFind(); - virtual void ZoomUpdated(double new_zoom_level); - virtual void RotateClockwise(); - virtual void RotateCounterclockwise(); - virtual std::string GetSelectedText(); - virtual std::string GetLinkAtPosition(const pp::Point& point); - virtual bool IsSelecting(); - virtual bool HasPermission(DocumentPermission permission) const; - virtual void SelectAll(); - virtual int GetNumberOfPages(); - virtual pp::VarArray GetBookmarks(); - virtual int GetNamedDestinationPage(const std::string& destination); - virtual int GetFirstVisiblePage(); - virtual int GetMostVisiblePage(); - virtual pp::Rect GetPageRect(int index); - virtual pp::Rect GetPageContentsRect(int index); - virtual pp::Rect GetPageScreenRect(int page_index) const; - virtual int GetVerticalScrollbarYPosition() { return position_.y(); } - virtual void PaintThumbnail(pp::ImageData* image_data, int index); - virtual void SetGrayscale(bool grayscale); - virtual void OnCallback(int id); - virtual std::string GetPageAsJSON(int index); - virtual bool GetPrintScaling(); - virtual int GetCopiesToPrint(); - virtual int GetDuplexType(); - virtual bool GetPageSizeAndUniformity(pp::Size* size); - virtual void AppendBlankPages(int num_pages); - virtual void AppendPage(PDFEngine* engine, int index); - virtual pp::Point GetScrollPosition(); - virtual void SetScrollPosition(const pp::Point& position); - virtual bool IsProgressiveLoad(); - virtual std::string GetMetadata(const std::string& key); + bool New(const char* url, const char* headers) override; + void PageOffsetUpdated(const pp::Point& page_offset) override; + void PluginSizeUpdated(const pp::Size& size) override; + void ScrolledToXPosition(int position) override; + void ScrolledToYPosition(int position) override; + void PrePaint() override; + void Paint(const pp::Rect& rect, + pp::ImageData* image_data, + std::vector<pp::Rect>* ready, + std::vector<pp::Rect>* pending) override; + void PostPaint() override; + bool HandleDocumentLoad(const pp::URLLoader& loader) override; + bool HandleEvent(const pp::InputEvent& event) override; + uint32_t QuerySupportedPrintOutputFormats() override; + void PrintBegin() override; + pp::Resource PrintPages(const PP_PrintPageNumberRange_Dev* page_ranges, + uint32_t page_range_count, + const PP_PrintSettings_Dev& print_settings) override; + void PrintEnd() override; + void StartFind(const std::string& text, bool case_sensitive) override; + bool SelectFindResult(bool forward) override; + void StopFind() override; + void ZoomUpdated(double new_zoom_level) override; + void RotateClockwise() override; + void RotateCounterclockwise() override; + std::string GetSelectedText() override; + std::string GetLinkAtPosition(const pp::Point& point) override; + bool IsSelecting() override; + bool HasPermission(DocumentPermission permission) const override; + void SelectAll() override; + int GetNumberOfPages() override; + pp::VarArray GetBookmarks() override; + int GetNamedDestinationPage(const std::string& destination) override; + int GetFirstVisiblePage() override; + int GetMostVisiblePage() override; + pp::Rect GetPageRect(int index) override; + pp::Rect GetPageContentsRect(int index) override; + pp::Rect GetPageScreenRect(int page_index) const override; + int GetVerticalScrollbarYPosition() override { return position_.y(); } + void PaintThumbnail(pp::ImageData* image_data, int index) override; + void SetGrayscale(bool grayscale) override; + void OnCallback(int id) override; + std::string GetPageAsJSON(int index) override; + bool GetPrintScaling() override; + int GetCopiesToPrint() override; + int GetDuplexType() override; + bool GetPageSizeAndUniformity(pp::Size* size) override; + void AppendBlankPages(int num_pages) override; + void AppendPage(PDFEngine* engine, int index) override; + pp::Point GetScrollPosition() override; + void SetScrollPosition(const pp::Point& position) override; + bool IsProgressiveLoad() override; + std::string GetMetadata(const std::string& key) override; // DocumentLoader::Client implementation. - virtual pp::Instance* GetPluginInstance(); - virtual pp::URLLoader CreateURLLoader(); - virtual void OnPartialDocumentLoaded(); - virtual void OnPendingRequestComplete(); - virtual void OnNewDataAvailable(); - virtual void OnDocumentComplete(); + pp::Instance* GetPluginInstance() override; + pp::URLLoader CreateURLLoader() override; + void OnPartialDocumentLoaded() override; + void OnPendingRequestComplete() override; + void OnNewDataAvailable() override; + void OnDocumentComplete() override; void UnsupportedFeature(int type); @@ -578,7 +577,7 @@ class PDFiumEngine : public PDFEngine, // IFSDK_PAUSE callbacks static FPDF_BOOL Pause_NeedToPauseNow(IFSDK_PAUSE* param); - PDFEngine::Client* client_; + PDFEngine::Client* const client_; pp::Size document_size_; // Size of document in pixels. // The scroll position in screen coordinates. @@ -735,29 +734,29 @@ class ScopedUnsupportedFeature { class PDFiumEngineExports : public PDFEngineExports { public: PDFiumEngineExports() {} + +// PDFEngineExports: #if defined(OS_WIN) - // See the definition of RenderPDFPageToDC in pdf.cc for details. - virtual bool RenderPDFPageToDC(const void* pdf_buffer, - int buffer_size, - int page_number, - const RenderingSettings& settings, - HDC dc); -#endif // OS_WIN - virtual bool RenderPDFPageToBitmap(const void* pdf_buffer, - int pdf_buffer_size, - int page_number, - const RenderingSettings& settings, - void* bitmap_buffer); - - virtual bool GetPDFDocInfo(const void* pdf_buffer, - int buffer_size, - int* page_count, - double* max_page_width); - - // See the definition of GetPDFPageSizeByIndex in pdf.cc for details. - virtual bool GetPDFPageSizeByIndex(const void* pdf_buffer, - int pdf_buffer_size, int page_number, - double* width, double* height); + bool RenderPDFPageToDC(const void* pdf_buffer, + int buffer_size, + int page_number, + const RenderingSettings& settings, + HDC dc) override; +#endif // defined(OS_WIN) + bool RenderPDFPageToBitmap(const void* pdf_buffer, + int pdf_buffer_size, + int page_number, + const RenderingSettings& settings, + void* bitmap_buffer) override; + bool GetPDFDocInfo(const void* pdf_buffer, + int buffer_size, + int* page_count, + double* max_page_width) override; + bool GetPDFPageSizeByIndex(const void* pdf_buffer, + int pdf_buffer_size, + int page_number, + double* width, + double* height) override; }; } // namespace chrome_pdf diff --git a/pdf/preview_mode_client.h b/pdf/preview_mode_client.h index 1f424a7..0127db9 100644 --- a/pdf/preview_mode_client.h +++ b/pdf/preview_mode_client.h @@ -22,57 +22,57 @@ class PreviewModeClient : public PDFEngine::Client { virtual void PreviewDocumentLoadFailed() = 0; virtual void PreviewDocumentLoadComplete() = 0; }; + explicit PreviewModeClient(Client* client); - virtual ~PreviewModeClient() {} + ~PreviewModeClient() override {} // PDFEngine::Client implementation. - virtual void DocumentSizeUpdated(const pp::Size& size); - virtual void Invalidate(const pp::Rect& rect); - virtual void Scroll(const pp::Point& point); - virtual void ScrollToX(int position); - virtual void ScrollToY(int position); - virtual void ScrollToPage(int page); - virtual void NavigateTo(const std::string& url, bool open_in_new_tab); - virtual void UpdateCursor(PP_CursorType_Dev cursor); - virtual void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks); - virtual void NotifyNumberOfFindResultsChanged(int total, - bool final_result); - virtual void NotifySelectedFindResultChanged(int current_find_index); - virtual void GetDocumentPassword( - pp::CompletionCallbackWithOutput<pp::Var> callback); - virtual void Alert(const std::string& message); - virtual bool Confirm(const std::string& message); - virtual std::string Prompt(const std::string& question, - const std::string& default_answer); - virtual std::string GetURL(); - virtual void Email(const std::string& to, - const std::string& cc, - const std::string& bcc, - const std::string& subject, - const std::string& body); - virtual void Print(); - virtual void SubmitForm(const std::string& url, - const void* data, - int length); - virtual std::string ShowFileSelectionDialog(); - virtual pp::URLLoader CreateURLLoader(); - virtual void ScheduleCallback(int id, int delay_in_ms); - virtual void SearchString(const base::char16* string, - const base::char16* term, - bool case_sensitive, - std::vector<SearchStringResult>* results); - virtual void DocumentPaintOccurred(); - virtual void DocumentLoadComplete(int page_count); - virtual void DocumentLoadFailed(); - virtual pp::Instance* GetPluginInstance(); - virtual void DocumentHasUnsupportedFeature(const std::string& feature); - virtual void DocumentLoadProgress(uint32_t available, uint32_t doc_size); - virtual void FormTextFieldFocusChange(bool in_focus); - virtual bool IsPrintPreview(); - virtual uint32_t GetBackgroundColor(); + void DocumentSizeUpdated(const pp::Size& size) override; + void Invalidate(const pp::Rect& rect) override; + void Scroll(const pp::Point& point) override; + void ScrollToX(int position) override; + void ScrollToY(int position) override; + void ScrollToPage(int page) override; + void NavigateTo(const std::string& url, bool open_in_new_tab) override; + void UpdateCursor(PP_CursorType_Dev cursor) override; + void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks) override; + void NotifyNumberOfFindResultsChanged(int total, bool final_result) override; + void NotifySelectedFindResultChanged(int current_find_index) override; + void GetDocumentPassword( + pp::CompletionCallbackWithOutput<pp::Var> callback) override; + void Alert(const std::string& message) override; + bool Confirm(const std::string& message) override; + std::string Prompt(const std::string& question, + const std::string& default_answer) override; + std::string GetURL() override; + void Email(const std::string& to, + const std::string& cc, + const std::string& bcc, + const std::string& subject, + const std::string& body) override; + void Print() override; + void SubmitForm(const std::string& url, + const void* data, + int length) override; + std::string ShowFileSelectionDialog() override; + pp::URLLoader CreateURLLoader() override; + void ScheduleCallback(int id, int delay_in_ms) override; + void SearchString(const base::char16* string, + const base::char16* term, + bool case_sensitive, + std::vector<SearchStringResult>* results) override; + void DocumentPaintOccurred() override; + void DocumentLoadComplete(int page_count) override; + void DocumentLoadFailed() override; + pp::Instance* GetPluginInstance() override; + void DocumentHasUnsupportedFeature(const std::string& feature) override; + void DocumentLoadProgress(uint32_t available, uint32_t doc_size) override; + void FormTextFieldFocusChange(bool in_focus) override; + bool IsPrintPreview() override; + uint32_t GetBackgroundColor() override; private: - Client* client_; + Client* const client_; }; } // namespace chrome_pdf |