OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 12 matching lines...) Expand all Loading... | |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "TestPlugin.h" | 26 #include "TestPlugin.h" |
27 | 27 |
28 #include "TestCommon.h" | 28 #include "TestCommon.h" |
29 #include "public/platform/Platform.h" | 29 #include "public/platform/Platform.h" |
30 #include "public/platform/WebCompositorSupport.h" | 30 #include "public/platform/WebCompositorSupport.h" |
31 #include "public/platform/WebGraphicsContext3D.h" | 31 #include "public/platform/WebGraphicsContext3D.h" |
32 #include "public/testing/WebTestDelegate.h" | 32 #include "public/testing/WebTestDelegate.h" |
33 #include "public/web/WebBindings.h" | |
33 #include "public/web/WebFrame.h" | 34 #include "public/web/WebFrame.h" |
34 #include "public/web/WebInputEvent.h" | 35 #include "public/web/WebInputEvent.h" |
35 #include "public/web/WebKit.h" | 36 #include "public/web/WebKit.h" |
36 #include "public/web/WebPluginParams.h" | 37 #include "public/web/WebPluginParams.h" |
37 #include "public/web/WebTouchPoint.h" | 38 #include "public/web/WebTouchPoint.h" |
38 #include "public/web/WebUserGestureIndicator.h" | 39 #include "public/web/WebUserGestureIndicator.h" |
39 | 40 |
40 using namespace blink; | 41 using namespace blink; |
41 using namespace std; | 42 using namespace std; |
42 | 43 |
43 namespace WebTestRunner { | 44 namespace WebTestRunner { |
44 | 45 |
45 namespace { | 46 namespace { |
46 | 47 |
47 // GLenum values copied from gl2.h. | 48 // GLenum values copied from gl2.h. |
48 #define GL_FALSE 0 | 49 #define GL_FALSE 0 |
49 #define GL_TRUE 1 | 50 #define GL_TRUE 1 |
50 #define GL_ONE 1 | 51 #define GL_ONE 1 |
51 #define GL_TRIANGLES 0x0004 | 52 #define GL_TRIANGLES 0x0004 |
52 #define GL_ONE_MINUS_SRC_ALPHA 0x0303 | 53 #define GL_ONE_MINUS_SRC_ALPHA 0x0303 |
53 #define GL_DEPTH_TEST 0x0B71 | 54 #define GL_DEPTH_TEST 0x0B71 |
54 #define GL_BLEND 0x0BE2 | 55 #define GL_BLEND 0x0BE2 |
55 #define GL_SCISSOR_TEST 0x0B90 | |
56 #define GL_TEXTURE_2D 0x0DE1 | 56 #define GL_TEXTURE_2D 0x0DE1 |
57 #define GL_FLOAT 0x1406 | 57 #define GL_FLOAT 0x1406 |
58 #define GL_RGBA 0x1908 | 58 #define GL_RGBA 0x1908 |
59 #define GL_UNSIGNED_BYTE 0x1401 | 59 #define GL_UNSIGNED_BYTE 0x1401 |
60 #define GL_TEXTURE_MAG_FILTER 0x2800 | 60 #define GL_TEXTURE_MAG_FILTER 0x2800 |
61 #define GL_TEXTURE_MIN_FILTER 0x2801 | 61 #define GL_TEXTURE_MIN_FILTER 0x2801 |
62 #define GL_TEXTURE_WRAP_S 0x2802 | 62 #define GL_TEXTURE_WRAP_S 0x2802 |
63 #define GL_TEXTURE_WRAP_T 0x2803 | 63 #define GL_TEXTURE_WRAP_T 0x2803 |
64 #define GL_NEAREST 0x2600 | 64 #define GL_NEAREST 0x2600 |
65 #define GL_COLOR_BUFFER_BIT 0x4000 | |
66 #define GL_CLAMP_TO_EDGE 0x812F | 65 #define GL_CLAMP_TO_EDGE 0x812F |
67 #define GL_ARRAY_BUFFER 0x8892 | 66 #define GL_ARRAY_BUFFER 0x8892 |
68 #define GL_STATIC_DRAW 0x88E4 | 67 #define GL_STATIC_DRAW 0x88E4 |
69 #define GL_FRAGMENT_SHADER 0x8B30 | 68 #define GL_FRAGMENT_SHADER 0x8B30 |
70 #define GL_VERTEX_SHADER 0x8B31 | 69 #define GL_VERTEX_SHADER 0x8B31 |
71 #define GL_COMPILE_STATUS 0x8B81 | 70 #define GL_COMPILE_STATUS 0x8B81 |
72 #define GL_LINK_STATUS 0x8B82 | 71 #define GL_LINK_STATUS 0x8B82 |
73 #define GL_COLOR_ATTACHMENT0 0x8CE0 | 72 #define GL_COLOR_ATTACHMENT0 0x8CE0 |
74 #define GL_FRAMEBUFFER_COMPLETE 0x8CD5 | 73 #define GL_FRAMEBUFFER_COMPLETE 0x8CD5 |
75 #define GL_FRAMEBUFFER 0x8D40 | 74 #define GL_FRAMEBUFFER 0x8D40 |
76 | 75 |
76 // 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
| |
77 #ifndef GL_SCISSOR_TEST | |
78 #define GL_SCISSOR_TEST 0x0B90 | |
79 #endif | |
80 #ifndef GL_COLOR_BUFFER_BIT | |
81 #define GL_COLOR_BUFFER_BIT 0x4000 | |
82 #endif | |
83 | |
77 void premultiplyAlpha(const unsigned colorIn[3], float alpha, float colorOut[4]) | 84 void premultiplyAlpha(const unsigned colorIn[3], float alpha, float colorOut[4]) |
78 { | 85 { |
79 for (int i = 0; i < 3; ++i) | 86 for (int i = 0; i < 3; ++i) |
80 colorOut[i] = (colorIn[i] / 255.0f) * alpha; | 87 colorOut[i] = (colorIn[i] / 255.0f) * alpha; |
81 | 88 |
82 colorOut[3] = alpha; | 89 colorOut[3] = alpha; |
83 } | 90 } |
84 | 91 |
85 const char* pointState(WebTouchPoint::State state) | 92 const char* pointState(WebTouchPoint::State state) |
86 { | 93 { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 } | 147 } |
141 | 148 |
142 void deferredDelete(void* context) | 149 void deferredDelete(void* context) |
143 { | 150 { |
144 TestPlugin* plugin = static_cast<TestPlugin*>(context); | 151 TestPlugin* plugin = static_cast<TestPlugin*>(context); |
145 delete plugin; | 152 delete plugin; |
146 } | 153 } |
147 | 154 |
148 } | 155 } |
149 | 156 |
157 static int s_instanceCount = 0; | |
150 | 158 |
151 TestPlugin::TestPlugin(WebFrame* frame, const WebPluginParams& params, WebTestDe legate* delegate) | 159 TestPlugin::TestPlugin(WebFrame* frame, const WebPluginParams& params, WebTestDe legate* delegate) |
152 : m_frame(frame) | 160 : m_frame(frame) |
153 , m_delegate(delegate) | 161 , m_delegate(delegate) |
154 , m_container(0) | 162 , m_container(0) |
155 , m_context(0) | 163 , m_context(0) |
156 , m_colorTexture(0) | 164 , m_colorTexture(0) |
157 , m_mailboxChanged(false) | 165 , m_mailboxChanged(false) |
158 , m_framebuffer(0) | 166 , m_framebuffer(0) |
159 , m_touchEventRequest(WebPluginContainer::TouchEventRequestTypeNone) | 167 , m_touchEventRequest(WebPluginContainer::TouchEventRequestTypeNone) |
160 , m_reRequestTouchEvents(false) | 168 , m_reRequestTouchEvents(false) |
161 , m_printEventDetails(false) | 169 , m_printEventDetails(false) |
162 , m_printUserGestureStatus(false) | 170 , m_printUserGestureStatus(false) |
163 , m_canProcessDrag(false) | 171 , m_canProcessDrag(false) |
172 , m_npObject(0) | |
173 , m_instanceId(++s_instanceCount) | |
174 , m_isPersistent(params.mimeType.utf8().find(pluginPersistsSuffix().utf8()) != std::string::npos) | |
175 , m_canCreateWithoutRenderer(params.mimeType.utf8().find(canCreateWithoutRen dererSuffix().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()
| |
164 { | 176 { |
165 static const WebString kAttributePrimitive = WebString::fromUTF8("primitive" ); | 177 static const WebString kAttributePrimitive = WebString::fromUTF8("primitive" ); |
166 static const WebString kAttributeBackgroundColor = WebString::fromUTF8("back ground-color"); | 178 static const WebString kAttributeBackgroundColor = WebString::fromUTF8("back ground-color"); |
167 static const WebString kAttributePrimitiveColor = WebString::fromUTF8("primi tive-color"); | 179 static const WebString kAttributePrimitiveColor = WebString::fromUTF8("primi tive-color"); |
168 static const WebString kAttributeOpacity = WebString::fromUTF8("opacity"); | 180 static const WebString kAttributeOpacity = WebString::fromUTF8("opacity"); |
169 static const WebString kAttributeAcceptsTouch = WebString::fromUTF8("accepts -touch"); | 181 static const WebString kAttributeAcceptsTouch = WebString::fromUTF8("accepts -touch"); |
170 static const WebString kAttributeReRequestTouchEvents = WebString::fromUTF8( "re-request-touch"); | 182 static const WebString kAttributeReRequestTouchEvents = WebString::fromUTF8( "re-request-touch"); |
171 static const WebString kAttributePrintEventDetails = WebString::fromUTF8("pr int-event-details"); | 183 static const WebString kAttributePrintEventDetails = WebString::fromUTF8("pr int-event-details"); |
172 static const WebString kAttributeCanProcessDrag = WebString::fromUTF8("can-p rocess-drag"); | 184 static const WebString kAttributeCanProcessDrag = WebString::fromUTF8("can-p rocess-drag"); |
173 static const WebString kAttributePrintUserGestureStatus = WebString::fromUTF 8("print-user-gesture-status"); | 185 static const WebString kAttributePrintUserGestureStatus = WebString::fromUTF 8("print-user-gesture-status"); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 | 230 |
219 m_layer = WebScopedPtr<WebExternalTextureLayer>(Platform::current()->composi torSupport()->createExternalTextureLayer(this)); | 231 m_layer = WebScopedPtr<WebExternalTextureLayer>(Platform::current()->composi torSupport()->createExternalTextureLayer(this)); |
220 m_container = container; | 232 m_container = container; |
221 m_container->setWebLayer(m_layer->layer()); | 233 m_container->setWebLayer(m_layer->layer()); |
222 if (m_reRequestTouchEvents) { | 234 if (m_reRequestTouchEvents) { |
223 m_container->requestTouchEventType(WebPluginContainer::TouchEventRequest TypeSynthesizedMouse); | 235 m_container->requestTouchEventType(WebPluginContainer::TouchEventRequest TypeSynthesizedMouse); |
224 m_container->requestTouchEventType(WebPluginContainer::TouchEventRequest TypeRaw); | 236 m_container->requestTouchEventType(WebPluginContainer::TouchEventRequest TypeRaw); |
225 } | 237 } |
226 m_container->requestTouchEventType(m_touchEventRequest); | 238 m_container->requestTouchEventType(m_touchEventRequest); |
227 m_container->setWantsWheelEvents(true); | 239 m_container->setWantsWheelEvents(true); |
240 m_container->allowScriptObjects(); | |
228 return true; | 241 return true; |
229 } | 242 } |
230 | 243 |
231 void TestPlugin::destroy() | 244 void TestPlugin::destroy() |
232 { | 245 { |
233 if (m_layer.get()) | 246 if (m_layer.get()) |
234 m_layer->clearTexture(); | 247 m_layer->clearTexture(); |
235 if (m_container) | 248 if (m_container) |
236 m_container->setWebLayer(0); | 249 m_container->setWebLayer(0); |
237 m_layer.reset(); | 250 m_layer.reset(); |
238 destroyScene(); | 251 destroyScene(); |
239 | 252 |
240 delete m_context; | 253 delete m_context; |
241 m_context = 0; | 254 m_context = 0; |
242 | 255 |
243 m_container = 0; | 256 m_container = 0; |
244 m_frame = 0; | 257 m_frame = 0; |
245 | 258 |
246 Platform::current()->callOnMainThread(deferredDelete, this); | 259 Platform::current()->callOnMainThread(deferredDelete, this); |
247 } | 260 } |
248 | 261 |
262 class TestPluginNPObject : public NPObject { | |
263 public: | |
264 TestPluginNPObject(TestPlugin* plugin): m_plugin(plugin) { } | |
265 ~TestPluginNPObject() { } | |
266 | |
267 // This is a raw pointer; we assume this object doesn't outlive the associat ed | |
268 // plugin object. | |
269 TestPlugin* m_plugin; | |
270 }; | |
271 | |
272 NPObject* TestPluginBindingsAllocate(NPP npp, NPClass* nppClass) | |
273 { | |
274 return new TestPluginNPObject(static_cast<TestPlugin*>(npp->pdata)); | |
275 } | |
276 | |
277 WebString NPIdentifierToString(const NPIdentifier& npIdentifier) | |
278 { | |
279 NPUTF8* nputF8 = blink::WebBindings::utf8FromIdentifier(npIdentifier); | |
280 WebString identifier = WebString::fromUTF8(nputF8); | |
281 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
| |
282 return identifier; | |
283 } | |
284 | |
285 static const WebString kPropertyInstanceId = WebString::fromUTF8("instanceId"); | |
286 static const WebString kPropertyIsPersistent = WebString::fromUTF8("isPersistent "); | |
287 static const WebString kPropertyCanCreateWithoutRenderer = WebString::fromUTF8(" canCreateWithoutRenderer"); | |
288 | |
289 bool TestPluginBindingsHasProperty(NPObject* npObject, NPIdentifier name) | |
290 { | |
291 WebString nameString = NPIdentifierToString(name); | |
292 return nameString == kPropertyInstanceId || nameString == kPropertyIsPersist ent || nameString == kPropertyCanCreateWithoutRenderer; | |
293 } | |
294 | |
295 bool TestPluginBindingsGetProperty(NPObject* npObject, NPIdentifier name, NPVari ant* result) | |
296 { | |
297 if (!npObject) | |
298 return false; | |
299 | |
300 WebString nameString = NPIdentifierToString(name); | |
301 if (nameString == kPropertyInstanceId) | |
302 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.
| |
303 | |
304 if (nameString == kPropertyIsPersistent) | |
305 BOOLEAN_TO_NPVARIANT(static_cast<TestPluginNPObject*>(npObject)->m_plugi n->isPersistent(), *result); | |
306 | |
307 if (nameString == kPropertyCanCreateWithoutRenderer) | |
308 BOOLEAN_TO_NPVARIANT(static_cast<TestPluginNPObject*>(npObject)->m_plugi n->canCreateWithoutRenderer(), *result); | |
309 | |
310 return true; | |
311 } | |
312 | |
313 bool TestPluginBindingsSetProperty(NPObject* npObject, NPIdentifier, const NPVar iant*result) | |
314 { | |
315 // For now, all properties are read-only. | |
316 return false; | |
317 } | |
318 | |
319 NPClass testPluginClass = { | |
320 NP_CLASS_STRUCT_VERSION, | |
321 &TestPluginBindingsAllocate, | |
322 0, | |
323 0, | |
324 0, | |
325 0, | |
326 0, | |
327 &TestPluginBindingsHasProperty, | |
328 &TestPluginBindingsGetProperty, | |
329 &TestPluginBindingsSetProperty, | |
330 0, | |
331 0, | |
332 }; | |
333 | |
334 NPObject* TestPlugin::scriptableObject() | |
335 { | |
336 if (!m_npObject) { | |
337 m_NPP.reset(new NPP_t); | |
338 m_NPP->pdata = this; | |
339 m_NPP->ndata = 0; | |
340 m_npObject = blink::WebBindings::createObject(m_NPP.get(), &testPluginCl ass); | |
341 blink::WebBindings::retainObject(m_npObject); | |
342 } | |
343 return m_npObject; | |
344 } | |
345 | |
249 void TestPlugin::updateGeometry(const WebRect& frameRect, const WebRect& clipRec t, const WebVector<WebRect>& cutOutsRects, bool isVisible) | 346 void TestPlugin::updateGeometry(const WebRect& frameRect, const WebRect& clipRec t, const WebVector<WebRect>& cutOutsRects, bool isVisible) |
250 { | 347 { |
251 if (clipRect == m_rect) | 348 if (clipRect == m_rect) |
252 return; | 349 return; |
253 m_rect = clipRect; | 350 m_rect = clipRect; |
254 if (m_rect.isEmpty()) | 351 if (m_rect.isEmpty()) |
255 return; | 352 return; |
256 | 353 |
257 m_context->reshapeWithScaleFactor(m_rect.width, m_rect.height, 1.f); | 354 m_context->reshapeWithScaleFactor(m_rect.width, m_rect.height, 1.f); |
258 m_context->viewport(0, 0, m_rect.width, m_rect.height); | 355 m_context->viewport(0, 0, m_rect.width, m_rect.height); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 { | 668 { |
572 return new TestPlugin(frame, params, delegate); | 669 return new TestPlugin(frame, params, delegate); |
573 } | 670 } |
574 | 671 |
575 const WebString& TestPlugin::mimeType() | 672 const WebString& TestPlugin::mimeType() |
576 { | 673 { |
577 static const WebString kMimeType = WebString::fromUTF8("application/x-webkit -test-webplugin"); | 674 static const WebString kMimeType = WebString::fromUTF8("application/x-webkit -test-webplugin"); |
578 return kMimeType; | 675 return kMimeType; |
579 } | 676 } |
580 | 677 |
678 const WebString& TestPlugin::canCreateWithoutRendererSuffix() | |
679 { | |
680 static const WebString kCanCreateWithoutRendererSuffix = WebString::fromUTF 8("-can-create-without-renderer"); | |
681 return kCanCreateWithoutRendererSuffix; | |
581 } | 682 } |
683 | |
684 const WebString& TestPlugin::pluginPersistsSuffix() | |
685 { | |
686 static const WebString kPluginPersistsSuffix = WebString::fromUTF8("-persist ent"); | |
687 return kPluginPersistsSuffix; | |
688 } | |
689 | |
690 } | |
OLD | NEW |