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

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

Powered by Google App Engine
This is Rietveld 408576698