forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathout_of_process_instance.h
410 lines (336 loc) · 15.1 KB
/
out_of_process_instance.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
// Copyright (c) 2012 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_OUT_OF_PROCESS_INSTANCE_H_
#define PDF_OUT_OF_PROCESS_INSTANCE_H_
#include <stdint.h>
#include <string.h>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/callback.h"
#include "base/containers/queue.h"
#include "base/location.h"
#include "base/memory/weak_ptr.h"
#include "pdf/pdf_view_plugin_base.h"
#include "pdf/preview_mode_client.h"
#include "ppapi/c/private/ppp_pdf.h"
#include "ppapi/cpp/dev/printing_dev.h"
#include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/private/find_private.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
namespace gfx {
class Size;
class Vector2d;
} // namespace gfx
namespace pp {
class Size;
class TextInput_Dev;
class VarArray;
class VarDictionary;
} // namespace pp
namespace chrome_pdf {
class Graphics;
class PDFiumEngine;
class Thumbnail;
class UrlLoader;
class OutOfProcessInstance : public PdfViewPluginBase,
public pp::Instance,
public pp::Find_Private,
public pp::Printing_Dev,
public PreviewModeClient::Client {
public:
explicit OutOfProcessInstance(PP_Instance instance);
OutOfProcessInstance(const OutOfProcessInstance&) = delete;
OutOfProcessInstance& operator=(const OutOfProcessInstance&) = delete;
~OutOfProcessInstance() override;
// pp::Instance:
bool Init(uint32_t argc, const char* argn[], const char* argv[]) override;
void HandleMessage(const pp::Var& message) override;
bool HandleInputEvent(const pp::InputEvent& event) override;
void DidChangeView(const pp::View& view) override;
void DidChangeFocus(bool has_focus) override;
// pp::Find_Private:
bool StartFind(const std::string& text, bool case_sensitive) override;
void SelectFindResult(bool forward) override;
void StopFind() override;
// pp::Printing_Dev:
uint32_t QuerySupportedPrintOutputFormats() override;
int32_t PrintBegin(const PP_PrintSettings_Dev& print_settings) override;
pp::Resource PrintPages(const PP_PrintPageNumberRange_Dev* page_ranges,
uint32_t page_range_count) override;
void PrintEnd() override;
bool IsPrintScalingDisabled() override;
// pp::Private:
pp::Var GetLinkAtPosition(const pp::Point& point);
void GetPrintPresetOptionsFromDocument(PP_PdfPrintPresetOptions_Dev* options);
void SetCaretPosition(const pp::FloatPoint& position);
void MoveRangeSelectionExtent(const pp::FloatPoint& extent);
void SetSelectionBounds(const pp::FloatPoint& base,
const pp::FloatPoint& extent);
bool CanEditText();
bool HasEditableText();
void ReplaceSelection(const std::string& text);
bool CanUndo();
bool CanRedo();
void Undo();
void Redo();
int32_t PdfPrintBegin(const PP_PrintSettings_Dev* print_settings,
const PP_PdfPrintSettings_Dev* pdf_print_settings);
void FlushCallback(int32_t result);
// 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) 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() 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;
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;
// PreviewModeClient::Client:
void PreviewDocumentLoadComplete() override;
void PreviewDocumentLoadFailed() override;
// Helper functions for implementing PPP_PDF.
void RotateClockwise();
void RotateCounterclockwise();
// Creates a file name for saving a PDF file, given the source URL. Exposed
// for testing.
static std::string GetFileNameFromUrl(const std::string& url);
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 SendMessage(base::Value message) override;
void InitImageData(const gfx::Size& size) override;
Image GetPluginImageData() const override;
void SetAccessibilityDocInfo(const AccessibilityDocInfo& doc_info) override;
void SetAccessibilityPageInfo(AccessibilityPageInfo page_info,
std::vector<AccessibilityTextRunInfo> text_runs,
std::vector<AccessibilityCharInfo> chars,
AccessibilityPageObjects page_objects) override;
void SetAccessibilityViewportInfo(
const AccessibilityViewportInfo& viewport_info) override;
private:
// Message handlers.
void HandleGetPasswordCompleteMessage(const pp::VarDictionary& dict);
void HandleGetThumbnailMessage(const pp::VarDictionary& dict);
void HandleLoadPreviewPageMessage(const pp::VarDictionary& dict);
void HandleResetPrintPreviewModeMessage(const pp::VarDictionary& dict);
void HandleSaveAttachmentMessage(const pp::VarDictionary& dict);
void HandleSaveMessage(const pp::VarDictionary& dict);
void HandleUpdateScrollMessage(const pp::VarDictionary& dict);
// Repaints plugin contents based on the current scroll position.
void UpdateScroll();
void ResetRecentlySentFindUpdate(int32_t);
// Returns a VarArray of Attachments. Each Attachment is a VarDictionary
// which contains the following key/values:
// - "name" - a string Var.
// - "size" - an int Var (-1 indicates the attachment file is too big to be
// downloaded).
// - "readable" a bool Var.
pp::VarArray GetDocumentAttachments();
bool CanSaveEdits() const;
void SaveToFile(const std::string& token);
void SaveToBuffer(const std::string& token);
void ConsumeSaveToken(const std::string& token);
void FormDidOpen(int32_t result);
void RecordDocumentMetrics();
void UserMetricsRecordAction(const std::string& action);
// Must match SaveRequestType in chrome/browser/resources/pdf/constants.js.
enum class SaveRequestType {
kAnnotation = 0,
kOriginal = 1,
kEdited = 2,
};
// 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://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();
// Send a notification that the print preview has loaded.
void SendPrintPreviewLoadedNotification();
// Send attachments.
void SendAttachments();
// Send bookmarks.
void SendBookmarks();
// Send document metadata.
void SendMetadata();
// Send the loading progress, where |percentage| represents the progress, or
// -1 for loading error.
void SendLoadingProgress(double percentage);
// Sends the thumbnail image data.
void SendThumbnail(const std::string& message_id, Thumbnail thumbnail);
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class PdfHasAttachment {
kNo = 0,
kYes = 1,
kMaxValue = kYes,
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class PdfIsTagged {
kNo = 0,
kYes = 1,
kMaxValue = kYes,
};
// Add a sample to an enumerated histogram and filter out print preview usage.
template <typename T>
void HistogramEnumeration(const char* name, T sample);
// Add 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);
// Callback to print without re-entrancy issues.
void OnPrint(int32_t /*unused_but_required*/);
// Helper for HandleInputEvent(). Returns whether engine() handled the event
// or not.
bool SendInputEventToEngine(const pp::InputEvent& event);
// The Pepper image data that is in sync with image_data().
pp::ImageData pepper_image_data_;
// The current cursor.
PP_CursorType_Dev cursor_ = PP_CURSORTYPE_POINTER;
// The scroll position in CSS pixels.
gfx::Point scroll_position_;
// True if the plugin is full-page.
bool full_ = false;
struct PrintSettings {
PrintSettings() { Clear(); }
void Clear();
// This is set to true when PdfPrintBegin() is called and false when
// PrintEnd() is called.
bool is_printing;
// To know whether this was an actual print operation, so we don't double
// count UMA logging.
bool print_pages_called;
// Generic print settings.
PP_PrintSettings_Dev pepper_print_settings;
// PDF-specific print settings.
PP_PdfPrintSettings_Dev pdf_print_settings;
};
PrintSettings print_settings_;
// 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_;
std::string url_;
// Used for submitting forms.
std::unique_ptr<UrlLoader> form_loader_;
// The callback for receiving the password from the page.
base::OnceCallback<void(const std::string&)> password_callback_;
DocumentLoadState preview_document_load_state_ = DocumentLoadState::kComplete;
// Used so that we only tell the browser once about an unsupported feature, to
// avoid the infobar going up more than once.
bool told_browser_about_unsupported_feature_ = false;
// Keeps track of which unsupported features we reported, so we avoid spamming
// the stats if a feature shows up many times per document.
std::set<std::string> unsupported_features_reported_;
// 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_;
// Used to signal the browser about focus changes to trigger the OSK.
// TODO(abodenha@chromium.org) Implement full IME support in the plugin.
// http://crbug.com/132565
std::unique_ptr<pp::TextInput_Dev> text_input_;
// The last document load progress value sent to the web page.
double last_progress_sent_ = 0.0;
// Whether an update to the number of find results found was sent less than
// |kFindResultCooldownMs| milliseconds ago.
bool recently_sent_find_update_ = false;
// The tickmarks.
std::vector<pp::Rect> tickmarks_;
// If true, this means we told the RenderView that we're starting a network
// request so that it can start the throbber. We will tell it again once the
// document finishes loading.
bool did_call_start_loading_ = false;
bool edit_mode_ = false;
base::WeakPtrFactory<OutOfProcessInstance> weak_factory_{this};
};
} // namespace chrome_pdf
#endif // PDF_OUT_OF_PROCESS_INSTANCE_H_