| 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/shell/ui/internals.h" | 5 #include "sky/shell/ui/internals.h" |
| 6 | 6 |
| 7 #include "base/threading/worker_pool.h" | 7 #include "base/threading/worker_pool.h" |
| 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 "services/asset_bundle/asset_unpacker_impl.h" | 10 #include "services/asset_bundle/asset_unpacker_impl.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 int kInternalsKey = 0; | 22 int kInternalsKey = 0; |
| 23 | 23 |
| 24 Internals* GetInternals() { | 24 Internals* GetInternals() { |
| 25 DartState* state = DartState::Current(); | 25 DartState* state = DartState::Current(); |
| 26 return static_cast<Internals*>(state->GetUserData(&kInternalsKey)); | 26 return static_cast<Internals*>(state->GetUserData(&kInternalsKey)); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void NotifyTestComplete(Dart_NativeArguments args) { | 29 void NotifyTestComplete(Dart_NativeArguments args) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 void TakeRootBundleHandle(Dart_NativeArguments args) { |
| 33 Dart_SetIntegerReturnValue( |
| 34 args, GetInternals()->TakeRootBundleHandle().value()); |
| 35 } |
| 36 |
| 32 void TakeShellProxyHandle(Dart_NativeArguments args) { | 37 void TakeShellProxyHandle(Dart_NativeArguments args) { |
| 33 Dart_SetIntegerReturnValue(args, 0); | 38 Dart_SetIntegerReturnValue(args, 0); |
| 34 } | 39 } |
| 35 | 40 |
| 36 void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) { | 41 void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) { |
| 37 Dart_SetIntegerReturnValue( | 42 Dart_SetIntegerReturnValue( |
| 38 args, GetInternals()->TakeServicesProvidedByEmbedder().value()); | 43 args, GetInternals()->TakeServicesProvidedByEmbedder().value()); |
| 39 } | 44 } |
| 40 | 45 |
| 41 void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) { | 46 void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) { |
| 42 Dart_SetIntegerReturnValue(args, 0); | 47 Dart_SetIntegerReturnValue(args, 0); |
| 43 } | 48 } |
| 44 | 49 |
| 45 void TakeServiceRegistry(Dart_NativeArguments args) { | 50 void TakeServiceRegistry(Dart_NativeArguments args) { |
| 46 Dart_SetIntegerReturnValue(args, 0); | 51 Dart_SetIntegerReturnValue(args, 0); |
| 47 } | 52 } |
| 48 | 53 |
| 49 const DartBuiltin::Natives kNativeFunctions[] = { | 54 const DartBuiltin::Natives kNativeFunctions[] = { |
| 50 {"notifyTestComplete", NotifyTestComplete, 1}, | 55 {"notifyTestComplete", NotifyTestComplete, 1}, |
| 51 {"takeShellProxyHandle", TakeShellProxyHandle, 0}, | 56 {"takeRootBundleHandle", TakeRootBundleHandle, 0}, |
| 57 {"takeServiceRegistry", TakeServiceRegistry, 0}, |
| 52 {"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0}, | 58 {"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0}, |
| 53 {"takeServicesProvidedToEmbedder", TakeServicesProvidedToEmbedder, 0}, | 59 {"takeServicesProvidedToEmbedder", TakeServicesProvidedToEmbedder, 0}, |
| 54 {"takeServiceRegistry", TakeServiceRegistry, 0}, | 60 {"takeShellProxyHandle", TakeShellProxyHandle, 0}, |
| 55 }; | 61 }; |
| 56 | 62 |
| 57 const DartBuiltin& GetBuiltin() { | 63 const DartBuiltin& GetBuiltin() { |
| 58 static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions, | 64 static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions, |
| 59 arraysize(kNativeFunctions)); | 65 arraysize(kNativeFunctions)); |
| 60 return builtin; | 66 return builtin; |
| 61 } | 67 } |
| 62 | 68 |
| 63 Dart_NativeFunction Resolver(Dart_Handle name, | 69 Dart_NativeFunction Resolver(Dart_Handle name, |
| 64 int argument_count, | 70 int argument_count, |
| 65 bool* auto_setup_scope) { | 71 bool* auto_setup_scope) { |
| 66 return GetBuiltin().Resolver(name, argument_count, auto_setup_scope); | 72 return GetBuiltin().Resolver(name, argument_count, auto_setup_scope); |
| 67 } | 73 } |
| 68 | 74 |
| 69 const uint8_t* Symbolizer(Dart_NativeFunction native_function) { | 75 const uint8_t* Symbolizer(Dart_NativeFunction native_function) { |
| 70 return GetBuiltin().Symbolizer(native_function); | 76 return GetBuiltin().Symbolizer(native_function); |
| 71 } | 77 } |
| 72 | 78 |
| 73 const char kLibraryName[] = "dart:sky.internals"; | 79 const char kLibraryName[] = "dart:sky.internals"; |
| 74 | 80 |
| 75 } // namespace | 81 } // namespace |
| 76 | 82 |
| 77 void Internals::Create(Dart_Isolate isolate, | 83 void Internals::Create(Dart_Isolate isolate, |
| 78 mojo::ServiceProviderPtr service_provider) { | 84 mojo::ServiceProviderPtr service_provider, |
| 85 mojo::asset_bundle::AssetBundlePtr root_bundle) { |
| 79 DartState* state = DartState::From(isolate); | 86 DartState* state = DartState::From(isolate); |
| 80 state->SetUserData(&kInternalsKey, new Internals(service_provider.Pass())); | 87 state->SetUserData(&kInternalsKey, new Internals(service_provider.Pass(), |
| 88 root_bundle.Pass())); |
| 81 Dart_Handle library = | 89 Dart_Handle library = |
| 82 Dart_LookupLibrary(Dart_NewStringFromCString(kLibraryName)); | 90 Dart_LookupLibrary(Dart_NewStringFromCString(kLibraryName)); |
| 83 CHECK(!LogIfError(library)); | 91 CHECK(!LogIfError(library)); |
| 84 CHECK(!LogIfError(Dart_SetNativeResolver(library, Resolver, Symbolizer))); | 92 CHECK(!LogIfError(Dart_SetNativeResolver(library, Resolver, Symbolizer))); |
| 85 } | 93 } |
| 86 | 94 |
| 87 Internals::Internals(mojo::ServiceProviderPtr platform_service_provider) | 95 Internals::Internals(mojo::ServiceProviderPtr platform_service_provider, |
| 88 : service_provider_impl_(GetProxy(&service_provider_)), | 96 mojo::asset_bundle::AssetBundlePtr root_bundle) |
| 97 : root_bundle_(root_bundle.Pass()), |
| 98 service_provider_impl_(GetProxy(&service_provider_)), |
| 89 platform_service_provider_(platform_service_provider.Pass()) { | 99 platform_service_provider_(platform_service_provider.Pass()) { |
| 90 service_provider_impl_.set_fallback_service_provider( | 100 service_provider_impl_.set_fallback_service_provider( |
| 91 platform_service_provider_.get()); | 101 platform_service_provider_.get()); |
| 92 service_provider_impl_.AddService<mojo::asset_bundle::AssetUnpacker>(this); | 102 service_provider_impl_.AddService<mojo::asset_bundle::AssetUnpacker>(this); |
| 93 } | 103 } |
| 94 | 104 |
| 95 Internals::~Internals() { | 105 Internals::~Internals() { |
| 96 } | 106 } |
| 97 | 107 |
| 98 void Internals::Create( | 108 void Internals::Create( |
| 99 mojo::ApplicationConnection* connection, | 109 mojo::ApplicationConnection* connection, |
| 100 mojo::InterfaceRequest<mojo::asset_bundle::AssetUnpacker> request) { | 110 mojo::InterfaceRequest<mojo::asset_bundle::AssetUnpacker> request) { |
| 101 new mojo::asset_bundle::AssetUnpackerImpl( | 111 new mojo::asset_bundle::AssetUnpackerImpl( |
| 102 request.Pass(), base::WorkerPool::GetTaskRunner(true)); | 112 request.Pass(), base::WorkerPool::GetTaskRunner(true)); |
| 103 } | 113 } |
| 104 | 114 |
| 105 mojo::Handle Internals::TakeServicesProvidedByEmbedder() { | 115 mojo::Handle Internals::TakeServicesProvidedByEmbedder() { |
| 106 return service_provider_.PassInterface().PassHandle().release(); | 116 return service_provider_.PassInterface().PassHandle().release(); |
| 107 } | 117 } |
| 108 | 118 |
| 119 mojo::Handle Internals::TakeRootBundleHandle() { |
| 120 return root_bundle_.PassInterface().PassHandle().release(); |
| 121 } |
| 122 |
| 109 } // namespace shell | 123 } // namespace shell |
| 110 } // namespace sky | 124 } // namespace sky |
| OLD | NEW |