Skip to content

Commit

Permalink
(multiple CLs): Use an opaque type for FrameTreeNode IDs
Browse files Browse the repository at this point in the history
5807683: Use an opaque type for FrameTreeNode IDs, part 1 | https://chromium-review.googlesource.com/c/chromium/src/+/5807683
5829746: Use an opaque type for FrameTreeNode IDs, part 2 | https://chromium-review.googlesource.com/c/chromium/src/+/5829746
5836903: Use an opaque type for FrameTreeNode IDs, part 7 | https://chromium-review.googlesource.com/c/chromium/src/+/5836903
5837249: Use an opaque type for FrameTreeNode IDs, part 8 | https://chromium-review.googlesource.com/c/chromium/src/+/5837249
5836564: Use an opaque type for FrameTreeNode IDs, part 12 | https://chromium-review.googlesource.com/c/chromium/src/+/5836564
5837180: Use an opaque type for FrameTreeNode IDs, part 15 | https://chromium-review.googlesource.com/c/chromium/src/+/5837180
  • Loading branch information
clavin committed Sep 18, 2024
1 parent 0ac4852 commit 1dd67f5
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 24 deletions.
5 changes: 3 additions & 2 deletions shell/browser/api/electron_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@ bool IsDevToolsFileSystemAdded(content::WebContents* web_contents,

content::RenderFrameHost* GetRenderFrameHost(
content::NavigationHandle* navigation_handle) {
int frame_tree_node_id = navigation_handle->GetFrameTreeNodeId();
content::FrameTreeNodeId frame_tree_node_id =
navigation_handle->GetFrameTreeNodeId();
content::FrameTreeNode* frame_tree_node =
content::FrameTreeNode::GloballyFindByID(frame_tree_node_id);
content::RenderFrameHostManager* render_manager =
Expand Down Expand Up @@ -1698,7 +1699,7 @@ void WebContents::RenderFrameHostChanged(content::RenderFrameHost* old_host,
}
}

void WebContents::FrameDeleted(int frame_tree_node_id) {
void WebContents::FrameDeleted(content::FrameTreeNodeId frame_tree_node_id) {
auto* web_frame = WebFrameMain::FromFrameTreeNodeId(frame_tree_node_id);
if (web_frame)
web_frame->Destroyed();
Expand Down
3 changes: 2 additions & 1 deletion shell/browser/api/electron_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "content/common/frame.mojom-forward.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/frame_tree_node_id.h"
#include "content/public/browser/javascript_dialog_manager.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/web_contents_delegate.h"
Expand Down Expand Up @@ -648,7 +649,7 @@ class WebContents final : public ExclusiveAccessContext,
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
void RenderFrameHostChanged(content::RenderFrameHost* old_host,
content::RenderFrameHost* new_host) override;
void FrameDeleted(int frame_tree_node_id) override;
void FrameDeleted(content::FrameTreeNodeId frame_tree_node_id) override;
void RenderViewDeleted(content::RenderViewHost*) override;
void PrimaryMainFrameRenderProcessGone(
base::TerminationStatus status) override;
Expand Down
4 changes: 2 additions & 2 deletions shell/browser/api/electron_api_web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace electron::api {

void WebContents::DetachFromOuterFrame() {
// See detach_webview_frame.patch on how to detach.
int frame_tree_node_id =
content::FrameTreeNodeId frame_tree_node_id =
static_cast<content::WebContentsImpl*>(web_contents())
->GetOuterDelegateFrameTreeNodeId();
if (frame_tree_node_id != content::FrameTreeNode::kFrameTreeNodeInvalidId) {
if (!frame_tree_node_id) {
auto* node = content::FrameTreeNode::GloballyFindByID(frame_tree_node_id);
DCHECK(node->parent());
node->frame_tree().RemoveFrame(node);
Expand Down
11 changes: 8 additions & 3 deletions shell/browser/api/electron_api_web_frame_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/logging.h"
#include "base/no_destructor.h"
#include "content/browser/renderer_host/render_frame_host_impl.h" // nogncheck
#include "content/public/browser/frame_tree_node_id.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/common/isolated_world_ids.h"
#include "electron/shell/common/api/api.mojom.h"
Expand Down Expand Up @@ -56,15 +57,19 @@ struct Converter<blink::mojom::PageVisibilityState> {

namespace electron::api {

typedef std::unordered_map<int, WebFrameMain*> WebFrameMainIdMap;
typedef std::unordered_map<content::FrameTreeNodeId,
WebFrameMain*,
content::FrameTreeNodeId::Hasher>
WebFrameMainIdMap;

WebFrameMainIdMap& GetWebFrameMainMap() {
static base::NoDestructor<WebFrameMainIdMap> instance;
return *instance;
}

// static
WebFrameMain* WebFrameMain::FromFrameTreeNodeId(int frame_tree_node_id) {
WebFrameMain* WebFrameMain::FromFrameTreeNodeId(
content::FrameTreeNodeId frame_tree_node_id) {
WebFrameMainIdMap& frame_map = GetWebFrameMainMap();
auto iter = frame_map.find(frame_tree_node_id);
auto* web_frame = iter == frame_map.end() ? nullptr : iter->second;
Expand Down Expand Up @@ -270,7 +275,7 @@ void WebFrameMain::PostMessage(v8::Isolate* isolate,
std::move(transferable_message));
}

int WebFrameMain::FrameTreeNodeID() const {
content::FrameTreeNodeId WebFrameMain::FrameTreeNodeID() const {
return frame_tree_node_id_;
}

Expand Down
8 changes: 5 additions & 3 deletions shell/browser/api/electron_api_web_frame_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/process/process.h"
#include "content/public/browser/frame_tree_node_id.h"
#include "gin/wrappable.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
Expand Down Expand Up @@ -53,7 +54,8 @@ class WebFrameMain final : public gin::Wrappable<WebFrameMain>,
static gin::Handle<WebFrameMain> FromOrNull(
v8::Isolate* isolate,
content::RenderFrameHost* render_frame_host);
static WebFrameMain* FromFrameTreeNodeId(int frame_tree_node_id);
static WebFrameMain* FromFrameTreeNodeId(
content::FrameTreeNodeId frame_tree_node_id);
static WebFrameMain* FromRenderFrameHost(
content::RenderFrameHost* render_frame_host);

Expand Down Expand Up @@ -110,7 +112,7 @@ class WebFrameMain final : public gin::Wrappable<WebFrameMain>,
v8::Local<v8::Value> message_value,
std::optional<v8::Local<v8::Value>> transfer);

int FrameTreeNodeID() const;
content::FrameTreeNodeId FrameTreeNodeID() const;
std::string Name() const;
base::ProcessId OSProcessID() const;
int ProcessID() const;
Expand All @@ -129,7 +131,7 @@ class WebFrameMain final : public gin::Wrappable<WebFrameMain>,
mojo::Remote<mojom::ElectronRenderer> renderer_api_;
mojo::PendingReceiver<mojom::ElectronRenderer> pending_receiver_;

int frame_tree_node_id_;
content::FrameTreeNodeId frame_tree_node_id_;

raw_ptr<content::RenderFrameHost> render_frame_ = nullptr;

Expand Down
8 changes: 4 additions & 4 deletions shell/browser/electron_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ void HandleExternalProtocolInUI(
bool ElectronBrowserClient::HandleExternalProtocol(
const GURL& url,
content::WebContents::Getter web_contents_getter,
int frame_tree_node_id,
content::FrameTreeNodeId frame_tree_node_id,
content::NavigationUIData* navigation_data,
bool is_primary_main_frame,
bool is_in_fenced_frame_tree,
Expand Down Expand Up @@ -1033,7 +1033,7 @@ blink::UserAgentMetadata ElectronBrowserClient::GetUserAgentMetadata() {
mojo::PendingRemote<network::mojom::URLLoaderFactory>
ElectronBrowserClient::CreateNonNetworkNavigationURLLoaderFactory(
const std::string& scheme,
int frame_tree_node_id) {
content::FrameTreeNodeId frame_tree_node_id) {
content::WebContents* web_contents =
content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
content::BrowserContext* context = web_contents->GetBrowserContext();
Expand Down Expand Up @@ -1361,7 +1361,7 @@ void ElectronBrowserClient::WillCreateURLLoaderFactory(
std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
ElectronBrowserClient::WillCreateURLLoaderRequestInterceptors(
content::NavigationUIData* navigation_ui_data,
int frame_tree_node_id,
content::FrameTreeNodeId frame_tree_node_id,
int64_t navigation_id,
bool force_no_https_upgrade,
scoped_refptr<base::SequencedTaskRunner> navigation_response_task_runner) {
Expand Down Expand Up @@ -1664,7 +1664,7 @@ ElectronBrowserClient::CreateURLLoaderThrottles(
content::BrowserContext* browser_context,
const base::RepeatingCallback<content::WebContents*()>& wc_getter,
content::NavigationUIData* navigation_ui_data,
int frame_tree_node_id,
content::FrameTreeNodeId frame_tree_node_id,
absl::optional<int64_t> navigation_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);

Expand Down
12 changes: 7 additions & 5 deletions shell/browser/electron_browser_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/memory/raw_ptr.h"
#include "base/synchronization/lock.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/frame_tree_node_id.h"
#include "content/public/browser/render_process_host_observer.h"
#include "content/public/browser/web_contents.h"
#include "electron/buildflags/buildflags.h"
Expand Down Expand Up @@ -200,8 +201,9 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
std::vector<base::FilePath> GetNetworkContextsParentDirectory() override;
std::string GetProduct() override;
mojo::PendingRemote<network::mojom::URLLoaderFactory>
CreateNonNetworkNavigationURLLoaderFactory(const std::string& scheme,
int frame_tree_node_id) override;
CreateNonNetworkNavigationURLLoaderFactory(
const std::string& scheme,
content::FrameTreeNodeId frame_tree_node_id) override;
void RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
content::BrowserContext* browser_context,
NonNetworkURLLoaderFactoryMap* factories) override;
Expand Down Expand Up @@ -242,7 +244,7 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
WillCreateURLLoaderRequestInterceptors(
content::NavigationUIData* navigation_ui_data,
int frame_tree_node_id,
content::FrameTreeNodeId frame_tree_node_id,
int64_t navigation_id,
bool force_no_https_upgrade,
scoped_refptr<base::SequencedTaskRunner> navigation_response_task_runner)
Expand All @@ -265,7 +267,7 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
bool HandleExternalProtocol(
const GURL& url,
content::WebContents::Getter web_contents_getter,
int frame_tree_node_id,
content::FrameTreeNodeId frame_tree_node_id,
content::NavigationUIData* navigation_data,
bool is_primary_main_frame,
bool is_in_fenced_frame_tree,
Expand Down Expand Up @@ -294,7 +296,7 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
content::BrowserContext* browser_context,
const base::RepeatingCallback<content::WebContents*()>& wc_getter,
content::NavigationUIData* navigation_ui_data,
int frame_tree_node_id,
content::FrameTreeNodeId frame_tree_node_id,
std::optional<int64_t> navigation_id) override;
base::flat_set<std::string> GetPluginMimeTypesWithExternalHandlers(
content::BrowserContext* browser_context) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <utility>

#include "content/public/browser/browser_thread.h"
#include "content/public/browser/frame_tree_node_id.h"
#include "content/public/browser/web_contents.h"
#include "electron/buildflags/buildflags.h"
#include "extensions/browser/extension_registry.h"
Expand All @@ -29,7 +30,7 @@ void StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent(
const std::string& extension_id,
const std::string& stream_id,
bool embedded,
int frame_tree_node_id,
content::FrameTreeNodeId frame_tree_node_id,
blink::mojom::TransferrableURLLoaderPtr transferrable_loader,
const GURL& original_url,
const std::string& internal_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <string>

#include "content/public/browser/frame_tree_node_id.h"
#include "third_party/blink/public/mojom/loader/transferrable_url_loader.mojom-forward.h"

class GURL;
Expand All @@ -26,7 +27,7 @@ class StreamsPrivateAPI {
const std::string& extension_id,
const std::string& stream_id,
bool embedded,
int frame_tree_node_id,
content::FrameTreeNodeId frame_tree_node_id,
blink::mojom::TransferrableURLLoaderPtr transferrable_loader,
const GURL& original_url,
const std::string& internal_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/frame_tree_node_id.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/common/user_agent.h"
#include "extensions/browser/api/core_extensions_browser_api_provider.h"
Expand Down Expand Up @@ -271,7 +272,7 @@ ElectronExtensionsBrowserClient::GetProcessManagerDelegate() const {
mojo::PendingRemote<network::mojom::URLLoaderFactory>
ElectronExtensionsBrowserClient::GetControlledFrameEmbedderURLLoader(
const url::Origin& app_origin,
int frame_tree_node_id,
content::FrameTreeNodeId frame_tree_node_id,
content::BrowserContext* browser_context) {
return mojo::PendingRemote<network::mojom::URLLoaderFactory>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include <vector>

#include "content/public/browser/frame_tree_node_id.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/kiosk/kiosk_delegate.h"
#include "services/network/public/cpp/resource_request.h"
Expand Down Expand Up @@ -111,7 +112,7 @@ class ElectronExtensionsBrowserClient
mojo::PendingRemote<network::mojom::URLLoaderFactory>
GetControlledFrameEmbedderURLLoader(
const url::Origin& app_origin,
int frame_tree_node_id,
content::FrameTreeNodeId frame_tree_node_id,
content::BrowserContext* browser_context) override;
std::unique_ptr<extensions::ExtensionHostDelegate>
CreateExtensionHostDelegate() override;
Expand Down

0 comments on commit 1dd67f5

Please sign in to comment.