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

Side by Side Diff: printing/backend/cups_helper.cc

Issue 578493003: Take PPD and CUPS defaults into account on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "printing/backend/cups_helper.h" 5 #include "printing/backend/cups_helper.h"
6 6
7 #include <cups/ppd.h> 7 #include <cups/ppd.h>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 20 matching lines...) Expand all
31 const char kPrintoutMode[] = "PrintoutMode"; 31 const char kPrintoutMode[] = "PrintoutMode";
32 const char kDraftGray[] = "Draft.Gray"; 32 const char kDraftGray[] = "Draft.Gray";
33 const char kHighGray[] = "High.Gray"; 33 const char kHighGray[] = "High.Gray";
34 34
35 const char kDuplex[] = "Duplex"; 35 const char kDuplex[] = "Duplex";
36 const char kDuplexNone[] = "None"; 36 const char kDuplexNone[] = "None";
37 const char kPageSize[] = "PageSize"; 37 const char kPageSize[] = "PageSize";
38 38
39 const double kMicronsPerPoint = 10.0f * kHundrethsMMPerInch / kPointsPerInch; 39 const double kMicronsPerPoint = 10.0f * kHundrethsMMPerInch / kPointsPerInch;
40 40
41 #if !defined(OS_MACOSX)
42 void ParseLpOptions(const base::FilePath& filepath, 41 void ParseLpOptions(const base::FilePath& filepath,
43 const std::string& printer_name, 42 const std::string& printer_name,
44 int* num_options, cups_option_t** options) { 43 int* num_options, cups_option_t** options) {
45 std::string content; 44 std::string content;
46 if (!base::ReadFileToString(filepath, &content)) 45 if (!base::ReadFileToString(filepath, &content))
47 return; 46 return;
48 47
49 const char kDest[] = "dest"; 48 const char kDest[] = "dest";
50 const char kDefault[] = "default"; 49 const char kDefault[] = "default";
51 const size_t kDestLen = sizeof(kDest) - 1; 50 const size_t kDestLen = sizeof(kDest) - 1;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 if (line.empty()) 90 if (line.empty())
92 continue; 91 continue;
93 // Parse the selected printer custom options. 92 // Parse the selected printer custom options.
94 *num_options = cupsParseOptions(line.c_str(), 0, options); 93 *num_options = cupsParseOptions(line.c_str(), 0, options);
95 } 94 }
96 } 95 }
97 96
98 void MarkLpOptions(const std::string& printer_name, ppd_file_t** ppd) { 97 void MarkLpOptions(const std::string& printer_name, ppd_file_t** ppd) {
99 cups_option_t* options = NULL; 98 cups_option_t* options = NULL;
100 int num_options = 0; 99 int num_options = 0;
101 ppdMarkDefaults(*ppd);
102 100
103 const char kSystemLpOptionPath[] = "/etc/cups/lpoptions"; 101 const char kSystemLpOptionPath[] = "/etc/cups/lpoptions";
104 const char kUserLpOptionPath[] = ".cups/lpoptions"; 102 const char kUserLpOptionPath[] = ".cups/lpoptions";
105 103
106 std::vector<base::FilePath> file_locations; 104 std::vector<base::FilePath> file_locations;
107 file_locations.push_back(base::FilePath(kSystemLpOptionPath)); 105 file_locations.push_back(base::FilePath(kSystemLpOptionPath));
108 base::FilePath homedir; 106 base::FilePath homedir;
109 PathService::Get(base::DIR_HOME, &homedir); 107 PathService::Get(base::DIR_HOME, &homedir);
110 file_locations.push_back(base::FilePath(homedir.Append(kUserLpOptionPath))); 108 file_locations.push_back(base::FilePath(homedir.Append(kUserLpOptionPath)));
111 109
112 for (std::vector<base::FilePath>::const_iterator it = file_locations.begin(); 110 for (std::vector<base::FilePath>::const_iterator it = file_locations.begin();
113 it != file_locations.end(); ++it) { 111 it != file_locations.end(); ++it) {
114 num_options = 0; 112 num_options = 0;
115 options = NULL; 113 options = NULL;
116 ParseLpOptions(*it, printer_name, &num_options, &options); 114 ParseLpOptions(*it, printer_name, &num_options, &options);
117 if (num_options > 0 && options) { 115 if (num_options > 0 && options) {
118 cupsMarkOptions(*ppd, num_options, options); 116 cupsMarkOptions(*ppd, num_options, options);
119 cupsFreeOptions(num_options, options); 117 cupsFreeOptions(num_options, options);
120 } 118 }
121 } 119 }
122 } 120 }
123 #endif // !defined(OS_MACOSX)
124 121
125 bool GetBasicColorModelSettings(ppd_file_t* ppd, 122 bool GetBasicColorModelSettings(ppd_file_t* ppd,
126 ColorModel* color_model_for_black, 123 ColorModel* color_model_for_black,
127 ColorModel* color_model_for_color, 124 ColorModel* color_model_for_color,
128 bool* color_is_default) { 125 bool* color_is_default) {
129 ppd_option_t* color_model = ppdFindOption(ppd, kColorModel); 126 ppd_option_t* color_model = ppdFindOption(ppd, kColorModel);
130 if (!color_model) 127 if (!color_model)
131 return false; 128 return false;
132 129
133 if (ppdFindChoice(color_model, printing::kBlack)) 130 if (ppdFindChoice(color_model, printing::kBlack))
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 } 359 }
363 360
364 ppd_file_t* ppd = ppdOpenFile(ppd_file_path.value().c_str()); 361 ppd_file_t* ppd = ppdOpenFile(ppd_file_path.value().c_str());
365 if (!ppd) { 362 if (!ppd) {
366 int line = 0; 363 int line = 0;
367 ppd_status_t ppd_status = ppdLastError(&line); 364 ppd_status_t ppd_status = ppdLastError(&line);
368 LOG(ERROR) << "Failed to open PDD file: error " << ppd_status << " at line " 365 LOG(ERROR) << "Failed to open PDD file: error " << ppd_status << " at line "
369 << line << ", " << ppdErrorString(ppd_status); 366 << line << ", " << ppdErrorString(ppd_status);
370 return false; 367 return false;
371 } 368 }
369 ppdMarkDefaults(ppd);
370 MarkLpOptions(printer_name, &ppd);
372 371
373 printing::PrinterSemanticCapsAndDefaults caps; 372 printing::PrinterSemanticCapsAndDefaults caps;
374 #if !defined(OS_MACOSX)
375 MarkLpOptions(printer_name, &ppd);
376 #endif
377 caps.collate_capable = true; 373 caps.collate_capable = true;
378 caps.collate_default = true; 374 caps.collate_default = true;
379 caps.copies_capable = true; 375 caps.copies_capable = true;
380 376
381 ppd_choice_t* duplex_choice = ppdFindMarkedChoice(ppd, kDuplex); 377 ppd_choice_t* duplex_choice = ppdFindMarkedChoice(ppd, kDuplex);
382 if (!duplex_choice) { 378 if (!duplex_choice) {
383 ppd_option_t* option = ppdFindOption(ppd, kDuplex); 379 ppd_option_t* option = ppdFindOption(ppd, kDuplex);
384 if (option) 380 if (option)
385 duplex_choice = ppdFindChoice(option, option->defchoice); 381 duplex_choice = ppdFindChoice(option, option->defchoice);
386 } 382 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 } 431 }
436 432
437 ppdClose(ppd); 433 ppdClose(ppd);
438 base::DeleteFile(ppd_file_path, false); 434 base::DeleteFile(ppd_file_path, false);
439 435
440 *printer_info = caps; 436 *printer_info = caps;
441 return true; 437 return true;
442 } 438 }
443 439
444 } // namespace printing 440 } // namespace printing
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698