summaryrefslogtreecommitdiff
path: root/chromium/ppapi/c/private/ppb_pdf.h
blob: 267037219f6ed1756e45b2581d23f4a27007d35f (plain)
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
// Copyright (c) 2011 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 PPAPI_C_PRIVATE_PPB_PDF_H_
#define PPAPI_C_PRIVATE_PPB_PDF_H_

#include <stdint.h>

#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_point.h"
#include "ppapi/c/pp_rect.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/c/private/pp_private_font_charset.h"

#define PPB_PDF_INTERFACE "PPB_PDF;1"

typedef enum {
  PP_PDFFEATURE_HIDPI = 0,
  PP_PDFFEATURE_PRINTING = 1
} PP_PDFFeature;

struct PP_PrivateFontFileDescription {
  const char* face;
  uint32_t weight;
  bool italic;
};

struct PP_PrivateFindResult {
  int start_index;
  int length;
};

struct PP_PrivateAccessibilityViewportInfo {
  double zoom;
  double scale;
  struct PP_Point scroll;
  struct PP_Point offset;
  uint32_t selection_start_page_index;
  uint32_t selection_start_char_index;
  uint32_t selection_end_page_index;
  uint32_t selection_end_char_index;
};

struct PP_PrivateAccessibilityDocInfo {
  uint32_t page_count;
  PP_Bool text_accessible;
  PP_Bool text_copyable;
};

typedef enum {
  PP_PRIVATEDIRECTION_NONE = 0,
  PP_PRIVATEDIRECTION_LTR = 1,
  PP_PRIVATEDIRECTION_RTL = 2,
  PP_PRIVATEDIRECTION_TTB = 3,
  PP_PRIVATEDIRECTION_BTT = 4,
  PP_PRIVATEDIRECTION_LAST = PP_PRIVATEDIRECTION_BTT
} PP_PrivateDirection;

struct PP_PrivateAccessibilityPageInfo {
  uint32_t page_index;
  struct PP_Rect bounds;
  uint32_t text_run_count;
  uint32_t char_count;
};

// See PDF Reference 1.7, page 402, table 5.3.
typedef enum {
  PP_TEXTRENDERINGMODE_UNKNOWN = -1,
  PP_TEXTRENDERINGMODE_FILL = 0,
  PP_TEXTRENDERINGMODE_STROKE = 1,
  PP_TEXTRENDERINGMODE_FILLSTROKE = 2,
  PP_TEXTRENDERINGMODE_INVISIBLE = 3,
  PP_TEXTRENDERINGMODE_FILLCLIP = 4,
  PP_TEXTRENDERINGMODE_STROKECLIP = 5,
  PP_TEXTRENDERINGMODE_FILLSTROKECLIP = 6,
  PP_TEXTRENDERINGMODE_CLIP = 7,
  PP_TEXTRENDERINGMODE_LAST = PP_TEXTRENDERINGMODE_CLIP
} PP_TextRenderingMode;

// This holds the text style information provided by the PDF and will be used
// in accessibility to provide the text style information. Needs to stay in
// sync with C++ version. (PrivateAccessibilityTextStyleInfo and
// PdfAccessibilityTextStyleInfo)
struct PP_PrivateAccessibilityTextStyleInfo {
  const char* font_name;
  uint32_t font_name_length;
  int font_weight;
  PP_TextRenderingMode render_mode;
  float font_size;
  // Colors are ARGB.
  uint32_t fill_color;
  uint32_t stroke_color;
  bool is_italic;
  bool is_bold;
};

// This holds the text run information provided by the PDF and will be used in
// accessibility to provide the text run information.
// Needs to stay in sync with C++ version. (PrivateAccessibilityTextRunInfo and
// PdfAccessibilityTextRunInfo)
struct PP_PrivateAccessibilityTextRunInfo {
  uint32_t len;
  struct PP_FloatRect bounds;
  PP_PrivateDirection direction;
  struct PP_PrivateAccessibilityTextStyleInfo style;
};

struct PP_PrivateAccessibilityCharInfo {
  uint32_t unicode_character;
  double char_width;
};

// This holds the link information provided by the PDF and will be used in
// accessibility to provide the link information. Needs to stay in sync with
// C++ versions (PdfAccessibilityLinkInfo and PrivateAccessibilityLinkInfo).
// This struct contains index state that should be validated using
// PdfAccessibilityTree::IsDataFromPluginValid() before usage.
struct PP_PrivateAccessibilityLinkInfo {
  // URL of the link.
  const char* url;
  uint32_t url_length;
  // Index of the link in the page. This will be used to identify the link on
  // which action has to be performed in the page.
  // |index_in_page| is populated and used in plugin process to handle
  // accessiility actions from mimehandler process. It's value should be
  // validated in plugin before usage.
  uint32_t index_in_page;
  // Link can either be part of the page text or not. If the link is part of the
  // page text, then |text_run_index| denotes the text run which contains the
  // start_index of the link and the |text_run_count| equals the number of text
  // runs the link spans in the page text. If the link is not part of the page
  // text then |text_run_count| should be 0 and the |text_run_index| should
  // contain the nearest char index to the bounding rectangle of the link.
  uint32_t text_run_index;
  uint32_t text_run_count;
  // Bounding box of the link.
  struct PP_FloatRect bounds;
};

// This holds the image information provided by the PDF and will be used in
// accessibility to provide the image information. Needs to stay in sync with
// C++ versions (PdfAccessibilityImageInfo and PrivateAccessibilityImageInfo).
// This struct contains index state that should be validated using
// PdfAccessibilityTree::IsDataFromPluginValid() before usage.
struct PP_PrivateAccessibilityImageInfo {
  // Alternate text for the image provided by PDF.
  const char* alt_text;
  uint32_t alt_text_length;
  // We anchor the image to a char index, this denotes the text run before
  // which the image should be inserted in the accessibility tree. The text run
  // at this index should contain the anchor char index.
  uint32_t text_run_index;
  // Bounding box of the image.
  struct PP_FloatRect bounds;
};

// This holds text highlight information provided by the PDF and will be
// used in accessibility to expose it. Text highlights can have an associated
// popup note, the data of which is also captured here.
// Needs to stay in sync with C++ versions (PdfAccessibilityHighlightInfo and
// PrivateAccessibilityHighlightInfo).
// This struct contains index state that should be validated using
// PdfAccessibilityTree::IsDataFromPluginValid() before usage.
struct PP_PrivateAccessibilityHighlightInfo {
  // Represents the text of the associated popup note, if present.
  const char* note_text;
  uint32_t note_text_length;
  // Index of the highlight in the page annotation list. Used to identify the
  // annotation on which action needs to be performed.
  // |index_in_page| is populated and used in plugin process to handle
  // accessiility actions from mimehandler process. It's value should be
  // validated in plugin before usage.
  uint32_t index_in_page;
  // Highlights are annotations over existing page text.  |text_run_index|
  // denotes the index of the text run where the highlight starts and
  // |text_run_count| denotes the number of text runs which the highlight spans
  // across.
  uint32_t text_run_index;
  uint32_t text_run_count;
  // Bounding box of the highlight.
  struct PP_FloatRect bounds;
  // Color of the highlight in ARGB. Alpha is stored in the first 8 MSBs. RGB
  // follows after it with each using 8 bytes.
  uint32_t color;
};

// This holds text form field information provided by the PDF and will be used
// in accessibility to expose it. Needs to stay in sync with C++ versions
// (PdfAccessibilityTextFieldInfo and PrivateAccessibilityTextFieldInfo).
// This struct contains index state that should be validated using
// PdfAccessibilityTree::IsDataFromPluginValid() before usage.
struct PP_PrivateAccessibilityTextFieldInfo {
  // Represents the name property of text field, if present.
  const char* name;
  uint32_t name_length;
  // Represents the value property of text field, if present.
  const char* value;
  uint32_t value_length;
  // Represents if the text field is non-editable.
  bool is_read_only;
  // Represents if the field should have value at the time it is exported by a
  // submit form action.
  bool is_required;
  // Represents if the text field is a password text field type.
  bool is_password;
  // Index of the text field in the collection of text fields in the page. Used
  // to identify the annotation on which action needs to be performed.
  // |index_in_page| is populated and used in plugin process to handle
  // accessiility actions from mimehandler process. It's value should be
  // validated in plugin before usage.
  uint32_t index_in_page;
  // We anchor the text field to a text run index, this denotes the text run
  // before which the text field should be inserted in the accessibility tree.
  uint32_t text_run_index;
  // Bounding box of the text field.
  struct PP_FloatRect bounds;
};

// This holds choice form field option information provided by the PDF and
// will be used in accessibility to expose it. Needs to stay in sync with C++
// versions (PdfAccessibilityChoiceFieldOptionInfo and
// PrivateAccessibilityChoiceFieldOptionInfo).
struct PP_PrivateAccessibilityChoiceFieldOptionInfo {
  // Represents the name property of choice field option.
  const char* name;
  uint32_t name_length;
  // Represents if a choice field option is selected or not.
  bool is_selected;
  // Bounding box of the choice field option.
  struct PP_FloatRect bounds;
};

typedef enum {
  PP_PRIVATECHOICEFIELD_LISTBOX = 0,
  PP_PRIVATECHOICEFIELD_COMBOBOX = 1,
  PP_PRIVATECHOICEFIELD_LAST = PP_PRIVATECHOICEFIELD_COMBOBOX
} PP_PrivateChoiceFieldType;

// This holds choice form field information provided by the PDF and will be used
// in accessibility to expose it. Needs to stay in sync with C++ versions
// (PdfAccessibilityChoiceFieldInfo and PrivateAccessibilityChoiceFieldInfo).
// This struct contains index state that should be validated using
// PdfAccessibilityTree::IsDataFromPluginValid() before usage.
struct PP_PrivateAccessibilityChoiceFieldInfo {
  // Represents the name property of choice field, if present.
  const char* name;
  uint32_t name_length;
  // Represents list of options in choice field, if present.
  struct PP_PrivateAccessibilityChoiceFieldOptionInfo* options;
  uint32_t options_length;
  // Represents type of choice field.
  PP_PrivateChoiceFieldType type;
  // Represents if the choice field is non-editable.
  bool is_read_only;
  // Represents if the choice field is multi-selectable.
  bool is_multi_select;
  // Represents if the choice field includes an editable text box.
  bool has_editable_text_box;
  // Index of the choice field in the collection of choice fields in the page.
  // Used to identify the annotation on which action needs to be performed.
  // |index_in_page| is populated and used in plugin process to handle
  // accessiility actions from mimehandler process. It's value should be
  // validated in plugin before usage.
  uint32_t index_in_page;
  // We anchor the choice field to a text run index, this denotes the text run
  // before which the choice field should be inserted in the accessibility tree.
  uint32_t text_run_index;
  // Bounding box of the choice field.
  struct PP_FloatRect bounds;
};

typedef enum {
  PP_PRIVATEBUTTON_PUSHBUTTON = 1,
  PP_PRIVATEBUTTON_FIRST = PP_PRIVATEBUTTON_PUSHBUTTON,
  PP_PRIVATEBUTTON_CHECKBOX = 2,
  PP_PRIVATEBUTTON_RADIOBUTTON = 3,
  PP_PRIVATEBUTTON_LAST = PP_PRIVATEBUTTON_RADIOBUTTON
} PP_PrivateButtonType;

// This holds button form field information provided by the PDF and will be
// used in accessibility to expose it. Needs to stay in sync with C++ versions
// (PdfAccessibilityButtonInfo and PrivateAccessibilityButtonInfo).
// This struct contains index states that should be validated using
// PdfAccessibilityTree::IsDataFromPluginValid() before usage.
struct PP_PrivateAccessibilityButtonInfo {
  // Represents the name property of button, if present.
  const char* name;
  uint32_t name_length;
  // Represents the value property of button, if present.
  const char* value;
  uint32_t value_length;
  // Represents the button type.
  PP_PrivateButtonType type;
  // Represents if the button is non-editable.
  bool is_read_only;
  // Represents if the radio button or check box is checked or not.
  bool is_checked;
  // Represents count of controls in the control group. A group of interactive
  // form annotations is collectively called a form control group. Here, an
  // interactive form annotation, should be either a radio button or a checkbox.
  // Value of |control_count| is >= 1.
  uint32_t control_count;
  // Represents index of the control in the control group. A group of
  // interactive form annotations is collectively called a form control group.
  // Here, an interactive form annotation, should be either a radio button or a
  // checkbox. Value of |control_index| should always be less than
  // |control_count|.
  uint32_t control_index;
  // Index of the button in the collection of buttons in the page. Used
  // to identify the annotation on which action needs to be performed.
  // |index_in_page| is populated and used in plugin process to handle
  // accessiility actions from mimehandler process. It's value should be
  // validated in plugin before usage.
  uint32_t index_in_page;
  // We anchor the button to a text run index, this denotes the text run
  // before which the button should be inserted in the accessibility tree.
  uint32_t text_run_index;
  // Bounding box of the button.
  struct PP_FloatRect bounds;
};

// This holds form fields within a PDF page. Needs to stay in sync with C++
// versions (PdfAccessibilityFormFieldInfo and
// PrivateAccessibilityFormFieldInfo).
struct PP_PrivateAccessibilityFormFieldInfo {
  struct PP_PrivateAccessibilityTextFieldInfo* text_fields;
  uint32_t text_field_count;
  struct PP_PrivateAccessibilityChoiceFieldInfo* choice_fields;
  uint32_t choice_field_count;
  struct PP_PrivateAccessibilityButtonInfo* buttons;
  uint32_t button_count;
};

// This holds different PDF page objects - links, images, highlights and
// form fields within a PDF page so that IPC messages passing accessibility
// objects do not have too many parameters. Needs to stay in sync with C++
// versions (PdfAccessibilityPageObjects and PrivateAccessibilityPageObjects).
struct PP_PrivateAccessibilityPageObjects {
  struct PP_PrivateAccessibilityLinkInfo* links;
  uint32_t link_count;
  struct PP_PrivateAccessibilityImageInfo* images;
  uint32_t image_count;
  struct PP_PrivateAccessibilityHighlightInfo* highlights;
  uint32_t highlight_count;
  struct PP_PrivateAccessibilityFormFieldInfo form_fields;
};

struct PPB_PDF {
  // Returns a resource identifying a font file corresponding to the given font
  // request after applying the browser-specific fallback.
  //
  // Currently Linux-only.
  PP_Resource (*GetFontFileWithFallback)(
      PP_Instance instance,
      const struct PP_BrowserFont_Trusted_Description* description,
      PP_PrivateFontCharset charset);

  // Given a resource previously returned by GetFontFileWithFallback, returns
  // a pointer to the requested font table. Linux only.
  bool (*GetFontTableForPrivateFontFile)(PP_Resource font_file,
                                         uint32_t table,
                                         void* output,
                                         uint32_t* output_length);

  // Search the given string using ICU.  Use PPB_Core's MemFree on results when
  // done.
  void (*SearchString)(PP_Instance instance,
                       const unsigned short* string,
                       const unsigned short* term,
                       bool case_sensitive,
                       struct PP_PrivateFindResult** results,
                       uint32_t* count);

  // Since WebFrame doesn't know about PPAPI requests, it'll think the page has
  // finished loading even if there are outstanding requests by the plugin.
  // Take this out once WebFrame knows about requests by PPAPI plugins.
  void (*DidStartLoading)(PP_Instance instance);
  void (*DidStopLoading)(PP_Instance instance);

  // Sets content restriction for a full-page plugin (i.e. can't copy/print).
  // The value is a bitfield of ContentRestriction enums.
  void (*SetContentRestriction)(PP_Instance instance, int restrictions);

  // Notifies the browser that the given action has been performed.
  void (*UserMetricsRecordAction)(PP_Instance instance, struct PP_Var action);

  // Notifies the browser that the PDF has an unsupported feature.
  void (*HasUnsupportedFeature)(PP_Instance instance);

  // Invoke SaveAs... dialog, similar to the right-click or wrench menu.
  void (*SaveAs)(PP_Instance instance);

  // Invoke Print dialog for plugin.
  void (*Print)(PP_Instance instance);

  PP_Bool(*IsFeatureEnabled)(PP_Instance instance, PP_PDFFeature feature);

  // Sets the selected text of the plugin.
  void(*SetSelectedText)(PP_Instance instance, const char* selected_text);

  // Sets the link currently under the cursor.
  void (*SetLinkUnderCursor)(PP_Instance instance, const char* url);

  // Gets pointers to the mmap'd V8 snapshot file and its size.
  // This is needed when loading V8's initial snapshot from an external file.
  void (*GetV8ExternalSnapshotData)(PP_Instance instance,
                                    const char** snapshot_data_out,
                                    int* snapshot_size_out);

  // Sends information about the viewport to the renderer for accessibility
  // support.
  void (*SetAccessibilityViewportInfo)(
      PP_Instance instance,
      const struct PP_PrivateAccessibilityViewportInfo* viewport_info);

  // Sends information about the PDF document to the renderer for accessibility
  // support.
  void (*SetAccessibilityDocInfo)(
      PP_Instance instance,
      const struct PP_PrivateAccessibilityDocInfo* doc_info);

  // Sends information about one page in a PDF document to the renderer for
  // accessibility support.
  void (*SetAccessibilityPageInfo)(
      PP_Instance instance,
      const struct PP_PrivateAccessibilityPageInfo* page_info,
      const struct PP_PrivateAccessibilityTextRunInfo text_runs[],
      const struct PP_PrivateAccessibilityCharInfo chars[],
      const struct PP_PrivateAccessibilityPageObjects* page_objects);

  // Sends information about the PDF's URL and the embedder's URL.
  void (*SetCrashData)(PP_Instance instance,
                       const char* pdf_url,
                       const char* top_level_url);

  // Sets the current selection bounding edges.
  void (*SelectionChanged)(PP_Instance instance,
                           const struct PP_FloatPoint* left,
                           int32_t left_height,
                           const struct PP_FloatPoint* right,
                           int32_t right_height);

  // Sets whether the PDF viewer can handle save commands internally.
  void (*SetPluginCanSave)(PP_Instance instance, bool can_save);

  // Displays an alert dialog.
  void (*ShowAlertDialog)(PP_Instance instance, const char* message);

  // Displays a confirmation dialog. This method is synchronous.
  bool (*ShowConfirmDialog)(PP_Instance instance, const char* message);

  // Displays a prompt dialog. This method is synchronous.
  struct PP_Var (*ShowPromptDialog)(PP_Instance instance,
                                    const char* message,
                                    const char* default_answer);
};

#endif  // PPAPI_C_PRIVATE_PPB_PDF_H_