[M108 Migration][HBBTV] Implement ewk_context_register_jsplugin_mime_types API
[platform/framework/web/chromium-efl.git] / pdf / pdf_view_plugin_base.h
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.
4
5 #ifndef PDF_PDF_VIEW_PLUGIN_BASE_H_
6 #define PDF_PDF_VIEW_PLUGIN_BASE_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <string>
12 #include <utility>
13 #include <vector>
14
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"
26
27 namespace gfx {
28 class PointF;
29 }  // namespace gfx
30
31 namespace chrome_pdf {
32
33 class PDFiumEngine;
34 struct AccessibilityCharInfo;
35 struct AccessibilityDocInfo;
36 struct AccessibilityPageInfo;
37 struct AccessibilityPageObjects;
38 struct AccessibilityTextRunInfo;
39 struct AccessibilityViewportInfo;
40
41 // TODO(crbug.com/1302059): Merge with PdfViewWebPlugin.
42 class PdfViewPluginBase : public PDFEngine::Client {
43  public:
44   enum class AccessibilityState {
45     kOff = 0,  // Off.
46     kPending,  // Enabled but waiting for doc to load.
47     kLoaded,   // Fully loaded.
48   };
49
50   enum class DocumentLoadState {
51     kLoading = 0,
52     kComplete,
53     kFailed,
54   };
55
56   PdfViewPluginBase(const PdfViewPluginBase& other) = delete;
57   PdfViewPluginBase& operator=(const PdfViewPluginBase& other) = delete;
58
59   // PDFEngine::Client:
60   void DocumentLoadComplete() override;
61   void DocumentLoadFailed() override;
62   void SelectionChanged(const gfx::Rect& left, const gfx::Rect& right) override;
63
64  protected:
65   PdfViewPluginBase();
66   ~PdfViewPluginBase() override;
67
68   virtual const PDFiumEngine* engine() const = 0;
69   virtual PDFiumEngine* engine() = 0;
70
71   // Gets a weak pointer with a lifetime matching the derived class.
72   virtual base::WeakPtr<PdfViewPluginBase> GetWeakPtr() = 0;
73
74   // Runs when document load completes in Print Preview, before
75   // `OnDocumentLoadComplete()`.
76   virtual void OnPrintPreviewLoaded() = 0;
77
78   // Runs when document load completes.
79   virtual void OnDocumentLoadComplete() = 0;
80
81   // Sends the loading progress, where `percentage` represents the progress, or
82   // -1 for loading error.
83   virtual void SendLoadingProgress(double percentage) = 0;
84
85   // Sets the accessibility information about the PDF document in the renderer.
86   virtual void SetAccessibilityDocInfo(AccessibilityDocInfo doc_info) = 0;
87
88   // Sets the accessibility information about the given `page_index` in the
89   // renderer.
90   void PrepareAndSetAccessibilityPageInfo(int32_t page_index);
91
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;
98
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();
104
105   // Sets the accessibility information about the current viewport in the
106   // renderer.
107   virtual void SetAccessibilityViewportInfo(
108       AccessibilityViewportInfo viewport_info) = 0;
109
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;
114
115   // Sends start/stop loading notifications to the plugin's render frame.
116   virtual void DidStartLoading() = 0;
117   virtual void DidStopLoading() = 0;
118
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,
122                                       int left_height,
123                                       const gfx::PointF& right,
124                                       int right_height) = 0;
125
126   // Records user actions.
127   virtual void UserMetricsRecordAction(const std::string& action) = 0;
128
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;
133
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;
137
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;
146
147   // Starts loading accessibility information.
148   void LoadAccessibility();
149
150   // Gets the content restrictions based on the permissions which `engine_` has.
151   int GetContentRestrictions() const;
152
153   // Gets the accessibility doc info based on the information from `engine_`.
154   AccessibilityDocInfo GetAccessibilityDocInfo() const;
155 };
156
157 }  // namespace chrome_pdf
158
159 #endif  // PDF_PDF_VIEW_PLUGIN_BASE_H_