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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_util.h" 8 #include "base/logging.h"
9 #include "content/public/common/content_switches.h" 9 #include "content/public/common/content_switches.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 // static 13 // static
14 bool ServiceWorkerUtils::IsFeatureEnabled() { 14 bool ServiceWorkerUtils::IsFeatureEnabled() {
15 static bool enabled = CommandLine::ForCurrentProcess()->HasSwitch( 15 static bool enabled = CommandLine::ForCurrentProcess()->HasSwitch(
16 switches::kEnableServiceWorker); 16 switches::kEnableServiceWorker);
17 return enabled; 17 return enabled;
18 } 18 }
19 19
20 // static 20 // static
21 bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) { 21 bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) {
22 // This is a really basic, naive 22 DCHECK(!scope.has_ref());
23 // TODO(alecflett): Formalize what scope matches mean. 23 DCHECK(!url.has_ref());
24 // Temporarily borrowed directly from appcache::Namespace::IsMatch(). 24 const std::string& scope_spec = scope.spec();
25 // We have to escape '?' characters since MatchPattern also treats those 25 const std::string& url_spec = url.spec();
26 // as wildcards which we don't want here, we only do '*'s. 26
27 std::string scope_spec(scope.spec()); 27 size_t len = scope_spec.size();
28 if (scope.has_query()) 28 if (len > 0 && scope_spec[len - 1] == '*')
29 ReplaceSubstringsAfterOffset(&scope_spec, 0, "?", "\\?"); 29 return scope_spec.compare(0, len - 1, url_spec, 0, len - 1) == 0;
30 return MatchPattern(url.spec(), scope_spec); 30 return scope_spec == url_spec;
31 } 31 }
32 32
33 } // namespace content 33 } // namespace content
OLDNEW
« 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