| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) { | 52 void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) { |
| 53 Dart_SetIntegerReturnValue( | 53 Dart_SetIntegerReturnValue( |
| 54 args, GetInternals()->TakeServicesProvidedByEmbedder().value()); | 54 args, GetInternals()->TakeServicesProvidedByEmbedder().value()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) { | 57 void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) { |
| 58 Dart_SetIntegerReturnValue( | 58 Dart_SetIntegerReturnValue( |
| 59 args, GetInternals()->TakeServicesProvidedToEmbedder().value()); | 59 args, GetInternals()->TakeServicesProvidedToEmbedder().value()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void TakeServiceRegistry(Dart_NativeArguments args) { |
| 63 Dart_SetIntegerReturnValue( |
| 64 args, GetInternals()->TakeServiceRegistry().value()); |
| 65 } |
| 66 |
| 62 const DartBuiltin::Natives kNativeFunctions[] = { | 67 const DartBuiltin::Natives kNativeFunctions[] = { |
| 63 {"contentAsText", ContentAsText, 0}, | 68 {"contentAsText", ContentAsText, 0}, |
| 64 {"notifyTestComplete", NotifyTestComplete, 1}, | 69 {"notifyTestComplete", NotifyTestComplete, 1}, |
| 65 {"renderTreeAsText", RenderTreeAsText, 0}, | 70 {"renderTreeAsText", RenderTreeAsText, 0}, |
| 66 {"takeShellProxyHandle", TakeShellProxyHandle, 0}, | 71 {"takeShellProxyHandle", TakeShellProxyHandle, 0}, |
| 67 {"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0}, | 72 {"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0}, |
| 68 {"takeServicesProvidedToEmbedder", TakeServicesProvidedToEmbedder, 0}, | 73 {"takeServicesProvidedToEmbedder", TakeServicesProvidedToEmbedder, 0}, |
| 74 {"takeServiceRegistry", TakeServiceRegistry, 0}, |
| 69 }; | 75 }; |
| 70 | 76 |
| 71 const DartBuiltin& GetBuiltin() { | 77 const DartBuiltin& GetBuiltin() { |
| 72 static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions, | 78 static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions, |
| 73 arraysize(kNativeFunctions)); | 79 arraysize(kNativeFunctions)); |
| 74 return builtin; | 80 return builtin; |
| 75 } | 81 } |
| 76 | 82 |
| 77 Dart_NativeFunction Resolver(Dart_Handle name, | 83 Dart_NativeFunction Resolver(Dart_Handle name, |
| 78 int argument_count, | 84 int argument_count, |
| 79 bool* auto_setup_scope) { | 85 bool* auto_setup_scope) { |
| 80 return GetBuiltin().Resolver(name, argument_count, auto_setup_scope); | 86 return GetBuiltin().Resolver(name, argument_count, auto_setup_scope); |
| 81 } | 87 } |
| 82 | 88 |
| 83 const uint8_t* Symbolizer(Dart_NativeFunction native_function) { | 89 const uint8_t* Symbolizer(Dart_NativeFunction native_function) { |
| 84 return GetBuiltin().Symbolizer(native_function); | 90 return GetBuiltin().Symbolizer(native_function); |
| 85 } | 91 } |
| 86 | 92 |
| 87 const char kLibraryName[] = "dart:sky.internals"; | 93 const char kLibraryName[] = "dart:sky.internals"; |
| 88 const char kLibrarySource[] = R"DART( | 94 const char kLibrarySource[] = R"DART( |
| 89 String contentAsText() native "contentAsText"; | 95 String contentAsText() native "contentAsText"; |
| 90 void notifyTestComplete(String test_result) native "notifyTestComplete"; | 96 void notifyTestComplete(String test_result) native "notifyTestComplete"; |
| 91 String renderTreeAsText() native "renderTreeAsText"; | 97 String renderTreeAsText() native "renderTreeAsText"; |
| 92 int takeShellProxyHandle() native "takeShellProxyHandle"; | 98 int takeShellProxyHandle() native "takeShellProxyHandle"; |
| 93 int takeServicesProvidedByEmbedder() native "takeServicesProvidedByEmbedder"; | 99 int takeServicesProvidedByEmbedder() native "takeServicesProvidedByEmbedder"; |
| 94 int takeServicesProvidedToEmbedder() native "takeServicesProvidedToEmbedder"; | 100 int takeServicesProvidedToEmbedder() native "takeServicesProvidedToEmbedder"; |
| 101 int takeServiceRegistry() native "takeServiceRegistry"; |
| 95 )DART"; | 102 )DART"; |
| 96 | 103 |
| 97 } // namespace | 104 } // namespace |
| 98 | 105 |
| 99 void Internals::Create(Dart_Isolate isolate, DocumentView* document_view) { | 106 void Internals::Create(Dart_Isolate isolate, DocumentView* document_view) { |
| 100 DartState* state = DartState::From(isolate); | 107 DartState* state = DartState::From(isolate); |
| 101 state->SetUserData(&kInternalsKey, new Internals(document_view)); | 108 state->SetUserData(&kInternalsKey, new Internals(document_view)); |
| 102 Dart_Handle library = | 109 Dart_Handle library = |
| 103 Dart_LoadLibrary(Dart_NewStringFromCString(kLibraryName), | 110 Dart_LoadLibrary(Dart_NewStringFromCString(kLibraryName), |
| 104 Dart_NewStringFromCString(kLibrarySource), 0, 0); | 111 Dart_NewStringFromCString(kLibrarySource), 0, 0); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 return mojo::Handle(); | 152 return mojo::Handle(); |
| 146 return document_view_->TakeServicesProvidedToEmbedder().release(); | 153 return document_view_->TakeServicesProvidedToEmbedder().release(); |
| 147 } | 154 } |
| 148 | 155 |
| 149 mojo::Handle Internals::TakeServicesProvidedByEmbedder() { | 156 mojo::Handle Internals::TakeServicesProvidedByEmbedder() { |
| 150 if (!document_view_) | 157 if (!document_view_) |
| 151 return mojo::Handle(); | 158 return mojo::Handle(); |
| 152 return document_view_->TakeServicesProvidedByEmbedder().release(); | 159 return document_view_->TakeServicesProvidedByEmbedder().release(); |
| 153 } | 160 } |
| 154 | 161 |
| 162 mojo::Handle Internals::TakeServiceRegistry() { |
| 163 if (!document_view_) |
| 164 return mojo::Handle(); |
| 165 return document_view_->TakeServiceRegistry().release(); |
| 166 } |
| 167 |
| 155 // Returns a MessagePipe handle that's connected to this Shell. The caller | 168 // Returns a MessagePipe handle that's connected to this Shell. The caller |
| 156 // owns the handle and is expected to use it to create the JS Application for | 169 // owns the handle and is expected to use it to create the JS Application for |
| 157 // the DocumentView. | 170 // the DocumentView. |
| 158 mojo::Handle Internals::TakeShellProxyHandle() { | 171 mojo::Handle Internals::TakeShellProxyHandle() { |
| 159 mojo::ShellPtr shell; | 172 mojo::ShellPtr shell; |
| 160 if (!shell_binding_.is_bound()) | 173 if (!shell_binding_.is_bound()) |
| 161 shell_binding_.Bind(GetProxy(&shell)); | 174 shell_binding_.Bind(GetProxy(&shell)); |
| 162 return shell.PassMessagePipe().release(); | 175 return shell.PassMessagePipe().release(); |
| 163 } | 176 } |
| 164 | 177 |
| 165 void Internals::ConnectToApplication( | 178 void Internals::ConnectToApplication( |
| 166 const mojo::String& application_url, | 179 const mojo::String& application_url, |
| 167 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 180 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 168 mojo::ServiceProviderPtr exposed_services) { | 181 mojo::ServiceProviderPtr exposed_services) { |
| 169 if (document_view_) { | 182 if (document_view_) { |
| 170 document_view_->shell()->ConnectToApplication( | 183 document_view_->shell()->ConnectToApplication( |
| 171 application_url, services.Pass(), exposed_services.Pass()); | 184 application_url, services.Pass(), exposed_services.Pass()); |
| 172 } | 185 } |
| 173 } | 186 } |
| 174 | 187 |
| 175 void Internals::pauseAnimations(double pauseTime) { | 188 void Internals::pauseAnimations(double pauseTime) { |
| 176 if (pauseTime < 0) | 189 if (pauseTime < 0) |
| 177 return; | 190 return; |
| 178 | 191 |
| 179 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin
g(pauseTime); | 192 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin
g(pauseTime); |
| 180 } | 193 } |
| 181 | 194 |
| 182 } // namespace sky | 195 } // namespace sky |
| OLD | NEW |