summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/url_pattern_set.h
blob: 2120e547e41506390641506cbcfc1b36f20e31ee (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
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2011 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.

#ifndef CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_
#define CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_
#pragma once

#include <vector>

#include "chrome/common/extensions/url_pattern.h"

class GURL;

// Represents the set of URLs an extension uses for web content.
class URLPatternSet {
 public:
  // Clears |out| and populates the set with the union of |set1| and |set2|.
  // NOTE: this does not discard duplicates.
  static void CreateUnion(const URLPatternSet& set1,
                          const URLPatternSet& set2,
                          URLPatternSet* out);

  URLPatternSet();
  URLPatternSet(const URLPatternSet& rhs);
  ~URLPatternSet();
  URLPatternSet& operator=(const URLPatternSet& rhs);

  bool is_empty() const;

  const URLPatternList& patterns() const { return patterns_; }
  void AddPattern(const URLPattern& pattern);
  void ClearPatterns();

  // Test if the extent contains a URL.
  bool MatchesURL(const GURL& url) const;

  // Returns true if there is a single URL that would be in two extents.
  bool OverlapsWith(const URLPatternSet& other) const;

 private:
  // The list of URL patterns that comprise the extent.
  URLPatternList patterns_;
};

#endif  // CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_