OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ |
6 #define CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ | 6 #define CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "content/common/content_export.h" | |
10 #include "content/renderer/pepper/v8_var_converter.h" | |
9 #include "ppapi/c/pp_var.h" | 11 #include "ppapi/c/pp_var.h" |
10 #include "ppapi/shared_impl/scoped_pp_var.h" | 12 #include "ppapi/shared_impl/scoped_pp_var.h" |
11 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
12 | 14 |
13 namespace content { | 15 namespace content { |
14 | 16 |
15 class PepperPluginInstanceImpl; | 17 class PepperPluginInstanceImpl; |
16 | 18 |
17 // Base class for scripting TryCatch helpers. | 19 // Base class for scripting TryCatch helpers. |
18 class PepperTryCatch { | 20 class CONTENT_EXPORT PepperTryCatch { |
19 public: | 21 public: |
20 PepperTryCatch(PepperPluginInstanceImpl* instance, | 22 PepperTryCatch(PepperPluginInstanceImpl* instance, |
21 bool convert_objects); | 23 V8VarConverter::AllowObjectVars convert_objects); |
22 virtual ~PepperTryCatch(); | 24 virtual ~PepperTryCatch(); |
23 | 25 |
24 virtual void SetException(const char* message) = 0; | 26 virtual void SetException(const char* message) = 0; |
25 // Gets the plugin context. Virtual so it can be overriden for testing. | 27 // Gets the plugin context. Virtual so it can be overriden for testing. |
26 virtual v8::Handle<v8::Context> GetContext(); | 28 virtual v8::Handle<v8::Context> GetContext(); |
27 | 29 |
28 // Convenience functions for doing conversions to/from V8 values and sets an | 30 // Convenience functions for doing conversions to/from V8 values and sets an |
29 // exception if there is an error in the conversion. | 31 // exception if there is an error in the conversion. |
30 v8::Handle<v8::Value> ToV8(PP_Var var); | 32 v8::Handle<v8::Value> ToV8(PP_Var var); |
31 ppapi::ScopedPPVar FromV8(v8::Handle<v8::Value> v8_value); | 33 ppapi::ScopedPPVar FromV8(v8::Handle<v8::Value> v8_value); |
32 | 34 |
33 protected: | 35 protected: |
34 PepperPluginInstanceImpl* instance_; | 36 PepperPluginInstanceImpl* instance_; |
35 | 37 |
36 // Whether To/FromV8 should convert object vars. If set to false, an exception | 38 // Whether To/FromV8 should convert object vars. If set to false, an exception |
dmichael (off chromium)
2014/08/22 16:28:47
nit: comment is out of date
raymes
2014/08/25 01:40:01
Done.
| |
37 // should be set if they are encountered during conversion. | 39 // should be set if they are encountered during conversion. |
38 bool convert_objects_; | 40 V8VarConverter::AllowObjectVars convert_objects_; |
39 }; | 41 }; |
40 | 42 |
41 // Catches var exceptions and emits a v8 exception. | 43 // Catches var exceptions and emits a v8 exception. |
42 class PepperTryCatchV8 : public PepperTryCatch { | 44 class PepperTryCatchV8 : public PepperTryCatch { |
43 public: | 45 public: |
44 PepperTryCatchV8(PepperPluginInstanceImpl* instance, | 46 PepperTryCatchV8(PepperPluginInstanceImpl* instance, |
45 bool convert_objects, | 47 V8VarConverter::AllowObjectVars convert_objects, |
46 v8::Isolate* isolate); | 48 v8::Isolate* isolate); |
47 virtual ~PepperTryCatchV8(); | 49 virtual ~PepperTryCatchV8(); |
48 | 50 |
49 bool HasException(); | 51 bool HasException(); |
50 bool ThrowException(); | 52 bool ThrowException(); |
51 void ThrowException(const char* message); | 53 void ThrowException(const char* message); |
52 PP_Var* exception() { return &exception_; } | 54 PP_Var* exception() { return &exception_; } |
53 | 55 |
54 // PepperTryCatch | 56 // PepperTryCatch |
55 virtual void SetException(const char* message) OVERRIDE; | 57 virtual void SetException(const char* message) OVERRIDE; |
56 | 58 |
57 private: | 59 private: |
58 PP_Var exception_; | 60 PP_Var exception_; |
59 | 61 |
60 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchV8); | 62 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchV8); |
61 }; | 63 }; |
62 | 64 |
63 // Catches v8 exceptions and emits a var exception. | 65 // Catches v8 exceptions and emits a var exception. |
64 class PepperTryCatchVar : public PepperTryCatch { | 66 class PepperTryCatchVar : public PepperTryCatch { |
65 public: | 67 public: |
66 // The PP_Var exception will be placed in |exception|. The user of this class | 68 // The PP_Var exception will be placed in |exception|. The user of this class |
67 // is responsible for managing the lifetime of the exception. It is valid to | 69 // is responsible for managing the lifetime of the exception. It is valid to |
68 // pass NULL for |exception| in which case no exception will be set. | 70 // pass NULL for |exception| in which case no exception will be set. |
69 PepperTryCatchVar(PepperPluginInstanceImpl* instance, | 71 PepperTryCatchVar(PepperPluginInstanceImpl* instance, |
70 bool convert_objects, | |
71 PP_Var* exception); | 72 PP_Var* exception); |
72 virtual ~PepperTryCatchVar(); | 73 virtual ~PepperTryCatchVar(); |
73 | 74 |
74 bool HasException(); | 75 bool HasException(); |
75 | 76 |
76 // PepperTryCatch | 77 // PepperTryCatch |
77 virtual void SetException(const char* message) OVERRIDE; | 78 virtual void SetException(const char* message) OVERRIDE; |
78 | 79 |
79 private: | 80 private: |
80 // Code which uses PepperTryCatchVar doesn't typically have a HandleScope, | 81 // Code which uses PepperTryCatchVar doesn't typically have a HandleScope, |
81 // make one for them. Note that this class is always allocated on the stack. | 82 // make one for them. Note that this class is always allocated on the stack. |
82 v8::HandleScope handle_scope_; | 83 v8::HandleScope handle_scope_; |
83 | 84 |
84 v8::TryCatch try_catch_; | 85 v8::TryCatch try_catch_; |
85 | 86 |
86 PP_Var* exception_; | 87 PP_Var* exception_; |
87 bool exception_is_set_; | 88 bool exception_is_set_; |
88 | 89 |
89 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchVar); | 90 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchVar); |
90 }; | 91 }; |
91 | 92 |
92 } // namespace content | 93 } // namespace content |
93 | 94 |
94 #endif // CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ | 95 #endif // CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ |
OLD | NEW |