| Index: content/renderer/pepper/pepper_plugin_instance_impl.cc
|
| diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.cc b/content/renderer/pepper/pepper_plugin_instance_impl.cc
|
| index a1116811924e0ad9789ef791752b8a1de7341d0c..eac7a763fcc7e0d9ec4668baa3fafe93e5fd9c23 100644
|
| --- a/content/renderer/pepper/pepper_plugin_instance_impl.cc
|
| +++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc
|
| @@ -32,13 +32,12 @@
|
| #include "content/renderer/pepper/gfx_conversion.h"
|
| #include "content/renderer/pepper/host_dispatcher_wrapper.h"
|
| #include "content/renderer/pepper/host_globals.h"
|
| -#include "content/renderer/pepper/message_channel.h"
|
| -#include "content/renderer/pepper/npapi_glue.h"
|
| #include "content/renderer/pepper/pepper_browser_connection.h"
|
| #include "content/renderer/pepper/pepper_compositor_host.h"
|
| #include "content/renderer/pepper/pepper_file_ref_renderer_host.h"
|
| #include "content/renderer/pepper/pepper_graphics_2d_host.h"
|
| #include "content/renderer/pepper/pepper_in_process_router.h"
|
| +#include "content/renderer/pepper/pepper_try_catch.h"
|
| #include "content/renderer/pepper/pepper_url_loader_host.h"
|
| #include "content/renderer/pepper/plugin_module.h"
|
| #include "content/renderer/pepper/plugin_object.h"
|
| @@ -115,6 +114,7 @@
|
| #include "third_party/WebKit/public/web/WebPrintParams.h"
|
| #include "third_party/WebKit/public/web/WebPrintScalingOption.h"
|
| #include "third_party/WebKit/public/web/WebScopedUserGesture.h"
|
| +#include "third_party/WebKit/public/web/WebScriptSource.h"
|
| #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
|
| #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
|
| #include "third_party/WebKit/public/web/WebView.h"
|
| @@ -559,7 +559,6 @@ PepperPluginInstanceImpl::PepperPluginInstanceImpl(
|
| pending_user_gesture_(0.0),
|
| document_loader_(NULL),
|
| external_document_load_(false),
|
| - npp_(new NPP_t),
|
| isolate_(v8::Isolate::GetCurrent()),
|
| is_deleted_(false),
|
| last_input_number_(0),
|
| @@ -620,17 +619,15 @@ PepperPluginInstanceImpl::PepperPluginInstanceImpl(
|
| PepperPluginInstanceImpl::~PepperPluginInstanceImpl() {
|
| DCHECK(!fullscreen_container_);
|
|
|
| - // Free all the plugin objects. This will automatically clear the back-
|
| - // pointer from the NPObject so WebKit can't call into the plugin any more.
|
| - //
|
| - // Swap out the set so we can delete from it (the objects will try to
|
| - // unregister themselves inside the delete call).
|
| + // Free all the plugin objects. This will prevent WebKit from calling into the
|
| + // plugin any more.
|
| PluginObjectSet plugin_object_copy;
|
| live_plugin_objects_.swap(plugin_object_copy);
|
| for (PluginObjectSet::iterator i = plugin_object_copy.begin();
|
| i != plugin_object_copy.end();
|
| - ++i)
|
| - delete *i;
|
| + ++i) {
|
| + (*i)->InstanceDeleted();
|
| + }
|
|
|
| if (TrackedCallback::IsPending(lock_mouse_callback_))
|
| lock_mouse_callback_->Abort();
|
| @@ -661,6 +658,27 @@ PepperPluginInstanceImpl::~PepperPluginInstanceImpl() {
|
| // If a method needs to access a member of the instance after the call has
|
| // returned, then it needs to keep its own reference on the stack.
|
|
|
| +v8::Local<v8::Object> PepperPluginInstanceImpl::GetMessageChannelObject() {
|
| + return v8::Local<v8::Object>::New(isolate_, message_channel_);
|
| +}
|
| +
|
| +MessageChannel* PepperPluginInstanceImpl::GetMessageChannel() {
|
| + MessageChannel* message_channel;
|
| + v8::HandleScope scope(isolate_);
|
| + if (gin::ConvertFromV8(isolate_, GetMessageChannelObject(), &message_channel))
|
| + return message_channel;
|
| + return NULL;
|
| +}
|
| +
|
| +v8::Handle<v8::Context> PepperPluginInstanceImpl::GetPluginContext() {
|
| + if (!container_)
|
| + return v8::Handle<v8::Context>();
|
| + v8::Handle<v8::Context> context =
|
| + container_->element().document().frame()->mainWorldScriptContext();
|
| + DCHECK(context->GetIsolate() == isolate_);
|
| + return context;
|
| +}
|
| +
|
| void PepperPluginInstanceImpl::Delete() {
|
| is_deleted_ = true;
|
|
|
| @@ -675,7 +693,7 @@ void PepperPluginInstanceImpl::Delete() {
|
| // release our last reference to the "InstanceObject" and will probably
|
| // destroy it. We want to do this prior to calling DidDestroy in case the
|
| // destructor of the instance object tries to use the instance.
|
| - message_channel_->SetPassthroughObject(NULL);
|
| + GetMessageChannel()->SetPassthroughObject(v8::Handle<v8::Object>());
|
| // If this is a NaCl plugin instance, shut down the NaCl plugin by calling
|
| // its DidDestroy. Don't call DidDestroy on the untrusted plugin instance,
|
| // since there is little that it can do at this point.
|
| @@ -837,7 +855,7 @@ bool PepperPluginInstanceImpl::Initialize(
|
| bool full_frame) {
|
| if (!render_frame_)
|
| return false;
|
| - message_channel_.reset(new MessageChannel(this));
|
| + MessageChannel::Create(this, &message_channel_);
|
|
|
| full_frame_ = full_frame;
|
|
|
| @@ -862,7 +880,7 @@ bool PepperPluginInstanceImpl::Initialize(
|
| // A host for external plugins will call ResetAsProxied later, at which point
|
| // we can Start() the message_channel_.
|
| if (success && (!module_->renderer_ppapi_host()->IsExternalPluginHost()))
|
| - message_channel_->Start();
|
| + GetMessageChannel()->Start();
|
| return success;
|
| }
|
|
|
| @@ -1206,10 +1224,12 @@ bool PepperPluginInstanceImpl::HandleBlockingMessage(ScopedPPVar message,
|
| return was_handled;
|
| }
|
|
|
| -PP_Var PepperPluginInstanceImpl::GetInstanceObject() {
|
| +PP_Var PepperPluginInstanceImpl::GetInstanceObject(v8::Isolate* isolate) {
|
| // Keep a reference on the stack. See NOTE above.
|
| scoped_refptr<PepperPluginInstanceImpl> ref(this);
|
|
|
| + CHECK(isolate == isolate_);
|
| +
|
| // If the plugin supports the private instance interface, try to retrieve its
|
| // instance object.
|
| if (LoadPrivateInterface())
|
| @@ -1345,7 +1365,7 @@ void PepperPluginInstanceImpl::SetTextInputType(ui::TextInputType type) {
|
| }
|
|
|
| void PepperPluginInstanceImpl::PostMessageToJavaScript(PP_Var message) {
|
| - message_channel_->PostMessageToJavaScript(message);
|
| + GetMessageChannel()->PostMessageToJavaScript(message);
|
| }
|
|
|
| int32_t PepperPluginInstanceImpl::RegisterMessageHandler(
|
| @@ -2346,71 +2366,59 @@ PP_Bool PepperPluginInstanceImpl::FlashIsFullscreen(PP_Instance instance) {
|
| }
|
|
|
| PP_Var PepperPluginInstanceImpl::GetWindowObject(PP_Instance instance) {
|
| - if (!container_)
|
| - return PP_MakeUndefined();
|
| -
|
| - WebLocalFrame* frame = container_->element().document().frame();
|
| - if (!frame)
|
| - return PP_MakeUndefined();
|
| -
|
| - return NPObjectToPPVar(this, frame->windowObject());
|
| + ScopedPPVar script(ScopedPPVar::PassRef(),
|
| + StringVar::StringToPPVar("window"));
|
| + return ExecuteScript(pp_instance(), script.get(), NULL);
|
| }
|
|
|
| PP_Var PepperPluginInstanceImpl::GetOwnerElementObject(PP_Instance instance) {
|
| if (!container_)
|
| return PP_MakeUndefined();
|
| - return NPObjectToPPVar(this, container_->scriptableObjectForElement());
|
| + PepperTryCatchVar try_catch(this, true, NULL);
|
| + ScopedPPVar result = try_catch.FromV8(container_->getV8ObjectForElement());
|
| + DCHECK(!try_catch.HasException());
|
| + return result.Release();
|
| }
|
|
|
| PP_Var PepperPluginInstanceImpl::ExecuteScript(PP_Instance instance,
|
| - PP_Var script,
|
| + PP_Var script_var,
|
| PP_Var* exception) {
|
| + if (!container_)
|
| + return PP_MakeUndefined();
|
| +
|
| // Executing the script may remove the plugin from the DOM, so we need to keep
|
| // a reference to ourselves so that we can still process the result after the
|
| // WebBindings::evaluate() below.
|
| scoped_refptr<PepperPluginInstanceImpl> ref(this);
|
| - TryCatch try_catch(exception);
|
| - if (try_catch.has_exception())
|
| - return PP_MakeUndefined();
|
| -
|
| - // Convert the script into an inconvenient NPString object.
|
| - StringVar* script_string = StringVar::FromPPVar(script);
|
| - if (!script_string) {
|
| - try_catch.SetException("Script param to ExecuteScript must be a string.");
|
| - return PP_MakeUndefined();
|
| - }
|
| - NPString np_script;
|
| - np_script.UTF8Characters = script_string->value().c_str();
|
| - np_script.UTF8Length = script_string->value().length();
|
| -
|
| - // Get the current frame to pass to the evaluate function.
|
| + PepperTryCatchVar try_catch(this, true, exception);
|
| WebLocalFrame* frame = container_->element().document().frame();
|
| if (!frame) {
|
| try_catch.SetException("No frame to execute script in.");
|
| return PP_MakeUndefined();
|
| }
|
|
|
| - NPVariant result;
|
| - bool ok = false;
|
| + StringVar* script_string_var = StringVar::FromPPVar(script_var);
|
| + if (!script_string_var) {
|
| + try_catch.SetException("Script param to ExecuteScript must be a string.");
|
| + return PP_MakeUndefined();
|
| + }
|
| +
|
| + std::string script_string = script_string_var->value();
|
| + blink::WebScriptSource script(
|
| + blink::WebString::fromUTF8(script_string.c_str()));
|
| + v8::Handle<v8::Value> result;
|
| if (IsProcessingUserGesture()) {
|
| blink::WebScopedUserGesture user_gesture(CurrentUserGestureToken());
|
| - ok =
|
| - WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result);
|
| + result = frame->executeScriptAndReturnValue(script);
|
| } else {
|
| - ok =
|
| - WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result);
|
| - }
|
| - if (!ok) {
|
| - // TryCatch doesn't catch the exceptions properly. Since this is only for
|
| - // a trusted API, just set to a general exception message.
|
| - try_catch.SetException("Exception caught");
|
| - WebBindings::releaseVariantValue(&result);
|
| - return PP_MakeUndefined();
|
| + result = frame->executeScriptAndReturnValue(script);
|
| }
|
|
|
| - PP_Var ret = NPVariantToPPVar(this, &result);
|
| - WebBindings::releaseVariantValue(&result);
|
| - return ret;
|
| + ScopedPPVar var_result = try_catch.FromV8(result);
|
| + if (try_catch.HasException())
|
| + return PP_MakeUndefined();
|
| +
|
| + return var_result.Release();
|
| }
|
|
|
| uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputSampleRate(
|
| @@ -2939,7 +2947,7 @@ PP_ExternalPluginResult PepperPluginInstanceImpl::ResetAsProxied(
|
| if (!instance_interface_->DidCreate(
|
| pp_instance(), argn_.size(), argn_array.get(), argv_array.get()))
|
| return PP_EXTERNAL_PLUGIN_ERROR_INSTANCE;
|
| - message_channel_->Start();
|
| + GetMessageChannel()->Start();
|
|
|
| // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView
|
| // event. This way, SendDidChangeView will send the "current" view
|
| @@ -2968,8 +2976,6 @@ bool PepperPluginInstanceImpl::IsValidInstanceOf(PluginModule* module) {
|
| return module == module_.get() || module == original_module_.get();
|
| }
|
|
|
| -NPP PepperPluginInstanceImpl::instanceNPP() { return npp_.get(); }
|
| -
|
| PepperPluginInstance* PepperPluginInstance::Get(PP_Instance instance_id) {
|
| return HostGlobals::Get()->GetInstance(instance_id);
|
| }
|
| @@ -3176,7 +3182,7 @@ int PepperPluginInstanceImpl::MakePendingFileRefRendererHost(
|
| }
|
|
|
| void PepperPluginInstanceImpl::SetEmbedProperty(PP_Var key, PP_Var value) {
|
| - message_channel_->SetReadOnlyProperty(key, value);
|
| + GetMessageChannel()->SetReadOnlyProperty(key, value);
|
| }
|
|
|
| bool PepperPluginInstanceImpl::CanAccessMainFrame() const {
|
|
|