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 CHECK(args->GetString(0, &callback_id)); |
| 789 if (!args->GetString(1, &json_str)) { | |
| 790 RejectJavascriptCallback(base::Value(callback_id), | |
| 791 base::Value("INVALID_SETTINGS")); | |
| 788 return; | 792 return; |
| 793 } | |
| 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 if (!settings) { |
| 797 RejectJavascriptCallback(base::Value(callback_id), | |
| 798 base::Value("INVALID_SETTINGS")); | |
| 792 return; | 799 return; |
| 800 } | |
| 793 int request_id = -1; | 801 int request_id = -1; |
| 794 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) | 802 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) { |
| 803 RejectJavascriptCallback(base::Value(callback_id), | |
| 804 base::Value("INVALID_SETTINGS")); | |
| 795 return; | 805 return; |
| 796 | 806 } |
| 807 DCHECK(preview_callbacks_.size() == static_cast<size_t>(request_id)); | |
| 808 preview_callbacks_.push_back(callback_id); | |
| 797 print_preview_ui()->OnPrintPreviewRequest(request_id); | 809 print_preview_ui()->OnPrintPreviewRequest(request_id); |
| 798 // Add an additional key in order to identify |print_preview_ui| later on | 810 // Add an additional key in order to identify |print_preview_ui| later on |
| 799 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO | 811 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO |
| 800 // thread. | 812 // thread. |
| 801 settings->SetInteger(printing::kPreviewUIID, | 813 settings->SetInteger(printing::kPreviewUIID, |
| 802 print_preview_ui()->GetIDForPrintPreviewUI()); | 814 print_preview_ui()->GetIDForPrintPreviewUI()); |
| 803 | 815 |
| 804 // Increment request count. | 816 // Increment request count. |
| 805 ++regenerate_preview_request_count_; | 817 ++regenerate_preview_request_count_; |
| 806 | 818 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 837 settings->SetString(printing::kSettingHeaderFooterURL, url); | 849 settings->SetString(printing::kSettingHeaderFooterURL, url); |
| 838 } | 850 } |
| 839 | 851 |
| 840 bool generate_draft_data = false; | 852 bool generate_draft_data = false; |
| 841 success = settings->GetBoolean(printing::kSettingGenerateDraftData, | 853 success = settings->GetBoolean(printing::kSettingGenerateDraftData, |
| 842 &generate_draft_data); | 854 &generate_draft_data); |
| 843 DCHECK(success); | 855 DCHECK(success); |
| 844 | 856 |
| 845 if (!generate_draft_data) { | 857 if (!generate_draft_data) { |
| 846 int page_count = -1; | 858 int page_count = -1; |
| 847 success = args->GetInteger(1, &page_count); | 859 success = args->GetInteger(2, &page_count); |
| 848 DCHECK(success); | 860 DCHECK(success); |
| 849 | 861 |
| 850 if (page_count != -1) { | 862 if (page_count != -1) { |
| 851 bool preview_modifiable = false; | 863 bool preview_modifiable = false; |
| 852 success = settings->GetBoolean(printing::kSettingPreviewModifiable, | 864 success = settings->GetBoolean(printing::kSettingPreviewModifiable, |
| 853 &preview_modifiable); | 865 &preview_modifiable); |
| 854 DCHECK(success); | 866 DCHECK(success); |
| 855 | 867 |
| 856 if (preview_modifiable && | 868 if (preview_modifiable && |
| 857 print_preview_ui()->GetAvailableDraftPageCount() != page_count) { | 869 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, | 1530 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), path, |
| 1519 &file_type_info, 0, base::FilePath::StringType(), | 1531 &file_type_info, 0, base::FilePath::StringType(), |
| 1520 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()), | 1532 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()), |
| 1521 NULL); | 1533 NULL); |
| 1522 } | 1534 } |
| 1523 | 1535 |
| 1524 void PrintPreviewHandler::OnGotUniqueFileName(const base::FilePath& path) { | 1536 void PrintPreviewHandler::OnGotUniqueFileName(const base::FilePath& path) { |
| 1525 FileSelected(path, 0, nullptr); | 1537 FileSelected(path, 0, nullptr); |
| 1526 } | 1538 } |
| 1527 | 1539 |
| 1528 void PrintPreviewHandler::OnPrintPreviewFailed() { | 1540 void PrintPreviewHandler::OnPrintPreviewReady(int preview_uid, int request_id) { |
| 1529 if (reported_failed_preview_) | 1541 ResolveJavascriptCallback(base::Value(preview_callbacks_[request_id]), |
|
Lei Zhang
2017/06/29 19:25:46
If |request_id| is negative, or too big, then this
rbpotter
2017/06/29 20:44:10
Done.
| |
| 1542 base::Value(preview_uid)); | |
| 1543 } | |
| 1544 | |
| 1545 void PrintPreviewHandler::OnPrintPreviewFailed(int request_id) { | |
| 1546 if (!reported_failed_preview_) { | |
| 1547 reported_failed_preview_ = true; | |
| 1548 ReportUserActionHistogram(PREVIEW_FAILED); | |
| 1549 } | |
| 1550 if (request_id == -1) | |
| 1530 return; | 1551 return; |
| 1531 reported_failed_preview_ = true; | 1552 DCHECK(preview_callbacks_.size() > static_cast<size_t>(request_id)); |
| 1532 ReportUserActionHistogram(PREVIEW_FAILED); | 1553 RejectJavascriptCallback(base::Value(preview_callbacks_[request_id]), |
| 1554 base::Value("PREVIEW_FAILED")); | |
| 1555 } | |
| 1556 | |
| 1557 void PrintPreviewHandler::OnInvalidPrinterSettings(int request_id) { | |
| 1558 if (request_id == -1) | |
| 1559 return; | |
| 1560 DCHECK(preview_callbacks_.size() > static_cast<size_t>(request_id)); | |
| 1561 RejectJavascriptCallback(base::Value(preview_callbacks_[request_id]), | |
| 1562 base::Value("INVALID_SETTINGS")); | |
| 1533 } | 1563 } |
| 1534 | 1564 |
| 1535 #if BUILDFLAG(ENABLE_BASIC_PRINT_DIALOG) | 1565 #if BUILDFLAG(ENABLE_BASIC_PRINT_DIALOG) |
| 1536 void PrintPreviewHandler::ShowSystemDialog() { | 1566 void PrintPreviewHandler::ShowSystemDialog() { |
| 1537 HandleShowSystemDialog(NULL); | 1567 HandleShowSystemDialog(NULL); |
| 1538 } | 1568 } |
| 1539 #endif | 1569 #endif |
| 1540 | 1570 |
| 1541 void PrintPreviewHandler::FileSelected(const base::FilePath& path, | 1571 void PrintPreviewHandler::FileSelected(const base::FilePath& path, |
| 1542 int /* index */, | 1572 int /* index */, |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1890 | 1920 |
| 1891 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1921 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1892 if (gaia_cookie_manager_service_) | 1922 if (gaia_cookie_manager_service_) |
| 1893 gaia_cookie_manager_service_->RemoveObserver(this); | 1923 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1894 } | 1924 } |
| 1895 | 1925 |
| 1896 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1926 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1897 const base::Closure& closure) { | 1927 const base::Closure& closure) { |
| 1898 pdf_file_saved_closure_ = closure; | 1928 pdf_file_saved_closure_ = closure; |
| 1899 } | 1929 } |
| OLD | NEW |