1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/shell/renderer/test_runner/TestPlugin.h"
7 #include "base/basictypes.h"
9 #include "base/logging.h"
10 #include "base/memory/shared_memory.h"
11 #include "content/public/renderer/render_thread.h"
12 #include "content/shell/renderer/test_runner/TestCommon.h"
13 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "third_party/skia/include/core/SkCanvas.h"
16 #include "third_party/skia/include/core/SkColor.h"
17 #include "third_party/WebKit/public/platform/Platform.h"
18 #include "third_party/WebKit/public/platform/WebCompositorSupport.h"
19 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
20 #include "third_party/WebKit/public/web/WebFrame.h"
21 #include "third_party/WebKit/public/web/WebInputEvent.h"
22 #include "third_party/WebKit/public/web/WebKit.h"
23 #include "third_party/WebKit/public/web/WebPluginParams.h"
24 #include "third_party/WebKit/public/web/WebTouchPoint.h"
25 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
27 using namespace blink
;
30 namespace WebTestRunner
{
34 // GLenum values copied from gl2.h.
38 #define GL_TRIANGLES 0x0004
39 #define GL_ONE_MINUS_SRC_ALPHA 0x0303
40 #define GL_DEPTH_TEST 0x0B71
41 #define GL_BLEND 0x0BE2
42 #define GL_SCISSOR_TEST 0x0B90
43 #define GL_TEXTURE_2D 0x0DE1
44 #define GL_FLOAT 0x1406
45 #define GL_RGBA 0x1908
46 #define GL_UNSIGNED_BYTE 0x1401
47 #define GL_TEXTURE_MAG_FILTER 0x2800
48 #define GL_TEXTURE_MIN_FILTER 0x2801
49 #define GL_TEXTURE_WRAP_S 0x2802
50 #define GL_TEXTURE_WRAP_T 0x2803
51 #define GL_NEAREST 0x2600
52 #define GL_COLOR_BUFFER_BIT 0x4000
53 #define GL_CLAMP_TO_EDGE 0x812F
54 #define GL_ARRAY_BUFFER 0x8892
55 #define GL_STATIC_DRAW 0x88E4
56 #define GL_FRAGMENT_SHADER 0x8B30
57 #define GL_VERTEX_SHADER 0x8B31
58 #define GL_COMPILE_STATUS 0x8B81
59 #define GL_LINK_STATUS 0x8B82
60 #define GL_COLOR_ATTACHMENT0 0x8CE0
61 #define GL_FRAMEBUFFER_COMPLETE 0x8CD5
62 #define GL_FRAMEBUFFER 0x8D40
64 void premultiplyAlpha(const unsigned colorIn
[3], float alpha
, float colorOut
[4])
66 for (int i
= 0; i
< 3; ++i
)
67 colorOut
[i
] = (colorIn
[i
] / 255.0f
) * alpha
;
72 const char* pointState(WebTouchPoint::State state
)
75 case WebTouchPoint::StateReleased
:
77 case WebTouchPoint::StatePressed
:
79 case WebTouchPoint::StateMoved
:
81 case WebTouchPoint::StateCancelled
:
88 void printTouchList(WebTestDelegate
* delegate
, const WebTouchPoint
* points
, int length
)
90 for (int i
= 0; i
< length
; ++i
) {
97 pointState(points
[i
].state
));
98 delegate
->printMessage(buffer
);
102 void printEventDetails(WebTestDelegate
* delegate
, const WebInputEvent
& event
)
104 if (WebInputEvent::isTouchEventType(event
.type
)) {
105 const WebTouchEvent
& touch
= static_cast<const WebTouchEvent
&>(event
);
106 printTouchList(delegate
, touch
.touches
, touch
.touchesLength
);
107 printTouchList(delegate
, touch
.changedTouches
, touch
.changedTouchesLength
);
108 printTouchList(delegate
, touch
.targetTouches
, touch
.targetTouchesLength
);
109 } else if (WebInputEvent::isMouseEventType(event
.type
) || event
.type
== WebInputEvent::MouseWheel
) {
110 const WebMouseEvent
& mouse
= static_cast<const WebMouseEvent
&>(event
);
112 snprintf(buffer
, sizeof(buffer
), "* %d, %d\n", mouse
.x
, mouse
.y
);
113 delegate
->printMessage(buffer
);
114 } else if (WebInputEvent::isGestureEventType(event
.type
)) {
115 const WebGestureEvent
& gesture
= static_cast<const WebGestureEvent
&>(event
);
117 snprintf(buffer
, sizeof(buffer
), "* %d, %d\n", gesture
.x
, gesture
.y
);
118 delegate
->printMessage(buffer
);
122 WebPluginContainer::TouchEventRequestType
parseTouchEventRequestType(const WebString
& string
)
124 if (string
== WebString::fromUTF8("raw"))
125 return WebPluginContainer::TouchEventRequestTypeRaw
;
126 if (string
== WebString::fromUTF8("synthetic"))
127 return WebPluginContainer::TouchEventRequestTypeSynthesizedMouse
;
128 return WebPluginContainer::TouchEventRequestTypeNone
;
131 void deferredDelete(void* context
)
133 TestPlugin
* plugin
= static_cast<TestPlugin
*>(context
);
139 TestPlugin::TestPlugin(WebFrame
* frame
, const WebPluginParams
& params
, WebTestDelegate
* delegate
)
141 , m_delegate(delegate
)
145 , m_mailboxChanged(false)
147 , m_touchEventRequest(WebPluginContainer::TouchEventRequestTypeNone
)
148 , m_reRequestTouchEvents(false)
149 , m_printEventDetails(false)
150 , m_printUserGestureStatus(false)
151 , m_canProcessDrag(false)
152 , m_isPersistent(params
.mimeType
== pluginPersistsMimeType())
153 , m_canCreateWithoutRenderer(params
.mimeType
== canCreateWithoutRendererMimeType())
155 const CR_DEFINE_STATIC_LOCAL(WebString
, kAttributePrimitive
, ("primitive"));
156 const CR_DEFINE_STATIC_LOCAL(WebString
, kAttributeBackgroundColor
, ("background-color"));
157 const CR_DEFINE_STATIC_LOCAL(WebString
, kAttributePrimitiveColor
, ("primitive-color"));
158 const CR_DEFINE_STATIC_LOCAL(WebString
, kAttributeOpacity
, ("opacity"));
159 const CR_DEFINE_STATIC_LOCAL(WebString
, kAttributeAcceptsTouch
, ("accepts-touch"));
160 const CR_DEFINE_STATIC_LOCAL(WebString
, kAttributeReRequestTouchEvents
, ("re-request-touch"));
161 const CR_DEFINE_STATIC_LOCAL(WebString
, kAttributePrintEventDetails
, ("print-event-details"));
162 const CR_DEFINE_STATIC_LOCAL(WebString
, kAttributeCanProcessDrag
, ("can-process-drag"));
163 const CR_DEFINE_STATIC_LOCAL(WebString
, kAttributePrintUserGestureStatus
, ("print-user-gesture-status"));
165 DCHECK_EQ(params
.attributeNames
.size(), params
.attributeValues
.size());
166 size_t size
= params
.attributeNames
.size();
167 for (size_t i
= 0; i
< size
; ++i
) {
168 const WebString
& attributeName
= params
.attributeNames
[i
];
169 const WebString
& attributeValue
= params
.attributeValues
[i
];
171 if (attributeName
== kAttributePrimitive
)
172 m_scene
.primitive
= parsePrimitive(attributeValue
);
173 else if (attributeName
== kAttributeBackgroundColor
)
174 parseColor(attributeValue
, m_scene
.backgroundColor
);
175 else if (attributeName
== kAttributePrimitiveColor
)
176 parseColor(attributeValue
, m_scene
.primitiveColor
);
177 else if (attributeName
== kAttributeOpacity
)
178 m_scene
.opacity
= parseOpacity(attributeValue
);
179 else if (attributeName
== kAttributeAcceptsTouch
)
180 m_touchEventRequest
= parseTouchEventRequestType(attributeValue
);
181 else if (attributeName
== kAttributeReRequestTouchEvents
)
182 m_reRequestTouchEvents
= parseBoolean(attributeValue
);
183 else if (attributeName
== kAttributePrintEventDetails
)
184 m_printEventDetails
= parseBoolean(attributeValue
);
185 else if (attributeName
== kAttributeCanProcessDrag
)
186 m_canProcessDrag
= parseBoolean(attributeValue
);
187 else if (attributeName
== kAttributePrintUserGestureStatus
)
188 m_printUserGestureStatus
= parseBoolean(attributeValue
);
190 if (m_canCreateWithoutRenderer
)
191 m_delegate
->printMessage(std::string("TestPlugin: canCreateWithoutRenderer\n"));
194 TestPlugin::~TestPlugin()
198 bool TestPlugin::initialize(WebPluginContainer
* container
)
200 WebGraphicsContext3D::Attributes attrs
;
201 m_context
= Platform::current()->createOffscreenGraphicsContext3D(attrs
);
202 if (m_context
&& !m_context
->makeContextCurrent()) {
210 m_layer
= cc::TextureLayer::CreateForMailbox(this);
211 m_webLayer
= make_scoped_ptr(new webkit::WebLayerImpl(m_layer
));
212 m_container
= container
;
213 m_container
->setWebLayer(m_webLayer
.get());
214 if (m_reRequestTouchEvents
) {
215 m_container
->requestTouchEventType(WebPluginContainer::TouchEventRequestTypeSynthesizedMouse
);
216 m_container
->requestTouchEventType(WebPluginContainer::TouchEventRequestTypeRaw
);
218 m_container
->requestTouchEventType(m_touchEventRequest
);
219 m_container
->setWantsWheelEvents(true);
223 void TestPlugin::destroy()
226 m_layer
->ClearTexture();
228 m_container
->setWebLayer(0);
239 Platform::current()->callOnMainThread(deferredDelete
, this);
242 NPObject
* TestPlugin::scriptableObject()
247 bool TestPlugin::canProcessDrag() const
249 return m_canProcessDrag
;
252 void TestPlugin::updateGeometry(const WebRect
& frameRect
, const WebRect
& clipRect
, const WebVector
<WebRect
>& cutOutsRects
, bool isVisible
)
254 if (clipRect
== m_rect
)
258 if (m_rect
.isEmpty()) {
259 m_textureMailbox
= cc::TextureMailbox();
260 } else if (m_context
) {
261 m_context
->viewport(0, 0, m_rect
.width
, m_rect
.height
);
263 m_context
->bindTexture(GL_TEXTURE_2D
, m_colorTexture
);
264 m_context
->texParameteri(
265 GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
266 m_context
->texParameteri(
267 GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
268 m_context
->texParameteri(
269 GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
270 m_context
->texParameteri(
271 GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
272 m_context
->texImage2D(GL_TEXTURE_2D
,
281 m_context
->bindFramebuffer(GL_FRAMEBUFFER
, m_framebuffer
);
282 m_context
->framebufferTexture2D(GL_FRAMEBUFFER
,
283 GL_COLOR_ATTACHMENT0
,
290 gpu::Mailbox mailbox
;
291 m_context
->genMailboxCHROMIUM(mailbox
.name
);
292 m_context
->produceTextureCHROMIUM(GL_TEXTURE_2D
, mailbox
.name
);
294 uint32 syncPoint
= m_context
->insertSyncPoint();
295 m_textureMailbox
= cc::TextureMailbox(mailbox
, GL_TEXTURE_2D
, syncPoint
);
297 size_t bytes
= 4 * m_rect
.width
* m_rect
.height
;
298 scoped_ptr
<base::SharedMemory
> bitmap
=
299 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(bytes
);
300 if (!bitmap
->Map(bytes
)) {
301 m_textureMailbox
= cc::TextureMailbox();
303 drawSceneSoftware(bitmap
->memory(), bytes
);
304 m_textureMailbox
= cc::TextureMailbox(
305 bitmap
.get(), gfx::Size(m_rect
.width
, m_rect
.height
));
306 m_sharedBitmap
= bitmap
.Pass();
310 m_mailboxChanged
= true;
311 m_layer
->SetNeedsDisplay();
314 bool TestPlugin::acceptsInputEvents()
319 bool TestPlugin::isPlaceholder()
324 static void ignoreReleaseCallback(uint32 sync_point
, bool lost
) {}
326 static void releaseSharedMemory(scoped_ptr
<base::SharedMemory
> bitmap
,
330 bool TestPlugin::PrepareTextureMailbox(
331 cc::TextureMailbox
* mailbox
,
332 scoped_ptr
<cc::SingleReleaseCallback
>* releaseCallback
,
333 bool useSharedMemory
) {
334 if (!m_mailboxChanged
)
336 *mailbox
= m_textureMailbox
;
337 if (m_textureMailbox
.IsTexture()) {
339 cc::SingleReleaseCallback::Create(base::Bind(&ignoreReleaseCallback
));
341 *releaseCallback
= cc::SingleReleaseCallback::Create(
342 base::Bind(&releaseSharedMemory
, base::Passed(&m_sharedBitmap
)));
344 m_mailboxChanged
= false;
348 TestPlugin::Primitive
TestPlugin::parsePrimitive(const WebString
& string
)
350 const CR_DEFINE_STATIC_LOCAL(WebString
, kPrimitiveNone
, ("none"));
351 const CR_DEFINE_STATIC_LOCAL(WebString
, kPrimitiveTriangle
, ("triangle"));
353 Primitive primitive
= PrimitiveNone
;
354 if (string
== kPrimitiveNone
)
355 primitive
= PrimitiveNone
;
356 else if (string
== kPrimitiveTriangle
)
357 primitive
= PrimitiveTriangle
;
363 // FIXME: This method should already exist. Use it.
364 // For now just parse primary colors.
365 void TestPlugin::parseColor(const WebString
& string
, unsigned color
[3])
367 color
[0] = color
[1] = color
[2] = 0;
368 if (string
== "black")
373 else if (string
== "green")
375 else if (string
== "blue")
381 float TestPlugin::parseOpacity(const WebString
& string
)
383 return static_cast<float>(atof(string
.utf8().data()));
386 bool TestPlugin::parseBoolean(const WebString
& string
)
388 const CR_DEFINE_STATIC_LOCAL(WebString
, kPrimitiveTrue
, ("true"));
389 return string
== kPrimitiveTrue
;
392 bool TestPlugin::initScene()
398 premultiplyAlpha(m_scene
.backgroundColor
, m_scene
.opacity
, color
);
400 m_colorTexture
= m_context
->createTexture();
401 m_framebuffer
= m_context
->createFramebuffer();
403 m_context
->viewport(0, 0, m_rect
.width
, m_rect
.height
);
404 m_context
->disable(GL_DEPTH_TEST
);
405 m_context
->disable(GL_SCISSOR_TEST
);
407 m_context
->clearColor(color
[0], color
[1], color
[2], color
[3]);
409 m_context
->enable(GL_BLEND
);
410 m_context
->blendFunc(GL_ONE
, GL_ONE_MINUS_SRC_ALPHA
);
412 return m_scene
.primitive
!= PrimitiveNone
? initProgram() && initPrimitive() : true;
415 void TestPlugin::drawSceneGL() {
416 m_context
->viewport(0, 0, m_rect
.width
, m_rect
.height
);
417 m_context
->clear(GL_COLOR_BUFFER_BIT
);
419 if (m_scene
.primitive
!= PrimitiveNone
)
423 void TestPlugin::drawSceneSoftware(void* memory
, size_t bytes
) {
424 DCHECK_EQ(bytes
, m_rect
.width
* m_rect
.height
* 4u);
426 SkColor backgroundColor
=
427 SkColorSetARGB(static_cast<uint8
>(m_scene
.opacity
* 255),
428 m_scene
.backgroundColor
[0],
429 m_scene
.backgroundColor
[1],
430 m_scene
.backgroundColor
[2]);
433 bitmap
.setConfig(SkBitmap::kARGB_8888_Config
, m_rect
.width
, m_rect
.height
);
434 bitmap
.setPixels(memory
);
435 SkCanvas
canvas(bitmap
);
436 canvas
.clear(backgroundColor
);
438 if (m_scene
.primitive
!= PrimitiveNone
) {
439 DCHECK_EQ(PrimitiveTriangle
, m_scene
.primitive
);
440 SkColor foregroundColor
=
441 SkColorSetARGB(static_cast<uint8
>(m_scene
.opacity
* 255),
442 m_scene
.primitiveColor
[0],
443 m_scene
.primitiveColor
[1],
444 m_scene
.primitiveColor
[2]);
446 trianglePath
.moveTo(0.5f
* m_rect
.width
, 0.9f
* m_rect
.height
);
447 trianglePath
.lineTo(0.1f
* m_rect
.width
, 0.1f
* m_rect
.height
);
448 trianglePath
.lineTo(0.9f
* m_rect
.width
, 0.1f
* m_rect
.height
);
450 paint
.setColor(foregroundColor
);
451 paint
.setStyle(SkPaint::kFill_Style
);
452 canvas
.drawPath(trianglePath
, paint
);
456 void TestPlugin::destroyScene()
458 if (m_scene
.program
) {
459 m_context
->deleteProgram(m_scene
.program
);
463 m_context
->deleteBuffer(m_scene
.vbo
);
468 m_context
->deleteFramebuffer(m_framebuffer
);
472 if (m_colorTexture
) {
473 m_context
->deleteTexture(m_colorTexture
);
478 bool TestPlugin::initProgram()
480 const string
vertexSource(
481 "attribute vec4 position; \n"
483 " gl_Position = position; \n"
487 const string
fragmentSource(
488 "precision mediump float; \n"
489 "uniform vec4 color; \n"
491 " gl_FragColor = color; \n"
495 m_scene
.program
= loadProgram(vertexSource
, fragmentSource
);
496 if (!m_scene
.program
)
499 m_scene
.colorLocation
= m_context
->getUniformLocation(m_scene
.program
, "color");
500 m_scene
.positionLocation
= m_context
->getAttribLocation(m_scene
.program
, "position");
504 bool TestPlugin::initPrimitive()
506 DCHECK_EQ(m_scene
.primitive
, PrimitiveTriangle
);
508 m_scene
.vbo
= m_context
->createBuffer();
512 const float vertices
[] = {
516 m_context
->bindBuffer(GL_ARRAY_BUFFER
, m_scene
.vbo
);
517 m_context
->bufferData(GL_ARRAY_BUFFER
, sizeof(vertices
), 0, GL_STATIC_DRAW
);
518 m_context
->bufferSubData(GL_ARRAY_BUFFER
, 0, sizeof(vertices
), vertices
);
522 void TestPlugin::drawPrimitive()
524 DCHECK_EQ(m_scene
.primitive
, PrimitiveTriangle
);
526 DCHECK(m_scene
.program
);
528 m_context
->useProgram(m_scene
.program
);
530 // Bind primitive color.
532 premultiplyAlpha(m_scene
.primitiveColor
, m_scene
.opacity
, color
);
533 m_context
->uniform4f(m_scene
.colorLocation
, color
[0], color
[1], color
[2], color
[3]);
535 // Bind primitive vertices.
536 m_context
->bindBuffer(GL_ARRAY_BUFFER
, m_scene
.vbo
);
537 m_context
->enableVertexAttribArray(m_scene
.positionLocation
);
538 m_context
->vertexAttribPointer(m_scene
.positionLocation
, 3, GL_FLOAT
, GL_FALSE
, 0, 0);
539 m_context
->drawArrays(GL_TRIANGLES
, 0, 3);
542 unsigned TestPlugin::loadShader(unsigned type
, const string
& source
)
544 unsigned shader
= m_context
->createShader(type
);
546 m_context
->shaderSource(shader
, source
.data());
547 m_context
->compileShader(shader
);
550 m_context
->getShaderiv(shader
, GL_COMPILE_STATUS
, &compiled
);
552 m_context
->deleteShader(shader
);
559 unsigned TestPlugin::loadProgram(const string
& vertexSource
, const string
& fragmentSource
)
561 unsigned vertexShader
= loadShader(GL_VERTEX_SHADER
, vertexSource
);
562 unsigned fragmentShader
= loadShader(GL_FRAGMENT_SHADER
, fragmentSource
);
563 unsigned program
= m_context
->createProgram();
564 if (vertexShader
&& fragmentShader
&& program
) {
565 m_context
->attachShader(program
, vertexShader
);
566 m_context
->attachShader(program
, fragmentShader
);
567 m_context
->linkProgram(program
);
570 m_context
->getProgramiv(program
, GL_LINK_STATUS
, &linked
);
572 m_context
->deleteProgram(program
);
577 m_context
->deleteShader(vertexShader
);
579 m_context
->deleteShader(fragmentShader
);
584 bool TestPlugin::handleInputEvent(const WebInputEvent
& event
, WebCursorInfo
& info
)
586 const char* eventName
= 0;
587 switch (event
.type
) {
588 case WebInputEvent::Undefined
: eventName
= "unknown"; break;
590 case WebInputEvent::MouseDown
: eventName
= "MouseDown"; break;
591 case WebInputEvent::MouseUp
: eventName
= "MouseUp"; break;
592 case WebInputEvent::MouseMove
: eventName
= "MouseMove"; break;
593 case WebInputEvent::MouseEnter
: eventName
= "MouseEnter"; break;
594 case WebInputEvent::MouseLeave
: eventName
= "MouseLeave"; break;
595 case WebInputEvent::ContextMenu
: eventName
= "ContextMenu"; break;
597 case WebInputEvent::MouseWheel
: eventName
= "MouseWheel"; break;
599 case WebInputEvent::RawKeyDown
: eventName
= "RawKeyDown"; break;
600 case WebInputEvent::KeyDown
: eventName
= "KeyDown"; break;
601 case WebInputEvent::KeyUp
: eventName
= "KeyUp"; break;
602 case WebInputEvent::Char
: eventName
= "Char"; break;
604 case WebInputEvent::GestureScrollBegin
: eventName
= "GestureScrollBegin"; break;
605 case WebInputEvent::GestureScrollEnd
: eventName
= "GestureScrollEnd"; break;
606 case WebInputEvent::GestureScrollUpdateWithoutPropagation
:
607 case WebInputEvent::GestureScrollUpdate
: eventName
= "GestureScrollUpdate"; break;
608 case WebInputEvent::GestureFlingStart
: eventName
= "GestureFlingStart"; break;
609 case WebInputEvent::GestureFlingCancel
: eventName
= "GestureFlingCancel"; break;
610 case WebInputEvent::GestureTap
: eventName
= "GestureTap"; break;
611 case WebInputEvent::GestureTapUnconfirmed
:
612 eventName
= "GestureTapUnconfirmed"; break;
613 case WebInputEvent::GestureTapDown
: eventName
= "GestureTapDown"; break;
614 case WebInputEvent::GestureShowPress
: eventName
= "GestureShowPress"; break;
615 case WebInputEvent::GestureTapCancel
: eventName
= "GestureTapCancel"; break;
616 case WebInputEvent::GestureDoubleTap
: eventName
= "GestureDoubleTap"; break;
617 case WebInputEvent::GestureTwoFingerTap
: eventName
= "GestureTwoFingerTap"; break;
618 case WebInputEvent::GestureLongPress
: eventName
= "GestureLongPress"; break;
619 case WebInputEvent::GestureLongTap
: eventName
= "GestureLongTap"; break;
620 case WebInputEvent::GesturePinchBegin
: eventName
= "GesturePinchBegin"; break;
621 case WebInputEvent::GesturePinchEnd
: eventName
= "GesturePinchEnd"; break;
622 case WebInputEvent::GesturePinchUpdate
: eventName
= "GesturePinchUpdate"; break;
624 case WebInputEvent::TouchStart
: eventName
= "TouchStart"; break;
625 case WebInputEvent::TouchMove
: eventName
= "TouchMove"; break;
626 case WebInputEvent::TouchEnd
: eventName
= "TouchEnd"; break;
627 case WebInputEvent::TouchCancel
: eventName
= "TouchCancel"; break;
630 m_delegate
->printMessage(std::string("Plugin received event: ") + (eventName
? eventName
: "unknown") + "\n");
631 if (m_printEventDetails
)
632 printEventDetails(m_delegate
, event
);
633 if (m_printUserGestureStatus
)
634 m_delegate
->printMessage(std::string("* ") + (WebUserGestureIndicator::isProcessingUserGesture() ? "" : "not ") + "handling user gesture\n");
636 m_delegate
->printMessage(std::string("TestPlugin: isPersistent\n"));
640 bool TestPlugin::handleDragStatusUpdate(WebDragStatus dragStatus
, const WebDragData
&, WebDragOperationsMask
, const WebPoint
& position
, const WebPoint
& screenPosition
)
642 const char* dragStatusName
= 0;
643 switch (dragStatus
) {
644 case WebDragStatusEnter
:
645 dragStatusName
= "DragEnter";
647 case WebDragStatusOver
:
648 dragStatusName
= "DragOver";
650 case WebDragStatusLeave
:
651 dragStatusName
= "DragLeave";
653 case WebDragStatusDrop
:
654 dragStatusName
= "DragDrop";
656 case WebDragStatusUnknown
:
659 m_delegate
->printMessage(std::string("Plugin received event: ") + dragStatusName
+ "\n");
663 TestPlugin
* TestPlugin::create(WebFrame
* frame
, const WebPluginParams
& params
, WebTestDelegate
* delegate
)
665 return new TestPlugin(frame
, params
, delegate
);
668 const WebString
& TestPlugin::mimeType()
670 const CR_DEFINE_STATIC_LOCAL(WebString
, kMimeType
, ("application/x-webkit-test-webplugin"));
674 const WebString
& TestPlugin::canCreateWithoutRendererMimeType()
676 const CR_DEFINE_STATIC_LOCAL(WebString
, kCanCreateWithoutRendererMimeType
, ("application/x-webkit-test-webplugin-can-create-without-renderer"));
677 return kCanCreateWithoutRendererMimeType
;
680 const WebString
& TestPlugin::pluginPersistsMimeType()
682 const CR_DEFINE_STATIC_LOCAL(WebString
, kPluginPersistsMimeType
, ("application/x-webkit-test-webplugin-persistent"));
683 return kPluginPersistsMimeType
;
686 bool TestPlugin::isSupportedMimeType(const WebString
& mimeType
)
688 return mimeType
== TestPlugin::mimeType()
689 || mimeType
== pluginPersistsMimeType()
690 || mimeType
== canCreateWithoutRendererMimeType();