Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1480)

Unified Diff: lib/html/frog/html_frog.dart

Side-by-side diff isn't available for this file because of its large size.
Issue 10534130: Wrap Location object on Firefox. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
Download patch
Index: lib/html/frog/html_frog.dart
diff --git a/lib/html/frog/html_frog.dart b/lib/html/frog/html_frog.dart
index d09988ebfb5503f4ede88ff0d3cae93bde1776ad..b7bb02c7fe89e991112d08f3e7d99aafb88ccd78 100644
--- a/lib/html/frog/html_frog.dart
+++ b/lib/html/frog/html_frog.dart
@@ -16325,6 +16325,53 @@ class _WindowImpl extends _EventTargetImpl implements Window native "@*DOMWindow
// Override top to return secure wrapper.
Window get top() => _DOMWindowCrossFrameImpl._createSafe(_top);
+
+ // API level getter and setter for Location.
+ // TODO: The cross domain safe wrapper can be inserted here or folded into
+ // _LocationWrapper.
+ Location get location() => _get_location();
+ void set location(Location value) => _set_location(value);
+
+ // Firefox work-around for Location. The Firefox location object cannot be
+ // made to behave like a Dart object so must be wrapped.
+
+ Location _get_location() {
+ var result = _location;
+ if (_isDartLocation(result)) return result; // e.g. on Chrome.
+ if (null == _location_wrapper) {
+ _location_wrapper = new _LocationWrapper(result);
+ }
+ return _location_wrapper;
+ }
+
+ void _set_location(Location value) {
+ if (value is _LocationWrapper) {
+ _location = value._ptr;
+ } else {
+ _location = value;
+ }
+ }
+
+ var _location_wrapper; // Cached wrapped Location object.
+
+ // Native getter and setter to access raw Location object.
+ Location get _location() native 'return this.location';
+ void set _location(Location value) native 'this.location = value';
+ // Prevent compiled from thinking 'location' property is available for a Dart
+ // member.
+ _protect_location() native 'location';
+
+ static _isDartLocation(thing) {
+ // On Firefox the code that implements 'is Location' fails to find the patch
+ // stub on Object.prototype and throws an exception.
+ try {
+ return thing is Location;
+ } catch (var e) {
+ return false;
+ }
+ }
+
+
void requestLayoutFrame(TimeoutHandler callback) {
_addMeasurementFrameCallback(callback);
}
@@ -16406,8 +16453,6 @@ class _WindowImpl extends _EventTargetImpl implements Window native "@*DOMWindow
final _StorageImpl localStorage;
- _LocationImpl location;
-
final _BarInfoImpl locationbar;
final _BarInfoImpl menubar;
@@ -36919,6 +36964,79 @@ class _IDBOpenDBRequestEventsImpl extends _IDBRequestEventsImpl implements IDBOp
EventListenerList get upgradeneeded() => _get('upgradeneeded');
}
+// 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.
+
+
+// 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 '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() => _get(_ptr, 'origin');
+
+ // 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) => _assign(_ptr, url);
+
+ void reload() => _reload(_ptr);
+
+ void replace(String url) => _replace(_ptr, url);
+
+ String toString() => _toString(_ptr);
+
+
+ static _get(p, m) native 'return p[m];';
+ static _set(p, m, v) native 'p[m] = v;';
+
+ static _assign(p, url) native 'p.assign(url);';
+ static _reload(p) native 'p.reload()';
+ static _replace(p, url) native 'p.replace(url);';
+ static _toString(p) native 'return p.toString();';
+}
// Copyright (c) 2012, 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.

Powered by Google App Engine
This is Rietveld 408576698