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#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ 6#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ 7 8#include "base/macros.h" 9#include "content/common/content_export.h" 10#include "content/common/service_worker/service_worker_status_code.h" 11#include "content/public/common/resource_type.h" 12#include "url/gurl.h" 13 14namespace content { 15 16class ServiceWorkerUtils { 17 public: 18 static bool IsMainResourceType(ResourceType type) { 19 return IsResourceTypeFrame(type) || type == RESOURCE_TYPE_SHARED_WORKER; 20 } 21 22 // A helper for creating a do-nothing status callback. 23 static void NoOpStatusCallback(ServiceWorkerStatusCode status) {} 24 25 // Returns true if |scope| matches |url|. 26 CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url); 27}; 28 29class CONTENT_EXPORT LongestScopeMatcher { 30 public: 31 explicit LongestScopeMatcher(const GURL& url) : url_(url) {} 32 virtual ~LongestScopeMatcher() {} 33 34 // Returns true if |scope| matches |url_| longer than |match_|. 35 bool MatchLongest(const GURL& scope); 36 37 private: 38 const GURL url_; 39 GURL match_; 40 41 DISALLOW_COPY_AND_ASSIGN(LongestScopeMatcher); 42}; 43 44} // namespace content 45 46#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ 47