aboutsummaryrefslogtreecommitdiffstats
path: root/plugin/icedteanp/IcedTeaPluginUtils.cc
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/icedteanp/IcedTeaPluginUtils.cc')
-rw-r--r--plugin/icedteanp/IcedTeaPluginUtils.cc134
1 files changed, 40 insertions, 94 deletions
diff --git a/plugin/icedteanp/IcedTeaPluginUtils.cc b/plugin/icedteanp/IcedTeaPluginUtils.cc
index 6ce37e8..d8ae1ee 100644
--- a/plugin/icedteanp/IcedTeaPluginUtils.cc
+++ b/plugin/icedteanp/IcedTeaPluginUtils.cc
@@ -53,7 +53,7 @@ exception statement from your version. */
int IcedTeaPluginUtilities::reference = -1;
pthread_mutex_t IcedTeaPluginUtilities::reference_mutex = PTHREAD_MUTEX_INITIALIZER;
std::map<void*, NPP>* IcedTeaPluginUtilities::instance_map = new std::map<void*, NPP>();
-std::map<std::string, NPObjectRef> IcedTeaPluginUtilities::object_map;
+std::map<std::string, NPObject*>* IcedTeaPluginUtilities::object_map = new std::map<std::string, NPObject*>();
/* Plugin async call queue */
static std::vector< PluginThreadCall* >* pendingPluginThreadRequests = new std::vector< PluginThreadCall* >();
@@ -433,9 +433,9 @@ void
IcedTeaPluginUtilities::printStringVector(const char* prefix, std::vector<std::string>* str_vector)
{
- // This is a CPU intensive function. Run only if debugging
- if (!plugin_debug)
- return;
+ // This is a CPU intensive function. Run only if debugging
+ if (!plugin_debug)
+ return;
std::string* str = new std::string();
*str += "{ ";
@@ -561,25 +561,27 @@ IcedTeaPluginUtilities::getInstanceFromMemberPtr(void* member_ptr)
* @return The associated active NPObject, NULL otherwise
*/
-NPObjectRef
+NPObject*
IcedTeaPluginUtilities::getNPObjectFromJavaKey(std::string key)
{
+
+ NPObject* object = NULL;
PLUGIN_DEBUG("getNPObjectFromJavaKey looking for %s\n", key.c_str());
- std::map<std::string, NPObjectRef>::iterator iterator = object_map.find(key);
+ std::map<std::string, NPObject*>::iterator iterator = object_map->find(key);
- if (iterator != object_map.end())
+ if (iterator != object_map->end())
{
- NPObjectRef object = object_map.find(key)->second;
+ NPObject* mapped_object = object_map->find(key)->second;
- if (getInstanceFromMemberPtr(object.get()) != NULL)
+ if (getInstanceFromMemberPtr(mapped_object) != NULL)
{
- PLUGIN_DEBUG("getNPObjectFromJavaKey found %s. NPObject = %p\n", key.c_str(), object.get());
- return object;
+ object = mapped_object;
+ PLUGIN_DEBUG("getNPObjectFromJavaKey found %s. NPObject = %p\n", key.c_str(), object);
}
}
- return NPObjectRef(NULL);
+ return object;
}
/**
@@ -590,10 +592,10 @@ IcedTeaPluginUtilities::getNPObjectFromJavaKey(std::string key)
*/
void
-IcedTeaPluginUtilities::storeObjectMapping(std::string key, NPObjectRef object)
+IcedTeaPluginUtilities::storeObjectMapping(std::string key, NPObject* object)
{
- PLUGIN_DEBUG("Storing object %p with key %s\n", object.get(), key.c_str());
- object_map.insert(std::make_pair(key, object));
+ PLUGIN_DEBUG("Storing object %p with key %s\n", object, key.c_str());
+ object_map->insert(std::make_pair(key, object));
}
/**
@@ -606,14 +608,19 @@ void
IcedTeaPluginUtilities::removeObjectMapping(std::string key)
{
PLUGIN_DEBUG("Removing key %s from object map\n", key.c_str());
- object_map.erase(key);
+ object_map->erase(key);
}
/* Clear object_map. Useful for tests. */
void
IcedTeaPluginUtilities::clearObjectMapping()
{
- object_map = std::map<std::string, NPObjectRef>();
+ std::map<std::string, NPObject*>::iterator iter = object_map->begin();
+ for (; iter != object_map->end(); ++iter) {
+ browser_functions.releaseobject(iter->second);
+ }
+ delete object_map;
+ object_map = new std::map<std::string, NPObject*>();
}
/*
@@ -626,9 +633,9 @@ IcedTeaPluginUtilities::clearObjectMapping()
void
IcedTeaPluginUtilities::printStringPtrVector(const char* prefix, std::vector<std::string*>* str_ptr_vector)
{
- // This is a CPU intensive function. Run only if debugging
- if (!plugin_debug)
- return;
+ // This is a CPU intensive function. Run only if debugging
+ if (!plugin_debug)
+ return;
std::string* str = new std::string();
*str += "{ ";
@@ -812,13 +819,18 @@ javaObjectResultToNPVariant(NPP instance, const std::string& jobject_id, NPVaria
std::string jclass_id = *jclass_result->return_string;
- bool is_array = (jclass_id.at(0) == '[');
- NPObjectRef object = IcedTeaScriptableJavaObject::get_scriptable_java_object(instance, jclass_id,
- jobject_id, is_array);
+ NPObject* obj;
+ if (jclass_id.at(0) == '[') // array
+ {
+ obj = IcedTeaScriptableJavaObject::get_scriptable_java_object(instance, jclass_id,
+ jobject_id, true);
+ } else
+ {
+ obj = IcedTeaScriptableJavaObject::get_scriptable_java_object(instance, jclass_id,
+ jobject_id, false);
+ }
- OBJECT_TO_NPVARIANT(object.get(), *variant);
- /* Retain because we are returning an NPObject* */
- object.raw_retain();
+ OBJECT_TO_NPVARIANT(obj, *variant);
return true;
}
@@ -862,12 +874,12 @@ IcedTeaPluginUtilities::javaResultToNPVariant(NPP instance,
}
bool
-IcedTeaPluginUtilities::isObjectJSArray(NPP instance, NPObjectRef object)
+IcedTeaPluginUtilities::isObjectJSArray(NPP instance, NPObject* object)
{
NPVariant constructor_v = NPVariant();
NPIdentifier constructor_id = browser_functions.getstringidentifier("constructor");
- browser_functions.getproperty(instance, object.get(), constructor_id, &constructor_v);
+ browser_functions.getproperty(instance, object, constructor_id, &constructor_v);
IcedTeaPluginUtilities::printNPVariant(constructor_v);
// void constructor => not an array
@@ -1075,34 +1087,6 @@ void IcedTeaPluginUtilities::trim(std::string& str) {
str = str.substr(start, end - start + 1);
}
-std::string
-IcedTeaPluginUtilities::stringPrintf(const char* fmt, /*variable arguments*/ ...)
-{
- /* Extract the variable arguments */
- va_list args;
- va_start(args, fmt);
-
- gchar* result = NULL;
- size_t size;
-
- /* Format the arguments into a new buffer, held in 'result' */
- size = g_vasprintf (&result, fmt, args);
-
- if (result == NULL)
- {
- // We are out of memory
- throw std::bad_alloc();
- }
-
- /* Wrap as string and free buffer */
- std::string str(result, size);
- g_free(result);
-
- va_end(args); /* Finish using variable arguments */
-
- return str;
-}
-
std::string IcedTeaPluginUtilities::NPIdentifierAsString(NPIdentifier id) {
NPUTF8* cstr = browser_functions.utf8fromidentifier(id);
if (cstr == NULL) {
@@ -1258,41 +1242,3 @@ MessageBus::post(const char* message)
PLUGIN_DEBUG("%p unlocked...\n", &msg_queue_mutex);
}
-void
-NPObjectRef::set(NPObject* new_object)
-{
- if (new_object != NULL) {
- /* Increase the new object's reference count */
- browser_functions.retainobject(new_object);
- }
- if (current_object != NULL) {
- /* Decrease the old object's reference count */
- browser_functions.releaseobject(current_object);
- }
-
- this->current_object = new_object;
-}
-
-NPObjectRef
-NPObjectRef::create(NPP instance, NPClass* np_class)
-{
- NPObjectRef ref;
- /* Don't use set(), otherwise we'd double-retain */
- ref.current_object = browser_functions.createobject(instance, np_class);
- return ref;
-}
-
-/* Explicit reference counting operations, use only if needed for interoperating with NPObject* */
-void
-NPObjectRef::raw_retain() {
- if (current_object != NULL) {
- browser_functions.retainobject(current_object);
- }
-}
-
-void
-NPObjectRef::raw_release() {
- if (current_object != NULL) {
- browser_functions.releaseobject(current_object);
- }
-}