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

This commit is contained in:
av%netscape.com 2002-08-23 11:23:49 +00:00
Родитель 0470f79669
Коммит cbb401e71a
4 изменённых файлов: 53 добавлений и 163 удалений

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

@ -1,61 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsPIPluginInstancePeer_h___
#define nsPIPluginInstancePeer_h___
#include "nsIPluginInstanceOwner.h"
#define NS_PIPLUGININSTANCEPEER_IID \
{/* 4a708562-8a37-400b-8c08-20037d1adad3 */ \
0x4a708562, 0x8a37, 0x400b, \
{0x8c, 0x08, 0x20, 0x03, 0x7d, 0x1a, 0xda, 0xd3} \
}
class nsPIPluginInstancePeer : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_PIPLUGININSTANCEPEER_IID)
/*
* To get a plugin instance owner
*/
NS_IMETHOD
GetOwner(nsCOMPtr<nsIPluginInstanceOwner> &aOwner) = 0;
};
#endif /* nsPIPluginInstancePeer_h___ */

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

@ -506,10 +506,11 @@ nsActivePlugin::~nsActivePlugin()
if(mPeer) if(mPeer)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsPluginInstancePeerImpl * peer = (nsPluginInstancePeerImpl *)mPeer; nsCOMPtr<nsPIPluginInstancePeer> peer(do_QueryInterface(mPeer));
nsCOMPtr<nsIPluginInstanceOwner> owner; nsCOMPtr<nsIPluginInstanceOwner> owner;
rv = peer->GetOwner(*getter_AddRefs(owner)); rv = peer->GetOwner(getter_AddRefs(owner));
owner->SetInstance(nsnull); if (owner)
owner->SetInstance(nsnull);
} }
// now check for cached plugins because they haven't had nsIPluginInstance::Destroy() // now check for cached plugins because they haven't had nsIPluginInstance::Destroy()
@ -711,9 +712,9 @@ void nsActivePluginList::stopRunning(nsISupportsArray* aReloadDocs)
// removing duplicates. These will be reframed (embedded) or reloaded (full-page) later // removing duplicates. These will be reframed (embedded) or reloaded (full-page) later
// to kickstart our instances. // to kickstart our instances.
if (aReloadDocs && p->mPeer) { if (aReloadDocs && p->mPeer) {
nsPluginInstancePeerImpl * peer = (nsPluginInstancePeerImpl *)p->mPeer; nsCOMPtr<nsPIPluginInstancePeer> peer(do_QueryInterface(p->mPeer));
nsCOMPtr<nsIPluginInstanceOwner> owner; nsCOMPtr<nsIPluginInstanceOwner> owner;
peer->GetOwner(*getter_AddRefs(owner)); peer->GetOwner(getter_AddRefs(owner));
if (owner) { if (owner) {
nsCOMPtr<nsIDocument> doc; nsCOMPtr<nsIDocument> doc;
owner->GetDocument(getter_AddRefs(doc)); owner->GetDocument(getter_AddRefs(doc));
@ -3027,17 +3028,14 @@ NS_IMETHODIMP nsPluginHostImpl::GetURLWithHeaders(nsISupports* pluginInst,
{ {
if (nsnull != target) if (nsnull != target)
{ {
nsPluginInstancePeerImpl *peer; nsCOMPtr<nsIPluginInstancePeer> peer;
rv = instance->GetPeer(getter_AddRefs(peer));
rv = instance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer));
if (NS_SUCCEEDED(rv) && peer) if (NS_SUCCEEDED(rv) && peer)
{ {
nsCOMPtr<nsPIPluginInstancePeer> privpeer(do_QueryInterface(peer));
nsCOMPtr<nsIPluginInstanceOwner> owner; nsCOMPtr<nsIPluginInstanceOwner> owner;
rv = privpeer->GetOwner(getter_AddRefs(owner));
rv = peer->GetOwner(*getter_AddRefs(owner)); if (owner)
if (NS_SUCCEEDED(rv))
{ {
if ((0 == PL_strcmp(target, "newwindow")) || if ((0 == PL_strcmp(target, "newwindow")) ||
(0 == PL_strcmp(target, "_new"))) (0 == PL_strcmp(target, "_new")))
@ -3045,19 +3043,14 @@ NS_IMETHODIMP nsPluginHostImpl::GetURLWithHeaders(nsISupports* pluginInst,
else if (0 == PL_strcmp(target, "_current")) else if (0 == PL_strcmp(target, "_current"))
target = "_self"; target = "_self";
rv = owner->GetURL(url, target, nsnull, 0, (void *) getHeaders, rv = owner->GetURL(url, target, nsnull, 0, (void *) getHeaders, getHeadersLength);
getHeadersLength);
} }
NS_RELEASE(peer);
} }
} }
if (nsnull != streamListener) if (nsnull != streamListener)
rv = NewPluginURLStream(string, instance, streamListener, nsnull, rv = NewPluginURLStream(string, instance, streamListener, nsnull,
PR_FALSE, nsnull, getHeaders, getHeadersLength); PR_FALSE, nsnull, getHeaders, getHeadersLength);
NS_RELEASE(instance);
} }
return rv; return rv;
@ -3112,16 +3105,15 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst,
if (nsnull != target) if (nsnull != target)
{ {
nsPluginInstancePeerImpl *peer; nsCOMPtr<nsIPluginInstancePeer> peer;
rv = instance->GetPeer(NS_REINTERPRET_CAST(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; nsCOMPtr<nsIPluginInstanceOwner> owner;
rv = privpeer->GetOwner(getter_AddRefs(owner));
rv = peer->GetOwner(*getter_AddRefs(owner)); if (owner)
if (NS_SUCCEEDED(rv))
{ {
if (!target) { if (!target) {
target = "_self"; target = "_self";
@ -3137,8 +3129,6 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst,
rv = owner->GetURL(url, target, (void*)dataToPost, postDataLen, rv = owner->GetURL(url, target, (void*)dataToPost, postDataLen,
(void*) postHeaders, postHeadersLength, isFile); (void*) postHeaders, postHeadersLength, isFile);
} }
NS_RELEASE(peer);
} }
} }
@ -5063,8 +5053,9 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins()
nsresult nsPluginHostImpl::FindPlugins(PRBool aCreatePluginList, PRBool * aPluginsChanged) nsresult nsPluginHostImpl::FindPlugins(PRBool aCreatePluginList, PRBool * aPluginsChanged)
{ {
// let's start timing if we are only really creating the plugin list // let's start timing if we are only really creating the plugin list
if (aCreatePluginList) if (aCreatePluginList) {
NS_TIMELINE_START_TIMER("LoadPlugins"); NS_TIMELINE_START_TIMER("LoadPlugins");
}
#ifdef CALL_SAFETY_ON #ifdef CALL_SAFETY_ON
// check preferences on whether or not we want to try safe calls to plugins // check preferences on whether or not we want to try safe calls to plugins
@ -5614,13 +5605,15 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
// get the full URL of the document that the plugin is embedded // get the full URL of the document that the plugin is embedded
// in to create an absolute url in case aURL is relative // in to create an absolute url in case aURL is relative
nsCOMPtr<nsIDocument> doc; nsCOMPtr<nsIDocument> doc;
nsPluginInstancePeerImpl *peer; nsCOMPtr<nsIPluginInstancePeer> peer;
rv = aInstance->GetPeer(getter_AddRefs(peer));
rv = aInstance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer)); rv = aInstance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer));
if (NS_SUCCEEDED(rv) && peer) if (NS_SUCCEEDED(rv) && peer)
{ {
nsCOMPtr<nsPIPluginInstancePeer> privpeer(do_QueryInterface(peer));
nsCOMPtr<nsIPluginInstanceOwner> owner; nsCOMPtr<nsIPluginInstanceOwner> owner;
rv = peer->GetOwner(*getter_AddRefs(owner)); rv = privpeer->GetOwner(getter_AddRefs(owner));
if (NS_SUCCEEDED(rv) && owner) if (owner)
{ {
rv = owner->GetDocument(getter_AddRefs(doc)); rv = owner->GetDocument(getter_AddRefs(doc));
if (NS_SUCCEEDED(rv) && doc) if (NS_SUCCEEDED(rv) && doc)
@ -5633,7 +5626,6 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
rv = NS_MakeAbsoluteURI(absUrl, aURL, docURL); rv = NS_MakeAbsoluteURI(absUrl, aURL, docURL);
} }
} }
NS_RELEASE(peer);
} }
if (absUrl.IsEmpty()) if (absUrl.IsEmpty())
@ -6107,10 +6099,11 @@ NS_IMETHODIMP nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginIn
nsCOMPtr<nsIPluginInstanceOwner> owner; nsCOMPtr<nsIPluginInstanceOwner> owner;
if (instance) { if (instance) {
nsPluginInstancePeerImpl *peer; nsCOMPtr<nsIPluginInstancePeer> peer;
rv =instance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer)); rv =instance->GetPeer(getter_AddRefs(peer));
if (NS_SUCCEEDED(rv) && peer) { if (NS_SUCCEEDED(rv) && peer) {
peer->GetOwner(*getter_AddRefs(owner)); nsCOMPtr<nsPIPluginInstancePeer> privpeer(do_QueryInterface(peer));
privpeer->GetOwner(getter_AddRefs(owner));
} }
} }
@ -6544,20 +6537,18 @@ nsresult nsPluginStreamListenerPeer::ServeStreamAsFile(nsIRequest *request,
// mInstance->Stop calls mPStreamListener->CleanUpStream(), so stream will be properly clean up // mInstance->Stop calls mPStreamListener->CleanUpStream(), so stream will be properly clean up
mInstance->Stop(); mInstance->Stop();
mInstance->Start(); mInstance->Start();
nsPluginInstancePeerImpl *peer; nsCOMPtr<nsIPluginInstancePeer> peer;
mInstance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer)); mInstance->GetPeer(getter_AddRefs(peer));
if (peer) { if (peer) {
nsCOMPtr<nsPIPluginInstancePeer> privpeer(do_QueryInterface(peer));
nsCOMPtr<nsIPluginInstanceOwner> owner; nsCOMPtr<nsIPluginInstanceOwner> owner;
peer->GetOwner(*getter_AddRefs(owner)); privpeer->GetOwner(getter_AddRefs(owner));
if (owner) { if (owner) {
nsPluginWindow *window = nsnull; nsPluginWindow *window = nsnull;
owner->GetWindow(window); owner->GetWindow(window);
if (window->window) if (window->window)
mInstance->SetWindow(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); mPluginStreamInfo->SetSeekable(0);

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

@ -86,55 +86,15 @@ nsPluginInstancePeerImpl::~nsPluginInstancePeerImpl()
static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID); static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID); static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID);
static NS_DEFINE_IID(kIJVMPluginTagInfoIID, NS_IJVMPLUGINTAGINFO_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_ISUPPORTS7(nsPluginInstancePeerImpl,
NS_IMPL_RELEASE(nsPluginInstancePeerImpl); nsIPluginInstancePeer,
nsIPluginInstancePeer2,
nsresult nsPluginInstancePeerImpl::QueryInterface(const nsIID& iid, void** instance) nsIWindowlessPluginInstancePeer,
{ nsIPluginTagInfo,
if (instance == NULL) nsIPluginTagInfo2,
return NS_ERROR_NULL_POINTER; nsIJVMPluginTagInfo,
nsPIPluginInstancePeer);
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_IMETHODIMP nsPluginInstancePeerImpl::GetValue(nsPluginInstancePeerVariable variable, void *value) NS_IMETHODIMP nsPluginInstancePeerImpl::GetValue(nsPluginInstancePeerVariable variable, void *value)
{ {
@ -837,18 +797,14 @@ nsresult nsPluginInstancePeerImpl::SetOwner(nsIPluginInstanceOwner *aOwner)
return NS_OK; return NS_OK;
} }
nsresult nsPluginInstancePeerImpl::GetOwner(nsIPluginInstanceOwner *&aOwner) NS_IMETHODIMP nsPluginInstancePeerImpl::GetOwner(nsIPluginInstanceOwner **aOwner)
{ {
aOwner = mOwner; NS_ENSURE_ARG_POINTER(aOwner);
*aOwner = mOwner;
NS_IF_ADDREF(mOwner); NS_IF_ADDREF(mOwner);
return (mOwner) ? NS_OK : NS_ERROR_FAILURE;
if (nsnull != mOwner)
return NS_OK;
else
return NS_ERROR_FAILURE;
} }
NS_IMETHODIMP nsPluginInstancePeerImpl::InvalidateRect(nsPluginRect *invalidRect) NS_IMETHODIMP nsPluginInstancePeerImpl::InvalidateRect(nsPluginRect *invalidRect)
{ {
if(!mOwner) if(!mOwner)

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

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