updating the sample plugin to reflect the latest changes in android_npapi.h
diff --git a/samples/BrowserPlugin/jni/Android.mk b/samples/BrowserPlugin/jni/Android.mk
index c3acbd8..3d1c88f 100644
--- a/samples/BrowserPlugin/jni/Android.mk
+++ b/samples/BrowserPlugin/jni/Android.mk
@@ -35,7 +35,6 @@
 	background/BackgroundPlugin.cpp \
 	form/FormPlugin.cpp \
 	paint/PaintPlugin.cpp \
-	surface/SurfacePlugin.cpp \
 
 LOCAL_C_INCLUDES += \
 	$(LOCAL_PATH) \
@@ -44,7 +43,6 @@
 	$(LOCAL_PATH)/background \
 	$(LOCAL_PATH)/form \
 	$(LOCAL_PATH)/paint \
-	$(LOCAL_PATH)/surface \
 	external/webkit/WebCore/bridge \
 	external/webkit/WebCore/plugins \
 	external/webkit/WebCore/platform/android/JavaVM \
diff --git a/samples/BrowserPlugin/jni/PluginObject.h b/samples/BrowserPlugin/jni/PluginObject.h
index 248a09b..82f6f48 100644
--- a/samples/BrowserPlugin/jni/PluginObject.h
+++ b/samples/BrowserPlugin/jni/PluginObject.h
@@ -56,7 +56,6 @@
     kForm_PluginType       = 4,
     kText_PluginType       = 5,
     kPaint_PluginType      = 6,
-    kSurface_PluginType    = 7,
 };
 typedef uint32_t PluginType;
 
diff --git a/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp b/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp
index 4ca79ed..548f0e5 100644
--- a/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp
+++ b/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp
@@ -34,10 +34,10 @@
 
 extern NPNetscapeFuncs*        browser;
 extern ANPBitmapInterfaceV0    gBitmapI;
-extern ANPLogInterfaceV0       gLogI;
 extern ANPCanvasInterfaceV0    gCanvasI;
+extern ANPLogInterfaceV0       gLogI;
 extern ANPPaintInterfaceV0     gPaintI;
-extern ANPPathInterfaceV0      gPathI;
+extern ANPSurfaceInterfaceV0   gSurfaceI;
 extern ANPTypefaceInterfaceV0  gTypefaceI;
 
 extern uint32_t getMSecs();
@@ -50,16 +50,13 @@
 
 BackgroundPlugin::BackgroundPlugin(NPP inst) : SubPlugin(inst) {
 
-    m_paint = gPaintI.newPaint();
-    gPaintI.setFlags(m_paint, gPaintI.getFlags(m_paint) | kAntiAlias_ANPPaintFlag);
-    gPaintI.setColor(m_paint, 0xFFFF0000);
-    gPaintI.setTextSize(m_paint, 16);
+    // initialize the drawing surface
+    m_surfaceReady = false;
+    m_surface = gSurfaceI.newSurface(inst, kRGBA_ANPSurfaceType, false);
+    if(!m_surface)
+        gLogI.log(inst, kError_ANPLogType, "----%p Unable to create RGBA surface", inst);
 
-    ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle);
-    gPaintI.setTypeface(m_paint, tf);
-    gTypefaceI.unref(tf);
-
-    //initialize variables
+    //initialize bitmap transparency variables
     mFinishedStageOne   = false;
     mFinishedStageTwo   = false;
     mFinishedStageThree = false;
@@ -73,55 +70,97 @@
 }
 
 BackgroundPlugin::~BackgroundPlugin() {
+    gSurfaceI.deleteSurface(m_surface);
 }
 
 bool BackgroundPlugin::supportsDrawingModel(ANPDrawingModel model) {
-    return (model == kBitmap_ANPDrawingModel);
+    return (model == kSurface_ANPDrawingModel);
 }
 
-void BackgroundPlugin::drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip) {
+void BackgroundPlugin::drawPlugin(int surfaceWidth, int surfaceHeight) {
+
+    // get the plugin's dimensions according to the DOM
+    PluginObject *obj = (PluginObject*) inst()->pdata;
+    const int W = obj->window->width;
+    const int H = obj->window->height;
+
+    // compute the current zoom level
+    const float zoomFactorW = static_cast<float>(surfaceWidth) / W;
+    const float zoomFactorH = static_cast<float>(surfaceHeight) / H;
+
+    // check to make sure the zoom level is uniform
+    if (zoomFactorW + .01 < zoomFactorH && zoomFactorW - .01 > zoomFactorH)
+        gLogI.log(inst(), kError_ANPLogType, " ------ %p zoom is out of sync (%f,%f)",
+                  inst(), zoomFactorW, zoomFactorH);
+
+    // scale the variables based on the zoom level
+    const int fontSize = (int)(zoomFactorW * 16);
+    const int leftMargin = (int)(zoomFactorW * 10);
+
+    // lock the surface
+    ANPBitmap bitmap;
+    if (!m_surfaceReady || !gSurfaceI.lock(m_surface, &bitmap, NULL)) {
+        gLogI.log(inst(), kError_ANPLogType, " ------ %p unable to lock the plugin", inst());
+        return;
+    }
+
+    // create a canvas
     ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);
-
-    ANPRectF clipR;
-    clipR.left = clip.left;
-    clipR.top = clip.top;
-    clipR.right = clip.right;
-    clipR.bottom = clip.bottom;
-    gCanvasI.clipRect(canvas, &clipR);
-
-    draw(canvas);
-    gCanvasI.deleteCanvas(canvas);
-}
-
-void BackgroundPlugin::draw(ANPCanvas* canvas) {
-
     gCanvasI.drawColor(canvas, 0xFFFFFFFF);
 
-    ANPFontMetrics fm;
-    gPaintI.getFontMetrics(m_paint, &fm);
+    ANPPaint* paint = gPaintI.newPaint();
+    gPaintI.setFlags(paint, gPaintI.getFlags(paint) | kAntiAlias_ANPPaintFlag);
+    gPaintI.setColor(paint, 0xFFFF0000);
+    gPaintI.setTextSize(paint, fontSize);
 
-    gPaintI.setColor(m_paint, 0xFF0000FF);
+    ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle);
+    gPaintI.setTypeface(paint, tf);
+    gTypefaceI.unref(tf);
+
+    ANPFontMetrics fm;
+    gPaintI.getFontMetrics(paint, &fm);
+
+    gPaintI.setColor(paint, 0xFF0000FF);
     const char c[] = "This is a background plugin.";
-    gCanvasI.drawText(canvas, c, sizeof(c)-1, 10, -fm.fTop, m_paint);
+    gCanvasI.drawText(canvas, c, sizeof(c)-1, leftMargin, -fm.fTop, paint);
+
+    // clean up variables and unlock the surface
+    gPaintI.deletePaint(paint);
+    gCanvasI.deleteCanvas(canvas);
+    gSurfaceI.unlock(m_surface);
 }
 
 int16 BackgroundPlugin::handleEvent(const ANPEvent* evt) {
-    NPP instance = this->inst();
-
     switch (evt->eventType) {
         case kDraw_ANPEventType:
-            switch (evt->data.draw.model) {
-                case kBitmap_ANPDrawingModel:
-                    test_bitmap_transparency(evt);
-                    drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip);
-                    return 1;
-                default:
-                    break;   // unknown drawing model
+            gLogI.log(inst(), kError_ANPLogType, " ------ %p the plugin did not request draw events", inst());
+            break;
+        case kSurface_ANPEventType:
+                    switch (evt->data.surface.action) {
+                        case kCreated_ANPSurfaceAction:
+                            m_surfaceReady = true;
+                            return 1;
+                        case kDestroyed_ANPSurfaceAction:
+                            m_surfaceReady = false;
+                            return 1;
+                        case kChanged_ANPSurfaceAction:
+                            drawPlugin(evt->data.surface.data.changed.width,
+                                       evt->data.surface.data.changed.height);
+                            return 1;
+                    }
+                    break;
+        case kLifecycle_ANPEventType:
+            if (evt->data.lifecycle.action == kOnLoad_ANPLifecycleAction) {
+                gLogI.log(inst(), kDebug_ANPLogType, " ------ %p the plugin received an onLoad event", inst());
+                return 1;
             }
+            break;
         case kTouch_ANPEventType:
-            gLogI.log(instance, kError_ANPLogType, " ------ %p the plugin did not request touch events", instance);
+            gLogI.log(inst(), kError_ANPLogType, " ------ %p the plugin did not request touch events", inst());
+            break;
         case kKey_ANPEventType:
-            gLogI.log(instance, kError_ANPLogType, " ------ %p the plugin did not request key events", instance);
+            gLogI.log(inst(), kError_ANPLogType, " ------ %p the plugin did not request key events", inst());
+            break;
         default:
             break;
     }
diff --git a/samples/BrowserPlugin/jni/background/BackgroundPlugin.h b/samples/BrowserPlugin/jni/background/BackgroundPlugin.h
index 0d7389b..ed428b5 100644
--- a/samples/BrowserPlugin/jni/background/BackgroundPlugin.h
+++ b/samples/BrowserPlugin/jni/background/BackgroundPlugin.h
@@ -48,10 +48,10 @@
     bool mFinishedStageThree; // check opaque
 
 private:
-    void draw(ANPCanvas*);
-    void drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip);
+    void drawPlugin(int surfaceWidth, int surfaceHeight);
 
-    ANPPaint*   m_paint;
+    bool        m_surfaceReady;
+    ANPSurface* m_surface;
 
     void test_logging();
     void test_timers();
diff --git a/samples/BrowserPlugin/jni/form/FormPlugin.cpp b/samples/BrowserPlugin/jni/form/FormPlugin.cpp
index 589550a..a92d447 100644
--- a/samples/BrowserPlugin/jni/form/FormPlugin.cpp
+++ b/samples/BrowserPlugin/jni/form/FormPlugin.cpp
@@ -303,6 +303,7 @@
     gLogI.log(instance, kDebug_ANPLogType, "----%p Recvd Nav Key %d", instance, keyCode);
 
     if (!m_activeInput) {
+        gWindowI.showKeyboard(instance, true);
         switchActiveInput(&m_usernameInput);
     }
     else if (m_activeInput == &m_usernameInput) {
diff --git a/samples/BrowserPlugin/jni/main.cpp b/samples/BrowserPlugin/jni/main.cpp
index 119081c..b5aea95 100644
--- a/samples/BrowserPlugin/jni/main.cpp
+++ b/samples/BrowserPlugin/jni/main.cpp
@@ -33,7 +33,6 @@
 #include "BackgroundPlugin.h"
 #include "FormPlugin.h"
 #include "PaintPlugin.h"
-#include "SurfacePlugin.h"
 #include "android_npapi.h"
 
 NPNetscapeFuncs* browser;
@@ -213,10 +212,6 @@
                 obj->pluginType = kPaint_PluginType;
                 obj->activePlugin = new PaintPlugin(instance);
             }
-            else if (!strcmp(argv[i], "RGBA_Surface")) {
-                obj->pluginType = kSurface_PluginType;
-                obj->activePlugin = new SurfacePlugin(instance, kRGBA_ANPSurfaceType);
-            }
             gLogI.log(instance, kDebug_ANPLogType, "------ %p PluginType is %d", instance, obj->pluginType);
             break;
         }
diff --git a/samples/BrowserPlugin/jni/paint/PaintPlugin.cpp b/samples/BrowserPlugin/jni/paint/PaintPlugin.cpp
index ba5257c..62cb079 100644
--- a/samples/BrowserPlugin/jni/paint/PaintPlugin.cpp
+++ b/samples/BrowserPlugin/jni/paint/PaintPlugin.cpp
@@ -52,7 +52,7 @@
 
     // initialize the drawing surface
     m_surfaceReady = false;
-    m_surface = gSurfaceI.newSurface(inst, kRGBA_ANPSurfaceType);
+    m_surface = gSurfaceI.newSurface(inst, kRGBA_ANPSurfaceType, true);
     if(!m_surface)
         gLogI.log(inst, kError_ANPLogType, "----%p Unable to create RGBA surface", inst);
 
@@ -219,6 +219,19 @@
                 case kDestroyed_ANPSurfaceAction:
                     m_surfaceReady = false;
                     return 1;
+                case kChanged_ANPSurfaceAction:
+                    // get the plugin's dimensions according to the DOM
+                    PluginObject *obj = (PluginObject*) inst()->pdata;
+                    const int pW = obj->window->width;
+                    const int pH = obj->window->height;
+                    // get the plugin's surface dimensions
+                    const int sW = evt->data.surface.data.changed.width;
+                    const int sH = evt->data.surface.data.changed.height;
+                    if (pW != sW || pH != sH)
+                        gLogI.log(inst(), kError_ANPLogType,
+                                  "----%p Invalid Surface Dimensions (%d,%d):(%d,%d)",
+                                  inst(), pW, pH, sW, sH);
+                    return 1;
             }
             break;
 
diff --git a/samples/BrowserPlugin/jni/surface/SurfacePlugin.cpp b/samples/BrowserPlugin/jni/surface/SurfacePlugin.cpp
deleted file mode 100644
index b3be90a..0000000
--- a/samples/BrowserPlugin/jni/surface/SurfacePlugin.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2009, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "SurfacePlugin.h"
-
-#include <stdio.h>
-#include <sys/time.h>
-#include <time.h>
-#include <math.h>
-#include <string.h>
-
-extern NPNetscapeFuncs*        browser;
-extern ANPLogInterfaceV0       gLogI;
-extern ANPPaintInterfaceV0     gPaintI;
-extern ANPSurfaceInterfaceV0   gSurfaceI;
-extern ANPTypefaceInterfaceV0  gTypefaceI;
-extern ANPWindowInterfaceV0    gWindowI;
-
-///////////////////////////////////////////////////////////////////////////////
-
-SurfacePlugin::SurfacePlugin(NPP inst, ANPSurfaceType surfaceType) : SubPlugin(inst) {
-
-    m_surface = gSurfaceI.newSurface(inst, surfaceType);
-
-    if(!m_surface)
-        gLogI.log(inst, kError_ANPLogType, "----%p Unable to create surface (%d)", inst, surfaceType);
-}
-
-SurfacePlugin::~SurfacePlugin() {
-    if (m_surface)
-        gSurfaceI.deleteSurface(m_surface);
-}
-
-bool SurfacePlugin::supportsDrawingModel(ANPDrawingModel model) {
-    return (model == kSurface_ANPDrawingModel);
-}
-
-void SurfacePlugin::draw() {
-    NPP instance = this->inst();
-    PluginObject *obj = (PluginObject*) instance->pdata;
-
-    ANPBitmap bitmap;
-
-    bool value = gSurfaceI.lock(m_surface, &bitmap, NULL);
-    gLogI.log(instance, kDebug_ANPLogType, "----%p locking: %b", instance, value);
-    gSurfaceI.unlock(m_surface);
-}
-
-int16 SurfacePlugin::handleEvent(const ANPEvent* evt) {
-    NPP instance = this->inst();
-
-    switch (evt->eventType) {
-        case kDraw_ANPEventType:
-            switch (evt->data.draw.model) {
-                case kSurface_ANPDrawingModel:
-                    if (m_surface)
-                        draw();
-                    return 1;
-                default:
-                    break;   // unknown drawing model
-            }
-        default:
-            break;
-    }
-    return 0;   // unknown or unhandled event
-}
diff --git a/samples/BrowserPlugin/jni/surface/SurfacePlugin.h b/samples/BrowserPlugin/jni/surface/SurfacePlugin.h
deleted file mode 100644
index 349f8b1..0000000
--- a/samples/BrowserPlugin/jni/surface/SurfacePlugin.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2009, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "PluginObject.h"
-
-#ifndef surfacePlugin__DEFINED
-#define surfacePlugin__DEFINED
-
-class SurfacePlugin : public SubPlugin {
-public:
-    SurfacePlugin(NPP inst, ANPSurfaceType surfaceType);
-    virtual ~SurfacePlugin();
-    virtual bool supportsDrawingModel(ANPDrawingModel);
-    virtual int16 handleEvent(const ANPEvent* evt);
-private:
-    void draw();
-    ANPSurface* m_surface;
-
-};
-#endif // surfacePlugin__DEFINED