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

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

Issue 7817013: PrintPreview: Added code to identify the printer default duplex value. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test failures 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/cups.h> 51 #include <cups/cups.h>
52 #include <cups/ppd.h> 52 #include <cups/ppd.h>
53 53
54 #include "base/file_util.h" 54 #include "base/file_util.h"
55 #endif 55 #endif
56 56
57 namespace { 57 namespace {
58 58
59 const char kDisableColorOption[] = "disableColorOption"; 59 const char kDisableColorOption[] = "disableColorOption";
60 const char kSetColorAsDefault[] = "setColorAsDefault"; 60 const char kSetColorAsDefault[] = "setColorAsDefault";
61 const char kSetDuplexAsDefault[] = "setDuplexAsDefault";
62 61
63 #if defined(USE_CUPS) 62 #if defined(USE_CUPS)
64 const char kColorDevice[] = "ColorDevice"; 63 const char kColorDevice[] = "ColorDevice";
65 const char kDuplex[] = "Duplex"; 64 const char kDuplex[] = "Duplex";
66 const char kDuplexNone[] = "None"; 65 const char kDuplexNone[] = "None";
67 #elif defined(OS_WIN) 66 #elif defined(OS_WIN)
68 const char kPskColor[] = "psk:Color"; 67 const char kPskColor[] = "psk:Color";
69 const char kPskDuplexFeature[] = "psk:JobDuplexAllDocumentsContiguously"; 68 const char kPskDuplexFeature[] = "psk:JobDuplexAllDocumentsContiguously";
70 const char kPskTwoSided[] = "psk:TwoSided"; 69 const char kPskTwoSided[] = "psk:TwoSided";
71 #endif 70 #endif
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // Track the popularity of print settings and report the stats. 152 // Track the popularity of print settings and report the stats.
154 void ReportPrintSettingsStats(const DictionaryValue& settings) { 153 void ReportPrintSettingsStats(const DictionaryValue& settings) {
155 bool landscape; 154 bool landscape;
156 if (settings.GetBoolean(printing::kSettingLandscape, &landscape)) 155 if (settings.GetBoolean(printing::kSettingLandscape, &landscape))
157 ReportPrintSettingHistogram(landscape ? LANDSCAPE : PORTRAIT); 156 ReportPrintSettingHistogram(landscape ? LANDSCAPE : PORTRAIT);
158 157
159 bool collate; 158 bool collate;
160 if (settings.GetBoolean(printing::kSettingCollate, &collate) && collate) 159 if (settings.GetBoolean(printing::kSettingCollate, &collate) && collate)
161 ReportPrintSettingHistogram(COLLATE); 160 ReportPrintSettingHistogram(COLLATE);
162 161
163 int duplex_mode; 162 DictionaryValue* duplex_info;
164 if (settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode)) 163 if (settings.GetDictionary(printing::kSettingDuplexModeInfo, &duplex_info)) {
165 ReportPrintSettingHistogram(duplex_mode ? DUPLEX : SIMPLEX); 164 int duplex_mode;
165 if (settings.GetInteger(printing::kUserSelectedDuplexValue, &duplex_mode))
166 ReportPrintSettingHistogram(duplex_mode ? DUPLEX : SIMPLEX);
167 }
166 168
167 bool is_color; 169 bool is_color;
168 if (settings.GetBoolean(printing::kSettingColor, &is_color)) 170 if (settings.GetBoolean(printing::kSettingColor, &is_color))
169 ReportPrintSettingHistogram(is_color ? COLOR : BLACK_AND_WHITE); 171 ReportPrintSettingHistogram(is_color ? COLOR : BLACK_AND_WHITE);
170 } 172 }
171 173
172 printing::BackgroundPrintingManager* GetBackgroundPrintingManager() { 174 printing::BackgroundPrintingManager* GetBackgroundPrintingManager() {
173 return g_browser_process->background_printing_manager(); 175 return g_browser_process->background_printing_manager();
174 } 176 }
175 177
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 if (handler_) { 269 if (handler_) {
268 handler_->SetupPrinterList(*printers); 270 handler_->SetupPrinterList(*printers);
269 } 271 }
270 delete printers; 272 delete printers;
271 } 273 }
272 274
273 void GetPrinterCapabilities(const std::string& printer_name) { 275 void GetPrinterCapabilities(const std::string& printer_name) {
274 VLOG(1) << "Get printer capabilities start for " << printer_name; 276 VLOG(1) << "Get printer capabilities start for " << printer_name;
275 printing::PrinterCapsAndDefaults printer_info; 277 printing::PrinterCapsAndDefaults printer_info;
276 bool supports_color = true; 278 bool supports_color = true;
277 bool set_duplex_as_default = false; 279 int default_duplex_setting_value = printing::UNKNOWN;
278 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, 280 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name,
279 &printer_info)) { 281 &printer_info)) {
280 return; 282 return;
281 } 283 }
282 284
283 #if defined(USE_CUPS) 285 #if defined(USE_CUPS)
284 FilePath ppd_file_path; 286 FilePath ppd_file_path;
285 if (!file_util::CreateTemporaryFile(&ppd_file_path)) 287 if (!file_util::CreateTemporaryFile(&ppd_file_path))
286 return; 288 return;
287 289
(...skipping 12 matching lines...) Expand all
300 if (attr && attr->value) 302 if (attr && attr->value)
301 supports_color = ppd->color_device; 303 supports_color = ppd->color_device;
302 304
303 ppd_choice_t* ch = ppdFindMarkedChoice(ppd, kDuplex); 305 ppd_choice_t* ch = ppdFindMarkedChoice(ppd, kDuplex);
304 if (ch == NULL) { 306 if (ch == NULL) {
305 ppd_option_t* option = ppdFindOption(ppd, kDuplex); 307 ppd_option_t* option = ppdFindOption(ppd, kDuplex);
306 if (option != NULL) 308 if (option != NULL)
307 ch = ppdFindChoice(option, option->defchoice); 309 ch = ppdFindChoice(option, option->defchoice);
308 } 310 }
309 311
310 if (ch != NULL && strcmp(ch->choice, kDuplexNone) != 0) 312 if (ch != NULL) {
311 set_duplex_as_default = true; 313 if (strcmp(ch->choice, kDuplexNone) != 0)
312 314 default_duplex_setting_value = printing::TWO_SIDED;
315 else
316 default_duplex_setting_value = printing::ONE_SIDED;
317 }
313 ppdClose(ppd); 318 ppdClose(ppd);
314 } 319 }
315 file_util::Delete(ppd_file_path, false); 320 file_util::Delete(ppd_file_path, false);
316 #elif defined(OS_WIN) 321 #elif defined(OS_WIN)
317 // According to XPS 1.0 spec, only color printers have psk:Color. 322 // According to XPS 1.0 spec, only color printers have psk:Color.
318 // Therefore we don't need to parse the whole XML file, we just need to 323 // Therefore we don't need to parse the whole XML file, we just need to
319 // search the string. The spec can be found at: 324 // search the string. The spec can be found at:
320 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. 325 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431.
321 supports_color = (printer_info.printer_capabilities.find(kPskColor) != 326 supports_color = (printer_info.printer_capabilities.find(kPskColor) !=
322 std::string::npos); 327 std::string::npos);
323 set_duplex_as_default = 328
324 (printer_info.printer_defaults.find(kPskDuplexFeature) != 329 if (printer_info.printer_defaults.find(kPskDuplexFeature) !=
325 std::string::npos) && 330 std::string::npos) {
326 (printer_info.printer_defaults.find(kPskTwoSided) != 331 if (printer_info.printer_defaults.find(kPskTwoSided) !=
327 std::string::npos); 332 std::string::npos) {
333 default_duplex_setting_value = printing::TWO_SIDED;
334 } else {
335 default_duplex_setting_value = printing::ONE_SIDED;
336 }
337 }
328 #else 338 #else
329 NOTIMPLEMENTED(); 339 NOTIMPLEMENTED();
330 #endif 340 #endif
331 341
332 DictionaryValue settings_info; 342 DictionaryValue settings_info;
333 settings_info.SetBoolean(kDisableColorOption, !supports_color); 343 settings_info.SetBoolean(kDisableColorOption, !supports_color);
334 if (!supports_color) { 344 if (!supports_color) {
335 settings_info.SetBoolean(kSetColorAsDefault, false); 345 settings_info.SetBoolean(kSetColorAsDefault, false);
336 } else { 346 } else {
337 settings_info.SetBoolean(kSetColorAsDefault, 347 settings_info.SetBoolean(kSetColorAsDefault,
338 PrintPreviewHandler::last_used_color_setting_); 348 PrintPreviewHandler::last_used_color_setting_);
339 } 349 }
340 settings_info.SetBoolean(kSetDuplexAsDefault, set_duplex_as_default); 350 settings_info.SetInteger(printing::kPrinterDefaultDuplexValue,
351 default_duplex_setting_value);
341 BrowserThread::PostTask( 352 BrowserThread::PostTask(
342 BrowserThread::UI, FROM_HERE, 353 BrowserThread::UI, FROM_HERE,
343 NewRunnableMethod(this, 354 NewRunnableMethod(this,
344 &PrintSystemTaskProxy::SendPrinterCapabilities, 355 &PrintSystemTaskProxy::SendPrinterCapabilities,
345 settings_info.DeepCopy())); 356 settings_info.DeepCopy()));
346 } 357 }
347 358
348 void SendPrinterCapabilities(DictionaryValue* settings_info) { 359 void SendPrinterCapabilities(DictionaryValue* settings_info) {
349 if (handler_) 360 if (handler_)
350 handler_->SendPrinterCapabilities(*settings_info); 361 handler_->SendPrinterCapabilities(*settings_info);
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 return; 985 return;
975 986
976 // We no longer require the initiator tab details. Remove those details 987 // We no longer require the initiator tab details. Remove those details
977 // associated with the preview tab to allow the initiator tab to create 988 // associated with the preview tab to allow the initiator tab to create
978 // another preview tab. 989 // another preview tab.
979 printing::PrintPreviewTabController* tab_controller = 990 printing::PrintPreviewTabController* tab_controller =
980 printing::PrintPreviewTabController::GetInstance(); 991 printing::PrintPreviewTabController::GetInstance();
981 if (tab_controller) 992 if (tab_controller)
982 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); 993 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper());
983 } 994 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698