forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_view_web_plugin.h
159 lines (142 loc) · 6.92 KB
/
pdf_view_web_plugin.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
// 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_WEB_PLUGIN_H_
#define PDF_PDF_VIEW_WEB_PLUGIN_H_
#include "base/location.h"
#include "base/memory/weak_ptr.h"
#include "pdf/pdf_view_plugin_base.h"
#include "pdf/post_message_receiver.h"
#include "pdf/ppapi_migration/url_loader.h"
#include "third_party/blink/public/web/web_plugin.h"
#include "third_party/blink/public/web/web_plugin_params.h"
#include "v8/include/v8.h"
namespace base {
class Value;
} // namespace base
namespace blink {
class WebPluginContainer;
} // namespace blink
namespace chrome_pdf {
// Skeleton for a `blink::WebPlugin` to replace `OutOfProcessInstance`.
class PdfViewWebPlugin final : public PdfViewPluginBase,
public blink::WebPlugin,
public BlinkUrlLoader::Client,
public PostMessageReceiver::Client {
public:
explicit PdfViewWebPlugin(const blink::WebPluginParams& params);
PdfViewWebPlugin(const PdfViewWebPlugin& other) = delete;
PdfViewWebPlugin& operator=(const PdfViewWebPlugin& other) = delete;
// blink::WebPlugin:
bool Initialize(blink::WebPluginContainer* container) override;
void Destroy() override;
blink::WebPluginContainer* Container() const override;
v8::Local<v8::Object> V8ScriptableObject(v8::Isolate* isolate) override;
void UpdateAllLifecyclePhases(blink::DocumentUpdateReason reason) override;
void Paint(cc::PaintCanvas* canvas, const gfx::Rect& rect) override;
void UpdateGeometry(const gfx::Rect& window_rect,
const gfx::Rect& clip_rect,
const gfx::Rect& unobscured_rect,
bool is_visible) override;
void UpdateFocus(bool focused, blink::mojom::FocusType focus_type) override;
void UpdateVisibility(bool visibility) override;
blink::WebInputEventResult HandleInputEvent(
const blink::WebCoalescedInputEvent& event,
ui::Cursor* cursor) override;
void DidReceiveResponse(const blink::WebURLResponse& response) override;
void DidReceiveData(const char* data, size_t data_length) override;
void DidFinishLoading() override;
void DidFailLoading(const blink::WebURLError& error) override;
// PdfViewPluginBase:
void ProposeDocumentLayout(const DocumentLayout& layout) override;
void DidScroll(const gfx::Vector2d& offset) override;
void ScrollToX(int x_in_screen_coords) override;
void ScrollToY(int y_in_screen_coords, bool compensate_for_toolbar) override;
void ScrollBy(const gfx::Vector2d& scroll_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 UpdateCursor(PP_CursorType_Dev cursor) override;
void UpdateTickMarks(const std::vector<gfx::Rect>& tickmarks) override;
void NotifyNumberOfFindResultsChanged(int total, bool final_result) override;
void NotifySelectedFindResultChanged(int current_find_index) override;
void NotifyTouchSelectionOccurred() override;
void GetDocumentPassword(
base::OnceCallback<void(const std::string&)> callback) override;
void Beep() 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::unique_ptr<UrlLoader> CreateUrlLoader() override;
std::vector<SearchStringResult> SearchString(const base::char16* string,
const base::char16* term,
bool case_sensitive) override;
void DocumentLoadComplete(
const PDFEngine::DocumentFeatures& document_features) 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;
void IsSelectingChanged(bool is_selecting) override;
void SelectionChanged(const gfx::Rect& left, const gfx::Rect& right) override;
void EnteredEditMode() override;
float GetToolbarHeightInScreenCoords() override;
void DocumentFocusChanged(bool document_has_focus) override;
void SetSelectedText(const std::string& selected_text) override;
void SetLinkUnderCursor(const std::string& link_under_cursor) override;
bool IsValidLink(const std::string& url) override;
std::unique_ptr<Graphics> CreatePaintGraphics(const gfx::Size& size) override;
bool BindPaintGraphics(Graphics& graphics) override;
void ScheduleTaskOnMainThread(
base::TimeDelta delay,
ResultCallback callback,
int32_t result,
const base::Location& from_here = base::Location::Current()) override;
// BlinkUrlLoader::Client:
bool IsValid() const override;
blink::WebURL CompleteURL(const blink::WebString& partial_url) const override;
net::SiteForCookies SiteForCookies() const override;
void SetReferrerForRequest(blink::WebURLRequest& request,
const blink::WebURL& referrer_url) override;
std::unique_ptr<blink::WebAssociatedURLLoader> CreateAssociatedURLLoader(
const blink::WebAssociatedURLLoaderOptions& options) override;
// PostMessageReceiver::Client:
void OnMessage(const base::Value& message) override;
protected:
// PdfViewPluginBase:
base::WeakPtr<PdfViewPluginBase> GetWeakPtr() override;
std::unique_ptr<UrlLoader> CreateUrlLoaderInternal() override;
void DidOpen(std::unique_ptr<UrlLoader> loader, int32_t result) override;
void DidOpenPreview(std::unique_ptr<UrlLoader> loader,
int32_t result) override;
void DoPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) override;
void OnGeometryChanged(double old_zoom, float old_device_scale) override;
private:
// Call `Destroy()` instead.
~PdfViewWebPlugin() override;
blink::WebPluginParams initial_params_;
blink::WebPluginContainer* container_ = nullptr;
v8::Persistent<v8::Object> scriptable_receiver_;
base::WeakPtrFactory<PdfViewWebPlugin> weak_factory_{this};
};
} // namespace chrome_pdf
#endif // PDF_PDF_VIEW_WEB_PLUGIN_H_