[cr144] LocalFrame not Supplementable

Chromium changes:
https://chromium.googlesource.com/chromium/src/+/0f6376931bf3fb3d504a646fe904f3dc2287faa6
https://chromium.googlesource.com/chromium/src/+/209a1e822a43055ed8beff03a552a492ea024d2f

commit 0f6376931bf3fb3d504a646fe904f3dc2287faa6
Author: Steinar H. Gunderson <sesse@chromium.org>
Date:   Fri Nov 14 06:12:48 2025 -0800

    Make LocalFrame less Supplementable.

    Part of Supplementable cleanup. Done with a script followed by
    human cleanup/review and git cl format.

    There's one case left that we haven't solved, due to issues with
    diamond inheritance and ambiguous casts. We will deal with that
    later.

    Bug: 460165754
    Change-Id: I94e843232ec47b8aa07c49877a4b8aa539daa08e
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7146310
    Auto-Submit: Steinar H Gunderson <sesse@chromium.org>
    Reviewed-by: Anders Hartvoll Ruud <andruud@chromium.org>
    Commit-Queue: Steinar H Gunderson <sesse@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1544916}

commit 209a1e822a43055ed8beff03a552a492ea024d2f
Author: Steinar H. Gunderson <sesse@chromium.org>
Date:   Fri Nov 14 06:13:02 2025 -0800

    Make LocalFrame not Supplementable.

    Part of Supplementable cleanup. Done with a script followed by
    human cleanup/review and git cl format.

    This required extending ForwardDeclaredMember with an extra
    (optional) parameter to support supplements that inherit twice
    from GarbageCollectedMixin.

    Bug: 460165754
    Change-Id: Ic8ac4b3dd20810b77943a5b36955cbc597a7e82f
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7151118
    Reviewed-by: Anders Hartvoll Ruud <andruud@chromium.org>
    Commit-Queue: Steinar H Gunderson <sesse@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1544917}
This commit is contained in:
Claudio DeSouza
2025-12-21 17:12:38 -05:00
committed by Emerick Rogul
parent 32f9f997bc
commit dfd55169f6
6 changed files with 49 additions and 47 deletions
@@ -8,6 +8,10 @@
class SkBitmap;
namespace blink {
class PageGraph;
} // namespace blink
#define CopyImageAtViewportPoint \
CopyImageAtViewportPoint_UnUsed() {} \
SkBitmap GetImageAtViewportPoint(const gfx::Point& viewport_point); \
@@ -17,7 +21,24 @@ class SkBitmap;
ScriptEnabled(const KURL& script_url); \
bool ScriptEnabled_ChromiumImpl
#define PerformSpellCheck \
PerformSpellCheck(); \
ForwardDeclaredMember<PageGraph> GetPageGraph() const { \
return page_graph_; \
} \
void SetPageGraph(ForwardDeclaredMember<PageGraph> page_graph) { \
page_graph_ = page_graph; \
} \
void Unused
#define link_preview_triggerer_ \
link_preview_triggerer_; \
ForwardDeclaredMember<PageGraph> page_graph_
#include <third_party/blink/renderer/core/frame/local_frame.h> // IWYU pragma: export
#undef link_preview_triggerer_
#undef PerformSpellCheck
#undef ScriptEnabled
#undef CopyImageAtViewportPoint
@@ -20,7 +20,7 @@ protocol::Response InspectorPageAgent::generatePageGraph(String* data) {
return protocol::Response::ServerError("No main frame found");
}
PageGraph* page_graph = blink::PageGraph::From(*main_frame);
PageGraph* page_graph = main_frame->GetPageGraph();
if (!page_graph) {
return protocol::Response::ServerError("No Page Graph for main frame");
}
@@ -41,7 +41,7 @@ protocol::Response InspectorPageAgent::generatePageGraphNodeReport(
return protocol::Response::ServerError("No main frame found");
}
PageGraph* page_graph = blink::PageGraph::From(*main_frame);
PageGraph* page_graph = main_frame->GetPageGraph();
if (!page_graph) {
return protocol::Response::ServerError("No Page Graph for main frame");
}
@@ -0,0 +1,12 @@
diff --git a/third_party/blink/renderer/core/frame/local_frame.cc b/third_party/blink/renderer/core/frame/local_frame.cc
index 3805db629d92c2b61b3475a18a0c079f7e7a752f..10b43cd8c2bb5da716d5d4789c026313b1474287 100644
--- a/third_party/blink/renderer/core/frame/local_frame.cc
+++ b/third_party/blink/renderer/core/frame/local_frame.cc
@@ -538,6 +538,7 @@ void LocalFrame::Trace(Visitor* visitor) const {
visitor->Trace(remote_object_gateway_factory_impl_);
visitor->Trace(remote_object_gateway_impl_);
visitor->Trace(text_suggestion_backend_impl_);
+ visitor->Trace(page_graph_);
Frame::Trace(visitor);
visitor->Trace(dev_tools_frontend_impl_);
}
@@ -1,21 +0,0 @@
diff --git a/third_party/blink/renderer/core/frame/local_frame.h b/third_party/blink/renderer/core/frame/local_frame.h
index 648455136f6a70a6c6b9c93febec6f6071bd7447..cba31394e4a09ccb0767ce668224a93061ba1b10 100644
--- a/third_party/blink/renderer/core/frame/local_frame.h
+++ b/third_party/blink/renderer/core/frame/local_frame.h
@@ -193,7 +193,7 @@ class CORE_EXPORT LocalFrame final
: public Frame,
public FrameScheduler::Delegate,
public BackForwardCacheLoaderHelperImpl::Delegate,
- public Supplementable<LocalFrame, 5> {
+ public Supplementable<LocalFrame, 6> {
public:
enum class Supplements {
kRemoteObjectGatewayImpl = 0,
@@ -201,6 +201,7 @@ class CORE_EXPORT LocalFrame final
kImageDownloaderImpl = 2,
kTextSuggestionBackendImpl = 3,
kDevToolsFrontendImpl = 4
+ , kBravePageGraph,
};
// Returns the LocalFrame instance for the given |frame_token|.
@@ -240,9 +240,9 @@ PageGraph* GetPageGraphFromIsolate(v8::Isolate* isolate) {
if (auto* top_local_frame =
blink::DynamicTo<blink::LocalFrame>(&frame->Tree().Top())) {
return blink::PageGraph::From(*top_local_frame);
return top_local_frame->GetPageGraph();
} else {
return blink::PageGraph::From(*frame);
return frame->GetPageGraph();
}
}
@@ -340,17 +340,12 @@ static void AssignSecurityOriginToNodeDOMRoot(
} // namespace
// static
PageGraph* PageGraph::From(LocalFrame& frame) {
return Supplement<LocalFrame>::From<PageGraph>(frame);
}
// static
void PageGraph::ProvideTo(LocalFrame& frame) {
if (!base::FeatureList::IsEnabled(brave_page_graph::features::kPageGraph)) {
return;
}
CHECK(!PageGraph::From(frame));
CHECK(!frame.GetPageGraph());
CHECK(frame.IsLocalRoot());
Page* page = frame.GetPage();
CHECK(page);
@@ -362,8 +357,8 @@ void PageGraph::ProvideTo(LocalFrame& frame) {
blink::Node* initiator_node =
blink::DOMNodeIds::NodeForId(initiator_dom_node_id);
if (initiator_node) {
auto* initiator_tree_page_graph = Supplement<LocalFrame>::From<PageGraph>(
*initiator_node->TreeRoot().GetDocument().GetFrame());
auto initiator_tree_page_graph =
initiator_node->TreeRoot().GetDocument().GetFrame()->GetPageGraph();
if (initiator_tree_page_graph) {
frame.GetProbeSink()->AddPageGraph(initiator_tree_page_graph);
return;
@@ -377,8 +372,7 @@ void PageGraph::ProvideTo(LocalFrame& frame) {
if (!main_local_frame) {
continue;
}
auto* related_page_graph =
Supplement<LocalFrame>::From<PageGraph>(main_local_frame);
auto related_page_graph = main_local_frame->GetPageGraph();
if (related_page_graph) {
frame.GetProbeSink()->AddPageGraph(related_page_graph);
return;
@@ -391,8 +385,7 @@ void PageGraph::ProvideTo(LocalFrame& frame) {
if (!main_local_frame) {
continue;
}
auto* ordinary_page_graph =
Supplement<LocalFrame>::From<PageGraph>(main_local_frame);
auto ordinary_page_graph = main_local_frame->GetPageGraph();
if (ordinary_page_graph) {
frame.GetProbeSink()->AddPageGraph(ordinary_page_graph);
return;
@@ -402,11 +395,11 @@ void PageGraph::ProvideTo(LocalFrame& frame) {
// Create a new PageGraph for the current frame.
PageGraph* page_graph = MakeGarbageCollected<PageGraph>(frame);
frame.GetProbeSink()->AddPageGraph(page_graph);
Supplement<LocalFrame>::ProvideTo(frame, page_graph);
frame.SetPageGraph(page_graph);
}
PageGraph::PageGraph(LocalFrame& local_frame)
: Supplement<LocalFrame>(local_frame),
: local_frame_(local_frame),
frame_id_(GetFrameId(local_frame)),
script_tracker_(this),
request_tracker_(this) {
@@ -444,7 +437,7 @@ PageGraph::PageGraph(LocalFrame& local_frame)
PageGraph::~PageGraph() = default;
void PageGraph::Trace(blink::Visitor* visitor) const {
Supplement<LocalFrame>::Trace(visitor);
visitor->Trace(local_frame_);
visitor->Trace(execution_context_nodes_);
visitor->Trace(processed_js_urls_);
}
@@ -968,8 +961,7 @@ void PageGraph::ConsoleMessageAdded(blink::ConsoleMessage* console_message) {
blink::LocalFrame* frame = console_message->Frame();
blink::Document* document = frame ? frame->GetDocument() : nullptr;
if (!document) {
frame = GetSupplementable();
document = frame->GetDocument();
document = local_frame_->GetDocument();
if (!document) {
return nullptr;
}
@@ -2171,7 +2163,7 @@ NodeBinding* PageGraph::GetBindingNode(const Binding binding,
}
bool PageGraph::IsRootFrame() const {
return GetSupplementable()->IsLocalRoot();
return local_frame_->IsLocalRoot();
}
} // namespace blink
@@ -116,12 +116,9 @@ enum class ResourceType : uint8_t;
// https://docs.google.com/presentation/d/1pHjF3TNCX--j0ss3SK09pXlVOFK0Cdq6HkMcOzcov1o/edit#slide=id.g4983c55b2d55fcc7_42
class CORE_EXPORT PageGraph : public GarbageCollected<PageGraph>,
public Supplement<LocalFrame>,
public GarbageCollectedMixin,
public brave_page_graph::PageGraphContext {
public:
static constexpr auto kSupplementIndex =
LocalFrame::Supplements::kBravePageGraph;
static PageGraph* From(LocalFrame&);
static void ProvideTo(LocalFrame&);
explicit PageGraph(LocalFrame& local_frame);
@@ -457,6 +454,7 @@ class CORE_EXPORT PageGraph : public GarbageCollected<PageGraph>,
// frame tree.
bool IsRootFrame() const;
blink::Member<LocalFrame> local_frame_;
// The blink assigned frame id for the local root's frame.
const brave_page_graph::FrameId frame_id_;
// Script tracker helper.