CatalystInstanceImpl.setSourceURL
Reviewed By: javache Differential Revision: D4422416 fbshipit-source-id: bc49485ac64064909f32375b6b8360a0a505975b
This commit is contained in:
parent
bbd5750bb4
commit
76c4faee5e
|
@ -181,6 +181,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||
MessageQueueThread moduleQueue,
|
||||
ModuleRegistryHolder registryHolder);
|
||||
|
||||
/* package */ native void setSourceURL(String sourceURL);
|
||||
/* package */ native void loadScriptFromAssets(AssetManager assetManager, String assetURL);
|
||||
/* package */ native void loadScriptFromFile(String fileName, String sourceURL);
|
||||
/* package */ native void loadScriptFromOptimizedBundle(String path, String sourceURL, int flags);
|
||||
|
|
|
@ -83,7 +83,7 @@ public abstract class JSBundleLoader {
|
|||
return new JSBundleLoader() {
|
||||
@Override
|
||||
public String loadScript(CatalystInstanceImpl instance) {
|
||||
instance.loadScriptFromFile(null, proxySourceURL);
|
||||
instance.setSourceURL(proxySourceURL);
|
||||
return realSourceURL;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -103,6 +103,7 @@ void CatalystInstanceImpl::registerNatives() {
|
|||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", CatalystInstanceImpl::initHybrid),
|
||||
makeNativeMethod("initializeBridge", CatalystInstanceImpl::initializeBridge),
|
||||
makeNativeMethod("setSourceURL", CatalystInstanceImpl::setSourceURL),
|
||||
makeNativeMethod("loadScriptFromAssets",
|
||||
"(Landroid/content/res/AssetManager;Ljava/lang/String;)V",
|
||||
CatalystInstanceImpl::loadScriptFromAssets),
|
||||
|
@ -158,6 +159,10 @@ void CatalystInstanceImpl::initializeBridge(
|
|||
mrh->getModuleRegistry());
|
||||
}
|
||||
|
||||
void CatalystInstanceImpl::setSourceURL(const std::string& sourceURL) {
|
||||
instance_->setSourceURL(sourceURL);
|
||||
}
|
||||
|
||||
void CatalystInstanceImpl::loadScriptFromAssets(jobject assetManager,
|
||||
const std::string& assetURL) {
|
||||
const int kAssetsLength = 9; // strlen("assets://");
|
||||
|
@ -187,20 +192,18 @@ bool CatalystInstanceImpl::isIndexedRAMBundle(const char *sourcePath) {
|
|||
return parseTypeFromHeader(header) == ScriptTag::RAMBundle;
|
||||
}
|
||||
|
||||
void CatalystInstanceImpl::loadScriptFromFile(jni::alias_ref<jstring> fileName,
|
||||
void CatalystInstanceImpl::loadScriptFromFile(const std::string& fileName,
|
||||
const std::string& sourceURL) {
|
||||
|
||||
std::string file = fileName ? fileName->toStdString() : "";
|
||||
|
||||
if (isIndexedRAMBundle(file.c_str())) {
|
||||
auto bundle = folly::make_unique<JSIndexedRAMBundle>(file.c_str());
|
||||
auto zFileName = fileName.c_str();
|
||||
if (isIndexedRAMBundle(zFileName)) {
|
||||
auto bundle = folly::make_unique<JSIndexedRAMBundle>(zFileName);
|
||||
auto startupScript = bundle->getStartupCode();
|
||||
instance_->loadUnbundle(
|
||||
std::move(bundle),
|
||||
std::move(startupScript),
|
||||
sourceURL);
|
||||
} else {
|
||||
instance_->loadScriptFromFile(file, sourceURL);
|
||||
instance_->loadScriptFromFile(fileName, sourceURL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,8 +49,14 @@ class CatalystInstanceImpl : public jni::HybridClass<CatalystInstanceImpl> {
|
|||
jni::alias_ref<JavaMessageQueueThread::javaobject> jsQueue,
|
||||
jni::alias_ref<JavaMessageQueueThread::javaobject> moduleQueue,
|
||||
ModuleRegistryHolder* mrh);
|
||||
|
||||
/**
|
||||
* Sets the source URL of the underlying bridge without loading any JS code.
|
||||
*/
|
||||
void setSourceURL(const std::string& sourceURL);
|
||||
|
||||
void loadScriptFromAssets(jobject assetManager, const std::string& assetURL);
|
||||
void loadScriptFromFile(jni::alias_ref<jstring> fileName, const std::string& sourceURL);
|
||||
void loadScriptFromFile(const std::string& fileName, const std::string& sourceURL);
|
||||
void loadScriptFromOptimizedBundle(const std::string& bundlePath, const std::string& sourceURL, jint flags);
|
||||
void callJSFunction(JExecutorToken* token, std::string module, std::string method, NativeArray* arguments);
|
||||
void callJSCallback(JExecutorToken* token, jint callbackId, NativeArray* arguments);
|
||||
|
|
|
@ -50,6 +50,14 @@ void Instance::initializeBridge(
|
|||
CHECK(nativeToJsBridge_);
|
||||
}
|
||||
|
||||
void Instance::setSourceURL(std::string sourceURL) {
|
||||
callback_->incrementPendingJSCalls();
|
||||
SystraceSection s("reactbridge_xplat_setSourceURL",
|
||||
"sourceURL", sourceURL);
|
||||
|
||||
nativeToJsBridge_->loadApplication(nullptr, nullptr, std::move(sourceURL));
|
||||
}
|
||||
|
||||
void Instance::loadScriptFromString(std::unique_ptr<const JSBigString> string,
|
||||
std::string sourceURL) {
|
||||
callback_->incrementPendingJSCalls();
|
||||
|
@ -74,15 +82,10 @@ void Instance::loadScriptFromFile(const std::string& filename,
|
|||
|
||||
std::unique_ptr<const JSBigFileString> script;
|
||||
|
||||
// This function can be called in order to change the Bridge's Source URL.
|
||||
// In that case, the filename will be empty, and we should not attempt to
|
||||
// load it.
|
||||
if (!filename.empty()) {
|
||||
RecoverableError::runRethrowingAsRecoverable<std::system_error>(
|
||||
[&filename, &script]() {
|
||||
script = JSBigFileString::fromPath(filename);
|
||||
});
|
||||
}
|
||||
|
||||
nativeToJsBridge_->loadApplication(nullptr, std::move(script), sourceURL);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@ class Instance {
|
|||
std::shared_ptr<MessageQueueThread> jsQueue,
|
||||
std::unique_ptr<MessageQueueThread> nativeQueue,
|
||||
std::shared_ptr<ModuleRegistry> moduleRegistry);
|
||||
|
||||
void setSourceURL(std::string sourceURL);
|
||||
|
||||
void loadScriptFromString(std::unique_ptr<const JSBigString> string, std::string sourceURL);
|
||||
void loadScriptFromStringSync(std::unique_ptr<const JSBigString> string, std::string sourceURL);
|
||||
void loadScriptFromFile(const std::string& filename, const std::string& sourceURL);
|
||||
|
|
Loading…
Reference in New Issue