Chromium Code Reviews| 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/ui/webui/print_preview/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 38 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 39 #include "chrome/browser/signin/signin_manager_factory.h" | 39 #include "chrome/browser/signin/signin_manager_factory.h" |
| 40 #include "chrome/browser/ui/browser_finder.h" | 40 #include "chrome/browser/ui/browser_finder.h" |
| 41 #include "chrome/browser/ui/browser_tabstrip.h" | 41 #include "chrome/browser/ui/browser_tabstrip.h" |
| 42 #include "chrome/browser/ui/chrome_select_file_policy.h" | 42 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 43 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 43 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 44 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 44 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 45 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" | 45 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" |
| 46 #include "chrome/common/chrome_paths.h" | 46 #include "chrome/common/chrome_paths.h" |
| 47 #include "chrome/common/chrome_switches.h" | 47 #include "chrome/common/chrome_switches.h" |
| 48 #include "chrome/common/cloud_print/cloud_print_cdd_conversion.h" | |
| 48 #include "chrome/common/cloud_print/cloud_print_constants.h" | 49 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 49 #include "chrome/common/crash_keys.h" | 50 #include "chrome/common/crash_keys.h" |
| 50 #include "chrome/common/pref_names.h" | 51 #include "chrome/common/pref_names.h" |
| 51 #include "chrome/common/print_messages.h" | 52 #include "chrome/common/print_messages.h" |
| 52 #include "components/cloud_devices/common/cloud_device_description.h" | 53 #include "components/cloud_devices/common/cloud_device_description.h" |
| 53 #include "components/cloud_devices/common/cloud_devices_urls.h" | 54 #include "components/cloud_devices/common/cloud_devices_urls.h" |
| 54 #include "components/cloud_devices/common/printer_description.h" | 55 #include "components/cloud_devices/common/printer_description.h" |
| 55 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 56 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 56 #include "components/signin/core/browser/signin_manager.h" | 57 #include "components/signin/core/browser/signin_manager.h" |
| 57 #include "components/signin/core/browser/signin_manager_base.h" | 58 #include "components/signin/core/browser/signin_manager_base.h" |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 for (size_t i = 0; i < arraysize(kPdfMedia); ++i) { | 343 for (size_t i = 0; i < arraysize(kPdfMedia); ++i) { |
| 343 Media media_option(kPdfMedia[i]); | 344 Media media_option(kPdfMedia[i]); |
| 344 media.AddDefaultOption(media_option, | 345 media.AddDefaultOption(media_option, |
| 345 default_media.type == media_option.type); | 346 default_media.type == media_option.type); |
| 346 } | 347 } |
| 347 media.SaveTo(&description); | 348 media.SaveTo(&description); |
| 348 | 349 |
| 349 return scoped_ptr<base::DictionaryValue>(description.root().DeepCopy()); | 350 return scoped_ptr<base::DictionaryValue>(description.root().DeepCopy()); |
| 350 } | 351 } |
| 351 | 352 |
| 353 scoped_ptr<base::DictionaryValue> GetLocalPrinterCapabilitiesOnFileThread( | |
| 354 const std::string& printer_name) { | |
| 355 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
| 356 | |
| 357 scoped_refptr<printing::PrintBackend> print_backend( | |
| 358 printing::PrintBackend::CreateInstance(NULL)); | |
| 359 | |
| 360 VLOG(1) << "Get printer capabilities start for " << printer_name; | |
| 361 crash_keys::ScopedPrinterInfo crash_key( | |
| 362 print_backend->GetPrinterDriverInfo(printer_name)); | |
| 363 | |
| 364 if (!print_backend->IsValidPrinter(printer_name)) { | |
| 365 LOG(WARNING) << "Invalid printer " << printer_name; | |
| 366 return scoped_ptr<base::DictionaryValue>(); | |
| 367 } | |
| 368 | |
| 369 printing::PrinterSemanticCapsAndDefaults info; | |
| 370 if (!print_backend->GetPrinterSemanticCapsAndDefaults(printer_name, &info)) { | |
| 371 LOG(WARNING) << "Failed to get capabilities for " << printer_name; | |
| 372 return scoped_ptr<base::DictionaryValue>(); | |
| 373 } | |
| 374 | |
| 375 scoped_ptr<base::DictionaryValue> description( | |
| 376 cloud_print::PrinterSemanticCapsAndDefaultsToCdd(info)); | |
| 377 if (description == NULL) { | |
|
Vitaly Buka (NO REVIEWS)
2014/06/04 00:05:46
if (!description)
Aleksey Shlyapnikov
2014/06/04 02:02:47
Done.
| |
| 378 LOG(WARNING) << "Failed to convert capabilities for " << printer_name; | |
| 379 return scoped_ptr<base::DictionaryValue>(); | |
| 380 } | |
| 381 | |
| 382 #if defined(USE_CUPS) | |
| 383 // TODO(alekseys): Use CUSTOM_COLOR/MONOCHROME instead. | |
| 384 description->SetInteger(kCUPSsColorModel, info.color_model); | |
| 385 description->SetInteger(kCUPSsBWModel, info.bw_model); | |
| 386 #endif | |
| 387 return description.Pass(); | |
| 388 } | |
| 389 | |
| 352 void EnumeratePrintersOnFileThread(base::ListValue* printers) { | 390 void EnumeratePrintersOnFileThread(base::ListValue* printers) { |
| 353 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 391 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 354 | 392 |
| 355 scoped_refptr<printing::PrintBackend> print_backend( | 393 scoped_refptr<printing::PrintBackend> print_backend( |
| 356 printing::PrintBackend::CreateInstance(NULL)); | 394 printing::PrintBackend::CreateInstance(NULL)); |
| 357 | 395 |
| 358 VLOG(1) << "Enumerate printers start"; | 396 VLOG(1) << "Enumerate printers start"; |
| 359 printing::PrinterList printer_list; | 397 printing::PrinterList printer_list; |
| 360 print_backend->EnumeratePrinters(&printer_list); | 398 print_backend->EnumeratePrinters(&printer_list); |
| 361 | 399 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 GetPrinterCapabilitiesFailureCallback; | 441 GetPrinterCapabilitiesFailureCallback; |
| 404 | 442 |
| 405 void GetPrinterCapabilitiesOnFileThread( | 443 void GetPrinterCapabilitiesOnFileThread( |
| 406 const std::string& printer_name, | 444 const std::string& printer_name, |
| 407 const std::string& locale, | 445 const std::string& locale, |
| 408 const GetPrinterCapabilitiesSuccessCallback& success_cb, | 446 const GetPrinterCapabilitiesSuccessCallback& success_cb, |
| 409 const GetPrinterCapabilitiesFailureCallback& failure_cb) { | 447 const GetPrinterCapabilitiesFailureCallback& failure_cb) { |
| 410 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 448 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 411 DCHECK(!printer_name.empty()); | 449 DCHECK(!printer_name.empty()); |
| 412 | 450 |
| 413 // Special case for PDF printer. | 451 scoped_ptr<base::DictionaryValue> printer_capabilities( |
| 414 if (printer_name == kLocalPdfPrinterId) { | 452 printer_name == kLocalPdfPrinterId ? |
| 415 scoped_ptr<base::DictionaryValue> printer_info(new base::DictionaryValue); | 453 GetPdfCapabilitiesOnFileThread(locale) : |
| 416 printer_info->SetString(kPrinterId, printer_name); | 454 GetLocalPrinterCapabilitiesOnFileThread(printer_name)); |
| 417 printer_info->Set(kPrinterCapabilities, | 455 if (printer_capabilities == NULL) { |
|
Vitaly Buka (NO REVIEWS)
2014/06/04 00:05:46
if (!printer_capabilities) {
Aleksey Shlyapnikov
2014/06/04 02:02:47
Done.
| |
| 418 GetPdfCapabilitiesOnFileThread(locale).release()); | |
| 419 BrowserThread::PostTask( | |
| 420 BrowserThread::UI, FROM_HERE, | |
| 421 base::Bind(success_cb, base::Owned(printer_info.release()))); | |
| 422 return; | |
| 423 } | |
| 424 | |
| 425 scoped_refptr<printing::PrintBackend> print_backend( | |
| 426 printing::PrintBackend::CreateInstance(NULL)); | |
| 427 | |
| 428 VLOG(1) << "Get printer capabilities start for " << printer_name; | |
| 429 crash_keys::ScopedPrinterInfo crash_key( | |
| 430 print_backend->GetPrinterDriverInfo(printer_name)); | |
| 431 | |
| 432 if (!print_backend->IsValidPrinter(printer_name)) { | |
| 433 // TODO(gene): Notify explicitly if printer is not valid, instead of | |
| 434 // failed to get capabilities. | |
| 435 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 456 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 436 base::Bind(failure_cb, printer_name)); | 457 base::Bind(failure_cb, printer_name)); |
| 437 return; | 458 return; |
| 438 } | 459 } |
| 439 | 460 |
| 440 printing::PrinterSemanticCapsAndDefaults info; | 461 scoped_ptr<base::DictionaryValue> printer_info(new base::DictionaryValue); |
| 441 if (!print_backend->GetPrinterSemanticCapsAndDefaults(printer_name, &info)) { | 462 printer_info->SetString(kPrinterId, printer_name); |
| 442 LOG(WARNING) << "Failed to get capabilities for " << printer_name; | 463 printer_info->Set(kPrinterCapabilities, printer_capabilities.release()); |
| 443 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 444 base::Bind(failure_cb, printer_name)); | |
| 445 return; | |
| 446 } | |
| 447 | |
| 448 scoped_ptr<base::DictionaryValue> settings_info(new base::DictionaryValue); | |
| 449 settings_info->SetString(kPrinterId, printer_name); | |
| 450 settings_info->SetBoolean(kDisableColorOption, !info.color_changeable); | |
| 451 settings_info->SetBoolean(printing::kSettingSetColorAsDefault, | |
| 452 info.color_default); | |
| 453 #if defined(USE_CUPS) | |
| 454 settings_info->SetInteger(kCUPSsColorModel, info.color_model); | |
| 455 settings_info->SetInteger(kCUPSsBWModel, info.bw_model); | |
| 456 #endif | |
| 457 | |
| 458 // TODO(gene): Make new capabilities format for Print Preview | |
| 459 // that will suit semantic capabilities better. | |
| 460 // Refactor pld API code below | |
| 461 bool default_duplex = info.duplex_capable ? | |
| 462 (info.duplex_default != printing::SIMPLEX) : false; | |
| 463 int duplex_value = info.duplex_capable ? | |
| 464 printing::LONG_EDGE : printing::UNKNOWN_DUPLEX_MODE; | |
| 465 settings_info->SetBoolean(kSetDuplexAsDefault, default_duplex); | |
| 466 settings_info->SetInteger(kPrinterDefaultDuplexValue, duplex_value); | |
| 467 | 464 |
| 468 BrowserThread::PostTask( | 465 BrowserThread::PostTask( |
| 469 BrowserThread::UI, FROM_HERE, | 466 BrowserThread::UI, FROM_HERE, |
| 470 base::Bind(success_cb, base::Owned(settings_info.release()))); | 467 base::Bind(success_cb, base::Owned(printer_info.release()))); |
| 471 } | 468 } |
| 472 | 469 |
| 473 base::LazyInstance<printing::StickySettings> g_sticky_settings = | 470 base::LazyInstance<printing::StickySettings> g_sticky_settings = |
| 474 LAZY_INSTANCE_INITIALIZER; | 471 LAZY_INSTANCE_INITIALIZER; |
| 475 | 472 |
| 476 printing::StickySettings* GetStickySettings() { | 473 printing::StickySettings* GetStickySettings() { |
| 477 return g_sticky_settings.Pointer(); | 474 return g_sticky_settings.Pointer(); |
| 478 } | 475 } |
| 479 | 476 |
| 480 } // namespace | 477 } // namespace |
| (...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1413 *data = tmp_data; | 1410 *data = tmp_data; |
| 1414 *title = print_preview_ui->initiator_title(); | 1411 *title = print_preview_ui->initiator_title(); |
| 1415 return true; | 1412 return true; |
| 1416 } | 1413 } |
| 1417 | 1414 |
| 1418 #if defined(USE_CUPS) | 1415 #if defined(USE_CUPS) |
| 1419 void PrintPreviewHandler::SaveCUPSColorSetting( | 1416 void PrintPreviewHandler::SaveCUPSColorSetting( |
| 1420 const base::DictionaryValue* settings) { | 1417 const base::DictionaryValue* settings) { |
| 1421 cups_printer_color_models_.reset(new CUPSPrinterColorModels); | 1418 cups_printer_color_models_.reset(new CUPSPrinterColorModels); |
| 1422 settings->GetString(kPrinterId, &cups_printer_color_models_->printer_name); | 1419 settings->GetString(kPrinterId, &cups_printer_color_models_->printer_name); |
| 1423 settings->GetInteger( | 1420 const base::DictionaryValue* capabilities = NULL; |
| 1421 if (!settings->GetDictionary(kPrinterCapabilities, &capabilities) || | |
| 1422 !capabilities) { | |
| 1423 NOTREACHED(); | |
| 1424 return; | |
| 1425 } | |
| 1426 capabilities->GetInteger( | |
| 1424 kCUPSsColorModel, | 1427 kCUPSsColorModel, |
| 1425 reinterpret_cast<int*>(&cups_printer_color_models_->color_model)); | 1428 reinterpret_cast<int*>(&cups_printer_color_models_->color_model)); |
| 1426 settings->GetInteger( | 1429 capabilities->GetInteger( |
| 1427 kCUPSsBWModel, | 1430 kCUPSsBWModel, |
| 1428 reinterpret_cast<int*>(&cups_printer_color_models_->bw_model)); | 1431 reinterpret_cast<int*>(&cups_printer_color_models_->bw_model)); |
| 1429 } | 1432 } |
| 1430 | 1433 |
| 1431 void PrintPreviewHandler::ConvertColorSettingToCUPSColorModel( | 1434 void PrintPreviewHandler::ConvertColorSettingToCUPSColorModel( |
| 1432 base::DictionaryValue* settings) const { | 1435 base::DictionaryValue* settings) const { |
| 1433 if (!cups_printer_color_models_) | 1436 if (!cups_printer_color_models_) |
| 1434 return; | 1437 return; |
| 1435 | 1438 |
| 1436 // Sanity check the printer name. | 1439 // Sanity check the printer name. |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1655 printer_value->SetString("name", description.name); | 1658 printer_value->SetString("name", description.name); |
| 1656 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); | 1659 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); |
| 1657 printer_value->SetBoolean( | 1660 printer_value->SetBoolean( |
| 1658 "isUnregistered", | 1661 "isUnregistered", |
| 1659 description.id.empty() && | 1662 description.id.empty() && |
| 1660 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)); | 1663 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)); |
| 1661 printer_value->SetString("cloudID", description.id); | 1664 printer_value->SetString("cloudID", description.id); |
| 1662 } | 1665 } |
| 1663 | 1666 |
| 1664 #endif | 1667 #endif |
| OLD | NEW |