* @param {object} window The global window object. * @param {object} document jQuery wrapped document. * @param {object} $log window.console or an object with the same interface. * @param {object} $sniffer $sniffer service
(window, document, $log, $sniffer)
| 5806 | * @param {object} $sniffer $sniffer service |
| 5807 | */ |
| 5808 | function Browser(window, document, $log, $sniffer) { |
| 5809 | var self = this, |
| 5810 | rawDocument = document[0], |
| 5811 | location = window.location, |
| 5812 | history = window.history, |
| 5813 | setTimeout = window.setTimeout, |
| 5814 | clearTimeout = window.clearTimeout, |
| 5815 | pendingDeferIds = {}; |
| 5816 | |
| 5817 | self.isMock = false; |
| 5818 | |
| 5819 | var outstandingRequestCount = 0; |
| 5820 | var outstandingRequestCallbacks = []; |
| 5821 | |
| 5822 | // TODO(vojta): remove this temporary api |
| 5823 | self.$$completeOutstandingRequest = completeOutstandingRequest; |
| 5824 | self.$$incOutstandingRequestCount = function () { outstandingRequestCount++; }; |
| 5825 | |
| 5826 | /** |
| 5827 | * Executes the `fn` function(supports currying) and decrements the `outstandingRequestCallbacks` |
| 5828 | * counter. If the counter reaches 0, all the `outstandingRequestCallbacks` are executed. |
| 5829 | */ |
| 5830 | function completeOutstandingRequest(fn) { |
| 5831 | try { |
| 5832 | fn.apply(null, sliceArgs(arguments, 1)); |
| 5833 | } finally { |
| 5834 | outstandingRequestCount--; |
| 5835 | if (outstandingRequestCount === 0) { |
| 5836 | while (outstandingRequestCallbacks.length) { |
| 5837 | try { |
| 5838 | outstandingRequestCallbacks.pop()(); |
| 5839 | } catch (e) { |
| 5840 | $log.error(e); |
| 5841 | } |
| 5842 | } |
| 5843 | } |
| 5844 | } |
| 5845 | } |
| 5846 | |
| 5847 | function getHash(url) { |
| 5848 | var index = url.indexOf('#'); |
| 5849 | return index === -1 ? '' : url.substr(index); |
| 5850 | } |
| 5851 | |
| 5852 | /** |
| 5853 | * @private |
| 5854 | * Note: this method is used only by scenario runner |
| 5855 | * TODO(vojta): prefix this method with $$ ? |
| 5856 | * @param {function()} callback Function that will be called when no outstanding request |
| 5857 | */ |
| 5858 | self.notifyWhenNoOutstandingRequests = function (callback) { |
| 5859 | if (outstandingRequestCount === 0) { |
| 5860 | callback(); |
| 5861 | } else { |
| 5862 | outstandingRequestCallbacks.push(callback); |
| 5863 | } |
| 5864 | }; |
| 5865 |
nothing calls this directly
no test coverage detected