Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: chrome/renderer/printing/print_web_view_helper.cc

Issue 255543006: Printing on Windows via PDF (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: start looking at service process Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 prep_frame_view_->GetPrintCanvasSize())) { 1344 prep_frame_view_->GetPrintCanvasSize())) {
1345 LOG(ERROR) << "Printing failed."; 1345 LOG(ERROR) << "Printing failed.";
1346 return DidFinishPrinting(FAIL_PRINT); 1346 return DidFinishPrinting(FAIL_PRINT);
1347 } 1347 }
1348 } 1348 }
1349 1349
1350 void PrintWebViewHelper::FinishFramePrinting() { 1350 void PrintWebViewHelper::FinishFramePrinting() {
1351 prep_frame_view_.reset(); 1351 prep_frame_view_.reset();
1352 } 1352 }
1353 1353
1354 #if defined(OS_MACOSX) || defined(OS_WIN) 1354 #if defined(OS_MACOSX) || (defined(OS_WIN) && PRINTING_USE_EMF_METAFILE)
1355 bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame, 1355 bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
1356 int page_count, 1356 int page_count,
1357 const gfx::Size& canvas_size) { 1357 const gfx::Size& canvas_size) {
1358 const PrintMsg_PrintPages_Params& params = *print_pages_params_; 1358 const PrintMsg_PrintPages_Params& params = *print_pages_params_;
1359 const PrintMsg_Print_Params& print_params = params.params; 1359 const PrintMsg_Print_Params& print_params = params.params;
1360 1360
1361 PrintMsg_PrintPage_Params page_params; 1361 PrintMsg_PrintPage_Params page_params;
1362 page_params.params = print_params; 1362 page_params.params = print_params;
1363 if (params.pages.empty()) { 1363 if (params.pages.empty()) {
1364 for (int i = 0; i < page_count; ++i) { 1364 for (int i = 0; i < page_count; ++i) {
1365 page_params.page_number = i; 1365 page_params.page_number = i;
1366 PrintPageInternal(page_params, canvas_size, frame); 1366 PrintPageInternal(page_params, canvas_size, frame);
1367 } 1367 }
1368 } else { 1368 } else {
1369 for (size_t i = 0; i < params.pages.size(); ++i) { 1369 for (size_t i = 0; i < params.pages.size(); ++i) {
1370 if (params.pages[i] >= page_count) 1370 if (params.pages[i] >= page_count)
1371 break; 1371 break;
1372 page_params.page_number = params.pages[i]; 1372 page_params.page_number = params.pages[i];
1373 PrintPageInternal(page_params, canvas_size, frame); 1373 PrintPageInternal(page_params, canvas_size, frame);
1374 } 1374 }
1375 } 1375 }
1376 return true; 1376 return true;
1377 } 1377 }
1378 1378
1379 #endif // OS_MACOSX || OS_WIN 1379 #endif // OS_MACOSX || (OS_WIN && !PRINTING_USE_EMF_METAFILE)
1380 1380
1381 // static - Not anonymous so that platform implementations can use it. 1381 // static - Not anonymous so that platform implementations can use it.
1382 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( 1382 void PrintWebViewHelper::ComputePageLayoutInPointsForCss(
1383 blink::WebFrame* frame, 1383 blink::WebFrame* frame,
1384 int page_index, 1384 int page_index,
1385 const PrintMsg_Print_Params& page_params, 1385 const PrintMsg_Print_Params& page_params,
1386 bool ignore_css_margins, 1386 bool ignore_css_margins,
1387 double* scale_factor, 1387 double* scale_factor,
1388 PageSizeMargins* page_layout_in_points) { 1388 PageSizeMargins* page_layout_in_points) {
1389 PrintMsg_Print_Params params = CalculatePrintParamsForCss( 1389 PrintMsg_Print_Params params = CalculatePrintParamsForCss(
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 if (shared_buf->Map(buf_size)) { 1604 if (shared_buf->Map(buf_size)) {
1605 metafile->GetData(shared_buf->memory(), buf_size); 1605 metafile->GetData(shared_buf->memory(), buf_size);
1606 shared_buf->GiveToProcess(base::GetCurrentProcessHandle(), 1606 shared_buf->GiveToProcess(base::GetCurrentProcessHandle(),
1607 shared_mem_handle); 1607 shared_mem_handle);
1608 return true; 1608 return true;
1609 } 1609 }
1610 } 1610 }
1611 NOTREACHED(); 1611 NOTREACHED();
1612 return false; 1612 return false;
1613 } 1613 }
1614 #endif // defined(OS_POSIX) 1614 #endif // defined(OS_POSIX) || (defined(OS_WIN) && !PRINTING_USE_EMF_METAFILE)
1615 1615
1616 bool PrintWebViewHelper::IsScriptInitiatedPrintTooFrequent( 1616 bool PrintWebViewHelper::IsScriptInitiatedPrintTooFrequent(
1617 blink::WebFrame* frame) { 1617 blink::WebFrame* frame) {
1618 const int kMinSecondsToIgnoreJavascriptInitiatedPrint = 2; 1618 const int kMinSecondsToIgnoreJavascriptInitiatedPrint = 2;
1619 const int kMaxSecondsToIgnoreJavascriptInitiatedPrint = 32; 1619 const int kMaxSecondsToIgnoreJavascriptInitiatedPrint = 32;
1620 bool too_frequent = false; 1620 bool too_frequent = false;
1621 1621
1622 // Check if there is script repeatedly trying to print and ignore it if too 1622 // Check if there is script repeatedly trying to print and ignore it if too
1623 // frequent. The first 3 times, we use a constant wait time, but if this 1623 // frequent. The first 3 times, we use a constant wait time, but if this
1624 // gets excessive, we switch to exponential wait time. So for a page that 1624 // gets excessive, we switch to exponential wait time. So for a page that
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
2007 } 2007 }
2008 2008
2009 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 2009 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
2010 prep_frame_view_.reset(); 2010 prep_frame_view_.reset();
2011 metafile_.reset(); 2011 metafile_.reset();
2012 pages_to_render_.clear(); 2012 pages_to_render_.clear();
2013 error_ = PREVIEW_ERROR_NONE; 2013 error_ = PREVIEW_ERROR_NONE;
2014 } 2014 }
2015 2015
2016 } // namespace printing 2016 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698