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/printing/printing_message_filter.h" | 5 #include "chrome/browser/printing/printing_message_filter.h" |
| 6 | 6 |
| 7 #include "base/i18n/time_formatting.h" | |
| 7 #include "base/process_util.h" | 8 #include "base/process_util.h" |
| 9 #include "base/string_number_conversions.h" | |
| 10 #include "base/time.h" | |
| 11 #include "base/utf_string_conversions.h" | |
| 8 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/printing/printer_query.h" | 13 #include "chrome/browser/printing/printer_query.h" |
| 10 #include "chrome/browser/printing/print_job_manager.h" | 14 #include "chrome/browser/printing/print_job_manager.h" |
| 11 #include "chrome/common/print_messages.h" | 15 #include "chrome/common/print_messages.h" |
| 12 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
| 17 #include "printing/print_job_constants.h" | |
| 18 #include "printing/units.h" | |
| 19 #include "ui/base/text/text_elider.h" | |
| 13 | 20 |
| 14 #if defined(OS_CHROMEOS) | 21 #if defined(OS_CHROMEOS) |
| 15 #include <fcntl.h> | 22 #include <fcntl.h> |
| 16 | 23 |
| 17 #include "base/file_util.h" | 24 #include "base/file_util.h" |
| 18 #include "base/lazy_instance.h" | 25 #include "base/lazy_instance.h" |
| 19 #include "chrome/browser/printing/print_dialog_cloud.h" | 26 #include "chrome/browser/printing/print_dialog_cloud.h" |
| 20 #else | 27 #else |
| 21 #include "base/command_line.h" | 28 #include "base/command_line.h" |
| 22 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 23 #endif | 30 #endif |
| 24 | 31 |
| 32 using base::Time; | |
| 33 using printing::ConvertPointsToPixelDouble; | |
| 34 using printing::ConvertUnitDouble; | |
| 35 using printing::GetSegmentWidth; | |
| 36 using printing::GetDPI; | |
| 37 | |
| 25 namespace { | 38 namespace { |
| 26 | 39 |
| 27 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
| 28 typedef std::map<int, FilePath> SequenceToPathMap; | 41 typedef std::map<int, FilePath> SequenceToPathMap; |
| 29 | 42 |
| 30 struct PrintingSequencePathMap { | 43 struct PrintingSequencePathMap { |
| 31 SequenceToPathMap map; | 44 SequenceToPathMap map; |
| 32 int sequence; | 45 int sequence; |
| 33 }; | 46 }; |
| 34 | 47 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 } else { | 281 } else { |
| 269 printer_query->StopWorker(); | 282 printer_query->StopWorker(); |
| 270 } | 283 } |
| 271 } | 284 } |
| 272 | 285 |
| 273 void PrintingMessageFilter::OnUpdatePrintSettings( | 286 void PrintingMessageFilter::OnUpdatePrintSettings( |
| 274 int document_cookie, const DictionaryValue& job_settings, | 287 int document_cookie, const DictionaryValue& job_settings, |
| 275 IPC::Message* reply_msg) { | 288 IPC::Message* reply_msg) { |
| 276 scoped_refptr<printing::PrinterQuery> printer_query; | 289 scoped_refptr<printing::PrinterQuery> printer_query; |
| 277 print_job_manager_->PopPrinterQuery(document_cookie, &printer_query); | 290 print_job_manager_->PopPrinterQuery(document_cookie, &printer_query); |
| 291 | |
| 292 // Getting Header and Footer settings. | |
| 293 if (!job_settings.GetBoolean(printing::kSettingHeaderFooterEnabled, | |
| 294 &display_header_footer_)) { | |
| 295 NOTREACHED(); | |
| 296 } | |
| 297 | |
| 298 if (display_header_footer_) { | |
| 299 string16 title; | |
| 300 std::string url; | |
| 301 if (!job_settings.GetString(printing::kSettingHeaderFooterTitle, &title) || | |
| 302 !job_settings.GetString(printing::kSettingHeaderFooterURL, &url)) { | |
| 303 NOTREACHED(); | |
| 304 } | |
| 305 header_footer_info_.reset(new DictionaryValue()); | |
| 306 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, url); | |
| 307 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, title); | |
| 308 } | |
| 309 | |
| 278 if (printer_query.get()) { | 310 if (printer_query.get()) { |
| 279 CancelableTask* task = NewRunnableMethod( | 311 CancelableTask* task = NewRunnableMethod( |
| 280 this, | 312 this, |
| 281 &PrintingMessageFilter::OnUpdatePrintSettingsReply, | 313 &PrintingMessageFilter::OnUpdatePrintSettingsReply, |
| 282 printer_query, | 314 printer_query, |
| 283 reply_msg); | 315 reply_msg); |
| 284 printer_query->SetSettings(job_settings, task); | 316 printer_query->SetSettings(job_settings, task); |
| 285 } | 317 } |
| 286 } | 318 } |
| 287 | 319 |
| 320 void UpdateHeaderFooterStrings(const base::DictionaryValue& header_footer_info, | |
|
vandebo (ex-Chrome)
2011/08/11 23:32:13
What process adds the strings to params? Can the
Aayush Kumar
2011/08/12 08:35:40
As discussed, this is the browser process. :)
| |
| 321 PrintMsg_PrintPages_Params* params) { | |
| 322 string16 date = base::TimeFormatShortDateNumeric(Time::Now()); | |
| 323 string16 title; | |
| 324 std::string url; | |
| 325 if (!header_footer_info.GetString(printing::kSettingHeaderFooterTitle, | |
| 326 &title) || | |
| 327 !header_footer_info.GetString(printing::kSettingHeaderFooterURL, | |
| 328 &url)) { | |
| 329 NOTREACHED(); | |
| 330 } | |
| 331 | |
| 332 gfx::Font font(UTF8ToUTF16(printing::kSettingHeaderFooterFontName), | |
| 333 ceil(ConvertPointsToPixelDouble( | |
| 334 printing::kSettingHeaderFooterFontSize))); | |
| 335 double segment_width = GetSegmentWidth(ConvertUnitDouble( | |
| 336 params->params.page_size.width(), GetDPI(¶ms->params), | |
| 337 printing::kPixelsPerInch)); | |
| 338 params->params.date = ui::ElideText(date, font, segment_width, false); | |
| 339 | |
| 340 // Calculate the available title width. If the date string is not long | |
| 341 // enough, increase the available space for the title. | |
| 342 // Assumes there is no header text to RIGHT of title. | |
| 343 double date_width = font.GetStringWidth(date); | |
| 344 SkScalar max_title_width = std::min(2 * segment_width, | |
| 345 2 * (segment_width - date_width) + | |
| 346 segment_width); | |
| 347 params->params.title = ui::ElideText(title, font, max_title_width, false); | |
| 348 | |
| 349 double max_url_width = 2 * segment_width; | |
| 350 GURL gurl(url); | |
| 351 params->params.url = ui::ElideUrl(gurl, font, max_url_width, std::string()); | |
| 352 } | |
| 353 | |
| 288 void PrintingMessageFilter::OnUpdatePrintSettingsReply( | 354 void PrintingMessageFilter::OnUpdatePrintSettingsReply( |
| 289 scoped_refptr<printing::PrinterQuery> printer_query, | 355 scoped_refptr<printing::PrinterQuery> printer_query, |
| 290 IPC::Message* reply_msg) { | 356 IPC::Message* reply_msg) { |
| 291 PrintMsg_PrintPages_Params params; | 357 PrintMsg_PrintPages_Params params; |
| 292 if (printer_query->last_status() != printing::PrintingContext::OK) { | 358 if (printer_query->last_status() != printing::PrintingContext::OK) { |
| 293 memset(¶ms, 0, sizeof(params)); | 359 memset(¶ms, 0, sizeof(params)); |
| 294 } else { | 360 } else { |
| 295 RenderParamsFromPrintSettings(printer_query->settings(), ¶ms.params); | 361 RenderParamsFromPrintSettings(printer_query->settings(), ¶ms.params); |
| 296 params.params.document_cookie = printer_query->cookie(); | 362 params.params.document_cookie = printer_query->cookie(); |
| 297 params.pages = | 363 params.pages = |
| 298 printing::PageRange::GetPages(printer_query->settings().ranges); | 364 printing::PageRange::GetPages(printer_query->settings().ranges); |
| 365 | |
| 366 if (display_header_footer_) | |
| 367 UpdateHeaderFooterStrings(*header_footer_info_, ¶ms); | |
| 299 } | 368 } |
| 300 PrintHostMsg_UpdatePrintSettings::WriteReplyParams(reply_msg, params); | 369 PrintHostMsg_UpdatePrintSettings::WriteReplyParams(reply_msg, params); |
| 301 Send(reply_msg); | 370 Send(reply_msg); |
| 302 // If user hasn't cancelled. | 371 // If user hasn't cancelled. |
| 303 if (printer_query->cookie() && printer_query->settings().dpi()) | 372 if (printer_query->cookie() && printer_query->settings().dpi()) |
| 304 print_job_manager_->QueuePrinterQuery(printer_query.get()); | 373 print_job_manager_->QueuePrinterQuery(printer_query.get()); |
| 305 else | 374 else |
| 306 printer_query->StopWorker(); | 375 printer_query->StopWorker(); |
| 307 } | 376 } |
| OLD | NEW |