Revision: 6106 Author: [email protected] Date: Wed Sep 9 14:57:53 2009 Log: Remove unused cruft, change tracking JS object identity to use an expando property on JS objects. With this, the Chrome plugin is usable but the access control still needs to be implemented before we can ship it.
http://code.google.com/p/google-web-toolkit/source/detail?r=6106 Modified: /trunk/plugins/npapi/LocalObjectTable.cpp /trunk/plugins/npapi/LocalObjectTable.h /trunk/plugins/npapi/NPVariantWrapper.h /trunk/plugins/npapi/ScriptableInstance.cpp /trunk/plugins/npapi/ScriptableInstance.h /trunk/plugins/npapi/main.cpp /trunk/plugins/npapi/prebuilt/winnt_x86-msvc/npOOPHM.dll ======================================= --- /trunk/plugins/npapi/LocalObjectTable.cpp Wed Sep 9 08:52:07 2009 +++ /trunk/plugins/npapi/LocalObjectTable.cpp Wed Sep 9 14:57:53 2009 @@ -1,37 +1,8 @@ #include "mozincludes.h" #include "LocalObjectTable.h" -// Mirrors of NPObjectWrapper and NPObjectProxy from Chrome -// TODO(jat): this is very fragile and may break if Chrome changes -struct ChromeNPObjectProxy { - // IPC::Channel::Listener and IPC::Message::Sender are pure interfaces, so we don't need to - // account for any data fields from their inheritance - void* channel_; // scoped_refptr keeps only a single pointer - void* unknown; // looks like another pointer before route id - int route_id_; - intptr_t npobject_ptr_; -}; - -struct ChromeNPObjectWrapper { - NPObject object; - ChromeNPObjectProxy* proxy; -}; - -NPClass* LocalObjectTable::wrappedObjectClass = 0; - LocalObjectTable::~LocalObjectTable() { if (!dontFree) { freeAll(); } } - -void* LocalObjectTable::getIdentityFrom(NPObject* obj) { - void* id = obj; - if (obj->_class == wrappedObjectClass) { - ChromeNPObjectWrapper* wrapper = reinterpret_cast<ChromeNPObjectWrapper*>(obj); - ChromeNPObjectProxy* proxy = wrapper->proxy; - id = reinterpret_cast<void*>(proxy->npobject_ptr_); - Debug::log(Debug::Info) << "Mapped obj=" << (void*)obj << " to " << id << Debug::flush; - } - return id; -} ======================================= --- /trunk/plugins/npapi/LocalObjectTable.h Wed Sep 9 08:52:07 2009 +++ /trunk/plugins/npapi/LocalObjectTable.h Wed Sep 9 14:57:53 2009 @@ -18,7 +18,6 @@ #include <vector> #include <algorithm> -#include <map> #include "Debug.h" @@ -30,9 +29,7 @@ int nextFree; std::vector<NPObject*> objects; - std::map<void*, int> objectIndex; bool dontFree; - static NPClass* wrappedObjectClass; bool isFree(int id) { // low bit is set for free pointers, object pointers can't be odd @@ -45,15 +42,6 @@ nextFree = id; } - int findIndex(void* ptr) { - std::map<void*, int>::iterator it = objectIndex.find(ptr); - if (it == objectIndex.end()) { - return -1; - } - return it->second; - } - - static void* getIdentityFrom(NPObject* obj); public: LocalObjectTable() { nextFree = -1; @@ -63,18 +51,11 @@ virtual ~LocalObjectTable(); - static void setWrappedObjectClass(NPClass* clazz) { - wrappedObjectClass = clazz; - } - + /** + * Add a new object, which must not be in the table, and return a new id for it. + */ int add(NPObject* obj) { - void* objId = getIdentityFrom(obj); - int id = findIndex(objId); - if (id >= 0) { - Debug::log(Debug::Spam) << "LocalObjectTable::add(obj=" << obj - << "): returning old id=" << id << Debug::flush; - return id; - } + int id; if (nextFree >= 0) { id = nextFree; nextFree = int(reinterpret_cast<long long>(objects[nextFree])) >> 1; @@ -83,18 +64,12 @@ id = static_cast<int>(objects.size()); objects.push_back(obj); } - objectIndex[objId] = id; Debug::log(Debug::Spam) << "LocalObjectTable::add(obj=" << obj << "): id=" << id << Debug::flush; // keep track that we hold a reference in the table NPN_RetainObject(obj); return id; } - - int find(NPObject* obj) { - void* objId = getIdentityFrom(obj); - return findIndex(objId); - } void free(int id) { Debug::log(Debug::Spam) << "LocalObjectTable::free(id=" << id << ")" << Debug::flush; ======================================= --- /trunk/plugins/npapi/NPVariantWrapper.h Mon Aug 3 08:30:11 2009 +++ /trunk/plugins/npapi/NPVariantWrapper.h Wed Sep 9 14:57:53 2009 @@ -489,6 +489,12 @@ NPVariantProxy::assignFrom(variant, strval); return *this; } + + // Convenience method for C++ code + NPVariantWrapper& operator=(int intval) { + NPVariantProxy::assignFrom(variant, intval); + return *this; + } void release() { NPVariantProxy::release(variant); ======================================= --- /trunk/plugins/npapi/ScriptableInstance.cpp Wed Sep 9 08:52:07 2009 +++ /trunk/plugins/npapi/ScriptableInstance.cpp Wed Sep 9 14:57:53 2009 @@ -65,7 +65,7 @@ toStringID(NPN_GetStringIdentifier("toString")), connectedID(NPN_GetStringIdentifier("connected")), statsID(NPN_GetStringIdentifier("stats")), - savedID(NPN_GetStringIdentifier("saved")), + gwtId(NPN_GetStringIdentifier("__gwt_ObjectId")), jsInvokeID(NPN_GetStringIdentifier("__gwt_jsInvoke")), jsResultID(NPN_GetStringIdentifier("__gwt_makeResult")), jsTearOffID(NPN_GetStringIdentifier("__gwt_makeTearOff")), @@ -145,7 +145,7 @@ return true; } // TODO: special-case toString tear-offs - return name == statsID || name == connectedID || name == savedID; + return name == statsID || name == connectedID; } bool ScriptableInstance::getProperty(NPIdentifier name, NPVariant* variant) { @@ -158,13 +158,6 @@ retVal = true; } else if (name == statsID) { NPVariantProxy::assignFrom(*variant, "<stats data>"); - retVal = true; - } else if (name == savedID) { - if (savedValueIdx >= 0) { - NPObject* npObj = localObjects.get(savedValueIdx); - OBJECT_TO_NPVARIANT(npObj, *variant); - NPN_RetainObject(npObj); - } retVal = true; } if (retVal) { @@ -179,14 +172,6 @@ Debug::log(Debug::Debugging) << "ScriptableInstance::setProperty(name=" << NPN_UTF8FromIdentifier(name) << ", value=" << *variant << ")" << Debug::flush; - if (NPN_IdentifierIsString(name)) { - if (name == savedID && NPVariantProxy::isObject(*variant)) { - Debug::log(Debug::Debugging) << " set saved value" << Debug::flush; - savedValueIdx = localObjects.add(NPVariantProxy::getAsObject(*variant)); - return true; - } - return false; - } return false; } @@ -259,7 +244,6 @@ // replace our window object with that passed by the caller window = NPVariantProxy::getAsObject(args[0]); NPN_RetainObject(window); - LocalObjectTable::setWrappedObjectClass(window->_class); BOOLEAN_TO_NPVARIANT(true, *result); result->type = NPVariantType_Bool; } @@ -344,6 +328,22 @@ BOOLEAN_TO_NPVARIANT(connected, *result); result->type = NPVariantType_Bool; } + +int ScriptableInstance::getLocalObjectRef(NPObject* obj) { + NPVariantWrapper wrappedRetVal(*this); + int id; + if (NPN_GetProperty(getNPP(), obj, gwtId, wrappedRetVal.addressForReturn()) + && wrappedRetVal.isInt()) { + id = wrappedRetVal.getAsInt(); + } else { + id = localObjects.add(obj); + wrappedRetVal = id; + if (!NPN_SetProperty(getNPP(), obj, gwtId, wrappedRetVal.address())) { + Debug::log(Debug::Error) << "Setting GWT id on object failed" << Debug::flush; + } + } + return id; +} void ScriptableInstance::fatalError(HostChannel& channel, const std::string& message) { // TODO(jat): better error handling ======================================= --- /trunk/plugins/npapi/ScriptableInstance.h Fri Sep 4 16:37:06 2009 +++ /trunk/plugins/npapi/ScriptableInstance.h Wed Sep 9 14:57:53 2009 @@ -63,7 +63,7 @@ void dumpJSresult(const char* js); - int getLocalObjectRef(NPObject* obj) { return localObjects.add(obj); } + int getLocalObjectRef(NPObject* obj); NPObject* getLocalObject(int refid) { return localObjects.get(refid); } bool tryGetStringPrimitive(NPObject* obj, NPVariant& result); @@ -92,7 +92,7 @@ const NPIdentifier connectedID; const NPIdentifier statsID; - const NPIdentifier savedID; + const NPIdentifier gwtId; const NPIdentifier jsInvokeID; const NPIdentifier jsResultID; ======================================= --- /trunk/plugins/npapi/main.cpp Mon Aug 3 08:30:11 2009 +++ /trunk/plugins/npapi/main.cpp Wed Sep 9 14:57:53 2009 @@ -280,11 +280,11 @@ Debug::log(Debug::Info) << "NP_GetValue(var=" << variable << ")" << Debug::flush; switch (variable) { case NPPVpluginNameString: - *static_cast<const char **>(value) = "GWT Hosted-mode Plugin"; + *static_cast<const char **>(value) = "GWT Development-Mode Plugin"; break; case NPPVpluginDescriptionString: *static_cast<const char **>(value) = "Plugin to enable debugging of Google Web Toolkit " - "applications in hosted mode."; + "applications in development mode."; break; default: Debug::log(Debug::Info) << "NPP_GetValue(var=" << variable ======================================= --- /trunk/plugins/npapi/prebuilt/winnt_x86-msvc/npOOPHM.dll Fri Sep 4 16:37:06 2009 +++ /trunk/plugins/npapi/prebuilt/winnt_x86-msvc/npOOPHM.dll Wed Sep 9 14:57:53 2009 Binary file, no diff available. --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
