diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-11 02:37:20 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-11 02:37:20 +0000 |
commit | dae536dc8d53e598873672bc24b231bb38601385 (patch) | |
tree | 7514e21f5a95e8bc524e8e43100e85ac67185bd1 /webkit | |
parent | e174f0a9ce418e24525bbf7610fb4bdddf52971d (diff) | |
download | chromium_src-dae536dc8d53e598873672bc24b231bb38601385.zip chromium_src-dae536dc8d53e598873672bc24b231bb38601385.tar.gz chromium_src-dae536dc8d53e598873672bc24b231bb38601385.tar.bz2 |
Linux: Trade one hack for another to allow pepper plugins to print only selected pages.
BUG=59732
TEST=none
Review URL: http://codereview.chromium.org/6012004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70990 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 65 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 27 |
2 files changed, 50 insertions, 42 deletions
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 35ac1ad..7533a79 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -304,10 +304,9 @@ PluginInstance::PluginInstance(PluginDelegate* delegate, plugin_pdf_interface_(NULL), plugin_selection_interface_(NULL), plugin_zoom_interface_(NULL), -#if defined (OS_LINUX) - num_pages_(0), - pdf_output_done_(false), -#endif // defined (OS_LINUX) +#if defined(OS_LINUX) + canvas_(NULL), +#endif // defined(OS_LINUX) plugin_print_interface_(NULL), plugin_graphics_3d_interface_(NULL), always_on_top_(false), @@ -327,6 +326,9 @@ PluginInstance::~PluginInstance() { module_->InstanceDeleted(this); ResourceTracker::Get()->InstanceDeleted(pp_instance_); +#if defined(OS_LINUX) + ranges_.clear(); +#endif // defined(OS_LINUX) } // static @@ -837,34 +839,31 @@ int PluginInstance::PrintBegin(const gfx::Rect& printable_area, if (!num_pages) return 0; current_print_settings_ = print_settings; -#if defined (OS_LINUX) - num_pages_ = num_pages; - pdf_output_done_ = false; -#endif // (OS_LINUX) +#if defined(OS_LINUX) + canvas_ = NULL; + ranges_.clear(); +#endif // defined(OS_LINUX) return num_pages; } bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) { DCHECK(plugin_print_interface_); PP_PrintPageNumberRange_Dev page_range; -#if defined(OS_LINUX) - if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) { - // On Linux we will try and output all pages as PDF in the first call to - // PrintPage. This is a temporary hack. - // TODO(sanjeevr): Remove this hack and fix this by changing the print - // interfaces for WebFrame and WebPlugin. - if (page_number != 0) - return pdf_output_done_; - page_range.first_page_number = 0; - page_range.last_page_number = num_pages_ - 1; - } -#else // defined(OS_LINUX) page_range.first_page_number = page_range.last_page_number = page_number; +#if defined(OS_LINUX) + ranges_.push_back(page_range); + canvas_ = canvas; + return true; +#else + return PrintPageHelper(&page_range, 1, canvas); #endif // defined(OS_LINUX) +} - PP_Resource print_output = - plugin_print_interface_->PrintPages(pp_instance(), &page_range, 1); - +bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, + int num_ranges, + WebKit::WebCanvas* canvas) { + PP_Resource print_output = plugin_print_interface_->PrintPages( + pp_instance(), page_ranges, num_ranges); if (!print_output) return false; @@ -882,16 +881,22 @@ bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) { } void PluginInstance::PrintEnd() { +#if defined(OS_LINUX) + // This hack is here because all pages need to be written to PDF at once. + if (!ranges_.empty()) + PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_); + canvas_ = NULL; + ranges_.clear(); +#endif // defined(OS_LINUX) + DCHECK(plugin_print_interface_); if (plugin_print_interface_) plugin_print_interface_->End(pp_instance()); + memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); #if defined(OS_MACOSX) last_printed_page_ = NULL; -#elif defined(OS_LINUX) - num_pages_ = 0; - pdf_output_done_ = false; -#endif // defined(OS_LINUX) +#endif // defined(OS_MACOSX) } bool PluginInstance::IsFullscreen() { @@ -974,11 +979,8 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output, printing::NativeMetafile* metafile = printing::NativeMetafile::FromCairoContext(context); DCHECK(metafile); - if (metafile) { + if (metafile) ret = metafile->SetRawData(buffer->mapped_buffer(), buffer->size()); - if (ret) - pdf_output_done_ = true; - } canvas->endPlatformPaint(); #elif defined(OS_MACOSX) printing::NativeMetafile metafile; @@ -1189,4 +1191,3 @@ PPB_Surface3D_Impl* PluginInstance::bound_graphics_3d() const { } // namespace ppapi } // namespace webkit - diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index 3f34ea5..a4624e6 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -232,6 +232,11 @@ class PluginInstance : public base::RefCounted<PluginInstance> { // Returns NULL if bound graphics is not a 3D surface. PPB_Surface3D_Impl* bound_graphics_3d() const; + // Internal helper function for PrintPage(). + bool PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, + int num_ranges, + WebKit::WebCanvas* canvas); + PluginDelegate* delegate_; scoped_refptr<PluginModule> module_; const PPP_Instance* instance_interface_; @@ -283,16 +288,18 @@ class PluginInstance : public base::RefCounted<PluginInstance> { // variable to hold on to the pixels. scoped_refptr<PPB_ImageData_Impl> 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_; + // On Linux, all pages need to be written to a PDF file in one shot. However, + // when users print only a subset of all the pages, it is impossible to know + // if a call to PrintPage() is the last call. Thus in PrintPage(), just store + // the page number in |ranges_|. + // The hack is in PrintEnd(), where a valid |canvas_| is preserved in + // PrintWebViewHelper::PrintPages. This makes it possible to generate the + // entire PDF given the variables below: + // + // The most recently used WebCanvas, guaranteed to be valid. + WebKit::WebCanvas* canvas_; + // An array of page ranges. + std::vector<PP_PrintPageNumberRange_Dev> ranges_; #endif // defined(OS_LINUX) // The plugin print interface. |