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

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

Issue 7826040: PrintPreview: Fixed RICOH MP C3501 color print job issues. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix conflicts Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
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
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 kPrinterColorModelForColor[] = "printerColorModelForColor";
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 kColorModelForColor[] = "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
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
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
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, kColorModelForColor))
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;
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(kPrinterColorModelForColor, 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
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(printing::kSettingColor, &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 bool print_to_cloud = settings->HasKey(printing::kSettingCloudPrintId); 603 bool print_to_cloud = settings->HasKey(printing::kSettingCloudPrintId);
579 if (print_to_cloud) { 604 if (print_to_cloud) {
580 std::string print_ticket; 605 std::string print_ticket;
581 args->GetString(1, &print_ticket); 606 args->GetString(1, &print_ticket);
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 return; 988 return;
964 989
965 // We no longer require the initiator tab details. Remove those details 990 // We no longer require the initiator tab details. Remove those details
966 // associated with the preview tab to allow the initiator tab to create 991 // associated with the preview tab to allow the initiator tab to create
967 // another preview tab. 992 // another preview tab.
968 printing::PrintPreviewTabController* tab_controller = 993 printing::PrintPreviewTabController* tab_controller =
969 printing::PrintPreviewTabController::GetInstance(); 994 printing::PrintPreviewTabController::GetInstance();
970 if (tab_controller) 995 if (tab_controller)
971 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); 996 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper());
972 } 997 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698