Chromium Code Reviews| 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" | |
| 8 #include "gin/converter.h" | 9 #include "gin/converter.h" |
| 9 #include "ppapi/shared_impl/ppapi_globals.h" | 10 #include "ppapi/shared_impl/ppapi_globals.h" |
| 10 #include "ppapi/shared_impl/var_tracker.h" | 11 #include "ppapi/shared_impl/var_tracker.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 const char kConversionException[] = | 17 const char kConversionException[] = |
| 17 "Error: Failed conversion between PP_Var and V8 value"; | 18 "Error: Failed conversion between PP_Var and V8 value"; |
| 18 const char kInvalidException[] = "Error: An invalid exception was thrown."; | 19 const char kInvalidException[] = "Error: An invalid exception was thrown."; |
| 19 | 20 |
| 20 } // namespace | 21 } // namespace |
| 21 | 22 |
| 22 PepperTryCatch::PepperTryCatch(PepperPluginInstanceImpl* instance, | 23 PepperTryCatch::PepperTryCatch(PepperPluginInstanceImpl* instance, |
| 23 V8VarConverter::AllowObjectVars convert_objects) | 24 V8VarConverter* var_converter) |
| 24 : instance_(instance), | 25 : instance_(instance), var_converter_(var_converter) {} |
|
raymes
2014/10/09 22:04:42
nit, optional: since we know that the conversion m
dmichael (off chromium)
2014/10/09 22:45:37
You mean kAllowObjectVars? We don't know that here
raymes
2014/10/10 19:27:14
Sorry, yeah that's what I meant :)
| |
| 25 convert_objects_(convert_objects) {} | |
| 26 | 26 |
| 27 PepperTryCatch::~PepperTryCatch() {} | 27 PepperTryCatch::~PepperTryCatch() {} |
| 28 | 28 |
| 29 v8::Handle<v8::Value> PepperTryCatch::ToV8(PP_Var var) { | 29 v8::Handle<v8::Value> PepperTryCatch::ToV8(PP_Var var) { |
| 30 if (HasException()) { | 30 if (HasException()) { |
| 31 SetException(kConversionException); | 31 SetException(kConversionException); |
| 32 return v8::Handle<v8::Value>(); | 32 return v8::Handle<v8::Value>(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 V8VarConverter converter(instance_->pp_instance(), convert_objects_); | |
| 36 v8::Handle<v8::Value> result; | 35 v8::Handle<v8::Value> result; |
| 37 bool success = converter.ToV8Value(var, GetContext(), &result); | 36 bool success = var_converter_->ToV8Value(var, GetContext(), &result); |
| 38 if (!success) { | 37 if (!success) { |
| 39 SetException(kConversionException); | 38 SetException(kConversionException); |
| 40 return v8::Handle<v8::Value>(); | 39 return v8::Handle<v8::Value>(); |
| 41 } | 40 } |
| 42 return result; | 41 return result; |
| 43 } | 42 } |
| 44 | 43 |
| 45 ppapi::ScopedPPVar PepperTryCatch::FromV8(v8::Handle<v8::Value> v8_value) { | 44 ppapi::ScopedPPVar PepperTryCatch::FromV8(v8::Handle<v8::Value> v8_value) { |
| 46 if (HasException() || v8_value.IsEmpty()) { | 45 if (HasException() || v8_value.IsEmpty()) { |
| 47 SetException(kConversionException); | 46 SetException(kConversionException); |
| 48 return ppapi::ScopedPPVar(); | 47 return ppapi::ScopedPPVar(); |
| 49 } | 48 } |
| 50 ppapi::ScopedPPVar result; | 49 ppapi::ScopedPPVar result; |
| 51 V8VarConverter converter(instance_->pp_instance(), convert_objects_); | 50 bool success = |
| 52 bool success = converter.FromV8ValueSync(v8_value, GetContext(), &result); | 51 var_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( | 59 PepperTryCatchV8::PepperTryCatchV8(PepperPluginInstanceImpl* instance, |
| 61 PepperPluginInstanceImpl* instance, | 60 V8VarConverter* var_converter, |
| 62 V8VarConverter::AllowObjectVars convert_objects, | 61 v8::Isolate* isolate) |
| 63 v8::Isolate* isolate) | 62 : PepperTryCatch(instance, var_converter), |
| 64 : PepperTryCatch(instance, convert_objects), | |
| 65 exception_(PP_MakeUndefined()) { | 63 exception_(PP_MakeUndefined()) { |
| 66 // Typically when using PepperTryCatchV8 we are passed an isolate. We verify | 64 // Typically when using PepperTryCatchV8 we are passed an isolate. We verify |
| 67 // that this isolate is the same as the plugin isolate. | 65 // that this isolate is the same as the plugin isolate. |
| 68 DCHECK(isolate == instance_->GetIsolate()); | 66 DCHECK(isolate == instance_->GetIsolate()); |
| 69 | 67 |
| 70 // We assume that a handle scope and context has been setup by the user of | 68 // We assume that a handle scope and context has been setup by the user of |
| 71 // this class. This is typically true because this class is used when calling | 69 // this class. This is typically true because this class is used when calling |
| 72 // into the plugin from JavaScript. We want to use whatever v8 context the | 70 // into the plugin from JavaScript. We want to use whatever v8 context the |
| 73 // caller is in. | 71 // caller is in. |
| 74 } | 72 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 } | 111 } |
| 114 | 112 |
| 115 void PepperTryCatchV8::SetException(const char* message) { | 113 void PepperTryCatchV8::SetException(const char* message) { |
| 116 if (HasException()) | 114 if (HasException()) |
| 117 return; | 115 return; |
| 118 | 116 |
| 119 exception_ = ppapi::StringVar::StringToPPVar(message); | 117 exception_ = ppapi::StringVar::StringToPPVar(message); |
| 120 } | 118 } |
| 121 | 119 |
| 122 PepperTryCatchVar::PepperTryCatchVar(PepperPluginInstanceImpl* instance, | 120 PepperTryCatchVar::PepperTryCatchVar(PepperPluginInstanceImpl* instance, |
| 121 V8VarConverter* var_converter, | |
| 123 PP_Var* exception) | 122 PP_Var* exception) |
| 124 : PepperTryCatch(instance, V8VarConverter::kAllowObjectVars), | 123 : PepperTryCatch(instance, var_converter), |
| 125 handle_scope_(instance_->GetIsolate()), | 124 handle_scope_(instance_->GetIsolate()), |
| 126 context_(GetContext()), | 125 context_(GetContext()), |
| 127 exception_(exception), | 126 exception_(exception), |
| 128 exception_is_set_(false) { | 127 exception_is_set_(false) { |
| 129 // We switch to the plugin context if it's not empty. | 128 // We switch to the plugin context if it's not empty. |
| 130 if (!context_.IsEmpty()) | 129 if (!context_.IsEmpty()) |
| 131 context_->Enter(); | 130 context_->Enter(); |
| 132 } | 131 } |
| 133 | 132 |
| 134 PepperTryCatchVar::~PepperTryCatchVar() { | 133 PepperTryCatchVar::~PepperTryCatchVar() { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 165 void PepperTryCatchVar::SetException(const char* message) { | 164 void PepperTryCatchVar::SetException(const char* message) { |
| 166 if (exception_is_set_) | 165 if (exception_is_set_) |
| 167 return; | 166 return; |
| 168 | 167 |
| 169 if (exception_) | 168 if (exception_) |
| 170 *exception_ = ppapi::StringVar::StringToPPVar(message, strlen(message)); | 169 *exception_ = ppapi::StringVar::StringToPPVar(message, strlen(message)); |
| 171 exception_is_set_ = true; | 170 exception_is_set_ = true; |
| 172 } | 171 } |
| 173 | 172 |
| 174 } // namespace content | 173 } // namespace content |
| OLD | NEW |