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 #define PEPPER_APIS_ENABLED 1 | 5 #define PEPPER_APIS_ENABLED 1 |
6 | 6 |
7 #include "chrome/renderer/webplugin_delegate_pepper.h" | 7 #include "chrome/renderer/webplugin_delegate_pepper.h" |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "gfx/codec/jpeg_codec.h" | 48 #include "gfx/codec/jpeg_codec.h" |
49 #include "gfx/gdi_util.h" | 49 #include "gfx/gdi_util.h" |
50 #include "printing/units.h" | 50 #include "printing/units.h" |
51 #include "skia/ext/vector_platform_device.h" | 51 #include "skia/ext/vector_platform_device.h" |
52 #endif | 52 #endif |
53 #include "printing/native_metafile.h" | 53 #include "printing/native_metafile.h" |
54 #include "third_party/npapi/bindings/npapi_extensions.h" | 54 #include "third_party/npapi/bindings/npapi_extensions.h" |
55 #include "third_party/npapi/bindings/npapi_extensions_private.h" | 55 #include "third_party/npapi/bindings/npapi_extensions_private.h" |
56 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" | 56 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" |
57 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 57 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
58 #include "webkit/glue/plugins/plugin_constants_win.h" | |
59 #include "webkit/glue/plugins/plugin_instance.h" | |
60 #include "webkit/glue/plugins/plugin_lib.h" | |
61 #include "webkit/glue/plugins/plugin_list.h" | |
62 #include "webkit/glue/plugins/plugin_host.h" | |
63 #include "webkit/glue/plugins/plugin_stream_url.h" | |
64 #include "webkit/glue/webcursor.h" | 58 #include "webkit/glue/webcursor.h" |
65 #include "webkit/glue/webkit_glue.h" | 59 #include "webkit/glue/webkit_glue.h" |
| 60 #include "webkit/plugins/npapi/plugin_constants_win.h" |
| 61 #include "webkit/plugins/npapi/plugin_instance.h" |
| 62 #include "webkit/plugins/npapi/plugin_lib.h" |
| 63 #include "webkit/plugins/npapi/plugin_list.h" |
| 64 #include "webkit/plugins/npapi/plugin_host.h" |
| 65 #include "webkit/plugins/npapi/plugin_stream_url.h" |
66 | 66 |
67 #if defined(ENABLE_GPU) | 67 #if defined(ENABLE_GPU) |
68 #include "webkit/glue/plugins/plugin_constants_win.h" | 68 #include "webkit/plugins/npapi/plugin_constants_win.h" |
69 #endif | 69 #endif |
70 | 70 |
71 #if defined(ENABLE_GPU) | 71 #if defined(ENABLE_GPU) |
72 using gpu::Buffer; | 72 using gpu::Buffer; |
73 #endif | 73 #endif |
74 | 74 |
75 using webkit_glue::WebPlugin; | 75 using webkit::npapi::WebPlugin; |
76 using webkit_glue::WebPluginDelegate; | 76 using webkit::npapi::WebPluginDelegate; |
77 using webkit_glue::WebPluginResourceClient; | 77 using webkit::npapi::WebPluginResourceClient; |
78 using WebKit::WebCursorInfo; | 78 using WebKit::WebCursorInfo; |
79 using WebKit::WebKeyboardEvent; | 79 using WebKit::WebKeyboardEvent; |
80 using WebKit::WebInputEvent; | 80 using WebKit::WebInputEvent; |
81 using WebKit::WebMouseEvent; | 81 using WebKit::WebMouseEvent; |
82 using WebKit::WebMouseWheelEvent; | 82 using WebKit::WebMouseWheelEvent; |
83 | 83 |
84 namespace { | 84 namespace { |
85 | 85 |
86 // Implementation artifacts for a context | 86 // Implementation artifacts for a context |
87 struct Device2DImpl { | 87 struct Device2DImpl { |
(...skipping 19 matching lines...) Expand all Loading... |
107 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, | 107 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, |
108 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, | 108 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, |
109 int bounds_width, int bounds_height, bool fit_to_bounds, | 109 int bounds_width, int bounds_height, bool fit_to_bounds, |
110 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds); | 110 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds); |
111 #endif // defined(OS_WIN) | 111 #endif // defined(OS_WIN) |
112 | 112 |
113 WebPluginDelegatePepper* WebPluginDelegatePepper::Create( | 113 WebPluginDelegatePepper* WebPluginDelegatePepper::Create( |
114 const FilePath& filename, | 114 const FilePath& filename, |
115 const std::string& mime_type, | 115 const std::string& mime_type, |
116 const base::WeakPtr<RenderView>& render_view) { | 116 const base::WeakPtr<RenderView>& render_view) { |
117 scoped_refptr<NPAPI::PluginLib> plugin_lib( | 117 scoped_refptr<webkit::npapi::PluginLib> plugin_lib( |
118 NPAPI::PluginLib::CreatePluginLib(filename)); | 118 webkit::npapi::PluginLib::CreatePluginLib(filename)); |
119 if (plugin_lib.get() == NULL) | 119 if (plugin_lib.get() == NULL) |
120 return NULL; | 120 return NULL; |
121 | 121 |
122 NPError err = plugin_lib->NP_Initialize(); | 122 NPError err = plugin_lib->NP_Initialize(); |
123 if (err != NPERR_NO_ERROR) | 123 if (err != NPERR_NO_ERROR) |
124 return NULL; | 124 return NULL; |
125 | 125 |
126 scoped_refptr<NPAPI::PluginInstance> instance( | 126 scoped_refptr<webkit::npapi::PluginInstance> instance( |
127 plugin_lib->CreateInstance(mime_type)); | 127 plugin_lib->CreateInstance(mime_type)); |
128 return new WebPluginDelegatePepper(render_view, | 128 return new WebPluginDelegatePepper(render_view, |
129 instance.get()); | 129 instance.get()); |
130 } | 130 } |
131 | 131 |
132 void WebPluginDelegatePepper::didChooseFile( | 132 void WebPluginDelegatePepper::didChooseFile( |
133 const WebKit::WebVector<WebKit::WebString>& file_names) { | 133 const WebKit::WebVector<WebKit::WebString>& file_names) { |
134 if (file_names.isEmpty()) { | 134 if (file_names.isEmpty()) { |
135 current_choose_file_callback_(NULL, 0, current_choose_file_user_data_); | 135 current_choose_file_callback_(NULL, 0, current_choose_file_user_data_); |
136 } else { | 136 } else { |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 if (!extensions || !extensions->getSelection) | 537 if (!extensions || !extensions->getSelection) |
538 return string16(); | 538 return string16(); |
539 | 539 |
540 void* text; | 540 void* text; |
541 NPSelectionType type = html ? NPSelectionTypeHTML : NPSelectionTypePlainText; | 541 NPSelectionType type = html ? NPSelectionTypeHTML : NPSelectionTypePlainText; |
542 NPP npp = instance_->npp(); | 542 NPP npp = instance_->npp(); |
543 if (extensions->getSelection(npp, &type, &text) != NPERR_NO_ERROR) | 543 if (extensions->getSelection(npp, &type, &text) != NPERR_NO_ERROR) |
544 return string16(); | 544 return string16(); |
545 | 545 |
546 string16 rv = UTF8ToUTF16(static_cast<char*>(text)); | 546 string16 rv = UTF8ToUTF16(static_cast<char*>(text)); |
547 NPAPI::PluginHost::Singleton()->host_functions()->memfree(text); | 547 webkit::npapi::PluginHost::Singleton()->host_functions()->memfree(text); |
548 return rv; | 548 return rv; |
549 } | 549 } |
550 | 550 |
551 NPError WebPluginDelegatePepper::Device2DQueryCapability(int32 capability, | 551 NPError WebPluginDelegatePepper::Device2DQueryCapability(int32 capability, |
552 int32* value) { | 552 int32* value) { |
553 return NPERR_GENERIC_ERROR; | 553 return NPERR_GENERIC_ERROR; |
554 } | 554 } |
555 | 555 |
556 NPError WebPluginDelegatePepper::Device2DQueryConfig( | 556 NPError WebPluginDelegatePepper::Device2DQueryConfig( |
557 const NPDeviceContext2DConfig* request, | 557 const NPDeviceContext2DConfig* request, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 if (!context) | 673 if (!context) |
674 return NPERR_GENERIC_ERROR; | 674 return NPERR_GENERIC_ERROR; |
675 | 675 |
676 #if defined(ENABLE_GPU) | 676 #if defined(ENABLE_GPU) |
677 // Check to see if the GPU plugin is already initialized and fail if so. | 677 // Check to see if the GPU plugin is already initialized and fail if so. |
678 if (nested_delegate_) | 678 if (nested_delegate_) |
679 return NPERR_GENERIC_ERROR; | 679 return NPERR_GENERIC_ERROR; |
680 | 680 |
681 // Create an instance of the GPU plugin that is responsible for 3D | 681 // Create an instance of the GPU plugin that is responsible for 3D |
682 // rendering. | 682 // rendering. |
683 nested_delegate_ = new WebPluginDelegateProxy(kGPUPluginMimeType, | 683 nested_delegate_ = new WebPluginDelegateProxy( |
684 render_view_); | 684 "application/vnd.google.chrome.gpu-plugin", render_view_); |
685 | 685 |
686 // TODO(apatrick): should the GPU plugin be attached to plugin_? | 686 // TODO(apatrick): should the GPU plugin be attached to plugin_? |
687 if (nested_delegate_->Initialize(GURL(), | 687 if (nested_delegate_->Initialize(GURL(), |
688 std::vector<std::string>(), | 688 std::vector<std::string>(), |
689 std::vector<std::string>(), | 689 std::vector<std::string>(), |
690 plugin_, | 690 plugin_, |
691 false)) { | 691 false)) { |
692 plugin_->SetAcceptsInputEvents(true); | 692 plugin_->SetAcceptsInputEvents(true); |
693 | 693 |
694 // Ensure the window has the correct size before initializing the | 694 // Ensure the window has the correct size before initializing the |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 // scaling up that will happen in the browser. | 1263 // scaling up that will happen in the browser. |
1264 XFORM xform = {0}; | 1264 XFORM xform = {0}; |
1265 xform.eM11 = xform.eM22 = kPointsPerInch / current_printer_dpi_; | 1265 xform.eM11 = xform.eM22 = kPointsPerInch / current_printer_dpi_; |
1266 ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY); | 1266 ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY); |
1267 | 1267 |
1268 ret = render_proc(pdf_output, output_size, 0, dc, current_printer_dpi_, | 1268 ret = render_proc(pdf_output, output_size, 0, dc, current_printer_dpi_, |
1269 current_printer_dpi_, 0, 0, size_in_pixels.width(), | 1269 current_printer_dpi_, 0, 0, size_in_pixels.width(), |
1270 size_in_pixels.height(), true, false, true, true); | 1270 size_in_pixels.height(), true, false, true, true); |
1271 #endif // defined(OS_WIN) | 1271 #endif // defined(OS_WIN) |
1272 | 1272 |
1273 NPAPI::PluginHost::Singleton()->host_functions()->memfree(pdf_output); | 1273 webkit::npapi::PluginHost::Singleton()->host_functions()->memfree( |
| 1274 pdf_output); |
1274 return ret; | 1275 return ret; |
1275 } | 1276 } |
1276 | 1277 |
1277 bool WebPluginDelegatePepper::PrintPage(int page_number, | 1278 bool WebPluginDelegatePepper::PrintPage(int page_number, |
1278 WebKit::WebCanvas* canvas) { | 1279 WebKit::WebCanvas* canvas) { |
1279 NPPPrintExtensions* print_extensions = GetPrintExtensions(); | 1280 NPPPrintExtensions* print_extensions = GetPrintExtensions(); |
1280 if (!print_extensions) | 1281 if (!print_extensions) |
1281 return false; | 1282 return false; |
1282 | 1283 |
1283 // First try and use vector print. | 1284 // First try and use vector print. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 #if defined(OS_MACOSX) | 1372 #if defined(OS_MACOSX) |
1372 last_printed_page_ = SkBitmap(); | 1373 last_printed_page_ = SkBitmap(); |
1373 #elif defined(OS_LINUX) | 1374 #elif defined(OS_LINUX) |
1374 num_pages_ = 0; | 1375 num_pages_ = 0; |
1375 pdf_output_done_ = false; | 1376 pdf_output_done_ = false; |
1376 #endif // defined(OS_LINUX) | 1377 #endif // defined(OS_LINUX) |
1377 } | 1378 } |
1378 | 1379 |
1379 WebPluginDelegatePepper::WebPluginDelegatePepper( | 1380 WebPluginDelegatePepper::WebPluginDelegatePepper( |
1380 const base::WeakPtr<RenderView>& render_view, | 1381 const base::WeakPtr<RenderView>& render_view, |
1381 NPAPI::PluginInstance *instance) | 1382 webkit::npapi::PluginInstance *instance) |
1382 : render_view_(render_view), | 1383 : render_view_(render_view), |
1383 plugin_(NULL), | 1384 plugin_(NULL), |
1384 instance_(instance), | 1385 instance_(instance), |
1385 nested_delegate_(NULL), | 1386 nested_delegate_(NULL), |
1386 current_printer_dpi_(-1), | 1387 current_printer_dpi_(-1), |
1387 #if defined (OS_LINUX) | 1388 #if defined (OS_LINUX) |
1388 num_pages_(0), | 1389 num_pages_(0), |
1389 pdf_output_done_(false), | 1390 pdf_output_done_(false), |
1390 #endif // (OS_LINUX) | 1391 #endif // (OS_LINUX) |
1391 #if defined(ENABLE_GPU) | 1392 #if defined(ENABLE_GPU) |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1629 const gfx::Rect& clip_rect) { | 1630 const gfx::Rect& clip_rect) { |
1630 // Inform the browser about the location of the plugin on the page. | 1631 // Inform the browser about the location of the plugin on the page. |
1631 // It appears that initially the plugin does not get laid out correctly -- | 1632 // It appears that initially the plugin does not get laid out correctly -- |
1632 // possibly due to lazy creation of the nested delegate. | 1633 // possibly due to lazy creation of the nested delegate. |
1633 if (!nested_delegate_ || | 1634 if (!nested_delegate_ || |
1634 !nested_delegate_->GetPluginWindowHandle() || | 1635 !nested_delegate_->GetPluginWindowHandle() || |
1635 !render_view_) { | 1636 !render_view_) { |
1636 return; | 1637 return; |
1637 } | 1638 } |
1638 | 1639 |
1639 webkit_glue::WebPluginGeometry geom; | 1640 webkit::npapi::WebPluginGeometry geom; |
1640 geom.window = nested_delegate_->GetPluginWindowHandle(); | 1641 geom.window = nested_delegate_->GetPluginWindowHandle(); |
1641 geom.window_rect = window_rect; | 1642 geom.window_rect = window_rect; |
1642 geom.clip_rect = clip_rect; | 1643 geom.clip_rect = clip_rect; |
1643 // Rects_valid must be true for this to work in the Gtk port; | 1644 // Rects_valid must be true for this to work in the Gtk port; |
1644 // hopefully not having the cutout rects will not cause incorrect | 1645 // hopefully not having the cutout rects will not cause incorrect |
1645 // clipping. | 1646 // clipping. |
1646 geom.rects_valid = true; | 1647 geom.rects_valid = true; |
1647 geom.visible = true; | 1648 geom.visible = true; |
1648 render_view_->DidMovePlugin(geom); | 1649 render_view_->DidMovePlugin(geom); |
1649 } | 1650 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1760 CGRect bounds; | 1761 CGRect bounds; |
1761 bounds.origin.x = dest_rect.x(); | 1762 bounds.origin.x = dest_rect.x(); |
1762 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); | 1763 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); |
1763 bounds.size.width = dest_rect.width(); | 1764 bounds.size.width = dest_rect.width(); |
1764 bounds.size.height = dest_rect.height(); | 1765 bounds.size.height = dest_rect.height(); |
1765 | 1766 |
1766 CGContextDrawImage(canvas, bounds, image); | 1767 CGContextDrawImage(canvas, bounds, image); |
1767 CGContextRestoreGState(canvas); | 1768 CGContextRestoreGState(canvas); |
1768 } | 1769 } |
1769 #endif // defined(OS_MACOSX) | 1770 #endif // defined(OS_MACOSX) |
OLD | NEW |