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

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

Issue 566693002: Use file handles to interact with utility process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wed Sep 17 10:40:51 PDT 2014 Created 6 years, 3 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
« no previous file with comments | « chrome/browser/printing/print_view_manager_base.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_base.h" 5 #include "chrome/browser/printing/print_view_manager_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 15 matching lines...) Expand all
26 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "printing/pdf_metafile_skia.h" 28 #include "printing/pdf_metafile_skia.h"
29 #include "printing/printed_document.h" 29 #include "printing/printed_document.h"
30 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
31 31
32 #if defined(ENABLE_FULL_PRINTING) 32 #if defined(ENABLE_FULL_PRINTING)
33 #include "chrome/browser/printing/print_error_dialog.h" 33 #include "chrome/browser/printing/print_error_dialog.h"
34 #endif 34 #endif
35 35
36 #if defined(OS_WIN)
37 #include "base/memory/ref_counted.h"
38 #include "base/memory/ref_counted_memory.h"
39 #include "chrome/browser/printing/pdf_to_emf_converter.h"
40 #include "printing/emf_win.h"
41 #include "printing/pdf_render_settings.h"
42 #endif
43
44 using base::TimeDelta; 36 using base::TimeDelta;
45 using content::BrowserThread; 37 using content::BrowserThread;
46 38
47 namespace printing { 39 namespace printing {
48 40
49 namespace { 41 namespace {
50 42
51 } // namespace 43 } // namespace
52 44
53 PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents) 45 PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 DCHECK_GT(cookie, 0); 111 DCHECK_GT(cookie, 0);
120 DCHECK_GT(number_pages, 0); 112 DCHECK_GT(number_pages, 0);
121 number_pages_ = number_pages; 113 number_pages_ = number_pages;
122 OpportunisticallyCreatePrintJob(cookie); 114 OpportunisticallyCreatePrintJob(cookie);
123 } 115 }
124 116
125 void PrintViewManagerBase::OnDidGetDocumentCookie(int cookie) { 117 void PrintViewManagerBase::OnDidGetDocumentCookie(int cookie) {
126 cookie_ = cookie; 118 cookie_ = cookie;
127 } 119 }
128 120
129 #if defined(OS_WIN)
130 void PrintViewManagerBase::OnPdfToEmfConverted(
131 const PrintHostMsg_DidPrintPage_Params& params,
132 double scale_factor,
133 ScopedVector<MetafilePlayer>* emf_files) {
134 if (!print_job_.get())
135 return;
136
137 PrintedDocument* document = print_job_->document();
138 if (!document)
139 return;
140
141 for (size_t i = 0; i < emf_files->size(); ++i) {
142 if (!(*emf_files)[i]) {
143 web_contents()->Stop();
144 return;
145 }
146 }
147
148 for (size_t i = 0; i < emf_files->size(); ++i) {
149 // Update the rendered document. It will send notifications to the listener.
150 document->SetPage(i,
151 make_scoped_ptr((*emf_files)[i]),
152 scale_factor,
153 params.page_size,
154 params.content_area);
155 }
156 // document->SetPage took ownership of all EMFs.
157 emf_files->weak_clear();
158
159 ShouldQuitFromInnerMessageLoop();
160 }
161 #endif // OS_WIN
162
163 void PrintViewManagerBase::OnDidPrintPage( 121 void PrintViewManagerBase::OnDidPrintPage(
164 const PrintHostMsg_DidPrintPage_Params& params) { 122 const PrintHostMsg_DidPrintPage_Params& params) {
165 if (!OpportunisticallyCreatePrintJob(params.document_cookie)) 123 if (!OpportunisticallyCreatePrintJob(params.document_cookie))
166 return; 124 return;
167 125
168 PrintedDocument* document = print_job_->document(); 126 PrintedDocument* document = print_job_->document();
169 if (!document || params.document_cookie != document->cookie()) { 127 if (!document || params.document_cookie != document->cookie()) {
170 // Out of sync. It may happen since we are completely asynchronous. Old 128 // Out of sync. It may happen since we are completely asynchronous. Old
171 // spurious messages can be received if one of the processes is overloaded. 129 // spurious messages can be received if one of the processes is overloaded.
172 return; 130 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 params.content_area); 163 params.content_area);
206 164
207 ShouldQuitFromInnerMessageLoop(); 165 ShouldQuitFromInnerMessageLoop();
208 #else 166 #else
209 if (metafile_must_be_valid) { 167 if (metafile_must_be_valid) {
210 scoped_refptr<base::RefCountedBytes> bytes = new base::RefCountedBytes( 168 scoped_refptr<base::RefCountedBytes> bytes = new base::RefCountedBytes(
211 reinterpret_cast<const unsigned char*>(shared_buf.memory()), 169 reinterpret_cast<const unsigned char*>(shared_buf.memory()),
212 params.data_size); 170 params.data_size);
213 171
214 document->DebugDumpData(bytes, FILE_PATH_LITERAL(".pdf")); 172 document->DebugDumpData(bytes, FILE_PATH_LITERAL(".pdf"));
215 173 print_job_->StartPdfToEmfConversion(
216 if (!pdf_to_emf_converter_) 174 bytes, params.page_size, params.content_area);
217 pdf_to_emf_converter_ = PdfToEmfConverter::CreateDefault();
218
219 const int kPrinterDpi = print_job_->settings().dpi();
220 pdf_to_emf_converter_->Start(
221 bytes,
222 printing::PdfRenderSettings(params.content_area, kPrinterDpi, true),
223 base::Bind(&PrintViewManagerBase::OnPdfToEmfConverted,
224 base::Unretained(this),
225 params));
226 } 175 }
227 #endif // !OS_WIN 176 #endif // !OS_WIN
228 } 177 }
229 178
230 void PrintViewManagerBase::OnPrintingFailed(int cookie) { 179 void PrintViewManagerBase::OnPrintingFailed(int cookie) {
231 if (cookie != cookie_) { 180 if (cookie != cookie_) {
232 NOTREACHED(); 181 NOTREACHED();
233 return; 182 return;
234 } 183 }
235 184
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 scoped_refptr<printing::PrinterQuery> printer_query; 515 scoped_refptr<printing::PrinterQuery> printer_query;
567 printer_query = queue_->PopPrinterQuery(cookie); 516 printer_query = queue_->PopPrinterQuery(cookie);
568 if (!printer_query.get()) 517 if (!printer_query.get())
569 return; 518 return;
570 BrowserThread::PostTask( 519 BrowserThread::PostTask(
571 BrowserThread::IO, FROM_HERE, 520 BrowserThread::IO, FROM_HERE,
572 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); 521 base::Bind(&PrinterQuery::StopWorker, printer_query.get()));
573 } 522 }
574 523
575 } // namespace printing 524 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_view_manager_base.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698