diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-20 10:33:36 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-22 11:45:12 +0000 |
commit | be59a35641616a4cf23c4a13fa0632624b021c1b (patch) | |
tree | 9da183258bdf9cc413f7562079d25ace6955467f /chromium/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc | |
parent | d702e4b6a64574e97fc7df8fe3238cde70242080 (diff) |
BASELINE: Update Chromium to 62.0.3202.101
Change-Id: I2d5eca8117600df6d331f6166ab24d943d9814ac
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc')
-rw-r--r-- | chromium/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/chromium/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc b/chromium/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc index a75305fab98..86a3de231ad 100644 --- a/chromium/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc +++ b/chromium/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc @@ -184,7 +184,9 @@ std::string PrinterAddress(const std::string& host, int port) { return host; } -// Returns a JSON representation of |printer| as a CupsPrinterInfo. +// Returns a JSON representation of |printer| as a CupsPrinterInfo. Note it's +// possible that this function returns a nullptr if the printer url is not in +// the right format. std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) { std::unique_ptr<base::DictionaryValue> printer_info = CreateEmptyPrinterInfo(); @@ -308,7 +310,11 @@ void CupsPrintersHandler::HandleGetCupsPrintersList( auto printers_list = base::MakeUnique<base::ListValue>(); for (const Printer& printer : printers) { - printers_list->Append(GetPrinterInfo(printer)); + // TODO(skau): Theoretically |printer_info| should not be a nullptr as we + // should not allow adding an invalid configured printer to PrinterManager. + auto printer_info = GetPrinterInfo(printer); + if (printer_info) + printers_list->Append(std::move(printer_info)); } auto response = base::MakeUnique<base::DictionaryValue>(); @@ -495,6 +501,14 @@ void CupsPrintersHandler::HandleAddCupsPrinter(const base::ListValue* args) { printer_uri += "/" + printer_queue; } + // Validate uri before continuing. + PrinterUri uri; + if (!ParseUri(printer_uri, &uri)) { + LOG(ERROR) << "Failed to parse printer"; + OnAddPrinterError(); + return; + } + // Read PPD selection if it was used. std::string ppd_manufacturer; std::string ppd_model; @@ -677,7 +691,8 @@ void CupsPrintersHandler::HandleSelectPPDFile(const base::ListValue* args) { ->DownloadPath(); select_file_dialog_ = ui::SelectFileDialog::Create( - this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); + this, + std::make_unique<ChromeSelectFilePolicy>(web_ui()->GetWebContents())); gfx::NativeWindow owning_window = chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()) ->window() @@ -771,10 +786,14 @@ void CupsPrintersHandler::OnPrintersChanged( std::unique_ptr<base::ListValue> printers_list = base::MakeUnique<base::ListValue>(); for (const Printer& printer : automatic_printers_) { - printers_list->Append(GetPrinterInfo(printer)); + auto printer_info = GetPrinterInfo(printer); + if (printer_info) + printers_list->Append(std::move(printer_info)); } for (const Printer& printer : discovered_printers_) { - printers_list->Append(GetPrinterInfo(printer)); + auto printer_info = GetPrinterInfo(printer); + if (printer_info) + printers_list->Append(std::move(printer_info)); } FireWebUIListener("on-printer-discovered", *printers_list); @@ -789,9 +808,11 @@ void CupsPrintersHandler::HandleAddDiscoveredPrinter( CHECK(args->GetString(0, &printer_id)); std::unique_ptr<Printer> printer = printers_manager_->GetPrinter(printer_id); - if (printer == nullptr) { + PrinterUri uri; + if (printer == nullptr || !ParseUri(printer->uri(), &uri)) { // Printer disappeared, so we don't have information about it anymore and - // can't really do much. Fail the add. + // can't really do much. Or the printer uri was not parsed successfully. + // Fail the add. FireWebUIListener("on-add-cups-printer", base::Value(false), base::Value(printer_id)); return; |