• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "content/browser/service_worker/service_worker_utils.h"
6 
7 #include <string>
8 
9 #include "base/logging.h"
10 #include "base/strings/string_util.h"
11 
12 namespace content {
13 
14 // static
ScopeMatches(const GURL & scope,const GURL & url)15 bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) {
16   DCHECK(!scope.has_ref());
17   DCHECK(!url.has_ref());
18   return StartsWithASCII(url.spec(), scope.spec(), true);
19 }
20 
MatchLongest(const GURL & scope)21 bool LongestScopeMatcher::MatchLongest(const GURL& scope) {
22   if (!ServiceWorkerUtils::ScopeMatches(scope, url_))
23     return false;
24   if (match_.is_empty() || match_.spec().size() < scope.spec().size()) {
25     match_ = scope;
26     return true;
27   }
28   return false;
29 }
30 
31 }  // namespace content
32