File: batched_proxy_ipc_sender.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (124 lines) | stat: -rw-r--r-- 5,779 bytes parent folder | download | duplicates (4)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_RENDERER_HOST_BATCHED_PROXY_IPC_SENDER_H_
#define CONTENT_BROWSER_RENDERER_HOST_BATCHED_PROXY_IPC_SENDER_H_

#include <map>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/memory/safe_ref.h"
#include "content/common/content_export.h"
#include "content/public/browser/global_routing_id.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom-forward.h"
#include "third_party/blink/public/mojom/frame/frame_replication_state.mojom-forward.h"
#include "third_party/blink/public/mojom/frame/remote_frame.mojom.h"

namespace blink {
namespace mojom {
enum class TreeScopeType;
}  // namespace mojom
}  // namespace blink

namespace content {

class RenderFrameProxyHost;

// Used to batch create proxies for child frames within a `SiteInstanceGroup`.
//
// This is only used when proxies within a single `FrameTree` are created by
// `CreateProxiesForSiteInstance()`. There are 2 cases:
// (1) A subframe navigates to a new `SiteInstance`.
// (2) An opener chain created by a child/main frame navigation, in which case
// the navigating `FrameTree` will batch create proxies only for a child frame
// navigation. All other `FrameTree`s will create their own instance of
// `BatchedProxyIPCSender` to batch create proxies.
//
// `CreateProxiesForSiteInstance()` iterates through the `FrameTree` in breadth
// first order, and normally creates a proxy for a `FrameTreeNode` if needed.
// If this class is used for batch creation, a node with the necessary
// parameters for proxy creation will be added to
// `create_remote_children_params_` instead of creating the proxy
// immediately. After iterating the `FrameTree`, all child frames can be
// created with `CreateAllProxies()`. See doc in https://crbug.com/1393697 for
// more details.
//
// Note: When any frame in a frame tree navigates to a `SiteInstance` X,
// there are two cases: either (1) X is a new `SiteInstance`, in which case
// all `FrameTreeNode`s will need a new proxy, and hence we'll start creating
// proxies from the root; or (2) X is an existing `SiteInstance` that may
// already have some frames in it, in which case Chromium guarantees that all
// `FrameTreeNode`s on the page would either be actual frames in X or already
// have proxies for X. In either case, there shouldn't be a need to create
// additional proxies for just a part of a `FrameTree`, so this class can
// assume that new proxies will start to be created from the root.
class CONTENT_EXPORT BatchedProxyIPCSender {
 public:
  BatchedProxyIPCSender(
      base::SafeRef<RenderFrameProxyHost> root_proxy,
      const std::optional<base::UnguessableToken>& navigation_metrics_token);
  ~BatchedProxyIPCSender();

  // Creates a new node in `create_remote_children_params_` with all the
  // necessary parameters to create a proxy. The newly created node is in the
  // same relative position as the `FrameTreeNode` that `proxy_host` is for.
  void AddNewChildProxyCreationTask(
      base::SafeRef<RenderFrameProxyHost> proxy_host,
      const ::blink::RemoteFrameToken& token,
      const std::optional<::blink::FrameToken>& opener_frame_token,
      ::blink::mojom::TreeScopeType tree_scope_type,
      ::blink::mojom::FrameReplicationStatePtr replication_state,
      ::blink::mojom::FrameOwnerPropertiesPtr owner_properties,
      bool is_loading,
      const ::base::UnguessableToken& devtools_frame_token,
      ::blink::mojom::RemoteFrameInterfacesFromBrowserPtr
          remote_frame_interfaces,
      GlobalRoutingID parent_global_id);

  // Makes 1 IPC to the renderer to create all child frame proxies.
  void CreateAllProxies();

  // Checks if this `BatchedProxyIPCSender` will create a proxy for the
  // `RenderFrameProxyHost` corresponding to `global_id`.
  bool IsProxyCreationPending(GlobalRoutingID global_id);

 private:
  // The `RenderFrameProxyHost` for the proxy corresponding to the root of the
  // `FrameTree`. Used to make the IPC call to do the batch creation.
  base::SafeRef<RenderFrameProxyHost> root_proxy_host_;

  // The immediate children of the root node of a tree that is identical in
  // structure to the `FrameTree` this object is creating proxies for. The proxy
  // corresponding to the root node is a main frame proxy, and would have been
  // already created. Other than the root, all other nodes contain the
  // parameters needed to create the proxy for the corresponding node in the
  // FrameTree.
  std::vector<blink::mojom::CreateRemoteChildParamsPtr>
      create_remote_children_params_;

  // Maintain references to call `SetIsRenderFrameProxyCreated(true)` after
  // creating all proxies.
  std::vector<base::SafeRef<RenderFrameProxyHost>> proxy_hosts_;

  // Maps the `RenderFrameProxyHost`'s `GlobalRoutingID` to the node in
  // `create_remote_children_params_` with the params to create the
  // corresponding proxy.
  std::map<GlobalRoutingID,
           raw_ptr<blink::mojom::CreateRemoteChildParams, CtnExperimental>>
      proxy_to_child_params_;

  // If this class is used to create proxies for a navigation, this token
  // identifies the navigation for metrics purposes. It needs to be sent to the
  // renderer in the proxy creation IPC so that the renderer can record
  // appropriate navigation-related trace events and metrics. In non-navigation
  // cases like creating proxies for new subframes, this should be left as
  // nullopt.
  std::optional<base::UnguessableToken> navigation_metrics_token_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_RENDERER_HOST_BATCHED_PROXY_IPC_SENDER_H_