Mike Jackson | e2aa7af | 2023-05-17 06:45:07 | [diff] [blame] | 1 | // 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 | |
| 12 | namespace content { |
| 13 | |
| 14 | class SystemEntropyUtils { |
| 15 | public: |
| 16 | // Determines the current system entropy value for `frame_tree_node`. |
| 17 | // |
Mike Jackson | 2d7ed98 | 2023-08-17 14:27:13 | [diff] [blame] | 18 | // 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 Jackson | e2aa7af | 2023-05-17 06:45:07 | [diff] [blame] | 21 | // |
Mike Jackson | 2d7ed98 | 2023-08-17 14:27:13 | [diff] [blame] | 22 | // Returns `SystemEntropy::kNormal` for all top level navigations |
| 23 | // that occur after the first visible page has completed loading. |
Mike Jackson | e2aa7af | 2023-05-17 06:45:07 | [diff] [blame] | 24 | // |
| 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 Jackson | e2aa7af | 2023-05-17 06:45:07 | [diff] [blame] | 37 | // 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_ |