Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 775 } | 775 } |
| 776 | 776 |
| 777 EnsureExtensionPrinterHandlerSet(); | 777 EnsureExtensionPrinterHandlerSet(); |
| 778 extension_printer_handler_->StartGetCapability( | 778 extension_printer_handler_->StartGetCapability( |
| 779 printer_name, | 779 printer_name, |
| 780 base::Bind(&PrintPreviewHandler::OnGotExtensionPrinterCapabilities, | 780 base::Bind(&PrintPreviewHandler::OnGotExtensionPrinterCapabilities, |
| 781 weak_factory_.GetWeakPtr(), callback_id)); | 781 weak_factory_.GetWeakPtr(), callback_id)); |
| 782 } | 782 } |
| 783 | 783 |
| 784 void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) { | 784 void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) { |
| 785 DCHECK_EQ(2U, args->GetSize()); | 785 DCHECK_EQ(3U, args->GetSize()); |
| 786 std::string callback_id; | |
| 786 std::string json_str; | 787 std::string json_str; |
| 787 if (!args->GetString(0, &json_str)) | 788 |
| 788 return; | 789 // All of the conditions below should be guaranteed by the print preview |
| 790 // javascript. | |
| 791 args->GetString(0, &callback_id); | |
| 792 CHECK(!callback_id.empty()); | |
| 793 args->GetString(1, &json_str); | |
| 789 std::unique_ptr<base::DictionaryValue> settings = | 794 std::unique_ptr<base::DictionaryValue> settings = |
| 790 GetSettingsDictionary(json_str); | 795 GetSettingsDictionary(json_str); |
| 791 if (!settings) | 796 CHECK(settings); |
| 792 return; | |
| 793 int request_id = -1; | 797 int request_id = -1; |
| 794 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) | 798 CHECK(settings->GetInteger(printing::kPreviewRequestID, &request_id) && |
|
Lei Zhang
2017/06/30 22:58:18
One more. Just CHECK_GT(request_id, -1).
rbpotter
2017/06/30 23:16:24
Done.
| |
| 795 return; | 799 request_id > -1); |
| 796 | 800 |
| 801 preview_callbacks_.push(callback_id); | |
| 797 print_preview_ui()->OnPrintPreviewRequest(request_id); | 802 print_preview_ui()->OnPrintPreviewRequest(request_id); |
| 798 // Add an additional key in order to identify |print_preview_ui| later on | 803 // Add an additional key in order to identify |print_preview_ui| later on |
| 799 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO | 804 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO |
| 800 // thread. | 805 // thread. |
| 801 settings->SetInteger(printing::kPreviewUIID, | 806 settings->SetInteger(printing::kPreviewUIID, |
| 802 print_preview_ui()->GetIDForPrintPreviewUI()); | 807 print_preview_ui()->GetIDForPrintPreviewUI()); |
| 803 | 808 |
| 804 // Increment request count. | 809 // Increment request count. |
| 805 ++regenerate_preview_request_count_; | 810 ++regenerate_preview_request_count_; |
| 806 | 811 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 837 settings->SetString(printing::kSettingHeaderFooterURL, url); | 842 settings->SetString(printing::kSettingHeaderFooterURL, url); |
| 838 } | 843 } |
| 839 | 844 |
| 840 bool generate_draft_data = false; | 845 bool generate_draft_data = false; |
| 841 success = settings->GetBoolean(printing::kSettingGenerateDraftData, | 846 success = settings->GetBoolean(printing::kSettingGenerateDraftData, |
| 842 &generate_draft_data); | 847 &generate_draft_data); |
| 843 DCHECK(success); | 848 DCHECK(success); |
| 844 | 849 |
| 845 if (!generate_draft_data) { | 850 if (!generate_draft_data) { |
| 846 int page_count = -1; | 851 int page_count = -1; |
| 847 success = args->GetInteger(1, &page_count); | 852 success = args->GetInteger(2, &page_count); |
| 848 DCHECK(success); | 853 DCHECK(success); |
| 849 | 854 |
| 850 if (page_count != -1) { | 855 if (page_count != -1) { |
| 851 bool preview_modifiable = false; | 856 bool preview_modifiable = false; |
| 852 success = settings->GetBoolean(printing::kSettingPreviewModifiable, | 857 success = settings->GetBoolean(printing::kSettingPreviewModifiable, |
| 853 &preview_modifiable); | 858 &preview_modifiable); |
| 854 DCHECK(success); | 859 DCHECK(success); |
| 855 | 860 |
| 856 if (preview_modifiable && | 861 if (preview_modifiable && |
| 857 print_preview_ui()->GetAvailableDraftPageCount() != page_count) { | 862 print_preview_ui()->GetAvailableDraftPageCount() != page_count) { |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1518 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), path, | 1523 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), path, |
| 1519 &file_type_info, 0, base::FilePath::StringType(), | 1524 &file_type_info, 0, base::FilePath::StringType(), |
| 1520 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()), | 1525 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()), |
| 1521 NULL); | 1526 NULL); |
| 1522 } | 1527 } |
| 1523 | 1528 |
| 1524 void PrintPreviewHandler::OnGotUniqueFileName(const base::FilePath& path) { | 1529 void PrintPreviewHandler::OnGotUniqueFileName(const base::FilePath& path) { |
| 1525 FileSelected(path, 0, nullptr); | 1530 FileSelected(path, 0, nullptr); |
| 1526 } | 1531 } |
| 1527 | 1532 |
| 1533 void PrintPreviewHandler::OnPrintPreviewReady(int preview_uid, int request_id) { | |
| 1534 if (request_id < 0) // invalid ID. | |
| 1535 return; | |
| 1536 CHECK(!preview_callbacks_.empty()); | |
| 1537 ResolveJavascriptCallback(base::Value(preview_callbacks_.front()), | |
| 1538 base::Value(preview_uid)); | |
| 1539 preview_callbacks_.pop(); | |
| 1540 } | |
| 1541 | |
| 1528 void PrintPreviewHandler::OnPrintPreviewFailed() { | 1542 void PrintPreviewHandler::OnPrintPreviewFailed() { |
| 1529 if (reported_failed_preview_) | 1543 CHECK(!preview_callbacks_.empty()); |
| 1530 return; | 1544 if (!reported_failed_preview_) { |
| 1531 reported_failed_preview_ = true; | 1545 reported_failed_preview_ = true; |
| 1532 ReportUserActionHistogram(PREVIEW_FAILED); | 1546 ReportUserActionHistogram(PREVIEW_FAILED); |
| 1547 } | |
| 1548 RejectJavascriptCallback(base::Value(preview_callbacks_.front()), | |
| 1549 base::Value("PREVIEW_FAILED")); | |
| 1550 preview_callbacks_.pop(); | |
| 1551 } | |
| 1552 | |
| 1553 void PrintPreviewHandler::OnInvalidPrinterSettings() { | |
| 1554 CHECK(!preview_callbacks_.empty()); | |
| 1555 RejectJavascriptCallback(base::Value(preview_callbacks_.front()), | |
| 1556 base::Value("SETTINGS_INVALID")); | |
| 1557 preview_callbacks_.pop(); | |
| 1558 } | |
| 1559 | |
| 1560 void PrintPreviewHandler::OnPrintPreviewCancelled() { | |
| 1561 CHECK(!preview_callbacks_.empty()); | |
| 1562 RejectJavascriptCallback(base::Value(preview_callbacks_.front()), | |
| 1563 base::Value("CANCELLED")); | |
| 1564 preview_callbacks_.pop(); | |
| 1533 } | 1565 } |
| 1534 | 1566 |
| 1535 #if BUILDFLAG(ENABLE_BASIC_PRINT_DIALOG) | 1567 #if BUILDFLAG(ENABLE_BASIC_PRINT_DIALOG) |
| 1536 void PrintPreviewHandler::ShowSystemDialog() { | 1568 void PrintPreviewHandler::ShowSystemDialog() { |
| 1537 HandleShowSystemDialog(NULL); | 1569 HandleShowSystemDialog(NULL); |
| 1538 } | 1570 } |
| 1539 #endif | 1571 #endif |
| 1540 | 1572 |
| 1541 void PrintPreviewHandler::FileSelected(const base::FilePath& path, | 1573 void PrintPreviewHandler::FileSelected(const base::FilePath& path, |
| 1542 int /* index */, | 1574 int /* index */, |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1890 | 1922 |
| 1891 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1923 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1892 if (gaia_cookie_manager_service_) | 1924 if (gaia_cookie_manager_service_) |
| 1893 gaia_cookie_manager_service_->RemoveObserver(this); | 1925 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1894 } | 1926 } |
| 1895 | 1927 |
| 1896 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1928 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1897 const base::Closure& closure) { | 1929 const base::Closure& closure) { |
| 1898 pdf_file_saved_closure_ = closure; | 1930 pdf_file_saved_closure_ = closure; |
| 1899 } | 1931 } |
| OLD | NEW |