| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 /* |
| 6 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 7 * |
| 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions |
| 10 * are met: |
| 11 * |
| 12 * 1. Redistributions of source code must retain the above copyright |
| 13 * notice, this list of conditions and the following disclaimer. |
| 14 * 2. Redistributions in binary form must reproduce the above copyright |
| 15 * notice, this list of conditions and the following disclaimer in the |
| 16 * documentation and/or other materials provided with the distribution. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ |
| 29 |
| 30 #ifndef TestPlugin_h |
| 31 #define TestPlugin_h |
| 32 |
| 33 #include <string> |
| 34 |
| 35 #include "content/public/test/layout_tests/WebScopedPtr.h" |
| 36 #include "third_party/WebKit/public/platform/WebExternalTextureLayer.h" |
| 37 #include "third_party/WebKit/public/platform/WebExternalTextureLayerClient.h" |
| 38 #include "third_party/WebKit/public/platform/WebExternalTextureMailbox.h" |
| 39 #include "third_party/WebKit/public/platform/WebNonCopyable.h" |
| 40 #include "third_party/WebKit/public/web/WebPlugin.h" |
| 41 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 42 |
| 43 namespace WebTestRunner { |
| 44 |
| 45 class WebTestDelegate; |
| 46 |
| 47 // A fake implemention of blink::WebPlugin for testing purposes. |
| 48 // |
| 49 // It uses WebGraphicsContext3D to paint a scene consisiting of a primitive |
| 50 // over a background. The primitive and background can be customized using |
| 51 // the following plugin parameters: |
| 52 // primitive: none (default), triangle. |
| 53 // background-color: black (default), red, green, blue. |
| 54 // primitive-color: black (default), red, green, blue. |
| 55 // opacity: [0.0 - 1.0]. Default is 1.0. |
| 56 // |
| 57 // Whether the plugin accepts touch events or not can be customized using the |
| 58 // 'accepts-touch' plugin parameter (defaults to false). |
| 59 class TestPlugin : public blink::WebPlugin, public blink::WebExternalTextureLaye
rClient, public blink::WebNonCopyable { |
| 60 public: |
| 61 static TestPlugin* create(blink::WebFrame*, const blink::WebPluginParams&, W
ebTestDelegate*); |
| 62 virtual ~TestPlugin(); |
| 63 |
| 64 static const blink::WebString& mimeType(); |
| 65 |
| 66 // WebPlugin methods: |
| 67 virtual bool initialize(blink::WebPluginContainer*); |
| 68 virtual void destroy(); |
| 69 virtual NPObject* scriptableObject() { return 0; } |
| 70 virtual bool canProcessDrag() const { return m_canProcessDrag; } |
| 71 virtual void paint(blink::WebCanvas*, const blink::WebRect&) { } |
| 72 virtual void updateGeometry(const blink::WebRect& frameRect, const blink::We
bRect& clipRect, const blink::WebVector<blink::WebRect>& cutOutsRects, bool isVi
sible); |
| 73 virtual void updateFocus(bool) { } |
| 74 virtual void updateVisibility(bool) { } |
| 75 virtual bool acceptsInputEvents() { return true; } |
| 76 virtual bool handleInputEvent(const blink::WebInputEvent&, blink::WebCursorI
nfo&); |
| 77 virtual bool handleDragStatusUpdate(blink::WebDragStatus, const blink::WebDr
agData&, blink::WebDragOperationsMask, const blink::WebPoint& position, const bl
ink::WebPoint& screenPosition); |
| 78 virtual void didReceiveResponse(const blink::WebURLResponse&) { } |
| 79 virtual void didReceiveData(const char* data, int dataLength) { } |
| 80 virtual void didFinishLoading() { } |
| 81 virtual void didFailLoading(const blink::WebURLError&) { } |
| 82 virtual void didFinishLoadingFrameRequest(const blink::WebURL&, void* notify
Data) { } |
| 83 virtual void didFailLoadingFrameRequest(const blink::WebURL&, void* notifyDa
ta, const blink::WebURLError&) { } |
| 84 virtual bool isPlaceholder() { return false; } |
| 85 |
| 86 // WebExternalTextureLayerClient methods: |
| 87 virtual blink::WebGraphicsContext3D* context() { return 0; } |
| 88 virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExt
ernalBitmap*); |
| 89 virtual void mailboxReleased(const blink::WebExternalTextureMailbox&); |
| 90 |
| 91 private: |
| 92 TestPlugin(blink::WebFrame*, const blink::WebPluginParams&, WebTestDelegate*
); |
| 93 |
| 94 enum Primitive { |
| 95 PrimitiveNone, |
| 96 PrimitiveTriangle |
| 97 }; |
| 98 |
| 99 struct Scene { |
| 100 Primitive primitive; |
| 101 unsigned backgroundColor[3]; |
| 102 unsigned primitiveColor[3]; |
| 103 float opacity; |
| 104 |
| 105 unsigned vbo; |
| 106 unsigned program; |
| 107 int colorLocation; |
| 108 int positionLocation; |
| 109 |
| 110 Scene() |
| 111 : primitive(PrimitiveNone) |
| 112 , opacity(1.0f) // Fully opaque. |
| 113 , vbo(0) |
| 114 , program(0) |
| 115 , colorLocation(-1) |
| 116 , positionLocation(-1) |
| 117 { |
| 118 backgroundColor[0] = backgroundColor[1] = backgroundColor[2] = 0; |
| 119 primitiveColor[0] = primitiveColor[1] = primitiveColor[2] = 0; |
| 120 } |
| 121 }; |
| 122 |
| 123 // Functions for parsing plugin parameters. |
| 124 Primitive parsePrimitive(const blink::WebString&); |
| 125 void parseColor(const blink::WebString&, unsigned color[3]); |
| 126 float parseOpacity(const blink::WebString&); |
| 127 bool parseBoolean(const blink::WebString&); |
| 128 |
| 129 // Functions for loading and drawing scene. |
| 130 bool initScene(); |
| 131 void drawScene(); |
| 132 void destroyScene(); |
| 133 bool initProgram(); |
| 134 bool initPrimitive(); |
| 135 void drawPrimitive(); |
| 136 unsigned loadShader(unsigned type, const std::string& source); |
| 137 unsigned loadProgram(const std::string& vertexSource, const std::string& fra
gmentSource); |
| 138 |
| 139 blink::WebFrame* m_frame; |
| 140 WebTestDelegate* m_delegate; |
| 141 blink::WebPluginContainer* m_container; |
| 142 |
| 143 blink::WebRect m_rect; |
| 144 blink::WebGraphicsContext3D* m_context; |
| 145 unsigned m_colorTexture; |
| 146 blink::WebExternalTextureMailbox m_mailbox; |
| 147 bool m_mailboxChanged; |
| 148 unsigned m_framebuffer; |
| 149 Scene m_scene; |
| 150 WebScopedPtr<blink::WebExternalTextureLayer> m_layer; |
| 151 |
| 152 blink::WebPluginContainer::TouchEventRequestType m_touchEventRequest; |
| 153 // Requests touch events from the WebPluginContainerImpl multiple times to t
ickle webkit.org/b/108381 |
| 154 bool m_reRequestTouchEvents; |
| 155 bool m_printEventDetails; |
| 156 bool m_printUserGestureStatus; |
| 157 bool m_canProcessDrag; |
| 158 }; |
| 159 |
| 160 } |
| 161 |
| 162 #endif // TestPlugin_h |
| OLD | NEW |