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

Side by Side Diff: webkit/plugins/ppapi/npapi_glue.cc

Issue 8826011: Remove PP_Module from parameters for PPB_Var.VarFromUtf8. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix indentation. Created 9 years 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 (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/host_globals.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 case NPVariantType_Null: 88 case NPVariantType_Null:
89 return PP_MakeNull(); 89 return PP_MakeNull();
90 case NPVariantType_Bool: 90 case NPVariantType_Bool:
91 return PP_MakeBool(PP_FromBool(NPVARIANT_TO_BOOLEAN(*variant))); 91 return PP_MakeBool(PP_FromBool(NPVARIANT_TO_BOOLEAN(*variant)));
92 case NPVariantType_Int32: 92 case NPVariantType_Int32:
93 return PP_MakeInt32(NPVARIANT_TO_INT32(*variant)); 93 return PP_MakeInt32(NPVARIANT_TO_INT32(*variant));
94 case NPVariantType_Double: 94 case NPVariantType_Double:
95 return PP_MakeDouble(NPVARIANT_TO_DOUBLE(*variant)); 95 return PP_MakeDouble(NPVARIANT_TO_DOUBLE(*variant));
96 case NPVariantType_String: 96 case NPVariantType_String:
97 return StringVar::StringToPPVar( 97 return StringVar::StringToPPVar(
98 instance->module()->pp_module(),
99 NPVARIANT_TO_STRING(*variant).UTF8Characters, 98 NPVARIANT_TO_STRING(*variant).UTF8Characters,
100 NPVARIANT_TO_STRING(*variant).UTF8Length); 99 NPVARIANT_TO_STRING(*variant).UTF8Length);
101 case NPVariantType_Object: 100 case NPVariantType_Object:
102 return NPObjectToPPVar(instance, NPVARIANT_TO_OBJECT(*variant)); 101 return NPObjectToPPVar(instance, NPVARIANT_TO_OBJECT(*variant));
103 } 102 }
104 NOTREACHED(); 103 NOTREACHED();
105 return PP_MakeUndefined(); 104 return PP_MakeUndefined();
106 } 105 }
107 106
108 NPIdentifier PPVarToNPIdentifier(PP_Var var) { 107 NPIdentifier PPVarToNPIdentifier(PP_Var var) {
109 switch (var.type) { 108 switch (var.type) {
110 case PP_VARTYPE_STRING: { 109 case PP_VARTYPE_STRING: {
111 StringVar* string = StringVar::FromPPVar(var); 110 StringVar* string = StringVar::FromPPVar(var);
112 if (!string) 111 if (!string)
113 return NULL; 112 return NULL;
114 return WebBindings::getStringIdentifier(string->value().c_str()); 113 return WebBindings::getStringIdentifier(string->value().c_str());
115 } 114 }
116 case PP_VARTYPE_INT32: 115 case PP_VARTYPE_INT32:
117 return WebBindings::getIntIdentifier(var.value.as_int); 116 return WebBindings::getIntIdentifier(var.value.as_int);
118 default: 117 default:
119 return NULL; 118 return NULL;
120 } 119 }
121 } 120 }
122 121
123 PP_Var NPIdentifierToPPVar(PP_Module module, NPIdentifier id) { 122 PP_Var NPIdentifierToPPVar(NPIdentifier id) {
124 const NPUTF8* string_value = NULL; 123 const NPUTF8* string_value = NULL;
125 int32_t int_value = 0; 124 int32_t int_value = 0;
126 bool is_string = false; 125 bool is_string = false;
127 WebBindings::extractIdentifierData(id, string_value, int_value, is_string); 126 WebBindings::extractIdentifierData(id, string_value, int_value, is_string);
128 if (is_string) 127 if (is_string)
129 return StringVar::StringToPPVar(module, string_value); 128 return StringVar::StringToPPVar(string_value);
130 129
131 return PP_MakeInt32(int_value); 130 return PP_MakeInt32(int_value);
132 } 131 }
133 132
134 PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object) { 133 PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object) {
135 DCHECK(object); 134 DCHECK(object);
136 scoped_refptr<NPObjectVar> object_var( 135 scoped_refptr<NPObjectVar> object_var(
137 HostGlobals::Get()->host_var_tracker()->NPObjectVarForNPObject( 136 HostGlobals::Get()->host_var_tracker()->NPObjectVarForNPObject(
138 instance->pp_instance(), object)); 137 instance->pp_instance(), object));
139 if (!object_var) { // No object for this module yet, make a new one. 138 if (!object_var) { // No object for this module yet, make a new one.
140 object_var = new NPObjectVar(instance->module()->pp_module(), 139 object_var = new NPObjectVar(instance->pp_instance(), object);
141 instance->pp_instance(), object);
142 } 140 }
143 return object_var->GetPPVar(); 141 return object_var->GetPPVar();
144 } 142 }
145 143
146 // PPResultAndExceptionToNPResult ---------------------------------------------- 144 // PPResultAndExceptionToNPResult ----------------------------------------------
147 145
148 PPResultAndExceptionToNPResult::PPResultAndExceptionToNPResult( 146 PPResultAndExceptionToNPResult::PPResultAndExceptionToNPResult(
149 NPObject* object_var, 147 NPObject* object_var,
150 NPVariant* np_result) 148 NPVariant* np_result)
151 : object_var_(object_var), 149 : object_var_(object_var),
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 253
256 // NPObjectAccessorWithIdentifier ---------------------------------------------- 254 // NPObjectAccessorWithIdentifier ----------------------------------------------
257 255
258 NPObjectAccessorWithIdentifier::NPObjectAccessorWithIdentifier( 256 NPObjectAccessorWithIdentifier::NPObjectAccessorWithIdentifier(
259 NPObject* object, 257 NPObject* object,
260 NPIdentifier identifier, 258 NPIdentifier identifier,
261 bool allow_integer_identifier) 259 bool allow_integer_identifier)
262 : object_(PluginObject::FromNPObject(object)), 260 : object_(PluginObject::FromNPObject(object)),
263 identifier_(PP_MakeUndefined()) { 261 identifier_(PP_MakeUndefined()) {
264 if (object_) { 262 if (object_) {
265 identifier_ = NPIdentifierToPPVar( 263 identifier_ = NPIdentifierToPPVar(identifier);
266 object_->instance()->module()->pp_module(), identifier);
267 if (identifier_.type == PP_VARTYPE_INT32 && !allow_integer_identifier) 264 if (identifier_.type == PP_VARTYPE_INT32 && !allow_integer_identifier)
268 identifier_.type = PP_VARTYPE_UNDEFINED; // Mark it invalid. 265 identifier_.type = PP_VARTYPE_UNDEFINED; // Mark it invalid.
269 } 266 }
270 } 267 }
271 268
272 NPObjectAccessorWithIdentifier::~NPObjectAccessorWithIdentifier() { 269 NPObjectAccessorWithIdentifier::~NPObjectAccessorWithIdentifier() {
273 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(identifier_); 270 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(identifier_);
274 } 271 }
275 272
276 // TryCatch -------------------------------------------------------------------- 273 // TryCatch --------------------------------------------------------------------
277 274
278 TryCatch::TryCatch(PP_Module module, PP_Var* exception) 275 TryCatch::TryCatch(PP_Var* exception)
279 : pp_module_(module), 276 : has_exception_(exception && exception->type != PP_VARTYPE_UNDEFINED),
280 has_exception_(exception && exception->type != PP_VARTYPE_UNDEFINED),
281 exception_(exception) { 277 exception_(exception) {
282 WebBindings::pushExceptionHandler(&TryCatch::Catch, this); 278 WebBindings::pushExceptionHandler(&TryCatch::Catch, this);
283 } 279 }
284 280
285 TryCatch::~TryCatch() { 281 TryCatch::~TryCatch() {
286 WebBindings::popExceptionHandler(); 282 WebBindings::popExceptionHandler();
287 } 283 }
288 284
289 void TryCatch::SetException(const char* message) { 285 void TryCatch::SetException(const char* message) {
290 if (!pp_module_) {
291 // Don't have a module to make the string.
292 SetInvalidObjectException();
293 return;
294 }
295
296 if (!has_exception()) { 286 if (!has_exception()) {
297 has_exception_ = true; 287 has_exception_ = true;
298 if (exception_) { 288 if (exception_) {
299 *exception_ = ::ppapi::StringVar::StringToPPVar(pp_module_, 289 *exception_ = ::ppapi::StringVar::StringToPPVar(message, strlen(message));
300 message, strlen(message));
301 } 290 }
302 } 291 }
303 } 292 }
304 293
305 void TryCatch::SetInvalidObjectException() {
306 if (!has_exception()) {
307 has_exception_ = true;
308 // TODO(brettw) bug 54504: Have a global singleton string that can hold
309 // a generic error message.
310 if (exception_)
311 *exception_ = PP_MakeInt32(1);
312 }
313 }
314
315 // static 294 // static
316 void TryCatch::Catch(void* self, const char* message) { 295 void TryCatch::Catch(void* self, const char* message) {
317 static_cast<TryCatch*>(self)->SetException(message); 296 static_cast<TryCatch*>(self)->SetException(message);
318 } 297 }
319 298
320 } // namespace ppapi 299 } // namespace ppapi
321 } // namespace webkit 300 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698