| 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 18 matching lines...) Expand all Loading... |
| 29 } | 29 } |
| 30 return false; | 30 return false; |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 // static | 35 // static |
| 36 bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) { | 36 bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) { |
| 37 DCHECK(!scope.has_ref()); | 37 DCHECK(!scope.has_ref()); |
| 38 DCHECK(!url.has_ref()); | 38 DCHECK(!url.has_ref()); |
| 39 return base::StartsWithASCII(url.spec(), scope.spec(), true); | 39 return base::StartsWith(url.spec(), scope.spec(), |
| 40 base::CompareCase::SENSITIVE); |
| 40 } | 41 } |
| 41 | 42 |
| 42 // static | 43 // static |
| 43 bool ServiceWorkerUtils::IsPathRestrictionSatisfied( | 44 bool ServiceWorkerUtils::IsPathRestrictionSatisfied( |
| 44 const GURL& scope, | 45 const GURL& scope, |
| 45 const GURL& script_url, | 46 const GURL& script_url, |
| 46 const std::string* service_worker_allowed_header_value, | 47 const std::string* service_worker_allowed_header_value, |
| 47 std::string* error_message) { | 48 std::string* error_message) { |
| 48 DCHECK(scope.is_valid()); | 49 DCHECK(scope.is_valid()); |
| 49 DCHECK(!scope.has_ref()); | 50 DCHECK(!scope.has_ref()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 error_message->append(*service_worker_allowed_header_value); | 63 error_message->append(*service_worker_allowed_header_value); |
| 63 error_message->append("') was received when fetching the script."); | 64 error_message->append("') was received when fetching the script."); |
| 64 return false; | 65 return false; |
| 65 } | 66 } |
| 66 max_scope_string = max_scope.path(); | 67 max_scope_string = max_scope.path(); |
| 67 } else { | 68 } else { |
| 68 max_scope_string = script_url.Resolve(".").path(); | 69 max_scope_string = script_url.Resolve(".").path(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 std::string scope_string = scope.path(); | 72 std::string scope_string = scope.path(); |
| 72 if (!base::StartsWithASCII(scope_string, max_scope_string, true)) { | 73 if (!base::StartsWith(scope_string, max_scope_string, |
| 74 base::CompareCase::SENSITIVE)) { |
| 73 *error_message = "The path of the provided scope ('"; | 75 *error_message = "The path of the provided scope ('"; |
| 74 error_message->append(scope_string); | 76 error_message->append(scope_string); |
| 75 error_message->append("') is not under the max scope allowed ("); | 77 error_message->append("') is not under the max scope allowed ("); |
| 76 if (service_worker_allowed_header_value) | 78 if (service_worker_allowed_header_value) |
| 77 error_message->append("set by Service-Worker-Allowed: "); | 79 error_message->append("set by Service-Worker-Allowed: "); |
| 78 error_message->append("'"); | 80 error_message->append("'"); |
| 79 error_message->append(max_scope_string); | 81 error_message->append(max_scope_string); |
| 80 error_message->append( | 82 error_message->append( |
| 81 "'). Adjust the scope, move the Service Worker script, or use the " | 83 "'). Adjust the scope, move the Service Worker script, or use the " |
| 82 "Service-Worker-Allowed HTTP header to allow the scope."); | 84 "Service-Worker-Allowed HTTP header to allow the scope."); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 106 if (!ServiceWorkerUtils::ScopeMatches(scope, url_)) | 108 if (!ServiceWorkerUtils::ScopeMatches(scope, url_)) |
| 107 return false; | 109 return false; |
| 108 if (match_.is_empty() || match_.spec().size() < scope.spec().size()) { | 110 if (match_.is_empty() || match_.spec().size() < scope.spec().size()) { |
| 109 match_ = scope; | 111 match_ = scope; |
| 110 return true; | 112 return true; |
| 111 } | 113 } |
| 112 return false; | 114 return false; |
| 113 } | 115 } |
| 114 | 116 |
| 115 } // namespace content | 117 } // namespace content |
| OLD | NEW |