Mercurial > hg > cmmr2012-drupal-site
diff vendor/jcalderonzumba/gastonjs/src/Client/browser.js @ 2:5311817fb629
Theme updates
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 13:19:18 +0000 |
parents | c75dbcec494b |
children |
line wrap: on
line diff
--- a/vendor/jcalderonzumba/gastonjs/src/Client/browser.js Thu Jul 05 15:32:06 2018 +0100 +++ b/vendor/jcalderonzumba/gastonjs/src/Client/browser.js Tue Jul 10 13:19:18 2018 +0000 @@ -28,6 +28,7 @@ this.height = height || 768; this.pages = []; this.js_errors = (typeof jsErrors === 'boolean') ? jsErrors : true; + this._resourceTimeout = false; this._debug = false; this._counter = 0; this.resetPage(); @@ -35,7 +36,6 @@ /** * Resets the browser to a clean slate - * @return {Function} */ Browser.prototype.resetPage = function () { var _ref; @@ -55,20 +55,44 @@ phantom.clearCookies(); } - this.page = this.currentPage = new Poltergeist.WebPage; + this.page = this.currentPage = new Poltergeist.WebPage(null, this); this.page.setViewportSize({ width: this.width, height: this.height }); - this.page.handle = "" + (this._counter++); - this.pages.push(this.page); + }; - return this.page.onPageCreated = function (newPage) { - var page; - page = new Poltergeist.WebPage(newPage); - page.handle = "" + (self._counter++); - return self.pages.push(page); - }; + /** + * Adds given newly opened Poltergeist.WebPage to the list of available windows/frames + * consulted by methods getPageByHandle, window_handle, window_handles, switch_to_window and close_window. + * + * @param {WebPage} page + */ + Browser.prototype.registerPage = function (page) { + if (!('handle' in page)) + { + page.handle = "" + (this._counter++); + this.pages.push(page); + } + }; + + /** + * Removes given closed Poltergeist.WebPage from the list of available windows/frames + * consulted by methods getPageByHandle, window_handle, window_handles, switch_to_window and close_window. + * + * @param {Poltergeist.WebPage} page + */ + Browser.prototype.unregisterPage = function (page) { + if (('handle' in page) && (page.handle !== null)) + { + for (var i = this.pages.length; i--;) { + if (page === this.pages[i]) { + this.pages.splice(i,1); + break; + } + } + page.handle = null; + } }; /** @@ -198,6 +222,14 @@ var prevUrl; var self = this; this.currentPage.state = 'loading'; + + if (this._resourceTimeout) { + this.currentPage._native.settings.resourceTimeout = this._resourceTimeout; + this.currentPage._native.onResourceTimeout = function (request) { + console.log('Response (#' + request.id + '): ' + JSON.stringify(request)); + }; + } + prevUrl = this.currentPage.source === null ? 'about:blank' : this.currentPage.currentUrl(); this.currentPage.open(url); if (/#/.test(url) && prevUrl.split('#')[0] === url.split('#')[0]) { @@ -687,6 +719,7 @@ /** * Closes the window given by handle name if possible + * NOTE: Closing a page in PhantomJS also closes new windows/frames opened from that page (QWebPage behaviour) * @param serverResponse * @param handle * @return {*} @@ -1154,6 +1187,22 @@ }; /** + * Sets proxy or unsets web proxy + * @param {Object} serverResponse Phantomjs response object associated to the client request + * @param {String} ip IP or host name, or null/'' to unset + * @param {Number} port port number + * @param {String} proxyType socks5 or anything else for http(s) + * @param {String} user optional username for proxy authentication + * @param {String} password optional password for proxy authentication + * @return {*} + * @see {@link https://github.com/ariya/phantomjs/pull/11829/commits/84c31822a2e5eba21fe42298ec27ec4ccab95667} + */ + Browser.prototype.set_proxy = function (serverResponse, ip, port, proxyType, user, password) { + phantom.setProxy(ip, port, proxyType, user, password); + return this.serverSendResponse(true, serverResponse); + }; + + /** * US19: DONE * Sets a basic authentication credential to access a page * THIS SHOULD BE USED BEFORE accessing a page @@ -1239,6 +1288,18 @@ }; /** + * Sets the timeout in milliseconds, after which any resource requested will stop + * trying and proceed with other parts of the page + * @param serverResponse + * @param value + * @return {*} + */ + Browser.prototype.set_resource_timeout = function (serverResponse, value) { + this._resourceTimeout = value; + return this.serverSendResponse(true, serverResponse); + }; + + /** * Sets the urlBlacklist for the given urls as parameters * @return {boolean} */