From 61dcfbc0ede5965c25c8bec3fc8663fc17ae9340 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 24 Aug 2015 09:34:17 -0700 Subject: [PATCH] Add support for skyx to sky_viewer.mojo Fixes #753 --- services/sky/BUILD.gn | 1 + services/sky/document_view.cc | 35 +++++++++++++++++++++++++++++++---- services/sky/document_view.h | 6 ++++++ services/sky/internals.cc | 9 ++++++++- services/sky/internals.h | 1 + sky/shell/ui/engine.cc | 3 +-- 6 files changed, 48 insertions(+), 7 deletions(-) diff --git a/services/sky/BUILD.gn b/services/sky/BUILD.gn index 9b77b20a1..90ee4610e 100644 --- a/services/sky/BUILD.gn +++ b/services/sky/BUILD.gn @@ -47,6 +47,7 @@ mojo_native_application("sky") { "//mojo/services/surfaces/public/interfaces", "//mojo/services/view_manager/public/cpp", "//mojo/services/view_manager/public/interfaces", + "//services/asset_bundle:lib", "//services/sky/compositor", "//skia", "//sky/engine/public/sky", diff --git a/services/sky/document_view.cc b/services/sky/document_view.cc index dee2987c3..ae64f7200 100644 --- a/services/sky/document_view.cc +++ b/services/sky/document_view.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/location.h" +#include "base/message_loop/message_loop.h" #include "base/single_thread_task_runner.h" #include "base/strings/string_util.h" #include "base/thread_task_runner_handle.h" @@ -17,6 +18,7 @@ #include "mojo/services/view_manager/public/cpp/view.h" #include "mojo/services/view_manager/public/cpp/view_manager.h" #include "mojo/services/view_manager/public/interfaces/view_manager.mojom.h" +#include "services/asset_bundle/asset_unpacker_job.h" #include "services/sky/compositor/layer.h" #include "services/sky/compositor/layer_host.h" #include "services/sky/compositor/rasterizer_bitmap.h" @@ -34,9 +36,13 @@ #include "third_party/skia/include/core/SkDevice.h" #include "ui/events/gestures/gesture_recognizer.h" +using mojo::asset_bundle::AssetUnpackerJob; + namespace sky { namespace { +const char kSnapshotKey[] = "snapshot_blob.bin"; + ui::EventType ConvertEventTypeToUIEventType(blink::WebInputEvent::Type type) { if (type == blink::WebInputEvent::PointerDown) return ui::ET_TOUCH_PRESSED; @@ -133,17 +139,34 @@ void DocumentView::OnEmbed( void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { // TODO(aa): Need to figure out how shutdown works. } + +void DocumentView::LoadFromSnapshotStream( + String name, mojo::ScopedDataPipeConsumerHandle snapshot) { + if (sky_view_) + sky_view_->RunFromSnapshot(name, snapshot.Pass()); +} + void DocumentView::Load(mojo::URLResponsePtr response) { - String name = String::fromUTF8(response->url); - library_provider_.reset(new DartLibraryProviderImpl( - network_service_.get(), - CreatePrefetchedLibraryIfNeeded(name, response.Pass()))); sky_view_ = blink::SkyView::Create(this); layer_host_.reset(new LayerHost(this)); root_layer_ = make_scoped_refptr(new Layer(this)); root_layer_->set_rasterizer(CreateRasterizer()); layer_host_->SetRootLayer(root_layer_); + String name = String::fromUTF8(response->url); + if (name.endsWith(".skyx")) { + AssetUnpackerJob* unpacker = new AssetUnpackerJob( + mojo::GetProxy(&root_bundle_), + base::MessageLoop::current()->task_runner()); + unpacker->Unpack(response->body.Pass()); + root_bundle_->GetAsStream(kSnapshotKey, + base::Bind(&DocumentView::LoadFromSnapshotStream, + weak_factory_.GetWeakPtr(), name)); + return; + } + library_provider_.reset(new DartLibraryProviderImpl( + network_service_.get(), + CreatePrefetchedLibraryIfNeeded(name, response.Pass()))); sky_view_->RunFromLibrary(name, library_provider_.get()); } @@ -163,6 +186,10 @@ void DocumentView::GetPixelsForTesting(std::vector* pixels) { return bitmap_rasterizer_->GetPixelsForTesting(pixels); } +mojo::ScopedMessagePipeHandle DocumentView::TakeRootBundleHandle() { + return root_bundle_.PassInterface().PassHandle(); +} + mojo::ScopedMessagePipeHandle DocumentView::TakeServicesProvidedToEmbedder() { return services_provided_to_embedder_.PassMessagePipe(); } diff --git a/services/sky/document_view.h b/services/sky/document_view.h index f07e95e27..c6c89a1ae 100644 --- a/services/sky/document_view.h +++ b/services/sky/document_view.h @@ -11,6 +11,7 @@ #include "mojo/public/cpp/application/service_provider_impl.h" #include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/interfaces/application/application.mojom.h" +#include "mojo/services/asset_bundle/public/interfaces/asset_bundle.mojom.h" #include "mojo/services/content_handler/public/interfaces/content_handler.mojom.h" #include "mojo/services/navigation/public/interfaces/navigation.mojom.h" #include "mojo/services/network/public/interfaces/network_service.mojom.h" @@ -70,6 +71,7 @@ class DocumentView : public blink::ServiceProvider, void GetPixelsForTesting(std::vector* pixels); + mojo::ScopedMessagePipeHandle TakeRootBundleHandle(); mojo::ScopedMessagePipeHandle TakeServicesProvidedToEmbedder(); mojo::ScopedMessagePipeHandle TakeServicesProvidedByEmbedder(); mojo::ScopedMessagePipeHandle TakeServiceRegistry(); @@ -104,6 +106,9 @@ class DocumentView : public blink::ServiceProvider, float GetDevicePixelRatio() const; scoped_ptr CreateRasterizer(); + void LoadFromSnapshotStream(String name, + mojo::ScopedDataPipeConsumerHandle snapshot); + void UpdateRootSizeAndViewportMetrics(const mojo::Rect& new_bounds); void InitServiceRegistry(); @@ -115,6 +120,7 @@ class DocumentView : public blink::ServiceProvider, mojo::ServiceProviderPtr services_provided_by_embedder_; mojo::NetworkServicePtr network_service_; mojo::Shell* shell_; + mojo::asset_bundle::AssetBundlePtr root_bundle_; mojo::NavigatorHostPtr navigator_host_; std::unique_ptr sky_view_; mojo::View* root_; diff --git a/services/sky/internals.cc b/services/sky/internals.cc index 107799469..3dbd5dfbd 100644 --- a/services/sky/internals.cc +++ b/services/sky/internals.cc @@ -31,7 +31,8 @@ void NotifyTestComplete(Dart_NativeArguments args) { } void TakeRootBundleHandle(Dart_NativeArguments args) { - Dart_SetIntegerReturnValue(args, 0); + Dart_SetIntegerReturnValue(args, + GetInternals()->TakeRootBundleHandle().value()); } void TakeShellProxyHandle(Dart_NativeArguments args) { @@ -100,6 +101,12 @@ Internals::Internals(DocumentView* document_view) Internals::~Internals() { } +mojo::Handle Internals::TakeRootBundleHandle() { + if (!document_view_) + return mojo::Handle(); + return document_view_->TakeRootBundleHandle().release(); +} + mojo::Handle Internals::TakeServicesProvidedToEmbedder() { if (!document_view_) return mojo::Handle(); diff --git a/services/sky/internals.h b/services/sky/internals.h index 9addd8ead..8f7245809 100644 --- a/services/sky/internals.h +++ b/services/sky/internals.h @@ -28,6 +28,7 @@ class Internals : public base::SupportsUserData::Data, mojo::ServiceProviderPtr exposed_services) override; mojo::Handle TakeShellProxyHandle(); + mojo::Handle TakeRootBundleHandle(); mojo::Handle TakeServicesProvidedToEmbedder(); mojo::Handle TakeServicesProvidedByEmbedder(); mojo::Handle TakeServiceRegistry(); diff --git a/sky/shell/ui/engine.cc b/sky/shell/ui/engine.cc index 431157f6b..058efdc98 100644 --- a/sky/shell/ui/engine.cc +++ b/sky/shell/ui/engine.cc @@ -30,11 +30,10 @@ namespace sky { namespace shell { +namespace { const char kSnapshotKey[] = "snapshot_blob.bin"; -namespace { - void Ignored(bool) { }