diff options
-rw-r--r-- | chrome/browser/ui/webui/print_preview/print_preview_handler.cc | 68 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview/print_preview_handler.h | 16 | ||||
-rw-r--r-- | printing/backend/cups_helper.cc | 2 | ||||
-rw-r--r-- | printing/backend/print_backend.h | 5 |
4 files changed, 90 insertions, 1 deletions
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 28e2e5f..faf981b 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc +++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc @@ -173,6 +173,10 @@ const char kPrinterId[] = "printerId"; const char kDisableColorOption[] = "disableColorOption"; const char kSetDuplexAsDefault[] = "setDuplexAsDefault"; const char kPrinterDefaultDuplexValue[] = "printerDefaultDuplexValue"; +#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. @@ -328,6 +332,11 @@ void GetPrinterCapabilitiesOnFileThread( 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 capabiltities better. // Refactor pld API code below @@ -352,6 +361,14 @@ printing::StickySettings* GetStickySettings() { } // 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: @@ -658,6 +675,10 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) { // Remove selection only flag for the same reason. settings->Remove(printing::kSettingShouldPrintSelectionOnly, NULL); +#if defined(USE_CUPS) + ConvertColorSettingToCUPSColorModel(settings.get()); +#endif + // Set ID to know whether printing is for preview. settings->SetInteger(printing::kPreviewUIID, print_preview_ui->GetIDForPrintPreviewUI()); @@ -992,6 +1013,11 @@ void PrintPreviewHandler::SendAccessToken(const std::string& type, void PrintPreviewHandler::SendPrinterCapabilities( const DictionaryValue* settings_info) { VLOG(1) << "Get printer capabilities finished"; + +#if defined(USE_CUPS) + SaveCUPSColorSetting(settings_info); +#endif + web_ui()->CallJavascriptFunction("updateWithPrinterCapabilities", *settings_info); } @@ -1171,3 +1197,45 @@ bool PrintPreviewHandler::GetPreviewDataAndTitle( *title = print_preview_ui->initiator_title(); 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); + settings->GetInteger( + kCUPSsColorModel, + reinterpret_cast<int*>(&cups_printer_color_models_->color_model)); + settings->GetInteger( + kCUPSsBWModel, + reinterpret_cast<int*>(&cups_printer_color_models_->bw_model)); +} + +void PrintPreviewHandler::ConvertColorSettingToCUPSColorModel( + base::DictionaryValue* settings) const { + // 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; + } + + printing::ColorModel bw_model = cups_printer_color_models_->bw_model; + if (color == printing::GRAY && bw_model != printing::UNKNOWN_COLOR_MODEL) { + settings->SetInteger(printing::kSettingColor, bw_model); + return; + } + DCHECK_EQ(printing::COLOR, color); + printing::ColorModel color_model = cups_printer_color_models_->color_model; + if (color_model != printing::UNKNOWN_COLOR_MODEL) + settings->SetInteger(printing::kSettingColor, color_model); +} + +#endif diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.h b/chrome/browser/ui/webui/print_preview/print_preview_handler.h index 452f311..5500c32 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_handler.h +++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.h @@ -67,6 +67,9 @@ class PrintPreviewHandler : public content::WebUIMessageHandler, void ShowSystemDialog(); private: + class AccessTokenService; + struct CUPSPrinterColorModels; + content::WebContents* preview_web_contents() const; // Gets the list of printers. |args| is unused. @@ -191,6 +194,13 @@ class PrintPreviewHandler : public content::WebUIMessageHandler, bool GetPreviewDataAndTitle(scoped_refptr<base::RefCountedBytes>* data, string16* title) const; +#if defined(USE_CUPS) + void SaveCUPSColorSetting(const base::DictionaryValue* settings); + + void ConvertColorSettingToCUPSColorModel( + base::DictionaryValue* settings) const; +#endif + // Pointer to current print system. scoped_refptr<printing::PrintBackend> print_backend_; @@ -216,9 +226,13 @@ class PrintPreviewHandler : public content::WebUIMessageHandler, scoped_ptr<base::FilePath> print_to_pdf_path_; // Holds token service to get OAuth2 access tokens. - class AccessTokenService; scoped_ptr<AccessTokenService> token_service_; +#if defined(USE_CUPS) + // The color capabilities from the last printer queried. + scoped_ptr<CUPSPrinterColorModels> cups_printer_color_models_; +#endif + base::WeakPtrFactory<PrintPreviewHandler> weak_factory_; DISALLOW_COPY_AND_ASSIGN(PrintPreviewHandler); diff --git a/printing/backend/cups_helper.cc b/printing/backend/cups_helper.cc index eb49ca4..74df558 100644 --- a/printing/backend/cups_helper.cc +++ b/printing/backend/cups_helper.cc @@ -386,6 +386,8 @@ bool ParsePpdCapabilities( (cm_black != UNKNOWN_COLOR_MODEL) && (cm_color != cm_black)); caps.color_default = is_color; + caps.color_model = cm_color; + caps.bw_model = cm_black; ppdClose(ppd); base::DeleteFile(ppd_file_path, false); diff --git a/printing/backend/print_backend.h b/printing/backend/print_backend.h index 506bf07..1d058bf 100644 --- a/printing/backend/print_backend.h +++ b/printing/backend/print_backend.h @@ -42,6 +42,11 @@ struct PRINTING_EXPORT PrinterSemanticCapsAndDefaults { bool color_changeable; bool duplex_capable; +#if defined(USE_CUPS) + ColorModel color_model; + ColorModel bw_model; +#endif + // Current defaults. bool color_default; DuplexMode duplex_default; |