OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "sky/engine/config.h" |
| 6 #include "sky/shell/ui/internals.h" |
| 7 |
| 8 #include "mojo/public/cpp/application/connect.h" |
| 9 #include "mojo/public/cpp/bindings/array.h" |
| 10 #include "sky/engine/tonic/dart_builtin.h" |
| 11 #include "sky/engine/tonic/dart_converter.h" |
| 12 #include "sky/engine/tonic/dart_error.h" |
| 13 #include "sky/engine/tonic/dart_state.h" |
| 14 |
| 15 using namespace blink; |
| 16 |
| 17 namespace sky { |
| 18 namespace shell { |
| 19 namespace { |
| 20 |
| 21 int kInternalsKey = 0; |
| 22 |
| 23 Internals* GetInternals() { |
| 24 DartState* state = DartState::Current(); |
| 25 return static_cast<Internals*>(state->GetUserData(&kInternalsKey)); |
| 26 } |
| 27 |
| 28 void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) { |
| 29 Dart_SetIntegerReturnValue( |
| 30 args, GetInternals()->TakeServicesProvidedByEmbedder().value()); |
| 31 } |
| 32 |
| 33 const DartBuiltin::Natives kNativeFunctions[] = { |
| 34 {"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0}, |
| 35 }; |
| 36 |
| 37 const DartBuiltin& GetBuiltin() { |
| 38 static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions, |
| 39 arraysize(kNativeFunctions)); |
| 40 return builtin; |
| 41 } |
| 42 |
| 43 Dart_NativeFunction Resolver(Dart_Handle name, |
| 44 int argument_count, |
| 45 bool* auto_setup_scope) { |
| 46 return GetBuiltin().Resolver(name, argument_count, auto_setup_scope); |
| 47 } |
| 48 |
| 49 const uint8_t* Symbolizer(Dart_NativeFunction native_function) { |
| 50 return GetBuiltin().Symbolizer(native_function); |
| 51 } |
| 52 |
| 53 const char kLibraryName[] = "dart:sky.internals"; |
| 54 const char kLibrarySource[] = R"DART( |
| 55 int takeServicesProvidedByEmbedder() native "takeServicesProvidedByEmbedder"; |
| 56 )DART"; |
| 57 |
| 58 } // namespace |
| 59 |
| 60 void Internals::Create(Dart_Isolate isolate, |
| 61 mojo::ServiceProviderPtr service_provider) { |
| 62 DartState* state = DartState::From(isolate); |
| 63 state->SetUserData(&kInternalsKey, new Internals(service_provider.Pass())); |
| 64 Dart_Handle library = |
| 65 Dart_LoadLibrary(Dart_NewStringFromCString(kLibraryName), |
| 66 Dart_NewStringFromCString(kLibrarySource), 0, 0); |
| 67 CHECK(!LogIfError(library)); |
| 68 CHECK(!LogIfError(Dart_FinalizeLoading(true))); |
| 69 CHECK(!LogIfError(Dart_SetNativeResolver(library, Resolver, Symbolizer))); |
| 70 } |
| 71 |
| 72 Internals::Internals(mojo::ServiceProviderPtr service_provider) |
| 73 : service_provider_(service_provider.Pass()) { |
| 74 } |
| 75 |
| 76 Internals::~Internals() { |
| 77 } |
| 78 |
| 79 mojo::Handle Internals::TakeServicesProvidedByEmbedder() { |
| 80 return service_provider_.PassMessagePipe().release(); |
| 81 } |
| 82 |
| 83 } // namespace shell |
| 84 } // namespace sky |
OLD | NEW |