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 CHECK(args->GetString(0, &callback_id)); | |
|
Lei Zhang
2017/06/30 22:11:34
How about instead of doing the CHECK() here, check
rbpotter
2017/06/30 22:53:04
Done.
Also removed the CHECK below, since GetSett
| |
| 792 CHECK(args->GetString(1, &json_str)); | |
| 789 std::unique_ptr<base::DictionaryValue> settings = | 793 std::unique_ptr<base::DictionaryValue> settings = |
| 790 GetSettingsDictionary(json_str); | 794 GetSettingsDictionary(json_str); |
| 791 if (!settings) | 795 CHECK(settings); |
| 792 return; | |
| 793 int request_id = -1; | 796 int request_id = -1; |
| 794 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) | 797 CHECK(settings->GetInteger(printing::kPreviewRequestID, &request_id) && |
| 795 return; | 798 request_id > -1); |
| 796 | 799 |
| 800 preview_callbacks_.push(callback_id); | |
| 797 print_preview_ui()->OnPrintPreviewRequest(request_id); | 801 print_preview_ui()->OnPrintPreviewRequest(request_id); |
| 798 // Add an additional key in order to identify |print_preview_ui| later on | 802 // Add an additional key in order to identify |print_preview_ui| later on |
| 799 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO | 803 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO |
| 800 // thread. | 804 // thread. |
| 801 settings->SetInteger(printing::kPreviewUIID, | 805 settings->SetInteger(printing::kPreviewUIID, |
| 802 print_preview_ui()->GetIDForPrintPreviewUI()); | 806 print_preview_ui()->GetIDForPrintPreviewUI()); |
| 803 | 807 |
| 804 // Increment request count. | 808 // Increment request count. |
| 805 ++regenerate_preview_request_count_; | 809 ++regenerate_preview_request_count_; |
| 806 | 810 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 837 settings->SetString(printing::kSettingHeaderFooterURL, url); | 841 settings->SetString(printing::kSettingHeaderFooterURL, url); |
| 838 } | 842 } |
| 839 | 843 |
| 840 bool generate_draft_data = false; | 844 bool generate_draft_data = false; |
| 841 success = settings->GetBoolean(printing::kSettingGenerateDraftData, | 845 success = settings->GetBoolean(printing::kSettingGenerateDraftData, |
| 842 &generate_draft_data); | 846 &generate_draft_data); |
| 843 DCHECK(success); | 847 DCHECK(success); |
| 844 | 848 |
| 845 if (!generate_draft_data) { | 849 if (!generate_draft_data) { |
| 846 int page_count = -1; | 850 int page_count = -1; |
| 847 success = args->GetInteger(1, &page_count); | 851 success = args->GetInteger(2, &page_count); |
| 848 DCHECK(success); | 852 DCHECK(success); |
| 849 | 853 |
| 850 if (page_count != -1) { | 854 if (page_count != -1) { |
| 851 bool preview_modifiable = false; | 855 bool preview_modifiable = false; |
| 852 success = settings->GetBoolean(printing::kSettingPreviewModifiable, | 856 success = settings->GetBoolean(printing::kSettingPreviewModifiable, |
| 853 &preview_modifiable); | 857 &preview_modifiable); |
| 854 DCHECK(success); | 858 DCHECK(success); |
| 855 | 859 |
| 856 if (preview_modifiable && | 860 if (preview_modifiable && |
| 857 print_preview_ui()->GetAvailableDraftPageCount() != page_count) { | 861 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, | 1522 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), path, |
| 1519 &file_type_info, 0, base::FilePath::StringType(), | 1523 &file_type_info, 0, base::FilePath::StringType(), |
| 1520 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()), | 1524 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()), |
| 1521 NULL); | 1525 NULL); |
| 1522 } | 1526 } |
| 1523 | 1527 |
| 1524 void PrintPreviewHandler::OnGotUniqueFileName(const base::FilePath& path) { | 1528 void PrintPreviewHandler::OnGotUniqueFileName(const base::FilePath& path) { |
| 1525 FileSelected(path, 0, nullptr); | 1529 FileSelected(path, 0, nullptr); |
| 1526 } | 1530 } |
| 1527 | 1531 |
| 1532 void PrintPreviewHandler::OnPrintPreviewReady(int preview_uid, int request_id) { | |
| 1533 if (request_id < 0) // invalid ID. | |
| 1534 return; | |
| 1535 DCHECK(preview_callbacks_.size() > 0); | |
|
Lei Zhang
2017/06/30 22:11:34
If I controlled the renderer and made it malicious
Lei Zhang
2017/06/30 22:11:34
!preview_callbacks_.empty()
rbpotter
2017/06/30 22:53:04
Done.
rbpotter
2017/06/30 22:53:04
Done.
| |
| 1536 ResolveJavascriptCallback(base::Value(preview_callbacks_.front()), | |
| 1537 base::Value(preview_uid)); | |
| 1538 preview_callbacks_.pop(); | |
| 1539 } | |
| 1540 | |
| 1528 void PrintPreviewHandler::OnPrintPreviewFailed() { | 1541 void PrintPreviewHandler::OnPrintPreviewFailed() { |
| 1529 if (reported_failed_preview_) | 1542 DCHECK(preview_callbacks_.size() > 0); |
| 1530 return; | 1543 if (!reported_failed_preview_) { |
| 1531 reported_failed_preview_ = true; | 1544 reported_failed_preview_ = true; |
| 1532 ReportUserActionHistogram(PREVIEW_FAILED); | 1545 ReportUserActionHistogram(PREVIEW_FAILED); |
| 1546 } | |
| 1547 RejectJavascriptCallback(base::Value(preview_callbacks_.front()), | |
| 1548 base::Value("PREVIEW_FAILED")); | |
| 1549 preview_callbacks_.pop(); | |
| 1550 } | |
| 1551 | |
| 1552 void PrintPreviewHandler::OnInvalidPrinterSettings() { | |
| 1553 DCHECK(preview_callbacks_.size() > 0); | |
| 1554 RejectJavascriptCallback(base::Value(preview_callbacks_.front()), | |
| 1555 base::Value("SETTINGS_INVALID")); | |
| 1556 preview_callbacks_.pop(); | |
| 1557 } | |
| 1558 | |
| 1559 void PrintPreviewHandler::OnPrintPreviewCancelled() { | |
| 1560 DCHECK(preview_callbacks_.size() > 0); | |
| 1561 RejectJavascriptCallback(base::Value(preview_callbacks_.front()), | |
| 1562 base::Value("CANCELLED")); | |
| 1563 preview_callbacks_.pop(); | |
| 1533 } | 1564 } |
| 1534 | 1565 |
| 1535 #if BUILDFLAG(ENABLE_BASIC_PRINT_DIALOG) | 1566 #if BUILDFLAG(ENABLE_BASIC_PRINT_DIALOG) |
| 1536 void PrintPreviewHandler::ShowSystemDialog() { | 1567 void PrintPreviewHandler::ShowSystemDialog() { |
| 1537 HandleShowSystemDialog(NULL); | 1568 HandleShowSystemDialog(NULL); |
| 1538 } | 1569 } |
| 1539 #endif | 1570 #endif |
| 1540 | 1571 |
| 1541 void PrintPreviewHandler::FileSelected(const base::FilePath& path, | 1572 void PrintPreviewHandler::FileSelected(const base::FilePath& path, |
| 1542 int /* index */, | 1573 int /* index */, |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1890 | 1921 |
| 1891 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1922 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1892 if (gaia_cookie_manager_service_) | 1923 if (gaia_cookie_manager_service_) |
| 1893 gaia_cookie_manager_service_->RemoveObserver(this); | 1924 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1894 } | 1925 } |
| 1895 | 1926 |
| 1896 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1927 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1897 const base::Closure& closure) { | 1928 const base::Closure& closure) { |
| 1898 pdf_file_saved_closure_ = closure; | 1929 pdf_file_saved_closure_ = closure; |
| 1899 } | 1930 } |
| OLD | NEW |