Bug 1888590 - Mark some subtests on trusted-types-event-handlers.html as failing...
[gecko.git] / third_party / content_analysis_sdk / agent / src / event_base.cc
blobc8186a41121f362ff4fceaadbb7b6bee6fd1f05a
1 // Copyright 2022 The Chromium Authors.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "event_base.h"
7 namespace content_analysis {
8 namespace sdk {
10 ContentAnalysisEventBase::ContentAnalysisEventBase(
11 const BrowserInfo& browser_info)
12 : browser_info_(browser_info) {}
14 ResultCode ContentAnalysisEventBase::Close() {
15 return ResultCode::OK;
18 ResultCode UpdateResponse(ContentAnalysisResponse& response,
19 const std::string& tag,
20 ContentAnalysisResponse::Result::Status status) {
21 auto result = response.results_size() > 0
22 ? response.mutable_results(0)
23 : response.add_results();
25 if (!tag.empty()) {
26 result->set_tag(tag);
29 if (status != ContentAnalysisResponse::Result::STATUS_UNKNOWN) {
30 result->set_status(status);
33 return ResultCode::OK;
36 ResultCode SetEventVerdictTo(
37 ContentAnalysisEvent* event,
38 ContentAnalysisResponse::Result::TriggeredRule::Action action) {
39 // This function expects that the event's result has already been
40 // initialized by a call to UpdateResponse().
42 if (event->GetResponse().results_size() == 0) {
43 return ResultCode::ERR_MISSING_RESULT;
46 auto result = event->GetResponse().mutable_results(0);
48 // Content analysis responses generated with this SDK contain at most one
49 // triggered rule.
50 auto rule = result->triggered_rules_size() > 0
51 ? result->mutable_triggered_rules(0)
52 : result->add_triggered_rules();
54 rule->set_action(action);
56 return ResultCode::OK;
59 ResultCode SetEventVerdictToBlock(ContentAnalysisEvent* event) {
60 return SetEventVerdictTo(event,
61 ContentAnalysisResponse::Result::TriggeredRule::BLOCK);
64 } // namespace sdk
65 } // namespace content_analysis