提交 9a4feca9 编写于 作者: A Adam Barth

Teach SkyView how to load the main script

This CL implements SkyView::Load to start executing Sky content directly from
Dart's main(). This code isn't currently wired up to anything, so it's not yet
tested.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1130353009
上级 0a0975bf
......@@ -52,7 +52,7 @@ static const char* kCheckedModeArgs[] = {
extern const uint8_t* kDartVmIsolateSnapshotBuffer;
extern const uint8_t* kDartIsolateSnapshotBuffer;
DartController::DartController() {
DartController::DartController() : weak_factory_(this) {
}
DartController::~DartController() {
......@@ -107,6 +107,24 @@ Dart_Handle DartController::CreateLibrary(AbstractModule* module,
return library;
}
void DartController::DidLoadMainLibrary(KURL url) {
DCHECK(Dart_CurrentIsolate() == dart_state()->isolate());
DartApiScope dart_api_scope;
Dart_Handle library = Dart_LookupLibrary(
StringToDart(dart_state(), url.string()));
CHECK(!LogIfError(library));
DartInvokeAppField(library, ToDart("main"), 0, nullptr);
}
void DartController::LoadMainLibrary(const KURL& url) {
DartLoader& loader = dart_state()->loader();
DartDependencyCatcher dependency_catcher(loader);
loader.LoadLibrary(url);
loader.WaitForDependencies(dependency_catcher.dependencies(),
base::Bind(&DartController::DidLoadMainLibrary, weak_factory_.GetWeakPtr(), url));
}
void DartController::LoadScriptInModule(
AbstractModule* module,
const String& source,
......
......@@ -7,6 +7,7 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "dart/runtime/include/dart_api.h"
#include "sky/engine/wtf/OwnPtr.h"
#include "sky/engine/wtf/text/AtomicString.h"
......@@ -19,6 +20,7 @@ class DOMDartState;
class DartValue;
class Document;
class HTMLScriptElement;
class KURL;
class DartController {
public:
......@@ -30,6 +32,8 @@ class DartController {
typedef base::Callback<void(RefPtr<AbstractModule>, RefPtr<DartValue>)>
LoadFinishedCallback;
void LoadMainLibrary(const KURL& url);
void LoadScriptInModule(AbstractModule* module,
const String& source,
const TextPosition& textPosition,
......@@ -49,9 +53,13 @@ class DartController {
const String& source,
const TextPosition& position);
void DidLoadMainLibrary(KURL url);
OwnPtr<DOMDartState> dom_dart_state_;
OwnPtr<BuiltinSky> builtin_sky_;
base::WeakPtrFactory<DartController> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DartController);
};
......
......@@ -231,16 +231,19 @@ void DartLoader::WaitForDependencies(
adoptPtr(new DependencyWatcher(dependencies, callback)));
}
Dart_Handle DartLoader::Import(Dart_Handle library, Dart_Handle url) {
KURL parsed_url(ParsedURLString, StringFromDart(url));
const auto& result = pending_libraries_.add(parsed_url.string(), nullptr);
void DartLoader::LoadLibrary(const KURL& url) {
const auto& result = pending_libraries_.add(url.string(), nullptr);
if (result.isNewEntry) {
OwnPtr<Job> job = adoptPtr(new ImportJob(this, parsed_url));
OwnPtr<Job> job = adoptPtr(new ImportJob(this, url));
result.storedValue->value = job.get();
jobs_.add(job.release());
}
if (dependency_catcher_)
dependency_catcher_->AddDependency(result.storedValue->value);
}
Dart_Handle DartLoader::Import(Dart_Handle library, Dart_Handle url) {
LoadLibrary(KURL(ParsedURLString, StringFromDart(url)));
return Dart_True();
}
......
......@@ -19,6 +19,7 @@ namespace blink {
class DartState;
class DartDependency;
class DartDependencyCatcher;
class KURL;
// TODO(abarth): This class seems more complicated than it needs to be. Is
// there some way of simplifying this system? For example, we have a bunch
......@@ -34,6 +35,8 @@ class DartLoader {
Dart_Handle library,
Dart_Handle url);
void LoadLibrary(const KURL& url);
void WaitForDependencies(const HashSet<DartDependency*>& dependencies,
const base::Closure& callback);
......
......@@ -5,6 +5,9 @@
#include "config.h"
#include "sky/engine/public/sky/sky_view.h"
#include "sky/engine/core/script/dart_controller.h"
#include "sky/engine/platform/weborigin/KURL.h"
namespace blink {
std::unique_ptr<SkyView> SkyView::Create() {
......@@ -15,12 +18,19 @@ SkyView::SkyView() {
}
SkyView::~SkyView() {
// TODO(abarth): Move this work into the DartController destructor once we
// remove the Frame code path.
if (dart_controller_)
dart_controller_->ClearForClose();
}
void SkyView::SetDisplayMetrics(const SkyDisplayMetrics& metrics) {
}
void SkyView::Load(const WebURL& url) {
dart_controller_.reset(new DartController);
dart_controller_->CreateIsolateFor(nullptr);
dart_controller_->LoadMainLibrary(url);
}
skia::RefPtr<SkPicture> SkyView::Paint() {
......
......@@ -13,6 +13,7 @@
#include "third_party/skia/include/core/SkPicture.h"
namespace blink {
class DartController;
class WebInputEvent;
class SkyView {
......@@ -27,6 +28,10 @@ class SkyView {
private:
SkyView();
std::unique_ptr<DartController> dart_controller_;
DISALLOW_COPY_AND_ASSIGN(SkyView);
};
} // namespace blink
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册