提交 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,
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<ZipAssetBundle> zip_asset_bundle(
new ZipAssetBundle(flx_path, nullptr));
new ZipAssetBundle(bundle_path, nullptr));
CHECK(zip_asset_bundle->GetAsBuffer(kSnapshotAssetKey, &snapshot_data));
}
......
......@@ -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);
};
......@@ -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);
}
}
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -66,7 +66,7 @@ class ApplicationImpl : public mojo::Application,
mojo::BindingSet<mojo::ui::ViewProvider> view_provider_bindings_;
std::string url_;
mojo::ShellPtr shell_;
base::FilePath flx_path_;
base::FilePath bundle_path_;
};
} // namespace shell
......
......@@ -57,8 +57,8 @@ ViewImpl::ViewImpl(mojo::InterfaceRequest<mojo::ui::ViewOwner> 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,
......
......@@ -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
......
......@@ -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) {
......
......@@ -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<mojo::ServiceProvider> 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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册