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

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

Issue 23330008: Introduce MockResourceConverter to modularize testing of V8VarConverter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | « no previous file | content/renderer/pepper/resource_converter.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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 ppapi::ScopedPPVar(ppapi::ScopedPPVar::PassRef(), 347 ppapi::ScopedPPVar(ppapi::ScopedPPVar::PassRef(),
348 StringVar::StringToPPVar( 348 StringVar::StringToPPVar(
349 NPVARIANT_TO_STRING(*variant).UTF8Characters, 349 NPVARIANT_TO_STRING(*variant).UTF8Characters,
350 NPVARIANT_TO_STRING(*variant).UTF8Length)), 350 NPVARIANT_TO_STRING(*variant).UTF8Length)),
351 true); 351 true);
352 return; 352 return;
353 case NPVariantType_Object: { 353 case NPVariantType_Object: {
354 // Calling WebBindings::toV8Value creates a wrapper around NPVariant so it 354 // Calling WebBindings::toV8Value creates a wrapper around NPVariant so it
355 // shouldn't result in a deep copy. 355 // shouldn't result in a deep copy.
356 v8::Handle<v8::Value> v8_value = WebBindings::toV8Value(variant); 356 v8::Handle<v8::Value> v8_value = WebBindings::toV8Value(variant);
357 V8VarConverter::FromV8Value(v8_value, v8::Context::GetCurrent(), 357 V8VarConverter().FromV8Value(v8_value, v8::Context::GetCurrent(),
358 base::Bind(&MessageChannel::NPVariantToPPVarComplete, 358 base::Bind(&MessageChannel::NPVariantToPPVarComplete,
359 weak_ptr_factory_.GetWeakPtr(), result_iterator)); 359 weak_ptr_factory_.GetWeakPtr(), result_iterator));
360 return; 360 return;
361 } 361 }
362 } 362 }
363 NPVariantToPPVarComplete(result_iterator, 363 NPVariantToPPVarComplete(result_iterator,
364 ppapi::ScopedPPVar(PP_MakeUndefined()), false); 364 ppapi::ScopedPPVar(PP_MakeUndefined()), false);
365 } 365 }
366 366
367 void MessageChannel::PostMessageToJavaScript(PP_Var message_data) { 367 void MessageChannel::PostMessageToJavaScript(PP_Var message_data) {
368 v8::HandleScope scope; 368 v8::HandleScope scope;
369 369
370 // Because V8 is probably not on the stack for Native->JS calls, we need to 370 // Because V8 is probably not on the stack for Native->JS calls, we need to
371 // enter the appropriate context for the plugin. 371 // enter the appropriate context for the plugin.
372 WebPluginContainer* container = instance_->container(); 372 WebPluginContainer* container = instance_->container();
373 // It's possible that container() is NULL if the plugin has been removed from 373 // It's possible that container() is NULL if the plugin has been removed from
374 // the DOM (but the PluginInstance is not destroyed yet). 374 // the DOM (but the PluginInstance is not destroyed yet).
375 if (!container) 375 if (!container)
376 return; 376 return;
377 377
378 v8::Local<v8::Context> context = 378 v8::Local<v8::Context> context =
379 container->element().document().frame()->mainWorldScriptContext(); 379 container->element().document().frame()->mainWorldScriptContext();
380 // If the page is being destroyed, the context may be empty. 380 // If the page is being destroyed, the context may be empty.
381 if (context.IsEmpty()) 381 if (context.IsEmpty())
382 return; 382 return;
383 v8::Context::Scope context_scope(context); 383 v8::Context::Scope context_scope(context);
384 384
385 v8::Handle<v8::Value> v8_val; 385 v8::Handle<v8::Value> v8_val;
386 if (!V8VarConverter::ToV8Value(message_data, context, &v8_val)) { 386 if (!V8VarConverter().ToV8Value(message_data, context, &v8_val)) {
387 PpapiGlobals::Get()->LogWithSource(instance_->pp_instance(), 387 PpapiGlobals::Get()->LogWithSource(instance_->pp_instance(),
388 PP_LOGLEVEL_ERROR, std::string(), kVarToV8ConversionError); 388 PP_LOGLEVEL_ERROR, std::string(), kVarToV8ConversionError);
389 return; 389 return;
390 } 390 }
391 391
392 // This is for backward compatibility. It usually makes sense for us to return 392 // This is for backward compatibility. It usually makes sense for us to return
393 // a string object rather than a string primitive because it allows multiple 393 // a string object rather than a string primitive because it allows multiple
394 // references to the same string (as with PP_Var strings). However, prior to 394 // references to the same string (as with PP_Var strings). However, prior to
395 // implementing dictionary and array, vars we would return a string primitive 395 // implementing dictionary and array, vars we would return a string primitive
396 // here. Changing it to an object now will break existing code that uses 396 // here. Changing it to an object now will break existing code that uses
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 // incoming passthrough object first, so that we behave correctly if anyone 549 // incoming passthrough object first, so that we behave correctly if anyone
550 // invokes: 550 // invokes:
551 // SetPassthroughObject(passthrough_object()); 551 // SetPassthroughObject(passthrough_object());
552 if (passthrough_object_) 552 if (passthrough_object_)
553 WebBindings::releaseObject(passthrough_object_); 553 WebBindings::releaseObject(passthrough_object_);
554 554
555 passthrough_object_ = passthrough; 555 passthrough_object_ = passthrough;
556 } 556 }
557 557
558 } // namespace content 558 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/pepper/resource_converter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698