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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "url/url_util.h" 5 #include "url/url_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 22 matching lines...) Expand all
33 {kWssScheme, SCHEME_WITH_PORT}, // WebSocket secure. 33 {kWssScheme, SCHEME_WITH_PORT}, // WebSocket secure.
34 {kFileSystemScheme, SCHEME_WITHOUT_AUTHORITY}, 34 {kFileSystemScheme, SCHEME_WITHOUT_AUTHORITY},
35 }; 35 };
36 36
37 const int kNumReferrerURLSchemes = 2; 37 const int kNumReferrerURLSchemes = 2;
38 const SchemeWithType kReferrerURLSchemes[kNumReferrerURLSchemes] = { 38 const SchemeWithType kReferrerURLSchemes[kNumReferrerURLSchemes] = {
39 {kHttpScheme, SCHEME_WITH_PORT}, 39 {kHttpScheme, SCHEME_WITH_PORT},
40 {kHttpsScheme, SCHEME_WITH_PORT}, 40 {kHttpsScheme, SCHEME_WITH_PORT},
41 }; 41 };
42 42
43 const int kNumPrinterURLSchemes = 4;
44 const SchemeWithType kPrinterURLSchemes[kNumPrinterURLSchemes] = {
45 {kPrinterIppScheme, SCHEME_WITH_PORT},
46 {kPrinterIppsScheme, SCHEME_WITH_PORT},
47 {kPrinterLpdScheme, SCHEME_WITH_PORT},
48 {kPrinterSocketScheme, SCHEME_WITH_PORT},
49 };
50
43 // Lists of the currently installed standard and referrer schemes. These lists 51 // Lists of the currently installed standard and referrer schemes. These lists
44 // are lazily initialized by InitStandardSchemes and InitReferrerSchemes and are 52 // are lazily initialized by InitStandardSchemes and InitReferrerSchemes and are
45 // leaked on shutdown to prevent any destructors from being called that will 53 // leaked on shutdown to prevent any destructors from being called that will
46 // slow us down or cause problems. 54 // slow us down or cause problems.
47 std::vector<SchemeWithType>* standard_schemes = nullptr; 55 std::vector<SchemeWithType>* standard_schemes = nullptr;
48 std::vector<SchemeWithType>* referrer_schemes = nullptr; 56 std::vector<SchemeWithType>* referrer_schemes = nullptr;
57 std::vector<SchemeWithType>* printer_schemes = nullptr;
49 58
50 // See the LockSchemeRegistries declaration in the header. 59 // See the LockSchemeRegistries declaration in the header.
51 bool scheme_registries_locked = false; 60 bool scheme_registries_locked = false;
52 61
53 // This template converts a given character type to the corresponding 62 // This template converts a given character type to the corresponding
54 // StringPiece type. 63 // StringPiece type.
55 template<typename CHAR> struct CharToStringPiece { 64 template<typename CHAR> struct CharToStringPiece {
56 }; 65 };
57 template<> struct CharToStringPiece<char> { 66 template<> struct CharToStringPiece<char> {
58 typedef base::StringPiece Piece; 67 typedef base::StringPiece Piece;
(...skipping 18 matching lines...) Expand all
77 void InitStandardSchemes() { 86 void InitStandardSchemes() {
78 InitSchemes(&standard_schemes, kStandardURLSchemes, kNumStandardURLSchemes); 87 InitSchemes(&standard_schemes, kStandardURLSchemes, kNumStandardURLSchemes);
79 } 88 }
80 89
81 // Ensures that the referrer_schemes list is initialized, does nothing if 90 // Ensures that the referrer_schemes list is initialized, does nothing if
82 // it already has values. 91 // it already has values.
83 void InitReferrerSchemes() { 92 void InitReferrerSchemes() {
84 InitSchemes(&referrer_schemes, kReferrerURLSchemes, kNumReferrerURLSchemes); 93 InitSchemes(&referrer_schemes, kReferrerURLSchemes, kNumReferrerURLSchemes);
85 } 94 }
86 95
96 // Ensures that the printer_schemes list is initialized, does nothing if it
97 // already has values.
98 void InitPrinterSchemes() {
99 InitSchemes(&printer_schemes, kPrinterURLSchemes, kNumPrinterURLSchemes);
100 }
101
87 // Given a string and a range inside the string, compares it to the given 102 // Given a string and a range inside the string, compares it to the given
88 // lower-case |compare_to| buffer. 103 // lower-case |compare_to| buffer.
89 template<typename CHAR> 104 template<typename CHAR>
90 inline bool DoCompareSchemeComponent(const CHAR* spec, 105 inline bool DoCompareSchemeComponent(const CHAR* spec,
91 const Component& component, 106 const Component& component,
92 const char* compare_to) { 107 const char* compare_to) {
93 if (!component.is_nonempty()) 108 if (!component.is_nonempty())
94 return compare_to[0] == 0; // When component is empty, match empty scheme. 109 return compare_to[0] == 0; // When component is empty, match empty scheme.
95 return base::LowerCaseEqualsASCII( 110 return base::LowerCaseEqualsASCII(
96 typename CharToStringPiece<CHAR>::Piece( 111 typename CharToStringPiece<CHAR>::Piece(
(...skipping 21 matching lines...) Expand all
118 } 133 }
119 return false; 134 return false;
120 } 135 }
121 136
122 template<typename CHAR> 137 template<typename CHAR>
123 bool DoIsStandard(const CHAR* spec, const Component& scheme, SchemeType* type) { 138 bool DoIsStandard(const CHAR* spec, const Component& scheme, SchemeType* type) {
124 InitStandardSchemes(); 139 InitStandardSchemes();
125 return DoIsInSchemes(spec, scheme, type, *standard_schemes); 140 return DoIsInSchemes(spec, scheme, type, *standard_schemes);
126 } 141 }
127 142
143 template <typename CHAR>
144 bool IsPrinterScheme(const CHAR* spec,
145 const Component& scheme,
146 SchemeType* type) {
147 InitPrinterSchemes();
148 return DoIsInSchemes(spec, scheme, type, *printer_schemes);
149 }
128 150
129 template<typename CHAR> 151 template<typename CHAR>
130 bool DoFindAndCompareScheme(const CHAR* str, 152 bool DoFindAndCompareScheme(const CHAR* str,
131 int str_len, 153 int str_len,
132 const char* compare, 154 const char* compare,
133 Component* found_scheme) { 155 Component* found_scheme) {
134 // Before extracting scheme, canonicalize the URL to remove any whitespace. 156 // Before extracting scheme, canonicalize the URL to remove any whitespace.
135 // This matches the canonicalization done in DoCanonicalize function. 157 // This matches the canonicalization done in DoCanonicalize function.
136 RawCanonOutputT<CHAR> whitespace_buffer; 158 RawCanonOutputT<CHAR> whitespace_buffer;
137 int spec_len; 159 int spec_len;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 ParseFileURL(spec, spec_len, &parsed_input); 219 ParseFileURL(spec, spec_len, &parsed_input);
198 success = CanonicalizeFileURL(spec, spec_len, parsed_input, 220 success = CanonicalizeFileURL(spec, spec_len, parsed_input,
199 charset_converter, output, output_parsed); 221 charset_converter, output, output_parsed);
200 } else if (DoCompareSchemeComponent(spec, scheme, url::kFileSystemScheme)) { 222 } else if (DoCompareSchemeComponent(spec, scheme, url::kFileSystemScheme)) {
201 // Filesystem URLs are special. 223 // Filesystem URLs are special.
202 ParseFileSystemURL(spec, spec_len, &parsed_input); 224 ParseFileSystemURL(spec, spec_len, &parsed_input);
203 success = CanonicalizeFileSystemURL(spec, spec_len, parsed_input, 225 success = CanonicalizeFileSystemURL(spec, spec_len, parsed_input,
204 charset_converter, output, 226 charset_converter, output,
205 output_parsed); 227 output_parsed);
206 228
207 } else if (DoIsStandard(spec, scheme, &unused_scheme_type)) { 229 } else if (DoIsStandard(spec, scheme, &unused_scheme_type) ||
230 IsPrinterScheme(spec, scheme, &unused_scheme_type)) {
208 // All "normal" URLs. 231 // All "normal" URLs.
209 ParseStandardURL(spec, spec_len, &parsed_input); 232 ParseStandardURL(spec, spec_len, &parsed_input);
210 success = CanonicalizeStandardURL(spec, spec_len, parsed_input, 233 success = CanonicalizeStandardURL(spec, spec_len, parsed_input,
211 charset_converter, output, output_parsed); 234 charset_converter, output, output_parsed);
212 235
213 } else if (DoCompareSchemeComponent(spec, scheme, url::kMailToScheme)) { 236 } else if (DoCompareSchemeComponent(spec, scheme, url::kMailToScheme)) {
214 // Mailto URLs are treated like standard URLs, with only a scheme, path, 237 // Mailto URLs are treated like standard URLs, with only a scheme, path,
215 // and query. 238 // and query.
216 ParseMailtoURL(spec, spec_len, &parsed_input); 239 ParseMailtoURL(spec, spec_len, &parsed_input);
217 success = CanonicalizeMailtoURL(spec, spec_len, parsed_input, output, 240 success = CanonicalizeMailtoURL(spec, spec_len, parsed_input, output,
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 return DoCompareSchemeComponent(spec, component, compare_to); 645 return DoCompareSchemeComponent(spec, component, compare_to);
623 } 646 }
624 647
625 bool CompareSchemeComponent(const base::char16* spec, 648 bool CompareSchemeComponent(const base::char16* spec,
626 const Component& component, 649 const Component& component,
627 const char* compare_to) { 650 const char* compare_to) {
628 return DoCompareSchemeComponent(spec, component, compare_to); 651 return DoCompareSchemeComponent(spec, component, compare_to);
629 } 652 }
630 653
631 } // namespace url 654 } // namespace url
OLDNEW
« 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