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

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

Issue 288693002: ServiceWorker: * is only wildcard at end of scope URLs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: leaner Created 6 years, 7 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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e05c546d73d1ba9f28d991d9dbca3068282054f6..165bcbec563e8226494083450aedad1f7a90c9c8 100644
--- a/content/browser/service_worker/service_worker_utils.cc
+++ b/content/browser/service_worker/service_worker_utils.cc
@@ -5,7 +5,7 @@
#include "content/browser/service_worker/service_worker_utils.h"
#include "base/command_line.h"
-#include "base/strings/string_util.h"
+#include "base/logging.h"
#include "content/public/common/content_switches.h"
namespace content {
@@ -19,15 +19,15 @@ bool ServiceWorkerUtils::IsFeatureEnabled() {
// static
bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) {
- // This is a really basic, naive
- // TODO(alecflett): Formalize what scope matches mean.
- // Temporarily borrowed directly from appcache::Namespace::IsMatch().
- // We have to escape '?' characters since MatchPattern also treats those
- // as wildcards which we don't want here, we only do '*'s.
- std::string scope_spec(scope.spec());
- if (scope.has_query())
- ReplaceSubstringsAfterOffset(&scope_spec, 0, "?", "\\?");
- return MatchPattern(url.spec(), scope_spec);
+ 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;
}
} // namespace content
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698