Chromium Code Reviews| 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 <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/base64.h" | 12 #include "base/base64.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 15 #include "base/i18n/file_util_icu.h" | 15 #include "base/i18n/file_util_icu.h" |
| 16 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/i18n/number_formatting.h" | |
| 19 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 20 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 21 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
| 22 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 23 #include "base/values.h" | 24 #include "base/values.h" |
| 24 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/platform_util.h" | 26 #include "chrome/browser/platform_util.h" |
| 26 #include "chrome/browser/printing/background_printing_manager.h" | 27 #include "chrome/browser/printing/background_printing_manager.h" |
| 27 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 28 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
| 28 #include "chrome/browser/printing/print_dialog_cloud.h" | 29 #include "chrome/browser/printing/print_dialog_cloud.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 40 #include "chrome/common/chrome_paths.h" | 41 #include "chrome/common/chrome_paths.h" |
| 41 #include "chrome/common/print_messages.h" | 42 #include "chrome/common/print_messages.h" |
| 42 #include "content/browser/browser_thread.h" | 43 #include "content/browser/browser_thread.h" |
| 43 #include "content/browser/renderer_host/render_view_host.h" | 44 #include "content/browser/renderer_host/render_view_host.h" |
| 44 #include "content/browser/tab_contents/tab_contents.h" | 45 #include "content/browser/tab_contents/tab_contents.h" |
| 45 #include "printing/backend/print_backend.h" | 46 #include "printing/backend/print_backend.h" |
| 46 #include "printing/metafile.h" | 47 #include "printing/metafile.h" |
| 47 #include "printing/metafile_impl.h" | 48 #include "printing/metafile_impl.h" |
| 48 #include "printing/page_range.h" | 49 #include "printing/page_range.h" |
| 49 #include "printing/print_settings.h" | 50 #include "printing/print_settings.h" |
| 51 #include "third_party/icu/public/i18n/unicode/ulocdata.h" | |
|
Lei Zhang
2011/10/20 23:19:48
it seems other parts of the code just do: #include
dpapad
2011/10/20 23:41:28
Done.
| |
| 50 | 52 |
| 51 #if !defined(OS_CHROMEOS) | 53 #if !defined(OS_CHROMEOS) |
| 52 #include "base/command_line.h" | 54 #include "base/command_line.h" |
| 53 #include "chrome/common/chrome_switches.h" | 55 #include "chrome/common/chrome_switches.h" |
| 54 #endif | 56 #endif |
| 55 | 57 |
| 56 namespace { | 58 namespace { |
| 57 | 59 |
| 58 enum UserActionBuckets { | 60 enum UserActionBuckets { |
| 59 PRINT_TO_PRINTER, | 61 PRINT_TO_PRINTER, |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 base::Unretained(this))); | 253 base::Unretained(this))); |
| 252 web_ui_->RegisterMessageCallback("cancelPendingPrintRequest", | 254 web_ui_->RegisterMessageCallback("cancelPendingPrintRequest", |
| 253 base::Bind(&PrintPreviewHandler::HandleCancelPendingPrintRequest, | 255 base::Bind(&PrintPreviewHandler::HandleCancelPendingPrintRequest, |
| 254 base::Unretained(this))); | 256 base::Unretained(this))); |
| 255 web_ui_->RegisterMessageCallback("saveLastPrinter", | 257 web_ui_->RegisterMessageCallback("saveLastPrinter", |
| 256 base::Bind(&PrintPreviewHandler::HandleSaveLastPrinter, | 258 base::Bind(&PrintPreviewHandler::HandleSaveLastPrinter, |
| 257 base::Unretained(this))); | 259 base::Unretained(this))); |
| 258 web_ui_->RegisterMessageCallback("getInitiatorTabTitle", | 260 web_ui_->RegisterMessageCallback("getInitiatorTabTitle", |
| 259 base::Bind(&PrintPreviewHandler::HandleGetInitiatorTabTitle, | 261 base::Bind(&PrintPreviewHandler::HandleGetInitiatorTabTitle, |
| 260 base::Unretained(this))); | 262 base::Unretained(this))); |
| 263 web_ui_->RegisterMessageCallback("getNumberFormatAndMeasurementSystem", | |
| 264 base::Bind( | |
| 265 &PrintPreviewHandler::HandleGetNumberFormatAndMeasurementSystem, | |
| 266 base::Unretained(this))); | |
| 261 } | 267 } |
| 262 | 268 |
| 263 TabContentsWrapper* PrintPreviewHandler::preview_tab_wrapper() const { | 269 TabContentsWrapper* PrintPreviewHandler::preview_tab_wrapper() const { |
| 264 return TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); | 270 return TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); |
| 265 } | 271 } |
| 266 TabContents* PrintPreviewHandler::preview_tab() const { | 272 TabContents* PrintPreviewHandler::preview_tab() const { |
| 267 return web_ui_->tab_contents(); | 273 return web_ui_->tab_contents(); |
| 268 } | 274 } |
| 269 | 275 |
| 270 void PrintPreviewHandler::HandleGetDefaultPrinter(const ListValue* /*args*/) { | 276 void PrintPreviewHandler::HandleGetDefaultPrinter(const ListValue* /*args*/) { |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 manage_printers_dialog_request_count_); | 600 manage_printers_dialog_request_count_); |
| 595 } | 601 } |
| 596 | 602 |
| 597 void PrintPreviewHandler::HandleGetInitiatorTabTitle( | 603 void PrintPreviewHandler::HandleGetInitiatorTabTitle( |
| 598 const ListValue* /*args*/) { | 604 const ListValue* /*args*/) { |
| 599 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 605 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
| 600 base::StringValue tab_title(print_preview_ui->initiator_tab_title()); | 606 base::StringValue tab_title(print_preview_ui->initiator_tab_title()); |
| 601 web_ui_->CallJavascriptFunction("setInitiatorTabTitle", tab_title); | 607 web_ui_->CallJavascriptFunction("setInitiatorTabTitle", tab_title); |
| 602 } | 608 } |
| 603 | 609 |
| 610 void PrintPreviewHandler::HandleGetNumberFormatAndMeasurementSystem( | |
| 611 const ListValue* /*args*/) { | |
| 612 | |
| 613 // Getting the measurement system based on the lcoale. | |
|
Lei Zhang
2011/10/20 23:19:48
typo: lcoale => locale
dpapad
2011/10/20 23:41:28
Done.
| |
| 614 const std::string application_locale( | |
|
Lei Zhang
2011/10/20 23:19:48
unused variable?
dpapad
2011/10/20 23:41:28
Oops, forgot to remove it, done.
| |
| 615 g_browser_process->GetApplicationLocale()); | |
| 616 UErrorCode errorCode = U_ZERO_ERROR; | |
| 617 const char *locale = g_browser_process->GetApplicationLocale().c_str(); | |
| 618 UMeasurementSystem measurement_system = | |
| 619 ulocdata_getMeasurementSystem(locale, &errorCode); | |
| 620 if (errorCode > U_ZERO_ERROR || measurement_system == UMS_LIMIT) | |
|
Lei Zhang
2011/10/20 23:19:48
Change "> U_ZERO_ERROR" to !=
dpapad
2011/10/20 23:41:28
Can't do this. According to the documentation, val
| |
| 621 measurement_system = UMS_SI; | |
| 622 | |
| 623 // Getting the number formatting based on the locale. | |
| 624 StringValue number_format(base::FormatDouble(123456.78, 2)); | |
| 625 base::FundamentalValue system(measurement_system); | |
| 626 | |
| 627 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | |
| 628 print_preview_ui->CallJavascriptFunction( | |
| 629 "setNumberFormatAndMeasurementSystem", number_format, system); | |
| 630 } | |
| 631 | |
| 604 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { | 632 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { |
| 605 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 633 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
| 606 if (initiator_tab) { | 634 if (initiator_tab) { |
| 607 static_cast<RenderViewHostDelegate*>( | 635 static_cast<RenderViewHostDelegate*>( |
| 608 initiator_tab->tab_contents())->Activate(); | 636 initiator_tab->tab_contents())->Activate(); |
| 609 } | 637 } |
| 610 ClosePrintPreviewTab(); | 638 ClosePrintPreviewTab(); |
| 611 } | 639 } |
| 612 | 640 |
| 613 void PrintPreviewHandler::SendPrinterCapabilities( | 641 void PrintPreviewHandler::SendPrinterCapabilities( |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 return; | 850 return; |
| 823 | 851 |
| 824 // We no longer require the initiator tab details. Remove those details | 852 // We no longer require the initiator tab details. Remove those details |
| 825 // associated with the preview tab to allow the initiator tab to create | 853 // associated with the preview tab to allow the initiator tab to create |
| 826 // another preview tab. | 854 // another preview tab. |
| 827 printing::PrintPreviewTabController* tab_controller = | 855 printing::PrintPreviewTabController* tab_controller = |
| 828 printing::PrintPreviewTabController::GetInstance(); | 856 printing::PrintPreviewTabController::GetInstance(); |
| 829 if (tab_controller) | 857 if (tab_controller) |
| 830 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 858 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
| 831 } | 859 } |
| OLD | NEW |