summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsgjesse@chromium.org <sgjesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-27 09:26:58 +0000
committersgjesse@chromium.org <sgjesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-27 09:26:58 +0000
commitbc296f37929b762850ce2c3b317f8542bdace2a1 (patch)
tree7ae61fc12388c1c2cc8ae20974d1e78ecb94b45f /chrome
parent9c5e417def0fef57d5dc79b0348dab9b0d354d42 (diff)
downloadchromium_src-bc296f37929b762850ce2c3b317f8542bdace2a1.zip
chromium_src-bc296f37929b762850ce2c3b317f8542bdace2a1.tar.gz
chromium_src-bc296f37929b762850ce2c3b317f8542bdace2a1.tar.bz2
Added support for constructor calls in the NPAPI.
The LiveConnect test cases at http://java.sun.com/javase/6/webnotes/6u10/plugin2/liveconnect/LiveConnectTests/ now pass for Chromium. Parts of this change is rather mechanical, and leaves room for some refactoring afterwards. Merged the implementation of testConstruct and the "objectPointer" property from WebKit\WebKitTools\DumpRenderTree\TestNetscapePlugIn.subproj\TestObject.cpp to the Chromium TestObject.cpp for the layout test LayoutTests\plugins\netscape-construct.html pass. BUG=http://crbug.com/3285 BUG=http://crbug.com/10354 TEST=http://java.sun.com/javase/6/webnotes/6u10/plugin2/liveconnect/LiveConnectTests/ TEST=LayoutTests\plugins\netscape-construct.html Review URL: http://codereview.chromium.org/113823 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16979 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/common/plugin_messages_internal.h5
-rw-r--r--chrome/plugin/npobject_proxy.cc49
-rw-r--r--chrome/plugin/npobject_proxy.h6
-rw-r--r--chrome/plugin/npobject_stub.cc40
-rw-r--r--chrome/plugin/npobject_stub.h2
5 files changed, 99 insertions, 3 deletions
diff --git a/chrome/common/plugin_messages_internal.h b/chrome/common/plugin_messages_internal.h
index d02c6be..539be22 100644
--- a/chrome/common/plugin_messages_internal.h
+++ b/chrome/common/plugin_messages_internal.h
@@ -331,6 +331,11 @@ IPC_BEGIN_MESSAGES(NPObject)
std::vector<NPIdentifier_Param> /* value */,
bool /* result */)
+ IPC_SYNC_MESSAGE_ROUTED1_2(NPObjectMsg_Construct,
+ std::vector<NPVariant_Param> /* args */,
+ NPVariant_Param /* result_param */,
+ bool /* result */)
+
IPC_SYNC_MESSAGE_ROUTED2_2(NPObjectMsg_Evaluate,
std::string /* script */,
bool /* popups_allowed */,
diff --git a/chrome/plugin/npobject_proxy.cc b/chrome/plugin/npobject_proxy.cc
index fa48d87..f56832a 100644
--- a/chrome/plugin/npobject_proxy.cc
+++ b/chrome/plugin/npobject_proxy.cc
@@ -18,7 +18,7 @@ struct NPObjectWrapper {
};
NPClass NPObjectProxy::npclass_proxy_ = {
- 2,
+ NP_CLASS_STRUCT_VERSION,
NPObjectProxy::NPAllocate,
NPObjectProxy::NPDeallocate,
NPObjectProxy::NPPInvalidate,
@@ -29,7 +29,8 @@ NPClass NPObjectProxy::npclass_proxy_ = {
NPObjectProxy::NPGetProperty,
NPObjectProxy::NPSetProperty,
NPObjectProxy::NPRemoveProperty,
- NPObjectProxy::NPNEnumerate
+ NPObjectProxy::NPNEnumerate,
+ NPObjectProxy::NPNConstruct
};
NPObjectProxy* NPObjectProxy::GetProxy(NPObject* object) {
@@ -339,6 +340,50 @@ bool NPObjectProxy::NPNEnumerate(NPObject *obj,
return true;
}
+bool NPObjectProxy::NPNConstruct(NPObject *obj,
+ const NPVariant *args,
+ uint32_t arg_count,
+ NPVariant *np_result) {
+ NPObjectProxy* proxy = GetProxy(obj);
+ if (!proxy) {
+ return obj->_class->construct(obj, args, arg_count, np_result);
+ }
+
+ bool result = false;
+
+ // Note: This instance can get destroyed in the context of
+ // Send so addref the channel in this scope.
+ scoped_refptr<PluginChannelBase> channel_copy = proxy->channel_;
+ std::vector<NPVariant_Param> args_param;
+ for (unsigned int i = 0; i < arg_count; ++i) {
+ NPVariant_Param param;
+ CreateNPVariantParam(
+ args[i], channel_copy, &param, false, proxy->modal_dialog_event_);
+ args_param.push_back(param);
+ }
+
+ NPVariant_Param param_result;
+ NPObjectMsg_Construct* msg = new NPObjectMsg_Construct(
+ proxy->route_id_, args_param, &param_result, &result);
+
+ // See comment in NPObjectProxy::NPInvokePrivate.
+ msg->set_pump_messages_event(proxy->modal_dialog_event_);
+
+ base::WaitableEvent* modal_dialog_event_handle = proxy->modal_dialog_event_;
+
+ proxy->Send(msg);
+
+ // Send may delete proxy.
+ proxy = NULL;
+
+ if (!result)
+ return false;
+
+ CreateNPVariant(
+ param_result, channel_copy, np_result, modal_dialog_event_handle);
+ return true;
+}
+
bool NPObjectProxy::NPNEvaluate(NPP npp,
NPObject *obj,
NPString *script,
diff --git a/chrome/plugin/npobject_proxy.h b/chrome/plugin/npobject_proxy.h
index d4a22d4..3cdae9e 100644
--- a/chrome/plugin/npobject_proxy.h
+++ b/chrome/plugin/npobject_proxy.h
@@ -47,7 +47,7 @@ class NPObjectProxy : public IPC::Channel::Listener,
// process).
intptr_t npobject_ptr() { return npobject_ptr_; }
- // The next 8 functions are called on NPObjects from the plugin and browser.
+ // The next 9 functions are called on NPObjects from the plugin and browser.
static bool NPHasMethod(NPObject *obj,
NPIdentifier name);
static bool NPInvoke(NPObject *obj,
@@ -72,6 +72,10 @@ class NPObjectProxy : public IPC::Channel::Listener,
static bool NPNEnumerate(NPObject *obj,
NPIdentifier **value,
uint32_t *count);
+ static bool NPNConstruct(NPObject *npobj,
+ const NPVariant *args,
+ uint32_t arg_count,
+ NPVariant *result);
// The next two functions are only called on NPObjects from the browser.
static bool NPNEvaluate(NPP npp,
diff --git a/chrome/plugin/npobject_stub.cc b/chrome/plugin/npobject_stub.cc
index 26780d2..c5f14f5 100644
--- a/chrome/plugin/npobject_stub.cc
+++ b/chrome/plugin/npobject_stub.cc
@@ -64,6 +64,7 @@ void NPObjectStub::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(NPObjectMsg_RemoveProperty, OnRemoveProperty);
IPC_MESSAGE_HANDLER(NPObjectMsg_Invalidate, OnInvalidate);
IPC_MESSAGE_HANDLER(NPObjectMsg_Enumeration, OnEnumeration);
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(NPObjectMsg_Construct, OnConstruct);
IPC_MESSAGE_HANDLER_DELAY_REPLY(NPObjectMsg_Evaluate, OnEvaluate);
IPC_MESSAGE_HANDLER(NPObjectMsg_SetException, OnSetException);
IPC_MESSAGE_UNHANDLED_ERROR()
@@ -267,6 +268,45 @@ void NPObjectStub::OnEnumeration(std::vector<NPIdentifier_Param>* value,
NPN_MemFree(value_np);
}
+void NPObjectStub::OnConstruct(const std::vector<NPVariant_Param>& args,
+ IPC::Message* reply_msg) {
+ scoped_refptr<PluginChannelBase> local_channel = channel_;
+ bool return_value = false;
+ NPVariant_Param result_param;
+ NPVariant result_var;
+
+ VOID_TO_NPVARIANT(result_var);
+
+ int arg_count = static_cast<int>(args.size());
+ NPVariant* args_var = new NPVariant[arg_count];
+ for (int i = 0; i < arg_count; ++i) {
+ CreateNPVariant(
+ args[i], local_channel, &(args_var[i]), modal_dialog_event_);
+ }
+
+ if (IsPluginProcess()) {
+ if (npobject_->_class->construct) {
+ return_value = npobject_->_class->construct(
+ npobject_, args_var, arg_count, &result_var);
+ } else {
+ return_value = false;
+ }
+ } else {
+ return_value = NPN_Construct(
+ 0, npobject_, args_var, arg_count, &result_var);
+ }
+
+ for (int i = 0; i < arg_count; ++i)
+ NPN_ReleaseVariantValue(&(args_var[i]));
+
+ delete[] args_var;
+
+ CreateNPVariantParam(
+ result_var, local_channel, &result_param, true, modal_dialog_event_);
+ NPObjectMsg_Invoke::WriteReplyParams(reply_msg, result_param, return_value);
+ local_channel->Send(reply_msg);
+}
+
void NPObjectStub::OnEvaluate(const std::string& script,
bool popups_allowed,
IPC::Message* reply_msg) {
diff --git a/chrome/plugin/npobject_stub.h b/chrome/plugin/npobject_stub.h
index 0ab0019..94bf2b1 100644
--- a/chrome/plugin/npobject_stub.h
+++ b/chrome/plugin/npobject_stub.h
@@ -72,6 +72,8 @@ class NPObjectStub : public IPC::Channel::Listener,
void OnInvalidate();
void OnEnumeration(std::vector<NPIdentifier_Param>* value,
bool* result);
+ void OnConstruct(const std::vector<NPVariant_Param>& args,
+ IPC::Message* reply_msg);
void OnEvaluate(const std::string& script, bool popups_allowed,
IPC::Message* reply_msg);
void OnSetException(const std::string& message);