| 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 _DOMWindowCrossFrameImpl implements Window { |
| 7 // Private window. | 7 // Private window. |
| 8 _WindowImpl _window; | 8 _WindowImpl _window; |
| 9 | 9 |
| 10 // Fields. | 10 // Fields. |
| 11 // TODO(vsm): Implement history and location getters. | 11 // TODO(vsm): Implement history and location getters. |
| 12 | 12 |
| 13 bool get closed() => _window.closed; | 13 bool get closed() => _window.closed; |
| 14 int get length() => _window.length; | 14 int get length() => _window.length; |
| 15 Window get opener() => _createSafe(_window.opener); | 15 Window get opener() => _createSafe(_window.opener); |
| 16 Window get parent() => _createSafe(_window.parent); | 16 Window get parent() => _createSafe(_window.parent); |
| 17 Window get top() => _createSafe(_window.top); | 17 Window get top() => _createSafe(_window.top); |
| 18 | 18 |
| 19 // Methods. | 19 // Methods. |
| 20 void focus() => _window.focus(); | 20 void focus() => _window.focus(); |
| 21 | 21 |
| 22 void blur() => _window.blur(); | 22 void blur() => _window.blur(); |
| 23 | 23 |
| 24 void close() => _window.close(); | 24 void close() => _window.close(); |
| 25 | 25 |
| 26 void postMessage(Dynamic message, | 26 void postMessage(Dynamic message, |
| 27 String targetOrigin, | 27 String targetOrigin, |
| 28 [List messagePorts = null]) { | 28 [List messagePorts = null]) { |
| 29 if (messagePorts == null) { | 29 if (messagePorts == null) { |
| 30 _window.postMessage(message, targetOrigin); | 30 _postMessage2(_window, message, targetOrigin); |
| 31 } else { | 31 } else { |
| 32 _window.postMessage(message, targetOrigin, messagePorts); | 32 _postMessage3(_window, message, targetOrigin, messagePorts); |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 // TODO(vsm): This is a hack to workaround dartbug.com/3175. We |
| 37 // need a more robust convention to invoke JS methods on the |
| 38 // underlying window. |
| 39 static void _postMessage2(win, message, targetOrigin) native """ |
| 40 win.postMessage(message, targetOrigin); |
| 41 """; |
| 42 |
| 43 static void _postMessage3(win, message, targetOrigin, messagePorts) native """ |
| 44 win.postMessage(message, targetOrigin, messagePorts); |
| 45 """; |
| 46 |
| 36 // Implementation support. | 47 // Implementation support. |
| 37 _DOMWindowCrossFrameImpl(this._window); | 48 _DOMWindowCrossFrameImpl(this._window); |
| 38 | 49 |
| 39 static Window _createSafe(w) { | 50 static Window _createSafe(w) { |
| 40 if (w === window) { | 51 if (w === window) { |
| 41 return w; | 52 return w; |
| 42 } else { | 53 } else { |
| 43 // TODO(vsm): Cache or implement equality. | 54 // TODO(vsm): Cache or implement equality. |
| 44 return new _DOMWindowCrossFrameImpl(w); | 55 return new _DOMWindowCrossFrameImpl(w); |
| 45 } | 56 } |
| 46 } | 57 } |
| 47 } | 58 } |
| OLD | NEW |