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/base64.h" | 9 #include "base/base64.h" |
10 #if !defined(OS_CHROMEOS) | 10 #if !defined(OS_CHROMEOS) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 #include <cups/cups.h> | 50 #include <cups/cups.h> |
51 #include <cups/ppd.h> | 51 #include <cups/ppd.h> |
52 | 52 |
53 #include "base/file_util.h" | 53 #include "base/file_util.h" |
54 #endif | 54 #endif |
55 | 55 |
56 namespace { | 56 namespace { |
57 | 57 |
58 const char kDisableColorOption[] = "disableColorOption"; | 58 const char kDisableColorOption[] = "disableColorOption"; |
59 const char kSetColorAsDefault[] = "setColorAsDefault"; | 59 const char kSetColorAsDefault[] = "setColorAsDefault"; |
60 const char kSetDuplexAsDefault[] = "setDuplexAsDefault"; | 60 const char kPrinterDefaultDuplexValue[] = "printerDefaultDuplexValue"; |
61 | 61 |
62 #if defined(USE_CUPS) | 62 #if defined(USE_CUPS) |
63 const char kColorDevice[] = "ColorDevice"; | 63 const char kColorDevice[] = "ColorDevice"; |
64 const char kDuplex[] = "Duplex"; | 64 const char kDuplex[] = "Duplex"; |
65 const char kDuplexNone[] = "None"; | 65 const char kDuplexNone[] = "None"; |
66 #elif defined(OS_WIN) | 66 #elif defined(OS_WIN) |
67 const char kPskColor[] = "psk:Color"; | 67 const char kPskColor[] = "psk:Color"; |
68 const char kPskDuplexFeature[] = "psk:JobDuplexAllDocumentsContiguously"; | 68 const char kPskDuplexFeature[] = "psk:JobDuplexAllDocumentsContiguously"; |
69 const char kPskTwoSided[] = "psk:TwoSided"; | 69 const char kPskTwoSided[] = "psk:TwoSided"; |
70 #endif | 70 #endif |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 if (handler_) { | 266 if (handler_) { |
267 handler_->SetupPrinterList(*printers); | 267 handler_->SetupPrinterList(*printers); |
268 } | 268 } |
269 delete printers; | 269 delete printers; |
270 } | 270 } |
271 | 271 |
272 void GetPrinterCapabilities(const std::string& printer_name) { | 272 void GetPrinterCapabilities(const std::string& printer_name) { |
273 VLOG(1) << "Get printer capabilities start for " << printer_name; | 273 VLOG(1) << "Get printer capabilities start for " << printer_name; |
274 printing::PrinterCapsAndDefaults printer_info; | 274 printing::PrinterCapsAndDefaults printer_info; |
275 bool supports_color = true; | 275 bool supports_color = true; |
276 bool set_duplex_as_default = false; | 276 int default_duplex_setting_value = printing::UNKNOWN; |
277 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, | 277 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, |
278 &printer_info)) { | 278 &printer_info)) { |
279 return; | 279 return; |
280 } | 280 } |
281 | 281 |
282 #if defined(USE_CUPS) | 282 #if defined(USE_CUPS) |
283 FilePath ppd_file_path; | 283 FilePath ppd_file_path; |
284 if (!file_util::CreateTemporaryFile(&ppd_file_path)) | 284 if (!file_util::CreateTemporaryFile(&ppd_file_path)) |
285 return; | 285 return; |
286 | 286 |
(...skipping 12 matching lines...) Expand all Loading... |
299 if (attr && attr->value) | 299 if (attr && attr->value) |
300 supports_color = ppd->color_device; | 300 supports_color = ppd->color_device; |
301 | 301 |
302 ppd_choice_t* ch = ppdFindMarkedChoice(ppd, kDuplex); | 302 ppd_choice_t* ch = ppdFindMarkedChoice(ppd, kDuplex); |
303 if (ch == NULL) { | 303 if (ch == NULL) { |
304 ppd_option_t* option = ppdFindOption(ppd, kDuplex); | 304 ppd_option_t* option = ppdFindOption(ppd, kDuplex); |
305 if (option != NULL) | 305 if (option != NULL) |
306 ch = ppdFindChoice(option, option->defchoice); | 306 ch = ppdFindChoice(option, option->defchoice); |
307 } | 307 } |
308 | 308 |
309 if (ch != NULL && strcmp(ch->choice, kDuplexNone) != 0) | 309 if (ch != NULL) { |
310 set_duplex_as_default = true; | 310 if (strcmp(ch->choice, kDuplexNone) != 0) |
311 | 311 default_duplex_setting_value = printing::TWO_SIDED; |
| 312 else |
| 313 default_duplex_setting_value = printing::ONE_SIDED; |
| 314 } |
312 ppdClose(ppd); | 315 ppdClose(ppd); |
313 } | 316 } |
314 file_util::Delete(ppd_file_path, false); | 317 file_util::Delete(ppd_file_path, false); |
315 #elif defined(OS_WIN) | 318 #elif defined(OS_WIN) |
316 // According to XPS 1.0 spec, only color printers have psk:Color. | 319 // According to XPS 1.0 spec, only color printers have psk:Color. |
317 // Therefore we don't need to parse the whole XML file, we just need to | 320 // Therefore we don't need to parse the whole XML file, we just need to |
318 // search the string. The spec can be found at: | 321 // search the string. The spec can be found at: |
319 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. | 322 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. |
320 supports_color = (printer_info.printer_capabilities.find(kPskColor) != | 323 supports_color = (printer_info.printer_capabilities.find(kPskColor) != |
321 std::string::npos); | 324 std::string::npos); |
322 set_duplex_as_default = | 325 |
323 (printer_info.printer_defaults.find(kPskDuplexFeature) != | 326 if (printer_info.printer_defaults.find(kPskDuplexFeature) != |
324 std::string::npos) && | 327 std::string::npos) { |
325 (printer_info.printer_defaults.find(kPskTwoSided) != | 328 if (printer_info.printer_defaults.find(kPskTwoSided) != |
326 std::string::npos); | 329 std::string::npos) { |
| 330 default_duplex_setting_value = printing::TWO_SIDED; |
| 331 } else { |
| 332 default_duplex_setting_value = printing::ONE_SIDED; |
| 333 } |
| 334 } |
327 #else | 335 #else |
328 NOTIMPLEMENTED(); | 336 NOTIMPLEMENTED(); |
329 #endif | 337 #endif |
330 | 338 |
331 DictionaryValue settings_info; | 339 DictionaryValue settings_info; |
332 settings_info.SetBoolean(kDisableColorOption, !supports_color); | 340 settings_info.SetBoolean(kDisableColorOption, !supports_color); |
333 if (!supports_color) { | 341 if (!supports_color) { |
334 settings_info.SetBoolean(kSetColorAsDefault, false); | 342 settings_info.SetBoolean(kSetColorAsDefault, false); |
335 } else { | 343 } else { |
336 settings_info.SetBoolean(kSetColorAsDefault, | 344 settings_info.SetBoolean(kSetColorAsDefault, |
337 PrintPreviewHandler::last_used_color_setting_); | 345 PrintPreviewHandler::last_used_color_setting_); |
338 } | 346 } |
339 settings_info.SetBoolean(kSetDuplexAsDefault, set_duplex_as_default); | 347 settings_info.SetInteger(kPrinterDefaultDuplexValue, |
| 348 default_duplex_setting_value); |
340 BrowserThread::PostTask( | 349 BrowserThread::PostTask( |
341 BrowserThread::UI, FROM_HERE, | 350 BrowserThread::UI, FROM_HERE, |
342 NewRunnableMethod(this, | 351 NewRunnableMethod(this, |
343 &PrintSystemTaskProxy::SendPrinterCapabilities, | 352 &PrintSystemTaskProxy::SendPrinterCapabilities, |
344 settings_info.DeepCopy())); | 353 settings_info.DeepCopy())); |
345 } | 354 } |
346 | 355 |
347 void SendPrinterCapabilities(DictionaryValue* settings_info) { | 356 void SendPrinterCapabilities(DictionaryValue* settings_info) { |
348 if (handler_) | 357 if (handler_) |
349 handler_->SendPrinterCapabilities(*settings_info); | 358 handler_->SendPrinterCapabilities(*settings_info); |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 return; | 978 return; |
970 | 979 |
971 // We no longer require the initiator tab details. Remove those details | 980 // We no longer require the initiator tab details. Remove those details |
972 // associated with the preview tab to allow the initiator tab to create | 981 // associated with the preview tab to allow the initiator tab to create |
973 // another preview tab. | 982 // another preview tab. |
974 printing::PrintPreviewTabController* tab_controller = | 983 printing::PrintPreviewTabController* tab_controller = |
975 printing::PrintPreviewTabController::GetInstance(); | 984 printing::PrintPreviewTabController::GetInstance(); |
976 if (tab_controller) | 985 if (tab_controller) |
977 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 986 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
978 } | 987 } |
OLD | NEW |