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

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

Issue 10827068: gdata: Fix "save as pdf" to work on Google Drive. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + made header ordering correct. 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 | Annotate | Revision Log
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 <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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
satorux1 2012/08/02 06:59:16 on what thread this function is called? can you ad
kinaba 2012/08/02 07:22:39 Done.
935 gdata::util::PrepareWritableFileAndRun(
936 Profile::FromBrowserContext(preview_web_contents()->GetBrowserContext()),
937 *print_to_pdf_path_,
938 base::Bind(&PrintToPdfCallbackWithCheck, metafile));
939 #else
914 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 940 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
915 base::Bind(&PrintToPdfCallback, metafile, 941 base::Bind(&PrintToPdfCallback, metafile,
916 *print_to_pdf_path_)); 942 *print_to_pdf_path_));
943 #endif
944
917 print_to_pdf_path_.reset(); 945 print_to_pdf_path_.reset();
918 ActivateInitiatorTabAndClosePreviewTab(); 946 ActivateInitiatorTabAndClosePreviewTab();
919 } 947 }
920 948
921 void PrintPreviewHandler::FileSelectionCanceled(void* params) { 949 void PrintPreviewHandler::FileSelectionCanceled(void* params) {
922 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 950 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
923 web_ui()->GetController()); 951 web_ui()->GetController());
924 print_preview_ui->OnFileSelectionCancelled(); 952 print_preview_ui->OnFileSelectionCancelled();
925 } 953 }
926 954
927 void PrintPreviewHandler::ClearInitiatorTabDetails() { 955 void PrintPreviewHandler::ClearInitiatorTabDetails() {
928 TabContents* initiator_tab = GetInitiatorTab(); 956 TabContents* initiator_tab = GetInitiatorTab();
929 if (!initiator_tab) 957 if (!initiator_tab)
930 return; 958 return;
931 959
932 // We no longer require the initiator tab details. Remove those details 960 // We no longer require the initiator tab details. Remove those details
933 // associated with the preview tab to allow the initiator tab to create 961 // associated with the preview tab to allow the initiator tab to create
934 // another preview tab. 962 // another preview tab.
935 printing::PrintPreviewTabController* tab_controller = 963 printing::PrintPreviewTabController* tab_controller =
936 printing::PrintPreviewTabController::GetInstance(); 964 printing::PrintPreviewTabController::GetInstance();
937 if (tab_controller) 965 if (tab_controller)
938 tab_controller->EraseInitiatorTabInfo(preview_tab_contents()); 966 tab_controller->EraseInitiatorTabInfo(preview_tab_contents());
939 } 967 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698