Fixing 132759 -- 100% CPU with Flash, r=peterl, sr=jst

git-svn-id: svn://10.0.0.236/trunk@130492 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
av%netscape.com
2002-09-26 02:53:27 +00:00
parent 6d8428579c
commit 945a20c30b
12 changed files with 438 additions and 198 deletions

View File

@@ -987,6 +987,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginNativeWindow.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginDocLoaderFactory.cpp</PATH>
@@ -1098,6 +1105,11 @@
<PATH>nsPluginsDirMac.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginNativeWindow.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginDirServiceProvider.cpp</PATH>
@@ -2064,6 +2076,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginNativeWindow.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginDocLoaderFactory.cpp</PATH>
@@ -2175,6 +2194,11 @@
<PATH>nsPluginsDirMac.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginNativeWindow.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginDirServiceProvider.cpp</PATH>
@@ -2260,6 +2284,12 @@
<PATH>nsPluginsDirMac.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>pluginDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginNativeWindow.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>pluginDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

View File

@@ -987,6 +987,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginNativeWindow.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
</FILELIST>
<LINKORDER>
<FILEREF>
@@ -1044,6 +1051,11 @@
<PATH>nsPluginsDirMac.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginNativeWindow.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</LINKORDER>
</TARGET>
<TARGET>
@@ -1980,6 +1992,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginNativeWindow.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
</FILELIST>
<LINKORDER>
<FILEREF>
@@ -2037,6 +2056,11 @@
<PATH>nsPluginsDirMac.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginNativeWindow.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</LINKORDER>
</TARGET>
</TARGETLIST>
@@ -2126,6 +2150,12 @@
<PATH>nsPluginsDirMac.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>pluginClassicDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPluginNativeWindow.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
<GROUP><NAME>System Libraries</NAME>
<FILEREF>

View File

@@ -55,3 +55,4 @@ npapi.h
npupp.h
nsDefaultPlugin.h
nsPIPluginInstancePeer.h
nsPluginNativeWindow.h

View File

@@ -57,6 +57,7 @@ EXPORTS = \
nsPluginError.h \
nsDefaultPlugin.h \
nsPIPluginInstancePeer.h \
nsPluginNativeWindow.h \
$(NULL)
# 4.x headers moved from mozilla/include

View File

@@ -39,6 +39,7 @@
#define nsPIPluginHost_h___
#include "nsIPluginInstance.h"
#include "nsPluginNativeWindow.h"
#define NS_PIPLUGINHOST_IID \
{/* 8e3d71e6-2319-11d5-9cf8-0060b0fbd8ac */ \
@@ -87,8 +88,20 @@ public:
/*
* To create tmp file with Content len header in, it will use by http POST
*/
NS_IMETHOD
NS_IMETHOD
CreateTmpFileToPost(const char *postDataURL, char **pTmpFileName) = 0;
/**
* Creates a new plugin native window object
*/
NS_IMETHOD
NewPluginNativeWindow(nsPluginNativeWindow ** aPluginNativeWindow) = 0;
/**
* Deletes plugin native window object created by NewPluginNativeWindow
*/
NS_IMETHOD
DeletePluginNativeWindow(nsPluginNativeWindow * aPluginNativeWindow) = 0;
};
#endif /* nsPIPluginHost_h___ */

View File

@@ -73,14 +73,18 @@ CPPSRCS = \
ifeq ($(OS_ARCH), BeOS)
CPPSRCS += nsPluginsDirBeOS.cpp
CPPSRCS += nsPluginNativeWindow.cpp
else
ifeq ($(OS_ARCH),WINNT)
CPPSRCS += nsPluginsDirWin.cpp
CPPSRCS += nsPluginNativeWindowWin.cpp
else
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
CPPSRCS += nsPluginsDirOS2.cpp
CPPSRCS += nsPluginNativeWindow.cpp
else
CPPSRCS += nsPluginsDirUnix.cpp
CPPSRCS += nsPluginNativeWindow.cpp
endif
endif
endif

View File

@@ -163,6 +163,7 @@
#include "nsIWebNavigation.h"
#include "nsISupportsArray.h"
#include "nsIDocShell.h"
#include "nsPluginNativeWindow.h"
#ifdef XP_UNIX
#if defined(MOZ_WIDGET_GTK) || defined (MOZ_WIDGET_GTK2)
@@ -3624,28 +3625,27 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateFullPagePlugin(const char *aMimeType,
if (NS_OK == rv)
{
nsIPluginInstance *instance = nsnull;
nsPluginWindow *window = nsnull;
nsCOMPtr<nsIPluginInstance> instance;
nsPluginWindow * win = nsnull;
aOwner->GetInstance(instance);
aOwner->GetWindow(window);
aOwner->GetInstance(*getter_AddRefs(instance));
aOwner->GetWindow(win);
if (nsnull != instance)
if (win && instance)
{
instance->Start();
aOwner->CreateWidget();
// If we've got a native window, the let the plugin know about it.
nsPluginNativeWindow * window = (nsPluginNativeWindow *)win;
if (window->window)
instance->SetWindow(window);
window->CallSetWindow(instance);
rv = NewFullPagePluginStream(aStreamListener, instance);
// If we've got a native window, the let the plugin know about it.
if (window->window)
instance->SetWindow(window);
NS_RELEASE(instance);
window->CallSetWindow(instance);
}
}
@@ -5729,7 +5729,7 @@ nsPluginHostImpl::AddHeadersToChannel(const char *aHeadersData,
// FINALLY: we can set the header!
//
rv =aChannel->SetRequestHeader(headerName, headerValue);
rv = aChannel->SetRequestHeader(headerName, headerValue);
if (NS_FAILED(rv)) {
rv = NS_ERROR_NULL_POINTER;
return rv;
@@ -6034,8 +6034,13 @@ NS_IMETHODIMP nsPluginHostImpl::Observe(nsISupports *aSubject,
}
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginInstance *instance)
NS_IMETHODIMP
nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginInstance *aInstance)
{
// the |aLibrary| parameter is not needed anymore, after we added |aInstance| which
// can also be used to look up the plugin name, but we cannot get rid of it because
// the |nsIPluginHost| interface is deprecated which in fact means 'frozen'
nsresult rv = NS_OK;
NS_ASSERTION(PR_FALSE, "Plugin performed illegal operation");
@@ -6045,9 +6050,9 @@ NS_IMETHODIMP nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginIn
nsCOMPtr<nsIPluginInstanceOwner> owner;
if (instance) {
if (aInstance) {
nsCOMPtr<nsIPluginInstancePeer> peer;
rv =instance->GetPeer(getter_AddRefs(peer));
rv = aInstance->GetPeer(getter_AddRefs(peer));
if (NS_SUCCEEDED(rv) && peer) {
nsCOMPtr<nsPIPluginInstancePeer> privpeer(do_QueryInterface(peer));
privpeer->GetOwner(getter_AddRefs(owner));
@@ -6081,8 +6086,10 @@ NS_IMETHODIMP nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginIn
// add plugin name to the message
char * pluginname = nsnull;
for (nsPluginTag * tag = mPlugins; tag; tag = tag->mNext) {
if (tag->mLibrary == aLibrary) {
nsActivePlugin * p = mActivePluginList.find(aInstance);
if (p) {
nsPluginTag * tag = p->mPluginTag;
if (tag) {
if (tag->mName)
pluginname = tag->mName;
else
@@ -6110,9 +6117,10 @@ NS_IMETHODIMP nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginIn
return rv;
}
// nsPIPluginHost interface
/**
* nsPIPluginHost interface
*/
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsPluginHostImpl::SetIsScriptableInstance(nsCOMPtr<nsIPluginInstance> aPluginInstance,
PRBool aScriptable)
@@ -6128,8 +6136,6 @@ nsPluginHostImpl::SetIsScriptableInstance(nsCOMPtr<nsIPluginInstance> aPluginIns
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsPluginHostImpl::ParsePostBufferToFixHeaders(
const char *inPostData, PRUint32 inPostDataLen,
@@ -6284,7 +6290,6 @@ nsPluginHostImpl::ParsePostBufferToFixHeaders(
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileName)
{
@@ -6400,6 +6405,20 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa
return rv;
}
NS_IMETHODIMP
nsPluginHostImpl::NewPluginNativeWindow(nsPluginNativeWindow ** aPluginNativeWindow)
{
return PLUG_NewPluginNativeWindow(aPluginNativeWindow);
}
NS_IMETHODIMP
nsPluginHostImpl::DeletePluginNativeWindow(nsPluginNativeWindow * aPluginNativeWindow)
{
return PLUG_DeletePluginNativeWindow(aPluginNativeWindow);
}
/* ----- end of nsPIPluginHost implementation ----- */
nsresult
nsPluginHostImpl::ScanForRealInComponentsFolder(nsIComponentManager * aCompManager)
{

View File

@@ -55,6 +55,7 @@
#include "nsIPrompt.h"
#include "nsIGenericFactory.h"
#include "nsISupportsArray.h"
#include "nsPluginNativeWindow.h"
class ns4xPlugin;
class nsFileSpec;
@@ -363,6 +364,12 @@ public:
NS_IMETHOD
CreateTmpFileToPost(const char *postDataURL, char **pTmpFileName);
NS_IMETHOD
NewPluginNativeWindow(nsPluginNativeWindow ** aPluginNativeWindow);
NS_IMETHOD
DeletePluginNativeWindow(nsPluginNativeWindow * aPluginNativeWindow);
/* Called by GetURL and PostURL */
NS_IMETHOD

View File

@@ -38,6 +38,9 @@
#ifndef nsPluginSafety_h__
#define nsPluginSafety_h__
#include "npapi.h"
#include "nsIPluginHost.h"
#if defined(XP_PC) && !defined(XP_OS2)
#define CALL_SAFETY_ON
#endif

View File

@@ -67,6 +67,8 @@
#include "nsContentCID.h"
#include "nsIScriptGlobalObject.h"
#include "nsITimer.h"
#include "nsPIPluginHost.h"
#include "nsPluginNativeWindow.h"
class nsIPrintSettings;
class nsIDOMWindow;
@@ -163,7 +165,7 @@ public:
#endif
private:
nsPluginWindow mPluginWindow;
nsPluginNativeWindow *mPluginWindow;
nsIPluginInstance *mInstance;
nsIWidget *mWindow; //we do not addref this...
PluginViewerImpl *mViewer; //we do not addref this...
@@ -454,9 +456,14 @@ PluginViewerImpl::Destroy(void)
// doing this in the destructor is too late.
if(mOwner != nsnull)
{
nsIPluginInstance *inst;
if(NS_OK == mOwner->GetInstance(inst))
nsCOMPtr<nsIPluginInstance> inst;
if(NS_SUCCEEDED(mOwner->GetInstance(*getter_AddRefs(inst))))
{
nsPluginWindow *win;
mOwner->GetWindow(win);
nsPluginNativeWindow *window = (nsPluginNativeWindow *)win;
nsCOMPtr<nsIPluginInstance> nullinst;
PRBool doCache = PR_TRUE;
PRBool doCallSetWindowAfterDestroy = PR_FALSE;
@@ -465,23 +472,30 @@ PluginViewerImpl::Destroy(void)
(void *) &doCache);
if (!doCache) {
// then determine if the plugin wants Destroy to be called after
// Set Window. This is for bug 50547.
// Set Window. This is for bug 50547.
inst->GetValue(nsPluginInstanceVariable_CallSetWindowAfterDestroyBool,
(void *) &doCallSetWindowAfterDestroy);
!doCallSetWindowAfterDestroy ? inst->SetWindow(nsnull) : 0;
if (!doCallSetWindowAfterDestroy) {
if (window)
window->CallSetWindow(nullinst);
else
inst->SetWindow(nsnull);
}
inst->Stop();
inst->Destroy();
doCallSetWindowAfterDestroy ? inst->SetWindow(nsnull) : 0; }
else {
inst->SetWindow(nsnull);
if (doCallSetWindowAfterDestroy) {
if (window)
window->CallSetWindow(nullinst);
else
inst->SetWindow(nsnull);
}
} else {
window ? window->CallSetWindow(nullinst) : inst->SetWindow(nsnull);
inst->Stop();
}
NS_RELEASE(inst);
}
}
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP
@@ -586,9 +600,9 @@ PluginViewerImpl::SetBounds(const nsRect& aBounds)
if (nsnull != mWindow) {
// Don't have the widget repaint. Layout will generate repaint requests
// during reflow
nsIPluginInstance *inst;
nsCOMPtr<nsIPluginInstance> inst;
mWindow->Resize(aBounds.x, aBounds.y, aBounds.width, aBounds.height, PR_FALSE);
if ((nsnull != mOwner) && (NS_OK == mOwner->GetInstance(inst)) && (nsnull != inst)) {
if (mOwner && NS_SUCCEEDED(mOwner->GetInstance(*getter_AddRefs(inst))) && inst) {
nsPluginWindow *win;
if (NS_OK == mOwner->GetWindow(win)) {
win->x = aBounds.x;
@@ -603,9 +617,8 @@ PluginViewerImpl::SetBounds(const nsRect& aBounds)
#ifdef XP_MAC // On Mac we also need to add in the widget offset to the plugin window
mOwner->FixUpPluginWindow();
#endif
inst->SetWindow(win);
((nsPluginNativeWindow *)win)->CallSetWindow(inst);
}
NS_RELEASE(inst);
}
}
return NS_OK;
@@ -616,9 +629,9 @@ PluginViewerImpl::Move(PRInt32 aX, PRInt32 aY)
{
NS_PRECONDITION(nsnull != mWindow, "null window");
if (nsnull != mWindow) {
nsIPluginInstance *inst;
nsCOMPtr<nsIPluginInstance> inst;
mWindow->Move(aX, aY);
if ((nsnull != mOwner) && (NS_OK == mOwner->GetInstance(inst)) && (nsnull != inst)) {
if (mOwner && NS_SUCCEEDED(mOwner->GetInstance(*getter_AddRefs(inst))) && inst) {
nsPluginWindow *win;
if (NS_OK == mOwner->GetWindow(win)) {
win->x = aX;
@@ -631,9 +644,8 @@ PluginViewerImpl::Move(PRInt32 aX, PRInt32 aY)
#ifdef XP_MAC // On Mac we also need to add in the widget offset to the plugin window
mOwner->FixUpPluginWindow();
#endif
inst->SetWindow(win);
((nsPluginNativeWindow *)win)->CallSetWindow(inst);
}
NS_RELEASE(inst);
}
}
return NS_OK;
@@ -1020,7 +1032,15 @@ pluginInstanceOwner :: pluginInstanceOwner()
{
NS_INIT_ISUPPORTS();
memset(&mPluginWindow, 0, sizeof(mPluginWindow));
// create nsPluginNativeWindow object, it is derived from nsPluginWindow
// struct and allows to manipulate native window procedure
nsCOMPtr<nsIPluginHost> ph = do_GetService(kCPluginManagerCID);
nsCOMPtr<nsPIPluginHost> pph(do_QueryInterface(ph));
if (pph)
pph->NewPluginNativeWindow(&mPluginWindow);
else
mPluginWindow = nsnull;
mInstance = nsnull;
mWindow = nsnull;
mViewer = nsnull;
@@ -1038,6 +1058,14 @@ pluginInstanceOwner :: ~pluginInstanceOwner()
mWindow = nsnull;
mViewer = nsnull;
// clean up plugin native window object
nsCOMPtr<nsIPluginHost> ph = do_GetService(kCPluginManagerCID);
nsCOMPtr<nsPIPluginHost> pph(do_QueryInterface(ph));
if (pph) {
pph->DeletePluginNativeWindow(mPluginWindow);
mPluginWindow = nsnull;
}
}
NS_IMPL_ISUPPORTS2(pluginInstanceOwner, nsIPluginInstanceOwner,nsITimerCallback);
@@ -1064,7 +1092,8 @@ NS_IMETHODIMP pluginInstanceOwner :: GetInstance(nsIPluginInstance *&aInstance)
NS_IMETHODIMP pluginInstanceOwner :: GetWindow(nsPluginWindow *&aWindow)
{
aWindow = &mPluginWindow;
NS_ASSERTION(mPluginWindow, "the plugin window object being returned is null");
aWindow = mPluginWindow;
return NS_OK;
}
@@ -1076,6 +1105,8 @@ NS_IMETHODIMP pluginInstanceOwner :: GetMode(nsPluginMode *aMode)
NS_IMETHODIMP pluginInstanceOwner :: CreateWidget(void)
{
NS_ENSURE_TRUE(mPluginWindow, NS_ERROR_NULL_POINTER);
PRBool windowless;
nsresult rv = NS_OK;
@@ -1093,13 +1124,13 @@ NS_IMETHODIMP pluginInstanceOwner :: CreateWidget(void)
if (PR_TRUE == windowless)
{
mPluginWindow.window = nsnull; //XXX this needs to be a HDC
mPluginWindow.type = nsPluginWindowType_Drawable;
mPluginWindow->window = nsnull; //XXX this needs to be a HDC
mPluginWindow->type = nsPluginWindowType_Drawable;
}
else if (nsnull != mWindow)
{
mPluginWindow.window = (nsPluginPort *)mWindow->GetNativeData(NS_NATIVE_PLUGIN_PORT);
mPluginWindow.type = nsPluginWindowType_Window;
mPluginWindow->window = (nsPluginPort *)mWindow->GetNativeData(NS_NATIVE_PLUGIN_PORT);
mPluginWindow->type = nsPluginWindowType_Window;
}
else
return NS_ERROR_FAILURE;
@@ -1210,7 +1241,7 @@ NS_IMETHODIMP pluginInstanceOwner::ShowStatus(const PRUnichar *aStatusMsg)
NS_IMETHODIMP pluginInstanceOwner :: GetDocument(nsIDocument* *aDocument)
{
return mViewer->GetDocument(aDocument);
return mViewer->GetDocument(aDocument);
}
NS_IMETHODIMP pluginInstanceOwner :: Init(PluginViewerImpl *aViewer, nsIWidget *aWindow)
@@ -1447,6 +1478,9 @@ static void GetWidgetPosClipAndVis(nsIWidget* aWidget,nscoord& aAbsX, nscoord& a
void pluginInstanceOwner::FixUpPluginWindow()
{
if (!mPluginWindow)
return;
if (mWindow) {
nscoord absWidgetX = 0;
nscoord absWidgetY = 0;
@@ -1458,14 +1492,14 @@ void pluginInstanceOwner::FixUpPluginWindow()
mWidgetVisible = isVisible;
// set the port coordinates
mPluginWindow.x = absWidgetX;
mPluginWindow.y = absWidgetY;
mPluginWindow->x = absWidgetX;
mPluginWindow->y = absWidgetY;
// fix up the clipping region
mPluginWindow.clipRect.top = widgetClip.y;
mPluginWindow.clipRect.left = widgetClip.x;
mPluginWindow.clipRect.bottom = mPluginWindow.clipRect.top + widgetClip.height;
mPluginWindow.clipRect.right = mPluginWindow.clipRect.left + widgetClip.width;
mPluginWindow->clipRect.top = widgetClip.y;
mPluginWindow->clipRect.left = widgetClip.x;
mPluginWindow->clipRect.bottom = mPluginWindow->clipRect.top + widgetClip.height;
mPluginWindow->clipRect.right = mPluginWindow->clipRect.left + widgetClip.width;
}
}