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

Side by Side Diff: chrome/browser/printing/print_view_manager.cc

Issue 10836330: Rasterize page before printing. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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
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/browser/printing/print_view_manager.h" 5 #include "chrome/browser/printing/print_view_manager.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
13 #include "base/timer.h" 14 #include "base/timer.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/printing/print_error_dialog.h" 17 #include "chrome/browser/printing/print_error_dialog.h"
17 #include "chrome/browser/printing/print_job.h" 18 #include "chrome/browser/printing/print_job.h"
18 #include "chrome/browser/printing/print_job_manager.h" 19 #include "chrome/browser/printing/print_job_manager.h"
19 #include "chrome/browser/printing/print_preview_tab_controller.h" 20 #include "chrome/browser/printing/print_preview_tab_controller.h"
20 #include "chrome/browser/printing/print_view_manager_observer.h" 21 #include "chrome/browser/printing/print_view_manager_observer.h"
21 #include "chrome/browser/printing/printer_query.h" 22 #include "chrome/browser/printing/printer_query.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/tab_contents/tab_contents.h" 24 #include "chrome/browser/ui/tab_contents/tab_contents.h"
24 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" 25 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
25 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
27 #include "chrome/common/print_messages.h" 29 #include "chrome/common/print_messages.h"
28 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/notification_details.h" 31 #include "content/public/browser/notification_details.h"
30 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/notification_source.h" 33 #include "content/public/browser/notification_source.h"
32 #include "content/public/browser/render_view_host.h" 34 #include "content/public/browser/render_view_host.h"
33 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
34 #include "content/public/browser/web_contents_view.h" 36 #include "content/public/browser/web_contents_view.h"
35 #include "grit/generated_resources.h" 37 #include "grit/generated_resources.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 if (!OpportunisticallyCreatePrintJob(params.document_cookie)) 215 if (!OpportunisticallyCreatePrintJob(params.document_cookie))
214 return; 216 return;
215 217
216 PrintedDocument* document = print_job_->document(); 218 PrintedDocument* document = print_job_->document();
217 if (!document || params.document_cookie != document->cookie()) { 219 if (!document || params.document_cookie != document->cookie()) {
218 // Out of sync. It may happen since we are completely asynchronous. Old 220 // Out of sync. It may happen since we are completely asynchronous. Old
219 // spurious messages can be received if one of the processes is overloaded. 221 // spurious messages can be received if one of the processes is overloaded.
220 return; 222 return;
221 } 223 }
222 224
223 #if defined(OS_WIN)
224 // http://msdn2.microsoft.com/en-us/library/ms535522.aspx
225 // Windows 2000/XP: When a page in a spooled file exceeds approximately 350
226 // MB, it can fail to print and not send an error message.
227 if (params.data_size && params.data_size >= 350*1024*1024) {
228 NOTREACHED() << "size:" << params.data_size;
229 TerminatePrintJob(true);
230 web_contents()->Stop();
231 return;
232 }
233 #endif
234
235 #if defined(OS_WIN) || defined(OS_MACOSX) 225 #if defined(OS_WIN) || defined(OS_MACOSX)
236 const bool metafile_must_be_valid = true; 226 const bool metafile_must_be_valid = true;
237 #elif defined(OS_POSIX) 227 #elif defined(OS_POSIX)
238 const bool metafile_must_be_valid = expecting_first_page_; 228 const bool metafile_must_be_valid = expecting_first_page_;
239 expecting_first_page_ = false; 229 expecting_first_page_ = false;
240 #endif 230 #endif
241 231
242 base::SharedMemory shared_buf(params.metafile_data_handle, true); 232 base::SharedMemory shared_buf(params.metafile_data_handle, true);
243 if (metafile_must_be_valid) { 233 if (metafile_must_be_valid) {
244 if (!shared_buf.Map(params.data_size)) { 234 if (!shared_buf.Map(params.data_size)) {
245 NOTREACHED() << "couldn't map"; 235 NOTREACHED() << "couldn't map";
246 web_contents()->Stop(); 236 web_contents()->Stop();
247 return; 237 return;
248 } 238 }
249 } 239 }
250 240
251 scoped_ptr<Metafile> metafile(new NativeMetafile); 241 scoped_ptr<NativeMetafile> metafile(new NativeMetafile);
252 if (metafile_must_be_valid) { 242 if (metafile_must_be_valid) {
253 if (!metafile->InitFromData(shared_buf.memory(), params.data_size)) { 243 if (!metafile->InitFromData(shared_buf.memory(), params.data_size)) {
254 NOTREACHED() << "Invalid metafile header"; 244 NOTREACHED() << "Invalid metafile header";
255 web_contents()->Stop(); 245 web_contents()->Stop();
256 return; 246 return;
257 } 247 }
258 } 248 }
259 249
250 #if defined(OS_WIN)
251 bool big_emf = (params.data_size && params.data_size >= kMetafileMaxSize);
252 const CommandLine* cmdline = CommandLine::ForCurrentProcess();
253 if (big_emf ||
254 (cmdline && cmdline->HasSwitch(switches::kPrintRaster)) ||
255 (!print_job_->settings().supports_alpha_blend() &&
256 IsAlphaBlendUsed(*metafile))) {
257 int raster_size = std::min(params.page_size.GetArea(), 16*1024*1024);
258 scoped_ptr<NativeMetafile> raster_metafile(RasterizeMetafile(*metafile,
259 raster_size));
260 if (raster_metafile.get()) {
261 metafile.swap(raster_metafile);
262 } else if (big_emf) {
263 // Don't fall back to emf here.
264 NOTREACHED() << "size:" << params.data_size;
265 TerminatePrintJob(true);
266 web_contents()->Stop();
267 return;
268 }
269 }
270
271 #endif
272
260 // Update the rendered document. It will send notifications to the listener. 273 // Update the rendered document. It will send notifications to the listener.
261 document->SetPage(params.page_number, 274 document->SetPage(params.page_number,
262 metafile.release(), 275 metafile.release(),
263 params.actual_shrink, 276 params.actual_shrink,
264 params.page_size, 277 params.page_size,
265 params.content_area); 278 params.content_area);
266 279
267 ShouldQuitFromInnerMessageLoop(); 280 ShouldQuitFromInnerMessageLoop();
268 } 281 }
269 282
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 scoped_refptr<printing::PrinterQuery> printer_query; 668 scoped_refptr<printing::PrinterQuery> printer_query;
656 print_job_manager->PopPrinterQuery(cookie, &printer_query); 669 print_job_manager->PopPrinterQuery(cookie, &printer_query);
657 if (!printer_query.get()) 670 if (!printer_query.get())
658 return; 671 return;
659 BrowserThread::PostTask( 672 BrowserThread::PostTask(
660 BrowserThread::IO, FROM_HERE, 673 BrowserThread::IO, FROM_HERE,
661 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); 674 base::Bind(&PrinterQuery::StopWorker, printer_query.get()));
662 } 675 }
663 676
664 } // namespace printing 677 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698