summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-19 15:18:36 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-19 15:18:36 +0000
commitb6e61227773f4d00d5a5daa857f7cb7f91b1d012 (patch)
tree4bf46dbfb9015fc5796a484818f18bf212d40d44 /webkit
parentc4c0ce8b7086e34ef9159439fd27c9b3db1354c4 (diff)
downloadchromium_src-b6e61227773f4d00d5a5daa857f7cb7f91b1d012.zip
chromium_src-b6e61227773f4d00d5a5daa857f7cb7f91b1d012.tar.gz
chromium_src-b6e61227773f4d00d5a5daa857f7cb7f91b1d012.tar.bz2
Change PPP_Printing_Dev QuerySupportedFormats to not require MemAlloc and MemFree.
This also is a first stab at providing backwards-compatibility (even though in this case 0.3 will go away once everyone is ported). To use the new version, you need to 'opt-in' by adding the following line before including ppp_printing_dev.h: #define PPP_PRINTING_DEV_USE_0_4 I have NOT updated the C++ wrapper. I can work on that next, although it would help to have some test code that relies on it to make sure I'm not breaking anything. brettw: Please focus on the backwards-compatibility code, let me know what you think. thestig: Please focus on print code. I'd appreciate any tips on being able to test this better; I don't have access to the PDF plugin code. I verified that the existing plugin still works with this change by copying in libpdf.so, opening a PDF, and printing it. BUG=80696 TEST=Manual. Try to print a PDF. Review URL: http://codereview.chromium.org/6975018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85912 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc119
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.h36
2 files changed, 124 insertions, 31 deletions
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index e5b8ccc..bee7a61 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -970,6 +970,26 @@ bool PluginInstance::LoadSelectionInterface() {
return !!plugin_selection_interface_;
}
+bool PluginInstance::LoadPrintInterface() {
+ if (!plugin_print_interface_.get()) {
+ // Try to get the most recent version first. Fall back to older supported
+ // versions if necessary.
+ const PPP_Printing_Dev* print_if = static_cast<const PPP_Printing_Dev*>(
+ module_->GetPluginInterface(PPP_PRINTING_DEV_INTERFACE));
+ if (print_if) {
+ plugin_print_interface_.reset(new PPP_Printing_Dev_Combined(*print_if));
+ } else {
+ const PPP_Printing_Dev_0_3* print_if_0_3 =
+ static_cast<const PPP_Printing_Dev_0_3*>(
+ module_->GetPluginInterface(PPP_PRINTING_DEV_INTERFACE_0_3));
+ if (print_if_0_3)
+ plugin_print_interface_.reset(
+ new PPP_Printing_Dev_Combined(*print_if_0_3));
+ }
+ }
+ return !!plugin_print_interface_.get();
+}
+
bool PluginInstance::LoadPrivateInterface() {
if (!plugin_private_interface_) {
plugin_private_interface_ = static_cast<const PPP_Instance_Private*>(
@@ -1005,35 +1025,49 @@ bool PluginInstance::GetPreferredPrintOutputFormat(
PP_PrintOutputFormat_Dev* format) {
// Keep a reference on the stack. See NOTE above.
scoped_refptr<PluginInstance> ref(this);
- if (!plugin_print_interface_) {
- plugin_print_interface_ =
- static_cast<const PPP_Printing_Dev*>(module_->GetPluginInterface(
- PPP_PRINTING_DEV_INTERFACE));
- }
- if (!plugin_print_interface_)
+ if (!LoadPrintInterface())
return false;
- uint32_t format_count = 0;
- PP_PrintOutputFormat_Dev* supported_formats =
- plugin_print_interface_->QuerySupportedFormats(pp_instance(),
- &format_count);
- if (!supported_formats)
- return false;
-
- bool found_supported_format = false;
- for (uint32_t index = 0; index < format_count; index++) {
- if (supported_formats[index] == PP_PRINTOUTPUTFORMAT_PDF) {
- // If we found PDF, we are done.
- found_supported_format = true;
+ if (plugin_print_interface_->QuerySupportedFormats) {
+ // If the most recent version of the QuerySupportedFormats functions is
+ // available, use it.
+ uint32_t supported_formats =
+ plugin_print_interface_->QuerySupportedFormats(pp_instance());
+ if (supported_formats & PP_PRINTOUTPUTFORMAT_PDF) {
*format = PP_PRINTOUTPUTFORMAT_PDF;
- break;
- } else if (supported_formats[index] == PP_PRINTOUTPUTFORMAT_RASTER) {
- // We found raster. Keep looking.
- found_supported_format = true;
+ return true;
+ } else if (supported_formats & PP_PRINTOUTPUTFORMAT_RASTER) {
*format = PP_PRINTOUTPUTFORMAT_RASTER;
+ return true;
}
+ return false;
+ } else if (plugin_print_interface_->QuerySupportedFormats_0_3) {
+ // If we couldn't use the latest version of the function, but the 0.3
+ // version exists, we can use it.
+ uint32_t format_count = 0;
+ PP_PrintOutputFormat_Dev_0_3* supported_formats =
+ plugin_print_interface_->QuerySupportedFormats_0_3(pp_instance(),
+ &format_count);
+ if (!supported_formats)
+ return false;
+
+ bool found_supported_format = false;
+ for (uint32_t index = 0; index < format_count; index++) {
+ if (supported_formats[index] == PP_PRINTOUTPUTFORMAT_PDF_DEPRECATED) {
+ // If we found PDF, we are done.
+ found_supported_format = true;
+ *format = PP_PRINTOUTPUTFORMAT_PDF;
+ break;
+ } else if (supported_formats[index] ==
+ PP_PRINTOUTPUTFORMAT_RASTER_DEPRECATED) {
+ // We found raster. Keep looking.
+ found_supported_format = true;
+ *format = PP_PRINTOUTPUTFORMAT_RASTER;
+ }
+ }
+ PluginModule::GetCore()->MemFree(supported_formats);
+ return found_supported_format;
}
- PluginModule::GetCore()->MemFree(supported_formats);
- return found_supported_format;
+ return false;
}
bool PluginInstance::SupportsPrintInterface() {
@@ -1053,14 +1087,41 @@ int PluginInstance::PrintBegin(const gfx::Rect& printable_area,
return 0;
}
+ int num_pages = 0;
PP_PrintSettings_Dev print_settings;
RectToPPRect(printable_area, &print_settings.printable_area);
print_settings.dpi = printer_dpi;
print_settings.orientation = PP_PRINTORIENTATION_NORMAL;
print_settings.grayscale = PP_FALSE;
print_settings.format = format;
- int num_pages = plugin_print_interface_->Begin(pp_instance(),
- &print_settings);
+ if (plugin_print_interface_->Begin) {
+ // If we have the most current version of Begin, use it.
+ num_pages = plugin_print_interface_->Begin(pp_instance(),
+ &print_settings);
+ } else if (plugin_print_interface_->Begin_0_3) {
+ // Fall back to the 0.3 version of Begin if necessary, and convert the
+ // output format.
+ PP_PrintSettings_Dev_0_3 print_settings_0_3;
+ RectToPPRect(printable_area, &print_settings_0_3.printable_area);
+ print_settings_0_3.dpi = printer_dpi;
+ print_settings_0_3.orientation = PP_PRINTORIENTATION_NORMAL;
+ print_settings_0_3.grayscale = PP_FALSE;
+ switch (format) {
+ case PP_PRINTOUTPUTFORMAT_RASTER:
+ print_settings_0_3.format = PP_PRINTOUTPUTFORMAT_RASTER_DEPRECATED;
+ break;
+ case PP_PRINTOUTPUTFORMAT_PDF:
+ print_settings_0_3.format = PP_PRINTOUTPUTFORMAT_PDF_DEPRECATED;
+ break;
+ case PP_PRINTOUTPUTFORMAT_POSTSCRIPT:
+ print_settings_0_3.format = PP_PRINTOUTPUTFORMAT_POSTSCRIPT_DEPRECATED;
+ break;
+ default:
+ return 0;
+ }
+ num_pages = plugin_print_interface_->Begin_0_3(pp_instance(),
+ &print_settings_0_3);
+ }
if (!num_pages)
return 0;
current_print_settings_ = print_settings;
@@ -1072,7 +1133,7 @@ int PluginInstance::PrintBegin(const gfx::Rect& printable_area,
}
bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) {
- DCHECK(plugin_print_interface_);
+ DCHECK(plugin_print_interface_.get());
PP_PrintPageNumberRange_Dev page_range;
page_range.first_page_number = page_range.last_page_number = page_number;
#if defined(OS_LINUX)
@@ -1118,8 +1179,8 @@ void PluginInstance::PrintEnd() {
ranges_.clear();
#endif // defined(OS_LINUX)
- DCHECK(plugin_print_interface_);
- if (plugin_print_interface_)
+ DCHECK(plugin_print_interface_.get());
+ if (plugin_print_interface_.get())
plugin_print_interface_->End(pp_instance());
memset(&current_print_settings_, 0, sizeof(current_print_settings_));
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h
index b893fc3..5ce4fcf 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.h
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h
@@ -17,6 +17,9 @@
#include "googleurl/src/gurl.h"
#include "ppapi/c/dev/pp_cursor_type_dev.h"
#include "ppapi/c/dev/ppp_graphics_3d_dev.h"
+// TODO(dmichael): Remove the 0.3 printing interface and remove the following
+// #define.
+#define PPP_PRINTING_DEV_USE_0_4 1
#include "ppapi/c/dev/ppp_printing_dev.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
@@ -266,6 +269,7 @@ class PluginInstance : public base::RefCounted<PluginInstance> {
bool LoadMessagingInterface();
bool LoadPdfInterface();
bool LoadSelectionInterface();
+ bool LoadPrintInterface();
bool LoadPrivateInterface();
bool LoadZoomInterface();
@@ -386,8 +390,36 @@ class PluginInstance : public base::RefCounted<PluginInstance> {
std::vector<PP_PrintPageNumberRange_Dev> ranges_;
#endif // defined(OS_LINUX)
- // The plugin print interface.
- const PPP_Printing_Dev* plugin_print_interface_;
+ // The plugin print interface. This nested struct adds functions needed for
+ // backwards compatibility.
+ struct PPP_Printing_Dev_Combined : public PPP_Printing_Dev {
+ // Conversion constructor for the most current interface. Sets all old
+ // functions to NULL, so we know not to try to use them.
+ PPP_Printing_Dev_Combined(const PPP_Printing_Dev& base_if)
+ : PPP_Printing_Dev(base_if),
+ QuerySupportedFormats_0_3(NULL),
+ Begin_0_3(NULL) {}
+
+ // Conversion constructor for version 0.3. Sets unsupported functions to
+ // NULL, so we know not to try to use them.
+ PPP_Printing_Dev_Combined(const PPP_Printing_Dev_0_3& old_if)
+ : PPP_Printing_Dev(), // NOTE: The parens are important, to zero-
+ // initialize the struct.
+ QuerySupportedFormats_0_3(old_if.QuerySupportedFormats),
+ Begin_0_3(old_if.Begin) {
+ PrintPages = old_if.PrintPages;
+ End = old_if.End;
+ }
+
+ // The 0.3 version of 'QuerySupportedFormats'.
+ PP_PrintOutputFormat_Dev_0_3* (*QuerySupportedFormats_0_3)(
+ PP_Instance instance, uint32_t* format_count);
+ // The 0.3 version of 'Begin'.
+ int32_t (*Begin_0_3)(PP_Instance instance,
+ const struct PP_PrintSettings_Dev_0_3* print_settings);
+
+ };
+ scoped_ptr<PPP_Printing_Dev_Combined> plugin_print_interface_;
// The plugin 3D interface.
const PPP_Graphics3D_Dev* plugin_graphics_3d_interface_;