]> git.sesse.net Git - casparcg/blob - dependencies64/cef/include/cef_v8.h
* Merged html producer and updated to latest CEF version (does not have satisfactory...
[casparcg] / dependencies64 / cef / include / cef_v8.h
1 // Copyright (c) 2013 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 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
35 //
36
37
38 #ifndef CEF_INCLUDE_CEF_V8_H_
39 #define CEF_INCLUDE_CEF_V8_H_
40 #pragma once
41
42 #include "include/cef_base.h"
43 #include "include/cef_browser.h"
44 #include "include/cef_frame.h"
45 #include "include/cef_task.h"
46 #include <vector>
47
48 class CefV8Exception;
49 class CefV8Handler;
50 class CefV8StackFrame;
51 class CefV8Value;
52
53
54 ///
55 // Register a new V8 extension with the specified JavaScript extension code and
56 // handler. Functions implemented by the handler are prototyped using the
57 // keyword 'native'. The calling of a native function is restricted to the scope
58 // in which the prototype of the native function is defined. This function may
59 // only be called on the render process main thread.
60 //
61 // Example JavaScript extension code:
62 // <pre>
63 //   // create the 'example' global object if it doesn't already exist.
64 //   if (!example)
65 //     example = {};
66 //   // create the 'example.test' global object if it doesn't already exist.
67 //   if (!example.test)
68 //     example.test = {};
69 //   (function() {
70 //     // Define the function 'example.test.myfunction'.
71 //     example.test.myfunction = function() {
72 //       // Call CefV8Handler::Execute() with the function name 'MyFunction'
73 //       // and no arguments.
74 //       native function MyFunction();
75 //       return MyFunction();
76 //     };
77 //     // Define the getter function for parameter 'example.test.myparam'.
78 //     example.test.__defineGetter__('myparam', function() {
79 //       // Call CefV8Handler::Execute() with the function name 'GetMyParam'
80 //       // and no arguments.
81 //       native function GetMyParam();
82 //       return GetMyParam();
83 //     });
84 //     // Define the setter function for parameter 'example.test.myparam'.
85 //     example.test.__defineSetter__('myparam', function(b) {
86 //       // Call CefV8Handler::Execute() with the function name 'SetMyParam'
87 //       // and a single argument.
88 //       native function SetMyParam();
89 //       if(b) SetMyParam(b);
90 //     });
91 //
92 //     // Extension definitions can also contain normal JavaScript variables
93 //     // and functions.
94 //     var myint = 0;
95 //     example.test.increment = function() {
96 //       myint += 1;
97 //       return myint;
98 //     };
99 //   })();
100 // </pre>
101 // Example usage in the page:
102 // <pre>
103 //   // Call the function.
104 //   example.test.myfunction();
105 //   // Set the parameter.
106 //   example.test.myparam = value;
107 //   // Get the parameter.
108 //   value = example.test.myparam;
109 //   // Call another function.
110 //   example.test.increment();
111 // </pre>
112 ///
113 /*--cef(optional_param=handler)--*/
114 bool CefRegisterExtension(const CefString& extension_name,
115                           const CefString& javascript_code,
116                           CefRefPtr<CefV8Handler> handler);
117
118
119 ///
120 // Class representing a V8 context handle. V8 handles can only be accessed from
121 // the thread on which they are created. Valid threads for creating a V8 handle
122 // include the render process main thread (TID_RENDERER) and WebWorker threads.
123 // A task runner for posting tasks on the associated thread can be retrieved via
124 // the CefV8Context::GetTaskRunner() method.
125 ///
126 /*--cef(source=library)--*/
127 class CefV8Context : public virtual CefBase {
128  public:
129   ///
130   // Returns the current (top) context object in the V8 context stack.
131   ///
132   /*--cef()--*/
133   static CefRefPtr<CefV8Context> GetCurrentContext();
134
135   ///
136   // Returns the entered (bottom) context object in the V8 context stack.
137   ///
138   /*--cef()--*/
139   static CefRefPtr<CefV8Context> GetEnteredContext();
140
141   ///
142   // Returns true if V8 is currently inside a context.
143   ///
144   /*--cef()--*/
145   static bool InContext();
146
147   ///
148   // Returns the task runner associated with this context. V8 handles can only
149   // be accessed from the thread on which they are created. This method can be
150   // called on any render process thread.
151   ///
152   /*--cef()--*/
153   virtual CefRefPtr<CefTaskRunner> GetTaskRunner() =0;
154
155   ///
156   // Returns true if the underlying handle is valid and it can be accessed on
157   // the current thread. Do not call any other methods if this method returns
158   // false.
159   ///
160   /*--cef()--*/
161   virtual bool IsValid() =0;
162
163   ///
164   // Returns the browser for this context. This method will return an empty
165   // reference for WebWorker contexts.
166   ///
167   /*--cef()--*/
168   virtual CefRefPtr<CefBrowser> GetBrowser() =0;
169
170   ///
171   // Returns the frame for this context. This method will return an empty
172   // reference for WebWorker contexts.
173   ///
174   /*--cef()--*/
175   virtual CefRefPtr<CefFrame> GetFrame() =0;
176
177   ///
178   // Returns the global object for this context. The context must be entered
179   // before calling this method.
180   ///
181   /*--cef()--*/
182   virtual CefRefPtr<CefV8Value> GetGlobal() =0;
183
184   ///
185   // Enter this context. A context must be explicitly entered before creating a
186   // V8 Object, Array, Function or Date asynchronously. Exit() must be called
187   // the same number of times as Enter() before releasing this context. V8
188   // objects belong to the context in which they are created. Returns true if
189   // the scope was entered successfully.
190   ///
191   /*--cef()--*/
192   virtual bool Enter() =0;
193
194   ///
195   // Exit this context. Call this method only after calling Enter(). Returns
196   // true if the scope was exited successfully.
197   ///
198   /*--cef()--*/
199   virtual bool Exit() =0;
200
201   ///
202   // Returns true if this object is pointing to the same handle as |that|
203   // object.
204   ///
205   /*--cef()--*/
206   virtual bool IsSame(CefRefPtr<CefV8Context> that) =0;
207
208   ///
209   // Evaluates the specified JavaScript code using this context's global object.
210   // On success |retval| will be set to the return value, if any, and the
211   // function will return true. On failure |exception| will be set to the
212   // exception, if any, and the function will return false.
213   ///
214   /*--cef()--*/
215   virtual bool Eval(const CefString& code,
216                     CefRefPtr<CefV8Value>& retval,
217                     CefRefPtr<CefV8Exception>& exception) =0;
218 };
219
220
221 typedef std::vector<CefRefPtr<CefV8Value> > CefV8ValueList;
222
223 ///
224 // Interface that should be implemented to handle V8 function calls. The methods
225 // of this class will be called on the thread associated with the V8 function.
226 ///
227 /*--cef(source=client)--*/
228 class CefV8Handler : public virtual CefBase {
229  public:
230   ///
231   // Handle execution of the function identified by |name|. |object| is the
232   // receiver ('this' object) of the function. |arguments| is the list of
233   // arguments passed to the function. If execution succeeds set |retval| to the
234   // function return value. If execution fails set |exception| to the exception
235   // that will be thrown. Return true if execution was handled.
236   ///
237   /*--cef()--*/
238   virtual bool Execute(const CefString& name,
239                        CefRefPtr<CefV8Value> object,
240                        const CefV8ValueList& arguments,
241                        CefRefPtr<CefV8Value>& retval,
242                        CefString& exception) =0;
243 };
244
245 ///
246 // Interface that should be implemented to handle V8 accessor calls. Accessor
247 // identifiers are registered by calling CefV8Value::SetValue(). The methods
248 // of this class will be called on the thread associated with the V8 accessor.
249 ///
250 /*--cef(source=client)--*/
251 class CefV8Accessor : public virtual CefBase {
252  public:
253   ///
254   // Handle retrieval the accessor value identified by |name|. |object| is the
255   // receiver ('this' object) of the accessor. If retrieval succeeds set
256   // |retval| to the return value. If retrieval fails set |exception| to the
257   // exception that will be thrown. Return true if accessor retrieval was
258   // handled.
259   ///
260   /*--cef()--*/
261   virtual bool Get(const CefString& name,
262                    const CefRefPtr<CefV8Value> object,
263                    CefRefPtr<CefV8Value>& retval,
264                    CefString& exception) =0;
265
266   ///
267   // Handle assignment of the accessor value identified by |name|. |object| is
268   // the receiver ('this' object) of the accessor. |value| is the new value
269   // being assigned to the accessor. If assignment fails set |exception| to the
270   // exception that will be thrown. Return true if accessor assignment was
271   // handled.
272   ///
273   /*--cef()--*/
274   virtual bool Set(const CefString& name,
275                    const CefRefPtr<CefV8Value> object,
276                    const CefRefPtr<CefV8Value> value,
277                    CefString& exception) =0;
278 };
279
280 ///
281 // Class representing a V8 exception. The methods of this class may be called on
282 // any render process thread.
283 ///
284 /*--cef(source=library)--*/
285 class CefV8Exception : public virtual CefBase {
286  public:
287   ///
288   // Returns the exception message.
289   ///
290   /*--cef()--*/
291   virtual CefString GetMessage() =0;
292
293   ///
294   // Returns the line of source code that the exception occurred within.
295   ///
296   /*--cef()--*/
297   virtual CefString GetSourceLine() =0;
298
299   ///
300   // Returns the resource name for the script from where the function causing
301   // the error originates.
302   ///
303   /*--cef()--*/
304   virtual CefString GetScriptResourceName() =0;
305
306   ///
307   // Returns the 1-based number of the line where the error occurred or 0 if the
308   // line number is unknown.
309   ///
310   /*--cef()--*/
311   virtual int GetLineNumber() =0;
312
313   ///
314   // Returns the index within the script of the first character where the error
315   // occurred.
316   ///
317   /*--cef()--*/
318   virtual int GetStartPosition() =0;
319
320   ///
321   // Returns the index within the script of the last character where the error
322   // occurred.
323   ///
324   /*--cef()--*/
325   virtual int GetEndPosition() =0;
326
327   ///
328   // Returns the index within the line of the first character where the error
329   // occurred.
330   ///
331   /*--cef()--*/
332   virtual int GetStartColumn() =0;
333
334   ///
335   // Returns the index within the line of the last character where the error
336   // occurred.
337   ///
338   /*--cef()--*/
339   virtual int GetEndColumn() =0;
340 };
341
342 ///
343 // Class representing a V8 value handle. V8 handles can only be accessed from
344 // the thread on which they are created. Valid threads for creating a V8 handle
345 // include the render process main thread (TID_RENDERER) and WebWorker threads.
346 // A task runner for posting tasks on the associated thread can be retrieved via
347 // the CefV8Context::GetTaskRunner() method.
348 ///
349 /*--cef(source=library)--*/
350 class CefV8Value : public virtual CefBase {
351  public:
352   typedef cef_v8_accesscontrol_t AccessControl;
353   typedef cef_v8_propertyattribute_t PropertyAttribute;
354
355   ///
356   // Create a new CefV8Value object of type undefined.
357   ///
358   /*--cef()--*/
359   static CefRefPtr<CefV8Value> CreateUndefined();
360
361   ///
362   // Create a new CefV8Value object of type null.
363   ///
364   /*--cef()--*/
365   static CefRefPtr<CefV8Value> CreateNull();
366
367   ///
368   // Create a new CefV8Value object of type bool.
369   ///
370   /*--cef()--*/
371   static CefRefPtr<CefV8Value> CreateBool(bool value);
372
373   ///
374   // Create a new CefV8Value object of type int.
375   ///
376   /*--cef()--*/
377   static CefRefPtr<CefV8Value> CreateInt(int32 value);
378
379   ///
380   // Create a new CefV8Value object of type unsigned int.
381   ///
382   /*--cef()--*/
383   static CefRefPtr<CefV8Value> CreateUInt(uint32 value);
384
385   ///
386   // Create a new CefV8Value object of type double.
387   ///
388   /*--cef()--*/
389   static CefRefPtr<CefV8Value> CreateDouble(double value);
390
391   ///
392   // Create a new CefV8Value object of type Date. This method should only be
393   // called from within the scope of a CefRenderProcessHandler, CefV8Handler or
394   // CefV8Accessor callback, or in combination with calling Enter() and Exit()
395   // on a stored CefV8Context reference.
396   ///
397   /*--cef()--*/
398   static CefRefPtr<CefV8Value> CreateDate(const CefTime& date);
399
400   ///
401   // Create a new CefV8Value object of type string.
402   ///
403   /*--cef(optional_param=value)--*/
404   static CefRefPtr<CefV8Value> CreateString(const CefString& value);
405
406   ///
407   // Create a new CefV8Value object of type object with optional accessor. This
408   // method should only be called from within the scope of a
409   // CefRenderProcessHandler, CefV8Handler or CefV8Accessor callback, or in
410   // combination with calling Enter() and Exit() on a stored CefV8Context
411   // reference.
412   ///
413   /*--cef(optional_param=accessor)--*/
414   static CefRefPtr<CefV8Value> CreateObject(CefRefPtr<CefV8Accessor> accessor);
415
416   ///
417   // Create a new CefV8Value object of type array with the specified |length|.
418   // If |length| is negative the returned array will have length 0. This method
419   // should only be called from within the scope of a CefRenderProcessHandler,
420   // CefV8Handler or CefV8Accessor callback, or in combination with calling
421   // Enter() and Exit() on a stored CefV8Context reference.
422   ///
423   /*--cef()--*/
424   static CefRefPtr<CefV8Value> CreateArray(int length);
425
426   ///
427   // Create a new CefV8Value object of type function. This method should only be
428   // called from within the scope of a CefRenderProcessHandler, CefV8Handler or
429   // CefV8Accessor callback, or in combination with calling Enter() and Exit()
430   // on a stored CefV8Context reference.
431   ///
432   /*--cef()--*/
433   static CefRefPtr<CefV8Value> CreateFunction(const CefString& name,
434                                               CefRefPtr<CefV8Handler> handler);
435
436   ///
437   // Returns true if the underlying handle is valid and it can be accessed on
438   // the current thread. Do not call any other methods if this method returns
439   // false.
440   ///
441   /*--cef()--*/
442   virtual bool IsValid() =0;
443
444   ///
445   // True if the value type is undefined.
446   ///
447   /*--cef()--*/
448   virtual bool IsUndefined() =0;
449
450   ///
451   // True if the value type is null.
452   ///
453   /*--cef()--*/
454   virtual bool IsNull() =0;
455
456   ///
457   // True if the value type is bool.
458   ///
459   /*--cef()--*/
460   virtual bool IsBool() =0;
461
462   ///
463   // True if the value type is int.
464   ///
465   /*--cef()--*/
466   virtual bool IsInt() =0;
467
468   ///
469   // True if the value type is unsigned int.
470   ///
471   /*--cef()--*/
472   virtual bool IsUInt() =0;
473
474   ///
475   // True if the value type is double.
476   ///
477   /*--cef()--*/
478   virtual bool IsDouble() =0;
479
480   ///
481   // True if the value type is Date.
482   ///
483   /*--cef()--*/
484   virtual bool IsDate() =0;
485
486   ///
487   // True if the value type is string.
488   ///
489   /*--cef()--*/
490   virtual bool IsString() =0;
491
492   ///
493   // True if the value type is object.
494   ///
495   /*--cef()--*/
496   virtual bool IsObject() =0;
497
498   ///
499   // True if the value type is array.
500   ///
501   /*--cef()--*/
502   virtual bool IsArray() =0;
503
504   ///
505   // True if the value type is function.
506   ///
507   /*--cef()--*/
508   virtual bool IsFunction() =0;
509
510   ///
511   // Returns true if this object is pointing to the same handle as |that|
512   // object.
513   ///
514   /*--cef()--*/
515   virtual bool IsSame(CefRefPtr<CefV8Value> that) =0;
516
517   ///
518   // Return a bool value.  The underlying data will be converted to if
519   // necessary.
520   ///
521   /*--cef()--*/
522   virtual bool GetBoolValue() =0;
523
524   ///
525   // Return an int value.  The underlying data will be converted to if
526   // necessary.
527   ///
528   /*--cef()--*/
529   virtual int32 GetIntValue() =0;
530
531   ///
532   // Return an unisgned int value.  The underlying data will be converted to if
533   // necessary.
534   ///
535   /*--cef()--*/
536   virtual uint32 GetUIntValue() =0;
537
538   ///
539   // Return a double value.  The underlying data will be converted to if
540   // necessary.
541   ///
542   /*--cef()--*/
543   virtual double GetDoubleValue() =0;
544
545   ///
546   // Return a Date value.  The underlying data will be converted to if
547   // necessary.
548   ///
549   /*--cef()--*/
550   virtual CefTime GetDateValue() =0;
551
552   ///
553   // Return a string value.  The underlying data will be converted to if
554   // necessary.
555   ///
556   /*--cef()--*/
557   virtual CefString GetStringValue() =0;
558
559
560   // OBJECT METHODS - These methods are only available on objects. Arrays and
561   // functions are also objects. String- and integer-based keys can be used
562   // interchangably with the framework converting between them as necessary.
563
564   ///
565   // Returns true if this is a user created object.
566   ///
567   /*--cef()--*/
568   virtual bool IsUserCreated() =0;
569
570   ///
571   // Returns true if the last method call resulted in an exception. This
572   // attribute exists only in the scope of the current CEF value object.
573   ///
574   /*--cef()--*/
575   virtual bool HasException() =0;
576
577   ///
578   // Returns the exception resulting from the last method call. This attribute
579   // exists only in the scope of the current CEF value object.
580   ///
581   /*--cef()--*/
582   virtual CefRefPtr<CefV8Exception> GetException() =0;
583
584   ///
585   // Clears the last exception and returns true on success.
586   ///
587   /*--cef()--*/
588   virtual bool ClearException() =0;
589
590   ///
591   // Returns true if this object will re-throw future exceptions. This attribute
592   // exists only in the scope of the current CEF value object.
593   ///
594   /*--cef()--*/
595   virtual bool WillRethrowExceptions() =0;
596
597   ///
598   // Set whether this object will re-throw future exceptions. By default
599   // exceptions are not re-thrown. If a exception is re-thrown the current
600   // context should not be accessed again until after the exception has been
601   // caught and not re-thrown. Returns true on success. This attribute exists
602   // only in the scope of the current CEF value object.
603   ///
604   /*--cef()--*/
605   virtual bool SetRethrowExceptions(bool rethrow) =0;
606
607   ///
608   // Returns true if the object has a value with the specified identifier.
609   ///
610   /*--cef(capi_name=has_value_bykey,optional_param=key)--*/
611   virtual bool HasValue(const CefString& key) =0;
612
613   ///
614   // Returns true if the object has a value with the specified identifier.
615   ///
616   /*--cef(capi_name=has_value_byindex,index_param=index)--*/
617   virtual bool HasValue(int index) =0;
618
619   ///
620   // Deletes the value with the specified identifier and returns true on
621   // success. Returns false if this method is called incorrectly or an exception
622   // is thrown. For read-only and don't-delete values this method will return
623   // true even though deletion failed.
624   ///
625   /*--cef(capi_name=delete_value_bykey,optional_param=key)--*/
626   virtual bool DeleteValue(const CefString& key) =0;
627
628   ///
629   // Deletes the value with the specified identifier and returns true on
630   // success. Returns false if this method is called incorrectly, deletion fails
631   // or an exception is thrown. For read-only and don't-delete values this
632   // method will return true even though deletion failed.
633   ///
634   /*--cef(capi_name=delete_value_byindex,index_param=index)--*/
635   virtual bool DeleteValue(int index) =0;
636
637   ///
638   // Returns the value with the specified identifier on success. Returns NULL
639   // if this method is called incorrectly or an exception is thrown.
640   ///
641   /*--cef(capi_name=get_value_bykey,optional_param=key)--*/
642   virtual CefRefPtr<CefV8Value> GetValue(const CefString& key) =0;
643
644   ///
645   // Returns the value with the specified identifier on success. Returns NULL
646   // if this method is called incorrectly or an exception is thrown.
647   ///
648   /*--cef(capi_name=get_value_byindex,index_param=index)--*/
649   virtual CefRefPtr<CefV8Value> GetValue(int index) =0;
650
651   ///
652   // Associates a value with the specified identifier and returns true on
653   // success. Returns false if this method is called incorrectly or an exception
654   // is thrown. For read-only values this method will return true even though
655   // assignment failed.
656   ///
657   /*--cef(capi_name=set_value_bykey,optional_param=key)--*/
658   virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value,
659                         PropertyAttribute attribute) =0;
660
661   ///
662   // Associates a value with the specified identifier and returns true on
663   // success. Returns false if this method is called incorrectly or an exception
664   // is thrown. For read-only values this method will return true even though
665   // assignment failed.
666   ///
667   /*--cef(capi_name=set_value_byindex,index_param=index)--*/
668   virtual bool SetValue(int index, CefRefPtr<CefV8Value> value) =0;
669
670   ///
671   // Registers an identifier and returns true on success. Access to the
672   // identifier will be forwarded to the CefV8Accessor instance passed to
673   // CefV8Value::CreateObject(). Returns false if this method is called
674   // incorrectly or an exception is thrown. For read-only values this method
675   // will return true even though assignment failed.
676   ///
677   /*--cef(capi_name=set_value_byaccessor,optional_param=key)--*/
678   virtual bool SetValue(const CefString& key, AccessControl settings,
679                         PropertyAttribute attribute) =0;
680
681   ///
682   // Read the keys for the object's values into the specified vector. Integer-
683   // based keys will also be returned as strings.
684   ///
685   /*--cef()--*/
686   virtual bool GetKeys(std::vector<CefString>& keys) =0;
687
688   ///
689   // Sets the user data for this object and returns true on success. Returns
690   // false if this method is called incorrectly. This method can only be called
691   // on user created objects.
692   ///
693   /*--cef(optional_param=user_data)--*/
694   virtual bool SetUserData(CefRefPtr<CefBase> user_data) =0;
695
696   ///
697   // Returns the user data, if any, assigned to this object.
698   ///
699   /*--cef()--*/
700   virtual CefRefPtr<CefBase> GetUserData() =0;
701
702   ///
703   // Returns the amount of externally allocated memory registered for the
704   // object.
705   ///
706   /*--cef()--*/
707   virtual int GetExternallyAllocatedMemory() =0;
708
709   ///
710   // Adjusts the amount of registered external memory for the object. Used to
711   // give V8 an indication of the amount of externally allocated memory that is
712   // kept alive by JavaScript objects. V8 uses this information to decide when
713   // to perform global garbage collection. Each CefV8Value tracks the amount of
714   // external memory associated with it and automatically decreases the global
715   // total by the appropriate amount on its destruction. |change_in_bytes|
716   // specifies the number of bytes to adjust by. This method returns the number
717   // of bytes associated with the object after the adjustment. This method can
718   // only be called on user created objects.
719   ///
720   /*--cef()--*/
721   virtual int AdjustExternallyAllocatedMemory(int change_in_bytes) =0;
722
723
724   // ARRAY METHODS - These methods are only available on arrays.
725
726   ///
727   // Returns the number of elements in the array.
728   ///
729   /*--cef()--*/
730   virtual int GetArrayLength() =0;
731
732
733   // FUNCTION METHODS - These methods are only available on functions.
734
735   ///
736   // Returns the function name.
737   ///
738   /*--cef()--*/
739   virtual CefString GetFunctionName() =0;
740
741   ///
742   // Returns the function handler or NULL if not a CEF-created function.
743   ///
744   /*--cef()--*/
745   virtual CefRefPtr<CefV8Handler> GetFunctionHandler() =0;
746
747   ///
748   // Execute the function using the current V8 context. This method should only
749   // be called from within the scope of a CefV8Handler or CefV8Accessor
750   // callback, or in combination with calling Enter() and Exit() on a stored
751   // CefV8Context reference. |object| is the receiver ('this' object) of the
752   // function. If |object| is empty the current context's global object will be
753   // used. |arguments| is the list of arguments that will be passed to the
754   // function. Returns the function return value on success. Returns NULL if
755   // this method is called incorrectly or an exception is thrown.
756   ///
757   /*--cef(optional_param=object)--*/
758   virtual CefRefPtr<CefV8Value> ExecuteFunction(
759       CefRefPtr<CefV8Value> object,
760       const CefV8ValueList& arguments) =0;
761
762   ///
763   // Execute the function using the specified V8 context. |object| is the
764   // receiver ('this' object) of the function. If |object| is empty the
765   // specified context's global object will be used. |arguments| is the list of
766   // arguments that will be passed to the function. Returns the function return
767   // value on success. Returns NULL if this method is called incorrectly or an
768   // exception is thrown.
769   ///
770   /*--cef(optional_param=object)--*/
771   virtual CefRefPtr<CefV8Value> ExecuteFunctionWithContext(
772       CefRefPtr<CefV8Context> context,
773       CefRefPtr<CefV8Value> object,
774       const CefV8ValueList& arguments) =0;
775 };
776
777 ///
778 // Class representing a V8 stack trace handle. V8 handles can only be accessed
779 // from the thread on which they are created. Valid threads for creating a V8
780 // handle include the render process main thread (TID_RENDERER) and WebWorker
781 // threads. A task runner for posting tasks on the associated thread can be
782 // retrieved via the CefV8Context::GetTaskRunner() method.
783 ///
784 /*--cef(source=library)--*/
785 class CefV8StackTrace : public virtual CefBase {
786  public:
787   ///
788   // Returns the stack trace for the currently active context. |frame_limit| is
789   // the maximum number of frames that will be captured.
790   ///
791   /*--cef()--*/
792   static CefRefPtr<CefV8StackTrace> GetCurrent(int frame_limit);
793
794   ///
795   // Returns true if the underlying handle is valid and it can be accessed on
796   // the current thread. Do not call any other methods if this method returns
797   // false.
798   ///
799   /*--cef()--*/
800   virtual bool IsValid() =0;
801
802   ///
803   // Returns the number of stack frames.
804   ///
805   /*--cef()--*/
806   virtual int GetFrameCount() =0;
807
808   ///
809   // Returns the stack frame at the specified 0-based index.
810   ///
811   /*--cef()--*/
812   virtual CefRefPtr<CefV8StackFrame> GetFrame(int index) =0;
813 };
814
815 ///
816 // Class representing a V8 stack frame handle. V8 handles can only be accessed
817 // from the thread on which they are created. Valid threads for creating a V8
818 // handle include the render process main thread (TID_RENDERER) and WebWorker
819 // threads. A task runner for posting tasks on the associated thread can be
820 // retrieved via the CefV8Context::GetTaskRunner() method.
821 ///
822 /*--cef(source=library)--*/
823 class CefV8StackFrame : public virtual CefBase {
824  public:
825   ///
826   // Returns true if the underlying handle is valid and it can be accessed on
827   // the current thread. Do not call any other methods if this method returns
828   // false.
829   ///
830   /*--cef()--*/
831   virtual bool IsValid() =0;
832
833   ///
834   // Returns the name of the resource script that contains the function.
835   ///
836   /*--cef()--*/
837   virtual CefString GetScriptName() =0;
838
839   ///
840   // Returns the name of the resource script that contains the function or the
841   // sourceURL value if the script name is undefined and its source ends with
842   // a "//@ sourceURL=..." string.
843   ///
844   /*--cef()--*/
845   virtual CefString GetScriptNameOrSourceURL() =0;
846
847   ///
848   // Returns the name of the function.
849   ///
850   /*--cef()--*/
851   virtual CefString GetFunctionName() =0;
852
853   ///
854   // Returns the 1-based line number for the function call or 0 if unknown.
855   ///
856   /*--cef()--*/
857   virtual int GetLineNumber() =0;
858
859   ///
860   // Returns the 1-based column offset on the line for the function call or 0 if
861   // unknown.
862   ///
863   /*--cef()--*/
864   virtual int GetColumn() =0;
865
866   ///
867   // Returns true if the function was compiled using eval().
868   ///
869   /*--cef()--*/
870   virtual bool IsEval() =0;
871
872   ///
873   // Returns true if the function was called as a constructor via "new".
874   ///
875   /*--cef()--*/
876   virtual bool IsConstructor() =0;
877 };
878
879 #endif  // CEF_INCLUDE_CEF_V8_H_