- add sources.
[platform/framework/web/crosswalk.git] / src / third_party / npapi / bindings / npapi_extensions.h
1 /* Copyright (c) 2006-2009 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
6 #ifndef _NP_EXTENSIONS_H_
7 #define _NP_EXTENSIONS_H_
8
9 // Use the shorter include path here so that this file can be used in non-
10 // Chromium projects, such as the Native Client SDK.
11 #include "npapi.h"
12
13 #include <stddef.h>         // For size_t
14
15 /*
16  * A fake "enum" value for getting browser-implemented Pepper extensions.
17  * The variable returns a pointer to an NPNExtensions structure. */
18 #define NPNVPepperExtensions ((NPNVariable) 4000)
19
20 /*
21  * A fake "enum" value for getting plugin-implemented Pepper extensions.
22  * The variable returns a pointer to an NPPExtensions structure. */
23 #define NPPVPepperExtensions ((NPPVariable) 4001)
24
25 typedef void NPDeviceConfig;
26 typedef void NPDeviceContext;
27 typedef void NPUserData;
28
29 /* unique id for each device interface */
30 typedef int32_t NPDeviceID;
31
32 /* Events -------------------------------------------------------------------*/
33
34 typedef enum {
35   NPMouseButton_None    = -1,
36   NPMouseButton_Left    = 0,
37   NPMouseButton_Middle  = 1,
38   NPMouseButton_Right   = 2
39 } NPMouseButtons;
40
41 typedef enum {
42   NPEventType_Undefined   = -1,
43   NPEventType_MouseDown   = 0,
44   NPEventType_MouseUp     = 1,
45   NPEventType_MouseMove   = 2,
46   NPEventType_MouseEnter  = 3,
47   NPEventType_MouseLeave  = 4,
48   NPEventType_MouseWheel  = 5,
49   NPEventType_RawKeyDown  = 6,
50   NPEventType_KeyDown     = 7,
51   NPEventType_KeyUp       = 8,
52   NPEventType_Char        = 9,
53   NPEventType_Minimize    = 10,
54   NPEventType_Focus       = 11,
55   NPEventType_Device      = 12
56 } NPEventTypes;
57
58 typedef enum {
59   NPEventModifier_ShiftKey         = 1 << 0,
60   NPEventModifier_ControlKey       = 1 << 1,
61   NPEventModifier_AltKey           = 1 << 2,
62   NPEventModifier_MetaKey          = 1 << 3,
63   NPEventModifier_IsKeyPad         = 1 << 4,
64   NPEventModifier_IsAutoRepeat     = 1 << 5,
65   NPEventModifier_LeftButtonDown   = 1 << 6,
66   NPEventModifier_MiddleButtonDown = 1 << 7,
67   NPEventModifier_RightButtonDown  = 1 << 8
68 } NPEventModifiers;
69
70 typedef struct _NPKeyEvent
71 {
72   uint32_t modifier;
73   uint32_t normalizedKeyCode;
74 } NPKeyEvent;
75
76 typedef struct _NPCharacterEvent
77 {
78   uint32_t modifier;
79   uint16_t text[4];
80   uint16_t unmodifiedText[4];
81 } NPCharacterEvent;
82
83 typedef struct _NPMouseEvent
84 {
85   uint32_t modifier;
86   int32_t button;
87   int32_t x;
88   int32_t y;
89   int32_t clickCount;
90 } NPMouseEvent;
91
92 typedef struct _NPMouseWheelEvent
93 {
94   uint32_t modifier;
95   float deltaX;
96   float deltaY;
97   float wheelTicksX;
98   float wheelTicksY;
99   uint32_t scrollByPage;
100 } NPMouseWheelEvent;
101
102 typedef struct _NPDeviceEvent {
103   uint32_t device_uid;
104   uint32_t subtype;
105   /* uint8_t generic[0]; */
106 } NPDeviceEvent;
107
108 typedef struct _NPMinimizeEvent {
109   int32_t value;
110 } NPMinimizeEvent;
111
112 typedef struct _NPFocusEvent {
113   int32_t value;
114 } NPFocusEvent;
115
116 typedef struct _NPPepperEvent
117 {
118   uint32_t size;
119   int32_t type;
120   double timeStampSeconds;
121   union {
122     NPKeyEvent key;
123     NPCharacterEvent character;
124     NPMouseEvent mouse;
125     NPMouseWheelEvent wheel;
126     NPMinimizeEvent minimize;
127     NPFocusEvent focus;
128     NPDeviceEvent device;
129   } u;
130 } NPPepperEvent;
131
132 /* 2D -----------------------------------------------------------------------*/
133
134 #define NPPepper2DDevice 1
135
136 typedef struct _NPDeviceContext2DConfig {
137 } NPDeviceContext2DConfig;
138
139 typedef struct _NPDeviceContext2D
140 {
141   /* Internal value used by the browser to identify this device. */
142   void* reserved;
143
144   /* A pointer to the pixel data. This data is 8-bit values in BGRA order in
145    * memory. Each row will start |stride| bytes after the previous one.
146    *
147    * THIS DATA USES PREMULTIPLIED ALPHA. This means that each color channel has
148    * been multiplied with the corresponding alpha, which makes compositing
149    * easier. If any color channels have a value greater than the alpha value,
150    * you'll likely get crazy colors and weird artifacts. */
151   void* region;
152
153   /* Length of each row of pixels in bytes. This may be larger than width * 4
154    * if there is padding at the end of each row to help with alignment. */
155   int32_t stride;
156
157   /* The dirty region that the plugin has painted into the buffer. This
158    * will be initialized to the size of the plugin image in
159    * initializeContextPtr. The plugin can change the values to only
160    * update portions of the image. */
161   struct {
162     int32_t left;
163     int32_t top;
164     int32_t right;
165     int32_t bottom;
166   } dirty;
167 } NPDeviceContext2D;
168
169 typedef struct _NPDeviceBuffer {
170   void* ptr;
171   size_t size;
172 } NPDeviceBuffer;
173
174 /* completion callback for flush device */
175 typedef void (*NPDeviceFlushContextCallbackPtr)(
176     NPP instance,
177     NPDeviceContext* context,
178     NPError err,
179     NPUserData* userData);
180
181 /* query single capabilities of device */
182 typedef NPError (
183     *NPDeviceQueryCapabilityPtr)(NPP instance,
184     int32_t capability,
185     int32_t *value);
186 /* query config (configuration == a set of capabilities) */
187 typedef NPError (
188     *NPDeviceQueryConfigPtr)(NPP instance,
189     const NPDeviceConfig* request,
190     NPDeviceConfig* obtain);
191 /* device initialization */
192 typedef NPError (*NPDeviceInitializeContextPtr)(
193     NPP instance,
194     const NPDeviceConfig* config,
195     NPDeviceContext* context);
196 /* peek at device state */
197 typedef NPError (*NPDeviceGetStateContextPtr) (
198     NPP instance,
199     NPDeviceContext* context,
200     int32_t state,
201     intptr_t* value);
202 /* poke device state */
203 typedef NPError (*NPDeviceSetStateContextPtr) (
204     NPP instance,
205     NPDeviceContext* context,
206     int32_t state,
207     intptr_t value);
208 /* flush context, if callback, userData are NULL */
209 /* this becomes a blocking call */
210 typedef NPError (*NPDeviceFlushContextPtr)(
211     NPP instance,
212     NPDeviceContext* context,
213     NPDeviceFlushContextCallbackPtr callback,
214     void* userData);
215 /* destroy device context.  Application responsible for */
216 /* freeing context, if applicable */
217 typedef NPError (*NPDeviceDestroyContextPtr)(
218     NPP instance,
219     NPDeviceContext* context);
220 /* Create a buffer associated with a particular context. The usage of the */
221 /* buffer is device specific. The lifetime of the buffer is scoped with the */
222 /* lifetime of the context. */
223 typedef NPError (*NPDeviceCreateBufferPtr)(
224     NPP instance,
225     NPDeviceContext* context,
226     size_t size,
227     int32_t* id);
228 /* Destroy a buffer associated with a particular context. */
229 typedef NPError (*NPDeviceDestroyBufferPtr)(
230     NPP instance,
231     NPDeviceContext* context,
232     int32_t id);
233 /* Map a buffer id to its address. */
234 typedef NPError (*NPDeviceMapBufferPtr)(
235     NPP instance,
236     NPDeviceContext* context,
237     int32_t id,
238     NPDeviceBuffer* buffer);
239
240
241 /* forward decl typdef structs */
242 typedef struct NPDevice NPDevice;
243 typedef struct NPNExtensions NPNExtensions;
244
245 // DEPRECATED: this typedef is just for the NaCl code until they switch to NPNExtensions.
246 // PLEASE REMOVE THIS WHEN THE NACL CODE IS UPDATED.
247 typedef struct NPNExtensions NPExtensions;
248
249
250 /* New experimental device API. */
251
252 /* Mode for calls to NPDeviceSynchronizeContext. */
253 typedef enum {
254   /* Get or set locally cached state without synchronizing or communicating   */
255   /* with the service process (or thread).                                    */
256   NPDeviceSynchronizationMode_Cached,
257
258   /* Exchanges state with service process (or thread). Does not wait for any  */
259   /* progress before returning.                                               */
260   NPDeviceSynchronizationMode_Immediate,
261
262   /* Exchanges state with service process (or thread). Blocks caller until    */
263   /* further progress can be made.                                            */
264   NPDeviceSynchronizationMode_Flush
265 } NPDeviceSynchronizationMode;
266
267 /* Get the number of configs supported by a given device. */
268 typedef NPError (*NPDeviceGetNumConfigsPtr)(NPP instance,
269                                             int32_t* numConfigs);
270
271 /* Get attribute values from a config. NPDeviceGetConfigs might return        */
272 /* multiple configs. This function can be used to examine them to             */
273 /* find the most suitable. For example, NPDeviceGetConfigs might return one   */
274 /* config with antialiasing enabled and one without. This can be determined   */
275 /* using this function.                                                       */
276 /* Inputs:                                                                    */
277 /*  config: The config index to extract the attributes from.                  */
278 /*  attribList: Array of input config attribute / value pairs                 */
279 /*              terminated with NPAttrib_End.                                 */
280 /* Outputs:                                                                   */
281 /*  attribList: The values paired up with each attribute are filled in        */
282 /*              on return.                                                    */
283 typedef NPError (*NPDeviceGetConfigAttribsPtr)(NPP instance,
284                                                int32_t config,
285                                                int32_t* attribList);
286
287 /* Create a device context based on a particular device configuration and a   */
288 /* list config input attributes.                                              */
289 /* Inputs:                                                                    */
290 /*  config: The device configuration to use.                                  */
291 /*  attribList: NULL or an array of context specific attribute / value        */
292 /*              pairs terminated with NPAttrib_End.                           */
293 /* Outputs:                                                                   */
294 /*  context: The created context.                                             */
295 typedef NPError (*NPDeviceCreateContextPtr)(NPP instance,
296                                             int32_t config,
297                                             const int32_t* attribList,
298                                             NPDeviceContext** context);
299
300 /* Destroy a context.                                                         */
301 /* Inputs:                                                                    */
302 /*  context: The context to destroy.                                          */
303 /*typedef NPError (*NPDestroyContext)(NPP instance,                           */
304 /*                                    NPDeviceContext* context);              */
305
306 /* This type should be cast to the type associated with the particular        */
307 /* callback type */
308 typedef void (*NPDeviceGenericCallbackPtr)(void);
309
310 /* Register a callback with a context. Callbacks are never invoked after the  */
311 /* associated context has been destroyed. The semantics of the particular     */
312 /* callback type determine which thread the callback is invoked on. It might  */
313 /* be the plugin thread, the thread RegisterCallback is invoked on or a       */
314 /* special thread created for servicing callbacks, such as an audio thread    */
315 /* Inputs:                                                                    */
316 /*  callbackType: The device specific callback type                           */
317 /*  callback: The callback to invoke. The signature varies by type. Use       */
318 /*            NULL to unregister the callback for a particular type.          */
319 /*  callbackData: A value that is passed to the callback function. Other      */
320 /*                callback arguments vary by type.                            */
321 typedef NPError (*NPDeviceRegisterCallbackPtr)(
322     NPP instance,
323     NPDeviceContext* context,
324     int32_t callbackType,
325     NPDeviceGenericCallbackPtr callback,
326     void* callbackData);
327
328 /* Callback for NPDeviceSynchronizeContext.                                   */
329 /* Inputs:                                                                    */
330 /*  instance: The associated plugin instance.                                 */
331 /*  context: The context that was flushed.                                    */
332 /*  error: Indicates success of flush operation.                              */
333 /*  data: The completion callback data that was passed to                     */
334 /*        NPDeviceSynchronizeContext.                                         */
335 typedef void (*NPDeviceSynchronizeContextCallbackPtr)(
336     NPP instance,
337     NPDeviceContext* context,
338     NPError error,
339     void* data);
340
341 /* Synchronize the state of a device context. Takes lists of input and output */
342 /* attributes. Generally, the input attributes are copied into the context    */
343 /* and the output attributes are filled in the state of the context either    */
344 /* after (before) the synchronization depending on whether it is synchronous  */
345 /* (asynchronous). The get the state of the context after an asynchronous     */
346 /* synchronization, call this function a second time with Cached mode after   */
347 /* the callback has been invoked.                                             */
348 /* Inputs:                                                                    */
349 /*  context: The context to synchronize.                                      */
350 /*  mode: The type of synchronization to perform.                             */
351 /*  inputAttribList: NULL or an array of input synchronization attribute /    */
352 /*                   value pairs terminated with NPAttrib_End.                */
353 /*  outputAttribList: NULL or an array of output synchronization              */
354 /*                    attributes / uninitialized value pairs terminated       */
355 /*                    with NPAttrib_End.                                      */
356 /*  callback: NULL for synchronous operation or completion callback function  */
357 /*            for asynchronous operation.                                     */
358 /*  callbackData: Argument passed to callback function.                       */
359 /* Outputs:                                                                   */
360 /*  outputAttribList: The values paired up with each attribute are filled     */
361 /*                    in on return for synchronous operation.                 */
362 typedef NPError (*NPDeviceSynchronizeContextPtr)(
363     NPP instance,
364     NPDeviceContext* context,
365     NPDeviceSynchronizationMode mode,
366     const int32_t* inputAttribList,
367     int32_t* outputAttribList,
368     NPDeviceSynchronizeContextCallbackPtr callback,
369     void* callbackData);
370
371 /* All attributes shared between devices, with the exception of               */
372 /* NPDeviceContextAttrib_End, have bit 31 set. Device specific attributes     */
373 /* have the bit clear.                                                        */
374 enum {
375   /* Used to terminate arrays of attribute / value pairs. */
376   NPAttrib_End   = 0,
377
378   /* Error status of context. Non-zero means error. Shared by all devices,    */
379   /* though error values are device specific.                                 */
380   NPAttrib_Error = 0x80000000
381 };
382
383 /* generic device interface */
384 struct NPDevice {
385   NPDeviceQueryCapabilityPtr queryCapability;
386   NPDeviceQueryConfigPtr queryConfig;
387   NPDeviceInitializeContextPtr initializeContext;
388   NPDeviceSetStateContextPtr setStateContext;
389   NPDeviceGetStateContextPtr getStateContext;
390   NPDeviceFlushContextPtr flushContext;
391   NPDeviceDestroyContextPtr destroyContext;
392   NPDeviceCreateBufferPtr createBuffer;
393   NPDeviceDestroyBufferPtr destroyBuffer;
394   NPDeviceMapBufferPtr mapBuffer;
395
396   /* Experimental device API */
397   NPDeviceGetNumConfigsPtr getNumConfigs;
398   NPDeviceGetConfigAttribsPtr getConfigAttribs;
399   NPDeviceCreateContextPtr createContext;
400 /*  NPDeviceDestroyContextPtr destroyContext; */
401   NPDeviceRegisterCallbackPtr registerCallback;
402   NPDeviceSynchronizeContextPtr synchronizeContext;
403 /*  NPDeviceCreateBufferPtr createBuffer; */
404 /*  NPDeviceDestroyBufferPtr destroyBuffer; */
405 /*  NPDeviceMapBufferPtr mapBuffer; */
406 };
407
408 /* returns NULL if deviceID unavailable / unrecognized */
409 typedef NPDevice* (*NPAcquireDevicePtr)(
410     NPP instance,
411     NPDeviceID device);
412
413 /* Updates the number of find results for the current search term.  If
414  * there are no matches 0 should be passed in.  Only when the plugin has
415  * finished searching should it pass in the final count with finalResult set to
416  * true. */
417 typedef void (*NPNumberOfFindResultsChangedPtr)(
418     NPP instance,
419     int total,
420     bool finalResult);
421
422  /* Updates the index of the currently selected search item. */
423 typedef void (*NPSelectedFindResultChangedPtr)(
424     NPP instance,
425     int index);
426
427 /* Theming -----------------------------------------------------------------*/
428 typedef int32_t NPWidgetID;
429
430 typedef enum {
431   NPWidgetTypeScrollbar = 0
432 } NPWidgetType;
433
434 typedef struct _NPScrollbarCreateParams {
435   bool vertical;
436 } NPScrollbarCreateParams;
437
438 typedef struct _NPRect32
439 {
440   uint32_t top;
441   uint32_t left;
442   uint32_t bottom;
443   uint32_t right;
444 } NPRect32;
445
446 typedef struct _NPScrollbarTickMarks {
447   uint32_t count;
448   NPRect32* tickmarks;
449 } NPScrollbarTickMarks;
450
451 typedef enum {
452   NPWidgetPropertyLocation = 0,  // variable is NPRect*.
453   NPWidgetPropertyDirtyRect = 1,  // Get only.  variable is NPRec*.
454   NPWidgetPropertyScrollbarThickness = 2,  // Get only.  variable is int32_t*.
455   NPWidgetPropertyScrollbarValue = 3,  // variable is int32_t*.
456   NPWidgetPropertyScrollbarDocumentSize = 4,  // Set only. variable is int32_t*.
457   // Set only.  variable is NPScrollbarTickMarks*.
458   NPWidgetPropertyScrollbarTickMarks = 5,
459   // Set only.  variable is bool* (true for forward, false for backward).
460   NPWidgetPropertyScrollbarScrollByLine = 6,
461   // Set only.  variable is bool* (true for forward, false for backward).
462   NPWidgetPropertyScrollbarScrollByPage = 7,
463   // Set only.  variable is bool* (true for forward, false for backward).
464   NPWidgetPropertyScrollbarScrollByDocument = 8,
465   // Set only.  variable is int32_t* (positive forward, negative  backward).
466   NPWidgetPropertyScrollbarScrollByPixels = 9
467 } NPWidgetProperty;
468
469 // Creates a widget.  If it returns NPERR_NO_ERROR then id will contain a unique
470 // identifer for the widget that's used for the next functions.
471 typedef NPError (*NPCreateWidgetPtr) (
472     NPP instance,
473     NPWidgetType type,
474     void* params,  // Widget specific.
475     NPWidgetID* id);
476
477 // Destroys a widget.
478 typedef NPError (*NPDestroyWidgetPtr) (
479     NPP instance,
480     NPWidgetID id);
481
482 // Paint the dirty rectangle of the given widget into context.
483 typedef NPError (*NPPaintWidgetPtr) (
484     NPP instance,
485     NPWidgetID id,
486     NPDeviceContext2D* context,
487     NPRect* dirty);
488
489 // Pass in a pepper event to a plugin.  It'll return true iff it uses it.
490 typedef bool (*NPHandleWidgetEventPtr) (
491     NPP instance,
492     NPWidgetID id,
493     NPPepperEvent* event);
494
495 // Gets a property of the widget.  "value" varies depending on the variable.
496 typedef NPError (*NPGetWidgetPropertyPtr) (
497     NPP instance,
498     NPWidgetID id,
499     NPWidgetProperty property,
500     void* value);
501
502 // Sets a property of the widget.
503 typedef NPError (*NPSetWidgetPropertyPtr) (
504     NPP instance,
505     NPWidgetID id,
506     NPWidgetProperty property,
507     void* value);
508
509 typedef struct _NPWidgetExtensions {
510   NPCreateWidgetPtr createWidget;
511   NPDestroyWidgetPtr destroyWidget;
512   NPPaintWidgetPtr paintWidget;
513   NPHandleWidgetEventPtr handleWidgetEvent;
514   NPGetWidgetPropertyPtr getWidgetProperty;
515   NPSetWidgetPropertyPtr setWidgetProperty;
516 } NPWidgetExtensions;
517
518 typedef NPWidgetExtensions* (*NPGetWidgetExtensionsPtr)(
519     NPP instance);
520
521
522 /* Supports opening files anywhere on the system after prompting the user to
523  * pick one.
524  *
525  * This API is asynchronous. It will return immediately and the user will be
526  * prompted in parallel to pick a file. The plugin may continue to receive
527  * events while the open file dialog is up, and may continue to paint. Plugins
528  * may want to ignore input events between the call and the callback to avoid
529  * reentrant behavior. If the return value is not NPERR_NO_ERROR, the callback
530  * will NOT be executed.
531  *
532  * It is an error to call BrowseForFile before a previous call has executed
533  * the callback.
534  *
535  * Setting the flags to "Open" requires that the file exist to allow picking.
536  * Setting the flags to "Save" allows selecting nonexistant files (which will
537  * then be created), and will prompt the user if they want to overwrite an
538  * existing file if it exists.
539  *
540  * The plugin may specify a comma-separated list of possible mime types in
541  * the "extensions" parameter. If no extensions are specified, the dialog box
542  * will default to allowing all extensions. The first extension in the list
543  * will be the default.
544  *
545  * TODO(brettw) On Windows the extensions traditionally include a text
546  * description with the extension in the popup, do we want to allow this?
547  * We should probably also allow the ability to put "All files" in the
548  * list on Windows.
549  *
550  * Once the user has picked a file or has canceled the dialog box, the given
551  * callback will be called with the results of the operation and the passed in
552  * "user data" pointer. If the user successfully picked a file, the filename
553  * will be non-NULL and will contain a pointer to an array of strings, one for
554  * each file picked (the first file will be file_paths[0]). This buffer will
555  * become invalid as soon as the call completes, so it is the plugin's
556  * responsibility to copy the filename(sp if it needs future access to them.
557  * A NULL file_paths in the callback means the user canceled the dialog box.
558  *
559  * The filename will be in UTF-8. It may not actually correspond to the actual
560  * file on disk on a Linux system, because we'll do our best to convert it from
561  * the filesystem's locale to UTF-8. Instead, the string will be appropriate for
562  * displaying to the user which file they picked.
563  * */
564 typedef enum {
565   NPChooseFile_Open = 1,
566   NPChooseFile_OpenMultiple = 2,
567   NPChooseFile_Save = 3
568 } NPChooseFileMode;
569 typedef void (*NPChooseFileCallback)(const char** filePaths,
570                                      uint32_t pathCount,
571                                      void* userData);
572 typedef NPError (*NPChooseFilePtr)(
573     NPP instance,
574     const char* mimeTypes,
575     NPChooseFileMode mode,
576     NPChooseFileCallback callback,
577     void* userData);
578
579 typedef enum {
580   NPCursorTypePointer = 0,
581   NPCursorTypeCross = 1,
582   NPCursorTypeHand = 2,
583   NPCursorTypeIBeam = 3,
584   NPCursorTypeWait = 4,
585   NPCursorTypeHelp = 5,
586   NPCursorTypeEastResize = 6,
587   NPCursorTypeNorthResize = 7,
588   NPCursorTypeNorthEastResize = 8,
589   NPCursorTypeNorthWestResize = 9,
590   NPCursorTypeSouthResize = 10,
591   NPCursorTypeSouthEastResize = 11,
592   NPCursorTypeSouthWestResize = 12,
593   NPCursorTypeWestResize = 13,
594   NPCursorTypeNorthSouthResize = 14,
595   NPCursorTypeEastWestResize = 15,
596   NPCursorTypeNorthEastSouthWestResize = 16,
597   NPCursorTypeNorthWestSouthEastResize = 17,
598   NPCursorTypeColumnResize = 18,
599   NPCursorTypeRowResize = 19,
600   NPCursorTypeMiddlePanning = 20,
601   NPCursorTypeEastPanning = 21,
602   NPCursorTypeNorthPanning = 22,
603   NPCursorTypeNorthEastPanning = 23,
604   NPCursorTypeNorthWestPanning = 24,
605   NPCursorTypeSouthPanning = 25,
606   NPCursorTypeSouthEastPanning = 26,
607   NPCursorTypeSouthWestPanning = 27,
608   NPCursorTypeWestPanning = 28,
609   NPCursorTypeMove = 29,
610   NPCursorTypeVerticalText = 30,
611   NPCursorTypeCell = 31,
612   NPCursorTypeContextMenu = 32,
613   NPCursorTypeAlias = 33,
614   NPCursorTypeProgress = 34,
615   NPCursorTypeNoDrop = 35,
616   NPCursorTypeCopy = 36,
617   NPCursorTypeNone = 37,
618   NPCursorTypeNotAllowed = 38,
619   NPCursorTypeZoomIn = 39,
620   NPCursorTypeZoomOut = 40
621 } NPCursorType;
622
623 // Temporary SetCursor API.
624 typedef NPError (*NPSetCursorPtr)(
625     NPP instance,
626     NPCursorType type);
627
628 /* unique id for each font */
629 typedef int NPFontID;
630
631 typedef enum {
632   NPCharsetAnsi = 0,
633   NPCharsetDefault = 1,
634   NPCharsetSymbol = 2,
635   NPCharsetMac = 77,
636   NPCharsetShiftJIS = 128,
637   NPCharsetHangul = 129,
638   NPCharsetJohab = 130,
639   NPCharsetGB2312 =134,
640   NPCharsetChineseBIG5 = 136,
641   NPCharsetGreek = 161,
642   NPCharsetTurkish = 162,
643   NPCharsetVietnamese = 163,
644   NPCharsetHebrew = 177,
645   NPCharsetArabic = 178,
646   NPCharsetBaltic = 186,
647   NPCharsetRussian = 204,
648   NPCharsetThai = 222,
649   NPCharsetEastEurope = 238,
650   NPCharsetOEM = 255
651 } NPCharset;
652
653 typedef enum {
654   NPPitchDefault,
655   NPPitchFixed
656 } NPPitch;
657
658 typedef enum {
659   NPFamilyDefault,
660   NPFamilyRoman,
661   NPFamilyScript
662 } NPFamily;
663
664 typedef struct _NPFontDescription {
665   const char* face;
666   int weight;
667   bool italic;
668   NPPitch pitch;
669   NPFamily family;
670   NPCharset charset;
671 } NPFontDescription;
672
673 // Return a font which best matches the given properties.
674 typedef NPError (*NPMatchFontWithFallbackPtr) (
675     NPP instance,
676     const NPFontDescription* description,
677     NPFontID* id);
678
679 // Loads a specified font table for the given font.
680 //   table: the table in *big-endian* format, or 0 for the whole font file.
681 //   output: a buffer of size output_length that gets the data.  can be 0, in
682 //     which case output_length will be set to the required size in bytes.
683 //   output_length: size of output, if it's not 0.
684 typedef NPError (*GetFontTablePtr) (
685     NPP instance,
686     NPFontID id,
687     uint32_t table,
688     void* output,
689     size_t* output_length);
690
691 // Destroys a font.
692 typedef NPError (*NPDestroyFontPtr) (
693     NPP instance,
694     NPFontID id);
695
696 typedef struct _NPFontExtensions {
697   NPMatchFontWithFallbackPtr matchFontWithFallback;
698   GetFontTablePtr getFontTable;
699   NPDestroyFontPtr destroyFont;
700 } NPFontExtensions;
701
702 typedef NPFontExtensions* (*NPGetFontExtensionsPtr)(
703     NPP instance);
704
705 /* Pepper extensions */
706 struct NPNExtensions {
707   /* Device interface acquisition */
708   NPAcquireDevicePtr acquireDevice;
709   /* Find */
710   NPNumberOfFindResultsChangedPtr numberOfFindResultsChanged;
711   NPSelectedFindResultChangedPtr selectedFindResultChanged;
712   /* File I/O extensions */
713   NPChooseFilePtr chooseFile;
714   /* Widget */
715   NPGetWidgetExtensionsPtr getWidgetExtensions;
716   /* Cursor */
717   NPSetCursorPtr setCursor;
718   /* Font */
719   NPGetFontExtensionsPtr getFontExtensions;
720 };
721
722 /* 3D -----------------------------------------------------------------------*/
723
724 #define NPPepper3DDevice 2
725
726 typedef struct _NPDeviceContext3DConfig {
727   int32_t commandBufferSize;
728 } NPDeviceContext3DConfig;
729
730 typedef enum _NPDeviceContext3DError {
731   // No error has ocurred.
732   NPDeviceContext3DError_NoError,
733
734   // The size of a command was invalid.
735   NPDeviceContext3DError_InvalidSize,
736
737   // An offset was out of bounds.
738   NPDeviceContext3DError_OutOfBounds,
739
740   // A command was not recognized.
741   NPDeviceContext3DError_UnknownCommand,
742
743   // The arguments to a command were invalid.
744   NPDeviceContext3DError_InvalidArguments,
745
746   // The 3D context was lost, for example due to a power management event. The
747   // context must be destroyed and a new one created.
748   NPDeviceContext3DError_LostContext,
749
750   // Any other error.
751   NPDeviceContext3DError_GenericError
752 } NPDeviceContext3DError;
753
754 typedef struct _NPDeviceContext3D NPDeviceContext3D;
755
756 typedef void (*NPDeviceContext3DRepaintPtr)(NPP npp,
757                                             NPDeviceContext3D* context);
758
759 // TODO(apatrick): this need not be exposed when we switch over to the new
760 // device API. It's layout can also be implementation dependent.
761 typedef struct _NPDeviceContext3D
762 {
763   void* reserved;
764
765   // If true, then a flush will only complete once the get offset has advanced
766   // on the GPU thread. If false, then the get offset might have changed but
767   // the GPU thread will respond as quickly as possible without guaranteeing
768   // having made any progress in executing pending commands. Set to true
769   // to ensure that progress is made or when flushing in a loop waiting for the
770   // GPU to reach a certain state, for example in advancing beyond a particular
771   // token. Set to false when flushing to query the current state, for example
772   // whether an error has occurred.
773   bool waitForProgress;
774
775   // Buffer in which commands are stored.
776   void* commandBuffer;
777   int32_t commandBufferSize;
778
779   // Offset in command buffer reader has reached. Synchronized on flush.
780   int32_t getOffset;
781
782   // Offset in command buffer writer has reached. Synchronized on flush.
783   int32_t putOffset;
784
785   // Last processed token. Synchronized on flush.
786   int32_t token;
787
788   // Callback invoked on the main thread when the context must be repainted.
789   // TODO(apatrick): move this out of the context struct like the rest of the
790   // fields.
791   NPDeviceContext3DRepaintPtr repaintCallback;
792
793   // Error status. Synchronized on flush.
794   NPDeviceContext3DError error;
795 } NPDeviceContext3D;
796
797
798 /* Begin 3D specific portion of experimental device API */
799
800 /* Device buffer ID reserved for command buffer */
801 enum {
802   NP3DCommandBufferId = 0
803 };
804
805 /* 3D attributes */
806 enum {
807   /* Example GetConfigAttribs attributes. See EGL 1.4 spec. */
808   /* These may be passed to GetConfigAttribs. */
809   NP3DAttrib_BufferSize        = 0x3020,
810   NP3DAttrib_AlphaSize         = 0x3021,
811   NP3DAttrib_BlueSize          = 0x3022,
812   NP3DAttrib_GreenSize         = 0x3023,
813   NP3DAttrib_RedSize           = 0x3024,
814   NP3DAttrib_DepthSize         = 0x3025,
815   NP3DAttrib_StencilSize       = 0x3026,
816   NP3DAttrib_SurfaceType       = 0x3033,
817
818   /* Example CreateContext attributes. See EGL 1.4 spec. */
819   /* These may be passed to CreateContext. */
820   NP3DAttrib_SwapBehavior       = 0x3093,
821   NP3DAttrib_MultisampleResolve = 0x3099,
822
823   /* Size of command buffer in 32-bit entries. */
824   /* This may be passed to CreateContext as an input or SynchronizeContext as */
825   /* an output. */
826   NP3DAttrib_CommandBufferSize  = 0x10000000,
827
828   /* These may be passed to SynchronizeContext. */
829
830   /* Offset in command buffer writer has reached. In / out.*/
831   NP3DAttrib_PutOffset,
832
833   /* Offset in command buffer reader has reached. Out only. */
834   NP3DAttrib_GetOffset,
835
836   /* Last processed token. Out only. */
837   NP3DAttrib_Token
838 };
839
840 /* 3D callbacks */
841 enum {
842   /* This callback is invoked whenever the plugin must repaint everything.    */
843   /* This might be because the window manager must repaint a window or        */
844   /* the context has been lost, for example a power management event.         */
845   NP3DCallback_Repaint = 1
846 };
847
848 /* Flags for NPConfig3DOutAttrib_SurfaceType */
849 enum {
850   NP3DSurfaceType_MultisampleResolveBox = 0x0200,
851   NP3DSurfaceType_SwapBehaviorPreserved = 0x0400
852 };
853
854 /* Values for NPConfig3DInAttrib_SwapBehavior */
855 enum {
856   NP3DSwapBehavior_Preserved            = 0x3094,
857   NP3DSwapBehavior_Destroyed            = 0x3095
858 };
859
860 /* Values for NPConfig3DInAttrib_MultisampleResolve */
861 enum {
862   NP3DMultisampleResolve_Default        = 0x309A,
863   NP3DMultisampleResolve_Box            = 0x309B
864 };
865
866 /* End 3D specific API */
867
868 /* Audio --------------------------------------------------------------------*/
869
870 #define NPPepperAudioDevice 3
871
872 /* min & max sample frame count */
873 typedef enum {
874   NPAudioMinSampleFrameCount = 64,
875   NPAudioMaxSampleFrameCount = 32768
876 } NPAudioSampleFrameCounts;
877
878 /* supported sample rates */
879 typedef enum {
880   NPAudioSampleRate44100Hz = 44100,
881   NPAudioSampleRate48000Hz = 48000,
882   NPAudioSampleRate96000Hz = 96000
883 } NPAudioSampleRates;
884
885 /* supported sample formats */
886 typedef enum {
887   NPAudioSampleTypeInt16   = 0,
888   NPAudioSampleTypeFloat32 = 1
889 } NPAudioSampleTypes;
890
891 /* supported channel layouts */
892 /* there is code that depends on these being the actual number of channels */
893 typedef enum {
894   NPAudioChannelNone     = 0,
895   NPAudioChannelMono     = 1,
896   NPAudioChannelStereo   = 2,
897   NPAudioChannelThree    = 3,
898   NPAudioChannelFour     = 4,
899   NPAudioChannelFive     = 5,
900   NPAudioChannelFiveOne  = 6,
901   NPAudioChannelSeven    = 7,
902   NPAudioChannelSevenOne = 8
903 } NPAudioChannels;
904
905 /* audio context states */
906 typedef enum {
907   NPAudioContextStateCallback = 0,
908   NPAudioContextStateUnderrunCounter = 1
909 } NPAudioContextStates;
910
911 /* audio context state values */
912 typedef enum {
913   NPAudioCallbackStop = 0,
914   NPAudioCallbackStart = 1
915 } NPAudioContextStateValues;
916
917 /* audio query capabilities */
918 typedef enum {
919   NPAudioCapabilitySampleRate              = 0,
920   NPAudioCapabilitySampleType              = 1,
921   NPAudioCapabilitySampleFrameCount        = 2,
922   NPAudioCapabilitySampleFrameCount44100Hz = 3,
923   NPAudioCapabilitySampleFrameCount48000Hz = 4,
924   NPAudioCapabilitySampleFrameCount96000Hz = 5,
925   NPAudioCapabilityOutputChannelMap        = 6,
926   NPAudioCapabilityInputChannelMap         = 7
927 } NPAudioCapabilities;
928
929 typedef struct _NPDeviceContextAudio NPDeviceContextAudio;
930
931 /* user supplied callback function */
932 typedef void (*NPAudioCallback)(NPDeviceContextAudio *context);
933
934 typedef struct _NPDeviceContextAudioConfig {
935   int32_t sampleRate;
936   int32_t sampleType;
937   int32_t outputChannelMap;
938   int32_t inputChannelMap;
939   int32_t sampleFrameCount;
940   uint32_t startThread;
941   uint32_t flags;
942   NPAudioCallback callback;
943   void *userData;
944 } NPDeviceContextAudioConfig;
945
946 struct _NPDeviceContextAudio {
947   NPDeviceContextAudioConfig config;
948   void *outBuffer;
949   void *inBuffer;
950   void *reserved;
951 };
952
953 /* Printing related APIs ---------------------------------------------------*/
954
955 /* Defines a contiguous range of pages to be printed. Page numbers use a
956  * zero-based index. */
957 typedef struct _NPPrintPageNumberRange {
958   int32_t firstPageNumber;
959   int32_t lastPageNumber;
960 } NPPrintPageNumberRange;
961
962 /* Being a print operation. Returns the total number of pages to print at the
963  * given printableArea size and DPI. printableArea is in points (a point is 1/72
964  * of an inch). The plugin is expected to remember the values of printableArea
965  * and printerDPI for use in subsequent print interface calls. These values
966  * should be cleared in printEnd. */
967 typedef NPError (*NPPPrintBeginPtr) (
968     NPP instance,
969     NPRect* printableArea,
970     int32_t printerDPI,
971     int32_t* numPages);
972 /* Returns the required raster dimensions for the given page. */
973 typedef NPError (*NPPGetRasterDimensionsPtr) (
974     NPP instance,
975     int32_t pageNumber,
976     int32_t* widthInPixels,
977     int32_t* heightInPixels);
978 /* Prints the specified page This allows the plugin to print a raster output. */
979 typedef NPError (*NPPPrintPageRasterPtr) (
980     NPP instance,
981     int32_t pageNumber,
982     NPDeviceContext2D* printSurface);
983 /* Ends the print operation */
984 typedef NPError (*NPPPrintEndPtr) (NPP instance);
985 /* Prints the specified pages as PDF. The plugin allocates the output buffer
986  * pointed to by pdf_output using the browser-supplied NPN_MemAlloc function.
987  * The caller is expected to free the output buffer upon success.*/
988 typedef NPError (*NPPrintPagesAsPDFPtr)(NPP instance,
989                                         NPPrintPageNumberRange* page_ranges,
990                                         int32_t page_range_count,
991                                         unsigned char** pdf_output,
992                                         int32_t* output_size);
993
994
995 /* TODO(sanjeevr) : Provide a vector interface for printing. We need to decide
996  * on a vector format that can support embedded fonts. A vector format will
997  * greatly reduce the size of the required output buffer. */
998
999 typedef struct _NPPPrintExtensions {
1000   NPPPrintBeginPtr printBegin;
1001   NPPGetRasterDimensionsPtr getRasterDimensions;
1002   NPPPrintPageRasterPtr printPageRaster;
1003   NPPPrintEndPtr printEnd;
1004   NPPrintPagesAsPDFPtr printPagesAsPDF;
1005 } NPPPrintExtensions;
1006
1007 /* Returns NULL if the plugin does not support print extensions */
1008 typedef NPPPrintExtensions* (*NPPGetPrintExtensionsPtr)(NPP instance);
1009
1010 /* Find ---------------------------------------------------------------------*/
1011
1012 /* Finds the given UTF-8 text starting at the current selection.  The number of
1013  * results will be updated asynchronously via numberOfFindResultsChanged.  Note
1014  * that multiple StartFind calls can happen before StopFind is called in the
1015  * case of the search term changing. */
1016 typedef NPError (*NPPStartFindPtr) (
1017     NPP instance,
1018     const char* text,
1019     bool caseSensitive);
1020
1021 /* Go to the next/previous result. */
1022 typedef NPError (*NPPSelectFindResultPtr) (
1023     NPP instance,
1024     bool forward);
1025
1026 /* Tells the plugin that the find operation has stopped, so it should clear
1027  * any highlighting. */
1028 typedef NPError (*NPPStopFindPtr) (
1029     NPP instance);
1030
1031 typedef struct _NPPFindExtensions {
1032   NPPStartFindPtr startFind;
1033   NPPSelectFindResultPtr selectFindResult;
1034   NPPStopFindPtr stopFind;
1035 } NPPFindExtensions;
1036
1037 /* Returns NULL if the plugin does not support find extensions. */
1038 typedef NPPFindExtensions* (*NPPGetFindExtensionsPtr)(NPP instance);
1039
1040 /* Zooms a plugin to the given factor.  If text_only is true, then only the text
1041  * should be zoomed. */
1042 typedef NPError (*NPPZoomPtr) (
1043     NPP instance,
1044     float factor,
1045     bool text_only);
1046
1047 typedef NPError (*NPPWidgetPropertyChangedPtr) (
1048     NPP instance,
1049     NPWidgetID id,
1050     NPWidgetProperty property);
1051
1052 /* type of selection */
1053 typedef enum {
1054   NPSelectionTypeAny       = 0,
1055   NPSelectionTypePlainText = 1,
1056   NPSelectionTypeHTML      = 2
1057 } NPSelectionType;
1058
1059 /* Gets the selection.  NPERR_GENERIC_ERROR is returned if nothing is selected.
1060  * 'type' is both an input and output parameter.  The caller can request a
1061  * specific type, and if the plugin can't provide it, it will return
1062  * NPERR_GENERIC_ERROR.  Or the caller can specify NPSelectionTypeAny to let the
1063  * plugin pick the best format for the data.  The result is returned in a buffer
1064  * that's owned by the caller and which is allocated using NPN_MemAlloc.  If no
1065  * data is available, NPERR_GENERIC_ERROR is returned. */
1066 typedef NPError (*NPPGetSelectionPtr) (
1067     NPP instance,
1068     NPSelectionType* type,
1069     void** data);
1070
1071 typedef struct _NPPExtensions {
1072   NPPGetPrintExtensionsPtr getPrintExtensions;
1073   NPPGetFindExtensionsPtr getFindExtensions;
1074   NPPZoomPtr zoom;
1075   NPPWidgetPropertyChangedPtr widgetPropertyChanged;
1076   NPPGetSelectionPtr getSelection;
1077 } NPPExtensions;
1078
1079 #endif  /* _NP_EXTENSIONS_H_ */