summaryrefslogtreecommitdiffstats
path: root/content/browser/service_worker/service_worker_utils.cc
blob: e05c546d73d1ba9f28d991d9dbca3068282054f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/service_worker/service_worker_utils.h"

#include "base/command_line.h"
#include "base/strings/string_util.h"
#include "content/public/common/content_switches.h"

namespace content {

// static
bool ServiceWorkerUtils::IsFeatureEnabled() {
  static bool enabled = CommandLine::ForCurrentProcess()->HasSwitch(
      switches::kEnableServiceWorker);
  return enabled;
}

// static
bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) {
  // This is a really basic, naive
  // TODO(alecflett): Formalize what scope matches mean.
  // Temporarily borrowed directly from appcache::Namespace::IsMatch().
  // We have to escape '?' characters since MatchPattern also treats those
  // as wildcards which we don't want here, we only do '*'s.
  std::string scope_spec(scope.spec());
  if (scope.has_query())
    ReplaceSubstringsAfterOffset(&scope_spec, 0, "?", "\\?");
  return MatchPattern(url.spec(), scope_spec);
}

}  // namespace content