blob: fc08f41c365625dd54045501f395b5bab5640ac3 [file] [log] [blame]
Mike Jacksone2aa7af2023-05-17 06:45:071// Copyright 2023 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.
4
5#ifndef CONTENT_BROWSER_RENDERER_HOST_SYSTEM_ENTROPY_UTILS_H_
6#define CONTENT_BROWSER_RENDERER_HOST_SYSTEM_ENTROPY_UTILS_H_
7
8#include "content/browser/renderer_host/frame_tree_node.h"
9#include "content/public/common/content_client.h"
10#include "third_party/blink/public/mojom/navigation/system_entropy.mojom.h"
11
12namespace content {
13
14class SystemEntropyUtils {
15 public:
16 // Determines the current system entropy value for `frame_tree_node`.
17 //
Mike Jackson2d7ed982023-08-17 14:27:1318 // Returns `SystemEntropy::kHigh` for all top level navigations that
19 // occur between the start of the browser process up until the first
20 // visible page completes loading.
Mike Jacksone2aa7af2023-05-17 06:45:0721 //
Mike Jackson2d7ed982023-08-17 14:27:1322 // Returns `SystemEntropy::kNormal` for all top level navigations
23 // that occur after the first visible page has completed loading.
Mike Jacksone2aa7af2023-05-17 06:45:0724 //
25 // Returns `SystemEntropy::kEmpty` for all framed navigations, or if the
26 // `suggested_system_entropy` is `SystemEntropy::kEmpty`.
27 static blink::mojom::SystemEntropy ComputeSystemEntropyForFrameTreeNode(
28 FrameTreeNode* frame_tree_node,
29 blink::mojom::SystemEntropy suggested_system_entropy) {
30 // If the suggested system entropy is `SystemEntropy::kEmpty`, or this is
31 // a framed navigation, return `SystemEntropy::kEmpty`.
32 if (suggested_system_entropy == blink::mojom::SystemEntropy::kEmpty ||
33 !frame_tree_node->IsOutermostMainFrame()) {
34 return blink::mojom::SystemEntropy::kEmpty;
35 }
36
Mike Jacksone2aa7af2023-05-17 06:45:0737 // During browser startup, return `SystemEntropy::kHigh`.
38 if (!GetContentClient()->browser()->IsBrowserStartupComplete()) {
39 return blink::mojom::SystemEntropy::kHigh;
40 }
41
42 CHECK_NE(suggested_system_entropy, blink::mojom::SystemEntropy::kEmpty);
43 return suggested_system_entropy;
44 }
45};
46} // namespace content
47
48#endif // CONTENT_BROWSER_RENDERER_HOST_SYSTEM_ENTROPY_UTILS_H_