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

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

Issue 6731051: Fix up some reference counting when WebPluginImpl::scriptableObject is called. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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/message_channel.h ('k') | webkit/plugins/ppapi/plugin_object.cc » ('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/message_channel.h" 5 #include "webkit/plugins/ppapi/message_channel.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 275
276 MessageChannel::MessageChannelNPObject::~MessageChannelNPObject() {} 276 MessageChannel::MessageChannelNPObject::~MessageChannelNPObject() {}
277 277
278 MessageChannel::MessageChannel(PluginInstance* instance) 278 MessageChannel::MessageChannel(PluginInstance* instance)
279 : instance_(instance), 279 : instance_(instance),
280 passthrough_object_(NULL), 280 passthrough_object_(NULL),
281 np_object_(NULL), 281 np_object_(NULL),
282 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 282 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
283 VOID_TO_NPVARIANT(onmessage_invoker_); 283 VOID_TO_NPVARIANT(onmessage_invoker_);
284 284
285 // Now create an NPObject for receiving calls to postMessage. 285 // Now create an NPObject for receiving calls to postMessage. This sets the
286 // reference count to 1. We release it in the destructor.
286 NPObject* obj = WebBindings::createObject(NULL, &message_channel_class); 287 NPObject* obj = WebBindings::createObject(NULL, &message_channel_class);
287 DCHECK(obj); 288 DCHECK(obj);
288 np_object_ = static_cast<MessageChannel::MessageChannelNPObject*>(obj); 289 np_object_ = static_cast<MessageChannel::MessageChannelNPObject*>(obj);
289 np_object_->message_channel = this; 290 np_object_->message_channel = this;
290 } 291 }
291 292
292 bool MessageChannel::EvaluateOnMessageInvoker() { 293 bool MessageChannel::EvaluateOnMessageInvoker() {
293 // If we've already evaluated the function, just return. 294 // If we've already evaluated the function, just return.
294 if (NPVARIANT_IS_OBJECT(onmessage_invoker_)) 295 if (NPVARIANT_IS_OBJECT(onmessage_invoker_))
295 return true; 296 return true;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 &MessageChannel::PostMessageToNativeImpl, 375 &MessageChannel::PostMessageToNativeImpl,
375 var_copy)); 376 var_copy));
376 } 377 }
377 378
378 void MessageChannel::PostMessageToNativeImpl(PP_Var message_data) { 379 void MessageChannel::PostMessageToNativeImpl(PP_Var message_data) {
379 instance_->HandleMessage(message_data); 380 instance_->HandleMessage(message_data);
380 } 381 }
381 382
382 MessageChannel::~MessageChannel() { 383 MessageChannel::~MessageChannel() {
383 WebBindings::releaseObject(np_object_); 384 WebBindings::releaseObject(np_object_);
385 if (passthrough_object_)
386 WebBindings::releaseObject(passthrough_object_);
384 WebBindings::releaseVariantValue(&onmessage_invoker_); 387 WebBindings::releaseVariantValue(&onmessage_invoker_);
385 } 388 }
386 389
390 void MessageChannel::SetPassthroughObject(NPObject* passthrough) {
391 // Retain the passthrough object; We need to ensure it lives as long as this
392 // MessageChannel.
393 WebBindings::retainObject(passthrough);
394
395 // If we had a passthrough set already, release it. Note that we retain the
396 // incoming passthrough object first, so that we behave correctly if anyone
397 // invokes:
398 // SetPassthroughObject(passthrough_object());
399 if (passthrough_object_)
400 WebBindings::releaseObject(passthrough_object_);
401
402 passthrough_object_ = passthrough;
403 }
404
387 } // namespace ppapi 405 } // namespace ppapi
388 } // namespace webkit 406 } // namespace webkit
389 407
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/message_channel.h ('k') | webkit/plugins/ppapi/plugin_object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698