Index: Source/testing/runner/TestPlugin.cpp |
diff --git a/Source/testing/runner/TestPlugin.cpp b/Source/testing/runner/TestPlugin.cpp |
index 42de524369cf02a5d7f06ee078058260d1296c97..21fd97b2b50bbb017ba9b025680fb7a7eddb8546 100644 |
--- a/Source/testing/runner/TestPlugin.cpp |
+++ b/Source/testing/runner/TestPlugin.cpp |
@@ -30,6 +30,7 @@ |
#include "public/platform/WebCompositorSupport.h" |
#include "public/platform/WebGraphicsContext3D.h" |
#include "public/testing/WebTestDelegate.h" |
+#include "public/web/WebBindings.h" |
#include "public/web/WebFrame.h" |
#include "public/web/WebInputEvent.h" |
#include "public/web/WebKit.h" |
@@ -147,6 +148,7 @@ void deferredDelete(void* context) |
} |
+static int s_instanceCount = 0; |
TestPlugin::TestPlugin(WebFrame* frame, const WebPluginParams& params, WebTestDelegate* delegate) |
: m_frame(frame) |
@@ -161,6 +163,10 @@ TestPlugin::TestPlugin(WebFrame* frame, const WebPluginParams& params, WebTestDe |
, m_printEventDetails(false) |
, m_printUserGestureStatus(false) |
, m_canProcessDrag(false) |
+ , m_npObject(0) |
+ , m_instanceId(++s_instanceCount) |
+ , m_isPersistent(params.mimeType.utf8().find(pluginPersistsSuffix().utf8()) != std::string::npos) |
+ , m_canCreateWithoutRenderer(params.mimeType.utf8().find(canCreateWithoutRendererSuffix().utf8()) != std::string::npos) |
{ |
static const WebString kAttributePrimitive = WebString::fromUTF8("primitive"); |
static const WebString kAttributeBackgroundColor = WebString::fromUTF8("background-color"); |
@@ -225,6 +231,7 @@ bool TestPlugin::initialize(WebPluginContainer* container) |
} |
m_container->requestTouchEventType(m_touchEventRequest); |
m_container->setWantsWheelEvents(true); |
+ m_container->allowScriptObjects(); |
return true; |
} |
@@ -246,6 +253,90 @@ void TestPlugin::destroy() |
Platform::current()->callOnMainThread(deferredDelete, this); |
} |
+class TestPluginNPObject : public NPObject { |
+public: |
+ TestPluginNPObject(TestPlugin* plugin): m_plugin(plugin) { } |
+ ~TestPluginNPObject() { } |
+ |
+ // This is a raw pointer; we assume this object doesn't outlive the associated |
+ // plugin object. |
+ TestPlugin* m_plugin; |
+}; |
+ |
+NPObject* TestPluginBindingsAllocate(NPP npp, NPClass* nppClass) |
+{ |
+ return new TestPluginNPObject(static_cast<TestPlugin*>(npp->pdata)); |
+} |
+ |
+WebString NPIdentifierToString(const NPIdentifier& npIdentifier) |
+{ |
+ NPUTF8* nputF8 = blink::WebBindings::utf8FromIdentifier(npIdentifier); |
+ WebString identifier = WebString::fromUTF8(nputF8); |
+ free(nputF8); |
+ return identifier; |
+} |
+ |
+static const WebString kPropertyInstanceId = WebString::fromUTF8("instanceId"); |
+static const WebString kPropertyIsPersistent = WebString::fromUTF8("isPersistent"); |
+static const WebString kPropertyCanCreateWithoutRenderer = WebString::fromUTF8("canCreateWithoutRenderer"); |
+ |
+bool TestPluginBindingsHasProperty(NPObject* npObject, NPIdentifier name) |
+{ |
+ WebString nameString = NPIdentifierToString(name); |
+ return nameString == kPropertyInstanceId || nameString == kPropertyIsPersistent || nameString == kPropertyCanCreateWithoutRenderer; |
wjmaclean
2013/12/12 20:30:46
Sorry about the length of this line, but presubmit
|
+} |
+ |
+bool TestPluginBindingsGetProperty(NPObject* npObject, NPIdentifier name, NPVariant* result) |
+{ |
+ if (!npObject) |
+ return false; |
+ |
+ WebString nameString = NPIdentifierToString(name); |
+ if (nameString == kPropertyInstanceId) |
+ INT32_TO_NPVARIANT(static_cast<TestPluginNPObject*>(npObject)->m_plugin->instanceId(), *result); |
+ |
+ if (nameString == kPropertyIsPersistent) |
+ BOOLEAN_TO_NPVARIANT(static_cast<TestPluginNPObject*>(npObject)->m_plugin->isPersistent(), *result); |
+ |
+ if (nameString == kPropertyCanCreateWithoutRenderer) |
+ BOOLEAN_TO_NPVARIANT(static_cast<TestPluginNPObject*>(npObject)->m_plugin->canCreateWithoutRenderer(), *result); |
+ |
+ return true; |
+} |
+ |
+bool TestPluginBindingsSetProperty(NPObject* npObject, NPIdentifier, const NPVariant*result) |
+{ |
+ // For now, all properties are read-only. |
+ return false; |
+} |
+ |
+NPClass testPluginClass = { |
+ NP_CLASS_STRUCT_VERSION, |
+ &TestPluginBindingsAllocate, |
+ 0, |
+ 0, |
+ 0, |
+ 0, |
+ 0, |
+ &TestPluginBindingsHasProperty, |
+ &TestPluginBindingsGetProperty, |
+ &TestPluginBindingsSetProperty, |
+ 0, |
+ 0, |
+}; |
+ |
+NPObject* TestPlugin::scriptableObject() |
+{ |
+ if (!m_npObject) { |
+ m_NPP.reset(new NPP_t); |
+ m_NPP->pdata = this; |
+ m_NPP->ndata = 0; |
+ m_npObject = blink::WebBindings::createObject(m_NPP.get(), &testPluginClass); |
+ blink::WebBindings::retainObject(m_npObject); |
+ } |
+ return m_npObject; |
+} |
+ |
void TestPlugin::updateGeometry(const WebRect& frameRect, const WebRect& clipRect, const WebVector<WebRect>& cutOutsRects, bool isVisible) |
{ |
if (clipRect == m_rect) |
@@ -578,4 +669,16 @@ const WebString& TestPlugin::mimeType() |
return kMimeType; |
} |
+const WebString& TestPlugin::canCreateWithoutRendererSuffix() |
+{ |
+ static const WebString kCanCreateWithoutRendererSuffix = WebString::fromUTF8("-can-create-without-renderer"); |
+ return kCanCreateWithoutRendererSuffix; |
+} |
+ |
+const WebString& TestPlugin::pluginPersistsSuffix() |
+{ |
+ static const WebString kPluginPersistsSuffix = WebString::fromUTF8("-persistent"); |
+ return kPluginPersistsSuffix; |
+} |
+ |
} |