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

Unified Diff: url/url_util.cc

Issue 2250843002: [CUPS] WebUI handler for CUPS printing: Retrieve the printer list from user preference. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address skau@ and dbeam@'s comments. Created 4 years, 4 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
Index: url/url_util.cc
diff --git a/url/url_util.cc b/url/url_util.cc
index c1e997992d3569496b96e64014a79e692bc01bcf..1d37daab6b255c34598c9b92aa13be066c941676 100644
--- a/url/url_util.cc
+++ b/url/url_util.cc
@@ -40,12 +40,21 @@ const SchemeWithType kReferrerURLSchemes[kNumReferrerURLSchemes] = {
{kHttpsScheme, SCHEME_WITH_PORT},
};
+const int kNumPrinterURLSchemes = 4;
+const SchemeWithType kPrinterURLSchemes[kNumPrinterURLSchemes] = {
+ {kPrinterIppScheme, SCHEME_WITH_PORT},
+ {kPrinterIppsScheme, SCHEME_WITH_PORT},
+ {kPrinterLpdScheme, SCHEME_WITH_PORT},
+ {kPrinterSocketScheme, SCHEME_WITH_PORT},
+};
+
// Lists of the currently installed standard and referrer schemes. These lists
// are lazily initialized by InitStandardSchemes and InitReferrerSchemes and are
// leaked on shutdown to prevent any destructors from being called that will
// slow us down or cause problems.
std::vector<SchemeWithType>* standard_schemes = nullptr;
std::vector<SchemeWithType>* referrer_schemes = nullptr;
+std::vector<SchemeWithType>* printer_schemes = nullptr;
// See the LockSchemeRegistries declaration in the header.
bool scheme_registries_locked = false;
@@ -84,6 +93,12 @@ void InitReferrerSchemes() {
InitSchemes(&referrer_schemes, kReferrerURLSchemes, kNumReferrerURLSchemes);
}
+// Ensures that the printer_schemes list is initialized, does nothing if it
+// already has values.
+void InitPrinterSchemes() {
+ InitSchemes(&printer_schemes, kPrinterURLSchemes, kNumPrinterURLSchemes);
+}
+
// Given a string and a range inside the string, compares it to the given
// lower-case |compare_to| buffer.
template<typename CHAR>
@@ -125,6 +140,13 @@ bool DoIsStandard(const CHAR* spec, const Component& scheme, SchemeType* type) {
return DoIsInSchemes(spec, scheme, type, *standard_schemes);
}
+template <typename CHAR>
+bool IsPrinterScheme(const CHAR* spec,
+ const Component& scheme,
+ SchemeType* type) {
+ InitPrinterSchemes();
+ return DoIsInSchemes(spec, scheme, type, *printer_schemes);
+}
template<typename CHAR>
bool DoFindAndCompareScheme(const CHAR* str,
@@ -204,7 +226,8 @@ bool DoCanonicalize(const CHAR* in_spec,
charset_converter, output,
output_parsed);
- } else if (DoIsStandard(spec, scheme, &unused_scheme_type)) {
+ } else if (DoIsStandard(spec, scheme, &unused_scheme_type) ||
+ IsPrinterScheme(spec, scheme, &unused_scheme_type)) {
// All "normal" URLs.
ParseStandardURL(spec, spec_len, &parsed_input);
success = CanonicalizeStandardURL(spec, spec_len, parsed_input,
« chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc ('K') | « url/url_constants.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698