diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index 7324d931656..66b34e1b6d2 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -128,6 +128,8 @@ #include "nsObjectFrame.h" #include "nsIObjectFrame.h" +#include "nsPluginNativeWindow.h" +#include "nsPIPluginHost.h" // accessibility support #ifdef ACCESSIBILITY @@ -327,7 +329,7 @@ public: #endif private: - nsPluginWindow mPluginWindow; + nsPluginNativeWindow *mPluginWindow; nsIPluginInstance *mInstance; nsObjectFrame *mOwner; nsCString mDocumentBase; @@ -667,9 +669,14 @@ nsObjectFrame::Destroy(nsIPresContext* aPresContext) // doing this in the destructor is too late. if(mInstanceOwner != nsnull) { - nsIPluginInstance *inst; - if(NS_OK == mInstanceOwner->GetInstance(inst)) + nsCOMPtr inst; + if(NS_SUCCEEDED(mInstanceOwner->GetInstance(*getter_AddRefs(inst)))) { + nsPluginWindow *win; + mInstanceOwner->GetWindow(win); + nsPluginNativeWindow *window = (nsPluginNativeWindow *)win; + nsCOMPtr nullinst; + PRBool doCache = PR_TRUE; PRBool doCallSetWindowAfterDestroy = PR_FALSE; @@ -684,24 +691,34 @@ nsObjectFrame::Destroy(nsIPresContext* aPresContext) if (doCallSetWindowAfterDestroy) { inst->Stop(); inst->Destroy(); - inst->SetWindow(nsnull); + + if (window) + window->CallSetWindow(nullinst); + else + inst->SetWindow(nsnull); } else { - inst->SetWindow(nsnull); + if (window) + window->CallSetWindow(nullinst); + else + inst->SetWindow(nsnull); + inst->Stop(); inst->Destroy(); } } else { - inst->SetWindow(nsnull); + if (window) + window->CallSetWindow(nullinst); + else + inst->SetWindow(nsnull); + inst->Stop(); } nsCOMPtr pluginHost = do_GetService(kCPluginManagerCID); if(pluginHost) pluginHost->StopPluginInstance(inst); - - NS_RELEASE(inst); } } return nsObjectFrameSuper::Destroy(aPresContext); @@ -1243,6 +1260,8 @@ nsObjectFrame::InstantiatePlugin(nsIPresContext* aPresContext, mInstanceOwner->GetWindow(window); + NS_ENSURE_TRUE(window, NS_ERROR_NULL_POINTER); + GetOffsetFromView(aPresContext, origin, &parentWithView); window->x = NSTwipsToIntPixels(origin.x, t2p); window->y = NSTwipsToIntPixels(origin.y, t2p); @@ -1528,16 +1547,18 @@ nsObjectFrame::DidReflow(nsIPresContext* aPresContext, vm->SetViewVisibility(view, bHidden ? nsViewVisibility_kHide : nsViewVisibility_kShow); } - nsPluginWindow *window; + nsPluginWindow *win = nsnull; nsCOMPtr pi; if (!mInstanceOwner || - NS_FAILED(rv = mInstanceOwner->GetWindow(window)) || + NS_FAILED(rv = mInstanceOwner->GetWindow(win)) || NS_FAILED(rv = mInstanceOwner->GetInstance(*getter_AddRefs(pi))) || !pi || - !window) + !win) return rv; + nsPluginNativeWindow *window = (nsPluginNativeWindow *)win; + #ifdef XP_MAC mInstanceOwner->FixUpPluginWindow(); #endif // XP_MAC @@ -1557,7 +1578,11 @@ nsObjectFrame::DidReflow(nsIPresContext* aPresContext, // refresh the plugin port as well window->window = mInstanceOwner->GetPluginPort(); - pi->SetWindow(window); + + // this will call pi->SetWindow and take care of window subclassing + // if needed, see bug 132759 + window->CallSetWindow(pi); + mInstanceOwner->ReleasePluginPort((nsPluginPort *)window->window); if (mWidget) { @@ -2091,7 +2116,15 @@ nsPluginInstanceOwner::nsPluginInstanceOwner() { 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 ph = do_GetService(kCPluginManagerCID); + nsCOMPtr pph(do_QueryInterface(ph)); + if (pph) + pph->NewPluginNativeWindow(&mPluginWindow); + else + mPluginWindow = nsnull; + mInstance = nsnull; mOwner = nsnull; mWidget = nsnull; @@ -2152,11 +2185,19 @@ nsPluginInstanceOwner::~nsPluginInstanceOwner() #ifdef XP_UNIX // the mem for this struct is allocated // by PR_MALLOC in ns4xPluginInstance.cpp:ns4xPluginInstance::SetWindow() - if (mPluginWindow.ws_info) { - PR_Free(mPluginWindow.ws_info); - mPluginWindow.ws_info = nsnull; + if (mPluginWindow && mPluginWindow->ws_info) { + PR_Free(mPluginWindow->ws_info); + mPluginWindow->ws_info = nsnull; } #endif + + // clean up plugin native window object + nsCOMPtr ph = do_GetService(kCPluginManagerCID); + nsCOMPtr pph(do_QueryInterface(ph)); + if (pph) { + pph->DeletePluginNativeWindow(mPluginWindow); + mPluginWindow = nsnull; + } } /* @@ -2193,7 +2234,8 @@ NS_IMETHODIMP nsPluginInstanceOwner::SetInstance(nsIPluginInstance *aInstance) NS_IMETHODIMP nsPluginInstanceOwner::GetWindow(nsPluginWindow *&aWindow) { - aWindow = &mPluginWindow; + NS_ASSERTION(mPluginWindow, "the plugin window object being returned is null"); + aWindow = mPluginWindow; return NS_OK; } @@ -2746,7 +2788,9 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetWidth(PRUint32 *result) { NS_ENSURE_ARG_POINTER(result); - *result = mPluginWindow.width; + NS_ENSURE_TRUE(mPluginWindow, NS_ERROR_NULL_POINTER); + + *result = mPluginWindow->width; return NS_OK; } @@ -2755,7 +2799,9 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetHeight(PRUint32 *result) { NS_ENSURE_ARG_POINTER(result); - *result = mPluginWindow.height; + NS_ENSURE_TRUE(mPluginWindow, NS_ERROR_NULL_POINTER); + + *result = mPluginWindow->height; return NS_OK; } @@ -3190,7 +3236,7 @@ nsresult nsPluginInstanceOwner::Blur(nsIDOMEvent * aFocusEvent) nsresult nsPluginInstanceOwner::DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent) { #ifndef XP_MAC - if (nsPluginWindowType_Window == mPluginWindow.type) + if (!mPluginWindow || nsPluginWindowType_Window == mPluginWindow->type) return NS_ERROR_FAILURE; // means consume event // continue only for cases without child window #endif @@ -3344,7 +3390,7 @@ nsresult nsPluginInstanceOwner::KeyPress(nsIDOMEvent* aKeyEvent) nsresult nsPluginInstanceOwner::DispatchKeyToPlugin(nsIDOMEvent* aKeyEvent) { #ifndef XP_MAC - if (nsPluginWindowType_Window == mPluginWindow.type) + if (!mPluginWindow || nsPluginWindowType_Window == mPluginWindow->type) return NS_ERROR_FAILURE; // means consume event // continue only for cases without child window #endif @@ -3382,7 +3428,7 @@ nsresult nsPluginInstanceOwner::MouseMove(nsIDOMEvent* aMouseEvent) { #ifndef XP_MAC - if (nsPluginWindowType_Window == mPluginWindow.type) + if (!mPluginWindow || nsPluginWindowType_Window == mPluginWindow->type) return NS_ERROR_FAILURE; // means consume event // continue only for cases without child window #endif @@ -3414,14 +3460,14 @@ nsresult nsPluginInstanceOwner::MouseDown(nsIDOMEvent* aMouseEvent) { #ifndef XP_MAC - if (nsPluginWindowType_Window == mPluginWindow.type) + if (!mPluginWindow || nsPluginWindowType_Window == mPluginWindow->type) return NS_ERROR_FAILURE; // means consume event // continue only for cases without child window #endif // if the plugin is windowless, we need to set focus ourselves // otherwise, we might not get key events - if (mPluginWindow.type == nsPluginWindowType_Drawable) { + if (mPluginWindow && mPluginWindow->type == nsPluginWindowType_Drawable) { nsCOMPtr content; mOwner->GetContent(getter_AddRefs(content)); if (content) @@ -3478,7 +3524,7 @@ nsPluginInstanceOwner::MouseOut(nsIDOMEvent* aMouseEvent) nsresult nsPluginInstanceOwner::DispatchMouseToPlugin(nsIDOMEvent* aMouseEvent) { #ifndef XP_MAC - if (nsPluginWindowType_Window == mPluginWindow.type) + if (!mPluginWindow || nsPluginWindowType_Window == mPluginWindow->type) return NS_ERROR_FAILURE; // means consume event // continue only for cases without child window #endif @@ -3899,7 +3945,7 @@ nsPluginPort* nsPluginInstanceOwner::GetPluginPort() if (mWidget != NULL) { #ifdef XP_WIN - if(mPluginWindow.type == nsPluginWindowType_Drawable) + if(mPluginWindow && mPluginWindow->type == nsPluginWindowType_Drawable) result = (nsPluginPort*) mWidget->GetNativeData(NS_NATIVE_GRAPHIC); else #endif @@ -3913,7 +3959,7 @@ void nsPluginInstanceOwner::ReleasePluginPort(nsPluginPort * pluginPort) #ifdef XP_WIN if (mWidget != NULL) { - if(mPluginWindow.type == nsPluginWindowType_Drawable) + if(mPluginWindow && mPluginWindow->type == nsPluginWindowType_Drawable) mWidget->FreeNativeData((HDC)pluginPort, NS_NATIVE_GRAPHIC); } #endif @@ -3921,6 +3967,8 @@ void nsPluginInstanceOwner::ReleasePluginPort(nsPluginPort * pluginPort) NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void) { + NS_ENSURE_TRUE(mPluginWindow, NS_ERROR_NULL_POINTER); + nsIView *view; nsresult rv = NS_ERROR_FAILURE; float p2t; @@ -3940,8 +3988,8 @@ NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void) // always create widgets in Twips, not pixels mContext->GetScaledPixelsToTwips(&p2t); rv = mOwner->CreateWidget(mContext, - NSIntPixelsToTwips(mPluginWindow.width, p2t), - NSIntPixelsToTwips(mPluginWindow.height, p2t), + NSIntPixelsToTwips(mPluginWindow->width, p2t), + NSIntPixelsToTwips(mPluginWindow->height, p2t), windowless); if (NS_OK == rv) { @@ -3961,20 +4009,20 @@ NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void) if (PR_TRUE == windowless) { - mPluginWindow.type = nsPluginWindowType_Drawable; - mPluginWindow.window = nsnull; // this needs to be a HDC according to the spec, + mPluginWindow->type = nsPluginWindowType_Drawable; + mPluginWindow->window = nsnull; // this needs to be a HDC according to the spec, // but I do not see the right way to release it // so let's postpone passing HDC till paint event // when it is really needed. Change spec? } else if (mWidget) { - mWidget->Resize(mPluginWindow.width, mPluginWindow.height, PR_FALSE); + mWidget->Resize(mPluginWindow->width, mPluginWindow->height, PR_FALSE); - // mPluginWindow.type is used in |GetPluginPort| so it must be initilized first - mPluginWindow.type = nsPluginWindowType_Window; - mPluginWindow.window = GetPluginPort(); + // mPluginWindow->type is used in |GetPluginPort| so it must be initilized first + mPluginWindow->type = nsPluginWindowType_Window; + mPluginWindow->window = GetPluginPort(); #if defined(XP_MAC) // Is this needed in the windowless case ??? @@ -4131,48 +4179,49 @@ inline PRUint16 COLOR8TOCOLOR16(PRUint8 color8) void nsPluginInstanceOwner::FixUpPluginWindow() { - if (mWidget) { - nscoord absWidgetX = 0; - nscoord absWidgetY = 0; - nsRect widgetClip(0,0,0,0); - - // first, check our view for CSS visibility style - nsIView *view; - mOwner->GetView(mContext, &view); - nsViewVisibility vis; - view->GetVisibility(vis); - PRBool isVisible = (vis == nsViewVisibility_kShow) ? PR_TRUE : PR_FALSE; - - GetWidgetPosClipAndVis(mWidget,absWidgetX,absWidgetY,widgetClip,isVisible); + if (!mWidget || !mPluginWindow) + return; - if (mWidgetVisible != isVisible) - mWidgetVisible = isVisible; + nscoord absWidgetX = 0; + nscoord absWidgetY = 0; + nsRect widgetClip(0,0,0,0); + + // first, check our view for CSS visibility style + nsIView *view; + mOwner->GetView(mContext, &view); + nsViewVisibility vis; + view->GetVisibility(vis); + PRBool isVisible = (vis == nsViewVisibility_kShow) ? PR_TRUE : PR_FALSE; + + GetWidgetPosClipAndVis(mWidget,absWidgetX,absWidgetY,widgetClip,isVisible); - // set the port coordinates - mPluginWindow.x = absWidgetX; - mPluginWindow.y = absWidgetY; + if (mWidgetVisible != isVisible) + mWidgetVisible = isVisible; - // 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; + // set the port coordinates + mPluginWindow->x = absWidgetX; + mPluginWindow->y = absWidgetY; - // the Mac widget doesn't set the background color right away!! - // the background color needs to be set here on the plugin port - GrafPtr savePort; - ::GetPort(&savePort); // save our current port - nsPluginPort* pluginPort = GetPluginPort(); - ::SetPort((GrafPtr)pluginPort->port); + // 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; - nscolor color = mWidget->GetBackgroundColor(); - RGBColor macColor; - macColor.red = COLOR8TOCOLOR16(NS_GET_R(color)); // convert to Mac color - macColor.green = COLOR8TOCOLOR16(NS_GET_G(color)); - macColor.blue = COLOR8TOCOLOR16(NS_GET_B(color)); - ::RGBBackColor(&macColor); - ::SetPort(savePort); // restore port - } + // the Mac widget doesn't set the background color right away!! + // the background color needs to be set here on the plugin port + GrafPtr savePort; + ::GetPort(&savePort); // save our current port + nsPluginPort* pluginPort = GetPluginPort(); + ::SetPort((GrafPtr)pluginPort->port); + + nscolor color = mWidget->GetBackgroundColor(); + RGBColor macColor; + macColor.red = COLOR8TOCOLOR16(NS_GET_R(color)); // convert to Mac color + macColor.green = COLOR8TOCOLOR16(NS_GET_G(color)); + macColor.blue = COLOR8TOCOLOR16(NS_GET_B(color)); + ::RGBBackColor(&macColor); + ::SetPort(savePort); // restore port } #endif // XP_MAC diff --git a/mozilla/layout/html/base/src/nsObjectFrame.cpp b/mozilla/layout/html/base/src/nsObjectFrame.cpp index 7324d931656..66b34e1b6d2 100644 --- a/mozilla/layout/html/base/src/nsObjectFrame.cpp +++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp @@ -128,6 +128,8 @@ #include "nsObjectFrame.h" #include "nsIObjectFrame.h" +#include "nsPluginNativeWindow.h" +#include "nsPIPluginHost.h" // accessibility support #ifdef ACCESSIBILITY @@ -327,7 +329,7 @@ public: #endif private: - nsPluginWindow mPluginWindow; + nsPluginNativeWindow *mPluginWindow; nsIPluginInstance *mInstance; nsObjectFrame *mOwner; nsCString mDocumentBase; @@ -667,9 +669,14 @@ nsObjectFrame::Destroy(nsIPresContext* aPresContext) // doing this in the destructor is too late. if(mInstanceOwner != nsnull) { - nsIPluginInstance *inst; - if(NS_OK == mInstanceOwner->GetInstance(inst)) + nsCOMPtr inst; + if(NS_SUCCEEDED(mInstanceOwner->GetInstance(*getter_AddRefs(inst)))) { + nsPluginWindow *win; + mInstanceOwner->GetWindow(win); + nsPluginNativeWindow *window = (nsPluginNativeWindow *)win; + nsCOMPtr nullinst; + PRBool doCache = PR_TRUE; PRBool doCallSetWindowAfterDestroy = PR_FALSE; @@ -684,24 +691,34 @@ nsObjectFrame::Destroy(nsIPresContext* aPresContext) if (doCallSetWindowAfterDestroy) { inst->Stop(); inst->Destroy(); - inst->SetWindow(nsnull); + + if (window) + window->CallSetWindow(nullinst); + else + inst->SetWindow(nsnull); } else { - inst->SetWindow(nsnull); + if (window) + window->CallSetWindow(nullinst); + else + inst->SetWindow(nsnull); + inst->Stop(); inst->Destroy(); } } else { - inst->SetWindow(nsnull); + if (window) + window->CallSetWindow(nullinst); + else + inst->SetWindow(nsnull); + inst->Stop(); } nsCOMPtr pluginHost = do_GetService(kCPluginManagerCID); if(pluginHost) pluginHost->StopPluginInstance(inst); - - NS_RELEASE(inst); } } return nsObjectFrameSuper::Destroy(aPresContext); @@ -1243,6 +1260,8 @@ nsObjectFrame::InstantiatePlugin(nsIPresContext* aPresContext, mInstanceOwner->GetWindow(window); + NS_ENSURE_TRUE(window, NS_ERROR_NULL_POINTER); + GetOffsetFromView(aPresContext, origin, &parentWithView); window->x = NSTwipsToIntPixels(origin.x, t2p); window->y = NSTwipsToIntPixels(origin.y, t2p); @@ -1528,16 +1547,18 @@ nsObjectFrame::DidReflow(nsIPresContext* aPresContext, vm->SetViewVisibility(view, bHidden ? nsViewVisibility_kHide : nsViewVisibility_kShow); } - nsPluginWindow *window; + nsPluginWindow *win = nsnull; nsCOMPtr pi; if (!mInstanceOwner || - NS_FAILED(rv = mInstanceOwner->GetWindow(window)) || + NS_FAILED(rv = mInstanceOwner->GetWindow(win)) || NS_FAILED(rv = mInstanceOwner->GetInstance(*getter_AddRefs(pi))) || !pi || - !window) + !win) return rv; + nsPluginNativeWindow *window = (nsPluginNativeWindow *)win; + #ifdef XP_MAC mInstanceOwner->FixUpPluginWindow(); #endif // XP_MAC @@ -1557,7 +1578,11 @@ nsObjectFrame::DidReflow(nsIPresContext* aPresContext, // refresh the plugin port as well window->window = mInstanceOwner->GetPluginPort(); - pi->SetWindow(window); + + // this will call pi->SetWindow and take care of window subclassing + // if needed, see bug 132759 + window->CallSetWindow(pi); + mInstanceOwner->ReleasePluginPort((nsPluginPort *)window->window); if (mWidget) { @@ -2091,7 +2116,15 @@ nsPluginInstanceOwner::nsPluginInstanceOwner() { 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 ph = do_GetService(kCPluginManagerCID); + nsCOMPtr pph(do_QueryInterface(ph)); + if (pph) + pph->NewPluginNativeWindow(&mPluginWindow); + else + mPluginWindow = nsnull; + mInstance = nsnull; mOwner = nsnull; mWidget = nsnull; @@ -2152,11 +2185,19 @@ nsPluginInstanceOwner::~nsPluginInstanceOwner() #ifdef XP_UNIX // the mem for this struct is allocated // by PR_MALLOC in ns4xPluginInstance.cpp:ns4xPluginInstance::SetWindow() - if (mPluginWindow.ws_info) { - PR_Free(mPluginWindow.ws_info); - mPluginWindow.ws_info = nsnull; + if (mPluginWindow && mPluginWindow->ws_info) { + PR_Free(mPluginWindow->ws_info); + mPluginWindow->ws_info = nsnull; } #endif + + // clean up plugin native window object + nsCOMPtr ph = do_GetService(kCPluginManagerCID); + nsCOMPtr pph(do_QueryInterface(ph)); + if (pph) { + pph->DeletePluginNativeWindow(mPluginWindow); + mPluginWindow = nsnull; + } } /* @@ -2193,7 +2234,8 @@ NS_IMETHODIMP nsPluginInstanceOwner::SetInstance(nsIPluginInstance *aInstance) NS_IMETHODIMP nsPluginInstanceOwner::GetWindow(nsPluginWindow *&aWindow) { - aWindow = &mPluginWindow; + NS_ASSERTION(mPluginWindow, "the plugin window object being returned is null"); + aWindow = mPluginWindow; return NS_OK; } @@ -2746,7 +2788,9 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetWidth(PRUint32 *result) { NS_ENSURE_ARG_POINTER(result); - *result = mPluginWindow.width; + NS_ENSURE_TRUE(mPluginWindow, NS_ERROR_NULL_POINTER); + + *result = mPluginWindow->width; return NS_OK; } @@ -2755,7 +2799,9 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetHeight(PRUint32 *result) { NS_ENSURE_ARG_POINTER(result); - *result = mPluginWindow.height; + NS_ENSURE_TRUE(mPluginWindow, NS_ERROR_NULL_POINTER); + + *result = mPluginWindow->height; return NS_OK; } @@ -3190,7 +3236,7 @@ nsresult nsPluginInstanceOwner::Blur(nsIDOMEvent * aFocusEvent) nsresult nsPluginInstanceOwner::DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent) { #ifndef XP_MAC - if (nsPluginWindowType_Window == mPluginWindow.type) + if (!mPluginWindow || nsPluginWindowType_Window == mPluginWindow->type) return NS_ERROR_FAILURE; // means consume event // continue only for cases without child window #endif @@ -3344,7 +3390,7 @@ nsresult nsPluginInstanceOwner::KeyPress(nsIDOMEvent* aKeyEvent) nsresult nsPluginInstanceOwner::DispatchKeyToPlugin(nsIDOMEvent* aKeyEvent) { #ifndef XP_MAC - if (nsPluginWindowType_Window == mPluginWindow.type) + if (!mPluginWindow || nsPluginWindowType_Window == mPluginWindow->type) return NS_ERROR_FAILURE; // means consume event // continue only for cases without child window #endif @@ -3382,7 +3428,7 @@ nsresult nsPluginInstanceOwner::MouseMove(nsIDOMEvent* aMouseEvent) { #ifndef XP_MAC - if (nsPluginWindowType_Window == mPluginWindow.type) + if (!mPluginWindow || nsPluginWindowType_Window == mPluginWindow->type) return NS_ERROR_FAILURE; // means consume event // continue only for cases without child window #endif @@ -3414,14 +3460,14 @@ nsresult nsPluginInstanceOwner::MouseDown(nsIDOMEvent* aMouseEvent) { #ifndef XP_MAC - if (nsPluginWindowType_Window == mPluginWindow.type) + if (!mPluginWindow || nsPluginWindowType_Window == mPluginWindow->type) return NS_ERROR_FAILURE; // means consume event // continue only for cases without child window #endif // if the plugin is windowless, we need to set focus ourselves // otherwise, we might not get key events - if (mPluginWindow.type == nsPluginWindowType_Drawable) { + if (mPluginWindow && mPluginWindow->type == nsPluginWindowType_Drawable) { nsCOMPtr content; mOwner->GetContent(getter_AddRefs(content)); if (content) @@ -3478,7 +3524,7 @@ nsPluginInstanceOwner::MouseOut(nsIDOMEvent* aMouseEvent) nsresult nsPluginInstanceOwner::DispatchMouseToPlugin(nsIDOMEvent* aMouseEvent) { #ifndef XP_MAC - if (nsPluginWindowType_Window == mPluginWindow.type) + if (!mPluginWindow || nsPluginWindowType_Window == mPluginWindow->type) return NS_ERROR_FAILURE; // means consume event // continue only for cases without child window #endif @@ -3899,7 +3945,7 @@ nsPluginPort* nsPluginInstanceOwner::GetPluginPort() if (mWidget != NULL) { #ifdef XP_WIN - if(mPluginWindow.type == nsPluginWindowType_Drawable) + if(mPluginWindow && mPluginWindow->type == nsPluginWindowType_Drawable) result = (nsPluginPort*) mWidget->GetNativeData(NS_NATIVE_GRAPHIC); else #endif @@ -3913,7 +3959,7 @@ void nsPluginInstanceOwner::ReleasePluginPort(nsPluginPort * pluginPort) #ifdef XP_WIN if (mWidget != NULL) { - if(mPluginWindow.type == nsPluginWindowType_Drawable) + if(mPluginWindow && mPluginWindow->type == nsPluginWindowType_Drawable) mWidget->FreeNativeData((HDC)pluginPort, NS_NATIVE_GRAPHIC); } #endif @@ -3921,6 +3967,8 @@ void nsPluginInstanceOwner::ReleasePluginPort(nsPluginPort * pluginPort) NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void) { + NS_ENSURE_TRUE(mPluginWindow, NS_ERROR_NULL_POINTER); + nsIView *view; nsresult rv = NS_ERROR_FAILURE; float p2t; @@ -3940,8 +3988,8 @@ NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void) // always create widgets in Twips, not pixels mContext->GetScaledPixelsToTwips(&p2t); rv = mOwner->CreateWidget(mContext, - NSIntPixelsToTwips(mPluginWindow.width, p2t), - NSIntPixelsToTwips(mPluginWindow.height, p2t), + NSIntPixelsToTwips(mPluginWindow->width, p2t), + NSIntPixelsToTwips(mPluginWindow->height, p2t), windowless); if (NS_OK == rv) { @@ -3961,20 +4009,20 @@ NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void) if (PR_TRUE == windowless) { - mPluginWindow.type = nsPluginWindowType_Drawable; - mPluginWindow.window = nsnull; // this needs to be a HDC according to the spec, + mPluginWindow->type = nsPluginWindowType_Drawable; + mPluginWindow->window = nsnull; // this needs to be a HDC according to the spec, // but I do not see the right way to release it // so let's postpone passing HDC till paint event // when it is really needed. Change spec? } else if (mWidget) { - mWidget->Resize(mPluginWindow.width, mPluginWindow.height, PR_FALSE); + mWidget->Resize(mPluginWindow->width, mPluginWindow->height, PR_FALSE); - // mPluginWindow.type is used in |GetPluginPort| so it must be initilized first - mPluginWindow.type = nsPluginWindowType_Window; - mPluginWindow.window = GetPluginPort(); + // mPluginWindow->type is used in |GetPluginPort| so it must be initilized first + mPluginWindow->type = nsPluginWindowType_Window; + mPluginWindow->window = GetPluginPort(); #if defined(XP_MAC) // Is this needed in the windowless case ??? @@ -4131,48 +4179,49 @@ inline PRUint16 COLOR8TOCOLOR16(PRUint8 color8) void nsPluginInstanceOwner::FixUpPluginWindow() { - if (mWidget) { - nscoord absWidgetX = 0; - nscoord absWidgetY = 0; - nsRect widgetClip(0,0,0,0); - - // first, check our view for CSS visibility style - nsIView *view; - mOwner->GetView(mContext, &view); - nsViewVisibility vis; - view->GetVisibility(vis); - PRBool isVisible = (vis == nsViewVisibility_kShow) ? PR_TRUE : PR_FALSE; - - GetWidgetPosClipAndVis(mWidget,absWidgetX,absWidgetY,widgetClip,isVisible); + if (!mWidget || !mPluginWindow) + return; - if (mWidgetVisible != isVisible) - mWidgetVisible = isVisible; + nscoord absWidgetX = 0; + nscoord absWidgetY = 0; + nsRect widgetClip(0,0,0,0); + + // first, check our view for CSS visibility style + nsIView *view; + mOwner->GetView(mContext, &view); + nsViewVisibility vis; + view->GetVisibility(vis); + PRBool isVisible = (vis == nsViewVisibility_kShow) ? PR_TRUE : PR_FALSE; + + GetWidgetPosClipAndVis(mWidget,absWidgetX,absWidgetY,widgetClip,isVisible); - // set the port coordinates - mPluginWindow.x = absWidgetX; - mPluginWindow.y = absWidgetY; + if (mWidgetVisible != isVisible) + mWidgetVisible = isVisible; - // 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; + // set the port coordinates + mPluginWindow->x = absWidgetX; + mPluginWindow->y = absWidgetY; - // the Mac widget doesn't set the background color right away!! - // the background color needs to be set here on the plugin port - GrafPtr savePort; - ::GetPort(&savePort); // save our current port - nsPluginPort* pluginPort = GetPluginPort(); - ::SetPort((GrafPtr)pluginPort->port); + // 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; - nscolor color = mWidget->GetBackgroundColor(); - RGBColor macColor; - macColor.red = COLOR8TOCOLOR16(NS_GET_R(color)); // convert to Mac color - macColor.green = COLOR8TOCOLOR16(NS_GET_G(color)); - macColor.blue = COLOR8TOCOLOR16(NS_GET_B(color)); - ::RGBBackColor(&macColor); - ::SetPort(savePort); // restore port - } + // the Mac widget doesn't set the background color right away!! + // the background color needs to be set here on the plugin port + GrafPtr savePort; + ::GetPort(&savePort); // save our current port + nsPluginPort* pluginPort = GetPluginPort(); + ::SetPort((GrafPtr)pluginPort->port); + + nscolor color = mWidget->GetBackgroundColor(); + RGBColor macColor; + macColor.red = COLOR8TOCOLOR16(NS_GET_R(color)); // convert to Mac color + macColor.green = COLOR8TOCOLOR16(NS_GET_G(color)); + macColor.blue = COLOR8TOCOLOR16(NS_GET_B(color)); + ::RGBBackColor(&macColor); + ::SetPort(savePort); // restore port } #endif // XP_MAC diff --git a/mozilla/modules/plugin/base/macbuild/plugin.xml b/mozilla/modules/plugin/base/macbuild/plugin.xml index c789dde0981..8a9c00b6ea5 100644 --- a/mozilla/modules/plugin/base/macbuild/plugin.xml +++ b/mozilla/modules/plugin/base/macbuild/plugin.xml @@ -987,6 +987,13 @@ Text Debug + + Name + nsPluginNativeWindow.cpp + MacOS + Text + Debug + Name nsPluginDocLoaderFactory.cpp @@ -1098,6 +1105,11 @@ nsPluginsDirMac.cpp MacOS + + Name + nsPluginNativeWindow.cpp + MacOS + Name nsPluginDirServiceProvider.cpp @@ -2064,6 +2076,13 @@ Text Debug + + Name + nsPluginNativeWindow.cpp + MacOS + Text + Debug + Name nsPluginDocLoaderFactory.cpp @@ -2175,6 +2194,11 @@ nsPluginsDirMac.cpp MacOS + + Name + nsPluginNativeWindow.cpp + MacOS + Name nsPluginDirServiceProvider.cpp @@ -2260,6 +2284,12 @@ nsPluginsDirMac.cpp MacOS + + pluginDebug.shlb + Name + nsPluginNativeWindow.cpp + MacOS + pluginDebug.shlb Name diff --git a/mozilla/modules/plugin/base/macbuild/pluginClassic.xml b/mozilla/modules/plugin/base/macbuild/pluginClassic.xml index b13ce321cb3..20cfcb9d27c 100644 --- a/mozilla/modules/plugin/base/macbuild/pluginClassic.xml +++ b/mozilla/modules/plugin/base/macbuild/pluginClassic.xml @@ -987,6 +987,13 @@ Text Debug + + Name + nsPluginNativeWindow.cpp + MacOS + Text + Debug + @@ -1044,6 +1051,11 @@ nsPluginsDirMac.cpp MacOS + + Name + nsPluginNativeWindow.cpp + MacOS + @@ -1980,6 +1992,13 @@ Text Debug + + Name + nsPluginNativeWindow.cpp + MacOS + Text + Debug + @@ -2037,6 +2056,11 @@ nsPluginsDirMac.cpp MacOS + + Name + nsPluginNativeWindow.cpp + MacOS + @@ -2126,6 +2150,12 @@ nsPluginsDirMac.cpp MacOS + + pluginClassicDebug.shlb + Name + nsPluginNativeWindow.cpp + MacOS + System Libraries diff --git a/mozilla/modules/plugin/base/public/MANIFEST b/mozilla/modules/plugin/base/public/MANIFEST index 906bfdd1b93..707bacd3d1f 100644 --- a/mozilla/modules/plugin/base/public/MANIFEST +++ b/mozilla/modules/plugin/base/public/MANIFEST @@ -55,3 +55,4 @@ npapi.h npupp.h nsDefaultPlugin.h nsPIPluginInstancePeer.h +nsPluginNativeWindow.h diff --git a/mozilla/modules/plugin/base/public/Makefile.in b/mozilla/modules/plugin/base/public/Makefile.in index 47ab88f9ba9..7ac48a2ea1e 100644 --- a/mozilla/modules/plugin/base/public/Makefile.in +++ b/mozilla/modules/plugin/base/public/Makefile.in @@ -57,6 +57,7 @@ EXPORTS = \ nsPluginError.h \ nsDefaultPlugin.h \ nsPIPluginInstancePeer.h \ + nsPluginNativeWindow.h \ $(NULL) # 4.x headers moved from mozilla/include diff --git a/mozilla/modules/plugin/base/public/nsPIPluginHost.h b/mozilla/modules/plugin/base/public/nsPIPluginHost.h index 501f55d637d..6f5fdb9914a 100644 --- a/mozilla/modules/plugin/base/public/nsPIPluginHost.h +++ b/mozilla/modules/plugin/base/public/nsPIPluginHost.h @@ -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___ */ diff --git a/mozilla/modules/plugin/base/src/Makefile.in b/mozilla/modules/plugin/base/src/Makefile.in index 7f46c860c5a..9ab194aa244 100644 --- a/mozilla/modules/plugin/base/src/Makefile.in +++ b/mozilla/modules/plugin/base/src/Makefile.in @@ -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 diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index 06016132681..047acafc9d8 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -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 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 owner; - if (instance) { + if (aInstance) { nsCOMPtr peer; - rv =instance->GetPeer(getter_AddRefs(peer)); + rv = aInstance->GetPeer(getter_AddRefs(peer)); if (NS_SUCCEEDED(rv) && peer) { nsCOMPtr 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 aPluginInstance, PRBool aScriptable) @@ -6128,8 +6136,6 @@ nsPluginHostImpl::SetIsScriptableInstance(nsCOMPtr 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) { diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h index 4c853a16925..7f1674baa0d 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h @@ -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 diff --git a/mozilla/modules/plugin/base/src/nsPluginSafety.h b/mozilla/modules/plugin/base/src/nsPluginSafety.h index b4e5dde9d59..14fa3fb19bf 100644 --- a/mozilla/modules/plugin/base/src/nsPluginSafety.h +++ b/mozilla/modules/plugin/base/src/nsPluginSafety.h @@ -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 diff --git a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp index 8b9dd33bb16..8cdb1995d41 100644 --- a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp @@ -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 inst; + if(NS_SUCCEEDED(mOwner->GetInstance(*getter_AddRefs(inst)))) { + nsPluginWindow *win; + mOwner->GetWindow(win); + nsPluginNativeWindow *window = (nsPluginNativeWindow *)win; + nsCOMPtr 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 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 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 ph = do_GetService(kCPluginManagerCID); + nsCOMPtr 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 ph = do_GetService(kCPluginManagerCID); + nsCOMPtr 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; } }