OLD | NEW |
---|---|
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/engine/config.h" |
6 #include "sky/viewer/internals.h" | 6 #include "sky/viewer/internals.h" |
7 | 7 |
8 #include "mojo/public/cpp/application/connect.h" | 8 #include "mojo/public/cpp/application/connect.h" |
9 #include "mojo/public/cpp/bindings/array.h" | 9 #include "mojo/public/cpp/bindings/array.h" |
10 #include "sky/engine/public/web/WebDocument.h" | 10 #include "sky/engine/public/web/WebDocument.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 namespace sky { | 22 namespace sky { |
23 namespace { | 23 namespace { |
24 | 24 |
25 int kInternalsKey = 0; | 25 int kInternalsKey = 0; |
26 | 26 |
27 Internals* GetInternals() { | 27 Internals* GetInternals() { |
28 DartState* state = DartState::Current(); | 28 DartState* state = DartState::Current(); |
29 return static_cast<Internals*>(state->GetUserData(&kInternalsKey)); | 29 return static_cast<Internals*>(state->GetUserData(&kInternalsKey)); |
30 } | 30 } |
31 | 31 |
32 void RenderTreeAsText(Dart_NativeArguments args) { | 32 void ConnectToService(Dart_NativeArguments args) { |
33 Dart_Handle result = StdStringToDart(GetInternals()->RenderTreeAsText()); | 33 Dart_Handle application_url_handle = Dart_GetNativeArgument(args, 0); |
34 Dart_SetReturnValue(args, result); | 34 Dart_Handle interface_name_handle = Dart_GetNativeArgument(args, 1); |
35 mojo::ScopedMessagePipeHandle handle(GetInternals()->ConnectToService( | |
36 StdStringFromDart(application_url_handle), | |
37 StdStringFromDart(interface_name_handle))); | |
38 Dart_SetReturnValue( | |
39 args, | |
40 DartConverter<mojo::ScopedMessagePipeHandle>::ToDart(handle.Pass())); | |
abarth-chromium
2015/02/23 22:29:38
You should add a SetReturnValue function to DartCo
| |
35 } | 41 } |
36 | 42 |
37 void ContentAsText(Dart_NativeArguments args) { | 43 void ContentAsText(Dart_NativeArguments args) { |
38 Dart_Handle result = StdStringToDart(GetInternals()->ContentAsText()); | 44 Dart_Handle result = StdStringToDart(GetInternals()->ContentAsText()); |
39 Dart_SetReturnValue(args, result); | 45 Dart_SetReturnValue(args, result); |
40 } | 46 } |
41 | 47 |
42 void NotifyTestComplete(Dart_NativeArguments args) { | 48 void NotifyTestComplete(Dart_NativeArguments args) { |
43 Dart_Handle test_result = Dart_GetNativeArgument(args, 0); | 49 Dart_Handle test_result = Dart_GetNativeArgument(args, 0); |
44 GetInternals()->NotifyTestComplete(StdStringFromDart(test_result)); | 50 GetInternals()->NotifyTestComplete(StdStringFromDart(test_result)); |
45 } | 51 } |
46 | 52 |
53 void RenderTreeAsText(Dart_NativeArguments args) { | |
sky
2015/02/23 22:09:33
I reorder these to be be alphabetical. I can easil
abarth-chromium
2015/02/23 22:29:38
That's great, thanks!
| |
54 Dart_Handle result = StdStringToDart(GetInternals()->RenderTreeAsText()); | |
55 Dart_SetReturnValue(args, result); | |
56 } | |
57 | |
47 void TakeShellProxyHandle(Dart_NativeArguments args) { | 58 void TakeShellProxyHandle(Dart_NativeArguments args) { |
48 Dart_SetIntegerReturnValue(args, | 59 Dart_SetIntegerReturnValue(args, |
49 GetInternals()->TakeShellProxyHandle().value()); | 60 GetInternals()->TakeShellProxyHandle().value()); |
50 } | 61 } |
51 | 62 |
52 void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) { | 63 void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) { |
53 Dart_SetIntegerReturnValue(args, | 64 Dart_SetIntegerReturnValue( |
54 GetInternals()->TakeServicesProvidedToEmbedder().value()); | 65 args, GetInternals()->TakeServicesProvidedByEmbedder().value()); |
55 } | 66 } |
56 | 67 |
57 void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) { | 68 void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) { |
58 Dart_SetIntegerReturnValue(args, | 69 Dart_SetIntegerReturnValue( |
59 GetInternals()->TakeServicesProvidedByEmbedder().value()); | 70 args, GetInternals()->TakeServicesProvidedToEmbedder().value()); |
60 } | 71 } |
61 | 72 |
62 const DartBuiltin::Natives kNativeFunctions[] = { | 73 const DartBuiltin::Natives kNativeFunctions[] = { |
63 {"renderTreeAsText", RenderTreeAsText, 0}, | 74 {"connectToService", ConnectToService, 2}, |
abarth-chromium
2015/02/23 22:29:37
Why do you need connectToService? Can't you just
sky
2015/02/23 22:38:56
That can certainly be done. I was assuming we want
| |
64 {"contentAsText", ContentAsText, 0}, | 75 {"contentAsText", ContentAsText, 0}, |
65 {"notifyTestComplete", NotifyTestComplete, 1}, | 76 {"notifyTestComplete", NotifyTestComplete, 1}, |
66 {"takeShellProxyHandle", TakeShellProxyHandle, 0}, | 77 {"renderTreeAsText", RenderTreeAsText, 0}, |
67 {"takeServicesProvidedToEmbedder", TakeServicesProvidedToEmbedder, 0}, | 78 {"takeShellProxyHandle", TakeShellProxyHandle, 0}, |
68 {"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0}, | 79 {"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0}, |
80 {"takeServicesProvidedToEmbedder", TakeServicesProvidedToEmbedder, 0}, | |
69 }; | 81 }; |
70 | 82 |
71 const DartBuiltin& GetBuiltin() { | 83 const DartBuiltin& GetBuiltin() { |
72 static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions, | 84 static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions, |
73 arraysize(kNativeFunctions)); | 85 arraysize(kNativeFunctions)); |
74 return builtin; | 86 return builtin; |
75 } | 87 } |
76 | 88 |
77 Dart_NativeFunction Resolver(Dart_Handle name, | 89 Dart_NativeFunction Resolver(Dart_Handle name, |
78 int argument_count, | 90 int argument_count, |
79 bool* auto_setup_scope) { | 91 bool* auto_setup_scope) { |
80 return GetBuiltin().Resolver(name, argument_count, auto_setup_scope); | 92 return GetBuiltin().Resolver(name, argument_count, auto_setup_scope); |
81 } | 93 } |
82 | 94 |
83 const uint8_t* Symbolizer(Dart_NativeFunction native_function) { | 95 const uint8_t* Symbolizer(Dart_NativeFunction native_function) { |
84 return GetBuiltin().Symbolizer(native_function); | 96 return GetBuiltin().Symbolizer(native_function); |
85 } | 97 } |
86 | 98 |
87 const char kLibraryName[] = "dart:sky.internals"; | 99 const char kLibraryName[] = "dart:sky.internals"; |
88 const char kLibrarySource[] = R"DART( | 100 const char kLibrarySource[] = R"DART( |
89 String renderTreeAsText() native "renderTreeAsText"; | 101 int connectToService(String application_url, String interface_name) native |
102 "connectToService"; | |
90 String contentAsText() native "contentAsText"; | 103 String contentAsText() native "contentAsText"; |
91 void notifyTestComplete(String test_result) native "notifyTestComplete"; | 104 void notifyTestComplete(String test_result) native "notifyTestComplete"; |
105 String renderTreeAsText() native "renderTreeAsText"; | |
92 int takeShellProxyHandle() native "takeShellProxyHandle"; | 106 int takeShellProxyHandle() native "takeShellProxyHandle"; |
107 int takeServicesProvidedByEmbedder() native "takeServicesProvidedByEmbedder"; | |
93 int takeServicesProvidedToEmbedder() native "takeServicesProvidedToEmbedder"; | 108 int takeServicesProvidedToEmbedder() native "takeServicesProvidedToEmbedder"; |
94 int takeServicesProvidedByEmbedder() native "takeServicesProvidedByEmbedder"; | |
95 )DART"; | 109 )DART"; |
96 | 110 |
97 } // namespace | 111 } // namespace |
98 | 112 |
99 void Internals::Create(Dart_Isolate isolate, DocumentView* document_view) { | 113 void Internals::Create(Dart_Isolate isolate, DocumentView* document_view) { |
100 DartState* state = DartState::From(isolate); | 114 DartState* state = DartState::From(isolate); |
101 state->SetUserData(&kInternalsKey, new Internals(document_view)); | 115 state->SetUserData(&kInternalsKey, new Internals(document_view)); |
102 Dart_Handle library = | 116 Dart_Handle library = |
103 Dart_LoadLibrary(Dart_NewStringFromCString(kLibraryName), | 117 Dart_LoadLibrary(Dart_NewStringFromCString(kLibraryName), |
104 Dart_NewStringFromCString(kLibrarySource), 0, 0); | 118 Dart_NewStringFromCString(kLibrarySource), 0, 0); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 void Internals::ConnectToApplication( | 179 void Internals::ConnectToApplication( |
166 const mojo::String& application_url, | 180 const mojo::String& application_url, |
167 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 181 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
168 mojo::ServiceProviderPtr exposed_services) { | 182 mojo::ServiceProviderPtr exposed_services) { |
169 if (document_view_) { | 183 if (document_view_) { |
170 document_view_->shell()->ConnectToApplication( | 184 document_view_->shell()->ConnectToApplication( |
171 application_url, services.Pass(), exposed_services.Pass()); | 185 application_url, services.Pass(), exposed_services.Pass()); |
172 } | 186 } |
173 } | 187 } |
174 | 188 |
175 mojo::Handle Internals::ConnectToService( | 189 mojo::ScopedMessagePipeHandle Internals::ConnectToService( |
176 const std::string& application_url, const std::string& interface_name) { | 190 const std::string& application_url, |
191 const std::string& interface_name) { | |
177 if (!document_view_) | 192 if (!document_view_) |
178 return mojo::Handle(); | 193 return mojo::ScopedMessagePipeHandle(); |
179 | 194 |
180 mojo::ServiceProviderPtr service_provider; | 195 mojo::ServiceProviderPtr service_provider; |
181 ConnectToApplication(application_url, mojo::GetProxy(&service_provider), | 196 ConnectToApplication(application_url, mojo::GetProxy(&service_provider), |
182 nullptr); | 197 nullptr); |
183 | 198 |
184 mojo::MessagePipe pipe; | 199 mojo::MessagePipe pipe; |
185 service_provider->ConnectToService(interface_name, pipe.handle1.Pass()); | 200 service_provider->ConnectToService(interface_name, pipe.handle1.Pass()); |
186 return pipe.handle0.release(); | 201 return pipe.handle0.Pass(); |
187 } | 202 } |
188 | 203 |
189 void Internals::pauseAnimations(double pauseTime) { | 204 void Internals::pauseAnimations(double pauseTime) { |
190 if (pauseTime < 0) | 205 if (pauseTime < 0) |
191 return; | 206 return; |
192 | 207 |
193 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin g(pauseTime); | 208 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin g(pauseTime); |
194 } | 209 } |
195 | 210 |
196 } // namespace sky | 211 } // namespace sky |
OLD | NEW |