| 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 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 } | 777 } |
| 778 | 778 |
| 779 EnsureExtensionPrinterHandlerSet(); | 779 EnsureExtensionPrinterHandlerSet(); |
| 780 extension_printer_handler_->StartGetCapability( | 780 extension_printer_handler_->StartGetCapability( |
| 781 printer_name, | 781 printer_name, |
| 782 base::Bind(&PrintPreviewHandler::OnGotExtensionPrinterCapabilities, | 782 base::Bind(&PrintPreviewHandler::OnGotExtensionPrinterCapabilities, |
| 783 weak_factory_.GetWeakPtr(), callback_id)); | 783 weak_factory_.GetWeakPtr(), callback_id)); |
| 784 } | 784 } |
| 785 | 785 |
| 786 void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) { | 786 void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) { |
| 787 DCHECK_EQ(2U, args->GetSize()); | 787 DCHECK_EQ(3U, args->GetSize()); |
| 788 std::string callback_id; |
| 788 std::string json_str; | 789 std::string json_str; |
| 789 if (!args->GetString(0, &json_str)) | 790 CHECK(args->GetString(0, &callback_id)); |
| 791 if (!args->GetString(1, &json_str)) { |
| 792 RejectJavascriptCallback(base::Value(callback_id), |
| 793 base::Value("INVALID_SETTINGS")); |
| 790 return; | 794 return; |
| 795 } |
| 791 std::unique_ptr<base::DictionaryValue> settings = | 796 std::unique_ptr<base::DictionaryValue> settings = |
| 792 GetSettingsDictionary(json_str); | 797 GetSettingsDictionary(json_str); |
| 793 if (!settings) | 798 if (!settings) { |
| 799 RejectJavascriptCallback(base::Value(callback_id), |
| 800 base::Value("INVALID_SETTINGS")); |
| 794 return; | 801 return; |
| 802 } |
| 795 int request_id = -1; | 803 int request_id = -1; |
| 796 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) | 804 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) { |
| 805 RejectJavascriptCallback(base::Value(callback_id), |
| 806 base::Value("INVALID_SETTINGS")); |
| 797 return; | 807 return; |
| 798 | 808 } |
| 809 DCHECK(preview_callbacks_.size() == static_cast<size_t>(request_id)); |
| 810 preview_callbacks_.push_back(callback_id); |
| 799 print_preview_ui()->OnPrintPreviewRequest(request_id); | 811 print_preview_ui()->OnPrintPreviewRequest(request_id); |
| 800 // Add an additional key in order to identify |print_preview_ui| later on | 812 // Add an additional key in order to identify |print_preview_ui| later on |
| 801 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO | 813 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO |
| 802 // thread. | 814 // thread. |
| 803 settings->SetInteger(printing::kPreviewUIID, | 815 settings->SetInteger(printing::kPreviewUIID, |
| 804 print_preview_ui()->GetIDForPrintPreviewUI()); | 816 print_preview_ui()->GetIDForPrintPreviewUI()); |
| 805 | 817 |
| 806 // Increment request count. | 818 // Increment request count. |
| 807 ++regenerate_preview_request_count_; | 819 ++regenerate_preview_request_count_; |
| 808 | 820 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 839 settings->SetString(printing::kSettingHeaderFooterURL, url); | 851 settings->SetString(printing::kSettingHeaderFooterURL, url); |
| 840 } | 852 } |
| 841 | 853 |
| 842 bool generate_draft_data = false; | 854 bool generate_draft_data = false; |
| 843 success = settings->GetBoolean(printing::kSettingGenerateDraftData, | 855 success = settings->GetBoolean(printing::kSettingGenerateDraftData, |
| 844 &generate_draft_data); | 856 &generate_draft_data); |
| 845 DCHECK(success); | 857 DCHECK(success); |
| 846 | 858 |
| 847 if (!generate_draft_data) { | 859 if (!generate_draft_data) { |
| 848 int page_count = -1; | 860 int page_count = -1; |
| 849 success = args->GetInteger(1, &page_count); | 861 success = args->GetInteger(2, &page_count); |
| 850 DCHECK(success); | 862 DCHECK(success); |
| 851 | 863 |
| 852 if (page_count != -1) { | 864 if (page_count != -1) { |
| 853 bool preview_modifiable = false; | 865 bool preview_modifiable = false; |
| 854 success = settings->GetBoolean(printing::kSettingPreviewModifiable, | 866 success = settings->GetBoolean(printing::kSettingPreviewModifiable, |
| 855 &preview_modifiable); | 867 &preview_modifiable); |
| 856 DCHECK(success); | 868 DCHECK(success); |
| 857 | 869 |
| 858 if (preview_modifiable && | 870 if (preview_modifiable && |
| 859 print_preview_ui()->GetAvailableDraftPageCount() != page_count) { | 871 print_preview_ui()->GetAvailableDraftPageCount() != page_count) { |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), path, | 1538 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), path, |
| 1527 &file_type_info, 0, base::FilePath::StringType(), | 1539 &file_type_info, 0, base::FilePath::StringType(), |
| 1528 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()), | 1540 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()), |
| 1529 NULL); | 1541 NULL); |
| 1530 } | 1542 } |
| 1531 | 1543 |
| 1532 void PrintPreviewHandler::OnGotUniqueFileName(const base::FilePath& path) { | 1544 void PrintPreviewHandler::OnGotUniqueFileName(const base::FilePath& path) { |
| 1533 FileSelected(path, 0, nullptr); | 1545 FileSelected(path, 0, nullptr); |
| 1534 } | 1546 } |
| 1535 | 1547 |
| 1536 void PrintPreviewHandler::OnPrintPreviewFailed() { | 1548 void PrintPreviewHandler::OnPrintPreviewReady(int preview_uid, int request_id) { |
| 1537 if (reported_failed_preview_) | 1549 ResolveJavascriptCallback(base::Value(preview_callbacks_[request_id]), |
| 1550 base::Value(preview_uid)); |
| 1551 } |
| 1552 |
| 1553 void PrintPreviewHandler::OnPrintPreviewFailed(int request_id) { |
| 1554 if (!reported_failed_preview_) { |
| 1555 reported_failed_preview_ = true; |
| 1556 ReportUserActionHistogram(PREVIEW_FAILED); |
| 1557 } |
| 1558 if (request_id == -1) |
| 1538 return; | 1559 return; |
| 1539 reported_failed_preview_ = true; | 1560 DCHECK(preview_callbacks_.size() > static_cast<size_t>(request_id)); |
| 1540 ReportUserActionHistogram(PREVIEW_FAILED); | 1561 RejectJavascriptCallback(base::Value(preview_callbacks_[request_id]), |
| 1562 base::Value("PREVIEW_FAILED")); |
| 1563 } |
| 1564 |
| 1565 void PrintPreviewHandler::OnInvalidPrinterSettings(int request_id) { |
| 1566 if (request_id == -1) |
| 1567 return; |
| 1568 DCHECK(preview_callbacks_.size() > static_cast<size_t>(request_id)); |
| 1569 RejectJavascriptCallback(base::Value(preview_callbacks_[request_id]), |
| 1570 base::Value("INVALID_SETTINGS")); |
| 1541 } | 1571 } |
| 1542 | 1572 |
| 1543 #if BUILDFLAG(ENABLE_BASIC_PRINT_DIALOG) | 1573 #if BUILDFLAG(ENABLE_BASIC_PRINT_DIALOG) |
| 1544 void PrintPreviewHandler::ShowSystemDialog() { | 1574 void PrintPreviewHandler::ShowSystemDialog() { |
| 1545 HandleShowSystemDialog(NULL); | 1575 HandleShowSystemDialog(NULL); |
| 1546 } | 1576 } |
| 1547 #endif | 1577 #endif |
| 1548 | 1578 |
| 1549 void PrintPreviewHandler::FileSelected(const base::FilePath& path, | 1579 void PrintPreviewHandler::FileSelected(const base::FilePath& path, |
| 1550 int /* index */, | 1580 int /* index */, |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1898 | 1928 |
| 1899 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1929 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1900 if (gaia_cookie_manager_service_) | 1930 if (gaia_cookie_manager_service_) |
| 1901 gaia_cookie_manager_service_->RemoveObserver(this); | 1931 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1902 } | 1932 } |
| 1903 | 1933 |
| 1904 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1934 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1905 const base::Closure& closure) { | 1935 const base::Closure& closure) { |
| 1906 pdf_file_saved_closure_ = closure; | 1936 pdf_file_saved_closure_ = closure; |
| 1907 } | 1937 } |
| OLD | NEW |