提交 f9281a1e 编写于 作者: C Chinmay Garde

Allow specification of the FLX bundle (containing no Dart snapshot) outside...

Allow specification of the FLX bundle (containing no Dart snapshot) outside the iOS/Mac application bundle.

Allows launching of apps without having any Xcodebuild step in the simulator.
上级 d4f97e4f
...@@ -48,7 +48,7 @@ interface SkyEngine { ...@@ -48,7 +48,7 @@ interface SkyEngine {
PushRoute(string route); PushRoute(string route);
PopRoute(); PopRoute();
RunFromFile(string main, string package_root); RunFromFile(string main, string package_root, string bundle);
RunFromPrecompiledSnapshot(string path); RunFromPrecompiledSnapshot(string path);
RunFromBundle(string path); RunFromBundle(string path);
......
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
// found in the LICENSE file. // found in the LICENSE file.
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "sky/shell/platform/ios/sky_app_delegate.h"
#include "sky/shell/platform/ios/sky_app_delegate.h"
#include "sky/shell/platform/mac/platform_mac.h" #include "sky/shell/platform/mac/platform_mac.h"
int main(int argc, const char * argv[]) { int main(int argc, const char* argv[]) {
return PlatformMacMain(argc, argv, ^(){ return sky::shell::PlatformMacMain(argc, argv, ^() {
return UIApplicationMain(argc, (char **)argv, nil, return UIApplicationMain(argc, (char**)argv, nil,
NSStringFromClass([SkyAppDelegate class])); NSStringFromClass([SkyAppDelegate class]));
}); });
} }
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import <OpenGLES/EAGL.h> #import <OpenGLES/EAGL.h>
#import <OpenGLES/EAGLDrawable.h> #import <OpenGLES/EAGLDrawable.h>
#include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
...@@ -15,10 +16,12 @@ ...@@ -15,10 +16,12 @@
#include "sky/services/engine/input_event.mojom.h" #include "sky/services/engine/input_event.mojom.h"
#include "sky/services/pointer/pointer.mojom.h" #include "sky/services/pointer/pointer.mojom.h"
#include "sky/shell/platform/ios/sky_dynamic_service_loader.h" #include "sky/shell/platform/ios/sky_dynamic_service_loader.h"
#include "sky/shell/platform/mac/platform_mac.h"
#include "sky/shell/platform/mac/platform_service_provider.h" #include "sky/shell/platform/mac/platform_service_provider.h"
#include "sky/shell/platform/mac/platform_view_mac.h" #include "sky/shell/platform/mac/platform_view_mac.h"
#include "sky/shell/shell.h" #include "sky/shell/shell.h"
#include "sky/shell/shell_view.h" #include "sky/shell/shell_view.h"
#include "sky/shell/switches.h"
#include "sky/shell/ui_delegate.h" #include "sky/shell/ui_delegate.h"
#include <strings.h> #include <strings.h>
...@@ -226,7 +229,6 @@ static std::string TracesBasePath() { ...@@ -226,7 +229,6 @@ static std::string TracesBasePath() {
// In case this runner is part of the precompilation SDK, the FLX bundle is // In case this runner is part of the precompilation SDK, the FLX bundle is
// present in the application bundle instead of the runner bundle. Attempt // present in the application bundle instead of the runner bundle. Attempt
// to resolve the path there first. // to resolve the path there first.
// TODO: Allow specification of the application bundle identifier
NSBundle* applicationBundle = [NSBundle NSBundle* applicationBundle = [NSBundle
bundleWithIdentifier:@"io.flutter.application.FlutterApplication"]; bundleWithIdentifier:@"io.flutter.application.FlutterApplication"];
NSString* path = [applicationBundle pathForResource:@"app" ofType:@"flx"]; NSString* path = [applicationBundle pathForResource:@"app" ofType:@"flx"];
...@@ -251,18 +253,44 @@ static std::string TracesBasePath() { ...@@ -251,18 +253,44 @@ static std::string TracesBasePath() {
services->services_provided_by_embedder = service_provider.Pass(); services->services_provided_by_embedder = service_provider.Pass();
_engine->SetServices(services.Pass()); _engine->SetServices(services.Pass());
mojo::String bundle_path([self flxBundlePath]); #if TARGET_IPHONE_SIMULATOR
[self runFromDartSource];
CHECK(bundle_path.size() != 0) #else
<< "There must be a valid FLX bundle to run the application"; [self runFromPrecompiledSource];
#endif
}
#if TARGET_IPHONE_SIMULATOR #if TARGET_IPHONE_SIMULATOR
_engine->RunFromBundle(bundle_path);
- (void)runFromDartSource {
if (sky::shell::AttemptLaunchFromCommandLineSwitches(_engine)) {
return;
}
UIAlertView* alert = [[UIAlertView alloc]
initWithTitle:@"Error"
message:@"Could not resolve one or all of either the main dart "
@"file path, the FLX bundle path or the package root "
@"on the host. Use the tooling to relaunch the "
@"application."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
#else #else
- (void)runFromPrecompiledSource {
mojo::String bundle_path([self flxBundlePath]);
CHECK(bundle_path.size() != 0)
<< "There must be a valid FLX bundle to run the application";
_engine->RunFromPrecompiledSnapshot(bundle_path); _engine->RunFromPrecompiledSnapshot(bundle_path);
#endif
} }
#endif // TARGET_IPHONE_SIMULATOR
#pragma mark - UIResponder overrides for raw touches #pragma mark - UIResponder overrides for raw touches
- (void)dispatchTouches:(NSSet*)touches phase:(UITouchPhase)phase { - (void)dispatchTouches:(NSSet*)touches phase:(UITouchPhase)phase {
......
...@@ -32,7 +32,7 @@ void AttachMessageLoopToMainRunLoop(void) { ...@@ -32,7 +32,7 @@ void AttachMessageLoopToMainRunLoop(void) {
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
[SkyApplication sharedApplication]; [SkyApplication sharedApplication];
return PlatformMacMain(argc, argv, ^() { return sky::shell::PlatformMacMain(argc, argv, ^() {
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(sky::shell::switches::kHelp)) { if (command_line.HasSwitch(sky::shell::switches::kHelp)) {
sky::shell::switches::PrintUsage("SkyShell"); sky::shell::switches::PrintUsage("SkyShell");
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef SKY_SHELL_MAC_PLATFORM_MAC_H_ #ifndef SKY_SHELL_PLATFORM_MAC_PLATFORM_MAC_H_
#define SKY_SHELL_MAC_PLATFORM_MAC_H_ #define SKY_SHELL_PLATFORM_MAC_PLATFORM_MAC_H_
#ifdef __cplusplus #include "sky/services/engine/sky_engine.mojom.h"
extern "C" {
#endif namespace sky {
namespace shell {
typedef int (^PlatformMacMainCallback)(void); typedef int (^PlatformMacMainCallback)(void);
...@@ -15,8 +16,9 @@ int PlatformMacMain(int argc, ...@@ -15,8 +16,9 @@ int PlatformMacMain(int argc,
const char* argv[], const char* argv[],
PlatformMacMainCallback callback); PlatformMacMainCallback callback);
#ifdef __cplusplus bool AttemptLaunchFromCommandLineSwitches(sky::SkyEnginePtr& engine);
}
#endif } // namespace shell
} // namespace sky
#endif // SKY_SHELL_MAC_PLATFORM_MAC_H_ #endif // SKY_SHELL_PLATFORM_MAC_PLATFORM_MAC_H_
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "sky/shell/platform/mac/platform_mac.h" #include "sky/shell/platform/mac/platform_mac.h"
#include <Foundation/Foundation.h>
#include <asl.h> #include <asl.h>
#include "base/at_exit.h" #include "base/at_exit.h"
#include "base/command_line.h" #include "base/command_line.h"
...@@ -21,6 +23,9 @@ ...@@ -21,6 +23,9 @@
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
namespace sky {
namespace shell {
static void InitializeLogging() { static void InitializeLogging() {
logging::LoggingSettings settings; logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
...@@ -72,7 +77,8 @@ int PlatformMacMain(int argc, ...@@ -72,7 +77,8 @@ int PlatformMacMain(int argc,
// marker that can be used as a reference for startup. // marker that can be used as a reference for startup.
TRACE_EVENT_INSTANT0("flutter", "main", TRACE_EVENT_SCOPE_PROCESS); TRACE_EVENT_INSTANT0("flutter", "main", TRACE_EVENT_SCOPE_PROCESS);
std::unique_ptr<base::MessageLoopForUI> message_loop(new base::MessageLoopForUI()); std::unique_ptr<base::MessageLoopForUI> message_loop(
new base::MessageLoopForUI());
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// One cannot start the message loop on the platform main thread. Instead, // One cannot start the message loop on the platform main thread. Instead,
...@@ -96,3 +102,95 @@ int PlatformMacMain(int argc, ...@@ -96,3 +102,95 @@ int PlatformMacMain(int argc,
return result; return result;
} }
static bool FlagsValidForCommandLineLaunch(const std::string& dart_main,
const std::string& package_root,
const std::string& bundle) {
if (dart_main.size() == 0 || package_root.size() == 0 || bundle.size() == 0) {
return false;
}
// Ensure that the paths exists. This catches cases where the user has
// successfully launched the application from the tooling but has since moved
// the source files on disk and is launching again directly.
NSFileManager* manager = [NSFileManager defaultManager];
if (![manager fileExistsAtPath:@(dart_main.c_str())]) {
return false;
}
if (![manager fileExistsAtPath:@(package_root.c_str())]) {
return false;
}
if (![manager fileExistsAtPath:@(bundle.c_str())]) {
return false;
}
return true;
}
static std::string ResolveCommandLineLaunchFlag(const char* name) {
auto command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(name)) {
return command_line.GetSwitchValueASCII(name);
}
const char* saved_default =
[[NSUserDefaults standardUserDefaults] stringForKey:@(name)].UTF8String;
if (saved_default != NULL) {
return saved_default;
}
return "";
}
bool AttemptLaunchFromCommandLineSwitches(sky::SkyEnginePtr& engine) {
base::mac::ScopedNSAutoreleasePool pool;
using namespace sky::shell::switches;
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
auto command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(kMainDartFile) ||
command_line.HasSwitch(kPackageRoot) || command_line.HasSwitch(kFLX)) {
// The main dart file, flx bundle and the package root must be specified in
// one go. We dont want to end up in a situation where we take one value
// from the command line and the others from user defaults. In case, any
// new flags are specified, forget about all the old ones.
[defaults removeObjectForKey:@(kMainDartFile)];
[defaults removeObjectForKey:@(kPackageRoot)];
[defaults removeObjectForKey:@(kFLX)];
[defaults synchronize];
}
std::string dart_main = ResolveCommandLineLaunchFlag(kMainDartFile);
std::string package_root = ResolveCommandLineLaunchFlag(kPackageRoot);
std::string bundle = ResolveCommandLineLaunchFlag(kFLX);
if (!FlagsValidForCommandLineLaunch(dart_main, package_root, bundle)) {
return false;
}
// Save the newly resolved dart main file and the package root to user
// defaults so that the next time the user launches the application in the
// simulator without the tooling, the application boots up.
[defaults setObject:@(dart_main.c_str()) forKey:@(kMainDartFile)];
[defaults setObject:@(package_root.c_str()) forKey:@(kPackageRoot)];
[defaults setObject:@(bundle.c_str()) forKey:@(kFLX)];
[defaults synchronize];
// Finally launch with the newly resolved arguments.
engine->RunFromFile(dart_main, package_root, bundle);
return true;
}
} // namespace shell
} // namespace sky
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "mojo/public/cpp/bindings/interface_request.h" #include "mojo/public/cpp/bindings/interface_request.h"
#include "sky/services/engine/input_event.mojom.h" #include "sky/services/engine/input_event.mojom.h"
#include "sky/services/pointer/pointer.mojom.h" #include "sky/services/pointer/pointer.mojom.h"
#include "sky/shell/platform/mac/platform_mac.h"
#include "sky/shell/platform/mac/platform_view_mac.h" #include "sky/shell/platform/mac/platform_view_mac.h"
#include "sky/shell/platform/mac/platform_service_provider.h" #include "sky/shell/platform/mac/platform_service_provider.h"
#include "sky/shell/shell_view.h" #include "sky/shell/shell_view.h"
...@@ -16,8 +17,7 @@ ...@@ -16,8 +17,7 @@
#include "sky/shell/ui_delegate.h" #include "sky/shell/ui_delegate.h"
static void DynamicServiceResolve(const mojo::String& service_name, static void DynamicServiceResolve(const mojo::String& service_name,
mojo::ScopedMessagePipeHandle handle) { mojo::ScopedMessagePipeHandle handle) {}
}
@interface SkyWindow ()<NSWindowDelegate> @interface SkyWindow ()<NSWindowDelegate>
...@@ -26,7 +26,8 @@ static void DynamicServiceResolve(const mojo::String& service_name, ...@@ -26,7 +26,8 @@ static void DynamicServiceResolve(const mojo::String& service_name,
@end @end
static inline pointer::PointerType EventTypeFromNSEventPhase(NSEventPhase phase) { static inline pointer::PointerType EventTypeFromNSEventPhase(
NSEventPhase phase) {
switch (phase) { switch (phase) {
case NSEventPhaseNone: case NSEventPhaseNone:
return pointer::PointerType::CANCEL; return pointer::PointerType::CANCEL;
...@@ -72,14 +73,8 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(NSEventPhase phase) ...@@ -72,14 +73,8 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(NSEventPhase phase)
self.platformView->SurfaceCreated(widget); self.platformView->SurfaceCreated(widget);
} }
- (NSString*)skyInitialBundleURL {
return [[NSBundle mainBundle] pathForResource:@"app" ofType:@"flx"];
}
// TODO(eseidel): This does not belong in sky_window! // TODO(eseidel): This does not belong in sky_window!
// Probably belongs in NSApplicationDelegate didFinishLaunching. // Probably belongs in NSApplicationDelegate didFinishLaunching.
// We also want a separate setup for normal apps vs SkyShell
// normal apps only use a flx vs. SkyShell which always pulls from network.
- (void)setupAndLoadDart { - (void)setupAndLoadDart {
self.platformView->ConnectToEngine(mojo::GetProxy(&_sky_engine)); self.platformView->ConnectToEngine(mojo::GetProxy(&_sky_engine));
...@@ -90,9 +85,16 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(NSEventPhase phase) ...@@ -90,9 +85,16 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(NSEventPhase phase)
services->services_provided_by_embedder = service_provider.Pass(); services->services_provided_by_embedder = service_provider.Pass();
_sky_engine->SetServices(services.Pass()); _sky_engine->SetServices(services.Pass());
if (sky::shell::AttemptLaunchFromCommandLineSwitches(_sky_engine)) {
// This attempts launching from an FLX bundle that does not contain a
// dart snapshot.
return;
}
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
std::string flx = command_line.GetSwitchValueASCII(sky::shell::switches::kFLX); std::string flx =
command_line.GetSwitchValueASCII(sky::shell::switches::kFLX);
if (!flx.empty()) { if (!flx.empty()) {
_sky_engine->RunFromBundle(flx); _sky_engine->RunFromBundle(flx);
return; return;
...@@ -100,15 +102,9 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(NSEventPhase phase) ...@@ -100,15 +102,9 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(NSEventPhase phase)
auto args = command_line.GetArgs(); auto args = command_line.GetArgs();
if (args.size() > 0) { if (args.size() > 0) {
_sky_engine->RunFromFile(args[0], auto package_root =
command_line.GetSwitchValueASCII(sky::shell::switches::kPackageRoot)); command_line.GetSwitchValueASCII(sky::shell::switches::kPackageRoot);
return; _sky_engine->RunFromFile(args[0], package_root, "");
}
NSString *endpoint = self.skyInitialBundleURL;
if (endpoint.length > 0) {
mojo::String string(endpoint.UTF8String);
_sky_engine->RunFromBundle(string);
return; return;
} }
} }
......
...@@ -14,6 +14,7 @@ const char kEnableCheckedMode[] = "enable-checked-mode"; ...@@ -14,6 +14,7 @@ const char kEnableCheckedMode[] = "enable-checked-mode";
const char kFLX[] = "flx"; const char kFLX[] = "flx";
const char kHelp[] = "help"; const char kHelp[] = "help";
const char kNonInteractive[] = "non-interactive"; const char kNonInteractive[] = "non-interactive";
const char kMainDartFile[] = "dart-main";
const char kPackageRoot[] = "package-root"; const char kPackageRoot[] = "package-root";
const char kStartPaused[] = "start-paused"; const char kStartPaused[] = "start-paused";
const char kTraceStartup[] = "trace-startup"; const char kTraceStartup[] = "trace-startup";
......
...@@ -15,6 +15,7 @@ extern const char kEnableCheckedMode[]; ...@@ -15,6 +15,7 @@ extern const char kEnableCheckedMode[];
extern const char kFLX[]; extern const char kFLX[];
extern const char kHelp[]; extern const char kHelp[];
extern const char kNonInteractive[]; extern const char kNonInteractive[];
extern const char kMainDartFile[];
extern const char kPackageRoot[]; extern const char kPackageRoot[];
extern const char kStartPaused[]; extern const char kStartPaused[];
extern const char kTraceStartup[]; extern const char kTraceStartup[];
......
...@@ -22,8 +22,7 @@ static TestRunner* g_test_runner = nullptr; ...@@ -22,8 +22,7 @@ static TestRunner* g_test_runner = nullptr;
} // namespace } // namespace
TestRunner::TestRunner() TestRunner::TestRunner()
: shell_view_(new ShellView(Shell::Shared())), : shell_view_(new ShellView(Shell::Shared())), weak_ptr_factory_(this) {
weak_ptr_factory_(this) {
CHECK(!g_test_runner) << "Only create one TestRunner."; CHECK(!g_test_runner) << "Only create one TestRunner.";
shell_view_->view()->ConnectToEngine(GetProxy(&sky_engine_)); shell_view_->view()->ConnectToEngine(GetProxy(&sky_engine_));
...@@ -33,8 +32,7 @@ TestRunner::TestRunner() ...@@ -33,8 +32,7 @@ TestRunner::TestRunner()
sky_engine_->OnViewportMetricsChanged(metrics.Pass()); sky_engine_->OnViewportMetricsChanged(metrics.Pass());
} }
TestRunner::~TestRunner() { TestRunner::~TestRunner() {}
}
TestRunner& TestRunner::Shared() { TestRunner& TestRunner::Shared() {
if (!g_test_runner) if (!g_test_runner)
...@@ -43,7 +41,7 @@ TestRunner& TestRunner::Shared() { ...@@ -43,7 +41,7 @@ TestRunner& TestRunner::Shared() {
} }
void TestRunner::Run(const TestDescriptor& test) { void TestRunner::Run(const TestDescriptor& test) {
sky_engine_->RunFromFile(test.path, test.package_root); sky_engine_->RunFromFile(test.path, test.package_root, "");
} }
} // namespace shell } // namespace shell
......
...@@ -37,11 +37,9 @@ PlatformImpl* g_platform_impl = nullptr; ...@@ -37,11 +37,9 @@ PlatformImpl* g_platform_impl = nullptr;
using mojo::asset_bundle::ZipAssetBundle; using mojo::asset_bundle::ZipAssetBundle;
using mojo::asset_bundle::ZipAssetService; using mojo::asset_bundle::ZipAssetService;
Engine::Config::Config() { Engine::Config::Config() {}
}
Engine::Config::~Config() { Engine::Config::~Config() {}
}
Engine::Engine(const Config& config, rasterizer::RasterizerPtr rasterizer) Engine::Engine(const Config& config, rasterizer::RasterizerPtr rasterizer)
: config_(config), : config_(config),
...@@ -49,11 +47,9 @@ Engine::Engine(const Config& config, rasterizer::RasterizerPtr rasterizer) ...@@ -49,11 +47,9 @@ Engine::Engine(const Config& config, rasterizer::RasterizerPtr rasterizer)
binding_(this), binding_(this),
activity_running_(false), activity_running_(false),
have_surface_(false), have_surface_(false),
weak_factory_(this) { weak_factory_(this) {}
}
Engine::~Engine() { Engine::~Engine() {}
}
base::WeakPtr<Engine> Engine::GetWeakPtr() { base::WeakPtr<Engine> Engine::GetWeakPtr() {
return weak_factory_.GetWeakPtr(); return weak_factory_.GetWeakPtr();
...@@ -185,13 +181,16 @@ void Engine::RunFromSnapshotStream( ...@@ -185,13 +181,16 @@ void Engine::RunFromSnapshotStream(
sky_view_->PushRoute(initial_route_); sky_view_->PushRoute(initial_route_);
} }
void Engine::ConfigureZipAssetBundle(const mojo::String& path) {
zip_asset_bundle_ = new ZipAssetBundle(base::FilePath(std::string{path}),
base::WorkerPool::GetTaskRunner(true));
ZipAssetService::Create(mojo::GetProxy(&root_bundle_), zip_asset_bundle_);
}
void Engine::RunFromPrecompiledSnapshot(const mojo::String& bundle_path) { void Engine::RunFromPrecompiledSnapshot(const mojo::String& bundle_path) {
TRACE_EVENT0("flutter", "Engine::RunFromPrecompiledSnapshot"); TRACE_EVENT0("flutter", "Engine::RunFromPrecompiledSnapshot");
std::string path_str = bundle_path; ConfigureZipAssetBundle(bundle_path);
zip_asset_bundle_ = new ZipAssetBundle(
base::FilePath(path_str), base::WorkerPool::GetTaskRunner(true));
ZipAssetService::Create(mojo::GetProxy(&root_bundle_), zip_asset_bundle_);
sky_view_ = blink::SkyView::Create(this); sky_view_ = blink::SkyView::Create(this);
sky_view_->CreateView("http://localhost"); sky_view_->CreateView("http://localhost");
...@@ -203,8 +202,13 @@ void Engine::RunFromPrecompiledSnapshot(const mojo::String& bundle_path) { ...@@ -203,8 +202,13 @@ void Engine::RunFromPrecompiledSnapshot(const mojo::String& bundle_path) {
} }
void Engine::RunFromFile(const mojo::String& main, void Engine::RunFromFile(const mojo::String& main,
const mojo::String& package_root) { const mojo::String& package_root,
const mojo::String& bundle) {
TRACE_EVENT0("flutter", "Engine::RunFromFile"); TRACE_EVENT0("flutter", "Engine::RunFromFile");
if (bundle.size() != 0) {
// The specification of an FLX bundle is optional.
ConfigureZipAssetBundle(bundle);
}
std::string package_root_str = package_root; std::string package_root_str = package_root;
dart_library_provider_.reset( dart_library_provider_.reset(
new DartLibraryProviderFiles(base::FilePath(package_root_str))); new DartLibraryProviderFiles(base::FilePath(package_root_str)));
...@@ -213,32 +217,29 @@ void Engine::RunFromFile(const mojo::String& main, ...@@ -213,32 +217,29 @@ void Engine::RunFromFile(const mojo::String& main,
void Engine::RunFromBundle(const mojo::String& path) { void Engine::RunFromBundle(const mojo::String& path) {
TRACE_EVENT0("flutter", "Engine::RunFromBundle"); TRACE_EVENT0("flutter", "Engine::RunFromBundle");
std::string path_str = path;
zip_asset_bundle_ = new ZipAssetBundle(
base::FilePath(path_str), base::WorkerPool::GetTaskRunner(true));
ZipAssetService::Create(mojo::GetProxy(&root_bundle_), zip_asset_bundle_);
root_bundle_->GetAsStream(blink::kSnapshotAssetKey, ConfigureZipAssetBundle(path);
base::Bind(&Engine::RunFromSnapshotStream,
weak_factory_.GetWeakPtr(), path_str)); root_bundle_->GetAsStream(
blink::kSnapshotAssetKey,
base::Bind(&Engine::RunFromSnapshotStream, weak_factory_.GetWeakPtr(),
std::string{path}));
} }
void Engine::RunFromBundleAndSnapshot(const mojo::String& bundle_path, void Engine::RunFromBundleAndSnapshot(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");
std::string bundle_path_str = bundle_path;
zip_asset_bundle_ = new ZipAssetBundle( ConfigureZipAssetBundle(bundle_path);
base::FilePath(bundle_path_str), base::WorkerPool::GetTaskRunner(true));
ZipAssetService::Create(mojo::GetProxy(&root_bundle_), zip_asset_bundle_);
std::string snapshot_path_str = snapshot_path; std::string snapshot_path_str = snapshot_path;
zip_asset_bundle_->AddOverlayFile(blink::kSnapshotAssetKey, zip_asset_bundle_->AddOverlayFile(blink::kSnapshotAssetKey,
base::FilePath(snapshot_path_str)); base::FilePath(snapshot_path_str));
root_bundle_->GetAsStream(blink::kSnapshotAssetKey, root_bundle_->GetAsStream(
base::Bind(&Engine::RunFromSnapshotStream, blink::kSnapshotAssetKey,
weak_factory_.GetWeakPtr(), base::Bind(&Engine::RunFromSnapshotStream, weak_factory_.GetWeakPtr(),
bundle_path_str)); std::string{bundle_path}));
} }
void Engine::PushRoute(const mojo::String& route) { void Engine::PushRoute(const mojo::String& route) {
...@@ -295,8 +296,7 @@ void Engine::FlushRealTimeEvents() { ...@@ -295,8 +296,7 @@ void Engine::FlushRealTimeEvents() {
animator_->FlushRealTimeEvents(); animator_->FlushRealTimeEvents();
} }
void Engine::Render(std::unique_ptr<flow::LayerTree> layer_tree) { void Engine::Render(std::unique_ptr<flow::LayerTree> layer_tree) {}
}
} // namespace shell } // namespace shell
} // namespace sky } // namespace sky
...@@ -68,7 +68,8 @@ class Engine : public UIDelegate, ...@@ -68,7 +68,8 @@ class Engine : public UIDelegate,
void OnPointerPacket(pointer::PointerPacketPtr packet) override; void OnPointerPacket(pointer::PointerPacketPtr packet) override;
void RunFromFile(const mojo::String& main, void RunFromFile(const mojo::String& main,
const mojo::String& package_root) override; const mojo::String& package_root,
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& path) override;
void RunFromBundleAndSnapshot(const mojo::String& bundle_path, void RunFromBundleAndSnapshot(const mojo::String& bundle_path,
...@@ -92,6 +93,8 @@ class Engine : public UIDelegate, ...@@ -92,6 +93,8 @@ class Engine : public UIDelegate,
void StopAnimator(); void StopAnimator();
void StartAnimatorIfPossible(); void StartAnimatorIfPossible();
void ConfigureZipAssetBundle(const mojo::String& path);
Config config_; Config config_;
std::unique_ptr<Animator> animator_; std::unique_ptr<Animator> animator_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册