| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/message_channel.h" | 5 #include "content/renderer/pepper/message_channel.h" |
| 6 | 6 |
| 7 #include <cstdlib> | 7 #include <cstdlib> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 // static | 85 // static |
| 86 gin::WrapperInfo MessageChannel::kWrapperInfo = {gin::kEmbedderNativeGin}; | 86 gin::WrapperInfo MessageChannel::kWrapperInfo = {gin::kEmbedderNativeGin}; |
| 87 | 87 |
| 88 // static | 88 // static |
| 89 MessageChannel* MessageChannel::Create(PepperPluginInstanceImpl* instance, | 89 MessageChannel* MessageChannel::Create(PepperPluginInstanceImpl* instance, |
| 90 v8::Persistent<v8::Object>* result) { | 90 v8::Persistent<v8::Object>* result) { |
| 91 MessageChannel* message_channel = new MessageChannel(instance); | 91 MessageChannel* message_channel = new MessageChannel(instance); |
| 92 v8::HandleScope handle_scope(instance->GetIsolate()); | 92 v8::HandleScope handle_scope(instance->GetIsolate()); |
| 93 v8::Context::Scope context_scope(instance->GetContext()); | 93 v8::Context::Scope context_scope(instance->GetMainWorldContext()); |
| 94 gin::Handle<MessageChannel> handle = | 94 gin::Handle<MessageChannel> handle = |
| 95 gin::CreateHandle(instance->GetIsolate(), message_channel); | 95 gin::CreateHandle(instance->GetIsolate(), message_channel); |
| 96 result->Reset(instance->GetIsolate(), handle.ToV8()->ToObject()); | 96 result->Reset(instance->GetIsolate(), handle.ToV8()->ToObject()); |
| 97 return message_channel; | 97 return message_channel; |
| 98 } | 98 } |
| 99 | 99 |
| 100 MessageChannel::~MessageChannel() { | 100 MessageChannel::~MessageChannel() { |
| 101 passthrough_object_.Reset(); | 101 passthrough_object_.Reset(); |
| 102 if (instance_) | 102 if (instance_) |
| 103 instance_->MessageChannelDestroyed(); | 103 instance_->MessageChannelDestroyed(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void MessageChannel::InstanceDeleted() { | 106 void MessageChannel::InstanceDeleted() { |
| 107 instance_ = NULL; | 107 instance_ = NULL; |
| 108 } | 108 } |
| 109 | 109 |
| 110 void MessageChannel::PostMessageToJavaScript(PP_Var message_data) { | 110 void MessageChannel::PostMessageToJavaScript(PP_Var message_data) { |
| 111 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 111 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 112 | 112 |
| 113 // Because V8 is probably not on the stack for Native->JS calls, we need to | 113 // Because V8 is probably not on the stack for Native->JS calls, we need to |
| 114 // enter the appropriate context for the plugin. | 114 // enter the appropriate context for the plugin. |
| 115 v8::Local<v8::Context> context = instance_->GetContext(); | 115 v8::Local<v8::Context> context = instance_->GetMainWorldContext(); |
| 116 if (context.IsEmpty()) | 116 if (context.IsEmpty()) |
| 117 return; | 117 return; |
| 118 | 118 |
| 119 v8::Context::Scope context_scope(context); | 119 v8::Context::Scope context_scope(context); |
| 120 | 120 |
| 121 v8::Handle<v8::Value> v8_val; | 121 v8::Handle<v8::Value> v8_val; |
| 122 if (!V8VarConverter(instance_->pp_instance()) | 122 if (!V8VarConverter(instance_->pp_instance()) |
| 123 .ToV8Value(message_data, context, &v8_val)) { | 123 .ToV8Value(message_data, context, &v8_val)) { |
| 124 PpapiGlobals::Get()->LogWithSource(instance_->pp_instance(), | 124 PpapiGlobals::Get()->LogWithSource(instance_->pp_instance(), |
| 125 PP_LOGLEVEL_ERROR, | 125 PP_LOGLEVEL_ERROR, |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 while (!early_message_queue_.empty()) { | 422 while (!early_message_queue_.empty()) { |
| 423 PostMessageToJavaScriptImpl(early_message_queue_.front()); | 423 PostMessageToJavaScriptImpl(early_message_queue_.front()); |
| 424 early_message_queue_.pop_front(); | 424 early_message_queue_.pop_front(); |
| 425 } | 425 } |
| 426 early_message_queue_state_ = SEND_DIRECTLY; | 426 early_message_queue_state_ = SEND_DIRECTLY; |
| 427 | 427 |
| 428 DrainCompletedPluginMessages(); | 428 DrainCompletedPluginMessages(); |
| 429 } | 429 } |
| 430 | 430 |
| 431 } // namespace content | 431 } // namespace content |
| OLD | NEW |