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

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

Issue 537483002: 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 checked_for_plugin_input_event_interface_(false), 536 checked_for_plugin_input_event_interface_(false),
538 checked_for_plugin_pdf_interface_(false), 537 checked_for_plugin_pdf_interface_(false),
539 gamepad_impl_(new GamepadImpl()), 538 gamepad_impl_(new GamepadImpl()),
540 uma_private_impl_(NULL), 539 uma_private_impl_(NULL),
541 plugin_print_interface_(NULL), 540 plugin_print_interface_(NULL),
542 plugin_graphics_3d_interface_(NULL), 541 plugin_graphics_3d_interface_(NULL),
543 always_on_top_(false), 542 always_on_top_(false),
544 fullscreen_container_(NULL), 543 fullscreen_container_(NULL),
545 flash_fullscreen_(false), 544 flash_fullscreen_(false),
546 desired_fullscreen_state_(false), 545 desired_fullscreen_state_(false),
547 message_channel_(NULL),
548 sad_plugin_(NULL), 546 sad_plugin_(NULL),
549 input_event_mask_(0), 547 input_event_mask_(0),
550 filtered_input_event_mask_(0), 548 filtered_input_event_mask_(0),
551 text_input_type_(kPluginDefaultTextInputType), 549 text_input_type_(kPluginDefaultTextInputType),
552 text_input_caret_(0, 0, 0, 0), 550 text_input_caret_(0, 0, 0, 0),
553 text_input_caret_bounds_(0, 0, 0, 0), 551 text_input_caret_bounds_(0, 0, 0, 0),
554 text_input_caret_set_(false), 552 text_input_caret_set_(false),
555 selection_caret_(0), 553 selection_caret_(0),
556 selection_anchor_(0), 554 selection_anchor_(0),
557 pending_user_gesture_(0.0), 555 pending_user_gesture_(0.0),
558 document_loader_(NULL), 556 document_loader_(NULL),
559 external_document_load_(false), 557 external_document_load_(false),
558 npp_(new NPP_t),
560 isolate_(v8::Isolate::GetCurrent()), 559 isolate_(v8::Isolate::GetCurrent()),
561 is_deleted_(false), 560 is_deleted_(false),
562 last_input_number_(0), 561 last_input_number_(0),
563 is_tracking_latency_(false), 562 is_tracking_latency_(false),
564 view_change_weak_ptr_factory_(this), 563 view_change_weak_ptr_factory_(this),
565 weak_factory_(this) { 564 weak_factory_(this) {
566 pp_instance_ = HostGlobals::Get()->AddInstance(this); 565 pp_instance_ = HostGlobals::Get()->AddInstance(this);
567 566
568 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 567 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
569 module_->InstanceCreated(this); 568 module_->InstanceCreated(this);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); 609 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this);
611 610
612 if (GetContentClient()->renderer() && // NULL in unit tests. 611 if (GetContentClient()->renderer() && // NULL in unit tests.
613 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) 612 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name()))
614 external_document_load_ = true; 613 external_document_load_ = true;
615 } 614 }
616 615
617 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { 616 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() {
618 DCHECK(!fullscreen_container_); 617 DCHECK(!fullscreen_container_);
619 618
620 // Notify all the plugin objects of deletion. This will prevent blink from 619 // Free all the plugin objects. This will automatically clear the back-
621 // calling into the plugin any more. 620 // pointer from the NPObject so WebKit can't call into the plugin any more.
622 // 621 //
623 // Swap out the set so we can delete from it (the objects will try to 622 // Swap out the set so we can delete from it (the objects will try to
624 // unregister themselves inside the delete call). 623 // unregister themselves inside the delete call).
625 PluginObjectSet plugin_object_copy; 624 PluginObjectSet plugin_object_copy;
626 live_plugin_objects_.swap(plugin_object_copy); 625 live_plugin_objects_.swap(plugin_object_copy);
627 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); 626 for (PluginObjectSet::iterator i = plugin_object_copy.begin();
628 i != plugin_object_copy.end(); 627 i != plugin_object_copy.end();
629 ++i) { 628 ++i)
630 (*i)->InstanceDeleted(); 629 delete *i;
631 }
632
633 if (message_channel_) {
634 message_channel_->InstanceDeleted();
635 message_channel_object_.Reset();
636 message_channel_ = NULL;
637 }
638 630
639 if (TrackedCallback::IsPending(lock_mouse_callback_)) 631 if (TrackedCallback::IsPending(lock_mouse_callback_))
640 lock_mouse_callback_->Abort(); 632 lock_mouse_callback_->Abort();
641 633
642 if (!instance_deleted_callback_.is_null()) 634 if (!instance_deleted_callback_.is_null())
643 instance_deleted_callback_.Run(); 635 instance_deleted_callback_.Run();
644 636
645 if (!module_->IsProxied() && render_frame_) { 637 if (!module_->IsProxied() && render_frame_) {
646 PepperBrowserConnection* browser_connection = 638 PepperBrowserConnection* browser_connection =
647 PepperBrowserConnection::Get(render_frame_); 639 PepperBrowserConnection::Get(render_frame_);
(...skipping 10 matching lines...) Expand all
658 // want to look up in the global map to get info off of our object. 650 // want to look up in the global map to get info off of our object.
659 HostGlobals::Get()->InstanceDeleted(pp_instance_); 651 HostGlobals::Get()->InstanceDeleted(pp_instance_);
660 } 652 }
661 653
662 // NOTE: Any of these methods that calls into the plugin needs to take into 654 // 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 655 // 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. 656 // 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 657 // 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. 658 // returned, then it needs to keep its own reference on the stack.
667 659
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() { 660 v8::Local<v8::Context> PepperPluginInstanceImpl::GetContext() {
673 if (!container_) 661 if (!container_)
674 return v8::Handle<v8::Context>(); 662 return v8::Handle<v8::Context>();
675 WebLocalFrame* frame = container_->element().document().frame(); 663 WebLocalFrame* frame = container_->element().document().frame();
676 if (!frame) 664 if (!frame)
677 return v8::Handle<v8::Context>(); 665 return v8::Handle<v8::Context>();
678 666
679 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); 667 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
680 DCHECK(context->GetIsolate() == isolate_); 668 DCHECK(context->GetIsolate() == isolate_);
681 return context; 669 return context;
682 } 670 }
683 671
684 void PepperPluginInstanceImpl::Delete() { 672 void PepperPluginInstanceImpl::Delete() {
685 is_deleted_ = true; 673 is_deleted_ = true;
686 674
687 if (render_frame_ && 675 if (render_frame_ &&
688 render_frame_->render_view()->plugin_find_handler() == this) { 676 render_frame_->render_view()->plugin_find_handler() == this) {
689 render_frame_->render_view()->set_plugin_find_handler(NULL); 677 render_frame_->render_view()->set_plugin_find_handler(NULL);
690 } 678 }
691 679
692 // Keep a reference on the stack. See NOTE above. 680 // Keep a reference on the stack. See NOTE above.
693 scoped_refptr<PepperPluginInstanceImpl> ref(this); 681 scoped_refptr<PepperPluginInstanceImpl> ref(this);
694 // Force the MessageChannel to release its "passthrough object" which should 682 // Force the MessageChannel to release its "passthrough object" which should
695 // release our last reference to the "InstanceObject" and will probably 683 // 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 684 // 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. 685 // destructor of the instance object tries to use the instance.
698 message_channel_->SetPassthroughObject(v8::Handle<v8::Object>()); 686 message_channel_->SetPassthroughObject(NULL);
699 // If this is a NaCl plugin instance, shut down the NaCl plugin by calling 687 // 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, 688 // its DidDestroy. Don't call DidDestroy on the untrusted plugin instance,
701 // since there is little that it can do at this point. 689 // since there is little that it can do at this point.
702 if (original_instance_interface_) 690 if (original_instance_interface_)
703 original_instance_interface_->DidDestroy(pp_instance()); 691 original_instance_interface_->DidDestroy(pp_instance());
704 else 692 else
705 instance_interface_->DidDestroy(pp_instance()); 693 instance_interface_->DidDestroy(pp_instance());
706 // Ensure we don't attempt to call functions on the destroyed instance. 694 // Ensure we don't attempt to call functions on the destroyed instance.
707 original_instance_interface_.reset(); 695 original_instance_interface_.reset();
708 instance_interface_.reset(); 696 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); 838 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8);
851 #endif 839 #endif
852 } 840 }
853 841
854 bool PepperPluginInstanceImpl::Initialize( 842 bool PepperPluginInstanceImpl::Initialize(
855 const std::vector<std::string>& arg_names, 843 const std::vector<std::string>& arg_names,
856 const std::vector<std::string>& arg_values, 844 const std::vector<std::string>& arg_values,
857 bool full_frame) { 845 bool full_frame) {
858 if (!render_frame_) 846 if (!render_frame_)
859 return false; 847 return false;
860 message_channel_ = MessageChannel::Create(this, &message_channel_object_); 848 message_channel_.reset(new MessageChannel(this));
861 849
862 full_frame_ = full_frame; 850 full_frame_ = full_frame;
863 851
864 UpdateTouchEventRequest(); 852 UpdateTouchEventRequest();
865 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); 853 container_->setWantsWheelEvents(IsAcceptingWheelEvents());
866 854
867 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( 855 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build(
868 render_frame_->render_view()->webkit_preferences())), 856 render_frame_->render_view()->webkit_preferences())),
869 arg_names, 857 arg_names,
870 arg_values); 858 arg_values);
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(), 1207 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(),
1220 pp_instance()), 1208 pp_instance()),
1221 &msg_reply, 1209 &msg_reply,
1222 &was_handled)); 1210 &was_handled));
1223 *result = ScopedPPVar(ScopedPPVar::PassRef(), msg_reply.Return(dispatcher)); 1211 *result = ScopedPPVar(ScopedPPVar::PassRef(), msg_reply.Return(dispatcher));
1224 TRACE_EVENT0("ppapi", 1212 TRACE_EVENT0("ppapi",
1225 "PepperPluginInstanceImpl::HandleBlockingMessage return."); 1213 "PepperPluginInstanceImpl::HandleBlockingMessage return.");
1226 return was_handled; 1214 return was_handled;
1227 } 1215 }
1228 1216
1229 PP_Var PepperPluginInstanceImpl::GetInstanceObject(v8::Isolate* isolate) { 1217 PP_Var PepperPluginInstanceImpl::GetInstanceObject() {
1230 // Keep a reference on the stack. See NOTE above. 1218 // Keep a reference on the stack. See NOTE above.
1231 scoped_refptr<PepperPluginInstanceImpl> ref(this); 1219 scoped_refptr<PepperPluginInstanceImpl> ref(this);
1232 1220
1233 DCHECK_EQ(isolate, isolate_);
1234
1235 // If the plugin supports the private instance interface, try to retrieve its 1221 // If the plugin supports the private instance interface, try to retrieve its
1236 // instance object. 1222 // instance object.
1237 if (LoadPrivateInterface()) 1223 if (LoadPrivateInterface())
1238 return plugin_private_interface_->GetInstanceObject(pp_instance()); 1224 return plugin_private_interface_->GetInstanceObject(pp_instance());
1239 return PP_MakeUndefined(); 1225 return PP_MakeUndefined();
1240 } 1226 }
1241 1227
1242 void PepperPluginInstanceImpl::ViewChanged( 1228 void PepperPluginInstanceImpl::ViewChanged(
1243 const gfx::Rect& position, 1229 const gfx::Rect& position,
1244 const gfx::Rect& clip, 1230 const gfx::Rect& clip,
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 } 2345 }
2360 2346
2361 PP_Bool PepperPluginInstanceImpl::FlashIsFullscreen(PP_Instance instance) { 2347 PP_Bool PepperPluginInstanceImpl::FlashIsFullscreen(PP_Instance instance) {
2362 return PP_FromBool(flash_fullscreen_); 2348 return PP_FromBool(flash_fullscreen_);
2363 } 2349 }
2364 2350
2365 PP_Var PepperPluginInstanceImpl::GetWindowObject(PP_Instance instance) { 2351 PP_Var PepperPluginInstanceImpl::GetWindowObject(PP_Instance instance) {
2366 if (!container_) 2352 if (!container_)
2367 return PP_MakeUndefined(); 2353 return PP_MakeUndefined();
2368 2354
2369 PepperTryCatchVar try_catch(this, NULL);
2370 WebLocalFrame* frame = container_->element().document().frame(); 2355 WebLocalFrame* frame = container_->element().document().frame();
2371 if (!frame) { 2356 if (!frame)
2372 try_catch.SetException("No frame exists for window object.");
2373 return PP_MakeUndefined(); 2357 return PP_MakeUndefined();
2374 }
2375 2358
2376 ScopedPPVar result = 2359 return NPObjectToPPVar(this, frame->windowObject());
2377 try_catch.FromV8(frame->mainWorldScriptContext()->Global());
2378 DCHECK(!try_catch.HasException());
2379 return result.Release();
2380 } 2360 }
2381 2361
2382 PP_Var PepperPluginInstanceImpl::GetOwnerElementObject(PP_Instance instance) { 2362 PP_Var PepperPluginInstanceImpl::GetOwnerElementObject(PP_Instance instance) {
2383 if (!container_) 2363 if (!container_)
2384 return PP_MakeUndefined(); 2364 return PP_MakeUndefined();
2385 PepperTryCatchVar try_catch(this, NULL); 2365 return NPObjectToPPVar(this, container_->scriptableObjectForElement());
2386 ScopedPPVar result = try_catch.FromV8(container_->v8ObjectForElement());
2387 DCHECK(!try_catch.HasException());
2388 return result.Release();
2389 } 2366 }
2390 2367
2391 PP_Var PepperPluginInstanceImpl::ExecuteScript(PP_Instance instance, 2368 PP_Var PepperPluginInstanceImpl::ExecuteScript(PP_Instance instance,
2392 PP_Var script_var, 2369 PP_Var script,
2393 PP_Var* exception) { 2370 PP_Var* exception) {
2394 if (!container_)
2395 return PP_MakeUndefined();
2396
2397 // Executing the script may remove the plugin from the DOM, so we need to keep 2371 // Executing the script may remove the plugin from the DOM, so we need to keep
2398 // a reference to ourselves so that we can still process the result after the 2372 // a reference to ourselves so that we can still process the result after the
2399 // WebBindings::evaluate() below. 2373 // WebBindings::evaluate() below.
2400 scoped_refptr<PepperPluginInstanceImpl> ref(this); 2374 scoped_refptr<PepperPluginInstanceImpl> ref(this);
2401 PepperTryCatchVar try_catch(this, exception); 2375 TryCatch try_catch(exception);
2402 WebLocalFrame* frame = container_->element().document().frame(); 2376 if (try_catch.has_exception())
2403 if (!frame) { 2377 return PP_MakeUndefined();
2404 try_catch.SetException("No frame to execute script in."); 2378
2379 // Convert the script into an inconvenient NPString object.
2380 StringVar* script_string = StringVar::FromPPVar(script);
2381 if (!script_string) {
2382 try_catch.SetException("Script param to ExecuteScript must be a string.");
2383 return PP_MakeUndefined();
2384 }
2385 NPString np_script;
2386 np_script.UTF8Characters = script_string->value().c_str();
2387 np_script.UTF8Length = script_string->value().length();
2388
2389 // Get the current frame to pass to the evaluate function.
2390 WebLocalFrame* frame = NULL;
2391 if (container_)
2392 frame = container_->element().document().frame();
2393 if (!frame || !frame->windowObject()) {
2394 try_catch.SetException("No context in which to execute script.");
2405 return PP_MakeUndefined(); 2395 return PP_MakeUndefined();
2406 } 2396 }
2407 2397
2408 StringVar* script_string_var = StringVar::FromPPVar(script_var); 2398 NPVariant result;
2409 if (!script_string_var) { 2399 bool ok = false;
2410 try_catch.SetException("Script param to ExecuteScript must be a string."); 2400 if (IsProcessingUserGesture()) {
2401 blink::WebScopedUserGesture user_gesture(CurrentUserGestureToken());
2402 ok =
2403 WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result);
2404 } else {
2405 ok =
2406 WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result);
2407 }
2408 if (!ok) {
2409 // TryCatch doesn't catch the exceptions properly. Since this is only for
2410 // a trusted API, just set to a general exception message.
2411 try_catch.SetException("Exception caught");
2412 WebBindings::releaseVariantValue(&result);
2411 return PP_MakeUndefined(); 2413 return PP_MakeUndefined();
2412 } 2414 }
2413 2415
2414 std::string script_string = script_string_var->value(); 2416 PP_Var ret = NPVariantToPPVar(this, &result);
2415 blink::WebScriptSource script( 2417 WebBindings::releaseVariantValue(&result);
2416 blink::WebString::fromUTF8(script_string.c_str())); 2418 return ret;
2417 v8::Handle<v8::Value> result;
2418 if (IsProcessingUserGesture()) {
2419 blink::WebScopedUserGesture user_gesture(CurrentUserGestureToken());
2420 result = frame->executeScriptAndReturnValue(script);
2421 } else {
2422 result = frame->executeScriptAndReturnValue(script);
2423 }
2424
2425 ScopedPPVar var_result = try_catch.FromV8(result);
2426 if (try_catch.HasException())
2427 return PP_MakeUndefined();
2428
2429 return var_result.Release();
2430 } 2419 }
2431 2420
2432 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputSampleRate( 2421 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputSampleRate(
2433 PP_Instance instance) { 2422 PP_Instance instance) {
2434 RenderThreadImpl* thread = RenderThreadImpl::current(); 2423 RenderThreadImpl* thread = RenderThreadImpl::current();
2435 return thread->GetAudioHardwareConfig()->GetOutputSampleRate(); 2424 return thread->GetAudioHardwareConfig()->GetOutputSampleRate();
2436 } 2425 }
2437 2426
2438 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputBufferSize( 2427 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputBufferSize(
2439 PP_Instance instance) { 2428 PP_Instance instance) {
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
2977 } 2966 }
2978 2967
2979 return PP_EXTERNAL_PLUGIN_OK; 2968 return PP_EXTERNAL_PLUGIN_OK;
2980 } 2969 }
2981 2970
2982 bool PepperPluginInstanceImpl::IsValidInstanceOf(PluginModule* module) { 2971 bool PepperPluginInstanceImpl::IsValidInstanceOf(PluginModule* module) {
2983 DCHECK(module); 2972 DCHECK(module);
2984 return module == module_.get() || module == original_module_.get(); 2973 return module == module_.get() || module == original_module_.get();
2985 } 2974 }
2986 2975
2976 NPP PepperPluginInstanceImpl::instanceNPP() { return npp_.get(); }
2977
2987 PepperPluginInstance* PepperPluginInstance::Get(PP_Instance instance_id) { 2978 PepperPluginInstance* PepperPluginInstance::Get(PP_Instance instance_id) {
2988 return HostGlobals::Get()->GetInstance(instance_id); 2979 return HostGlobals::Get()->GetInstance(instance_id);
2989 } 2980 }
2990 2981
2991 RenderView* PepperPluginInstanceImpl::GetRenderView() { 2982 RenderView* PepperPluginInstanceImpl::GetRenderView() {
2992 return render_frame_ ? render_frame_->render_view() : NULL; 2983 return render_frame_ ? render_frame_->render_view() : NULL;
2993 } 2984 }
2994 2985
2995 blink::WebPluginContainer* PepperPluginInstanceImpl::GetContainer() { 2986 blink::WebPluginContainer* PepperPluginInstanceImpl::GetContainer() {
2996 return container_; 2987 return container_;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
3320 // Running out-of-process. Initiate an IPC call to notify the plugin 3311 // Running out-of-process. Initiate an IPC call to notify the plugin
3321 // process. 3312 // process.
3322 ppapi::proxy::HostDispatcher* dispatcher = 3313 ppapi::proxy::HostDispatcher* dispatcher =
3323 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); 3314 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
3324 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( 3315 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad(
3325 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); 3316 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data));
3326 } 3317 }
3327 } 3318 }
3328 3319
3329 } // namespace content 3320 } // 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