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

Side by Side Diff: tools/dom/src/chrome/app.runtime.dart

Issue 12049030: Initial commit for Chrome.* APIs in Dart (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // from app_runtime.idl
6 part of chrome;
7
8 /**
9 * Types
10 */
11
12 // A WebIntents intent object. Deprecated.
13 class Intent extends ChromeObject {
14 // The WebIntent being invoked.
15 String _action;
16
17 // The MIME type of the data.
18 String _type;
19
20 // Data associated with the intent.
21 var _data;
22
23 // Callback to be compatible with WebIntents.
24 Function _postResult;
25
26 // Callback to be compatible with WebIntents.
27 Function _postFailure;
28
29 /*
30 * Public (Dart) constructor
31 */
32 Intent({
33 String action,
blois 2013/01/23 02:06:12 Normally these are all collapsed onto the same lin
sashab 2013/01/23 04:45:34 Done.
34 String type,
35 var data,
36 Function postResult,
37 Function postFailure
blois 2013/01/23 02:06:12 Can this be further typed? As in what are the para
sashab 2013/01/23 04:45:34 This is actually a mistake; see the TODO below:
38 }) :
39 _action = action,
40 _type = type,
41 _data = data,
42 _postResult = postResult,
43 _postFailure = postFailure
44 ;
45
46 /*
47 * Private (JS) constructor
48 */
49 Intent._proxy(_jsObject)
50 : super._proxy(_jsObject);
51
52 /*
53 * Serialisation method
54 */
55 Map _toMap() {
56 Map m = {};
57 if (action != null) m['action'] = action;
58 if (type != null) m['type'] = type;
59 if (data != null) m['data'] = data;
60 if (postResult != null) m['postResult'] = postResult;
61 if (postFailure != null) m['postFailure'] = postFailure;
62 return m;
63 }
64
65 /*
66 * Public accessors
67 */
68 String get action {
blois 2013/01/23 02:06:12 Couldn't you just have it always have the JS proxy
sashab 2013/01/23 04:45:34 Done.
69 if (!this._hasProxy())
70 return this._action;
71 return JS('String', '#.action', this._jsObject);
72 }
73
74 void set action(String action) {
75 if (!this._hasProxy())
76 this._action = action;
77 else
78 JS('void', '#.action = #', this._jsObject, convertArgument(action));
79 }
80
81 String get type {
82 if (!this._hasProxy())
83 return this._type;
84 return JS('String', '#.action', this._jsObject);
85 }
86
87 void set type(String type) {
88 if (!this._hasProxy())
89 this._type = type;
90 else
91 JS('void', '#.type = #', this._jsObject, convertArgument(type));
92 }
93
94 /* TODO(sashab): What's the best way to return generic JS objects? */
95 Object get data {
96 if (!this._hasProxy())
97 return this._data;
98 return convertNativeToDart_SerializedScriptValue(JS('Object', '#.data', this ._jsObject));
99 }
100
101 /* TODO(sashab): What's the best way to serialize generic JS objects? */
102 void set data(var data) {
103 if (!this._hasProxy())
104 this._data = data;
105 else
106 JS('void', '#.data = #', this._jsObject, convertArgument(data));
107 }
108
109 /*
110 * TODO(sashab): What is a NullCallback() type?
111 * Add postResult and postFailure once understanding what this type is, and
112 * how to pass functions back from JS.
113 */
114 }
115
116 class LaunchItem extends ChromeObject {
117 // FileEntry for the file.
118 FileEntry _entry;
119
120 // The MIME type of the file.
121 String _type;
122
123 /*
124 * Public constructor
125 */
126 LaunchItem({
127 FileEntry entry,
128 String type
129 }) :
130 _entry = entry,
131 _type = type
132 ;
133
134 /*
135 * Private constructor
136 */
137 LaunchItem._proxy(_jsObject)
138 : super._proxy(_jsObject);
139
140 /*
141 * Serialisation method
142 */
143 Map _toMap() {
144 Map m = {};
145 if (entry != null) m['entry'] = entry;
146 if (type != null) m['type'] = type;
147 return m;
148 }
149
150 /*
151 * Public accessors
152 */
153 FileEntry get entry {
154 if (!this._hasProxy())
155 return this._entry;
156 return JS('FileEntry', '#.entry', this._jsObject);
157 }
158
159 /* TODO(sashab): Find a way to serialize a html.FileEntry? */
160 void set entry(FileEntry entry) {
161 if (!this._hasProxy())
162 this._entry = entry;
163 else
164 JS('void', '#.entry = #', this._jsObject, convertArgument(entry));
165 }
166
167 String get type {
168 if (!this._hasProxy())
169 return this._type;
170 return JS('String', '#.type', this._jsObject);
171 }
172
173 void set type(String type) {
174 if (!this._hasProxy())
175 this._type = type;
176 else
177 JS('void', '#.type = #', this._jsObject, convertArgument(type));
178 }
179
180
181 }
182
183 // Optional data for the launch.
184 class LaunchData extends ChromeObject {
185 Intent _intent;
186
187 // The id of the file handler that the app is being invoked with.
188 String _id;
189
190 List<LaunchItem> _items;
191
192 /*
193 * Public constructor
194 */
195 LaunchData({
196 Intent intent,
197 String id,
198 List<LaunchItem> items
199 }) :
200 _intent = intent,
201 _id = id,
202 _items = items
203 ;
204
205 /*
206 * Private constructor
207 */
208 LaunchData._proxy(_jsObject)
209 : super._proxy(_jsObject);
210
211 /*
212 * Serialisation method
213 */
214 Map _toMap() {
215 Map m = {};
216 if (intent != null) m['intent'] = intent;
217 if (id != null) m['id'] = id;
218 if (items != null) m['items'] = items;
219 return m;
220 }
221
222 /*
223 * Public accessors
224 */
225 Intent get intent {
226 if (!this._hasProxy())
227 return this._intent;
228 return new Intent._proxy(JS('Object', '#.intent', this._jsObject));
229 }
230
231 void set intent(Intent intent) {
232 if (!this._hasProxy())
233 this._intent = intent;
234 else
235 JS('void', '#.intent = #', this._jsObject, convertArgument(intent));
236 }
237
238 String get id {
239 if (!this._hasProxy())
240 return this._id;
241 return JS('String', '#.id', this._jsObject);
242 }
243
244 void set id(String id) {
245 if (!this._hasProxy())
246 this._id = id;
247 else
248 JS('void', '#.id = #', this._jsObject, convertArgument(id));
249 }
250
251 /* TODO(sashab): Wrap lists of custom types when returning. */
252 List<LaunchItem> get items {
253 if (!this._hasProxy())
254 return this._items;
255 return JS('List', '#.items', this._jsObject);
256 }
257
258 void set items(List<LaunchItem> items) {
259 if (!this._hasProxy())
260 this._items = items;
261 else
262 JS('void', '#.items = #', this._jsObject, convertArgument(items));
263 }
264 }
265
266 class IntentResponse extends ChromeObject {
267 // Identifies the intent.
268 int _intentId;
269
270 // Was this intent successful? (i.e., postSuccess vs postFailure).
271 bool _success;
272
273 // Data associated with the intent response.
274 Object _data;
275
276 /*
277 * Public constructor
278 */
279 IntentResponse({
280 int intentId,
281 bool success,
282 Object data
283 }) :
284 _intentId = intentId,
285 _success = success,
286 _data = data
287 ;
288
289 /*
290 * Private constructor
291 */
292 IntentResponse._proxy(JSObject _jsObject)
293 : super._proxy(_jsObject);
294
295 /*
296 * Serialisation method
297 */
298 Map _toMap() {
299 Map m = {};
300 if (intentId != null) m['intentId'] = intentId;
301 if (success != null) m['success'] = success;
302 if (data != null) m['data'] = data;
303 return m;
304 }
305
306 /*
307 * Public accessors
308 */
309 int get intentId {
310 if (!this._hasProxy())
311 return this._intentId;
312 return JS('int', '#.intentId', this._jsObject);
313 }
314
315 void set intentId(int intentId) {
316 if (!this._hasProxy())
317 this._intentId = intentId;
318 else
319 JS('void', '#.intentId = #', this._jsObject, convertArgument(intentId));
320 }
321
322 bool get success {
323 if (!this._hasProxy())
324 return this._success;
325 return JS('bool', '#.success', this._jsObject);
326 }
327
328 void set success(bool success) {
329 if (!this._hasProxy())
330 this._success = success;
331 else
332 JS('void', '#.success = #', this._jsObject, convertArgument(success));
333 }
334
335 /* TODO(sashab): What's the best way to return generic JS objects? */
336 Object get data {
337 if (!this._hasProxy())
338 return this._data;
339 return convertNativeToDart_SerializedScriptValue(JS('Object', '#.data', this ._jsObject));
340 }
341
342 /* TODO(sashab): What's the best way to serialize generic JS objects? */
343 void set data(var data) {
344 if (!this._hasProxy())
345 this._data = data;
346 else
347 JS('void', '#.data = #', this._jsObject, convertArgument(data));
348 }
349 }
350
351 /**
352 * Events
353 */
354
355 // Fired at Chrome startup to apps that were running when Chrome last shut
356 // down.
357 class $Event_ChromeAppRuntimeOnRestarted extends $Event {
358 /*
359 * Override callback type definitions
360 */
361 void addListener(void callback())
362 => super.addListener(callback);
363 void removeListener(void callback())
364 => super.removeListener(callback);
365 bool hasListener(void callback())
366 => super.hasListener(callback);
367
368 /*
369 * Constructor
370 */
371 $Event_ChromeAppRuntimeOnRestarted(jsObject) :
372 super._(jsObject, 0);
373 }
374
375 // Fired when an app is launched from the launcher or in response to a web
376 // intent.
377 class $Event_ChromeAppRuntimeOnLaunched extends $Event {
378 /*
379 * Override callback type definitions
380 */
381 void addListener(void callback(LaunchData launchData))
382 => super.addListener(callback);
383 void removeListener(void callback(LaunchData launchData))
384 => super.removeListener(callback);
385 bool hasListener(void callback(LaunchData launchData))
386 => super.hasListener(callback);
387
388 /*
389 * Constructor
390 */
391 $Event_ChromeAppRuntimeOnLaunched(jsObject) :
392 super._(jsObject, 1);
393 }
394
395 /**
396 * Functions
397 */
398 class $API_ChromeAppRuntime {
399 /*
400 * API connection
401 */
402 Object _jsObject;
403
404 /*
405 * Events
406 */
407 $Event_ChromeAppRuntimeOnRestarted onRestarted;
408 $Event_ChromeAppRuntimeOnLaunched onLaunched;
409
410 /*
411 * Functions
412 */
413 void postIntentResponse(IntentResponse intentResponse) {
414 JS('void', '#.postIntentResponse(#)', this._jsObject, convertArgument(intent Response));
415 }
416
417 /*
418 * Constructor
419 */
420 $API_ChromeAppRuntime(this._jsObject) {
421 onRestarted = new $Event_ChromeAppRuntimeOnRestarted(JS('Object', '#.onResta rted', this._jsObject));
422 onLaunched = new $Event_ChromeAppRuntimeOnLaunched(JS('Object', '#.onLaunche d', this._jsObject));
423 }
424 }
425
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698