Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5996)

Unified Diff: chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc

Issue 2825153002: Update CUPS settings UI to allow USB printers to be added via discovery. (Closed)
Patch Set: One more round of xdai comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc
diff --git a/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc b/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc
index 33fef4d27f499f3835121bf96781cfab57cb5ec5..05343f71327dcdda75a309f168b5aec38a5c6409 100644
--- a/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc
+++ b/chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc
@@ -54,7 +54,6 @@ std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) {
printer_info->SetString("printerDescription", printer.description());
printer_info->SetString("printerManufacturer", printer.manufacturer());
printer_info->SetString("printerModel", printer.model());
-
// Get protocol, ip address and queue from the printer's URI.
const std::string printer_uri = printer.uri();
url::Parsed parsed;
@@ -69,11 +68,20 @@ std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) {
host = std::string(printer_uri, parsed.host.begin, parsed.host.len);
if (parsed.path.len > 0)
path = std::string(printer_uri, parsed.path.begin, parsed.path.len);
-
- printer_info->SetString("printerAddress", host);
+ if (base::ToLowerASCII(scheme) == "usb") {
+ // USB has URI path (and, maybe, query) components that aren't really
+ // associated with a queue -- the mapping between printing semantics and URI
+ // semantics breaks down a bit here. From the user's point of view, the
+ // entire host/path/query block is the printer address for USB.
+ printer_info->SetString("printerAddress",
+ printer_uri.substr(parsed.host.begin));
+ } else {
+ printer_info->SetString("printerAddress", host);
+ if (!path.empty()) {
+ printer_info->SetString("printerQueue", path.substr(1));
+ }
+ }
printer_info->SetString("printerProtocol", base::ToLowerASCII(scheme));
- if (!path.empty())
- printer_info->SetString("printerQueue", path.substr(1));
return printer_info;
}
@@ -203,8 +211,10 @@ void CupsPrintersHandler::HandleAddCupsPrinter(const base::ListValue* args) {
// printerPPDPath might be null for an auto-discovered printer.
printer_dict->GetString("printerPPDPath", &printer_ppd_path);
- std::string printer_uri =
- printer_protocol + "://" + printer_address + "/" + printer_queue;
+ std::string printer_uri = printer_protocol + "://" + printer_address;
+ if (!printer_queue.empty()) {
+ printer_uri += "/" + printer_queue;
+ }
stevenjb 2017/05/12 17:19:09 nit: no {}
Carlson 2017/05/12 18:14:09 As I understand it, it's optional in C++ and doing
std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(printer_id);
printer->set_display_name(printer_name);
« no previous file with comments | « chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698