1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
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 PPAPI_C_PRIVATE_PPB_PDF_H_
6 #define PPAPI_C_PRIVATE_PPB_PDF_H_
7 
8 #include <stdint.h>
9 
10 #include "ppapi/c/pp_bool.h"
11 #include "ppapi/c/pp_instance.h"
12 #include "ppapi/c/pp_point.h"
13 #include "ppapi/c/pp_rect.h"
14 #include "ppapi/c/pp_resource.h"
15 #include "ppapi/c/pp_var.h"
16 #include "ppapi/c/private/pp_private_font_charset.h"
17 
18 #define PPB_PDF_INTERFACE "PPB_PDF;1"
19 
20 typedef enum {
21   PP_PDFFEATURE_HIDPI = 0,
22   PP_PDFFEATURE_PRINTING = 1
23 } PP_PDFFeature;
24 
25 typedef enum {
26   PP_CONTENT_RESTRICTION_COPY = 1 << 0,
27   PP_CONTENT_RESTRICTION_CUT = 1 << 1,
28   PP_CONTENT_RESTRICTION_PASTE = 1 << 2,
29   PP_CONTENT_RESTRICTION_PRINT = 1 << 3,
30   PP_CONTENT_RESTRICTION_SAVE = 1 << 4
31 } PP_ContentRestriction;
32 
33 struct PP_PrivateFontFileDescription {
34   const char* face;
35   uint32_t weight;
36   bool italic;
37 };
38 
39 struct PP_PrivateFindResult {
40   int start_index;
41   int length;
42 };
43 
44 typedef enum {
45   PP_PRIVATEFOCUSOBJECT_NONE = 0,
46   PP_PRIVATEFOCUSOBJECT_DOCUMENT = 1,
47   PP_PRIVATEFOCUSOBJECT_LINK = 2,
48   PP_PRIVATEFOCUSOBJECT_HIGHLIGHT = 3,
49   PP_PRIVATEFOCUSOBJECT_TEXT_FIELD = 4,
50   PP_PRIVATEFOCUSOBJECT_LAST = PP_PRIVATEFOCUSOBJECT_TEXT_FIELD
51 } PP_PrivateFocusObjectType;
52 
53 // Represents the information to uniquely identify the focused object
54 // in PDF.
55 struct PP_PrivateAccessibilityFocusInfo {
56   // Holds the type of the focused object in PDFiumEngine.
57   PP_PrivateFocusObjectType focused_object_type;
58   // Holds the PDF page index in the which the focused annotation is present.
59   // When |focused_object_type| is PP_PRIVATEFOCUSOBJECT_NONE or
60   // PP_PRIVATEFOCUSOBJECT_DOCUMENT then the value of this member shouldn't
61   // be used, set to zero as a sentinel value.
62   uint32_t focused_object_page_index;
63   // Holds the focused annotation's index in page's annotations array.
64   // When |focused_object_type| is PP_PRIVATEFOCUSOBJECT_NONE or
65   // PP_PRIVATEFOCUSOBJECT_DOCUMENT then the value of this member shouldn't
66   // be used, set to zero as a sentinel value.
67   uint32_t focused_annotation_index_in_page;
68 };
69 
70 struct PP_PrivateAccessibilityViewportInfo {
71   double zoom;
72   double scale;
73   struct PP_Point scroll;
74   struct PP_Point offset;
75   uint32_t selection_start_page_index;
76   uint32_t selection_start_char_index;
77   uint32_t selection_end_page_index;
78   uint32_t selection_end_char_index;
79   struct PP_PrivateAccessibilityFocusInfo focus_info;
80 };
81 
82 struct PP_PrivateAccessibilityDocInfo {
83   uint32_t page_count;
84   PP_Bool text_accessible;
85   PP_Bool text_copyable;
86 };
87 
88 typedef enum {
89   PP_PRIVATEDIRECTION_NONE = 0,
90   PP_PRIVATEDIRECTION_LTR = 1,
91   PP_PRIVATEDIRECTION_RTL = 2,
92   PP_PRIVATEDIRECTION_TTB = 3,
93   PP_PRIVATEDIRECTION_BTT = 4,
94   PP_PRIVATEDIRECTION_LAST = PP_PRIVATEDIRECTION_BTT
95 } PP_PrivateDirection;
96 
97 struct PP_PrivateAccessibilityPageInfo {
98   uint32_t page_index;
99   struct PP_Rect bounds;
100   uint32_t text_run_count;
101   uint32_t char_count;
102 };
103 
104 // See PDF Reference 1.7, page 402, table 5.3.
105 typedef enum {
106   PP_TEXTRENDERINGMODE_UNKNOWN = -1,
107   PP_TEXTRENDERINGMODE_FILL = 0,
108   PP_TEXTRENDERINGMODE_STROKE = 1,
109   PP_TEXTRENDERINGMODE_FILLSTROKE = 2,
110   PP_TEXTRENDERINGMODE_INVISIBLE = 3,
111   PP_TEXTRENDERINGMODE_FILLCLIP = 4,
112   PP_TEXTRENDERINGMODE_STROKECLIP = 5,
113   PP_TEXTRENDERINGMODE_FILLSTROKECLIP = 6,
114   PP_TEXTRENDERINGMODE_CLIP = 7,
115   PP_TEXTRENDERINGMODE_LAST = PP_TEXTRENDERINGMODE_CLIP
116 } PP_TextRenderingMode;
117 
118 // This holds the text style information provided by the PDF and will be used
119 // in accessibility to provide the text style information. Needs to stay in
120 // sync with C++ version. (PrivateAccessibilityTextStyleInfo and
121 // PdfAccessibilityTextStyleInfo)
122 struct PP_PrivateAccessibilityTextStyleInfo {
123   const char* font_name;
124   uint32_t font_name_length;
125   int font_weight;
126   PP_TextRenderingMode render_mode;
127   float font_size;
128   // Colors are ARGB.
129   uint32_t fill_color;
130   uint32_t stroke_color;
131   bool is_italic;
132   bool is_bold;
133 };
134 
135 // This holds the text run information provided by the PDF and will be used in
136 // accessibility to provide the text run information.
137 // Needs to stay in sync with C++ version. (PrivateAccessibilityTextRunInfo and
138 // PdfAccessibilityTextRunInfo)
139 struct PP_PrivateAccessibilityTextRunInfo {
140   uint32_t len;
141   struct PP_FloatRect bounds;
142   PP_PrivateDirection direction;
143   struct PP_PrivateAccessibilityTextStyleInfo style;
144 };
145 
146 struct PP_PrivateAccessibilityCharInfo {
147   uint32_t unicode_character;
148   double char_width;
149 };
150 
151 // This holds the link information provided by the PDF and will be used in
152 // accessibility to provide the link information. Needs to stay in sync with
153 // C++ versions (PdfAccessibilityLinkInfo and PrivateAccessibilityLinkInfo).
154 // This struct contains index state that should be validated using
155 // PdfAccessibilityTree::IsDataFromPluginValid() before usage.
156 struct PP_PrivateAccessibilityLinkInfo {
157   // URL of the link.
158   const char* url;
159   uint32_t url_length;
160   // Index of the link in the page. This will be used to identify the link on
161   // which action has to be performed in the page.
162   // |index_in_page| is populated and used in plugin process to handle
163   // accessiility actions from mimehandler process. It's value should be
164   // validated in plugin before usage.
165   uint32_t index_in_page;
166   // Link can either be part of the page text or not. If the link is part of the
167   // page text, then |text_run_index| denotes the text run which contains the
168   // start_index of the link and the |text_run_count| equals the number of text
169   // runs the link spans in the page text. If the link is not part of the page
170   // text then |text_run_count| should be 0 and the |text_run_index| should
171   // contain the nearest char index to the bounding rectangle of the link.
172   uint32_t text_run_index;
173   uint32_t text_run_count;
174   // Bounding box of the link.
175   struct PP_FloatRect bounds;
176 };
177 
178 // This holds the image information provided by the PDF and will be used in
179 // accessibility to provide the image information. Needs to stay in sync with
180 // C++ versions (PdfAccessibilityImageInfo and PrivateAccessibilityImageInfo).
181 // This struct contains index state that should be validated using
182 // PdfAccessibilityTree::IsDataFromPluginValid() before usage.
183 struct PP_PrivateAccessibilityImageInfo {
184   // Alternate text for the image provided by PDF.
185   const char* alt_text;
186   uint32_t alt_text_length;
187   // We anchor the image to a char index, this denotes the text run before
188   // which the image should be inserted in the accessibility tree. The text run
189   // at this index should contain the anchor char index.
190   uint32_t text_run_index;
191   // Bounding box of the image.
192   struct PP_FloatRect bounds;
193 };
194 
195 // This holds text highlight information provided by the PDF and will be
196 // used in accessibility to expose it. Text highlights can have an associated
197 // popup note, the data of which is also captured here.
198 // Needs to stay in sync with C++ versions (PdfAccessibilityHighlightInfo and
199 // PrivateAccessibilityHighlightInfo).
200 // This struct contains index state that should be validated using
201 // PdfAccessibilityTree::IsDataFromPluginValid() before usage.
202 struct PP_PrivateAccessibilityHighlightInfo {
203   // Represents the text of the associated popup note, if present.
204   const char* note_text;
205   uint32_t note_text_length;
206   // Index of the highlight in the page annotation list. Used to identify the
207   // annotation on which action needs to be performed.
208   // |index_in_page| is populated and used in plugin process to handle
209   // accessiility actions from mimehandler process. It's value should be
210   // validated in plugin before usage.
211   uint32_t index_in_page;
212   // Highlights are annotations over existing page text.  |text_run_index|
213   // denotes the index of the text run where the highlight starts and
214   // |text_run_count| denotes the number of text runs which the highlight spans
215   // across.
216   uint32_t text_run_index;
217   uint32_t text_run_count;
218   // Bounding box of the highlight.
219   struct PP_FloatRect bounds;
220   // Color of the highlight in ARGB. Alpha is stored in the first 8 MSBs. RGB
221   // follows after it with each using 8 bytes.
222   uint32_t color;
223 };
224 
225 // This holds text form field information provided by the PDF and will be used
226 // in accessibility to expose it. Needs to stay in sync with C++ versions
227 // (PdfAccessibilityTextFieldInfo and PrivateAccessibilityTextFieldInfo).
228 // This struct contains index state that should be validated using
229 // PdfAccessibilityTree::IsDataFromPluginValid() before usage.
230 struct PP_PrivateAccessibilityTextFieldInfo {
231   // Represents the name property of text field, if present.
232   const char* name;
233   uint32_t name_length;
234   // Represents the value property of text field, if present.
235   const char* value;
236   uint32_t value_length;
237   // Represents if the text field is non-editable.
238   bool is_read_only;
239   // Represents if the field should have value at the time it is exported by a
240   // submit form action.
241   bool is_required;
242   // Represents if the text field is a password text field type.
243   bool is_password;
244   // Index of the text field in the collection of text fields in the page. Used
245   // to identify the annotation on which action needs to be performed.
246   // |index_in_page| is populated and used in plugin process to handle
247   // accessiility actions from mimehandler process. It's value should be
248   // validated in plugin before usage.
249   uint32_t index_in_page;
250   // We anchor the text field to a text run index, this denotes the text run
251   // before which the text field should be inserted in the accessibility tree.
252   uint32_t text_run_index;
253   // Bounding box of the text field.
254   struct PP_FloatRect bounds;
255 };
256 
257 // This holds choice form field option information provided by the PDF and
258 // will be used in accessibility to expose it. Needs to stay in sync with C++
259 // versions (PdfAccessibilityChoiceFieldOptionInfo and
260 // PrivateAccessibilityChoiceFieldOptionInfo).
261 struct PP_PrivateAccessibilityChoiceFieldOptionInfo {
262   // Represents the name property of choice field option.
263   const char* name;
264   uint32_t name_length;
265   // Represents if a choice field option is selected or not.
266   bool is_selected;
267   // Bounding box of the choice field option.
268   struct PP_FloatRect bounds;
269 };
270 
271 typedef enum {
272   PP_PRIVATECHOICEFIELD_LISTBOX = 0,
273   PP_PRIVATECHOICEFIELD_COMBOBOX = 1,
274   PP_PRIVATECHOICEFIELD_LAST = PP_PRIVATECHOICEFIELD_COMBOBOX
275 } PP_PrivateChoiceFieldType;
276 
277 // This holds choice form field information provided by the PDF and will be used
278 // in accessibility to expose it. Needs to stay in sync with C++ versions
279 // (PdfAccessibilityChoiceFieldInfo and PrivateAccessibilityChoiceFieldInfo).
280 // This struct contains index state that should be validated using
281 // PdfAccessibilityTree::IsDataFromPluginValid() before usage.
282 struct PP_PrivateAccessibilityChoiceFieldInfo {
283   // Represents the name property of choice field, if present.
284   const char* name;
285   uint32_t name_length;
286   // Represents list of options in choice field, if present.
287   struct PP_PrivateAccessibilityChoiceFieldOptionInfo* options;
288   uint32_t options_length;
289   // Represents type of choice field.
290   PP_PrivateChoiceFieldType type;
291   // Represents if the choice field is non-editable.
292   bool is_read_only;
293   // Represents if the choice field is multi-selectable.
294   bool is_multi_select;
295   // Represents if the choice field includes an editable text box.
296   bool has_editable_text_box;
297   // Index of the choice field in the collection of choice fields in the page.
298   // Used to identify the annotation on which action needs to be performed.
299   // |index_in_page| is populated and used in plugin process to handle
300   // accessiility actions from mimehandler process. It's value should be
301   // validated in plugin before usage.
302   uint32_t index_in_page;
303   // We anchor the choice field to a text run index, this denotes the text run
304   // before which the choice field should be inserted in the accessibility tree.
305   uint32_t text_run_index;
306   // Bounding box of the choice field.
307   struct PP_FloatRect bounds;
308 };
309 
310 typedef enum {
311   PP_PRIVATEBUTTON_PUSHBUTTON = 1,
312   PP_PRIVATEBUTTON_FIRST = PP_PRIVATEBUTTON_PUSHBUTTON,
313   PP_PRIVATEBUTTON_CHECKBOX = 2,
314   PP_PRIVATEBUTTON_RADIOBUTTON = 3,
315   PP_PRIVATEBUTTON_LAST = PP_PRIVATEBUTTON_RADIOBUTTON
316 } PP_PrivateButtonType;
317 
318 // This holds button form field information provided by the PDF and will be
319 // used in accessibility to expose it. Needs to stay in sync with C++ versions
320 // (PdfAccessibilityButtonInfo and PrivateAccessibilityButtonInfo).
321 // This struct contains index states that should be validated using
322 // PdfAccessibilityTree::IsDataFromPluginValid() before usage.
323 struct PP_PrivateAccessibilityButtonInfo {
324   // Represents the name property of button, if present.
325   const char* name;
326   uint32_t name_length;
327   // Represents the value property of button, if present.
328   const char* value;
329   uint32_t value_length;
330   // Represents the button type.
331   PP_PrivateButtonType type;
332   // Represents if the button is non-editable.
333   bool is_read_only;
334   // Represents if the radio button or check box is checked or not.
335   bool is_checked;
336   // Represents count of controls in the control group. A group of interactive
337   // form annotations is collectively called a form control group. Here, an
338   // interactive form annotation, should be either a radio button or a checkbox.
339   // Value of |control_count| is >= 1.
340   uint32_t control_count;
341   // Represents index of the control in the control group. A group of
342   // interactive form annotations is collectively called a form control group.
343   // Here, an interactive form annotation, should be either a radio button or a
344   // checkbox. Value of |control_index| should always be less than
345   // |control_count|.
346   uint32_t control_index;
347   // Index of the button in the collection of buttons in the page. Used
348   // to identify the annotation on which action needs to be performed.
349   // |index_in_page| is populated and used in plugin process to handle
350   // accessiility actions from mimehandler process. It's value should be
351   // validated in plugin before usage.
352   uint32_t index_in_page;
353   // We anchor the button to a text run index, this denotes the text run
354   // before which the button should be inserted in the accessibility tree.
355   uint32_t text_run_index;
356   // Bounding box of the button.
357   struct PP_FloatRect bounds;
358 };
359 
360 // This holds form fields within a PDF page. Needs to stay in sync with C++
361 // versions (PdfAccessibilityFormFieldInfo and
362 // PrivateAccessibilityFormFieldInfo).
363 struct PP_PrivateAccessibilityFormFieldInfo {
364   struct PP_PrivateAccessibilityTextFieldInfo* text_fields;
365   uint32_t text_field_count;
366   struct PP_PrivateAccessibilityChoiceFieldInfo* choice_fields;
367   uint32_t choice_field_count;
368   struct PP_PrivateAccessibilityButtonInfo* buttons;
369   uint32_t button_count;
370 };
371 
372 // This holds different PDF page objects - links, images, highlights and
373 // form fields within a PDF page so that IPC messages passing accessibility
374 // objects do not have too many parameters. Needs to stay in sync with C++
375 // versions (PdfAccessibilityPageObjects and PrivateAccessibilityPageObjects).
376 struct PP_PrivateAccessibilityPageObjects {
377   struct PP_PrivateAccessibilityLinkInfo* links;
378   uint32_t link_count;
379   struct PP_PrivateAccessibilityImageInfo* images;
380   uint32_t image_count;
381   struct PP_PrivateAccessibilityHighlightInfo* highlights;
382   uint32_t highlight_count;
383   struct PP_PrivateAccessibilityFormFieldInfo form_fields;
384 };
385 
386 struct PPB_PDF {
387   // Returns a resource identifying a font file corresponding to the given font
388   // request after applying the browser-specific fallback.
389   //
390   // Currently Linux-only.
391   PP_Resource (*GetFontFileWithFallback)(
392       PP_Instance instance,
393       const struct PP_BrowserFont_Trusted_Description* description,
394       PP_PrivateFontCharset charset);
395 
396   // Given a resource previously returned by GetFontFileWithFallback, returns
397   // a pointer to the requested font table. Linux only.
398   bool (*GetFontTableForPrivateFontFile)(PP_Resource font_file,
399                                          uint32_t table,
400                                          void* output,
401                                          uint32_t* output_length);
402 
403   // Search the given string using ICU.  Use PPB_Core's MemFree on results when
404   // done.
405   void (*SearchString)(PP_Instance instance,
406                        const unsigned short* string,
407                        const unsigned short* term,
408                        bool case_sensitive,
409                        struct PP_PrivateFindResult** results,
410                        uint32_t* count);
411 
412   // Since WebFrame doesn't know about PPAPI requests, it'll think the page has
413   // finished loading even if there are outstanding requests by the plugin.
414   // Take this out once WebFrame knows about requests by PPAPI plugins.
415   void (*DidStartLoading)(PP_Instance instance);
416   void (*DidStopLoading)(PP_Instance instance);
417 
418   // Sets content restriction for a full-page plugin (i.e. can't copy/print).
419   // The value is a bitfield of PP_ContentRestriction enums.
420   void (*SetContentRestriction)(PP_Instance instance, int restrictions);
421 
422   // Notifies the browser that the given action has been performed.
423   void (*UserMetricsRecordAction)(PP_Instance instance, struct PP_Var action);
424 
425   // Notifies the browser that the PDF has an unsupported feature.
426   void (*HasUnsupportedFeature)(PP_Instance instance);
427 
428   // Invoke SaveAs... dialog, similar to the right-click or wrench menu.
429   void (*SaveAs)(PP_Instance instance);
430 
431   // Invoke Print dialog for plugin.
432   void (*Print)(PP_Instance instance);
433 
434   PP_Bool(*IsFeatureEnabled)(PP_Instance instance, PP_PDFFeature feature);
435 
436   // Sets the selected text of the plugin.
437   void(*SetSelectedText)(PP_Instance instance, const char* selected_text);
438 
439   // Sets the link currently under the cursor.
440   void (*SetLinkUnderCursor)(PP_Instance instance, const char* url);
441 
442   // Gets pointers to the mmap'd V8 snapshot file and its size.
443   // This is needed when loading V8's initial snapshot from an external file.
444   void (*GetV8ExternalSnapshotData)(PP_Instance instance,
445                                     const char** snapshot_data_out,
446                                     int* snapshot_size_out);
447 
448   // Sends information about the viewport to the renderer for accessibility
449   // support.
450   void (*SetAccessibilityViewportInfo)(
451       PP_Instance instance,
452       const struct PP_PrivateAccessibilityViewportInfo* viewport_info);
453 
454   // Sends information about the PDF document to the renderer for accessibility
455   // support.
456   void (*SetAccessibilityDocInfo)(
457       PP_Instance instance,
458       const struct PP_PrivateAccessibilityDocInfo* doc_info);
459 
460   // Sends information about one page in a PDF document to the renderer for
461   // accessibility support.
462   void (*SetAccessibilityPageInfo)(
463       PP_Instance instance,
464       const struct PP_PrivateAccessibilityPageInfo* page_info,
465       const struct PP_PrivateAccessibilityTextRunInfo text_runs[],
466       const struct PP_PrivateAccessibilityCharInfo chars[],
467       const struct PP_PrivateAccessibilityPageObjects* page_objects);
468 
469   // Sends information about the PDF's URL and the embedder's URL.
470   void (*SetCrashData)(PP_Instance instance,
471                        const char* pdf_url,
472                        const char* top_level_url);
473 
474   // Sets the current selection bounding edges.
475   void (*SelectionChanged)(PP_Instance instance,
476                            const struct PP_FloatPoint* left,
477                            int32_t left_height,
478                            const struct PP_FloatPoint* right,
479                            int32_t right_height);
480 
481   // Sets whether the PDF viewer can handle save commands internally.
482   void (*SetPluginCanSave)(PP_Instance instance, bool can_save);
483 
484   // Displays an alert dialog.
485   void (*ShowAlertDialog)(PP_Instance instance, const char* message);
486 
487   // Displays a confirmation dialog. This method is synchronous.
488   bool (*ShowConfirmDialog)(PP_Instance instance, const char* message);
489 
490   // Displays a prompt dialog. This method is synchronous.
491   struct PP_Var (*ShowPromptDialog)(PP_Instance instance,
492                                     const char* message,
493                                     const char* default_answer);
494 };
495 
496 #endif  // PPAPI_C_PRIVATE_PPB_PDF_H_
497