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

Side by Side Diff: webkit/glue/plugins/pepper_plugin_instance.h

Issue 5828003: Move the Pepper implementation from webkit/glue/plugins/pepper_* to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_INSTANCE_H_
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_INSTANCE_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/observer_list.h"
13 #include "base/ref_counted.h"
14 #include "base/scoped_ptr.h"
15 #include "base/string16.h"
16 #include "gfx/rect.h"
17 #include "ppapi/c/dev/pp_cursor_type_dev.h"
18 #include "ppapi/c/dev/ppp_graphics_3d_dev.h"
19 #include "ppapi/c/dev/ppp_printing_dev.h"
20 #include "ppapi/c/pp_instance.h"
21 #include "ppapi/c/pp_resource.h"
22 #include "third_party/skia/include/core/SkBitmap.h"
23 #include "third_party/WebKit/WebKit/chromium/public/WebCanvas.h"
24
25 struct PP_Var;
26 struct PPB_Instance;
27 struct PPB_Find_Dev;
28 struct PPB_Fullscreen_Dev;
29 struct PPB_Zoom_Dev;
30 struct PPP_Find_Dev;
31 struct PPP_Instance;
32 struct PPP_Private;
33 struct PPP_Selection_Dev;
34 struct PPP_Zoom_Dev;
35
36 class SkBitmap;
37 class TransportDIB;
38
39 namespace gfx {
40 class Rect;
41 }
42
43 namespace WebKit {
44 struct WebCursorInfo;
45 class WebInputEvent;
46 class WebPluginContainer;
47 }
48
49 namespace pepper {
50
51 class Graphics2D;
52 class Graphics3D;
53 class ImageData;
54 class PluginDelegate;
55 class PluginModule;
56 class Resource;
57 class URLLoader;
58 class FullscreenContainer;
59
60 // Represents one time a plugin appears on one web page.
61 //
62 // Note: to get from a PP_Instance to a PluginInstance*, use the
63 // ResourceTracker.
64 class PluginInstance : public base::RefCounted<PluginInstance> {
65 public:
66 class Observer {
67 public:
68 // Indicates that the instance is being destroyed. This will be called from
69 // the instance's destructor so don't do anything in this callback that
70 // uses the instance.
71 virtual void InstanceDestroyed(PluginInstance* instance) = 0;
72 };
73
74 PluginInstance(PluginDelegate* delegate,
75 PluginModule* module,
76 const PPP_Instance* instance_interface);
77 ~PluginInstance();
78
79 static const PPB_Instance* GetInterface();
80
81 // Returns a pointer to the interface implementing PPB_Find that is
82 // exposed to the plugin.
83 static const PPB_Find_Dev* GetFindInterface();
84 static const PPB_Fullscreen_Dev* GetFullscreenInterface();
85 static const PPB_Zoom_Dev* GetZoomInterface();
86
87 PluginDelegate* delegate() const { return delegate_; }
88 PluginModule* module() const { return module_.get(); }
89
90 WebKit::WebPluginContainer* container() const { return container_; }
91
92 const gfx::Rect& position() const { return position_; }
93 const gfx::Rect& clip() const { return clip_; }
94
95 int find_identifier() const { return find_identifier_; }
96
97 void set_always_on_top(bool on_top) { always_on_top_ = on_top; }
98
99 // Returns the PP_Instance uniquely identifying this instance. Guaranteed
100 // nonzero.
101 PP_Instance pp_instance() const { return pp_instance_; }
102
103 // Other classes can register an observer for instance events. These pointers
104 // are NOT owned by the Instance. If the object implementing the observer
105 // goes away, it must take care to unregister itself.
106 void AddObserver(Observer* observer);
107 void RemoveObserver(Observer* observer);
108
109 // Paints the current backing store to the web page.
110 void Paint(WebKit::WebCanvas* canvas,
111 const gfx::Rect& plugin_rect,
112 const gfx::Rect& paint_rect);
113
114 // Schedules a paint of the page for the given region. The coordinates are
115 // relative to the top-left of the plugin. This does nothing if the plugin
116 // has not yet been positioned. You can supply an empty gfx::Rect() to
117 // invalidate the entire plugin.
118 void InvalidateRect(const gfx::Rect& rect);
119
120 // Schedules a scroll of the plugin. This uses optimized scrolling only for
121 // full-frame plugins, as otherwise there could be other elements on top. The
122 // slow path can also be triggered if there is an overlapping frame.
123 void ScrollRect(int dx, int dy, const gfx::Rect& rect);
124
125 // If the plugin instance is backed by a texture, return its texture ID in the
126 // compositor's namespace. Otherwise return 0. Returns 0 by default.
127 virtual unsigned GetBackingTextureId();
128
129 // Commit the backing texture to the screen once the side effects some
130 // rendering up to an offscreen SwapBuffers are visible.
131 void CommitBackingTexture();
132
133 // PPB_Instance implementation.
134 PP_Var GetWindowObject();
135 PP_Var GetOwnerElementObject();
136 bool BindGraphics(PP_Resource graphics_id);
137 bool full_frame() const { return full_frame_; }
138 bool SetCursor(PP_CursorType_Dev type);
139 PP_Var ExecuteScript(PP_Var script, PP_Var* exception);
140
141 // PPP_Instance pass-through.
142 void Delete();
143 bool Initialize(WebKit::WebPluginContainer* container,
144 const std::vector<std::string>& arg_names,
145 const std::vector<std::string>& arg_values,
146 bool full_frame);
147 bool HandleDocumentLoad(URLLoader* loader);
148 bool HandleInputEvent(const WebKit::WebInputEvent& event,
149 WebKit::WebCursorInfo* cursor_info);
150 PP_Var GetInstanceObject();
151 void ViewChanged(const gfx::Rect& position, const gfx::Rect& clip);
152
153 // Notifications about focus changes, see has_webkit_focus_ below.
154 void SetWebKitFocus(bool has_focus);
155 void SetContentAreaFocus(bool has_focus);
156
157 // Notifications that the view has rendered the page and that it has been
158 // flushed to the screen. These messages are used to send Flush callbacks to
159 // the plugin for DeviceContext2D.
160 void ViewInitiatedPaint();
161 void ViewFlushedPaint();
162
163 // If this plugin can be painted merely by copying the backing store to the
164 // screen, and the plugin bounds encloses the given paint bounds, returns
165 // true. In this case, the location, clipping, and ID of the backing store
166 // will be filled into the given output parameters.
167 bool GetBitmapForOptimizedPluginPaint(
168 const gfx::Rect& paint_bounds,
169 TransportDIB** dib,
170 gfx::Rect* dib_bounds,
171 gfx::Rect* clip);
172
173 string16 GetSelectedText(bool html);
174 string16 GetLinkAtPosition(const gfx::Point& point);
175 void Zoom(double factor, bool text_only);
176 bool StartFind(const string16& search_text,
177 bool case_sensitive,
178 int identifier);
179 void SelectFindResult(bool forward);
180 void StopFind();
181
182 bool SupportsPrintInterface();
183 int PrintBegin(const gfx::Rect& printable_area, int printer_dpi);
184 bool PrintPage(int page_number, WebKit::WebCanvas* canvas);
185 void PrintEnd();
186
187 void Graphics3DContextLost();
188
189 // Implementation of PPB_Fullscreen_Dev.
190 bool IsFullscreen();
191 bool SetFullscreen(bool fullscreen);
192
193 // Implementation of PPB_Private2.
194 bool NavigateToURL(const char* url, const char* target);
195
196 private:
197 bool LoadFindInterface();
198 bool LoadPrivateInterface();
199 bool LoadSelectionInterface();
200 bool LoadZoomInterface();
201
202 // Determines if we think the plugin has focus, both content area and webkit
203 // (see has_webkit_focus_ below).
204 bool PluginHasFocus() const;
205
206 // Queries the plugin for supported print formats and sets |format| to the
207 // best format to use. Returns false if the plugin does not support any
208 // print format that we can handle (we can handle raster and PDF).
209 bool GetPreferredPrintOutputFormat(PP_PrintOutputFormat_Dev* format);
210 bool PrintPDFOutput(PP_Resource print_output, WebKit::WebCanvas* canvas);
211 bool PrintRasterOutput(PP_Resource print_output, WebKit::WebCanvas* canvas);
212 #if defined(OS_WIN)
213 bool DrawJPEGToPlatformDC(const SkBitmap& bitmap,
214 const gfx::Rect& printable_area,
215 WebKit::WebCanvas* canvas);
216 #elif defined(OS_MACOSX)
217 // Draws the given kARGB_8888_Config bitmap to the specified canvas starting
218 // at the specified destination rect.
219 void DrawSkBitmapToCanvas(const SkBitmap& bitmap, WebKit::WebCanvas* canvas,
220 const gfx::Rect& dest_rect, int canvas_height);
221 #endif // OS_MACOSX
222
223 // Get the bound graphics context as a concrete 2D graphics context or returns
224 // null if the context is not 2D.
225 Graphics2D* bound_graphics_2d() const;
226
227 // Get the bound graphics context as a concrete 3D graphics context or returns
228 // null if the context is not 3D.
229 Graphics3D* bound_graphics_3d() const;
230
231 PluginDelegate* delegate_;
232 scoped_refptr<PluginModule> module_;
233 const PPP_Instance* instance_interface_;
234
235 PP_Instance pp_instance_;
236
237 // NULL until we have been initialized.
238 WebKit::WebPluginContainer* container_;
239
240 // Indicates whether this is a full frame instance, which means it represents
241 // an entire document rather than an embed tag.
242 bool full_frame_;
243
244 // Position in the viewport (which moves as the page is scrolled) of this
245 // plugin. This will be a 0-sized rectangle if the plugin has not yet been
246 // laid out.
247 gfx::Rect position_;
248
249 // Current clip rect. This will be empty if the plugin is not currently
250 // visible. This is in the plugin's coordinate system, so fully visible will
251 // be (0, 0, w, h) regardless of scroll position.
252 gfx::Rect clip_;
253
254 // The current device context for painting in 2D or 3D.
255 scoped_refptr<Resource> bound_graphics_;
256
257 // We track two types of focus, one from WebKit, which is the focus among
258 // all elements of the page, one one from the browser, which is whether the
259 // tab/window has focus. We tell the plugin it has focus only when both of
260 // these values are set to true.
261 bool has_webkit_focus_;
262 bool has_content_area_focus_;
263
264 // The id of the current find operation, or -1 if none is in process.
265 int find_identifier_;
266
267 // The plugin-provided interfaces.
268 const PPP_Find_Dev* plugin_find_interface_;
269 const PPP_Private* plugin_private_interface_;
270 const PPP_Selection_Dev* plugin_selection_interface_;
271 const PPP_Zoom_Dev* plugin_zoom_interface_;
272
273 // This is only valid between a successful PrintBegin call and a PrintEnd
274 // call.
275 PP_PrintSettings_Dev current_print_settings_;
276 #if defined(OS_MACOSX)
277 // On the Mac, when we draw the bitmap to the PDFContext, it seems necessary
278 // to keep the pixels valid until CGContextEndPage is called. We use this
279 // variable to hold on to the pixels.
280 scoped_refptr<ImageData> last_printed_page_;
281 #elif defined(OS_LINUX)
282 // On Linux, we always send all pages from the renderer to the browser.
283 // So, if the plugin supports printPagesAsPDF we print the entire output
284 // in one shot in the first call to PrintPage.
285 // (This is a temporary hack until we change the WebFrame and WebPlugin print
286 // interfaces).
287 // Specifies the total number of pages to be printed. It it set in PrintBegin.
288 int32 num_pages_;
289 // Specifies whether we have already output all pages. This is used to ignore
290 // subsequent PrintPage requests.
291 bool pdf_output_done_;
292 #endif // defined(OS_LINUX)
293
294 // The plugin print interface.
295 const PPP_Printing_Dev* plugin_print_interface_;
296
297 // The plugin 3D interface.
298 const PPP_Graphics3D_Dev* plugin_graphics_3d_interface_;
299
300 // Containes the cursor if it's set by the plugin.
301 scoped_ptr<WebKit::WebCursorInfo> cursor_;
302
303 // Set to true if this plugin thinks it will always be on top. This allows us
304 // to use a more optimized painting path in some cases.
305 bool always_on_top_;
306
307 // Plugin container for fullscreen mode. NULL if not in fullscreen mode.
308 FullscreenContainer* fullscreen_container_;
309
310 // Non-owning pointers to all active observers.
311 ObserverList<Observer, false> observers_;
312
313 DISALLOW_COPY_AND_ASSIGN(PluginInstance);
314 };
315
316 } // namespace pepper
317
318 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_INSTANCE_H_
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_plugin_delegate.h ('k') | webkit/glue/plugins/pepper_plugin_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698