Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: chrome/browser/ui/webui/print_preview_handler.cc

Issue 8351048: Print Preview: Making margin selection sticky (part 2/2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanups Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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
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 last_used_page_size_margins_ = new printing::PageSizeMargins();
kmadhusu 2011/11/02 20:40:05 where do you release this object?
dpapad 2011/11/02 21:33:57 This object is never realeased (it is an intention
kmadhusu 2011/11/02 23:46:16 (repeating our conversation): Instantiate once and
dpapad 2011/11/03 00:15:27 Done. This was meant to use "new" only once. Good
412 extractPageSizeMargins(*settings, last_used_page_size_margins_);
413 }
404 414
405 bool print_to_pdf = false; 415 bool print_to_pdf = false;
406 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); 416 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf);
407 417
408 settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false); 418 settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false);
409 419
410 bool is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId); 420 bool is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId);
411 bool is_cloud_dialog = false; 421 bool is_cloud_dialog = false;
412 settings->GetBoolean(printing::kSettingCloudPrintDialog, &is_cloud_dialog); 422 settings->GetBoolean(printing::kSettingCloudPrintDialog, &is_cloud_dialog);
413 if (is_cloud_printer) { 423 if (is_cloud_printer) {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 // Getting the number formatting based on the locale. 644 // Getting the number formatting based on the locale.
635 StringValue number_format(base::FormatDouble(123456.78, 2)); 645 StringValue number_format(base::FormatDouble(123456.78, 2));
636 base::FundamentalValue system(measurement_system); 646 base::FundamentalValue system(measurement_system);
637 647
638 web_ui_->CallJavascriptFunction( 648 web_ui_->CallJavascriptFunction(
639 "print_preview.setNumberFormatAndMeasurementSystem", 649 "print_preview.setNumberFormatAndMeasurementSystem",
640 number_format, 650 number_format,
641 system); 651 system);
642 } 652 }
643 653
654 void PrintPreviewHandler::HandleGetLastUsedMarginSettings(
655 const ListValue* /*args*/) {
656 base::FundamentalValue margins_type(
657 PrintPreviewHandler::last_used_margins_type_);
658 if (last_used_page_size_margins_ != NULL) {
kmadhusu 2011/11/02 20:40:05 nit: if (last_used_page_size_margins_) { }
dpapad 2011/11/02 21:33:57 Done.
659 base::DictionaryValue page_size_margins;
660 page_size_margins.SetDouble(printing::kSettingMarginTop,
661 last_used_page_size_margins_->margin_top);
662 page_size_margins.SetDouble(printing::kSettingMarginBottom,
663 last_used_page_size_margins_->margin_bottom);
664 page_size_margins.SetDouble(printing::kSettingMarginLeft,
665 last_used_page_size_margins_->margin_left);
666 page_size_margins.SetDouble(printing::kSettingMarginRight,
667 last_used_page_size_margins_->margin_right);
668 web_ui_->CallJavascriptFunction("print_preview.setLastUsedMargins",
669 margins_type,
670 page_size_margins);
671 } else {
672 web_ui_->CallJavascriptFunction("print_preview.setLastUsedMargins",
673 margins_type);
674 }
675 }
676
644 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { 677 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() {
645 TabContentsWrapper* initiator_tab = GetInitiatorTab(); 678 TabContentsWrapper* initiator_tab = GetInitiatorTab();
646 if (initiator_tab) { 679 if (initiator_tab) {
647 static_cast<RenderViewHostDelegate*>( 680 static_cast<RenderViewHostDelegate*>(
648 initiator_tab->tab_contents())->Activate(); 681 initiator_tab->tab_contents())->Activate();
649 } 682 }
650 ClosePrintPreviewTab(); 683 ClosePrintPreviewTab();
651 } 684 }
652 685
653 void PrintPreviewHandler::SendPrinterCapabilities( 686 void PrintPreviewHandler::SendPrinterCapabilities(
654 const DictionaryValue& settings_info) { 687 const DictionaryValue& settings_info) {
655 VLOG(1) << "Get printer capabilities finished"; 688 VLOG(1) << "Get printer capabilities finished";
656 web_ui_->CallJavascriptFunction("updateWithPrinterCapabilities", 689 web_ui_->CallJavascriptFunction("updateWithPrinterCapabilities",
657 settings_info); 690 settings_info);
658 } 691 }
659 692
660 void PrintPreviewHandler::SendDefaultPrinter( 693 void PrintPreviewHandler::SendDefaultPrinter(
661 const StringValue& default_printer, 694 const StringValue& default_printer,
662 const StringValue& cloud_print_data) { 695 const StringValue& cloud_print_data) {
663 base::FundamentalValue margins_type( 696 web_ui_->CallJavascriptFunction(
664 PrintPreviewHandler::last_used_margins_type_); 697 "setDefaultPrinter", default_printer, cloud_print_data);
665 web_ui_->CallJavascriptFunction("setDefaultPrinter",
666 default_printer,
667 cloud_print_data,
668 margins_type);
669 } 698 }
670 699
671 void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) { 700 void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) {
672 SendCloudPrintEnabled(); 701 SendCloudPrintEnabled();
673 web_ui_->CallJavascriptFunction("setPrinters", printers); 702 web_ui_->CallJavascriptFunction("setPrinters", printers);
674 } 703 }
675 704
676 void PrintPreviewHandler::SendCloudPrintEnabled() { 705 void PrintPreviewHandler::SendCloudPrintEnabled() {
677 Profile* profile = BrowserList::GetLastActive()->profile(); 706 Profile* profile = BrowserList::GetLastActive()->profile();
678 PrefService* prefs = profile->GetPrefs(); 707 PrefService* prefs = profile->GetPrefs();
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 return; 897 return;
869 898
870 // We no longer require the initiator tab details. Remove those details 899 // We no longer require the initiator tab details. Remove those details
871 // associated with the preview tab to allow the initiator tab to create 900 // associated with the preview tab to allow the initiator tab to create
872 // another preview tab. 901 // another preview tab.
873 printing::PrintPreviewTabController* tab_controller = 902 printing::PrintPreviewTabController* tab_controller =
874 printing::PrintPreviewTabController::GetInstance(); 903 printing::PrintPreviewTabController::GetInstance();
875 if (tab_controller) 904 if (tab_controller)
876 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); 905 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper());
877 } 906 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698