2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef TestWebPlugin_h
27 #define TestWebPlugin_h
29 #include "WebPlugin.h"
33 class WebGraphicsContext3D;
36 // A fake implemention of WebKit::WebPlugin for testing purposes.
38 // It uses WebGraphicsContext3D to paint a scene consisiting of a primitive
39 // over a background. The primitive and background can be customized using
40 // the following plugin parameters:
41 // primitive: none (default), triangle.
42 // background-color: black (default), red, green, blue.
43 // primitive-color: black (default), red, green, blue.
44 // opacity: [0.0 - 1.0]. Default is 1.0.
45 class TestWebPlugin : public WebKit::WebPlugin {
47 TestWebPlugin(WebKit::WebFrame*, const WebKit::WebPluginParams&);
48 virtual ~TestWebPlugin();
50 static const WebKit::WebString& mimeType();
53 virtual bool initialize(WebKit::WebPluginContainer*);
54 virtual void destroy();
55 virtual NPObject* scriptableObject() { return 0; }
56 virtual void paint(WebKit::WebCanvas*, const WebKit::WebRect&) { }
57 virtual void updateGeometry(const WebKit::WebRect& frameRect,
58 const WebKit::WebRect& clipRect,
59 const WebKit::WebVector<WebKit::WebRect>& cutOutsRects,
61 virtual void updateFocus(bool) { }
62 virtual void updateVisibility(bool) { }
63 virtual bool acceptsInputEvents() { return false; }
64 virtual bool handleInputEvent(const WebKit::WebInputEvent&, WebKit::WebCursorInfo&) { return false; }
65 virtual void didReceiveResponse(const WebKit::WebURLResponse&) { }
66 virtual void didReceiveData(const char* data, int dataLength) { }
67 virtual void didFinishLoading() { }
68 virtual void didFailLoading(const WebKit::WebURLError&) { }
69 virtual void didFinishLoadingFrameRequest(const WebKit::WebURL&, void* notifyData) { }
70 virtual void didFailLoadingFrameRequest(const WebKit::WebURL&, void* notifyData, const WebKit::WebURLError&) { }
80 unsigned backgroundColor[3];
81 unsigned primitiveColor[3];
90 : primitive(PrimitiveNone)
91 , opacity(1.0f) // Fully opaque.
95 , positionLocation(-1)
97 backgroundColor[0] = backgroundColor[1] = backgroundColor[2] = 0;
98 primitiveColor[0] = primitiveColor[1] = primitiveColor[2] = 0;
102 // Functions for parsing plugin parameters.
103 Primitive parsePrimitive(const WebKit::WebString&);
104 void parseColor(const WebKit::WebString&, unsigned color[3]);
105 float parseOpacity(const WebKit::WebString&);
107 // Functions for loading and drawing scene.
112 bool initPrimitive();
113 void drawPrimitive();
114 unsigned loadShader(unsigned type, const WTF::CString& source);
115 unsigned loadProgram(const WTF::CString& vertexSource,
116 const WTF::CString& fragmentSource);
118 WebKit::WebFrame* m_frame;
119 WebKit::WebPluginContainer* m_container;
121 WebKit::WebRect m_rect;
122 WebKit::WebGraphicsContext3D* m_context;
126 #endif // TestPepperPlugin_h