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 "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()); |
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] == '*') { |
kinuko
2014/05/14 23:44:23
Does this code assume scope is relative or * is in
jsbell
2014/05/16 07:05:45
It assumes scope GURL is absolute (it's made so in
| |
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 |
OLD | NEW |