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/base64.h" | 9 #include "base/base64.h" |
10 #if !defined(OS_CHROMEOS) | 10 #if !defined(OS_CHROMEOS) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 #include <cups/ppd.h> | 51 #include <cups/ppd.h> |
52 | 52 |
53 #include "base/file_util.h" | 53 #include "base/file_util.h" |
54 #endif | 54 #endif |
55 | 55 |
56 namespace { | 56 namespace { |
57 | 57 |
58 const char kDisableColorOption[] = "disableColorOption"; | 58 const char kDisableColorOption[] = "disableColorOption"; |
59 const char kSetColorAsDefault[] = "setColorAsDefault"; | 59 const char kSetColorAsDefault[] = "setColorAsDefault"; |
60 const char kSetDuplexAsDefault[] = "setDuplexAsDefault"; | 60 const char kSetDuplexAsDefault[] = "setDuplexAsDefault"; |
61 const char kPrinterColorSpace[] = "printerColorSpace"; | |
61 | 62 |
62 #if defined(USE_CUPS) | 63 #if defined(USE_CUPS) |
63 const char kColorDevice[] = "ColorDevice"; | 64 const char kColorDevice[] = "ColorDevice"; |
65 const char kColorModel[] = "ColorModel"; | |
66 const char kColor[] = "Color"; | |
67 const char kCMYK[] = "CMYK"; | |
64 const char kDuplex[] = "Duplex"; | 68 const char kDuplex[] = "Duplex"; |
65 const char kDuplexNone[] = "None"; | 69 const char kDuplexNone[] = "None"; |
66 #elif defined(OS_WIN) | 70 #elif defined(OS_WIN) |
67 const char kPskColor[] = "psk:Color"; | 71 const char kPskColor[] = "psk:Color"; |
68 const char kPskDuplexFeature[] = "psk:JobDuplexAllDocumentsContiguously"; | 72 const char kPskDuplexFeature[] = "psk:JobDuplexAllDocumentsContiguously"; |
69 const char kPskTwoSided[] = "psk:TwoSided"; | 73 const char kPskTwoSided[] = "psk:TwoSided"; |
70 #endif | 74 #endif |
71 | 75 |
72 enum UserActionBuckets { | 76 enum UserActionBuckets { |
73 PRINT_TO_PRINTER, | 77 PRINT_TO_PRINTER, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 ReportPrintSettingHistogram(landscape ? LANDSCAPE : PORTRAIT); | 160 ReportPrintSettingHistogram(landscape ? LANDSCAPE : PORTRAIT); |
157 | 161 |
158 bool collate; | 162 bool collate; |
159 if (settings.GetBoolean(printing::kSettingCollate, &collate) && collate) | 163 if (settings.GetBoolean(printing::kSettingCollate, &collate) && collate) |
160 ReportPrintSettingHistogram(COLLATE); | 164 ReportPrintSettingHistogram(COLLATE); |
161 | 165 |
162 int duplex_mode; | 166 int duplex_mode; |
163 if (settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode)) | 167 if (settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode)) |
164 ReportPrintSettingHistogram(duplex_mode ? DUPLEX : SIMPLEX); | 168 ReportPrintSettingHistogram(duplex_mode ? DUPLEX : SIMPLEX); |
165 | 169 |
166 bool is_color; | 170 int color_mode; |
167 if (settings.GetBoolean(printing::kSettingColor, &is_color)) | 171 if (settings.GetInteger(printing::kSettingColor, &color_mode)) { |
168 ReportPrintSettingHistogram(is_color ? COLOR : BLACK_AND_WHITE); | 172 ReportPrintSettingHistogram(color_mode == printing::GRAY ? BLACK_AND_WHITE : |
173 COLOR); | |
174 } | |
169 } | 175 } |
170 | 176 |
171 printing::BackgroundPrintingManager* GetBackgroundPrintingManager() { | 177 printing::BackgroundPrintingManager* GetBackgroundPrintingManager() { |
172 return g_browser_process->background_printing_manager(); | 178 return g_browser_process->background_printing_manager(); |
173 } | 179 } |
174 | 180 |
175 } // namespace | 181 } // namespace |
176 | 182 |
177 class PrintSystemTaskProxy | 183 class PrintSystemTaskProxy |
178 : public base::RefCountedThreadSafe<PrintSystemTaskProxy, | 184 : public base::RefCountedThreadSafe<PrintSystemTaskProxy, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 handler_->SetupPrinterList(*printers); | 273 handler_->SetupPrinterList(*printers); |
268 } | 274 } |
269 delete printers; | 275 delete printers; |
270 } | 276 } |
271 | 277 |
272 void GetPrinterCapabilities(const std::string& printer_name) { | 278 void GetPrinterCapabilities(const std::string& printer_name) { |
273 VLOG(1) << "Get printer capabilities start for " << printer_name; | 279 VLOG(1) << "Get printer capabilities start for " << printer_name; |
274 printing::PrinterCapsAndDefaults printer_info; | 280 printing::PrinterCapsAndDefaults printer_info; |
275 bool supports_color = true; | 281 bool supports_color = true; |
276 bool set_duplex_as_default = false; | 282 bool set_duplex_as_default = false; |
283 int printer_color_space = printing::GRAY; | |
277 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, | 284 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, |
278 &printer_info)) { | 285 &printer_info)) { |
279 return; | 286 return; |
280 } | 287 } |
281 | 288 |
282 #if defined(USE_CUPS) | 289 #if defined(USE_CUPS) |
283 FilePath ppd_file_path; | 290 FilePath ppd_file_path; |
284 if (!file_util::CreateTemporaryFile(&ppd_file_path)) | 291 if (!file_util::CreateTemporaryFile(&ppd_file_path)) |
285 return; | 292 return; |
286 | 293 |
(...skipping 15 matching lines...) Expand all Loading... | |
302 ppd_choice_t* ch = ppdFindMarkedChoice(ppd, kDuplex); | 309 ppd_choice_t* ch = ppdFindMarkedChoice(ppd, kDuplex); |
303 if (ch == NULL) { | 310 if (ch == NULL) { |
304 ppd_option_t* option = ppdFindOption(ppd, kDuplex); | 311 ppd_option_t* option = ppdFindOption(ppd, kDuplex); |
305 if (option != NULL) | 312 if (option != NULL) |
306 ch = ppdFindChoice(option, option->defchoice); | 313 ch = ppdFindChoice(option, option->defchoice); |
307 } | 314 } |
308 | 315 |
309 if (ch != NULL && strcmp(ch->choice, kDuplexNone) != 0) | 316 if (ch != NULL && strcmp(ch->choice, kDuplexNone) != 0) |
310 set_duplex_as_default = true; | 317 set_duplex_as_default = true; |
311 | 318 |
319 if (supports_color) { | |
320 // Identify the color space (COLOR/CMYK) for this printer. | |
321 ppd_option_t* color_model = ppdFindOption(ppd, kColorModel); | |
322 if (color_model != NULL) { | |
323 if (ppdFindChoice(color_model, kColor)) | |
324 printer_color_space = printing::COLOR; | |
325 else if (ppdFindChoice(color_model, kCMYK)) | |
326 printer_color_space = printing::CMYK; | |
327 } | |
328 } | |
329 | |
312 ppdClose(ppd); | 330 ppdClose(ppd); |
313 } | 331 } |
314 file_util::Delete(ppd_file_path, false); | 332 file_util::Delete(ppd_file_path, false); |
315 #elif defined(OS_WIN) | 333 #elif defined(OS_WIN) |
316 // According to XPS 1.0 spec, only color printers have psk:Color. | 334 // According to XPS 1.0 spec, only color printers have psk:Color. |
317 // Therefore we don't need to parse the whole XML file, we just need to | 335 // Therefore we don't need to parse the whole XML file, we just need to |
318 // search the string. The spec can be found at: | 336 // search the string. The spec can be found at: |
319 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. | 337 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. |
320 supports_color = (printer_info.printer_capabilities.find(kPskColor) != | 338 supports_color = (printer_info.printer_capabilities.find(kPskColor) != |
321 std::string::npos); | 339 std::string::npos); |
340 if (supports_color) | |
341 printer_color_space = printing::COLOR; | |
vandebo (ex-Chrome)
2011/09/02 22:38:18
Does this mean that the bug this is trying to solv
kmadhusu
2011/09/04 01:52:51
(repeating our conversation for future reference):
| |
342 | |
322 set_duplex_as_default = | 343 set_duplex_as_default = |
323 (printer_info.printer_defaults.find(kPskDuplexFeature) != | 344 (printer_info.printer_defaults.find(kPskDuplexFeature) != |
324 std::string::npos) && | 345 std::string::npos) && |
325 (printer_info.printer_defaults.find(kPskTwoSided) != | 346 (printer_info.printer_defaults.find(kPskTwoSided) != |
326 std::string::npos); | 347 std::string::npos); |
327 #else | 348 #else |
328 NOTIMPLEMENTED(); | 349 NOTIMPLEMENTED(); |
329 #endif | 350 #endif |
330 | 351 |
331 DictionaryValue settings_info; | 352 DictionaryValue settings_info; |
332 settings_info.SetBoolean(kDisableColorOption, !supports_color); | 353 settings_info.SetBoolean(kDisableColorOption, !supports_color); |
333 if (!supports_color) { | 354 if (!supports_color) { |
334 settings_info.SetBoolean(kSetColorAsDefault, false); | 355 settings_info.SetBoolean(kSetColorAsDefault, false); |
335 } else { | 356 } else { |
336 settings_info.SetBoolean(kSetColorAsDefault, | 357 settings_info.SetBoolean(kSetColorAsDefault, |
337 PrintPreviewHandler::last_used_color_setting_); | 358 PrintPreviewHandler::last_used_color_setting_); |
338 } | 359 } |
339 settings_info.SetBoolean(kSetDuplexAsDefault, set_duplex_as_default); | 360 settings_info.SetBoolean(kSetDuplexAsDefault, set_duplex_as_default); |
361 settings_info.SetInteger(kPrinterColorSpace, printer_color_space); | |
340 BrowserThread::PostTask( | 362 BrowserThread::PostTask( |
341 BrowserThread::UI, FROM_HERE, | 363 BrowserThread::UI, FROM_HERE, |
342 NewRunnableMethod(this, | 364 NewRunnableMethod(this, |
343 &PrintSystemTaskProxy::SendPrinterCapabilities, | 365 &PrintSystemTaskProxy::SendPrinterCapabilities, |
344 settings_info.DeepCopy())); | 366 settings_info.DeepCopy())); |
345 } | 367 } |
346 | 368 |
347 void SendPrinterCapabilities(DictionaryValue* settings_info) { | 369 void SendPrinterCapabilities(DictionaryValue* settings_info) { |
348 if (handler_) | 370 if (handler_) |
349 handler_->SendPrinterCapabilities(*settings_info); | 371 handler_->SendPrinterCapabilities(*settings_info); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 if (initiator_tab) { | 583 if (initiator_tab) { |
562 RenderViewHost* rvh = initiator_tab->render_view_host(); | 584 RenderViewHost* rvh = initiator_tab->render_view_host(); |
563 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->routing_id())); | 585 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->routing_id())); |
564 } | 586 } |
565 | 587 |
566 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); | 588 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); |
567 if (!settings.get()) | 589 if (!settings.get()) |
568 return; | 590 return; |
569 | 591 |
570 // Storing last used color setting. | 592 // Storing last used color setting. |
571 settings->GetBoolean("color", &last_used_color_setting_); | 593 int color_mode; |
594 if (!settings->GetInteger(printing::kSettingColor, &color_mode)) | |
595 color_mode = printing::GRAY; | |
596 last_used_color_setting_ = (color_mode != printing::GRAY); | |
572 | 597 |
573 bool print_to_pdf = false; | 598 bool print_to_pdf = false; |
574 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); | 599 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); |
575 | 600 |
576 settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false); | 601 settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false); |
577 | 602 |
578 TabContentsWrapper* preview_tab_wrapper = | 603 TabContentsWrapper* preview_tab_wrapper = |
579 TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); | 604 TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); |
580 | 605 |
581 bool print_to_cloud = settings->HasKey(printing::kSettingCloudPrintId); | 606 bool print_to_cloud = settings->HasKey(printing::kSettingCloudPrintId); |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
969 return; | 994 return; |
970 | 995 |
971 // We no longer require the initiator tab details. Remove those details | 996 // We no longer require the initiator tab details. Remove those details |
972 // associated with the preview tab to allow the initiator tab to create | 997 // associated with the preview tab to allow the initiator tab to create |
973 // another preview tab. | 998 // another preview tab. |
974 printing::PrintPreviewTabController* tab_controller = | 999 printing::PrintPreviewTabController* tab_controller = |
975 printing::PrintPreviewTabController::GetInstance(); | 1000 printing::PrintPreviewTabController::GetInstance(); |
976 if (tab_controller) | 1001 if (tab_controller) |
977 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 1002 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
978 } | 1003 } |
OLD | NEW |