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 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 } | 141 } |
141 | 142 |
142 void deferredDelete(void* context) | 143 void deferredDelete(void* context) |
143 { | 144 { |
144 TestPlugin* plugin = static_cast<TestPlugin*>(context); | 145 TestPlugin* plugin = static_cast<TestPlugin*>(context); |
145 delete plugin; | 146 delete plugin; |
146 } | 147 } |
147 | 148 |
148 } | 149 } |
149 | 150 |
151 static int s_instanceCount = 0; | |
150 | 152 |
151 TestPlugin::TestPlugin(WebFrame* frame, const WebPluginParams& params, WebTestDe legate* delegate) | 153 TestPlugin::TestPlugin(WebFrame* frame, const WebPluginParams& params, WebTestDe legate* delegate) |
152 : m_frame(frame) | 154 : m_frame(frame) |
153 , m_delegate(delegate) | 155 , m_delegate(delegate) |
154 , m_container(0) | 156 , m_container(0) |
155 , m_context(0) | 157 , m_context(0) |
156 , m_colorTexture(0) | 158 , m_colorTexture(0) |
157 , m_mailboxChanged(false) | 159 , m_mailboxChanged(false) |
158 , m_framebuffer(0) | 160 , m_framebuffer(0) |
159 , m_touchEventRequest(WebPluginContainer::TouchEventRequestTypeNone) | 161 , m_touchEventRequest(WebPluginContainer::TouchEventRequestTypeNone) |
160 , m_reRequestTouchEvents(false) | 162 , m_reRequestTouchEvents(false) |
161 , m_printEventDetails(false) | 163 , m_printEventDetails(false) |
162 , m_printUserGestureStatus(false) | 164 , m_printUserGestureStatus(false) |
163 , m_canProcessDrag(false) | 165 , m_canProcessDrag(false) |
166 , m_npObject(0) | |
167 , m_instanceId(++s_instanceCount) | |
168 , m_isPersistent(params.mimeType.utf8().find(pluginPersistsSuffix().utf8()) != std::string::npos) | |
169 , m_canCreateWithoutRenderer(params.mimeType.utf8().find(canCreateWithoutRen dererSuffix().utf8()) != std::string::npos) | |
164 { | 170 { |
165 static const WebString kAttributePrimitive = WebString::fromUTF8("primitive" ); | 171 static const WebString kAttributePrimitive = WebString::fromUTF8("primitive" ); |
166 static const WebString kAttributeBackgroundColor = WebString::fromUTF8("back ground-color"); | 172 static const WebString kAttributeBackgroundColor = WebString::fromUTF8("back ground-color"); |
167 static const WebString kAttributePrimitiveColor = WebString::fromUTF8("primi tive-color"); | 173 static const WebString kAttributePrimitiveColor = WebString::fromUTF8("primi tive-color"); |
168 static const WebString kAttributeOpacity = WebString::fromUTF8("opacity"); | 174 static const WebString kAttributeOpacity = WebString::fromUTF8("opacity"); |
169 static const WebString kAttributeAcceptsTouch = WebString::fromUTF8("accepts -touch"); | 175 static const WebString kAttributeAcceptsTouch = WebString::fromUTF8("accepts -touch"); |
170 static const WebString kAttributeReRequestTouchEvents = WebString::fromUTF8( "re-request-touch"); | 176 static const WebString kAttributeReRequestTouchEvents = WebString::fromUTF8( "re-request-touch"); |
171 static const WebString kAttributePrintEventDetails = WebString::fromUTF8("pr int-event-details"); | 177 static const WebString kAttributePrintEventDetails = WebString::fromUTF8("pr int-event-details"); |
172 static const WebString kAttributeCanProcessDrag = WebString::fromUTF8("can-p rocess-drag"); | 178 static const WebString kAttributeCanProcessDrag = WebString::fromUTF8("can-p rocess-drag"); |
173 static const WebString kAttributePrintUserGestureStatus = WebString::fromUTF 8("print-user-gesture-status"); | 179 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 | 224 |
219 m_layer = WebScopedPtr<WebExternalTextureLayer>(Platform::current()->composi torSupport()->createExternalTextureLayer(this)); | 225 m_layer = WebScopedPtr<WebExternalTextureLayer>(Platform::current()->composi torSupport()->createExternalTextureLayer(this)); |
220 m_container = container; | 226 m_container = container; |
221 m_container->setWebLayer(m_layer->layer()); | 227 m_container->setWebLayer(m_layer->layer()); |
222 if (m_reRequestTouchEvents) { | 228 if (m_reRequestTouchEvents) { |
223 m_container->requestTouchEventType(WebPluginContainer::TouchEventRequest TypeSynthesizedMouse); | 229 m_container->requestTouchEventType(WebPluginContainer::TouchEventRequest TypeSynthesizedMouse); |
224 m_container->requestTouchEventType(WebPluginContainer::TouchEventRequest TypeRaw); | 230 m_container->requestTouchEventType(WebPluginContainer::TouchEventRequest TypeRaw); |
225 } | 231 } |
226 m_container->requestTouchEventType(m_touchEventRequest); | 232 m_container->requestTouchEventType(m_touchEventRequest); |
227 m_container->setWantsWheelEvents(true); | 233 m_container->setWantsWheelEvents(true); |
234 m_container->allowScriptObjects(); | |
228 return true; | 235 return true; |
229 } | 236 } |
230 | 237 |
231 void TestPlugin::destroy() | 238 void TestPlugin::destroy() |
232 { | 239 { |
233 if (m_layer.get()) | 240 if (m_layer.get()) |
234 m_layer->clearTexture(); | 241 m_layer->clearTexture(); |
235 if (m_container) | 242 if (m_container) |
236 m_container->setWebLayer(0); | 243 m_container->setWebLayer(0); |
237 m_layer.reset(); | 244 m_layer.reset(); |
238 destroyScene(); | 245 destroyScene(); |
239 | 246 |
240 delete m_context; | 247 delete m_context; |
241 m_context = 0; | 248 m_context = 0; |
242 | 249 |
243 m_container = 0; | 250 m_container = 0; |
244 m_frame = 0; | 251 m_frame = 0; |
245 | 252 |
246 Platform::current()->callOnMainThread(deferredDelete, this); | 253 Platform::current()->callOnMainThread(deferredDelete, this); |
247 } | 254 } |
248 | 255 |
256 class TestPluginNPObject : public NPObject { | |
257 public: | |
258 TestPluginNPObject(TestPlugin* plugin): m_plugin(plugin) { } | |
259 ~TestPluginNPObject() { } | |
260 | |
261 // This is a raw pointer; we assume this object doesn't outlive the associat ed | |
262 // plugin object. | |
263 TestPlugin* m_plugin; | |
264 }; | |
265 | |
266 NPObject* TestPluginBindingsAllocate(NPP npp, NPClass* nppClass) | |
267 { | |
268 return new TestPluginNPObject(static_cast<TestPlugin*>(npp->pdata)); | |
269 } | |
270 | |
271 WebString NPIdentifierToString(const NPIdentifier& npIdentifier) | |
272 { | |
273 NPUTF8* nputF8 = blink::WebBindings::utf8FromIdentifier(npIdentifier); | |
274 WebString identifier = WebString::fromUTF8(nputF8); | |
275 free(nputF8); | |
276 return identifier; | |
277 } | |
278 | |
279 static const WebString kPropertyInstanceId = WebString::fromUTF8("instanceId"); | |
280 static const WebString kPropertyIsPersistent = WebString::fromUTF8("isPersistent "); | |
281 static const WebString kPropertyCanCreateWithoutRenderer = WebString::fromUTF8(" canCreateWithoutRenderer"); | |
282 | |
283 bool TestPluginBindingsHasProperty(NPObject* npObject, NPIdentifier name) | |
284 { | |
285 WebString nameString = NPIdentifierToString(name); | |
286 return nameString == kPropertyInstanceId || nameString == kPropertyIsPersist ent || nameString == kPropertyCanCreateWithoutRenderer; | |
wjmaclean
2013/12/12 20:30:46
Sorry about the length of this line, but presubmit
| |
287 } | |
288 | |
289 bool TestPluginBindingsGetProperty(NPObject* npObject, NPIdentifier name, NPVari ant* result) | |
290 { | |
291 if (!npObject) | |
292 return false; | |
293 | |
294 WebString nameString = NPIdentifierToString(name); | |
295 if (nameString == kPropertyInstanceId) | |
296 INT32_TO_NPVARIANT(static_cast<TestPluginNPObject*>(npObject)->m_plugin- >instanceId(), *result); | |
297 | |
298 if (nameString == kPropertyIsPersistent) | |
299 BOOLEAN_TO_NPVARIANT(static_cast<TestPluginNPObject*>(npObject)->m_plugi n->isPersistent(), *result); | |
300 | |
301 if (nameString == kPropertyCanCreateWithoutRenderer) | |
302 BOOLEAN_TO_NPVARIANT(static_cast<TestPluginNPObject*>(npObject)->m_plugi n->canCreateWithoutRenderer(), *result); | |
303 | |
304 return true; | |
305 } | |
306 | |
307 bool TestPluginBindingsSetProperty(NPObject* npObject, NPIdentifier, const NPVar iant*result) | |
308 { | |
309 // For now, all properties are read-only. | |
310 return false; | |
311 } | |
312 | |
313 NPClass testPluginClass = { | |
314 NP_CLASS_STRUCT_VERSION, | |
315 &TestPluginBindingsAllocate, | |
316 0, | |
317 0, | |
318 0, | |
319 0, | |
320 0, | |
321 &TestPluginBindingsHasProperty, | |
322 &TestPluginBindingsGetProperty, | |
323 &TestPluginBindingsSetProperty, | |
324 0, | |
325 0, | |
326 }; | |
327 | |
328 NPObject* TestPlugin::scriptableObject() | |
329 { | |
330 if (!m_npObject) { | |
331 m_NPP.reset(new NPP_t); | |
332 m_NPP->pdata = this; | |
333 m_NPP->ndata = 0; | |
334 m_npObject = blink::WebBindings::createObject(m_NPP.get(), &testPluginCl ass); | |
335 blink::WebBindings::retainObject(m_npObject); | |
336 } | |
337 return m_npObject; | |
338 } | |
339 | |
249 void TestPlugin::updateGeometry(const WebRect& frameRect, const WebRect& clipRec t, const WebVector<WebRect>& cutOutsRects, bool isVisible) | 340 void TestPlugin::updateGeometry(const WebRect& frameRect, const WebRect& clipRec t, const WebVector<WebRect>& cutOutsRects, bool isVisible) |
250 { | 341 { |
251 if (clipRect == m_rect) | 342 if (clipRect == m_rect) |
252 return; | 343 return; |
253 m_rect = clipRect; | 344 m_rect = clipRect; |
254 if (m_rect.isEmpty()) | 345 if (m_rect.isEmpty()) |
255 return; | 346 return; |
256 | 347 |
257 m_context->reshapeWithScaleFactor(m_rect.width, m_rect.height, 1.f); | 348 m_context->reshapeWithScaleFactor(m_rect.width, m_rect.height, 1.f); |
258 m_context->viewport(0, 0, m_rect.width, m_rect.height); | 349 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 { | 662 { |
572 return new TestPlugin(frame, params, delegate); | 663 return new TestPlugin(frame, params, delegate); |
573 } | 664 } |
574 | 665 |
575 const WebString& TestPlugin::mimeType() | 666 const WebString& TestPlugin::mimeType() |
576 { | 667 { |
577 static const WebString kMimeType = WebString::fromUTF8("application/x-webkit -test-webplugin"); | 668 static const WebString kMimeType = WebString::fromUTF8("application/x-webkit -test-webplugin"); |
578 return kMimeType; | 669 return kMimeType; |
579 } | 670 } |
580 | 671 |
672 const WebString& TestPlugin::canCreateWithoutRendererSuffix() | |
673 { | |
674 static const WebString kCanCreateWithoutRendererSuffix = WebString::fromUTF 8("-can-create-without-renderer"); | |
675 return kCanCreateWithoutRendererSuffix; | |
581 } | 676 } |
677 | |
678 const WebString& TestPlugin::pluginPersistsSuffix() | |
679 { | |
680 static const WebString kPluginPersistsSuffix = WebString::fromUTF8("-persist ent"); | |
681 return kPluginPersistsSuffix; | |
682 } | |
683 | |
684 } | |
OLD | NEW |