Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/ui/webui/print_preview/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <map> | |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/base64.h" | 12 #include "base/base64.h" |
| 12 #include "base/bind.h" | 13 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 15 #include "base/i18n/file_util_icu.h" | 16 #include "base/i18n/file_util_icu.h" |
| 16 #include "base/i18n/number_formatting.h" | 17 #include "base/i18n/number_formatting.h" |
| 17 #include "base/json/json_reader.h" | 18 #include "base/json/json_reader.h" |
| 18 #include "base/lazy_instance.h" | 19 #include "base/lazy_instance.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 41 #include "chrome/browser/ui/chrome_select_file_policy.h" | 42 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 42 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 43 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 43 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 44 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 44 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" | 45 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" |
| 45 #include "chrome/common/chrome_paths.h" | 46 #include "chrome/common/chrome_paths.h" |
| 46 #include "chrome/common/chrome_switches.h" | 47 #include "chrome/common/chrome_switches.h" |
| 47 #include "chrome/common/cloud_print/cloud_print_constants.h" | 48 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 48 #include "chrome/common/crash_keys.h" | 49 #include "chrome/common/crash_keys.h" |
| 49 #include "chrome/common/pref_names.h" | 50 #include "chrome/common/pref_names.h" |
| 50 #include "chrome/common/print_messages.h" | 51 #include "chrome/common/print_messages.h" |
| 52 #include "components/cloud_devices/common/cloud_device_description.h" | |
| 51 #include "components/cloud_devices/common/cloud_devices_urls.h" | 53 #include "components/cloud_devices/common/cloud_devices_urls.h" |
| 54 #include "components/cloud_devices/common/printer_description.h" | |
| 52 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 55 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 53 #include "components/signin/core/browser/signin_manager.h" | 56 #include "components/signin/core/browser/signin_manager.h" |
| 54 #include "components/signin/core/browser/signin_manager_base.h" | 57 #include "components/signin/core/browser/signin_manager_base.h" |
| 55 #include "content/public/browser/browser_context.h" | 58 #include "content/public/browser/browser_context.h" |
| 56 #include "content/public/browser/browser_thread.h" | 59 #include "content/public/browser/browser_thread.h" |
| 57 #include "content/public/browser/navigation_controller.h" | 60 #include "content/public/browser/navigation_controller.h" |
| 58 #include "content/public/browser/navigation_entry.h" | 61 #include "content/public/browser/navigation_entry.h" |
| 59 #include "content/public/browser/render_view_host.h" | 62 #include "content/public/browser/render_view_host.h" |
| 60 #include "content/public/browser/web_contents.h" | 63 #include "content/public/browser/web_contents.h" |
| 61 #include "content/public/browser/web_ui.h" | 64 #include "content/public/browser/web_ui.h" |
| 62 #include "google_apis/gaia/oauth2_token_service.h" | 65 #include "google_apis/gaia/oauth2_token_service.h" |
| 63 #include "printing/backend/print_backend.h" | 66 #include "printing/backend/print_backend.h" |
| 64 #include "printing/backend/print_backend_consts.h" | 67 #include "printing/backend/print_backend_consts.h" |
| 65 #include "printing/metafile.h" | 68 #include "printing/metafile.h" |
| 66 #include "printing/metafile_impl.h" | 69 #include "printing/metafile_impl.h" |
| 67 #include "printing/pdf_render_settings.h" | 70 #include "printing/pdf_render_settings.h" |
| 68 #include "printing/print_settings.h" | 71 #include "printing/print_settings.h" |
| 72 #include "printing/printing_context.h" | |
| 69 #include "printing/units.h" | 73 #include "printing/units.h" |
| 70 #include "third_party/icu/source/i18n/unicode/ulocdata.h" | 74 #include "third_party/icu/source/i18n/unicode/ulocdata.h" |
| 71 | 75 |
| 72 #if defined(OS_CHROMEOS) | 76 #if defined(OS_CHROMEOS) |
| 73 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 77 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
| 74 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " | 78 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " |
| 75 #endif | 79 #endif |
| 76 | 80 |
| 77 #if defined(ENABLE_SERVICE_DISCOVERY) | 81 #if defined(ENABLE_SERVICE_DISCOVERY) |
| 78 #include "chrome/browser/local_discovery/privet_constants.h" | 82 #include "chrome/browser/local_discovery/privet_constants.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 const char kNumberFormat[] = "numberFormat"; | 176 const char kNumberFormat[] = "numberFormat"; |
| 173 // Name of a dictionary field specifying whether to print automatically in | 177 // Name of a dictionary field specifying whether to print automatically in |
| 174 // kiosk mode. See http://crbug.com/31395. | 178 // kiosk mode. See http://crbug.com/31395. |
| 175 const char kPrintAutomaticallyInKioskMode[] = "printAutomaticallyInKioskMode"; | 179 const char kPrintAutomaticallyInKioskMode[] = "printAutomaticallyInKioskMode"; |
| 176 #if defined(OS_WIN) | 180 #if defined(OS_WIN) |
| 177 const char kHidePrintWithSystemDialogLink[] = "hidePrintWithSystemDialogLink"; | 181 const char kHidePrintWithSystemDialogLink[] = "hidePrintWithSystemDialogLink"; |
| 178 #endif | 182 #endif |
| 179 // Name of a dictionary field holding the state of selection for document. | 183 // Name of a dictionary field holding the state of selection for document. |
| 180 const char kDocumentHasSelection[] = "documentHasSelection"; | 184 const char kDocumentHasSelection[] = "documentHasSelection"; |
| 181 | 185 |
| 186 // Id of the predefined PDF printer. | |
| 187 const char kLocalPdfPrinterId[] = "Save as PDF"; | |
| 188 | |
| 182 // Additional printer capability setting keys. | 189 // Additional printer capability setting keys. |
| 183 const char kPrinterId[] = "printerId"; | 190 const char kPrinterId[] = "printerId"; |
| 191 const char kPrinterCapabilities[] = "capabilities"; | |
| 184 const char kDisableColorOption[] = "disableColorOption"; | 192 const char kDisableColorOption[] = "disableColorOption"; |
| 185 const char kSetDuplexAsDefault[] = "setDuplexAsDefault"; | 193 const char kSetDuplexAsDefault[] = "setDuplexAsDefault"; |
| 186 const char kPrinterDefaultDuplexValue[] = "printerDefaultDuplexValue"; | 194 const char kPrinterDefaultDuplexValue[] = "printerDefaultDuplexValue"; |
| 187 #if defined(USE_CUPS) | 195 #if defined(USE_CUPS) |
| 188 const char kCUPSsColorModel[] = "cupsColorModel"; | 196 const char kCUPSsColorModel[] = "cupsColorModel"; |
| 189 const char kCUPSsBWModel[] = "cupsBWModel"; | 197 const char kCUPSsBWModel[] = "cupsBWModel"; |
| 190 #endif | 198 #endif |
| 191 | 199 |
| 192 // Get the print job settings dictionary from |args|. The caller takes | 200 // Get the print job settings dictionary from |args|. The caller takes |
| 193 // ownership of the returned DictionaryValue. Returns NULL on failure. | 201 // ownership of the returned DictionaryValue. Returns NULL on failure. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 | 277 |
| 270 std::string GetDefaultPrinterOnFileThread( | 278 std::string GetDefaultPrinterOnFileThread( |
| 271 scoped_refptr<printing::PrintBackend> print_backend) { | 279 scoped_refptr<printing::PrintBackend> print_backend) { |
| 272 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 280 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 273 | 281 |
| 274 std::string default_printer = print_backend->GetDefaultPrinterName(); | 282 std::string default_printer = print_backend->GetDefaultPrinterName(); |
| 275 VLOG(1) << "Default Printer: " << default_printer; | 283 VLOG(1) << "Default Printer: " << default_printer; |
| 276 return default_printer; | 284 return default_printer; |
| 277 } | 285 } |
| 278 | 286 |
| 287 gfx::Size GetDefaultPdfMediaSizeMicrons() { | |
| 288 scoped_ptr<printing::PrintingContext> printing_context( | |
| 289 printing::PrintingContext::Create( | |
| 290 g_browser_process->GetApplicationLocale())); | |
| 291 if (printing::PrintingContext::OK != printing_context->UsePdfSettings() || | |
| 292 printing_context->settings().device_units_per_inch() <= 0) { | |
| 293 return gfx::Size(); | |
| 294 } | |
| 295 gfx::Size pdf_media_size = printing_context->GetPdfPaperSizeDeviceUnits(); | |
| 296 float deviceMicronsPerDeviceUnit = | |
| 297 (printing::kHundrethsMMPerInch * 10.0f) / | |
| 298 printing_context->settings().device_units_per_inch(); | |
| 299 return gfx::Size(pdf_media_size.width() * deviceMicronsPerDeviceUnit, | |
| 300 pdf_media_size.height() * deviceMicronsPerDeviceUnit); | |
| 301 } | |
| 302 | |
| 303 typedef base::Callback<void(const base::DictionaryValue*)> | |
| 304 GetPdfCapabilitiesCallback; | |
| 305 | |
| 306 const cloud_devices::printer::MediaType PDF_MEDIA[] = { | |
| 307 cloud_devices::printer::ISO_A4, | |
| 308 cloud_devices::printer::ISO_A3, | |
| 309 cloud_devices::printer::NA_LETTER, | |
| 310 cloud_devices::printer::NA_LEGAL, | |
| 311 cloud_devices::printer::NA_LEDGER | |
| 312 }; | |
| 313 | |
| 314 scoped_ptr<base::DictionaryValue> GetPdfCapabilities( | |
| 315 scoped_refptr<printing::PrintBackend> print_backend) { | |
| 316 gfx::Size default_media_size = GetDefaultPdfMediaSizeMicrons(); | |
| 317 | |
| 318 cloud_devices::CloudDeviceDescription description; | |
|
Vitaly Buka (NO REVIEWS)
2014/05/22 01:11:21
use namespace cloud_devices::printer;
Aleksey Shlyapnikov
2014/05/22 03:51:18
Done.
| |
| 319 | |
| 320 cloud_devices::printer::OrientationCapability orientation; | |
| 321 orientation.AddOption(cloud_devices::printer::PORTRAIT); | |
| 322 orientation.AddOption(cloud_devices::printer::LANDSCAPE); | |
| 323 orientation.AddDefaultOption(cloud_devices::printer::AUTO_ORIENTATION, true); | |
| 324 orientation.SaveTo(&description); | |
| 325 | |
| 326 cloud_devices::printer::ColorCapability color; | |
| 327 color.AddDefaultOption(cloud_devices::printer::Color( | |
| 328 cloud_devices::printer::STANDARD_COLOR), true); | |
| 329 color.SaveTo(&description); | |
| 330 | |
| 331 cloud_devices::printer::Media default_media_option( | |
| 332 "", default_media_size.width(), default_media_size.height()); | |
| 333 if (!default_media_option.MatchBySize() || | |
| 334 std::find(PDF_MEDIA, | |
| 335 PDF_MEDIA + arraysize(PDF_MEDIA), | |
| 336 default_media_option.type) == | |
| 337 PDF_MEDIA + arraysize(PDF_MEDIA)) { | |
| 338 default_media_option = cloud_devices::printer::Media( | |
| 339 g_browser_process->GetApplicationLocale() == "en-US" ? | |
| 340 cloud_devices::printer::NA_LETTER : cloud_devices::printer::ISO_A4); | |
| 341 default_media_option.MatchByType(); | |
| 342 } | |
| 343 cloud_devices::printer::MediaCapability media; | |
| 344 for (size_t i = 0; i < arraysize(PDF_MEDIA); ++i) { | |
| 345 cloud_devices::printer::Media media_option(PDF_MEDIA[i]); | |
| 346 if (media_option.MatchByType()) { | |
| 347 media.AddDefaultOption(media_option, | |
| 348 default_media_option.type == media_option.type); | |
| 349 } | |
| 350 } | |
| 351 media.SaveTo(&description); | |
| 352 | |
| 353 return description.release(); | |
|
Vitaly Buka (NO REVIEWS)
2014/05/22 01:11:21
return description.Pass();
Aleksey Shlyapnikov
2014/05/22 03:51:18
Done.
| |
| 354 } | |
| 355 | |
| 279 void EnumeratePrintersOnFileThread( | 356 void EnumeratePrintersOnFileThread( |
| 280 scoped_refptr<printing::PrintBackend> print_backend, | 357 scoped_refptr<printing::PrintBackend> print_backend, |
| 281 base::ListValue* printers) { | 358 base::ListValue* printers) { |
| 282 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 359 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 283 | 360 |
| 284 VLOG(1) << "Enumerate printers start"; | 361 VLOG(1) << "Enumerate printers start"; |
| 285 printing::PrinterList printer_list; | 362 printing::PrinterList printer_list; |
| 286 print_backend->EnumeratePrinters(&printer_list); | 363 print_backend->EnumeratePrinters(&printer_list); |
| 287 | 364 |
| 288 for (printing::PrinterList::iterator it = printer_list.begin(); | 365 for (printing::PrinterList::iterator it = printer_list.begin(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 GetPrinterCapabilitiesFailureCallback; | 406 GetPrinterCapabilitiesFailureCallback; |
| 330 | 407 |
| 331 void GetPrinterCapabilitiesOnFileThread( | 408 void GetPrinterCapabilitiesOnFileThread( |
| 332 scoped_refptr<printing::PrintBackend> print_backend, | 409 scoped_refptr<printing::PrintBackend> print_backend, |
| 333 const std::string& printer_name, | 410 const std::string& printer_name, |
| 334 const GetPrinterCapabilitiesSuccessCallback& success_cb, | 411 const GetPrinterCapabilitiesSuccessCallback& success_cb, |
| 335 const GetPrinterCapabilitiesFailureCallback& failure_cb) { | 412 const GetPrinterCapabilitiesFailureCallback& failure_cb) { |
| 336 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 413 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 337 DCHECK(!printer_name.empty()); | 414 DCHECK(!printer_name.empty()); |
| 338 | 415 |
| 416 // Special case for PDF printer. | |
| 417 if (printer_name == kLocalPdfPrinterId) { | |
| 418 scoped_ptr<base::DictionaryValue> printer_info(new base::DictionaryValue); | |
| 419 printer_info->SetString(kPrinterId, printer_name); | |
| 420 printer_info->Set(kPrinterCapabilities, | |
| 421 GetPdfCapabilities(print_backend).release()); | |
| 422 BrowserThread::PostTask( | |
| 423 BrowserThread::UI, FROM_HERE, | |
| 424 base::Bind(success_cb, base::Owned(printer_info.release()))); | |
| 425 return; | |
| 426 } | |
| 427 | |
| 339 VLOG(1) << "Get printer capabilities start for " << printer_name; | 428 VLOG(1) << "Get printer capabilities start for " << printer_name; |
| 340 crash_keys::ScopedPrinterInfo crash_key( | 429 crash_keys::ScopedPrinterInfo crash_key( |
| 341 print_backend->GetPrinterDriverInfo(printer_name)); | 430 print_backend->GetPrinterDriverInfo(printer_name)); |
| 342 | 431 |
| 343 if (!print_backend->IsValidPrinter(printer_name)) { | 432 if (!print_backend->IsValidPrinter(printer_name)) { |
| 344 // TODO(gene): Notify explicitly if printer is not valid, instead of | 433 // TODO(gene): Notify explicitly if printer is not valid, instead of |
| 345 // failed to get capabilities. | 434 // failed to get capabilities. |
| 346 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 435 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 347 base::Bind(failure_cb, printer_name)); | 436 base::Bind(failure_cb, printer_name)); |
| 348 return; | 437 return; |
| (...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1566 printer_value->SetString("name", description.name); | 1655 printer_value->SetString("name", description.name); |
| 1567 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); | 1656 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); |
| 1568 printer_value->SetBoolean( | 1657 printer_value->SetBoolean( |
| 1569 "isUnregistered", | 1658 "isUnregistered", |
| 1570 description.id.empty() && | 1659 description.id.empty() && |
| 1571 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)); | 1660 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)); |
| 1572 printer_value->SetString("cloudID", description.id); | 1661 printer_value->SetString("cloudID", description.id); |
| 1573 } | 1662 } |
| 1574 | 1663 |
| 1575 #endif | 1664 #endif |
| OLD | NEW |