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_TEST_PLUGIN_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_TEST_PLUGIN_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 "content/public/test/layouttest_support.h"
15 #include "third_party/WebKit/public/platform/WebExternalTextureLayer.h"
16 #include "third_party/WebKit/public/platform/WebExternalTextureLayerClient.h"
17 #include "third_party/WebKit/public/platform/WebExternalTextureMailbox.h"
18 #include "third_party/WebKit/public/platform/WebLayer.h"
19 #include "third_party/WebKit/public/web/WebPlugin.h"
20 #include "third_party/WebKit/public/web/WebPluginContainer.h"
29 class WebTestDelegate;
31 // A fake implemention of blink::WebPlugin for testing purposes.
33 // It uses WebGraphicsContext3D to paint a scene consisiting of a primitive
34 // over a background. The primitive and background can be customized using
35 // the following plugin parameters:
36 // primitive: none (default), triangle.
37 // background-color: black (default), red, green, blue.
38 // primitive-color: black (default), red, green, blue.
39 // opacity: [0.0 - 1.0]. Default is 1.0.
41 // Whether the plugin accepts touch events or not can be customized using the
42 // 'accepts-touch' plugin parameter (defaults to false).
43 class TestPlugin : public blink::WebPlugin, public cc::TextureLayerClient {
45 static TestPlugin* create(blink::WebFrame* frame,
46 const blink::WebPluginParams& params,
47 WebTestDelegate* delegate);
48 ~TestPlugin() override;
50 static const blink::WebString& MimeType();
51 static const blink::WebString& CanCreateWithoutRendererMimeType();
52 static const blink::WebString& PluginPersistsMimeType();
53 static bool IsSupportedMimeType(const blink::WebString& mime_type);
56 virtual bool initialize(blink::WebPluginContainer* container);
57 virtual void destroy();
58 virtual NPObject* scriptableObject();
59 virtual bool canProcessDrag() const;
60 virtual void paint(blink::WebCanvas* canvas, const blink::WebRect& rect) {}
61 virtual void updateGeometry(
62 const blink::WebRect& frame_rect,
63 const blink::WebRect& clip_rect,
64 const blink::WebVector<blink::WebRect>& cut_outs_rects,
66 virtual void updateFocus(bool focus) {}
67 virtual void updateVisibility(bool visibility) {}
68 virtual bool acceptsInputEvents();
69 virtual bool handleInputEvent(const blink::WebInputEvent& event,
70 blink::WebCursorInfo& info);
71 virtual bool handleDragStatusUpdate(blink::WebDragStatus drag_status,
72 const blink::WebDragData& data,
73 blink::WebDragOperationsMask mask,
74 const blink::WebPoint& position,
75 const blink::WebPoint& screen_position);
76 virtual void didReceiveResponse(const blink::WebURLResponse& response) {}
77 virtual void didReceiveData(const char* data, int data_length) {}
78 virtual void didFinishLoading() {}
79 virtual void didFailLoading(const blink::WebURLError& error) {}
80 virtual void didFinishLoadingFrameRequest(const blink::WebURL& url,
82 virtual void didFailLoadingFrameRequest(const blink::WebURL& url,
84 const blink::WebURLError& error) {}
85 virtual bool isPlaceholder();
87 // cc::TextureLayerClient methods:
88 bool PrepareTextureMailbox(
89 cc::TextureMailbox* mailbox,
90 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
91 bool use_shared_memory) override;
94 TestPlugin(blink::WebFrame* frame,
95 const blink::WebPluginParams& params,
96 WebTestDelegate* delegate);
98 enum Primitive { PrimitiveNone, PrimitiveTriangle };
102 unsigned background_color[3];
103 unsigned primitive_color[3];
109 int position_location;
112 : primitive(PrimitiveNone),
113 opacity(1.0f) // Fully opaque.
118 position_location(-1) {
119 background_color[0] = background_color[1] = background_color[2] = 0;
120 primitive_color[0] = primitive_color[1] = primitive_color[2] = 0;
124 // Functions for parsing plugin parameters.
125 Primitive ParsePrimitive(const blink::WebString& string);
126 void ParseColor(const blink::WebString& string, unsigned color[3]);
127 float ParseOpacity(const blink::WebString& string);
128 bool ParseBoolean(const blink::WebString& string);
130 // Functions for loading and drawing scene in GL.
135 bool InitPrimitive();
136 void DrawPrimitive();
137 unsigned LoadShader(unsigned type, const std::string& source);
138 unsigned LoadProgram(const std::string& vertex_source,
139 const std::string& fragment_source);
141 // Functions for drawing scene in Software.
142 void DrawSceneSoftware(void* memory, size_t bytes);
144 blink::WebFrame* frame_;
145 WebTestDelegate* delegate_;
146 blink::WebPluginContainer* container_;
148 blink::WebRect rect_;
149 blink::WebGraphicsContext3D* context_;
150 unsigned color_texture_;
151 cc::TextureMailbox texture_mailbox_;
152 scoped_ptr<base::SharedMemory> shared_bitmap_;
153 bool mailbox_changed_;
154 unsigned framebuffer_;
156 scoped_refptr<cc::TextureLayer> layer_;
157 scoped_ptr<blink::WebLayer> web_layer_;
159 blink::WebPluginContainer::TouchEventRequestType touch_event_request_;
160 // Requests touch events from the WebPluginContainerImpl multiple times to
161 // tickle webkit.org/b/108381
162 bool re_request_touch_events_;
163 bool print_event_details_;
164 bool print_user_gesture_status_;
165 bool can_process_drag_;
168 bool can_create_without_renderer_;
170 DISALLOW_COPY_AND_ASSIGN(TestPlugin);
173 } // namespace content
175 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_TEST_PLUGIN_H_