1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_INSTANCE_H_
#define WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_INSTANCE_H_
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "base/string16.h"
#include "gfx/rect.h"
#include "third_party/ppapi/c/pp_cursor_type.h"
#include "third_party/ppapi/c/pp_instance.h"
#include "third_party/ppapi/c/pp_resource.h"
#include "third_party/ppapi/c/ppp_printing.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/WebKit/WebKit/chromium/public/WebCanvas.h"
typedef struct _pp_Var PP_Var;
typedef struct _ppb_Instance PPB_Instance;
typedef struct _ppb_Find PPB_Find;
typedef struct _ppp_Find PPP_Find;
typedef struct _ppp_Instance PPP_Instance;
typedef struct _ppp_Zoom PPP_Zoom;
class SkBitmap;
namespace gfx {
class Rect;
}
namespace WebKit {
struct WebCursorInfo;
class WebInputEvent;
class WebPluginContainer;
}
namespace pepper {
class DeviceContext2D;
class PluginDelegate;
class PluginModule;
class URLLoader;
class PluginInstance : public base::RefCounted<PluginInstance> {
public:
PluginInstance(PluginDelegate* delegate,
PluginModule* module,
const PPP_Instance* instance_interface);
~PluginInstance();
static const PPB_Instance* GetInterface();
// Converts the given instance ID to an actual instance object.
static PluginInstance* FromPPInstance(PP_Instance instance);
// Returns a pointer to the interface implementing PPB_Find that is
// exposed to the plugin.
static const PPB_Find* GetFindInterface();
PluginDelegate* delegate() const { return delegate_; }
PluginModule* module() const { return module_.get(); }
WebKit::WebPluginContainer* container() const { return container_; }
const gfx::Rect& position() const { return position_; }
const gfx::Rect& clip() const { return clip_; }
int find_identifier() const { return find_identifier_; }
PP_Instance GetPPInstance();
// Paints the current backing store to the web page.
void Paint(WebKit::WebCanvas* canvas,
const gfx::Rect& plugin_rect,
const gfx::Rect& paint_rect);
// Schedules a paint of the page for the given region. The coordinates are
// relative to the top-left of the plugin. This does nothing if the plugin
// has not yet been positioned. You can supply an empty gfx::Rect() to
// invalidate the entire plugin.
void InvalidateRect(const gfx::Rect& rect);
// PPB_Instance implementation.
PP_Var GetWindowObject();
PP_Var GetOwnerElementObject();
bool BindGraphicsDeviceContext(PP_Resource device_id);
bool full_frame() const { return full_frame_; }
bool SetCursor(PP_CursorType type);
// PPP_Instance pass-through.
void Delete();
bool Initialize(WebKit::WebPluginContainer* container,
const std::vector<std::string>& arg_names,
const std::vector<std::string>& arg_values,
bool full_frame);
bool HandleDocumentLoad(URLLoader* loader);
bool HandleInputEvent(const WebKit::WebInputEvent& event,
WebKit::WebCursorInfo* cursor_info);
PP_Var GetInstanceObject();
void ViewChanged(const gfx::Rect& position, const gfx::Rect& clip);
// Notifications that the view has rendered the page and that it has been
// flushed to the screen. These messages are used to send Flush callbacks to
// the plugin for DeviceContext2D.
void ViewInitiatedPaint();
void ViewFlushedPaint();
string16 GetSelectedText(bool html);
void Zoom(float factor, bool text_only);
bool StartFind(const string16& search_text,
bool case_sensitive,
int identifier);
void SelectFindResult(bool forward);
void StopFind();
bool SupportsPrintInterface();
int PrintBegin(const gfx::Rect& printable_area, int printer_dpi);
bool PrintPage(int page_number, WebKit::WebCanvas* canvas);
void PrintEnd();
private:
bool LoadFindInterface();
bool LoadZoomInterface();
// Queries the plugin for supported print formats and sets |format| to the
// best format to use. Returns false if the plugin does not support any
// print format that we can handle (we can handle raster and PDF).
bool GetPreferredPrintOutputFormat(PP_PrintOutputFormat* format);
bool PrintPDFOutput(PP_Resource print_output, WebKit::WebCanvas* canvas);
bool PrintRasterOutput(PP_Resource print_output, WebKit::WebCanvas* canvas);
#if defined(OS_WIN)
bool DrawJPEGToPlatformDC(const SkBitmap& bitmap,
const gfx::Rect& printable_area,
WebKit::WebCanvas* canvas);
#elif defined(OS_MACOSX)
// Draws the given kARGB_8888_Config bitmap to the specified canvas starting
// at the specified destination rect.
void DrawSkBitmapToCanvas(const SkBitmap& bitmap, WebKit::WebCanvas* canvas,
const gfx::Rect& dest_rect, int canvas_height);
#endif // OS_MACOSX
PluginDelegate* delegate_;
scoped_refptr<PluginModule> module_;
const PPP_Instance* instance_interface_;
// NULL until we have been initialized.
WebKit::WebPluginContainer* container_;
// Indicates whether this is a full frame instance, which means it represents
// an entire document rather than an embed tag.
bool full_frame_;
// Position in the viewport (which moves as the page is scrolled) of this
// plugin. This will be a 0-sized rectangle if the plugin has not yet been
// laid out.
gfx::Rect position_;
// Current clip rect. This will be empty if the plugin is not currently
// visible. This is in the plugin's coordinate system, so fully visible will
// be (0, 0, w, h) regardless of scroll position.
gfx::Rect clip_;
// The current device context for painting in 2D.
scoped_refptr<DeviceContext2D> device_context_2d_;
// The id of the current find operation, or -1 if none is in process.
int find_identifier_;
// The plugin find and zoom interfaces.
const PPP_Find* plugin_find_interface_;
const PPP_Zoom* plugin_zoom_interface_;
// This is only valid between a successful PrintBegin call and a PrintEnd
// call.
PP_PrintSettings current_print_settings_;
#if defined(OS_MACOSX)
// On the Mac, when we draw the bitmap to the PDFContext, it seems necessary
// to keep the pixels valid until CGContextEndPage is called. We use this
// variable to hold on to the pixels.
SkBitmap last_printed_page_;
#elif defined(OS_LINUX)
// On Linux, we always send all pages from the renderer to the browser.
// So, if the plugin supports printPagesAsPDF we print the entire output
// in one shot in the first call to PrintPage.
// (This is a temporary hack until we change the WebFrame and WebPlugin print
// interfaces).
// Specifies the total number of pages to be printed. It it set in PrintBegin.
int32 num_pages_;
// Specifies whether we have already output all pages. This is used to ignore
// subsequent PrintPage requests.
bool pdf_output_done_;
#endif // defined(OS_LINUX)
// The plugin print interface.
const PPP_Printing* plugin_print_interface_;
// Containes the cursor if it's set by the plugin.
scoped_ptr<WebKit::WebCursorInfo> cursor_;
DISALLOW_COPY_AND_ASSIGN(PluginInstance);
};
} // namespace pepper
#endif // WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_INSTANCE_H_
|