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

Side by Side Diff: services/sky/internals.cc

Issue 1239963003: Remove //services/sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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 | « services/sky/internals.h ('k') | services/sky/platform_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "services/sky/internals.h"
6
7 #include <limits>
8
9 #include "mojo/public/cpp/application/connect.h"
10 #include "mojo/public/cpp/bindings/array.h"
11 #include "services/sky/document_view.h"
12 #include "services/sky/runtime_flags.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
17
18 using namespace blink;
19
20 namespace sky {
21 namespace {
22
23 int kInternalsKey = 0;
24
25 Internals* GetInternals() {
26 DartState* state = DartState::Current();
27 return static_cast<Internals*>(state->GetUserData(&kInternalsKey));
28 }
29
30 void NotifyTestComplete(Dart_NativeArguments args) {
31 }
32
33 void TakeRootBundleHandle(Dart_NativeArguments args) {
34 Dart_SetIntegerReturnValue(args, 0);
35 }
36
37 void TakeShellProxyHandle(Dart_NativeArguments args) {
38 Dart_SetIntegerReturnValue(args,
39 GetInternals()->TakeShellProxyHandle().value());
40 }
41
42 void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) {
43 Dart_SetIntegerReturnValue(
44 args, GetInternals()->TakeServicesProvidedByEmbedder().value());
45 }
46
47 void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) {
48 Dart_SetIntegerReturnValue(
49 args, GetInternals()->TakeServicesProvidedToEmbedder().value());
50 }
51
52 void TakeServiceRegistry(Dart_NativeArguments args) {
53 Dart_SetIntegerReturnValue(
54 args, GetInternals()->TakeServiceRegistry().value());
55 }
56
57 const DartBuiltin::Natives kNativeFunctions[] = {
58 {"notifyTestComplete", NotifyTestComplete, 1},
59 {"takeRootBundleHandle", TakeRootBundleHandle, 0},
60 {"takeServiceRegistry", TakeServiceRegistry, 0},
61 {"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0},
62 {"takeServicesProvidedToEmbedder", TakeServicesProvidedToEmbedder, 0},
63 {"takeShellProxyHandle", TakeShellProxyHandle, 0},
64 };
65
66 const DartBuiltin& GetBuiltin() {
67 static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions,
68 arraysize(kNativeFunctions));
69 return builtin;
70 }
71
72 Dart_NativeFunction Resolver(Dart_Handle name,
73 int argument_count,
74 bool* auto_setup_scope) {
75 return GetBuiltin().Resolver(name, argument_count, auto_setup_scope);
76 }
77
78 const uint8_t* Symbolizer(Dart_NativeFunction native_function) {
79 return GetBuiltin().Symbolizer(native_function);
80 }
81
82 const char kLibraryName[] = "dart:sky.internals";
83
84 } // namespace
85
86 void Internals::Create(Dart_Isolate isolate, DocumentView* document_view) {
87 DartState* state = DartState::From(isolate);
88 state->SetUserData(&kInternalsKey, new Internals(document_view));
89 Dart_Handle library =
90 Dart_LookupLibrary(Dart_NewStringFromCString(kLibraryName));
91 CHECK(!LogIfError(library));
92 CHECK(!LogIfError(Dart_SetNativeResolver(library, Resolver, Symbolizer)));
93 }
94
95 Internals::Internals(DocumentView* document_view)
96 : document_view_(document_view->GetWeakPtr()),
97 shell_binding_(this) {
98 }
99
100 Internals::~Internals() {
101 }
102
103 mojo::Handle Internals::TakeServicesProvidedToEmbedder() {
104 if (!document_view_)
105 return mojo::Handle();
106 return document_view_->TakeServicesProvidedToEmbedder().release();
107 }
108
109 mojo::Handle Internals::TakeServicesProvidedByEmbedder() {
110 if (!document_view_)
111 return mojo::Handle();
112 return document_view_->TakeServicesProvidedByEmbedder().release();
113 }
114
115 mojo::Handle Internals::TakeServiceRegistry() {
116 if (!document_view_)
117 return mojo::Handle();
118 return document_view_->TakeServiceRegistry().release();
119 }
120
121 // Returns a MessagePipe handle that's connected to this Shell. The caller
122 // owns the handle and is expected to use it to create the JS Application for
123 // the DocumentView.
124 mojo::Handle Internals::TakeShellProxyHandle() {
125 mojo::ShellPtr shell;
126 if (!shell_binding_.is_bound())
127 shell_binding_.Bind(GetProxy(&shell));
128 return shell.PassInterface().PassHandle().release();
129 }
130
131 void Internals::ConnectToApplication(
132 const mojo::String& application_url,
133 mojo::InterfaceRequest<mojo::ServiceProvider> services,
134 mojo::ServiceProviderPtr exposed_services) {
135 if (document_view_) {
136 document_view_->shell()->ConnectToApplication(
137 application_url, services.Pass(), exposed_services.Pass());
138 }
139 }
140
141 } // namespace sky
OLDNEW
« no previous file with comments | « services/sky/internals.h ('k') | services/sky/platform_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698