Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / service_worker / service_worker_utils.cc
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 "base/command_line.h"
8 #include "base/strings/string_util.h"
9 #include "content/public/common/content_switches.h"
10
11 namespace content {
12
13 // static
14 bool ServiceWorkerUtils::IsFeatureEnabled() {
15   static bool enabled = CommandLine::ForCurrentProcess()->HasSwitch(
16       switches::kEnableServiceWorker);
17   return enabled;
18 }
19
20 // static
21 bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) {
22   // This is a really basic, naive
23   // TODO(alecflett): Formalize what scope matches mean.
24   // Temporarily borrowed directly from appcache::Namespace::IsMatch().
25   // We have to escape '?' characters since MatchPattern also treats those
26   // as wildcards which we don't want here, we only do '*'s.
27   std::string scope_spec(scope.spec());
28   if (scope.has_query())
29     ReplaceSubstringsAfterOffset(&scope_spec, 0, "?", "\\?");
30   return MatchPattern(url.spec(), scope_spec);
31 }
32
33 }  // namespace content