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> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 #include "chrome/common/chrome_paths.h" | 43 #include "chrome/common/chrome_paths.h" |
44 #include "chrome/common/pref_names.h" | 44 #include "chrome/common/pref_names.h" |
45 #include "chrome/common/print_messages.h" | 45 #include "chrome/common/print_messages.h" |
46 #include "content/browser/renderer_host/render_view_host.h" | 46 #include "content/browser/renderer_host/render_view_host.h" |
47 #include "content/browser/tab_contents/tab_contents.h" | 47 #include "content/browser/tab_contents/tab_contents.h" |
48 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
49 #include "printing/backend/print_backend.h" | 49 #include "printing/backend/print_backend.h" |
50 #include "printing/metafile.h" | 50 #include "printing/metafile.h" |
51 #include "printing/metafile_impl.h" | 51 #include "printing/metafile_impl.h" |
52 #include "printing/page_range.h" | 52 #include "printing/page_range.h" |
53 #include "printing/page_size_margins.h" | |
53 #include "printing/print_settings.h" | 54 #include "printing/print_settings.h" |
54 #include "unicode/ulocdata.h" | 55 #include "unicode/ulocdata.h" |
55 | 56 |
56 #if !defined(OS_CHROMEOS) | 57 #if !defined(OS_CHROMEOS) |
57 #include "base/command_line.h" | 58 #include "base/command_line.h" |
58 #include "chrome/common/chrome_switches.h" | 59 #include "chrome/common/chrome_switches.h" |
59 #endif | 60 #endif |
60 | 61 |
61 using content::BrowserThread; | 62 using content::BrowserThread; |
62 | 63 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 }; | 200 }; |
200 | 201 |
201 // static | 202 // static |
202 FilePath* PrintPreviewHandler::last_saved_path_ = NULL; | 203 FilePath* PrintPreviewHandler::last_saved_path_ = NULL; |
203 std::string* PrintPreviewHandler::last_used_printer_cloud_print_data_ = NULL; | 204 std::string* PrintPreviewHandler::last_used_printer_cloud_print_data_ = NULL; |
204 std::string* PrintPreviewHandler::last_used_printer_name_ = NULL; | 205 std::string* PrintPreviewHandler::last_used_printer_name_ = NULL; |
205 printing::ColorModels PrintPreviewHandler::last_used_color_model_ = | 206 printing::ColorModels PrintPreviewHandler::last_used_color_model_ = |
206 printing::UNKNOWN_COLOR_MODEL; | 207 printing::UNKNOWN_COLOR_MODEL; |
207 printing::MarginType PrintPreviewHandler::last_used_margins_type_ = | 208 printing::MarginType PrintPreviewHandler::last_used_margins_type_ = |
208 printing::DEFAULT_MARGINS; | 209 printing::DEFAULT_MARGINS; |
210 printing::PageSizeMargins* | |
211 PrintPreviewHandler::last_used_page_size_margins_ = NULL; | |
209 | 212 |
210 PrintPreviewHandler::PrintPreviewHandler() | 213 PrintPreviewHandler::PrintPreviewHandler() |
211 : print_backend_(printing::PrintBackend::CreateInstance(NULL)), | 214 : print_backend_(printing::PrintBackend::CreateInstance(NULL)), |
212 regenerate_preview_request_count_(0), | 215 regenerate_preview_request_count_(0), |
213 manage_printers_dialog_request_count_(0), | 216 manage_printers_dialog_request_count_(0), |
214 reported_failed_preview_(false), | 217 reported_failed_preview_(false), |
215 has_logged_printers_count_(false) { | 218 has_logged_printers_count_(false) { |
216 ReportUserActionHistogram(PREVIEW_STARTED); | 219 ReportUserActionHistogram(PREVIEW_STARTED); |
217 } | 220 } |
218 | 221 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 web_ui_->RegisterMessageCallback("saveLastPrinter", | 267 web_ui_->RegisterMessageCallback("saveLastPrinter", |
265 base::Bind(&PrintPreviewHandler::HandleSaveLastPrinter, | 268 base::Bind(&PrintPreviewHandler::HandleSaveLastPrinter, |
266 base::Unretained(this))); | 269 base::Unretained(this))); |
267 web_ui_->RegisterMessageCallback("getInitiatorTabTitle", | 270 web_ui_->RegisterMessageCallback("getInitiatorTabTitle", |
268 base::Bind(&PrintPreviewHandler::HandleGetInitiatorTabTitle, | 271 base::Bind(&PrintPreviewHandler::HandleGetInitiatorTabTitle, |
269 base::Unretained(this))); | 272 base::Unretained(this))); |
270 web_ui_->RegisterMessageCallback("getNumberFormatAndMeasurementSystem", | 273 web_ui_->RegisterMessageCallback("getNumberFormatAndMeasurementSystem", |
271 base::Bind( | 274 base::Bind( |
272 &PrintPreviewHandler::HandleGetNumberFormatAndMeasurementSystem, | 275 &PrintPreviewHandler::HandleGetNumberFormatAndMeasurementSystem, |
273 base::Unretained(this))); | 276 base::Unretained(this))); |
277 web_ui_->RegisterMessageCallback("getLastUsedMarginSettings", | |
278 base::Bind(&PrintPreviewHandler::HandleGetLastUsedMarginSettings, | |
279 base::Unretained(this))); | |
274 } | 280 } |
275 | 281 |
276 TabContentsWrapper* PrintPreviewHandler::preview_tab_wrapper() const { | 282 TabContentsWrapper* PrintPreviewHandler::preview_tab_wrapper() const { |
277 return TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); | 283 return TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); |
278 } | 284 } |
279 TabContents* PrintPreviewHandler::preview_tab() const { | 285 TabContents* PrintPreviewHandler::preview_tab() const { |
280 return web_ui_->tab_contents(); | 286 return web_ui_->tab_contents(); |
281 } | 287 } |
282 | 288 |
283 void PrintPreviewHandler::HandleGetDefaultPrinter(const ListValue* /*args*/) { | 289 void PrintPreviewHandler::HandleGetDefaultPrinter(const ListValue* /*args*/) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 int color_model; | 400 int color_model; |
395 if (!settings->GetInteger(printing::kSettingColor, &color_model)) | 401 if (!settings->GetInteger(printing::kSettingColor, &color_model)) |
396 color_model = printing::GRAY; | 402 color_model = printing::GRAY; |
397 last_used_color_model_ = static_cast<printing::ColorModels>(color_model); | 403 last_used_color_model_ = static_cast<printing::ColorModels>(color_model); |
398 | 404 |
399 // Storing last used margin settings. | 405 // Storing last used margin settings. |
400 int margin_type; | 406 int margin_type; |
401 if (!settings->GetInteger(printing::kSettingMarginsType, &margin_type)) | 407 if (!settings->GetInteger(printing::kSettingMarginsType, &margin_type)) |
402 margin_type = printing::DEFAULT_MARGINS; | 408 margin_type = printing::DEFAULT_MARGINS; |
403 last_used_margins_type_ = static_cast<printing::MarginType>(margin_type); | 409 last_used_margins_type_ = static_cast<printing::MarginType>(margin_type); |
410 if (last_used_margins_type_ == printing::CUSTOM_MARGINS) { | |
411 if (!last_used_page_size_margins_) | |
412 last_used_page_size_margins_ = new printing::PageSizeMargins(); | |
413 getCustomMarginsFromJobSettings(*settings, last_used_page_size_margins_); | |
414 } | |
404 | 415 |
405 bool print_to_pdf = false; | 416 bool print_to_pdf = false; |
406 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); | 417 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); |
407 | 418 |
408 settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false); | 419 settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false); |
409 | 420 |
410 bool is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId); | 421 bool is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId); |
411 bool is_cloud_dialog = false; | 422 bool is_cloud_dialog = false; |
412 settings->GetBoolean(printing::kSettingCloudPrintDialog, &is_cloud_dialog); | 423 settings->GetBoolean(printing::kSettingCloudPrintDialog, &is_cloud_dialog); |
413 if (is_cloud_printer) { | 424 if (is_cloud_printer) { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 // Getting the number formatting based on the locale. | 645 // Getting the number formatting based on the locale. |
635 StringValue number_format(base::FormatDouble(123456.78, 2)); | 646 StringValue number_format(base::FormatDouble(123456.78, 2)); |
636 base::FundamentalValue system(measurement_system); | 647 base::FundamentalValue system(measurement_system); |
637 | 648 |
638 web_ui_->CallJavascriptFunction( | 649 web_ui_->CallJavascriptFunction( |
639 "print_preview.setNumberFormatAndMeasurementSystem", | 650 "print_preview.setNumberFormatAndMeasurementSystem", |
640 number_format, | 651 number_format, |
641 system); | 652 system); |
642 } | 653 } |
643 | 654 |
655 void PrintPreviewHandler::HandleGetLastUsedMarginSettings( | |
656 const ListValue* /*args*/) { | |
657 base::FundamentalValue margins_type( | |
658 PrintPreviewHandler::last_used_margins_type_); | |
659 if (last_used_margins_type_ == printing::CUSTOM_MARGINS) { | |
660 DCHECK(last_used_page_size_margins_); | |
dpapad
2011/11/03 18:48:27
Let me clarify a bit how the 4 margin values are u
| |
661 base::DictionaryValue page_size_margins; | |
662 page_size_margins.SetDouble(printing::kSettingMarginTop, | |
663 last_used_page_size_margins_->margin_top); | |
664 page_size_margins.SetDouble(printing::kSettingMarginBottom, | |
665 last_used_page_size_margins_->margin_bottom); | |
666 page_size_margins.SetDouble(printing::kSettingMarginLeft, | |
667 last_used_page_size_margins_->margin_left); | |
668 page_size_margins.SetDouble(printing::kSettingMarginRight, | |
669 last_used_page_size_margins_->margin_right); | |
670 web_ui_->CallJavascriptFunction("print_preview.setLastUsedMargins", | |
671 margins_type, | |
672 page_size_margins); | |
673 } else { | |
674 web_ui_->CallJavascriptFunction("print_preview.setLastUsedMargins", | |
675 margins_type); | |
676 } | |
677 } | |
678 | |
644 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { | 679 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { |
645 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 680 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
646 if (initiator_tab) { | 681 if (initiator_tab) { |
647 static_cast<RenderViewHostDelegate*>( | 682 static_cast<RenderViewHostDelegate*>( |
648 initiator_tab->tab_contents())->Activate(); | 683 initiator_tab->tab_contents())->Activate(); |
649 } | 684 } |
650 ClosePrintPreviewTab(); | 685 ClosePrintPreviewTab(); |
651 } | 686 } |
652 | 687 |
653 void PrintPreviewHandler::SendPrinterCapabilities( | 688 void PrintPreviewHandler::SendPrinterCapabilities( |
654 const DictionaryValue& settings_info) { | 689 const DictionaryValue& settings_info) { |
655 VLOG(1) << "Get printer capabilities finished"; | 690 VLOG(1) << "Get printer capabilities finished"; |
656 web_ui_->CallJavascriptFunction("updateWithPrinterCapabilities", | 691 web_ui_->CallJavascriptFunction("updateWithPrinterCapabilities", |
657 settings_info); | 692 settings_info); |
658 } | 693 } |
659 | 694 |
660 void PrintPreviewHandler::SendDefaultPrinter( | 695 void PrintPreviewHandler::SendDefaultPrinter( |
661 const StringValue& default_printer, | 696 const StringValue& default_printer, |
662 const StringValue& cloud_print_data) { | 697 const StringValue& cloud_print_data) { |
663 base::FundamentalValue margins_type( | 698 web_ui_->CallJavascriptFunction( |
664 PrintPreviewHandler::last_used_margins_type_); | 699 "setDefaultPrinter", default_printer, cloud_print_data); |
665 web_ui_->CallJavascriptFunction("setDefaultPrinter", | |
666 default_printer, | |
667 cloud_print_data, | |
668 margins_type); | |
669 } | 700 } |
670 | 701 |
671 void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) { | 702 void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) { |
672 SendCloudPrintEnabled(); | 703 SendCloudPrintEnabled(); |
673 web_ui_->CallJavascriptFunction("setPrinters", printers); | 704 web_ui_->CallJavascriptFunction("setPrinters", printers); |
674 } | 705 } |
675 | 706 |
676 void PrintPreviewHandler::SendCloudPrintEnabled() { | 707 void PrintPreviewHandler::SendCloudPrintEnabled() { |
677 Profile* profile = BrowserList::GetLastActive()->profile(); | 708 Profile* profile = BrowserList::GetLastActive()->profile(); |
678 PrefService* prefs = profile->GetPrefs(); | 709 PrefService* prefs = profile->GetPrefs(); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 return; | 899 return; |
869 | 900 |
870 // We no longer require the initiator tab details. Remove those details | 901 // We no longer require the initiator tab details. Remove those details |
871 // associated with the preview tab to allow the initiator tab to create | 902 // associated with the preview tab to allow the initiator tab to create |
872 // another preview tab. | 903 // another preview tab. |
873 printing::PrintPreviewTabController* tab_controller = | 904 printing::PrintPreviewTabController* tab_controller = |
874 printing::PrintPreviewTabController::GetInstance(); | 905 printing::PrintPreviewTabController::GetInstance(); |
875 if (tab_controller) | 906 if (tab_controller) |
876 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 907 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
877 } | 908 } |
OLD | NEW |