| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 7 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 8 /** | 8 /** |
| 9 * Checks to see if Indexed DB is supported on the current platform. | 9 * Checks to see if Indexed DB is supported on the current platform. |
| 10 */ | 10 */ |
| 11 static bool get supported { | 11 static bool get supported { |
| 12 $if DARTIUM | 12 $if DARTIUM |
| 13 return true; | 13 return true; |
| 14 $else | 14 $else |
| 15 return JS('bool', | 15 return JS('bool', |
| 16 '!!(window.indexedDB || ' | 16 '!!(window.indexedDB || ' |
| 17 'window.webkitIndexedDB || ' | 17 'window.webkitIndexedDB || ' |
| 18 'window.mozIndexedDB)'); | 18 'window.mozIndexedDB)'); |
| 19 $endif | 19 $endif |
| 20 } | 20 } |
| 21 | 21 |
| 22 @DomName('IDBFactory.open') | 22 @DomName('IDBFactory.open') |
| 23 Future<Database> open(String name, | 23 Future<Database> open(String name, |
| 24 {int version, void onUpgradeNeeded(VersionChangeEvent), | 24 {int version, void onUpgradeNeeded(VersionChangeEvent), |
| 25 void onBlocked(Event)}) { | 25 void onBlocked(Event)}) { |
| 26 if ((version == null) != (onUpgradeNeeded == null)) { | 26 if ((version == null) != (onUpgradeNeeded == null)) { |
| 27 return new Future.immediateError(new ArgumentError( | 27 return new Future.error(new ArgumentError( |
| 28 'version and onUpgradeNeeded must be specified together')); | 28 'version and onUpgradeNeeded must be specified together')); |
| 29 } | 29 } |
| 30 try { | 30 try { |
| 31 var request; | 31 var request; |
| 32 if (version != null) { | 32 if (version != null) { |
| 33 request = $dom_open(name, version); | 33 request = $dom_open(name, version); |
| 34 } else { | 34 } else { |
| 35 request = $dom_open(name); | 35 request = $dom_open(name); |
| 36 } | 36 } |
| 37 | 37 |
| 38 if (onUpgradeNeeded != null) { | 38 if (onUpgradeNeeded != null) { |
| 39 request.onUpgradeNeeded.listen(onUpgradeNeeded); | 39 request.onUpgradeNeeded.listen(onUpgradeNeeded); |
| 40 } | 40 } |
| 41 if (onBlocked != null) { | 41 if (onBlocked != null) { |
| 42 request.onBlocked.listen(onBlocked); | 42 request.onBlocked.listen(onBlocked); |
| 43 } | 43 } |
| 44 return _completeRequest(request); | 44 return _completeRequest(request); |
| 45 } catch (e, stacktrace) { | 45 } catch (e, stacktrace) { |
| 46 return new Future.immediateError(e, stacktrace); | 46 return new Future.error(e, stacktrace); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 @DomName('IDBFactory.deleteDatabase') | 50 @DomName('IDBFactory.deleteDatabase') |
| 51 Future<IdbFactory> deleteDatabase(String name, | 51 Future<IdbFactory> deleteDatabase(String name, |
| 52 {void onBlocked(Event)}) { | 52 {void onBlocked(Event)}) { |
| 53 try { | 53 try { |
| 54 var request = $dom_deleteDatabase(name); | 54 var request = $dom_deleteDatabase(name); |
| 55 | 55 |
| 56 if (onBlocked != null) { | 56 if (onBlocked != null) { |
| 57 request.onBlocked.listen(onBlocked); | 57 request.onBlocked.listen(onBlocked); |
| 58 } | 58 } |
| 59 return _completeRequest(request); | 59 return _completeRequest(request); |
| 60 } catch (e, stacktrace) { | 60 } catch (e, stacktrace) { |
| 61 return new Future.immediateError(e, stacktrace); | 61 return new Future.error(e, stacktrace); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 @DomName('IDBFactory.getDatabaseNames') | 65 @DomName('IDBFactory.getDatabaseNames') |
| 66 @SupportedBrowser(SupportedBrowser.CHROME) | 66 @SupportedBrowser(SupportedBrowser.CHROME) |
| 67 @Experimental | 67 @Experimental |
| 68 Future<List<String>> getDatabaseNames() { | 68 Future<List<String>> getDatabaseNames() { |
| 69 try { | 69 try { |
| 70 var request = $dom_webkitGetDatabaseNames(); | 70 var request = $dom_webkitGetDatabaseNames(); |
| 71 | 71 |
| 72 return _completeRequest(request); | 72 return _completeRequest(request); |
| 73 } catch (e, stacktrace) { | 73 } catch (e, stacktrace) { |
| 74 return new Future.immediateError(e, stacktrace); | 74 return new Future.error(e, stacktrace); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * Checks to see if getDatabaseNames is supported by the current platform. | 79 * Checks to see if getDatabaseNames is supported by the current platform. |
| 80 */ | 80 */ |
| 81 bool get supportsDatabaseNames { | 81 bool get supportsDatabaseNames { |
| 82 $if DART2JS | 82 $if DART2JS |
| 83 return supported && JS('bool', | 83 return supported && JS('bool', |
| 84 '!!(#.getDatabaseNames || #.webkitGetDatabaseNames)', this, this); | 84 '!!(#.getDatabaseNames || #.webkitGetDatabaseNames)', this, this); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 100 // TODO: make sure that completer.complete is synchronous as transactions | 100 // TODO: make sure that completer.complete is synchronous as transactions |
| 101 // may be committed if the result is not processed immediately. | 101 // may be committed if the result is not processed immediately. |
| 102 request.onSuccess.listen((e) { | 102 request.onSuccess.listen((e) { |
| 103 completer.complete(request.result); | 103 completer.complete(request.result); |
| 104 }); | 104 }); |
| 105 request.onError.listen((e) { | 105 request.onError.listen((e) { |
| 106 completer.completeError(e); | 106 completer.completeError(e); |
| 107 }); | 107 }); |
| 108 return completer.future; | 108 return completer.future; |
| 109 } | 109 } |
| OLD | NEW |