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

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 + add bug id + drive-by comment typo fix. 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
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_util.cc ('k') | chrome/chrome_browser.gypi » ('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 (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 // TODO(kinaba): provide more non-intrusive way for handling local/remote
64 // distinction and remove these ugly #ifdef's. http://crbug.com/140425
65 #include "chrome/browser/chromeos/gdata/gdata_util.h"
66 #endif
67
62 #if !defined(OS_MACOSX) 68 #if !defined(OS_MACOSX)
63 #include "base/command_line.h" 69 #include "base/command_line.h"
64 #include "chrome/common/chrome_switches.h" 70 #include "chrome/common/chrome_switches.h"
65 #endif 71 #endif
66 72
67 using content::BrowserThread; 73 using content::BrowserThread;
68 using content::NavigationEntry; 74 using content::NavigationEntry;
69 using content::OpenURLParams; 75 using content::OpenURLParams;
70 using content::RenderViewHost; 76 using content::RenderViewHost;
71 using content::Referrer; 77 using content::Referrer;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 void ReportPrintSettingHistogram(enum PrintSettingsBuckets setting) { 121 void ReportPrintSettingHistogram(enum PrintSettingsBuckets setting) {
116 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PrintSettings", setting, 122 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PrintSettings", setting,
117 PRINT_SETTINGS_BUCKET_BOUNDARY); 123 PRINT_SETTINGS_BUCKET_BOUNDARY);
118 } 124 }
119 125
120 void ReportPrintDestinationHistogram(enum PrintDestinationBuckets event) { 126 void ReportPrintDestinationHistogram(enum PrintDestinationBuckets event) {
121 UMA_HISTOGRAM_ENUMERATION("PrintPreview.DestinationAction", event, 127 UMA_HISTOGRAM_ENUMERATION("PrintPreview.DestinationAction", event,
122 PRINT_DESTINATION_BUCKET_BOUNDARY); 128 PRINT_DESTINATION_BUCKET_BOUNDARY);
123 } 129 }
124 130
125 // Name of a dictionary fielad holdong cloud print related data; 131 // Name of a dictionary field holding cloud print related data;
126 const char kCloudPrintData[] = "cloudPrintData"; 132 const char kCloudPrintData[] = "cloudPrintData";
127 // Name of a dictionary field holding the initiator tab title. 133 // Name of a dictionary field holding the initiator tab title.
128 const char kInitiatorTabTitle[] = "initiatorTabTitle"; 134 const char kInitiatorTabTitle[] = "initiatorTabTitle";
129 // Name of a dictionary field holding the measurement system according to the 135 // Name of a dictionary field holding the measurement system according to the
130 // locale. 136 // locale.
131 const char kMeasurementSystem[] = "measurementSystem"; 137 const char kMeasurementSystem[] = "measurementSystem";
132 // Name of a dictionary field holding the number format according to the locale. 138 // Name of a dictionary field holding the number format according to the locale.
133 const char kNumberFormat[] = "numberFormat"; 139 const char kNumberFormat[] = "numberFormat";
134 // Name of a dictionary field specifying whether to print automatically in 140 // Name of a dictionary field specifying whether to print automatically in
135 // kiosk mode. See http://crbug.com/31395. 141 // kiosk mode. See http://crbug.com/31395.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 212
207 // Callback that stores a PDF file on disk. 213 // Callback that stores a PDF file on disk.
208 void PrintToPdfCallback(Metafile* metafile, const FilePath& path) { 214 void PrintToPdfCallback(Metafile* metafile, const FilePath& path) {
209 metafile->SaveTo(path); 215 metafile->SaveTo(path);
210 // |metafile| must be deleted on the UI thread. 216 // |metafile| must be deleted on the UI thread.
211 BrowserThread::PostTask( 217 BrowserThread::PostTask(
212 BrowserThread::UI, FROM_HERE, 218 BrowserThread::UI, FROM_HERE,
213 base::Bind(&base::DeletePointer<Metafile>, metafile)); 219 base::Bind(&base::DeletePointer<Metafile>, metafile));
214 } 220 }
215 221
222 #ifdef OS_CHROMEOS
223 void PrintToPdfCallbackWithCheck(Metafile* metafile,
224 gdata::GDataFileError error,
225 const FilePath& path) {
226 if (error != gdata::GDATA_FILE_OK) {
227 LOG(ERROR) << "Save to pdf failed to write: " << error;
228 } else {
229 metafile->SaveTo(path);
230 }
231 // |metafile| must be deleted on the UI thread.
232 BrowserThread::PostTask(
233 BrowserThread::UI, FROM_HERE,
234 base::Bind(&base::DeletePointer<Metafile>, metafile));
235 }
236 #endif
237
216 static base::LazyInstance<printing::StickySettings> sticky_settings = 238 static base::LazyInstance<printing::StickySettings> sticky_settings =
217 LAZY_INSTANCE_INITIALIZER; 239 LAZY_INSTANCE_INITIALIZER;
218 240
219 } // namespace 241 } // namespace
220 242
221 // static 243 // static
222 printing::StickySettings* PrintPreviewHandler::GetStickySettings() { 244 printing::StickySettings* PrintPreviewHandler::GetStickySettings() {
223 return sticky_settings.Pointer(); 245 return sticky_settings.Pointer();
224 } 246 }
225 247
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 } 926 }
905 927
906 void PrintPreviewHandler::PostPrintToPdfTask(base::RefCountedBytes* data) { 928 void PrintPreviewHandler::PostPrintToPdfTask(base::RefCountedBytes* data) {
907 if (!data) { 929 if (!data) {
908 NOTREACHED(); 930 NOTREACHED();
909 return; 931 return;
910 } 932 }
911 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; 933 printing::PreviewMetafile* metafile = new printing::PreviewMetafile;
912 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); 934 metafile->InitFromData(static_cast<const void*>(data->front()), data->size());
913 // PrintToPdfCallback takes ownership of |metafile|. 935 // PrintToPdfCallback takes ownership of |metafile|.
936 #ifdef OS_CHROMEOS
937 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
938 gdata::util::PrepareWritableFileAndRun(
939 Profile::FromBrowserContext(preview_web_contents()->GetBrowserContext()),
940 *print_to_pdf_path_,
941 base::Bind(&PrintToPdfCallbackWithCheck, metafile));
942 #else
914 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 943 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
915 base::Bind(&PrintToPdfCallback, metafile, 944 base::Bind(&PrintToPdfCallback, metafile,
916 *print_to_pdf_path_)); 945 *print_to_pdf_path_));
946 #endif
947
917 print_to_pdf_path_.reset(); 948 print_to_pdf_path_.reset();
918 ActivateInitiatorTabAndClosePreviewTab(); 949 ActivateInitiatorTabAndClosePreviewTab();
919 } 950 }
920 951
921 void PrintPreviewHandler::FileSelectionCanceled(void* params) { 952 void PrintPreviewHandler::FileSelectionCanceled(void* params) {
922 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 953 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
923 web_ui()->GetController()); 954 web_ui()->GetController());
924 print_preview_ui->OnFileSelectionCancelled(); 955 print_preview_ui->OnFileSelectionCancelled();
925 } 956 }
926 957
927 void PrintPreviewHandler::ClearInitiatorTabDetails() { 958 void PrintPreviewHandler::ClearInitiatorTabDetails() {
928 TabContents* initiator_tab = GetInitiatorTab(); 959 TabContents* initiator_tab = GetInitiatorTab();
929 if (!initiator_tab) 960 if (!initiator_tab)
930 return; 961 return;
931 962
932 // We no longer require the initiator tab details. Remove those details 963 // We no longer require the initiator tab details. Remove those details
933 // associated with the preview tab to allow the initiator tab to create 964 // associated with the preview tab to allow the initiator tab to create
934 // another preview tab. 965 // another preview tab.
935 printing::PrintPreviewTabController* tab_controller = 966 printing::PrintPreviewTabController* tab_controller =
936 printing::PrintPreviewTabController::GetInstance(); 967 printing::PrintPreviewTabController::GetInstance();
937 if (tab_controller) 968 if (tab_controller)
938 tab_controller->EraseInitiatorTabInfo(preview_tab_contents()); 969 tab_controller->EraseInitiatorTabInfo(preview_tab_contents());
939 } 970 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_util.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698