| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1180 PREVIEW_EVENT_REQUESTED, PREVIEW_EVENT_MAX); | 1180 PREVIEW_EVENT_REQUESTED, PREVIEW_EVENT_MAX); |
| 1181 | 1181 |
| 1182 if (!print_preview_context_.source_frame()) { | 1182 if (!print_preview_context_.source_frame()) { |
| 1183 DidFinishPrinting(FAIL_PREVIEW); | 1183 DidFinishPrinting(FAIL_PREVIEW); |
| 1184 return; | 1184 return; |
| 1185 } | 1185 } |
| 1186 | 1186 |
| 1187 if (!UpdatePrintSettings(print_preview_context_.source_frame(), | 1187 if (!UpdatePrintSettings(print_preview_context_.source_frame(), |
| 1188 print_preview_context_.source_node(), settings)) { | 1188 print_preview_context_.source_node(), settings)) { |
| 1189 if (print_preview_context_.last_error() != PREVIEW_ERROR_BAD_SETTING) { | 1189 if (print_preview_context_.last_error() != PREVIEW_ERROR_BAD_SETTING) { |
| 1190 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( | 1190 DidFinishPrinting(INVALID_SETTINGS); |
| 1191 routing_id(), print_pages_params_ | 1191 } else { |
| 1192 ? print_pages_params_->params.document_cookie | 1192 DidFinishPrinting(FAIL_PREVIEW); |
| 1193 : 0)); | |
| 1194 notify_browser_of_print_failure_ = false; // Already sent. | |
| 1195 } | 1193 } |
| 1196 DidFinishPrinting(FAIL_PREVIEW); | |
| 1197 return; | 1194 return; |
| 1198 } | 1195 } |
| 1199 | 1196 |
| 1200 // Set the options from document if we are previewing a pdf and send a | 1197 // Set the options from document if we are previewing a pdf and send a |
| 1201 // message to browser. | 1198 // message to browser. |
| 1202 if (print_pages_params_->params.is_first_request && | 1199 if (print_pages_params_->params.is_first_request && |
| 1203 !print_preview_context_.IsModifiable()) { | 1200 !print_preview_context_.IsModifiable()) { |
| 1204 PrintHostMsg_SetOptionsFromDocument_Params options; | 1201 PrintHostMsg_SetOptionsFromDocument_Params options; |
| 1205 if (SetOptionsFromPdfDocument(&options)) | 1202 if (SetOptionsFromPdfDocument(&options)) |
| 1206 Send(new PrintHostMsg_SetOptionsFromDocument(routing_id(), options)); | 1203 Send(new PrintHostMsg_SetOptionsFromDocument(routing_id(), options)); |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1550 // Render Pages for printing. | 1547 // Render Pages for printing. |
| 1551 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1548 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
| 1552 LOG(ERROR) << "RenderPagesForPrint failed"; | 1549 LOG(ERROR) << "RenderPagesForPrint failed"; |
| 1553 DidFinishPrinting(FAIL_PRINT); | 1550 DidFinishPrinting(FAIL_PRINT); |
| 1554 } | 1551 } |
| 1555 scripting_throttler_.Reset(); | 1552 scripting_throttler_.Reset(); |
| 1556 } | 1553 } |
| 1557 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 1554 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1558 | 1555 |
| 1559 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1556 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
| 1557 int cookie = |
| 1558 print_pages_params_ ? print_pages_params_->params.document_cookie : 0; |
| 1560 switch (result) { | 1559 switch (result) { |
| 1561 case OK: | 1560 case OK: |
| 1562 break; | 1561 break; |
| 1563 | 1562 |
| 1564 case FAIL_PRINT_INIT: | 1563 case FAIL_PRINT_INIT: |
| 1565 DCHECK(!notify_browser_of_print_failure_); | 1564 DCHECK(!notify_browser_of_print_failure_); |
| 1566 break; | 1565 break; |
| 1567 | 1566 |
| 1568 case FAIL_PRINT: | 1567 case FAIL_PRINT: |
| 1569 if (notify_browser_of_print_failure_ && print_pages_params_) { | 1568 if (notify_browser_of_print_failure_ && print_pages_params_) { |
| 1570 int cookie = print_pages_params_->params.document_cookie; | |
| 1571 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); | 1569 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); |
| 1572 } | 1570 } |
| 1573 break; | 1571 break; |
| 1574 | 1572 |
| 1575 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1573 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 1576 case FAIL_PREVIEW: | 1574 case FAIL_PREVIEW: |
| 1577 int cookie = | |
| 1578 print_pages_params_ ? print_pages_params_->params.document_cookie : 0; | |
| 1579 if (notify_browser_of_print_failure_) { | 1575 if (notify_browser_of_print_failure_) { |
| 1580 LOG(ERROR) << "CreatePreviewDocument failed"; | 1576 LOG(ERROR) << "CreatePreviewDocument failed"; |
| 1581 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); | 1577 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); |
| 1582 } else { | 1578 } else { |
| 1583 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); | 1579 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); |
| 1584 } | 1580 } |
| 1585 print_preview_context_.Failed(notify_browser_of_print_failure_); | 1581 print_preview_context_.Failed(notify_browser_of_print_failure_); |
| 1586 break; | 1582 break; |
| 1583 case INVALID_SETTINGS: |
| 1584 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings(routing_id(), |
| 1585 cookie)); |
| 1586 print_preview_context_.Failed(false); |
| 1587 break; |
| 1587 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1588 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 1588 } | 1589 } |
| 1589 prep_frame_view_.reset(); | 1590 prep_frame_view_.reset(); |
| 1590 print_pages_params_.reset(); | 1591 print_pages_params_.reset(); |
| 1591 notify_browser_of_print_failure_ = true; | 1592 notify_browser_of_print_failure_ = true; |
| 1592 } | 1593 } |
| 1593 | 1594 |
| 1594 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 1595 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1595 void PrintWebViewHelper::OnFramePreparedForPrintPages() { | 1596 void PrintWebViewHelper::OnFramePreparedForPrintPages() { |
| 1596 PrintPages(); | 1597 PrintPages(); |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2402 blink::WebConsoleMessage::kLevelWarning, message)); | 2403 blink::WebConsoleMessage::kLevelWarning, message)); |
| 2403 return false; | 2404 return false; |
| 2404 } | 2405 } |
| 2405 | 2406 |
| 2406 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2407 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2407 // Reset counter on successful print. | 2408 // Reset counter on successful print. |
| 2408 count_ = 0; | 2409 count_ = 0; |
| 2409 } | 2410 } |
| 2410 | 2411 |
| 2411 } // namespace printing | 2412 } // namespace printing |
| OLD | NEW |