From 410aac589b29c2bfecbb184f86c0109f08206d95 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 18 Mar 2016 09:53:44 -0700 Subject: [PATCH] Flutter apps in Mozart should have reasonable Uri.base Previously this value was the temp directory that we used to store the FLX bundle. Now it's the URL given to us by MojoShell. --- sky/engine/core/script/dart_init.cc | 4 ++-- sky/services/engine/sky_engine.mojom | 8 ++++---- .../org/domokit/sky/shell/PlatformViewAndroid.java | 5 +++-- sky/shell/platform/mac/sky_window.mm | 7 ++++--- sky/shell/platform/mojo/application_impl.cc | 12 ++++++------ sky/shell/platform/mojo/application_impl.h | 2 +- sky/shell/platform/mojo/view_impl.cc | 4 ++-- sky/shell/platform/mojo/view_impl.h | 2 +- sky/shell/ui/engine.cc | 13 +++++++------ sky/shell/ui/engine.h | 8 +++++--- 10 files changed, 35 insertions(+), 30 deletions(-) diff --git a/sky/engine/core/script/dart_init.cc b/sky/engine/core/script/dart_init.cc index d087c7ca5..5d399e6d5 100644 --- a/sky/engine/core/script/dart_init.cc +++ b/sky/engine/core/script/dart_init.cc @@ -160,9 +160,9 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, if (!IsRunningPrecompiledCode()) { CHECK(base::StartsWith(script_uri, kFileUriPrefix, base::CompareCase::SENSITIVE)); - base::FilePath flx_path(script_uri + strlen(kFileUriPrefix)); + base::FilePath bundle_path(script_uri + strlen(kFileUriPrefix)); scoped_refptr zip_asset_bundle( - new ZipAssetBundle(flx_path, nullptr)); + new ZipAssetBundle(bundle_path, nullptr)); CHECK(zip_asset_bundle->GetAsBuffer(kSnapshotAssetKey, &snapshot_data)); } diff --git a/sky/services/engine/sky_engine.mojom b/sky/services/engine/sky_engine.mojom index 48ac724c7..009d6f862 100644 --- a/sky/services/engine/sky_engine.mojom +++ b/sky/services/engine/sky_engine.mojom @@ -48,11 +48,11 @@ interface SkyEngine { PushRoute(string route); PopRoute(); - RunFromFile(string main, string package_root, string bundle); - RunFromPrecompiledSnapshot(string path); - RunFromBundle(string path); + RunFromFile(string main, string package_root, string bundle_path); + RunFromPrecompiledSnapshot(string bundle_path); + RunFromBundle(string script_uri, string bundle_path); // Run the app from a bundle, but obtain the snapshot from snapshot_path // instead of using the snapshot within the bundle. - RunFromBundleAndSnapshot(string bundle_path, string snapshot_path); + RunFromBundleAndSnapshot(string script_uri, string bundle_path, string snapshot_path); }; diff --git a/sky/shell/platform/android/org/domokit/sky/shell/PlatformViewAndroid.java b/sky/shell/platform/android/org/domokit/sky/shell/PlatformViewAndroid.java index a6a18b60d..35c871663 100644 --- a/sky/shell/platform/android/org/domokit/sky/shell/PlatformViewAndroid.java +++ b/sky/shell/platform/android/org/domokit/sky/shell/PlatformViewAndroid.java @@ -366,10 +366,11 @@ public class PlatformViewAndroid extends SurfaceView resetAccessibilityTree(); + String scriptUri = "file://" + bundlePath; if (snapshotPath != null) { - mSkyEngine.runFromBundleAndSnapshot(bundlePath, snapshotPath); + mSkyEngine.runFromBundleAndSnapshot(scriptUri, bundlePath, snapshotPath); } else { - mSkyEngine.runFromBundle(bundlePath); + mSkyEngine.runFromBundle(scriptUri, bundlePath); } } diff --git a/sky/shell/platform/mac/sky_window.mm b/sky/shell/platform/mac/sky_window.mm index bcbbba589..577f322a5 100644 --- a/sky/shell/platform/mac/sky_window.mm +++ b/sky/shell/platform/mac/sky_window.mm @@ -93,10 +93,11 @@ static inline pointer::PointerType EventTypeFromNSEventPhase( base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); - std::string flx = + std::string bundle_path = command_line.GetSwitchValueASCII(sky::shell::switches::kFLX); - if (!flx.empty()) { - _sky_engine->RunFromBundle(flx); + if (!bundle_path.empty()) { + std::string script_uri = std::string("file://") + bundle_path; + _sky_engine->RunFromBundle(script_uri, bundle_path); return; } diff --git a/sky/shell/platform/mojo/application_impl.cc b/sky/shell/platform/mojo/application_impl.cc index a656d0637..19c0fbd82 100644 --- a/sky/shell/platform/mojo/application_impl.cc +++ b/sky/shell/platform/mojo/application_impl.cc @@ -20,8 +20,8 @@ ApplicationImpl::ApplicationImpl( } ApplicationImpl::~ApplicationImpl() { - if (!flx_path_.empty()) { - base::DeleteFile(flx_path_, false); + if (!bundle_path_.empty()) { + base::DeleteFile(bundle_path_, false); } } @@ -82,18 +82,18 @@ void ApplicationImpl::CreateView( services->services_provided_to_embedder = outgoing_services.Pass(); ViewImpl* view = new ViewImpl(view_owner.Pass(), services.Pass(), url_); - view->Run(flx_path_); + view->Run(bundle_path_); } void ApplicationImpl::UnpackInitialResponse(mojo::Shell* shell) { DCHECK(initial_response_); - DCHECK(flx_path_.empty()); + DCHECK(bundle_path_.empty()); - if (!base::CreateTemporaryFile(&flx_path_)) { + if (!base::CreateTemporaryFile(&bundle_path_)) { LOG(ERROR) << "Unable to create temporary file"; return; } - FILE* temp_file = base::OpenFile(flx_path_, "w"); + FILE* temp_file = base::OpenFile(bundle_path_, "w"); if (temp_file == nullptr) { LOG(ERROR) << "Unable to open temporary file"; return; diff --git a/sky/shell/platform/mojo/application_impl.h b/sky/shell/platform/mojo/application_impl.h index 494792698..e15f23280 100644 --- a/sky/shell/platform/mojo/application_impl.h +++ b/sky/shell/platform/mojo/application_impl.h @@ -66,7 +66,7 @@ class ApplicationImpl : public mojo::Application, mojo::BindingSet view_provider_bindings_; std::string url_; mojo::ShellPtr shell_; - base::FilePath flx_path_; + base::FilePath bundle_path_; }; } // namespace shell diff --git a/sky/shell/platform/mojo/view_impl.cc b/sky/shell/platform/mojo/view_impl.cc index 02546e473..8ff54cafb 100644 --- a/sky/shell/platform/mojo/view_impl.cc +++ b/sky/shell/platform/mojo/view_impl.cc @@ -57,8 +57,8 @@ ViewImpl::ViewImpl(mojo::InterfaceRequest view_owner, ViewImpl::~ViewImpl() { } -void ViewImpl::Run(base::FilePath flx_path) { - engine_->RunFromBundle(mojo::String(flx_path.value())); +void ViewImpl::Run(base::FilePath bundle_path) { + engine_->RunFromBundle(url_, bundle_path.value()); } void ViewImpl::OnLayout(mojo::ui::ViewLayoutParamsPtr layout_params, diff --git a/sky/shell/platform/mojo/view_impl.h b/sky/shell/platform/mojo/view_impl.h index 05586d371..7c9c72018 100644 --- a/sky/shell/platform/mojo/view_impl.h +++ b/sky/shell/platform/mojo/view_impl.h @@ -28,7 +28,7 @@ class ViewImpl : public mojo::ui::ViewListener, const std::string& url); ~ViewImpl() override; - void Run(base::FilePath flx_path); + void Run(base::FilePath bundle_path); private: // mojo::ui::ViewListener diff --git a/sky/shell/ui/engine.cc b/sky/shell/ui/engine.cc index 090d7f332..6d5fc338c 100644 --- a/sky/shell/ui/engine.cc +++ b/sky/shell/ui/engine.cc @@ -176,10 +176,9 @@ void Engine::RunFromLibrary(const std::string& name) { } void Engine::RunFromSnapshotStream( - const std::string& bundle_path, + const std::string& script_uri, mojo::ScopedDataPipeConsumerHandle snapshot) { TRACE_EVENT0("flutter", "Engine::RunFromSnapshotStream"); - std::string script_uri = std::string("file://") + bundle_path; sky_view_ = blink::SkyView::Create(this); sky_view_->CreateView(script_uri); sky_view_->RunFromSnapshot(snapshot.Pass()); @@ -223,7 +222,8 @@ void Engine::RunFromFile(const mojo::String& main, RunFromLibrary(main); } -void Engine::RunFromBundle(const mojo::String& path) { +void Engine::RunFromBundle(const mojo::String& script_uri, + const mojo::String& path) { TRACE_EVENT0("flutter", "Engine::RunFromBundle"); ConfigureZipAssetBundle(path); @@ -231,10 +231,11 @@ void Engine::RunFromBundle(const mojo::String& path) { root_bundle_->GetAsStream( blink::kSnapshotAssetKey, base::Bind(&Engine::RunFromSnapshotStream, weak_factory_.GetWeakPtr(), - std::string{path})); + script_uri)); } -void Engine::RunFromBundleAndSnapshot(const mojo::String& bundle_path, +void Engine::RunFromBundleAndSnapshot(const mojo::String& script_uri, + const mojo::String& bundle_path, const mojo::String& snapshot_path) { TRACE_EVENT0("flutter", "Engine::RunFromBundleAndSnapshot"); @@ -247,7 +248,7 @@ void Engine::RunFromBundleAndSnapshot(const mojo::String& bundle_path, root_bundle_->GetAsStream( blink::kSnapshotAssetKey, base::Bind(&Engine::RunFromSnapshotStream, weak_factory_.GetWeakPtr(), - std::string{bundle_path})); + script_uri)); } void Engine::PushRoute(const mojo::String& route) { diff --git a/sky/shell/ui/engine.h b/sky/shell/ui/engine.h index 3d13cda87..4004f383e 100644 --- a/sky/shell/ui/engine.h +++ b/sky/shell/ui/engine.h @@ -74,8 +74,10 @@ class Engine : public UIDelegate, const mojo::String& package_root, const mojo::String& bundle) override; void RunFromPrecompiledSnapshot(const mojo::String& bundle_path) override; - void RunFromBundle(const mojo::String& path) override; - void RunFromBundleAndSnapshot(const mojo::String& bundle_path, + void RunFromBundle(const mojo::String& script_uri, + const mojo::String& bundle_path) override; + void RunFromBundleAndSnapshot(const mojo::String& script_uri, + const mojo::String& bundle_path, const mojo::String& snapshot_path) override; void PushRoute(const mojo::String& route) override; void PopRoute() override; @@ -92,7 +94,7 @@ class Engine : public UIDelegate, mojo::InterfaceRequest request); void RunFromLibrary(const std::string& name); - void RunFromSnapshotStream(const std::string& name, + void RunFromSnapshotStream(const std::string& script_uri, mojo::ScopedDataPipeConsumerHandle snapshot); void SetupAssetBundle(const mojo::String& bundle_path); -- GitLab