summaryrefslogtreecommitdiffstats
path: root/chromium/content/browser/initiator_csp_context.cc
blob: 3384af19f70badbd991c1b5b32c4d3a704da58f8 (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
// Copyright 2018 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.

#include "content/browser/initiator_csp_context.h"

namespace content {

InitiatorCSPContext::InitiatorCSPContext(
    std::vector<network::mojom::ContentSecurityPolicyPtr> policies,
    network::mojom::CSPSourcePtr self_source,
    mojo::PendingRemote<blink::mojom::NavigationInitiator> navigation_initiator)
    : reporting_render_frame_host_impl_(nullptr),
      initiator(std::move(navigation_initiator)) {
  for (auto& policy : policies)
    AddContentSecurityPolicy(std::move(policy));

  SetSelf(std::move(self_source));
}

InitiatorCSPContext::~InitiatorCSPContext() = default;

void InitiatorCSPContext::SetReportingRenderFrameHost(
    RenderFrameHostImpl* rfh) {
  reporting_render_frame_host_impl_ = rfh;
}

void InitiatorCSPContext::ReportContentSecurityPolicyViolation(
    network::mojom::CSPViolationPtr violation) {
  if (initiator)
    initiator->SendViolationReport(std::move(violation));
}

bool InitiatorCSPContext::SchemeShouldBypassCSP(
    const base::StringPiece& scheme) {
  // TODO(andypaicu): RenderFrameHostImpl::SchemeShouldBypassCSP could be
  // static except for the fact that it's virtual. It's weird to use
  // the reporting RFH to do this check but overall harmless.
  if (reporting_render_frame_host_impl_)
    return reporting_render_frame_host_impl_->SchemeShouldBypassCSP(scheme);

  return false;
}

void InitiatorCSPContext::SanitizeDataForUseInCspViolation(
    bool is_redirect,
    network::mojom::CSPDirectiveName directive,
    GURL* blocked_url,
    network::mojom::SourceLocation* source_location) const {
  if (reporting_render_frame_host_impl_) {
    reporting_render_frame_host_impl_->SanitizeDataForUseInCspViolation(
        is_redirect, directive, blocked_url, source_location);
  }
}

}  // namespace content