Chromium Code Reviews| Index: chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
| diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
| index b1c37ad87dc483737770f8f229cd36732f2098a4..8ce4bab9b57ee2c8c275336eeaeaadf2d085b89a 100644 |
| --- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
| +++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
| @@ -45,6 +45,7 @@ |
| #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" |
| #include "chrome/common/chrome_paths.h" |
| #include "chrome/common/chrome_switches.h" |
| +#include "chrome/common/cloud_print/cloud_print_cdd_conversion.h" |
| #include "chrome/common/cloud_print/cloud_print_constants.h" |
| #include "chrome/common/crash_keys.h" |
| #include "chrome/common/pref_names.h" |
| @@ -349,6 +350,43 @@ scoped_ptr<base::DictionaryValue> GetPdfCapabilitiesOnFileThread( |
| return scoped_ptr<base::DictionaryValue>(description.root().DeepCopy()); |
| } |
| +scoped_ptr<base::DictionaryValue> GetLocalPrinterCapabilitiesOnFileThread( |
| + const std::string& printer_name) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + |
| + scoped_refptr<printing::PrintBackend> print_backend( |
| + printing::PrintBackend::CreateInstance(NULL)); |
| + |
| + VLOG(1) << "Get printer capabilities start for " << printer_name; |
| + crash_keys::ScopedPrinterInfo crash_key( |
| + print_backend->GetPrinterDriverInfo(printer_name)); |
| + |
| + if (!print_backend->IsValidPrinter(printer_name)) { |
| + LOG(WARNING) << "Invalid printer " << printer_name; |
| + return scoped_ptr<base::DictionaryValue>(); |
| + } |
| + |
| + printing::PrinterSemanticCapsAndDefaults info; |
| + if (!print_backend->GetPrinterSemanticCapsAndDefaults(printer_name, &info)) { |
| + LOG(WARNING) << "Failed to get capabilities for " << printer_name; |
| + return scoped_ptr<base::DictionaryValue>(); |
| + } |
| + |
| + scoped_ptr<base::DictionaryValue> description( |
| + cloud_print::PrinterSemanticCapsAndDefaultsToCdd(info)); |
| + if (description == NULL) { |
|
Vitaly Buka (NO REVIEWS)
2014/06/04 00:05:46
if (!description)
Aleksey Shlyapnikov
2014/06/04 02:02:47
Done.
|
| + LOG(WARNING) << "Failed to convert capabilities for " << printer_name; |
| + return scoped_ptr<base::DictionaryValue>(); |
| + } |
| + |
| +#if defined(USE_CUPS) |
| + // TODO(alekseys): Use CUSTOM_COLOR/MONOCHROME instead. |
| + description->SetInteger(kCUPSsColorModel, info.color_model); |
| + description->SetInteger(kCUPSsBWModel, info.bw_model); |
| +#endif |
| + return description.Pass(); |
| +} |
| + |
| void EnumeratePrintersOnFileThread(base::ListValue* printers) { |
| DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| @@ -410,64 +448,23 @@ void GetPrinterCapabilitiesOnFileThread( |
| DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| DCHECK(!printer_name.empty()); |
| - // Special case for PDF printer. |
| - if (printer_name == kLocalPdfPrinterId) { |
| - scoped_ptr<base::DictionaryValue> printer_info(new base::DictionaryValue); |
| - printer_info->SetString(kPrinterId, printer_name); |
| - printer_info->Set(kPrinterCapabilities, |
| - GetPdfCapabilitiesOnFileThread(locale).release()); |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind(success_cb, base::Owned(printer_info.release()))); |
| - return; |
| - } |
| - |
| - scoped_refptr<printing::PrintBackend> print_backend( |
| - printing::PrintBackend::CreateInstance(NULL)); |
| - |
| - VLOG(1) << "Get printer capabilities start for " << printer_name; |
| - crash_keys::ScopedPrinterInfo crash_key( |
| - print_backend->GetPrinterDriverInfo(printer_name)); |
| - |
| - if (!print_backend->IsValidPrinter(printer_name)) { |
| - // TODO(gene): Notify explicitly if printer is not valid, instead of |
| - // failed to get capabilities. |
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| - base::Bind(failure_cb, printer_name)); |
| - return; |
| - } |
| - |
| - printing::PrinterSemanticCapsAndDefaults info; |
| - if (!print_backend->GetPrinterSemanticCapsAndDefaults(printer_name, &info)) { |
| - LOG(WARNING) << "Failed to get capabilities for " << printer_name; |
| + scoped_ptr<base::DictionaryValue> printer_capabilities( |
| + printer_name == kLocalPdfPrinterId ? |
| + GetPdfCapabilitiesOnFileThread(locale) : |
| + GetLocalPrinterCapabilitiesOnFileThread(printer_name)); |
| + if (printer_capabilities == NULL) { |
|
Vitaly Buka (NO REVIEWS)
2014/06/04 00:05:46
if (!printer_capabilities) {
Aleksey Shlyapnikov
2014/06/04 02:02:47
Done.
|
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| base::Bind(failure_cb, printer_name)); |
| return; |
| } |
| - scoped_ptr<base::DictionaryValue> settings_info(new base::DictionaryValue); |
| - settings_info->SetString(kPrinterId, printer_name); |
| - settings_info->SetBoolean(kDisableColorOption, !info.color_changeable); |
| - settings_info->SetBoolean(printing::kSettingSetColorAsDefault, |
| - info.color_default); |
| -#if defined(USE_CUPS) |
| - settings_info->SetInteger(kCUPSsColorModel, info.color_model); |
| - settings_info->SetInteger(kCUPSsBWModel, info.bw_model); |
| -#endif |
| - |
| - // TODO(gene): Make new capabilities format for Print Preview |
| - // that will suit semantic capabilities better. |
| - // Refactor pld API code below |
| - bool default_duplex = info.duplex_capable ? |
| - (info.duplex_default != printing::SIMPLEX) : false; |
| - int duplex_value = info.duplex_capable ? |
| - printing::LONG_EDGE : printing::UNKNOWN_DUPLEX_MODE; |
| - settings_info->SetBoolean(kSetDuplexAsDefault, default_duplex); |
| - settings_info->SetInteger(kPrinterDefaultDuplexValue, duplex_value); |
| + scoped_ptr<base::DictionaryValue> printer_info(new base::DictionaryValue); |
| + printer_info->SetString(kPrinterId, printer_name); |
| + printer_info->Set(kPrinterCapabilities, printer_capabilities.release()); |
| BrowserThread::PostTask( |
| BrowserThread::UI, FROM_HERE, |
| - base::Bind(success_cb, base::Owned(settings_info.release()))); |
| + base::Bind(success_cb, base::Owned(printer_info.release()))); |
| } |
| base::LazyInstance<printing::StickySettings> g_sticky_settings = |
| @@ -1420,10 +1417,16 @@ void PrintPreviewHandler::SaveCUPSColorSetting( |
| const base::DictionaryValue* settings) { |
| cups_printer_color_models_.reset(new CUPSPrinterColorModels); |
| settings->GetString(kPrinterId, &cups_printer_color_models_->printer_name); |
| - settings->GetInteger( |
| + const base::DictionaryValue* capabilities = NULL; |
| + if (!settings->GetDictionary(kPrinterCapabilities, &capabilities) || |
| + !capabilities) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + capabilities->GetInteger( |
| kCUPSsColorModel, |
| reinterpret_cast<int*>(&cups_printer_color_models_->color_model)); |
| - settings->GetInteger( |
| + capabilities->GetInteger( |
| kCUPSsBWModel, |
| reinterpret_cast<int*>(&cups_printer_color_models_->bw_model)); |
| } |