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 #include "content/renderer/pepper/pepper_try_catch.h" | 5 #include "content/renderer/pepper/pepper_try_catch.h" |
6 | 6 |
7 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 7 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
8 #include "content/renderer/pepper/v8_var_converter.h" | |
9 #include "gin/converter.h" | 8 #include "gin/converter.h" |
10 #include "ppapi/shared_impl/ppapi_globals.h" | 9 #include "ppapi/shared_impl/ppapi_globals.h" |
11 #include "ppapi/shared_impl/var_tracker.h" | 10 #include "ppapi/shared_impl/var_tracker.h" |
12 | 11 |
13 namespace content { | 12 namespace content { |
14 | 13 |
15 namespace { | 14 namespace { |
16 | 15 |
17 const char kConversionException[] = | 16 const char kConversionException[] = |
18 "Error: Failed conversion between PP_Var and V8 value"; | 17 "Error: Failed conversion between PP_Var and V8 value"; |
19 const char kInvalidException[] = "Error: An invalid exception was thrown."; | 18 const char kInvalidException[] = "Error: An invalid exception was thrown."; |
20 | 19 |
21 } // namespace | 20 } // namespace |
22 | 21 |
23 PepperTryCatch::PepperTryCatch(PepperPluginInstanceImpl* instance, | 22 PepperTryCatch::PepperTryCatch(PepperPluginInstanceImpl* instance, |
24 bool convert_objects) | 23 V8VarConverter::AllowObjectVars convert_objects) |
25 : instance_(instance), | 24 : instance_(instance), |
26 convert_objects_(convert_objects) {} | 25 convert_objects_(convert_objects) {} |
27 | 26 |
28 PepperTryCatch::~PepperTryCatch() {} | 27 PepperTryCatch::~PepperTryCatch() {} |
29 | 28 |
30 v8::Handle<v8::Context> PepperTryCatch::GetContext() { | 29 v8::Handle<v8::Context> PepperTryCatch::GetContext() { |
31 return instance_->GetContext(); | 30 return instance_->GetContext(); |
32 } | 31 } |
33 | 32 |
34 v8::Handle<v8::Value> PepperTryCatch::ToV8(PP_Var var) { | 33 v8::Handle<v8::Value> PepperTryCatch::ToV8(PP_Var var) { |
(...skipping 15 matching lines...) Expand all Loading... |
50 ppapi::ScopedPPVar result; | 49 ppapi::ScopedPPVar result; |
51 V8VarConverter converter(instance_->pp_instance(), convert_objects_); | 50 V8VarConverter converter(instance_->pp_instance(), convert_objects_); |
52 bool success = converter.FromV8ValueSync(v8_value, GetContext(), &result); | 51 bool success = converter.FromV8ValueSync(v8_value, GetContext(), &result); |
53 if (!success) { | 52 if (!success) { |
54 SetException(kConversionException); | 53 SetException(kConversionException); |
55 return ppapi::ScopedPPVar(); | 54 return ppapi::ScopedPPVar(); |
56 } | 55 } |
57 return result; | 56 return result; |
58 } | 57 } |
59 | 58 |
60 PepperTryCatchV8::PepperTryCatchV8(PepperPluginInstanceImpl* instance, | 59 PepperTryCatchV8::PepperTryCatchV8( |
61 bool convert_objects, | 60 PepperPluginInstanceImpl* instance, |
62 v8::Isolate* isolate) | 61 V8VarConverter::AllowObjectVars convert_objects, |
| 62 v8::Isolate* isolate) |
63 : PepperTryCatch(instance, convert_objects), | 63 : PepperTryCatch(instance, convert_objects), |
64 exception_(PP_MakeUndefined()) { | 64 exception_(PP_MakeUndefined()) { |
65 // Typically when using PepperTryCatchV8 we are passed an isolate. We verify | 65 // Typically when using PepperTryCatchV8 we are passed an isolate. We verify |
66 // that this isolate is the same as the plugin isolate. | 66 // that this isolate is the same as the plugin isolate. |
67 DCHECK(isolate == instance_->GetIsolate()); | 67 DCHECK(isolate == instance_->GetIsolate()); |
68 // We assume we are already in the plugin context for PepperTryCatchV8. | 68 // We assume we are already in the plugin context for PepperTryCatchV8. |
69 DCHECK(GetContext() == isolate->GetCurrentContext()); | 69 DCHECK(GetContext() == isolate->GetCurrentContext()); |
70 } | 70 } |
71 | 71 |
72 PepperTryCatchV8::~PepperTryCatchV8() { | 72 PepperTryCatchV8::~PepperTryCatchV8() { |
(...skipping 27 matching lines...) Expand all Loading... |
100 | 100 |
101 void PepperTryCatchV8::SetException(const char* message) { | 101 void PepperTryCatchV8::SetException(const char* message) { |
102 if (HasException()) { | 102 if (HasException()) { |
103 NOTREACHED(); | 103 NOTREACHED(); |
104 return; | 104 return; |
105 } | 105 } |
106 exception_ = ppapi::StringVar::StringToPPVar(message); | 106 exception_ = ppapi::StringVar::StringToPPVar(message); |
107 } | 107 } |
108 | 108 |
109 PepperTryCatchVar::PepperTryCatchVar(PepperPluginInstanceImpl* instance, | 109 PepperTryCatchVar::PepperTryCatchVar(PepperPluginInstanceImpl* instance, |
110 bool convert_objects, | |
111 PP_Var* exception) | 110 PP_Var* exception) |
112 : PepperTryCatch(instance, convert_objects), | 111 : PepperTryCatch(instance, V8VarConverter::kAllowObjectVars), |
113 handle_scope_(instance_->GetIsolate()), | 112 handle_scope_(instance_->GetIsolate()), |
114 exception_(exception), | 113 exception_(exception), |
115 exception_is_set_(false) { | 114 exception_is_set_(false) { |
116 // We switch to the plugin context. | 115 // We switch to the plugin context. |
117 GetContext()->Enter(); | 116 GetContext()->Enter(); |
118 } | 117 } |
119 | 118 |
120 PepperTryCatchVar::~PepperTryCatchVar() { | 119 PepperTryCatchVar::~PepperTryCatchVar() { |
121 GetContext()->Exit(); | 120 GetContext()->Exit(); |
122 } | 121 } |
(...skipping 16 matching lines...) Expand all Loading... |
139 if (exception_is_set_) { | 138 if (exception_is_set_) { |
140 NOTREACHED(); | 139 NOTREACHED(); |
141 return; | 140 return; |
142 } | 141 } |
143 if (exception_) | 142 if (exception_) |
144 *exception_ = ppapi::StringVar::StringToPPVar(message, strlen(message)); | 143 *exception_ = ppapi::StringVar::StringToPPVar(message, strlen(message)); |
145 exception_is_set_ = true; | 144 exception_is_set_ = true; |
146 } | 145 } |
147 | 146 |
148 } // namespace content | 147 } // namespace content |
OLD | NEW |