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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 const char kPrinterColorModelForColor[] = "printerColorModelForColor"; |
| 62 const char kPrinterDefaultDuplexValue[] = "printerDefaultDuplexValue"; |
62 | 63 |
63 #if defined(USE_CUPS) | 64 #if defined(USE_CUPS) |
64 const char kColorDevice[] = "ColorDevice"; | 65 const char kColorDevice[] = "ColorDevice"; |
65 const char kColorModel[] = "ColorModel"; | 66 const char kColorModel[] = "ColorModel"; |
66 const char kColorModelForColor[] = "Color"; | 67 const char kColorModelForColor[] = "Color"; |
67 const char kCMYK[] = "CMYK"; | 68 const char kCMYK[] = "CMYK"; |
68 const char kDuplex[] = "Duplex"; | 69 const char kDuplex[] = "Duplex"; |
69 const char kDuplexNone[] = "None"; | 70 const char kDuplexNone[] = "None"; |
70 #elif defined(OS_WIN) | 71 #elif defined(OS_WIN) |
71 const char kPskColor[] = "psk:Color"; | 72 const char kPskColor[] = "psk:Color"; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 275 } |
275 delete printers; | 276 delete printers; |
276 } | 277 } |
277 | 278 |
278 void GetPrinterCapabilities(const std::string& printer_name) { | 279 void GetPrinterCapabilities(const std::string& printer_name) { |
279 VLOG(1) << "Get printer capabilities start for " << printer_name; | 280 VLOG(1) << "Get printer capabilities start for " << printer_name; |
280 printing::PrinterCapsAndDefaults printer_info; | 281 printing::PrinterCapsAndDefaults printer_info; |
281 bool supports_color = true; | 282 bool supports_color = true; |
282 bool set_duplex_as_default = false; | 283 bool set_duplex_as_default = false; |
283 int printer_color_space = printing::GRAY; | 284 int printer_color_space = printing::GRAY; |
| 285 int default_duplex_setting_value = printing::UNKNOWN_DUPLEX_MODE; |
284 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, | 286 if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, |
285 &printer_info)) { | 287 &printer_info)) { |
286 return; | 288 return; |
287 } | 289 } |
288 | 290 |
289 #if defined(USE_CUPS) | 291 #if defined(USE_CUPS) |
290 FilePath ppd_file_path; | 292 FilePath ppd_file_path; |
291 if (!file_util::CreateTemporaryFile(&ppd_file_path)) | 293 if (!file_util::CreateTemporaryFile(&ppd_file_path)) |
292 return; | 294 return; |
293 | 295 |
294 int data_size = printer_info.printer_capabilities.length(); | 296 int data_size = printer_info.printer_capabilities.length(); |
295 if (data_size != file_util::WriteFile( | 297 if (data_size != file_util::WriteFile( |
296 ppd_file_path, | 298 ppd_file_path, |
297 printer_info.printer_capabilities.data(), | 299 printer_info.printer_capabilities.data(), |
298 data_size)) { | 300 data_size)) { |
299 file_util::Delete(ppd_file_path, false); | 301 file_util::Delete(ppd_file_path, false); |
300 return; | 302 return; |
301 } | 303 } |
302 | 304 |
303 ppd_file_t* ppd = ppdOpenFile(ppd_file_path.value().c_str()); | 305 ppd_file_t* ppd = ppdOpenFile(ppd_file_path.value().c_str()); |
304 if (ppd) { | 306 if (ppd) { |
305 ppd_attr_t* attr = ppdFindAttr(ppd, kColorDevice, NULL); | 307 ppd_attr_t* attr = ppdFindAttr(ppd, kColorDevice, NULL); |
306 if (attr && attr->value) | 308 if (attr && attr->value) |
307 supports_color = ppd->color_device; | 309 supports_color = ppd->color_device; |
308 | 310 |
309 ppd_choice_t* ch = ppdFindMarkedChoice(ppd, kDuplex); | 311 ppd_choice_t* duplex_choice = ppdFindMarkedChoice(ppd, kDuplex); |
310 if (ch == NULL) { | 312 if (duplex_choice == NULL) { |
311 ppd_option_t* option = ppdFindOption(ppd, kDuplex); | 313 ppd_option_t* option = ppdFindOption(ppd, kDuplex); |
312 if (option != NULL) | 314 if (option != NULL) |
313 ch = ppdFindChoice(option, option->defchoice); | 315 duplex_choice = ppdFindChoice(option, option->defchoice); |
314 } | 316 } |
315 | 317 |
316 if (ch != NULL && strcmp(ch->choice, kDuplexNone) != 0) | 318 if (duplex_choice != NULL && |
| 319 strcmp(duplex_choice->choice, kDuplexNone) != 0) |
317 set_duplex_as_default = true; | 320 set_duplex_as_default = true; |
318 | 321 |
| 322 if (duplex_choice != NULL) { |
| 323 if (strcmp(duplex_choice->choice, kDuplexNone) != 0) |
| 324 default_duplex_setting_value = printing::LONG_EDGE; |
| 325 else |
| 326 default_duplex_setting_value = printing::SIMPLEX; |
| 327 } |
| 328 |
319 if (supports_color) { | 329 if (supports_color) { |
320 // Identify the color space (COLOR/CMYK) for this printer. | 330 // Identify the color space (COLOR/CMYK) for this printer. |
321 ppd_option_t* color_model = ppdFindOption(ppd, kColorModel); | 331 ppd_option_t* color_model = ppdFindOption(ppd, kColorModel); |
322 if (color_model != NULL) { | 332 if (color_model != NULL) { |
323 if (ppdFindChoice(color_model, kColorModelForColor)) | 333 if (ppdFindChoice(color_model, kColorModelForColor)) |
324 printer_color_space = printing::COLOR; | 334 printer_color_space = printing::COLOR; |
325 else if (ppdFindChoice(color_model, kCMYK)) | 335 else if (ppdFindChoice(color_model, kCMYK)) |
326 printer_color_space = printing::CMYK; | 336 printer_color_space = printing::CMYK; |
327 } | 337 } |
328 } | 338 } |
329 | |
330 ppdClose(ppd); | 339 ppdClose(ppd); |
331 } | 340 } |
332 file_util::Delete(ppd_file_path, false); | 341 file_util::Delete(ppd_file_path, false); |
333 #elif defined(OS_WIN) | 342 #elif defined(OS_WIN) |
334 // According to XPS 1.0 spec, only color printers have psk:Color. | 343 // According to XPS 1.0 spec, only color printers have psk:Color. |
335 // Therefore we don't need to parse the whole XML file, we just need to | 344 // Therefore we don't need to parse the whole XML file, we just need to |
336 // search the string. The spec can be found at: | 345 // search the string. The spec can be found at: |
337 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. | 346 // http://msdn.microsoft.com/en-us/windows/hardware/gg463431. |
338 supports_color = (printer_info.printer_capabilities.find(kPskColor) != | 347 supports_color = (printer_info.printer_capabilities.find(kPskColor) != |
339 std::string::npos); | 348 std::string::npos); |
340 if (supports_color) | 349 if (supports_color) |
341 printer_color_space = printing::COLOR; | 350 printer_color_space = printing::COLOR; |
342 | 351 |
343 set_duplex_as_default = | 352 set_duplex_as_default = |
344 (printer_info.printer_defaults.find(kPskDuplexFeature) != | 353 (printer_info.printer_defaults.find(kPskDuplexFeature) != |
345 std::string::npos) && | 354 std::string::npos) && |
346 (printer_info.printer_defaults.find(kPskTwoSided) != | 355 (printer_info.printer_defaults.find(kPskTwoSided) != |
347 std::string::npos); | 356 std::string::npos); |
| 357 |
| 358 if (printer_info.printer_defaults.find(kPskDuplexFeature) != |
| 359 std::string::npos) { |
| 360 if (printer_info.printer_defaults.find(kPskTwoSided) != |
| 361 std::string::npos) { |
| 362 default_duplex_setting_value = printing::LONG_EDGE; |
| 363 } else { |
| 364 default_duplex_setting_value = printing::SIMPLEX; |
| 365 } |
| 366 } |
348 #else | 367 #else |
349 NOTIMPLEMENTED(); | 368 NOTIMPLEMENTED(); |
350 #endif | 369 #endif |
351 | 370 |
352 DictionaryValue settings_info; | 371 DictionaryValue settings_info; |
353 settings_info.SetBoolean(kDisableColorOption, !supports_color); | 372 settings_info.SetBoolean(kDisableColorOption, !supports_color); |
354 if (!supports_color) { | 373 if (!supports_color) { |
355 settings_info.SetBoolean(kSetColorAsDefault, false); | 374 settings_info.SetBoolean(kSetColorAsDefault, false); |
356 } else { | 375 } else { |
357 settings_info.SetBoolean(kSetColorAsDefault, | 376 settings_info.SetBoolean(kSetColorAsDefault, |
358 PrintPreviewHandler::last_used_color_setting_); | 377 PrintPreviewHandler::last_used_color_setting_); |
359 } | 378 } |
360 settings_info.SetBoolean(kSetDuplexAsDefault, set_duplex_as_default); | 379 settings_info.SetBoolean(kSetDuplexAsDefault, set_duplex_as_default); |
361 settings_info.SetInteger(kPrinterColorModelForColor, printer_color_space); | 380 settings_info.SetInteger(kPrinterColorModelForColor, printer_color_space); |
| 381 settings_info.SetInteger(kPrinterDefaultDuplexValue, |
| 382 default_duplex_setting_value); |
362 BrowserThread::PostTask( | 383 BrowserThread::PostTask( |
363 BrowserThread::UI, FROM_HERE, | 384 BrowserThread::UI, FROM_HERE, |
364 NewRunnableMethod(this, | 385 NewRunnableMethod(this, |
365 &PrintSystemTaskProxy::SendPrinterCapabilities, | 386 &PrintSystemTaskProxy::SendPrinterCapabilities, |
366 settings_info.DeepCopy())); | 387 settings_info.DeepCopy())); |
367 } | 388 } |
368 | 389 |
369 void SendPrinterCapabilities(DictionaryValue* settings_info) { | 390 void SendPrinterCapabilities(DictionaryValue* settings_info) { |
370 if (handler_) | 391 if (handler_) |
371 handler_->SendPrinterCapabilities(*settings_info); | 392 handler_->SendPrinterCapabilities(*settings_info); |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 return; | 1019 return; |
999 | 1020 |
1000 // We no longer require the initiator tab details. Remove those details | 1021 // We no longer require the initiator tab details. Remove those details |
1001 // associated with the preview tab to allow the initiator tab to create | 1022 // associated with the preview tab to allow the initiator tab to create |
1002 // another preview tab. | 1023 // another preview tab. |
1003 printing::PrintPreviewTabController* tab_controller = | 1024 printing::PrintPreviewTabController* tab_controller = |
1004 printing::PrintPreviewTabController::GetInstance(); | 1025 printing::PrintPreviewTabController::GetInstance(); |
1005 if (tab_controller) | 1026 if (tab_controller) |
1006 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 1027 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
1007 } | 1028 } |
OLD | NEW |