* @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)
| 5778 | * @param {object} $sniffer $sniffer service |
| 5779 | */ |
| 5780 | function Browser(window, document, $log, $sniffer) { |
| 5781 | var self = this, |
| 5782 | rawDocument = document[0], |
| 5783 | location = window.location, |
| 5784 | history = window.history, |
| 5785 | setTimeout = window.setTimeout, |
| 5786 | clearTimeout = window.clearTimeout, |
| 5787 | pendingDeferIds = {}; |
| 5788 | |
| 5789 | self.isMock = false; |
| 5790 | |
| 5791 | var outstandingRequestCount = 0; |
| 5792 | var outstandingRequestCallbacks = []; |
| 5793 | |
| 5794 | // TODO(vojta): remove this temporary api |
| 5795 | self.$$completeOutstandingRequest = completeOutstandingRequest; |
| 5796 | self.$$incOutstandingRequestCount = function() { outstandingRequestCount++; }; |
| 5797 | |
| 5798 | /** |
| 5799 | * Executes the `fn` function(supports currying) and decrements the `outstandingRequestCallbacks` |
| 5800 | * counter. If the counter reaches 0, all the `outstandingRequestCallbacks` are executed. |
| 5801 | */ |
| 5802 | function completeOutstandingRequest(fn) { |
| 5803 | try { |
| 5804 | fn.apply(null, sliceArgs(arguments, 1)); |
| 5805 | } finally { |
| 5806 | outstandingRequestCount--; |
| 5807 | if (outstandingRequestCount === 0) { |
| 5808 | while (outstandingRequestCallbacks.length) { |
| 5809 | try { |
| 5810 | outstandingRequestCallbacks.pop()(); |
| 5811 | } catch (e) { |
| 5812 | $log.error(e); |
| 5813 | } |
| 5814 | } |
| 5815 | } |
| 5816 | } |
| 5817 | } |
| 5818 | |
| 5819 | function getHash(url) { |
| 5820 | var index = url.indexOf('#'); |
| 5821 | return index === -1 ? '' : url.substr(index); |
| 5822 | } |
| 5823 | |
| 5824 | /** |
| 5825 | * @private |
| 5826 | * Note: this method is used only by scenario runner |
| 5827 | * TODO(vojta): prefix this method with $$ ? |
| 5828 | * @param {function()} callback Function that will be called when no outstanding request |
| 5829 | */ |
| 5830 | self.notifyWhenNoOutstandingRequests = function(callback) { |
| 5831 | if (outstandingRequestCount === 0) { |
| 5832 | callback(); |
| 5833 | } else { |
| 5834 | outstandingRequestCallbacks.push(callback); |
| 5835 | } |
| 5836 | }; |
| 5837 |
nothing calls this directly
no test coverage detected