]> git.sesse.net Git - casparcg/blob - dependencies64/cef/windows/include/cef_v8.h
2ec4feb8e502e5c9915b4febb8ca0d58db6f190b
[casparcg] / dependencies64 / cef / windows / 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 CefBaseRefCounted {
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   // Execute a string of JavaScript code in this V8 context. The |script_url|
210   // parameter is the URL where the script in question can be found, if any.
211   // The |start_line| parameter is the base line number to use for error
212   // reporting. On success |retval| will be set to the return value, if any, and
213   // the function will return true. On failure |exception| will be set to the
214   // exception, if any, and the function will return false.
215   ///
216   /*--cef(optional_param=script_url)--*/
217   virtual bool Eval(const CefString& code,
218                     const CefString& script_url,
219                     int start_line,
220                     CefRefPtr<CefV8Value>& retval,
221                     CefRefPtr<CefV8Exception>& exception) =0;
222 };
223
224
225 typedef std::vector<CefRefPtr<CefV8Value> > CefV8ValueList;
226
227 ///
228 // Interface that should be implemented to handle V8 function calls. The methods
229 // of this class will be called on the thread associated with the V8 function.
230 ///
231 /*--cef(source=client)--*/
232 class CefV8Handler : public virtual CefBaseRefCounted {
233  public:
234   ///
235   // Handle execution of the function identified by |name|. |object| is the
236   // receiver ('this' object) of the function. |arguments| is the list of
237   // arguments passed to the function. If execution succeeds set |retval| to the
238   // function return value. If execution fails set |exception| to the exception
239   // that will be thrown. Return true if execution was handled.
240   ///
241   /*--cef()--*/
242   virtual bool Execute(const CefString& name,
243                        CefRefPtr<CefV8Value> object,
244                        const CefV8ValueList& arguments,
245                        CefRefPtr<CefV8Value>& retval,
246                        CefString& exception) =0;
247 };
248
249 ///
250 // Interface that should be implemented to handle V8 accessor calls. Accessor
251 // identifiers are registered by calling CefV8Value::SetValue(). The methods
252 // of this class will be called on the thread associated with the V8 accessor.
253 ///
254 /*--cef(source=client)--*/
255 class CefV8Accessor : public virtual CefBaseRefCounted {
256  public:
257   ///
258   // Handle retrieval the accessor value identified by |name|. |object| is the
259   // receiver ('this' object) of the accessor. If retrieval succeeds set
260   // |retval| to the return value. If retrieval fails set |exception| to the
261   // exception that will be thrown. Return true if accessor retrieval was
262   // handled.
263   ///
264   /*--cef()--*/
265   virtual bool Get(const CefString& name,
266                    const CefRefPtr<CefV8Value> object,
267                    CefRefPtr<CefV8Value>& retval,
268                    CefString& exception) =0;
269
270   ///
271   // Handle assignment of the accessor value identified by |name|. |object| is
272   // the receiver ('this' object) of the accessor. |value| is the new value
273   // being assigned to the accessor. If assignment fails set |exception| to the
274   // exception that will be thrown. Return true if accessor assignment was
275   // handled.
276   ///
277   /*--cef()--*/
278   virtual bool Set(const CefString& name,
279                    const CefRefPtr<CefV8Value> object,
280                    const CefRefPtr<CefV8Value> value,
281                    CefString& exception) =0;
282 };
283
284 ///
285 // Interface that should be implemented to handle V8 interceptor calls. The
286 // methods of this class will be called on the thread associated with the V8
287 // interceptor. Interceptor's named property handlers (with first argument of
288 // type CefString) are called when object is indexed by string. Indexed property
289 // handlers (with first argument of type int) are called when object is indexed
290 // by integer.
291 ///
292 /*--cef(source=client)--*/
293 class CefV8Interceptor : public virtual CefBaseRefCounted {
294 public:
295   ///
296   // Handle retrieval of the interceptor value identified by |name|. |object| is
297   // the receiver ('this' object) of the interceptor. If retrieval succeeds, set
298   // |retval| to the return value. If the requested value does not exist, don't
299   // set either |retval| or |exception|. If retrieval fails, set |exception| to
300   // the exception that will be thrown. If the property has an associated
301   // accessor, it will be called only if you don't set |retval|.
302   // Return true if interceptor retrieval was handled, false otherwise.
303   ///
304   /*--cef(capi_name=get_byname)--*/
305   virtual bool Get(const CefString& name,
306                    const CefRefPtr<CefV8Value> object,
307                    CefRefPtr<CefV8Value>& retval,
308                    CefString& exception) =0;
309
310   ///
311   // Handle retrieval of the interceptor value identified by |index|. |object|
312   // is the receiver ('this' object) of the interceptor. If retrieval succeeds,
313   // set |retval| to the return value. If the requested value does not exist,
314   // don't set either |retval| or |exception|. If retrieval fails, set
315   // |exception| to the exception that will be thrown.
316   // Return true if interceptor retrieval was handled, false otherwise.
317   ///
318   /*--cef(capi_name=get_byindex,index_param=index)--*/
319   virtual bool Get(int index,
320                    const CefRefPtr<CefV8Value> object,
321                    CefRefPtr<CefV8Value>& retval,
322                    CefString& exception) =0;
323
324   ///
325   // Handle assignment of the interceptor value identified by |name|. |object|
326   // is the receiver ('this' object) of the interceptor. |value| is the new
327   // value being assigned to the interceptor. If assignment fails, set
328   // |exception| to the exception that will be thrown. This setter will always
329   // be called, even when the property has an associated accessor.
330   // Return true if interceptor assignment was handled, false otherwise.
331   ///
332   /*--cef(capi_name=set_byname)--*/
333   virtual bool Set(const CefString& name,
334                    const CefRefPtr<CefV8Value> object,
335                    const CefRefPtr<CefV8Value> value,
336                    CefString& exception) =0;
337
338   ///
339   // Handle assignment of the interceptor value identified by |index|. |object|
340   // is the receiver ('this' object) of the interceptor. |value| is the new
341   // value being assigned to the interceptor. If assignment fails, set
342   // |exception| to the exception that will be thrown.
343   // Return true if interceptor assignment was handled, false otherwise.
344   ///
345   /*--cef(capi_name=set_byindex,index_param=index)--*/
346   virtual bool Set(int index,
347                    const CefRefPtr<CefV8Value> object,
348                    const CefRefPtr<CefV8Value> value,
349                    CefString& exception) =0;
350 };
351
352 ///
353 // Class representing a V8 exception. The methods of this class may be called on
354 // any render process thread.
355 ///
356 /*--cef(source=library)--*/
357 class CefV8Exception : public virtual CefBaseRefCounted {
358  public:
359   ///
360   // Returns the exception message.
361   ///
362   /*--cef()--*/
363   virtual CefString GetMessage() =0;
364
365   ///
366   // Returns the line of source code that the exception occurred within.
367   ///
368   /*--cef()--*/
369   virtual CefString GetSourceLine() =0;
370
371   ///
372   // Returns the resource name for the script from where the function causing
373   // the error originates.
374   ///
375   /*--cef()--*/
376   virtual CefString GetScriptResourceName() =0;
377
378   ///
379   // Returns the 1-based number of the line where the error occurred or 0 if the
380   // line number is unknown.
381   ///
382   /*--cef()--*/
383   virtual int GetLineNumber() =0;
384
385   ///
386   // Returns the index within the script of the first character where the error
387   // occurred.
388   ///
389   /*--cef()--*/
390   virtual int GetStartPosition() =0;
391
392   ///
393   // Returns the index within the script of the last character where the error
394   // occurred.
395   ///
396   /*--cef()--*/
397   virtual int GetEndPosition() =0;
398
399   ///
400   // Returns the index within the line of the first character where the error
401   // occurred.
402   ///
403   /*--cef()--*/
404   virtual int GetStartColumn() =0;
405
406   ///
407   // Returns the index within the line of the last character where the error
408   // occurred.
409   ///
410   /*--cef()--*/
411   virtual int GetEndColumn() =0;
412 };
413
414 ///
415 // Class representing a V8 value handle. V8 handles can only be accessed from
416 // the thread on which they are created. Valid threads for creating a V8 handle
417 // include the render process main thread (TID_RENDERER) and WebWorker threads.
418 // A task runner for posting tasks on the associated thread can be retrieved via
419 // the CefV8Context::GetTaskRunner() method.
420 ///
421 /*--cef(source=library)--*/
422 class CefV8Value : public virtual CefBaseRefCounted {
423  public:
424   typedef cef_v8_accesscontrol_t AccessControl;
425   typedef cef_v8_propertyattribute_t PropertyAttribute;
426
427   ///
428   // Create a new CefV8Value object of type undefined.
429   ///
430   /*--cef()--*/
431   static CefRefPtr<CefV8Value> CreateUndefined();
432
433   ///
434   // Create a new CefV8Value object of type null.
435   ///
436   /*--cef()--*/
437   static CefRefPtr<CefV8Value> CreateNull();
438
439   ///
440   // Create a new CefV8Value object of type bool.
441   ///
442   /*--cef()--*/
443   static CefRefPtr<CefV8Value> CreateBool(bool value);
444
445   ///
446   // Create a new CefV8Value object of type int.
447   ///
448   /*--cef()--*/
449   static CefRefPtr<CefV8Value> CreateInt(int32 value);
450
451   ///
452   // Create a new CefV8Value object of type unsigned int.
453   ///
454   /*--cef()--*/
455   static CefRefPtr<CefV8Value> CreateUInt(uint32 value);
456
457   ///
458   // Create a new CefV8Value object of type double.
459   ///
460   /*--cef()--*/
461   static CefRefPtr<CefV8Value> CreateDouble(double value);
462
463   ///
464   // Create a new CefV8Value object of type Date. This method should only be
465   // called from within the scope of a CefRenderProcessHandler, CefV8Handler or
466   // CefV8Accessor callback, or in combination with calling Enter() and Exit()
467   // on a stored CefV8Context reference.
468   ///
469   /*--cef()--*/
470   static CefRefPtr<CefV8Value> CreateDate(const CefTime& date);
471
472   ///
473   // Create a new CefV8Value object of type string.
474   ///
475   /*--cef(optional_param=value)--*/
476   static CefRefPtr<CefV8Value> CreateString(const CefString& value);
477
478   ///
479   // Create a new CefV8Value object of type object with optional accessor and/or
480   // interceptor. This method should only be called from within the scope of a
481   // CefRenderProcessHandler, CefV8Handler or CefV8Accessor callback, or in
482   // combination with calling Enter() and Exit() on a stored CefV8Context
483   // reference.
484   ///
485   /*--cef(optional_param=accessor, optional_param=interceptor)--*/
486   static CefRefPtr<CefV8Value> CreateObject(
487       CefRefPtr<CefV8Accessor> accessor,
488       CefRefPtr<CefV8Interceptor> interceptor);
489
490   ///
491   // Create a new CefV8Value object of type array with the specified |length|.
492   // If |length| is negative the returned array will have length 0. This method
493   // should only be called from within the scope of a CefRenderProcessHandler,
494   // CefV8Handler or CefV8Accessor callback, or in combination with calling
495   // Enter() and Exit() on a stored CefV8Context reference.
496   ///
497   /*--cef()--*/
498   static CefRefPtr<CefV8Value> CreateArray(int length);
499
500   ///
501   // Create a new CefV8Value object of type function. This method should only be
502   // called from within the scope of a CefRenderProcessHandler, CefV8Handler or
503   // CefV8Accessor callback, or in combination with calling Enter() and Exit()
504   // on a stored CefV8Context reference.
505   ///
506   /*--cef()--*/
507   static CefRefPtr<CefV8Value> CreateFunction(const CefString& name,
508                                               CefRefPtr<CefV8Handler> handler);
509
510   ///
511   // Returns true if the underlying handle is valid and it can be accessed on
512   // the current thread. Do not call any other methods if this method returns
513   // false.
514   ///
515   /*--cef()--*/
516   virtual bool IsValid() =0;
517
518   ///
519   // True if the value type is undefined.
520   ///
521   /*--cef()--*/
522   virtual bool IsUndefined() =0;
523
524   ///
525   // True if the value type is null.
526   ///
527   /*--cef()--*/
528   virtual bool IsNull() =0;
529
530   ///
531   // True if the value type is bool.
532   ///
533   /*--cef()--*/
534   virtual bool IsBool() =0;
535
536   ///
537   // True if the value type is int.
538   ///
539   /*--cef()--*/
540   virtual bool IsInt() =0;
541
542   ///
543   // True if the value type is unsigned int.
544   ///
545   /*--cef()--*/
546   virtual bool IsUInt() =0;
547
548   ///
549   // True if the value type is double.
550   ///
551   /*--cef()--*/
552   virtual bool IsDouble() =0;
553
554   ///
555   // True if the value type is Date.
556   ///
557   /*--cef()--*/
558   virtual bool IsDate() =0;
559
560   ///
561   // True if the value type is string.
562   ///
563   /*--cef()--*/
564   virtual bool IsString() =0;
565
566   ///
567   // True if the value type is object.
568   ///
569   /*--cef()--*/
570   virtual bool IsObject() =0;
571
572   ///
573   // True if the value type is array.
574   ///
575   /*--cef()--*/
576   virtual bool IsArray() =0;
577
578   ///
579   // True if the value type is function.
580   ///
581   /*--cef()--*/
582   virtual bool IsFunction() =0;
583
584   ///
585   // Returns true if this object is pointing to the same handle as |that|
586   // object.
587   ///
588   /*--cef()--*/
589   virtual bool IsSame(CefRefPtr<CefV8Value> that) =0;
590
591   ///
592   // Return a bool value.
593   ///
594   /*--cef()--*/
595   virtual bool GetBoolValue() =0;
596
597   ///
598   // Return an int value.
599   ///
600   /*--cef()--*/
601   virtual int32 GetIntValue() =0;
602
603   ///
604   // Return an unsigned int value.
605   ///
606   /*--cef()--*/
607   virtual uint32 GetUIntValue() =0;
608
609   ///
610   // Return a double value.
611   ///
612   /*--cef()--*/
613   virtual double GetDoubleValue() =0;
614
615   ///
616   // Return a Date value.
617   ///
618   /*--cef()--*/
619   virtual CefTime GetDateValue() =0;
620
621   ///
622   // Return a string value.
623   ///
624   /*--cef()--*/
625   virtual CefString GetStringValue() =0;
626
627
628   // OBJECT METHODS - These methods are only available on objects. Arrays and
629   // functions are also objects. String- and integer-based keys can be used
630   // interchangably with the framework converting between them as necessary.
631
632   ///
633   // Returns true if this is a user created object.
634   ///
635   /*--cef()--*/
636   virtual bool IsUserCreated() =0;
637
638   ///
639   // Returns true if the last method call resulted in an exception. This
640   // attribute exists only in the scope of the current CEF value object.
641   ///
642   /*--cef()--*/
643   virtual bool HasException() =0;
644
645   ///
646   // Returns the exception resulting from the last method call. This attribute
647   // exists only in the scope of the current CEF value object.
648   ///
649   /*--cef()--*/
650   virtual CefRefPtr<CefV8Exception> GetException() =0;
651
652   ///
653   // Clears the last exception and returns true on success.
654   ///
655   /*--cef()--*/
656   virtual bool ClearException() =0;
657
658   ///
659   // Returns true if this object will re-throw future exceptions. This attribute
660   // exists only in the scope of the current CEF value object.
661   ///
662   /*--cef()--*/
663   virtual bool WillRethrowExceptions() =0;
664
665   ///
666   // Set whether this object will re-throw future exceptions. By default
667   // exceptions are not re-thrown. If a exception is re-thrown the current
668   // context should not be accessed again until after the exception has been
669   // caught and not re-thrown. Returns true on success. This attribute exists
670   // only in the scope of the current CEF value object.
671   ///
672   /*--cef()--*/
673   virtual bool SetRethrowExceptions(bool rethrow) =0;
674
675   ///
676   // Returns true if the object has a value with the specified identifier.
677   ///
678   /*--cef(capi_name=has_value_bykey,optional_param=key)--*/
679   virtual bool HasValue(const CefString& key) =0;
680
681   ///
682   // Returns true if the object has a value with the specified identifier.
683   ///
684   /*--cef(capi_name=has_value_byindex,index_param=index)--*/
685   virtual bool HasValue(int index) =0;
686
687   ///
688   // Deletes the value with the specified identifier and returns true on
689   // success. Returns false if this method is called incorrectly or an exception
690   // is thrown. For read-only and don't-delete values this method will return
691   // true even though deletion failed.
692   ///
693   /*--cef(capi_name=delete_value_bykey,optional_param=key)--*/
694   virtual bool DeleteValue(const CefString& key) =0;
695
696   ///
697   // Deletes the value with the specified identifier and returns true on
698   // success. Returns false if this method is called incorrectly, deletion fails
699   // or an exception is thrown. For read-only and don't-delete values this
700   // method will return true even though deletion failed.
701   ///
702   /*--cef(capi_name=delete_value_byindex,index_param=index)--*/
703   virtual bool DeleteValue(int index) =0;
704
705   ///
706   // Returns the value with the specified identifier on success. Returns NULL
707   // if this method is called incorrectly or an exception is thrown.
708   ///
709   /*--cef(capi_name=get_value_bykey,optional_param=key)--*/
710   virtual CefRefPtr<CefV8Value> GetValue(const CefString& key) =0;
711
712   ///
713   // Returns the value with the specified identifier on success. Returns NULL
714   // if this method is called incorrectly or an exception is thrown.
715   ///
716   /*--cef(capi_name=get_value_byindex,index_param=index)--*/
717   virtual CefRefPtr<CefV8Value> GetValue(int index) =0;
718
719   ///
720   // Associates a value with the specified identifier and returns true on
721   // success. Returns false if this method is called incorrectly or an exception
722   // is thrown. For read-only values this method will return true even though
723   // assignment failed.
724   ///
725   /*--cef(capi_name=set_value_bykey,optional_param=key)--*/
726   virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value,
727                         PropertyAttribute attribute) =0;
728
729   ///
730   // Associates a value with the specified identifier and returns true on
731   // success. Returns false if this method is called incorrectly or an exception
732   // is thrown. For read-only values this method will return true even though
733   // assignment failed.
734   ///
735   /*--cef(capi_name=set_value_byindex,index_param=index)--*/
736   virtual bool SetValue(int index, CefRefPtr<CefV8Value> value) =0;
737
738   ///
739   // Registers an identifier and returns true on success. Access to the
740   // identifier will be forwarded to the CefV8Accessor instance passed to
741   // CefV8Value::CreateObject(). Returns false if this method is called
742   // incorrectly or an exception is thrown. For read-only values this method
743   // will return true even though assignment failed.
744   ///
745   /*--cef(capi_name=set_value_byaccessor,optional_param=key)--*/
746   virtual bool SetValue(const CefString& key, AccessControl settings,
747                         PropertyAttribute attribute) =0;
748
749   ///
750   // Read the keys for the object's values into the specified vector. Integer-
751   // based keys will also be returned as strings.
752   ///
753   /*--cef()--*/
754   virtual bool GetKeys(std::vector<CefString>& keys) =0;
755
756   ///
757   // Sets the user data for this object and returns true on success. Returns
758   // false if this method is called incorrectly. This method can only be called
759   // on user created objects.
760   ///
761   /*--cef(optional_param=user_data)--*/
762   virtual bool SetUserData(CefRefPtr<CefBaseRefCounted> user_data) =0;
763
764   ///
765   // Returns the user data, if any, assigned to this object.
766   ///
767   /*--cef()--*/
768   virtual CefRefPtr<CefBaseRefCounted> GetUserData() =0;
769
770   ///
771   // Returns the amount of externally allocated memory registered for the
772   // object.
773   ///
774   /*--cef()--*/
775   virtual int GetExternallyAllocatedMemory() =0;
776
777   ///
778   // Adjusts the amount of registered external memory for the object. Used to
779   // give V8 an indication of the amount of externally allocated memory that is
780   // kept alive by JavaScript objects. V8 uses this information to decide when
781   // to perform global garbage collection. Each CefV8Value tracks the amount of
782   // external memory associated with it and automatically decreases the global
783   // total by the appropriate amount on its destruction. |change_in_bytes|
784   // specifies the number of bytes to adjust by. This method returns the number
785   // of bytes associated with the object after the adjustment. This method can
786   // only be called on user created objects.
787   ///
788   /*--cef()--*/
789   virtual int AdjustExternallyAllocatedMemory(int change_in_bytes) =0;
790
791
792   // ARRAY METHODS - These methods are only available on arrays.
793
794   ///
795   // Returns the number of elements in the array.
796   ///
797   /*--cef()--*/
798   virtual int GetArrayLength() =0;
799
800
801   // FUNCTION METHODS - These methods are only available on functions.
802
803   ///
804   // Returns the function name.
805   ///
806   /*--cef()--*/
807   virtual CefString GetFunctionName() =0;
808
809   ///
810   // Returns the function handler or NULL if not a CEF-created function.
811   ///
812   /*--cef()--*/
813   virtual CefRefPtr<CefV8Handler> GetFunctionHandler() =0;
814
815   ///
816   // Execute the function using the current V8 context. This method should only
817   // be called from within the scope of a CefV8Handler or CefV8Accessor
818   // callback, or in combination with calling Enter() and Exit() on a stored
819   // CefV8Context reference. |object| is the receiver ('this' object) of the
820   // function. If |object| is empty the current context's global object will be
821   // used. |arguments| is the list of arguments that will be passed to the
822   // function. Returns the function return value on success. Returns NULL if
823   // this method is called incorrectly or an exception is thrown.
824   ///
825   /*--cef(optional_param=object)--*/
826   virtual CefRefPtr<CefV8Value> ExecuteFunction(
827       CefRefPtr<CefV8Value> object,
828       const CefV8ValueList& arguments) =0;
829
830   ///
831   // Execute the function using the specified V8 context. |object| is the
832   // receiver ('this' object) of the function. If |object| is empty the
833   // specified context's global object will be used. |arguments| is the list of
834   // arguments that will be passed to the function. Returns the function return
835   // value on success. Returns NULL if this method is called incorrectly or an
836   // exception is thrown.
837   ///
838   /*--cef(optional_param=object)--*/
839   virtual CefRefPtr<CefV8Value> ExecuteFunctionWithContext(
840       CefRefPtr<CefV8Context> context,
841       CefRefPtr<CefV8Value> object,
842       const CefV8ValueList& arguments) =0;
843 };
844
845 ///
846 // Class representing a V8 stack trace handle. V8 handles can only be accessed
847 // from the thread on which they are created. Valid threads for creating a V8
848 // handle include the render process main thread (TID_RENDERER) and WebWorker
849 // threads. A task runner for posting tasks on the associated thread can be
850 // retrieved via the CefV8Context::GetTaskRunner() method.
851 ///
852 /*--cef(source=library)--*/
853 class CefV8StackTrace : public virtual CefBaseRefCounted {
854  public:
855   ///
856   // Returns the stack trace for the currently active context. |frame_limit| is
857   // the maximum number of frames that will be captured.
858   ///
859   /*--cef()--*/
860   static CefRefPtr<CefV8StackTrace> GetCurrent(int frame_limit);
861
862   ///
863   // Returns true if the underlying handle is valid and it can be accessed on
864   // the current thread. Do not call any other methods if this method returns
865   // false.
866   ///
867   /*--cef()--*/
868   virtual bool IsValid() =0;
869
870   ///
871   // Returns the number of stack frames.
872   ///
873   /*--cef()--*/
874   virtual int GetFrameCount() =0;
875
876   ///
877   // Returns the stack frame at the specified 0-based index.
878   ///
879   /*--cef()--*/
880   virtual CefRefPtr<CefV8StackFrame> GetFrame(int index) =0;
881 };
882
883 ///
884 // Class representing a V8 stack frame handle. V8 handles can only be accessed
885 // from the thread on which they are created. Valid threads for creating a V8
886 // handle include the render process main thread (TID_RENDERER) and WebWorker
887 // threads. A task runner for posting tasks on the associated thread can be
888 // retrieved via the CefV8Context::GetTaskRunner() method.
889 ///
890 /*--cef(source=library)--*/
891 class CefV8StackFrame : public virtual CefBaseRefCounted {
892  public:
893   ///
894   // Returns true if the underlying handle is valid and it can be accessed on
895   // the current thread. Do not call any other methods if this method returns
896   // false.
897   ///
898   /*--cef()--*/
899   virtual bool IsValid() =0;
900
901   ///
902   // Returns the name of the resource script that contains the function.
903   ///
904   /*--cef()--*/
905   virtual CefString GetScriptName() =0;
906
907   ///
908   // Returns the name of the resource script that contains the function or the
909   // sourceURL value if the script name is undefined and its source ends with
910   // a "//@ sourceURL=..." string.
911   ///
912   /*--cef()--*/
913   virtual CefString GetScriptNameOrSourceURL() =0;
914
915   ///
916   // Returns the name of the function.
917   ///
918   /*--cef()--*/
919   virtual CefString GetFunctionName() =0;
920
921   ///
922   // Returns the 1-based line number for the function call or 0 if unknown.
923   ///
924   /*--cef()--*/
925   virtual int GetLineNumber() =0;
926
927   ///
928   // Returns the 1-based column offset on the line for the function call or 0 if
929   // unknown.
930   ///
931   /*--cef()--*/
932   virtual int GetColumn() =0;
933
934   ///
935   // Returns true if the function was compiled using eval().
936   ///
937   /*--cef()--*/
938   virtual bool IsEval() =0;
939
940   ///
941   // Returns true if the function was called as a constructor via "new".
942   ///
943   /*--cef()--*/
944   virtual bool IsConstructor() =0;
945 };
946
947 #endif  // CEF_INCLUDE_CEF_V8_H_