| OLD | NEW |
| 1 library chrome; | 1 library chrome; |
| 2 | 2 |
| 3 import 'dart:html_common'; |
| 4 import 'dart:html'; |
| 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 5 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 4 // for details. All rights reserved. Use of this source code is governed by a | 6 // for details. All rights reserved. Use of this source code is governed by a |
| 5 // BSD-style license that can be found in the LICENSE file. | 7 // BSD-style license that can be found in the LICENSE file. |
| 6 | 8 |
| 7 // DO NOT EDIT | 9 // DO NOT EDIT |
| 8 // Auto-generated dart:chrome library. | 10 // Auto-generated dart:chrome library. |
| 9 | 11 |
| 10 | 12 |
| 13 |
| 14 |
| 11 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 15 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 12 // for details. All rights reserved. Use of this source code is governed by a | 16 // for details. All rights reserved. Use of this source code is governed by a |
| 13 // BSD-style license that can be found in the LICENSE file. | 17 // BSD-style license that can be found in the LICENSE file. |
| 14 | 18 |
| 15 | 19 /** |
| 16 // This is an example of exposing chrome APIs in Dart and will be replaced with | 20 * A set of utilities for use with the Chrome Extension APIs. |
| 17 // the proper implementation in the future. | 21 * |
| 18 | 22 * Allows for easy access to required JS objects. |
| 19 class AppModule { | 23 */ |
| 20 AppModule._(); | 24 |
| 21 | 25 /** |
| 22 WindowModule get window => new WindowModule._(); | 26 * A dart object, that is convertible to JS. Used for creating objects in dart, |
| 23 } | 27 * then passing them to JS. |
| 24 | 28 * |
| 25 class WindowModule { | 29 * Objects that are passable to JS need to implement this interface. |
| 26 WindowModule._(); | 30 */ |
| 27 | 31 abstract class ChromeObject { |
| 28 void create(String url) { | 32 /* |
| 29 var chrome = JS('', 'chrome'); | 33 * Default Constructor |
| 30 | 34 * |
| 31 if (chrome == null) { | 35 * Called by child objects during their regular construction. |
| 32 throw new UnsupportedError('Not supported by current browser'); | 36 */ |
| 37 ChromeObject() : |
| 38 _jsObject = null; |
| 39 |
| 40 /* |
| 41 * Internal proxy constructor |
| 42 * |
| 43 * Creates a new object using this existing proxy. |
| 44 */ |
| 45 ChromeObject._proxy(this._jsObject); |
| 46 |
| 47 /* |
| 48 * JS Object Representation |
| 49 */ |
| 50 Object _jsObject; |
| 51 |
| 52 /* |
| 53 * Return a Map representation of this object's members, non-recursively. |
| 54 */ |
| 55 Map _toMap(); |
| 56 |
| 57 /* |
| 58 * Return a non-recursive serialized representation of this object. |
| 59 * |
| 60 * Returns a Map representation, if this object has not yet been proxied, |
| 61 * or the existing proxy, if it has already been proxied. |
| 62 */ |
| 63 Object _serialize() { |
| 64 if (_jsObject == null) |
| 65 return this._toMap(); |
| 66 return _jsObject; |
| 67 } |
| 68 |
| 69 /* |
| 70 * Returns True if this object has a matching JS object, False otherwise. |
| 71 */ |
| 72 bool _hasProxy() { |
| 73 return this._jsObject != null; |
| 74 } |
| 75 } |
| 76 |
| 77 /** |
| 78 * Useful functions for converting arguments. |
| 79 */ |
| 80 |
| 81 /** |
| 82 * Converts the given map-type argument to js-friendly format, recursively. |
| 83 * Returns the new Map object. |
| 84 */ |
| 85 Object _convertMapArgument(Map argument) { |
| 86 Map m = new Map(); |
| 87 for (Object key in argument.keys) |
| 88 m[key] = convertArgument(argument[key]); |
| 89 return convertDartToNative_Dictionary(m); |
| 90 } |
| 91 |
| 92 /* |
| 93 Map _convertMapArgument(Map argument) { |
| 94 var object = JS('var', '{}'); |
| 95 for (Object key in argument.keys) |
| 96 JS('void', '#[#] = #', object, key, convertArgument(argument[key])); |
| 97 return object; |
| 98 } |
| 99 */ |
| 100 |
| 101 /** |
| 102 * Converts the given list-type argument to js-friendly format, recursively. |
| 103 * Returns the new List object. |
| 104 */ |
| 105 List _convertListArgument(List argument) { |
| 106 List l = new List(); |
| 107 for (var i = 0; i < argument.length; i ++) |
| 108 l.add(convertArgument(argument[i])); |
| 109 return l; |
| 110 } |
| 111 |
| 112 /** |
| 113 * Converts the given argument Object to js-friendly format, recursively. |
| 114 * |
| 115 * Flattens out all Chrome objects into their corresponding ._toMap() |
| 116 * definitions, then converts them to JS objects. |
| 117 * |
| 118 * Returns the new argument. |
| 119 * |
| 120 * Cannot be used for functions. |
| 121 */ |
| 122 Object convertArgument(var argument) { |
| 123 if (argument == null) |
| 124 return argument; |
| 125 |
| 126 if (argument is num || argument is String || argument is bool) |
| 127 return argument; |
| 128 |
| 129 if (argument is ChromeObject) |
| 130 return convertArgument(argument._serialize()); |
| 131 |
| 132 if (argument is List) |
| 133 return _convertListArgument(argument); |
| 134 |
| 135 if (argument is Map) |
| 136 return _convertMapArgument(argument); |
| 137 |
| 138 if (argument is Function) |
| 139 throw new Exception("Cannot serialize Function argument ${argument}."); |
| 140 |
| 141 // TODO(sashab): Try and detect whether the argument is already serialized. |
| 142 return argument; |
| 143 } |
| 144 |
| 145 /** |
| 146 * Description of a declarative rule for handling events. |
| 147 */ |
| 148 class Rule extends ChromeObject { |
| 149 String _id; |
| 150 List _conditions; |
| 151 List _actions; |
| 152 int _priority; |
| 153 |
| 154 /* |
| 155 * Public (Dart) constructor |
| 156 */ |
| 157 Rule({ |
| 158 String id, |
| 159 List conditions, |
| 160 List actions, |
| 161 int priority |
| 162 }) : |
| 163 _id = id, |
| 164 _conditions = conditions, |
| 165 _actions = actions, |
| 166 _priority = priority |
| 167 ; |
| 168 |
| 169 /* |
| 170 * Private (JS) constructor |
| 171 */ |
| 172 Rule._proxy(_jsObject) |
| 173 : super._proxy(_jsObject); |
| 174 |
| 175 /* |
| 176 * Serialisation method |
| 177 */ |
| 178 Map _toMap() { |
| 179 Map m = {}; |
| 180 if (id != null) m['id'] = id; |
| 181 if (conditions != null) m['conditions'] = conditions; |
| 182 if (actions != null) m['actions'] = actions; |
| 183 if (priority != null) m['priority'] = priority; |
| 184 return m; |
| 185 } |
| 186 |
| 187 /* |
| 188 * Public accessors |
| 189 */ |
| 190 String get id { |
| 191 if (!this._hasProxy()) |
| 192 return this._id; |
| 193 return JS('String', '#.id', this._jsObject); |
| 194 } |
| 195 |
| 196 void set id(String id) { |
| 197 if (!this._hasProxy()) |
| 198 this._id = id; |
| 199 else |
| 200 JS('void', '#.id = #', this._jsObject, convertArgument(id)); |
| 201 } |
| 202 |
| 203 List get conditions { |
| 204 if (!this._hasProxy()) |
| 205 return this._conditions; |
| 206 return JS('List', '#.conditions', this._jsObject); |
| 207 } |
| 208 |
| 209 void set conditions(List conditions) { |
| 210 if (!this._hasProxy()) |
| 211 this._conditions = conditions; |
| 212 else |
| 213 JS('void', '#.conditions = #', this._jsObject, convertArgument(conditions)
); |
| 214 } |
| 215 |
| 216 List get actions { |
| 217 if (!this._hasProxy()) |
| 218 return this._actions; |
| 219 return JS('List', '#.actions', this._jsObject); |
| 220 } |
| 221 |
| 222 void set actions(List actions) { |
| 223 if (!this._hasProxy()) |
| 224 this._actions = actions; |
| 225 else |
| 226 JS('void', '#.actions = #', this._jsObject, convertArgument(actions)); |
| 227 } |
| 228 |
| 229 int get priority { |
| 230 if (!this._hasProxy()) |
| 231 return this._priority; |
| 232 return JS('int', '#.priority', this._jsObject); |
| 233 } |
| 234 |
| 235 void set priority(int priority) { |
| 236 if (!this._hasProxy()) |
| 237 this._priority = priority; |
| 238 else |
| 239 JS('void', '#.priority = #', this._jsObject, convertArgument(priority)); |
| 240 } |
| 241 |
| 242 } |
| 243 |
| 244 /** |
| 245 * The Event class. |
| 246 * |
| 247 * Chrome Event classes extend this interface. |
| 248 * |
| 249 * e.g. |
| 250 * |
| 251 * // chrome.app.runtime.onLaunched |
| 252 * class $Event_ChromeAppRuntimeOnLaunched extends $Event { |
| 253 * // constructor, passing the arity of the callback |
| 254 * $Event_ChromeAppRuntimeOnLaunched(jsObject) : |
| 255 * super._(jsObject, 1); |
| 256 * |
| 257 * // methods, strengthening the Function parameter specificity |
| 258 * void addListener(void callback(LaunchData launchData)) |
| 259 * => super.addListener(callback); |
| 260 * void removeListener(void callback(LaunchData launchData)) |
| 261 * => super.removeListener(callback); |
| 262 * bool hasListener(void callback(LaunchData launchData)) |
| 263 * => super.hasListener(callback); |
| 264 * } |
| 265 * |
| 266 */ |
| 267 class $Event { |
| 268 // JS var |
| 269 Object _jsObject; |
| 270 |
| 271 // number of arguments the callback takes |
| 272 int _callbackArity; |
| 273 |
| 274 // constructor |
| 275 $Event._(this._jsObject, this._callbackArity); |
| 276 |
| 277 // methods |
| 278 |
| 279 /** |
| 280 * Registers an event listener <em>callback</em> to an event. |
| 281 */ |
| 282 void addListener(Function callback) => |
| 283 JS('void', |
| 284 '#.addListener(#)', |
| 285 this._jsObject, |
| 286 convertDartClosureToJS(callback, this._callbackArity) |
| 287 ); |
| 288 |
| 289 /** |
| 290 * Deregisters an event listener <em>callback</em> from an event. |
| 291 */ |
| 292 void removeListener(Function callback) => |
| 293 JS('void', |
| 294 '#.removeListener(#)', |
| 295 this._jsObject, |
| 296 convertDartClosureToJS(callback, this._callbackArity) |
| 297 ); |
| 298 |
| 299 /** |
| 300 * Returns True if <em>callback</em> is registered to the event. |
| 301 */ |
| 302 bool hasListener(Function callback) => |
| 303 JS('bool', |
| 304 '#.hasListener(#)', |
| 305 this._jsObject, |
| 306 convertDartClosureToJS(callback, this._callbackArity) |
| 307 ); |
| 308 |
| 309 /** |
| 310 * Returns true if any event listeners are registered to the event. |
| 311 */ |
| 312 bool hasListeners() => |
| 313 JS('bool', |
| 314 '#.hasListeners()', |
| 315 this._jsObject |
| 316 ); |
| 317 |
| 318 /** |
| 319 * Registers rules to handle events. |
| 320 * |
| 321 * @param eventName Name of the event this function affects. |
| 322 * @param rules Rules to be registered. These do not replace previously regist
ered rules. |
| 323 * @param callback Called with registered rules. |
| 324 */ |
| 325 void addRules(String eventName, List<Rule> rules, [ void callback(List<Rule> r
ules) ]) { |
| 326 // proxy the callback |
| 327 void __proxied_callback(List rules) {}; |
| 328 |
| 329 if (callback != null) |
| 330 void __proxied_callback(List rules) { |
| 331 List<Rule> __proxy_rules = new List<Rule>(); |
| 332 |
| 333 for (Object o in rules) |
| 334 __proxy_rules.add(new Rule._proxy(o)); |
| 335 |
| 336 callback(__proxy_rules); |
| 337 } |
| 338 |
| 339 JS('void', |
| 340 '#.addRules(#, #, #)', |
| 341 this._jsObject, |
| 342 convertArgument(eventName), |
| 343 convertArgument(rules), |
| 344 convertDartClosureToJS(callback, 1) |
| 345 ); |
| 346 } |
| 347 |
| 348 /** |
| 349 * Returns currently registered rules. |
| 350 * |
| 351 * @param eventName Name of the event this function affects. |
| 352 * @param ruleIdentifiers If an array is passed, only rules with identifiers c
ontained in this array are returned. |
| 353 * @param callback Called with registered rules. |
| 354 */ |
| 355 void getRules(String eventName, [ List<String> ruleIdentifiers, void callback(
List<Rule> rules) ]) { |
| 356 // proxy the callback |
| 357 void __proxied_callback(List rules) {}; |
| 358 |
| 359 if (callback != null) |
| 360 void __proxied_callback(List rules) { |
| 361 List<Rule> __proxy_rules = new List<Rule>(); |
| 362 |
| 363 for (Object o in rules) |
| 364 __proxy_rules.add(new Rule._proxy(o)); |
| 365 |
| 366 callback(__proxy_rules); |
| 367 } |
| 368 |
| 369 JS('void', |
| 370 '#.getRules(#, #, #)', |
| 371 this._jsObject, |
| 372 convertArgument(eventName), |
| 373 convertArgument(ruleIdentifiers), |
| 374 convertDartClosureToJS(callback, 1) |
| 375 ); |
| 376 } |
| 377 |
| 378 /** |
| 379 * Unregisters currently registered rules. |
| 380 * |
| 381 * @param eventName Name of the event this function affects. |
| 382 * @param ruleIdentifiers If an array is passed, only rules with identifiers c
ontained in this array are unregistered. |
| 383 * @param callback Called when rules were unregistered. |
| 384 */ |
| 385 void removeRules(String eventName, [ List<String> ruleIdentifiers, void callba
ck() ]) => |
| 386 JS('void', |
| 387 '#.removeRules(#, #, #)', |
| 388 this._jsObject, |
| 389 convertArgument(eventName), |
| 390 convertArgument(ruleIdentifiers), |
| 391 convertDartClosureToJS(callback, 0) |
| 392 ); |
| 393 } |
| 394 |
| 395 |
| 396 |
| 397 |
| 398 |
| 399 |
| 400 |
| 401 |
| 402 |
| 403 |
| 404 |
| 405 |
| 406 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 407 // for details. All rights reserved. Use of this source code is governed by a |
| 408 // BSD-style license that can be found in the LICENSE file. |
| 409 |
| 410 // TODO(sashab): Change all chrome-API object types to be JS-bound, so that the |
| 411 // proxy types are not needed. Instead, creation of an object also creates its |
| 412 // JS counterpart, and all objects are proxies from the start. |
| 413 |
| 414 // chrome.app |
| 415 class $API_ChromeApp { |
| 416 /* |
| 417 * JS Variable |
| 418 */ |
| 419 Object _jsObject; |
| 420 |
| 421 /* |
| 422 * Members |
| 423 */ |
| 424 $API_ChromeAppWindow window; |
| 425 $API_ChromeAppRuntime runtime; |
| 426 |
| 427 /* |
| 428 * Constructor |
| 429 */ |
| 430 $API_ChromeApp(this._jsObject) { |
| 431 var window_object = JS('', '#.window', this._jsObject); |
| 432 if (window_object == null) |
| 433 throw new UnsupportedError('Not supported by current browser.'); |
| 434 window = new $API_ChromeAppWindow(window_object); |
| 435 |
| 436 var runtime_object = JS('', '#.runtime', this._jsObject); |
| 437 if (runtime_object == null) |
| 438 throw new UnsupportedError('Not supported by current browser.'); |
| 439 runtime = new $API_ChromeAppRuntime(runtime_object); |
| 440 } |
| 441 } |
| 442 |
| 443 // chrome |
| 444 class $API_Chrome { |
| 445 /* |
| 446 * JS Variable |
| 447 */ |
| 448 Object _jsObject; |
| 449 |
| 450 /* |
| 451 * Members |
| 452 */ |
| 453 $API_ChromeApp app; |
| 454 |
| 455 /* |
| 456 * Constructor |
| 457 */ |
| 458 $API_Chrome() { |
| 459 this._jsObject = JS("Object", "chrome"); |
| 460 if (this._jsObject == null) |
| 461 throw new UnsupportedError('Not supported by current browser.'); |
| 462 |
| 463 var app_object = JS('', '#.app', this._jsObject); |
| 464 if (app_object == null) |
| 465 throw new UnsupportedError('Not supported by current browser.'); |
| 466 app = new $API_ChromeApp(app_object); |
| 467 } |
| 468 } |
| 469 |
| 470 // The final chrome object |
| 471 final $API_Chrome chrome = new $API_Chrome(); |
| 472 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 473 // for details. All rights reserved. Use of this source code is governed by a |
| 474 // BSD-style license that can be found in the LICENSE file. |
| 475 |
| 476 // from app_runtime.idl |
| 477 |
| 478 /** |
| 479 * Types |
| 480 */ |
| 481 |
| 482 // A WebIntents intent object. Deprecated. |
| 483 class Intent extends ChromeObject { |
| 484 // The WebIntent being invoked. |
| 485 String _action; |
| 486 |
| 487 // The MIME type of the data. |
| 488 String _type; |
| 489 |
| 490 // Data associated with the intent. |
| 491 var _data; |
| 492 |
| 493 // Callback to be compatible with WebIntents. |
| 494 Function _postResult; |
| 495 |
| 496 // Callback to be compatible with WebIntents. |
| 497 Function _postFailure; |
| 498 |
| 499 /* |
| 500 * Public (Dart) constructor |
| 501 */ |
| 502 Intent({ |
| 503 String action, |
| 504 String type, |
| 505 var data, |
| 506 Function postResult, |
| 507 Function postFailure |
| 508 }) : |
| 509 _action = action, |
| 510 _type = type, |
| 511 _data = data, |
| 512 _postResult = postResult, |
| 513 _postFailure = postFailure |
| 514 ; |
| 515 |
| 516 /* |
| 517 * Private (JS) constructor |
| 518 */ |
| 519 Intent._proxy(_jsObject) |
| 520 : super._proxy(_jsObject); |
| 521 |
| 522 /* |
| 523 * Serialisation method |
| 524 */ |
| 525 Map _toMap() { |
| 526 Map m = {}; |
| 527 if (action != null) m['action'] = action; |
| 528 if (type != null) m['type'] = type; |
| 529 if (data != null) m['data'] = data; |
| 530 if (postResult != null) m['postResult'] = postResult; |
| 531 if (postFailure != null) m['postFailure'] = postFailure; |
| 532 return m; |
| 533 } |
| 534 |
| 535 /* |
| 536 * Public accessors |
| 537 */ |
| 538 String get action { |
| 539 if (!this._hasProxy()) |
| 540 return this._action; |
| 541 return JS('String', '#.action', this._jsObject); |
| 542 } |
| 543 |
| 544 void set action(String action) { |
| 545 if (!this._hasProxy()) |
| 546 this._action = action; |
| 547 else |
| 548 JS('void', '#.action = #', this._jsObject, convertArgument(action)); |
| 549 } |
| 550 |
| 551 String get type { |
| 552 if (!this._hasProxy()) |
| 553 return this._type; |
| 554 return JS('String', '#.action', this._jsObject); |
| 555 } |
| 556 |
| 557 void set type(String type) { |
| 558 if (!this._hasProxy()) |
| 559 this._type = type; |
| 560 else |
| 561 JS('void', '#.type = #', this._jsObject, convertArgument(type)); |
| 562 } |
| 563 |
| 564 /* TODO(sashab): What's the best way to return generic JS objects? */ |
| 565 Object get data { |
| 566 if (!this._hasProxy()) |
| 567 return this._data; |
| 568 return convertNativeToDart_SerializedScriptValue(JS('Object', '#.data', this
._jsObject)); |
| 569 } |
| 570 |
| 571 /* TODO(sashab): What's the best way to serialize generic JS objects? */ |
| 572 void set data(var data) { |
| 573 if (!this._hasProxy()) |
| 574 this._data = data; |
| 575 else |
| 576 JS('void', '#.data = #', this._jsObject, convertArgument(data)); |
| 577 } |
| 578 |
| 579 /* |
| 580 * TODO(sashab): What is a NullCallback() type? |
| 581 * Add postResult and postFailure once understanding what this type is, and |
| 582 * how to pass functions back from JS. |
| 583 */ |
| 584 } |
| 585 |
| 586 class LaunchItem extends ChromeObject { |
| 587 // FileEntry for the file. |
| 588 FileEntry _entry; |
| 589 |
| 590 // The MIME type of the file. |
| 591 String _type; |
| 592 |
| 593 /* |
| 594 * Public constructor |
| 595 */ |
| 596 LaunchItem({ |
| 597 FileEntry entry, |
| 598 String type |
| 599 }) : |
| 600 _entry = entry, |
| 601 _type = type |
| 602 ; |
| 603 |
| 604 /* |
| 605 * Private constructor |
| 606 */ |
| 607 LaunchItem._proxy(_jsObject) |
| 608 : super._proxy(_jsObject); |
| 609 |
| 610 /* |
| 611 * Serialisation method |
| 612 */ |
| 613 Map _toMap() { |
| 614 Map m = {}; |
| 615 if (entry != null) m['entry'] = entry; |
| 616 if (type != null) m['type'] = type; |
| 617 return m; |
| 618 } |
| 619 |
| 620 /* |
| 621 * Public accessors |
| 622 */ |
| 623 FileEntry get entry { |
| 624 if (!this._hasProxy()) |
| 625 return this._entry; |
| 626 return JS('FileEntry', '#.entry', this._jsObject); |
| 627 } |
| 628 |
| 629 /* TODO(sashab): Find a way to serialize a html.FileEntry? */ |
| 630 void set entry(FileEntry entry) { |
| 631 if (!this._hasProxy()) |
| 632 this._entry = entry; |
| 633 else |
| 634 JS('void', '#.entry = #', this._jsObject, convertArgument(entry)); |
| 635 } |
| 636 |
| 637 String get type { |
| 638 if (!this._hasProxy()) |
| 639 return this._type; |
| 640 return JS('String', '#.type', this._jsObject); |
| 641 } |
| 642 |
| 643 void set type(String type) { |
| 644 if (!this._hasProxy()) |
| 645 this._type = type; |
| 646 else |
| 647 JS('void', '#.type = #', this._jsObject, convertArgument(type)); |
| 648 } |
| 649 |
| 650 |
| 651 } |
| 652 |
| 653 // Optional data for the launch. |
| 654 class LaunchData extends ChromeObject { |
| 655 Intent _intent; |
| 656 |
| 657 // The id of the file handler that the app is being invoked with. |
| 658 String _id; |
| 659 |
| 660 List<LaunchItem> _items; |
| 661 |
| 662 /* |
| 663 * Public constructor |
| 664 */ |
| 665 LaunchData({ |
| 666 Intent intent, |
| 667 String id, |
| 668 List<LaunchItem> items |
| 669 }) : |
| 670 _intent = intent, |
| 671 _id = id, |
| 672 _items = items |
| 673 ; |
| 674 |
| 675 /* |
| 676 * Private constructor |
| 677 */ |
| 678 LaunchData._proxy(_jsObject) |
| 679 : super._proxy(_jsObject); |
| 680 |
| 681 /* |
| 682 * Serialisation method |
| 683 */ |
| 684 Map _toMap() { |
| 685 Map m = {}; |
| 686 if (intent != null) m['intent'] = intent; |
| 687 if (id != null) m['id'] = id; |
| 688 if (items != null) m['items'] = items; |
| 689 return m; |
| 690 } |
| 691 |
| 692 /* |
| 693 * Public accessors |
| 694 */ |
| 695 Intent get intent { |
| 696 if (!this._hasProxy()) |
| 697 return this._intent; |
| 698 return new Intent._proxy(JS('Object', '#.intent', this._jsObject)); |
| 699 } |
| 700 |
| 701 void set intent(Intent intent) { |
| 702 if (!this._hasProxy()) |
| 703 this._intent = intent; |
| 704 else |
| 705 JS('void', '#.intent = #', this._jsObject, convertArgument(intent)); |
| 706 } |
| 707 |
| 708 String get id { |
| 709 if (!this._hasProxy()) |
| 710 return this._id; |
| 711 return JS('String', '#.id', this._jsObject); |
| 712 } |
| 713 |
| 714 void set id(String id) { |
| 715 if (!this._hasProxy()) |
| 716 this._id = id; |
| 717 else |
| 718 JS('void', '#.id = #', this._jsObject, convertArgument(id)); |
| 719 } |
| 720 |
| 721 /* TODO(sashab): Wrap lists of custom types when returning. */ |
| 722 List<LaunchItem> get items { |
| 723 if (!this._hasProxy()) |
| 724 return this._items; |
| 725 return JS('List', '#.items', this._jsObject); |
| 726 } |
| 727 |
| 728 void set items(List<LaunchItem> items) { |
| 729 if (!this._hasProxy()) |
| 730 this._items = items; |
| 731 else |
| 732 JS('void', '#.items = #', this._jsObject, convertArgument(items)); |
| 733 } |
| 734 } |
| 735 |
| 736 class IntentResponse extends ChromeObject { |
| 737 // Identifies the intent. |
| 738 int _intentId; |
| 739 |
| 740 // Was this intent successful? (i.e., postSuccess vs postFailure). |
| 741 bool _success; |
| 742 |
| 743 // Data associated with the intent response. |
| 744 Object _data; |
| 745 |
| 746 /* |
| 747 * Public constructor |
| 748 */ |
| 749 IntentResponse({ |
| 750 int intentId, |
| 751 bool success, |
| 752 Object data |
| 753 }) : |
| 754 _intentId = intentId, |
| 755 _success = success, |
| 756 _data = data |
| 757 ; |
| 758 |
| 759 /* |
| 760 * Private constructor |
| 761 */ |
| 762 IntentResponse._proxy(JSObject _jsObject) |
| 763 : super._proxy(_jsObject); |
| 764 |
| 765 /* |
| 766 * Serialisation method |
| 767 */ |
| 768 Map _toMap() { |
| 769 Map m = {}; |
| 770 if (intentId != null) m['intentId'] = intentId; |
| 771 if (success != null) m['success'] = success; |
| 772 if (data != null) m['data'] = data; |
| 773 return m; |
| 774 } |
| 775 |
| 776 /* |
| 777 * Public accessors |
| 778 */ |
| 779 int get intentId { |
| 780 if (!this._hasProxy()) |
| 781 return this._intentId; |
| 782 return JS('int', '#.intentId', this._jsObject); |
| 783 } |
| 784 |
| 785 void set intentId(int intentId) { |
| 786 if (!this._hasProxy()) |
| 787 this._intentId = intentId; |
| 788 else |
| 789 JS('void', '#.intentId = #', this._jsObject, convertArgument(intentId)); |
| 790 } |
| 791 |
| 792 bool get success { |
| 793 if (!this._hasProxy()) |
| 794 return this._success; |
| 795 return JS('bool', '#.success', this._jsObject); |
| 796 } |
| 797 |
| 798 void set success(bool success) { |
| 799 if (!this._hasProxy()) |
| 800 this._success = success; |
| 801 else |
| 802 JS('void', '#.success = #', this._jsObject, convertArgument(success)); |
| 803 } |
| 804 |
| 805 /* TODO(sashab): What's the best way to return generic JS objects? */ |
| 806 Object get data { |
| 807 if (!this._hasProxy()) |
| 808 return this._data; |
| 809 return convertNativeToDart_SerializedScriptValue(JS('Object', '#.data', this
._jsObject)); |
| 810 } |
| 811 |
| 812 /* TODO(sashab): What's the best way to serialize generic JS objects? */ |
| 813 void set data(var data) { |
| 814 if (!this._hasProxy()) |
| 815 this._data = data; |
| 816 else |
| 817 JS('void', '#.data = #', this._jsObject, convertArgument(data)); |
| 818 } |
| 819 } |
| 820 |
| 821 /** |
| 822 * Events |
| 823 */ |
| 824 |
| 825 // Fired at Chrome startup to apps that were running when Chrome last shut |
| 826 // down. |
| 827 class $Event_ChromeAppRuntimeOnRestarted extends $Event { |
| 828 /* |
| 829 * Override callback type definitions |
| 830 */ |
| 831 void addListener(void callback()) |
| 832 => super.addListener(callback); |
| 833 void removeListener(void callback()) |
| 834 => super.removeListener(callback); |
| 835 bool hasListener(void callback()) |
| 836 => super.hasListener(callback); |
| 837 |
| 838 /* |
| 839 * Constructor |
| 840 */ |
| 841 $Event_ChromeAppRuntimeOnRestarted(jsObject) : |
| 842 super._(jsObject, 0); |
| 843 } |
| 844 |
| 845 // Fired when an app is launched from the launcher or in response to a web |
| 846 // intent. |
| 847 class $Event_ChromeAppRuntimeOnLaunched extends $Event { |
| 848 /* |
| 849 * Override callback type definitions |
| 850 */ |
| 851 void addListener(void callback(LaunchData launchData)) |
| 852 => super.addListener(callback); |
| 853 void removeListener(void callback(LaunchData launchData)) |
| 854 => super.removeListener(callback); |
| 855 bool hasListener(void callback(LaunchData launchData)) |
| 856 => super.hasListener(callback); |
| 857 |
| 858 /* |
| 859 * Constructor |
| 860 */ |
| 861 $Event_ChromeAppRuntimeOnLaunched(jsObject) : |
| 862 super._(jsObject, 1); |
| 863 } |
| 864 |
| 865 /** |
| 866 * Functions |
| 867 */ |
| 868 class $API_ChromeAppRuntime { |
| 869 /* |
| 870 * API connection |
| 871 */ |
| 872 Object _jsObject; |
| 873 |
| 874 /* |
| 875 * Events |
| 876 */ |
| 877 $Event_ChromeAppRuntimeOnRestarted onRestarted; |
| 878 $Event_ChromeAppRuntimeOnLaunched onLaunched; |
| 879 |
| 880 /* |
| 881 * Functions |
| 882 */ |
| 883 void postIntentResponse(IntentResponse intentResponse) { |
| 884 JS('void', '#.postIntentResponse(#)', this._jsObject, convertArgument(intent
Response)); |
| 885 } |
| 886 |
| 887 /* |
| 888 * Constructor |
| 889 */ |
| 890 $API_ChromeAppRuntime(this._jsObject) { |
| 891 onRestarted = new $Event_ChromeAppRuntimeOnRestarted(JS('Object', '#.onResta
rted', this._jsObject)); |
| 892 onLaunched = new $Event_ChromeAppRuntimeOnLaunched(JS('Object', '#.onLaunche
d', this._jsObject)); |
| 893 } |
| 894 } |
| 895 |
| 896 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 897 // for details. All rights reserved. Use of this source code is governed by a |
| 898 // BSD-style license that can be found in the LICENSE file. |
| 899 |
| 900 // from app.window.idl |
| 901 |
| 902 /** |
| 903 * Types |
| 904 */ |
| 905 class CreateWindowOptions extends ChromeObject { |
| 906 // Id to identify the window. This will be used to remember the size |
| 907 // and position of the window and restore that geometry when a window |
| 908 // with the same id (and no explicit size or position) is later opened. |
| 909 String _id; |
| 910 |
| 911 // Default width of the window. (Deprecated; regular bounds act like this |
| 912 // now.) |
| 913 int _defaultWidth; |
| 914 |
| 915 // Default height of the window. (Deprecated; regular bounds act like this |
| 916 // now.) |
| 917 int _defaultHeight; |
| 918 |
| 919 // Default X coordinate of the window. (Deprecated; regular bounds act like |
| 920 // this now.) |
| 921 int _defaultLeft; |
| 922 |
| 923 // Default Y coordinate of the window. (Deprecated; regular bounds act like |
| 924 // this now.) |
| 925 int _defaultTop; |
| 926 |
| 927 // Width of the window. (Deprecated; use 'bounds'.) |
| 928 int _width; |
| 929 |
| 930 // Height of the window. (Deprecated; use 'bounds'.) |
| 931 int _height; |
| 932 |
| 933 // X coordinate of the window. (Deprecated; use 'bounds'.) |
| 934 int _left; |
| 935 |
| 936 // Y coordinate of the window. (Deprecated; use 'bounds'.) |
| 937 int _top; |
| 938 |
| 939 // Minimium width of the window. |
| 940 int _minWidth; |
| 941 |
| 942 // Minimum height of the window. |
| 943 int _minHeight; |
| 944 |
| 945 // Maximum width of the window. |
| 946 int _maxWidth; |
| 947 |
| 948 // Maximum height of the window. |
| 949 int _maxHeight; |
| 950 |
| 951 // Window type: 'shell' (the default) is the only currently supported value. |
| 952 String _type; |
| 953 |
| 954 // Frame type: 'none' or 'chrome' (defaults to 'chrome'). |
| 955 String _frame; |
| 956 |
| 957 // Size of the content in the window (excluding the titlebar). If specified |
| 958 // in addition to any of the left/top/width/height parameters, this field |
| 959 // takes precedence. If a frameBounds is specified, the frameBounds take |
| 960 // precedence. |
| 961 Bounds _bounds; |
| 962 |
| 963 // If true, the window will be created in a hidden state. Call show() on |
| 964 // the window to show it once it has been created. Defaults to false. |
| 965 bool _hidden; |
| 966 |
| 967 /* |
| 968 * Public constructor |
| 969 */ |
| 970 CreateWindowOptions({ |
| 971 String id, |
| 972 int defaultWidth, |
| 973 int defaultHeight, |
| 974 int defaultLeft, |
| 975 int defaultTop, |
| 976 int width, |
| 977 int height, |
| 978 int left, |
| 979 int top, |
| 980 int minWidth, |
| 981 int minHeight, |
| 982 int maxWidth, |
| 983 int maxHeight, |
| 984 String type, |
| 985 String frame, |
| 986 Bounds bounds, |
| 987 bool hidden |
| 988 }) : |
| 989 _id = id, |
| 990 _defaultWidth = defaultWidth, |
| 991 _defaultHeight = defaultHeight, |
| 992 _defaultLeft = defaultLeft, |
| 993 _defaultTop = defaultTop, |
| 994 _width = width, |
| 995 _height = height, |
| 996 _left = left, |
| 997 _top = top, |
| 998 _minWidth = minWidth, |
| 999 _minHeight = minHeight, |
| 1000 _maxWidth = maxWidth, |
| 1001 _maxHeight = maxHeight, |
| 1002 _type = type, |
| 1003 _frame = frame, |
| 1004 _bounds = bounds, |
| 1005 _hidden = hidden |
| 1006 ; |
| 1007 |
| 1008 /* |
| 1009 * Private constructor |
| 1010 */ |
| 1011 CreateWindowOptions._proxy(_jsObject) |
| 1012 : super._proxy(_jsObject); |
| 1013 |
| 1014 /* |
| 1015 * Serialisation method |
| 1016 */ |
| 1017 Map _toMap() { |
| 1018 Map m = {}; |
| 1019 if (id != null) m['id'] = id; |
| 1020 if (defaultWidth != null) m['defaultWidth'] = defaultWidth; |
| 1021 if (defaultHeight != null) m['defaultHeight'] = defaultHeight; |
| 1022 if (defaultLeft != null) m['defaultLeft'] = defaultLeft; |
| 1023 if (defaultTop != null) m['defaultTop'] = defaultTop; |
| 1024 if (width != null) m['width'] = width; |
| 1025 if (height != null) m['height'] = height; |
| 1026 if (left != null) m['left'] = left; |
| 1027 if (top != null) m['top'] = top; |
| 1028 if (minWidth != null) m['minWidth'] = minWidth; |
| 1029 if (minHeight != null) m['minHeight'] = minHeight; |
| 1030 if (maxWidth != null) m['maxWidth'] = maxWidth; |
| 1031 if (maxHeight != null) m['maxHeight'] = maxHeight; |
| 1032 if (type != null) m['type'] = type; |
| 1033 if (frame != null) m['frame'] = frame; |
| 1034 if (bounds != null) m['bounds'] = bounds; |
| 1035 if (hidden != null) m['hidden'] = hidden; |
| 1036 return m; |
| 1037 } |
| 1038 |
| 1039 /* |
| 1040 * Public accessors |
| 1041 */ |
| 1042 String get id { |
| 1043 if (!this._hasProxy()) |
| 1044 return this._id; |
| 1045 return JS('String', '#.id', this._jsObject); |
| 1046 } |
| 1047 |
| 1048 void set id(String id) { |
| 1049 if (!this._hasProxy()) |
| 1050 this._id = id; |
| 1051 else |
| 1052 JS('void', '#.id = #', this._jsObject, convertArgument(id)); |
| 1053 } |
| 1054 |
| 1055 int get defaultWidth { |
| 1056 if (!this._hasProxy()) |
| 1057 return this._defaultWidth; |
| 1058 return JS('int', '#.defaultWidth', this._jsObject); |
| 1059 } |
| 1060 |
| 1061 void set defaultWidth(int defaultWidth) { |
| 1062 if (!this._hasProxy()) |
| 1063 this._defaultWidth = defaultWidth; |
| 1064 else |
| 1065 JS('void', '#.defaultWidth = #', this._jsObject, convertArgument(defaultWi
dth)); |
| 1066 } |
| 1067 |
| 1068 int get defaultHeight { |
| 1069 if (!this._hasProxy()) |
| 1070 return this._defaultHeight; |
| 1071 return JS('int', '#.defaultHeight', this._jsObject); |
| 1072 } |
| 1073 |
| 1074 void set defaultHeight(int defaultHeight) { |
| 1075 if (!this._hasProxy()) |
| 1076 this._defaultHeight = defaultHeight; |
| 1077 else |
| 1078 JS('void', '#.defaultHeight = #', this._jsObject, convertArgument(defaultH
eight)); |
| 1079 } |
| 1080 |
| 1081 int get defaultLeft { |
| 1082 if (!this._hasProxy()) |
| 1083 return this._defaultLeft; |
| 1084 return JS('int', '#.defaultLeft', this._jsObject); |
| 1085 } |
| 1086 |
| 1087 void set defaultLeft(int defaultLeft) { |
| 1088 if (!this._hasProxy()) |
| 1089 this._defaultLeft = defaultLeft; |
| 1090 else |
| 1091 JS('void', '#.defaultLeft = #', this._jsObject, convertArgument(defaultLef
t)); |
| 1092 } |
| 1093 |
| 1094 int get defaultTop { |
| 1095 if (!this._hasProxy()) |
| 1096 return this._defaultTop; |
| 1097 return JS('int', '#.defaultTop', this._jsObject); |
| 1098 } |
| 1099 |
| 1100 void set defaultTop(int defaultTop) { |
| 1101 if (!this._hasProxy()) |
| 1102 this._defaultTop = defaultTop; |
| 1103 else |
| 1104 JS('void', '#.defaultTop = #', this._jsObject, convertArgument(defaultTop)
); |
| 1105 } |
| 1106 |
| 1107 int get width { |
| 1108 if (!this._hasProxy()) |
| 1109 return this._width; |
| 1110 return JS('int', '#.width', this._jsObject); |
| 1111 } |
| 1112 |
| 1113 void set width(int width) { |
| 1114 if (!this._hasProxy()) |
| 1115 this._width = width; |
| 1116 else |
| 1117 JS('void', '#.width = #', this._jsObject, convertArgument(width)); |
| 1118 } |
| 1119 |
| 1120 int get height { |
| 1121 if (!this._hasProxy()) |
| 1122 return this._height; |
| 1123 return JS('int', '#.height', this._jsObject); |
| 1124 } |
| 1125 |
| 1126 void set height(int height) { |
| 1127 if (!this._hasProxy()) |
| 1128 this._height = height; |
| 1129 else |
| 1130 JS('void', '#.height = #', this._jsObject, convertArgument(height)); |
| 1131 } |
| 1132 |
| 1133 int get left { |
| 1134 if (!this._hasProxy()) |
| 1135 return this._left; |
| 1136 return JS('int', '#.left', this._jsObject); |
| 1137 } |
| 1138 |
| 1139 void set left(int left) { |
| 1140 if (!this._hasProxy()) |
| 1141 this._left = left; |
| 1142 else |
| 1143 JS('void', '#.left = #', this._jsObject, convertArgument(left)); |
| 1144 } |
| 1145 |
| 1146 int get top { |
| 1147 if (!this._hasProxy()) |
| 1148 return this._top; |
| 1149 return JS('int', '#.top', this._jsObject); |
| 1150 } |
| 1151 |
| 1152 void set top(int top) { |
| 1153 if (!this._hasProxy()) |
| 1154 this._top = top; |
| 1155 else |
| 1156 JS('void', '#.top = #', this._jsObject, convertArgument(top)); |
| 1157 } |
| 1158 |
| 1159 int get minWidth { |
| 1160 if (!this._hasProxy()) |
| 1161 return this._minWidth; |
| 1162 return JS('int', '#.minWidth', this._jsObject); |
| 1163 } |
| 1164 |
| 1165 void set minWidth(int minWidth) { |
| 1166 if (!this._hasProxy()) |
| 1167 this._minWidth = minWidth; |
| 1168 else |
| 1169 JS('void', '#.minWidth = #', this._jsObject, convertArgument(minWidth)); |
| 1170 } |
| 1171 |
| 1172 int get minHeight { |
| 1173 if (!this._hasProxy()) |
| 1174 return this._minHeight; |
| 1175 return JS('int', '#.minHeight', this._jsObject); |
| 1176 } |
| 1177 |
| 1178 void set minHeight(int minHeight) { |
| 1179 if (!this._hasProxy()) |
| 1180 this._minHeight = minHeight; |
| 1181 else |
| 1182 JS('void', '#.minHeight = #', this._jsObject, convertArgument(minHeight)); |
| 1183 } |
| 1184 |
| 1185 int get maxWidth { |
| 1186 if (!this._hasProxy()) |
| 1187 return this._maxWidth; |
| 1188 return JS('int', '#.maxWidth', this._jsObject); |
| 1189 } |
| 1190 |
| 1191 void set maxWidth(int maxWidth) { |
| 1192 if (!this._hasProxy()) |
| 1193 this._maxWidth = maxWidth; |
| 1194 else |
| 1195 JS('void', '#.maxWidth = #', this._jsObject, convertArgument(maxWidth)); |
| 1196 } |
| 1197 |
| 1198 int get maxHeight { |
| 1199 if (!this._hasProxy()) |
| 1200 return this._maxHeight; |
| 1201 return JS('int', '#.maxHeight', this._jsObject); |
| 1202 } |
| 1203 |
| 1204 void set maxHeight(int maxHeight) { |
| 1205 if (!this._hasProxy()) |
| 1206 this._maxHeight = maxHeight; |
| 1207 else |
| 1208 JS('void', '#.maxHeight = #', this._jsObject, convertArgument(maxHeight)); |
| 1209 } |
| 1210 |
| 1211 String get type { |
| 1212 if (!this._hasProxy()) |
| 1213 return this._type; |
| 1214 return JS('String', '#.type', this._jsObject); |
| 1215 } |
| 1216 |
| 1217 void set type(String type) { |
| 1218 if (!this._hasProxy()) |
| 1219 this._type = type; |
| 1220 else |
| 1221 JS('void', '#.type = #', this._jsObject, convertArgument(type)); |
| 1222 } |
| 1223 |
| 1224 String get frame { |
| 1225 if (!this._hasProxy()) |
| 1226 return this._frame; |
| 1227 return JS('String', '#.frame', this._jsObject); |
| 1228 } |
| 1229 |
| 1230 void set frame(String frame) { |
| 1231 if (!this._hasProxy()) |
| 1232 this._frame = frame; |
| 1233 else |
| 1234 JS('void', '#.frame = #', this._jsObject, convertArgument(frame)); |
| 1235 } |
| 1236 |
| 1237 Bounds get bounds { |
| 1238 if (!this._hasProxy()) |
| 1239 return this._bounds; |
| 1240 return new Bounds._proxy(JS('Bounds', '#.bounds', this._jsObject)); |
| 1241 } |
| 1242 |
| 1243 void set bounds(Bounds bounds) { |
| 1244 if (!this._hasProxy()) |
| 1245 this._bounds = bounds; |
| 1246 else |
| 1247 JS('void', '#.bounds = #', this._jsObject, convertArgument(bounds)); |
| 1248 } |
| 1249 |
| 1250 bool get hidden { |
| 1251 if (!this._hasProxy()) |
| 1252 return this._hidden; |
| 1253 return JS('String', '#.hidden', this._jsObject); |
| 1254 } |
| 1255 |
| 1256 void set hidden(bool hidden) { |
| 1257 if (!this._hasProxy()) |
| 1258 this._hidden = hidden; |
| 1259 else |
| 1260 JS('void', '#.hidden = #', this._jsObject, convertArgument(hidden)); |
| 1261 } |
| 1262 } |
| 1263 |
| 1264 class Bounds extends ChromeObject { |
| 1265 int _left; |
| 1266 int _top; |
| 1267 int _width; |
| 1268 int _height; |
| 1269 |
| 1270 /* |
| 1271 * Public constructor |
| 1272 */ |
| 1273 Bounds({ |
| 1274 int left, |
| 1275 int top, |
| 1276 int width, |
| 1277 int height |
| 1278 }) : |
| 1279 _left = left, |
| 1280 _top = top, |
| 1281 _width = width, |
| 1282 _height = height |
| 1283 ; |
| 1284 |
| 1285 |
| 1286 /* |
| 1287 * Private constructor |
| 1288 */ |
| 1289 Bounds._proxy(_jsObject) |
| 1290 : super._proxy(_jsObject); |
| 1291 |
| 1292 /* |
| 1293 * Serialisation method |
| 1294 */ |
| 1295 Map _toMap() { |
| 1296 Map m = {}; |
| 1297 if (left != null) m['left'] = left; |
| 1298 if (top != null) m['top'] = top; |
| 1299 if (width != null) m['width'] = width; |
| 1300 if (height != null) m['height'] = height; |
| 1301 return m; |
| 1302 } |
| 1303 |
| 1304 /* |
| 1305 * Public accessors |
| 1306 */ |
| 1307 int get width { |
| 1308 if (!this._hasProxy()) |
| 1309 return this._width; |
| 1310 return JS('int', '#.width', this._jsObject); |
| 1311 } |
| 1312 |
| 1313 void set width(int width) { |
| 1314 if (!this._hasProxy()) |
| 1315 this._width = width; |
| 1316 else |
| 1317 JS('void', '#.width = #', this._jsObject, convertArgument(width)); |
| 1318 } |
| 1319 |
| 1320 int get height { |
| 1321 if (!this._hasProxy()) |
| 1322 return this._height; |
| 1323 return JS('int', '#.height', this._jsObject); |
| 1324 } |
| 1325 |
| 1326 void set height(int height) { |
| 1327 if (!this._hasProxy()) |
| 1328 this._height = height; |
| 1329 else |
| 1330 JS('void', '#.height = #', this._jsObject, convertArgument(height)); |
| 1331 } |
| 1332 |
| 1333 int get left { |
| 1334 if (!this._hasProxy()) |
| 1335 return this._left; |
| 1336 return JS('int', '#.left', this._jsObject); |
| 1337 } |
| 1338 |
| 1339 void set left(int left) { |
| 1340 if (!this._hasProxy()) |
| 1341 this._left = left; |
| 1342 else |
| 1343 JS('void', '#.left = #', this._jsObject, convertArgument(left)); |
| 1344 } |
| 1345 |
| 1346 int get top { |
| 1347 if (!this._hasProxy()) |
| 1348 return this._top; |
| 1349 return JS('int', '#.top', this._jsObject); |
| 1350 } |
| 1351 |
| 1352 void set top(int top) { |
| 1353 if (!this._hasProxy()) |
| 1354 this._top = top; |
| 1355 else |
| 1356 JS('void', '#.top = #', this._jsObject, convertArgument(top)); |
| 1357 } |
| 1358 } |
| 1359 |
| 1360 class AppWindow extends ChromeObject { |
| 1361 /* |
| 1362 * Public constructor |
| 1363 * TODO(sashab): Does it make sense to be able to create a new AppWindow this
way? |
| 1364 */ |
| 1365 //AppWindow(); |
| 1366 |
| 1367 /* |
| 1368 * Private constructor |
| 1369 */ |
| 1370 AppWindow._proxy(jsObject) |
| 1371 : super._proxy(jsObject); |
| 1372 |
| 1373 /* |
| 1374 * Serialisation method |
| 1375 */ |
| 1376 Map _toMap() { |
| 1377 return {}; |
| 1378 } |
| 1379 |
| 1380 /* |
| 1381 * Public accessors |
| 1382 */ |
| 1383 // The JavaScript 'window' object for the created child. |
| 1384 // TODO(sashab, sra): Detect whether this is the current window, or an |
| 1385 // external one, and return an appropriately-typed object |
| 1386 WindowBase get contentWindow { |
| 1387 return JS("Window", "#.contentWindow", this._jsObject); |
| 1388 } |
| 1389 |
| 1390 /* |
| 1391 * Functions |
| 1392 */ |
| 1393 |
| 1394 // Focus the window. |
| 1395 void focus() => |
| 1396 JS("void", "#.focus()", this._jsObject); |
| 1397 |
| 1398 // Minimize the window. |
| 1399 void minimize() => |
| 1400 JS("void", "#.minimize()", this._jsObject); |
| 1401 |
| 1402 // Is the window minimized? |
| 1403 bool isMinimized() => |
| 1404 JS("bool", "#.isMinimized()", this._jsObject); |
| 1405 |
| 1406 // Maximize the window. |
| 1407 void maximize() => |
| 1408 JS("void", "#.maximize()", this._jsObject); |
| 1409 |
| 1410 // Is the window maximized? |
| 1411 bool isMaximized() => |
| 1412 JS("bool", "c#.isMaximized()", this._jsObject); |
| 1413 |
| 1414 // Restore the window. |
| 1415 void restore() => |
| 1416 JS("void", "#.restore()", this._jsObject); |
| 1417 |
| 1418 // Move the window to the position (|left|, |top|). |
| 1419 void moveTo(int left, int top) => |
| 1420 JS("void", "#.moveTo(#, #)", this._jsObject, left, top); |
| 1421 |
| 1422 // Resize the window to |width|x|height| pixels in size. |
| 1423 void resizeTo(int width, int height) => |
| 1424 JS("void", "#.resizeTo(#, #)", this._jsObject, width, height); |
| 1425 |
| 1426 // Draw attention to the window. |
| 1427 void drawAttention() => |
| 1428 JS("void", "#.drawAttention()", this._jsObject); |
| 1429 |
| 1430 // Clear attention to the window. |
| 1431 void clearAttention() => |
| 1432 JS("void", "#.clearAttention()", this._jsObject); |
| 1433 |
| 1434 // Close the window. |
| 1435 void close() => |
| 1436 JS("void", "#.close()", this._jsObject); |
| 1437 |
| 1438 // Show the window. Does nothing if the window is already visible. |
| 1439 void show() => |
| 1440 JS("void", "#.show()", this._jsObject); |
| 1441 |
| 1442 // Hide the window. Does nothing if the window is already hidden. |
| 1443 void hide() => |
| 1444 JS("void", "#.hide()", this._jsObject); |
| 1445 |
| 1446 // Set the window's bounds. |
| 1447 void setBounds(Bounds bounds) => |
| 1448 JS("void", "#.setBounds(#)", this._jsObject, convertArgument(bounds)); |
| 1449 |
| 1450 } |
| 1451 |
| 1452 /** |
| 1453 * Functions |
| 1454 */ |
| 1455 class $API_ChromeAppWindow { |
| 1456 /** |
| 1457 * JS object |
| 1458 */ |
| 1459 Object _jsObject; |
| 1460 |
| 1461 /** |
| 1462 * Constructor |
| 1463 */ |
| 1464 $API_ChromeAppWindow(this._jsObject); |
| 1465 |
| 1466 /** |
| 1467 * Functions |
| 1468 */ |
| 1469 |
| 1470 // Returns an <a href="#type-AppWindow">AppWindow</a> object for the |
| 1471 // current script context (ie JavaScript 'window' object). This can also be |
| 1472 // called on a handle to a script context for another page, for example: |
| 1473 // otherWindow.chrome.app.window.current(). |
| 1474 AppWindow current() => |
| 1475 new AppWindow._proxy(JS("Object", "#.current()", this._jsObject)); |
| 1476 |
| 1477 // The size and position of a window can be specified in a number of |
| 1478 // different ways. The most simple option is not specifying anything at |
| 1479 // all, in which case a default size and platform dependent position will |
| 1480 // be used. |
| 1481 // |
| 1482 // Another option is to use the top/left and width/height properties, |
| 1483 // which will always put the window at the specified coordinates with the |
| 1484 // specified size. |
| 1485 // |
| 1486 // Yet another option is to give the window a (unique) id. This id is then |
| 1487 // used to remember the size and position of the window whenever it is |
| 1488 // moved or resized. This size and position is then used instead of the |
| 1489 // specified bounds on subsequent opening of a window with the same id. If |
| 1490 // you need to open a window with an id at a location other than the |
| 1491 // remembered default, you can create it hidden, move it to the desired |
| 1492 // location, then show it. |
| 1493 // |
| 1494 // You can also combine these various options, explicitly specifying for |
| 1495 // example the size while having the position be remembered or other |
| 1496 // combinations like that. Size and position are dealt with seperately, |
| 1497 // but individual coordinates are not. So if you specify a top (or left) |
| 1498 // coordinate, you should also specify a left (or top) coordinate, and |
| 1499 // similar for size. |
| 1500 // |
| 1501 // If you specify both a regular and a default value for the same option |
| 1502 // the regular value is the only one that takes effect. |
| 1503 void create(String url, [ CreateWindowOptions options, void callback(AppWindow
created_window) ]) { |
| 1504 void __proxy_callback(Object created_window) { |
| 1505 if (?callback) |
| 1506 callback(new AppWindow._proxy(created_window)); |
| 33 } | 1507 } |
| 34 var app = JS('', '#.app', chrome); | 1508 |
| 35 if (app == null) { | 1509 JS("void", "#.create(#, #, #)", |
| 36 throw new UnsupportedError('Not supported by current browser'); | 1510 this._jsObject, |
| 37 } | 1511 url, |
| 38 var window = JS('', '#.window', app); | 1512 convertArgument(options), |
| 39 if (app == null) { | 1513 convertDartClosureToJS(__proxy_callback, 1) |
| 40 throw new UnsupportedError('Not supported by current browser'); | 1514 ); |
| 41 } | 1515 } |
| 42 JS('void', '#.create(#)', window, url); | 1516 } |
| 43 } | |
| 44 } | |
| 45 | |
| 46 final app = new AppModule._(); | |
| OLD | NEW |