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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #if !defined(OS_CHROMEOS) | 10 #if !defined(OS_CHROMEOS) |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #endif | 12 #endif |
13 #include "base/i18n/file_util_icu.h" | 13 #include "base/i18n/file_util_icu.h" |
14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/string_number_conversions.h" |
18 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
19 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
20 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
21 #include "base/values.h" | 22 #include "base/values.h" |
22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/platform_util.h" | 24 #include "chrome/browser/platform_util.h" |
24 #include "chrome/browser/printing/background_printing_manager.h" | 25 #include "chrome/browser/printing/background_printing_manager.h" |
25 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 26 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
26 #include "chrome/browser/printing/printer_manager_dialog.h" | 27 #include "chrome/browser/printing/printer_manager_dialog.h" |
27 #include "chrome/browser/printing/print_preview_tab_controller.h" | 28 #include "chrome/browser/printing/print_preview_tab_controller.h" |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 has_logged_printers_count_); | 470 has_logged_printers_count_); |
470 has_logged_printers_count_ = true; | 471 has_logged_printers_count_ = true; |
471 | 472 |
472 BrowserThread::PostTask( | 473 BrowserThread::PostTask( |
473 BrowserThread::FILE, FROM_HERE, | 474 BrowserThread::FILE, FROM_HERE, |
474 NewRunnableMethod(task.get(), | 475 NewRunnableMethod(task.get(), |
475 &PrintSystemTaskProxy::EnumeratePrinters)); | 476 &PrintSystemTaskProxy::EnumeratePrinters)); |
476 } | 477 } |
477 | 478 |
478 void PrintPreviewHandler::HandleGetPreview(const ListValue* args) { | 479 void PrintPreviewHandler::HandleGetPreview(const ListValue* args) { |
| 480 DCHECK(args->GetSize() == 3); |
479 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); | 481 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); |
480 if (!settings.get()) | 482 if (!settings.get()) |
481 return; | 483 return; |
482 int request_id = -1; | 484 int request_id = -1; |
483 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) | 485 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) |
484 return; | 486 return; |
485 | 487 |
486 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 488 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
487 print_preview_ui->OnPrintPreviewRequest(request_id); | 489 print_preview_ui->OnPrintPreviewRequest(request_id); |
488 // Add an additional key in order to identify |print_preview_ui| later on | 490 // Add an additional key in order to identify |print_preview_ui| later on |
(...skipping 22 matching lines...) Expand all Loading... |
511 if (display_header_footer) { | 513 if (display_header_footer) { |
512 settings->SetString(printing::kSettingHeaderFooterTitle, | 514 settings->SetString(printing::kSettingHeaderFooterTitle, |
513 initiator_tab->GetTitle()); | 515 initiator_tab->GetTitle()); |
514 std::string url; | 516 std::string url; |
515 NavigationEntry* entry = initiator_tab->controller().GetActiveEntry(); | 517 NavigationEntry* entry = initiator_tab->controller().GetActiveEntry(); |
516 if (entry) | 518 if (entry) |
517 url = entry->virtual_url().spec(); | 519 url = entry->virtual_url().spec(); |
518 settings->SetString(printing::kSettingHeaderFooterURL, url); | 520 settings->SetString(printing::kSettingHeaderFooterURL, url); |
519 } | 521 } |
520 | 522 |
| 523 bool generate_draft_data = false; |
| 524 if (!settings->GetBoolean(printing::kSettingGenerateDraftData, |
| 525 &generate_draft_data)) { |
| 526 NOTREACHED(); |
| 527 } |
| 528 |
| 529 if (!generate_draft_data) { |
| 530 int draft_page_count = -1; |
| 531 bool preview_modifiable = false; |
| 532 std::string draft_page_count_str; |
| 533 if (!args->GetString(1, &draft_page_count_str) || |
| 534 !base::StringToInt(draft_page_count_str, &draft_page_count)) { |
| 535 NOTREACHED(); |
| 536 draft_page_count = -1; |
| 537 } |
| 538 |
| 539 if (!args->GetBoolean(2, &preview_modifiable)) |
| 540 NOTREACHED(); |
| 541 |
| 542 if (draft_page_count != -1 && preview_modifiable && |
| 543 print_preview_ui->GetAvailableDraftPageCount() != draft_page_count) { |
| 544 settings->SetBoolean(printing::kSettingGenerateDraftData, true); |
| 545 } |
| 546 } |
| 547 |
521 VLOG(1) << "Print preview request start"; | 548 VLOG(1) << "Print preview request start"; |
522 RenderViewHost* rvh = initiator_tab->render_view_host(); | 549 RenderViewHost* rvh = initiator_tab->render_view_host(); |
523 rvh->Send(new PrintMsg_PrintPreview(rvh->routing_id(), *settings)); | 550 rvh->Send(new PrintMsg_PrintPreview(rvh->routing_id(), *settings)); |
524 } | 551 } |
525 | 552 |
526 void PrintPreviewHandler::HandlePrint(const ListValue* args) { | 553 void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
527 ReportStats(); | 554 ReportStats(); |
528 | 555 |
529 // Record the number of times the user requests to regenerate preview data | 556 // Record the number of times the user requests to regenerate preview data |
530 // before printing. | 557 // before printing. |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 return; | 972 return; |
946 | 973 |
947 // We no longer require the initiator tab details. Remove those details | 974 // We no longer require the initiator tab details. Remove those details |
948 // associated with the preview tab to allow the initiator tab to create | 975 // associated with the preview tab to allow the initiator tab to create |
949 // another preview tab. | 976 // another preview tab. |
950 printing::PrintPreviewTabController* tab_controller = | 977 printing::PrintPreviewTabController* tab_controller = |
951 printing::PrintPreviewTabController::GetInstance(); | 978 printing::PrintPreviewTabController::GetInstance(); |
952 if (tab_controller) | 979 if (tab_controller) |
953 tab_controller->EraseInitiatorTabInfo(preview_tab()); | 980 tab_controller->EraseInitiatorTabInfo(preview_tab()); |
954 } | 981 } |
OLD | NEW |