Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(789)

Side by Side Diff: chrome/browser/ui/webui/print_preview/print_preview_handler.cc

Issue 909143004: Add support for starting an extension print job to print preview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: vitaly's feedback Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 return; 839 return;
840 840
841 ReportPrintSettingsStats(*settings); 841 ReportPrintSettingsStats(*settings);
842 842
843 // Never try to add headers/footers here. It's already in the generated PDF. 843 // Never try to add headers/footers here. It's already in the generated PDF.
844 settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false); 844 settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false);
845 845
846 bool print_to_pdf = false; 846 bool print_to_pdf = false;
847 bool is_cloud_printer = false; 847 bool is_cloud_printer = false;
848 bool print_with_privet = false; 848 bool print_with_privet = false;
849 bool print_with_extension = false;
849 850
850 bool open_pdf_in_preview = false; 851 bool open_pdf_in_preview = false;
851 #if defined(OS_MACOSX) 852 #if defined(OS_MACOSX)
852 open_pdf_in_preview = settings->HasKey(printing::kSettingOpenPDFInPreview); 853 open_pdf_in_preview = settings->HasKey(printing::kSettingOpenPDFInPreview);
853 #endif 854 #endif
854 855
855 if (!open_pdf_in_preview) { 856 if (!open_pdf_in_preview) {
856 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); 857 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf);
857 settings->GetBoolean(printing::kSettingPrintWithPrivet, &print_with_privet); 858 settings->GetBoolean(printing::kSettingPrintWithPrivet, &print_with_privet);
859 settings->GetBoolean(printing::kSettingPrintWithExtension,
860 &print_with_extension);
858 is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId); 861 is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId);
859 } 862 }
860 863
861 int page_count = 0; 864 int page_count = 0;
862 settings->GetInteger(printing::kSettingPreviewPageCount, &page_count); 865 settings->GetInteger(printing::kSettingPreviewPageCount, &page_count);
863 866
864 if (print_to_pdf) { 867 if (print_to_pdf) {
865 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", page_count); 868 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", page_count);
866 ReportUserActionHistogram(PRINT_TO_PDF); 869 ReportUserActionHistogram(PRINT_TO_PDF);
867 PrintToPdf(); 870 PrintToPdf();
(...skipping 21 matching lines...) Expand all
889 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); 892 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value);
890 return; 893 return;
891 } 894 }
892 895
893 PrintToPrivetPrinter( 896 PrintToPrivetPrinter(
894 printer_name, print_ticket, capabilities, gfx::Size(width, height)); 897 printer_name, print_ticket, capabilities, gfx::Size(width, height));
895 return; 898 return;
896 } 899 }
897 #endif 900 #endif
898 901
902 if (print_with_extension) {
903 // TODO(tbarzic): Implement this and record UMA stats.
904 OnExtensionPrintResult(false, "NOT_IMPLEMENTED");
905 return;
906 }
907
899 scoped_refptr<base::RefCountedBytes> data; 908 scoped_refptr<base::RefCountedBytes> data;
900 base::string16 title; 909 base::string16 title;
901 if (!GetPreviewDataAndTitle(&data, &title)) { 910 if (!GetPreviewDataAndTitle(&data, &title)) {
902 // Nothing to print, no preview available. 911 // Nothing to print, no preview available.
903 return; 912 return;
904 } 913 }
905 914
906 if (is_cloud_printer) { 915 if (is_cloud_printer) {
907 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrint", 916 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrint",
908 page_count); 917 page_count);
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 if (capabilities.empty()) { 1658 if (capabilities.empty()) {
1650 web_ui()->CallJavascriptFunction("failedToGetExtensionPrinterCapabilities", 1659 web_ui()->CallJavascriptFunction("failedToGetExtensionPrinterCapabilities",
1651 base::StringValue(printer_id)); 1660 base::StringValue(printer_id));
1652 return; 1661 return;
1653 } 1662 }
1654 1663
1655 web_ui()->CallJavascriptFunction("onExtensionCapabilitiesSet", 1664 web_ui()->CallJavascriptFunction("onExtensionCapabilitiesSet",
1656 base::StringValue(printer_id), capabilities); 1665 base::StringValue(printer_id), capabilities);
1657 } 1666 }
1658 1667
1668 void PrintPreviewHandler::OnExtensionPrintResult(bool success,
1669 const std::string& status) {
1670 if (success) {
1671 ClosePreviewDialog();
1672 return;
1673 }
1674
1675 // TODO(tbarzic): This function works for extension printers case too, but it
1676 // should be renamed to something more generic.
1677 web_ui()->CallJavascriptFunction("onPrivetPrintFailed",
1678 base::StringValue(status));
1679 }
1680
1659 void PrintPreviewHandler::RegisterForMergeSession() { 1681 void PrintPreviewHandler::RegisterForMergeSession() {
1660 DCHECK(!reconcilor_); 1682 DCHECK(!reconcilor_);
1661 Profile* profile = Profile::FromWebUI(web_ui()); 1683 Profile* profile = Profile::FromWebUI(web_ui());
1662 if (switches::IsEnableAccountConsistency() && !profile->IsOffTheRecord()) { 1684 if (switches::IsEnableAccountConsistency() && !profile->IsOffTheRecord()) {
1663 reconcilor_ = AccountReconcilorFactory::GetForProfile(profile); 1685 reconcilor_ = AccountReconcilorFactory::GetForProfile(profile);
1664 if (reconcilor_) 1686 if (reconcilor_)
1665 reconcilor_->AddMergeSessionObserver(this); 1687 reconcilor_->AddMergeSessionObserver(this);
1666 } 1688 }
1667 } 1689 }
1668 1690
1669 void PrintPreviewHandler::UnregisterForMergeSession() { 1691 void PrintPreviewHandler::UnregisterForMergeSession() {
1670 if (reconcilor_) 1692 if (reconcilor_)
1671 reconcilor_->RemoveMergeSessionObserver(this); 1693 reconcilor_->RemoveMergeSessionObserver(this);
1672 } 1694 }
1673 1695
1674 void PrintPreviewHandler::SetPdfSavedClosureForTesting( 1696 void PrintPreviewHandler::SetPdfSavedClosureForTesting(
1675 const base::Closure& closure) { 1697 const base::Closure& closure) {
1676 pdf_file_saved_closure_ = closure; 1698 pdf_file_saved_closure_ = closure;
1677 } 1699 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698