Index: trunk/src/chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
=================================================================== |
--- trunk/src/chrome/browser/ui/webui/print_preview/print_preview_handler.cc (revision 275710) |
+++ trunk/src/chrome/browser/ui/webui/print_preview/print_preview_handler.cc (working copy) |
@@ -22,7 +22,6 @@ |
#include "base/metrics/histogram.h" |
#include "base/path_service.h" |
#include "base/prefs/pref_service.h" |
-#include "base/strings/string_number_conversions.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/threading/thread.h" |
#include "base/threading/thread_restrictions.h" |
@@ -191,6 +190,10 @@ |
// Additional printer capability setting keys. |
const char kPrinterId[] = "printerId"; |
const char kPrinterCapabilities[] = "capabilities"; |
+#if defined(USE_CUPS) |
+const char kCUPSsColorModel[] = "cupsColorModel"; |
+const char kCUPSsBWModel[] = "cupsBWModel"; |
+#endif |
// Get the print job settings dictionary from |args|. The caller takes |
// ownership of the returned DictionaryValue. Returns NULL on failure. |
@@ -314,11 +317,7 @@ |
orientation.SaveTo(&description); |
ColorCapability color; |
- { |
- Color standard_color(STANDARD_COLOR); |
- standard_color.vendor_id = base::IntToString(printing::COLOR); |
- color.AddDefaultOption(standard_color, true); |
- } |
+ color.AddDefaultOption(Color(STANDARD_COLOR), true); |
color.SaveTo(&description); |
static const cloud_devices::printer::MediaType kPdfMedia[] = { |
@@ -377,6 +376,11 @@ |
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(); |
} |
@@ -469,6 +473,14 @@ |
} // namespace |
+#if defined(USE_CUPS) |
+struct PrintPreviewHandler::CUPSPrinterColorModels { |
+ std::string printer_name; |
+ printing::ColorModel color_model; |
+ printing::ColorModel bw_model; |
+}; |
+#endif |
+ |
class PrintPreviewHandler::AccessTokenService |
: public OAuth2TokenService::Consumer { |
public: |
@@ -868,6 +880,11 @@ |
// Reset selection only flag for the same reason. |
settings->SetBoolean(printing::kSettingShouldPrintSelectionOnly, false); |
+#if defined(USE_CUPS) |
+ if (!open_pdf_in_preview) // We can get here even for cloud printers. |
+ ConvertColorSettingToCUPSColorModel(settings.get()); |
+#endif |
+ |
// Set ID to know whether printing is for preview. |
settings->SetInteger(printing::kPreviewUIID, |
print_preview_ui->GetIDForPrintPreviewUI()); |
@@ -1212,6 +1229,11 @@ |
void PrintPreviewHandler::SendPrinterCapabilities( |
const base::DictionaryValue* settings_info) { |
VLOG(1) << "Get printer capabilities finished"; |
+ |
+#if defined(USE_CUPS) |
+ SaveCUPSColorSetting(settings_info); |
+#endif |
+ |
web_ui()->CallJavascriptFunction("updateWithPrinterCapabilities", |
*settings_info); |
} |
@@ -1388,6 +1410,59 @@ |
return true; |
} |
+#if defined(USE_CUPS) |
+void PrintPreviewHandler::SaveCUPSColorSetting( |
+ const base::DictionaryValue* settings) { |
+ cups_printer_color_models_.reset(new CUPSPrinterColorModels); |
+ settings->GetString(kPrinterId, &cups_printer_color_models_->printer_name); |
+ 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)); |
+ capabilities->GetInteger( |
+ kCUPSsBWModel, |
+ reinterpret_cast<int*>(&cups_printer_color_models_->bw_model)); |
+} |
+ |
+void PrintPreviewHandler::ConvertColorSettingToCUPSColorModel( |
+ base::DictionaryValue* settings) const { |
+ if (!cups_printer_color_models_) |
+ return; |
+ |
+ // Sanity check the printer name. |
+ std::string printer_name; |
+ if (!settings->GetString(printing::kSettingDeviceName, &printer_name) || |
+ printer_name != cups_printer_color_models_->printer_name) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ |
+ int color; |
+ if (!settings->GetInteger(printing::kSettingColor, &color)) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ |
+ if (color == printing::GRAY) { |
+ if (cups_printer_color_models_->bw_model != printing::UNKNOWN_COLOR_MODEL) { |
+ settings->SetInteger(printing::kSettingColor, |
+ cups_printer_color_models_->bw_model); |
+ } |
+ return; |
+ } |
+ |
+ printing::ColorModel color_model = cups_printer_color_models_->color_model; |
+ if (color_model != printing::UNKNOWN_COLOR_MODEL) |
+ settings->SetInteger(printing::kSettingColor, color_model); |
+} |
+ |
+#endif // defined(USE_CUPS) |
+ |
#if defined(ENABLE_SERVICE_DISCOVERY) |
void PrintPreviewHandler::LocalPrinterChanged( |
bool added, |