| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 268 |
| 261 // Callback that stores a PDF file on disk. | 269 // Callback that stores a PDF file on disk. |
| 262 void PrintToPdfCallback(printing::Metafile* metafile, | 270 void PrintToPdfCallback(printing::Metafile* metafile, |
| 263 const base::FilePath& path) { | 271 const base::FilePath& path) { |
| 264 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 272 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 265 metafile->SaveTo(path); | 273 metafile->SaveTo(path); |
| 266 // |metafile| must be deleted on the UI thread. | 274 // |metafile| must be deleted on the UI thread. |
| 267 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, metafile); | 275 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, metafile); |
| 268 } | 276 } |
| 269 | 277 |
| 270 std::string GetDefaultPrinterOnFileThread( | 278 std::string GetDefaultPrinterOnFileThread() { |
| 271 scoped_refptr<printing::PrintBackend> print_backend) { | |
| 272 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 279 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 273 | 280 |
| 281 scoped_refptr<printing::PrintBackend> print_backend( |
| 282 printing::PrintBackend::CreateInstance(NULL)); |
| 283 |
| 274 std::string default_printer = print_backend->GetDefaultPrinterName(); | 284 std::string default_printer = print_backend->GetDefaultPrinterName(); |
| 275 VLOG(1) << "Default Printer: " << default_printer; | 285 VLOG(1) << "Default Printer: " << default_printer; |
| 276 return default_printer; | 286 return default_printer; |
| 277 } | 287 } |
| 278 | 288 |
| 279 void EnumeratePrintersOnFileThread( | 289 gfx::Size GetDefaultPdfMediaSizeMicrons() { |
| 280 scoped_refptr<printing::PrintBackend> print_backend, | 290 scoped_ptr<printing::PrintingContext> printing_context( |
| 281 base::ListValue* printers) { | 291 printing::PrintingContext::Create( |
| 292 g_browser_process->GetApplicationLocale())); |
| 293 if (printing::PrintingContext::OK != printing_context->UsePdfSettings() || |
| 294 printing_context->settings().device_units_per_inch() <= 0) { |
| 295 return gfx::Size(); |
| 296 } |
| 297 gfx::Size pdf_media_size = printing_context->GetPdfPaperSizeDeviceUnits(); |
| 298 float deviceMicronsPerDeviceUnit = |
| 299 (printing::kHundrethsMMPerInch * 10.0f) / |
| 300 printing_context->settings().device_units_per_inch(); |
| 301 return gfx::Size(pdf_media_size.width() * deviceMicronsPerDeviceUnit, |
| 302 pdf_media_size.height() * deviceMicronsPerDeviceUnit); |
| 303 } |
| 304 |
| 305 typedef base::Callback<void(const base::DictionaryValue*)> |
| 306 GetPdfCapabilitiesCallback; |
| 307 |
| 308 scoped_ptr<base::DictionaryValue> GetPdfCapabilitiesOnFileThread( |
| 309 const std::string& locale) { |
| 282 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 310 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 283 | 311 |
| 312 cloud_devices::CloudDeviceDescription description; |
| 313 using namespace cloud_devices::printer; |
| 314 |
| 315 OrientationCapability orientation; |
| 316 orientation.AddOption(cloud_devices::printer::PORTRAIT); |
| 317 orientation.AddOption(cloud_devices::printer::LANDSCAPE); |
| 318 orientation.AddDefaultOption(AUTO_ORIENTATION, true); |
| 319 orientation.SaveTo(&description); |
| 320 |
| 321 ColorCapability color; |
| 322 color.AddDefaultOption(Color(STANDARD_COLOR), true); |
| 323 color.SaveTo(&description); |
| 324 |
| 325 static const cloud_devices::printer::MediaType kPdfMedia[] = { |
| 326 ISO_A4, |
| 327 ISO_A3, |
| 328 NA_LETTER, |
| 329 NA_LEGAL, |
| 330 NA_LEDGER |
| 331 }; |
| 332 const gfx::Size default_media_size = GetDefaultPdfMediaSizeMicrons(); |
| 333 Media default_media( |
| 334 "", default_media_size.width(), default_media_size.height()); |
| 335 if (!default_media.MatchBySize() || |
| 336 std::find(kPdfMedia, |
| 337 kPdfMedia + arraysize(kPdfMedia), |
| 338 default_media.type) == kPdfMedia + arraysize(kPdfMedia)) { |
| 339 default_media = Media(locale == "en-US" ? NA_LETTER : ISO_A4); |
| 340 } |
| 341 MediaCapability media; |
| 342 for (size_t i = 0; i < arraysize(kPdfMedia); ++i) { |
| 343 Media media_option(kPdfMedia[i]); |
| 344 media.AddDefaultOption(media_option, |
| 345 default_media.type == media_option.type); |
| 346 } |
| 347 media.SaveTo(&description); |
| 348 |
| 349 return scoped_ptr<base::DictionaryValue>(description.root().DeepCopy()); |
| 350 } |
| 351 |
| 352 void EnumeratePrintersOnFileThread(base::ListValue* printers) { |
| 353 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 354 |
| 355 scoped_refptr<printing::PrintBackend> print_backend( |
| 356 printing::PrintBackend::CreateInstance(NULL)); |
| 357 |
| 284 VLOG(1) << "Enumerate printers start"; | 358 VLOG(1) << "Enumerate printers start"; |
| 285 printing::PrinterList printer_list; | 359 printing::PrinterList printer_list; |
| 286 print_backend->EnumeratePrinters(&printer_list); | 360 print_backend->EnumeratePrinters(&printer_list); |
| 287 | 361 |
| 288 for (printing::PrinterList::iterator it = printer_list.begin(); | 362 for (printing::PrinterList::iterator it = printer_list.begin(); |
| 289 it != printer_list.end(); ++it) { | 363 it != printer_list.end(); ++it) { |
| 290 base::DictionaryValue* printer_info = new base::DictionaryValue; | 364 base::DictionaryValue* printer_info = new base::DictionaryValue; |
| 291 printers->Append(printer_info); | 365 printers->Append(printer_info); |
| 292 std::string printer_name; | 366 std::string printer_name; |
| 293 std::string printer_description; | 367 std::string printer_description; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 322 VLOG(1) << "Enumerate printers finished, found " << printers->GetSize() | 396 VLOG(1) << "Enumerate printers finished, found " << printers->GetSize() |
| 323 << " printers"; | 397 << " printers"; |
| 324 } | 398 } |
| 325 | 399 |
| 326 typedef base::Callback<void(const base::DictionaryValue*)> | 400 typedef base::Callback<void(const base::DictionaryValue*)> |
| 327 GetPrinterCapabilitiesSuccessCallback; | 401 GetPrinterCapabilitiesSuccessCallback; |
| 328 typedef base::Callback<void(const std::string&)> | 402 typedef base::Callback<void(const std::string&)> |
| 329 GetPrinterCapabilitiesFailureCallback; | 403 GetPrinterCapabilitiesFailureCallback; |
| 330 | 404 |
| 331 void GetPrinterCapabilitiesOnFileThread( | 405 void GetPrinterCapabilitiesOnFileThread( |
| 332 scoped_refptr<printing::PrintBackend> print_backend, | |
| 333 const std::string& printer_name, | 406 const std::string& printer_name, |
| 407 const std::string& locale, |
| 334 const GetPrinterCapabilitiesSuccessCallback& success_cb, | 408 const GetPrinterCapabilitiesSuccessCallback& success_cb, |
| 335 const GetPrinterCapabilitiesFailureCallback& failure_cb) { | 409 const GetPrinterCapabilitiesFailureCallback& failure_cb) { |
| 336 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 410 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 337 DCHECK(!printer_name.empty()); | 411 DCHECK(!printer_name.empty()); |
| 338 | 412 |
| 413 // Special case for PDF printer. |
| 414 if (printer_name == kLocalPdfPrinterId) { |
| 415 scoped_ptr<base::DictionaryValue> printer_info(new base::DictionaryValue); |
| 416 printer_info->SetString(kPrinterId, printer_name); |
| 417 printer_info->Set(kPrinterCapabilities, |
| 418 GetPdfCapabilitiesOnFileThread(locale).release()); |
| 419 BrowserThread::PostTask( |
| 420 BrowserThread::UI, FROM_HERE, |
| 421 base::Bind(success_cb, base::Owned(printer_info.release()))); |
| 422 return; |
| 423 } |
| 424 |
| 425 scoped_refptr<printing::PrintBackend> print_backend( |
| 426 printing::PrintBackend::CreateInstance(NULL)); |
| 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 11 matching lines...) Expand all Loading... |
| 360 settings_info->SetString(kPrinterId, printer_name); | 449 settings_info->SetString(kPrinterId, printer_name); |
| 361 settings_info->SetBoolean(kDisableColorOption, !info.color_changeable); | 450 settings_info->SetBoolean(kDisableColorOption, !info.color_changeable); |
| 362 settings_info->SetBoolean(printing::kSettingSetColorAsDefault, | 451 settings_info->SetBoolean(printing::kSettingSetColorAsDefault, |
| 363 info.color_default); | 452 info.color_default); |
| 364 #if defined(USE_CUPS) | 453 #if defined(USE_CUPS) |
| 365 settings_info->SetInteger(kCUPSsColorModel, info.color_model); | 454 settings_info->SetInteger(kCUPSsColorModel, info.color_model); |
| 366 settings_info->SetInteger(kCUPSsBWModel, info.bw_model); | 455 settings_info->SetInteger(kCUPSsBWModel, info.bw_model); |
| 367 #endif | 456 #endif |
| 368 | 457 |
| 369 // TODO(gene): Make new capabilities format for Print Preview | 458 // TODO(gene): Make new capabilities format for Print Preview |
| 370 // that will suit semantic capabiltities better. | 459 // that will suit semantic capabilities better. |
| 371 // Refactor pld API code below | 460 // Refactor pld API code below |
| 372 bool default_duplex = info.duplex_capable ? | 461 bool default_duplex = info.duplex_capable ? |
| 373 (info.duplex_default != printing::SIMPLEX) : false; | 462 (info.duplex_default != printing::SIMPLEX) : false; |
| 374 int duplex_value = info.duplex_capable ? | 463 int duplex_value = info.duplex_capable ? |
| 375 printing::LONG_EDGE : printing::UNKNOWN_DUPLEX_MODE; | 464 printing::LONG_EDGE : printing::UNKNOWN_DUPLEX_MODE; |
| 376 settings_info->SetBoolean(kSetDuplexAsDefault, default_duplex); | 465 settings_info->SetBoolean(kSetDuplexAsDefault, default_duplex); |
| 377 settings_info->SetInteger(kPrinterDefaultDuplexValue, duplex_value); | 466 settings_info->SetInteger(kPrinterDefaultDuplexValue, duplex_value); |
| 378 | 467 |
| 379 BrowserThread::PostTask( | 468 BrowserThread::PostTask( |
| 380 BrowserThread::UI, FROM_HERE, | 469 BrowserThread::UI, FROM_HERE, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 | 557 |
| 469 typedef std::map<std::string, | 558 typedef std::map<std::string, |
| 470 linked_ptr<OAuth2TokenService::Request> > Requests; | 559 linked_ptr<OAuth2TokenService::Request> > Requests; |
| 471 Requests requests_; | 560 Requests requests_; |
| 472 PrintPreviewHandler* handler_; | 561 PrintPreviewHandler* handler_; |
| 473 | 562 |
| 474 DISALLOW_COPY_AND_ASSIGN(AccessTokenService); | 563 DISALLOW_COPY_AND_ASSIGN(AccessTokenService); |
| 475 }; | 564 }; |
| 476 | 565 |
| 477 PrintPreviewHandler::PrintPreviewHandler() | 566 PrintPreviewHandler::PrintPreviewHandler() |
| 478 : print_backend_(printing::PrintBackend::CreateInstance(NULL)), | 567 : regenerate_preview_request_count_(0), |
| 479 regenerate_preview_request_count_(0), | |
| 480 manage_printers_dialog_request_count_(0), | 568 manage_printers_dialog_request_count_(0), |
| 481 manage_cloud_printers_dialog_request_count_(0), | 569 manage_cloud_printers_dialog_request_count_(0), |
| 482 reported_failed_preview_(false), | 570 reported_failed_preview_(false), |
| 483 has_logged_printers_count_(false), | 571 has_logged_printers_count_(false), |
| 484 weak_factory_(this) { | 572 weak_factory_(this) { |
| 485 ReportUserActionHistogram(PREVIEW_STARTED); | 573 ReportUserActionHistogram(PREVIEW_STARTED); |
| 486 } | 574 } |
| 487 | 575 |
| 488 PrintPreviewHandler::~PrintPreviewHandler() { | 576 PrintPreviewHandler::~PrintPreviewHandler() { |
| 489 if (select_file_dialog_.get()) | 577 if (select_file_dialog_.get()) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 } | 651 } |
| 564 | 652 |
| 565 WebContents* PrintPreviewHandler::preview_web_contents() const { | 653 WebContents* PrintPreviewHandler::preview_web_contents() const { |
| 566 return web_ui()->GetWebContents(); | 654 return web_ui()->GetWebContents(); |
| 567 } | 655 } |
| 568 | 656 |
| 569 void PrintPreviewHandler::HandleGetPrinters(const base::ListValue* /*args*/) { | 657 void PrintPreviewHandler::HandleGetPrinters(const base::ListValue* /*args*/) { |
| 570 base::ListValue* results = new base::ListValue; | 658 base::ListValue* results = new base::ListValue; |
| 571 BrowserThread::PostTaskAndReply( | 659 BrowserThread::PostTaskAndReply( |
| 572 BrowserThread::FILE, FROM_HERE, | 660 BrowserThread::FILE, FROM_HERE, |
| 573 base::Bind(&EnumeratePrintersOnFileThread, print_backend_, | 661 base::Bind(&EnumeratePrintersOnFileThread, |
| 574 base::Unretained(results)), | 662 base::Unretained(results)), |
| 575 base::Bind(&PrintPreviewHandler::SetupPrinterList, | 663 base::Bind(&PrintPreviewHandler::SetupPrinterList, |
| 576 weak_factory_.GetWeakPtr(), | 664 weak_factory_.GetWeakPtr(), |
| 577 base::Owned(results))); | 665 base::Owned(results))); |
| 578 } | 666 } |
| 579 | 667 |
| 580 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { | 668 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { |
| 581 #if defined(ENABLE_SERVICE_DISCOVERY) | 669 #if defined(ENABLE_SERVICE_DISCOVERY) |
| 582 if (PrivetPrintingEnabled()) { | 670 if (PrivetPrintingEnabled()) { |
| 583 Profile* profile = Profile::FromWebUI(web_ui()); | 671 Profile* profile = Profile::FromWebUI(web_ui()); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 bool ret = args->GetString(0, &printer_name); | 967 bool ret = args->GetString(0, &printer_name); |
| 880 if (!ret || printer_name.empty()) | 968 if (!ret || printer_name.empty()) |
| 881 return; | 969 return; |
| 882 | 970 |
| 883 GetPrinterCapabilitiesSuccessCallback success_cb = | 971 GetPrinterCapabilitiesSuccessCallback success_cb = |
| 884 base::Bind(&PrintPreviewHandler::SendPrinterCapabilities, | 972 base::Bind(&PrintPreviewHandler::SendPrinterCapabilities, |
| 885 weak_factory_.GetWeakPtr()); | 973 weak_factory_.GetWeakPtr()); |
| 886 GetPrinterCapabilitiesFailureCallback failure_cb = | 974 GetPrinterCapabilitiesFailureCallback failure_cb = |
| 887 base::Bind(&PrintPreviewHandler::SendFailedToGetPrinterCapabilities, | 975 base::Bind(&PrintPreviewHandler::SendFailedToGetPrinterCapabilities, |
| 888 weak_factory_.GetWeakPtr()); | 976 weak_factory_.GetWeakPtr()); |
| 889 BrowserThread::PostTask( | 977 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 890 BrowserThread::FILE, FROM_HERE, | 978 base::Bind(&GetPrinterCapabilitiesOnFileThread, |
| 891 base::Bind(&GetPrinterCapabilitiesOnFileThread, | 979 printer_name, |
| 892 print_backend_, printer_name, success_cb, failure_cb)); | 980 g_browser_process->GetApplicationLocale(), |
| 981 success_cb, failure_cb)); |
| 893 } | 982 } |
| 894 | 983 |
| 895 void PrintPreviewHandler::OnSigninComplete() { | 984 void PrintPreviewHandler::OnSigninComplete() { |
| 896 PrintPreviewUI* print_preview_ui = | 985 PrintPreviewUI* print_preview_ui = |
| 897 static_cast<PrintPreviewUI*>(web_ui()->GetController()); | 986 static_cast<PrintPreviewUI*>(web_ui()->GetController()); |
| 898 if (print_preview_ui) | 987 if (print_preview_ui) |
| 899 print_preview_ui->OnReloadPrintersList(); | 988 print_preview_ui->OnReloadPrintersList(); |
| 900 } | 989 } |
| 901 | 990 |
| 902 void PrintPreviewHandler::HandleSignin(const base::ListValue* args) { | 991 void PrintPreviewHandler::HandleSignin(const base::ListValue* args) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 settings->SetString(kNumberFormat, base::FormatDouble(123456.78, 2)); | 1123 settings->SetString(kNumberFormat, base::FormatDouble(123456.78, 2)); |
| 1035 settings->SetInteger(kMeasurementSystem, system); | 1124 settings->SetInteger(kMeasurementSystem, system); |
| 1036 } | 1125 } |
| 1037 | 1126 |
| 1038 void PrintPreviewHandler::HandleGetInitialSettings( | 1127 void PrintPreviewHandler::HandleGetInitialSettings( |
| 1039 const base::ListValue* /*args*/) { | 1128 const base::ListValue* /*args*/) { |
| 1040 // Send before SendInitialSettings to allow cloud printer auto select. | 1129 // Send before SendInitialSettings to allow cloud printer auto select. |
| 1041 SendCloudPrintEnabled(); | 1130 SendCloudPrintEnabled(); |
| 1042 BrowserThread::PostTaskAndReplyWithResult( | 1131 BrowserThread::PostTaskAndReplyWithResult( |
| 1043 BrowserThread::FILE, FROM_HERE, | 1132 BrowserThread::FILE, FROM_HERE, |
| 1044 base::Bind(&GetDefaultPrinterOnFileThread, print_backend_), | 1133 base::Bind(&GetDefaultPrinterOnFileThread), |
| 1045 base::Bind(&PrintPreviewHandler::SendInitialSettings, | 1134 base::Bind(&PrintPreviewHandler::SendInitialSettings, |
| 1046 weak_factory_.GetWeakPtr())); | 1135 weak_factory_.GetWeakPtr())); |
| 1047 } | 1136 } |
| 1048 | 1137 |
| 1049 void PrintPreviewHandler::HandleReportUiEvent(const base::ListValue* args) { | 1138 void PrintPreviewHandler::HandleReportUiEvent(const base::ListValue* args) { |
| 1050 int event_group, event_number; | 1139 int event_group, event_number; |
| 1051 if (!args->GetInteger(0, &event_group) || !args->GetInteger(1, &event_number)) | 1140 if (!args->GetInteger(0, &event_group) || !args->GetInteger(1, &event_number)) |
| 1052 return; | 1141 return; |
| 1053 | 1142 |
| 1054 enum UiBucketGroups ui_bucket_group = | 1143 enum UiBucketGroups ui_bucket_group = |
| (...skipping 511 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 |