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

Side by Side Diff: content/renderer/pepper/message_channel.cc

Issue 588083002: Use the correct v8 context for conversions when calling into the plugin from JS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « no previous file | content/renderer/pepper/pepper_plugin_instance_impl.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) 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 }; 89 };
90 90
91 // static 91 // static
92 gin::WrapperInfo MessageChannel::kWrapperInfo = {gin::kEmbedderNativeGin}; 92 gin::WrapperInfo MessageChannel::kWrapperInfo = {gin::kEmbedderNativeGin};
93 93
94 // static 94 // static
95 MessageChannel* MessageChannel::Create(PepperPluginInstanceImpl* instance, 95 MessageChannel* MessageChannel::Create(PepperPluginInstanceImpl* instance,
96 v8::Persistent<v8::Object>* result) { 96 v8::Persistent<v8::Object>* result) {
97 MessageChannel* message_channel = new MessageChannel(instance); 97 MessageChannel* message_channel = new MessageChannel(instance);
98 v8::HandleScope handle_scope(instance->GetIsolate()); 98 v8::HandleScope handle_scope(instance->GetIsolate());
99 v8::Context::Scope context_scope(instance->GetContext()); 99 v8::Context::Scope context_scope(instance->GetMainWorldContext());
100 gin::Handle<MessageChannel> handle = 100 gin::Handle<MessageChannel> handle =
101 gin::CreateHandle(instance->GetIsolate(), message_channel); 101 gin::CreateHandle(instance->GetIsolate(), message_channel);
102 result->Reset(instance->GetIsolate(), handle.ToV8()->ToObject()); 102 result->Reset(instance->GetIsolate(), handle.ToV8()->ToObject());
103 return message_channel; 103 return message_channel;
104 } 104 }
105 105
106 MessageChannel::~MessageChannel() { 106 MessageChannel::~MessageChannel() {
107 passthrough_object_.Reset(); 107 passthrough_object_.Reset();
108 if (instance_) 108 if (instance_)
109 instance_->MessageChannelDestroyed(); 109 instance_->MessageChannelDestroyed();
110 } 110 }
111 111
112 void MessageChannel::InstanceDeleted() { 112 void MessageChannel::InstanceDeleted() {
113 instance_ = NULL; 113 instance_ = NULL;
114 } 114 }
115 115
116 void MessageChannel::PostMessageToJavaScript(PP_Var message_data) { 116 void MessageChannel::PostMessageToJavaScript(PP_Var message_data) {
117 v8::HandleScope scope(v8::Isolate::GetCurrent()); 117 v8::HandleScope scope(v8::Isolate::GetCurrent());
118 118
119 // Because V8 is probably not on the stack for Native->JS calls, we need to 119 // Because V8 is probably not on the stack for Native->JS calls, we need to
120 // enter the appropriate context for the plugin. 120 // enter the appropriate context for the plugin.
121 v8::Local<v8::Context> context = instance_->GetContext(); 121 v8::Local<v8::Context> context = instance_->GetMainWorldContext();
122 if (context.IsEmpty()) 122 if (context.IsEmpty())
123 return; 123 return;
124 124
125 v8::Context::Scope context_scope(context); 125 v8::Context::Scope context_scope(context);
126 126
127 v8::Handle<v8::Value> v8_val; 127 v8::Handle<v8::Value> v8_val;
128 if (!V8VarConverter(instance_->pp_instance()) 128 if (!V8VarConverter(instance_->pp_instance())
129 .ToV8Value(message_data, context, &v8_val)) { 129 .ToV8Value(message_data, context, &v8_val)) {
130 PpapiGlobals::Get()->LogWithSource(instance_->pp_instance(), 130 PpapiGlobals::Get()->LogWithSource(instance_->pp_instance(),
131 PP_LOGLEVEL_ERROR, 131 PP_LOGLEVEL_ERROR,
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 while (!early_message_queue_.empty()) { 429 while (!early_message_queue_.empty()) {
430 PostMessageToJavaScriptImpl(early_message_queue_.front()); 430 PostMessageToJavaScriptImpl(early_message_queue_.front());
431 early_message_queue_.pop_front(); 431 early_message_queue_.pop_front();
432 } 432 }
433 early_message_queue_state_ = SEND_DIRECTLY; 433 early_message_queue_state_ = SEND_DIRECTLY;
434 434
435 DrainCompletedPluginMessages(); 435 DrainCompletedPluginMessages();
436 } 436 }
437 437
438 } // namespace content 438 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/pepper/pepper_plugin_instance_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698