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 objects should only be used as stack variables. This object |
| 23 // takes a reference on the given PepperPluginInstanceImpl. |
22 PepperTryCatch(PepperPluginInstanceImpl* instance, | 24 PepperTryCatch(PepperPluginInstanceImpl* instance, |
23 V8VarConverter::AllowObjectVars convert_objects); | 25 V8VarConverter::AllowObjectVars convert_objects); |
24 virtual ~PepperTryCatch(); | 26 virtual ~PepperTryCatch(); |
25 | 27 |
26 virtual void SetException(const char* message) = 0; | 28 virtual void SetException(const char* message) = 0; |
27 virtual bool HasException() = 0; | 29 virtual bool HasException() = 0; |
28 // Gets the plugin context. Virtual so it can be overriden for testing. | 30 // Gets the plugin context. Virtual so it can be overriden for testing. |
29 virtual v8::Handle<v8::Context> GetContext(); | 31 virtual v8::Handle<v8::Context> GetContext(); |
30 | 32 |
31 // Convenience functions for doing conversions to/from V8 values and sets an | 33 // Convenience functions for doing conversions to/from V8 values and sets an |
32 // exception if there is an error in the conversion. | 34 // exception if there is an error in the conversion. |
33 v8::Handle<v8::Value> ToV8(PP_Var var); | 35 v8::Handle<v8::Value> ToV8(PP_Var var); |
34 ppapi::ScopedPPVar FromV8(v8::Handle<v8::Value> v8_value); | 36 ppapi::ScopedPPVar FromV8(v8::Handle<v8::Value> v8_value); |
35 | 37 |
36 protected: | 38 protected: |
37 PepperPluginInstanceImpl* instance_; | 39 // Make sure that |instance_| is alive for the lifetime of PepperTryCatch. |
| 40 // PepperTryCatch is used mostly in Pepper scripting code, where it can be |
| 41 // possible to enter JavaScript synchronously which can cause the plugin to |
| 42 // be deleted. |
| 43 // |
| 44 // Note that PepperTryCatch objects should only ever be on the stack, so this |
| 45 // shouldn't keep the instance around for too long. |
| 46 scoped_refptr<PepperPluginInstanceImpl> instance_; |
38 | 47 |
39 // Whether To/FromV8 should convert object vars. If set to | 48 // Whether To/FromV8 should convert object vars. If set to |
40 // kDisallowObjectVars, an exception should be set if they are encountered | 49 // kDisallowObjectVars, an exception should be set if they are encountered |
41 // during conversion. | 50 // during conversion. |
42 V8VarConverter::AllowObjectVars convert_objects_; | 51 V8VarConverter::AllowObjectVars convert_objects_; |
43 }; | 52 }; |
44 | 53 |
45 // Catches var exceptions and emits a v8 exception. | 54 // Catches var exceptions and emits a v8 exception. |
46 class PepperTryCatchV8 : public PepperTryCatch { | 55 class PepperTryCatchV8 : public PepperTryCatch { |
47 public: | 56 public: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 98 |
90 PP_Var* exception_; | 99 PP_Var* exception_; |
91 bool exception_is_set_; | 100 bool exception_is_set_; |
92 | 101 |
93 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchVar); | 102 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchVar); |
94 }; | 103 }; |
95 | 104 |
96 } // namespace content | 105 } // namespace content |
97 | 106 |
98 #endif // CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ | 107 #endif // CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ |
OLD | NEW |