Commit fade9662 authored by Chris Hamilton's avatar Chris Hamilton Committed by Commit Bot

Add strongly typed frame token accessors to blink.

Further CLs will migrate blink code to use these bit by bit.

BUG=1096617

Change-Id: Iceb0090a4ea835cf5a524a7333da65068ee7afb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363552Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Chris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799594}
parent 8d1ed9ae
......@@ -33,6 +33,7 @@
#include <memory>
#include "cc/paint/paint_canvas.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/frame/tree_scope_type.mojom-shared.h"
#include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom-shared.h"
#include "third_party/blink/public/platform/web_common.h"
......@@ -72,7 +73,9 @@ class BLINK_EXPORT WebFrame {
// Returns the number of live WebFrame objects, used for leak checking.
static int InstanceCount();
// TODO(crbug.com/1096617): Remove the UnguessableToken version of this.
static WebFrame* FromFrameToken(const base::UnguessableToken&);
static WebFrame* FromFrameToken(const FrameToken&);
virtual bool IsWebLocalFrame() const = 0;
virtual WebLocalFrame* ToWebLocalFrame() = 0;
......@@ -155,6 +158,7 @@ class BLINK_EXPORT WebFrame {
// This identifier represents the stable identifier between a
// LocalFrame <--> RenderFrameHostImpl or a
// RemoteFrame <--> RenderFrameProxyHost in the browser process.
// TODO(crbug.com/1096617): Make this return a FrameToken instead.
const base::UnguessableToken& GetFrameToken() const { return frame_token_; }
#if INSIDE_BLINK
......
......@@ -172,6 +172,10 @@ class WebLocalFrame : public WebFrame {
// Basic properties ---------------------------------------------------
LocalFrameToken GetLocalFrameToken() const {
return LocalFrameToken(GetFrameToken());
}
virtual WebDocument GetDocument() const = 0;
// The name of this frame. If no name is given, empty string is returned.
......
......@@ -7,6 +7,7 @@
#include "services/network/public/mojom/content_security_policy.mojom-shared.h"
#include "third_party/blink/public/common/feature_policy/feature_policy.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/ad_tagging/ad_frame.mojom-shared.h"
#include "third_party/blink/public/mojom/frame/frame_owner_element_type.mojom-shared.h"
#include "third_party/blink/public/mojom/frame/user_activation_notification_type.mojom-shared.h"
......@@ -161,6 +162,10 @@ class WebRemoteFrame : public WebFrame {
// session restore state for this frame.
virtual WebString UniqueName() const = 0;
RemoteFrameToken GetRemoteFrameToken() const {
return RemoteFrameToken(GetFrameToken());
}
protected:
explicit WebRemoteFrame(mojom::TreeScopeType scope,
const base::UnguessableToken& frame_token)
......
......@@ -78,6 +78,14 @@ Frame* Frame::ResolveFrame(const base::UnguessableToken& frame_token) {
return nullptr;
}
// static
Frame* Frame::ResolveFrame(const FrameToken& frame_token) {
if (frame_token.Is<RemoteFrameToken>())
return RemoteFrame::FromFrameToken(frame_token.GetAs<RemoteFrameToken>());
DCHECK(frame_token.Is<LocalFrameToken>());
return LocalFrame::FromFrameToken(frame_token.GetAs<LocalFrameToken>());
}
Frame::~Frame() {
InstanceCounters::DecrementCounter(InstanceCounters::kFrameCounter);
DCHECK(!owner_);
......
......@@ -36,6 +36,7 @@
#include "third_party/blink/public/common/feature_policy/feature_policy_features.h"
#include "third_party/blink/public/common/frame/user_activation_state.h"
#include "third_party/blink/public/common/frame/user_activation_update_source.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/ad_tagging/ad_frame.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/frame/user_activation_notification_type.mojom-blink-forward.h"
......@@ -87,7 +88,9 @@ class CORE_EXPORT Frame : public GarbageCollected<Frame> {
public:
// Returns the Frame instance for the given |frame_token|.
// Note that this Frame can be either a LocalFrame or Remote instance.
// TODO(crbug.com/1096617): Remove the UnguessableToken version of this.
static Frame* ResolveFrame(const base::UnguessableToken& frame_token);
static Frame* ResolveFrame(const FrameToken& frame_token);
virtual ~Frame();
......@@ -287,6 +290,7 @@ class CORE_EXPORT Frame : public GarbageCollected<Frame> {
// This identifier represents the stable identifier between a
// LocalFrame <--> RenderFrameHostImpl or a
// RemoteFrame <--> RenderFrameProxyHost in the browser process.
// TODO(crbug.com/1096617): Make this return a FrameToken instead.
const base::UnguessableToken& GetFrameToken() const { return frame_token_; }
bool GetVisibleToHitTesting() const { return visible_to_hit_testing_; }
......
......@@ -337,6 +337,11 @@ LocalFrame* LocalFrame::FromFrameToken(
return it == local_frames_map.end() ? nullptr : it->value.Get();
}
// static
LocalFrame* LocalFrame::FromFrameToken(const LocalFrameToken& frame_token) {
return FromFrameToken(frame_token.value());
}
void LocalFrame::Init(Frame* opener) {
CoreInitializer::GetInstance().InitLocalFrame(*this);
......
......@@ -148,7 +148,9 @@ class CORE_EXPORT LocalFrame final
public mojom::blink::HighPriorityLocalFrame {
public:
// Returns the LocalFrame instance for the given |frame_token|.
// TODO(crbug.com/1096617): Remove the UnguessableToken version of this.
static LocalFrame* FromFrameToken(const base::UnguessableToken& frame_token);
static LocalFrame* FromFrameToken(const LocalFrameToken& frame_token);
// For a description of |inheriting_agent_factory| go see the comment on the
// Frame constructor.
......@@ -672,6 +674,10 @@ class CORE_EXPORT LocalFrame final
return optimization_guide_hints_.get();
}
LocalFrameToken GetLocalFrameToken() const {
return LocalFrameToken(GetFrameToken());
}
private:
friend class FrameNavigationDisabler;
FRIEND_TEST_ALL_PREFIXES(LocalFrameTest, CharacterIndexAtPointWithPinchZoom);
......
......@@ -83,6 +83,11 @@ RemoteFrame* RemoteFrame::FromFrameToken(
return it == remote_frames_map.end() ? nullptr : it->value.Get();
}
// static
RemoteFrame* RemoteFrame::FromFrameToken(const RemoteFrameToken& frame_token) {
return FromFrameToken(frame_token.value());
}
RemoteFrame::RemoteFrame(
RemoteFrameClient* client,
Page& page,
......
......@@ -37,7 +37,9 @@ class CORE_EXPORT RemoteFrame final : public Frame,
public mojom::blink::RemoteFrame {
public:
// Returns the RemoteFrame for the given |frame_token|.
// TODO(crbug.com/1096617): Remove the UnguessableToken version of this.
static RemoteFrame* FromFrameToken(const base::UnguessableToken& frame_token);
static RemoteFrame* FromFrameToken(const RemoteFrameToken& frame_token);
// For a description of |inheriting_agent_factory| go see the comment on the
// Frame constructor.
......@@ -178,6 +180,10 @@ class CORE_EXPORT RemoteFrame final : public Frame,
// Indicate that this frame was attached as a MainFrame.
void WasAttachedAsRemoteMainFrame();
RemoteFrameToken GetRemoteFrameToken() const {
return RemoteFrameToken(GetFrameToken());
}
private:
// Frame protected overrides:
void DetachImpl(FrameDetachType) override;
......
......@@ -595,6 +595,12 @@ WebFrame* WebFrame::FromFrameToken(const base::UnguessableToken& frame_token) {
return WebFrame::FromFrame(frame);
}
// static
WebFrame* WebFrame::FromFrameToken(const FrameToken& frame_token) {
auto* frame = Frame::ResolveFrame(frame_token);
return WebFrame::FromFrame(frame);
}
WebLocalFrame* WebLocalFrame::FrameForCurrentContext() {
v8::Local<v8::Context> context =
v8::Isolate::GetCurrent()->GetCurrentContext();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment