Commit bf825927 authored by Paul Meyer's avatar Paul Meyer Committed by Commit Bot

Use ReportingServiceProxy directly with CSP violation reports.

This removes the need for ReportingServiceProxyPtrHolder altogether,
which is removed.

This is part of a larger effort to refactor the reporting code in Blink.

Bug: 931863
Change-Id: I1668ca1b6761ef2fd485bb06fe3743f29fde362b
TBR: foolip@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1534573
Commit-Queue: Paul Meyer <paulmeyer@chromium.org>
Reviewed-by: default avatarNate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644472}
parent 6c8fb8b5
......@@ -21,7 +21,6 @@
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/platform/network/encoded_form_data.h"
#include "third_party/blink/renderer/platform/weborigin/reporting_service_proxy_ptr_holder.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
namespace blink {
......@@ -154,15 +153,19 @@ void ExecutionContextCSPDelegate::PostViolationReport(
scoped_refptr<EncodedFormData> report =
EncodedFormData::Create(stringified_report.Utf8());
DEFINE_STATIC_LOCAL(ReportingServiceProxyPtrHolder,
reporting_service_proxy_holder, ());
// Construct and route the report to the ReportingContext, to be observed
// by any ReportingObservers.
CSPViolationReportBody* body = CSPViolationReportBody::Create(violation_data);
Report* observed_report =
MakeGarbageCollected<Report>("csp-violation", Url().GetString(), body);
ReportingContext::From(document)->QueueReport(observed_report);
auto* reporting_context = ReportingContext::From(document);
reporting_context->QueueReport(observed_report);
bool is_null;
int line_number = body->lineNumber(is_null);
line_number = is_null ? 0 : line_number;
int column_number = body->columnNumber(is_null);
column_number = is_null ? 0 : column_number;
for (const auto& report_endpoint : report_endpoints) {
if (use_reporting_api) {
......@@ -173,8 +176,21 @@ void ExecutionContextCSPDelegate::PostViolationReport(
// https://w3c.github.io/reporting/#queue-report
// Step 2. If url was not provided by the caller, let url be settings’s
// creation URL. [spec text]
reporting_service_proxy_holder.QueueCspViolationReport(
Url(), report_endpoint, &violation_data);
reporting_context->GetReportingService()->QueueCspViolationReport(
Url(),
report_endpoint,
body->documentURL() ? body->documentURL() : "",
body->referrer() ? body->referrer() : "",
body->effectiveDirective() ? body->effectiveDirective() : "",
body->effectiveDirective() ? body->effectiveDirective() : "",
body->originalPolicy() ? body->originalPolicy() : "",
body->disposition() ? body->disposition() : "",
body->blockedURL() ? body->blockedURL() : "",
line_number,
column_number,
body->sourceFile() ? body->sourceFile() : "",
body->statusCode(),
body->sample() ? body->sample() : "");
continue;
}
......
// Copyright (c) 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_WEBORIGIN_REPORTING_SERVICE_PROXY_PTR_HOLDER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WEBORIGIN_REPORTING_SERVICE_PROXY_PTR_HOLDER_H_
#include "third_party/blink/public/mojom/reporting/reporting.mojom-blink.h"
#include "third_party/blink/public/platform/interface_provider.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
namespace blink {
class ReportingServiceProxyPtrHolder {
USING_FAST_MALLOC(ReportingServiceProxyPtrHolder);
public:
ReportingServiceProxyPtrHolder() {
Platform::Current()->GetInterfaceProvider()->GetInterface(
mojo::MakeRequest(&reporting_service_proxy));
}
~ReportingServiceProxyPtrHolder() = default;
void QueueCspViolationReport(
const KURL& url,
const String& group,
const SecurityPolicyViolationEventInit* violation_data) {
if (reporting_service_proxy) {
reporting_service_proxy->QueueCspViolationReport(
url, group ? group : "default",
violation_data->documentURI() ? violation_data->documentURI() : "",
violation_data->referrer() ? violation_data->referrer() : "",
violation_data->violatedDirective()
? violation_data->violatedDirective()
: "",
violation_data->effectiveDirective()
? violation_data->effectiveDirective()
: "",
violation_data->originalPolicy() ? violation_data->originalPolicy()
: "",
violation_data->disposition() ? violation_data->disposition() : "",
violation_data->blockedURI() ? violation_data->blockedURI() : "",
violation_data->lineNumber(), violation_data->columnNumber(),
violation_data->sourceFile() ? violation_data->sourceFile() : "",
violation_data->statusCode(),
violation_data->sample() ? violation_data->sample() : "");
}
}
private:
mojom::blink::ReportingServiceProxyPtr reporting_service_proxy;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WEBORIGIN_REPORTING_SERVICE_PROXY_PTR_HOLDER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment