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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « sky/viewer/internals.h ('k') | sky/viewer/script/core.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sky/engine/config.h"
5 #include "sky/viewer/internals.h" 6 #include "sky/viewer/internals.h"
6 7
7 #include "mojo/edk/js/core.h"
8 #include "mojo/edk/js/handle.h"
9 #include "mojo/edk/js/support.h"
10 #include "mojo/edk/js/threading.h"
11 #include "mojo/public/cpp/application/connect.h" 8 #include "mojo/public/cpp/application/connect.h"
12 #include "mojo/public/cpp/bindings/array.h" 9 #include "mojo/public/cpp/bindings/array.h"
13 #include "sky/engine/public/web/WebDocument.h" 10 #include "sky/engine/public/web/WebDocument.h"
14 #include "sky/engine/public/web/WebFrame.h" 11 #include "sky/engine/public/web/WebFrame.h"
15 #include "sky/engine/public/web/WebView.h" 12 #include "sky/engine/public/web/WebView.h"
13 #include "sky/engine/tonic/dart_builtin.h"
14 #include "sky/engine/tonic/dart_converter.h"
15 #include "sky/engine/tonic/dart_error.h"
16 #include "sky/viewer/document_view.h" 16 #include "sky/viewer/document_view.h"
17 #include "sky/viewer/runtime_flags.h" 17 #include "sky/viewer/runtime_flags.h"
18 #include "v8/include/v8.h"
19 #include <limits> 18 #include <limits>
20 19
20 using namespace blink;
21
21 namespace sky { 22 namespace sky {
23 namespace {
22 24
23 gin::WrapperInfo Internals::kWrapperInfo = {gin::kEmbedderNativeGin}; 25 int kInternalsKey = 0;
24 26
25 // static 27 Internals* GetInternals() {
26 gin::Handle<Internals> Internals::Create( 28 DartState* state = DartState::Current();
27 v8::Isolate* isolate, DocumentView* document_view) { 29 return static_cast<Internals*>(state->GetUserData(&kInternalsKey));
28 gin::Handle<Internals> internals = 30 }
29 gin::CreateHandle(isolate, new Internals(document_view)); 31
30 v8::Handle<v8::Object> object = internals.ToV8().As<v8::Object>(); 32 void RenderTreeAsText(Dart_NativeArguments args) {
31 object->Set(gin::StringToV8(isolate, "core"), 33 Dart_Handle result = StdStringToDart(GetInternals()->RenderTreeAsText());
32 mojo::js::Core::GetModule(isolate)); 34 Dart_SetReturnValue(args, result);
33 object->Set(gin::StringToV8(isolate, "support"), 35 }
34 mojo::js::Support::GetModule(isolate)); 36
35 object->Set(gin::StringToV8(isolate, "threading"), 37 void ContentAsText(Dart_NativeArguments args) {
36 mojo::js::Threading::GetModule(isolate)); 38 Dart_Handle result = StdStringToDart(GetInternals()->ContentAsText());
37 return internals; 39 Dart_SetReturnValue(args, result);
40 }
41
42 void NotifyTestComplete(Dart_NativeArguments args) {
43 Dart_Handle test_result = Dart_GetNativeArgument(args, 0);
44 GetInternals()->NotifyTestComplete(StdStringFromDart(test_result));
45 }
46
47 void PassShellProxyHandle(Dart_NativeArguments args) {
48 Dart_SetIntegerReturnValue(args, GetInternals()->PassShellProxyHandle().value( ));
49 }
50
51 const DartBuiltin::Natives kNativeFunctions[] = {
52 {"renderTreeAsText", RenderTreeAsText, 0},
53 {"contentAsText", ContentAsText, 0},
54 {"notifyTestComplete", NotifyTestComplete, 1},
55 {"passShellProxyHandle", PassShellProxyHandle, 0},
56 };
57
58 const DartBuiltin& GetBuiltin() {
59 static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions,
60 arraysize(kNativeFunctions));
61 return builtin;
62 }
63
64 Dart_NativeFunction Resolver(Dart_Handle name,
65 int argument_count,
66 bool* auto_setup_scope) {
67 return GetBuiltin().Resolver(name, argument_count, auto_setup_scope);
68 }
69
70 const uint8_t* Symbolizer(Dart_NativeFunction native_function) {
71 return GetBuiltin().Symbolizer(native_function);
72 }
73
74 const char kLibraryName[] = "dart:sky.internals";
75 const char kLibrarySource[] = R"DART(
76 String renderTreeAsText() native "renderTreeAsText";
77 String contentAsText() native "contentAsText";
78 void notifyTestComplete(String test_result) native "notifyTestComplete";
79 int passShellProxyHandle() native "passShellProxyHandle";
80 )DART";
81
82 } // namespace
83
84 void Internals::Create(Dart_Isolate isolate, DocumentView* document_view) {
85 DartState* state = DartState::From(isolate);
86 state->SetUserData(&kInternalsKey, new Internals(document_view));
87 Dart_Handle library =
88 Dart_LoadLibrary(Dart_NewStringFromCString(kLibraryName),
89 Dart_NewStringFromCString(kLibrarySource), 0, 0);
90 CHECK(!LogIfError(library));
91 CHECK(!LogIfError(Dart_FinalizeLoading(true)));
92 CHECK(!LogIfError(Dart_SetNativeResolver(library, Resolver, Symbolizer)));
38 } 93 }
39 94
40 Internals::Internals(DocumentView* document_view) 95 Internals::Internals(DocumentView* document_view)
41 : document_view_(document_view->GetWeakPtr()), 96 : document_view_(document_view->GetWeakPtr()),
42 shell_binding_(this) { 97 shell_binding_(this) {
43 if (document_view_->imported_services()) 98 if (document_view_->imported_services())
44 mojo::ConnectToService(document_view_->imported_services(), &test_harness_); 99 mojo::ConnectToService(document_view_->imported_services(), &test_harness_);
45 } 100 }
46 101
47 Internals::~Internals() { 102 Internals::~Internals() {
48 } 103 }
49 104
50 gin::ObjectTemplateBuilder Internals::GetObjectTemplateBuilder(
51 v8::Isolate* isolate) {
52 return Wrappable<Internals>::GetObjectTemplateBuilder(isolate)
53 .SetMethod("renderTreeAsText", &Internals::RenderTreeAsText)
54 .SetMethod("contentAsText", &Internals::ContentAsText)
55 .SetMethod("notifyTestComplete", &Internals::NotifyTestComplete)
56 .SetMethod("connectToService", &Internals::ConnectToService)
57 .SetMethod("connectToEmbedderService",
58 &Internals::ConnectToEmbedderService)
59 .SetMethod("pauseAnimations", &Internals::pauseAnimations)
60 .SetMethod("passShellProxyHandle", &Internals::PassShellProxyHandle);
61 }
62
63 std::string Internals::RenderTreeAsText() { 105 std::string Internals::RenderTreeAsText() {
64 if (!document_view_) 106 if (!document_view_)
65 return std::string(); 107 return std::string();
66 return document_view_->web_view()->mainFrame()->renderTreeAsText().utf8(); 108 return document_view_->web_view()->mainFrame()->renderTreeAsText().utf8();
67 } 109 }
68 110
69 std::string Internals::ContentAsText() { 111 std::string Internals::ContentAsText() {
70 if (!document_view_) 112 if (!document_view_)
71 return std::string(); 113 return std::string();
72 return document_view_->web_view()->mainFrame()->contentAsText( 114 return document_view_->web_view()->mainFrame()->contentAsText(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 172 }
131 173
132 void Internals::pauseAnimations(double pauseTime) { 174 void Internals::pauseAnimations(double pauseTime) {
133 if (pauseTime < 0) 175 if (pauseTime < 0)
134 return; 176 return;
135 177
136 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin g(pauseTime); 178 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin g(pauseTime);
137 } 179 }
138 180
139 } // namespace sky 181 } // namespace sky
OLDNEW
« 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