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 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_TESTPLUGIN_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_TESTPLUGIN_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "cc/layers/texture_layer.h"
13 #include "cc/layers/texture_layer_client.h"
14 #include "third_party/WebKit/public/platform/WebExternalTextureLayer.h"
15 #include "third_party/WebKit/public/platform/WebExternalTextureLayerClient.h"
16 #include "third_party/WebKit/public/platform/WebExternalTextureMailbox.h"
17 #include "third_party/WebKit/public/web/WebPlugin.h"
18 #include "third_party/WebKit/public/web/WebPluginContainer.h"
19 #include "webkit/renderer/compositor_bindings/web_layer_impl.h"
25 namespace WebTestRunner
{
27 class WebTestDelegate
;
29 // A fake implemention of blink::WebPlugin for testing purposes.
31 // It uses WebGraphicsContext3D to paint a scene consisiting of a primitive
32 // over a background. The primitive and background can be customized using
33 // the following plugin parameters:
34 // primitive: none (default), triangle.
35 // background-color: black (default), red, green, blue.
36 // primitive-color: black (default), red, green, blue.
37 // opacity: [0.0 - 1.0]. Default is 1.0.
39 // Whether the plugin accepts touch events or not can be customized using the
40 // 'accepts-touch' plugin parameter (defaults to false).
41 class TestPlugin
: public blink::WebPlugin
, public cc::TextureLayerClient
{
43 static TestPlugin
* create(blink::WebFrame
*, const blink::WebPluginParams
&, WebTestDelegate
*);
44 virtual ~TestPlugin();
46 static const blink::WebString
& mimeType();
47 static const blink::WebString
& canCreateWithoutRendererMimeType();
48 static const blink::WebString
& pluginPersistsMimeType();
49 static bool isSupportedMimeType(const blink::WebString
& mimeType
);
52 virtual bool initialize(blink::WebPluginContainer
*);
53 virtual void destroy();
54 virtual NPObject
* scriptableObject();
55 virtual bool canProcessDrag() const;
56 virtual void paint(blink::WebCanvas
*, const blink::WebRect
&) { }
57 virtual void updateGeometry(const blink::WebRect
& frameRect
, const blink::WebRect
& clipRect
, const blink::WebVector
<blink::WebRect
>& cutOutsRects
, bool isVisible
);
58 virtual void updateFocus(bool) { }
59 virtual void updateVisibility(bool) { }
60 virtual bool acceptsInputEvents();
61 virtual bool handleInputEvent(const blink::WebInputEvent
&, blink::WebCursorInfo
&);
62 virtual bool handleDragStatusUpdate(blink::WebDragStatus
, const blink::WebDragData
&, blink::WebDragOperationsMask
, const blink::WebPoint
& position
, const blink::WebPoint
& screenPosition
);
63 virtual void didReceiveResponse(const blink::WebURLResponse
&) { }
64 virtual void didReceiveData(const char* data
, int dataLength
) { }
65 virtual void didFinishLoading() { }
66 virtual void didFailLoading(const blink::WebURLError
&) { }
67 virtual void didFinishLoadingFrameRequest(const blink::WebURL
&, void* notifyData
) { }
68 virtual void didFailLoadingFrameRequest(const blink::WebURL
&, void* notifyData
, const blink::WebURLError
&) { }
69 virtual bool isPlaceholder();
71 // cc::TextureLayerClient methods:
72 virtual bool PrepareTextureMailbox(
73 cc::TextureMailbox
* mailbox
,
74 scoped_ptr
<cc::SingleReleaseCallback
>* releaseCallback
,
75 bool useSharedMemory
) OVERRIDE
;
78 TestPlugin(blink::WebFrame
*, const blink::WebPluginParams
&, WebTestDelegate
*);
87 unsigned backgroundColor
[3];
88 unsigned primitiveColor
[3];
97 : primitive(PrimitiveNone
)
98 , opacity(1.0f
) // Fully opaque.
102 , positionLocation(-1)
104 backgroundColor
[0] = backgroundColor
[1] = backgroundColor
[2] = 0;
105 primitiveColor
[0] = primitiveColor
[1] = primitiveColor
[2] = 0;
109 // Functions for parsing plugin parameters.
110 Primitive
parsePrimitive(const blink::WebString
&);
111 void parseColor(const blink::WebString
&, unsigned color
[3]);
112 float parseOpacity(const blink::WebString
&);
113 bool parseBoolean(const blink::WebString
&);
115 // Functions for loading and drawing scene in GL.
120 bool initPrimitive();
121 void drawPrimitive();
122 unsigned loadShader(unsigned type
, const std::string
& source
);
123 unsigned loadProgram(const std::string
& vertexSource
, const std::string
& fragmentSource
);
125 // Functions for drawing scene in Software.
126 void drawSceneSoftware(void* memory
, size_t bytes
);
128 blink::WebFrame
* m_frame
;
129 WebTestDelegate
* m_delegate
;
130 blink::WebPluginContainer
* m_container
;
132 blink::WebRect m_rect
;
133 blink::WebGraphicsContext3D
* m_context
;
134 unsigned m_colorTexture
;
135 cc::TextureMailbox m_textureMailbox
;
136 scoped_ptr
<base::SharedMemory
> m_sharedBitmap
;
137 bool m_mailboxChanged
;
138 unsigned m_framebuffer
;
140 scoped_refptr
<cc::TextureLayer
> m_layer
;
141 scoped_ptr
<webkit::WebLayerImpl
> m_webLayer
;
143 blink::WebPluginContainer::TouchEventRequestType m_touchEventRequest
;
144 // Requests touch events from the WebPluginContainerImpl multiple times to tickle webkit.org/b/108381
145 bool m_reRequestTouchEvents
;
146 bool m_printEventDetails
;
147 bool m_printUserGestureStatus
;
148 bool m_canProcessDrag
;
151 bool m_canCreateWithoutRenderer
;
153 DISALLOW_COPY_AND_ASSIGN(TestPlugin
);
158 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_TESTPLUGIN_H_