Chromium Code Reviews| Index: Source/testing/runner/TestPlugin.cpp |
| diff --git a/Source/testing/runner/TestPlugin.cpp b/Source/testing/runner/TestPlugin.cpp |
| index 42de524369cf02a5d7f06ee078058260d1296c97..33de3153abc834ad9c388302337d24d1b8142169 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" |
| @@ -52,7 +53,6 @@ namespace { |
| #define GL_ONE_MINUS_SRC_ALPHA 0x0303 |
| #define GL_DEPTH_TEST 0x0B71 |
| #define GL_BLEND 0x0BE2 |
| -#define GL_SCISSOR_TEST 0x0B90 |
| #define GL_TEXTURE_2D 0x0DE1 |
| #define GL_FLOAT 0x1406 |
| #define GL_RGBA 0x1908 |
| @@ -62,7 +62,6 @@ namespace { |
| #define GL_TEXTURE_WRAP_S 0x2802 |
| #define GL_TEXTURE_WRAP_T 0x2803 |
| #define GL_NEAREST 0x2600 |
| -#define GL_COLOR_BUFFER_BIT 0x4000 |
| #define GL_CLAMP_TO_EDGE 0x812F |
| #define GL_ARRAY_BUFFER 0x8892 |
| #define GL_STATIC_DRAW 0x88E4 |
| @@ -74,6 +73,14 @@ namespace { |
| #define GL_FRAMEBUFFER_COMPLETE 0x8CD5 |
| #define GL_FRAMEBUFFER 0x8D40 |
| +// Mac defines these elsewhere and doesn't like duplicates. |
|
eseidel
2013/12/18 18:38:18
Why are we defining these in TestPlugin.cpp in teh
wjmaclean
2013/12/23 23:49:53
I'm not sure, though I would imagine that one reas
|
| +#ifndef GL_SCISSOR_TEST |
| +#define GL_SCISSOR_TEST 0x0B90 |
| +#endif |
| +#ifndef GL_COLOR_BUFFER_BIT |
| +#define GL_COLOR_BUFFER_BIT 0x4000 |
| +#endif |
| + |
| void premultiplyAlpha(const unsigned colorIn[3], float alpha, float colorOut[4]) |
| { |
| for (int i = 0; i < 3; ++i) |
| @@ -147,6 +154,7 @@ void deferredDelete(void* context) |
| } |
| +static int s_instanceCount = 0; |
| TestPlugin::TestPlugin(WebFrame* frame, const WebPluginParams& params, WebTestDelegate* delegate) |
| : m_frame(frame) |
| @@ -161,6 +169,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) |
|
eseidel
2013/12/18 18:38:18
Why all the .utf8? Does this not have a contains(
wjmaclean
2013/12/23 23:49:53
No longer using find()
|
| { |
| static const WebString kAttributePrimitive = WebString::fromUTF8("primitive"); |
| static const WebString kAttributeBackgroundColor = WebString::fromUTF8("background-color"); |
| @@ -225,6 +237,7 @@ bool TestPlugin::initialize(WebPluginContainer* container) |
| } |
| m_container->requestTouchEventType(m_touchEventRequest); |
| m_container->setWantsWheelEvents(true); |
| + m_container->allowScriptObjects(); |
| return true; |
| } |
| @@ -246,6 +259,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); |
|
eseidel
2013/12/18 18:38:18
Do we have a OwnPtr-like concept for this instead?
wjmaclean
2013/12/23 23:49:53
I'm unsure ... aren't all the owned-ptr types base
|
| + 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; |
| +} |
| + |
| +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); |
|
eseidel
2013/12/18 18:38:18
Should we pull this cast out into a local?
wjmaclean
2013/12/23 23:49:53
Done.
|
| + |
| + 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 +675,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; |
| +} |
| + |
| } |