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

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: 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"
9 #include "content/public/common/content_switches.h" 8 #include "content/public/common/content_switches.h"
10 9
11 namespace content { 10 namespace content {
12 11
13 // static 12 // static
14 bool ServiceWorkerUtils::IsFeatureEnabled() { 13 bool ServiceWorkerUtils::IsFeatureEnabled() {
15 static bool enabled = CommandLine::ForCurrentProcess()->HasSwitch( 14 static bool enabled = CommandLine::ForCurrentProcess()->HasSwitch(
16 switches::kEnableServiceWorker); 15 switches::kEnableServiceWorker);
17 return enabled; 16 return enabled;
18 } 17 }
19 18
20 // static 19 // static
21 bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) { 20 bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) {
22 // This is a really basic, naive 21 const std::string scope_spec(scope.spec());
falken 2014/05/14 14:51:30 can it just be const std::string& scope_spec = sco
jsbell 2014/05/14 20:31:38 Cool, yes it can! Done.
23 // TODO(alecflett): Formalize what scope matches mean. 22 size_t len = scope_spec.size();
24 // Temporarily borrowed directly from appcache::Namespace::IsMatch(). 23 if (len > 0 && scope_spec[len - 1] == '*') {
25 // We have to escape '?' characters since MatchPattern also treats those 24 return scope_spec.compare(0, len - 1, url.spec(), 0, len - 1) == 0;
26 // as wildcards which we don't want here, we only do '*'s. 25 }
27 std::string scope_spec(scope.spec()); 26 return scope_spec == url.spec();
28 if (scope.has_query())
29 ReplaceSubstringsAfterOffset(&scope_spec, 0, "?", "\\?");
30 return MatchPattern(url.spec(), scope_spec);
31 } 27 }
32 28
33 } // namespace content 29 } // 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