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 COMPONENTS_TEST_RUNNER_TEST_PLUGIN_H_
6 #define COMPONENTS_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 "third_party/WebKit/public/platform/WebExternalTextureLayer.h"
15 #include "third_party/WebKit/public/platform/WebExternalTextureLayerClient.h"
16 #include "third_party/WebKit/public/platform/WebExternalTextureMailbox.h"
17 #include "third_party/WebKit/public/platform/WebLayer.h"
18 #include "third_party/WebKit/public/web/WebPlugin.h"
19 #include "third_party/WebKit/public/web/WebPluginContainer.h"
23 class WebGraphicsContext3D
;
25 struct WebPluginParams
;
32 namespace test_runner
{
34 class WebTestDelegate
;
36 // A fake implemention of blink::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.
46 // Whether the plugin accepts touch events or not can be customized using the
47 // 'accepts-touch' plugin parameter (defaults to false).
48 class TestPlugin
: public blink::WebPlugin
, public cc::TextureLayerClient
{
50 static TestPlugin
* create(blink::WebFrame
* frame
,
51 const blink::WebPluginParams
& params
,
52 WebTestDelegate
* delegate
);
53 ~TestPlugin() override
;
55 static const blink::WebString
& MimeType();
56 static const blink::WebString
& CanCreateWithoutRendererMimeType();
57 static const blink::WebString
& PluginPersistsMimeType();
58 static bool IsSupportedMimeType(const blink::WebString
& mime_type
);
61 virtual bool initialize(blink::WebPluginContainer
* container
);
62 virtual void destroy();
63 virtual NPObject
* scriptableObject();
64 virtual bool canProcessDrag() const;
65 virtual bool supportsKeyboardFocus() const;
66 virtual void layoutIfNeeded() override
{ }
67 virtual void paint(blink::WebCanvas
* canvas
, const blink::WebRect
& rect
) {}
68 virtual void updateGeometry(
69 const blink::WebRect
& window_rect
,
70 const blink::WebRect
& clip_rect
,
71 const blink::WebRect
& unobscured_rect
,
72 const blink::WebVector
<blink::WebRect
>& cut_outs_rects
,
74 virtual void updateFocus(bool focus
, blink::WebFocusType focus_type
) {}
75 virtual void updateVisibility(bool visibility
) {}
76 virtual bool acceptsInputEvents();
77 virtual bool handleInputEvent(const blink::WebInputEvent
& event
,
78 blink::WebCursorInfo
& info
);
79 virtual bool handleDragStatusUpdate(blink::WebDragStatus drag_status
,
80 const blink::WebDragData
& data
,
81 blink::WebDragOperationsMask mask
,
82 const blink::WebPoint
& position
,
83 const blink::WebPoint
& screen_position
);
84 virtual void didReceiveResponse(const blink::WebURLResponse
& response
) {}
85 virtual void didReceiveData(const char* data
, int data_length
) {}
86 virtual void didFinishLoading() {}
87 virtual void didFailLoading(const blink::WebURLError
& error
) {}
88 virtual void didFinishLoadingFrameRequest(const blink::WebURL
& url
,
90 virtual void didFailLoadingFrameRequest(const blink::WebURL
& url
,
92 const blink::WebURLError
& error
) {}
93 virtual bool isPlaceholder();
95 // cc::TextureLayerClient methods:
96 bool PrepareTextureMailbox(
97 cc::TextureMailbox
* mailbox
,
98 scoped_ptr
<cc::SingleReleaseCallback
>* release_callback
,
99 bool use_shared_memory
) override
;
102 TestPlugin(blink::WebFrame
* frame
,
103 const blink::WebPluginParams
& params
,
104 WebTestDelegate
* delegate
);
106 enum Primitive
{ PrimitiveNone
, PrimitiveTriangle
};
110 unsigned background_color
[3];
111 unsigned primitive_color
[3];
117 int position_location
;
120 : primitive(PrimitiveNone
),
121 opacity(1.0f
) // Fully opaque.
126 position_location(-1) {
127 background_color
[0] = background_color
[1] = background_color
[2] = 0;
128 primitive_color
[0] = primitive_color
[1] = primitive_color
[2] = 0;
132 // Functions for parsing plugin parameters.
133 Primitive
ParsePrimitive(const blink::WebString
& string
);
134 void ParseColor(const blink::WebString
& string
, unsigned color
[3]);
135 float ParseOpacity(const blink::WebString
& string
);
136 bool ParseBoolean(const blink::WebString
& string
);
138 // Functions for loading and drawing scene in GL.
143 bool InitPrimitive();
144 void DrawPrimitive();
145 unsigned LoadShader(unsigned type
, const std::string
& source
);
146 unsigned LoadProgram(const std::string
& vertex_source
,
147 const std::string
& fragment_source
);
149 // Functions for drawing scene in Software.
150 void DrawSceneSoftware(void* memory
);
152 blink::WebFrame
* frame_
;
153 WebTestDelegate
* delegate_
;
154 blink::WebPluginContainer
* container_
;
156 blink::WebRect rect_
;
157 blink::WebGraphicsContext3D
* context_
;
158 unsigned color_texture_
;
159 cc::TextureMailbox texture_mailbox_
;
160 scoped_ptr
<cc::SharedBitmap
> shared_bitmap_
;
161 bool mailbox_changed_
;
162 unsigned framebuffer_
;
164 scoped_refptr
<cc::TextureLayer
> layer_
;
165 scoped_ptr
<blink::WebLayer
> web_layer_
;
167 blink::WebPluginContainer::TouchEventRequestType touch_event_request_
;
168 // Requests touch events from the WebPluginContainerImpl multiple times to
169 // tickle webkit.org/b/108381
170 bool re_request_touch_events_
;
171 bool print_event_details_
;
172 bool print_user_gesture_status_
;
173 bool can_process_drag_
;
174 bool supports_keyboard_focus_
;
177 bool can_create_without_renderer_
;
179 DISALLOW_COPY_AND_ASSIGN(TestPlugin
);
182 } // namespace test_runner
184 #endif // COMPONENTS_TEST_RUNNER_TEST_PLUGIN_H_