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/printing/print_system_task_proxy.h" | 5 #include "chrome/browser/printing/print_system_task_proxy.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 304 |
305 PrintSystemTaskProxy::PrintSystemTaskProxy( | 305 PrintSystemTaskProxy::PrintSystemTaskProxy( |
306 const base::WeakPtr<PrintPreviewHandler>& handler, | 306 const base::WeakPtr<PrintPreviewHandler>& handler, |
307 printing::PrintBackend* print_backend, | 307 printing::PrintBackend* print_backend, |
308 bool has_logged_printers_count) | 308 bool has_logged_printers_count) |
309 : handler_(handler), | 309 : handler_(handler), |
310 print_backend_(print_backend), | 310 print_backend_(print_backend), |
311 has_logged_printers_count_(has_logged_printers_count) { | 311 has_logged_printers_count_(has_logged_printers_count) { |
312 } | 312 } |
313 | 313 |
| 314 PrintSystemTaskProxy::PrintSystemTaskProxy() { |
| 315 } |
| 316 |
314 PrintSystemTaskProxy::~PrintSystemTaskProxy() { | 317 PrintSystemTaskProxy::~PrintSystemTaskProxy() { |
315 } | 318 } |
316 | 319 |
317 void PrintSystemTaskProxy::GetDefaultPrinter() { | 320 void PrintSystemTaskProxy::GetDefaultPrinter() { |
318 VLOG(1) << "Get default printer start"; | 321 VLOG(1) << "Get default printer start"; |
319 std::string* default_printer = NULL; | 322 std::string* default_printer = NULL; |
320 if (PrintPreviewHandler::last_used_printer_name_ == NULL) { | 323 if (PrintPreviewHandler::last_used_printer_name_ == NULL) { |
321 default_printer = new std::string(print_backend_->GetDefaultPrinterName()); | 324 default_printer = new std::string(print_backend_->GetDefaultPrinterName()); |
322 } else { | 325 } else { |
323 default_printer = new std::string( | 326 default_printer = new std::string( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 BrowserThread::UI, FROM_HERE, | 383 BrowserThread::UI, FROM_HERE, |
381 base::Bind(&PrintSystemTaskProxy::SetupPrinterList, this, printers)); | 384 base::Bind(&PrintSystemTaskProxy::SetupPrinterList, this, printers)); |
382 } | 385 } |
383 | 386 |
384 void PrintSystemTaskProxy::SetupPrinterList(ListValue* printers) { | 387 void PrintSystemTaskProxy::SetupPrinterList(ListValue* printers) { |
385 if (handler_) | 388 if (handler_) |
386 handler_->SetupPrinterList(*printers); | 389 handler_->SetupPrinterList(*printers); |
387 delete printers; | 390 delete printers; |
388 } | 391 } |
389 | 392 |
390 void PrintSystemTaskProxy::GetPrinterCapabilities( | |
391 const std::string& printer_name) { | |
392 VLOG(1) << "Get printer capabilities start for " << printer_name; | |
393 printing::PrinterCapsAndDefaults printer_info; | |
394 | |
395 bool set_color_as_default = false; | |
396 bool disable_color_options = true; | |
397 bool set_duplex_as_default = false; | |
398 int printer_color_space_for_color = printing::UNKNOWN_COLOR_MODEL; | |
399 int printer_color_space_for_black = printing::UNKNOWN_COLOR_MODEL; | |
400 int default_duplex_setting_value = printing::UNKNOWN_DUPLEX_MODE; | |
401 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, | |
402 &printer_info)) { | |
403 return; | |
404 } | |
405 | |
406 #if defined(USE_CUPS) | 393 #if defined(USE_CUPS) |
| 394 bool PrintSystemTaskProxy::GetPrinterCapabilitiesCUPS( |
| 395 const printing::PrinterCapsAndDefaults& printer_info, |
| 396 const std::string& printer_name, |
| 397 bool* set_color_as_default, |
| 398 int* printer_color_space_for_color, |
| 399 int* printer_color_space_for_black, |
| 400 bool* set_duplex_as_default, |
| 401 int* default_duplex_setting_value) { |
407 FilePath ppd_file_path; | 402 FilePath ppd_file_path; |
408 if (!file_util::CreateTemporaryFile(&ppd_file_path)) | 403 if (!file_util::CreateTemporaryFile(&ppd_file_path)) |
409 return; | 404 return false; |
410 | 405 |
411 int data_size = printer_info.printer_capabilities.length(); | 406 int data_size = printer_info.printer_capabilities.length(); |
412 if (data_size != file_util::WriteFile( | 407 if (data_size != file_util::WriteFile( |
413 ppd_file_path, | 408 ppd_file_path, |
414 printer_info.printer_capabilities.data(), | 409 printer_info.printer_capabilities.data(), |
415 data_size)) { | 410 data_size)) { |
416 file_util::Delete(ppd_file_path, false); | 411 file_util::Delete(ppd_file_path, false); |
417 return; | 412 return false; |
418 } | 413 } |
419 | 414 |
420 ppd_file_t* ppd = ppdOpenFile(ppd_file_path.value().c_str()); | 415 ppd_file_t* ppd = ppdOpenFile(ppd_file_path.value().c_str()); |
421 if (ppd) { | 416 if (ppd) { |
422 #if !defined(OS_MACOSX) | 417 #if !defined(OS_MACOSX) |
423 printing_internal::mark_lpoptions(printer_name, &ppd); | 418 printing_internal::mark_lpoptions(printer_name, &ppd); |
424 #endif | 419 #endif |
425 ppd_choice_t* duplex_choice = ppdFindMarkedChoice(ppd, kDuplex); | 420 ppd_choice_t* duplex_choice = ppdFindMarkedChoice(ppd, kDuplex); |
426 if (!duplex_choice) { | 421 if (!duplex_choice) { |
427 ppd_option_t* option = ppdFindOption(ppd, kDuplex); | 422 ppd_option_t* option = ppdFindOption(ppd, kDuplex); |
428 if (option) | 423 if (option) |
429 duplex_choice = ppdFindChoice(option, option->defchoice); | 424 duplex_choice = ppdFindChoice(option, option->defchoice); |
430 } | 425 } |
431 | 426 |
432 if (duplex_choice) { | 427 if (duplex_choice) { |
433 if (base::strcasecmp(duplex_choice->choice, kDuplexNone) != 0) { | 428 if (base::strcasecmp(duplex_choice->choice, kDuplexNone) != 0) { |
434 set_duplex_as_default = true; | 429 *set_duplex_as_default = true; |
435 default_duplex_setting_value = printing::LONG_EDGE; | 430 *default_duplex_setting_value = printing::LONG_EDGE; |
436 } else { | 431 } else { |
437 default_duplex_setting_value = printing::SIMPLEX; | 432 *default_duplex_setting_value = printing::SIMPLEX; |
438 } | 433 } |
439 } | 434 } |
440 | 435 |
441 bool is_color_device = false; | 436 bool is_color_device = false; |
442 ppd_attr_t* attr = ppdFindAttr(ppd, kColorDevice, NULL); | 437 ppd_attr_t* attr = ppdFindAttr(ppd, kColorDevice, NULL); |
443 if (attr && attr->value) | 438 if (attr && attr->value) |
444 is_color_device = ppd->color_device; | 439 is_color_device = ppd->color_device; |
445 disable_color_options = !is_color_device; | 440 *set_color_as_default = is_color_device; |
446 set_color_as_default = is_color_device; | |
447 | 441 |
448 if (!((is_color_device && getBasicColorModelSettings( | 442 if (!((is_color_device && getBasicColorModelSettings( |
449 ppd, &printer_color_space_for_black, | 443 ppd, printer_color_space_for_black, |
450 &printer_color_space_for_color, &set_color_as_default)) || | 444 printer_color_space_for_color, set_color_as_default)) || |
451 getPrintOutModeColorSettings( | 445 getPrintOutModeColorSettings( |
452 ppd, &printer_color_space_for_black, | 446 ppd, printer_color_space_for_black, |
453 &printer_color_space_for_color, &set_color_as_default) || | 447 printer_color_space_for_color, set_color_as_default) || |
454 getColorModeSettings( | 448 getColorModeSettings( |
455 ppd, &printer_color_space_for_black, | 449 ppd, printer_color_space_for_black, |
456 &printer_color_space_for_color, &set_color_as_default) || | 450 printer_color_space_for_color, set_color_as_default) || |
457 getHPColorSettings( | 451 getHPColorSettings( |
458 ppd, &printer_color_space_for_black, | 452 ppd, printer_color_space_for_black, |
459 &printer_color_space_for_color, &set_color_as_default) || | 453 printer_color_space_for_color, set_color_as_default) || |
460 getProcessColorModelSettings( | 454 getProcessColorModelSettings( |
461 ppd, &printer_color_space_for_black, | 455 ppd, printer_color_space_for_black, |
462 &printer_color_space_for_color, &set_color_as_default))) { | 456 printer_color_space_for_color, set_color_as_default))) { |
463 VLOG(1) << "Unknown printer color model"; | 457 VLOG(1) << "Unknown printer color model"; |
464 } | 458 } |
465 ppdClose(ppd); | 459 ppdClose(ppd); |
466 } | 460 } |
467 file_util::Delete(ppd_file_path, false); | 461 file_util::Delete(ppd_file_path, false); |
468 #elif defined(OS_WIN) | 462 return true; |
| 463 } |
| 464 #endif // defined(USE_CUPS) |
| 465 |
| 466 #if defined(OS_WIN) |
| 467 void PrintSystemTaskProxy::GetPrinterCapabilitiesWin( |
| 468 const printing::PrinterCapsAndDefaults& printer_info, |
| 469 bool* set_color_as_default, |
| 470 int* printer_color_space_for_color, |
| 471 int* printer_color_space_for_black, |
| 472 bool* set_duplex_as_default, |
| 473 int* default_duplex_setting_value) { |
469 // According to XPS 1.0 spec, only color printers have psk:Color. | 474 // According to XPS 1.0 spec, only color printers have psk:Color. |
470 // Therefore we don't need to parse the whole XML file, we just need to | 475 // Therefore we don't need to parse the whole XML file, we just need to |
471 // search the string. The spec can be found at: | 476 // search the string. The spec can be found at: |
472 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. | 477 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. |
473 if (printer_info.printer_capabilities.find(kPskColor) != std::string::npos) | 478 if (printer_info.printer_capabilities.find(kPskColor) != std::string::npos) |
474 printer_color_space_for_color = printing::COLOR; | 479 *printer_color_space_for_color = printing::COLOR; |
475 | 480 |
476 if ((printer_info.printer_capabilities.find(kPskGray) != | 481 if ((printer_info.printer_capabilities.find(kPskGray) != |
477 std::string::npos) || | 482 std::string::npos) || |
478 (printer_info.printer_capabilities.find(kPskMonochrome) != | 483 (printer_info.printer_capabilities.find(kPskMonochrome) != |
479 std::string::npos)) { | 484 std::string::npos)) { |
480 printer_color_space_for_black = printing::GRAY; | 485 *printer_color_space_for_black = printing::GRAY; |
481 } | 486 } |
482 set_color_as_default = | 487 *set_color_as_default = |
483 (printer_info.printer_defaults.find(kPskColor) != std::string::npos); | 488 (printer_info.printer_defaults.find(kPskColor) != std::string::npos); |
484 | 489 |
485 set_duplex_as_default = | 490 *set_duplex_as_default = |
486 (printer_info.printer_defaults.find(kPskDuplexFeature) != | 491 (printer_info.printer_defaults.find(kPskDuplexFeature) != |
487 std::string::npos) && | 492 std::string::npos) && |
488 (printer_info.printer_defaults.find(kPskTwoSided) != | 493 (printer_info.printer_defaults.find(kPskTwoSided) != |
489 std::string::npos); | 494 std::string::npos); |
490 | 495 |
491 if (printer_info.printer_defaults.find(kPskDuplexFeature) != | 496 if (printer_info.printer_defaults.find(kPskDuplexFeature) != |
492 std::string::npos) { | 497 std::string::npos) { |
493 if (printer_info.printer_defaults.find(kPskTwoSided) != | 498 if (printer_info.printer_defaults.find(kPskTwoSided) != |
494 std::string::npos) { | 499 std::string::npos) { |
495 default_duplex_setting_value = printing::LONG_EDGE; | 500 *default_duplex_setting_value = printing::LONG_EDGE; |
496 } else { | 501 } else { |
497 default_duplex_setting_value = printing::SIMPLEX; | 502 *default_duplex_setting_value = printing::SIMPLEX; |
498 } | 503 } |
499 } | 504 } |
| 505 } |
| 506 #endif // defined(OS_WIN) |
| 507 |
| 508 void PrintSystemTaskProxy::GetPrinterCapabilities( |
| 509 const std::string& printer_name) { |
| 510 VLOG(1) << "Get printer capabilities start for " << printer_name; |
| 511 printing::PrinterCapsAndDefaults printer_info; |
| 512 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, |
| 513 &printer_info)) { |
| 514 return; |
| 515 } |
| 516 |
| 517 bool set_color_as_default = false; |
| 518 bool set_duplex_as_default = false; |
| 519 int printer_color_space_for_color = printing::UNKNOWN_COLOR_MODEL; |
| 520 int printer_color_space_for_black = printing::UNKNOWN_COLOR_MODEL; |
| 521 int default_duplex_setting_value = printing::UNKNOWN_DUPLEX_MODE; |
| 522 |
| 523 #if defined(USE_CUPS) |
| 524 if (!GetPrinterCapabilitiesCUPS(printer_info, |
| 525 printer_name, |
| 526 &set_color_as_default, |
| 527 &printer_color_space_for_color, |
| 528 &printer_color_space_for_black, |
| 529 &set_duplex_as_default, |
| 530 &default_duplex_setting_value)) { |
| 531 return; |
| 532 } |
| 533 #elif defined(OS_WIN) |
| 534 GetPrinterCapabilitiesWin(printer_info, |
| 535 &set_color_as_default, |
| 536 &printer_color_space_for_color, |
| 537 &printer_color_space_for_black, |
| 538 &set_duplex_as_default, |
| 539 &default_duplex_setting_value); |
500 #else | 540 #else |
501 NOTIMPLEMENTED(); | 541 NOTIMPLEMENTED(); |
502 #endif | 542 #endif |
503 disable_color_options = !printer_color_space_for_color || | 543 bool disable_color_options = (!printer_color_space_for_color || |
504 !printer_color_space_for_black || | 544 !printer_color_space_for_black || |
505 (printer_color_space_for_color == | 545 (printer_color_space_for_color == |
506 printer_color_space_for_black); | 546 printer_color_space_for_black)); |
507 | 547 |
508 DictionaryValue settings_info; | 548 DictionaryValue settings_info; |
509 settings_info.SetBoolean(kDisableColorOption, disable_color_options); | 549 settings_info.SetBoolean(kDisableColorOption, disable_color_options); |
510 if (printer_color_space_for_color == printing::UNKNOWN_COLOR_MODEL) | 550 if (printer_color_space_for_color == printing::UNKNOWN_COLOR_MODEL) |
511 printer_color_space_for_color = printing::COLOR; | 551 printer_color_space_for_color = printing::COLOR; |
512 | 552 |
513 if (printer_color_space_for_black == printing::UNKNOWN_COLOR_MODEL) | 553 if (printer_color_space_for_black == printing::UNKNOWN_COLOR_MODEL) |
514 printer_color_space_for_black = printing::GRAY; | 554 printer_color_space_for_black = printing::GRAY; |
515 | 555 |
516 if (disable_color_options || | 556 if (disable_color_options || |
(...skipping 18 matching lines...) Expand all Loading... |
535 base::Bind(&PrintSystemTaskProxy::SendPrinterCapabilities, this, | 575 base::Bind(&PrintSystemTaskProxy::SendPrinterCapabilities, this, |
536 settings_info.DeepCopy())); | 576 settings_info.DeepCopy())); |
537 } | 577 } |
538 | 578 |
539 void PrintSystemTaskProxy::SendPrinterCapabilities( | 579 void PrintSystemTaskProxy::SendPrinterCapabilities( |
540 DictionaryValue* settings_info) { | 580 DictionaryValue* settings_info) { |
541 if (handler_) | 581 if (handler_) |
542 handler_->SendPrinterCapabilities(*settings_info); | 582 handler_->SendPrinterCapabilities(*settings_info); |
543 delete settings_info; | 583 delete settings_info; |
544 } | 584 } |
OLD | NEW |