OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/i18n/file_util_icu.h" | 9 #include "base/i18n/file_util_icu.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
23 #include "chrome/common/print_messages.h" | 23 #include "chrome/common/print_messages.h" |
24 #include "content/browser/browser_thread.h" | 24 #include "content/browser/browser_thread.h" |
25 #include "content/browser/renderer_host/render_view_host.h" | 25 #include "content/browser/renderer_host/render_view_host.h" |
26 #include "content/browser/tab_contents/tab_contents.h" | 26 #include "content/browser/tab_contents/tab_contents.h" |
27 #include "printing/backend/print_backend.h" | 27 #include "printing/backend/print_backend.h" |
28 #include "printing/metafile.h" | 28 #include "printing/metafile.h" |
29 #include "printing/metafile_impl.h" | 29 #include "printing/metafile_impl.h" |
30 #include "printing/print_job_constants.h" | 30 #include "printing/print_job_constants.h" |
31 | 31 |
32 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) | 32 #if defined(USE_CUPS) |
33 #include <cups/cups.h> | 33 #include <cups/cups.h> |
34 | 34 |
35 #include "base/file_util.h" | 35 #include "base/file_util.h" |
36 #endif | 36 #endif |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 const bool kColorDefaultValue = false; | 40 const bool kColorDefaultValue = false; |
41 const bool kLandscapeDefaultValue = false; | 41 const bool kLandscapeDefaultValue = false; |
42 | 42 |
43 const char kDisableColorOption[] = "disableColorOption"; | 43 const char kDisableColorOption[] = "disableColorOption"; |
44 const char kSetColorAsDefault[] = "setColorAsDefault"; | 44 const char kSetColorAsDefault[] = "setColorAsDefault"; |
45 | 45 |
46 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) | 46 #if defined(USE_CUPS) |
47 const char kColorDevice[] = "ColorDevice"; | 47 const char kColorDevice[] = "ColorDevice"; |
48 #elif defined(OS_WIN) | 48 #elif defined(OS_WIN) |
49 const char kPskColor[] = "psk:Color"; | 49 const char kPskColor[] = "psk:Color"; |
50 #endif | 50 #endif |
51 | 51 |
52 // Get the print job settings dictionary from |args|. The caller takes | 52 // Get the print job settings dictionary from |args|. The caller takes |
53 // ownership of the returned DictionaryValue. Returns NULL on failure. | 53 // ownership of the returned DictionaryValue. Returns NULL on failure. |
54 DictionaryValue* GetSettingsDictionary(const ListValue* args) { | 54 DictionaryValue* GetSettingsDictionary(const ListValue* args) { |
55 std::string json_str; | 55 std::string json_str; |
56 if (!args->GetString(0, &json_str)) { | 56 if (!args->GetString(0, &json_str)) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 } | 119 } |
120 | 120 |
121 void GetPrinterCapabilities(const std::string& printer_name) { | 121 void GetPrinterCapabilities(const std::string& printer_name) { |
122 printing::PrinterCapsAndDefaults printer_info; | 122 printing::PrinterCapsAndDefaults printer_info; |
123 bool supports_color = true; | 123 bool supports_color = true; |
124 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, | 124 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, |
125 &printer_info)) { | 125 &printer_info)) { |
126 return; | 126 return; |
127 } | 127 } |
128 | 128 |
129 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) | 129 #if defined(USE_CUPS) |
130 FilePath ppd_file_path; | 130 FilePath ppd_file_path; |
131 if (!file_util::CreateTemporaryFile(&ppd_file_path)) | 131 if (!file_util::CreateTemporaryFile(&ppd_file_path)) |
132 return; | 132 return; |
133 | 133 |
134 int data_size = printer_info.printer_capabilities.length(); | 134 int data_size = printer_info.printer_capabilities.length(); |
135 if (data_size != file_util::WriteFile( | 135 if (data_size != file_util::WriteFile( |
136 ppd_file_path, | 136 ppd_file_path, |
137 printer_info.printer_capabilities.data(), | 137 printer_info.printer_capabilities.data(), |
138 data_size)) { | 138 data_size)) { |
139 file_util::Delete(ppd_file_path, false); | 139 file_util::Delete(ppd_file_path, false); |
140 return; | 140 return; |
141 } | 141 } |
142 | 142 |
143 ppd_file_t* ppd = ppdOpenFile(ppd_file_path.value().c_str()); | 143 ppd_file_t* ppd = ppdOpenFile(ppd_file_path.value().c_str()); |
144 if (ppd) { | 144 if (ppd) { |
145 ppd_attr_t* attr = ppdFindAttr(ppd, kColorDevice, NULL); | 145 ppd_attr_t* attr = ppdFindAttr(ppd, kColorDevice, NULL); |
146 if (attr && attr->value) | 146 if (attr && attr->value) |
147 supports_color = ppd->color_device; | 147 supports_color = ppd->color_device; |
148 ppdClose(ppd); | 148 ppdClose(ppd); |
149 } | 149 } |
150 file_util::Delete(ppd_file_path, false); | 150 file_util::Delete(ppd_file_path, false); |
151 #elif defined(OS_WIN) | 151 #elif defined(OS_WIN) |
152 // According to XPS 1.0 spec, only color printers have psk:Color. | 152 // According to XPS 1.0 spec, only color printers have psk:Color. |
153 // Therefore we don't need to parse the whole XML file, we just need to | 153 // Therefore we don't need to parse the whole XML file, we just need to |
154 // search the string. The spec can be found at: | 154 // search the string. The spec can be found at: |
155 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. | 155 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. |
156 supports_color = (printer_info.printer_capabilities.find(kPskColor) != | 156 supports_color = (printer_info.printer_capabilities.find(kPskColor) != |
157 std::string::npos); | 157 std::string::npos); |
158 #elif defined(OS_CHROMEOS) | 158 #else |
159 NOTIMPLEMENTED(); | 159 NOTIMPLEMENTED(); |
160 #endif | 160 #endif |
161 | 161 |
162 DictionaryValue settings_info; | 162 DictionaryValue settings_info; |
163 settings_info.SetBoolean(kDisableColorOption, !supports_color); | 163 settings_info.SetBoolean(kDisableColorOption, !supports_color); |
164 settings_info.SetBoolean(kSetColorAsDefault, false); | 164 settings_info.SetBoolean(kSetColorAsDefault, false); |
165 BrowserThread::PostTask( | 165 BrowserThread::PostTask( |
166 BrowserThread::UI, FROM_HERE, | 166 BrowserThread::UI, FROM_HERE, |
167 NewRunnableMethod(this, | 167 NewRunnableMethod(this, |
168 &PrintSystemTaskProxy::SendPrinterCapabilities, | 168 &PrintSystemTaskProxy::SendPrinterCapabilities, |
169 settings_info.DeepCopy())); | 169 settings_info.DeepCopy())); |
170 } | 170 } |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 metafile->InitFromData(data.first->memory(), data.second); | 403 metafile->InitFromData(data.first->memory(), data.second); |
404 | 404 |
405 // Updating last_saved_path_ to the newly selected folder. | 405 // Updating last_saved_path_ to the newly selected folder. |
406 *last_saved_path_ = path.DirName(); | 406 *last_saved_path_ = path.DirName(); |
407 | 407 |
408 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); | 408 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); |
409 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); | 409 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); |
410 | 410 |
411 ClosePrintPreviewTab(); | 411 ClosePrintPreviewTab(); |
412 } | 412 } |
OLD | NEW |