1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PDF_PDFIUM_PDFIUM_ENGINE_H_
6 #define PDF_PDFIUM_PDFIUM_ENGINE_H_
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
15 #include "pdf/document_loader.h"
16 #include "pdf/pdf_engine.h"
17 #include "pdf/pdfium/pdfium_page.h"
18 #include "pdf/pdfium/pdfium_range.h"
19 #include "ppapi/cpp/completion_callback.h"
20 #include "ppapi/cpp/dev/buffer_dev.h"
21 #include "ppapi/cpp/image_data.h"
22 #include "ppapi/cpp/point.h"
23 #include "ppapi/cpp/var_array.h"
24 #include "third_party/pdfium/fpdfsdk/include/fpdf_dataavail.h"
25 #include "third_party/pdfium/fpdfsdk/include/fpdf_progressive.h"
26 #include "third_party/pdfium/fpdfsdk/include/fpdfformfill.h"
27 #include "third_party/pdfium/fpdfsdk/include/fpdfview.h"
30 class KeyboardInputEvent
;
31 class MouseInputEvent
;
35 namespace chrome_pdf
{
39 class PDFiumEngine
: public PDFEngine
,
40 public DocumentLoader::Client
,
41 public FPDF_FORMFILLINFO
,
42 public IPDF_JSPLATFORM
,
45 explicit PDFiumEngine(PDFEngine::Client
* client
);
46 virtual ~PDFiumEngine();
48 // PDFEngine implementation.
49 virtual bool New(const char* url
);
50 virtual bool New(const char* url
,
52 virtual void PageOffsetUpdated(const pp::Point
& page_offset
);
53 virtual void PluginSizeUpdated(const pp::Size
& size
);
54 virtual void ScrolledToXPosition(int position
);
55 virtual void ScrolledToYPosition(int position
);
56 virtual void PrePaint();
57 virtual void Paint(const pp::Rect
& rect
,
58 pp::ImageData
* image_data
,
59 std::vector
<pp::Rect
>* ready
,
60 std::vector
<pp::Rect
>* pending
);
61 virtual void PostPaint();
62 virtual bool HandleDocumentLoad(const pp::URLLoader
& loader
);
63 virtual bool HandleEvent(const pp::InputEvent
& event
);
64 virtual uint32_t QuerySupportedPrintOutputFormats();
65 virtual void PrintBegin();
66 virtual pp::Resource
PrintPages(
67 const PP_PrintPageNumberRange_Dev
* page_ranges
,
68 uint32_t page_range_count
,
69 const PP_PrintSettings_Dev
& print_settings
);
70 virtual void PrintEnd();
71 virtual void StartFind(const char* text
, bool case_sensitive
);
72 virtual bool SelectFindResult(bool forward
);
73 virtual void StopFind();
74 virtual void ZoomUpdated(double new_zoom_level
);
75 virtual void RotateClockwise();
76 virtual void RotateCounterclockwise();
77 virtual std::string
GetSelectedText();
78 virtual std::string
GetLinkAtPosition(const pp::Point
& point
);
79 virtual bool IsSelecting();
80 virtual bool HasPermission(DocumentPermission permission
) const;
81 virtual void SelectAll();
82 virtual int GetNumberOfPages();
83 virtual pp::VarArray
GetBookmarks();
84 virtual int GetNamedDestinationPage(const std::string
& destination
);
85 virtual int GetFirstVisiblePage();
86 virtual int GetMostVisiblePage();
87 virtual pp::Rect
GetPageRect(int index
);
88 virtual pp::Rect
GetPageContentsRect(int index
);
89 virtual int GetVerticalScrollbarYPosition() { return position_
.y(); }
90 virtual void PaintThumbnail(pp::ImageData
* image_data
, int index
);
91 virtual void SetGrayscale(bool grayscale
);
92 virtual void OnCallback(int id
);
93 virtual std::string
GetPageAsJSON(int index
);
94 virtual bool GetPrintScaling();
95 virtual int GetCopiesToPrint();
96 virtual void AppendBlankPages(int num_pages
);
97 virtual void AppendPage(PDFEngine
* engine
, int index
);
98 virtual pp::Point
GetScrollPosition();
99 virtual void SetScrollPosition(const pp::Point
& position
);
100 virtual bool IsProgressiveLoad();
102 // DocumentLoader::Client implementation.
103 virtual pp::Instance
* GetPluginInstance();
104 virtual pp::URLLoader
CreateURLLoader();
105 virtual void OnPartialDocumentLoaded();
106 virtual void OnPendingRequestComplete();
107 virtual void OnNewDataAvailable();
108 virtual void OnDocumentComplete();
110 void UnsupportedFeature(int type
);
112 std::string
current_find_text() const { return current_find_text_
; }
114 FPDF_DOCUMENT
doc() { return doc_
; }
115 FPDF_FORMHANDLE
form() { return form_
; }
118 // This helper class is used to detect the difference in selection between
119 // construction and destruction. At destruction, it invalidates all the
120 // parts that are newly selected, along with all the parts that used to be
121 // selected but are not anymore.
122 class SelectionChangeInvalidator
{
124 explicit SelectionChangeInvalidator(PDFiumEngine
* engine
);
125 ~SelectionChangeInvalidator();
127 // Sets the given container to the all the currently visible selection
128 // rectangles, in screen coordinates.
129 void GetVisibleSelectionsScreenRects(std::vector
<pp::Rect
>* rects
);
131 PDFiumEngine
* engine_
;
132 // Screen rectangles that were selected on construction.
133 std::vector
<pp::Rect
> old_selections_
;
134 // The origin at the time this object was constructed.
135 pp::Point previous_origin_
;
138 // Used to store mouse down state to handle it in other mouse event handlers.
139 class MouseDownState
{
141 MouseDownState(const PDFiumPage::Area
& area
,
142 const PDFiumPage::LinkTarget
& target
);
145 void Set(const PDFiumPage::Area
& area
,
146 const PDFiumPage::LinkTarget
& target
);
148 bool Matches(const PDFiumPage::Area
& area
,
149 const PDFiumPage::LinkTarget
& target
) const;
152 PDFiumPage::Area area_
;
153 PDFiumPage::LinkTarget target_
;
155 DISALLOW_COPY_AND_ASSIGN(MouseDownState
);
158 // Used to store the state of a text search.
159 class FindTextIndex
{
164 bool valid() const { return valid_
; }
167 size_t GetIndex() const;
168 void SetIndex(size_t index
);
169 size_t IncrementIndex();
172 bool valid_
; // Whether |index_| is valid or not.
173 size_t index_
; // The current search result, 0-based.
175 DISALLOW_COPY_AND_ASSIGN(FindTextIndex
);
178 friend class SelectionChangeInvalidator
;
180 struct FileAvail
: public FX_FILEAVAIL
{
181 DocumentLoader
* loader
;
184 struct DownloadHints
: public FX_DOWNLOADHINTS
{
185 DocumentLoader
* loader
;
188 // PDFium interface to get block of data.
189 static int GetBlock(void* param
, unsigned long position
,
190 unsigned char* buffer
, unsigned long size
);
192 // PDFium interface to check is block of data is available.
193 static bool IsDataAvail(FX_FILEAVAIL
* param
,
194 size_t offset
, size_t size
);
196 // PDFium interface to request download of the block of data.
197 static void AddSegment(FX_DOWNLOADHINTS
* param
,
198 size_t offset
, size_t size
);
200 // We finished getting the pdf file, so load it. This will complete
201 // asynchronously (due to password fetching) and may be run multiple times.
204 // Try loading the document. Returns true if the document is successfully
205 // loaded or is already loaded otherwise it will return false. If
206 // |with_password| is set to true, the document will be loaded with
207 // |password|. If the document could not be loaded and needs a password,
208 // |needs_password| will be set to true.
209 bool TryLoadingDoc(bool with_password
,
210 const std::string
& password
,
211 bool* needs_password
);
213 // Ask the user for the document password and then continue loading the
215 void GetPasswordAndLoad();
217 // Called when the password has been retrieved.
218 void OnGetPasswordComplete(int32_t result
,
219 const pp::Var
& password
);
221 // Continues loading the document when the password has been retrieved, or if
222 // there is no password.
223 void ContinueLoadingDocument(bool has_password
,
224 const std::string
& password
);
226 // Finish loading the document and notify the client that the document has
227 // been loaded. This should only be run after |doc_| has been loaded and the
228 // document is fully downloaded. If this has been run once, it will result in
230 void FinishLoadingDocument();
232 // Loads information about the pages in the document and calculate the
234 void LoadPageInfo(bool reload
);
236 // Calculate which pages should be displayed right now.
237 void CalculateVisiblePages();
239 // Returns true iff the given page index is visible. CalculateVisiblePages
240 // must have been called first.
241 bool IsPageVisible(int index
) const;
243 // Checks if a page is now available, and if so marks it as such and returns
244 // true. Otherwise, it will return false and will add the index to the given
245 // array if it's not already there.
246 bool CheckPageAvailable(int index
, std::vector
<int>* pending
);
248 // Helper function to get a given page's size in pixels. This is not part of
249 // PDFiumPage because we might not have that structure when we need this.
250 pp::Size
GetPageSize(int index
);
252 void GetAllScreenRectsUnion(std::vector
<PDFiumRange
>* rect_range
,
253 const pp::Point
& offset_point
,
254 std::vector
<pp::Rect
>* rect_vector
);
256 void UpdateTickMarks();
258 // Called to continue searching so we don't block the main thread.
259 void ContinueFind(int32_t result
);
261 // Inserts a find result into find_results_, which is sorted.
262 void AddFindResult(const PDFiumRange
& result
);
264 // Search a page using PDFium's methods. Doesn't work with unicode. This
265 // function is just kept arount in case PDFium code is fixed.
266 void SearchUsingPDFium(const base::string16
& term
,
269 int character_to_start_searching_from
,
272 // Search a page ourself using ICU.
273 void SearchUsingICU(const base::string16
& term
,
276 int character_to_start_searching_from
,
279 // Input event handlers.
280 bool OnMouseDown(const pp::MouseInputEvent
& event
);
281 bool OnMouseUp(const pp::MouseInputEvent
& event
);
282 bool OnMouseMove(const pp::MouseInputEvent
& event
);
283 bool OnKeyDown(const pp::KeyboardInputEvent
& event
);
284 bool OnKeyUp(const pp::KeyboardInputEvent
& event
);
285 bool OnChar(const pp::KeyboardInputEvent
& event
);
287 FPDF_DOCUMENT
CreateSinglePageRasterPdf(
288 double source_page_width
,
289 double source_page_height
,
290 const PP_PrintSettings_Dev
& print_settings
,
291 PDFiumPage
* page_to_print
);
293 pp::Buffer_Dev
PrintPagesAsRasterPDF(
294 const PP_PrintPageNumberRange_Dev
* page_ranges
,
295 uint32_t page_range_count
,
296 const PP_PrintSettings_Dev
& print_settings
);
298 pp::Buffer_Dev
PrintPagesAsPDF(const PP_PrintPageNumberRange_Dev
* page_ranges
,
299 uint32_t page_range_count
,
300 const PP_PrintSettings_Dev
& print_settings
);
302 pp::Buffer_Dev
GetFlattenedPrintData(const FPDF_DOCUMENT
& doc
);
303 void FitContentsToPrintableAreaIfRequired(
304 const FPDF_DOCUMENT
& doc
,
305 const PP_PrintSettings_Dev
& print_settings
);
306 void SaveSelectedFormForPrint();
308 // Given a mouse event, returns which page and character location it's closest
310 PDFiumPage::Area
GetCharIndex(const pp::MouseInputEvent
& event
,
313 PDFiumPage::LinkTarget
* target
);
314 PDFiumPage::Area
GetCharIndex(const pp::Point
& point
,
317 PDFiumPage::LinkTarget
* target
);
319 void OnSingleClick(int page_index
, int char_index
);
320 void OnMultipleClick(int click_count
, int page_index
, int char_index
);
322 // Starts a progressive paint operation given a rectangle in screen
323 // coordinates. Returns the index in progressive_rects_.
324 int StartPaint(int page_index
, const pp::Rect
& dirty
);
326 // Continues a paint operation that was started earlier. Returns true if the
327 // paint is done, or false if it needs to be continued.
328 bool ContinuePaint(int progressive_index
, pp::ImageData
* image_data
);
330 // Called once PDFium is finished rendering a page so that we draw our
331 // borders, highlighting etc.
332 void FinishPaint(int progressive_index
, pp::ImageData
* image_data
);
334 // Stops any paints that are in progress.
337 // Invalidates all pages. Use this when some global parameter, such as page
338 // orientation, has changed.
339 void InvalidateAllPages();
341 // If the page is narrower than the document size, paint the extra space
342 // with the page background.
343 void FillPageSides(int progressive_index
);
345 void PaintPageShadow(int progressive_index
, pp::ImageData
* image_data
);
347 // Highlight visible find results and selections.
348 void DrawSelections(int progressive_index
, pp::ImageData
* image_data
);
350 // Paints an page that hasn't finished downloading.
351 void PaintUnavailablePage(int page_index
,
352 const pp::Rect
& dirty
,
353 pp::ImageData
* image_data
);
355 // Given a page index, returns the corresponding index in progressive_rects_,
356 // or -1 if it doesn't exist.
357 int GetProgressiveIndex(int page_index
) const;
359 // Creates a FPDF_BITMAP from a rectangle in screen coordinates.
360 FPDF_BITMAP
CreateBitmap(const pp::Rect
& rect
,
361 pp::ImageData
* image_data
) const;
363 // Given a rectangle in screen coordinates, returns the coordinates in the
364 // units that PDFium rendering functions expect.
365 void GetPDFiumRect(int page_index
, const pp::Rect
& rect
, int* start_x
,
366 int* start_y
, int* size_x
, int* size_y
) const;
368 // Returns the rendering flags to pass to PDFium.
369 int GetRenderingFlags() const;
371 // Returns the currently visible rectangle in document coordinates.
372 pp::Rect
GetVisibleRect() const;
374 // Returns a page's rect in screen coordinates, as well as its surrounding
375 // border areas and bottom separator.
376 pp::Rect
GetPageScreenRect(int page_index
) const;
378 // Given a rectangle in document coordinates, returns the rectange into screen
379 // coordinates (i.e. 0,0 is top left corner of plugin area). If it's not
380 // visible, an empty rectangle is returned.
381 pp::Rect
GetScreenRect(const pp::Rect
& rect
) const;
383 // Highlights the given rectangle.
384 void Highlight(void* buffer
,
386 const pp::Rect
& rect
,
387 std::vector
<pp::Rect
>* highlighted_rects
);
389 // Helper function to convert a device to page coordinates. If the page is
390 // not yet loaded, page_x and page_y will be set to 0.
391 void DeviceToPage(int page_index
,
397 // Helper function to get the index of a given FPDF_PAGE. Returns -1 if not
399 int GetVisiblePageIndex(FPDF_PAGE page
);
401 // Helper function to change the current page, running page open/close
402 // triggers as necessary.
403 void SetCurrentPage(int index
);
405 // Transform |page| contents to fit in the selected printer paper size.
406 void TransformPDFPageForPrinting(FPDF_PAGE page
,
407 const PP_PrintSettings_Dev
& print_settings
);
409 void DrawPageShadow(const pp::Rect
& page_rect
,
410 const pp::Rect
& shadow_rect
,
411 const pp::Rect
& clip_rect
,
412 pp::ImageData
* image_data
);
414 void GetRegion(const pp::Point
& location
,
415 pp::ImageData
* image_data
,
419 // Called when the selection changes.
420 void OnSelectionChanged();
422 // Common code shared by RotateClockwise() and RotateCounterclockwise().
423 void RotateInternal();
425 // Setting selection status of document.
426 void SetSelecting(bool selecting
);
428 // FPDF_FORMFILLINFO callbacks.
429 static void Form_Invalidate(FPDF_FORMFILLINFO
* param
,
435 static void Form_OutputSelectedRect(FPDF_FORMFILLINFO
* param
,
441 static void Form_SetCursor(FPDF_FORMFILLINFO
* param
, int cursor_type
);
442 static int Form_SetTimer(FPDF_FORMFILLINFO
* param
,
444 TimerCallback timer_func
);
445 static void Form_KillTimer(FPDF_FORMFILLINFO
* param
, int timer_id
);
446 static FPDF_SYSTEMTIME
Form_GetLocalTime(FPDF_FORMFILLINFO
* param
);
447 static void Form_OnChange(FPDF_FORMFILLINFO
* param
);
448 static FPDF_PAGE
Form_GetPage(FPDF_FORMFILLINFO
* param
,
449 FPDF_DOCUMENT document
,
451 static FPDF_PAGE
Form_GetCurrentPage(FPDF_FORMFILLINFO
* param
,
452 FPDF_DOCUMENT document
);
453 static int Form_GetRotation(FPDF_FORMFILLINFO
* param
, FPDF_PAGE page
);
454 static void Form_ExecuteNamedAction(FPDF_FORMFILLINFO
* param
,
455 FPDF_BYTESTRING named_action
);
456 static void Form_SetTextFieldFocus(FPDF_FORMFILLINFO
* param
,
457 FPDF_WIDESTRING value
,
460 static void Form_DoURIAction(FPDF_FORMFILLINFO
* param
, FPDF_BYTESTRING uri
);
461 static void Form_DoGoToAction(FPDF_FORMFILLINFO
* param
,
464 float* position_array
,
467 // IPDF_JSPLATFORM callbacks.
468 static int Form_Alert(IPDF_JSPLATFORM
* param
,
469 FPDF_WIDESTRING message
,
470 FPDF_WIDESTRING title
,
473 static void Form_Beep(IPDF_JSPLATFORM
* param
, int type
);
474 static int Form_Response(IPDF_JSPLATFORM
* param
,
475 FPDF_WIDESTRING question
,
476 FPDF_WIDESTRING title
,
477 FPDF_WIDESTRING default_response
,
478 FPDF_WIDESTRING label
,
482 static int Form_GetFilePath(IPDF_JSPLATFORM
* param
,
485 static void Form_Mail(IPDF_JSPLATFORM
* param
,
490 FPDF_WIDESTRING subject
,
493 FPDF_WIDESTRING message
);
494 static void Form_Print(IPDF_JSPLATFORM
* param
,
499 FPDF_BOOL shrink_to_fit
,
500 FPDF_BOOL print_as_image
,
502 FPDF_BOOL annotations
);
503 static void Form_SubmitForm(IPDF_JSPLATFORM
* param
,
506 FPDF_WIDESTRING url
);
507 static void Form_GotoPage(IPDF_JSPLATFORM
* param
, int page_number
);
508 static int Form_Browse(IPDF_JSPLATFORM
* param
, void* file_path
, int length
);
511 static void Form_EmailTo(FPDF_FORMFILLINFO
* param
,
512 FPDF_FILEHANDLER
* file_handler
,
514 FPDF_WIDESTRING subject
,
517 FPDF_WIDESTRING message
);
518 static void Form_DisplayCaret(FPDF_FORMFILLINFO
* param
,
525 static void Form_SetCurrentPage(FPDF_FORMFILLINFO
* param
,
526 FPDF_DOCUMENT document
,
528 static int Form_GetCurrentPageIndex(FPDF_FORMFILLINFO
* param
,
529 FPDF_DOCUMENT document
);
530 static void Form_GetPageViewRect(FPDF_FORMFILLINFO
* param
,
536 static int Form_GetPlatform(FPDF_FORMFILLINFO
* param
,
539 static FPDF_BOOL
Form_PopupMenu(FPDF_FORMFILLINFO
* param
,
545 static FPDF_BOOL
Form_PostRequestURL(FPDF_FORMFILLINFO
* param
,
547 FPDF_WIDESTRING data
,
548 FPDF_WIDESTRING content_type
,
549 FPDF_WIDESTRING encode
,
550 FPDF_WIDESTRING header
,
551 FPDF_BSTR
* response
);
552 static FPDF_BOOL
Form_PutRequestURL(FPDF_FORMFILLINFO
* param
,
554 FPDF_WIDESTRING data
,
555 FPDF_WIDESTRING encode
);
556 static void Form_UploadTo(FPDF_FORMFILLINFO
* param
,
557 FPDF_FILEHANDLER
* file_handler
,
559 FPDF_WIDESTRING dest
);
560 static FPDF_LPFILEHANDLER
Form_DownloadFromURL(FPDF_FORMFILLINFO
* param
,
561 FPDF_WIDESTRING url
);
562 static FPDF_FILEHANDLER
* Form_OpenFile(FPDF_FORMFILLINFO
* param
,
566 static void Form_GotoURL(FPDF_FORMFILLINFO
* param
,
567 FPDF_DOCUMENT document
,
568 FPDF_WIDESTRING url
);
569 static int Form_GetLanguage(FPDF_FORMFILLINFO
* param
,
572 #endif // PDF_USE_XFA
574 // IFSDK_PAUSE callbacks
575 static FPDF_BOOL
Pause_NeedToPauseNow(IFSDK_PAUSE
* param
);
577 PDFEngine::Client
* client_
;
578 pp::Size document_size_
; // Size of document in pixels.
580 // The scroll position in screen coordinates.
582 // The offset of the page into the viewport.
583 pp::Point page_offset_
;
584 // The plugin size in screen coordinates.
585 pp::Size plugin_size_
;
586 double current_zoom_
;
587 unsigned int current_rotation_
;
589 DocumentLoader doc_loader_
; // Main document's loader.
591 std::string headers_
;
592 pp::CompletionCallbackFactory
<PDFiumEngine
> find_factory_
;
594 pp::CompletionCallbackFactory
<PDFiumEngine
> password_factory_
;
595 int32_t password_tries_remaining_
;
597 // The current text used for searching.
598 std::string current_find_text_
;
600 // The PDFium wrapper object for the document.
603 // The PDFium wrapper for form data. Used even if there are no form controls
605 FPDF_FORMHANDLE form_
;
607 // The page(s) of the document. Store a vector of pointers so that when the
608 // vector is resized we don't close the pages that are used in pending
610 std::vector
<PDFiumPage
*> pages_
;
612 // The indexes of the pages currently visible.
613 std::vector
<int> visible_pages_
;
615 // The indexes of the pages pending download.
616 std::vector
<int> pending_pages_
;
618 // During handling of input events we don't want to unload any pages in
619 // callbacks to us from PDFium, since the current page can change while PDFium
620 // code still has a pointer to it.
621 bool defer_page_unload_
;
622 std::vector
<int> deferred_page_unloads_
;
624 // Used for selection. There could be more than one range if selection spans
625 // more than one page.
626 std::vector
<PDFiumRange
> selection_
;
627 // True if we're in the middle of selection.
630 MouseDownState mouse_down_state_
;
632 // Used for searching.
633 typedef std::vector
<PDFiumRange
> FindResults
;
634 FindResults find_results_
;
635 // Which page to search next.
636 int next_page_to_search_
;
637 // Where to stop searching.
638 int last_page_to_search_
;
639 int last_character_index_to_search_
; // -1 if search until end of page.
640 // Which result the user has currently selected.
641 FindTextIndex current_find_index_
;
642 // Where to resume searching.
643 FindTextIndex resume_find_index_
;
645 // Permissions bitfield.
646 unsigned long permissions_
;
648 // Interface structure to provide access to document stream.
649 FPDF_FILEACCESS file_access_
;
650 // Interface structure to check data availability in the document stream.
651 FileAvail file_availability_
;
652 // Interface structure to request data chunks from the document stream.
653 DownloadHints download_hints_
;
654 // Pointer to the document availability interface.
655 FPDF_AVAIL fpdf_availability_
;
657 pp::Size default_page_size_
;
659 // Used to manage timers that form fill API needs. The pair holds the timer
660 // period, in ms, and the callback function.
661 std::map
<int, std::pair
<int, TimerCallback
> > timers_
;
664 // Holds the page index of the last page that the mouse clicked on.
665 int last_page_mouse_down_
;
667 // Holds the page index of the first visible page; refreshed by calling
668 // CalculateVisiblePages()
669 int first_visible_page_
;
671 // Holds the page index of the most visible page; refreshed by calling
672 // CalculateVisiblePages()
673 int most_visible_page_
;
675 // Set to true after FORM_DoDocumentJSAction/FORM_DoDocumentOpenAction have
676 // been called. Only after that can we call FORM_DoPageAAction.
677 bool called_do_document_action_
;
679 // Records parts of form fields that need to be highlighted at next paint, in
680 // screen coordinates.
681 std::vector
<pp::Rect
> form_highlights_
;
683 // Whether to render in grayscale or in color.
684 bool render_grayscale_
;
686 // The link currently under the cursor.
687 std::string link_under_cursor_
;
689 // Pending progressive paints.
690 struct ProgressivePaint
{
691 pp::Rect rect
; // In screen coordinates.
694 // Temporary used to figure out if in a series of Paint() calls whether this
695 // pending paint was updated or not.
698 std::vector
<ProgressivePaint
> progressive_paints_
;
700 // Keeps track of when we started the last progressive paint, so that in our
701 // callback we can determine if we need to pause.
702 base::Time last_progressive_start_time_
;
704 // The timeout to use for the current progressive paint.
705 int progressive_paint_timeout_
;
707 // Shadow matrix for generating the page shadow bitmap.
708 scoped_ptr
<ShadowMatrix
> page_shadow_
;
710 // Set to true if the user is being prompted for their password. Will be set
711 // to false after the user finishes getting their password.
712 bool getting_password_
;
714 DISALLOW_COPY_AND_ASSIGN(PDFiumEngine
);
717 // Create a local variable of this when calling PDFium functions which can call
718 // our global callback when an unsupported feature is reached.
719 class ScopedUnsupportedFeature
{
721 explicit ScopedUnsupportedFeature(PDFiumEngine
* engine
);
722 ~ScopedUnsupportedFeature();
724 PDFiumEngine
* engine_
;
725 PDFiumEngine
* old_engine_
;
728 class PDFiumEngineExports
: public PDFEngineExports
{
730 PDFiumEngineExports() {}
732 // See the definition of RenderPDFPageToDC in pdf.cc for details.
733 virtual bool RenderPDFPageToDC(const void* pdf_buffer
,
736 const RenderingSettings
& settings
,
739 virtual bool RenderPDFPageToBitmap(const void* pdf_buffer
,
742 const RenderingSettings
& settings
,
743 void* bitmap_buffer
);
745 virtual bool GetPDFDocInfo(const void* pdf_buffer
,
748 double* max_page_width
);
750 // See the definition of GetPDFPageSizeByIndex in pdf.cc for details.
751 virtual bool GetPDFPageSizeByIndex(const void* pdf_buffer
,
752 int pdf_buffer_size
, int page_number
,
753 double* width
, double* height
);
756 } // namespace chrome_pdf
758 #endif // PDF_PDFIUM_PDFIUM_ENGINE_H_