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/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 <string> | 9 #include <string> |
10 | 10 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 208 |
209 // Callback that stores a PDF file on disk. | 209 // Callback that stores a PDF file on disk. |
210 void PrintToPdfCallback(Metafile* metafile, const base::FilePath& path) { | 210 void PrintToPdfCallback(Metafile* metafile, const base::FilePath& path) { |
211 metafile->SaveTo(path); | 211 metafile->SaveTo(path); |
212 // |metafile| must be deleted on the UI thread. | 212 // |metafile| must be deleted on the UI thread. |
213 BrowserThread::PostTask( | 213 BrowserThread::PostTask( |
214 BrowserThread::UI, FROM_HERE, | 214 BrowserThread::UI, FROM_HERE, |
215 base::Bind(&base::DeletePointer<Metafile>, metafile)); | 215 base::Bind(&base::DeletePointer<Metafile>, metafile)); |
216 } | 216 } |
217 | 217 |
218 #ifdef OS_CHROMEOS | 218 #if defined(OS_CHROMEOS) |
219 void PrintToPdfCallbackWithCheck(Metafile* metafile, | 219 void PrintToPdfCallbackWithCheck(Metafile* metafile, |
220 drive::DriveFileError error, | 220 drive::DriveFileError error, |
221 const base::FilePath& path) { | 221 const base::FilePath& path) { |
222 if (error != drive::DRIVE_FILE_OK) { | 222 if (error != drive::DRIVE_FILE_OK) { |
223 LOG(ERROR) << "Save to pdf failed to write: " << error; | 223 LOG(ERROR) << "Save to pdf failed to write: " << error; |
224 } else { | 224 } else { |
225 metafile->SaveTo(path); | 225 metafile->SaveTo(path); |
226 } | 226 } |
227 // |metafile| must be deleted on the UI thread. | 227 // |metafile| must be deleted on the UI thread. |
228 BrowserThread::PostTask( | 228 BrowserThread::PostTask( |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 void PrintPreviewHandler::PostPrintToPdfTask() { | 908 void PrintPreviewHandler::PostPrintToPdfTask() { |
909 scoped_refptr<base::RefCountedBytes> data; | 909 scoped_refptr<base::RefCountedBytes> data; |
910 string16 title; | 910 string16 title; |
911 if (!GetPreviewDataAndTitle(&data, &title)) { | 911 if (!GetPreviewDataAndTitle(&data, &title)) { |
912 NOTREACHED() << "Preview data was checked before file dialog."; | 912 NOTREACHED() << "Preview data was checked before file dialog."; |
913 return; | 913 return; |
914 } | 914 } |
915 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; | 915 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; |
916 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); | 916 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); |
917 // PrintToPdfCallback takes ownership of |metafile|. | 917 // PrintToPdfCallback takes ownership of |metafile|. |
918 #ifdef OS_CHROMEOS | 918 #if defined(OS_CHROMEOS) |
919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
920 drive::util::PrepareWritableFileAndRun( | 920 drive::util::PrepareWritableFileAndRun( |
921 Profile::FromBrowserContext(preview_web_contents()->GetBrowserContext()), | 921 Profile::FromBrowserContext(preview_web_contents()->GetBrowserContext()), |
922 *print_to_pdf_path_, | 922 *print_to_pdf_path_, |
923 base::Bind(&PrintToPdfCallbackWithCheck, metafile)); | 923 base::Bind(&PrintToPdfCallbackWithCheck, metafile)); |
924 #else | 924 #else |
925 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 925 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
926 base::Bind(&PrintToPdfCallback, metafile, | 926 base::Bind(&PrintToPdfCallback, metafile, |
927 *print_to_pdf_path_)); | 927 *print_to_pdf_path_)); |
928 #endif | 928 #endif |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 // Nothing to print, no preview available. | 964 // Nothing to print, no preview available. |
965 return false; | 965 return false; |
966 } | 966 } |
967 DCHECK(tmp_data->size() && tmp_data->front()); | 967 DCHECK(tmp_data->size() && tmp_data->front()); |
968 | 968 |
969 *data = tmp_data; | 969 *data = tmp_data; |
970 *title = print_preview_ui->initiator_tab_title(); | 970 *title = print_preview_ui->initiator_tab_title(); |
971 return true; | 971 return true; |
972 } | 972 } |
973 | 973 |
OLD | NEW |