| OLD | NEW |
| (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_TEST_PLUGIN_H_ | |
| 6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_TEST_PLUGIN_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 "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" | |
| 20 | |
| 21 namespace blink { | |
| 22 class WebFrame; | |
| 23 class WebGraphicsContext3D; | |
| 24 class WebLayer; | |
| 25 struct WebPluginParams; | |
| 26 } | |
| 27 | |
| 28 namespace cc { | |
| 29 class SharedBitmap; | |
| 30 } | |
| 31 | |
| 32 namespace content { | |
| 33 | |
| 34 class WebTestDelegate; | |
| 35 | |
| 36 // A fake implemention of blink::WebPlugin for testing purposes. | |
| 37 // | |
| 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. | |
| 45 // | |
| 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 { | |
| 49 public: | |
| 50 static TestPlugin* create(blink::WebFrame* frame, | |
| 51 const blink::WebPluginParams& params, | |
| 52 WebTestDelegate* delegate); | |
| 53 ~TestPlugin() override; | |
| 54 | |
| 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); | |
| 59 | |
| 60 // WebPlugin methods: | |
| 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, | |
| 73 bool is_visible); | |
| 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, | |
| 89 void* notify_data) {} | |
| 90 virtual void didFailLoadingFrameRequest(const blink::WebURL& url, | |
| 91 void* notify_data, | |
| 92 const blink::WebURLError& error) {} | |
| 93 virtual bool isPlaceholder(); | |
| 94 | |
| 95 // cc::TextureLayerClient methods: | |
| 96 bool PrepareTextureMailbox( | |
| 97 cc::TextureMailbox* mailbox, | |
| 98 scoped_ptr<cc::SingleReleaseCallback>* release_callback, | |
| 99 bool use_shared_memory) override; | |
| 100 | |
| 101 private: | |
| 102 TestPlugin(blink::WebFrame* frame, | |
| 103 const blink::WebPluginParams& params, | |
| 104 WebTestDelegate* delegate); | |
| 105 | |
| 106 enum Primitive { PrimitiveNone, PrimitiveTriangle }; | |
| 107 | |
| 108 struct Scene { | |
| 109 Primitive primitive; | |
| 110 unsigned background_color[3]; | |
| 111 unsigned primitive_color[3]; | |
| 112 float opacity; | |
| 113 | |
| 114 unsigned vbo; | |
| 115 unsigned program; | |
| 116 int color_location; | |
| 117 int position_location; | |
| 118 | |
| 119 Scene() | |
| 120 : primitive(PrimitiveNone), | |
| 121 opacity(1.0f) // Fully opaque. | |
| 122 , | |
| 123 vbo(0), | |
| 124 program(0), | |
| 125 color_location(-1), | |
| 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; | |
| 129 } | |
| 130 }; | |
| 131 | |
| 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); | |
| 137 | |
| 138 // Functions for loading and drawing scene in GL. | |
| 139 bool InitScene(); | |
| 140 void DrawSceneGL(); | |
| 141 void DestroyScene(); | |
| 142 bool InitProgram(); | |
| 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); | |
| 148 | |
| 149 // Functions for drawing scene in Software. | |
| 150 void DrawSceneSoftware(void* memory); | |
| 151 | |
| 152 blink::WebFrame* frame_; | |
| 153 WebTestDelegate* delegate_; | |
| 154 blink::WebPluginContainer* container_; | |
| 155 | |
| 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_; | |
| 163 Scene scene_; | |
| 164 scoped_refptr<cc::TextureLayer> layer_; | |
| 165 scoped_ptr<blink::WebLayer> web_layer_; | |
| 166 | |
| 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_; | |
| 175 | |
| 176 bool is_persistent_; | |
| 177 bool can_create_without_renderer_; | |
| 178 | |
| 179 DISALLOW_COPY_AND_ASSIGN(TestPlugin); | |
| 180 }; | |
| 181 | |
| 182 } // namespace content | |
| 183 | |
| 184 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_TEST_PLUGIN_H_ | |
| OLD | NEW |