提交 410aac58 编写于 作者: A Adam Barth

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.
上级 138fae11
...@@ -160,9 +160,9 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, ...@@ -160,9 +160,9 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
if (!IsRunningPrecompiledCode()) { if (!IsRunningPrecompiledCode()) {
CHECK(base::StartsWith(script_uri, kFileUriPrefix, CHECK(base::StartsWith(script_uri, kFileUriPrefix,
base::CompareCase::SENSITIVE)); base::CompareCase::SENSITIVE));
base::FilePath flx_path(script_uri + strlen(kFileUriPrefix)); base::FilePath bundle_path(script_uri + strlen(kFileUriPrefix));
scoped_refptr<ZipAssetBundle> zip_asset_bundle( scoped_refptr<ZipAssetBundle> zip_asset_bundle(
new ZipAssetBundle(flx_path, nullptr)); new ZipAssetBundle(bundle_path, nullptr));
CHECK(zip_asset_bundle->GetAsBuffer(kSnapshotAssetKey, &snapshot_data)); CHECK(zip_asset_bundle->GetAsBuffer(kSnapshotAssetKey, &snapshot_data));
} }
......
...@@ -48,11 +48,11 @@ interface SkyEngine { ...@@ -48,11 +48,11 @@ interface SkyEngine {
PushRoute(string route); PushRoute(string route);
PopRoute(); PopRoute();
RunFromFile(string main, string package_root, string bundle); RunFromFile(string main, string package_root, string bundle_path);
RunFromPrecompiledSnapshot(string path); RunFromPrecompiledSnapshot(string bundle_path);
RunFromBundle(string path); RunFromBundle(string script_uri, string bundle_path);
// Run the app from a bundle, but obtain the snapshot from snapshot_path // Run the app from a bundle, but obtain the snapshot from snapshot_path
// instead of using the snapshot within the bundle. // 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);
}; };
...@@ -366,10 +366,11 @@ public class PlatformViewAndroid extends SurfaceView ...@@ -366,10 +366,11 @@ public class PlatformViewAndroid extends SurfaceView
resetAccessibilityTree(); resetAccessibilityTree();
String scriptUri = "file://" + bundlePath;
if (snapshotPath != null) { if (snapshotPath != null) {
mSkyEngine.runFromBundleAndSnapshot(bundlePath, snapshotPath); mSkyEngine.runFromBundleAndSnapshot(scriptUri, bundlePath, snapshotPath);
} else { } else {
mSkyEngine.runFromBundle(bundlePath); mSkyEngine.runFromBundle(scriptUri, bundlePath);
} }
} }
......
...@@ -93,10 +93,11 @@ static inline pointer::PointerType EventTypeFromNSEventPhase( ...@@ -93,10 +93,11 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
std::string flx = std::string bundle_path =
command_line.GetSwitchValueASCII(sky::shell::switches::kFLX); command_line.GetSwitchValueASCII(sky::shell::switches::kFLX);
if (!flx.empty()) { if (!bundle_path.empty()) {
_sky_engine->RunFromBundle(flx); std::string script_uri = std::string("file://") + bundle_path;
_sky_engine->RunFromBundle(script_uri, bundle_path);
return; return;
} }
......
...@@ -20,8 +20,8 @@ ApplicationImpl::ApplicationImpl( ...@@ -20,8 +20,8 @@ ApplicationImpl::ApplicationImpl(
} }
ApplicationImpl::~ApplicationImpl() { ApplicationImpl::~ApplicationImpl() {
if (!flx_path_.empty()) { if (!bundle_path_.empty()) {
base::DeleteFile(flx_path_, false); base::DeleteFile(bundle_path_, false);
} }
} }
...@@ -82,18 +82,18 @@ void ApplicationImpl::CreateView( ...@@ -82,18 +82,18 @@ void ApplicationImpl::CreateView(
services->services_provided_to_embedder = outgoing_services.Pass(); services->services_provided_to_embedder = outgoing_services.Pass();
ViewImpl* view = new ViewImpl(view_owner.Pass(), services.Pass(), url_); ViewImpl* view = new ViewImpl(view_owner.Pass(), services.Pass(), url_);
view->Run(flx_path_); view->Run(bundle_path_);
} }
void ApplicationImpl::UnpackInitialResponse(mojo::Shell* shell) { void ApplicationImpl::UnpackInitialResponse(mojo::Shell* shell) {
DCHECK(initial_response_); 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"; LOG(ERROR) << "Unable to create temporary file";
return; return;
} }
FILE* temp_file = base::OpenFile(flx_path_, "w"); FILE* temp_file = base::OpenFile(bundle_path_, "w");
if (temp_file == nullptr) { if (temp_file == nullptr) {
LOG(ERROR) << "Unable to open temporary file"; LOG(ERROR) << "Unable to open temporary file";
return; return;
......
...@@ -66,7 +66,7 @@ class ApplicationImpl : public mojo::Application, ...@@ -66,7 +66,7 @@ class ApplicationImpl : public mojo::Application,
mojo::BindingSet<mojo::ui::ViewProvider> view_provider_bindings_; mojo::BindingSet<mojo::ui::ViewProvider> view_provider_bindings_;
std::string url_; std::string url_;
mojo::ShellPtr shell_; mojo::ShellPtr shell_;
base::FilePath flx_path_; base::FilePath bundle_path_;
}; };
} // namespace shell } // namespace shell
......
...@@ -57,8 +57,8 @@ ViewImpl::ViewImpl(mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner, ...@@ -57,8 +57,8 @@ ViewImpl::ViewImpl(mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner,
ViewImpl::~ViewImpl() { ViewImpl::~ViewImpl() {
} }
void ViewImpl::Run(base::FilePath flx_path) { void ViewImpl::Run(base::FilePath bundle_path) {
engine_->RunFromBundle(mojo::String(flx_path.value())); engine_->RunFromBundle(url_, bundle_path.value());
} }
void ViewImpl::OnLayout(mojo::ui::ViewLayoutParamsPtr layout_params, void ViewImpl::OnLayout(mojo::ui::ViewLayoutParamsPtr layout_params,
......
...@@ -28,7 +28,7 @@ class ViewImpl : public mojo::ui::ViewListener, ...@@ -28,7 +28,7 @@ class ViewImpl : public mojo::ui::ViewListener,
const std::string& url); const std::string& url);
~ViewImpl() override; ~ViewImpl() override;
void Run(base::FilePath flx_path); void Run(base::FilePath bundle_path);
private: private:
// mojo::ui::ViewListener // mojo::ui::ViewListener
......
...@@ -176,10 +176,9 @@ void Engine::RunFromLibrary(const std::string& name) { ...@@ -176,10 +176,9 @@ void Engine::RunFromLibrary(const std::string& name) {
} }
void Engine::RunFromSnapshotStream( void Engine::RunFromSnapshotStream(
const std::string& bundle_path, const std::string& script_uri,
mojo::ScopedDataPipeConsumerHandle snapshot) { mojo::ScopedDataPipeConsumerHandle snapshot) {
TRACE_EVENT0("flutter", "Engine::RunFromSnapshotStream"); TRACE_EVENT0("flutter", "Engine::RunFromSnapshotStream");
std::string script_uri = std::string("file://") + bundle_path;
sky_view_ = blink::SkyView::Create(this); sky_view_ = blink::SkyView::Create(this);
sky_view_->CreateView(script_uri); sky_view_->CreateView(script_uri);
sky_view_->RunFromSnapshot(snapshot.Pass()); sky_view_->RunFromSnapshot(snapshot.Pass());
...@@ -223,7 +222,8 @@ void Engine::RunFromFile(const mojo::String& main, ...@@ -223,7 +222,8 @@ void Engine::RunFromFile(const mojo::String& main,
RunFromLibrary(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"); TRACE_EVENT0("flutter", "Engine::RunFromBundle");
ConfigureZipAssetBundle(path); ConfigureZipAssetBundle(path);
...@@ -231,10 +231,11 @@ void Engine::RunFromBundle(const mojo::String& path) { ...@@ -231,10 +231,11 @@ void Engine::RunFromBundle(const mojo::String& path) {
root_bundle_->GetAsStream( root_bundle_->GetAsStream(
blink::kSnapshotAssetKey, blink::kSnapshotAssetKey,
base::Bind(&Engine::RunFromSnapshotStream, weak_factory_.GetWeakPtr(), 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) { const mojo::String& snapshot_path) {
TRACE_EVENT0("flutter", "Engine::RunFromBundleAndSnapshot"); TRACE_EVENT0("flutter", "Engine::RunFromBundleAndSnapshot");
...@@ -247,7 +248,7 @@ void Engine::RunFromBundleAndSnapshot(const mojo::String& bundle_path, ...@@ -247,7 +248,7 @@ void Engine::RunFromBundleAndSnapshot(const mojo::String& bundle_path,
root_bundle_->GetAsStream( root_bundle_->GetAsStream(
blink::kSnapshotAssetKey, blink::kSnapshotAssetKey,
base::Bind(&Engine::RunFromSnapshotStream, weak_factory_.GetWeakPtr(), base::Bind(&Engine::RunFromSnapshotStream, weak_factory_.GetWeakPtr(),
std::string{bundle_path})); script_uri));
} }
void Engine::PushRoute(const mojo::String& route) { void Engine::PushRoute(const mojo::String& route) {
......
...@@ -74,8 +74,10 @@ class Engine : public UIDelegate, ...@@ -74,8 +74,10 @@ class Engine : public UIDelegate,
const mojo::String& package_root, const mojo::String& package_root,
const mojo::String& bundle) override; const mojo::String& bundle) override;
void RunFromPrecompiledSnapshot(const mojo::String& bundle_path) override; void RunFromPrecompiledSnapshot(const mojo::String& bundle_path) override;
void RunFromBundle(const mojo::String& path) override; void RunFromBundle(const mojo::String& script_uri,
void RunFromBundleAndSnapshot(const mojo::String& bundle_path, const mojo::String& bundle_path) override;
void RunFromBundleAndSnapshot(const mojo::String& script_uri,
const mojo::String& bundle_path,
const mojo::String& snapshot_path) override; const mojo::String& snapshot_path) override;
void PushRoute(const mojo::String& route) override; void PushRoute(const mojo::String& route) override;
void PopRoute() override; void PopRoute() override;
...@@ -92,7 +94,7 @@ class Engine : public UIDelegate, ...@@ -92,7 +94,7 @@ class Engine : public UIDelegate,
mojo::InterfaceRequest<mojo::ServiceProvider> request); mojo::InterfaceRequest<mojo::ServiceProvider> request);
void RunFromLibrary(const std::string& name); void RunFromLibrary(const std::string& name);
void RunFromSnapshotStream(const std::string& name, void RunFromSnapshotStream(const std::string& script_uri,
mojo::ScopedDataPipeConsumerHandle snapshot); mojo::ScopedDataPipeConsumerHandle snapshot);
void SetupAssetBundle(const mojo::String& bundle_path); void SetupAssetBundle(const mojo::String& bundle_path);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册