forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpdf_view_plugin_base.h
689 lines (529 loc) · 25.8 KB
/
pdf_view_plugin_base.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_PDF_VIEW_PLUGIN_BASE_H_
#define PDF_PDF_VIEW_PLUGIN_BASE_H_
#include <stdint.h>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/callback.h"
#include "base/containers/flat_set.h"
#include "base/containers/queue.h"
#include "base/i18n/rtl.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_piece.h"
#include "base/values.h"
#include "pdf/accessibility_structs.h"
#include "pdf/paint_manager.h"
#include "pdf/pdf_engine.h"
#include "pdf/pdfium/pdfium_form_filler.h"
#include "pdf/preview_mode_client.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/web/web_print_params.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace blink {
class WebInputEvent;
struct WebPrintPresetOptions;
} // namespace blink
namespace gfx {
class PointF;
} // namespace gfx
namespace chrome_pdf {
class Image;
class PDFiumEngine;
class Thumbnail;
class UrlLoader;
struct AccessibilityActionData;
struct AccessibilityCharInfo;
struct AccessibilityDocInfo;
struct AccessibilityPageInfo;
struct AccessibilityPageObjects;
struct AccessibilityTextRunInfo;
struct AccessibilityViewportInfo;
// Common base to share code between the two plugin implementations,
// `OutOfProcessInstance` (Pepper) and `PdfViewWebPlugin` (Blink).
class PdfViewPluginBase : public PDFEngine::Client,
public PaintManager::Client,
public PreviewModeClient::Client {
public:
using PDFEngine::Client::ScheduleTaskOnMainThread;
// Do not save files with over 100 MB. This cap should be kept in sync with
// and is also enforced in chrome/browser/resources/pdf/pdf_viewer.js.
static constexpr size_t kMaximumSavedFileSize = 100 * 1000 * 1000;
// Print Preview base URL.
static constexpr base::StringPiece kChromePrintHost = "chrome://print/";
// Untrusted Print Preview base URL.
static constexpr base::StringPiece kChromeUntrustedPrintHost =
"chrome-untrusted://print/";
enum class AccessibilityState {
kOff = 0, // Off.
kPending, // Enabled but waiting for doc to load.
kLoaded, // Fully loaded.
};
enum class DocumentLoadState {
kLoading = 0,
kComplete,
kFailed,
};
// Must match `SaveRequestType` in chrome/browser/resources/pdf/constants.js.
enum class SaveRequestType {
kAnnotation = 0,
kOriginal = 1,
kEdited = 2,
};
PdfViewPluginBase(const PdfViewPluginBase& other) = delete;
PdfViewPluginBase& operator=(const PdfViewPluginBase& other) = delete;
// PDFEngine::Client:
void ProposeDocumentLayout(const DocumentLayout& layout) override;
void Invalidate(const gfx::Rect& rect) override;
void DidScroll(const gfx::Vector2d& offset) override;
void ScrollToX(int x_screen_coords) override;
void ScrollToY(int y_screen_coords) override;
void ScrollBy(const gfx::Vector2d& delta) override;
void ScrollToPage(int page) override;
void NavigateTo(const std::string& url,
WindowOpenDisposition disposition) override;
void NavigateToDestination(int page,
const float* x,
const float* y,
const float* zoom) override;
void UpdateTickMarks(const std::vector<gfx::Rect>& tickmarks) override;
void NotifyNumberOfFindResultsChanged(int total, bool final_result) override;
void NotifyTouchSelectionOccurred() override;
void GetDocumentPassword(
base::OnceCallback<void(const std::string&)> callback) override;
void Beep() 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::unique_ptr<UrlLoader> CreateUrlLoader() override;
void DocumentLoadComplete() override;
void DocumentLoadFailed() override;
void DocumentHasUnsupportedFeature(const std::string& feature) override;
void DocumentLoadProgress(uint32_t available, uint32_t doc_size) override;
void FormFieldFocusChange(PDFEngine::FocusFieldType type) override;
bool IsPrintPreview() const override;
SkColor GetBackgroundColor() override;
void SetIsSelecting(bool is_selecting) override;
void SelectionChanged(const gfx::Rect& left, const gfx::Rect& right) override;
void EnteredEditMode() override;
void DocumentFocusChanged(bool document_has_focus) override;
void SetLinkUnderCursor(const std::string& link_under_cursor) override;
// PaintManager::Client:
void OnPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>& ready,
std::vector<gfx::Rect>& pending) override;
// PreviewModeClient::Client:
void PreviewDocumentLoadComplete() override;
void PreviewDocumentLoadFailed() override;
// Enable accessibility for PDF plugin.
void EnableAccessibility();
// Handle invoked accessibility actions.
void HandleAccessibilityAction(const AccessibilityActionData& action_data);
// Gets the content restrictions based on the permissions which `engine_` has.
int GetContentRestrictions() const;
// Gets the accessibility doc info based on the information from `engine_`.
AccessibilityDocInfo GetAccessibilityDocInfo() const;
bool GetDidCallStartLoadingForTesting() const {
return did_call_start_loading_;
}
bool UnsupportedFeatureIsReportedForTesting(const std::string& feature) const;
bool GetNotifiedBrowserAboutUnsupportedFeatureForTesting() const {
return notified_browser_about_unsupported_feature_;
}
void InitializeEngineForTesting(std::unique_ptr<PDFiumEngine> engine);
void set_full_frame_for_testing(bool full_frame) { full_frame_ = full_frame; }
DocumentLoadState document_load_state_for_testing() const {
return document_load_state_;
}
bool edit_mode_for_testing() const { return edit_mode_; }
protected:
struct BackgroundPart {
gfx::Rect location;
uint32_t color;
};
PdfViewPluginBase();
~PdfViewPluginBase() override;
// Performs initialization common to all implementations of this plugin.
// `engine` should be an appropriately-configured PDF engine, and
// `embedder_origin` should be the origin of the plugin's embedder. The other
// parameters come from the corresponding plugin attributes.
void InitializeBase(std::unique_ptr<PDFiumEngine> engine,
base::StringPiece embedder_origin,
base::StringPiece src_url,
base::StringPiece original_url,
bool full_frame,
SkColor background_color,
bool has_edits);
// Creates a new `PDFiumEngine`.
virtual std::unique_ptr<PDFiumEngine> CreateEngine(
PDFEngine::Client* client,
PDFiumFormFiller::ScriptOption script_option);
// Destroys the main `PDFiumEngine`. Subclasses should call this method in
// their destructor to ensure the engine is destroyed first.
void DestroyEngine();
// Destroys the `PDFiumEngine` used for Print Preview. Subclasses should call
// this method in their destructor to ensure the engine is destroyed first.
void DestroyPreviewEngine();
const PDFiumEngine* engine() const { return engine_.get(); }
PDFiumEngine* engine() { return engine_.get(); }
// Starts loading `url`. If `is_print_preview` is `true`, load for print
// preview instead of normal PDF viewing.
void LoadUrl(base::StringPiece url, bool is_print_preview);
// Gets a weak pointer with a lifetime matching the derived class.
virtual base::WeakPtr<PdfViewPluginBase> GetWeakPtr() = 0;
// Creates a URL loader and allows it to access all urls, i.e. not just the
// frame's origin.
virtual std::unique_ptr<UrlLoader> CreateUrlLoaderInternal() = 0;
// Rewrites the request URL just before sending to the URL loader.
//
// TODO(crbug.com/1238829): This is a workaround for Pepper not supporting
// chrome-untrusted://print/ URLs.
virtual std::string RewriteRequestUrl(base::StringPiece url) const;
bool HandleInputEvent(const blink::WebInputEvent& event);
// Handles `postMessage()` calls from the embedder.
void HandleMessage(const base::Value& message);
// Enqueues a "message" event carrying `message` to the embedder. Messages are
// guaranteed to be received in the order that they are sent. This method is
// non-blocking.
virtual void SendMessage(base::Value message) = 0;
// Invokes the "SaveAs" dialog.
virtual void SaveAs() = 0;
void SaveToBuffer(const std::string& token);
// Consumes a token for saving the document.
void ConsumeSaveToken(const std::string& token);
// Sends the loading progress, where `percentage` represents the progress, or
// -1 for loading error.
void SendLoadingProgress(double percentage);
// Send a notification that the print preview has loaded.
void SendPrintPreviewLoadedNotification();
// Initialize image buffer(s) according to the new context size.
virtual void InitImageData(const gfx::Size& size) = 0;
// Schedules invalidation tasks after painting finishes.
void InvalidateAfterPaintDone();
// Updates the available area and the background parts, notifies the PDF
// engine, and updates the accessibility information.
void OnGeometryChanged(double old_zoom, float old_device_scale);
// Returns the plugin-specific image data buffer.
virtual Image GetPluginImageData() const;
// Updates the geometry of the plugin and its image data if the plugin rect
// or the device scale has changed. `new_plugin_rect` must be in device
// pixels (with the device scale applied).
void UpdateGeometryOnPluginRectChanged(const gfx::Rect& new_plugin_rect,
float new_device_scale);
// A helper of OnGeometryChanged() which updates the available area and
// the background parts, and notifies the PDF engine of geometry changes.
void RecalculateAreas(double old_zoom, float old_device_scale);
// Figures out the location of any background rectangles (i.e. those that
// aren't painted by the PDF engine).
void CalculateBackgroundParts();
// Updates the scroll position. `scroll_offset` is in CSS pixels relative to
// the scroll origin (which depends on the UI direction).
void UpdateScroll(const gfx::Vector2dF& scroll_offset);
// Computes document width/height in device pixels, based on current zoom and
// device scale
int GetDocumentPixelWidth() const;
int GetDocumentPixelHeight() const;
// Sets the text input type for this plugin based on `in_focus`.
virtual void SetFormTextFieldInFocus(bool in_focus) = 0;
// Sets the accessibility information about the PDF document in the renderer.
virtual void SetAccessibilityDocInfo(
const AccessibilityDocInfo& doc_info) = 0;
// Sets the accessibility information about the given `page_index` in the
// renderer.
void PrepareAndSetAccessibilityPageInfo(int32_t page_index);
// Sets the accessibility information about the page in the renderer.
virtual void SetAccessibilityPageInfo(
AccessibilityPageInfo page_info,
std::vector<AccessibilityTextRunInfo> text_runs,
std::vector<AccessibilityCharInfo> chars,
AccessibilityPageObjects page_objects) = 0;
// Prepares the accessibility information about the current viewport. Calls
// SetAccessibilityViewportInfo() internally to set this information in the
// renderer. This is done once when accessibility is first loaded and again
// when the geometry changes.
void PrepareAndSetAccessibilityViewportInfo();
// Sets the accessibility information about the current viewport in the
// renderer.
virtual void SetAccessibilityViewportInfo(
const AccessibilityViewportInfo& viewport_info) = 0;
// Find handlers.
bool StartFind(const std::string& text, bool case_sensitive);
void SelectFindResult(bool forward);
void StopFind();
// Notify the plugin container about the total matches for a find request.
virtual void NotifyFindResultsChanged(int total, bool final_result) = 0;
// Notify the frame about the tickmarks for the find request.
virtual void NotifyFindTickmarks(const std::vector<gfx::Rect>& tickmarks) = 0;
// Returns the print preset options for the document.
blink::WebPrintPresetOptions GetPrintPresetOptions();
// Begins a print session with the given `print_params`. A call to
// `PrintPages()` can only be made after after a successful call to
// `PrintBegin()`. Returns the number of pages required for the print output.
// A returned value of 0 indicates failure.
int PrintBegin(const blink::WebPrintParams& print_params);
// Prints the pages specified by `page_numbers` using the parameters passed to
// `PrintBegin()` Returns a vector of bytes containing the printed output. An
// empty returned value indicates failure.
std::vector<uint8_t> PrintPages(const std::vector<int>& page_numbers);
// Ends the print session. Further calls to `PrintPages()` will fail.
void PrintEnd();
// Disables browser commands because of restrictions on how the data is to be
// used (i.e. can't copy/print). `content_restrictions` should have its bits
// set by `chrome_pdf::ContentRestriction` enum values.
virtual void SetContentRestrictions(int content_restrictions) = 0;
// Informs the embedder whether the plugin can handle save commands
// internally.
virtual void SetPluginCanSave(bool can_save) = 0;
// Sends start/stop loading notifications to the plugin's render frame.
virtual void PluginDidStartLoading() = 0;
virtual void PluginDidStopLoading() = 0;
// Requests the plugin's render frame to set up a print dialog for the
// document.
virtual void InvokePrintDialog() = 0;
// Notifies the embedder about a new link under the cursor.
// TODO(crbug.com/702993): This is only needed by `OutOfProcessInstance`.
// Remove this method when that class ceases to exist.
virtual void NotifyLinkUnderCursor() {}
// Notifies the embedder of the top-left and bottom-right coordinates of the
// current selection.
virtual void NotifySelectionChanged(const gfx::PointF& left,
int left_height,
const gfx::PointF& right,
int right_height) = 0;
// Notifies the user about unsupported feature if the PDF Viewer occupies the
// full frame.
virtual void NotifyUnsupportedFeature() = 0;
// Records user actions.
virtual void UserMetricsRecordAction(const std::string& action) = 0;
ui::mojom::CursorType cursor_type() const { return cursor_type_; }
void set_cursor_type(ui::mojom::CursorType cursor_type) {
cursor_type_ = cursor_type;
}
const std::string& link_under_cursor() const { return link_under_cursor_; }
bool full_frame() const { return full_frame_; }
SkBitmap& mutable_image_data() { return image_data_; }
const gfx::Rect& available_area() const { return available_area_; }
void set_document_size(const gfx::Size& size) { document_size_ = size; }
const gfx::Rect& plugin_rect() const { return plugin_rect_; }
// Sets the new zoom scale.
void SetZoom(double scale);
double zoom() const { return zoom_; }
float device_scale() const { return device_scale_; }
AccessibilityState accessibility_state() const {
return accessibility_state_;
}
static constexpr bool IsSaveDataSizeValid(size_t size) {
return size > 0 && size <= kMaximumSavedFileSize;
}
static base::Value::DictStorage DictFromRect(const gfx::Rect& rect);
private:
// Message handlers.
void HandleDisplayAnnotationsMessage(const base::Value& message);
void HandleGetNamedDestinationMessage(const base::Value& message);
void HandleGetPasswordCompleteMessage(const base::Value& message);
void HandleGetSelectedTextMessage(const base::Value& message);
void HandleGetThumbnailMessage(const base::Value& message);
void HandleLoadPreviewPageMessage(const base::Value& message);
void HandlePrintMessage(const base::Value& /*message*/);
void HandleResetPrintPreviewModeMessage(const base::Value& message);
void HandleRotateClockwiseMessage(const base::Value& /*message*/);
void HandleRotateCounterclockwiseMessage(const base::Value& /*message*/);
void HandleSaveMessage(const base::Value& message);
void HandleSaveAttachmentMessage(const base::Value& message);
void HandleSelectAllMessage(const base::Value& /*message*/);
void HandleSetBackgroundColorMessage(const base::Value& message);
void HandleSetReadOnlyMessage(const base::Value& message);
void HandleSetTwoUpViewMessage(const base::Value& message);
void HandleStopScrollingMessage(const base::Value& /*message*/);
void HandleUpdateScrollMessage(const base::Value& message);
void HandleViewportMessage(const base::Value& message);
// Sends start/stop loading notifications to the plugin's render frame
// depending on `did_call_start_loading_`.
void DidStartLoading();
void DidStopLoading();
// Saves the document to a file.
void SaveToFile(const std::string& token);
// Paints the given invalid area of the plugin to the given graphics device.
// PaintManager::Client::OnPaint() should be its only caller.
void DoPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>& ready,
std::vector<gfx::Rect>& pending);
// The preparation when painting on the image data buffer for the first
// time.
void PrepareForFirstPaint(std::vector<PaintReadyRect>& ready);
// Callback to clear deferred invalidates after painting finishes.
void ClearDeferredInvalidates(int32_t /*unused_but_required*/);
// Sends the attachments data.
void SendAttachments();
// Sends the bookmarks data.
void SendBookmarks();
// Send document metadata data.
void SendMetadata();
// Sends the thumbnail image data.
void SendThumbnail(base::Value reply, Thumbnail thumbnail);
// Starts loading accessibility information.
void LoadAccessibility();
void ResetRecentlySentFindUpdate(int32_t /*unused_but_required*/);
// Records metrics about the document metadata.
void RecordDocumentMetrics();
// Adds a sample to an enumerated histogram and filter out print preview
// usage.
template <typename T>
void HistogramEnumeration(const char* name, T sample);
// Adds a sample to a custom counts histogram and filter out print preview
// usage.
void HistogramCustomCounts(const char* name,
int32_t sample,
int32_t min,
int32_t max,
uint32_t bucket_count);
// Handles `LoadUrl()` result.
void DidOpen(std::unique_ptr<UrlLoader> loader, int32_t result);
// Handles `LoadUrl()` result for print preview.
void DidOpenPreview(std::unique_ptr<UrlLoader> loader, int32_t result);
// Handles `Open()` result for `form_loader_`.
void DidFormOpen(int32_t result);
// Performs tasks necessary when the document is loaded in print preview mode.
void OnPrintPreviewLoaded();
// Reduces the document to 1 page and appends `print_preview_page_count_` - 1
// blank pages to the document for print preview.
void AppendBlankPrintPreviewPages();
// Process the preview page data information. `src_url` specifies the preview
// page data location. The `src_url` is in the format:
// chrome-untrusted://print/id/page_number/print.pdf
// `dest_page_index` specifies the blank page index that needs to be replaced
// with the new page data.
void ProcessPreviewPageInfo(const std::string& src_url, int dest_page_index);
// Load the next available preview page into the blank page.
void LoadAvailablePreviewPage();
// Called after a preview page has loaded or failed to load.
void LoadNextPreviewPage();
std::unique_ptr<PDFiumEngine> engine_;
PaintManager paint_manager_{this};
// The URL of the PDF document.
std::string url_;
// The current cursor type.
ui::mojom::CursorType cursor_type_ = ui::mojom::CursorType::kPointer;
// The URL currently under the cursor.
std::string link_under_cursor_;
// True if the plugin occupies the entire frame (not embedded).
bool full_frame_ = false;
// Image data buffer for painting.
SkBitmap image_data_;
std::vector<BackgroundPart> background_parts_;
// Deferred invalidates while `in_paint_` is true.
std::vector<gfx::Rect> deferred_invalidates_;
// Remaining area, in pixels, to render the pdf in after accounting for
// horizontal centering.
gfx::Rect available_area_;
// The size of the entire document in pixels (i.e. if each page is 800 pixels
// high and there are 10 pages, the height will be 8000).
gfx::Size document_size_;
// Size, in DIPs, of plugin rectangle.
gfx::Size plugin_dip_size_;
// The plugin rectangle in device pixels.
gfx::Rect plugin_rect_;
// The background color of the PDF viewer.
SkColor background_color_ = SK_ColorTRANSPARENT;
// Current zoom factor.
double zoom_ = 1.0;
// Current device scale factor. Multiply by `device_scale_` to convert from
// viewport to screen coordinates. Divide by `device_scale_` to convert from
// screen to viewport coordinates.
float device_scale_ = 1.0f;
// True if we haven't painted the plugin viewport yet.
bool first_paint_ = true;
// Whether OnPaint() is in progress or not.
bool in_paint_ = false;
// True if last bitmap was smaller than the screen.
bool last_bitmap_smaller_ = false;
// True if we request a new bitmap rendering.
bool needs_reraster_ = true;
// The UI direction.
base::i18n::TextDirection ui_direction_ = base::i18n::UNKNOWN_DIRECTION;
// The scroll offset for the last raster in CSS pixels, before any
// transformations are applied.
gfx::Vector2dF scroll_offset_at_last_raster_;
// If this is true, then don't scroll the plugin in response to the messages
// from DidChangeView() or HandleUpdateScrollMessage(). This will be true when
// the extension page is in the process of zooming the plugin so that
// flickering doesn't occur while zooming.
bool stop_scrolling_ = false;
// Whether the plugin has received a viewport changed message. Nothing should
// be painted until this is received.
bool received_viewport_message_ = false;
// The callback for receiving the password from the page.
base::OnceCallback<void(const std::string&)> password_callback_;
// The last document load progress value sent to the web page.
double last_progress_sent_ = 0.0;
// The current state of document load.
DocumentLoadState document_load_state_ = DocumentLoadState::kLoading;
// If true, the render frame has been notified that we're starting a network
// request so that it can start the throbber. It will be notified again once
// the document finishes loading.
bool did_call_start_loading_ = false;
// The current state of accessibility.
AccessibilityState accessibility_state_ = AccessibilityState::kOff;
// The next accessibility page index, used to track interprocess calls when
// reconstructing the tree for new document layouts.
int32_t next_accessibility_page_index_ = 0;
// Whether an update to the number of find results found was sent less than
// `kFindResultCooldownMs` milliseconds ago.
bool recently_sent_find_update_ = false;
// Stores the tickmarks to be shown for the current find results.
std::vector<gfx::Rect> tickmarks_;
// Keeps track of which unsupported features have been reported to avoid
// spamming the metrics if a feature shows up many times per document.
base::flat_set<std::string> unsupported_features_reported_;
// Indicates whether the browser has been notified about an unsupported
// feature once, which helps prevent the infobar from going up more than once.
bool notified_browser_about_unsupported_feature_ = false;
// Whether the document is in edit mode.
bool edit_mode_ = false;
// Used for submitting forms.
std::unique_ptr<UrlLoader> form_loader_;
// Assigned a value only between `PrintBegin()` and `PrintEnd()` calls.
absl::optional<blink::WebPrintParams> print_params_;
// For identifying actual print operations to avoid double logging of UMA.
bool print_pages_called_;
// The PreviewModeClient used for print preview. Will be passed to
// `preview_engine_`.
std::unique_ptr<PreviewModeClient> preview_client_;
// This engine is used to render the individual preview page data. This is
// used only in print preview mode. This will use `PreviewModeClient`
// interface which has very limited access to the pp::Instance.
std::unique_ptr<PDFiumEngine> preview_engine_;
DocumentLoadState preview_document_load_state_ = DocumentLoadState::kComplete;
// True if the plugin is loaded in print preview, otherwise false.
bool is_print_preview_ = false;
// Number of pages in print preview mode for non-PDF source, 0 if print
// previewing a PDF, and -1 if not in print preview mode.
int print_preview_page_count_ = -1;
// Number of pages loaded in print preview mode for non-PDF source. Always
// less than or equal to `print_preview_page_count_`.
int print_preview_loaded_page_count_ = -1;
// Used to manage loaded print preview page information. A `PreviewPageInfo`
// consists of data source URL string and the page index in the destination
// document.
// The URL string embeds a page number that can be found with
// ExtractPrintPreviewPageIndex(). This page number is always greater than 0.
// The page index is always in the range of [0, print_preview_page_count_).
using PreviewPageInfo = std::pair<std::string, int>;
base::queue<PreviewPageInfo> preview_pages_info_;
};
} // namespace chrome_pdf
#endif // PDF_PDF_VIEW_PLUGIN_BASE_H_