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

Side by Side Diff: extensions/common/url_pattern.cc

Issue 2449913002: Support WebSocket in WebRequest API. (Closed)
Patch Set: Refactor tests; add test; update documentation. Created 3 years, 10 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 (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 "extensions/common/url_pattern.h" 5 #include "extensions/common/url_pattern.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <ostream> 9 #include <ostream>
10 10
(...skipping 13 matching lines...) Expand all
24 const char URLPattern::kAllUrlsPattern[] = "<all_urls>"; 24 const char URLPattern::kAllUrlsPattern[] = "<all_urls>";
25 25
26 namespace { 26 namespace {
27 27
28 // TODO(aa): What about more obscure schemes like data: and javascript: ? 28 // TODO(aa): What about more obscure schemes like data: and javascript: ?
29 // Note: keep this array in sync with kValidSchemeMasks. 29 // Note: keep this array in sync with kValidSchemeMasks.
30 const char* const kValidSchemes[] = { 30 const char* const kValidSchemes[] = {
31 url::kHttpScheme, url::kHttpsScheme, 31 url::kHttpScheme, url::kHttpsScheme,
32 url::kFileScheme, url::kFtpScheme, 32 url::kFileScheme, url::kFtpScheme,
33 content::kChromeUIScheme, extensions::kExtensionScheme, 33 content::kChromeUIScheme, extensions::kExtensionScheme,
34 url::kFileSystemScheme, 34 url::kFileSystemScheme, url::kWsScheme,
35 url::kWssScheme,
35 }; 36 };
36 37
37 const int kValidSchemeMasks[] = { 38 const int kValidSchemeMasks[] = {
38 URLPattern::SCHEME_HTTP, 39 URLPattern::SCHEME_HTTP,
39 URLPattern::SCHEME_HTTPS, 40 URLPattern::SCHEME_HTTPS,
40 URLPattern::SCHEME_FILE, 41 URLPattern::SCHEME_FILE,
41 URLPattern::SCHEME_FTP, 42 URLPattern::SCHEME_FTP,
42 URLPattern::SCHEME_CHROMEUI, 43 URLPattern::SCHEME_CHROMEUI,
43 URLPattern::SCHEME_EXTENSION, 44 URLPattern::SCHEME_EXTENSION,
44 URLPattern::SCHEME_FILESYSTEM, 45 URLPattern::SCHEME_FILESYSTEM,
46 URLPattern::SCHEME_WS,
47 URLPattern::SCHEME_WSS,
45 }; 48 };
46 49
47 static_assert(arraysize(kValidSchemes) == arraysize(kValidSchemeMasks), 50 static_assert(arraysize(kValidSchemes) == arraysize(kValidSchemeMasks),
48 "must keep these arrays in sync"); 51 "must keep these arrays in sync");
49 52
50 const char kParseSuccess[] = "Success."; 53 const char kParseSuccess[] = "Success.";
51 const char kParseErrorMissingSchemeSeparator[] = "Missing scheme separator."; 54 const char kParseErrorMissingSchemeSeparator[] = "Missing scheme separator.";
52 const char kParseErrorInvalidScheme[] = "Invalid scheme."; 55 const char kParseErrorInvalidScheme[] = "Invalid scheme.";
53 const char kParseErrorWrongSchemeType[] = "Wrong scheme type."; 56 const char kParseErrorWrongSchemeType[] = "Wrong scheme type.";
54 const char kParseErrorEmptyHost[] = "Host can not be empty."; 57 const char kParseErrorEmptyHost[] = "Host can not be empty.";
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 315
313 void URLPattern::SetMatchSubdomains(bool val) { 316 void URLPattern::SetMatchSubdomains(bool val) {
314 spec_.clear(); 317 spec_.clear();
315 match_subdomains_ = val; 318 match_subdomains_ = val;
316 } 319 }
317 320
318 bool URLPattern::SetScheme(base::StringPiece scheme) { 321 bool URLPattern::SetScheme(base::StringPiece scheme) {
319 spec_.clear(); 322 spec_.clear();
320 scheme.CopyToString(&scheme_); 323 scheme.CopyToString(&scheme_);
321 if (scheme_ == "*") { 324 if (scheme_ == "*") {
322 valid_schemes_ &= (SCHEME_HTTP | SCHEME_HTTPS); 325 valid_schemes_ &= (SCHEME_HTTP | SCHEME_HTTPS | SCHEME_WS | SCHEME_WSS);
Devlin 2017/02/14 01:21:38 Hmm... I'm not sure this is preferable. We don't
pkalinnikov 2017/02/14 13:49:51 SGTM.
323 } else if (!IsValidScheme(scheme_)) { 326 } else if (!IsValidScheme(scheme_)) {
324 return false; 327 return false;
325 } 328 }
326 return true; 329 return true;
327 } 330 }
328 331
329 bool URLPattern::IsValidScheme(base::StringPiece scheme) const { 332 bool URLPattern::IsValidScheme(base::StringPiece scheme) const {
330 if (valid_schemes_ == SCHEME_ALL) 333 if (valid_schemes_ == SCHEME_ALL)
331 return true; 334 return true;
332 335
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 } 627 }
625 628
626 return result; 629 return result;
627 } 630 }
628 631
629 // static 632 // static
630 const char* URLPattern::GetParseResultString( 633 const char* URLPattern::GetParseResultString(
631 URLPattern::ParseResult parse_result) { 634 URLPattern::ParseResult parse_result) {
632 return kParseResultMessages[parse_result]; 635 return kParseResultMessages[parse_result];
633 } 636 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698