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/ui/webui/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/i18n/file_util_icu.h" | 9 #include "base/i18n/file_util_icu.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 public: | 112 public: |
113 PrintSystemTaskProxy(const base::WeakPtr<PrintPreviewHandler>& handler, | 113 PrintSystemTaskProxy(const base::WeakPtr<PrintPreviewHandler>& handler, |
114 printing::PrintBackend* print_backend, | 114 printing::PrintBackend* print_backend, |
115 bool has_logged_printers_count) | 115 bool has_logged_printers_count) |
116 : handler_(handler), | 116 : handler_(handler), |
117 print_backend_(print_backend), | 117 print_backend_(print_backend), |
118 has_logged_printers_count_(has_logged_printers_count) { | 118 has_logged_printers_count_(has_logged_printers_count) { |
119 } | 119 } |
120 | 120 |
121 void EnumeratePrinters() { | 121 void EnumeratePrinters() { |
| 122 VLOG(1) << "Enumerate printers start"; |
122 ListValue* printers = new ListValue; | 123 ListValue* printers = new ListValue; |
123 int default_printer_index = -1; | 124 int default_printer_index = -1; |
124 | 125 |
125 printing::PrinterList printer_list; | 126 printing::PrinterList printer_list; |
126 print_backend_->EnumeratePrinters(&printer_list); | 127 print_backend_->EnumeratePrinters(&printer_list); |
127 | 128 |
128 if (!has_logged_printers_count_) { | 129 if (!has_logged_printers_count_) { |
129 // Record the total number of printers. | 130 // Record the total number of printers. |
130 UMA_HISTOGRAM_COUNTS(kNumberOfPrinters, printer_list.size()); | 131 UMA_HISTOGRAM_COUNTS(kNumberOfPrinters, printer_list.size()); |
131 } | 132 } |
132 | 133 |
133 int i = 0; | 134 int i = 0; |
134 for (printing::PrinterList::iterator index = printer_list.begin(); | 135 for (printing::PrinterList::iterator iter = printer_list.begin(); |
135 index != printer_list.end(); ++index, ++i) { | 136 iter != printer_list.end(); ++iter, ++i) { |
136 DictionaryValue* printer_info = new DictionaryValue; | 137 DictionaryValue* printer_info = new DictionaryValue; |
137 std::string printerName; | 138 std::string printerName; |
138 #if defined(OS_MACOSX) | 139 #if defined(OS_MACOSX) |
139 // On Mac, |index->printer_description| specifies the printer name and | 140 // On Mac, |iter->printer_description| specifies the printer name and |
140 // |index->printer_name| specifies the device name / printer queue name. | 141 // |iter->printer_name| specifies the device name / printer queue name. |
141 printerName = index->printer_description; | 142 printerName = iter->printer_description; |
142 #else | 143 #else |
143 printerName = index->printer_name; | 144 printerName = iter->printer_name; |
144 #endif | 145 #endif |
145 printer_info->SetString(printing::kSettingPrinterName, printerName); | 146 printer_info->SetString(printing::kSettingPrinterName, printerName); |
146 printer_info->SetString(printing::kSettingDeviceName, | 147 printer_info->SetString(printing::kSettingDeviceName, iter->printer_name); |
147 index->printer_name); | |
148 printers->Append(printer_info); | 148 printers->Append(printer_info); |
149 if (index->is_default) | 149 if (iter->is_default) |
150 default_printer_index = i; | 150 default_printer_index = i; |
151 } | 151 } |
| 152 VLOG(1) << "Enumerate printers finished, found " << i << " printers"; |
152 | 153 |
153 BrowserThread::PostTask( | 154 BrowserThread::PostTask( |
154 BrowserThread::UI, FROM_HERE, | 155 BrowserThread::UI, FROM_HERE, |
155 NewRunnableMethod(this, | 156 NewRunnableMethod(this, |
156 &PrintSystemTaskProxy::SendPrinterList, | 157 &PrintSystemTaskProxy::SendPrinterList, |
157 printers, | 158 printers, |
158 new FundamentalValue(default_printer_index))); | 159 new FundamentalValue(default_printer_index))); |
159 } | 160 } |
160 | 161 |
161 void SendPrinterList(ListValue* printers, | 162 void SendPrinterList(ListValue* printers, |
162 FundamentalValue* default_printer_index) { | 163 FundamentalValue* default_printer_index) { |
163 if (handler_) | 164 if (handler_) |
164 handler_->SendPrinterList(*printers, *default_printer_index); | 165 handler_->SendPrinterList(*printers, *default_printer_index); |
165 delete printers; | 166 delete printers; |
166 delete default_printer_index; | 167 delete default_printer_index; |
167 } | 168 } |
168 | 169 |
169 void GetPrinterCapabilities(const std::string& printer_name) { | 170 void GetPrinterCapabilities(const std::string& printer_name) { |
| 171 VLOG(1) << "Get printer capabilities start for " << printer_name; |
170 printing::PrinterCapsAndDefaults printer_info; | 172 printing::PrinterCapsAndDefaults printer_info; |
171 bool supports_color = true; | 173 bool supports_color = true; |
172 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, | 174 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, |
173 &printer_info)) { | 175 &printer_info)) { |
174 return; | 176 return; |
175 } | 177 } |
176 | 178 |
177 #if defined(USE_CUPS) | 179 #if defined(USE_CUPS) |
178 FilePath ppd_file_path; | 180 FilePath ppd_file_path; |
179 if (!file_util::CreateTemporaryFile(&ppd_file_path)) | 181 if (!file_util::CreateTemporaryFile(&ppd_file_path)) |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 TabContents* initiator_tab = GetInitiatorTab(); | 325 TabContents* initiator_tab = GetInitiatorTab(); |
324 if (!initiator_tab) { | 326 if (!initiator_tab) { |
325 ++print_preview_failed_count_; | 327 ++print_preview_failed_count_; |
326 web_ui_->CallJavascriptFunction("printPreviewFailed"); | 328 web_ui_->CallJavascriptFunction("printPreviewFailed"); |
327 return; | 329 return; |
328 } | 330 } |
329 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); | 331 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); |
330 if (!settings.get()) | 332 if (!settings.get()) |
331 return; | 333 return; |
332 | 334 |
| 335 VLOG(1) << "Print preview request start"; |
333 RenderViewHost* rvh = initiator_tab->render_view_host(); | 336 RenderViewHost* rvh = initiator_tab->render_view_host(); |
334 rvh->Send(new PrintMsg_PrintPreview(rvh->routing_id(), *settings)); | 337 rvh->Send(new PrintMsg_PrintPreview(rvh->routing_id(), *settings)); |
335 } | 338 } |
336 | 339 |
337 void PrintPreviewHandler::HandlePrint(const ListValue* args) { | 340 void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
338 ReportStats(); | 341 ReportStats(); |
339 | 342 |
340 // Record the number of times the user requests to regenerate preview data | 343 // Record the number of times the user requests to regenerate preview data |
341 // before printing. | 344 // before printing. |
342 UMA_HISTOGRAM_COUNTS(kRegeneratePreviewRequestsRcvdBeforePrint, | 345 UMA_HISTOGRAM_COUNTS(kRegeneratePreviewRequestsRcvdBeforePrint, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 465 |
463 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { | 466 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { |
464 TabContents* initiator_tab = GetInitiatorTab(); | 467 TabContents* initiator_tab = GetInitiatorTab(); |
465 if (initiator_tab) | 468 if (initiator_tab) |
466 initiator_tab->Activate(); | 469 initiator_tab->Activate(); |
467 ClosePrintPreviewTab(); | 470 ClosePrintPreviewTab(); |
468 } | 471 } |
469 | 472 |
470 void PrintPreviewHandler::SendPrinterCapabilities( | 473 void PrintPreviewHandler::SendPrinterCapabilities( |
471 const DictionaryValue& settings_info) { | 474 const DictionaryValue& settings_info) { |
| 475 VLOG(1) << "Get printer capabilities finished"; |
472 web_ui_->CallJavascriptFunction("updateWithPrinterCapabilities", | 476 web_ui_->CallJavascriptFunction("updateWithPrinterCapabilities", |
473 settings_info); | 477 settings_info); |
474 } | 478 } |
475 | 479 |
476 void PrintPreviewHandler::SendPrinterList( | 480 void PrintPreviewHandler::SendPrinterList( |
477 const ListValue& printers, | 481 const ListValue& printers, |
478 const FundamentalValue& default_printer_index) { | 482 const FundamentalValue& default_printer_index) { |
479 web_ui_->CallJavascriptFunction("setPrinters", printers, | 483 web_ui_->CallJavascriptFunction("setPrinters", printers, |
480 default_printer_index); | 484 default_printer_index); |
481 } | 485 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 metafile->InitFromData(data.first->memory(), data.second); | 549 metafile->InitFromData(data.first->memory(), data.second); |
546 | 550 |
547 // Updating last_saved_path_ to the newly selected folder. | 551 // Updating last_saved_path_ to the newly selected folder. |
548 *last_saved_path_ = path.DirName(); | 552 *last_saved_path_ = path.DirName(); |
549 | 553 |
550 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); | 554 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); |
551 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); | 555 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); |
552 | 556 |
553 ActivateInitiatorTabAndClosePreviewTab(); | 557 ActivateInitiatorTabAndClosePreviewTab(); |
554 } | 558 } |
OLD | NEW |