Permalink
Browse files

Add AppIdentity and DeviceIdentity to Inspector

Reviewed By: Hypuk

Differential Revision: D5924011

fbshipit-source-id: a81d420dbe1a5ede203d2fa313548e19664b9587
  • Loading branch information...
pakoito authored and facebook-github-bot committed Oct 3, 2017
1 parent 96f23e7 commit da14fad829732b638373464b55a79d3b143116a9
@@ -328,9 +328,13 @@ - (void)start
BOOL useCustomJSC =
[self.delegate respondsToSelector:@selector(shouldBridgeUseCustomJSC:)] &&
[self.delegate shouldBridgeUseCustomJSC:self];
NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// The arg is a cache dir. It's not used with standard JSC.
executorFactory.reset(new JSCExecutorFactory(folly::dynamic::object
("OwnerIdentity", "ReactNative")
("AppIdentity", [(escapedAppName ?: @"unknown") UTF8String])
("DeviceIdentity", [(escapedDeviceName ?: @"unknown") UTF8String])
("UseCustomJSC", (bool)useCustomJSC)
#if RCT_PROFILE
("StartSamplingProfilerOnInit", (bool)self.devSettings.startSamplingProfilerOnLaunch)
@@ -73,7 +73,7 @@ public CatalystInstance build() {
}
JavaScriptExecutor executor = null;
try {
executor = new JSCJavaScriptExecutorFactory().create();
executor = new JSCJavaScriptExecutorFactory("ReactTestHelperApp", "ReactTestHelperDevice").create();
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -2,8 +2,12 @@
package com.facebook.react;
import static com.facebook.react.modules.systeminfo.AndroidInfoHelpers.getFriendlyDeviceName;
import android.app.Activity;
import android.app.Application;
import android.net.Uri;
import android.os.Build;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.JSBundleLoader;
import com.facebook.react.bridge.JSCJavaScriptExecutorFactory;
@@ -262,12 +266,15 @@ public ReactInstanceManager build() {
mUIImplementationProvider = new UIImplementationProvider();
}
String appName = Uri.encode(mApplication.getPackageName());
String deviceName = Uri.encode(getFriendlyDeviceName());
return new ReactInstanceManager(
mApplication,
mCurrentActivity,
mDefaultHardwareBackBtnHandler,
mJavaScriptExecutorFactory == null
? new JSCJavaScriptExecutorFactory()
? new JSCJavaScriptExecutorFactory(appName, deviceName)
: mJavaScriptExecutorFactory,
(mJSBundleLoader == null && mJSBundleAssetUrl != null)
? JSBundleLoader.createAssetLoader(
@@ -10,10 +10,20 @@
package com.facebook.react.bridge;
public class JSCJavaScriptExecutorFactory implements JavaScriptExecutorFactory {
private final String mAppName;
private final String mDeviceName;
public JSCJavaScriptExecutorFactory(String appName, String deviceName) {
this.mAppName = appName;
this.mDeviceName = deviceName;
}
@Override
public JavaScriptExecutor create() throws Exception {
WritableNativeMap jscConfig = new WritableNativeMap();
jscConfig.putString("OwnerIdentity", "ReactNative");
jscConfig.putString("AppIdentity", mAppName);
jscConfig.putString("OwnerIdentity", mDeviceName);
return new JSCJavaScriptExecutor(jscConfig);
}
}
@@ -31,6 +31,7 @@ public static String getInspectorProxyHost() {
return getServerIpAddress(INSPECTOR_PROXY_PORT);
}
// FIXME(festevezga): This method is duplicated in an internal module. Any changes should be applied to both.
public static String getFriendlyDeviceName() {
if (isRunningOnGenymotion()) {
// Genymotion already has a friendly name by default
@@ -209,9 +209,14 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) {
Object::getGlobalObject(m_context).setPrivate(this);
if (canUseInspector(m_context)) {
const std::string ownerId = m_jscConfig.getDefault("OwnerIdentity", "main").getString();
const std::string ownerId = m_jscConfig.getDefault("OwnerIdentity", "unknown").getString();
const std::string appId = m_jscConfig.getDefault("AppIdentity", "unknown").getString();
const std::string deviceId = m_jscConfig.getDefault("DeviceIdentity", "unknown").getString();
const std::function<bool()> checkIsInspectedRemote = [&ownerId, &appId, &deviceId](){
return false;
};
IInspector* pInspector = JSC_JSInspectorGetInstance(true);
pInspector->registerGlobalContext(ownerId, m_context);
pInspector->registerGlobalContext(ownerId, checkIsInspectedRemote, m_context);
}
installNativeHook<&JSCExecutor::nativeFlushQueueImmediate>("nativeFlushQueueImmediate");
@@ -9,9 +9,11 @@
#pragma once
#include <functional>
#include <memory>
#include <string>
#include <vector>
#include <JavaScriptCore/JSBase.h>
namespace facebook {
@@ -44,7 +46,7 @@ class ILocalConnection : public IDestructible {
// Note: not destructible!
class IInspector {
public:
virtual void registerGlobalContext(std::string title, JSGlobalContextRef ctx) = 0;
virtual void registerGlobalContext(const std::string& title, const std::function<bool()> &checkIsInspectedRemote, JSGlobalContextRef ctx) = 0;
virtual void unregisterGlobalContext(JSGlobalContextRef ctx) = 0;
virtual std::vector<InspectorPage> getPages() const = 0;

0 comments on commit da14fad

Please sign in to comment.