Chromium Code Reviews| 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 <string> | |
| 8 | |
| 7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
| 12 #include "url/gurl.h" | |
| 10 | 13 |
| 11 namespace content { | 14 namespace content { |
| 12 | 15 |
| 13 // static | 16 // static |
| 14 bool ServiceWorkerUtils::IsFeatureEnabled() { | 17 bool ServiceWorkerUtils::IsFeatureEnabled() { |
| 15 static bool enabled = CommandLine::ForCurrentProcess()->HasSwitch( | 18 static bool enabled = CommandLine::ForCurrentProcess()->HasSwitch( |
| 16 switches::kEnableServiceWorker); | 19 switches::kEnableServiceWorker); |
| 17 return enabled; | 20 return enabled; |
| 18 } | 21 } |
| 19 | 22 |
| 20 // static | 23 // static |
| 21 bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) { | 24 bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) { |
| 22 DCHECK(!scope.has_ref()); | 25 DCHECK(!scope.has_ref()); |
| 23 DCHECK(!url.has_ref()); | 26 DCHECK(!url.has_ref()); |
| 24 const std::string& scope_spec = scope.spec(); | 27 const std::string& scope_spec = scope.spec(); |
| 25 const std::string& url_spec = url.spec(); | 28 const std::string& url_spec = url.spec(); |
| 26 | 29 |
| 27 size_t len = scope_spec.size(); | 30 size_t len = scope_spec.size(); |
| 28 if (len > 0 && scope_spec[len - 1] == '*') | 31 if (len > 0 && scope_spec[len - 1] == '*') |
| 29 return scope_spec.compare(0, len - 1, url_spec, 0, len - 1) == 0; | 32 return scope_spec.compare(0, len - 1, url_spec, 0, len - 1) == 0; |
| 30 return scope_spec == url_spec; | 33 return scope_spec == url_spec; |
| 31 } | 34 } |
| 32 | 35 |
| 36 bool LongestScopeMatcher::MatchLongest(const GURL& scope) { | |
| 37 if (!ServiceWorkerUtils::ScopeMatches(scope, url_)) | |
| 38 return false; | |
| 39 // TODO(nhiroki): How should we prioritize scopes "/fo*" and "/foo" | |
| 40 // for a document "/foo"? | |
|
jsbell
2014/06/03 18:48:30
Add link to github spec issue?
nhiroki
2014/06/05 11:00:35
Done.
| |
| 41 if (match_.is_empty() || | |
| 42 match_.spec().size() < scope.spec().size()) { | |
| 43 match_ = scope; | |
| 44 return true; | |
| 45 } | |
| 46 return false; | |
| 47 } | |
| 48 | |
| 33 } // namespace content | 49 } // namespace content |
| OLD | NEW |