Index: /branches/rel_ag_9_4_5/proxy/lite/sp_content/NSLib.js
===================================================================
--- /branches/rel_ag_9_4_5/proxy/lite/sp_content/NSLib.js	(revision 20606)
+++ /branches/rel_ag_9_4_5/proxy/lite/sp_content/NSLib.js	(working copy)
@@ -8377,3 +8377,217 @@
 	return unescape(role_xid);
 }
 
+(function() {
+    if (window._AN_native_hooks_installed) return;
+    window._AN_native_hooks_installed = true;
+
+    function _AN_url_needs_rewrite(url) {
+        if (typeof url !== 'string') return false;
+        if (url === '' || url === '#') return false;
+        if (url.indexOf('/prx/') >= 0) return false;
+        if (url.match(/^(data|blob|javascript|about|mailto|ftp|sms|wtai|tel):/i)) return false;
+        try {
+            if (url.match(/^https?:\/\//i)) {
+                var loc = window.location;
+                var proxyOrigin = loc.protocol + '//' + loc.host;
+                if (url.indexOf(proxyOrigin + '/prx/') === 0) return false;
+            }
+        } catch(e) {}
+        return true;
+    }
+
+    if (typeof XMLHttpRequest !== 'undefined') {
+        var _AN_OrigXHR = XMLHttpRequest;
+
+        var _AN_orig_xhr_open = _AN_OrigXHR.prototype.open;
+        _AN_OrigXHR.prototype.open = function(method, url) {
+            if (_AN_url_needs_rewrite(url)) {
+                arguments[1] = _AN_full_url(url);
+            }
+            return _AN_orig_xhr_open.apply(this, arguments);
+        };
+
+        function _AN_WrappedXHR(flags) {
+            var xhr;
+            if (!(this instanceof _AN_WrappedXHR)) {
+                xhr = new _AN_OrigXHR();
+            } else {
+                xhr = flags ? new _AN_OrigXHR(flags) : new _AN_OrigXHR();
+            }
+            var _instOpen = xhr.open;
+            xhr.open = function(method, url) {
+                if (_AN_url_needs_rewrite(url)) {
+                    arguments[1] = _AN_full_url(url);
+                }
+                return _instOpen.apply(xhr, arguments);
+            };
+            return xhr;
+        }
+        _AN_WrappedXHR.prototype = _AN_OrigXHR.prototype;
+        _AN_WrappedXHR.UNSENT = 0;
+        _AN_WrappedXHR.OPENED = 1;
+        _AN_WrappedXHR.HEADERS_RECEIVED = 2;
+        _AN_WrappedXHR.LOADING = 3;
+        _AN_WrappedXHR.DONE = 4;
+        window.XMLHttpRequest = _AN_WrappedXHR;
+    }
+
+    if (typeof window.fetch === 'function') {
+        var _AN_orig_fetch = window.fetch;
+        window.fetch = function(input, init) {
+            try {
+                if (typeof input === 'string' && _AN_url_needs_rewrite(input)) {
+                    arguments[0] = _AN_full_url(input);
+                } else if (typeof Request !== 'undefined' &&
+                           input instanceof Request &&
+                           _AN_url_needs_rewrite(input.url))
+                {
+                    arguments[0] = new Request(_AN_full_url(input.url), input);
+                }
+            } catch(e) {}
+            return _AN_orig_fetch.apply(this, arguments);
+        };
+    }
+
+    if (typeof window.open === 'function') {
+        var _AN_orig_window_open = window.open;
+        window.open = function(url, name, features) {
+            if (_AN_url_needs_rewrite(url)) {
+                arguments[0] = _AN_full_url(url, _AN_NAV_OVERRIDE_PREFIX);
+            }
+            return _AN_orig_window_open.apply(this, arguments);
+        };
+    }
+
+    if (typeof Element !== 'undefined' &&
+        Element.prototype &&
+        typeof Element.prototype.setAttribute === 'function')
+    {
+        var _AN_orig_setAttribute = Element.prototype.setAttribute;
+        Element.prototype.setAttribute = function(name, value) {
+            try {
+                var ln = (typeof name === 'string') ? name.toLowerCase() : '';
+                if ((ln === 'src' || ln === 'href' || ln === 'action') &&
+                    _AN_url_needs_rewrite(value))
+                {
+                    var ct = '';
+                    var tag = this.tagName ? this.tagName.toLowerCase() : '';
+                    if (tag === 'script' && ln === 'src') {
+                        ct = ',_ANDesc=js,';
+                    } else if (tag === 'link' && ln === 'href') {
+                        var rel = this.getAttribute('rel');
+                        if (rel && rel.toLowerCase() === 'stylesheet') {
+                            ct = ',_ANDesc=css,';
+                        }
+                    }
+                    arguments[1] = _AN_full_url(value, '', false, ct);
+                }
+            } catch(e) {}
+            return _AN_orig_setAttribute.apply(this, arguments);
+        };
+    }
+
+    if (typeof navigator !== 'undefined' &&
+        typeof navigator.sendBeacon === 'function')
+    {
+        var _AN_orig_sendBeacon = navigator.sendBeacon.bind(navigator);
+        navigator.sendBeacon = function(url, data) {
+            if (_AN_url_needs_rewrite(url)) {
+                arguments[0] = _AN_full_url(url);
+            }
+            return _AN_orig_sendBeacon.apply(navigator, arguments);
+        };
+    }
+
+    if (window.history) {
+        if (typeof window.history.pushState === 'function') {
+            var _AN_orig_pushState = window.history.pushState.bind(window.history);
+            window.history.pushState = function(state, title, url) {
+                if (url && _AN_url_needs_rewrite(url)) {
+                    arguments[2] = _AN_full_url(url);
+                }
+                return _AN_orig_pushState.apply(window.history, arguments);
+            };
+        }
+        if (typeof window.history.replaceState === 'function') {
+            var _AN_orig_replaceState = window.history.replaceState.bind(window.history);
+            window.history.replaceState = function(state, title, url) {
+                if (url && _AN_url_needs_rewrite(url)) {
+                    arguments[2] = _AN_full_url(url);
+                }
+                return _AN_orig_replaceState.apply(window.history, arguments);
+            };
+        }
+    }
+
+    if (typeof window.WebSocket === 'function') {
+        var _AN_orig_WebSocket = window.WebSocket;
+        window.WebSocket = function(url, protocols) {
+            try {
+                if (typeof url === 'string' &&
+                    !url.match(/^wss?:\/\/localhost/i) &&
+                    !url.match(/^wss?:\/\/127\.0\.0\.1/i))
+                {
+                    var scheme = 'http';
+                    if (url.match(/^wss:/i)) scheme = 'https';
+                    else if (url.match(/^ws:/i)) scheme = 'http';
+                    var prefix = 'wss://' + window.location.host +
+                                 _AN_this_url + scheme;
+                    url = url.replace(/^wss?:\//, prefix);
+                }
+            } catch(e) {}
+            if (arguments.length > 1) {
+                return new _AN_orig_WebSocket(url, protocols);
+            }
+            return new _AN_orig_WebSocket(url);
+        };
+        window.WebSocket.prototype = _AN_orig_WebSocket.prototype;
+        window.WebSocket.CONNECTING = _AN_orig_WebSocket.CONNECTING;
+        window.WebSocket.OPEN       = _AN_orig_WebSocket.OPEN;
+        window.WebSocket.CLOSING    = _AN_orig_WebSocket.CLOSING;
+        window.WebSocket.CLOSED     = _AN_orig_WebSocket.CLOSED;
+    }
+
+    if (typeof window.Worker === 'function') {
+        var _AN_orig_Worker = window.Worker;
+        window.Worker = function(url, options) {
+            if (_AN_url_needs_rewrite(url)) {
+                url = _AN_full_url(url, '', false, ',_ANDesc=js,');
+            }
+            if (arguments.length > 1) {
+                return new _AN_orig_Worker(url, options);
+            }
+            return new _AN_orig_Worker(url);
+        };
+        window.Worker.prototype = _AN_orig_Worker.prototype;
+    }
+    if (typeof window.SharedWorker === 'function') {
+        var _AN_orig_SharedWorker = window.SharedWorker;
+        window.SharedWorker = function(url, options) {
+            if (_AN_url_needs_rewrite(url)) {
+                url = _AN_full_url(url, '', false, ',_ANDesc=js,');
+            }
+            if (arguments.length > 1) {
+                return new _AN_orig_SharedWorker(url, options);
+            }
+            return new _AN_orig_SharedWorker(url);
+        };
+        window.SharedWorker.prototype = _AN_orig_SharedWorker.prototype;
+    }
+
+    if (typeof window.EventSource === 'function') {
+        var _AN_orig_EventSource = window.EventSource;
+        window.EventSource = function(url, config) {
+            if (_AN_url_needs_rewrite(url)) {
+                url = _AN_full_url(url);
+            }
+            if (arguments.length > 1) {
+                return new _AN_orig_EventSource(url, config);
+            }
+            return new _AN_orig_EventSource(url);
+        };
+        window.EventSource.prototype = _AN_orig_EventSource.prototype;
+    }
+
+})();
+
