service_worker_utils.h revision a02191e04bc25c4935f804f2c080ae28663d096d
1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
8a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "content/common/content_export.h"
9a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "content/common/service_worker/service_worker_status_code.h"
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "webkit/common/resource_type.h"
11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace content {
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ServiceWorkerUtils {
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static bool IsMainResourceType(ResourceType::Type type) {
17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return ResourceType::IsFrame(type) ||
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)           ResourceType::IsSharedWorker(type);
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static bool IsServiceWorkerResourceType(ResourceType::Type type) {
22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return ResourceType::IsServiceWorker(type);
23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Returns true if the feature is enabled (or not disabled) by command-line
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // flag.
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static bool IsFeatureEnabled();
28a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
29a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // A helper for creating a do-nothing status callback.
30a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  static void NoOpStatusCallback(ServiceWorkerStatusCode status) {}
31a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
32a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Returns true if |scope| matches |url|.
33a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url);
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace content
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif  // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_
39