Skip to content

Commit

Permalink
PageTarget → HostTarget (#43113)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43113

Changelog: [Internal]

Renames the "Page" concept in the modern CDP backend to "Host". Now all the Target types we have are named consistently after React Native concepts (ReactHost, ReactInstance, JSI Runtime) rather than CDP/browser concepts (Page).

Reviewed By: robhogan

Differential Revision: D53945333

fbshipit-source-id: 90e8b914ba8b4927806cbdd072ca36c78fd2093f
  • Loading branch information
motiz88 authored and facebook-github-bot committed Feb 20, 2024
1 parent d6bf51c commit e9351f0
Show file tree
Hide file tree
Showing 27 changed files with 190 additions and 190 deletions.
4 changes: 2 additions & 2 deletions packages/react-native/React/Base/RCTBridge+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ RCT_EXTERN void RCTRegisterModule(Class);
@property (nonatomic, strong, readonly) RCTModuleRegistry *moduleRegistry;

/**
* The page target for this bridge, if one has been created. Exposed for RCTCxxBridge only.
* The HostTarget for this bridge, if one has been created. Exposed for RCTCxxBridge only.
*/
@property (nonatomic, assign, readonly)
#ifdef __cplusplus
facebook::react::jsinspector_modern::PageTarget *
facebook::react::jsinspector_modern::HostTarget *
#else
// The inspector infrastructure cannot be used in C code.
void *
Expand Down
14 changes: 7 additions & 7 deletions packages/react-native/React/Base/RCTBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ void RCTUIManagerSetDispatchAccessibilityManagerInitOntoMain(BOOL enabled)
kDispatchAccessibilityManagerInitOntoMain = enabled;
}

class RCTBridgePageTargetDelegate : public facebook::react::jsinspector_modern::PageTargetDelegate {
class RCTBridgeHostTargetDelegate : public facebook::react::jsinspector_modern::HostTargetDelegate {
public:
RCTBridgePageTargetDelegate(RCTBridge *bridge) : bridge_(bridge) {}
RCTBridgeHostTargetDelegate(RCTBridge *bridge) : bridge_(bridge) {}

void onReload(const PageReloadRequest &request) override
{
Expand All @@ -208,8 +208,8 @@ @interface RCTBridge () <RCTReloadListener>
@implementation RCTBridge {
NSURL *_delegateBundleURL;

std::unique_ptr<RCTBridgePageTargetDelegate> _inspectorPageDelegate;
std::shared_ptr<facebook::react::jsinspector_modern::PageTarget> _inspectorTarget;
std::unique_ptr<RCTBridgeHostTargetDelegate> _inspectorHostDelegate;
std::shared_ptr<facebook::react::jsinspector_modern::HostTarget> _inspectorTarget;
std::optional<int> _inspectorPageId;
}

Expand Down Expand Up @@ -259,7 +259,7 @@ - (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)delegate
_bundleURL = bundleURL;
_moduleProvider = block;
_launchOptions = [launchOptions copy];
_inspectorPageDelegate = std::make_unique<RCTBridgePageTargetDelegate>(self);
_inspectorHostDelegate = std::make_unique<RCTBridgeHostTargetDelegate>(self);

[self setUp];
}
Expand Down Expand Up @@ -413,7 +413,7 @@ - (void)setUp
auto &inspectorFlags = facebook::react::jsinspector_modern::InspectorFlags::getInstance();
if (inspectorFlags.getEnableModernCDPRegistry() && !_inspectorPageId.has_value()) {
_inspectorTarget =
facebook::react::jsinspector_modern::PageTarget::create(*_inspectorPageDelegate, [](auto callback) {
facebook::react::jsinspector_modern::HostTarget::create(*_inspectorHostDelegate, [](auto callback) {
RCTExecuteOnMainQueue(^{
callback();
});
Expand Down Expand Up @@ -526,7 +526,7 @@ - (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path
[self.batchedBridge registerSegmentWithId:segmentId path:path];
}

- (facebook::react::jsinspector_modern::PageTarget *)inspectorTarget
- (facebook::react::jsinspector_modern::HostTarget *)inspectorTarget
{
return _inspectorTarget.get();
}
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ - (void)start
// pointer into a member of RCTBridge! But we only use it while _reactInstance exists, meaning we
// haven't been invalidated, and therefore RCTBridge hasn't been deallocated yet.
RCTAssertMainQueue();
facebook::react::jsinspector_modern::PageTarget *parentInspectorTarget = _parentBridge.inspectorTarget;
facebook::react::jsinspector_modern::HostTarget *parentInspectorTarget = _parentBridge.inspectorTarget;

// Dispatch the instance initialization as soon as the initial module metadata has
// been collected (see initModules)
Expand Down Expand Up @@ -658,7 +658,7 @@ - (id)moduleForClass:(Class)moduleClass
}

- (void)_initializeBridge:(std::shared_ptr<JSExecutorFactory>)executorFactory
parentInspectorTarget:(facebook::react::jsinspector_modern::PageTarget *)parentInspectorTarget
parentInspectorTarget:(facebook::react::jsinspector_modern::HostTarget *)parentInspectorTarget
{
if (!self.valid) {
return;
Expand Down Expand Up @@ -691,7 +691,7 @@ - (void)_initializeBridge:(std::shared_ptr<JSExecutorFactory>)executorFactory
}

- (void)_initializeBridgeLocked:(std::shared_ptr<JSExecutorFactory>)executorFactory
parentInspectorTarget:(facebook::react::jsinspector_modern::PageTarget *)parentInspectorTarget
parentInspectorTarget:(facebook::react::jsinspector_modern::HostTarget *)parentInspectorTarget
{
std::lock_guard<std::mutex> guard(_moduleRegistryLock);

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/cxxreact/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void Instance::initializeBridge(
std::shared_ptr<JSExecutorFactory> jsef,
std::shared_ptr<MessageQueueThread> jsQueue,
std::shared_ptr<ModuleRegistry> moduleRegistry,
jsinspector_modern::PageTarget* parentInspectorTarget) {
jsinspector_modern::HostTarget* parentInspectorTarget) {
callback_ = std::move(callback);
moduleRegistry_ = std::move(moduleRegistry);
parentInspectorTarget_ = parentInspectorTarget;
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/ReactCommon/cxxreact/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class RN_EXPORT Instance : private jsinspector_modern::InstanceTargetDelegate {
std::shared_ptr<JSExecutorFactory> jsef,
std::shared_ptr<MessageQueueThread> jsQueue,
std::shared_ptr<ModuleRegistry> moduleRegistry,
jsinspector_modern::PageTarget* inspectorTarget = nullptr);
jsinspector_modern::HostTarget* inspectorTarget = nullptr);

void initializeRuntime();

Expand Down Expand Up @@ -178,7 +178,7 @@ class RN_EXPORT Instance : private jsinspector_modern::InstanceTargetDelegate {
std::shared_ptr<JSCallInvoker> jsCallInvoker_ =
std::make_shared<JSCallInvoker>();

jsinspector_modern::PageTarget* parentInspectorTarget_{nullptr};
jsinspector_modern::HostTarget* parentInspectorTarget_{nullptr};
jsinspector_modern::InstanceTarget* inspectorTarget_{nullptr};
jsinspector_modern::RuntimeTarget* runtimeInspectorTarget_{nullptr};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class HermesRuntimeAgentDelegate::Impl final : public RuntimeAgentDelegate {
* \param executionContextDescription A description of the execution context
* represented by this runtime. This is used for disambiguating the
* source/destination of CDP messages when there are multiple runtimes
* (concurrently or over the life of a Page).
* (concurrently or over the life of a Host).
* \param runtime The HermesRuntime that this agent is attached to.
* \param runtimeExecutor A callback for scheduling work on the JS thread.
* \c runtimeExecutor may drop scheduled work if the runtime is destroyed
Expand Down Expand Up @@ -155,7 +155,7 @@ class HermesRuntimeAgentDelegate::Impl final : public RuntimeAgentDelegate {
// TODO: Change to string::starts_with when we're on C++20.
if (req.method.rfind("Log.", 0) == 0) {
// Since we know Hermes doesn't do anything useful with Log messages, but
// our containing PageAgent will, just bail out early.
// our containing HostAgent will, just bail out early.
// TODO: We need a way to negotiate this more dynamically with Hermes
// through the API.
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class HermesRuntimeAgentDelegate : public RuntimeAgentDelegate {
* \param executionContextDescription A description of the execution context
* represented by this runtime. This is used for disambiguating the
* source/destination of CDP messages when there are multiple runtimes
* (concurrently or over the life of a Page).
* (concurrently or over the life of a Host).
* \param runtime The HermesRuntime that this agent is attached to.
* \param runtimeExecutor A callback for scheduling work on the JS thread.
* \c runtimeExecutor may drop scheduled work if the runtime is destroyed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ A debuggable entity that a debugger frontend can connect to.

### Target Delegate

An interface between a Target class and the underlying debuggable entity. For example, PageTargetDelegate is used by PageTarget to send page-related events to the native platform implementation.
An interface between a Target class and the underlying debuggable entity. For example, HostTargetDelegate is used by HostTarget to send host-related events to the native platform implementation.

### Target Controller

A private interface exposed by a Target class to its Sessions/Agents. For example, PageTargetController is used by PageAgent to safely access the page's PageTargetDelegate, without exposing PageTarget's other private state.
A private interface exposed by a Target class to its Sessions/Agents. For example, HostTargetController is used by HostAgent to safely access the host's HostTargetDelegate, without exposing HostTarget's other private state.

### Session

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include <folly/dynamic.h>
#include <folly/json.h>
#include <jsinspector-modern/HostAgent.h>
#include <jsinspector-modern/HostTarget.h>
#include <jsinspector-modern/InstanceAgent.h>
#include <jsinspector-modern/PageAgent.h>
#include <jsinspector-modern/PageTarget.h>

#include <chrono>

Expand All @@ -27,19 +27,19 @@ namespace facebook::react::jsinspector_modern {
static constexpr auto kModernCDPBackendNotice =
ANSI_COLOR_BG_YELLOW ANSI_WEIGHT_BOLD
"NOTE:" ANSI_WEIGHT_RESET " You are using the " ANSI_STYLE_ITALIC
"modern" ANSI_STYLE_RESET " CDP backend for React Native (PageTarget)."sv;
"modern" ANSI_STYLE_RESET " CDP backend for React Native (HostTarget)."sv;

PageAgent::PageAgent(
HostAgent::HostAgent(
FrontendChannel frontendChannel,
PageTargetController& targetController,
PageTarget::SessionMetadata sessionMetadata,
HostTargetController& targetController,
HostTarget::SessionMetadata sessionMetadata,
SessionState& sessionState)
: frontendChannel_(frontendChannel),
targetController_(targetController),
sessionMetadata_(std::move(sessionMetadata)),
sessionState_(sessionState) {}

void PageAgent::handleRequest(const cdp::PreparsedRequest& req) {
void HostAgent::handleRequest(const cdp::PreparsedRequest& req) {
bool shouldSendOKResponse = false;
bool isFinishedHandlingRequest = false;

Expand Down Expand Up @@ -113,7 +113,7 @@ void PageAgent::handleRequest(const cdp::PreparsedRequest& req) {
frontendChannel_(json);
}

void PageAgent::sendInfoLogEntry(std::string_view text) {
void HostAgent::sendInfoLogEntry(std::string_view text) {
frontendChannel_(
folly::toJson(folly::dynamic::object("method", "Log.entryAdded")(
"params",
Expand All @@ -127,7 +127,7 @@ void PageAgent::sendInfoLogEntry(std::string_view text) {
"level", "info")("text", text)))));
}

void PageAgent::setCurrentInstanceAgent(
void HostAgent::setCurrentInstanceAgent(
std::shared_ptr<InstanceAgent> instanceAgent) {
auto previousInstanceAgent = std::move(instanceAgent_);
instanceAgent_ = std::move(instanceAgent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#include "PageTarget.h"
#include "HostTarget.h"
#include "SessionState.h"

#include <jsinspector-modern/InspectorInterfaces.h>
Expand All @@ -19,32 +19,32 @@

namespace facebook::react::jsinspector_modern {

class PageTarget;
class HostTarget;
class InstanceAgent;
class InstanceTarget;

/**
* An Agent that handles requests from the Chrome DevTools Protocol for the
* given page.
* given Host.
* The constructor, destructor and all public methods must be called on the
* same thread, which is also the thread where the associated PageTarget is
* same thread, which is also the thread where the associated HostTarget is
* constructed and managed.
*/
class PageAgent final {
class HostAgent final {
public:
/**
* \param frontendChannel A channel used to send responses and events to the
* frontend.
* \param targetController An interface to the PageTarget that this agent is
* \param targetController An interface to the HostTarget that this agent is
* attached to. The caller is responsible for ensuring that the
* PageTargetDelegate and underlying PageTarget both outlive the agent.
* HostTargetDelegate and underlying HostTarget both outlive the agent.
* \param sessionMetadata Metadata about the session that created this agent.
* \param sessionState The state of the session that created this agent.
*/
PageAgent(
HostAgent(
FrontendChannel frontendChannel,
PageTargetController& targetController,
PageTarget::SessionMetadata sessionMetadata,
HostTargetController& targetController,
HostTarget::SessionMetadata sessionMetadata,
SessionState& sessionState);

/**
Expand All @@ -70,13 +70,13 @@ class PageAgent final {
* DevTools, the message will appear in the Console tab along with regular
* console messages. The difference between Log.entryAdded and
* Runtime.consoleAPICalled is that the latter requires an execution context
* ID, which does not exist at the Page level.
* ID, which does not exist at the Host level.
*/
void sendInfoLogEntry(std::string_view text);

FrontendChannel frontendChannel_;
PageTargetController& targetController_;
const PageTarget::SessionMetadata sessionMetadata_;
HostTargetController& targetController_;
const HostTarget::SessionMetadata sessionMetadata_;
std::shared_ptr<InstanceAgent> instanceAgent_;

/**
Expand Down
Loading

0 comments on commit e9351f0

Please sign in to comment.