Fixing bug 48972 -- adding an interface method GetOwner to plugin instance peer, r=peterl, sr=beard

This commit is contained in:
av%netscape.com 2002-08-22 01:31:44 +00:00
Родитель 6414b5988f
Коммит 7b3dd7bfcc
3 изменённых файлов: 104 добавлений и 176 удалений

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

@ -506,9 +506,10 @@ nsActivePlugin::~nsActivePlugin()
if(mPeer)
{
nsresult rv = NS_OK;
nsPluginInstancePeerImpl * peer = (nsPluginInstancePeerImpl *)mPeer;
nsCOMPtr<nsPIPluginInstancePeer> peer(do_QueryInterface(mPeer));
nsCOMPtr<nsIPluginInstanceOwner> owner;
rv = peer->GetOwner(*getter_AddRefs(owner));
rv = peer->GetOwner(owner);
if (owner)
owner->SetInstance(nsnull);
}
@ -711,9 +712,9 @@ void nsActivePluginList::stopRunning(nsISupportsArray* aReloadDocs)
// removing duplicates. These will be reframed (embedded) or reloaded (full-page) later
// to kickstart our instances.
if (aReloadDocs && p->mPeer) {
nsPluginInstancePeerImpl * peer = (nsPluginInstancePeerImpl *)p->mPeer;
nsCOMPtr<nsPIPluginInstancePeer> peer(do_QueryInterface(p->mPeer));
nsCOMPtr<nsIPluginInstanceOwner> owner;
peer->GetOwner(*getter_AddRefs(owner));
peer->GetOwner(owner);
if (owner) {
nsCOMPtr<nsIDocument> doc;
owner->GetDocument(getter_AddRefs(doc));
@ -3023,33 +3024,23 @@ NS_IMETHODIMP nsPluginHostImpl::GetURLWithHeaders(nsISupports* pluginInst,
rv = pluginInst->QueryInterface(kIPluginInstanceIID, (void **)&instance);
if (NS_SUCCEEDED(rv))
{
if (nsnull != target)
{
nsPluginInstancePeerImpl *peer;
rv = instance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer));
if (NS_SUCCEEDED(rv) && peer)
{
if (NS_SUCCEEDED(rv)) {
if (nsnull != target) {
nsCOMPtr<nsIPluginInstancePeer> peer;
rv = instance->GetPeer(getter_AddRefs(peer));
if (NS_SUCCEEDED(rv) && peer) {
nsCOMPtr<nsPIPluginInstancePeer> privpeer(do_QueryInterface(peer));
nsCOMPtr<nsIPluginInstanceOwner> owner;
rv = peer->GetOwner(*getter_AddRefs(owner));
if (NS_SUCCEEDED(rv))
{
rv = privpeer->GetOwner(owner);
if (owner) {
if ((0 == PL_strcmp(target, "newwindow")) ||
(0 == PL_strcmp(target, "_new")))
target = "_blank";
else if (0 == PL_strcmp(target, "_current"))
target = "_self";
rv = owner->GetURL(url, target, nsnull, 0, (void *) getHeaders,
getHeadersLength);
rv = owner->GetURL(url, target, nsnull, 0, (void *) getHeaders, getHeadersLength);
}
NS_RELEASE(peer);
}
}
@ -3090,8 +3081,7 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst,
rv = pluginInst->QueryInterface(kIPluginInstanceIID, (void **)&instance);
if (NS_SUCCEEDED(rv))
{
if (NS_SUCCEEDED(rv)) {
char *dataToPost;
if (isFile) {
rv = CreateTmpFileToPost(postData, &dataToPost);
@ -3110,22 +3100,17 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst,
postDataLen = newDataToPostLen;
}
if (nsnull != target)
{
nsPluginInstancePeerImpl *peer;
rv = instance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer));
if (nsnull != target) {
nsCOMPtr<nsIPluginInstancePeer> peer;
rv = instance->GetPeer(getter_AddRefs(peer));
if (NS_SUCCEEDED(rv) && peer)
{
if (NS_SUCCEEDED(rv) && peer) {
nsCOMPtr<nsPIPluginInstancePeer> privpeer(do_QueryInterface(peer));
nsCOMPtr<nsIPluginInstanceOwner> owner;
rv = peer->GetOwner(*getter_AddRefs(owner));
if (NS_SUCCEEDED(rv))
{
if (!target) {
rv = privpeer->GetOwner(owner);
if (owner) {
if (!target)
target = "_self";
}
else {
if ((0 == PL_strcmp(target, "newwindow")) ||
(0 == PL_strcmp(target, "_new")))
@ -3133,12 +3118,9 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst,
else if (0 == PL_strcmp(target, "_current"))
target = "_self";
}
rv = owner->GetURL(url, target, (void*)dataToPost, postDataLen,
(void*) postHeaders, postHeadersLength, isFile);
}
NS_RELEASE(peer);
}
}
@ -3150,10 +3132,9 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst,
postHeaders, postHeadersLength);
NS_RELEASE(instance);
if (isFile) {
if (isFile)
nsCRT::free(dataToPost);
}
}
return rv;
}
@ -5605,17 +5586,15 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
// get the full URL of the document that the plugin is embedded
// in to create an absolute url in case aURL is relative
nsCOMPtr<nsIDocument> doc;
nsPluginInstancePeerImpl *peer;
rv = aInstance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer));
if (NS_SUCCEEDED(rv) && peer)
{
nsCOMPtr<nsIPluginInstancePeer> peer;
rv = aInstance->GetPeer(getter_AddRefs(peer));
if (NS_SUCCEEDED(rv) && peer) {
nsCOMPtr<nsPIPluginInstancePeer> privpeer(do_QueryInterface(peer));
nsCOMPtr<nsIPluginInstanceOwner> owner;
rv = peer->GetOwner(*getter_AddRefs(owner));
if (NS_SUCCEEDED(rv) && owner)
{
rv = privpeer->GetOwner(owner);
if (owner) {
rv = owner->GetDocument(getter_AddRefs(doc));
if (NS_SUCCEEDED(rv) && doc)
{
if (NS_SUCCEEDED(rv) && doc) {
nsCOMPtr<nsIURI> docURL;
doc->GetDocumentURL(getter_AddRefs(docURL));
doc->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
@ -5624,7 +5603,6 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
rv = NS_MakeAbsoluteURI(absUrl, aURL, docURL);
}
}
NS_RELEASE(peer);
}
if (absUrl.IsEmpty())
@ -5632,8 +5610,7 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
rv = NS_NewURI(getter_AddRefs(url), absUrl);
if (NS_SUCCEEDED(rv))
{
if (NS_SUCCEEDED(rv)) {
nsPluginStreamListenerPeer *listenerPeer = new nsPluginStreamListenerPeer;
if (listenerPeer == NULL)
return NS_ERROR_OUT_OF_MEMORY;
@ -5641,8 +5618,7 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
NS_ADDREF(listenerPeer);
rv = listenerPeer->Initialize(url, aInstance, aListener);
if (NS_SUCCEEDED(rv))
{
if (NS_SUCCEEDED(rv)) {
// it is possible one plugin instance can request several different
// streams, if we are serving those streams as files from
// temp location (e.g. browser cache is not available)
@ -5651,22 +5627,19 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
// lets add this listener peer to the to list of stream peers for this instance,
// it'll delay the release until nsActivePlugin::setStopped() call.
nsActivePlugin * p = mActivePluginList.find(aInstance);
if (p && p->mStreams)
{
if (p && p->mStreams) {
p->mStreams->AppendElement((void *)listenerPeer);
NS_ADDREF(listenerPeer);
}
nsCOMPtr<nsIInterfaceRequestor> callbacks;
if (doc)
{
if (doc) {
// Get the script global object owner and use that as the notification callback
nsCOMPtr<nsIScriptGlobalObject> global;
doc->GetScriptGlobalObject(getter_AddRefs(global));
if (global)
{
if (global) {
nsCOMPtr<nsIScriptGlobalObjectOwner> owner;
global->GetGlobalObjectOwner(getter_AddRefs(owner));
@ -5680,8 +5653,7 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
if (NS_FAILED(rv))
return rv;
if (doc)
{
if (doc) {
// Set the owner of channel to the document principal...
nsCOMPtr<nsIPrincipal> principal;
doc->GetPrincipal(getter_AddRefs(principal));
@ -5698,8 +5670,7 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
rv = NS_NewPluginPostDataStream(getter_AddRefs(postDataStream), (const char*)aPostData,
aPostDataLen, aIsFile);
if (!postDataStream)
{
if (!postDataStream) {
NS_RELEASE(aInstance);
return NS_ERROR_UNEXPECTED;
}
@ -6098,10 +6069,11 @@ NS_IMETHODIMP nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginIn
nsCOMPtr<nsIPluginInstanceOwner> owner;
if (instance) {
nsPluginInstancePeerImpl *peer;
rv =instance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer));
nsCOMPtr<nsIPluginInstancePeer> peer;
rv =instance->GetPeer(getter_AddRefs(peer));
if (NS_SUCCEEDED(rv) && peer) {
peer->GetOwner(*getter_AddRefs(owner));
nsCOMPtr<nsPIPluginInstancePeer> privpeer(do_QueryInterface(peer));
privpeer->GetOwner(owner);
}
}
@ -6535,20 +6507,18 @@ nsresult nsPluginStreamListenerPeer::ServeStreamAsFile(nsIRequest *request,
// mInstance->Stop calls mPStreamListener->CleanUpStream(), so stream will be properly clean up
mInstance->Stop();
mInstance->Start();
nsPluginInstancePeerImpl *peer;
mInstance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer));
nsCOMPtr<nsIPluginInstancePeer> peer;
mInstance->GetPeer(getter_AddRefs(peer));
if (peer) {
nsCOMPtr<nsPIPluginInstancePeer> privpeer(do_QueryInterface(peer));
nsCOMPtr<nsIPluginInstanceOwner> owner;
peer->GetOwner(*getter_AddRefs(owner));
privpeer->GetOwner(owner);
if (owner) {
nsPluginWindow *window = nsnull;
owner->GetWindow(window);
if (window->window)
mInstance->SetWindow(window);
}
// because we are starting plugin using existing peer
// it'll get one extra RefCnt, release it here.
NS_RELEASE(peer);
}
mPluginStreamInfo->SetSeekable(0);

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

@ -86,55 +86,14 @@ nsPluginInstancePeerImpl::~nsPluginInstancePeerImpl()
static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID);
static NS_DEFINE_IID(kIJVMPluginTagInfoIID, NS_IJVMPLUGINTAGINFO_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIWindowlessPluginInstancePeerIID, NS_IWINDOWLESSPLUGININSTANCEPEER_IID);//~~~
NS_IMPL_ADDREF(nsPluginInstancePeerImpl);
NS_IMPL_RELEASE(nsPluginInstancePeerImpl);
nsresult nsPluginInstancePeerImpl::QueryInterface(const nsIID& iid, void** instance)
{
if (instance == NULL)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(NS_GET_IID(nsIPluginInstancePeer)) || iid.Equals(NS_GET_IID(nsIPluginInstancePeer2))) {
*instance = (void *)(nsIPluginInstancePeer2*)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kIWindowlessPluginInstancePeerIID)) {
*instance = (void *)(nsIWindowlessPluginInstancePeer*)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kIPluginTagInfoIID)) {
*instance = (void *)(nsIPluginTagInfo *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kIPluginTagInfo2IID)) {
*instance = (void *)(nsIPluginTagInfo2 *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kIJVMPluginTagInfoIID)) {
*instance = (void *)(nsIJVMPluginTagInfo *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kISupportsIID)) {
*instance = (void *)(nsISupports *)(nsIPluginTagInfo *)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ISUPPORTS6(nsPluginInstancePeerImpl,
nsIPluginInstancePeer,
nsIPluginInstancePeer2,
nsIWindowlessPluginInstancePeer,
nsIPluginTagInfo2,
nsIJVMPluginTagInfo,
nsPIPluginInstancePeer);
NS_IMETHODIMP nsPluginInstancePeerImpl::GetValue(nsPluginInstancePeerVariable variable, void *value)
{
@ -218,7 +177,7 @@ nsPluginStreamToFile::nsPluginStreamToFile(const char* target, nsIPluginInstance
if (NS_FAILED(rv))
return;
mOutputStream->Close();
//mOutputStream->Close();
// construct the URL we'll use later in calls to GetURL()
NS_GetURLSpecFromFile(mTempFile, mFileURL);
@ -837,15 +796,10 @@ nsresult nsPluginInstancePeerImpl::SetOwner(nsIPluginInstanceOwner *aOwner)
return NS_OK;
}
nsresult nsPluginInstancePeerImpl::GetOwner(nsIPluginInstanceOwner *&aOwner)
NS_IMETHODIMP nsPluginInstancePeerImpl::GetOwner(nsCOMPtr<nsIPluginInstanceOwner> &aOwner)
{
aOwner = mOwner;
NS_IF_ADDREF(mOwner);
if (nsnull != mOwner)
return NS_OK;
else
return NS_ERROR_FAILURE;
aOwner = mOwner; // this assignment will addref
return (mOwner) ? NS_OK : NS_ERROR_FAILURE;
}

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

@ -43,12 +43,13 @@
#include "nsIPluginTagInfo.h"
#include "nsIPluginInstanceOwner.h"
#include "nsIJVMPluginTagInfo.h"
#include "nsPIPluginInstancePeer.h"
class nsPluginInstancePeerImpl : public nsIPluginInstancePeer2,
public nsIWindowlessPluginInstancePeer,
public nsIPluginTagInfo2,
public nsIJVMPluginTagInfo
public nsIJVMPluginTagInfo,
public nsPIPluginInstancePeer
{
public:
@ -171,6 +172,11 @@ public:
NS_IMETHOD
GetMayScript(PRBool *result);
// nsPIPluginInstancePeer interface
NS_IMETHOD
GetOwner(nsCOMPtr<nsIPluginInstanceOwner> &aOwner);
//locals
nsresult Initialize(nsIPluginInstanceOwner *aOwner,
@ -178,8 +184,6 @@ public:
nsresult SetOwner(nsIPluginInstanceOwner *aOwner);
nsresult GetOwner(nsIPluginInstanceOwner *&aOwner);
private:
nsIPluginInstance *mInstance; //we don't add a ref to this
nsIPluginInstanceOwner *mOwner; //we don't add a ref to this