flutter_flutter/engine/core/script/dart_controller.h
Adam Barth 1a1ef489ee Make it possible to run Sky apps offline
This CL makes it possible to run Sky apps offline by introducing new
DartLibraryProvider subclasses, specifically one that can load directly from
the file system. A future CL will expand this functionality to work with asset
bundles as well.

Currently, the only platform that uses this functionality is Linux, which can
now load a simple Sky app without even loading a network stack. Making this
work on other platforms is work for future CLs.

TBR=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1203143004.
2015-06-25 13:59:22 -07:00

80 lines
2.4 KiB
C++

// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_SCRIPT_DART_CONTROLLER_H_
#define SKY_ENGINE_CORE_SCRIPT_DART_CONTROLLER_H_
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "dart/runtime/include/dart_api.h"
#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
#include "sky/engine/wtf/OwnPtr.h"
#include "sky/engine/wtf/text/AtomicString.h"
#include "sky/engine/wtf/text/TextPosition.h"
namespace blink {
class AbstractModule;
class BuiltinSky;
class DOMDartState;
class DartLibraryProvider;
class DartLibraryProviderWebView;
class DartSnapshotLoader;
class DartValue;
class HTMLScriptElement;
class KURL;
class View;
class DartController {
public:
DartController();
~DartController();
static void InitVM();
typedef base::Callback<void(RefPtr<AbstractModule>, RefPtr<DartValue>)>
LoadFinishedCallback;
void LoadSnapshot(const KURL& url, mojo::URLResponsePtr response = nullptr);
void RunFromLibrary(const String& name,
DartLibraryProvider* library_provider);
void LoadScriptInModule(AbstractModule* module,
const String& source,
const TextPosition& textPosition,
const LoadFinishedCallback& load_finished_callback);
void ExecuteLibraryInModule(AbstractModule* module,
Dart_Handle library,
HTMLScriptElement* script);
void ClearForClose();
void CreateIsolateFor(PassOwnPtr<DOMDartState> dom_dart_state);
void InstallView(View* view);
DOMDartState* dart_state() const { return dom_dart_state_.get(); }
private:
bool ImportChildLibraries(AbstractModule* module, Dart_Handle library);
Dart_Handle CreateLibrary(AbstractModule* module,
const String& source,
const TextPosition& position);
void DidLoadMainLibrary(String url);
void DidLoadSnapshot();
OwnPtr<DOMDartState> dom_dart_state_;
OwnPtr<BuiltinSky> builtin_sky_;
OwnPtr<DartLibraryProviderWebView> library_provider_;
OwnPtr<DartSnapshotLoader> snapshot_loader_;
base::WeakPtrFactory<DartController> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DartController);
};
}
#endif // SKY_ENGINE_CORE_SCRIPT_DART_CONTROLLER_H_