Bug 721741 - Add support for Flash on Android 4.0+ r=blassey

This commit is contained in:
James Willcox
2012-01-31 09:40:58 -05:00
parent 43516b489f
commit d28ecb7432
34 changed files with 1640 additions and 73 deletions

View File

@@ -120,6 +120,7 @@ static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
#include "ANPBase.h"
#include "android_npapi.h"
#include "AndroidBridge.h"
#include "AndroidMediaLayer.h"
using namespace mozilla::dom;
#include <android/log.h>
@@ -323,8 +324,9 @@ nsPluginInstanceOwner::nsPluginInstanceOwner()
mWaitingForPaint = false;
#ifdef MOZ_WIDGET_ANDROID
mPluginViewAdded = false;
mLastPluginRect = gfxRect(0, 0, 0, 0);
mOnScreen = false;
mInverted = false;
mLayer = new AndroidMediaLayer();
#endif
}
@@ -380,6 +382,13 @@ nsPluginInstanceOwner::~nsPluginInstanceOwner()
mPluginWindow = nsnull;
}
#ifdef MOZ_WIDGET_ANDROID
if (mLayer) {
delete mLayer;
mLayer = nsnull;
}
#endif
if (mInstance) {
mInstance->InvalidateOwner();
}
@@ -1658,6 +1667,43 @@ void nsPluginInstanceOwner::ScrollPositionDidChange(nscoord aX, nscoord aY)
}
#ifdef MOZ_WIDGET_ANDROID
void nsPluginInstanceOwner::SendSize(int width, int height)
{
if (!mInstance)
return;
PRInt32 model = mInstance->GetANPDrawingModel();
if (model != kOpenGL_ANPDrawingModel)
return;
ANPEvent event;
event.inSize = sizeof(ANPEvent);
event.eventType = kDraw_ANPEventType;
event.data.draw.model = kOpenGL_ANPDrawingModel;
event.data.draw.data.surfaceSize.width = width;
event.data.draw.data.surfaceSize.height = height;
mInstance->HandleEvent(&event, nsnull);
}
void nsPluginInstanceOwner::SendOnScreenEvent(bool onScreen)
{
if (!mInstance)
return;
if ((onScreen && !mOnScreen) || (!onScreen && mOnScreen)) {
ANPEvent event;
event.inSize = sizeof(ANPEvent);
event.eventType = kLifecycle_ANPEventType;
event.data.lifecycle.action = onScreen ? kOnScreen_ANPLifecycleAction : kOffScreen_ANPLifecycleAction;
mInstance->HandleEvent(&event, nsnull);
mOnScreen = onScreen;
}
}
bool nsPluginInstanceOwner::AddPluginView(const gfxRect& aRect)
{
void* javaSurface = mInstance->GetJavaSurface();
@@ -1666,11 +1712,6 @@ bool nsPluginInstanceOwner::AddPluginView(const gfxRect& aRect)
return false;
}
if (aRect.IsEqualEdges(mLastPluginRect)) {
// Already added and in position, no work to do
return true;
}
JNIEnv* env = GetJNIForThread();
if (!env)
return false;
@@ -1713,26 +1754,16 @@ bool nsPluginInstanceOwner::AddPluginView(const gfxRect& aRect)
aRect.height);
#endif
if (!mPluginViewAdded) {
ANPEvent event;
event.inSize = sizeof(ANPEvent);
event.eventType = kLifecycle_ANPEventType;
event.data.lifecycle.action = kOnScreen_ANPLifecycleAction;
mInstance->HandleEvent(&event, nsnull);
mPluginViewAdded = true;
}
SendOnScreenEvent(true);
return true;
}
void nsPluginInstanceOwner::RemovePluginView()
{
if (!mInstance || !mObjectFrame | !mPluginViewAdded)
if (!mInstance || !mObjectFrame | !mOnScreen)
return;
mPluginViewAdded = false;
void* surface = mInstance->GetJavaSurface();
if (!surface)
return;
@@ -1748,13 +1779,17 @@ void nsPluginInstanceOwner::RemovePluginView()
"removePluginView",
"(Landroid/view/View;)V");
env->CallStaticVoidMethod(cls, method, surface);
ANPEvent event;
event.inSize = sizeof(ANPEvent);
event.eventType = kLifecycle_ANPEventType;
event.data.lifecycle.action = kOffScreen_ANPLifecycleAction;
mInstance->HandleEvent(&event, nsnull);
SendOnScreenEvent(false);
}
void nsPluginInstanceOwner::Invalidate() {
NPRect rect;
rect.left = rect.top = 0;
rect.right = mPluginWindow->width;
rect.bottom = mPluginWindow->height;
InvalidateRect(&rect);
}
#endif
nsresult nsPluginInstanceOwner::DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent)
@@ -2779,7 +2814,15 @@ nsPluginInstanceOwner::PrepareToStop(bool aDelayedStop)
#endif
#ifdef MOZ_WIDGET_ANDROID
RemovePluginView();
PRInt32 model = mInstance->GetANPDrawingModel();
if (model == kSurface_ANPDrawingModel) {
RemovePluginView();
} else if (model == kOpenGL_ANPDrawingModel && mLayer) {
delete mLayer;
mLayer = nsnull;
}
#endif
// Unregister scroll position listeners
@@ -2891,15 +2934,21 @@ void nsPluginInstanceOwner::Paint(gfxContext* aContext,
if (model == kSurface_ANPDrawingModel) {
if (!AddPluginView(aFrameRect)) {
NPRect rect;
rect.left = rect.top = 0;
rect.right = aFrameRect.width;
rect.bottom = aFrameRect.height;
InvalidateRect(&rect);
Invalidate();
}
return;
}
if (model == kOpenGL_ANPDrawingModel) {
// FIXME: this is gross
float zoomLevel = aFrameRect.width / (float)mPluginWindow->width;
mLayer->UpdatePosition(aFrameRect, zoomLevel);
SendOnScreenEvent(true);
SendSize((int)aFrameRect.width, (int)aFrameRect.height);
return;
}
if (model != kBitmap_ANPDrawingModel)
return;
@@ -3590,8 +3639,16 @@ void nsPluginInstanceOwner::UpdateWindowPositionAndClipRect(bool aSetWindow)
} else {
mPluginWindow->clipRect.right = 0;
mPluginWindow->clipRect.bottom = 0;
#ifdef MOZ_WIDGET_ANDROID
RemovePluginView();
#if 0 //MOZ_WIDGET_ANDROID
if (mInstance) {
PRInt32 model = mInstance->GetANPDrawingModel();
if (model == kSurface_ANPDrawingModel) {
RemovePluginView();
} else if (model == kOpenGL_ANPDrawingModel) {
HidePluginLayer();
}
}
#endif
}