From 99a510701d7a252c2c4ab6318d81589ad5c2e763 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 21 Aug 2014 22:14:27 +0800 Subject: [PATCH] Strip out print preview. --- .../browser/printing/printing_message_filter.cc | 148 ---- .../browser/printing/printing_message_filter.h | 28 - chromium_src/chrome/common/print_messages.cc | 19 - chromium_src/chrome/common/print_messages.h | 158 ---- .../renderer/printing/print_web_view_helper.cc | 838 +-------------------- .../renderer/printing/print_web_view_helper.h | 177 ----- .../printing/print_web_view_helper_linux.cc | 43 +- .../renderer/printing/print_web_view_helper_mac.mm | 50 +- .../renderer/printing/print_web_view_helper_win.cc | 58 +- 9 files changed, 6 insertions(+), 1513 deletions(-) diff --git a/chromium_src/chrome/browser/printing/printing_message_filter.cc b/chromium_src/chrome/browser/printing/printing_message_filter.cc index 6dab425..f237159 100644 --- a/chromium_src/chrome/browser/printing/printing_message_filter.cc +++ b/chromium_src/chrome/browser/printing/printing_message_filter.cc @@ -18,26 +18,6 @@ #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" -#if defined(ENABLE_FULL_PRINTING) -#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" -#endif - -#if defined(OS_CHROMEOS) -#include - -#include - -#include "base/file_util.h" -#include "base/lazy_instance.h" -#include "chrome/browser/printing/print_dialog_cloud.h" -#endif - -#if defined(OS_ANDROID) -#include "base/strings/string_number_conversions.h" -#include "chrome/browser/printing/print_view_manager_basic.h" -#include "printing/printing_context_android.h" -#endif - using content::BrowserThread; namespace { @@ -80,7 +60,6 @@ void RenderParamsFromPrintSettings(const printing::PrintSettings& settings, params->selection_only = settings.selection_only(); params->supports_alpha_blend = settings.supports_alpha_blend(); params->should_print_backgrounds = settings.should_print_backgrounds(); - params->display_header_footer = settings.display_header_footer(); params->title = settings.title(); params->url = settings.url(); } @@ -119,21 +98,12 @@ bool PrintingMessageFilter::OnMessageReceived(const IPC::Message& message, #if defined(OS_WIN) IPC_MESSAGE_HANDLER(PrintHostMsg_DuplicateSection, OnDuplicateSection) #endif -#if defined(OS_CHROMEOS) || defined(OS_ANDROID) - IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting, - OnAllocateTempFileForPrinting) - IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten, - OnTempFileForPrintingWritten) -#endif IPC_MESSAGE_HANDLER(PrintHostMsg_IsPrintingEnabled, OnIsPrintingEnabled) IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings, OnGetDefaultPrintSettings) IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrint, OnScriptedPrint) IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_UpdatePrintSettings, OnUpdatePrintSettings) -#if defined(ENABLE_FULL_PRINTING) - IPC_MESSAGE_HANDLER(PrintHostMsg_CheckForCancel, OnCheckForCancel) -#endif IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -150,102 +120,6 @@ void PrintingMessageFilter::OnDuplicateSection( } #endif -#if defined(OS_CHROMEOS) || defined(OS_ANDROID) -void PrintingMessageFilter::OnAllocateTempFileForPrinting( - int render_view_id, - base::FileDescriptor* temp_file_fd, - int* sequence_number) { -#if defined(OS_CHROMEOS) - // TODO(thestig): Use |render_view_id| for Chrome OS. - DCHECK_CURRENTLY_ON(BrowserThread::FILE); - temp_file_fd->fd = *sequence_number = -1; - temp_file_fd->auto_close = false; - - SequenceToPathMap* map = &g_printing_file_descriptor_map.Get().map; - *sequence_number = g_printing_file_descriptor_map.Get().sequence++; - - base::FilePath path; - if (base::CreateTemporaryFile(&path)) { - int fd = open(path.value().c_str(), O_WRONLY); - if (fd >= 0) { - SequenceToPathMap::iterator it = map->find(*sequence_number); - if (it != map->end()) { - NOTREACHED() << "Sequence number already in use. seq=" << - *sequence_number; - } else { - (*map)[*sequence_number] = path; - temp_file_fd->fd = fd; - temp_file_fd->auto_close = true; - } - } - } -#elif defined(OS_ANDROID) - DCHECK_CURRENTLY_ON(BrowserThread::UI); - content::WebContents* wc = GetWebContentsForRenderView(render_view_id); - if (!wc) - return; - printing::PrintViewManagerBasic* print_view_manager = - printing::PrintViewManagerBasic::FromWebContents(wc); - // The file descriptor is originally created in & passed from the Android - // side, and it will handle the closing. - const base::FileDescriptor& file_descriptor = - print_view_manager->file_descriptor(); - temp_file_fd->fd = file_descriptor.fd; - temp_file_fd->auto_close = false; -#endif -} - -void PrintingMessageFilter::OnTempFileForPrintingWritten(int render_view_id, - int sequence_number) { -#if defined(OS_CHROMEOS) - DCHECK_CURRENTLY_ON(BrowserThread::FILE); - SequenceToPathMap* map = &g_printing_file_descriptor_map.Get().map; - SequenceToPathMap::iterator it = map->find(sequence_number); - if (it == map->end()) { - NOTREACHED() << "Got a sequence that we didn't pass to the " - "renderer: " << sequence_number; - return; - } - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind(&PrintingMessageFilter::CreatePrintDialogForFile, - this, render_view_id, it->second)); - - // Erase the entry in the map. - map->erase(it); -#elif defined(OS_ANDROID) - DCHECK_CURRENTLY_ON(BrowserThread::UI); - content::WebContents* wc = GetWebContentsForRenderView(render_view_id); - if (!wc) - return; - printing::PrintViewManagerBasic* print_view_manager = - printing::PrintViewManagerBasic::FromWebContents(wc); - const base::FileDescriptor& file_descriptor = - print_view_manager->file_descriptor(); - printing::PrintingContextAndroid::PdfWritingDone(file_descriptor.fd, true); - // Invalidate the file descriptor so it doesn't accidentally get reused. - print_view_manager->set_file_descriptor(base::FileDescriptor(-1, false)); -#endif -} -#endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) - -#if defined(OS_CHROMEOS) -void PrintingMessageFilter::CreatePrintDialogForFile( - int render_view_id, - const base::FilePath& path) { - content::WebContents* wc = GetWebContentsForRenderView(render_view_id); - if (!wc) - return; - print_dialog_cloud::CreatePrintDialogForFile( - wc->GetBrowserContext(), - wc->GetTopLevelNativeWindow(), - path, - wc->GetTitle(), - base::string16(), - std::string("application/pdf")); -} -#endif // defined(OS_CHROMEOS) - content::WebContents* PrintingMessageFilter::GetWebContentsForRenderView( int render_view_id) { DCHECK_CURRENTLY_ON(BrowserThread::UI); @@ -410,18 +284,6 @@ void PrintingMessageFilter::OnScriptedPrintReply( } } -#if defined(OS_ANDROID) -void PrintingMessageFilter::UpdateFileDescriptor(int render_view_id, int fd) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - content::WebContents* wc = GetWebContentsForRenderView(render_view_id); - if (!wc) - return; - printing::PrintViewManagerBasic* print_view_manager = - printing::PrintViewManagerBasic::FromWebContents(wc); - print_view_manager->set_file_descriptor(base::FileDescriptor(fd, false)); -} -#endif - void PrintingMessageFilter::OnUpdatePrintSettings( int document_cookie, const base::DictionaryValue& job_settings, IPC::Message* reply_msg) { @@ -464,13 +326,3 @@ void PrintingMessageFilter::OnUpdatePrintSettingsReply( } } } - -#if defined(ENABLE_FULL_PRINTING) -void PrintingMessageFilter::OnCheckForCancel(int32 preview_ui_id, - int preview_request_id, - bool* cancel) { - PrintPreviewUI::GetCurrentPrintPreviewStatus(preview_ui_id, - preview_request_id, - cancel); -} -#endif diff --git a/chromium_src/chrome/browser/printing/printing_message_filter.h b/chromium_src/chrome/browser/printing/printing_message_filter.h index 80684b5..656e175 100644 --- a/chromium_src/chrome/browser/printing/printing_message_filter.h +++ b/chromium_src/chrome/browser/printing/printing_message_filter.h @@ -53,25 +53,6 @@ class PrintingMessageFilter : public content::BrowserMessageFilter { base::SharedMemoryHandle* browser_handle); #endif -#if defined(OS_CHROMEOS) || defined(OS_ANDROID) - // Used to ask the browser allocate a temporary file for the renderer - // to fill in resulting PDF in renderer. - void OnAllocateTempFileForPrinting(int render_view_id, - base::FileDescriptor* temp_file_fd, - int* sequence_number); - void OnTempFileForPrintingWritten(int render_view_id, int sequence_number); -#endif - -#if defined(OS_CHROMEOS) - void CreatePrintDialogForFile(int render_view_id, const base::FilePath& path); -#endif - -#if defined(OS_ANDROID) - // Updates the file descriptor for the PrintViewManagerBasic of a given - // render_view_id. - void UpdateFileDescriptor(int render_view_id, int fd); -#endif - // Given a render_view_id get the corresponding WebContents. // Must be called on the UI thread. content::WebContents* GetWebContentsForRenderView(int render_view_id); @@ -122,15 +103,6 @@ class PrintingMessageFilter : public content::BrowserMessageFilter { scoped_refptr printer_query, IPC::Message* reply_msg); -#if defined(ENABLE_FULL_PRINTING) - // Check to see if print preview has been cancelled. - void OnCheckForCancel(int32 preview_ui_id, - int preview_request_id, - bool* cancel); -#endif - - // ProfileIOData* profile_io_data_; - const int render_process_id_; scoped_refptr queue_; diff --git a/chromium_src/chrome/common/print_messages.cc b/chromium_src/chrome/common/print_messages.cc index 5894629..ad34e6c 100644 --- a/chromium_src/chrome/common/print_messages.cc +++ b/chromium_src/chrome/common/print_messages.cc @@ -21,12 +21,8 @@ PrintMsg_Print_Params::PrintMsg_Print_Params() document_cookie(0), selection_only(false), supports_alpha_blend(false), - preview_ui_id(-1), - preview_request_id(0), - is_first_request(false), print_scaling_option(blink::WebPrintScalingOptionSourceSize), print_to_pdf(false), - display_header_footer(false), title(), url(), should_print_backgrounds(false) { @@ -47,12 +43,8 @@ void PrintMsg_Print_Params::Reset() { document_cookie = 0; selection_only = false; supports_alpha_blend = false; - preview_ui_id = -1; - preview_request_id = 0; - is_first_request = false; print_scaling_option = blink::WebPrintScalingOptionSourceSize; print_to_pdf = false; - display_header_footer = false; title = base::string16(); url = base::string16(); should_print_backgrounds = false; @@ -68,14 +60,3 @@ void PrintMsg_PrintPages_Params::Reset() { params.Reset(); pages = std::vector(); } - -PrintHostMsg_RequestPrintPreview_Params:: - PrintHostMsg_RequestPrintPreview_Params() - : is_modifiable(false), - webnode_only(false), - has_selection(false), - selection_only(false) { -} - -PrintHostMsg_RequestPrintPreview_Params:: - ~PrintHostMsg_RequestPrintPreview_Params() {} diff --git a/chromium_src/chrome/common/print_messages.h b/chromium_src/chrome/common/print_messages.h index d095417..7a20414 100644 --- a/chromium_src/chrome/common/print_messages.h +++ b/chromium_src/chrome/common/print_messages.h @@ -39,12 +39,8 @@ struct PrintMsg_Print_Params { int document_cookie; bool selection_only; bool supports_alpha_blend; - int32 preview_ui_id; - int preview_request_id; - bool is_first_request; blink::WebPrintScalingOption print_scaling_option; bool print_to_pdf; - bool display_header_footer; base::string16 title; base::string16 url; bool should_print_backgrounds; @@ -61,15 +57,6 @@ struct PrintMsg_PrintPages_Params { std::vector pages; }; -struct PrintHostMsg_RequestPrintPreview_Params { - PrintHostMsg_RequestPrintPreview_Params(); - ~PrintHostMsg_RequestPrintPreview_Params(); - bool is_modifiable; - bool webnode_only; - bool has_selection; - bool selection_only; -}; - #endif // CHROME_COMMON_PRINT_MESSAGES_H_ #define IPC_MESSAGE_START PrintMsgStart @@ -118,26 +105,12 @@ IPC_STRUCT_TRAITS_BEGIN(PrintMsg_Print_Params) // Does the printer support alpha blending? IPC_STRUCT_TRAITS_MEMBER(supports_alpha_blend) - // *** Parameters below are used only for print preview. *** - - // The print preview ui associated with this request. - IPC_STRUCT_TRAITS_MEMBER(preview_ui_id) - - // The id of the preview request. - IPC_STRUCT_TRAITS_MEMBER(preview_request_id) - - // True if this is the first preview request. - IPC_STRUCT_TRAITS_MEMBER(is_first_request) - // Specifies the page scaling option for preview printing. IPC_STRUCT_TRAITS_MEMBER(print_scaling_option) // True if print to pdf is requested. IPC_STRUCT_TRAITS_MEMBER(print_to_pdf) - // Specifies if the header and footer should be rendered. - IPC_STRUCT_TRAITS_MEMBER(display_header_footer) - // Title string to be printed as header if requested by the user. IPC_STRUCT_TRAITS_MEMBER(title) @@ -158,13 +131,6 @@ IPC_STRUCT_BEGIN(PrintMsg_PrintPage_Params) IPC_STRUCT_MEMBER(int, page_number) IPC_STRUCT_END() -IPC_STRUCT_TRAITS_BEGIN(PrintHostMsg_RequestPrintPreview_Params) - IPC_STRUCT_TRAITS_MEMBER(is_modifiable) - IPC_STRUCT_TRAITS_MEMBER(webnode_only) - IPC_STRUCT_TRAITS_MEMBER(has_selection) - IPC_STRUCT_TRAITS_MEMBER(selection_only) -IPC_STRUCT_TRAITS_END() - IPC_STRUCT_TRAITS_BEGIN(printing::PageSizeMargins) IPC_STRUCT_TRAITS_MEMBER(content_width) IPC_STRUCT_TRAITS_MEMBER(content_height) @@ -183,61 +149,6 @@ IPC_STRUCT_TRAITS_BEGIN(PrintMsg_PrintPages_Params) IPC_STRUCT_TRAITS_MEMBER(pages) IPC_STRUCT_TRAITS_END() -// Parameters to describe a rendered document. -IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewDocument_Params) - // A shared memory handle to metafile data. - IPC_STRUCT_MEMBER(base::SharedMemoryHandle, metafile_data_handle) - - // Size of metafile data. - IPC_STRUCT_MEMBER(uint32, data_size) - - // Cookie for the document to ensure correctness. - IPC_STRUCT_MEMBER(int, document_cookie) - - // Store the expected pages count. - IPC_STRUCT_MEMBER(int, expected_pages_count) - - // Whether the preview can be modified. - IPC_STRUCT_MEMBER(bool, modifiable) - - // The id of the preview request. - IPC_STRUCT_MEMBER(int, preview_request_id) -IPC_STRUCT_END() - -// Parameters to describe a rendered preview page. -IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewPage_Params) - // A shared memory handle to metafile data for a draft document of the page. - IPC_STRUCT_MEMBER(base::SharedMemoryHandle, metafile_data_handle) - - // Size of metafile data. - IPC_STRUCT_MEMBER(uint32, data_size) - - // |page_number| is zero-based and can be |printing::INVALID_PAGE_INDEX| if it - // is just a check. - IPC_STRUCT_MEMBER(int, page_number) - - // The id of the preview request. - IPC_STRUCT_MEMBER(int, preview_request_id) -IPC_STRUCT_END() - -// Parameters sent along with the page count. -IPC_STRUCT_BEGIN(PrintHostMsg_DidGetPreviewPageCount_Params) - // Cookie for the document to ensure correctness. - IPC_STRUCT_MEMBER(int, document_cookie) - - // Total page count. - IPC_STRUCT_MEMBER(int, page_count) - - // Indicates whether the previewed document is modifiable. - IPC_STRUCT_MEMBER(bool, is_modifiable) - - // The id of the preview request. - IPC_STRUCT_MEMBER(int, preview_request_id) - - // Indicates whether the existing preview data needs to be cleared or not. - IPC_STRUCT_MEMBER(bool, clear_preview_data) -IPC_STRUCT_END() - // Parameters to describe a rendered page. IPC_STRUCT_BEGIN(PrintHostMsg_DidPrintPage_Params) // A shared memory handle to the EMF data. This data can be quite large so a @@ -274,19 +185,10 @@ IPC_STRUCT_END() // Messages sent from the browser to the renderer. -// Tells the render view to initiate print preview for the entire document. -IPC_MESSAGE_ROUTED1(PrintMsg_InitiatePrintPreview, bool /* selection_only */) - // Tells the render frame to initiate printing or print preview for a particular // node, depending on which mode the render frame is in. IPC_MESSAGE_ROUTED0(PrintMsg_PrintNodeUnderContextMenu) -// Tells the renderer to print the print preview tab's PDF plugin without -// showing the print dialog. (This is the final step in the print preview -// workflow.) -IPC_MESSAGE_ROUTED1(PrintMsg_PrintForPrintPreview, - base::DictionaryValue /* settings */) - // Tells the render view to switch the CSS to print media type, renders every // requested pages and switch back the CSS to display media type. IPC_MESSAGE_ROUTED0(PrintMsg_PrintPages) @@ -295,15 +197,6 @@ IPC_MESSAGE_ROUTED0(PrintMsg_PrintPages) IPC_MESSAGE_ROUTED1(PrintMsg_PrintingDone, bool /* success */) -// Tells the render view to switch the CSS to print media type, renders every -// requested pages for print preview using the given |settings|. This gets -// called multiple times as the user updates settings. -IPC_MESSAGE_ROUTED1(PrintMsg_PrintPreview, - base::DictionaryValue /* settings */) - -// Like PrintMsg_PrintPages, but using the print preview document's frame/node. -IPC_MESSAGE_ROUTED0(PrintMsg_PrintForSystemDialog) - // Messages sent from the renderer to the browser. #if defined(OS_WIN) @@ -369,14 +262,6 @@ IPC_MESSAGE_CONTROL2(PrintHostMsg_TempFileForPrintingWritten, int /* fd in browser */) // Used only by Chrome OS. #endif -// Asks the browser to do print preview. -IPC_MESSAGE_ROUTED1(PrintHostMsg_RequestPrintPreview, - PrintHostMsg_RequestPrintPreview_Params /* params */) - -// Notify the browser the number of pages in the print preview document. -IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetPreviewPageCount, - PrintHostMsg_DidGetPreviewPageCount_Params /* params */) - // Notify the browser of the default page layout according to the currently // selected printer and page size. // |printable_area_in_points| Specifies the printable area in points. @@ -387,52 +272,9 @@ IPC_MESSAGE_ROUTED3(PrintHostMsg_DidGetDefaultPageLayout, gfx::Rect /* printable area in points */, bool /* has custom page size style */) -// Notify the browser a print preview page has been rendered. -IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPreviewPage, - PrintHostMsg_DidPreviewPage_Params /* params */) - -// Asks the browser whether the print preview has been cancelled. -IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_CheckForCancel, - int32 /* PrintPreviewUI ID */, - int /* request id */, - bool /* print preview cancelled */) - // This is sent when there are invalid printer settings. IPC_MESSAGE_ROUTED0(PrintHostMsg_ShowInvalidPrinterSettingsError) -// Sends back to the browser the complete rendered document (non-draft mode, -// used for printing) that was requested by a PrintMsg_PrintPreview message. -// The memory handle in this message is already valid in the browser process. -IPC_MESSAGE_ROUTED1(PrintHostMsg_MetafileReadyForPrinting, - PrintHostMsg_DidPreviewDocument_Params /* params */) - // Tell the browser printing failed. IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintingFailed, int /* document cookie */) - -// Tell the browser print preview failed. -IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewFailed, - int /* document cookie */) - -// Tell the browser print preview was cancelled. -IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewCancelled, - int /* document cookie */) - -// Tell the browser print preview found the selected printer has invalid -// settings (which typically caused by disconnected network printer or printer -// driver is bogus). -IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewInvalidPrinterSettings, - int /* document cookie */) - -// Run a nested message loop in the renderer until print preview for -// window.print() finishes. -IPC_SYNC_MESSAGE_ROUTED0_0(PrintHostMsg_SetupScriptedPrintPreview) - -// Tell the browser to show the print preview, when the document is sufficiently -// loaded such that the renderer can determine whether it is modifiable or not. -IPC_MESSAGE_ROUTED1(PrintHostMsg_ShowScriptedPrintPreview, - bool /* is_modifiable */) - -// Notify the browser that the PDF in the initiator renderer has disabled print -// scaling option. -IPC_MESSAGE_ROUTED0(PrintHostMsg_PrintPreviewScalingDisabled) diff --git a/chromium_src/chrome/renderer/printing/print_web_view_helper.cc b/chromium_src/chrome/renderer/printing/print_web_view_helper.cc index 67cd1a3..160718d 100644 --- a/chromium_src/chrome/renderer/printing/print_web_view_helper.cc +++ b/chromium_src/chrome/renderer/printing/print_web_view_helper.cc @@ -48,14 +48,6 @@ namespace printing { namespace { -enum PrintPreviewHelperEvents { - PREVIEW_EVENT_REQUESTED, - PREVIEW_EVENT_CACHE_HIT, // Unused - PREVIEW_EVENT_CREATE_DOCUMENT, - PREVIEW_EVENT_NEW_SETTINGS, // Unused - PREVIEW_EVENT_MAX, -}; - const double kMinDpi = 1.0; const char kPageLoadScriptFormat[] = @@ -286,20 +278,6 @@ bool PrintingNodeOrPdfFrame(const blink::WebFrame* frame, return plugin && plugin->supportsPaginatedPrint(); } -bool PrintingFrameHasPageSizeStyle(blink::WebFrame* frame, - int total_page_count) { - if (!frame) - return false; - bool frame_has_custom_page_size_style = false; - for (int i = 0; i < total_page_count; ++i) { - if (frame->hasCustomPageSizeStyle(i)) { - frame_has_custom_page_size_style = true; - break; - } - } - return frame_has_custom_page_size_style; -} - MarginType GetMarginsForPdf(blink::WebFrame* frame, const blink::WebNode& node) { if (frame->isPrintScalingDisabledForPlugin(node)) @@ -308,49 +286,6 @@ MarginType GetMarginsForPdf(blink::WebFrame* frame, return PRINTABLE_AREA_MARGINS; } -bool FitToPageEnabled(const base::DictionaryValue& job_settings) { - bool fit_to_paper_size = false; - if (!job_settings.GetBoolean(kSettingFitToPageEnabled, &fit_to_paper_size)) { - NOTREACHED(); - } - return fit_to_paper_size; -} - -// Returns the print scaling option to retain/scale/crop the source page size -// to fit the printable area of the paper. -// -// We retain the source page size when the current destination printer is -// SAVE_AS_PDF. -// -// We crop the source page size to fit the printable area or we print only the -// left top page contents when -// (1) Source is PDF and the user has requested not to fit to printable area -// via |job_settings|. -// (2) Source is PDF. This is the first preview request and print scaling -// option is disabled for initiator renderer plugin. -// -// In all other cases, we scale the source page to fit the printable area. -blink::WebPrintScalingOption GetPrintScalingOption( - blink::WebFrame* frame, - const blink::WebNode& node, - bool source_is_html, - const base::DictionaryValue& job_settings, - const PrintMsg_Print_Params& params) { - if (params.print_to_pdf) - return blink::WebPrintScalingOptionSourceSize; - - if (!source_is_html) { - if (!FitToPageEnabled(job_settings)) - return blink::WebPrintScalingOptionNone; - - bool no_plugin_scaling = frame->isPrintScalingDisabledForPlugin(node); - - if (params.is_first_request && no_plugin_scaling) - return blink::WebPrintScalingOptionNone; - } - return blink::WebPrintScalingOptionFitToPrintableArea; -} - PrintMsg_Print_Params CalculatePrintParamsForCss( blink::WebFrame* frame, int page_index, @@ -394,10 +329,6 @@ PrintMsg_Print_Params CalculatePrintParamsForCss( return result_params; } -bool IsPrintPreviewEnabled() { - return false; -} - } // namespace FrameReference::FrameReference(blink::WebLocalFrame* frame) { @@ -767,14 +698,11 @@ PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) : content::RenderViewObserver(render_view), content::RenderViewObserverTracker(render_view), reset_prep_frame_view_(false), - is_preview_enabled_(IsPrintPreviewEnabled()), is_print_ready_metafile_sent_(false), ignore_css_margins_(false), notify_browser_of_print_failure_(true), - print_for_preview_(false), print_node_in_progress_(false), is_loading_(false), - is_scripted_preview_delayed_(false), weak_ptr_factory_(this) { } @@ -786,91 +714,25 @@ void PrintWebViewHelper::DidStartLoading() { void PrintWebViewHelper::DidStopLoading() { is_loading_ = false; - ShowScriptedPrintPreview(); } // Prints |frame| which called window.print(). void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame, bool user_initiated) { DCHECK(frame); - - if (is_preview_enabled_) { - print_preview_context_.InitWithFrame(frame); - RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); - } else { - Print(frame, blink::WebNode()); - } + Print(frame, blink::WebNode()); } bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) - IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) - IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) - IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) - IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; } -void PrintWebViewHelper::OnPrintForPrintPreview( - const base::DictionaryValue& job_settings) { - DCHECK(is_preview_enabled_); - // If still not finished with earlier print request simply ignore. - if (prep_frame_view_) - return; - - if (!render_view()->GetWebView()) - return; - blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); - if (!main_frame) - return; - - blink::WebDocument document = main_frame->document(); - // /