]> git.sesse.net Git - casparcg/blob - dependencies64/cef/include/capi/cef_v8_capi.h
* Merged html producer and updated to latest CEF version (does not have satisfactory...
[casparcg] / dependencies64 / cef / include / capi / cef_v8_capi.h
1 // Copyright (c) 2015 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // ---------------------------------------------------------------------------
31 //
32 // This file was generated by the CEF translator tool and should not edited
33 // by hand. See the translator.README.txt file in the tools directory for
34 // more information.
35 //
36
37 #ifndef CEF_INCLUDE_CAPI_CEF_V8_CAPI_H_
38 #define CEF_INCLUDE_CAPI_CEF_V8_CAPI_H_
39 #pragma once
40
41 #include "include/capi/cef_base_capi.h"
42 #include "include/capi/cef_browser_capi.h"
43 #include "include/capi/cef_frame_capi.h"
44 #include "include/capi/cef_task_capi.h"
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 struct _cef_v8exception_t;
51 struct _cef_v8handler_t;
52 struct _cef_v8stack_frame_t;
53 struct _cef_v8value_t;
54
55 ///
56 // Structure representing a V8 context handle. V8 handles can only be accessed
57 // from the thread on which they are created. Valid threads for creating a V8
58 // handle include the render process main thread (TID_RENDERER) and WebWorker
59 // threads. A task runner for posting tasks on the associated thread can be
60 // retrieved via the cef_v8context_t::get_task_runner() function.
61 ///
62 typedef struct _cef_v8context_t {
63   ///
64   // Base structure.
65   ///
66   cef_base_t base;
67
68   ///
69   // Returns the task runner associated with this context. V8 handles can only
70   // be accessed from the thread on which they are created. This function can be
71   // called on any render process thread.
72   ///
73   struct _cef_task_runner_t* (CEF_CALLBACK *get_task_runner)(
74       struct _cef_v8context_t* self);
75
76   ///
77   // Returns true (1) if the underlying handle is valid and it can be accessed
78   // on the current thread. Do not call any other functions if this function
79   // returns false (0).
80   ///
81   int (CEF_CALLBACK *is_valid)(struct _cef_v8context_t* self);
82
83   ///
84   // Returns the browser for this context. This function will return an NULL
85   // reference for WebWorker contexts.
86   ///
87   struct _cef_browser_t* (CEF_CALLBACK *get_browser)(
88       struct _cef_v8context_t* self);
89
90   ///
91   // Returns the frame for this context. This function will return an NULL
92   // reference for WebWorker contexts.
93   ///
94   struct _cef_frame_t* (CEF_CALLBACK *get_frame)(struct _cef_v8context_t* self);
95
96   ///
97   // Returns the global object for this context. The context must be entered
98   // before calling this function.
99   ///
100   struct _cef_v8value_t* (CEF_CALLBACK *get_global)(
101       struct _cef_v8context_t* self);
102
103   ///
104   // Enter this context. A context must be explicitly entered before creating a
105   // V8 Object, Array, Function or Date asynchronously. exit() must be called
106   // the same number of times as enter() before releasing this context. V8
107   // objects belong to the context in which they are created. Returns true (1)
108   // if the scope was entered successfully.
109   ///
110   int (CEF_CALLBACK *enter)(struct _cef_v8context_t* self);
111
112   ///
113   // Exit this context. Call this function only after calling enter(). Returns
114   // true (1) if the scope was exited successfully.
115   ///
116   int (CEF_CALLBACK *exit)(struct _cef_v8context_t* self);
117
118   ///
119   // Returns true (1) if this object is pointing to the same handle as |that|
120   // object.
121   ///
122   int (CEF_CALLBACK *is_same)(struct _cef_v8context_t* self,
123       struct _cef_v8context_t* that);
124
125   ///
126   // Evaluates the specified JavaScript code using this context's global object.
127   // On success |retval| will be set to the return value, if any, and the
128   // function will return true (1). On failure |exception| will be set to the
129   // exception, if any, and the function will return false (0).
130   ///
131   int (CEF_CALLBACK *eval)(struct _cef_v8context_t* self,
132       const cef_string_t* code, struct _cef_v8value_t** retval,
133       struct _cef_v8exception_t** exception);
134 } cef_v8context_t;
135
136
137 ///
138 // Returns the current (top) context object in the V8 context stack.
139 ///
140 CEF_EXPORT cef_v8context_t* cef_v8context_get_current_context();
141
142 ///
143 // Returns the entered (bottom) context object in the V8 context stack.
144 ///
145 CEF_EXPORT cef_v8context_t* cef_v8context_get_entered_context();
146
147 ///
148 // Returns true (1) if V8 is currently inside a context.
149 ///
150 CEF_EXPORT int cef_v8context_in_context();
151
152
153 ///
154 // Structure that should be implemented to handle V8 function calls. The
155 // functions of this structure will be called on the thread associated with the
156 // V8 function.
157 ///
158 typedef struct _cef_v8handler_t {
159   ///
160   // Base structure.
161   ///
162   cef_base_t base;
163
164   ///
165   // Handle execution of the function identified by |name|. |object| is the
166   // receiver ('this' object) of the function. |arguments| is the list of
167   // arguments passed to the function. If execution succeeds set |retval| to the
168   // function return value. If execution fails set |exception| to the exception
169   // that will be thrown. Return true (1) if execution was handled.
170   ///
171   int (CEF_CALLBACK *execute)(struct _cef_v8handler_t* self,
172       const cef_string_t* name, struct _cef_v8value_t* object,
173       size_t argumentsCount, struct _cef_v8value_t* const* arguments,
174       struct _cef_v8value_t** retval, cef_string_t* exception);
175 } cef_v8handler_t;
176
177
178 ///
179 // Structure that should be implemented to handle V8 accessor calls. Accessor
180 // identifiers are registered by calling cef_v8value_t::set_value(). The
181 // functions of this structure will be called on the thread associated with the
182 // V8 accessor.
183 ///
184 typedef struct _cef_v8accessor_t {
185   ///
186   // Base structure.
187   ///
188   cef_base_t base;
189
190   ///
191   // Handle retrieval the accessor value identified by |name|. |object| is the
192   // receiver ('this' object) of the accessor. If retrieval succeeds set
193   // |retval| to the return value. If retrieval fails set |exception| to the
194   // exception that will be thrown. Return true (1) if accessor retrieval was
195   // handled.
196   ///
197   int (CEF_CALLBACK *get)(struct _cef_v8accessor_t* self,
198       const cef_string_t* name, struct _cef_v8value_t* object,
199       struct _cef_v8value_t** retval, cef_string_t* exception);
200
201   ///
202   // Handle assignment of the accessor value identified by |name|. |object| is
203   // the receiver ('this' object) of the accessor. |value| is the new value
204   // being assigned to the accessor. If assignment fails set |exception| to the
205   // exception that will be thrown. Return true (1) if accessor assignment was
206   // handled.
207   ///
208   int (CEF_CALLBACK *set)(struct _cef_v8accessor_t* self,
209       const cef_string_t* name, struct _cef_v8value_t* object,
210       struct _cef_v8value_t* value, cef_string_t* exception);
211 } cef_v8accessor_t;
212
213
214 ///
215 // Structure representing a V8 exception. The functions of this structure may be
216 // called on any render process thread.
217 ///
218 typedef struct _cef_v8exception_t {
219   ///
220   // Base structure.
221   ///
222   cef_base_t base;
223
224   ///
225   // Returns the exception message.
226   ///
227   // The resulting string must be freed by calling cef_string_userfree_free().
228   cef_string_userfree_t (CEF_CALLBACK *get_message)(
229       struct _cef_v8exception_t* self);
230
231   ///
232   // Returns the line of source code that the exception occurred within.
233   ///
234   // The resulting string must be freed by calling cef_string_userfree_free().
235   cef_string_userfree_t (CEF_CALLBACK *get_source_line)(
236       struct _cef_v8exception_t* self);
237
238   ///
239   // Returns the resource name for the script from where the function causing
240   // the error originates.
241   ///
242   // The resulting string must be freed by calling cef_string_userfree_free().
243   cef_string_userfree_t (CEF_CALLBACK *get_script_resource_name)(
244       struct _cef_v8exception_t* self);
245
246   ///
247   // Returns the 1-based number of the line where the error occurred or 0 if the
248   // line number is unknown.
249   ///
250   int (CEF_CALLBACK *get_line_number)(struct _cef_v8exception_t* self);
251
252   ///
253   // Returns the index within the script of the first character where the error
254   // occurred.
255   ///
256   int (CEF_CALLBACK *get_start_position)(struct _cef_v8exception_t* self);
257
258   ///
259   // Returns the index within the script of the last character where the error
260   // occurred.
261   ///
262   int (CEF_CALLBACK *get_end_position)(struct _cef_v8exception_t* self);
263
264   ///
265   // Returns the index within the line of the first character where the error
266   // occurred.
267   ///
268   int (CEF_CALLBACK *get_start_column)(struct _cef_v8exception_t* self);
269
270   ///
271   // Returns the index within the line of the last character where the error
272   // occurred.
273   ///
274   int (CEF_CALLBACK *get_end_column)(struct _cef_v8exception_t* self);
275 } cef_v8exception_t;
276
277
278 ///
279 // Structure representing a V8 value handle. V8 handles can only be accessed
280 // from the thread on which they are created. Valid threads for creating a V8
281 // handle include the render process main thread (TID_RENDERER) and WebWorker
282 // threads. A task runner for posting tasks on the associated thread can be
283 // retrieved via the cef_v8context_t::get_task_runner() function.
284 ///
285 typedef struct _cef_v8value_t {
286   ///
287   // Base structure.
288   ///
289   cef_base_t base;
290
291   ///
292   // Returns true (1) if the underlying handle is valid and it can be accessed
293   // on the current thread. Do not call any other functions if this function
294   // returns false (0).
295   ///
296   int (CEF_CALLBACK *is_valid)(struct _cef_v8value_t* self);
297
298   ///
299   // True if the value type is undefined.
300   ///
301   int (CEF_CALLBACK *is_undefined)(struct _cef_v8value_t* self);
302
303   ///
304   // True if the value type is null.
305   ///
306   int (CEF_CALLBACK *is_null)(struct _cef_v8value_t* self);
307
308   ///
309   // True if the value type is bool.
310   ///
311   int (CEF_CALLBACK *is_bool)(struct _cef_v8value_t* self);
312
313   ///
314   // True if the value type is int.
315   ///
316   int (CEF_CALLBACK *is_int)(struct _cef_v8value_t* self);
317
318   ///
319   // True if the value type is unsigned int.
320   ///
321   int (CEF_CALLBACK *is_uint)(struct _cef_v8value_t* self);
322
323   ///
324   // True if the value type is double.
325   ///
326   int (CEF_CALLBACK *is_double)(struct _cef_v8value_t* self);
327
328   ///
329   // True if the value type is Date.
330   ///
331   int (CEF_CALLBACK *is_date)(struct _cef_v8value_t* self);
332
333   ///
334   // True if the value type is string.
335   ///
336   int (CEF_CALLBACK *is_string)(struct _cef_v8value_t* self);
337
338   ///
339   // True if the value type is object.
340   ///
341   int (CEF_CALLBACK *is_object)(struct _cef_v8value_t* self);
342
343   ///
344   // True if the value type is array.
345   ///
346   int (CEF_CALLBACK *is_array)(struct _cef_v8value_t* self);
347
348   ///
349   // True if the value type is function.
350   ///
351   int (CEF_CALLBACK *is_function)(struct _cef_v8value_t* self);
352
353   ///
354   // Returns true (1) if this object is pointing to the same handle as |that|
355   // object.
356   ///
357   int (CEF_CALLBACK *is_same)(struct _cef_v8value_t* self,
358       struct _cef_v8value_t* that);
359
360   ///
361   // Return a bool value.  The underlying data will be converted to if
362   // necessary.
363   ///
364   int (CEF_CALLBACK *get_bool_value)(struct _cef_v8value_t* self);
365
366   ///
367   // Return an int value.  The underlying data will be converted to if
368   // necessary.
369   ///
370   int32 (CEF_CALLBACK *get_int_value)(struct _cef_v8value_t* self);
371
372   ///
373   // Return an unisgned int value.  The underlying data will be converted to if
374   // necessary.
375   ///
376   uint32 (CEF_CALLBACK *get_uint_value)(struct _cef_v8value_t* self);
377
378   ///
379   // Return a double value.  The underlying data will be converted to if
380   // necessary.
381   ///
382   double (CEF_CALLBACK *get_double_value)(struct _cef_v8value_t* self);
383
384   ///
385   // Return a Date value.  The underlying data will be converted to if
386   // necessary.
387   ///
388   cef_time_t (CEF_CALLBACK *get_date_value)(struct _cef_v8value_t* self);
389
390   ///
391   // Return a string value.  The underlying data will be converted to if
392   // necessary.
393   ///
394   // The resulting string must be freed by calling cef_string_userfree_free().
395   cef_string_userfree_t (CEF_CALLBACK *get_string_value)(
396       struct _cef_v8value_t* self);
397
398
399   // OBJECT METHODS - These functions are only available on objects. Arrays and
400   // functions are also objects. String- and integer-based keys can be used
401   // interchangably with the framework converting between them as necessary.
402
403   ///
404   // Returns true (1) if this is a user created object.
405   ///
406   int (CEF_CALLBACK *is_user_created)(struct _cef_v8value_t* self);
407
408   ///
409   // Returns true (1) if the last function call resulted in an exception. This
410   // attribute exists only in the scope of the current CEF value object.
411   ///
412   int (CEF_CALLBACK *has_exception)(struct _cef_v8value_t* self);
413
414   ///
415   // Returns the exception resulting from the last function call. This attribute
416   // exists only in the scope of the current CEF value object.
417   ///
418   struct _cef_v8exception_t* (CEF_CALLBACK *get_exception)(
419       struct _cef_v8value_t* self);
420
421   ///
422   // Clears the last exception and returns true (1) on success.
423   ///
424   int (CEF_CALLBACK *clear_exception)(struct _cef_v8value_t* self);
425
426   ///
427   // Returns true (1) if this object will re-throw future exceptions. This
428   // attribute exists only in the scope of the current CEF value object.
429   ///
430   int (CEF_CALLBACK *will_rethrow_exceptions)(struct _cef_v8value_t* self);
431
432   ///
433   // Set whether this object will re-throw future exceptions. By default
434   // exceptions are not re-thrown. If a exception is re-thrown the current
435   // context should not be accessed again until after the exception has been
436   // caught and not re-thrown. Returns true (1) on success. This attribute
437   // exists only in the scope of the current CEF value object.
438   ///
439   int (CEF_CALLBACK *set_rethrow_exceptions)(struct _cef_v8value_t* self,
440       int rethrow);
441
442   ///
443   // Returns true (1) if the object has a value with the specified identifier.
444   ///
445   int (CEF_CALLBACK *has_value_bykey)(struct _cef_v8value_t* self,
446       const cef_string_t* key);
447
448   ///
449   // Returns true (1) if the object has a value with the specified identifier.
450   ///
451   int (CEF_CALLBACK *has_value_byindex)(struct _cef_v8value_t* self, int index);
452
453   ///
454   // Deletes the value with the specified identifier and returns true (1) on
455   // success. Returns false (0) if this function is called incorrectly or an
456   // exception is thrown. For read-only and don't-delete values this function
457   // will return true (1) even though deletion failed.
458   ///
459   int (CEF_CALLBACK *delete_value_bykey)(struct _cef_v8value_t* self,
460       const cef_string_t* key);
461
462   ///
463   // Deletes the value with the specified identifier and returns true (1) on
464   // success. Returns false (0) if this function is called incorrectly, deletion
465   // fails or an exception is thrown. For read-only and don't-delete values this
466   // function will return true (1) even though deletion failed.
467   ///
468   int (CEF_CALLBACK *delete_value_byindex)(struct _cef_v8value_t* self,
469       int index);
470
471   ///
472   // Returns the value with the specified identifier on success. Returns NULL if
473   // this function is called incorrectly or an exception is thrown.
474   ///
475   struct _cef_v8value_t* (CEF_CALLBACK *get_value_bykey)(
476       struct _cef_v8value_t* self, const cef_string_t* key);
477
478   ///
479   // Returns the value with the specified identifier on success. Returns NULL if
480   // this function is called incorrectly or an exception is thrown.
481   ///
482   struct _cef_v8value_t* (CEF_CALLBACK *get_value_byindex)(
483       struct _cef_v8value_t* self, int index);
484
485   ///
486   // Associates a value with the specified identifier and returns true (1) on
487   // success. Returns false (0) if this function is called incorrectly or an
488   // exception is thrown. For read-only values this function will return true
489   // (1) even though assignment failed.
490   ///
491   int (CEF_CALLBACK *set_value_bykey)(struct _cef_v8value_t* self,
492       const cef_string_t* key, struct _cef_v8value_t* value,
493       cef_v8_propertyattribute_t attribute);
494
495   ///
496   // Associates a value with the specified identifier and returns true (1) on
497   // success. Returns false (0) if this function is called incorrectly or an
498   // exception is thrown. For read-only values this function will return true
499   // (1) even though assignment failed.
500   ///
501   int (CEF_CALLBACK *set_value_byindex)(struct _cef_v8value_t* self, int index,
502       struct _cef_v8value_t* value);
503
504   ///
505   // Registers an identifier and returns true (1) on success. Access to the
506   // identifier will be forwarded to the cef_v8accessor_t instance passed to
507   // cef_v8value_t::cef_v8value_create_object(). Returns false (0) if this
508   // function is called incorrectly or an exception is thrown. For read-only
509   // values this function will return true (1) even though assignment failed.
510   ///
511   int (CEF_CALLBACK *set_value_byaccessor)(struct _cef_v8value_t* self,
512       const cef_string_t* key, cef_v8_accesscontrol_t settings,
513       cef_v8_propertyattribute_t attribute);
514
515   ///
516   // Read the keys for the object's values into the specified vector. Integer-
517   // based keys will also be returned as strings.
518   ///
519   int (CEF_CALLBACK *get_keys)(struct _cef_v8value_t* self,
520       cef_string_list_t keys);
521
522   ///
523   // Sets the user data for this object and returns true (1) on success. Returns
524   // false (0) if this function is called incorrectly. This function can only be
525   // called on user created objects.
526   ///
527   int (CEF_CALLBACK *set_user_data)(struct _cef_v8value_t* self,
528       struct _cef_base_t* user_data);
529
530   ///
531   // Returns the user data, if any, assigned to this object.
532   ///
533   struct _cef_base_t* (CEF_CALLBACK *get_user_data)(
534       struct _cef_v8value_t* self);
535
536   ///
537   // Returns the amount of externally allocated memory registered for the
538   // object.
539   ///
540   int (CEF_CALLBACK *get_externally_allocated_memory)(
541       struct _cef_v8value_t* self);
542
543   ///
544   // Adjusts the amount of registered external memory for the object. Used to
545   // give V8 an indication of the amount of externally allocated memory that is
546   // kept alive by JavaScript objects. V8 uses this information to decide when
547   // to perform global garbage collection. Each cef_v8value_t tracks the amount
548   // of external memory associated with it and automatically decreases the
549   // global total by the appropriate amount on its destruction.
550   // |change_in_bytes| specifies the number of bytes to adjust by. This function
551   // returns the number of bytes associated with the object after the
552   // adjustment. This function can only be called on user created objects.
553   ///
554   int (CEF_CALLBACK *adjust_externally_allocated_memory)(
555       struct _cef_v8value_t* self, int change_in_bytes);
556
557
558   // ARRAY METHODS - These functions are only available on arrays.
559
560   ///
561   // Returns the number of elements in the array.
562   ///
563   int (CEF_CALLBACK *get_array_length)(struct _cef_v8value_t* self);
564
565
566   // FUNCTION METHODS - These functions are only available on functions.
567
568   ///
569   // Returns the function name.
570   ///
571   // The resulting string must be freed by calling cef_string_userfree_free().
572   cef_string_userfree_t (CEF_CALLBACK *get_function_name)(
573       struct _cef_v8value_t* self);
574
575   ///
576   // Returns the function handler or NULL if not a CEF-created function.
577   ///
578   struct _cef_v8handler_t* (CEF_CALLBACK *get_function_handler)(
579       struct _cef_v8value_t* self);
580
581   ///
582   // Execute the function using the current V8 context. This function should
583   // only be called from within the scope of a cef_v8handler_t or
584   // cef_v8accessor_t callback, or in combination with calling enter() and
585   // exit() on a stored cef_v8context_t reference. |object| is the receiver
586   // ('this' object) of the function. If |object| is NULL the current context's
587   // global object will be used. |arguments| is the list of arguments that will
588   // be passed to the function. Returns the function return value on success.
589   // Returns NULL if this function is called incorrectly or an exception is
590   // thrown.
591   ///
592   struct _cef_v8value_t* (CEF_CALLBACK *execute_function)(
593       struct _cef_v8value_t* self, struct _cef_v8value_t* object,
594       size_t argumentsCount, struct _cef_v8value_t* const* arguments);
595
596   ///
597   // Execute the function using the specified V8 context. |object| is the
598   // receiver ('this' object) of the function. If |object| is NULL the specified
599   // context's global object will be used. |arguments| is the list of arguments
600   // that will be passed to the function. Returns the function return value on
601   // success. Returns NULL if this function is called incorrectly or an
602   // exception is thrown.
603   ///
604   struct _cef_v8value_t* (CEF_CALLBACK *execute_function_with_context)(
605       struct _cef_v8value_t* self, struct _cef_v8context_t* context,
606       struct _cef_v8value_t* object, size_t argumentsCount,
607       struct _cef_v8value_t* const* arguments);
608 } cef_v8value_t;
609
610
611 ///
612 // Create a new cef_v8value_t object of type undefined.
613 ///
614 CEF_EXPORT cef_v8value_t* cef_v8value_create_undefined();
615
616 ///
617 // Create a new cef_v8value_t object of type null.
618 ///
619 CEF_EXPORT cef_v8value_t* cef_v8value_create_null();
620
621 ///
622 // Create a new cef_v8value_t object of type bool.
623 ///
624 CEF_EXPORT cef_v8value_t* cef_v8value_create_bool(int value);
625
626 ///
627 // Create a new cef_v8value_t object of type int.
628 ///
629 CEF_EXPORT cef_v8value_t* cef_v8value_create_int(int32 value);
630
631 ///
632 // Create a new cef_v8value_t object of type unsigned int.
633 ///
634 CEF_EXPORT cef_v8value_t* cef_v8value_create_uint(uint32 value);
635
636 ///
637 // Create a new cef_v8value_t object of type double.
638 ///
639 CEF_EXPORT cef_v8value_t* cef_v8value_create_double(double value);
640
641 ///
642 // Create a new cef_v8value_t object of type Date. This function should only be
643 // called from within the scope of a cef_render_process_handler_t,
644 // cef_v8handler_t or cef_v8accessor_t callback, or in combination with calling
645 // enter() and exit() on a stored cef_v8context_t reference.
646 ///
647 CEF_EXPORT cef_v8value_t* cef_v8value_create_date(const cef_time_t* date);
648
649 ///
650 // Create a new cef_v8value_t object of type string.
651 ///
652 CEF_EXPORT cef_v8value_t* cef_v8value_create_string(const cef_string_t* value);
653
654 ///
655 // Create a new cef_v8value_t object of type object with optional accessor. This
656 // function should only be called from within the scope of a
657 // cef_render_process_handler_t, cef_v8handler_t or cef_v8accessor_t callback,
658 // or in combination with calling enter() and exit() on a stored cef_v8context_t
659 // reference.
660 ///
661 CEF_EXPORT cef_v8value_t* cef_v8value_create_object(cef_v8accessor_t* accessor);
662
663 ///
664 // Create a new cef_v8value_t object of type array with the specified |length|.
665 // If |length| is negative the returned array will have length 0. This function
666 // should only be called from within the scope of a
667 // cef_render_process_handler_t, cef_v8handler_t or cef_v8accessor_t callback,
668 // or in combination with calling enter() and exit() on a stored cef_v8context_t
669 // reference.
670 ///
671 CEF_EXPORT cef_v8value_t* cef_v8value_create_array(int length);
672
673 ///
674 // Create a new cef_v8value_t object of type function. This function should only
675 // be called from within the scope of a cef_render_process_handler_t,
676 // cef_v8handler_t or cef_v8accessor_t callback, or in combination with calling
677 // enter() and exit() on a stored cef_v8context_t reference.
678 ///
679 CEF_EXPORT cef_v8value_t* cef_v8value_create_function(const cef_string_t* name,
680     cef_v8handler_t* handler);
681
682
683 ///
684 // Structure representing a V8 stack trace handle. V8 handles can only be
685 // accessed from the thread on which they are created. Valid threads for
686 // creating a V8 handle include the render process main thread (TID_RENDERER)
687 // and WebWorker threads. A task runner for posting tasks on the associated
688 // thread can be retrieved via the cef_v8context_t::get_task_runner() function.
689 ///
690 typedef struct _cef_v8stack_trace_t {
691   ///
692   // Base structure.
693   ///
694   cef_base_t base;
695
696   ///
697   // Returns true (1) if the underlying handle is valid and it can be accessed
698   // on the current thread. Do not call any other functions if this function
699   // returns false (0).
700   ///
701   int (CEF_CALLBACK *is_valid)(struct _cef_v8stack_trace_t* self);
702
703   ///
704   // Returns the number of stack frames.
705   ///
706   int (CEF_CALLBACK *get_frame_count)(struct _cef_v8stack_trace_t* self);
707
708   ///
709   // Returns the stack frame at the specified 0-based index.
710   ///
711   struct _cef_v8stack_frame_t* (CEF_CALLBACK *get_frame)(
712       struct _cef_v8stack_trace_t* self, int index);
713 } cef_v8stack_trace_t;
714
715
716 ///
717 // Returns the stack trace for the currently active context. |frame_limit| is
718 // the maximum number of frames that will be captured.
719 ///
720 CEF_EXPORT cef_v8stack_trace_t* cef_v8stack_trace_get_current(int frame_limit);
721
722
723 ///
724 // Structure representing a V8 stack frame handle. V8 handles can only be
725 // accessed from the thread on which they are created. Valid threads for
726 // creating a V8 handle include the render process main thread (TID_RENDERER)
727 // and WebWorker threads. A task runner for posting tasks on the associated
728 // thread can be retrieved via the cef_v8context_t::get_task_runner() function.
729 ///
730 typedef struct _cef_v8stack_frame_t {
731   ///
732   // Base structure.
733   ///
734   cef_base_t base;
735
736   ///
737   // Returns true (1) if the underlying handle is valid and it can be accessed
738   // on the current thread. Do not call any other functions if this function
739   // returns false (0).
740   ///
741   int (CEF_CALLBACK *is_valid)(struct _cef_v8stack_frame_t* self);
742
743   ///
744   // Returns the name of the resource script that contains the function.
745   ///
746   // The resulting string must be freed by calling cef_string_userfree_free().
747   cef_string_userfree_t (CEF_CALLBACK *get_script_name)(
748       struct _cef_v8stack_frame_t* self);
749
750   ///
751   // Returns the name of the resource script that contains the function or the
752   // sourceURL value if the script name is undefined and its source ends with a
753   // "//@ sourceURL=..." string.
754   ///
755   // The resulting string must be freed by calling cef_string_userfree_free().
756   cef_string_userfree_t (CEF_CALLBACK *get_script_name_or_source_url)(
757       struct _cef_v8stack_frame_t* self);
758
759   ///
760   // Returns the name of the function.
761   ///
762   // The resulting string must be freed by calling cef_string_userfree_free().
763   cef_string_userfree_t (CEF_CALLBACK *get_function_name)(
764       struct _cef_v8stack_frame_t* self);
765
766   ///
767   // Returns the 1-based line number for the function call or 0 if unknown.
768   ///
769   int (CEF_CALLBACK *get_line_number)(struct _cef_v8stack_frame_t* self);
770
771   ///
772   // Returns the 1-based column offset on the line for the function call or 0 if
773   // unknown.
774   ///
775   int (CEF_CALLBACK *get_column)(struct _cef_v8stack_frame_t* self);
776
777   ///
778   // Returns true (1) if the function was compiled using eval().
779   ///
780   int (CEF_CALLBACK *is_eval)(struct _cef_v8stack_frame_t* self);
781
782   ///
783   // Returns true (1) if the function was called as a constructor via "new".
784   ///
785   int (CEF_CALLBACK *is_constructor)(struct _cef_v8stack_frame_t* self);
786 } cef_v8stack_frame_t;
787
788
789 ///
790 // Register a new V8 extension with the specified JavaScript extension code and
791 // handler. Functions implemented by the handler are prototyped using the
792 // keyword 'native'. The calling of a native function is restricted to the scope
793 // in which the prototype of the native function is defined. This function may
794 // only be called on the render process main thread.
795 //
796 // Example JavaScript extension code: <pre>
797 //   // create the 'example' global object if it doesn't already exist.
798 //   if (!example)
799 //     example = {};
800 //   // create the 'example.test' global object if it doesn't already exist.
801 //   if (!example.test)
802 //     example.test = {};
803 //   (function() {
804 //     // Define the function 'example.test.myfunction'.
805 //     example.test.myfunction = function() {
806 //       // Call CefV8Handler::Execute() with the function name 'MyFunction'
807 //       // and no arguments.
808 //       native function MyFunction();
809 //       return MyFunction();
810 //     };
811 //     // Define the getter function for parameter 'example.test.myparam'.
812 //     example.test.__defineGetter__('myparam', function() {
813 //       // Call CefV8Handler::Execute() with the function name 'GetMyParam'
814 //       // and no arguments.
815 //       native function GetMyParam();
816 //       return GetMyParam();
817 //     });
818 //     // Define the setter function for parameter 'example.test.myparam'.
819 //     example.test.__defineSetter__('myparam', function(b) {
820 //       // Call CefV8Handler::Execute() with the function name 'SetMyParam'
821 //       // and a single argument.
822 //       native function SetMyParam();
823 //       if(b) SetMyParam(b);
824 //     });
825 //
826 //     // Extension definitions can also contain normal JavaScript variables
827 //     // and functions.
828 //     var myint = 0;
829 //     example.test.increment = function() {
830 //       myint += 1;
831 //       return myint;
832 //     };
833 //   })();
834 // </pre> Example usage in the page: <pre>
835 //   // Call the function.
836 //   example.test.myfunction();
837 //   // Set the parameter.
838 //   example.test.myparam = value;
839 //   // Get the parameter.
840 //   value = example.test.myparam;
841 //   // Call another function.
842 //   example.test.increment();
843 // </pre>
844 ///
845 CEF_EXPORT int cef_register_extension(const cef_string_t* extension_name,
846     const cef_string_t* javascript_code, cef_v8handler_t* handler);
847
848 #ifdef __cplusplus
849 }
850 #endif
851
852 #endif  // CEF_INCLUDE_CAPI_CEF_V8_CAPI_H_