Move origin url validation check to PermissionContextBase class.
[chromium-blink-merge.git] / content / shell / renderer / test_runner / test_plugin.h
blobb62ddc4c5b927defeadb6ad74832325a0b0f4b60
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_
8 #include <string>
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"
22 namespace blink {
23 class WebFrame;
24 class WebGraphicsContext3D;
25 class WebLayer;
26 struct WebPluginParams;
29 namespace cc {
30 class SharedBitmap;
33 namespace content {
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 {
50 public:
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);
61 // WebPlugin methods:
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,
71 bool is_visible);
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,
87 void* notify_data) {}
88 virtual void didFailLoadingFrameRequest(const blink::WebURL& url,
89 void* notify_data,
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;
99 private:
100 TestPlugin(blink::WebFrame* frame,
101 const blink::WebPluginParams& params,
102 WebTestDelegate* delegate);
104 enum Primitive { PrimitiveNone, PrimitiveTriangle };
106 struct Scene {
107 Primitive primitive;
108 unsigned background_color[3];
109 unsigned primitive_color[3];
110 float opacity;
112 unsigned vbo;
113 unsigned program;
114 int color_location;
115 int position_location;
117 Scene()
118 : primitive(PrimitiveNone),
119 opacity(1.0f) // Fully opaque.
121 vbo(0),
122 program(0),
123 color_location(-1),
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.
137 bool InitScene();
138 void DrawSceneGL();
139 void DestroyScene();
140 bool InitProgram();
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_;
161 Scene scene_;
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_;
173 bool is_persistent_;
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_