summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-15 16:25:09 +0000
committerkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-15 16:25:09 +0000
commitc797a198d5798753a2029133a5f0b94e2fed9d59 (patch)
tree40f0b8c0af4caa8c41d34a6c16bb569bf465478c
parent823a51b179f3bb00f3833f6ab438064ee0b64572 (diff)
downloadchromium_src-c797a198d5798753a2029133a5f0b94e2fed9d59.zip
chromium_src-c797a198d5798753a2029133a5f0b94e2fed9d59.tar.gz
chromium_src-c797a198d5798753a2029133a5f0b94e2fed9d59.tar.bz2
Print preview should use draft PDFs until it is ready to print to improve speed.
BUG=85767 TEST=none Review URL: http://codereview.chromium.org/7149020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89198 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/resources/print_preview.js33
-rw-r--r--chrome/browser/ui/webui/print_preview_handler.cc5
-rw-r--r--chrome/browser/ui/webui/print_preview_handler.h1
-rw-r--r--chrome/browser/ui/webui/print_preview_ui.cc4
-rw-r--r--chrome/browser/ui/webui/print_preview_ui.h3
-rw-r--r--chrome/renderer/print_web_view_helper.cc11
-rw-r--r--chrome/renderer/print_web_view_helper.h9
-rw-r--r--chrome/renderer/print_web_view_helper_linux.cc3
-rw-r--r--chrome/renderer/print_web_view_helper_mac.mm3
-rw-r--r--chrome/renderer/print_web_view_helper_win.cc3
-rw-r--r--printing/emf_win.h2
-rw-r--r--printing/metafile.h5
-rw-r--r--printing/pdf_metafile_cairo_linux.h2
-rw-r--r--printing/pdf_metafile_cg_mac.h2
-rw-r--r--printing/pdf_metafile_skia.cc7
-rw-r--r--printing/pdf_metafile_skia.h6
-rw-r--r--printing/print_job_constants.cc3
-rw-r--r--printing/print_job_constants.h1
18 files changed, 90 insertions, 13 deletions
diff --git a/chrome/browser/resources/print_preview.js b/chrome/browser/resources/print_preview.js
index 9ced90c..5902ed0 100644
--- a/chrome/browser/resources/print_preview.js
+++ b/chrome/browser/resources/print_preview.js
@@ -45,6 +45,9 @@ var hasError = false;
// True when preview tab is hidden.
var isTabHidden = false;
+// True when draft preview data is requested for preview.
+var draftDocument = true;
+
/**
* Window onload handler, sets up the page and starts print preview by getting
* the printer list.
@@ -346,7 +349,8 @@ function getSettingsJSON() {
'collate': isCollated(),
'landscape': isLandscape(),
'color': isColor(),
- 'printToPDF': printToPDF});
+ 'printToPDF': printToPDF,
+ 'draftDocument': draftDocument});
}
/**
@@ -367,9 +371,10 @@ function getSelectedPrinterName() {
*/
function printFile() {
hasPendingPrintFileRequest = hasPendingPreviewRequest;
+ var deviceName = getSelectedPrinterName();
if (hasPendingPrintFileRequest) {
- if (getSelectedPrinterName() != PRINT_TO_PDF) {
+ if (deviceName != PRINT_TO_PDF) {
isTabHidden = true;
chrome.send('hidePreview');
}
@@ -382,7 +387,13 @@ function printFile() {
return;
}
- if (isTabHidden || getSelectedPrinterName() == PRINT_TO_PDF) {
+ if (draftDocument) {
+ hasPendingPrintFileRequest = true;
+ requestPrintPreview();
+ return;
+ }
+
+ if (isTabHidden || deviceName == PRINT_TO_PDF) {
sendPrintFileRequest();
} else {
$('print-button').classList.add('loading');
@@ -392,6 +403,7 @@ function printFile() {
window.setTimeout(function() { sendPrintFileRequest(); }, 1000);
}
}
+
/**
* Sends a message to cancel the pending print request.
*/
@@ -413,11 +425,24 @@ function requestPrintPreview() {
hasPendingPreviewRequest = true;
removeEventListeners();
printSettings.save();
- showLoadingAnimation();
+ if (isTabHidden || hasPendingPrintFileRequest)
+ draftDocument = false;
+ else
+ showLoadingAnimation();
+
chrome.send('getPreview', [getSettingsJSON()]);
}
/**
+ * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print
+ * preview tab regarding the file selection cancel event.
+ */
+function fileSelectionCancelled() {
+ draftDocument = true;
+ hasPendingPrintFileRequest = false;
+}
+
+/**
* Set the default printer. If there is one, generate a print preview.
* @param {string} printer Name of the default printer. Empty if none.
*/
diff --git a/chrome/browser/ui/webui/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview_handler.cc
index 582814d..aff52a5 100644
--- a/chrome/browser/ui/webui/print_preview_handler.cc
+++ b/chrome/browser/ui/webui/print_preview_handler.cc
@@ -683,6 +683,11 @@ void PrintPreviewHandler::FileSelected(const FilePath& path,
ActivateInitiatorTabAndClosePreviewTab();
}
+void PrintPreviewHandler::FileSelectionCanceled(void* params) {
+ PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_);
+ print_preview_ui->OnFileSelectionCancelled();
+}
+
void PrintPreviewHandler::HidePreviewTab() {
TabContentsWrapper* preview_tab_wrapper =
TabContentsWrapper::GetCurrentWrapperForContents(preview_tab());
diff --git a/chrome/browser/ui/webui/print_preview_handler.h b/chrome/browser/ui/webui/print_preview_handler.h
index 0d91409..04e12a6 100644
--- a/chrome/browser/ui/webui/print_preview_handler.h
+++ b/chrome/browser/ui/webui/print_preview_handler.h
@@ -33,6 +33,7 @@ class PrintPreviewHandler : public WebUIMessageHandler,
// SelectFileDialog::Listener implementation.
virtual void FileSelected(const FilePath& path, int index, void* params);
+ virtual void FileSelectionCanceled(void* params);
// Displays a modal dialog, prompting the user to select a file.
void SelectFile(const FilePath& default_path);
diff --git a/chrome/browser/ui/webui/print_preview_ui.cc b/chrome/browser/ui/webui/print_preview_ui.cc
index 832cf52..89bcab0 100644
--- a/chrome/browser/ui/webui/print_preview_ui.cc
+++ b/chrome/browser/ui/webui/print_preview_ui.cc
@@ -69,6 +69,10 @@ void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count,
is_preview_modifiable, ui_identifier);
}
+void PrintPreviewUI::OnFileSelectionCancelled() {
+ CallJavascriptFunction("fileSelectionCancelled");
+}
+
PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() {
return PrintPreviewDataService::GetInstance();
}
diff --git a/chrome/browser/ui/webui/print_preview_ui.h b/chrome/browser/ui/webui/print_preview_ui.h
index 58ceda8..d55f306 100644
--- a/chrome/browser/ui/webui/print_preview_ui.h
+++ b/chrome/browser/ui/webui/print_preview_ui.h
@@ -44,6 +44,9 @@ class PrintPreviewUI : public ChromeWebUI {
// message.
void OnInitiatorTabClosed(const std::string& initiator_tab_url);
+ // Notify the Web UI renderer that file selection has been cancelled.
+ void OnFileSelectionCancelled();
+
private:
// Helper function
PrintPreviewDataService* print_preview_data_service();
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index 079d666..ff76964 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -18,6 +18,7 @@
#include "content/renderer/render_view.h"
#include "grit/generated_resources.h"
#include "printing/metafile.h"
+#include "printing/print_job_constants.h"
#include "printing/units.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
@@ -348,8 +349,11 @@ void PrintWebViewHelper::PrintPreview(WebKit::WebFrame* frame,
return;
}
+ bool draft;
+ settings.GetBoolean(printing::kSettingDraftDocument, &draft);
+
// Render Pages for printing.
- if (!RenderPagesForPreview(frame, node))
+ if (!RenderPagesForPreview(frame, node, draft))
DidFinishPrinting(FAIL_PREVIEW);
}
@@ -649,12 +653,13 @@ bool PrintWebViewHelper::RenderPagesForPrint(WebKit::WebFrame* frame,
}
bool PrintWebViewHelper::RenderPagesForPreview(WebKit::WebFrame* frame,
- WebKit::WebNode* node) {
+ WebKit::WebNode* node,
+ bool draft) {
PrintMsg_PrintPages_Params print_settings = *print_pages_params_;
// PDF printer device supports alpha blending.
print_settings.params.supports_alpha_blend = true;
// TODO(kmadhusu): Handle print selection.
- return CreatePreviewDocument(print_settings, frame, node);
+ return CreatePreviewDocument(print_settings, frame, node, draft);
}
base::TimeTicks PrintWebViewHelper::ReportPreviewPageRenderTime(
diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h
index 0899ed7..ccae1e8 100644
--- a/chrome/renderer/print_web_view_helper.h
+++ b/chrome/renderer/print_web_view_helper.h
@@ -176,14 +176,19 @@ class PrintWebViewHelper : public RenderViewObserver ,
bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node);
// Render the frame for preview.
- bool RenderPagesForPreview(WebKit::WebFrame* frame, WebKit::WebNode* node);
+ // |draft| is true when the output is only going to the screen and not the
+ // printer.
+ bool RenderPagesForPreview(WebKit::WebFrame* frame,
+ WebKit::WebNode* node,
+ bool draft);
// Renders all the pages listed in |params| for preview.
// On success, Send PrintHostMsg_PagesReadyForPreview message with a
// valid metafile data handle.
bool CreatePreviewDocument(const PrintMsg_PrintPages_Params& params,
WebKit::WebFrame* frame,
- WebKit::WebNode* node);
+ WebKit::WebNode* node,
+ bool draft);
// Platform specific helper function for rendering page(s) to |metafile|.
#if defined(OS_WIN)
diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc
index 08042b9..bb7a642 100644
--- a/chrome/renderer/print_web_view_helper_linux.cc
+++ b/chrome/renderer/print_web_view_helper_linux.cc
@@ -27,9 +27,10 @@ using WebKit::WebNode;
bool PrintWebViewHelper::CreatePreviewDocument(
const PrintMsg_PrintPages_Params& params, WebKit::WebFrame* frame,
- WebKit::WebNode* node) {
+ WebKit::WebNode* node, bool draft) {
int page_count = 0;
printing::PreviewMetafile metafile;
+ metafile.set_draft(draft);
if (!metafile.Init())
return false;
diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/print_web_view_helper_mac.mm
index e46320e..9105a11 100644
--- a/chrome/renderer/print_web_view_helper_mac.mm
+++ b/chrome/renderer/print_web_view_helper_mac.mm
@@ -55,7 +55,7 @@ void PrintWebViewHelper::PrintPageInternal(
bool PrintWebViewHelper::CreatePreviewDocument(
const PrintMsg_PrintPages_Params& params, WebKit::WebFrame* frame,
- WebKit::WebNode* node) {
+ WebKit::WebNode* node, bool draft) {
PrintMsg_Print_Params printParams = params.params;
UpdatePrintableSizeInPrintParameters(frame, node, &printParams);
@@ -67,6 +67,7 @@ bool PrintWebViewHelper::CreatePreviewDocument(
return false;
printing::PreviewMetafile metafile;
+ metafile.set_draft(draft);
if (!metafile.Init())
return false;
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc
index 8f55288..58cb354 100644
--- a/chrome/renderer/print_web_view_helper_win.cc
+++ b/chrome/renderer/print_web_view_helper_win.cc
@@ -125,7 +125,7 @@ void PrintWebViewHelper::PrintPageInternal(
bool PrintWebViewHelper::CreatePreviewDocument(
const PrintMsg_PrintPages_Params& params, WebKit::WebFrame* frame,
- WebKit::WebNode* node) {
+ WebKit::WebNode* node, bool draft) {
int page_count = 0;
PrintMsg_Print_Params print_params = params.params;
UpdatePrintableSizeInPrintParameters(frame, node, &print_params);
@@ -136,6 +136,7 @@ bool PrintWebViewHelper::CreatePreviewDocument(
return false;
scoped_ptr<Metafile> metafile(new printing::PreviewMetafile);
+ metafile->set_draft(draft);
metafile->Init();
// Calculate the dpi adjustment.
diff --git a/printing/emf_win.h b/printing/emf_win.h
index f7e0ed5..7b8dab6 100644
--- a/printing/emf_win.h
+++ b/printing/emf_win.h
@@ -84,6 +84,8 @@ class Emf : public Metafile {
return emf_;
}
+ virtual void set_draft(bool /* draft */) const {}
+
private:
FRIEND_TEST_ALL_PREFIXES(EmfTest, DC);
FRIEND_TEST_ALL_PREFIXES(EmfPrintingTest, PageBreak);
diff --git a/printing/metafile.h b/printing/metafile.h
index 84c0556..2ec1d78 100644
--- a/printing/metafile.h
+++ b/printing/metafile.h
@@ -143,6 +143,11 @@ class Metafile {
// Returns true if writing succeeded.
virtual bool SaveToFD(const base::FileDescriptor& fd) const = 0;
#endif // if defined(OS_CHROMEOS)
+
+ // Sets the flag to create a draft metafile.
+ // NOTE: Draft metafile does not include font embedding, compression, etc.
+ // This is currently used only in print preview workflow.
+ virtual void set_draft(bool draft) const = 0;
};
} // namespace printing
diff --git a/printing/pdf_metafile_cairo_linux.h b/printing/pdf_metafile_cairo_linux.h
index 6f07ae0..7919980 100644
--- a/printing/pdf_metafile_cairo_linux.h
+++ b/printing/pdf_metafile_cairo_linux.h
@@ -60,6 +60,8 @@ class PdfMetafileCairo : public Metafile {
virtual bool SaveToFD(const base::FileDescriptor& fd) const;
#endif // if defined(OS_CHROMEOS)
+ virtual void set_draft(bool /* draft */) const {}
+
private:
// Cleans up all resources.
void CleanUpAll();
diff --git a/printing/pdf_metafile_cg_mac.h b/printing/pdf_metafile_cg_mac.h
index 5a7f56d..303cfd5 100644
--- a/printing/pdf_metafile_cg_mac.h
+++ b/printing/pdf_metafile_cg_mac.h
@@ -65,6 +65,8 @@ class PdfMetafileCg : public Metafile, public base::ThreadChecker {
bool center_horizontally,
bool center_vertically) const;
+ virtual void set_draft(bool /* draft */) const {}
+
private:
// Returns a CGPDFDocumentRef version of pdf_data_.
CGPDFDocumentRef GetPDFDocument() const;
diff --git a/printing/pdf_metafile_skia.cc b/printing/pdf_metafile_skia.cc
index beda36f..bcb5af93 100644
--- a/printing/pdf_metafile_skia.cc
+++ b/printing/pdf_metafile_skia.cc
@@ -195,6 +195,11 @@ bool PdfMetafileSkia::SaveToFD(const base::FileDescriptor& fd) const {
}
#endif
-PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) {}
+PdfMetafileSkia::PdfMetafileSkia()
+ : data_(new PdfMetafileSkiaData),
+ draft_(false) {}
+void PdfMetafileSkia::set_draft(bool draft) const {
+ draft_ = draft;
+}
} // namespace printing
diff --git a/printing/pdf_metafile_skia.h b/printing/pdf_metafile_skia.h
index 0ad2afb..3d1c7bd 100644
--- a/printing/pdf_metafile_skia.h
+++ b/printing/pdf_metafile_skia.h
@@ -59,9 +59,15 @@ class PdfMetafileSkia : public Metafile {
#if defined(OS_CHROMEOS)
virtual bool SaveToFD(const base::FileDescriptor& fd) const;
#endif // if defined(OS_CHROMEOS)
+
+ virtual void set_draft(bool draft) const;
+
private:
scoped_ptr<PdfMetafileSkiaData> data_;
+ // True when a draft version of metafile is requested.
+ mutable bool draft_;
+
DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
};
diff --git a/printing/print_job_constants.cc b/printing/print_job_constants.cc
index d8eb0ce..5f72252 100644
--- a/printing/print_job_constants.cc
+++ b/printing/print_job_constants.cc
@@ -39,4 +39,7 @@ const char kSettingPrinterName[] = "printerName";
// Print to PDF option: true if selected, false if not.
const char kSettingPrintToPDF[] = "printToPDF";
+// True when draft preview document is required.
+const char kSettingDraftDocument[] = "draftDocument";
+
} // namespace printing
diff --git a/printing/print_job_constants.h b/printing/print_job_constants.h
index 0f43b7f..8ee5e7f 100644
--- a/printing/print_job_constants.h
+++ b/printing/print_job_constants.h
@@ -11,6 +11,7 @@ extern const char kSettingCollate[];
extern const char kSettingColor[];
extern const char kSettingCopies[];
extern const char kSettingDeviceName[];
+extern const char kSettingDraftDocument[];
extern const char kSettingDuplexMode[];
extern const char kSettingLandscape[];
extern const char kSettingPageRange[];