| // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| part of html; |
| |
| // On Firefox 11, the object obtained from 'window.location' is very strange. |
| // It can't be monkey-patched and seems immune to putting methods on |
| // Object.prototype. We are forced to wrap the object. |
| |
| class _LocationWrapper implements Location { |
| |
| final _ptr; // Opaque reference to real location. |
| |
| _LocationWrapper(this._ptr); |
| |
| // TODO(sra): Replace all the _set and _get calls with 'JS' forms. |
| |
| // final List<String> ancestorOrigins; |
| List<String> get ancestorOrigins => _get(_ptr, 'ancestorOrigins'); |
| |
| // String hash; |
| String get hash => _get(_ptr, 'hash'); |
| void set hash(String value) { |
| _set(_ptr, 'hash', value); |
| } |
| |
| // String host; |
| String get host => _get(_ptr, 'host'); |
| void set host(String value) { |
| _set(_ptr, 'host', value); |
| } |
| |
| // String hostname; |
| String get hostname => _get(_ptr, 'hostname'); |
| void set hostname(String value) { |
| _set(_ptr, 'hostname', value); |
| } |
| |
| // String href; |
| String get href => _get(_ptr, 'href'); |
| void set href(String value) { |
| _set(_ptr, 'href', value); |
| } |
| |
| // final String origin; |
| String get origin { |
| if (JS('bool', '("origin" in #)', _ptr)) { |
| return JS('String', '#.origin', _ptr); |
| } |
| return '${this.protocol}//${this.host}'; |
| } |
| |
| // String pathname; |
| String get pathname => _get(_ptr, 'pathname'); |
| void set pathname(String value) { |
| _set(_ptr, 'pathname', value); |
| } |
| |
| // String port; |
| String get port => _get(_ptr, 'port'); |
| void set port(String value) { |
| _set(_ptr, 'port', value); |
| } |
| |
| // String protocol; |
| String get protocol => _get(_ptr, 'protocol'); |
| void set protocol(String value) { |
| _set(_ptr, 'protocol', value); |
| } |
| |
| // String search; |
| String get search => _get(_ptr, 'search'); |
| void set search(String value) { |
| _set(_ptr, 'search', value); |
| } |
| |
| void assign(String url) => JS('void', '#.assign(#)', _ptr, url); |
| |
| void reload() => JS('void', '#.reload()', _ptr); |
| |
| void replace(String url) => JS('void', '#.replace(#)', _ptr, url); |
| |
| String toString() => JS('String', '#.toString()', _ptr); |
| |
| |
| static _get(p, m) => JS('var', '#[#]', p, m); |
| static _set(p, m, v) => JS('void', '#[#] = #', p, m, v); |
| } |