OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 print_backend_(print_backend), | 312 print_backend_(print_backend), |
313 has_logged_printers_count_(has_logged_printers_count) { | 313 has_logged_printers_count_(has_logged_printers_count) { |
314 } | 314 } |
315 | 315 |
316 PrintSystemTaskProxy::~PrintSystemTaskProxy() { | 316 PrintSystemTaskProxy::~PrintSystemTaskProxy() { |
317 } | 317 } |
318 | 318 |
319 void PrintSystemTaskProxy::GetDefaultPrinter() { | 319 void PrintSystemTaskProxy::GetDefaultPrinter() { |
320 VLOG(1) << "Get default printer start"; | 320 VLOG(1) << "Get default printer start"; |
321 | 321 |
322 std::string* default_printer = NULL; | |
323 default_printer = new std::string(print_backend_->GetDefaultPrinterName()); | |
324 | |
325 VLOG(1) << "Get default printer finished, found: " | 322 VLOG(1) << "Get default printer finished, found: " |
326 << *default_printer; | 323 << print_backend_->GetDefaultPrinterName(); |
327 | |
328 std::string* cloud_print_data = new std::string; | |
329 | 324 |
330 BrowserThread::PostTask( | 325 BrowserThread::PostTask( |
331 BrowserThread::UI, FROM_HERE, | 326 BrowserThread::UI, FROM_HERE, |
332 base::Bind(&PrintSystemTaskProxy::SendDefaultPrinter, this, | 327 base::Bind(&PrintSystemTaskProxy::SendDefaultPrinter, this, |
333 default_printer, cloud_print_data)); | 328 print_backend_->GetDefaultPrinterName(), |
| 329 std::string())); |
334 } | 330 } |
335 | 331 |
336 void PrintSystemTaskProxy::SendDefaultPrinter( | 332 void PrintSystemTaskProxy::SendDefaultPrinter( |
337 const std::string* default_printer, const std::string* cloud_print_data) { | 333 const std::string& default_printer, |
| 334 const std::string& cloud_print_data) { |
338 if (handler_) | 335 if (handler_) |
339 handler_->SendInitialSettings(*default_printer, *cloud_print_data); | 336 handler_->SendInitialSettings(default_printer, cloud_print_data); |
340 delete default_printer; | |
341 } | 337 } |
342 | 338 |
343 void PrintSystemTaskProxy::EnumeratePrinters() { | 339 void PrintSystemTaskProxy::EnumeratePrinters() { |
344 VLOG(1) << "Enumerate printers start"; | 340 VLOG(1) << "Enumerate printers start"; |
345 ListValue* printers = new ListValue; | 341 ListValue* printers = new ListValue; |
346 printing::PrinterList printer_list; | 342 printing::PrinterList printer_list; |
347 print_backend_->EnumeratePrinters(&printer_list); | 343 print_backend_->EnumeratePrinters(&printer_list); |
348 | 344 |
349 if (!has_logged_printers_count_) { | 345 if (!has_logged_printers_count_) { |
350 // Record the total number of printers. | 346 // Record the total number of printers. |
(...skipping 24 matching lines...) Expand all Loading... |
375 BrowserThread::UI, FROM_HERE, | 371 BrowserThread::UI, FROM_HERE, |
376 base::Bind(&PrintSystemTaskProxy::SetupPrinterList, this, printers)); | 372 base::Bind(&PrintSystemTaskProxy::SetupPrinterList, this, printers)); |
377 } | 373 } |
378 | 374 |
379 void PrintSystemTaskProxy::SetupPrinterList(ListValue* printers) { | 375 void PrintSystemTaskProxy::SetupPrinterList(ListValue* printers) { |
380 if (handler_) | 376 if (handler_) |
381 handler_->SetupPrinterList(*printers); | 377 handler_->SetupPrinterList(*printers); |
382 delete printers; | 378 delete printers; |
383 } | 379 } |
384 | 380 |
385 #if defined(USE_CUPS) | 381 bool PrintSystemTaskProxy::ParsePrinterCapabilities( |
386 // static | |
387 bool PrintSystemTaskProxy::GetPrinterCapabilitiesCUPS( | |
388 const printing::PrinterCapsAndDefaults& printer_info, | 382 const printing::PrinterCapsAndDefaults& printer_info, |
389 const std::string& printer_name, | 383 const std::string& printer_name, |
390 bool* set_color_as_default, | 384 bool* set_color_as_default, |
391 int* printer_color_space_for_color, | 385 int* printer_color_space_for_color, |
392 int* printer_color_space_for_black, | 386 int* printer_color_space_for_black, |
393 bool* set_duplex_as_default, | 387 bool* set_duplex_as_default, |
394 int* default_duplex_setting_value) { | 388 int* default_duplex_setting_value) { |
| 389 #if defined(USE_CUPS) |
395 FilePath ppd_file_path; | 390 FilePath ppd_file_path; |
396 if (!file_util::CreateTemporaryFile(&ppd_file_path)) | 391 if (!file_util::CreateTemporaryFile(&ppd_file_path)) |
397 return false; | 392 return false; |
398 | 393 |
399 int data_size = printer_info.printer_capabilities.length(); | 394 int data_size = printer_info.printer_capabilities.length(); |
400 if (data_size != file_util::WriteFile( | 395 if (data_size != file_util::WriteFile( |
401 ppd_file_path, | 396 ppd_file_path, |
402 printer_info.printer_capabilities.data(), | 397 printer_info.printer_capabilities.data(), |
403 data_size)) { | 398 data_size)) { |
404 file_util::Delete(ppd_file_path, false); | 399 file_util::Delete(ppd_file_path, false); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 printer_color_space_for_color, set_color_as_default) || | 441 printer_color_space_for_color, set_color_as_default) || |
447 getProcessColorModelSettings( | 442 getProcessColorModelSettings( |
448 ppd, printer_color_space_for_black, | 443 ppd, printer_color_space_for_black, |
449 printer_color_space_for_color, set_color_as_default))) { | 444 printer_color_space_for_color, set_color_as_default))) { |
450 VLOG(1) << "Unknown printer color model"; | 445 VLOG(1) << "Unknown printer color model"; |
451 } | 446 } |
452 ppdClose(ppd); | 447 ppdClose(ppd); |
453 } | 448 } |
454 file_util::Delete(ppd_file_path, false); | 449 file_util::Delete(ppd_file_path, false); |
455 return true; | 450 return true; |
456 } | |
457 #endif // defined(USE_CUPS) | |
458 | 451 |
459 #if defined(OS_WIN) | 452 #elif defined(OS_WIN) |
460 void PrintSystemTaskProxy::GetPrinterCapabilitiesWin( | 453 |
461 const printing::PrinterCapsAndDefaults& printer_info, | |
462 bool* set_color_as_default, | |
463 int* printer_color_space_for_color, | |
464 int* printer_color_space_for_black, | |
465 bool* set_duplex_as_default, | |
466 int* default_duplex_setting_value) { | |
467 // According to XPS 1.0 spec, only color printers have psk:Color. | 454 // According to XPS 1.0 spec, only color printers have psk:Color. |
468 // Therefore we don't need to parse the whole XML file, we just need to | 455 // Therefore we don't need to parse the whole XML file, we just need to |
469 // search the string. The spec can be found at: | 456 // search the string. The spec can be found at: |
470 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. | 457 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. |
471 if (printer_info.printer_capabilities.find(kPskColor) != std::string::npos) | 458 if (printer_info.printer_capabilities.find(kPskColor) != std::string::npos) |
472 *printer_color_space_for_color = printing::COLOR; | 459 *printer_color_space_for_color = printing::COLOR; |
473 | 460 |
474 if ((printer_info.printer_capabilities.find(kPskGray) != | 461 if ((printer_info.printer_capabilities.find(kPskGray) != |
475 std::string::npos) || | 462 std::string::npos) || |
476 (printer_info.printer_capabilities.find(kPskMonochrome) != | 463 (printer_info.printer_capabilities.find(kPskMonochrome) != |
(...skipping 11 matching lines...) Expand all Loading... |
488 | 475 |
489 if (printer_info.printer_defaults.find(kPskDuplexFeature) != | 476 if (printer_info.printer_defaults.find(kPskDuplexFeature) != |
490 std::string::npos) { | 477 std::string::npos) { |
491 if (printer_info.printer_defaults.find(kPskTwoSided) != | 478 if (printer_info.printer_defaults.find(kPskTwoSided) != |
492 std::string::npos) { | 479 std::string::npos) { |
493 *default_duplex_setting_value = printing::LONG_EDGE; | 480 *default_duplex_setting_value = printing::LONG_EDGE; |
494 } else { | 481 } else { |
495 *default_duplex_setting_value = printing::SIMPLEX; | 482 *default_duplex_setting_value = printing::SIMPLEX; |
496 } | 483 } |
497 } | 484 } |
| 485 return true; |
| 486 |
| 487 #else |
| 488 |
| 489 NOTIMPLEMENTED(); |
| 490 return false; |
| 491 |
| 492 #endif // defined(OS_WIN) |
498 } | 493 } |
499 #endif // defined(OS_WIN) | 494 |
500 | 495 |
501 void PrintSystemTaskProxy::GetPrinterCapabilities( | 496 void PrintSystemTaskProxy::GetPrinterCapabilities( |
502 const std::string& printer_name) { | 497 const std::string& printer_name) { |
503 VLOG(1) << "Get printer capabilities start for " << printer_name; | 498 VLOG(1) << "Get printer capabilities start for " << printer_name; |
504 child_process_logging::ScopedPrinterInfoSetter prn_info( | 499 child_process_logging::ScopedPrinterInfoSetter prn_info( |
505 print_backend_->GetPrinterDriverInfo(printer_name)); | 500 print_backend_->GetPrinterDriverInfo(printer_name)); |
506 | 501 |
507 bool set_color_as_default = false; | 502 bool set_color_as_default = false; |
508 bool set_duplex_as_default = false; | 503 bool set_duplex_as_default = false; |
509 int printer_color_space_for_color = printing::UNKNOWN_COLOR_MODEL; | 504 int printer_color_space_for_color = printing::UNKNOWN_COLOR_MODEL; |
510 int printer_color_space_for_black = printing::UNKNOWN_COLOR_MODEL; | 505 int printer_color_space_for_black = printing::UNKNOWN_COLOR_MODEL; |
511 int default_duplex_setting_value = printing::UNKNOWN_DUPLEX_MODE; | 506 int default_duplex_setting_value = printing::UNKNOWN_DUPLEX_MODE; |
512 | 507 |
513 printing::PrinterCapsAndDefaults printer_info; | 508 printing::PrinterCapsAndDefaults printer_info; |
514 if (print_backend_->GetPrinterCapsAndDefaults(printer_name, | 509 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, |
515 &printer_info)) { | 510 &printer_info) || |
516 #if defined(USE_CUPS) | 511 !ParsePrinterCapabilities(printer_info, |
517 if (!GetPrinterCapabilitiesCUPS(printer_info, | 512 printer_name, |
518 printer_name, | 513 &set_color_as_default, |
519 &set_color_as_default, | 514 &printer_color_space_for_color, |
520 &printer_color_space_for_color, | 515 &printer_color_space_for_black, |
521 &printer_color_space_for_black, | 516 &set_duplex_as_default, |
522 &set_duplex_as_default, | 517 &default_duplex_setting_value)) { |
523 &default_duplex_setting_value)) { | 518 BrowserThread::PostTask( |
524 return; | 519 BrowserThread::UI, FROM_HERE, |
525 } | 520 base::Bind(&PrintSystemTaskProxy::SendFailedToGetPrinterCapabilities, |
526 #elif defined(OS_WIN) | 521 this, printer_name)); |
527 GetPrinterCapabilitiesWin(printer_info, | 522 return; |
528 &set_color_as_default, | |
529 &printer_color_space_for_color, | |
530 &printer_color_space_for_black, | |
531 &set_duplex_as_default, | |
532 &default_duplex_setting_value); | |
533 #else | |
534 NOTIMPLEMENTED(); | |
535 #endif | |
536 } | 523 } |
537 bool disable_color_options = (!printer_color_space_for_color || | 524 bool disable_color_options = (!printer_color_space_for_color || |
538 !printer_color_space_for_black || | 525 !printer_color_space_for_black || |
539 (printer_color_space_for_color == | 526 (printer_color_space_for_color == |
540 printer_color_space_for_black)); | 527 printer_color_space_for_black)); |
541 | 528 |
542 DictionaryValue settings_info; | 529 DictionaryValue settings_info; |
543 settings_info.SetString(kPrinterId, printer_name); | 530 settings_info.SetString(kPrinterId, printer_name); |
544 settings_info.SetBoolean(kDisableColorOption, disable_color_options); | 531 settings_info.SetBoolean(kDisableColorOption, disable_color_options); |
545 if (printer_color_space_for_color == printing::UNKNOWN_COLOR_MODEL) | 532 if (printer_color_space_for_color == printing::UNKNOWN_COLOR_MODEL) |
(...skipping 16 matching lines...) Expand all Loading... |
562 base::Bind(&PrintSystemTaskProxy::SendPrinterCapabilities, this, | 549 base::Bind(&PrintSystemTaskProxy::SendPrinterCapabilities, this, |
563 settings_info.DeepCopy())); | 550 settings_info.DeepCopy())); |
564 } | 551 } |
565 | 552 |
566 void PrintSystemTaskProxy::SendPrinterCapabilities( | 553 void PrintSystemTaskProxy::SendPrinterCapabilities( |
567 DictionaryValue* settings_info) { | 554 DictionaryValue* settings_info) { |
568 if (handler_) | 555 if (handler_) |
569 handler_->SendPrinterCapabilities(*settings_info); | 556 handler_->SendPrinterCapabilities(*settings_info); |
570 delete settings_info; | 557 delete settings_info; |
571 } | 558 } |
| 559 |
| 560 void PrintSystemTaskProxy::SendFailedToGetPrinterCapabilities( |
| 561 const std::string& printer_name) { |
| 562 if (handler_) |
| 563 handler_->SendFailedToGetPrinterCapabilities(printer_name); |
| 564 } |
OLD | NEW |