OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ | |
6 #define CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "ppapi/c/pp_var.h" | |
10 #include "ppapi/shared_impl/scoped_pp_var.h" | |
11 #include "v8/include/v8.h" | |
12 | |
13 namespace content { | |
14 | |
15 class PepperPluginInstanceImpl; | |
16 | |
17 // Base class for scripting TryCatch helpers. | |
18 class PepperTryCatch { | |
19 public: | |
20 PepperTryCatch(PepperPluginInstanceImpl* instance, | |
21 bool convert_objects); | |
22 virtual ~PepperTryCatch(); | |
23 | |
24 virtual void SetException(const char* message) = 0; | |
25 // Gets the plugin context. Virtual so it can be overriden for testing. | |
26 virtual v8::Handle<v8::Context> GetContext(); | |
27 | |
28 // Convenience functions for doing conversions to/from V8 values and sets an | |
29 // exception if there is an error in the conversion. | |
30 v8::Handle<v8::Value> ToV8(PP_Var var); | |
31 ppapi::ScopedPPVar FromV8(v8::Handle<v8::Value> v8_value); | |
32 | |
33 protected: | |
34 PepperPluginInstanceImpl* instance_; | |
35 | |
36 // Whether To/FromV8 should convert object vars. If set to false, an exception | |
37 // should be set if they are encountered during conversion. | |
38 bool convert_objects_; | |
39 }; | |
40 | |
41 // Catches var exceptions and emits a v8 exception. | |
42 class PepperTryCatchV8 : public PepperTryCatch { | |
43 public: | |
44 PepperTryCatchV8(PepperPluginInstanceImpl* instance, | |
45 bool convert_objects, | |
46 v8::Isolate* isolate); | |
47 virtual ~PepperTryCatchV8(); | |
48 | |
49 bool HasException(); | |
50 bool ThrowException(); | |
51 void ThrowException(const char* message); | |
52 PP_Var* exception() { return &exception_; } | |
53 | |
54 // PepperTryCatch | |
55 virtual void SetException(const char* message) OVERRIDE; | |
56 | |
57 private: | |
58 PP_Var exception_; | |
dmichael (off chromium)
2014/07/30 19:34:14
It looks like using scoped_refptr<StringVar> might
raymes
2014/08/06 03:22:52
Done.
raymes
2014/08/06 03:29:56
Actually this won't work. We want to be able to pa
dmichael (off chromium)
2014/08/06 15:41:45
Ah, I see. Thanks for explaining.
| |
59 | |
60 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchV8); | |
61 }; | |
62 | |
63 // Catches v8 exceptions and emits a var exception. | |
64 class PepperTryCatchVar : public PepperTryCatch { | |
65 public: | |
66 // The PP_Var exception will be placed in |exception|. | |
67 PepperTryCatchVar(PepperPluginInstanceImpl* instance, | |
68 bool convert_objects, | |
69 PP_Var* exception); | |
dmichael (off chromium)
2014/07/30 19:34:14
ScopedPPVar*, maybe?
Otherwise the user of Pepper
raymes
2014/08/06 03:22:52
This class is mainly used to provide an exception
| |
70 virtual ~PepperTryCatchVar(); | |
71 | |
72 bool HasException(); | |
73 | |
74 // PepperTryCatch | |
75 virtual void SetException(const char* message) OVERRIDE; | |
76 | |
77 private: | |
78 // We typically don't have a HandleScope when using PepperTryCatchVar. | |
dmichael (off chromium)
2014/07/30 19:34:14
Maybe a clearer wording would be:
// Code which us
raymes
2014/08/06 03:22:52
Done, I reworded the comment! I think it makes the
| |
79 v8::HandleScope handle_scope_; | |
80 | |
81 v8::TryCatch try_catch_; | |
82 | |
83 PP_Var* exception_; | |
84 bool exception_is_set_; | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchVar); | |
87 }; | |
88 | |
89 } // namespace content | |
90 | |
91 #endif // CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ | |
OLD | NEW |