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

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

Issue 1113783002: Use Local instead of Handle in src/content/* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 v8::HandleScope scope(v8::Isolate::GetCurrent()); 114 v8::HandleScope scope(v8::Isolate::GetCurrent());
115 115
116 // Because V8 is probably not on the stack for Native->JS calls, we need to 116 // Because V8 is probably not on the stack for Native->JS calls, we need to
117 // enter the appropriate context for the plugin. 117 // enter the appropriate context for the plugin.
118 v8::Local<v8::Context> context = instance_->GetMainWorldContext(); 118 v8::Local<v8::Context> context = instance_->GetMainWorldContext();
119 if (context.IsEmpty()) 119 if (context.IsEmpty())
120 return; 120 return;
121 121
122 v8::Context::Scope context_scope(context); 122 v8::Context::Scope context_scope(context);
123 123
124 v8::Handle<v8::Value> v8_val; 124 v8::Local<v8::Value> v8_val;
125 if (!var_converter_.ToV8Value(message_data, context, &v8_val)) { 125 if (!var_converter_.ToV8Value(message_data, context, &v8_val)) {
126 PpapiGlobals::Get()->LogWithSource(instance_->pp_instance(), 126 PpapiGlobals::Get()->LogWithSource(instance_->pp_instance(),
127 PP_LOGLEVEL_ERROR, 127 PP_LOGLEVEL_ERROR,
128 std::string(), 128 std::string(),
129 kVarToV8ConversionError); 129 kVarToV8ConversionError);
130 return; 130 return;
131 } 131 }
132 132
133 WebSerializedScriptValue serialized_val = 133 WebSerializedScriptValue serialized_val =
134 WebSerializedScriptValue::serialize(v8_val); 134 WebSerializedScriptValue::serialize(v8_val);
(...skipping 25 matching lines...) Expand all
160 160
161 // We can't drain the JS message queue directly since we haven't finished 161 // We can't drain the JS message queue directly since we haven't finished
162 // initializing the PepperWebPluginImpl yet, so the plugin isn't available in 162 // initializing the PepperWebPluginImpl yet, so the plugin isn't available in
163 // the DOM. 163 // the DOM.
164 DrainJSMessageQueueSoon(); 164 DrainJSMessageQueueSoon();
165 165
166 plugin_message_queue_state_ = SEND_DIRECTLY; 166 plugin_message_queue_state_ = SEND_DIRECTLY;
167 DrainCompletedPluginMessages(); 167 DrainCompletedPluginMessages();
168 } 168 }
169 169
170 void MessageChannel::SetPassthroughObject(v8::Handle<v8::Object> passthrough) { 170 void MessageChannel::SetPassthroughObject(v8::Local<v8::Object> passthrough) {
171 passthrough_object_.Reset(instance_->GetIsolate(), passthrough); 171 passthrough_object_.Reset(instance_->GetIsolate(), passthrough);
172 } 172 }
173 173
174 void MessageChannel::SetReadOnlyProperty(PP_Var key, PP_Var value) { 174 void MessageChannel::SetReadOnlyProperty(PP_Var key, PP_Var value) {
175 StringVar* key_string = StringVar::FromPPVar(key); 175 StringVar* key_string = StringVar::FromPPVar(key);
176 if (key_string) { 176 if (key_string) {
177 internal_named_properties_[key_string->value()] = ScopedPPVar(value); 177 internal_named_properties_[key_string->value()] = ScopedPPVar(value);
178 } else { 178 } else {
179 NOTREACHED(); 179 NOTREACHED();
180 } 180 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 ->GetFunction(); 223 ->GetFunction();
224 } else if (identifier == kPostMessageAndAwaitResponse) { 224 } else if (identifier == kPostMessageAndAwaitResponse) {
225 return GetFunctionTemplate(isolate, identifier, 225 return GetFunctionTemplate(isolate, identifier,
226 &MessageChannel::PostBlockingMessageToNative) 226 &MessageChannel::PostBlockingMessageToNative)
227 ->GetFunction(); 227 ->GetFunction();
228 } 228 }
229 229
230 std::map<std::string, ScopedPPVar>::const_iterator it = 230 std::map<std::string, ScopedPPVar>::const_iterator it =
231 internal_named_properties_.find(identifier); 231 internal_named_properties_.find(identifier);
232 if (it != internal_named_properties_.end()) { 232 if (it != internal_named_properties_.end()) {
233 v8::Handle<v8::Value> result = try_catch.ToV8(it->second.get()); 233 v8::Local<v8::Value> result = try_catch.ToV8(it->second.get());
234 if (try_catch.ThrowException()) 234 if (try_catch.ThrowException())
235 return v8::Local<v8::Value>(); 235 return v8::Local<v8::Value>();
236 return result; 236 return result;
237 } 237 }
238 238
239 PluginObject* plugin_object = GetPluginObject(isolate); 239 PluginObject* plugin_object = GetPluginObject(isolate);
240 if (plugin_object) 240 if (plugin_object)
241 return plugin_object->GetNamedProperty(isolate, identifier); 241 return plugin_object->GetNamedProperty(isolate, identifier);
242 return v8::Local<v8::Value>(); 242 return v8::Local<v8::Value>();
243 } 243 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 277
278 void MessageChannel::PostMessageToNative(gin::Arguments* args) { 278 void MessageChannel::PostMessageToNative(gin::Arguments* args) {
279 if (!instance_) 279 if (!instance_)
280 return; 280 return;
281 if (args->Length() != 1) { 281 if (args->Length() != 1) {
282 // TODO(raymes): Consider throwing an exception here. We don't now for 282 // TODO(raymes): Consider throwing an exception here. We don't now for
283 // backward compatibility. 283 // backward compatibility.
284 return; 284 return;
285 } 285 }
286 286
287 v8::Handle<v8::Value> message_data; 287 v8::Local<v8::Value> message_data;
288 if (!args->GetNext(&message_data)) { 288 if (!args->GetNext(&message_data)) {
289 NOTREACHED(); 289 NOTREACHED();
290 } 290 }
291 291
292 EnqueuePluginMessage(message_data); 292 EnqueuePluginMessage(message_data);
293 DrainCompletedPluginMessages(); 293 DrainCompletedPluginMessages();
294 } 294 }
295 295
296 void MessageChannel::PostBlockingMessageToNative(gin::Arguments* args) { 296 void MessageChannel::PostBlockingMessageToNative(gin::Arguments* args) {
297 if (!instance_) 297 if (!instance_)
298 return; 298 return;
299 PepperTryCatchV8 try_catch(instance_, &var_converter_, args->isolate()); 299 PepperTryCatchV8 try_catch(instance_, &var_converter_, args->isolate());
300 if (args->Length() != 1) { 300 if (args->Length() != 1) {
301 try_catch.ThrowException( 301 try_catch.ThrowException(
302 "postMessageAndAwaitResponse requires one argument"); 302 "postMessageAndAwaitResponse requires one argument");
303 return; 303 return;
304 } 304 }
305 305
306 v8::Handle<v8::Value> message_data; 306 v8::Local<v8::Value> message_data;
307 if (!args->GetNext(&message_data)) { 307 if (!args->GetNext(&message_data)) {
308 NOTREACHED(); 308 NOTREACHED();
309 } 309 }
310 310
311 if (plugin_message_queue_state_ == WAITING_TO_START) { 311 if (plugin_message_queue_state_ == WAITING_TO_START) {
312 try_catch.ThrowException( 312 try_catch.ThrowException(
313 "Attempted to call a synchronous method on a plugin that was not " 313 "Attempted to call a synchronous method on a plugin that was not "
314 "yet loaded."); 314 "yet loaded.");
315 return; 315 return;
316 } 316 }
(...skipping 21 matching lines...) Expand all
338 338
339 ScopedPPVar pp_result; 339 ScopedPPVar pp_result;
340 bool was_handled = instance_->HandleBlockingMessage(param, &pp_result); 340 bool was_handled = instance_->HandleBlockingMessage(param, &pp_result);
341 if (!was_handled) { 341 if (!was_handled) {
342 try_catch.ThrowException( 342 try_catch.ThrowException(
343 "The plugin has not registered a handler for synchronous messages. " 343 "The plugin has not registered a handler for synchronous messages. "
344 "See the documentation for PPB_Messaging::RegisterMessageHandler " 344 "See the documentation for PPB_Messaging::RegisterMessageHandler "
345 "and PPP_MessageHandler."); 345 "and PPP_MessageHandler.");
346 return; 346 return;
347 } 347 }
348 v8::Handle<v8::Value> v8_result = try_catch.ToV8(pp_result.get()); 348 v8::Local<v8::Value> v8_result = try_catch.ToV8(pp_result.get());
349 if (try_catch.ThrowException()) 349 if (try_catch.ThrowException())
350 return; 350 return;
351 351
352 args->Return(v8_result); 352 args->Return(v8_result);
353 } 353 }
354 354
355 void MessageChannel::PostMessageToJavaScriptImpl( 355 void MessageChannel::PostMessageToJavaScriptImpl(
356 const WebSerializedScriptValue& message_data) { 356 const WebSerializedScriptValue& message_data) {
357 DCHECK(instance_); 357 DCHECK(instance_);
358 358
(...skipping 22 matching lines...) Expand all
381 // TODO(dmichael): Add origin if we change to a more iframe-like origin 381 // TODO(dmichael): Add origin if we change to a more iframe-like origin
382 // policy (see crbug.com/81537) 382 // policy (see crbug.com/81537)
383 container->element().dispatchEvent(msg_event); 383 container->element().dispatchEvent(msg_event);
384 } 384 }
385 385
386 PluginObject* MessageChannel::GetPluginObject(v8::Isolate* isolate) { 386 PluginObject* MessageChannel::GetPluginObject(v8::Isolate* isolate) {
387 return PluginObject::FromV8Object(isolate, 387 return PluginObject::FromV8Object(isolate,
388 v8::Local<v8::Object>::New(isolate, passthrough_object_)); 388 v8::Local<v8::Object>::New(isolate, passthrough_object_));
389 } 389 }
390 390
391 void MessageChannel::EnqueuePluginMessage(v8::Handle<v8::Value> v8_value) { 391 void MessageChannel::EnqueuePluginMessage(v8::Local<v8::Value> v8_value) {
392 plugin_message_queue_.push_back(VarConversionResult()); 392 plugin_message_queue_.push_back(VarConversionResult());
393 // Convert the v8 value in to an appropriate PP_Var like Dictionary, 393 // Convert the v8 value in to an appropriate PP_Var like Dictionary,
394 // Array, etc. (We explicitly don't want an "Object" PP_Var, which we don't 394 // Array, etc. (We explicitly don't want an "Object" PP_Var, which we don't
395 // support for Messaging.) 395 // support for Messaging.)
396 // TODO(raymes): Possibly change this to use TryCatch to do the conversion and 396 // TODO(raymes): Possibly change this to use TryCatch to do the conversion and
397 // throw an exception if necessary. 397 // throw an exception if necessary.
398 V8VarConverter::VarResult conversion_result = 398 V8VarConverter::VarResult conversion_result =
399 var_converter_.FromV8Value( 399 var_converter_.FromV8Value(
400 v8_value, 400 v8_value,
401 v8::Isolate::GetCurrent()->GetCurrentContext(), 401 v8::Isolate::GetCurrent()->GetCurrentContext(),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 v8::Local<v8::FunctionTemplate> function_template = template_cache_.Get(name); 476 v8::Local<v8::FunctionTemplate> function_template = template_cache_.Get(name);
477 if (!function_template.IsEmpty()) 477 if (!function_template.IsEmpty())
478 return function_template; 478 return function_template;
479 function_template = gin::CreateFunctionTemplate( 479 function_template = gin::CreateFunctionTemplate(
480 isolate, base::Bind(memberFuncPtr, weak_ptr_factory_.GetWeakPtr())); 480 isolate, base::Bind(memberFuncPtr, weak_ptr_factory_.GetWeakPtr()));
481 template_cache_.Set(name, function_template); 481 template_cache_.Set(name, function_template);
482 return function_template; 482 return function_template;
483 } 483 }
484 484
485 } // namespace content 485 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/message_channel.h ('k') | content/renderer/pepper/pepper_plugin_instance_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698