提交 0ede7dde 编写于 作者: J Jason Simmons

Implement support for invoking Mojo services from secondary isolates

上级 4ac75601
......@@ -20,10 +20,29 @@ source_set("bindings") {
"exception_state.h",
"exception_state_placeholder.cc",
"exception_state_placeholder.h",
"flutter_dart_state.cc",
"flutter_dart_state.h",
"mojo_services.cc",
"mojo_services.h",
]
if (is_android) {
sources += [
"jni/dart_jni.cc",
"jni/dart_jni.h",
"jni/jni_api.cc",
"jni/jni_api.h",
"jni/jni_array.cc",
"jni/jni_array.h",
"jni/jni_class.cc",
"jni/jni_class.h",
"jni/jni_object.cc",
"jni/jni_object.h",
"jni/jni_string.cc",
"jni/jni_string.h",
]
}
defines = [ "DART_IO_SECURE_SOCKET_DISABLED" ]
deps = [
......
......@@ -86,7 +86,7 @@ static void InitDartInternal(Dart_Handle builtin_library,
Dart_Handle timer_name = ToDart("timerFactory");
DART_CHECK_VALID(Dart_SetField(vm_hooks, timer_name, timer));
} else {
CHECK(isolate_type == DartRuntimeHooks::DartIOIsolate);
CHECK(isolate_type == DartRuntimeHooks::SecondaryIsolate);
Dart_Handle io_lib = Dart_LookupLibrary(ToDart("dart:io"));
DART_CHECK_VALID(io_lib);
Dart_Handle setup_hooks = Dart_NewStringFromCString("_setupHooks");
......@@ -111,7 +111,7 @@ static void InitDartAsync(Dart_Handle builtin_library,
schedule_microtask =
GetClosure(builtin_library, "_getScheduleMicrotaskClosure");
} else {
CHECK(isolate_type == DartRuntimeHooks::DartIOIsolate);
CHECK(isolate_type == DartRuntimeHooks::SecondaryIsolate);
Dart_Handle isolate_lib = Dart_LookupLibrary(ToDart("dart:isolate"));
Dart_Handle method_name =
Dart_NewStringFromCString("_getIsolateScheduleImmediateClosure");
......
......@@ -15,7 +15,7 @@ class DartRuntimeHooks {
public:
enum IsolateType {
MainIsolate,
DartIOIsolate,
SecondaryIsolate,
};
static void Install(IsolateType isolate_type, const std::string& script_uri);
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/bindings/flutter_dart_state.h"
#include "sky/engine/bindings/mojo_services.h"
#include "sky/engine/tonic/dart_converter.h"
#ifdef OS_ANDROID
#include "sky/engine/bindings/jni/dart_jni.h"
#endif
namespace blink {
IsolateClient::~IsolateClient() {
}
FlutterDartState::FlutterDartState(IsolateClient* isolate_client,
const std::string& url)
: isolate_client_(isolate_client), url_(url) {
}
FlutterDartState::~FlutterDartState() {
// We've already destroyed the isolate. Revoke any weak ptrs held by
// DartPersistentValues so they don't try to enter the destroyed isolate to
// clean themselves up.
weak_factory_.InvalidateWeakPtrs();
}
FlutterDartState* FlutterDartState::CreateForChildIsolate() {
return new FlutterDartState(isolate_client_, url_);
}
FlutterDartState* FlutterDartState::Current() {
return static_cast<FlutterDartState*>(DartState::Current());
}
void FlutterDartState::DidSetIsolate() {
Scope dart_scope(this);
x_handle_.Set(this, ToDart("x"));
y_handle_.Set(this, ToDart("y"));
dx_handle_.Set(this, ToDart("_dx"));
dy_handle_.Set(this, ToDart("_dy"));
value_handle_.Set(this, ToDart("_value"));
Dart_Handle library = Dart_LookupLibrary(ToDart("dart:ui"));
color_class_.Set(this, Dart_GetType(library, ToDart("Color"), 0, 0));
}
void FlutterDartState::set_mojo_services(
std::unique_ptr<MojoServices> mojo_services) {
mojo_services_ = std::move(mojo_services);
}
MojoServices* FlutterDartState::mojo_services() {
return mojo_services_.get();
}
#ifdef OS_ANDROID
void FlutterDartState::set_jni_data(
std::unique_ptr<DartJniIsolateData> jni_data) {
jni_data_ = std::move(jni_data);
}
DartJniIsolateData* FlutterDartState::jni_data() {
return jni_data_.get();
}
#endif
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_BINDINGS_FLUTTER_DART_STATE_H_
#define SKY_ENGINE_BINDINGS_FLUTTER_DART_STATE_H_
#include <string>
#include "dart/runtime/include/dart_api.h"
#include "sky/engine/tonic/dart_persistent_value.h"
#include "sky/engine/tonic/dart_state.h"
namespace blink {
class DartJniIsolateData;
class MojoServices;
class IsolateClient {
public:
virtual void DidCreateSecondaryIsolate(Dart_Isolate isolate) = 0;
protected:
virtual ~IsolateClient();
};
class FlutterDartState : public DartState {
public:
FlutterDartState* CreateForChildIsolate();
~FlutterDartState() override;
void DidSetIsolate() override;
IsolateClient* isolate_client() { return isolate_client_; }
const std::string& url() const { return url_; }
static FlutterDartState* Current();
// Cached handles to strings used in Dart/C++ conversions.
Dart_Handle x_handle() { return x_handle_.value(); }
Dart_Handle y_handle() { return y_handle_.value(); }
Dart_Handle dx_handle() { return dx_handle_.value(); }
Dart_Handle dy_handle() { return dy_handle_.value(); }
Dart_Handle value_handle() { return value_handle_.value(); }
Dart_Handle color_class() { return color_class_.value(); }
void set_mojo_services(std::unique_ptr<MojoServices> mojo_services);
MojoServices* mojo_services();
#ifdef OS_ANDROID
void set_jni_data(std::unique_ptr<DartJniIsolateData> jni_data);
DartJniIsolateData* jni_data();
#endif
protected:
FlutterDartState(IsolateClient* isolate_client, const std::string& url);
private:
IsolateClient* isolate_client_;
std::string url_;
DartPersistentValue x_handle_;
DartPersistentValue y_handle_;
DartPersistentValue dx_handle_;
DartPersistentValue dy_handle_;
DartPersistentValue value_handle_;
DartPersistentValue color_class_;
std::unique_ptr<MojoServices> mojo_services_;
#ifdef OS_ANDROID
std::unique_ptr<DartJniIsolateData> jni_data_;
#endif
};
} // namespace blink
#endif // SKY_ENGINE_BINDINGS_FLUTTER_DART_STATE_H_
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("jni") {
sources = [
"dart_jni.cc",
"dart_jni.h",
"jni_api.cc",
"jni_api.h",
"jni_array.cc",
"jni_array.h",
"jni_class.cc",
"jni_class.h",
"jni_object.cc",
"jni_object.h",
"jni_string.cc",
"jni_string.h",
]
deps = [
"//base",
"//dart/runtime:libdart",
"//sky/engine/tonic",
"//sky/engine/wtf",
]
}
......@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "sky/engine/bindings/flutter_dart_state.h"
#include "sky/engine/bindings/jni/jni_api.h"
#include "sky/engine/bindings/jni/jni_array.h"
#include "sky/engine/bindings/jni/jni_class.h"
......@@ -15,6 +16,7 @@
#include "sky/engine/tonic/dart_args.h"
#include "sky/engine/tonic/dart_binding_macros.h"
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/wtf/MakeUnique.h"
namespace blink {
......@@ -35,12 +37,6 @@ const uint8_t* GetSymbol(Dart_NativeFunction native_function) {
return g_natives->GetSymbol(native_function);
}
// Data cached for each Dart isolate.
struct DartJniIsolateData : public base::SupportsUserData::Data {
Dart_PersistentHandle jni_object_type;
Dart_PersistentHandle jni_float_type;
};
// Data cached from the Java VM.
struct DartJniJvmData {
ScopedJavaGlobalRef<jobject> class_loader;
......@@ -51,21 +47,13 @@ struct DartJniJvmData {
DartJniJvmData* g_jvm_data = nullptr;
void* UserDataKey() {
// Return a unique key for our per-isolate data.
static int data_key = 0;
return reinterpret_cast<void*>(&data_key);
}
void CreateIsolateData() {
DartState::Current()->SetUserData(UserDataKey(), new DartJniIsolateData());
static_cast<FlutterDartState*>(DartState::Current())->set_jni_data(
WTF::MakeUnique<DartJniIsolateData>());
}
DartJniIsolateData* IsolateData() {
base::SupportsUserData::Data* user_data =
DartState::Current()->GetUserData(UserDataKey());
DCHECK(user_data);
return static_cast<DartJniIsolateData*>(user_data);
return static_cast<FlutterDartState*>(DartState::Current())->jni_data();
}
} // anonymous namespace
......
......@@ -43,6 +43,12 @@ class DartJni {
static Dart_Handle jni_float_type();
};
// Data cached for each Dart isolate.
struct DartJniIsolateData {
Dart_PersistentHandle jni_object_type;
Dart_PersistentHandle jni_float_type;
};
class JniMethodArgs {
public:
void Convert(JNIEnv* env,
......
......@@ -7,7 +7,7 @@
#include "base/threading/worker_pool.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/cpp/bindings/array.h"
#include "services/asset_bundle/asset_unpacker_impl.h"
#include "sky/engine/bindings/flutter_dart_state.h"
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/tonic/dart_error.h"
#include "sky/engine/tonic/dart_library_natives.h"
......@@ -16,11 +16,8 @@
namespace blink {
namespace {
int kMojoServicesKey = 0;
MojoServices* GetMojoServices() {
DartState* state = DartState::Current();
return static_cast<MojoServices*>(state->GetUserData(&kMojoServicesKey));
return static_cast<FlutterDartState*>(DartState::Current())->mojo_services();
}
void DartTakeRootBundleHandle(Dart_NativeArguments args) {
......@@ -62,22 +59,20 @@ void MojoServices::RegisterNatives(DartLibraryNatives* natives) {
void MojoServices::Create(Dart_Isolate isolate,
sky::ServicesDataPtr services,
mojo::ServiceProviderPtr services_from_embedder,
mojo::asset_bundle::AssetBundlePtr root_bundle) {
DartState* state = DartState::From(isolate);
state->SetUserData(&kMojoServicesKey, new MojoServices(
services.Pass(), root_bundle.Pass()));
FlutterDartState* state = static_cast<FlutterDartState*>(
DartState::From(isolate));
state->set_mojo_services(std::unique_ptr<MojoServices>(new MojoServices(
services.Pass(), services_from_embedder.Pass(), root_bundle.Pass())));
}
MojoServices::MojoServices(sky::ServicesDataPtr services,
mojo::ServiceProviderPtr services_from_embedder,
mojo::asset_bundle::AssetBundlePtr root_bundle)
: services_(services.Pass()),
root_bundle_(root_bundle.Pass()),
service_provider_impl_(GetProxy(&service_provider_)) {
if (services_ && services_->services_provided_by_embedder) {
service_provider_impl_.set_fallback_service_provider(
services_->services_provided_by_embedder.get());
}
service_provider_impl_.AddService<mojo::asset_bundle::AssetUnpacker>(this);
services_from_embedder_(services_from_embedder.Pass()),
root_bundle_(root_bundle.Pass()) {
if (services_ && services_->services_provided_to_embedder.is_pending()) {
services_provided_to_embedder_ = services_->services_provided_to_embedder.Pass();
} else {
......@@ -88,19 +83,12 @@ MojoServices::MojoServices(sky::ServicesDataPtr services,
MojoServices::~MojoServices() {
}
void MojoServices::Create(
mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mojo::asset_bundle::AssetUnpacker> request) {
new mojo::asset_bundle::AssetUnpackerImpl(
request.Pass(), base::WorkerPool::GetTaskRunner(true));
}
mojo::Handle MojoServices::TakeShellProxy() {
return services_ ? services_->shell.PassInterface().PassHandle().release() : mojo::Handle();
}
mojo::Handle MojoServices::TakeServicesProvidedByEmbedder() {
return service_provider_.PassInterface().PassHandle().release();
return services_from_embedder_.PassInterface().PassHandle().release();
}
mojo::Handle MojoServices::TakeRootBundleHandle() {
......
......@@ -5,9 +5,7 @@
#ifndef SKY_ENGINE_BINDINGS_MOJO_SERVICES_H_
#define SKY_ENGINE_BINDINGS_MOJO_SERVICES_H_
#include "base/supports_user_data.h"
#include "dart/runtime/include/dart_api.h"
#include "mojo/public/cpp/application/interface_factory.h"
#include "mojo/public/cpp/application/service_provider_impl.h"
#include "mojo/public/interfaces/application/service_provider.mojom.h"
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
......@@ -20,14 +18,13 @@ class ApplicationConnection;
namespace blink {
class DartLibraryNatives;
class MojoServices
: public base::SupportsUserData::Data,
public mojo::InterfaceFactory<mojo::asset_bundle::AssetUnpacker> {
class MojoServices {
public:
~MojoServices() override;
~MojoServices();
static void Create(Dart_Isolate isolate,
sky::ServicesDataPtr services,
mojo::ServiceProviderPtr services_from_embedder,
mojo::asset_bundle::AssetBundlePtr root_bundle);
static void RegisterNatives(DartLibraryNatives* natives);
......@@ -40,19 +37,13 @@ class MojoServices
private:
explicit MojoServices(sky::ServicesDataPtr services,
mojo::ServiceProviderPtr services_from_embedder,
mojo::asset_bundle::AssetBundlePtr root_bundle);
// |mojo::InterfaceFactory<mojo::asset_bundle::AssetUnpacker>| implementation:
void Create(
mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mojo::asset_bundle::AssetUnpacker>) override;
sky::ServicesDataPtr services_;
mojo::ServiceProviderPtr services_from_embedder_;
mojo::asset_bundle::AssetBundlePtr root_bundle_;
mojo::ServiceProviderPtr service_provider_;
mojo::ServiceProviderImpl service_provider_impl_;
// We need to hold this object to work around
// https://github.com/domokit/mojo/issues/536
mojo::ServiceProviderPtr services_from_dart_;
......
......@@ -78,10 +78,6 @@ static_library("core") {
"//mojo/services/navigation/interfaces",
]
if (is_android) {
deps += [ "//sky/engine/bindings/jni" ]
}
sources = sky_core_files
sources += [ "$target_gen_dir/sky_embedder_service_isolate_resources.cc" ]
......
......@@ -33,6 +33,7 @@
#include "sky/engine/tonic/dart_state.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/tonic/uint8_list.h"
#include "sky/engine/wtf/MakeUnique.h"
#ifdef OS_ANDROID
#include "sky/engine/bindings/jni/dart_jni.h"
......@@ -130,10 +131,7 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
DartIO::InitForIsolate();
DartUI::InitForIsolate();
DartMojoInternal::InitForIsolate();
#ifdef OS_ANDROID
DartJni::InitForIsolate();
#endif
DartRuntimeHooks::Install(DartRuntimeHooks::DartIOIsolate, "");
DartRuntimeHooks::Install(DartRuntimeHooks::SecondaryIsolate, "");
const SkySettings& settings = SkySettings::Get();
if (settings.enable_observatory) {
std::string ip = "127.0.0.1";
......@@ -157,7 +155,10 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
CHECK(zip_asset_bundle->GetAsBuffer(kSnapshotAssetKey, &snapshot_data));
}
DartState* dart_state = new DartState();
FlutterDartState* parent_dart_state =
static_cast<FlutterDartState*>(callback_data);
FlutterDartState* dart_state = parent_dart_state->CreateForChildIsolate();
Dart_Isolate isolate = Dart_CreateIsolate(
script_uri, main,
reinterpret_cast<uint8_t*>(DART_SYMBOL(kDartIsolateSnapshotBuffer)),
......@@ -172,15 +173,18 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
DartIO::InitForIsolate();
DartUI::InitForIsolate();
DartMojoInternal::InitForIsolate();
#ifdef OS_ANDROID
DartJni::InitForIsolate();
#endif
DartRuntimeHooks::Install(DartRuntimeHooks::MainIsolate, script_uri);
DartRuntimeHooks::Install(DartRuntimeHooks::SecondaryIsolate, script_uri);
dart_state->class_library().add_provider(
"ui",
WTF::MakeUnique<DartClassProvider>(dart_state, "dart:ui"));
if (!snapshot_data.empty()) {
CHECK(!LogIfError(Dart_LoadScriptFromSnapshot(
snapshot_data.data(), snapshot_data.size())));
}
dart_state->isolate_client()->DidCreateSecondaryIsolate(isolate);
}
Dart_ExitIsolate();
......
......@@ -4,38 +4,24 @@
#include "sky/engine/core/script/dom_dart_state.h"
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/core/window/window.h"
namespace blink {
DOMDartState::DOMDartState(std::unique_ptr<Window> window, const std::string& url)
: window_(std::move(window)), url_(url) {
DOMDartState::DOMDartState(IsolateClient* isolate_client,
const std::string& url,
std::unique_ptr<Window> window)
: FlutterDartState(isolate_client, url),
window_(std::move(window)) {
}
DOMDartState::~DOMDartState() {
// We've already destroyed the isolate. Revoke any weak ptrs held by
// DartPersistentValues so they don't try to enter the destroyed isolate to
// clean themselves up.
weak_factory_.InvalidateWeakPtrs();
}
DOMDartState* DOMDartState::Current() {
return static_cast<DOMDartState*>(DartState::Current());
}
void DOMDartState::DidSetIsolate() {
Scope dart_scope(this);
x_handle_.Set(this, ToDart("x"));
y_handle_.Set(this, ToDart("y"));
dx_handle_.Set(this, ToDart("_dx"));
dy_handle_.Set(this, ToDart("_dy"));
value_handle_.Set(this, ToDart("_value"));
Dart_Handle library = Dart_LookupLibrary(ToDart("dart:ui"));
color_class_.Set(this, Dart_GetType(library, ToDart("Color"), 0, 0));
}
void DOMDartState::set_font_selector(PassRefPtr<FontSelector> selector) {
font_selector_ = selector;
}
......
......@@ -5,50 +5,28 @@
#ifndef SKY_ENGINE_CORE_SCRIPT_DOM_DART_STATE_H_
#define SKY_ENGINE_CORE_SCRIPT_DOM_DART_STATE_H_
#include <memory>
#include "dart/runtime/include/dart_api.h"
#include "sky/engine/bindings/flutter_dart_state.h"
#include "sky/engine/platform/fonts/FontSelector.h"
#include "sky/engine/tonic/dart_state.h"
#include "sky/engine/wtf/RefPtr.h"
#include "sky/engine/wtf/text/WTFString.h"
namespace blink {
class Window;
class DOMDartState : public DartState {
class DOMDartState : public FlutterDartState {
public:
DOMDartState(std::unique_ptr<Window> window, const std::string& url);
DOMDartState(IsolateClient* isolate_client, const std::string& url,
std::unique_ptr<Window> window);
~DOMDartState() override;
virtual void DidSetIsolate();
Window* window() const { return window_.get(); }
const std::string& url() const { return url_; }
static DOMDartState* Current();
// Cached handles to strings used in Dart/C++ conversions.
Dart_Handle x_handle() { return x_handle_.value(); }
Dart_Handle y_handle() { return y_handle_.value(); }
Dart_Handle dx_handle() { return dx_handle_.value(); }
Dart_Handle dy_handle() { return dy_handle_.value(); }
Dart_Handle value_handle() { return value_handle_.value(); }
Dart_Handle color_class() { return color_class_.value(); }
void set_font_selector(PassRefPtr<FontSelector> selector);
PassRefPtr<FontSelector> font_selector();
private:
std::unique_ptr<Window> window_;
std::string url_;
DartPersistentValue x_handle_;
DartPersistentValue y_handle_;
DartPersistentValue dx_handle_;
DartPersistentValue dy_handle_;
DartPersistentValue value_handle_;
DartPersistentValue color_class_;
RefPtr<FontSelector> font_selector_;
};
......
......@@ -9,6 +9,7 @@ source_set("sky") {
"//mojo/public/cpp/system",
"//mojo/services/network/interfaces",
"//skia",
"//sky/engine/bindings",
"//sky/engine/core",
"//sky/engine/platform",
"//sky/engine/wtf",
......
......@@ -22,7 +22,7 @@ void SkyHeadless::Init(const std::string& name) {
dart_controller_ = WTF::MakeUnique<DartController>();
dart_controller_->CreateIsolateFor(WTF::MakeUnique<DOMDartState>(
WTF::MakeUnique<Window>(this), name));
this, name, WTF::MakeUnique<Window>(this)));
DOMDartState* dart_state = dart_controller_->dart_state();
DartState::Scope scope(dart_state);
......@@ -43,4 +43,7 @@ void SkyHeadless::FlushRealTimeEvents() {
void SkyHeadless::Render(Scene* scene) {
}
void SkyHeadless::DidCreateSecondaryIsolate(Dart_Isolate isolate) {
}
} // namespace blink
......@@ -8,6 +8,7 @@
#include <memory>
#include "base/basictypes.h"
#include "sky/engine/bindings/flutter_dart_state.h"
#include "sky/engine/core/window/window.h"
#include "sky/engine/wtf/OwnPtr.h"
#include "sky/engine/wtf/text/WTFString.h"
......@@ -19,7 +20,7 @@ class DartController;
class Scene;
// This class provides a way to run Dart script without a View.
class SkyHeadless : public WindowClient {
class SkyHeadless : public WindowClient, public IsolateClient {
public:
class Client {
public:
......@@ -40,6 +41,8 @@ class SkyHeadless : public WindowClient {
void FlushRealTimeEvents() override;
void Render(Scene* scene) override;
void DidCreateSecondaryIsolate(Dart_Isolate isolate) override;
std::unique_ptr<DartController> dart_controller_;
Client* client_;
......
......@@ -56,12 +56,12 @@ void SkyView::CreateView(const std::string& script_uri) {
dart_controller_ = WTF::MakeUnique<DartController>();
dart_controller_->CreateIsolateFor(WTF::MakeUnique<DOMDartState>(
WTF::MakeUnique<Window>(this), script_uri));
this, script_uri, WTF::MakeUnique<Window>(this)));
DOMDartState* dart_state = dart_controller_->dart_state();
DartState::Scope scope(dart_state);
dart_state->window()->DidCreateIsolate();
client_->DidCreateIsolate(dart_state->isolate());
client_->DidCreateMainIsolate(dart_state->isolate());
GetWindow()->UpdateWindowMetrics(display_metrics_);
GetWindow()->UpdateLocale(language_code_, country_code_);
......@@ -107,6 +107,10 @@ void SkyView::Render(Scene* scene) {
layer_tree_ = scene->takeLayerTree();
}
void SkyView::DidCreateSecondaryIsolate(Dart_Isolate isolate) {
client_->DidCreateSecondaryIsolate(isolate);
}
void SkyView::OnAppLifecycleStateChanged(sky::AppLifecycleState state) {
GetWindow()->OnAppLifecycleStateChanged(state);
}
......
......@@ -12,6 +12,7 @@
#include "flow/layers/layer_tree.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "mojo/services/network/interfaces/url_loader.mojom.h"
#include "sky/engine/bindings/flutter_dart_state.h"
#include "sky/engine/core/window/window.h"
#include "sky/engine/public/platform/sky_display_metrics.h"
#include "sky/engine/public/platform/WebCommon.h"
......@@ -32,7 +33,7 @@ class View;
class WebInputEvent;
class Window;
class SkyView : public WindowClient {
class SkyView : public WindowClient, public IsolateClient {
public:
static std::unique_ptr<SkyView> Create(SkyViewClient* client);
~SkyView();
......@@ -67,6 +68,8 @@ class SkyView : public WindowClient {
void FlushRealTimeEvents() override;
void Render(Scene* scene) override;
void DidCreateSecondaryIsolate(Dart_Isolate isolate) override;
SkyViewClient* client_;
SkyDisplayMetrics display_metrics_;
std::string language_code_;
......
......@@ -19,7 +19,8 @@ class SkyViewClient {
virtual void FlushRealTimeEvents() = 0;
virtual void Render(std::unique_ptr<flow::LayerTree> layer_tree) = 0;
virtual void DidCreateIsolate(Dart_Isolate isolate) = 0;
virtual void DidCreateMainIsolate(Dart_Isolate isolate) = 0;
virtual void DidCreateSecondaryIsolate(Dart_Isolate isolate) = 0;
protected:
virtual ~SkyViewClient();
......
......@@ -7,7 +7,6 @@
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/supports_user_data.h"
#include "dart/runtime/include/dart_api.h"
#include "sky/engine/tonic/dart_api_scope.h"
#include "sky/engine/tonic/dart_isolate_scope.h"
......@@ -25,7 +24,7 @@ class DartMessageHandler;
// reference to a DartState instance, please hold a base::WeakPtr<DartState>.
//
// DartState is analogous to gin::PerIsolateData and JSC::ExecState.
class DartState : public base::SupportsUserData {
class DartState {
public:
class Scope {
public:
......
......@@ -140,7 +140,6 @@ if (is_android) {
"//mojo/android:libsystem_java",
"//mojo/edk/base_edk",
"//mojo/edk/system",
"//sky/engine/bindings/jni",
"//ui/gl",
":common",
":gpu_direct",
......
......@@ -103,6 +103,13 @@ void Engine::OnOutputSurfaceDestroyed(const base::Closure& gpu_continuation) {
void Engine::SetServices(ServicesDataPtr services) {
services_ = services.Pass();
if (services_->services_provided_by_embedder) {
services_provided_by_embedder_ =
services_->services_provided_by_embedder.Pass();
service_provider_impl_.set_fallback_service_provider(
services_provided_by_embedder_.get());
}
if (services_->scene_scheduler) {
animator_->Reset();
animator_->set_scene_scheduler(services_->scene_scheduler.Pass());
......@@ -113,7 +120,7 @@ void Engine::SetServices(ServicesDataPtr services) {
mojo::ConnectToService(services_->shell.get(), "mojo:vsync",
&vsync_provider);
} else {
mojo::ConnectToService(services_->services_provided_by_embedder.get(),
mojo::ConnectToService(services_provided_by_embedder_.get(),
&vsync_provider);
}
animator_->Reset();
......@@ -271,14 +278,39 @@ void Engine::OnAppLifecycleStateChanged(sky::AppLifecycleState state) {
sky_view_->OnAppLifecycleStateChanged(state);
}
void Engine::DidCreateIsolate(Dart_Isolate isolate) {
blink::MojoServices::Create(isolate, services_.Pass(), root_bundle_.Pass());
void Engine::DidCreateMainIsolate(Dart_Isolate isolate) {
mojo::ServiceProviderPtr services_from_embedder;
service_provider_bindings_.AddBinding(
&service_provider_impl_, mojo::GetProxy(&services_from_embedder));
blink::MojoServices::Create(
isolate, services_.Pass(), services_from_embedder.Pass(),
root_bundle_.Pass());
if (zip_asset_bundle_) {
FlutterFontSelector::install(zip_asset_bundle_);
}
}
void Engine::DidCreateSecondaryIsolate(Dart_Isolate isolate) {
mojo::ServiceProviderPtr services_from_embedder;
mojo::InterfaceRequest<mojo::ServiceProvider> request =
mojo::GetProxy(&services_from_embedder);
blink::Platform::current()->GetUITaskRunner()->PostTask(FROM_HERE,
base::Bind(&Engine::BindToServiceProvider,
weak_factory_.GetWeakPtr(),
base::Passed(&request)));
blink::MojoServices::Create(
isolate, nullptr, services_from_embedder.Pass(), nullptr);
}
void Engine::BindToServiceProvider(
mojo::InterfaceRequest<mojo::ServiceProvider> request) {
service_provider_bindings_.AddBinding(&service_provider_impl_,
request.Pass());
}
void Engine::StopAnimator() {
animator_->Stop();
}
......
......@@ -9,6 +9,9 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "mojo/common/binding_set.h"
#include "mojo/public/cpp/application/interface_factory.h"
#include "mojo/public/cpp/application/service_provider_impl.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/data_pipe.h"
......@@ -82,7 +85,11 @@ class Engine : public UIDelegate,
void ScheduleFrame() override;
void FlushRealTimeEvents() override;
void Render(std::unique_ptr<flow::LayerTree> layer_tree) override;
void DidCreateIsolate(Dart_Isolate isolate) override;
void DidCreateMainIsolate(Dart_Isolate isolate) override;
void DidCreateSecondaryIsolate(Dart_Isolate isolate) override;
void BindToServiceProvider(
mojo::InterfaceRequest<mojo::ServiceProvider> request);
void RunFromLibrary(const std::string& name);
void RunFromSnapshotStream(const std::string& name,
......@@ -99,6 +106,10 @@ class Engine : public UIDelegate,
std::unique_ptr<Animator> animator_;
ServicesDataPtr services_;
mojo::ServiceProviderImpl service_provider_impl_;
mojo::ServiceProviderPtr services_provided_by_embedder_;
mojo::BindingSet<mojo::ServiceProvider> service_provider_bindings_;
mojo::asset_bundle::AssetBundlePtr root_bundle_;
std::unique_ptr<blink::DartLibraryProvider> dart_library_provider_;
std::unique_ptr<blink::SkyView> sky_view_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册