* @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)
| 5738 | * @param {object} $sniffer $sniffer service |
| 5739 | */ |
| 5740 | function Browser(window, document, $log, $sniffer) { |
| 5741 | var self = this, |
| 5742 | rawDocument = document[0], |
| 5743 | location = window.location, |
| 5744 | history = window.history, |
| 5745 | setTimeout = window.setTimeout, |
| 5746 | clearTimeout = window.clearTimeout, |
| 5747 | pendingDeferIds = {}; |
| 5748 | |
| 5749 | self.isMock = false; |
| 5750 | |
| 5751 | var outstandingRequestCount = 0; |
| 5752 | var outstandingRequestCallbacks = []; |
| 5753 | |
| 5754 | // TODO(vojta): remove this temporary api |
| 5755 | self.$$completeOutstandingRequest = completeOutstandingRequest; |
| 5756 | self.$$incOutstandingRequestCount = function() { outstandingRequestCount++; }; |
| 5757 | |
| 5758 | /** |
| 5759 | * Executes the `fn` function(supports currying) and decrements the `outstandingRequestCallbacks` |
| 5760 | * counter. If the counter reaches 0, all the `outstandingRequestCallbacks` are executed. |
| 5761 | */ |
| 5762 | function completeOutstandingRequest(fn) { |
| 5763 | try { |
| 5764 | fn.apply(null, sliceArgs(arguments, 1)); |
| 5765 | } finally { |
| 5766 | outstandingRequestCount--; |
| 5767 | if (outstandingRequestCount === 0) { |
| 5768 | while (outstandingRequestCallbacks.length) { |
| 5769 | try { |
| 5770 | outstandingRequestCallbacks.pop()(); |
| 5771 | } catch (e) { |
| 5772 | $log.error(e); |
| 5773 | } |
| 5774 | } |
| 5775 | } |
| 5776 | } |
| 5777 | } |
| 5778 | |
| 5779 | function getHash(url) { |
| 5780 | var index = url.indexOf('#'); |
| 5781 | return index === -1 ? '' : url.substr(index); |
| 5782 | } |
| 5783 | |
| 5784 | /** |
| 5785 | * @private |
| 5786 | * Note: this method is used only by scenario runner |
| 5787 | * TODO(vojta): prefix this method with $$ ? |
| 5788 | * @param {function()} callback Function that will be called when no outstanding request |
| 5789 | */ |
| 5790 | self.notifyWhenNoOutstandingRequests = function(callback) { |
| 5791 | if (outstandingRequestCount === 0) { |
| 5792 | callback(); |
| 5793 | } else { |
| 5794 | outstandingRequestCallbacks.push(callback); |
| 5795 | } |
| 5796 | }; |
| 5797 |
nothing calls this directly
no test coverage detected