Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: content/shell/renderer/test_runner/TestPlugin.h

Issue 469943003: TestPlugin to chromium c++ style. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/shell/BUILD.gn ('k') | content/shell/renderer/test_runner/TestPlugin.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_TESTPLUGIN_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_TESTPLUGIN_H_
7
8 #include <string>
9
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"
21
22 namespace blink {
23 class WebFrame;
24 class WebLayer;
25 }
26
27 namespace content {
28
29 class WebTestDelegate;
30
31 // A fake implemention of blink::WebPlugin for testing purposes.
32 //
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.
40 //
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 {
44 public:
45 static TestPlugin* create(blink::WebFrame*, const blink::WebPluginParams&, W ebTestDelegate*);
46 virtual ~TestPlugin();
47
48 static const blink::WebString& mimeType();
49 static const blink::WebString& canCreateWithoutRendererMimeType();
50 static const blink::WebString& pluginPersistsMimeType();
51 static bool isSupportedMimeType(const blink::WebString& mimeType);
52
53 // WebPlugin methods:
54 virtual bool initialize(blink::WebPluginContainer*);
55 virtual void destroy();
56 virtual NPObject* scriptableObject();
57 virtual bool canProcessDrag() const;
58 virtual void paint(blink::WebCanvas*, const blink::WebRect&) { }
59 virtual void updateGeometry(const blink::WebRect& frameRect, const blink::We bRect& clipRect, const blink::WebVector<blink::WebRect>& cutOutsRects, bool isVi sible);
60 virtual void updateFocus(bool) { }
61 virtual void updateVisibility(bool) { }
62 virtual bool acceptsInputEvents();
63 virtual bool handleInputEvent(const blink::WebInputEvent&, blink::WebCursorI nfo&);
64 virtual bool handleDragStatusUpdate(blink::WebDragStatus, const blink::WebDr agData&, blink::WebDragOperationsMask, const blink::WebPoint& position, const bl ink::WebPoint& screenPosition);
65 virtual void didReceiveResponse(const blink::WebURLResponse&) { }
66 virtual void didReceiveData(const char* data, int dataLength) { }
67 virtual void didFinishLoading() { }
68 virtual void didFailLoading(const blink::WebURLError&) { }
69 virtual void didFinishLoadingFrameRequest(const blink::WebURL&, void* notify Data) { }
70 virtual void didFailLoadingFrameRequest(const blink::WebURL&, void* notifyDa ta, const blink::WebURLError&) { }
71 virtual bool isPlaceholder();
72
73 // cc::TextureLayerClient methods:
74 virtual bool PrepareTextureMailbox(
75 cc::TextureMailbox* mailbox,
76 scoped_ptr<cc::SingleReleaseCallback>* releaseCallback,
77 bool useSharedMemory) OVERRIDE;
78
79 private:
80 TestPlugin(blink::WebFrame*, const blink::WebPluginParams&, WebTestDelegate* );
81
82 enum Primitive {
83 PrimitiveNone,
84 PrimitiveTriangle
85 };
86
87 struct Scene {
88 Primitive primitive;
89 unsigned backgroundColor[3];
90 unsigned primitiveColor[3];
91 float opacity;
92
93 unsigned vbo;
94 unsigned program;
95 int colorLocation;
96 int positionLocation;
97
98 Scene()
99 : primitive(PrimitiveNone)
100 , opacity(1.0f) // Fully opaque.
101 , vbo(0)
102 , program(0)
103 , colorLocation(-1)
104 , positionLocation(-1)
105 {
106 backgroundColor[0] = backgroundColor[1] = backgroundColor[2] = 0;
107 primitiveColor[0] = primitiveColor[1] = primitiveColor[2] = 0;
108 }
109 };
110
111 // Functions for parsing plugin parameters.
112 Primitive parsePrimitive(const blink::WebString&);
113 void parseColor(const blink::WebString&, unsigned color[3]);
114 float parseOpacity(const blink::WebString&);
115 bool parseBoolean(const blink::WebString&);
116
117 // Functions for loading and drawing scene in GL.
118 bool initScene();
119 void drawSceneGL();
120 void destroyScene();
121 bool initProgram();
122 bool initPrimitive();
123 void drawPrimitive();
124 unsigned loadShader(unsigned type, const std::string& source);
125 unsigned loadProgram(const std::string& vertexSource, const std::string& fra gmentSource);
126
127 // Functions for drawing scene in Software.
128 void drawSceneSoftware(void* memory, size_t bytes);
129
130 blink::WebFrame* m_frame;
131 WebTestDelegate* m_delegate;
132 blink::WebPluginContainer* m_container;
133
134 blink::WebRect m_rect;
135 blink::WebGraphicsContext3D* m_context;
136 unsigned m_colorTexture;
137 cc::TextureMailbox m_textureMailbox;
138 scoped_ptr<base::SharedMemory> m_sharedBitmap;
139 bool m_mailboxChanged;
140 unsigned m_framebuffer;
141 Scene m_scene;
142 scoped_refptr<cc::TextureLayer> m_layer;
143 scoped_ptr<blink::WebLayer> m_webLayer;
144
145 blink::WebPluginContainer::TouchEventRequestType m_touchEventRequest;
146 // Requests touch events from the WebPluginContainerImpl multiple times to t ickle webkit.org/b/108381
147 bool m_reRequestTouchEvents;
148 bool m_printEventDetails;
149 bool m_printUserGestureStatus;
150 bool m_canProcessDrag;
151
152 bool m_isPersistent;
153 bool m_canCreateWithoutRenderer;
154
155 DISALLOW_COPY_AND_ASSIGN(TestPlugin);
156 };
157
158 } // namespace content
159
160 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_TESTPLUGIN_H_
OLDNEW
« no previous file with comments | « content/shell/BUILD.gn ('k') | content/shell/renderer/test_runner/TestPlugin.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698