OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 5 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/histogram.h" | 8 #include "base/histogram.h" |
9 #if defined(OS_MACOSX) | 9 #if defined(OS_MACOSX) |
10 #include "base/mac_util.h" | 10 #include "base/mac_util.h" |
11 #include "base/scoped_cftyperef.h" | 11 #include "base/scoped_cftyperef.h" |
12 #endif | 12 #endif |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "gfx/rect.h" | 15 #include "gfx/rect.h" |
16 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
17 #include "gfx/codec/jpeg_codec.h" | 17 #include "gfx/codec/jpeg_codec.h" |
18 #include "gfx/gdi_util.h" | 18 #include "gfx/gdi_util.h" |
19 #endif | 19 #endif |
20 #include "gfx/skia_util.h" | 20 #include "gfx/skia_util.h" |
21 #include "printing/native_metafile.h" | 21 #include "printing/native_metafile.h" |
22 #include "printing/units.h" | 22 #include "printing/units.h" |
23 #include "skia/ext/vector_platform_device.h" | 23 #include "skia/ext/vector_platform_device.h" |
24 #include "skia/ext/platform_canvas.h" | 24 #include "skia/ext/platform_canvas.h" |
25 #include "third_party/ppapi/c/dev/ppb_find_dev.h" | 25 #include "third_party/ppapi/c/dev/ppb_find_dev.h" |
| 26 #include "third_party/ppapi/c/dev/ppb_fullscreen_dev.h" |
26 #include "third_party/ppapi/c/dev/ppp_find_dev.h" | 27 #include "third_party/ppapi/c/dev/ppp_find_dev.h" |
27 #include "third_party/ppapi/c/dev/ppp_zoom_dev.h" | 28 #include "third_party/ppapi/c/dev/ppp_zoom_dev.h" |
28 #include "third_party/ppapi/c/pp_event.h" | 29 #include "third_party/ppapi/c/pp_event.h" |
29 #include "third_party/ppapi/c/pp_instance.h" | 30 #include "third_party/ppapi/c/pp_instance.h" |
30 #include "third_party/ppapi/c/pp_rect.h" | 31 #include "third_party/ppapi/c/pp_rect.h" |
31 #include "third_party/ppapi/c/pp_resource.h" | 32 #include "third_party/ppapi/c/pp_resource.h" |
32 #include "third_party/ppapi/c/pp_var.h" | 33 #include "third_party/ppapi/c/pp_var.h" |
33 #include "third_party/ppapi/c/ppb_core.h" | 34 #include "third_party/ppapi/c/ppb_core.h" |
34 #include "third_party/ppapi/c/ppb_instance.h" | 35 #include "third_party/ppapi/c/ppb_instance.h" |
35 #include "third_party/ppapi/c/ppp_instance.h" | 36 #include "third_party/ppapi/c/ppp_instance.h" |
36 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" | 37 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" |
37 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" | 38 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" |
38 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" | 39 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
39 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" | 40 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" |
40 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 41 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
41 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 42 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
42 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" | 43 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" |
43 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" | 44 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
44 #include "webkit/glue/plugins/pepper_buffer.h" | 45 #include "webkit/glue/plugins/pepper_buffer.h" |
45 #include "webkit/glue/plugins/pepper_graphics_2d.h" | 46 #include "webkit/glue/plugins/pepper_graphics_2d.h" |
46 #include "webkit/glue/plugins/pepper_event_conversion.h" | 47 #include "webkit/glue/plugins/pepper_event_conversion.h" |
| 48 #include "webkit/glue/plugins/pepper_fullscreen_container.h" |
47 #include "webkit/glue/plugins/pepper_image_data.h" | 49 #include "webkit/glue/plugins/pepper_image_data.h" |
48 #include "webkit/glue/plugins/pepper_plugin_delegate.h" | 50 #include "webkit/glue/plugins/pepper_plugin_delegate.h" |
49 #include "webkit/glue/plugins/pepper_plugin_module.h" | 51 #include "webkit/glue/plugins/pepper_plugin_module.h" |
50 #include "webkit/glue/plugins/pepper_string.h" | 52 #include "webkit/glue/plugins/pepper_string.h" |
51 #include "webkit/glue/plugins/pepper_url_loader.h" | 53 #include "webkit/glue/plugins/pepper_url_loader.h" |
52 #include "webkit/glue/plugins/pepper_var.h" | 54 #include "webkit/glue/plugins/pepper_var.h" |
53 | 55 |
54 using WebKit::WebBindings; | 56 using WebKit::WebBindings; |
55 using WebKit::WebCanvas; | 57 using WebKit::WebCanvas; |
56 using WebKit::WebCursorInfo; | 58 using WebKit::WebCursorInfo; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 DCHECK_NE(instance->find_identifier(), -1); | 202 DCHECK_NE(instance->find_identifier(), -1); |
201 instance->delegate()->DidChangeSelectedFindResult( | 203 instance->delegate()->DidChangeSelectedFindResult( |
202 instance->find_identifier(), index); | 204 instance->find_identifier(), index); |
203 } | 205 } |
204 | 206 |
205 const PPB_Find_Dev ppb_find = { | 207 const PPB_Find_Dev ppb_find = { |
206 &NumberOfFindResultsChanged, | 208 &NumberOfFindResultsChanged, |
207 &SelectedFindResultChanged, | 209 &SelectedFindResultChanged, |
208 }; | 210 }; |
209 | 211 |
| 212 bool IsFullscreen(PP_Instance instance_id) { |
| 213 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
| 214 if (!instance) |
| 215 return false; |
| 216 return instance->IsFullscreen(); |
| 217 } |
| 218 |
| 219 bool SetFullscreen(PP_Instance instance_id, bool fullscreen) { |
| 220 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
| 221 if (!instance) |
| 222 return false; |
| 223 return instance->SetFullscreen(fullscreen); |
| 224 } |
| 225 |
| 226 const PPB_Fullscreen_Dev ppb_fullscreen = { |
| 227 &IsFullscreen, |
| 228 &SetFullscreen, |
| 229 }; |
| 230 |
210 } // namespace | 231 } // namespace |
211 | 232 |
212 PluginInstance::PluginInstance(PluginDelegate* delegate, | 233 PluginInstance::PluginInstance(PluginDelegate* delegate, |
213 PluginModule* module, | 234 PluginModule* module, |
214 const PPP_Instance* instance_interface) | 235 const PPP_Instance* instance_interface) |
215 : delegate_(delegate), | 236 : delegate_(delegate), |
216 module_(module), | 237 module_(module), |
217 instance_interface_(instance_interface), | 238 instance_interface_(instance_interface), |
218 container_(NULL), | 239 container_(NULL), |
219 full_frame_(false), | 240 full_frame_(false), |
220 find_identifier_(-1), | 241 find_identifier_(-1), |
221 plugin_find_interface_(NULL), | 242 plugin_find_interface_(NULL), |
222 plugin_zoom_interface_(NULL), | 243 plugin_zoom_interface_(NULL), |
223 #if defined (OS_LINUX) | 244 #if defined (OS_LINUX) |
224 num_pages_(0), | 245 num_pages_(0), |
225 pdf_output_done_(false), | 246 pdf_output_done_(false), |
226 #endif // defined (OS_LINUX) | 247 #endif // defined (OS_LINUX) |
227 plugin_print_interface_(NULL), | 248 plugin_print_interface_(NULL), |
228 plugin_graphics_3d_interface_(NULL) { | 249 plugin_graphics_3d_interface_(NULL), |
| 250 fullscreen_container_(NULL) { |
229 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 251 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
230 DCHECK(delegate); | 252 DCHECK(delegate); |
231 module_->InstanceCreated(this); | 253 module_->InstanceCreated(this); |
232 delegate_->InstanceCreated(this); | 254 delegate_->InstanceCreated(this); |
233 } | 255 } |
234 | 256 |
235 PluginInstance::~PluginInstance() { | 257 PluginInstance::~PluginInstance() { |
236 delegate_->InstanceDeleted(this); | 258 delegate_->InstanceDeleted(this); |
237 module_->InstanceDeleted(this); | 259 module_->InstanceDeleted(this); |
238 } | 260 } |
239 | 261 |
240 // static | 262 // static |
241 const PPB_Instance* PluginInstance::GetInterface() { | 263 const PPB_Instance* PluginInstance::GetInterface() { |
242 return &ppb_instance; | 264 return &ppb_instance; |
243 } | 265 } |
244 | 266 |
245 // static | 267 // static |
246 PluginInstance* PluginInstance::FromPPInstance(PP_Instance instance) { | 268 PluginInstance* PluginInstance::FromPPInstance(PP_Instance instance) { |
247 return reinterpret_cast<PluginInstance*>(instance); | 269 return reinterpret_cast<PluginInstance*>(instance); |
248 } | 270 } |
249 | 271 |
250 // static | 272 // static |
251 const PPB_Find_Dev* PluginInstance::GetFindInterface() { | 273 const PPB_Find_Dev* PluginInstance::GetFindInterface() { |
252 return &ppb_find; | 274 return &ppb_find; |
253 } | 275 } |
254 | 276 |
| 277 // static |
| 278 const PPB_Fullscreen_Dev* PluginInstance::GetFullscreenInterface() { |
| 279 return &ppb_fullscreen; |
| 280 } |
| 281 |
255 PP_Instance PluginInstance::GetPPInstance() { | 282 PP_Instance PluginInstance::GetPPInstance() { |
256 return reinterpret_cast<intptr_t>(this); | 283 return reinterpret_cast<intptr_t>(this); |
257 } | 284 } |
258 | 285 |
259 void PluginInstance::Paint(WebCanvas* canvas, | 286 void PluginInstance::Paint(WebCanvas* canvas, |
260 const gfx::Rect& plugin_rect, | 287 const gfx::Rect& plugin_rect, |
261 const gfx::Rect& paint_rect) { | 288 const gfx::Rect& paint_rect) { |
262 if (bound_graphics_2d_) | 289 if (bound_graphics_2d_) |
263 bound_graphics_2d_->Paint(canvas, plugin_rect, paint_rect); | 290 bound_graphics_2d_->Paint(canvas, plugin_rect, paint_rect); |
264 } | 291 } |
265 | 292 |
266 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { | 293 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { |
267 if (!container_ || position_.IsEmpty()) | 294 if (fullscreen_container_) { |
268 return; // Nothing to do. | 295 if (rect.IsEmpty()) |
269 if (rect.IsEmpty()) | 296 fullscreen_container_->Invalidate(); |
270 container_->invalidate(); | 297 else |
271 else | 298 fullscreen_container_->InvalidateRect(rect); |
272 container_->invalidateRect(rect); | 299 } else { |
| 300 if (!container_ || position_.IsEmpty()) |
| 301 return; // Nothing to do. |
| 302 if (rect.IsEmpty()) |
| 303 container_->invalidate(); |
| 304 else |
| 305 container_->invalidateRect(rect); |
| 306 } |
273 } | 307 } |
274 | 308 |
275 PP_Var PluginInstance::GetWindowObject() { | 309 PP_Var PluginInstance::GetWindowObject() { |
276 if (!container_) | 310 if (!container_) |
277 return PP_MakeVoid(); | 311 return PP_MakeVoid(); |
278 | 312 |
279 WebFrame* frame = container_->element().document().frame(); | 313 WebFrame* frame = container_->element().document().frame(); |
280 if (!frame) | 314 if (!frame) |
281 return PP_MakeVoid(); | 315 return PP_MakeVoid(); |
282 | 316 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 } | 406 } |
373 | 407 |
374 PP_Var ret = Var::NPVariantToPPVar(module_, &result); | 408 PP_Var ret = Var::NPVariantToPPVar(module_, &result); |
375 WebBindings::releaseVariantValue(&result); | 409 WebBindings::releaseVariantValue(&result); |
376 return ret; | 410 return ret; |
377 } | 411 } |
378 | 412 |
379 void PluginInstance::Delete() { | 413 void PluginInstance::Delete() { |
380 instance_interface_->Delete(GetPPInstance()); | 414 instance_interface_->Delete(GetPPInstance()); |
381 | 415 |
| 416 if (fullscreen_container_) { |
| 417 fullscreen_container_->Destroy(); |
| 418 fullscreen_container_ = NULL; |
| 419 } |
382 container_ = NULL; | 420 container_ = NULL; |
383 } | 421 } |
384 | 422 |
385 bool PluginInstance::Initialize(WebPluginContainer* container, | 423 bool PluginInstance::Initialize(WebPluginContainer* container, |
386 const std::vector<std::string>& arg_names, | 424 const std::vector<std::string>& arg_names, |
387 const std::vector<std::string>& arg_values, | 425 const std::vector<std::string>& arg_values, |
388 bool full_frame) { | 426 bool full_frame) { |
389 container_ = container; | 427 container_ = container; |
390 full_frame_ = full_frame; | 428 full_frame_ = full_frame; |
391 | 429 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 void PluginInstance::Graphics3DContextLost() { | 671 void PluginInstance::Graphics3DContextLost() { |
634 if (!plugin_graphics_3d_interface_) { | 672 if (!plugin_graphics_3d_interface_) { |
635 plugin_graphics_3d_interface_ = | 673 plugin_graphics_3d_interface_ = |
636 reinterpret_cast<const PPP_Graphics3D_Dev*>(module_->GetPluginInterface( | 674 reinterpret_cast<const PPP_Graphics3D_Dev*>(module_->GetPluginInterface( |
637 PPP_GRAPHICS_3D_DEV_INTERFACE)); | 675 PPP_GRAPHICS_3D_DEV_INTERFACE)); |
638 } | 676 } |
639 if (plugin_graphics_3d_interface_) | 677 if (plugin_graphics_3d_interface_) |
640 plugin_graphics_3d_interface_->Graphics3DContextLost(GetPPInstance()); | 678 plugin_graphics_3d_interface_->Graphics3DContextLost(GetPPInstance()); |
641 } | 679 } |
642 | 680 |
| 681 bool PluginInstance::IsFullscreen() { |
| 682 return fullscreen_container_ != NULL; |
| 683 } |
| 684 |
| 685 bool PluginInstance::SetFullscreen(bool fullscreen) { |
| 686 bool is_fullscreen = (fullscreen_container_ != NULL); |
| 687 if (fullscreen == is_fullscreen) |
| 688 return true; |
| 689 LOG(INFO) << "Setting fullscreen to " << (fullscreen ? "on" : "off"); |
| 690 if (fullscreen) { |
| 691 fullscreen_container_ = delegate_->CreateFullscreenContainer(this); |
| 692 } else { |
| 693 fullscreen_container_->Destroy(); |
| 694 fullscreen_container_ = NULL; |
| 695 // TODO(piman): currently the fullscreen container resizes the plugin to the |
| 696 // fullscreen size so we need to reset the size here. Eventually it will |
| 697 // transparently scale and this won't be necessary. |
| 698 if (container_) { |
| 699 container_->reportGeometry(); |
| 700 container_->invalidate(); |
| 701 } |
| 702 } |
| 703 return true; |
| 704 } |
| 705 |
643 bool PluginInstance::PrintPDFOutput(PP_Resource print_output, | 706 bool PluginInstance::PrintPDFOutput(PP_Resource print_output, |
644 WebKit::WebCanvas* canvas) { | 707 WebKit::WebCanvas* canvas) { |
645 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(print_output)); | 708 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(print_output)); |
646 if (!buffer.get() || !buffer->is_mapped() || !buffer->size()) { | 709 if (!buffer.get() || !buffer->is_mapped() || !buffer->size()) { |
647 NOTREACHED(); | 710 NOTREACHED(); |
648 return false; | 711 return false; |
649 } | 712 } |
650 #if defined(OS_WIN) | 713 #if defined(OS_WIN) |
651 // For Windows, we need the PDF DLL to render the output PDF to a DC. | 714 // For Windows, we need the PDF DLL to render the output PDF to a DC. |
652 HMODULE pdf_module = GetModuleHandle(L"pdf.dll"); | 715 HMODULE pdf_module = GetModuleHandle(L"pdf.dll"); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 bounds.size.width = dest_rect.width(); | 923 bounds.size.width = dest_rect.width(); |
861 bounds.size.height = dest_rect.height(); | 924 bounds.size.height = dest_rect.height(); |
862 | 925 |
863 CGContextDrawImage(canvas, bounds, image); | 926 CGContextDrawImage(canvas, bounds, image); |
864 CGContextRestoreGState(canvas); | 927 CGContextRestoreGState(canvas); |
865 } | 928 } |
866 #endif // defined(OS_MACOSX) | 929 #endif // defined(OS_MACOSX) |
867 | 930 |
868 | 931 |
869 } // namespace pepper | 932 } // namespace pepper |
OLD | NEW |