| 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 // TODO(vsm): Unify with Dartium version. | 5 // TODO(vsm): Unify with Dartium version. |
| 6 class _DOMWindowCrossFrameImpl implements Window { | 6 class _DOMWindowCrossFrame implements Window { |
| 7 // Private window. Note, this is a window in another frame, so it | 7 // Private window. Note, this is a window in another frame, so it |
| 8 // cannot be typed as "Window" as its prototype is not patched | 8 // cannot be typed as "Window" as its prototype is not patched |
| 9 // properly. Its fields and methods can only be accessed via JavaScript. | 9 // properly. Its fields and methods can only be accessed via JavaScript. |
| 10 var _window; | 10 var _window; |
| 11 | 11 |
| 12 // Fields. | 12 // Fields. |
| 13 History get history => | 13 History get history => |
| 14 _HistoryCrossFrameImpl._createSafe(JS('History', '#.history', _window)); | 14 _HistoryCrossFrame._createSafe(JS('History', '#.history', _window)); |
| 15 Location get location => | 15 Location get location => |
| 16 _LocationCrossFrameImpl._createSafe(JS('Location', '#.location', _window)); | 16 _LocationCrossFrame._createSafe(JS('Location', '#.location', _window)); |
| 17 | 17 |
| 18 // TODO(vsm): Add frames to navigate subframes. See 2312. | 18 // TODO(vsm): Add frames to navigate subframes. See 2312. |
| 19 | 19 |
| 20 bool get closed => JS('bool', '#.closed', _window); | 20 bool get closed => JS('bool', '#.closed', _window); |
| 21 | 21 |
| 22 Window get opener => _createSafe(JS('Window', '#.opener', _window)); | 22 Window get opener => _createSafe(JS('Window', '#.opener', _window)); |
| 23 | 23 |
| 24 Window get parent => _createSafe(JS('Window', '#.parent', _window)); | 24 Window get parent => _createSafe(JS('Window', '#.parent', _window)); |
| 25 | 25 |
| 26 Window get top => _createSafe(JS('Window', '#.top', _window)); | 26 Window get top => _createSafe(JS('Window', '#.top', _window)); |
| 27 | 27 |
| 28 // Methods. | 28 // Methods. |
| 29 void focus() => JS('void', '#.focus()', _window); | 29 void focus() => JS('void', '#.focus()', _window); |
| 30 | 30 |
| 31 void blur() => JS('void', '#.blur()', _window); | 31 void blur() => JS('void', '#.blur()', _window); |
| 32 | 32 |
| 33 void close() => JS('void', '#.close()', _window); | 33 void close() => JS('void', '#.close()', _window); |
| 34 | 34 |
| 35 void postMessage(var message, String targetOrigin, [List messagePorts = null])
{ | 35 void postMessage(var message, String targetOrigin, [List messagePorts = null])
{ |
| 36 if (messagePorts == null) { | 36 if (messagePorts == null) { |
| 37 JS('void', '#.postMessage(#,#)', _window, message, targetOrigin); | 37 JS('void', '#.postMessage(#,#)', _window, message, targetOrigin); |
| 38 } else { | 38 } else { |
| 39 JS('void', '#.postMessage(#,#,#)', _window, message, targetOrigin, message
Ports); | 39 JS('void', '#.postMessage(#,#,#)', _window, message, targetOrigin, message
Ports); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 // Implementation support. | 43 // Implementation support. |
| 44 _DOMWindowCrossFrameImpl(this._window); | 44 _DOMWindowCrossFrame(this._window); |
| 45 | 45 |
| 46 static Window _createSafe(w) { | 46 static Window _createSafe(w) { |
| 47 if (identical(w, window)) { | 47 if (identical(w, window)) { |
| 48 return w; | 48 return w; |
| 49 } else { | 49 } else { |
| 50 // TODO(vsm): Cache or implement equality. | 50 // TODO(vsm): Cache or implement equality. |
| 51 return new _DOMWindowCrossFrameImpl(w); | 51 return new _DOMWindowCrossFrame(w); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 class _LocationCrossFrameImpl implements Location { | 56 class _LocationCrossFrame implements Location { |
| 57 // Private location. Note, this is a location object in another frame, so it | 57 // Private location. Note, this is a location object in another frame, so it |
| 58 // cannot be typed as "Location" as its prototype is not patched | 58 // cannot be typed as "Location" as its prototype is not patched |
| 59 // properly. Its fields and methods can only be accessed via JavaScript. | 59 // properly. Its fields and methods can only be accessed via JavaScript. |
| 60 var _location; | 60 var _location; |
| 61 | 61 |
| 62 void set href(String val) => _setHref(_location, val); | 62 void set href(String val) => _setHref(_location, val); |
| 63 static void _setHref(location, val) { | 63 static void _setHref(location, val) { |
| 64 JS('void', '#.href = #', location, val); | 64 JS('void', '#.href = #', location, val); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Implementation support. | 67 // Implementation support. |
| 68 _LocationCrossFrameImpl(this._location); | 68 _LocationCrossFrame(this._location); |
| 69 | 69 |
| 70 static Location _createSafe(location) { | 70 static Location _createSafe(location) { |
| 71 if (identical(location, window.location)) { | 71 if (identical(location, window.location)) { |
| 72 return location; | 72 return location; |
| 73 } else { | 73 } else { |
| 74 // TODO(vsm): Cache or implement equality. | 74 // TODO(vsm): Cache or implement equality. |
| 75 return new _LocationCrossFrameImpl(location); | 75 return new _LocationCrossFrame(location); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 class _HistoryCrossFrameImpl implements History { | 80 class _HistoryCrossFrame implements History { |
| 81 // Private history. Note, this is a history object in another frame, so it | 81 // Private history. Note, this is a history object in another frame, so it |
| 82 // cannot be typed as "History" as its prototype is not patched | 82 // cannot be typed as "History" as its prototype is not patched |
| 83 // properly. Its fields and methods can only be accessed via JavaScript. | 83 // properly. Its fields and methods can only be accessed via JavaScript. |
| 84 var _history; | 84 var _history; |
| 85 | 85 |
| 86 void back() => JS('void', '#.back()', _history); | 86 void back() => JS('void', '#.back()', _history); |
| 87 | 87 |
| 88 void forward() => JS('void', '#.forward()', _history); | 88 void forward() => JS('void', '#.forward()', _history); |
| 89 | 89 |
| 90 void go(int distance) => JS('void', '#.go(#)', _history, distance); | 90 void go(int distance) => JS('void', '#.go(#)', _history, distance); |
| 91 | 91 |
| 92 // Implementation support. | 92 // Implementation support. |
| 93 _HistoryCrossFrameImpl(this._history); | 93 _HistoryCrossFrame(this._history); |
| 94 | 94 |
| 95 static History _createSafe(h) { | 95 static History _createSafe(h) { |
| 96 if (identical(h, window.history)) { | 96 if (identical(h, window.history)) { |
| 97 return h; | 97 return h; |
| 98 } else { | 98 } else { |
| 99 // TODO(vsm): Cache or implement equality. | 99 // TODO(vsm): Cache or implement equality. |
| 100 return new _HistoryCrossFrameImpl(h); | 100 return new _HistoryCrossFrame(h); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 } | 103 } |
| OLD | NEW |