OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/npapi_glue.h" | 5 #include "webkit/plugins/ppapi/npapi_glue.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "webkit/plugins/ppapi/host_globals.h" |
10 #include "webkit/plugins/ppapi/npobject_var.h" | 11 #include "webkit/plugins/ppapi/npobject_var.h" |
11 #include "webkit/plugins/ppapi/plugin_module.h" | 12 #include "webkit/plugins/ppapi/plugin_module.h" |
12 #include "webkit/plugins/ppapi/plugin_object.h" | 13 #include "webkit/plugins/ppapi/plugin_object.h" |
13 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
14 #include "webkit/plugins/ppapi/resource_tracker.h" | 15 #include "webkit/plugins/ppapi/resource_tracker.h" |
15 #include "third_party/npapi/bindings/npapi.h" | 16 #include "third_party/npapi/bindings/npapi.h" |
16 #include "third_party/npapi/bindings/npruntime.h" | 17 #include "third_party/npapi/bindings/npruntime.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
18 | 19 |
19 using ppapi::NPObjectVar; | 20 using ppapi::NPObjectVar; |
| 21 using ppapi::PpapiGlobals; |
20 using ppapi::StringVar; | 22 using ppapi::StringVar; |
21 using ppapi::Var; | 23 using ppapi::Var; |
22 using WebKit::WebBindings; | 24 using WebKit::WebBindings; |
23 | 25 |
24 namespace webkit { | 26 namespace webkit { |
25 namespace ppapi { | 27 namespace ppapi { |
26 | 28 |
27 namespace { | 29 namespace { |
28 | 30 |
29 const char kInvalidPluginValue[] = "Error: Plugin returned invalid value."; | 31 const char kInvalidPluginValue[] = "Error: Plugin returned invalid value."; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 WebBindings::extractIdentifierData(id, string_value, int_value, is_string); | 127 WebBindings::extractIdentifierData(id, string_value, int_value, is_string); |
126 if (is_string) | 128 if (is_string) |
127 return StringVar::StringToPPVar(module, string_value); | 129 return StringVar::StringToPPVar(module, string_value); |
128 | 130 |
129 return PP_MakeInt32(int_value); | 131 return PP_MakeInt32(int_value); |
130 } | 132 } |
131 | 133 |
132 PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object) { | 134 PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object) { |
133 DCHECK(object); | 135 DCHECK(object); |
134 scoped_refptr<NPObjectVar> object_var( | 136 scoped_refptr<NPObjectVar> object_var( |
135 ResourceTracker::Get()->NPObjectVarForNPObject(instance->pp_instance(), | 137 HostGlobals::Get()->host_resource_tracker()->NPObjectVarForNPObject( |
136 object)); | 138 instance->pp_instance(), object)); |
137 if (!object_var) { // No object for this module yet, make a new one. | 139 if (!object_var) { // No object for this module yet, make a new one. |
138 object_var = new NPObjectVar(instance->module()->pp_module(), | 140 object_var = new NPObjectVar(instance->module()->pp_module(), |
139 instance->pp_instance(), object); | 141 instance->pp_instance(), object); |
140 } | 142 } |
141 return object_var->GetPPVar(); | 143 return object_var->GetPPVar(); |
142 } | 144 } |
143 | 145 |
144 // PPResultAndExceptionToNPResult ---------------------------------------------- | 146 // PPResultAndExceptionToNPResult ---------------------------------------------- |
145 | 147 |
146 PPResultAndExceptionToNPResult::PPResultAndExceptionToNPResult( | 148 PPResultAndExceptionToNPResult::PPResultAndExceptionToNPResult( |
147 NPObject* object_var, | 149 NPObject* object_var, |
148 NPVariant* np_result) | 150 NPVariant* np_result) |
149 : object_var_(object_var), | 151 : object_var_(object_var), |
150 np_result_(np_result), | 152 np_result_(np_result), |
151 exception_(PP_MakeUndefined()), | 153 exception_(PP_MakeUndefined()), |
152 success_(false), | 154 success_(false), |
153 checked_exception_(false) { | 155 checked_exception_(false) { |
154 } | 156 } |
155 | 157 |
156 PPResultAndExceptionToNPResult::~PPResultAndExceptionToNPResult() { | 158 PPResultAndExceptionToNPResult::~PPResultAndExceptionToNPResult() { |
157 // The user should have called SetResult or CheckExceptionForNoResult | 159 // The user should have called SetResult or CheckExceptionForNoResult |
158 // before letting this class go out of scope, or the exception will have | 160 // before letting this class go out of scope, or the exception will have |
159 // been lost. | 161 // been lost. |
160 DCHECK(checked_exception_); | 162 DCHECK(checked_exception_); |
161 | 163 |
162 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(exception_); | 164 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(exception_); |
163 } | 165 } |
164 | 166 |
165 // Call this with the return value of the PPAPI function. It will convert | 167 // Call this with the return value of the PPAPI function. It will convert |
166 // the result to the NPVariant output parameter and pass any exception on to | 168 // the result to the NPVariant output parameter and pass any exception on to |
167 // the JS engine. It will update the success flag and return it. | 169 // the JS engine. It will update the success flag and return it. |
168 bool PPResultAndExceptionToNPResult::SetResult(PP_Var result) { | 170 bool PPResultAndExceptionToNPResult::SetResult(PP_Var result) { |
169 DCHECK(!checked_exception_); // Don't call more than once. | 171 DCHECK(!checked_exception_); // Don't call more than once. |
170 DCHECK(np_result_); // Should be expecting a result. | 172 DCHECK(np_result_); // Should be expecting a result. |
171 | 173 |
172 checked_exception_ = true; | 174 checked_exception_ = true; |
173 | 175 |
174 if (has_exception()) { | 176 if (has_exception()) { |
175 ThrowException(); | 177 ThrowException(); |
176 success_ = false; | 178 success_ = false; |
177 } else if (!PPVarToNPVariant(result, np_result_)) { | 179 } else if (!PPVarToNPVariant(result, np_result_)) { |
178 WebBindings::setException(object_var_, kInvalidPluginValue); | 180 WebBindings::setException(object_var_, kInvalidPluginValue); |
179 success_ = false; | 181 success_ = false; |
180 } else { | 182 } else { |
181 success_ = true; | 183 success_ = true; |
182 } | 184 } |
183 | 185 |
184 // No matter what happened, we need to release the reference to the | 186 // No matter what happened, we need to release the reference to the |
185 // value passed in. On success, a reference to this value will be in | 187 // value passed in. On success, a reference to this value will be in |
186 // the np_result_. | 188 // the np_result_. |
187 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(result); | 189 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(result); |
188 return success_; | 190 return success_; |
189 } | 191 } |
190 | 192 |
191 // Call this after calling a PPAPI function that could have set the | 193 // Call this after calling a PPAPI function that could have set the |
192 // exception. It will pass the exception on to the JS engine and update | 194 // exception. It will pass the exception on to the JS engine and update |
193 // the success flag. | 195 // the success flag. |
194 // | 196 // |
195 // The success flag will be returned. | 197 // The success flag will be returned. |
196 bool PPResultAndExceptionToNPResult::CheckExceptionForNoResult() { | 198 bool PPResultAndExceptionToNPResult::CheckExceptionForNoResult() { |
197 DCHECK(!checked_exception_); // Don't call more than once. | 199 DCHECK(!checked_exception_); // Don't call more than once. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 const NPVariant* variants) | 231 const NPVariant* variants) |
230 : size_(size) { | 232 : size_(size) { |
231 if (size_ > 0) { | 233 if (size_ > 0) { |
232 array_.reset(new PP_Var[size_]); | 234 array_.reset(new PP_Var[size_]); |
233 for (size_t i = 0; i < size_; i++) | 235 for (size_t i = 0; i < size_; i++) |
234 array_[i] = NPVariantToPPVar(instance, &variants[i]); | 236 array_[i] = NPVariantToPPVar(instance, &variants[i]); |
235 } | 237 } |
236 } | 238 } |
237 | 239 |
238 PPVarArrayFromNPVariantArray::~PPVarArrayFromNPVariantArray() { | 240 PPVarArrayFromNPVariantArray::~PPVarArrayFromNPVariantArray() { |
239 ::ppapi::VarTracker* var_tracker = ResourceTracker::Get()->GetVarTracker(); | 241 ::ppapi::VarTracker* var_tracker = PpapiGlobals::Get()->GetVarTracker(); |
240 for (size_t i = 0; i < size_; i++) | 242 for (size_t i = 0; i < size_; i++) |
241 var_tracker->ReleaseVar(array_[i]); | 243 var_tracker->ReleaseVar(array_[i]); |
242 } | 244 } |
243 | 245 |
244 // PPVarFromNPObject ----------------------------------------------------------- | 246 // PPVarFromNPObject ----------------------------------------------------------- |
245 | 247 |
246 PPVarFromNPObject::PPVarFromNPObject(PluginInstance* instance, NPObject* object) | 248 PPVarFromNPObject::PPVarFromNPObject(PluginInstance* instance, NPObject* object) |
247 : var_(NPObjectToPPVar(instance, object)) { | 249 : var_(NPObjectToPPVar(instance, object)) { |
248 } | 250 } |
249 | 251 |
250 PPVarFromNPObject::~PPVarFromNPObject() { | 252 PPVarFromNPObject::~PPVarFromNPObject() { |
251 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(var_); | 253 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var_); |
252 } | 254 } |
253 | 255 |
254 // NPObjectAccessorWithIdentifier ---------------------------------------------- | 256 // NPObjectAccessorWithIdentifier ---------------------------------------------- |
255 | 257 |
256 NPObjectAccessorWithIdentifier::NPObjectAccessorWithIdentifier( | 258 NPObjectAccessorWithIdentifier::NPObjectAccessorWithIdentifier( |
257 NPObject* object, | 259 NPObject* object, |
258 NPIdentifier identifier, | 260 NPIdentifier identifier, |
259 bool allow_integer_identifier) | 261 bool allow_integer_identifier) |
260 : object_(PluginObject::FromNPObject(object)), | 262 : object_(PluginObject::FromNPObject(object)), |
261 identifier_(PP_MakeUndefined()) { | 263 identifier_(PP_MakeUndefined()) { |
262 if (object_) { | 264 if (object_) { |
263 identifier_ = NPIdentifierToPPVar( | 265 identifier_ = NPIdentifierToPPVar( |
264 object_->instance()->module()->pp_module(), identifier); | 266 object_->instance()->module()->pp_module(), identifier); |
265 if (identifier_.type == PP_VARTYPE_INT32 && !allow_integer_identifier) | 267 if (identifier_.type == PP_VARTYPE_INT32 && !allow_integer_identifier) |
266 identifier_.type = PP_VARTYPE_UNDEFINED; // Mark it invalid. | 268 identifier_.type = PP_VARTYPE_UNDEFINED; // Mark it invalid. |
267 } | 269 } |
268 } | 270 } |
269 | 271 |
270 NPObjectAccessorWithIdentifier::~NPObjectAccessorWithIdentifier() { | 272 NPObjectAccessorWithIdentifier::~NPObjectAccessorWithIdentifier() { |
271 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(identifier_); | 273 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(identifier_); |
272 } | 274 } |
273 | 275 |
274 // TryCatch -------------------------------------------------------------------- | 276 // TryCatch -------------------------------------------------------------------- |
275 | 277 |
276 TryCatch::TryCatch(PP_Module module, PP_Var* exception) | 278 TryCatch::TryCatch(PP_Module module, PP_Var* exception) |
277 : pp_module_(module), | 279 : pp_module_(module), |
278 has_exception_(exception && exception->type != PP_VARTYPE_UNDEFINED), | 280 has_exception_(exception && exception->type != PP_VARTYPE_UNDEFINED), |
279 exception_(exception) { | 281 exception_(exception) { |
280 WebBindings::pushExceptionHandler(&TryCatch::Catch, this); | 282 WebBindings::pushExceptionHandler(&TryCatch::Catch, this); |
281 } | 283 } |
(...skipping 28 matching lines...) Expand all Loading... |
310 } | 312 } |
311 } | 313 } |
312 | 314 |
313 // static | 315 // static |
314 void TryCatch::Catch(void* self, const char* message) { | 316 void TryCatch::Catch(void* self, const char* message) { |
315 static_cast<TryCatch*>(self)->SetException(message); | 317 static_cast<TryCatch*>(self)->SetException(message); |
316 } | 318 } |
317 | 319 |
318 } // namespace ppapi | 320 } // namespace ppapi |
319 } // namespace webkit | 321 } // namespace webkit |
OLD | NEW |