提交 6e2d67fa 编写于 作者: Z Zachary Anderson 提交者: GitHub

[Fuchsia] Pass namespaces to Isolates (#4047)

上级 75a7afa6
......@@ -6,6 +6,9 @@
#include <utility>
#include <magenta/status.h>
#include <mxio/namespace.h>
#include "application/lib/app/connect.h"
#include "flutter/content_handler/app.h"
#include "flutter/content_handler/runtime_holder.h"
......@@ -56,15 +59,50 @@ ApplicationControllerImpl::ApplicationControllerImpl(
auto request = service_provider.NewRequest();
service_provider_bridge_.set_backend(std::move(service_provider));
mxio_ns_t* mxio_ns = SetupNamespace(startup_info->flat_namespace);
if (mxio_ns == nullptr) {
FTL_LOG(ERROR) << "Failed to initialize namespace";
}
url_ = startup_info->launch_info->url;
runtime_holder_.reset(new RuntimeHolder());
runtime_holder_->Init(
mxio_ns,
app::ApplicationContext::CreateFrom(std::move(startup_info)),
std::move(request), std::move(bundle));
}
ApplicationControllerImpl::~ApplicationControllerImpl() = default;
constexpr char kServiceRootPath[] = "/svc";
mxio_ns_t* ApplicationControllerImpl::SetupNamespace(
const app::FlatNamespacePtr& flat) {
mxio_ns_t* mxio_namespc;
mx_status_t status = mxio_ns_create(&mxio_namespc);
if (status != MX_OK) {
FTL_LOG(ERROR) << "Failed to create namespace";
return nullptr;
}
for (size_t i = 0; i < flat->paths.size(); ++i) {
if (flat->paths[i] == kServiceRootPath) {
// Ownership of /svc goes to the ApplicationContext created above.
continue;
}
mx::channel dir = std::move(flat->directories[i]);
mx_handle_t dir_handle = dir.release();
const char* path = flat->paths[i].data();
status = mxio_ns_bind(mxio_namespc, path, dir_handle);
if (status != MX_OK) {
FTL_LOG(ERROR) << "Failed to bind " << flat->paths[i] << " to namespace";
mx_handle_close(dir_handle);
mxio_ns_destroy(mxio_namespc);
return nullptr;
}
}
return mxio_namespc;
}
void ApplicationControllerImpl::Kill() {
runtime_holder_.reset();
app_->Destroy(this);
......
......@@ -7,6 +7,8 @@
#include <memory>
#include <mxio/namespace.h>
#include "application/lib/svc/service_provider_bridge.h"
#include "application/services/application_controller.fidl.h"
#include "application/services/application_runner.fidl.h"
......@@ -50,6 +52,8 @@ class ApplicationControllerImpl : public app::ApplicationController,
private:
void StartRuntimeIfReady();
mxio_ns_t* SetupNamespace(const app::FlatNamespacePtr& flat);
App* app_;
fidl::Binding<app::ApplicationController> binding_;
......
......@@ -6,6 +6,7 @@
#include <dlfcn.h>
#include <magenta/dlfcn.h>
#include <mxio/namespace.h>
#include <utility>
#include "application/lib/app/connect.h"
......@@ -94,6 +95,7 @@ RuntimeHolder::~RuntimeHolder() {
}
void RuntimeHolder::Init(
mxio_ns_t* namespc,
std::unique_ptr<app::ApplicationContext> context,
fidl::InterfaceRequest<app::ServiceProvider> outgoing_services,
std::vector<char> bundle) {
......@@ -101,6 +103,7 @@ void RuntimeHolder::Init(
rasterizer_ = Rasterizer::Create();
FTL_DCHECK(rasterizer_);
namespc_ = namespc;
context_ = std::move(context);
outgoing_services_ = std::move(outgoing_services);
......@@ -351,10 +354,24 @@ void RuntimeHolder::HandlePlatformMessage(
void RuntimeHolder::DidCreateMainIsolate(Dart_Isolate isolate) {
if (asset_store_)
blink::AssetFontSelector::Install(asset_store_);
InitDartIoInternal();
InitFidlInternal();
InitMozartInternal();
}
void RuntimeHolder::InitDartIoInternal() {
Dart_Handle io_lib = Dart_LookupLibrary(ToDart("dart:io"));
Dart_Handle namespace_type =
Dart_GetType(io_lib, ToDart("_Namespace"), 0, nullptr);
DART_CHECK_VALID(namespace_type);
Dart_Handle namespace_args[1];
namespace_args[0] = Dart_NewInteger(reinterpret_cast<intptr_t>(namespc_));
DART_CHECK_VALID(namespace_args[0]);
DART_CHECK_VALID(Dart_Invoke(
namespace_type, ToDart("_setupNamespace"), 1, namespace_args));
}
void RuntimeHolder::InitFidlInternal() {
fidl::InterfaceHandle<app::ApplicationEnvironment> environment;
context_->ConnectToEnvironmentService(environment.NewRequest());
......
......@@ -6,6 +6,7 @@
#define FLUTTER_CONTENT_HANDLER_RUNTIME_HOLDER_H_
#include <mx/channel.h>
#include <mxio/namespace.h>
#include <unordered_set>
......@@ -39,7 +40,8 @@ class RuntimeHolder : public blink::RuntimeDelegate,
RuntimeHolder();
~RuntimeHolder();
void Init(std::unique_ptr<app::ApplicationContext> context,
void Init(mxio_ns_t* namespc,
std::unique_ptr<app::ApplicationContext> context,
fidl::InterfaceRequest<app::ServiceProvider> outgoing_services,
std::vector<char> bundle);
void CreateView(const std::string& script_uri,
......@@ -83,6 +85,7 @@ class RuntimeHolder : public blink::RuntimeDelegate,
bool HandleAssetPlatformMessage(blink::PlatformMessage* message);
bool HandleTextInputPlatformMessage(blink::PlatformMessage* message);
void InitDartIoInternal();
void InitFidlInternal();
void InitMozartInternal();
......@@ -92,6 +95,7 @@ class RuntimeHolder : public blink::RuntimeDelegate,
void OnRedrawFrame();
void Invalidate();
mxio_ns_t* namespc_;
std::unique_ptr<app::ApplicationContext> context_;
fidl::InterfaceRequest<app::ServiceProvider> outgoing_services_;
std::vector<char> root_bundle_data_;
......
dart:io,_Namespace,_setupNamespace
dart:fidl.internal,::,_environment
dart:fidl.internal,::,_outgoingServices
dart:fidl.internal,GetSizeResult,GetSizeResult.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册