1 // Copyright 2020 The Chromium Authors
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_PDF_VIEW_PLUGIN_BASE_H_
6 #define PDF_PDF_VIEW_PLUGIN_BASE_H_
15 #include "base/callback.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/strings/string_piece.h"
18 #include "base/values.h"
19 #include "pdf/accessibility_structs.h"
20 #include "pdf/paint_manager.h"
21 #include "pdf/pdf_engine.h"
22 #include "third_party/abseil-cpp/absl/types/optional.h"
23 #include "third_party/blink/public/web/web_print_params.h"
24 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "ui/gfx/geometry/rect.h"
31 namespace chrome_pdf {
34 struct AccessibilityCharInfo;
35 struct AccessibilityDocInfo;
36 struct AccessibilityPageInfo;
37 struct AccessibilityPageObjects;
38 struct AccessibilityTextRunInfo;
39 struct AccessibilityViewportInfo;
41 // TODO(crbug.com/1302059): Merge with PdfViewWebPlugin.
42 class PdfViewPluginBase : public PDFEngine::Client {
44 enum class AccessibilityState {
46 kPending, // Enabled but waiting for doc to load.
47 kLoaded, // Fully loaded.
50 enum class DocumentLoadState {
56 PdfViewPluginBase(const PdfViewPluginBase& other) = delete;
57 PdfViewPluginBase& operator=(const PdfViewPluginBase& other) = delete;
60 void DocumentLoadComplete() override;
61 void DocumentLoadFailed() override;
62 void SelectionChanged(const gfx::Rect& left, const gfx::Rect& right) override;
66 ~PdfViewPluginBase() override;
68 virtual const PDFiumEngine* engine() const = 0;
69 virtual PDFiumEngine* engine() = 0;
71 // Gets a weak pointer with a lifetime matching the derived class.
72 virtual base::WeakPtr<PdfViewPluginBase> GetWeakPtr() = 0;
74 // Runs when document load completes in Print Preview, before
75 // `OnDocumentLoadComplete()`.
76 virtual void OnPrintPreviewLoaded() = 0;
78 // Runs when document load completes.
79 virtual void OnDocumentLoadComplete() = 0;
81 // Sends the loading progress, where `percentage` represents the progress, or
82 // -1 for loading error.
83 virtual void SendLoadingProgress(double percentage) = 0;
85 // Sets the accessibility information about the PDF document in the renderer.
86 virtual void SetAccessibilityDocInfo(AccessibilityDocInfo doc_info) = 0;
88 // Sets the accessibility information about the given `page_index` in the
90 void PrepareAndSetAccessibilityPageInfo(int32_t page_index);
92 // Sets the accessibility information about the page in the renderer.
93 virtual void SetAccessibilityPageInfo(
94 AccessibilityPageInfo page_info,
95 std::vector<AccessibilityTextRunInfo> text_runs,
96 std::vector<AccessibilityCharInfo> chars,
97 AccessibilityPageObjects page_objects) = 0;
99 // Prepares the accessibility information about the current viewport. Calls
100 // SetAccessibilityViewportInfo() internally to set this information in the
101 // renderer. This is done once when accessibility is first loaded and again
102 // when the geometry changes.
103 void PrepareAndSetAccessibilityViewportInfo();
105 // Sets the accessibility information about the current viewport in the
107 virtual void SetAccessibilityViewportInfo(
108 AccessibilityViewportInfo viewport_info) = 0;
110 // Disables browser commands because of restrictions on how the data is to be
111 // used (i.e. can't copy/print). `content_restrictions` should have its bits
112 // set by `chrome_pdf::ContentRestriction` enum values.
113 virtual void SetContentRestrictions(int content_restrictions) = 0;
115 // Sends start/stop loading notifications to the plugin's render frame.
116 virtual void DidStartLoading() = 0;
117 virtual void DidStopLoading() = 0;
119 // Notifies the embedder of the top-left and bottom-right coordinates of the
120 // current selection.
121 virtual void NotifySelectionChanged(const gfx::PointF& left,
123 const gfx::PointF& right,
124 int right_height) = 0;
126 // Records user actions.
127 virtual void UserMetricsRecordAction(const std::string& action) = 0;
129 virtual PaintManager& paint_manager() = 0;
130 virtual const gfx::Rect& available_area() const = 0;
131 virtual double zoom() const = 0;
132 virtual bool full_frame() const = 0;
134 // TODO(crbug.com/1288847): Don't provide direct access to the origin of
135 // `plugin_rect_`, as this exposes the unintuitive "paint offset."
136 virtual const gfx::Rect& plugin_rect() const = 0;
138 virtual float device_scale() const = 0;
139 virtual DocumentLoadState document_load_state() const = 0;
140 virtual void set_document_load_state(DocumentLoadState state) = 0;
141 virtual AccessibilityState accessibility_state() const = 0;
142 virtual void set_accessibility_state(AccessibilityState state) = 0;
143 virtual int32_t next_accessibility_page_index() const = 0;
144 virtual void increment_next_accessibility_page_index() = 0;
145 virtual void reset_next_accessibility_page_index() = 0;
147 // Starts loading accessibility information.
148 void LoadAccessibility();
150 // Gets the content restrictions based on the permissions which `engine_` has.
151 int GetContentRestrictions() const;
153 // Gets the accessibility doc info based on the information from `engine_`.
154 AccessibilityDocInfo GetAccessibilityDocInfo() const;
157 } // namespace chrome_pdf
159 #endif // PDF_PDF_VIEW_PLUGIN_BASE_H_