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" | 9 #include "content/common/content_export.h" |
10 #include "content/renderer/pepper/v8_var_converter.h" | 10 #include "content/renderer/pepper/v8_var_converter.h" |
11 #include "ppapi/c/pp_var.h" | 11 #include "ppapi/c/pp_var.h" |
12 #include "ppapi/shared_impl/scoped_pp_var.h" | 12 #include "ppapi/shared_impl/scoped_pp_var.h" |
13 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 class PepperPluginInstanceImpl; | 17 class PepperPluginInstanceImpl; |
18 | 18 |
19 // Base class for scripting TryCatch helpers. | 19 // Base class for scripting TryCatch helpers. |
20 class CONTENT_EXPORT PepperTryCatch { | 20 class CONTENT_EXPORT PepperTryCatch { |
21 public: | 21 public: |
22 PepperTryCatch(PepperPluginInstanceImpl* instance, | 22 PepperTryCatch(PepperPluginInstanceImpl* instance, |
23 V8VarConverter::AllowObjectVars convert_objects); | 23 V8VarConverter::AllowObjectVars convert_objects); |
24 virtual ~PepperTryCatch(); | 24 virtual ~PepperTryCatch(); |
25 | 25 |
26 virtual void SetException(const char* message) = 0; | 26 virtual void SetException(const char* message) = 0; |
27 virtual bool HasException() = 0; | 27 virtual bool HasException() = 0; |
28 // Gets the plugin context. Virtual so it can be overriden for testing. | 28 // Gets the context to execute scripts in. |
29 virtual v8::Handle<v8::Context> GetContext(); | 29 virtual v8::Handle<v8::Context> GetContext() = 0; |
30 | 30 |
31 // Convenience functions for doing conversions to/from V8 values and sets an | 31 // Convenience functions for doing conversions to/from V8 values and sets an |
32 // exception if there is an error in the conversion. | 32 // exception if there is an error in the conversion. |
33 v8::Handle<v8::Value> ToV8(PP_Var var); | 33 v8::Handle<v8::Value> ToV8(PP_Var var); |
34 ppapi::ScopedPPVar FromV8(v8::Handle<v8::Value> v8_value); | 34 ppapi::ScopedPPVar FromV8(v8::Handle<v8::Value> v8_value); |
35 | 35 |
36 protected: | 36 protected: |
37 PepperPluginInstanceImpl* instance_; | 37 PepperPluginInstanceImpl* instance_; |
38 | 38 |
39 // Whether To/FromV8 should convert object vars. If set to | 39 // Whether To/FromV8 should convert object vars. If set to |
(...skipping 10 matching lines...) Expand all Loading... |
50 v8::Isolate* isolate); | 50 v8::Isolate* isolate); |
51 virtual ~PepperTryCatchV8(); | 51 virtual ~PepperTryCatchV8(); |
52 | 52 |
53 bool ThrowException(); | 53 bool ThrowException(); |
54 void ThrowException(const char* message); | 54 void ThrowException(const char* message); |
55 PP_Var* exception() { return &exception_; } | 55 PP_Var* exception() { return &exception_; } |
56 | 56 |
57 // PepperTryCatch | 57 // PepperTryCatch |
58 virtual void SetException(const char* message) OVERRIDE; | 58 virtual void SetException(const char* message) OVERRIDE; |
59 virtual bool HasException() OVERRIDE; | 59 virtual bool HasException() OVERRIDE; |
| 60 virtual v8::Handle<v8::Context> GetContext() OVERRIDE; |
60 | 61 |
61 private: | 62 private: |
62 PP_Var exception_; | 63 PP_Var exception_; |
63 | 64 |
64 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchV8); | 65 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchV8); |
65 }; | 66 }; |
66 | 67 |
67 // Catches v8 exceptions and emits a var exception. | 68 // Catches v8 exceptions and emits a var exception. |
68 class PepperTryCatchVar : public PepperTryCatch { | 69 class PepperTryCatchVar : public PepperTryCatch { |
69 public: | 70 public: |
70 // The PP_Var exception will be placed in |exception|. The user of this class | 71 // The PP_Var exception will be placed in |exception|. The user of this class |
71 // is responsible for managing the lifetime of the exception. It is valid to | 72 // is responsible for managing the lifetime of the exception. It is valid to |
72 // pass NULL for |exception| in which case no exception will be set. | 73 // pass NULL for |exception| in which case no exception will be set. |
73 PepperTryCatchVar(PepperPluginInstanceImpl* instance, | 74 PepperTryCatchVar(PepperPluginInstanceImpl* instance, |
74 PP_Var* exception); | 75 PP_Var* exception); |
75 virtual ~PepperTryCatchVar(); | 76 virtual ~PepperTryCatchVar(); |
76 | 77 |
77 // PepperTryCatch | 78 // PepperTryCatch |
78 virtual void SetException(const char* message) OVERRIDE; | 79 virtual void SetException(const char* message) OVERRIDE; |
79 virtual bool HasException() OVERRIDE; | 80 virtual bool HasException() OVERRIDE; |
| 81 virtual v8::Handle<v8::Context> GetContext() OVERRIDE; |
80 | 82 |
81 private: | 83 private: |
82 // Code which uses PepperTryCatchVar doesn't typically have a HandleScope, | 84 // Code which uses PepperTryCatchVar doesn't typically have a HandleScope, |
83 // make one for them. Note that this class is always allocated on the stack. | 85 // make one for them. Note that this class is always allocated on the stack. |
84 v8::HandleScope handle_scope_; | 86 v8::HandleScope handle_scope_; |
85 | 87 |
86 v8::Handle<v8::Context> context_; | 88 v8::Handle<v8::Context> context_; |
87 | 89 |
88 v8::TryCatch try_catch_; | 90 v8::TryCatch try_catch_; |
89 | 91 |
90 PP_Var* exception_; | 92 PP_Var* exception_; |
91 bool exception_is_set_; | 93 bool exception_is_set_; |
92 | 94 |
93 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchVar); | 95 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchVar); |
94 }; | 96 }; |
95 | 97 |
96 } // namespace content | 98 } // namespace content |
97 | 99 |
98 #endif // CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ | 100 #endif // CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ |
OLD | NEW |