Skip to content

Commit

Permalink
Use document from preview for System Dialog printing on Windows.
Browse files Browse the repository at this point in the history
System dialog shows only properties of selected printers, no system dialog with printers.
Removed global Ctrl+Shift+P shortcut on windows.

BUG=374321

Review URL: https://codereview.chromium.org/480303002

Cr-Commit-Position: refs/heads/master@{#292032}
  • Loading branch information
vitalybuka authored and Commit bot committed Aug 26, 2014
1 parent fa29c3e commit 92ab8ce
Show file tree
Hide file tree
Showing 26 changed files with 230 additions and 476 deletions.
3 changes: 3 additions & 0 deletions chrome/browser/printing/print_view_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ PrintViewManager::~PrintViewManager() {
}

bool PrintViewManager::PrintForSystemDialogNow() {
#if defined(OS_WIN)
NOTREACHED();
#endif
return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id()));
}

Expand Down
6 changes: 5 additions & 1 deletion chrome/browser/printing/printing_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ void PrintingMessageFilter::OnUpdatePrintSettingsReply(
params.params.document_cookie = printer_query->cookie();
params.pages = PageRange::GetPages(printer_query->settings().ranges());
}
PrintHostMsg_UpdatePrintSettings::WriteReplyParams(reply_msg, params);
PrintHostMsg_UpdatePrintSettings::WriteReplyParams(
reply_msg,
params,
printer_query &&
(printer_query->last_status() == printing::PrintingContext::CANCEL));
Send(reply_msg);
// If user hasn't cancelled.
if (printer_query.get()) {
Expand Down
12 changes: 10 additions & 2 deletions chrome/browser/resources/print_preview/native_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,18 @@ cr.define('print_preview', function() {
* @param {!print_preview.DocumentInfo} documentInfo Document data model.
* @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the
* system's preview application.
* @param {boolean=} opt_showSystemDialog Whether to open system dialog for
* advanced settings.
*/
startPrint: function(destination, printTicketStore, cloudPrintInterface,
documentInfo, opt_isOpenPdfInPreview) {
documentInfo, opt_isOpenPdfInPreview,
opt_showSystemDialog) {
assert(printTicketStore.isTicketValid(),
'Trying to print when ticket is not valid');

assert(!opt_showSystemDialog || (cr.isWindows && destination.isLocal),
'Implemented for Windows only');

var ticket = {
'pageRange': printTicketStore.pageRange.getDocumentPageRanges(),
'mediaSize': printTicketStore.mediaSize.getValue(),
Expand All @@ -304,7 +310,8 @@ cr.define('print_preview', function() {
'requestID': -1,
'fitToPageEnabled': printTicketStore.fitToPage.getValue(),
'pageWidth': documentInfo.pageSize.width,
'pageHeight': documentInfo.pageSize.height
'pageHeight': documentInfo.pageSize.height,
'showSystemDialog': opt_showSystemDialog
};

if (!destination.isLocal) {
Expand Down Expand Up @@ -347,6 +354,7 @@ cr.define('print_preview', function() {

/** Shows the system's native printing dialog. */
startShowSystemDialog: function() {
assert(!cr.isWindows);
chrome.send('showSystemDialog');
},

Expand Down
51 changes: 47 additions & 4 deletions chrome/browser/resources/print_preview/print_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ cr.define('print_preview', function() {
*/
this.isInAppKioskMode_ = false;

/**
* Whether Print with System Dialog option is available.
* @type {boolean}
* @private
*/
this.isSystemDialogAvailable_ = false;

/**
* State of the print preview UI.
* @type {print_preview.PrintPreview.UiState_}
Expand All @@ -243,6 +250,13 @@ cr.define('print_preview', function() {
* @private
*/
this.isPreviewGenerationInProgress_ = true;

/**
* Whether to show system dialog before next printing.
* @type {boolean}
* @private
*/
this.showSystemDialogBeforeNextPrint_ = false;
};

/**
Expand Down Expand Up @@ -538,7 +552,9 @@ cr.define('print_preview', function() {
this.printTicketStore_,
this.cloudPrintInterface_,
this.documentInfo_,
this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW);
this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW,
this.showSystemDialogBeforeNextPrint_);
this.showSystemDialogBeforeNextPrint_ = false;
}
return PrintPreview.PrintAttemptResult_.PRINTED;
},
Expand All @@ -558,6 +574,13 @@ cr.define('print_preview', function() {
* @private
*/
openSystemPrintDialog_: function() {
if (!this.shouldShowSystemDialogLink_())
return;
if (cr.isWindows) {
this.showSystemDialogBeforeNextPrint_ = true;
this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/);
return;
}
setIsVisible($('system-dialog-throbber'), true);
this.setIsEnabled_(false);
this.uiState_ = PrintPreview.UiState_.OPENING_NATIVE_PRINT_DIALOG;
Expand Down Expand Up @@ -599,9 +622,9 @@ cr.define('print_preview', function() {
this.appState_.setInitialized();

$('document-title').innerText = settings.documentTitle;
setIsVisible($('system-dialog-link'),
!settings.hidePrintWithSystemDialogLink &&
!settings.isInAppKioskMode);
this.isSystemDialogAvailable_ = !settings.hidePrintWithSystemDialogLink &&
!settings.isInAppKioskMode;
setIsVisible($('system-dialog-link'), this.shouldShowSystemDialogLink_());
},

/**
Expand Down Expand Up @@ -1080,6 +1103,23 @@ cr.define('print_preview', function() {
}
},

/**
* Returns true if "Print using system dialog" link should be shown for
* current destination.
* @return {boolean} Returns true if link should be shown.
*/
shouldShowSystemDialogLink_: function() {
if (!this.isSystemDialogAvailable_)
return false;
if (!cr.isWindows)
return true;
var selectedDest = this.destinationStore_.selectedDestination;
return selectedDest &&
selectedDest.origin == print_preview.Destination.Origin.LOCAL &&
selectedDest.id !=
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF;
},

/**
* Called when the open-cloud-print-dialog link is clicked. Opens the Google
* Cloud Print web dialog.
Expand All @@ -1105,6 +1145,9 @@ cr.define('print_preview', function() {
setIsVisible(
$('cloud-print-dialog-link'),
selectedDest && !cr.isChromeOS && !selectedDest.isLocal);
setIsVisible(
$('system-dialog-link'),
this.shouldShowSystemDialogLink_());
if (selectedDest && this.isInKioskAutoPrintMode_) {
this.onPrintButtonClick_();
}
Expand Down
11 changes: 9 additions & 2 deletions chrome/browser/ui/webui/print_preview/print_preview_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,15 @@ void PrintPreviewHandler::HandlePrint(const base::ListValue* args) {
ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT);
SendCloudPrintJob(data.get());
} else {
UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", page_count);
ReportUserActionHistogram(PRINT_TO_PRINTER);
bool system_dialog = false;
settings->GetBoolean(printing::kSettingShowSystemDialog, &system_dialog);
if (system_dialog) {
UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.SystemDialog", page_count);
ReportUserActionHistogram(FALLBACK_TO_ADVANCED_SETTINGS_DIALOG);
} else {
UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", page_count);
ReportUserActionHistogram(PRINT_TO_PRINTER);
}
ReportPrintSettingsStats(*settings);

// This tries to activate the initiator as well, so do not clear the
Expand Down
5 changes: 3 additions & 2 deletions chrome/common/print_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,11 @@ IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_GetDefaultPrintSettings,

// The renderer wants to update the current print settings with new
// |job_settings|.
IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_UpdatePrintSettings,
IPC_SYNC_MESSAGE_ROUTED2_2(PrintHostMsg_UpdatePrintSettings,
int /* document_cookie */,
base::DictionaryValue /* job_settings */,
PrintMsg_PrintPages_Params /* current_settings */)
PrintMsg_PrintPages_Params /* current_settings */,
bool /* canceled */)

// It's the renderer that controls the printing process when it is generated
// by javascript. This step is about showing UI to the user to select the
Expand Down
5 changes: 4 additions & 1 deletion chrome/renderer/chrome_mock_render_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ void ChromeMockRenderThread::OnCheckForCancel(int32 preview_ui_id,
void ChromeMockRenderThread::OnUpdatePrintSettings(
int document_cookie,
const base::DictionaryValue& job_settings,
PrintMsg_PrintPages_Params* params) {
PrintMsg_PrintPages_Params* params,
bool* canceled) {
if (canceled)
*canceled = false;
// Check and make sure the required settings are all there.
// We don't actually care about the values.
std::string dummy_string;
Expand Down
3 changes: 2 additions & 1 deletion chrome/renderer/chrome_mock_render_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class ChromeMockRenderThread : public content::MockRenderThread {
// For print preview, PrintWebViewHelper will update settings.
void OnUpdatePrintSettings(int document_cookie,
const base::DictionaryValue& job_settings,
PrintMsg_PrintPages_Params* params);
PrintMsg_PrintPages_Params* params,
bool* canceled);

// A mock printer device used for printing tests.
scoped_ptr<MockPrinter> printer_;
Expand Down
7 changes: 6 additions & 1 deletion chrome/renderer/printing/print_web_view_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1464,8 +1464,13 @@ bool PrintWebViewHelper::UpdatePrintSettings(
int cookie = print_pages_params_ ?
print_pages_params_->params.document_cookie : 0;
PrintMsg_PrintPages_Params settings;
bool canceled = false;
Send(new PrintHostMsg_UpdatePrintSettings(
routing_id(), cookie, *job_settings, &settings));
routing_id(), cookie, *job_settings, &settings, &canceled));
if (canceled) {
notify_browser_of_print_failure_ = false;
return false;
}

if (!job_settings->GetInteger(kPreviewUIID, &settings.params.preview_ui_id)) {
NOTREACHED();
Expand Down
32 changes: 32 additions & 0 deletions printing/backend/win_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,36 @@ scoped_ptr<DEVMODE, base::FreeDeleter> CreateDevMode(HANDLE printer,
return out.Pass();
}

scoped_ptr<DEVMODE, base::FreeDeleter> PromptDevMode(
HANDLE printer,
const base::string16& printer_name,
DEVMODE* in,
HWND window,
bool* canceled) {
LONG buffer_size =
DocumentProperties(window,
printer,
const_cast<wchar_t*>(printer_name.c_str()),
NULL,
NULL,
0);
if (buffer_size < static_cast<int>(sizeof(DEVMODE)))
return scoped_ptr<DEVMODE, base::FreeDeleter>();
scoped_ptr<DEVMODE, base::FreeDeleter> out(
reinterpret_cast<DEVMODE*>(malloc(buffer_size)));
DWORD flags = (in ? (DM_IN_BUFFER) : 0) | DM_OUT_BUFFER | DM_IN_PROMPT;
LONG result = DocumentProperties(window,
printer,
const_cast<wchar_t*>(printer_name.c_str()),
out.get(),
in,
flags);
if (canceled)
*canceled = (result == IDCANCEL);
if (result != IDOK)
return scoped_ptr<DEVMODE, base::FreeDeleter>();
CHECK_GE(buffer_size, out.get()->dmSize + out.get()->dmDriverExtra);
return out.Pass();
}

} // namespace printing
8 changes: 8 additions & 0 deletions printing/backend/win_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ PRINTING_EXPORT scoped_ptr<DEVMODE, base::FreeDeleter> CreateDevMode(
HANDLE printer,
DEVMODE* in);

// Prompts for new DEVMODE. If |in| is not NULL copy settings from there.
PRINTING_EXPORT scoped_ptr<DEVMODE, base::FreeDeleter> PromptDevMode(
HANDLE printer,
const base::string16& printer_name,
DEVMODE* in,
HWND window,
bool* canceled);

} // namespace printing

#endif // PRINTING_BACKEND_WIN_HELPER_H_
3 changes: 3 additions & 0 deletions printing/print_job_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ const char kSettingShouldPrintBackgrounds[] = "shouldPrintBackgrounds";
// Whether to print selection only.
const char kSettingShouldPrintSelectionOnly[] = "shouldPrintSelectionOnly";

// Whether to print selection only.
const char kSettingShowSystemDialog[] = "showSystemDialog";

// Indices used to represent first preview page and complete preview document.
const int FIRST_PAGE_INDEX = 0;
const int COMPLETE_PREVIEW_DOCUMENT_INDEX = -1;
Expand Down
1 change: 1 addition & 0 deletions printing/print_job_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ PRINTING_EXPORT extern const char kSettingPrinterOptions[];
PRINTING_EXPORT extern const char kSettingTicket[];
PRINTING_EXPORT extern const char kSettingShouldPrintBackgrounds[];
PRINTING_EXPORT extern const char kSettingShouldPrintSelectionOnly[];
PRINTING_EXPORT extern const char kSettingShowSystemDialog[];

PRINTING_EXPORT extern const int FIRST_PAGE_INDEX;
PRINTING_EXPORT extern const int COMPLETE_PREVIEW_DOCUMENT_INDEX;
Expand Down
6 changes: 5 additions & 1 deletion printing/printing_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ PrintingContext::Result PrintingContext::UpdatePrintSettings(
return OK;
}

return UpdatePrinterSettings(open_in_external_preview);
bool show_system_dialog = false;
job_settings.GetBoolean(printing::kSettingShowSystemDialog,
&show_system_dialog);

return UpdatePrinterSettings(open_in_external_preview, show_system_dialog);
}

} // namespace printing
3 changes: 2 additions & 1 deletion printing/printing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class PRINTING_EXPORT PrintingContext {
// Updates printer settings.
// |external_preview| is true if pdf is going to be opened in external
// preview. Used by MacOS only now to open Preview.app.
virtual Result UpdatePrinterSettings(bool external_preview) = 0;
virtual Result UpdatePrinterSettings(bool external_preview,
bool show_system_dialog) = 0;

// Updates Print Settings. |job_settings| contains all print job
// settings information. |ranges| has the new page range settings.
Expand Down
4 changes: 3 additions & 1 deletion printing/printing_context_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ gfx::Size PrintingContextAndroid::GetPdfPaperSizeDeviceUnits() {
}

PrintingContext::Result PrintingContextAndroid::UpdatePrinterSettings(
bool external_preview) {
bool external_preview,
bool show_system_dialog) {
DCHECK(!show_system_dialog);
DCHECK(!in_print_job_);

// Intentional No-op.
Expand Down
3 changes: 2 additions & 1 deletion printing/printing_context_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class PRINTING_EXPORT PrintingContextAndroid : public PrintingContext {
const PrintSettingsCallback& callback) OVERRIDE;
virtual Result UseDefaultSettings() OVERRIDE;
virtual gfx::Size GetPdfPaperSizeDeviceUnits() OVERRIDE;
virtual Result UpdatePrinterSettings(bool external_preview) OVERRIDE;
virtual Result UpdatePrinterSettings(bool external_preview,
bool show_system_dialog) OVERRIDE;
virtual Result InitWithSettings(const PrintSettings& settings) OVERRIDE;
virtual Result NewDocument(const base::string16& document_name) OVERRIDE;
virtual Result NewPage() OVERRIDE;
Expand Down
4 changes: 3 additions & 1 deletion printing/printing_context_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ gfx::Size PrintingContextLinux::GetPdfPaperSizeDeviceUnits() {
}

PrintingContext::Result PrintingContextLinux::UpdatePrinterSettings(
bool external_preview) {
bool external_preview,
bool show_system_dialog) {
DCHECK(!show_system_dialog);
DCHECK(!in_print_job_);
DCHECK(!external_preview) << "Not implemented";

Expand Down
3 changes: 2 additions & 1 deletion printing/printing_context_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class PRINTING_EXPORT PrintingContextLinux : public PrintingContext {
const PrintSettingsCallback& callback) OVERRIDE;
virtual gfx::Size GetPdfPaperSizeDeviceUnits() OVERRIDE;
virtual Result UseDefaultSettings() OVERRIDE;
virtual Result UpdatePrinterSettings(bool external_preview) OVERRIDE;
virtual Result UpdatePrinterSettings(bool external_preview,
bool show_system_dialog) OVERRIDE;
virtual Result InitWithSettings(const PrintSettings& settings) OVERRIDE;
virtual Result NewDocument(const base::string16& document_name) OVERRIDE;
virtual Result NewPage() OVERRIDE;
Expand Down
3 changes: 2 additions & 1 deletion printing/printing_context_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class PRINTING_EXPORT PrintingContextMac : public PrintingContext {
const PrintSettingsCallback& callback) OVERRIDE;
virtual Result UseDefaultSettings() OVERRIDE;
virtual gfx::Size GetPdfPaperSizeDeviceUnits() OVERRIDE;
virtual Result UpdatePrinterSettings(bool external_preview) OVERRIDE;
virtual Result UpdatePrinterSettings(bool external_preview,
bool show_system_dialog) OVERRIDE;
virtual Result InitWithSettings(const PrintSettings& settings) OVERRIDE;
virtual Result NewDocument(const base::string16& document_name) OVERRIDE;
virtual Result NewPage() OVERRIDE;
Expand Down
4 changes: 3 additions & 1 deletion printing/printing_context_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ PMPaper MatchPaper(CFArrayRef paper_list,
}

PrintingContext::Result PrintingContextMac::UpdatePrinterSettings(
bool external_preview) {
bool external_preview,
bool show_system_dialog) {
DCHECK(!show_system_dialog);
DCHECK(!in_print_job_);

// NOTE: Reset |print_info_| with a copy of |sharedPrintInfo| so as to start
Expand Down
4 changes: 3 additions & 1 deletion printing/printing_context_no_system_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() {
}

PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings(
bool external_preview) {
bool external_preview,
bool show_system_dialog) {
DCHECK(!show_system_dialog);

if (settings_.dpi() == 0)
UseDefaultSettings();
Expand Down
Loading

0 comments on commit 92ab8ce

Please sign in to comment.