Commit 3276e3b9 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Printing: Fix problems with system dialog and hidden preview

Bug: 796057
Change-Id: Ifda86af778af0fabf1153189a193c92b36727a1c
Reviewed-on: https://chromium-review.googlesource.com/834690Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525207}
parent e748d831
...@@ -196,6 +196,20 @@ void PrintViewManagerBase::OnPrintSettingsDone( ...@@ -196,6 +196,20 @@ void PrintViewManagerBase::OnPrintSettingsDone(
scoped_refptr<printing::PrinterQuery> printer_query) { scoped_refptr<printing::PrinterQuery> printer_query) {
queue_->QueuePrinterQuery(printer_query.get()); queue_->QueuePrinterQuery(printer_query.get());
// Check if the job was cancelled. This should only happen on Windows when
// the system dialog is cancelled.
if (printer_query &&
printer_query->last_status() == PrintingContext::CANCEL) {
#if defined(OS_WIN)
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::BindOnce(&PrintViewManagerBase::SystemDialogCancelled,
base::Unretained(this)));
#endif
std::move(callback).Run(base::Value());
return;
}
// Post task so that the query has time to reset the callback before calling // Post task so that the query has time to reset the callback before calling
// OnDidGetPrintedPagesCount. // OnDidGetPrintedPagesCount.
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
...@@ -380,6 +394,7 @@ void PrintViewManagerBase::RenderFrameDeleted( ...@@ -380,6 +394,7 @@ void PrintViewManagerBase::RenderFrameDeleted(
void PrintViewManagerBase::SystemDialogCancelled() { void PrintViewManagerBase::SystemDialogCancelled() {
// System dialog was cancelled. Clean up the print job and notify the // System dialog was cancelled. Clean up the print job and notify the
// BackgroundPrintingManager. // BackgroundPrintingManager.
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
ReleasePrinterQuery(); ReleasePrinterQuery();
TerminatePrintJob(true); TerminatePrintJob(true);
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "chrome/browser/app_mode/app_mode_utils.h" #include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/bad_message.h" #include "chrome/browser/bad_message.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/printing/background_printing_manager.h"
#include "chrome/browser/printing/print_dialog_cloud.h" #include "chrome/browser/printing/print_dialog_cloud.h"
#include "chrome/browser/printing/print_error_dialog.h" #include "chrome/browser/printing/print_error_dialog.h"
#include "chrome/browser/printing/print_job_manager.h" #include "chrome/browser/printing/print_job_manager.h"
...@@ -1250,11 +1251,20 @@ void PrintPreviewHandler::OnGotExtensionPrinterInfo( ...@@ -1250,11 +1251,20 @@ void PrintPreviewHandler::OnGotExtensionPrinterInfo(
void PrintPreviewHandler::OnPrintResult(const std::string& callback_id, void PrintPreviewHandler::OnPrintResult(const std::string& callback_id,
const base::Value& error) { const base::Value& error) {
if (error.is_none()) { if (error.is_none())
ResolveJavascriptCallback(base::Value(callback_id), error); ResolveJavascriptCallback(base::Value(callback_id), error);
return; else
RejectJavascriptCallback(base::Value(callback_id), error);
// Remove the preview dialog from the background printing manager if it is
// being stored there. Since the PDF has been sent and the callback is
// resolved or rejected, it is no longer needed and can be destroyed.
printing::BackgroundPrintingManager* background_printing_manager =
g_browser_process->background_printing_manager();
if (background_printing_manager->HasPrintPreviewDialog(
preview_web_contents())) {
background_printing_manager->OnPrintRequestCancelled(
preview_web_contents());
} }
RejectJavascriptCallback(base::Value(callback_id), error);
} }
void PrintPreviewHandler::RegisterForGaiaCookieChanges() { void PrintPreviewHandler::RegisterForGaiaCookieChanges() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment