Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: sky/viewer/internals.cc

Issue 922893002: Merge the Sky Engine changes from the SkyDart branch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/viewer/internals.h ('k') | sky/viewer/script/core.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/viewer/internals.cc
diff --git a/sky/viewer/internals.cc b/sky/viewer/internals.cc
index aca762a867a820e2aa4c07fd06de3aa8a4fc8010..3070f98273ffb79953d5c52b4981e6b345ffee8f 100644
--- a/sky/viewer/internals.cc
+++ b/sky/viewer/internals.cc
@@ -2,39 +2,94 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "sky/engine/config.h"
#include "sky/viewer/internals.h"
-#include "mojo/edk/js/core.h"
-#include "mojo/edk/js/handle.h"
-#include "mojo/edk/js/support.h"
-#include "mojo/edk/js/threading.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/cpp/bindings/array.h"
#include "sky/engine/public/web/WebDocument.h"
#include "sky/engine/public/web/WebFrame.h"
#include "sky/engine/public/web/WebView.h"
+#include "sky/engine/tonic/dart_builtin.h"
+#include "sky/engine/tonic/dart_converter.h"
+#include "sky/engine/tonic/dart_error.h"
#include "sky/viewer/document_view.h"
#include "sky/viewer/runtime_flags.h"
-#include "v8/include/v8.h"
#include <limits>
+using namespace blink;
+
namespace sky {
+namespace {
+
+int kInternalsKey = 0;
+
+Internals* GetInternals() {
+ DartState* state = DartState::Current();
+ return static_cast<Internals*>(state->GetUserData(&kInternalsKey));
+}
+
+void RenderTreeAsText(Dart_NativeArguments args) {
+ Dart_Handle result = StdStringToDart(GetInternals()->RenderTreeAsText());
+ Dart_SetReturnValue(args, result);
+}
-gin::WrapperInfo Internals::kWrapperInfo = {gin::kEmbedderNativeGin};
+void ContentAsText(Dart_NativeArguments args) {
+ Dart_Handle result = StdStringToDart(GetInternals()->ContentAsText());
+ Dart_SetReturnValue(args, result);
+}
-// static
-gin::Handle<Internals> Internals::Create(
- v8::Isolate* isolate, DocumentView* document_view) {
- gin::Handle<Internals> internals =
- gin::CreateHandle(isolate, new Internals(document_view));
- v8::Handle<v8::Object> object = internals.ToV8().As<v8::Object>();
- object->Set(gin::StringToV8(isolate, "core"),
- mojo::js::Core::GetModule(isolate));
- object->Set(gin::StringToV8(isolate, "support"),
- mojo::js::Support::GetModule(isolate));
- object->Set(gin::StringToV8(isolate, "threading"),
- mojo::js::Threading::GetModule(isolate));
- return internals;
+void NotifyTestComplete(Dart_NativeArguments args) {
+ Dart_Handle test_result = Dart_GetNativeArgument(args, 0);
+ GetInternals()->NotifyTestComplete(StdStringFromDart(test_result));
+}
+
+void PassShellProxyHandle(Dart_NativeArguments args) {
+ Dart_SetIntegerReturnValue(args, GetInternals()->PassShellProxyHandle().value());
+}
+
+const DartBuiltin::Natives kNativeFunctions[] = {
+ {"renderTreeAsText", RenderTreeAsText, 0},
+ {"contentAsText", ContentAsText, 0},
+ {"notifyTestComplete", NotifyTestComplete, 1},
+ {"passShellProxyHandle", PassShellProxyHandle, 0},
+};
+
+const DartBuiltin& GetBuiltin() {
+ static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions,
+ arraysize(kNativeFunctions));
+ return builtin;
+}
+
+Dart_NativeFunction Resolver(Dart_Handle name,
+ int argument_count,
+ bool* auto_setup_scope) {
+ return GetBuiltin().Resolver(name, argument_count, auto_setup_scope);
+}
+
+const uint8_t* Symbolizer(Dart_NativeFunction native_function) {
+ return GetBuiltin().Symbolizer(native_function);
+}
+
+const char kLibraryName[] = "dart:sky.internals";
+const char kLibrarySource[] = R"DART(
+String renderTreeAsText() native "renderTreeAsText";
+String contentAsText() native "contentAsText";
+void notifyTestComplete(String test_result) native "notifyTestComplete";
+int passShellProxyHandle() native "passShellProxyHandle";
+)DART";
+
+} // namespace
+
+void Internals::Create(Dart_Isolate isolate, DocumentView* document_view) {
+ DartState* state = DartState::From(isolate);
+ state->SetUserData(&kInternalsKey, new Internals(document_view));
+ Dart_Handle library =
+ Dart_LoadLibrary(Dart_NewStringFromCString(kLibraryName),
+ Dart_NewStringFromCString(kLibrarySource), 0, 0);
+ CHECK(!LogIfError(library));
+ CHECK(!LogIfError(Dart_FinalizeLoading(true)));
+ CHECK(!LogIfError(Dart_SetNativeResolver(library, Resolver, Symbolizer)));
}
Internals::Internals(DocumentView* document_view)
@@ -47,19 +102,6 @@ Internals::Internals(DocumentView* document_view)
Internals::~Internals() {
}
-gin::ObjectTemplateBuilder Internals::GetObjectTemplateBuilder(
- v8::Isolate* isolate) {
- return Wrappable<Internals>::GetObjectTemplateBuilder(isolate)
- .SetMethod("renderTreeAsText", &Internals::RenderTreeAsText)
- .SetMethod("contentAsText", &Internals::ContentAsText)
- .SetMethod("notifyTestComplete", &Internals::NotifyTestComplete)
- .SetMethod("connectToService", &Internals::ConnectToService)
- .SetMethod("connectToEmbedderService",
- &Internals::ConnectToEmbedderService)
- .SetMethod("pauseAnimations", &Internals::pauseAnimations)
- .SetMethod("passShellProxyHandle", &Internals::PassShellProxyHandle);
-}
-
std::string Internals::RenderTreeAsText() {
if (!document_view_)
return std::string();
« no previous file with comments | « sky/viewer/internals.h ('k') | sky/viewer/script/core.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698