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; | |
vandebo (ex-Chrome)
2011/08/29 18:21:56
nit: set default (false) here?
kmadhusu
2011/08/30 17:27:00
Default value is not required. If GetBoolean fails
| |
524 if (!settings->GetBoolean(printing::kSettingGenerateDraftData, | |
525 &generate_draft_data)) { | |
526 generate_draft_data = false; | |
527 NOTREACHED(); | |
528 } | |
529 | |
530 if (!generate_draft_data) { | |
531 int draft_page_count; | |
vandebo (ex-Chrome)
2011/08/29 18:21:56
nit: default here?
kmadhusu
2011/08/30 17:27:00
Done.
| |
532 bool preview_modifiable; | |
vandebo (ex-Chrome)
2011/08/29 18:21:56
need default
kmadhusu
2011/08/30 17:27:00
Done.
| |
533 std::string draft_page_count_str; | |
534 if (!args->GetString(1, &draft_page_count_str) || | |
535 !base::StringToInt(draft_page_count_str, &draft_page_count)) { | |
536 NOTREACHED(); | |
537 draft_page_count = -1; | |
538 } | |
539 | |
540 if (!args->GetBoolean(2, &preview_modifiable)) | |
541 NOTREACHED(); | |
542 | |
543 if (draft_page_count != -1 && preview_modifiable && | |
544 !print_preview_ui->IsDraftPagesAvailable(draft_page_count)) { | |
545 settings->SetBoolean(printing::kSettingGenerateDraftData, true); | |
546 } | |
547 } | |
548 | |
521 VLOG(1) << "Print preview request start"; | 549 VLOG(1) << "Print preview request start"; |
522 RenderViewHost* rvh = initiator_tab->render_view_host(); | 550 RenderViewHost* rvh = initiator_tab->render_view_host(); |
523 rvh->Send(new PrintMsg_PrintPreview(rvh->routing_id(), *settings)); | 551 rvh->Send(new PrintMsg_PrintPreview(rvh->routing_id(), *settings)); |
524 } | 552 } |
525 | 553 |
526 void PrintPreviewHandler::HandlePrint(const ListValue* args) { | 554 void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
527 ReportStats(); | 555 ReportStats(); |
528 | 556 |
529 // Record the number of times the user requests to regenerate preview data | 557 // Record the number of times the user requests to regenerate preview data |
530 // before printing. | 558 // before printing. |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
945 return; | 973 return; |
946 | 974 |
947 // We no longer require the initiator tab details. Remove those details | 975 // We no longer require the initiator tab details. Remove those details |
948 // associated with the preview tab to allow the initiator tab to create | 976 // associated with the preview tab to allow the initiator tab to create |
949 // another preview tab. | 977 // another preview tab. |
950 printing::PrintPreviewTabController* tab_controller = | 978 printing::PrintPreviewTabController* tab_controller = |
951 printing::PrintPreviewTabController::GetInstance(); | 979 printing::PrintPreviewTabController::GetInstance(); |
952 if (tab_controller) | 980 if (tab_controller) |
953 tab_controller->EraseInitiatorTabInfo(preview_tab()); | 981 tab_controller->EraseInitiatorTabInfo(preview_tab()); |
954 } | 982 } |
OLD | NEW |