• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
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.
13  *
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.
24  */
25 
26 #ifndef TestPlugin_h
27 #define TestPlugin_h
28 
29 #include "public/platform/WebExternalTextureLayer.h"
30 #include "public/platform/WebExternalTextureLayerClient.h"
31 #include "public/platform/WebExternalTextureMailbox.h"
32 #include "public/platform/WebNonCopyable.h"
33 #include "public/testing/WebScopedPtr.h"
34 #include "public/web/WebPlugin.h"
35 #include "public/web/WebPluginContainer.h"
36 #include <string>
37 
38 namespace WebTestRunner {
39 
40 class WebTestDelegate;
41 
42 // A fake implemention of blink::WebPlugin for testing purposes.
43 //
44 // It uses WebGraphicsContext3D to paint a scene consisiting of a primitive
45 // over a background. The primitive and background can be customized using
46 // the following plugin parameters:
47 // primitive: none (default), triangle.
48 // background-color: black (default), red, green, blue.
49 // primitive-color: black (default), red, green, blue.
50 // opacity: [0.0 - 1.0]. Default is 1.0.
51 //
52 // Whether the plugin accepts touch events or not can be customized using the
53 // 'accepts-touch' plugin parameter (defaults to false).
54 class TestPlugin : public blink::WebPlugin, public blink::WebExternalTextureLayerClient, public blink::WebNonCopyable {
55 public:
56     static TestPlugin* create(blink::WebFrame*, const blink::WebPluginParams&, WebTestDelegate*);
57     virtual ~TestPlugin();
58 
59     static const blink::WebString& mimeType();
60 
61     // WebPlugin methods:
62     virtual bool initialize(blink::WebPluginContainer*);
63     virtual void destroy();
scriptableObject()64     virtual NPObject* scriptableObject() { return 0; }
canProcessDrag()65     virtual bool canProcessDrag() const { return m_canProcessDrag; }
paint(blink::WebCanvas *,const blink::WebRect &)66     virtual void paint(blink::WebCanvas*, const blink::WebRect&) { }
67     virtual void updateGeometry(const blink::WebRect& frameRect, const blink::WebRect& clipRect, const blink::WebVector<blink::WebRect>& cutOutsRects, bool isVisible);
updateFocus(bool)68     virtual void updateFocus(bool) { }
updateVisibility(bool)69     virtual void updateVisibility(bool) { }
acceptsInputEvents()70     virtual bool acceptsInputEvents() { return true; }
71     virtual bool handleInputEvent(const blink::WebInputEvent&, blink::WebCursorInfo&);
72     virtual bool handleDragStatusUpdate(blink::WebDragStatus, const blink::WebDragData&, blink::WebDragOperationsMask, const blink::WebPoint& position, const blink::WebPoint& screenPosition);
didReceiveResponse(const blink::WebURLResponse &)73     virtual void didReceiveResponse(const blink::WebURLResponse&) { }
didReceiveData(const char * data,int dataLength)74     virtual void didReceiveData(const char* data, int dataLength) { }
didFinishLoading()75     virtual void didFinishLoading() { }
didFailLoading(const blink::WebURLError &)76     virtual void didFailLoading(const blink::WebURLError&) { }
didFinishLoadingFrameRequest(const blink::WebURL &,void * notifyData)77     virtual void didFinishLoadingFrameRequest(const blink::WebURL&, void* notifyData) { }
didFailLoadingFrameRequest(const blink::WebURL &,void * notifyData,const blink::WebURLError &)78     virtual void didFailLoadingFrameRequest(const blink::WebURL&, void* notifyData, const blink::WebURLError&) { }
isPlaceholder()79     virtual bool isPlaceholder() { return false; }
80 
81     // WebExternalTextureLayerClient methods:
context()82     virtual blink::WebGraphicsContext3D* context() { return 0; }
83     virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExternalBitmap*);
84     virtual void mailboxReleased(const blink::WebExternalTextureMailbox&);
85 
86 private:
87     TestPlugin(blink::WebFrame*, const blink::WebPluginParams&, WebTestDelegate*);
88 
89     enum Primitive {
90         PrimitiveNone,
91         PrimitiveTriangle
92     };
93 
94     struct Scene {
95         Primitive primitive;
96         unsigned backgroundColor[3];
97         unsigned primitiveColor[3];
98         float opacity;
99 
100         unsigned vbo;
101         unsigned program;
102         int colorLocation;
103         int positionLocation;
104 
SceneScene105         Scene()
106             : primitive(PrimitiveNone)
107             , opacity(1.0f) // Fully opaque.
108             , vbo(0)
109             , program(0)
110             , colorLocation(-1)
111             , positionLocation(-1)
112         {
113             backgroundColor[0] = backgroundColor[1] = backgroundColor[2] = 0;
114             primitiveColor[0] = primitiveColor[1] = primitiveColor[2] = 0;
115         }
116     };
117 
118     // Functions for parsing plugin parameters.
119     Primitive parsePrimitive(const blink::WebString&);
120     void parseColor(const blink::WebString&, unsigned color[3]);
121     float parseOpacity(const blink::WebString&);
122     bool parseBoolean(const blink::WebString&);
123 
124     // Functions for loading and drawing scene.
125     bool initScene();
126     void drawScene();
127     void destroyScene();
128     bool initProgram();
129     bool initPrimitive();
130     void drawPrimitive();
131     unsigned loadShader(unsigned type, const std::string& source);
132     unsigned loadProgram(const std::string& vertexSource, const std::string& fragmentSource);
133 
134     blink::WebFrame* m_frame;
135     WebTestDelegate* m_delegate;
136     blink::WebPluginContainer* m_container;
137 
138     blink::WebRect m_rect;
139     blink::WebGraphicsContext3D* m_context;
140     unsigned m_colorTexture;
141     blink::WebExternalTextureMailbox m_mailbox;
142     bool m_mailboxChanged;
143     unsigned m_framebuffer;
144     Scene m_scene;
145     WebScopedPtr<blink::WebExternalTextureLayer> m_layer;
146 
147     blink::WebPluginContainer::TouchEventRequestType m_touchEventRequest;
148     // Requests touch events from the WebPluginContainerImpl multiple times to tickle webkit.org/b/108381
149     bool m_reRequestTouchEvents;
150     bool m_printEventDetails;
151     bool m_printUserGestureStatus;
152     bool m_canProcessDrag;
153 };
154 
155 }
156 
157 #endif // TestPlugin_h
158