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 <string> | 9 #include <string> |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 #include "printing/pdf_render_settings.h" | 67 #include "printing/pdf_render_settings.h" |
68 #include "printing/print_settings.h" | 68 #include "printing/print_settings.h" |
69 #include "printing/units.h" | 69 #include "printing/units.h" |
70 #include "third_party/icu/source/i18n/unicode/ulocdata.h" | 70 #include "third_party/icu/source/i18n/unicode/ulocdata.h" |
71 | 71 |
72 #if defined(OS_CHROMEOS) | 72 #if defined(OS_CHROMEOS) |
73 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 73 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
74 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" | 74 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" |
75 #endif | 75 #endif |
76 | 76 |
77 #if defined(ENABLE_MDNS) | 77 #if defined(ENABLE_SERVICE_DISCOVERY) |
78 #include "chrome/browser/local_discovery/privet_constants.h" | 78 #include "chrome/browser/local_discovery/privet_constants.h" |
79 #endif | 79 #endif |
80 | 80 |
81 using content::BrowserThread; | 81 using content::BrowserThread; |
82 using content::RenderViewHost; | 82 using content::RenderViewHost; |
83 using content::WebContents; | 83 using content::WebContents; |
84 | 84 |
85 namespace { | 85 namespace { |
86 | 86 |
87 enum UserActionBuckets { | 87 enum UserActionBuckets { |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 base::Unretained(this))); | 528 base::Unretained(this))); |
529 web_ui()->RegisterMessageCallback("stopGetPrivetPrinters", | 529 web_ui()->RegisterMessageCallback("stopGetPrivetPrinters", |
530 base::Bind(&PrintPreviewHandler::HandleStopGetPrivetPrinters, | 530 base::Bind(&PrintPreviewHandler::HandleStopGetPrivetPrinters, |
531 base::Unretained(this))); | 531 base::Unretained(this))); |
532 web_ui()->RegisterMessageCallback("getPrivetPrinterCapabilities", | 532 web_ui()->RegisterMessageCallback("getPrivetPrinterCapabilities", |
533 base::Bind(&PrintPreviewHandler::HandleGetPrivetPrinterCapabilities, | 533 base::Bind(&PrintPreviewHandler::HandleGetPrivetPrinterCapabilities, |
534 base::Unretained(this))); | 534 base::Unretained(this))); |
535 } | 535 } |
536 | 536 |
537 bool PrintPreviewHandler::PrivetPrintingEnabled() { | 537 bool PrintPreviewHandler::PrivetPrintingEnabled() { |
538 #if defined(ENABLE_MDNS) | 538 #if defined(ENABLE_SERVICE_DISCOVERY) |
539 return !CommandLine::ForCurrentProcess()->HasSwitch( | 539 return !CommandLine::ForCurrentProcess()->HasSwitch( |
540 switches::kDisableDeviceDiscovery); | 540 switches::kDisableDeviceDiscovery); |
541 #else | 541 #else |
542 return false; | 542 return false; |
543 #endif | 543 #endif |
544 } | 544 } |
545 | 545 |
546 WebContents* PrintPreviewHandler::preview_web_contents() const { | 546 WebContents* PrintPreviewHandler::preview_web_contents() const { |
547 return web_ui()->GetWebContents(); | 547 return web_ui()->GetWebContents(); |
548 } | 548 } |
549 | 549 |
550 void PrintPreviewHandler::HandleGetPrinters(const base::ListValue* /*args*/) { | 550 void PrintPreviewHandler::HandleGetPrinters(const base::ListValue* /*args*/) { |
551 base::ListValue* results = new base::ListValue; | 551 base::ListValue* results = new base::ListValue; |
552 BrowserThread::PostTaskAndReply( | 552 BrowserThread::PostTaskAndReply( |
553 BrowserThread::FILE, FROM_HERE, | 553 BrowserThread::FILE, FROM_HERE, |
554 base::Bind(&EnumeratePrintersOnFileThread, print_backend_, | 554 base::Bind(&EnumeratePrintersOnFileThread, print_backend_, |
555 base::Unretained(results)), | 555 base::Unretained(results)), |
556 base::Bind(&PrintPreviewHandler::SetupPrinterList, | 556 base::Bind(&PrintPreviewHandler::SetupPrinterList, |
557 weak_factory_.GetWeakPtr(), | 557 weak_factory_.GetWeakPtr(), |
558 base::Owned(results))); | 558 base::Owned(results))); |
559 } | 559 } |
560 | 560 |
561 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { | 561 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { |
562 #if defined(ENABLE_MDNS) | 562 #if defined(ENABLE_SERVICE_DISCOVERY) |
563 if (PrivetPrintingEnabled()) { | 563 if (PrivetPrintingEnabled()) { |
564 Profile* profile = Profile::FromWebUI(web_ui()); | 564 Profile* profile = Profile::FromWebUI(web_ui()); |
565 service_discovery_client_ = | 565 service_discovery_client_ = |
566 local_discovery::ServiceDiscoverySharedClient::GetInstance(); | 566 local_discovery::ServiceDiscoverySharedClient::GetInstance(); |
567 printer_lister_.reset(new local_discovery::PrivetLocalPrinterLister( | 567 printer_lister_.reset(new local_discovery::PrivetLocalPrinterLister( |
568 service_discovery_client_.get(), | 568 service_discovery_client_.get(), |
569 profile->GetRequestContext(), | 569 profile->GetRequestContext(), |
570 this)); | 570 this)); |
571 printer_lister_->Start(); | 571 printer_lister_->Start(); |
572 } | 572 } |
573 #endif | 573 #endif |
574 | 574 |
575 if (!PrivetPrintingEnabled()) { | 575 if (!PrivetPrintingEnabled()) { |
576 web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone"); | 576 web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone"); |
577 } | 577 } |
578 } | 578 } |
579 | 579 |
580 void PrintPreviewHandler::HandleStopGetPrivetPrinters( | 580 void PrintPreviewHandler::HandleStopGetPrivetPrinters( |
581 const base::ListValue* args) { | 581 const base::ListValue* args) { |
582 #if defined(ENABLE_MDNS) | 582 #if defined(ENABLE_SERVICE_DISCOVERY) |
583 if (PrivetPrintingEnabled()) { | 583 if (PrivetPrintingEnabled()) { |
584 printer_lister_->Stop(); | 584 printer_lister_->Stop(); |
585 } | 585 } |
586 #endif | 586 #endif |
587 } | 587 } |
588 | 588 |
589 void PrintPreviewHandler::HandleGetPrivetPrinterCapabilities( | 589 void PrintPreviewHandler::HandleGetPrivetPrinterCapabilities( |
590 const base::ListValue* args) { | 590 const base::ListValue* args) { |
591 #if defined(ENABLE_MDNS) | 591 #if defined(ENABLE_SERVICE_DISCOVERY) |
592 std::string name; | 592 std::string name; |
593 bool success = args->GetString(0, &name); | 593 bool success = args->GetString(0, &name); |
594 DCHECK(success); | 594 DCHECK(success); |
595 | 595 |
596 CreatePrivetHTTP( | 596 CreatePrivetHTTP( |
597 name, | 597 name, |
598 base::Bind(&PrintPreviewHandler::PrivetCapabilitiesUpdateClient, | 598 base::Bind(&PrintPreviewHandler::PrivetCapabilitiesUpdateClient, |
599 base::Unretained(this))); | 599 base::Unretained(this))); |
600 #endif | 600 #endif |
601 } | 601 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 int page_count = 0; | 711 int page_count = 0; |
712 settings->GetInteger(printing::kSettingPreviewPageCount, &page_count); | 712 settings->GetInteger(printing::kSettingPreviewPageCount, &page_count); |
713 | 713 |
714 if (print_to_pdf) { | 714 if (print_to_pdf) { |
715 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", page_count); | 715 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", page_count); |
716 ReportUserActionHistogram(PRINT_TO_PDF); | 716 ReportUserActionHistogram(PRINT_TO_PDF); |
717 PrintToPdf(); | 717 PrintToPdf(); |
718 return; | 718 return; |
719 } | 719 } |
720 | 720 |
721 #if defined(ENABLE_MDNS) | 721 #if defined(ENABLE_SERVICE_DISCOVERY) |
722 if (print_with_privet && PrivetPrintingEnabled()) { | 722 if (print_with_privet && PrivetPrintingEnabled()) { |
723 std::string printer_name; | 723 std::string printer_name; |
724 std::string print_ticket; | 724 std::string print_ticket; |
725 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintWithPrivet", page_count); | 725 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintWithPrivet", page_count); |
726 ReportUserActionHistogram(PRINT_WITH_PRIVET); | 726 ReportUserActionHistogram(PRINT_WITH_PRIVET); |
727 | 727 |
728 int width = 0; | 728 int width = 0; |
729 int height = 0; | 729 int height = 0; |
730 if (!settings->GetString(printing::kSettingDeviceName, &printer_name) || | 730 if (!settings->GetString(printing::kSettingDeviceName, &printer_name) || |
731 !settings->GetString(printing::kSettingTicket, &print_ticket) || | 731 !settings->GetString(printing::kSettingTicket, &print_ticket) || |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 return; | 1343 return; |
1344 } | 1344 } |
1345 | 1345 |
1346 printing::ColorModel color_model = cups_printer_color_models_->color_model; | 1346 printing::ColorModel color_model = cups_printer_color_models_->color_model; |
1347 if (color_model != printing::UNKNOWN_COLOR_MODEL) | 1347 if (color_model != printing::UNKNOWN_COLOR_MODEL) |
1348 settings->SetInteger(printing::kSettingColor, color_model); | 1348 settings->SetInteger(printing::kSettingColor, color_model); |
1349 } | 1349 } |
1350 | 1350 |
1351 #endif | 1351 #endif |
1352 | 1352 |
1353 | 1353 #if defined(ENABLE_SERVICE_DISCOVERY) |
1354 #if defined(ENABLE_MDNS) | |
1355 void PrintPreviewHandler::LocalPrinterChanged( | 1354 void PrintPreviewHandler::LocalPrinterChanged( |
1356 bool added, | 1355 bool added, |
1357 const std::string& name, | 1356 const std::string& name, |
1358 bool has_local_printing, | 1357 bool has_local_printing, |
1359 const local_discovery::DeviceDescription& description) { | 1358 const local_discovery::DeviceDescription& description) { |
1360 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1359 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
1361 if (has_local_printing || | 1360 if (has_local_printing || |
1362 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)) { | 1361 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)) { |
1363 base::DictionaryValue info; | 1362 base::DictionaryValue info; |
1364 FillPrinterDescription(name, description, has_local_printing, &info); | 1363 FillPrinterDescription(name, description, has_local_printing, &info); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1539 printer_value->SetString("name", description.name); | 1538 printer_value->SetString("name", description.name); |
1540 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); | 1539 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); |
1541 printer_value->SetBoolean( | 1540 printer_value->SetBoolean( |
1542 "isUnregistered", | 1541 "isUnregistered", |
1543 description.id.empty() && | 1542 description.id.empty() && |
1544 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)); | 1543 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)); |
1545 printer_value->SetString("cloudID", description.id); | 1544 printer_value->SetString("cloudID", description.id); |
1546 } | 1545 } |
1547 | 1546 |
1548 #endif | 1547 #endif |
OLD | NEW |