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 67 68 69 70 71 72
|
// Copyright 2020 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 SERVICES_NETWORK_PUBLIC_CPP_WEB_SANDBOX_FLAGS_H_
#define SERVICES_NETWORK_PUBLIC_CPP_WEB_SANDBOX_FLAGS_H_
#include <cstdint>
#include <string>
#include "base/component_export.h"
#include "base/strings/string_piece_forward.h"
namespace network {
namespace mojom {
enum class WebSandboxFlags : int32_t;
inline constexpr WebSandboxFlags operator&(WebSandboxFlags a,
WebSandboxFlags b) {
return static_cast<WebSandboxFlags>(static_cast<int>(a) &
static_cast<int>(b));
}
inline constexpr WebSandboxFlags operator|(WebSandboxFlags a,
WebSandboxFlags b) {
return static_cast<WebSandboxFlags>(static_cast<int>(a) |
static_cast<int>(b));
}
inline WebSandboxFlags& operator|=(WebSandboxFlags& a, WebSandboxFlags b) {
return a = a | b;
}
inline WebSandboxFlags& operator&=(WebSandboxFlags& a, WebSandboxFlags b) {
return a = a & b;
}
inline constexpr WebSandboxFlags operator~(WebSandboxFlags flags) {
return static_cast<WebSandboxFlags>(~static_cast<int>(flags));
}
} // namespace mojom
// The output of |ParseSandboxPolicy(input)|.
struct WebSandboxFlagsParsingResult {
// The complement of the parsed WebSandboxFlags policy.
// TODO(arthursonzogni): Update the caller of ParseWebSandboxPolicy(). They
// should directly use the policy instead of its complement.
mojom::WebSandboxFlags flags;
// The console error message to be displayed for invalid input. Empty when
// there are no errors.
std::string error_message;
};
// Parses a WebSandboxPolicy. The input is an unordered set of unique
// space-separated sandbox tokens.
// See: http://www.w3.org/TR/html5/the-iframe-element.html#attr-iframe-sandbox
//
// |ignored_flags| is used by experimental features to ignore some tokens when
// the corresponding feature is off.
//
// Supposed to be called only from a (semi-)sandboxed processes, i.e. from blink
// or from the network process. See: docs/security/rule-of-2.md.
COMPONENT_EXPORT(NETWORK_CPP)
WebSandboxFlagsParsingResult ParseWebSandboxPolicy(
const base::StringPiece& input,
mojom::WebSandboxFlags ignored_flags);
} // namespace network
#endif // SERVICES_NETWORK_PUBLIC_CPP_SANDBOX_FLAGS_H_
|