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

Unified Diff: content/browser/service_worker/service_worker_utils.cc

Issue 435873002: ServiceWorker: Remove wildcard from scope matching (Chromium) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 6 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: content/browser/service_worker/service_worker_utils.cc
diff --git a/content/browser/service_worker/service_worker_utils.cc b/content/browser/service_worker/service_worker_utils.cc
index d088e97994915a9bc1e5ab2f970172947ec11d67..edbe9f97b227726057c5ce85c0ef4bb5322d138f 100644
--- a/content/browser/service_worker/service_worker_utils.cc
+++ b/content/browser/service_worker/service_worker_utils.cc
@@ -6,10 +6,8 @@
#include <string>
-#include "base/command_line.h"
#include "base/logging.h"
-#include "content/public/common/content_switches.h"
-#include "url/gurl.h"
+#include "base/strings/string_util.h"
namespace content {
@@ -17,41 +15,16 @@ namespace content {
bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) {
DCHECK(!scope.has_ref());
DCHECK(!url.has_ref());
- const std::string& scope_spec = scope.spec();
- const std::string& url_spec = url.spec();
-
- size_t len = scope_spec.size();
- if (len > 0 && scope_spec[len - 1] == '*')
- return scope_spec.compare(0, len - 1, url_spec, 0, len - 1) == 0;
- return scope_spec == url_spec;
+ return StartsWithASCII(url.spec(), scope.spec(), true);
}
bool LongestScopeMatcher::MatchLongest(const GURL& scope) {
if (!ServiceWorkerUtils::ScopeMatches(scope, url_))
return false;
- if (match_.is_empty()) {
- match_ = scope;
- return true;
- }
-
- const std::string match_spec = match_.spec();
- const std::string scope_spec = scope.spec();
- if (match_spec.size() < scope_spec.size()) {
+ if (match_.is_empty() || match_.spec().size() < scope.spec().size()) {
match_ = scope;
return true;
}
-
- // If |scope| has the same length with |match_|, they are compared as strings.
- // For example:
- // 1) for a document "/foo", "/foo" is prioritized over "/fo*".
- // 2) for a document "/f(1)", "/f(1*" is prioritized over "/f(1)".
- // TODO(nhiroki): This isn't in the spec.
- // (https://github.com/slightlyoff/ServiceWorker/issues/287)
- if (match_spec.size() == scope_spec.size() && match_spec < scope_spec) {
- match_ = scope;
- return true;
- }
-
return false;
}

Powered by Google App Engine
This is Rietveld 408576698