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 "unicode/ulocdata.h" | |
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*/) { | |
Evan Stade
2011/10/21 01:33:02
why is args commented out?
Evan Stade
2011/10/21 01:33:33
(ignore)
| |
612 | |
613 // Getting the measurement system based on the locale. | |
614 UErrorCode errorCode = U_ZERO_ERROR; | |
615 const char *locale = g_browser_process->GetApplicationLocale().c_str(); | |
Evan Stade
2011/10/21 01:33:02
asterisk on left
dpapad
2011/10/21 16:12:48
Done.
| |
616 UMeasurementSystem measurement_system = | |
617 ulocdata_getMeasurementSystem(locale, &errorCode); | |
618 if (errorCode > U_ZERO_ERROR || measurement_system == UMS_LIMIT) | |
619 measurement_system = UMS_SI; | |
620 | |
621 // Getting the number formatting based on the locale. | |
622 StringValue number_format(base::FormatDouble(123456.78, 2)); | |
623 base::FundamentalValue system(measurement_system); | |
624 | |
625 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | |
Evan Stade
2011/10/21 01:33:02
what is this
Lei Zhang
2011/10/21 01:40:46
Not needed, just call web_ui_->CallJavascriptFunct
dpapad
2011/10/21 16:12:48
Done. Initially I was planning to add a new method
| |
626 print_preview_ui->CallJavascriptFunction( | |
627 "setNumberFormatAndMeasurementSystem", number_format, system); | |
628 } | |
629 | |
604 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { | 630 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { |
605 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 631 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
606 if (initiator_tab) { | 632 if (initiator_tab) { |
607 static_cast<RenderViewHostDelegate*>( | 633 static_cast<RenderViewHostDelegate*>( |
608 initiator_tab->tab_contents())->Activate(); | 634 initiator_tab->tab_contents())->Activate(); |
609 } | 635 } |
610 ClosePrintPreviewTab(); | 636 ClosePrintPreviewTab(); |
611 } | 637 } |
612 | 638 |
613 void PrintPreviewHandler::SendPrinterCapabilities( | 639 void PrintPreviewHandler::SendPrinterCapabilities( |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
822 return; | 848 return; |
823 | 849 |
824 // We no longer require the initiator tab details. Remove those details | 850 // We no longer require the initiator tab details. Remove those details |
825 // associated with the preview tab to allow the initiator tab to create | 851 // associated with the preview tab to allow the initiator tab to create |
826 // another preview tab. | 852 // another preview tab. |
827 printing::PrintPreviewTabController* tab_controller = | 853 printing::PrintPreviewTabController* tab_controller = |
828 printing::PrintPreviewTabController::GetInstance(); | 854 printing::PrintPreviewTabController::GetInstance(); |
829 if (tab_controller) | 855 if (tab_controller) |
830 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 856 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
831 } | 857 } |
OLD | NEW |