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

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

Issue 512983004: Revert of Replace NPObject usage in ppapi with gin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
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/pepper_plugin_instance_impl.h" 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 15 matching lines...) Expand all
26 #include "content/public/common/page_zoom.h" 26 #include "content/public/common/page_zoom.h"
27 #include "content/public/renderer/content_renderer_client.h" 27 #include "content/public/renderer/content_renderer_client.h"
28 #include "content/renderer/gpu/render_widget_compositor.h" 28 #include "content/renderer/gpu/render_widget_compositor.h"
29 #include "content/renderer/pepper/content_decryptor_delegate.h" 29 #include "content/renderer/pepper/content_decryptor_delegate.h"
30 #include "content/renderer/pepper/event_conversion.h" 30 #include "content/renderer/pepper/event_conversion.h"
31 #include "content/renderer/pepper/fullscreen_container.h" 31 #include "content/renderer/pepper/fullscreen_container.h"
32 #include "content/renderer/pepper/gfx_conversion.h" 32 #include "content/renderer/pepper/gfx_conversion.h"
33 #include "content/renderer/pepper/host_dispatcher_wrapper.h" 33 #include "content/renderer/pepper/host_dispatcher_wrapper.h"
34 #include "content/renderer/pepper/host_globals.h" 34 #include "content/renderer/pepper/host_globals.h"
35 #include "content/renderer/pepper/message_channel.h" 35 #include "content/renderer/pepper/message_channel.h"
36 #include "content/renderer/pepper/npapi_glue.h"
36 #include "content/renderer/pepper/pepper_browser_connection.h" 37 #include "content/renderer/pepper/pepper_browser_connection.h"
37 #include "content/renderer/pepper/pepper_compositor_host.h" 38 #include "content/renderer/pepper/pepper_compositor_host.h"
38 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" 39 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h"
39 #include "content/renderer/pepper/pepper_graphics_2d_host.h" 40 #include "content/renderer/pepper/pepper_graphics_2d_host.h"
40 #include "content/renderer/pepper/pepper_in_process_router.h" 41 #include "content/renderer/pepper/pepper_in_process_router.h"
41 #include "content/renderer/pepper/pepper_try_catch.h"
42 #include "content/renderer/pepper/pepper_url_loader_host.h" 42 #include "content/renderer/pepper/pepper_url_loader_host.h"
43 #include "content/renderer/pepper/plugin_module.h" 43 #include "content/renderer/pepper/plugin_module.h"
44 #include "content/renderer/pepper/plugin_object.h" 44 #include "content/renderer/pepper/plugin_object.h"
45 #include "content/renderer/pepper/ppapi_preferences_builder.h" 45 #include "content/renderer/pepper/ppapi_preferences_builder.h"
46 #include "content/renderer/pepper/ppb_buffer_impl.h" 46 #include "content/renderer/pepper/ppb_buffer_impl.h"
47 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" 47 #include "content/renderer/pepper/ppb_graphics_3d_impl.h"
48 #include "content/renderer/pepper/ppb_image_data_impl.h" 48 #include "content/renderer/pepper/ppb_image_data_impl.h"
49 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" 49 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
50 #include "content/renderer/pepper/url_request_info_util.h" 50 #include "content/renderer/pepper/url_request_info_util.h"
51 #include "content/renderer/pepper/url_response_info_util.h" 51 #include "content/renderer/pepper/url_response_info_util.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 108 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
109 #include "third_party/WebKit/public/web/WebDataSource.h" 109 #include "third_party/WebKit/public/web/WebDataSource.h"
110 #include "third_party/WebKit/public/web/WebDocument.h" 110 #include "third_party/WebKit/public/web/WebDocument.h"
111 #include "third_party/WebKit/public/web/WebElement.h" 111 #include "third_party/WebKit/public/web/WebElement.h"
112 #include "third_party/WebKit/public/web/WebInputEvent.h" 112 #include "third_party/WebKit/public/web/WebInputEvent.h"
113 #include "third_party/WebKit/public/web/WebLocalFrame.h" 113 #include "third_party/WebKit/public/web/WebLocalFrame.h"
114 #include "third_party/WebKit/public/web/WebPluginContainer.h" 114 #include "third_party/WebKit/public/web/WebPluginContainer.h"
115 #include "third_party/WebKit/public/web/WebPrintParams.h" 115 #include "third_party/WebKit/public/web/WebPrintParams.h"
116 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" 116 #include "third_party/WebKit/public/web/WebPrintScalingOption.h"
117 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" 117 #include "third_party/WebKit/public/web/WebScopedUserGesture.h"
118 #include "third_party/WebKit/public/web/WebScriptSource.h"
119 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 118 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
120 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 119 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
121 #include "third_party/WebKit/public/web/WebView.h" 120 #include "third_party/WebKit/public/web/WebView.h"
122 #include "third_party/khronos/GLES2/gl2.h" 121 #include "third_party/khronos/GLES2/gl2.h"
123 #include "third_party/skia/include/core/SkCanvas.h" 122 #include "third_party/skia/include/core/SkCanvas.h"
124 #include "third_party/skia/include/core/SkRect.h" 123 #include "third_party/skia/include/core/SkRect.h"
125 #include "ui/gfx/image/image_skia.h" 124 #include "ui/gfx/image/image_skia.h"
126 #include "ui/gfx/image/image_skia_rep.h" 125 #include "ui/gfx/image/image_skia_rep.h"
127 #include "ui/gfx/range/range.h" 126 #include "ui/gfx/range/range.h"
128 #include "ui/gfx/rect_conversions.h" 127 #include "ui/gfx/rect_conversions.h"
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 filtered_input_event_mask_(0), 552 filtered_input_event_mask_(0),
554 text_input_type_(kPluginDefaultTextInputType), 553 text_input_type_(kPluginDefaultTextInputType),
555 text_input_caret_(0, 0, 0, 0), 554 text_input_caret_(0, 0, 0, 0),
556 text_input_caret_bounds_(0, 0, 0, 0), 555 text_input_caret_bounds_(0, 0, 0, 0),
557 text_input_caret_set_(false), 556 text_input_caret_set_(false),
558 selection_caret_(0), 557 selection_caret_(0),
559 selection_anchor_(0), 558 selection_anchor_(0),
560 pending_user_gesture_(0.0), 559 pending_user_gesture_(0.0),
561 document_loader_(NULL), 560 document_loader_(NULL),
562 external_document_load_(false), 561 external_document_load_(false),
562 npp_(new NPP_t),
563 isolate_(v8::Isolate::GetCurrent()), 563 isolate_(v8::Isolate::GetCurrent()),
564 is_deleted_(false), 564 is_deleted_(false),
565 last_input_number_(0), 565 last_input_number_(0),
566 is_tracking_latency_(false), 566 is_tracking_latency_(false),
567 view_change_weak_ptr_factory_(this), 567 view_change_weak_ptr_factory_(this),
568 weak_factory_(this) { 568 weak_factory_(this) {
569 pp_instance_ = HostGlobals::Get()->AddInstance(this); 569 pp_instance_ = HostGlobals::Get()->AddInstance(this);
570 570
571 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 571 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
572 module_->InstanceCreated(this); 572 module_->InstanceCreated(this);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); 613 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this);
614 614
615 if (GetContentClient()->renderer() && // NULL in unit tests. 615 if (GetContentClient()->renderer() && // NULL in unit tests.
616 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) 616 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name()))
617 external_document_load_ = true; 617 external_document_load_ = true;
618 } 618 }
619 619
620 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { 620 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() {
621 DCHECK(!fullscreen_container_); 621 DCHECK(!fullscreen_container_);
622 622
623 // Notify all the plugin objects of deletion. This will prevent blink from 623 // Free all the plugin objects. This will automatically clear the back-
624 // calling into the plugin any more. 624 // pointer from the NPObject so WebKit can't call into the plugin any more.
625 // 625 //
626 // Swap out the set so we can delete from it (the objects will try to 626 // Swap out the set so we can delete from it (the objects will try to
627 // unregister themselves inside the delete call). 627 // unregister themselves inside the delete call).
628 PluginObjectSet plugin_object_copy; 628 PluginObjectSet plugin_object_copy;
629 live_plugin_objects_.swap(plugin_object_copy); 629 live_plugin_objects_.swap(plugin_object_copy);
630 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); 630 for (PluginObjectSet::iterator i = plugin_object_copy.begin();
631 i != plugin_object_copy.end(); 631 i != plugin_object_copy.end();
632 ++i) { 632 ++i)
633 (*i)->InstanceDeleted(); 633 delete *i;
634 }
635 634
636 if (TrackedCallback::IsPending(lock_mouse_callback_)) 635 if (TrackedCallback::IsPending(lock_mouse_callback_))
637 lock_mouse_callback_->Abort(); 636 lock_mouse_callback_->Abort();
638 637
639 if (!instance_deleted_callback_.is_null()) 638 if (!instance_deleted_callback_.is_null())
640 instance_deleted_callback_.Run(); 639 instance_deleted_callback_.Run();
641 640
642 if (!module_->IsProxied() && render_frame_) { 641 if (!module_->IsProxied() && render_frame_) {
643 PepperBrowserConnection* browser_connection = 642 PepperBrowserConnection* browser_connection =
644 PepperBrowserConnection::Get(render_frame_); 643 PepperBrowserConnection::Get(render_frame_);
645 browser_connection->DidDeleteInProcessInstance(pp_instance()); 644 browser_connection->DidDeleteInProcessInstance(pp_instance());
646 } 645 }
647 646
648 UnSetAndDeleteLockTargetAdapter(); 647 UnSetAndDeleteLockTargetAdapter();
649 module_->InstanceDeleted(this); 648 module_->InstanceDeleted(this);
650 // If we switched from the NaCl plugin module, notify it too. 649 // If we switched from the NaCl plugin module, notify it too.
651 if (original_module_.get()) 650 if (original_module_.get())
652 original_module_->InstanceDeleted(this); 651 original_module_->InstanceDeleted(this);
653 652
654 // This should be last since some of the above "instance deleted" calls will 653 // This should be last since some of the above "instance deleted" calls will
655 // want to look up in the global map to get info off of our object. 654 // want to look up in the global map to get info off of our object.
656 HostGlobals::Get()->InstanceDeleted(pp_instance_); 655 HostGlobals::Get()->InstanceDeleted(pp_instance_);
657
658 message_channel_object_.Reset();
659 message_channel_ = NULL;
660 } 656 }
661 657
662 // NOTE: Any of these methods that calls into the plugin needs to take into 658 // NOTE: Any of these methods that calls into the plugin needs to take into
663 // account that the plugin may use Var to remove the <embed> from the DOM, which 659 // account that the plugin may use Var to remove the <embed> from the DOM, which
664 // will make the PepperWebPluginImpl drop its reference, usually the last one. 660 // will make the PepperWebPluginImpl drop its reference, usually the last one.
665 // If a method needs to access a member of the instance after the call has 661 // If a method needs to access a member of the instance after the call has
666 // returned, then it needs to keep its own reference on the stack. 662 // returned, then it needs to keep its own reference on the stack.
667 663
668 v8::Local<v8::Object> PepperPluginInstanceImpl::GetMessageChannelObject() {
669 return v8::Local<v8::Object>::New(isolate_, message_channel_object_);
670 }
671
672 v8::Local<v8::Context> PepperPluginInstanceImpl::GetContext() { 664 v8::Local<v8::Context> PepperPluginInstanceImpl::GetContext() {
673 if (!container_) 665 if (!container_)
674 return v8::Handle<v8::Context>(); 666 return v8::Handle<v8::Context>();
675 WebLocalFrame* frame = container_->element().document().frame(); 667 WebLocalFrame* frame = container_->element().document().frame();
676 if (!frame) 668 if (!frame)
677 return v8::Handle<v8::Context>(); 669 return v8::Handle<v8::Context>();
678 670
679 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); 671 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
680 DCHECK(context->GetIsolate() == isolate_); 672 DCHECK(context->GetIsolate() == isolate_);
681 return context; 673 return context;
682 } 674 }
683 675
684 void PepperPluginInstanceImpl::Delete() { 676 void PepperPluginInstanceImpl::Delete() {
685 is_deleted_ = true; 677 is_deleted_ = true;
686 678
687 if (render_frame_ && 679 if (render_frame_ &&
688 render_frame_->render_view()->plugin_find_handler() == this) { 680 render_frame_->render_view()->plugin_find_handler() == this) {
689 render_frame_->render_view()->set_plugin_find_handler(NULL); 681 render_frame_->render_view()->set_plugin_find_handler(NULL);
690 } 682 }
691 683
692 // Keep a reference on the stack. See NOTE above. 684 // Keep a reference on the stack. See NOTE above.
693 scoped_refptr<PepperPluginInstanceImpl> ref(this); 685 scoped_refptr<PepperPluginInstanceImpl> ref(this);
694 // Force the MessageChannel to release its "passthrough object" which should 686 // Force the MessageChannel to release its "passthrough object" which should
695 // release our last reference to the "InstanceObject" and will probably 687 // release our last reference to the "InstanceObject" and will probably
696 // destroy it. We want to do this prior to calling DidDestroy in case the 688 // destroy it. We want to do this prior to calling DidDestroy in case the
697 // destructor of the instance object tries to use the instance. 689 // destructor of the instance object tries to use the instance.
698 message_channel_->SetPassthroughObject(v8::Handle<v8::Object>()); 690 message_channel_->SetPassthroughObject(NULL);
699 // If this is a NaCl plugin instance, shut down the NaCl plugin by calling 691 // If this is a NaCl plugin instance, shut down the NaCl plugin by calling
700 // its DidDestroy. Don't call DidDestroy on the untrusted plugin instance, 692 // its DidDestroy. Don't call DidDestroy on the untrusted plugin instance,
701 // since there is little that it can do at this point. 693 // since there is little that it can do at this point.
702 if (original_instance_interface_) 694 if (original_instance_interface_)
703 original_instance_interface_->DidDestroy(pp_instance()); 695 original_instance_interface_->DidDestroy(pp_instance());
704 else 696 else
705 instance_interface_->DidDestroy(pp_instance()); 697 instance_interface_->DidDestroy(pp_instance());
706 // Ensure we don't attempt to call functions on the destroyed instance. 698 // Ensure we don't attempt to call functions on the destroyed instance.
707 original_instance_interface_.reset(); 699 original_instance_interface_.reset();
708 instance_interface_.reset(); 700 instance_interface_.reset();
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8); 842 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8);
851 #endif 843 #endif
852 } 844 }
853 845
854 bool PepperPluginInstanceImpl::Initialize( 846 bool PepperPluginInstanceImpl::Initialize(
855 const std::vector<std::string>& arg_names, 847 const std::vector<std::string>& arg_names,
856 const std::vector<std::string>& arg_values, 848 const std::vector<std::string>& arg_values,
857 bool full_frame) { 849 bool full_frame) {
858 if (!render_frame_) 850 if (!render_frame_)
859 return false; 851 return false;
860 message_channel_ = MessageChannel::Create(this, &message_channel_object_); 852 message_channel_.reset(new MessageChannel(this));
861 853
862 full_frame_ = full_frame; 854 full_frame_ = full_frame;
863 855
864 UpdateTouchEventRequest(); 856 UpdateTouchEventRequest();
865 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); 857 container_->setWantsWheelEvents(IsAcceptingWheelEvents());
866 858
867 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( 859 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build(
868 render_frame_->render_view()->webkit_preferences())), 860 render_frame_->render_view()->webkit_preferences())),
869 arg_names, 861 arg_names,
870 arg_values); 862 arg_values);
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(), 1211 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(),
1220 pp_instance()), 1212 pp_instance()),
1221 &msg_reply, 1213 &msg_reply,
1222 &was_handled)); 1214 &was_handled));
1223 *result = ScopedPPVar(ScopedPPVar::PassRef(), msg_reply.Return(dispatcher)); 1215 *result = ScopedPPVar(ScopedPPVar::PassRef(), msg_reply.Return(dispatcher));
1224 TRACE_EVENT0("ppapi", 1216 TRACE_EVENT0("ppapi",
1225 "PepperPluginInstanceImpl::HandleBlockingMessage return."); 1217 "PepperPluginInstanceImpl::HandleBlockingMessage return.");
1226 return was_handled; 1218 return was_handled;
1227 } 1219 }
1228 1220
1229 PP_Var PepperPluginInstanceImpl::GetInstanceObject(v8::Isolate* isolate) { 1221 PP_Var PepperPluginInstanceImpl::GetInstanceObject() {
1230 // Keep a reference on the stack. See NOTE above. 1222 // Keep a reference on the stack. See NOTE above.
1231 scoped_refptr<PepperPluginInstanceImpl> ref(this); 1223 scoped_refptr<PepperPluginInstanceImpl> ref(this);
1232 1224
1233 DCHECK_EQ(isolate, isolate_);
1234
1235 // If the plugin supports the private instance interface, try to retrieve its 1225 // If the plugin supports the private instance interface, try to retrieve its
1236 // instance object. 1226 // instance object.
1237 if (LoadPrivateInterface()) 1227 if (LoadPrivateInterface())
1238 return plugin_private_interface_->GetInstanceObject(pp_instance()); 1228 return plugin_private_interface_->GetInstanceObject(pp_instance());
1239 return PP_MakeUndefined(); 1229 return PP_MakeUndefined();
1240 } 1230 }
1241 1231
1242 void PepperPluginInstanceImpl::ViewChanged( 1232 void PepperPluginInstanceImpl::ViewChanged(
1243 const gfx::Rect& position, 1233 const gfx::Rect& position,
1244 const gfx::Rect& clip, 1234 const gfx::Rect& clip,
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 } 2353 }
2364 2354
2365 PP_Bool PepperPluginInstanceImpl::FlashIsFullscreen(PP_Instance instance) { 2355 PP_Bool PepperPluginInstanceImpl::FlashIsFullscreen(PP_Instance instance) {
2366 return PP_FromBool(flash_fullscreen_); 2356 return PP_FromBool(flash_fullscreen_);
2367 } 2357 }
2368 2358
2369 PP_Var PepperPluginInstanceImpl::GetWindowObject(PP_Instance instance) { 2359 PP_Var PepperPluginInstanceImpl::GetWindowObject(PP_Instance instance) {
2370 if (!container_) 2360 if (!container_)
2371 return PP_MakeUndefined(); 2361 return PP_MakeUndefined();
2372 2362
2373 PepperTryCatchVar try_catch(this, NULL);
2374 WebLocalFrame* frame = container_->element().document().frame(); 2363 WebLocalFrame* frame = container_->element().document().frame();
2375 if (!frame) { 2364 if (!frame)
2376 try_catch.SetException("No frame exists for window object.");
2377 return PP_MakeUndefined(); 2365 return PP_MakeUndefined();
2378 }
2379 2366
2380 ScopedPPVar result = 2367 return NPObjectToPPVar(this, frame->windowObject());
2381 try_catch.FromV8(frame->mainWorldScriptContext()->Global());
2382 DCHECK(!try_catch.HasException());
2383 return result.Release();
2384 } 2368 }
2385 2369
2386 PP_Var PepperPluginInstanceImpl::GetOwnerElementObject(PP_Instance instance) { 2370 PP_Var PepperPluginInstanceImpl::GetOwnerElementObject(PP_Instance instance) {
2387 if (!container_) 2371 if (!container_)
2388 return PP_MakeUndefined(); 2372 return PP_MakeUndefined();
2389 PepperTryCatchVar try_catch(this, NULL); 2373 return NPObjectToPPVar(this, container_->scriptableObjectForElement());
2390 ScopedPPVar result = try_catch.FromV8(container_->v8ObjectForElement());
2391 DCHECK(!try_catch.HasException());
2392 return result.Release();
2393 } 2374 }
2394 2375
2395 PP_Var PepperPluginInstanceImpl::ExecuteScript(PP_Instance instance, 2376 PP_Var PepperPluginInstanceImpl::ExecuteScript(PP_Instance instance,
2396 PP_Var script_var, 2377 PP_Var script,
2397 PP_Var* exception) { 2378 PP_Var* exception) {
2398 if (!container_)
2399 return PP_MakeUndefined();
2400
2401 // Executing the script may remove the plugin from the DOM, so we need to keep 2379 // Executing the script may remove the plugin from the DOM, so we need to keep
2402 // a reference to ourselves so that we can still process the result after the 2380 // a reference to ourselves so that we can still process the result after the
2403 // WebBindings::evaluate() below. 2381 // WebBindings::evaluate() below.
2404 scoped_refptr<PepperPluginInstanceImpl> ref(this); 2382 scoped_refptr<PepperPluginInstanceImpl> ref(this);
2405 PepperTryCatchVar try_catch(this, exception); 2383 TryCatch try_catch(exception);
2406 WebLocalFrame* frame = container_->element().document().frame(); 2384 if (try_catch.has_exception())
2407 if (!frame) { 2385 return PP_MakeUndefined();
2408 try_catch.SetException("No frame to execute script in."); 2386
2387 // Convert the script into an inconvenient NPString object.
2388 StringVar* script_string = StringVar::FromPPVar(script);
2389 if (!script_string) {
2390 try_catch.SetException("Script param to ExecuteScript must be a string.");
2391 return PP_MakeUndefined();
2392 }
2393 NPString np_script;
2394 np_script.UTF8Characters = script_string->value().c_str();
2395 np_script.UTF8Length = script_string->value().length();
2396
2397 // Get the current frame to pass to the evaluate function.
2398 WebLocalFrame* frame = NULL;
2399 if (container_)
2400 frame = container_->element().document().frame();
2401 if (!frame || !frame->windowObject()) {
2402 try_catch.SetException("No context in which to execute script.");
2409 return PP_MakeUndefined(); 2403 return PP_MakeUndefined();
2410 } 2404 }
2411 2405
2412 StringVar* script_string_var = StringVar::FromPPVar(script_var); 2406 NPVariant result;
2413 if (!script_string_var) { 2407 bool ok = false;
2414 try_catch.SetException("Script param to ExecuteScript must be a string."); 2408 if (IsProcessingUserGesture()) {
2409 blink::WebScopedUserGesture user_gesture(CurrentUserGestureToken());
2410 ok =
2411 WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result);
2412 } else {
2413 ok =
2414 WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result);
2415 }
2416 if (!ok) {
2417 // TryCatch doesn't catch the exceptions properly. Since this is only for
2418 // a trusted API, just set to a general exception message.
2419 try_catch.SetException("Exception caught");
2420 WebBindings::releaseVariantValue(&result);
2415 return PP_MakeUndefined(); 2421 return PP_MakeUndefined();
2416 } 2422 }
2417 2423
2418 std::string script_string = script_string_var->value(); 2424 PP_Var ret = NPVariantToPPVar(this, &result);
2419 blink::WebScriptSource script( 2425 WebBindings::releaseVariantValue(&result);
2420 blink::WebString::fromUTF8(script_string.c_str())); 2426 return ret;
2421 v8::Handle<v8::Value> result;
2422 if (IsProcessingUserGesture()) {
2423 blink::WebScopedUserGesture user_gesture(CurrentUserGestureToken());
2424 result = frame->executeScriptAndReturnValue(script);
2425 } else {
2426 result = frame->executeScriptAndReturnValue(script);
2427 }
2428
2429 ScopedPPVar var_result = try_catch.FromV8(result);
2430 if (try_catch.HasException())
2431 return PP_MakeUndefined();
2432
2433 return var_result.Release();
2434 } 2427 }
2435 2428
2436 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputSampleRate( 2429 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputSampleRate(
2437 PP_Instance instance) { 2430 PP_Instance instance) {
2438 RenderThreadImpl* thread = RenderThreadImpl::current(); 2431 RenderThreadImpl* thread = RenderThreadImpl::current();
2439 return thread->GetAudioHardwareConfig()->GetOutputSampleRate(); 2432 return thread->GetAudioHardwareConfig()->GetOutputSampleRate();
2440 } 2433 }
2441 2434
2442 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputBufferSize( 2435 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputBufferSize(
2443 PP_Instance instance) { 2436 PP_Instance instance) {
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
2981 } 2974 }
2982 2975
2983 return PP_EXTERNAL_PLUGIN_OK; 2976 return PP_EXTERNAL_PLUGIN_OK;
2984 } 2977 }
2985 2978
2986 bool PepperPluginInstanceImpl::IsValidInstanceOf(PluginModule* module) { 2979 bool PepperPluginInstanceImpl::IsValidInstanceOf(PluginModule* module) {
2987 DCHECK(module); 2980 DCHECK(module);
2988 return module == module_.get() || module == original_module_.get(); 2981 return module == module_.get() || module == original_module_.get();
2989 } 2982 }
2990 2983
2984 NPP PepperPluginInstanceImpl::instanceNPP() { return npp_.get(); }
2985
2991 PepperPluginInstance* PepperPluginInstance::Get(PP_Instance instance_id) { 2986 PepperPluginInstance* PepperPluginInstance::Get(PP_Instance instance_id) {
2992 return HostGlobals::Get()->GetInstance(instance_id); 2987 return HostGlobals::Get()->GetInstance(instance_id);
2993 } 2988 }
2994 2989
2995 RenderView* PepperPluginInstanceImpl::GetRenderView() { 2990 RenderView* PepperPluginInstanceImpl::GetRenderView() {
2996 return render_frame_ ? render_frame_->render_view() : NULL; 2991 return render_frame_ ? render_frame_->render_view() : NULL;
2997 } 2992 }
2998 2993
2999 blink::WebPluginContainer* PepperPluginInstanceImpl::GetContainer() { 2994 blink::WebPluginContainer* PepperPluginInstanceImpl::GetContainer() {
3000 return container_; 2995 return container_;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
3324 // Running out-of-process. Initiate an IPC call to notify the plugin 3319 // Running out-of-process. Initiate an IPC call to notify the plugin
3325 // process. 3320 // process.
3326 ppapi::proxy::HostDispatcher* dispatcher = 3321 ppapi::proxy::HostDispatcher* dispatcher =
3327 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); 3322 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
3328 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( 3323 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad(
3329 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); 3324 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data));
3330 } 3325 }
3331 } 3326 }
3332 3327
3333 } // namespace content 3328 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_plugin_instance_impl.h ('k') | content/renderer/pepper/pepper_try_catch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698