Teach Stocks.apk how to load a skyx bundle
This CL teaches Stocks.apk how to start from a skyx bundle name |app.skyx| in the APK's asset collection. Stocks.apk still actually starts from |snapshot_blob.bin| because we can't yet produce skyx files as part of the build process. TBR=eseidel@google.com Review URL: https://codereview.chromium.org/1221033006.
This commit is contained in:
@@ -186,6 +186,10 @@ public class PlatformViewAndroid extends SurfaceView
|
||||
mSkyEngine.runFromSnapshot(path);
|
||||
}
|
||||
|
||||
public void loadBundle(String path) {
|
||||
mSkyEngine.runFromBundle(path);
|
||||
}
|
||||
|
||||
public void loadUrl(String url) {
|
||||
mSkyEngine.runFromNetwork(url);
|
||||
}
|
||||
|
||||
@@ -66,9 +66,16 @@ public class SkyActivity extends Activity {
|
||||
}
|
||||
|
||||
private void loadSnapshotIfAvailable() {
|
||||
File snapshot = new File(PathUtils.getDataDirectory(this), SkyApplication.SNAPSHOT);
|
||||
File dataDir = new File(PathUtils.getDataDirectory(this));
|
||||
File snapshot = new File(dataDir, SkyApplication.SNAPSHOT);
|
||||
if (snapshot.exists()) {
|
||||
mView.loadSnapshot(snapshot.getPath());
|
||||
return;
|
||||
}
|
||||
File appBundle = new File(dataDir, SkyApplication.APP_BUNDLE);
|
||||
if (appBundle.exists()) {
|
||||
mView.loadBundle(appBundle.getPath());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,11 @@ import org.domokit.oknet.NetworkServiceImpl;
|
||||
*/
|
||||
public class SkyApplication extends BaseChromiumApplication {
|
||||
static final String SNAPSHOT = "snapshot_blob.bin";
|
||||
static final String APP_BUNDLE = "app.skyx";
|
||||
|
||||
private static final String TAG = "SkyApplication";
|
||||
private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "sky_shell";
|
||||
private static final String[] SKY_RESOURCES = {
|
||||
"icudtl.dat", SNAPSHOT
|
||||
};
|
||||
private static final String[] SKY_RESOURCES = {"icudtl.dat", SNAPSHOT, APP_BUNDLE};
|
||||
|
||||
private ResourceExtractor mResourceExtractor;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "mojo/common/data_pipe_utils.h"
|
||||
#include "mojo/public/cpp/application/connect.h"
|
||||
#include "services/asset_bundle/asset_unpacker_job.h"
|
||||
#include "sky/engine/public/platform/WebInputEvent.h"
|
||||
#include "sky/engine/public/platform/sky_display_metrics.h"
|
||||
#include "sky/engine/public/platform/sky_display_metrics.h"
|
||||
@@ -27,6 +28,8 @@
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
const char kSnapshotKey[] = "snapshot_blob.bin";
|
||||
|
||||
namespace {
|
||||
|
||||
void Ignored(bool) {
|
||||
@@ -42,7 +45,9 @@ mojo::ScopedDataPipeConsumerHandle Fetch(const base::FilePath& path) {
|
||||
|
||||
PlatformImpl* g_platform_impl = nullptr;
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
using mojo::asset_bundle::AssetUnpackerJob;
|
||||
|
||||
Engine::Config::Config() {
|
||||
}
|
||||
@@ -150,13 +155,21 @@ void Engine::OnInputEvent(InputEventPtr event) {
|
||||
sky_view_->HandleInputEvent(*web_event);
|
||||
}
|
||||
|
||||
void Engine::RunFromLibrary(const mojo::String& name) {
|
||||
void Engine::RunFromLibrary(const std::string& name) {
|
||||
sky_view_ = blink::SkyView::Create(this);
|
||||
sky_view_->RunFromLibrary(blink::WebString::fromUTF8(name),
|
||||
dart_library_provider_.get());
|
||||
UpdateSkyViewSize();
|
||||
}
|
||||
|
||||
void Engine::RunFromSnapshotStream(
|
||||
const std::string& name,
|
||||
mojo::ScopedDataPipeConsumerHandle snapshot) {
|
||||
sky_view_ = blink::SkyView::Create(this);
|
||||
sky_view_->RunFromSnapshot(blink::WebString::fromUTF8(name), snapshot.Pass());
|
||||
UpdateSkyViewSize();
|
||||
}
|
||||
|
||||
void Engine::RunFromNetwork(const mojo::String& url) {
|
||||
dart_library_provider_.reset(
|
||||
new DartLibraryProviderNetwork(g_platform_impl->networkService()));
|
||||
@@ -171,10 +184,18 @@ void Engine::RunFromFile(const mojo::String& main,
|
||||
}
|
||||
|
||||
void Engine::RunFromSnapshot(const mojo::String& path) {
|
||||
sky_view_ = blink::SkyView::Create(this);
|
||||
sky_view_->RunFromSnapshot(blink::WebString::fromUTF8(path),
|
||||
Fetch(base::FilePath(path)));
|
||||
UpdateSkyViewSize();
|
||||
std::string path_str = path;
|
||||
RunFromSnapshotStream(path_str, Fetch(base::FilePath(path_str)));
|
||||
}
|
||||
|
||||
void Engine::RunFromBundle(const mojo::String& path) {
|
||||
AssetUnpackerJob* unpacker = new AssetUnpackerJob(
|
||||
mojo::GetProxy(&root_bundle_), base::WorkerPool::GetTaskRunner(true));
|
||||
std::string path_str = path;
|
||||
unpacker->Unpack(Fetch(base::FilePath(path_str)));
|
||||
root_bundle_->GetAsStream(kSnapshotKey,
|
||||
base::Bind(&Engine::RunFromSnapshotStream,
|
||||
weak_factory_.GetWeakPtr(), path_str));
|
||||
}
|
||||
|
||||
void Engine::DidCreateIsolate(Dart_Isolate isolate) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "mojo/public/cpp/bindings/binding.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
#include "mojo/public/interfaces/application/service_provider.mojom.h"
|
||||
#include "mojo/services/asset_bundle/public/interfaces/asset_bundle.mojom.h"
|
||||
#include "mojo/services/navigation/public/interfaces/navigation.mojom.h"
|
||||
#include "skia/ext/refptr.h"
|
||||
#include "sky/engine/public/platform/ServiceProvider.h"
|
||||
@@ -69,6 +70,7 @@ class Engine : public UIDelegate,
|
||||
void RunFromFile(const mojo::String& main,
|
||||
const mojo::String& package_root) override;
|
||||
void RunFromSnapshot(const mojo::String& path) override;
|
||||
void RunFromBundle(const mojo::String& path) override;
|
||||
|
||||
// SkyViewClient methods:
|
||||
void ScheduleFrame() override;
|
||||
@@ -83,13 +85,16 @@ class Engine : public UIDelegate,
|
||||
void DidNavigateLocally(const mojo::String& url) override;
|
||||
void RequestNavigateHistory(int32_t delta) override;
|
||||
|
||||
void RunFromLibrary(const mojo::String& name);
|
||||
void RunFromLibrary(const std::string& name);
|
||||
void RunFromSnapshotStream(const std::string& name,
|
||||
mojo::ScopedDataPipeConsumerHandle snapshot);
|
||||
|
||||
void UpdateSkyViewSize();
|
||||
|
||||
Config config_;
|
||||
scoped_ptr<Animator> animator_;
|
||||
|
||||
mojo::asset_bundle::AssetBundlePtr root_bundle_;
|
||||
scoped_ptr<blink::DartLibraryProvider> dart_library_provider_;
|
||||
std::unique_ptr<blink::SkyView> sky_view_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user