Fixing bug 188938. Adding the ability for plugins to participate in form submission. r=bzbarsky@mit.edu, sr=brendan@mozilla.org

This commit is contained in:
jst%mozilla.jstenback.com 2005-03-09 17:01:22 +00:00
Родитель a9c69f758f
Коммит 5200e318d8
7 изменённых файлов: 89 добавлений и 15 удалений

Просмотреть файл

@ -71,6 +71,7 @@ REQUIRES = xpcom \
exthandler \
uconv \
intl \
plugin \
$(NULL)
EXPORTS = \

Просмотреть файл

@ -45,7 +45,10 @@
#include "nsIPresShell.h"
#include "nsIDOMDocument.h"
#include "nsIWebNavigation.h"
#include "nsIFormControl.h"
#include "nsIFormSubmission.h"
#include "nsIObjectFrame.h"
#include "nsIPluginInstance.h"
#include "nsIPluginInstanceInternal.h"
class nsHTMLObjectElement : public nsGenericHTMLFormElement,
public nsImageLoadingContent,
@ -170,7 +173,47 @@ NS_IMETHODIMP
nsHTMLObjectElement::SubmitNamesValues(nsIFormSubmission* aFormSubmission,
nsIContent* aSubmitElement)
{
return NS_OK;
nsAutoString name;
nsresult rv = GetAttr(kNameSpaceID_None, nsHTMLAtoms::name, name);
if (NS_FAILED(rv)) {
return rv;
}
if (rv == NS_CONTENT_ATTR_NOT_THERE) {
// No name, don't submit.
return NS_OK;
}
nsIFrame* frame = GetPrimaryFrame(PR_FALSE);
nsIObjectFrame *objFrame = nsnull;
if (frame) {
CallQueryInterface(frame, &objFrame);
}
if (!objFrame) {
// No frame, nothing to submit.
return NS_OK;
}
nsCOMPtr<nsIPluginInstance> pi;
objFrame->GetPluginInstance(*getter_AddRefs(pi));
nsCOMPtr<nsIPluginInstanceInternal> pi_internal(do_QueryInterface(pi));
if (!pi_internal) {
// No plugin, nothing to submit.
return NS_OK;
}
nsAutoString value;
rv = pi_internal->GetFormValue(value);
NS_ENSURE_SUCCESS(rv, rv);
return aFormSubmission->AddNameValuePair(this, name, value);
}
NS_IMETHODIMP

Просмотреть файл

@ -128,8 +128,8 @@
// HTMLEmbed/ObjectElement helper includes
#include "nsIPluginInstance.h"
#include "nsIPluginInstanceInternal.h"
#include "nsIObjectFrame.h"
#include "nsINPRuntimePlugin.h"
#include "nsIScriptablePlugin.h"
#include "nsIPluginHost.h"
#include "nsPIPluginHost.h"
@ -7340,11 +7340,11 @@ nsHTMLPluginObjElementSH::GetPluginJSObject(JSContext *cx, JSObject *obj,
*plugin_obj = nsnull;
*plugin_proto = nsnull;
nsCOMPtr<nsINPRuntimePlugin> npruntime_plugin =
nsCOMPtr<nsIPluginInstanceInternal> plugin_internal =
do_QueryInterface(plugin_inst);
if (npruntime_plugin) {
*plugin_obj = npruntime_plugin->GetJSObject(cx);
if (plugin_internal) {
*plugin_obj = plugin_internal->GetJSObject(cx);
if (*plugin_obj) {
*plugin_proto = ::JS_GetPrototype(cx, *plugin_obj);

Просмотреть файл

@ -57,7 +57,7 @@ EXPORTS = \
npupp.h \
npruntime.h \
nptypes.h \
nsINPRuntimePlugin.h \
nsIPluginInstanceInternal.h \
$(NULL)
SDK_HEADERS = \

Просмотреть файл

@ -37,7 +37,7 @@
/*
* npapi.h $Revision: 3.37 $
* npapi.h $Revision: 3.38 $
* Netscape client plug-in API spec
*/
@ -125,7 +125,7 @@
/*----------------------------------------------------------------------*/
#define NP_VERSION_MAJOR 0
#define NP_VERSION_MINOR 14
#define NP_VERSION_MINOR 15
/* The OS/2 version of Netscape uses RC_DATA to define the
@ -390,7 +390,13 @@ typedef enum {
NPPVpluginNeedsXEmbed = 14,
/* Get the NPObject for scripting the plugin. */
NPPVpluginScriptableNPObject = 15
NPPVpluginScriptableNPObject = 15,
/* Get the plugin value (as \0-terminated UTF-8 string data) for
* form submission if the plugin is part of a form. Use
* NPN_MemAlloc() to allocate memory for the string data.
*/
NPPVformValue = 16
} NPPVariable;
/*

Просмотреть файл

@ -764,7 +764,7 @@ nsInstanceStream::~nsInstanceStream()
///////////////////////////////////////////////////////////////////////////////
NS_IMPL_ISUPPORTS3(ns4xPluginInstance, nsIPluginInstance, nsIScriptablePlugin,
nsINPRuntimePlugin)
nsIPluginInstanceInternal)
///////////////////////////////////////////////////////////////////////////////
@ -1545,3 +1545,22 @@ ns4xPluginInstance::GetJSObject(JSContext *cx)
return obj;
}
nsresult
ns4xPluginInstance::GetFormValue(nsAString& aValue)
{
aValue.Truncate();
char *value = nsnull;
nsresult rv = GetValueInternal(NPPVformValue, &value);
if (NS_SUCCEEDED(rv) && value) {
CopyUTF8toUTF16(value, aValue);
// NPPVformValue allocates with NPN_MemAlloc(), which uses
// nsMemory.
nsMemory::Free(value);
}
return NS_OK;
}

Просмотреть файл

@ -54,7 +54,7 @@
#include "nsIPluginInstancePeer.h"
#include "nsIPluginTagInfo2.h"
#include "nsIScriptablePlugin.h"
#include "nsINPRuntimePlugin.h"
#include "nsIPluginInstanceInternal.h"
#include "npupp.h"
#ifdef OJI
@ -83,7 +83,7 @@ struct nsInstanceStream
class ns4xPluginInstance : public nsIPluginInstance,
public nsIScriptablePlugin,
public nsINPRuntimePlugin
public nsIPluginInstanceInternal
{
public:
@ -125,6 +125,13 @@ public:
NS_IMETHOD GetScriptableInterface(nsIID * *aScriptableInterface);
////////////////////////////////////////////////////////////////////////
// nsIPluginInstanceInternal methods
virtual JSObject *GetJSObject(JSContext *cx);
virtual nsresult GetFormValue(nsAString& aValue);
////////////////////////////////////////////////////////////////////////
// ns4xPluginInstance-specific methods
@ -162,8 +169,6 @@ public:
// cache this 4.x plugin like an XPCOM plugin
nsresult SetCached(PRBool aCache) { mCached = aCache; return NS_OK; };
virtual JSObject *GetJSObject(JSContext *cx);
// Non-refcounting accessor for faster access to the peer.
nsIPluginInstancePeer *Peer()
{