summaryrefslogtreecommitdiff
path: root/chromium/content/common/content_security_policy/csp_source.h
blob: de2c051945c2a468d92e2c7ede2bce7f06463cdf (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2017 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 CONTENT_COMMON_CONTENT_SECURITY_POLICY_CSP_SOURCE_H_
#define CONTENT_COMMON_CONTENT_SECURITY_POLICY_CSP_SOURCE_H_

#include <string>

#include "content/common/content_export.h"
#include "url/gurl.h"

namespace content {

class CSPContext;

// A CSPSource represents an expression that matches a set of urls.
// Examples of CSPSource:
// - domain.example.com
// - *.example.com
// - https://cdn.com
// - data:
// - 'none'
// - 'self'
// - *
struct CONTENT_EXPORT CSPSource {
  CSPSource();
  CSPSource(const std::string& scheme,
            const std::string& host,
            bool is_host_wildcard,
            int port,
            bool is_port_wildcard,
            const std::string& path);
  CSPSource(const CSPSource& source);
  ~CSPSource();

  // Scheme.
  std::string scheme;

  // Host.
  std::string host;
  bool is_host_wildcard;

  // port.
  int port;
  bool is_port_wildcard;

  // Path.
  std::string path;

  std::string ToString() const;

  bool IsSchemeOnly() const;
  bool HasPort() const;
  bool HasHost() const;
  bool HasPath() const;

  // Returns true if the |source| matches the |url| for a given |context|.
  static bool Allow(const CSPSource& source,
                    const GURL& url,
                    CSPContext* context,
                    bool has_followed_redirect = false);
};

}  // namespace content
#endif  // CONTENT_COMMON_CONTENT_SECURITY_POLICY_CSP_SOURCE_H_