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 $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | |
6 $!MEMBERS | |
7 | |
8 Window get _contentWindow() native "return this.contentWindow;"; | |
9 | |
10 // Override contentWindow to return secure wrapper. | |
11 Window get contentWindow() { | |
12 return _DOMWindowCrossFrameImpl._createSafe(_contentWindow); | |
13 } | |
14 } | |
15 | |
16 // TODO(vsm): Unify with Dartium version. | 5 // TODO(vsm): Unify with Dartium version. |
17 class _DOMWindowCrossFrameImpl implements DOMType, DOMWindow { | 6 class _DOMWindowCrossFrameImpl implements DOMType, DOMWindow { |
18 // Private window. | 7 // Private window. |
19 _DOMWindowJs _window; | 8 _DOMWindowJs _window; |
20 | 9 |
21 // DOMType | 10 // DOMType |
22 var dartObjectLocalStorage; | 11 var dartObjectLocalStorage; |
23 String get typeName() => "DOMWindow"; | 12 String get typeName() => "DOMWindow"; |
24 | 13 |
25 // Fields. | 14 // Fields. |
26 // TODO(vsm): Wrap these two. | 15 // TODO(vsm): Implement history and location getters. |
27 History get history() => _window.history; | |
28 Location get location() => _window.location; | |
29 | 16 |
30 bool get closed() => _window.closed; | 17 bool get closed() => _window.closed; |
31 int get length() => _window.length; | 18 int get length() => _window.length; |
32 DOMWindow get opener() => _createDOMWindowCrossFrame(_window.opener); | 19 DOMWindow get opener() => _createSafe(_window.opener); |
33 DOMWindow get parent() => _createDOMWindowCrossFrame(_window.parent); | 20 DOMWindow get parent() => _createSafe(_window.parent); |
34 DOMWindow get top() => _createDOMWindowCrossFrame(_window.top); | 21 DOMWindow get top() => _createSafe(_window.top); |
35 | 22 |
36 // Methods. | 23 // Methods. |
37 void focus() { | 24 void focus() => _window.focus(); |
38 _window.focus(); | |
39 } | |
40 | 25 |
41 void blur() { | 26 void blur() => _window.blur(); |
42 _window.blur(); | |
43 } | |
44 | 27 |
45 void close() { | 28 void close() => _window.close(); |
46 _window.close(); | |
47 } | |
48 | 29 |
49 void postMessage(Dynamic message, | 30 void postMessage(Dynamic message, |
50 String targetOrigin, | 31 String targetOrigin, |
51 [List messagePorts = null]) { | 32 [List messagePorts = null]) { |
52 if (messagePorts == null) { | 33 if (messagePorts == null) { |
53 _window.postMessage(message, targetOrigin); | 34 _window.postMessage(message, targetOrigin); |
54 } else { | 35 } else { |
55 _window.postMessage(message, targetOrigin, messagePorts); | 36 _window.postMessage(message, targetOrigin, messagePorts); |
56 } | 37 } |
57 } | 38 } |
58 | 39 |
59 // Implementation support. | 40 // Implementation support. |
60 _DOMWindowCrossFrameImpl(this._window); | 41 _DOMWindowCrossFrameImpl(this._window); |
61 | 42 |
62 static DOMWindow _createSafe(w) { | 43 static DOMWindow _createSafe(w) { |
63 // TODO(vsm): Check if it's the top-level window. Return unwrapped. | 44 if (w === window) { |
64 | 45 return w; |
65 // TODO(vsm): Cache or implement equality. | 46 } else { |
66 return new _DOMWindowCrossFrameImpl(w); | 47 // TODO(vsm): Cache or implement equality. |
| 48 return new _DOMWindowCrossFrameImpl(w); |
| 49 } |
67 } | 50 } |
68 } | 51 } |
OLD | NEW |