Rename VS project, attempt (unsucessfully) to get a stable identity from
NPObjects passed from Chrome, fix inconsistent line endings.
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6101 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/plugins/npapi/LocalObjectTable.cpp b/plugins/npapi/LocalObjectTable.cpp
index cc2a4ad..e0c381c 100644
--- a/plugins/npapi/LocalObjectTable.cpp
+++ b/plugins/npapi/LocalObjectTable.cpp
@@ -1,6 +1,24 @@
#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();
@@ -8,14 +26,12 @@
}
void* LocalObjectTable::getIdentityFrom(NPObject* obj) {
- void** rawPtr = reinterpret_cast<void**>(reinterpret_cast<char*>(obj) + sizeof(NPClass*)
- + sizeof(uint32_t));
- Debug::log(Debug::Info) << "getIdentity(obj=" << (void*)obj << "): class=" << (void*)obj->_class
- << ", bytes:";
- for (int i = 0; i< 4; ++i) {
- Debug::log(Debug::Info) << " " << rawPtr[i];
+ 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;
}
- Debug::log(Debug::Info) << Debug::flush;
- return obj;
+ return id;
}
-
diff --git a/plugins/npapi/LocalObjectTable.h b/plugins/npapi/LocalObjectTable.h
index 857d2e6..4943ff3 100644
--- a/plugins/npapi/LocalObjectTable.h
+++ b/plugins/npapi/LocalObjectTable.h
@@ -32,6 +32,7 @@
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
@@ -62,6 +63,10 @@
virtual ~LocalObjectTable();
+ static void setWrappedObjectClass(NPClass* clazz) {
+ wrappedObjectClass = clazz;
+ }
+
int add(NPObject* obj) {
void* objId = getIdentityFrom(obj);
int id = findIndex(objId);
diff --git a/plugins/npapi/ScriptableInstance.cpp b/plugins/npapi/ScriptableInstance.cpp
index 0a5c8c3..b3c5c18 100644
--- a/plugins/npapi/ScriptableInstance.cpp
+++ b/plugins/npapi/ScriptableInstance.cpp
@@ -259,6 +259,7 @@
// 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;
}
@@ -288,21 +289,21 @@
<< ",module=" << NPVariantProxy::toString(args[3]) << ",hostedHtmlVers=" << NPVariantProxy::toString(args[4])
<< ")" << Debug::flush;
const std::string urlStr = convertToString(url);
- bool allowed = false;
- // TODO(jat): load access list
- if (!AllowedConnections::matchesRule(urlStr, &allowed)) {
- // If we didn't match an existing rule, prompt the user
- bool remember = false;
- allowed = askUserToAllow(urlStr, &remember);
- if (remember) {
- // TODO(jat): update access list
- }
- }
- if (!allowed) {
+ bool allowed = false;
+ // TODO(jat): load access list
+ if (!AllowedConnections::matchesRule(urlStr, &allowed)) {
+ // If we didn't match an existing rule, prompt the user
+ bool remember = false;
+ allowed = askUserToAllow(urlStr, &remember);
+ if (remember) {
+ // TODO(jat): update access list
+ }
+ }
+ if (!allowed) {
BOOLEAN_TO_NPVARIANT(false, *result);
result->type = NPVariantType_Bool;
- return;
- }
+ return;
+ }
bool connected = false;
unsigned port = 9997; // TODO(jat): should there be a default?
diff --git a/plugins/npapi/VisualStudio/firefox-plugin.sln b/plugins/npapi/VisualStudio/npapi-plugin.sln
similarity index 89%
rename from plugins/npapi/VisualStudio/firefox-plugin.sln
rename to plugins/npapi/VisualStudio/npapi-plugin.sln
index a036212..5604d56 100755
--- a/plugins/npapi/VisualStudio/firefox-plugin.sln
+++ b/plugins/npapi/VisualStudio/npapi-plugin.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual C++ Express 2005
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "firefox-plugin", "firefox-plugin.vcproj", "{6BF0C2CE-CB0C-421B-A67C-1E448371D24A}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "npapi-plugin", "npapi-plugin.vcproj", "{6BF0C2CE-CB0C-421B-A67C-1E448371D24A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/plugins/npapi/VisualStudio/firefox-plugin.vcproj b/plugins/npapi/VisualStudio/npapi-plugin.vcproj
similarity index 98%
rename from plugins/npapi/VisualStudio/firefox-plugin.vcproj
rename to plugins/npapi/VisualStudio/npapi-plugin.vcproj
index 7ca867f..a0e4545 100755
--- a/plugins/npapi/VisualStudio/firefox-plugin.vcproj
+++ b/plugins/npapi/VisualStudio/npapi-plugin.vcproj
@@ -2,9 +2,9 @@
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
- Name="firefox-plugin"
+ Name="npapi-plugin"
ProjectGUID="{6BF0C2CE-CB0C-421B-A67C-1E448371D24A}"
- RootNamespace="firefox-plugin"
+ RootNamespace="npapi-plugin"
Keyword="Win32Proj"
>
<Platforms>
@@ -40,7 +40,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""$(ProjectDir)\..\..\common""
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;FIREFOXPLUGIN_EXPORTS;GWT_DEBUGLEVEL=Warning"
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;FIREFOXPLUGIN_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
@@ -123,7 +123,7 @@
Optimization="3"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories=""..\..\common""
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;FIREFOXPLUGIN_EXPORTS;GWT_DEBUGLEVEL=Warning"
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;FIREFOXPLUGIN_EXPORTS"
ExceptionHandling="1"
RuntimeLibrary="2"
UsePrecompiledHeader="0"