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