Chromium Code Reviews| 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 html; | 5 part of html; |
| 6 | 6 |
| 7 class _Property { | 7 class _Property { |
| 8 _Property(this.name) : | 8 _Property(this.name) : |
| 9 _hasValue = false, | 9 _hasValue = false, |
| 10 writable = false, | 10 writable = false, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 static DateTime doubleToDateTime(double dateTime) { | 117 static DateTime doubleToDateTime(double dateTime) { |
| 118 try { | 118 try { |
| 119 return new DateTime.fromMillisecondsSinceEpoch(dateTime.toInt()); | 119 return new DateTime.fromMillisecondsSinceEpoch(dateTime.toInt()); |
| 120 } catch(_) { | 120 } catch(_) { |
| 121 // TODO(antonnm): treat exceptions properly in bindings and | 121 // TODO(antonnm): treat exceptions properly in bindings and |
| 122 // find out how to treat NaNs. | 122 // find out how to treat NaNs. |
| 123 return null; | 123 return null; |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 static maybeUnwrapJso(obj) => unwrap_jso(obj); | |
| 128 | |
| 129 static List convertToList(List list) { | 127 static List convertToList(List list) { |
| 130 // FIXME: [possible optimization]: do not copy the array if Dart_IsArray is fine w/ it. | 128 // FIXME: [possible optimization]: do not copy the array if Dart_IsArray is fine w/ it. |
| 131 final length = list.length; | 129 final length = list.length; |
| 132 List result = new List(length); | 130 List result = new List(length); |
| 133 result.setRange(0, length, list); | 131 result.setRange(0, length, list); |
| 134 return result; | 132 return result; |
| 135 } | 133 } |
| 136 | 134 |
| 137 static List convertMapToList(Map map) { | 135 static List convertMapToList(Map map) { |
| 138 List result = []; | 136 List result = []; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 } | 180 } |
| 183 | 181 |
| 184 static Element getAndValidateNativeType(Type type, String tagName) { | 182 static Element getAndValidateNativeType(Type type, String tagName) { |
| 185 var element = new Element.tag(tagName); | 183 var element = new Element.tag(tagName); |
| 186 if (!isTypeSubclassOf(type, element.runtimeType)) { | 184 if (!isTypeSubclassOf(type, element.runtimeType)) { |
| 187 return null; | 185 return null; |
| 188 } | 186 } |
| 189 return element; | 187 return element; |
| 190 } | 188 } |
| 191 | 189 |
| 192 static window() => wrap_jso(js.context['window']); | |
| 193 | |
| 194 static forwardingPrint(String message) => _blink.Blink_Utils.forwardingPrint(m essage); | 190 static forwardingPrint(String message) => _blink.Blink_Utils.forwardingPrint(m essage); |
| 195 static void spawnDomHelper(Function f, int replyTo) => | 191 static void spawnDomHelper(Function f, int replyTo) => |
| 196 _blink.Blink_Utils.spawnDomHelper(f, replyTo); | 192 _blink.Blink_Utils.spawnDomHelper(f, replyTo); |
| 197 | 193 |
| 198 // TODO(vsm): Make this API compatible with spawnUri. It should also | 194 // TODO(vsm): Make this API compatible with spawnUri. It should also |
| 199 // return a Future<Isolate>. | 195 // return a Future<Isolate>. |
| 200 static spawnDomUri(String uri) => wrap_jso(_blink.Blink_Utils.spawnDomUri(uri) ); | 196 // TODO(jacobr): IS THIS RIGHT? I worry we have broken conversion from Promise to Future. |
| 197 static spawnDomUri(String uri) => _blink.Blink_Utils.spawnDomUri(uri); | |
| 201 | 198 |
| 202 // The following methods were added for debugger integration to make working | 199 // The following methods were added for debugger integration to make working |
| 203 // with the Dart C mirrors API simpler. | 200 // with the Dart C mirrors API simpler. |
| 204 // TODO(jacobr): consider moving them to a separate library. | 201 // TODO(jacobr): consider moving them to a separate library. |
| 205 // If Dart supported dynamic code injection, we would only inject this code | 202 // If Dart supported dynamic code injection, we would only inject this code |
| 206 // when the debugger is invoked. | 203 // when the debugger is invoked. |
| 207 | 204 |
| 208 /** | 205 /** |
| 209 * Strips the private secret prefix from member names of the form | 206 * Strips the private secret prefix from member names of the form |
| 210 * someName@hash. | 207 * someName@hash. |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 } | 764 } |
| 768 | 765 |
| 769 /** | 766 /** |
| 770 * Helper to wrap the inspect method on InjectedScriptHost to provide the | 767 * Helper to wrap the inspect method on InjectedScriptHost to provide the |
| 771 * inspect method required for the | 768 * inspect method required for the |
| 772 */ | 769 */ |
| 773 static List consoleApi(host) { | 770 static List consoleApi(host) { |
| 774 return [ | 771 return [ |
| 775 "inspect", | 772 "inspect", |
| 776 (o) { | 773 (o) { |
| 777 host.callMethod("_inspect", [unwrap_jso(o)]); | 774 js.JsNative.callMethod(host, "_inspect", [o]); |
| 778 return o; | 775 return o; |
| 779 }, | 776 }, |
| 780 "dir", | 777 "dir", |
| 781 window().console.dir, | 778 window.console.dir, |
| 782 "dirxml", | 779 "dirxml", |
| 783 window().console.dirxml | 780 window.console.dirxml |
| 784 // FIXME: add copy method. | 781 // FIXME: add copy method. |
| 785 ]; | 782 ]; |
| 786 } | 783 } |
| 787 | 784 |
| 788 static List getMapKeyList(Map map) => map.keys.toList(); | 785 static List getMapKeyList(Map map) => map.keys.toList(); |
| 789 | 786 |
| 790 static bool isNoSuchMethodError(obj) => obj is NoSuchMethodError; | 787 static bool isNoSuchMethodError(obj) => obj is NoSuchMethodError; |
| 791 | 788 |
| 792 static void register(Document document, String tag, Type type, | 789 static void register(Document document, String tag, Type type, |
| 793 String extendsTagName) { | 790 String extendsTagName) { |
| 794 var nativeClass = _validateCustomType(type); | 791 var nativeClass = _validateCustomType(type); |
| 795 | 792 |
| 796 if (extendsTagName == null) { | 793 if (extendsTagName == null) { |
| 797 if (nativeClass.reflectedType != HtmlElement) { | 794 if (nativeClass.reflectedType != HtmlElement) { |
| 798 throw new UnsupportedError('Class must provide extendsTag if base ' | 795 throw new UnsupportedError('Class must provide extendsTag if base ' |
| 799 'native class is not HTMLElement'); | 796 'native class is not HTMLElement'); |
| 800 } | 797 } |
| 801 } | 798 } |
| 802 | 799 |
| 803 _register(document, tag, type, extendsTagName); | 800 _register(document, tag, type, extendsTagName); |
| 804 } | 801 } |
| 805 | 802 |
| 806 static void _register(Document document, String tag, Type customType, | 803 static void _register(Document document, String tag, Type customType, |
| 807 String extendsTagName) => _blink.Blink_Utils.register(unwrap_jso(document), tag, customType, extendsTagName); | 804 String extendsTagName) => _blink.Blink_Utils.register(document, tag, customT ype, extendsTagName); |
| 808 | 805 |
| 809 static Element createElement(Document document, String tagName) => | 806 static Element createElement(Document document, String tagName) => |
| 810 wrap_jso(_blink.Blink_Utils.createElement(unwrap_jso(document), tagName)); | 807 _blink.Blink_Utils.createElement(document, tagName); |
| 811 | 808 |
| 809 // TODO(jacobr): I don't think this is used... If it is, it probably | |
| 810 // duplicates functionality in JsNative.setInstanceInterceptor | |
| 812 static Element changeElementWrapper(HtmlElement element, Type type) => | 811 static Element changeElementWrapper(HtmlElement element, Type type) => |
| 813 wrap_jso(_blink.Blink_Utils.changeElementWrapper(unwrap_jso(element), type )); | 812 _blink.Blink_Utils.changeElementWrapper(element, type); |
| 814 } | 813 } |
| 815 | 814 |
| 815 // TODO(jacobr): this seems busted. I believe we are actually | |
| 816 // giving users real windows for opener, parent, top, etc. | |
| 817 // Or worse, we are probaly returning a raw JSObject. | |
|
Alan Knight
2016/03/25 21:39:09
Yes, this is already broken. https://github.com/d
Jacob
2016/03/30 00:19:00
Acknowledged.
| |
| 816 class _DOMWindowCrossFrame extends DartHtmlDomObject implements | 818 class _DOMWindowCrossFrame extends DartHtmlDomObject implements |
| 817 WindowBase { | 819 WindowBase { |
| 818 /** Needed because KeyboardEvent is implements. | |
| 819 * TODO(terry): Consider making blink_jsObject private (add underscore) for | |
| 820 * all blink_jsObject. Then needed private wrap/unwrap_jso | |
| 821 * functions that delegate to a public wrap/unwrap_jso. | |
| 822 */ | |
| 823 js.JsObject blink_jsObject; | |
| 824 | 820 |
| 825 _DOMWindowCrossFrame.internal(); | 821 _DOMWindowCrossFrame.internal(); |
| 822 | |
| 823 static _createSafe(win) => js.JsNative.setInstanceInterceptor(win, _DOMWindowC rossFrame); | |
| 826 | 824 |
| 827 // Fields. | 825 // Fields. |
| 828 HistoryBase get history => wrap_jso(_blink.Blink_DOMWindowCrossFrame.get_histo ry(unwrap_jso(this))); | 826 HistoryBase get history => _blink.Blink_DOMWindowCrossFrame.get_history(this); |
| 829 LocationBase get location => wrap_jso(_blink.Blink_DOMWindowCrossFrame.get_loc ation(unwrap_jso(this))); | 827 LocationBase get location => _blink.Blink_DOMWindowCrossFrame.get_location(thi s); |
| 830 bool get closed => wrap_jso(_blink.Blink_DOMWindowCrossFrame.get_closed(unwrap _jso(this))); | 828 bool get closed => _blink.Blink_DOMWindowCrossFrame.get_closed(this); |
| 831 WindowBase get opener => wrap_jso(_blink.Blink_DOMWindowCrossFrame.get_opener( unwrap_jso(this))); | 829 WindowBase get opener => _blink.Blink_DOMWindowCrossFrame.get_opener(this); |
| 832 WindowBase get parent => wrap_jso(_blink.Blink_DOMWindowCrossFrame.get_parent( unwrap_jso(this))); | 830 WindowBase get parent => _blink.Blink_DOMWindowCrossFrame.get_parent(this); |
| 833 WindowBase get top => wrap_jso(_blink.Blink_DOMWindowCrossFrame.get_top(unwrap _jso(this))); | 831 WindowBase get top => _blink.Blink_DOMWindowCrossFrame.get_top(this); |
| 834 | 832 |
| 835 // Methods. | 833 // Methods. |
| 836 void close() => _blink.Blink_DOMWindowCrossFrame.close(unwrap_jso(this)); | 834 void close() => _blink.Blink_DOMWindowCrossFrame.close(this); |
| 837 void postMessage(/*SerializedScriptValue*/ message, String targetOrigin, [List messagePorts]) => | 835 void postMessage(/*SerializedScriptValue*/ message, String targetOrigin, [List messagePorts]) => |
| 838 _blink.Blink_DOMWindowCrossFrame.postMessage(unwrap_jso(this), | 836 _blink.Blink_DOMWindowCrossFrame.postMessage(this, |
| 839 convertDartToNative_SerializedScriptValue(message), targetOrigin, messa gePorts); | 837 convertDartToNative_SerializedScriptValue(message), targetOrigin, messa gePorts); |
| 840 | 838 |
| 841 // Implementation support. | 839 // Implementation support. |
| 842 String get typeName => "Window"; | 840 String get typeName => "Window"; |
| 843 | 841 |
| 844 // TODO(efortuna): Remove this method. dartbug.com/16814 | 842 // TODO(efortuna): Remove this method. dartbug.com/16814 |
| 845 Events get on => throw new UnsupportedError( | 843 Events get on => throw new UnsupportedError( |
| 846 'You can only attach EventListeners to your own window.'); | 844 'You can only attach EventListeners to your own window.'); |
| 847 // TODO(efortuna): Remove this method. dartbug.com/16814 | 845 // TODO(efortuna): Remove this method. dartbug.com/16814 |
| 848 void _addEventListener([String type, EventListener listener, bool useCapture]) | 846 void _addEventListener([String type, EventListener listener, bool useCapture]) |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 862 // TODO(efortuna): Remove this method. dartbug.com/16814 | 860 // TODO(efortuna): Remove this method. dartbug.com/16814 |
| 863 void removeEventListener(String type, EventListener listener, | 861 void removeEventListener(String type, EventListener listener, |
| 864 [bool useCapture]) => throw new UnsupportedError( | 862 [bool useCapture]) => throw new UnsupportedError( |
| 865 'You can only attach EventListeners to your own window.'); | 863 'You can only attach EventListeners to your own window.'); |
| 866 } | 864 } |
| 867 | 865 |
| 868 class _HistoryCrossFrame extends DartHtmlDomObject implements HistoryBase { | 866 class _HistoryCrossFrame extends DartHtmlDomObject implements HistoryBase { |
| 869 _HistoryCrossFrame.internal(); | 867 _HistoryCrossFrame.internal(); |
| 870 | 868 |
| 871 // Methods. | 869 // Methods. |
| 872 void back() => _blink.Blink_HistoryCrossFrame.back(unwrap_jso(this)); | 870 void back() => _blink.Blink_HistoryCrossFrame.back(this); |
| 873 void forward() => _blink.Blink_HistoryCrossFrame.forward(unwrap_jso(this)); | 871 void forward() => _blink.Blink_HistoryCrossFrame.forward(this); |
| 874 void go(int distance) => _blink.Blink_HistoryCrossFrame.go(unwrap_jso(this), d istance); | 872 void go(int distance) => _blink.Blink_HistoryCrossFrame.go(this, distance); |
| 875 | 873 |
| 876 // Implementation support. | 874 // Implementation support. |
| 877 String get typeName => "History"; | 875 String get typeName => "History"; |
| 878 } | 876 } |
| 879 | 877 |
| 880 class _LocationCrossFrame extends DartHtmlDomObject implements LocationBase { | 878 class _LocationCrossFrame extends DartHtmlDomObject implements LocationBase { |
| 881 _LocationCrossFrame.internal(); | 879 _LocationCrossFrame.internal(); |
| 882 | 880 |
| 883 // Fields. | 881 // Fields. |
| 884 set href(String h) => _blink.Blink_LocationCrossFrame.set_href(unwrap_jso(this ), h); | 882 set href(String h) => _blink.Blink_LocationCrossFrame.set_href(this, h); |
| 885 | 883 |
| 886 // Implementation support. | 884 // Implementation support. |
| 887 String get typeName => "Location"; | 885 String get typeName => "Location"; |
| 888 } | 886 } |
| 889 | 887 |
| 890 // TODO(vsm): Remove DOM isolate code once we have Dartium isolates | 888 // TODO(vsm): Remove DOM isolate code once we have Dartium isolates |
| 891 // as workers. This is only used to support | 889 // as workers. This is only used to support |
| 892 // printing and timers in background isolates. As workers they should | 890 // printing and timers in background isolates. As workers they should |
| 893 // be able to just do those things natively. | 891 // be able to just do those things natively. |
| 894 | 892 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1092 _scheduleImmediateHelper._schedule(callback); | 1090 _scheduleImmediateHelper._schedule(callback); |
| 1093 }; | 1091 }; |
| 1094 | 1092 |
| 1095 get _pureIsolateScheduleImmediateClosure => ((void callback()) => | 1093 get _pureIsolateScheduleImmediateClosure => ((void callback()) => |
| 1096 throw new UnimplementedError("scheduleMicrotask in background isolates " | 1094 throw new UnimplementedError("scheduleMicrotask in background isolates " |
| 1097 "are not supported in the browser")); | 1095 "are not supported in the browser")); |
| 1098 | 1096 |
| 1099 // Class for unsupported native browser 'DOM' objects. | 1097 // Class for unsupported native browser 'DOM' objects. |
| 1100 class _UnsupportedBrowserObject extends DartHtmlDomObject { | 1098 class _UnsupportedBrowserObject extends DartHtmlDomObject { |
| 1101 } | 1099 } |
| OLD | NEW |