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

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

Issue 8342016: Revert 106142 - Add a new globals object for PPAPI tracking information. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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
« no previous file with comments | « webkit/plugins/ppapi/host_globals.cc ('k') | webkit/plugins/ppapi/npobject_var.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:mergeinfo
Merged /branches/chrome_webkit_merge_branch/src/webkit/plugins/ppapi/npapi_glue.cc:r3734-4217,4606-5108,5177-5263
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"
11 #include "webkit/plugins/ppapi/npobject_var.h" 10 #include "webkit/plugins/ppapi/npobject_var.h"
12 #include "webkit/plugins/ppapi/plugin_module.h" 11 #include "webkit/plugins/ppapi/plugin_module.h"
13 #include "webkit/plugins/ppapi/plugin_object.h" 12 #include "webkit/plugins/ppapi/plugin_object.h"
14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 13 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
15 #include "webkit/plugins/ppapi/resource_tracker.h" 14 #include "webkit/plugins/ppapi/resource_tracker.h"
16 #include "third_party/npapi/bindings/npapi.h" 15 #include "third_party/npapi/bindings/npapi.h"
17 #include "third_party/npapi/bindings/npruntime.h" 16 #include "third_party/npapi/bindings/npruntime.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
19 18
20 using ppapi::NPObjectVar; 19 using ppapi::NPObjectVar;
21 using ppapi::PpapiGlobals;
22 using ppapi::StringVar; 20 using ppapi::StringVar;
23 using ppapi::Var; 21 using ppapi::Var;
24 using WebKit::WebBindings; 22 using WebKit::WebBindings;
25 23
26 namespace webkit { 24 namespace webkit {
27 namespace ppapi { 25 namespace ppapi {
28 26
29 namespace { 27 namespace {
30 28
31 const char kInvalidPluginValue[] = "Error: Plugin returned invalid value."; 29 const char kInvalidPluginValue[] = "Error: Plugin returned invalid value.";
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 WebBindings::extractIdentifierData(id, string_value, int_value, is_string); 125 WebBindings::extractIdentifierData(id, string_value, int_value, is_string);
128 if (is_string) 126 if (is_string)
129 return StringVar::StringToPPVar(module, string_value); 127 return StringVar::StringToPPVar(module, string_value);
130 128
131 return PP_MakeInt32(int_value); 129 return PP_MakeInt32(int_value);
132 } 130 }
133 131
134 PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object) { 132 PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object) {
135 DCHECK(object); 133 DCHECK(object);
136 scoped_refptr<NPObjectVar> object_var( 134 scoped_refptr<NPObjectVar> object_var(
137 HostGlobals::Get()->host_resource_tracker()->NPObjectVarForNPObject( 135 ResourceTracker::Get()->NPObjectVarForNPObject(instance->pp_instance(),
138 instance->pp_instance(), object)); 136 object));
139 if (!object_var) { // No object for this module yet, make a new one. 137 if (!object_var) { // No object for this module yet, make a new one.
140 object_var = new NPObjectVar(instance->module()->pp_module(), 138 object_var = new NPObjectVar(instance->module()->pp_module(),
141 instance->pp_instance(), object); 139 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),
152 np_result_(np_result), 150 np_result_(np_result),
153 exception_(PP_MakeUndefined()), 151 exception_(PP_MakeUndefined()),
154 success_(false), 152 success_(false),
155 checked_exception_(false) { 153 checked_exception_(false) {
156 } 154 }
157 155
158 PPResultAndExceptionToNPResult::~PPResultAndExceptionToNPResult() { 156 PPResultAndExceptionToNPResult::~PPResultAndExceptionToNPResult() {
159 // The user should have called SetResult or CheckExceptionForNoResult 157 // The user should have called SetResult or CheckExceptionForNoResult
160 // before letting this class go out of scope, or the exception will have 158 // before letting this class go out of scope, or the exception will have
161 // been lost. 159 // been lost.
162 DCHECK(checked_exception_); 160 DCHECK(checked_exception_);
163 161
164 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(exception_); 162 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(exception_);
165 } 163 }
166 164
167 // Call this with the return value of the PPAPI function. It will convert 165 // Call this with the return value of the PPAPI function. It will convert
168 // the result to the NPVariant output parameter and pass any exception on to 166 // the result to the NPVariant output parameter and pass any exception on to
169 // the JS engine. It will update the success flag and return it. 167 // the JS engine. It will update the success flag and return it.
170 bool PPResultAndExceptionToNPResult::SetResult(PP_Var result) { 168 bool PPResultAndExceptionToNPResult::SetResult(PP_Var result) {
171 DCHECK(!checked_exception_); // Don't call more than once. 169 DCHECK(!checked_exception_); // Don't call more than once.
172 DCHECK(np_result_); // Should be expecting a result. 170 DCHECK(np_result_); // Should be expecting a result.
173 171
174 checked_exception_ = true; 172 checked_exception_ = true;
175 173
176 if (has_exception()) { 174 if (has_exception()) {
177 ThrowException(); 175 ThrowException();
178 success_ = false; 176 success_ = false;
179 } else if (!PPVarToNPVariant(result, np_result_)) { 177 } else if (!PPVarToNPVariant(result, np_result_)) {
180 WebBindings::setException(object_var_, kInvalidPluginValue); 178 WebBindings::setException(object_var_, kInvalidPluginValue);
181 success_ = false; 179 success_ = false;
182 } else { 180 } else {
183 success_ = true; 181 success_ = true;
184 } 182 }
185 183
186 // No matter what happened, we need to release the reference to the 184 // No matter what happened, we need to release the reference to the
187 // value passed in. On success, a reference to this value will be in 185 // value passed in. On success, a reference to this value will be in
188 // the np_result_. 186 // the np_result_.
189 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(result); 187 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(result);
190 return success_; 188 return success_;
191 } 189 }
192 190
193 // Call this after calling a PPAPI function that could have set the 191 // Call this after calling a PPAPI function that could have set the
194 // exception. It will pass the exception on to the JS engine and update 192 // exception. It will pass the exception on to the JS engine and update
195 // the success flag. 193 // the success flag.
196 // 194 //
197 // The success flag will be returned. 195 // The success flag will be returned.
198 bool PPResultAndExceptionToNPResult::CheckExceptionForNoResult() { 196 bool PPResultAndExceptionToNPResult::CheckExceptionForNoResult() {
199 DCHECK(!checked_exception_); // Don't call more than once. 197 DCHECK(!checked_exception_); // Don't call more than once.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 const NPVariant* variants) 229 const NPVariant* variants)
232 : size_(size) { 230 : size_(size) {
233 if (size_ > 0) { 231 if (size_ > 0) {
234 array_.reset(new PP_Var[size_]); 232 array_.reset(new PP_Var[size_]);
235 for (size_t i = 0; i < size_; i++) 233 for (size_t i = 0; i < size_; i++)
236 array_[i] = NPVariantToPPVar(instance, &variants[i]); 234 array_[i] = NPVariantToPPVar(instance, &variants[i]);
237 } 235 }
238 } 236 }
239 237
240 PPVarArrayFromNPVariantArray::~PPVarArrayFromNPVariantArray() { 238 PPVarArrayFromNPVariantArray::~PPVarArrayFromNPVariantArray() {
241 ::ppapi::VarTracker* var_tracker = PpapiGlobals::Get()->GetVarTracker(); 239 ::ppapi::VarTracker* var_tracker = ResourceTracker::Get()->GetVarTracker();
242 for (size_t i = 0; i < size_; i++) 240 for (size_t i = 0; i < size_; i++)
243 var_tracker->ReleaseVar(array_[i]); 241 var_tracker->ReleaseVar(array_[i]);
244 } 242 }
245 243
246 // PPVarFromNPObject ----------------------------------------------------------- 244 // PPVarFromNPObject -----------------------------------------------------------
247 245
248 PPVarFromNPObject::PPVarFromNPObject(PluginInstance* instance, NPObject* object) 246 PPVarFromNPObject::PPVarFromNPObject(PluginInstance* instance, NPObject* object)
249 : var_(NPObjectToPPVar(instance, object)) { 247 : var_(NPObjectToPPVar(instance, object)) {
250 } 248 }
251 249
252 PPVarFromNPObject::~PPVarFromNPObject() { 250 PPVarFromNPObject::~PPVarFromNPObject() {
253 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var_); 251 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(var_);
254 } 252 }
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(
266 object_->instance()->module()->pp_module(), identifier); 264 object_->instance()->module()->pp_module(), identifier);
267 if (identifier_.type == PP_VARTYPE_INT32 && !allow_integer_identifier) 265 if (identifier_.type == PP_VARTYPE_INT32 && !allow_integer_identifier)
268 identifier_.type = PP_VARTYPE_UNDEFINED; // Mark it invalid. 266 identifier_.type = PP_VARTYPE_UNDEFINED; // Mark it invalid.
269 } 267 }
270 } 268 }
271 269
272 NPObjectAccessorWithIdentifier::~NPObjectAccessorWithIdentifier() { 270 NPObjectAccessorWithIdentifier::~NPObjectAccessorWithIdentifier() {
273 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(identifier_); 271 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(identifier_);
274 } 272 }
275 273
276 // TryCatch -------------------------------------------------------------------- 274 // TryCatch --------------------------------------------------------------------
277 275
278 TryCatch::TryCatch(PP_Module module, PP_Var* exception) 276 TryCatch::TryCatch(PP_Module module, PP_Var* exception)
279 : pp_module_(module), 277 : pp_module_(module),
280 has_exception_(exception && exception->type != PP_VARTYPE_UNDEFINED), 278 has_exception_(exception && exception->type != PP_VARTYPE_UNDEFINED),
281 exception_(exception) { 279 exception_(exception) {
282 WebBindings::pushExceptionHandler(&TryCatch::Catch, this); 280 WebBindings::pushExceptionHandler(&TryCatch::Catch, this);
283 } 281 }
(...skipping 28 matching lines...) Expand all
312 } 310 }
313 } 311 }
314 312
315 // static 313 // static
316 void TryCatch::Catch(void* self, const char* message) { 314 void TryCatch::Catch(void* self, const char* message) {
317 static_cast<TryCatch*>(self)->SetException(message); 315 static_cast<TryCatch*>(self)->SetException(message);
318 } 316 }
319 317
320 } // namespace ppapi 318 } // namespace ppapi
321 } // namespace webkit 319 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/host_globals.cc ('k') | webkit/plugins/ppapi/npobject_var.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698