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

Side by Side Diff: chrome/browser/ui/webui/print_preview/print_preview_handler.cc

Issue 559263002: Replaced Metafile with PdfMetafileSkia in renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Thu Sep 11 15:46:31 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
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/ui/webui/print_preview/print_preview_handler.h" 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 233 }
234 234
235 bool external_preview = false; 235 bool external_preview = false;
236 if (settings.GetBoolean(printing::kSettingOpenPDFInPreview, 236 if (settings.GetBoolean(printing::kSettingOpenPDFInPreview,
237 &external_preview) && external_preview) { 237 &external_preview) && external_preview) {
238 ReportPrintSettingHistogram(EXTERNAL_PDF_PREVIEW); 238 ReportPrintSettingHistogram(EXTERNAL_PDF_PREVIEW);
239 } 239 }
240 } 240 }
241 241
242 // Callback that stores a PDF file on disk. 242 // Callback that stores a PDF file on disk.
243 void PrintToPdfCallback(printing::Metafile* metafile, 243 void PrintToPdfCallback(const scoped_refptr<base::RefCountedBytes>& data,
244 const base::FilePath& path, 244 const base::FilePath& path,
245 const base::Closure& pdf_file_saved_closure) { 245 const base::Closure& pdf_file_saved_closure) {
246 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 246 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
247 metafile->SaveTo(path); 247 printing::PdfMetafileSkia metafile;
248 // |metafile| must be deleted on the UI thread. 248 metafile.InitFromData(static_cast<const void*>(data->front()), data->size());
249 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, metafile); 249 metafile.SaveTo(path);
250 if (!pdf_file_saved_closure.is_null()) 250 if (!pdf_file_saved_closure.is_null())
251 pdf_file_saved_closure.Run(); 251 pdf_file_saved_closure.Run();
252 } 252 }
253 253
254 std::string GetDefaultPrinterOnFileThread() { 254 std::string GetDefaultPrinterOnFileThread() {
255 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 255 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
256 256
257 scoped_refptr<printing::PrintBackend> print_backend( 257 scoped_refptr<printing::PrintBackend> print_backend(
258 printing::PrintBackend::CreateInstance(NULL)); 258 printing::PrintBackend::CreateInstance(NULL));
259 259
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 PostPrintToPdfTask(); 1308 PostPrintToPdfTask();
1309 } 1309 }
1310 1310
1311 void PrintPreviewHandler::PostPrintToPdfTask() { 1311 void PrintPreviewHandler::PostPrintToPdfTask() {
1312 scoped_refptr<base::RefCountedBytes> data; 1312 scoped_refptr<base::RefCountedBytes> data;
1313 base::string16 title; 1313 base::string16 title;
1314 if (!GetPreviewDataAndTitle(&data, &title)) { 1314 if (!GetPreviewDataAndTitle(&data, &title)) {
1315 NOTREACHED() << "Preview data was checked before file dialog."; 1315 NOTREACHED() << "Preview data was checked before file dialog.";
1316 return; 1316 return;
1317 } 1317 }
1318 scoped_ptr<printing::PdfMetafileSkia> metafile(new printing::PdfMetafileSkia); 1318 BrowserThread::PostTask(BrowserThread::FILE,
1319 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); 1319 FROM_HERE,
1320 BrowserThread::PostTask( 1320 base::Bind(&PrintToPdfCallback,
1321 BrowserThread::FILE, FROM_HERE, 1321 data,
1322 base::Bind(&PrintToPdfCallback, 1322 print_to_pdf_path_,
1323 metafile.release(), 1323 pdf_file_saved_closure_));
1324 print_to_pdf_path_,
1325 pdf_file_saved_closure_));
1326 print_to_pdf_path_ = base::FilePath(); 1324 print_to_pdf_path_ = base::FilePath();
1327 ClosePreviewDialog(); 1325 ClosePreviewDialog();
1328 } 1326 }
1329 1327
1330 void PrintPreviewHandler::FileSelectionCanceled(void* params) { 1328 void PrintPreviewHandler::FileSelectionCanceled(void* params) {
1331 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 1329 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
1332 web_ui()->GetController()); 1330 web_ui()->GetController());
1333 print_preview_ui->OnFileSelectionCancelled(); 1331 print_preview_ui->OnFileSelectionCancelled();
1334 } 1332 }
1335 1333
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 1593
1596 void PrintPreviewHandler::UnregisterForMergeSession() { 1594 void PrintPreviewHandler::UnregisterForMergeSession() {
1597 if (reconcilor_) 1595 if (reconcilor_)
1598 reconcilor_->RemoveMergeSessionObserver(this); 1596 reconcilor_->RemoveMergeSessionObserver(this);
1599 } 1597 }
1600 1598
1601 void PrintPreviewHandler::SetPdfSavedClosureForTesting( 1599 void PrintPreviewHandler::SetPdfSavedClosureForTesting(
1602 const base::Closure& closure) { 1600 const base::Closure& closure) {
1603 pdf_file_saved_closure_ = closure; 1601 pdf_file_saved_closure_ = closure;
1604 } 1602 }
OLDNEW
« no previous file with comments | « android_webview/renderer/print_web_view_helper_linux.cc ('k') | chrome/renderer/printing/print_web_view_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698