This cl is required by https://codereview.chromium.org/23618022/ to provide
[chromium-blink-merge.git] / content / shell / renderer / test_runner / TestPlugin.h
blobc573b6f38898231817417f52c4aaec67b8e2ca23
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_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "third_party/WebKit/public/platform/WebExternalTextureLayer.h"
13 #include "third_party/WebKit/public/platform/WebExternalTextureLayerClient.h"
14 #include "third_party/WebKit/public/platform/WebExternalTextureMailbox.h"
15 #include "third_party/WebKit/public/web/WebPlugin.h"
16 #include "third_party/WebKit/public/web/WebPluginContainer.h"
18 namespace WebTestRunner {
20 class WebTestDelegate;
22 // A fake implemention of blink::WebPlugin for testing purposes.
24 // It uses WebGraphicsContext3D to paint a scene consisiting of a primitive
25 // over a background. The primitive and background can be customized using
26 // the following plugin parameters:
27 // primitive: none (default), triangle.
28 // background-color: black (default), red, green, blue.
29 // primitive-color: black (default), red, green, blue.
30 // opacity: [0.0 - 1.0]. Default is 1.0.
32 // Whether the plugin accepts touch events or not can be customized using the
33 // 'accepts-touch' plugin parameter (defaults to false).
34 class TestPlugin : public blink::WebPlugin, public blink::WebExternalTextureLayerClient {
35 public:
36 static TestPlugin* create(blink::WebFrame*, const blink::WebPluginParams&, WebTestDelegate*);
37 virtual ~TestPlugin();
39 static const blink::WebString& mimeType();
40 static const blink::WebString& canCreateWithoutRendererMimeType();
41 static const blink::WebString& pluginPersistsMimeType();
42 static bool isSupportedMimeType(const blink::WebString& mimeType);
44 // WebPlugin methods:
45 virtual bool initialize(blink::WebPluginContainer*);
46 virtual void destroy();
47 virtual NPObject* scriptableObject();
48 virtual bool canProcessDrag() const;
49 virtual void paint(blink::WebCanvas*, const blink::WebRect&) { }
50 virtual void updateGeometry(const blink::WebRect& frameRect, const blink::WebRect& clipRect, const blink::WebVector<blink::WebRect>& cutOutsRects, bool isVisible);
51 virtual void updateFocus(bool) { }
52 virtual void updateVisibility(bool) { }
53 virtual bool acceptsInputEvents();
54 virtual bool handleInputEvent(const blink::WebInputEvent&, blink::WebCursorInfo&);
55 virtual bool handleDragStatusUpdate(blink::WebDragStatus, const blink::WebDragData&, blink::WebDragOperationsMask, const blink::WebPoint& position, const blink::WebPoint& screenPosition);
56 virtual void didReceiveResponse(const blink::WebURLResponse&) { }
57 virtual void didReceiveData(const char* data, int dataLength) { }
58 virtual void didFinishLoading() { }
59 virtual void didFailLoading(const blink::WebURLError&) { }
60 virtual void didFinishLoadingFrameRequest(const blink::WebURL&, void* notifyData) { }
61 virtual void didFailLoadingFrameRequest(const blink::WebURL&, void* notifyData, const blink::WebURLError&) { }
62 virtual bool isPlaceholder();
64 // WebExternalTextureLayerClient methods:
65 virtual blink::WebGraphicsContext3D* context();
66 virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExternalBitmap*);
67 virtual void mailboxReleased(const blink::WebExternalTextureMailbox&);
69 private:
70 TestPlugin(blink::WebFrame*, const blink::WebPluginParams&, WebTestDelegate*);
72 enum Primitive {
73 PrimitiveNone,
74 PrimitiveTriangle
77 struct Scene {
78 Primitive primitive;
79 unsigned backgroundColor[3];
80 unsigned primitiveColor[3];
81 float opacity;
83 unsigned vbo;
84 unsigned program;
85 int colorLocation;
86 int positionLocation;
88 Scene()
89 : primitive(PrimitiveNone)
90 , opacity(1.0f) // Fully opaque.
91 , vbo(0)
92 , program(0)
93 , colorLocation(-1)
94 , positionLocation(-1)
96 backgroundColor[0] = backgroundColor[1] = backgroundColor[2] = 0;
97 primitiveColor[0] = primitiveColor[1] = primitiveColor[2] = 0;
101 // Functions for parsing plugin parameters.
102 Primitive parsePrimitive(const blink::WebString&);
103 void parseColor(const blink::WebString&, unsigned color[3]);
104 float parseOpacity(const blink::WebString&);
105 bool parseBoolean(const blink::WebString&);
107 // Functions for loading and drawing scene.
108 bool initScene();
109 void drawScene();
110 void destroyScene();
111 bool initProgram();
112 bool initPrimitive();
113 void drawPrimitive();
114 unsigned loadShader(unsigned type, const std::string& source);
115 unsigned loadProgram(const std::string& vertexSource, const std::string& fragmentSource);
117 blink::WebFrame* m_frame;
118 WebTestDelegate* m_delegate;
119 blink::WebPluginContainer* m_container;
121 blink::WebRect m_rect;
122 blink::WebGraphicsContext3D* m_context;
123 unsigned m_colorTexture;
124 blink::WebExternalTextureMailbox m_mailbox;
125 bool m_mailboxChanged;
126 unsigned m_framebuffer;
127 Scene m_scene;
128 scoped_ptr<blink::WebExternalTextureLayer> m_layer;
130 blink::WebPluginContainer::TouchEventRequestType m_touchEventRequest;
131 // Requests touch events from the WebPluginContainerImpl multiple times to tickle webkit.org/b/108381
132 bool m_reRequestTouchEvents;
133 bool m_printEventDetails;
134 bool m_printUserGestureStatus;
135 bool m_canProcessDrag;
137 bool m_isPersistent;
138 bool m_canCreateWithoutRenderer;
140 DISALLOW_COPY_AND_ASSIGN(TestPlugin);
145 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_TESTPLUGIN_H_