| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/service_worker/service_worker_utils.h" | 5 #include "content/browser/service_worker/service_worker_utils.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // static | 90 // static |
| 91 bool ServiceWorkerUtils::ContainsDisallowedCharacter( | 91 bool ServiceWorkerUtils::ContainsDisallowedCharacter( |
| 92 const GURL& scope, | 92 const GURL& scope, |
| 93 const GURL& script_url, | 93 const GURL& script_url, |
| 94 std::string* error_message) { | 94 std::string* error_message) { |
| 95 if (PathContainsDisallowedCharacter(scope) || | 95 if (PathContainsDisallowedCharacter(scope) || |
| 96 PathContainsDisallowedCharacter(script_url)) { | 96 PathContainsDisallowedCharacter(script_url)) { |
| 97 *error_message = "The provided scope ('"; | 97 if (error_message) { |
| 98 error_message->append(scope.spec()); | 98 *error_message = "The provided scope ('"; |
| 99 error_message->append("') or scriptURL ('"); | 99 error_message->append(scope.spec()); |
| 100 error_message->append(script_url.spec()); | 100 error_message->append("') or scriptURL ('"); |
| 101 error_message->append("') includes a disallowed escape character."); | 101 error_message->append(script_url.spec()); |
| 102 error_message->append("') includes a disallowed escape character."); |
| 103 } |
| 102 return true; | 104 return true; |
| 103 } | 105 } |
| 104 return false; | 106 return false; |
| 105 } | 107 } |
| 106 | 108 |
| 107 bool LongestScopeMatcher::MatchLongest(const GURL& scope) { | 109 bool LongestScopeMatcher::MatchLongest(const GURL& scope) { |
| 108 if (!ServiceWorkerUtils::ScopeMatches(scope, url_)) | 110 if (!ServiceWorkerUtils::ScopeMatches(scope, url_)) |
| 109 return false; | 111 return false; |
| 110 if (match_.is_empty() || match_.spec().size() < scope.spec().size()) { | 112 if (match_.is_empty() || match_.spec().size() < scope.spec().size()) { |
| 111 match_ = scope; | 113 match_ = scope; |
| 112 return true; | 114 return true; |
| 113 } | 115 } |
| 114 return false; | 116 return false; |
| 115 } | 117 } |
| 116 | 118 |
| 117 } // namespace content | 119 } // namespace content |
| OLD | NEW |