Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 kSetDuplexAsDefault[] = "setDuplexAsDefault"; |
| 61 const char kPrinterColorModelForColor[] = "printerColorModelForColor"; | 61 const char kPrinterColorModelForColor[] = "printerColorModelForColor"; |
| 62 const char kPrinterDefaultDuplexValue[] = "printerDefaultDuplexValue"; | |
| 62 | 63 |
| 63 #if defined(USE_CUPS) | 64 #if defined(USE_CUPS) |
| 64 const char kColorDevice[] = "ColorDevice"; | 65 const char kColorDevice[] = "ColorDevice"; |
| 65 const char kColorModel[] = "ColorModel"; | 66 const char kColorModel[] = "ColorModel"; |
| 66 const char kColorModelForColor[] = "Color"; | 67 const char kColorModelForColor[] = "Color"; |
| 67 const char kCMYK[] = "CMYK"; | 68 const char kCMYK[] = "CMYK"; |
| 68 const char kDuplex[] = "Duplex"; | 69 const char kDuplex[] = "Duplex"; |
| 69 const char kDuplexNone[] = "None"; | 70 const char kDuplexNone[] = "None"; |
| 70 #elif defined(OS_WIN) | 71 #elif defined(OS_WIN) |
| 71 const char kPskColor[] = "psk:Color"; | 72 const char kPskColor[] = "psk:Color"; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 } | 275 } |
| 275 delete printers; | 276 delete printers; |
| 276 } | 277 } |
| 277 | 278 |
| 278 void GetPrinterCapabilities(const std::string& printer_name) { | 279 void GetPrinterCapabilities(const std::string& printer_name) { |
| 279 VLOG(1) << "Get printer capabilities start for " << printer_name; | 280 VLOG(1) << "Get printer capabilities start for " << printer_name; |
| 280 printing::PrinterCapsAndDefaults printer_info; | 281 printing::PrinterCapsAndDefaults printer_info; |
| 281 bool supports_color = true; | 282 bool supports_color = true; |
| 282 bool set_duplex_as_default = false; | 283 bool set_duplex_as_default = false; |
| 283 int printer_color_space = printing::GRAY; | 284 int printer_color_space = printing::GRAY; |
| 285 int default_duplex_setting_value = printing::UNKNOWN; | |
|
vandebo (ex-Chrome)
2011/09/07 21:55:57
nit: extra space
kmadhusu
2011/09/07 23:21:56
Done.
| |
| 284 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, | 286 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, |
| 285 &printer_info)) { | 287 &printer_info)) { |
| 286 return; | 288 return; |
| 287 } | 289 } |
| 288 | 290 |
| 289 #if defined(USE_CUPS) | 291 #if defined(USE_CUPS) |
| 290 FilePath ppd_file_path; | 292 FilePath ppd_file_path; |
| 291 if (!file_util::CreateTemporaryFile(&ppd_file_path)) | 293 if (!file_util::CreateTemporaryFile(&ppd_file_path)) |
| 292 return; | 294 return; |
| 293 | 295 |
| 294 int data_size = printer_info.printer_capabilities.length(); | 296 int data_size = printer_info.printer_capabilities.length(); |
| 295 if (data_size != file_util::WriteFile( | 297 if (data_size != file_util::WriteFile( |
| 296 ppd_file_path, | 298 ppd_file_path, |
| 297 printer_info.printer_capabilities.data(), | 299 printer_info.printer_capabilities.data(), |
| 298 data_size)) { | 300 data_size)) { |
| 299 file_util::Delete(ppd_file_path, false); | 301 file_util::Delete(ppd_file_path, false); |
| 300 return; | 302 return; |
| 301 } | 303 } |
| 302 | 304 |
| 303 ppd_file_t* ppd = ppdOpenFile(ppd_file_path.value().c_str()); | 305 ppd_file_t* ppd = ppdOpenFile(ppd_file_path.value().c_str()); |
| 304 if (ppd) { | 306 if (ppd) { |
| 305 ppd_attr_t* attr = ppdFindAttr(ppd, kColorDevice, NULL); | 307 ppd_attr_t* attr = ppdFindAttr(ppd, kColorDevice, NULL); |
| 306 if (attr && attr->value) | 308 if (attr && attr->value) |
| 307 supports_color = ppd->color_device; | 309 supports_color = ppd->color_device; |
| 308 | 310 |
| 309 ppd_choice_t* ch = ppdFindMarkedChoice(ppd, kDuplex); | 311 ppd_choice_t* ch = ppdFindMarkedChoice(ppd, kDuplex); |
|
vandebo (ex-Chrome)
2011/09/07 21:55:57
Can you fix ch? We don't use abbreviated variable
kmadhusu
2011/09/07 23:21:56
Done.
| |
| 310 if (ch == NULL) { | 312 if (ch == NULL) { |
| 311 ppd_option_t* option = ppdFindOption(ppd, kDuplex); | 313 ppd_option_t* option = ppdFindOption(ppd, kDuplex); |
| 312 if (option != NULL) | 314 if (option != NULL) |
| 313 ch = ppdFindChoice(option, option->defchoice); | 315 ch = ppdFindChoice(option, option->defchoice); |
| 314 } | 316 } |
| 315 | 317 |
| 316 if (ch != NULL && strcmp(ch->choice, kDuplexNone) != 0) | 318 if (ch != NULL && strcmp(ch->choice, kDuplexNone) != 0) |
| 317 set_duplex_as_default = true; | 319 set_duplex_as_default = true; |
| 318 | 320 |
| 319 if (supports_color) { | 321 if (supports_color) { |
| 320 // Identify the color space (COLOR/CMYK) for this printer. | 322 // Identify the color space (COLOR/CMYK) for this printer. |
| 321 ppd_option_t* color_model = ppdFindOption(ppd, kColorModel); | 323 ppd_option_t* color_model = ppdFindOption(ppd, kColorModel); |
| 322 if (color_model != NULL) { | 324 if (color_model != NULL) { |
| 323 if (ppdFindChoice(color_model, kColorModelForColor)) | 325 if (ppdFindChoice(color_model, kColorModelForColor)) |
| 324 printer_color_space = printing::COLOR; | 326 printer_color_space = printing::COLOR; |
| 325 else if (ppdFindChoice(color_model, kCMYK)) | 327 else if (ppdFindChoice(color_model, kCMYK)) |
| 326 printer_color_space = printing::CMYK; | 328 printer_color_space = printing::CMYK; |
| 327 } | 329 } |
| 328 } | 330 } |
| 329 | 331 |
| 332 if (ch != NULL) { | |
| 333 if (strcmp(ch->choice, kDuplexNone) != 0) | |
| 334 default_duplex_setting_value = printing::TWO_SIDED; | |
| 335 else | |
| 336 default_duplex_setting_value = printing::ONE_SIDED; | |
| 337 } | |
| 330 ppdClose(ppd); | 338 ppdClose(ppd); |
| 331 } | 339 } |
| 332 file_util::Delete(ppd_file_path, false); | 340 file_util::Delete(ppd_file_path, false); |
| 333 #elif defined(OS_WIN) | 341 #elif defined(OS_WIN) |
| 334 // According to XPS 1.0 spec, only color printers have psk:Color. | 342 // According to XPS 1.0 spec, only color printers have psk:Color. |
| 335 // Therefore we don't need to parse the whole XML file, we just need to | 343 // Therefore we don't need to parse the whole XML file, we just need to |
| 336 // search the string. The spec can be found at: | 344 // search the string. The spec can be found at: |
| 337 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. | 345 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. |
| 338 supports_color = (printer_info.printer_capabilities.find(kPskColor) != | 346 supports_color = (printer_info.printer_capabilities.find(kPskColor) != |
| 339 std::string::npos); | 347 std::string::npos); |
| 340 if (supports_color) | 348 if (supports_color) |
| 341 printer_color_space = printing::COLOR; | 349 printer_color_space = printing::COLOR; |
| 342 | 350 |
| 343 set_duplex_as_default = | 351 set_duplex_as_default = |
| 344 (printer_info.printer_defaults.find(kPskDuplexFeature) != | 352 (printer_info.printer_defaults.find(kPskDuplexFeature) != |
| 345 std::string::npos) && | 353 std::string::npos) && |
| 346 (printer_info.printer_defaults.find(kPskTwoSided) != | 354 (printer_info.printer_defaults.find(kPskTwoSided) != |
| 347 std::string::npos); | 355 std::string::npos); |
| 356 | |
| 357 if (printer_info.printer_defaults.find(kPskDuplexFeature) != | |
| 358 std::string::npos) { | |
| 359 if (printer_info.printer_defaults.find(kPskTwoSided) != | |
| 360 std::string::npos) { | |
| 361 default_duplex_setting_value = printing::TWO_SIDED; | |
| 362 } else { | |
| 363 default_duplex_setting_value = printing::ONE_SIDED; | |
| 364 } | |
| 365 } | |
| 348 #else | 366 #else |
| 349 NOTIMPLEMENTED(); | 367 NOTIMPLEMENTED(); |
| 350 #endif | 368 #endif |
| 351 | 369 |
| 352 DictionaryValue settings_info; | 370 DictionaryValue settings_info; |
| 353 settings_info.SetBoolean(kDisableColorOption, !supports_color); | 371 settings_info.SetBoolean(kDisableColorOption, !supports_color); |
| 354 if (!supports_color) { | 372 if (!supports_color) { |
| 355 settings_info.SetBoolean(kSetColorAsDefault, false); | 373 settings_info.SetBoolean(kSetColorAsDefault, false); |
| 356 } else { | 374 } else { |
| 357 settings_info.SetBoolean(kSetColorAsDefault, | 375 settings_info.SetBoolean(kSetColorAsDefault, |
| 358 PrintPreviewHandler::last_used_color_setting_); | 376 PrintPreviewHandler::last_used_color_setting_); |
| 359 } | 377 } |
| 360 settings_info.SetBoolean(kSetDuplexAsDefault, set_duplex_as_default); | 378 settings_info.SetBoolean(kSetDuplexAsDefault, set_duplex_as_default); |
| 361 settings_info.SetInteger(kPrinterColorModelForColor, printer_color_space); | 379 settings_info.SetInteger(kPrinterColorModelForColor, printer_color_space); |
| 380 settings_info.SetInteger(kPrinterDefaultDuplexValue, | |
| 381 default_duplex_setting_value); | |
| 362 BrowserThread::PostTask( | 382 BrowserThread::PostTask( |
| 363 BrowserThread::UI, FROM_HERE, | 383 BrowserThread::UI, FROM_HERE, |
| 364 NewRunnableMethod(this, | 384 NewRunnableMethod(this, |
| 365 &PrintSystemTaskProxy::SendPrinterCapabilities, | 385 &PrintSystemTaskProxy::SendPrinterCapabilities, |
| 366 settings_info.DeepCopy())); | 386 settings_info.DeepCopy())); |
| 367 } | 387 } |
| 368 | 388 |
| 369 void SendPrinterCapabilities(DictionaryValue* settings_info) { | 389 void SendPrinterCapabilities(DictionaryValue* settings_info) { |
| 370 if (handler_) | 390 if (handler_) |
| 371 handler_->SendPrinterCapabilities(*settings_info); | 391 handler_->SendPrinterCapabilities(*settings_info); |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 return; | 1018 return; |
| 999 | 1019 |
| 1000 // We no longer require the initiator tab details. Remove those details | 1020 // We no longer require the initiator tab details. Remove those details |
| 1001 // associated with the preview tab to allow the initiator tab to create | 1021 // associated with the preview tab to allow the initiator tab to create |
| 1002 // another preview tab. | 1022 // another preview tab. |
| 1003 printing::PrintPreviewTabController* tab_controller = | 1023 printing::PrintPreviewTabController* tab_controller = |
| 1004 printing::PrintPreviewTabController::GetInstance(); | 1024 printing::PrintPreviewTabController::GetInstance(); |
| 1005 if (tab_controller) | 1025 if (tab_controller) |
| 1006 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 1026 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
| 1007 } | 1027 } |
| OLD | NEW |