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