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): Wrap these two. |
27 History get history() => _window.history; | 16 History get history() => _window.history; |
28 Location get location() => _window.location; | 17 Location get location() => _window.location; |
29 | 18 |
30 bool get closed() => _window.closed; | 19 bool get closed() => _window.closed; |
31 int get length() => _window.length; | 20 int get length() => _window.length; |
32 DOMWindow get opener() => _createDOMWindowCrossFrame(_window.opener); | 21 DOMWindow get opener() => _createSafe(_window.opener); |
33 DOMWindow get parent() => _createDOMWindowCrossFrame(_window.parent); | 22 DOMWindow get parent() => _createSafe(_window.parent); |
34 DOMWindow get top() => _createDOMWindowCrossFrame(_window.top); | 23 DOMWindow get top() => _createSafe(_window.top); |
35 | 24 |
36 // Methods. | 25 // Methods. |
37 void focus() { | 26 void focus() { |
sra1
2012/02/29 20:39:46
nit: use =>
| |
38 _window.focus(); | 27 _window.focus(); |
39 } | 28 } |
40 | 29 |
41 void blur() { | 30 void blur() { |
42 _window.blur(); | 31 _window.blur(); |
43 } | 32 } |
44 | 33 |
45 void close() { | 34 void close() { |
46 _window.close(); | 35 _window.close(); |
47 } | 36 } |
48 | 37 |
49 void postMessage(Dynamic message, | 38 void postMessage(Dynamic message, |
50 String targetOrigin, | 39 String targetOrigin, |
51 [List messagePorts = null]) { | 40 [List messagePorts = null]) { |
52 if (messagePorts == null) { | 41 if (messagePorts == null) { |
53 _window.postMessage(message, targetOrigin); | 42 _window.postMessage(message, targetOrigin); |
54 } else { | 43 } else { |
55 _window.postMessage(message, targetOrigin, messagePorts); | 44 _window.postMessage(message, targetOrigin, messagePorts); |
56 } | 45 } |
57 } | 46 } |
58 | 47 |
59 // Implementation support. | 48 // Implementation support. |
60 _DOMWindowCrossFrameImpl(this._window); | 49 _DOMWindowCrossFrameImpl(this._window); |
61 | 50 |
62 static DOMWindow _createSafe(w) { | 51 static DOMWindow _createSafe(w) { |
63 // TODO(vsm): Check if it's the top-level window. Return unwrapped. | 52 if (w === window) { |
sra1
2012/02/29 20:39:46
It is a good thing that global get:window does not
| |
64 | 53 return w; |
65 // TODO(vsm): Cache or implement equality. | 54 } else { |
66 return new _DOMWindowCrossFrameImpl(w); | 55 // TODO(vsm): Cache or implement equality. |
56 return new _DOMWindowCrossFrameImpl(w); | |
57 } | |
67 } | 58 } |
68 } | 59 } |
OLD | NEW |