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"
24 class WebGraphicsContext3D
;
26 struct WebPluginParams
;
35 class WebTestDelegate
;
37 // A fake implemention of blink::WebPlugin for testing purposes.
39 // It uses WebGraphicsContext3D to paint a scene consisiting of a primitive
40 // over a background. The primitive and background can be customized using
41 // the following plugin parameters:
42 // primitive: none (default), triangle.
43 // background-color: black (default), red, green, blue.
44 // primitive-color: black (default), red, green, blue.
45 // opacity: [0.0 - 1.0]. Default is 1.0.
47 // Whether the plugin accepts touch events or not can be customized using the
48 // 'accepts-touch' plugin parameter (defaults to false).
49 class TestPlugin
: public blink::WebPlugin
, public cc::TextureLayerClient
{
51 static TestPlugin
* create(blink::WebFrame
* frame
,
52 const blink::WebPluginParams
& params
,
53 WebTestDelegate
* delegate
);
54 ~TestPlugin() override
;
56 static const blink::WebString
& MimeType();
57 static const blink::WebString
& CanCreateWithoutRendererMimeType();
58 static const blink::WebString
& PluginPersistsMimeType();
59 static bool IsSupportedMimeType(const blink::WebString
& mime_type
);
62 virtual bool initialize(blink::WebPluginContainer
* container
);
63 virtual void destroy();
64 virtual NPObject
* scriptableObject();
65 virtual bool canProcessDrag() const;
66 virtual void paint(blink::WebCanvas
* canvas
, const blink::WebRect
& rect
) {}
67 virtual void updateGeometry(
68 const blink::WebRect
& frame_rect
,
69 const blink::WebRect
& clip_rect
,
70 const blink::WebVector
<blink::WebRect
>& cut_outs_rects
,
72 virtual void updateFocus(bool focus
) {}
73 virtual void updateVisibility(bool visibility
) {}
74 virtual bool acceptsInputEvents();
75 virtual bool handleInputEvent(const blink::WebInputEvent
& event
,
76 blink::WebCursorInfo
& info
);
77 virtual bool handleDragStatusUpdate(blink::WebDragStatus drag_status
,
78 const blink::WebDragData
& data
,
79 blink::WebDragOperationsMask mask
,
80 const blink::WebPoint
& position
,
81 const blink::WebPoint
& screen_position
);
82 virtual void didReceiveResponse(const blink::WebURLResponse
& response
) {}
83 virtual void didReceiveData(const char* data
, int data_length
) {}
84 virtual void didFinishLoading() {}
85 virtual void didFailLoading(const blink::WebURLError
& error
) {}
86 virtual void didFinishLoadingFrameRequest(const blink::WebURL
& url
,
88 virtual void didFailLoadingFrameRequest(const blink::WebURL
& url
,
90 const blink::WebURLError
& error
) {}
91 virtual bool isPlaceholder();
93 // cc::TextureLayerClient methods:
94 bool PrepareTextureMailbox(
95 cc::TextureMailbox
* mailbox
,
96 scoped_ptr
<cc::SingleReleaseCallback
>* release_callback
,
97 bool use_shared_memory
) override
;
100 TestPlugin(blink::WebFrame
* frame
,
101 const blink::WebPluginParams
& params
,
102 WebTestDelegate
* delegate
);
104 enum Primitive
{ PrimitiveNone
, PrimitiveTriangle
};
108 unsigned background_color
[3];
109 unsigned primitive_color
[3];
115 int position_location
;
118 : primitive(PrimitiveNone
),
119 opacity(1.0f
) // Fully opaque.
124 position_location(-1) {
125 background_color
[0] = background_color
[1] = background_color
[2] = 0;
126 primitive_color
[0] = primitive_color
[1] = primitive_color
[2] = 0;
130 // Functions for parsing plugin parameters.
131 Primitive
ParsePrimitive(const blink::WebString
& string
);
132 void ParseColor(const blink::WebString
& string
, unsigned color
[3]);
133 float ParseOpacity(const blink::WebString
& string
);
134 bool ParseBoolean(const blink::WebString
& string
);
136 // Functions for loading and drawing scene in GL.
141 bool InitPrimitive();
142 void DrawPrimitive();
143 unsigned LoadShader(unsigned type
, const std::string
& source
);
144 unsigned LoadProgram(const std::string
& vertex_source
,
145 const std::string
& fragment_source
);
147 // Functions for drawing scene in Software.
148 void DrawSceneSoftware(void* memory
);
150 blink::WebFrame
* frame_
;
151 WebTestDelegate
* delegate_
;
152 blink::WebPluginContainer
* container_
;
154 blink::WebRect rect_
;
155 blink::WebGraphicsContext3D
* context_
;
156 unsigned color_texture_
;
157 cc::TextureMailbox texture_mailbox_
;
158 scoped_ptr
<cc::SharedBitmap
> shared_bitmap_
;
159 bool mailbox_changed_
;
160 unsigned framebuffer_
;
162 scoped_refptr
<cc::TextureLayer
> layer_
;
163 scoped_ptr
<blink::WebLayer
> web_layer_
;
165 blink::WebPluginContainer::TouchEventRequestType touch_event_request_
;
166 // Requests touch events from the WebPluginContainerImpl multiple times to
167 // tickle webkit.org/b/108381
168 bool re_request_touch_events_
;
169 bool print_event_details_
;
170 bool print_user_gesture_status_
;
171 bool can_process_drag_
;
174 bool can_create_without_renderer_
;
176 DISALLOW_COPY_AND_ASSIGN(TestPlugin
);
179 } // namespace content
181 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_TEST_PLUGIN_H_