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 "chrome/renderer/printing/print_web_view_helper.h" | 5 #include "chrome/renderer/printing/print_web_view_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 if (!print_preview_context_.source_frame()) { | 1009 if (!print_preview_context_.source_frame()) { |
1010 DidFinishPrinting(FAIL_PREVIEW); | 1010 DidFinishPrinting(FAIL_PREVIEW); |
1011 return; | 1011 return; |
1012 } | 1012 } |
1013 | 1013 |
1014 if (!UpdatePrintSettings(print_preview_context_.source_frame(), | 1014 if (!UpdatePrintSettings(print_preview_context_.source_frame(), |
1015 print_preview_context_.source_node(), settings)) { | 1015 print_preview_context_.source_node(), settings)) { |
1016 if (print_preview_context_.last_error() != PREVIEW_ERROR_BAD_SETTING) { | 1016 if (print_preview_context_.last_error() != PREVIEW_ERROR_BAD_SETTING) { |
1017 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( | 1017 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( |
1018 routing_id(), | 1018 routing_id(), |
1019 print_pages_params_.get() | 1019 print_pages_params_ ? |
1020 ? print_pages_params_->params.document_cookie | 1020 print_pages_params_->params.document_cookie : 0)); |
1021 : 0)); | |
1022 notify_browser_of_print_failure_ = false; // Already sent. | 1021 notify_browser_of_print_failure_ = false; // Already sent. |
1023 } | 1022 } |
1024 DidFinishPrinting(FAIL_PREVIEW); | 1023 DidFinishPrinting(FAIL_PREVIEW); |
1025 return; | 1024 return; |
1026 } | 1025 } |
1027 | 1026 |
1028 // If we are previewing a pdf and the print scaling is disabled, send a | 1027 // If we are previewing a pdf and the print scaling is disabled, send a |
1029 // message to browser. | 1028 // message to browser. |
1030 if (print_pages_params_->params.is_first_request && | 1029 if (print_pages_params_->params.is_first_request && |
1031 !print_preview_context_.IsModifiable() && | 1030 !print_preview_context_.IsModifiable() && |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1286 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
1288 switch (result) { | 1287 switch (result) { |
1289 case OK: | 1288 case OK: |
1290 break; | 1289 break; |
1291 | 1290 |
1292 case FAIL_PRINT_INIT: | 1291 case FAIL_PRINT_INIT: |
1293 DCHECK(!notify_browser_of_print_failure_); | 1292 DCHECK(!notify_browser_of_print_failure_); |
1294 break; | 1293 break; |
1295 | 1294 |
1296 case FAIL_PRINT: | 1295 case FAIL_PRINT: |
1297 if (notify_browser_of_print_failure_ && print_pages_params_.get()) { | 1296 if (notify_browser_of_print_failure_ && print_pages_params_) { |
1298 int cookie = print_pages_params_->params.document_cookie; | 1297 int cookie = print_pages_params_->params.document_cookie; |
1299 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); | 1298 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); |
1300 } | 1299 } |
1301 break; | 1300 break; |
1302 | 1301 |
1303 case FAIL_PREVIEW: | 1302 case FAIL_PREVIEW: |
1304 DCHECK(is_preview_enabled_); | 1303 DCHECK(is_preview_enabled_); |
1305 int cookie = print_pages_params_.get() ? | 1304 int cookie = print_pages_params_ ? |
1306 print_pages_params_->params.document_cookie : 0; | 1305 print_pages_params_->params.document_cookie : 0; |
1307 if (notify_browser_of_print_failure_) { | 1306 if (notify_browser_of_print_failure_) { |
1308 LOG(ERROR) << "CreatePreviewDocument failed"; | 1307 LOG(ERROR) << "CreatePreviewDocument failed"; |
1309 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); | 1308 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); |
1310 } else { | 1309 } else { |
1311 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); | 1310 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); |
1312 } | 1311 } |
1313 print_preview_context_.Failed(notify_browser_of_print_failure_); | 1312 print_preview_context_.Failed(notify_browser_of_print_failure_); |
1314 break; | 1313 break; |
1315 } | 1314 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 | 1489 |
1491 if (print_for_preview_ || !source_is_html) { | 1490 if (print_for_preview_ || !source_is_html) { |
1492 modified_job_settings.MergeDictionary(job_settings); | 1491 modified_job_settings.MergeDictionary(job_settings); |
1493 modified_job_settings.SetBoolean(kSettingHeaderFooterEnabled, false); | 1492 modified_job_settings.SetBoolean(kSettingHeaderFooterEnabled, false); |
1494 modified_job_settings.SetInteger(kSettingMarginsType, NO_MARGINS); | 1493 modified_job_settings.SetInteger(kSettingMarginsType, NO_MARGINS); |
1495 job_settings = &modified_job_settings; | 1494 job_settings = &modified_job_settings; |
1496 } | 1495 } |
1497 | 1496 |
1498 // Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when | 1497 // Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when |
1499 // possible. | 1498 // possible. |
1500 int cookie = print_pages_params_.get() ? | 1499 int cookie = print_pages_params_ ? |
1501 print_pages_params_->params.document_cookie : 0; | 1500 print_pages_params_->params.document_cookie : 0; |
1502 PrintMsg_PrintPages_Params settings; | 1501 PrintMsg_PrintPages_Params settings; |
1503 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, | 1502 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, |
1504 &settings)); | 1503 &settings)); |
1505 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1504 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
1506 | 1505 |
1507 if (!PrintMsg_Print_Params_IsValid(settings.params)) { | 1506 if (!PrintMsg_Print_Params_IsValid(settings.params)) { |
1508 if (!print_for_preview_) | 1507 if (!print_for_preview_) |
1509 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); | 1508 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); |
1510 else | 1509 else |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1611 | 1610 |
1612 #if defined(OS_POSIX) | 1611 #if defined(OS_POSIX) |
1613 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( | 1612 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( |
1614 Metafile* metafile, | 1613 Metafile* metafile, |
1615 base::SharedMemoryHandle* shared_mem_handle) { | 1614 base::SharedMemoryHandle* shared_mem_handle) { |
1616 uint32 buf_size = metafile->GetDataSize(); | 1615 uint32 buf_size = metafile->GetDataSize(); |
1617 scoped_ptr<base::SharedMemory> shared_buf( | 1616 scoped_ptr<base::SharedMemory> shared_buf( |
1618 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer( | 1617 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer( |
1619 buf_size).release()); | 1618 buf_size).release()); |
1620 | 1619 |
1621 if (shared_buf.get()) { | 1620 if (shared_buf) { |
1622 if (shared_buf->Map(buf_size)) { | 1621 if (shared_buf->Map(buf_size)) { |
1623 metafile->GetData(shared_buf->memory(), buf_size); | 1622 metafile->GetData(shared_buf->memory(), buf_size); |
1624 shared_buf->GiveToProcess(base::GetCurrentProcessHandle(), | 1623 return shared_buf->GiveToProcess(base::GetCurrentProcessHandle(), |
1625 shared_mem_handle); | 1624 shared_mem_handle); |
1626 return true; | |
1627 } | 1625 } |
1628 } | 1626 } |
1629 NOTREACHED(); | |
1630 return false; | 1627 return false; |
1631 } | 1628 } |
1632 #endif // defined(OS_POSIX) | 1629 #endif // defined(OS_POSIX) |
1633 | 1630 |
1634 bool PrintWebViewHelper::IsScriptInitiatedPrintTooFrequent( | 1631 bool PrintWebViewHelper::IsScriptInitiatedPrintTooFrequent( |
1635 blink::WebFrame* frame) { | 1632 blink::WebFrame* frame) { |
1636 const int kMinSecondsToIgnoreJavascriptInitiatedPrint = 2; | 1633 const int kMinSecondsToIgnoreJavascriptInitiatedPrint = 2; |
1637 const int kMaxSecondsToIgnoreJavascriptInitiatedPrint = 32; | 1634 const int kMaxSecondsToIgnoreJavascriptInitiatedPrint = 32; |
1638 bool too_frequent = false; | 1635 bool too_frequent = false; |
1639 | 1636 |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2025 } | 2022 } |
2026 | 2023 |
2027 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 2024 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
2028 prep_frame_view_.reset(); | 2025 prep_frame_view_.reset(); |
2029 metafile_.reset(); | 2026 metafile_.reset(); |
2030 pages_to_render_.clear(); | 2027 pages_to_render_.clear(); |
2031 error_ = PREVIEW_ERROR_NONE; | 2028 error_ = PREVIEW_ERROR_NONE; |
2032 } | 2029 } |
2033 | 2030 |
2034 } // namespace printing | 2031 } // namespace printing |
OLD | NEW |