提交 ae58ba7c 编写于 作者: A Adam Barth

Bring sky_shell.mojo up to feature parity with sky_viewer.mojo

I believe this patch implements all the remaining features from
sky_viewer.mojo.
上级 133a8781
......@@ -13,6 +13,7 @@ mojom("interfaces") {
deps = [
"//mojo/public/interfaces/application",
"//mojo/services/asset_bundle/interfaces",
"//mojo/services/service_registry/interfaces",
"//sky/services/pointer:interfaces",
]
}
......@@ -7,6 +7,7 @@ module sky;
import "mojo/public/interfaces/application/service_provider.mojom";
import "mojo/public/interfaces/application/shell.mojom";
import "mojo/services/asset_bundle/interfaces/asset_bundle.mojom";
import "mojo/services/service_registry/interfaces/service_registry.mojom";
import "sky/services/engine/input_event.mojom";
import "sky/services/pointer/pointer.mojom";
......@@ -22,6 +23,7 @@ struct ViewportMetrics {
struct ServicesData {
mojo.Shell? shell;
mojo.ServiceRegistry? service_registry;
mojo.ServiceProvider? services_provided_by_embedder;
mojo.ServiceProvider&? services_provided_to_embedder;
};
......
......@@ -19,6 +19,12 @@
namespace sky {
namespace shell {
namespace {
// Instruct the DartVM to report type errors.
const char kEnableCheckedMode[] = "--enable-checked-mode";
} // namespace
class MojoApp : public mojo::ApplicationDelegate,
public mojo::InterfaceFactory<mojo::ContentHandler> {
......@@ -31,7 +37,11 @@ class MojoApp : public mojo::ApplicationDelegate,
void Initialize(mojo::ApplicationImpl* app) override {
mojo::icu::Initialize(app);
tracing_.Initialize(app);
Shell::Init();
Shell::Settings settings;
settings.enable_dart_checked_mode = app->HasArg(kEnableCheckedMode);
Shell::Init(settings);
}
bool ConfigureIncomingConnection(
......
......@@ -54,17 +54,16 @@ PlatformViewMojo::PlatformViewMojo(const Config& config)
PlatformViewMojo::~PlatformViewMojo() {
}
void PlatformViewMojo::Init(mojo::ShellPtr shell) {
mojo::ConnectToService(
shell.get(), "mojo:native_viewport_service", &viewport_);
void PlatformViewMojo::Init(mojo::Shell* shell) {
mojo::ConnectToService(shell, "mojo:native_viewport_service", &viewport_);
mojo::NativeViewportEventDispatcherPtr ptr;
dispatcher_binding_.Bind(GetProxy(&ptr));
viewport_->SetEventDispatcher(ptr.Pass());
mojo::SizePtr size = mojo::Size::New();
size->width = 800;
size->height = 600;
size->width = 320;
size->height = 640;
viewport_->Create(
size.Clone(),
......@@ -88,13 +87,12 @@ void PlatformViewMojo::Init(mojo::ShellPtr shell) {
ConnectToEngine(mojo::GetProxy(&sky_engine_));
ServicesDataPtr services = ServicesData::New();
services->shell = shell.Pass();
sky_engine_->SetServices(services.Pass());
}
void PlatformViewMojo::Run(const mojo::String& url,
ServicesDataPtr services,
mojo::asset_bundle::AssetBundlePtr bundle) {
sky_engine_->SetServices(services.Pass());
sky_engine_->RunFromAssetBundle(url, bundle.Pass());
}
......
......@@ -21,9 +21,10 @@ class PlatformViewMojo : public PlatformView,
explicit PlatformViewMojo(const Config& config);
~PlatformViewMojo() override;
void Init(mojo::ShellPtr shell);
void Init(mojo::Shell* shell);
void Run(const mojo::String& url,
ServicesDataPtr services,
mojo::asset_bundle::AssetBundlePtr bundle);
private:
......
......@@ -27,16 +27,29 @@ void SkyApplicationImpl::Initialize(mojo::ShellPtr shell,
DCHECK(initial_response_);
UnpackInitialResponse(shell.get());
shell_view_.reset(new ShellView(Shell::Shared()));
PlatformViewMojo* view = platform_view();
view->Init(shell.Pass());
view->Run(url, bundle_.Pass());
platform_view()->Init(shell.get());
shell_ = shell.Pass();
}
void SkyApplicationImpl::AcceptConnection(
const mojo::String& requestor_url,
mojo::InterfaceRequest<mojo::ServiceProvider> services,
mojo::ServiceProviderPtr exposed_services,
mojo::InterfaceRequest<mojo::ServiceProvider> outgoing_services,
mojo::ServiceProviderPtr incoming_services,
const mojo::String& resolved_url) {
if (!bundle_) {
LOG(INFO) << "Cannot handle multiple connections yet.";
return;
}
mojo::ServiceRegistryPtr service_registry;
if (incoming_services)
mojo::ConnectToService(incoming_services.get(), &service_registry);
ServicesDataPtr services = ServicesData::New();
services->shell = shell_.Pass();
services->service_registry = service_registry.Pass();
platform_view()->Run(resolved_url, services.Pass(), bundle_.Pass());
}
void SkyApplicationImpl::RequestQuit() {
......
......@@ -28,10 +28,11 @@ class SkyApplicationImpl : public mojo::Application {
void Initialize(mojo::ShellPtr shell,
mojo::Array<mojo::String> args,
const mojo::String& url) override;
void AcceptConnection(const mojo::String& requestor_url,
mojo::InterfaceRequest<mojo::ServiceProvider> services,
mojo::ServiceProviderPtr exposed_services,
const mojo::String& resolved_url) override;
void AcceptConnection(
const mojo::String& requestor_url,
mojo::InterfaceRequest<mojo::ServiceProvider> outgoing_services,
mojo::ServiceProviderPtr incoming_services,
const mojo::String& resolved_url) override;
void RequestQuit() override;
PlatformViewMojo* platform_view() {
......@@ -42,6 +43,7 @@ class SkyApplicationImpl : public mojo::Application {
mojo::StrongBinding<mojo::Application> binding_;
mojo::URLResponsePtr initial_response_;
mojo::ShellPtr shell_;
mojo::asset_bundle::AssetBundlePtr bundle_;
scoped_ptr<ShellView> shell_view_;
};
......
......@@ -7,6 +7,7 @@
#include <memory>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/i18n/icu_util.h"
#include "base/lazy_instance.h"
#include "base/memory/discardable_memory.h"
......@@ -14,6 +15,7 @@
#include "base/single_thread_task_runner.h"
#include "mojo/message_pump/message_pump_mojo.h"
#include "sky/shell/ui/engine.h"
#include "sky/shell/switches.h"
#include "ui/gl/gl_surface.h"
namespace sky {
......@@ -49,7 +51,7 @@ base::LazyInstance<NonDiscardableMemoryAllocator> g_discardable;
} // namespace
Shell::Shell() {
Shell::Shell(const Settings& settings) : settings_(settings) {
DCHECK(!g_shell);
base::Thread::Options options;
......@@ -78,12 +80,18 @@ void Shell::InitStandalone() {
#if !defined(OS_LINUX)
CHECK(gfx::GLSurface::InitializeOneOff());
#endif
Init();
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
Settings settings;
settings.enable_dart_checked_mode =
command_line.HasSwitch(switches::kEnableCheckedMode);
Init(settings);
}
void Shell::Init() {
void Shell::Init(const Settings& settings) {
base::DiscardableMemoryAllocator::SetInstance(&g_discardable.Get());
g_shell = new Shell();
g_shell = new Shell(settings);
}
Shell& Shell::Shared() {
......
......@@ -19,10 +19,14 @@ class Shell {
public:
~Shell();
struct Settings {
bool enable_dart_checked_mode = false;
};
// Init the shell to stand alone from MojoShell.
static void InitStandalone();
// Init the shell to run inside MojoShell.
static void Init();
static void Init(const Settings& settings);
static Shell& Shared();
......@@ -38,10 +42,11 @@ class Shell {
return io_task_runner_.get();
}
const Settings& settings() { return settings_; }
TracingController& tracing_controller();
private:
explicit Shell();
explicit Shell(const Settings& settings);
void InitGPU(const base::Thread::Options& options);
void InitUI(const base::Thread::Options& options);
......@@ -54,6 +59,7 @@ class Shell {
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
Settings settings_;
TracingController tracing_controller_;
DISALLOW_COPY_AND_ASSIGN(Shell);
......
......@@ -5,7 +5,6 @@
#include "sky/shell/ui/engine.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/threading/worker_pool.h"
#include "base/time/time.h"
......@@ -19,8 +18,7 @@
#include "sky/engine/public/web/WebRuntimeFeatures.h"
#include "sky/shell/dart/dart_library_provider_files.h"
#include "sky/shell/dart/dart_library_provider_network.h"
#include "sky/shell/switches.h"
#include "sky/shell/switches.h"
#include "sky/shell/shell.h"
#include "sky/shell/ui/animator.h"
#include "sky/shell/ui/internals.h"
#include "sky/shell/ui/platform_impl.h"
......@@ -75,9 +73,8 @@ base::WeakPtr<Engine> Engine::GetWeakPtr() {
void Engine::Init() {
TRACE_EVENT0("flutter", "Engine::Init");
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
blink::WebRuntimeFeatures::enableDartCheckedMode(
command_line.HasSwitch(switches::kEnableCheckedMode));
Shell::Shared().settings().enable_dart_checked_mode);
DCHECK(!g_platform_impl);
g_platform_impl = new PlatformImpl();
......
......@@ -36,6 +36,11 @@ void TakeShellProxyHandle(Dart_NativeArguments args) {
args, GetInternals()->TakeShellProxy().value());
}
void TakeServiceRegistry(Dart_NativeArguments args) {
Dart_SetIntegerReturnValue(
args, GetInternals()->TakeServiceRegistry().value());
}
void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) {
Dart_SetIntegerReturnValue(
args, GetInternals()->TakeServicesProvidedByEmbedder().value());
......@@ -46,10 +51,6 @@ void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) {
args, GetInternals()->TakeServicesProvidedToEmbedder().value());
}
void TakeServiceRegistry(Dart_NativeArguments args) {
Dart_SetIntegerReturnValue(args, 0);
}
static DartLibraryNatives* g_natives;
void EnsureNatives() {
......@@ -119,6 +120,10 @@ mojo::Handle Internals::TakeShellProxy() {
return services_ ? services_->shell.PassInterface().PassHandle().release() : mojo::Handle();
}
mojo::Handle Internals::TakeServiceRegistry() {
return services_ ? services_->service_registry.PassInterface().PassHandle().release() : mojo::Handle();
}
mojo::Handle Internals::TakeServicesProvidedByEmbedder() {
return service_provider_.PassInterface().PassHandle().release();
}
......
......@@ -31,9 +31,10 @@ class Internals
mojo::asset_bundle::AssetBundlePtr root_bundle);
mojo::Handle TakeShellProxy();
mojo::Handle TakeServiceRegistry();
mojo::Handle TakeServicesProvidedByEmbedder();
mojo::Handle TakeRootBundleHandle();
mojo::Handle TakeServicesProvidedToEmbedder();
mojo::Handle TakeRootBundleHandle();
private:
explicit Internals(ServicesDataPtr services,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册