summaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2009-07-30 16:57:07 -0400
committerDerek Sollenberger <djsollen@google.com>2009-07-30 16:57:07 -0400
commitc356b9f04076f3f95dae80426ce455efe1e2c543 (patch)
tree1cd2756117f4e45da11bfbecccdd9e3d52f2b759 /samples
parentf5a65ef811dcfe2160a131c2dc70dd605f83b072 (diff)
downloadandroid_development-c356b9f04076f3f95dae80426ce455efe1e2c543.tar.gz
android_development-c356b9f04076f3f95dae80426ce455efe1e2c543.tar.bz2
android_development-c356b9f04076f3f95dae80426ce455efe1e2c543.zip
adding sample cod to access dom and javascript.
Diffstat (limited to 'samples')
-rw-r--r--samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp67
-rw-r--r--samples/BrowserPlugin/jni/background/BackgroundPlugin.h2
2 files changed, 69 insertions, 0 deletions
diff --git a/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp b/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp
index 09f58cf75..4ca79ed0e 100644
--- a/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp
+++ b/samples/BrowserPlugin/jni/background/BackgroundPlugin.cpp
@@ -68,6 +68,8 @@ BackgroundPlugin::BackgroundPlugin(NPP inst) : SubPlugin(inst) {
test_logging(); // android logging
test_timers(); // plugin timers
test_bitmaps(); // android bitmaps
+ test_domAccess();
+ test_javascript();
}
BackgroundPlugin::~BackgroundPlugin() {
@@ -308,3 +310,68 @@ void BackgroundPlugin::test_bitmap_transparency(const ANPEvent* evt) {
mFinishedStageThree = true;
}
}
+
+///////////////////////////////////////////////////////////////////////////////
+// DOM TESTS
+///////////////////////////////////////////////////////////////////////////////
+
+void BackgroundPlugin::test_domAccess() {
+ NPP instance = this->inst();
+
+ gLogI.log(instance, kDebug_ANPLogType, " ------ %p Testing DOM Access", instance);
+
+ // Get the plugin's DOM object
+ NPObject* windowObject = NULL;
+ browser->getvalue(instance, NPNVWindowNPObject, &windowObject);
+
+ if (!windowObject)
+ gLogI.log(instance, kError_ANPLogType, " ------ %p Unable to retrieve DOM Window", instance);
+
+ // Retrieve a property from the plugin's DOM object
+ NPIdentifier topIdentifier = browser->getstringidentifier("top");
+ NPVariant topObjectVariant;
+ browser->getproperty(instance, windowObject, topIdentifier, &topObjectVariant);
+
+ if (topObjectVariant.type != NPVariantType_Object)
+ gLogI.log(instance, kError_ANPLogType, " ------ %p Invalid Variant type for DOM Property: %d,%d", instance, topObjectVariant.type, NPVariantType_Object);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+// JAVASCRIPT TESTS
+///////////////////////////////////////////////////////////////////////////////
+
+
+void BackgroundPlugin::test_javascript() {
+ NPP instance = this->inst();
+
+ gLogI.log(instance, kDebug_ANPLogType, " ------ %p Testing JavaScript Access", instance);
+
+ // Get the plugin's DOM object
+ NPObject* windowObject = NULL;
+ browser->getvalue(instance, NPNVWindowNPObject, &windowObject);
+
+ if (!windowObject)
+ gLogI.log(instance, kError_ANPLogType, " ------ %p Unable to retrieve DOM Window", instance);
+
+ // create a string (JS code) that is stored in memory allocated by the browser
+ const char* jsString = "1200 + 34";
+ void* stringMem = browser->memalloc(strlen(jsString));
+ memcpy(stringMem, jsString, strlen(jsString));
+
+ // execute the javascript in the plugin's DOM object
+ NPString script = { (char*)stringMem, strlen(jsString) };
+ NPVariant scriptVariant;
+ if (!browser->evaluate(instance, windowObject, &script, &scriptVariant))
+ gLogI.log(instance, kError_ANPLogType, " ------ %p Unable to eval the JS.", instance);
+
+ if (scriptVariant.type == NPVariantType_Int32) {
+ if (scriptVariant.value.intValue != 1234)
+ gLogI.log(instance, kError_ANPLogType, " ------ %p Invalid Value for JS Return: %d,1234", instance, scriptVariant.value.intValue);
+ } else {
+ gLogI.log(instance, kError_ANPLogType, " ------ %p Invalid Variant type for JS Return: %d,%d", instance, scriptVariant.type, NPVariantType_Int32);
+ }
+
+ // free the memory allocated within the browser
+ browser->memfree(stringMem);
+}
diff --git a/samples/BrowserPlugin/jni/background/BackgroundPlugin.h b/samples/BrowserPlugin/jni/background/BackgroundPlugin.h
index 8893c9dc8..0d7389bc2 100644
--- a/samples/BrowserPlugin/jni/background/BackgroundPlugin.h
+++ b/samples/BrowserPlugin/jni/background/BackgroundPlugin.h
@@ -57,6 +57,8 @@ private:
void test_timers();
void test_bitmaps();
void test_bitmap_transparency(const ANPEvent* evt);
+ void test_domAccess();
+ void test_javascript();
};