Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Side by Side Diff: content/renderer/pepper/pepper_try_catch.cc

Issue 512983004: Revert of Replace NPObject usage in ppapi with gin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 bool convert_objects)
24 : instance_(instance), 25 : instance_(instance),
25 convert_objects_(convert_objects) {} 26 convert_objects_(convert_objects) {}
26 27
27 PepperTryCatch::~PepperTryCatch() {} 28 PepperTryCatch::~PepperTryCatch() {}
28 29
29 v8::Handle<v8::Context> PepperTryCatch::GetContext() { 30 v8::Handle<v8::Context> PepperTryCatch::GetContext() {
30 return instance_->GetContext(); 31 return instance_->GetContext();
31 } 32 }
32 33
33 v8::Handle<v8::Value> PepperTryCatch::ToV8(PP_Var var) { 34 v8::Handle<v8::Value> PepperTryCatch::ToV8(PP_Var var) {
(...skipping 15 matching lines...) Expand all
49 ppapi::ScopedPPVar result; 50 ppapi::ScopedPPVar result;
50 V8VarConverter converter(instance_->pp_instance(), convert_objects_); 51 V8VarConverter converter(instance_->pp_instance(), convert_objects_);
51 bool success = converter.FromV8ValueSync(v8_value, GetContext(), &result); 52 bool success = converter.FromV8ValueSync(v8_value, GetContext(), &result);
52 if (!success) { 53 if (!success) {
53 SetException(kConversionException); 54 SetException(kConversionException);
54 return ppapi::ScopedPPVar(); 55 return ppapi::ScopedPPVar();
55 } 56 }
56 return result; 57 return result;
57 } 58 }
58 59
59 PepperTryCatchV8::PepperTryCatchV8( 60 PepperTryCatchV8::PepperTryCatchV8(PepperPluginInstanceImpl* instance,
60 PepperPluginInstanceImpl* instance, 61 bool convert_objects,
61 V8VarConverter::AllowObjectVars convert_objects, 62 v8::Isolate* isolate)
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
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,
110 PP_Var* exception) 111 PP_Var* exception)
111 : PepperTryCatch(instance, V8VarConverter::kAllowObjectVars), 112 : PepperTryCatch(instance, convert_objects),
112 handle_scope_(instance_->GetIsolate()), 113 handle_scope_(instance_->GetIsolate()),
113 exception_(exception), 114 exception_(exception),
114 exception_is_set_(false) { 115 exception_is_set_(false) {
115 // We switch to the plugin context. 116 // We switch to the plugin context.
116 GetContext()->Enter(); 117 GetContext()->Enter();
117 } 118 }
118 119
119 PepperTryCatchVar::~PepperTryCatchVar() { 120 PepperTryCatchVar::~PepperTryCatchVar() {
120 GetContext()->Exit(); 121 GetContext()->Exit();
121 } 122 }
(...skipping 16 matching lines...) Expand all
138 if (exception_is_set_) { 139 if (exception_is_set_) {
139 NOTREACHED(); 140 NOTREACHED();
140 return; 141 return;
141 } 142 }
142 if (exception_) 143 if (exception_)
143 *exception_ = ppapi::StringVar::StringToPPVar(message, strlen(message)); 144 *exception_ = ppapi::StringVar::StringToPPVar(message, strlen(message));
144 exception_is_set_ = true; 145 exception_is_set_ = true;
145 } 146 }
146 147
147 } // namespace content 148 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_try_catch.h ('k') | content/renderer/pepper/pepper_webplugin_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698