| Index: chrome/browser/ui/webui/print_preview/print_preview_handler.cc
|
| diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
|
| index 7b05dfc3789aaa63bce6b0c9bdd9e77f48ce1e9e..c513aab5256f7d044d2af960f71d001299d9342a 100644
|
| --- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
|
| +++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
|
| @@ -782,18 +782,30 @@ void PrintPreviewHandler::HandleGetExtensionPrinterCapabilities(
|
| }
|
|
|
| void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) {
|
| - DCHECK_EQ(2U, args->GetSize());
|
| + DCHECK_EQ(3U, args->GetSize());
|
| + std::string callback_id;
|
| std::string json_str;
|
| - if (!args->GetString(0, &json_str))
|
| + CHECK(args->GetString(0, &callback_id));
|
| + if (!args->GetString(1, &json_str)) {
|
| + RejectJavascriptCallback(base::Value(callback_id),
|
| + base::Value("INVALID_SETTINGS"));
|
| return;
|
| + }
|
| std::unique_ptr<base::DictionaryValue> settings =
|
| GetSettingsDictionary(json_str);
|
| - if (!settings)
|
| + if (!settings) {
|
| + RejectJavascriptCallback(base::Value(callback_id),
|
| + base::Value("INVALID_SETTINGS"));
|
| return;
|
| + }
|
| int request_id = -1;
|
| - if (!settings->GetInteger(printing::kPreviewRequestID, &request_id))
|
| + if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) {
|
| + RejectJavascriptCallback(base::Value(callback_id),
|
| + base::Value("INVALID_SETTINGS"));
|
| return;
|
| -
|
| + }
|
| + DCHECK(preview_callbacks_.size() == static_cast<size_t>(request_id));
|
| + preview_callbacks_.push_back(callback_id);
|
| print_preview_ui()->OnPrintPreviewRequest(request_id);
|
| // Add an additional key in order to identify |print_preview_ui| later on
|
| // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO
|
| @@ -844,7 +856,7 @@ void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) {
|
|
|
| if (!generate_draft_data) {
|
| int page_count = -1;
|
| - success = args->GetInteger(1, &page_count);
|
| + success = args->GetInteger(2, &page_count);
|
| DCHECK(success);
|
|
|
| if (page_count != -1) {
|
| @@ -1525,11 +1537,29 @@ void PrintPreviewHandler::OnGotUniqueFileName(const base::FilePath& path) {
|
| FileSelected(path, 0, nullptr);
|
| }
|
|
|
| -void PrintPreviewHandler::OnPrintPreviewFailed() {
|
| - if (reported_failed_preview_)
|
| +void PrintPreviewHandler::OnPrintPreviewReady(int preview_uid, int request_id) {
|
| + ResolveJavascriptCallback(base::Value(preview_callbacks_[request_id]),
|
| + base::Value(preview_uid));
|
| +}
|
| +
|
| +void PrintPreviewHandler::OnPrintPreviewFailed(int request_id) {
|
| + if (!reported_failed_preview_) {
|
| + reported_failed_preview_ = true;
|
| + ReportUserActionHistogram(PREVIEW_FAILED);
|
| + }
|
| + if (request_id == -1)
|
| + return;
|
| + DCHECK(preview_callbacks_.size() > static_cast<size_t>(request_id));
|
| + RejectJavascriptCallback(base::Value(preview_callbacks_[request_id]),
|
| + base::Value("PREVIEW_FAILED"));
|
| +}
|
| +
|
| +void PrintPreviewHandler::OnInvalidPrinterSettings(int request_id) {
|
| + if (request_id == -1)
|
| return;
|
| - reported_failed_preview_ = true;
|
| - ReportUserActionHistogram(PREVIEW_FAILED);
|
| + DCHECK(preview_callbacks_.size() > static_cast<size_t>(request_id));
|
| + RejectJavascriptCallback(base::Value(preview_callbacks_[request_id]),
|
| + base::Value("INVALID_SETTINGS"));
|
| }
|
|
|
| #if BUILDFLAG(ENABLE_BASIC_PRINT_DIALOG)
|
|
|