| 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 class Utils { | 5 _dom_window() native "Utils_window"; |
| 6 static List convertToList(List list) { | 6 |
| 7 // FIXME: [possible optimization]: do not copy the array if Dart_IsArray is
fine w/ it. | 7 // This API is exploratory. |
| 8 final length = list.length; | 8 spawnDomIsolate(Window targetWindowWrapped, String entryPoint) { |
| 9 List result = new List(length); | 9 final targetWindow = _unwrap(targetWindowWrapped); |
| 10 result.copyFrom(list, 0, 0, length); | 10 if (targetWindow is! _DOMWindowDOMImpl && targetWindow is! _DOMWindowCrossFram
eDOMImpl) { |
| 11 return result; | 11 throw 'Bad window argument: $targetWindow'; |
| 12 } | 12 } |
| 13 | 13 final result = new Completer<SendPort>(); |
| 14 static List convertMapToList(Map map) { | 14 final port = _spawnDomIsolateImpl(targetWindow, entryPoint); |
| 15 List result = []; | 15 window.setTimeout(() { result.complete(port); }, 0); |
| 16 map.forEach((k, v) => result.addAll([k, v])); | 16 return result.future; |
| 17 return result; | |
| 18 } | |
| 19 | |
| 20 static void populateMap(Map result, List list) { | |
| 21 for (int i = 0; i < list.length; i += 2) { | |
| 22 result[list[i]] = list[i + 1]; | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 static bool isMap(obj) => obj is Map; | |
| 27 | |
| 28 static Map createMap() => {}; | |
| 29 | |
| 30 static makeNotImplementedException(String fileName, int lineNo) { | |
| 31 return new UnsupportedOperationException('[info: $fileName:$lineNo]'); | |
| 32 } | |
| 33 | |
| 34 static window() native "Utils_window"; | |
| 35 static print(String message) native "Utils_print"; | |
| 36 static SendPort spawnDomIsolate(Window window, String entryPoint) native "Util
s_spawnDomIsolate"; | |
| 37 } | 17 } |
| 38 | 18 |
| 39 /* | 19 SendPort _spawnDomIsolateImpl(_DOMWindow window, String entryPoint) native "Util
s_spawnDomIsolate"; |
| 40 * [NPObjectBase] is native wrapper class injected from embedder's code. | 20 |
| 41 */ | 21 // layoutTestController implementation. |
| 42 class NPObject extends DOMWrapperBase { | 22 // FIXME: provide a separate lib for layoutTestController. |
| 43 static NPObject retrieve(String key) native "NPObject_retrieve"; | 23 |
| 24 var _layoutTestController; |
| 25 |
| 26 LayoutTestController get layoutTestController() { |
| 27 if (_layoutTestController === null) |
| 28 _layoutTestController = new LayoutTestController._(_NPObject.retrieve("layou
tTestController")); |
| 29 return _layoutTestController; |
| 30 } |
| 31 |
| 32 class LayoutTestController { |
| 33 final _NPObject _npObject; |
| 34 |
| 35 LayoutTestController._(this._npObject); |
| 36 |
| 37 display() => _npObject.invoke('display'); |
| 38 dumpAsText() => _npObject.invoke('dumpAsText'); |
| 39 notifyDone() => _npObject.invoke('notifyDone'); |
| 40 setCanOpenWindows() => _npObject.invoke('setCanOpenWindows'); |
| 41 waitUntilDone() => _npObject.invoke('waitUntilDone'); |
| 42 } |
| 43 |
| 44 class _NPObject extends _DOMWrapperBase { |
| 45 static _NPObject retrieve(String key) native "NPObject_retrieve"; |
| 44 property(String propertyName) native "NPObject_property"; | 46 property(String propertyName) native "NPObject_property"; |
| 45 invoke(String methodName, [ObjectArray args = null]) native "NPObject_invoke"; | 47 invoke(String methodName, [ObjectArray args = null]) native "NPObject_invoke"; |
| 46 | 48 |
| 47 static _createNPObject() => new NPObject._createNPObject(); | 49 _NPObject._createNPObject(); |
| 48 NPObject._createNPObject(); | |
| 49 } | 50 } |
| 50 | 51 |
| 51 class DOMWindowCrossFrameImplementation extends DOMWrapperBase implements DOMWin
dow { | 52 _create_NPObject() => new _NPObject._createNPObject(); |
| 53 |
| 54 List _Utils_convertToList(List list) { |
| 55 // FIXME: [possible optimization]: do not copy the array if Dart_IsArray is fi
ne w/ it. |
| 56 final length = list.length; |
| 57 List result = new List(length); |
| 58 result.copyFrom(list, 0, 0, length); |
| 59 return result; |
| 60 } |
| 61 |
| 62 List _Utils_convertMapToList(Map map) { |
| 63 List result = []; |
| 64 map.forEach((k, v) => result.addAll([k, v])); |
| 65 return result; |
| 66 } |
| 67 |
| 68 _Utils_populateMap(Map result, List list) { |
| 69 for (int i = 0; i < list.length; i += 2) { |
| 70 result[list[i]] = list[i + 1]; |
| 71 } |
| 72 } |
| 73 |
| 74 bool _Utils_isMap(obj) => obj is Map; |
| 75 |
| 76 Map _Utils_createMap() => {}; |
| 77 |
| 78 _Utils_makeNotImplementedException(String fileName, int lineNo) { |
| 79 return new UnsupportedOperationException('[info: $fileName:$lineNo]'); |
| 80 } |
| 81 |
| 82 Utils_print(String message) native "Utils_print"; |
| 83 |
| 84 class _DOMWindowCrossFrameDOMImpl extends _DOMWrapperBase implements _DOMWindow
{ |
| 52 // Fields. | 85 // Fields. |
| 53 History get history() native "DOMWindow_history_cross_frame_Getter"; | 86 History get history() native "DOMWindow_history_cross_frame_Getter"; |
| 54 Location get location() native "DOMWindow_location_cross_frame_Getter"; | 87 Location get location() native "DOMWindow_location_cross_frame_Getter"; |
| 55 bool get closed() native "DOMWindow_closed_Getter"; | 88 bool get closed() native "DOMWindow_closed_Getter"; |
| 56 int get length() native "DOMWindow_length_Getter"; | 89 int get length() native "DOMWindow_length_Getter"; |
| 57 DOMWindow get opener() native "DOMWindow_opener_Getter"; | 90 DOMWindow get opener() native "DOMWindow_opener_Getter"; |
| 58 DOMWindow get parent() native "DOMWindow_parent_Getter"; | 91 DOMWindow get parent() native "DOMWindow_parent_Getter"; |
| 59 DOMWindow get top() native "DOMWindow_top_Getter"; | 92 DOMWindow get top() native "DOMWindow_top_Getter"; |
| 60 | 93 |
| 61 // Methods. | 94 // Methods. |
| 62 void focus() native "DOMWindow_focus_Callback"; | 95 void focus() native "DOMWindow_focus_Callback"; |
| 63 void blur() native "DOMWindow_blur_Callback"; | 96 void blur() native "DOMWindow_blur_Callback"; |
| 64 void close() native "DOMWindow_close_Callback"; | 97 void close() native "DOMWindow_close_Callback"; |
| 65 void postMessage(/*SerializedScriptValue*/ message, String targetOrigin, [List
messagePorts]) native "DOMWindow_postMessage_Callback"; | 98 void postMessage(/*SerializedScriptValue*/ message, String targetOrigin, [List
messagePorts]) native "DOMWindow_postMessage_Callback"; |
| 66 | 99 |
| 67 // Implementation support. | 100 // Implementation support. |
| 68 static DOMWindowCrossFrameImplementation _createDOMWindowCrossFrameImplementat
ion() => new DOMWindowCrossFrameImplementation._createDOMWindowCrossFrameImpleme
ntation(); | 101 _DOMWindowCrossFrameDOMImpl._create_DOMWindowCrossFrameDOMImpl(); |
| 69 DOMWindowCrossFrameImplementation._createDOMWindowCrossFrameImplementation(); | |
| 70 | |
| 71 String get typeName() => "DOMWindow"; | 102 String get typeName() => "DOMWindow"; |
| 72 } | 103 } |
| 73 | 104 |
| 74 class HistoryCrossFrameImplementation extends DOMWrapperBase implements History
{ | 105 _create_DOMWindowCrossFrameDOMImpl() => new _DOMWindowCrossFrameDOMImpl._create_
DOMWindowCrossFrameDOMImpl(); |
| 106 |
| 107 class _HistoryCrossFrameDOMImpl extends _DOMWrapperBase implements _History { |
| 75 // Methods. | 108 // Methods. |
| 76 void back() native "History_back_Callback"; | 109 void back() native "History_back_Callback"; |
| 77 void forward() native "History_forward_Callback"; | 110 void forward() native "History_forward_Callback"; |
| 78 void go(int distance) native "History_go_Callback"; | 111 void go(int distance) native "History_go_Callback"; |
| 79 | 112 |
| 80 // Implementation support. | 113 // Implementation support. |
| 81 static HistoryCrossFrameImplementation _createHistoryCrossFrameImplementation(
) => new HistoryCrossFrameImplementation._createHistoryCrossFrameImplementation(
); | 114 _HistoryCrossFrameDOMImpl._create_HistoryCrossFrameDOMImpl(); |
| 82 HistoryCrossFrameImplementation._createHistoryCrossFrameImplementation(); | |
| 83 | |
| 84 String get typeName() => "History"; | 115 String get typeName() => "History"; |
| 85 } | 116 } |
| 86 | 117 |
| 87 class LocationCrossFrameImplementation extends DOMWrapperBase implements Locatio
n { | 118 _create_HistoryCrossFrameDOMImpl() => new _HistoryCrossFrameDOMImpl._create_Hist
oryCrossFrameDOMImpl(); |
| 119 |
| 120 class _LocationCrossFrameDOMImpl extends _DOMWrapperBase implements _Location { |
| 88 // Fields. | 121 // Fields. |
| 89 void set href(String) native "Location_href_Setter"; | 122 void set href(String) native "Location_href_Setter"; |
| 90 | 123 |
| 91 // Implementation support. | 124 // Implementation support. |
| 92 static LocationCrossFrameImplementation _createLocationCrossFrameImplementatio
n() => new LocationCrossFrameImplementation._createLocationCrossFrameImplementat
ion(); | 125 _LocationCrossFrameDOMImpl._create_LocationCrossFrameDOMImpl(); |
| 93 LocationCrossFrameImplementation._createLocationCrossFrameImplementation(); | |
| 94 | |
| 95 String get typeName() => "Location"; | 126 String get typeName() => "Location"; |
| 96 } | 127 } |
| 97 | 128 |
| 98 class DOMStringMapImplementation extends DOMWrapperBase implements DOMStringMap
{ | 129 _create_LocationCrossFrameDOMImpl() => new _LocationCrossFrameDOMImpl._create_Lo
cationCrossFrameDOMImpl(); |
| 99 static DOMStringMapImplementation _createDOMStringMapImplementation() => new D
OMStringMapImplementation._createDOMStringMapImplementation(); | |
| 100 DOMStringMapImplementation._createDOMStringMapImplementation(); | |
| 101 | |
| 102 bool containsValue(String value) => Maps.containsValue(this, value); | |
| 103 bool containsKey(String key) native "DOMStringMap_containsKey_Callback"; | |
| 104 String operator [](String key) native "DOMStringMap_item_Callback"; | |
| 105 void operator []=(String key, String value) native "DOMStringMap_setItem_Callb
ack"; | |
| 106 String putIfAbsent(String key, String ifAbsent()) => Maps.putIfAbsent(this, ke
y, ifAbsent); | |
| 107 String remove(String key) native "DOMStringMap_remove_Callback"; | |
| 108 void clear() => Maps.clear(this); | |
| 109 void forEach(void f(String key, String value)) => Maps.forEach(this, f); | |
| 110 Collection<String> getKeys() native "DOMStringMap_getKeys_Callback"; | |
| 111 Collection<String> getValues() => Maps.getValues(this); | |
| 112 int get length() => Maps.length(this); | |
| 113 bool isEmpty() => Maps.isEmpty(this); | |
| 114 } | |
| OLD | NEW |