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 #include <vector> | 10 #include <vector> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 #include "content/public/browser/web_contents_delegate.h" | 52 #include "content/public/browser/web_contents_delegate.h" |
53 #include "content/public/browser/web_ui.h" | 53 #include "content/public/browser/web_ui.h" |
54 #include "printing/backend/print_backend.h" | 54 #include "printing/backend/print_backend.h" |
55 #include "printing/metafile.h" | 55 #include "printing/metafile.h" |
56 #include "printing/metafile_impl.h" | 56 #include "printing/metafile_impl.h" |
57 #include "printing/page_range.h" | 57 #include "printing/page_range.h" |
58 #include "printing/page_size_margins.h" | 58 #include "printing/page_size_margins.h" |
59 #include "printing/print_settings.h" | 59 #include "printing/print_settings.h" |
60 #include "unicode/ulocdata.h" | 60 #include "unicode/ulocdata.h" |
61 | 61 |
62 #ifdef OS_CHROMEOS | |
Albert Bodenhamer
2012/08/02 16:20:59
Could you create a bug to unify/simplify the flow
kinaba
2012/08/03 05:19:49
Done.
| |
63 #include "chrome/browser/chromeos/gdata/gdata_util.h" | |
64 #endif | |
65 | |
62 #if !defined(OS_MACOSX) | 66 #if !defined(OS_MACOSX) |
63 #include "base/command_line.h" | 67 #include "base/command_line.h" |
64 #include "chrome/common/chrome_switches.h" | 68 #include "chrome/common/chrome_switches.h" |
65 #endif | 69 #endif |
66 | 70 |
67 using content::BrowserThread; | 71 using content::BrowserThread; |
68 using content::NavigationEntry; | 72 using content::NavigationEntry; |
69 using content::OpenURLParams; | 73 using content::OpenURLParams; |
70 using content::RenderViewHost; | 74 using content::RenderViewHost; |
71 using content::Referrer; | 75 using content::Referrer; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 | 210 |
207 // Callback that stores a PDF file on disk. | 211 // Callback that stores a PDF file on disk. |
208 void PrintToPdfCallback(Metafile* metafile, const FilePath& path) { | 212 void PrintToPdfCallback(Metafile* metafile, const FilePath& path) { |
209 metafile->SaveTo(path); | 213 metafile->SaveTo(path); |
210 // |metafile| must be deleted on the UI thread. | 214 // |metafile| must be deleted on the UI thread. |
211 BrowserThread::PostTask( | 215 BrowserThread::PostTask( |
212 BrowserThread::UI, FROM_HERE, | 216 BrowserThread::UI, FROM_HERE, |
213 base::Bind(&base::DeletePointer<Metafile>, metafile)); | 217 base::Bind(&base::DeletePointer<Metafile>, metafile)); |
214 } | 218 } |
215 | 219 |
220 #ifdef OS_CHROMEOS | |
221 void PrintToPdfCallbackWithCheck(Metafile* metafile, | |
222 gdata::GDataFileError error, | |
223 const FilePath& path) { | |
224 if (error != gdata::GDATA_FILE_OK) { | |
225 LOG(ERROR) << "Save to pdf failed to write: " << error; | |
226 } else { | |
227 metafile->SaveTo(path); | |
228 } | |
229 // |metafile| must be deleted on the UI thread. | |
230 BrowserThread::PostTask( | |
231 BrowserThread::UI, FROM_HERE, | |
232 base::Bind(&base::DeletePointer<Metafile>, metafile)); | |
233 } | |
234 #endif | |
235 | |
216 static base::LazyInstance<printing::StickySettings> sticky_settings = | 236 static base::LazyInstance<printing::StickySettings> sticky_settings = |
217 LAZY_INSTANCE_INITIALIZER; | 237 LAZY_INSTANCE_INITIALIZER; |
218 | 238 |
219 } // namespace | 239 } // namespace |
220 | 240 |
221 // static | 241 // static |
222 printing::StickySettings* PrintPreviewHandler::GetStickySettings() { | 242 printing::StickySettings* PrintPreviewHandler::GetStickySettings() { |
223 return sticky_settings.Pointer(); | 243 return sticky_settings.Pointer(); |
224 } | 244 } |
225 | 245 |
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
904 } | 924 } |
905 | 925 |
906 void PrintPreviewHandler::PostPrintToPdfTask(base::RefCountedBytes* data) { | 926 void PrintPreviewHandler::PostPrintToPdfTask(base::RefCountedBytes* data) { |
907 if (!data) { | 927 if (!data) { |
908 NOTREACHED(); | 928 NOTREACHED(); |
909 return; | 929 return; |
910 } | 930 } |
911 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; | 931 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; |
912 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); | 932 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); |
913 // PrintToPdfCallback takes ownership of |metafile|. | 933 // PrintToPdfCallback takes ownership of |metafile|. |
934 #ifdef OS_CHROMEOS | |
935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
936 gdata::util::PrepareWritableFileAndRun( | |
937 Profile::FromBrowserContext(preview_web_contents()->GetBrowserContext()), | |
938 *print_to_pdf_path_, | |
939 base::Bind(&PrintToPdfCallbackWithCheck, metafile)); | |
940 #else | |
914 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 941 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
915 base::Bind(&PrintToPdfCallback, metafile, | 942 base::Bind(&PrintToPdfCallback, metafile, |
916 *print_to_pdf_path_)); | 943 *print_to_pdf_path_)); |
944 #endif | |
945 | |
917 print_to_pdf_path_.reset(); | 946 print_to_pdf_path_.reset(); |
918 ActivateInitiatorTabAndClosePreviewTab(); | 947 ActivateInitiatorTabAndClosePreviewTab(); |
919 } | 948 } |
920 | 949 |
921 void PrintPreviewHandler::FileSelectionCanceled(void* params) { | 950 void PrintPreviewHandler::FileSelectionCanceled(void* params) { |
922 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 951 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
923 web_ui()->GetController()); | 952 web_ui()->GetController()); |
924 print_preview_ui->OnFileSelectionCancelled(); | 953 print_preview_ui->OnFileSelectionCancelled(); |
925 } | 954 } |
926 | 955 |
927 void PrintPreviewHandler::ClearInitiatorTabDetails() { | 956 void PrintPreviewHandler::ClearInitiatorTabDetails() { |
928 TabContents* initiator_tab = GetInitiatorTab(); | 957 TabContents* initiator_tab = GetInitiatorTab(); |
929 if (!initiator_tab) | 958 if (!initiator_tab) |
930 return; | 959 return; |
931 | 960 |
932 // We no longer require the initiator tab details. Remove those details | 961 // We no longer require the initiator tab details. Remove those details |
933 // associated with the preview tab to allow the initiator tab to create | 962 // associated with the preview tab to allow the initiator tab to create |
934 // another preview tab. | 963 // another preview tab. |
935 printing::PrintPreviewTabController* tab_controller = | 964 printing::PrintPreviewTabController* tab_controller = |
936 printing::PrintPreviewTabController::GetInstance(); | 965 printing::PrintPreviewTabController::GetInstance(); |
937 if (tab_controller) | 966 if (tab_controller) |
938 tab_controller->EraseInitiatorTabInfo(preview_tab_contents()); | 967 tab_controller->EraseInitiatorTabInfo(preview_tab_contents()); |
939 } | 968 } |
OLD | NEW |