Chromium Code Reviews| 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/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 Loading... | |
| 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 Loading... | |
| 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 if (passthrough_object_) | |
| 392 WebBindings::releaseObject(passthrough_object_); | |
| 393 passthrough_object_ = passthrough; | |
| 394 // Retain the passthrough object; We need to ensure it lives as long as this | |
| 395 // MessageChannel. | |
| 396 WebBindings::retainObject(passthrough_object_); | |
|
piman
2011/03/29 17:36:10
Do you mind retaining before releasing ? Just in c
dmichael(do not use this one)
2011/03/29 18:03:21
Done. (Although I might argue that anyone doing t
| |
| 397 } | |
| 398 | |
| 387 } // namespace ppapi | 399 } // namespace ppapi |
| 388 } // namespace webkit | 400 } // namespace webkit |
| 389 | 401 |
| OLD | NEW |