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ACF;;;SAgBQ,eAAG;AACV,aAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACrC;;;WA8GgB,oBAAC,CAAC,EAAE,CAAC,EAAE;AACtB,aAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,YAAY,CAAC;KACpD;;;SAjKoB,IAAI;GAAS,KAAK,CAkKxC,CAAC","file":"tabs.js","sourcesContent":["// Tab management.\n\nconst _ = require('lodash');\nconst createHistory = require('./history');\n\n\nmodule.exports = class Tabs extends Array {\n\n constructor(browser) {\n super();\n this._current = null;\n this._browser = browser;\n this.length = 0;\n Object.defineProperty(this, 'length', { enumerable: false, writable: true });\n Object.defineProperty(this, '_browser', { enumerable: false, writable: true });\n Object.defineProperty(this, '_current', { enumerable: false, writable: true });\n }\n\n // Get the currently open tab\n get current() {\n return this._current;\n }\n\n // Sets the currently open tab\n // - Name - Pick existing window with this name\n // - Number - Pick existing window from tab position\n // - Window - Use this window\n set current(nameOrWindow) {\n const window = this.find(nameOrWindow);\n if (this._indexOf(window) < 0)\n return;\n if (!Tabs.sameWindow(this._current, window)) {\n if (this._current)\n this._browser.emit('inactive', this._current);\n this._current = window;\n this._browser.emit('active', this._current);\n }\n }\n\n // Returns window by index or name. Use this for window names that shadow\n // existing properties (e.g. tabs['open'] is a function, use\n find(nameOrWindow) {\n if (this.propertyIsEnumerable(nameOrWindow))\n return this[nameOrWindow];\n const byName = _.find(this, { name: nameOrWindow });\n if (byName)\n return byName;\n if (this._indexOf(nameOrWindow) >= 0)\n return nameOrWindow;\n return null;\n }\n\n // Index of currently selected tab.\n get index() {\n return this._indexOf(this._current);\n }\n\n // Opens and returns a tab. If an open window by the same name already exists,\n // opens this window in the same tab. Omit name or use '_blank' to always open\n // a new tab.\n //\n // name - Window name (optional)\n // opener - Opening window (window.open call)\n // referer - Referrer\n // url - Set document location to this URL upon opening\n // html - Document contents (browser.load)\n open(options = {}) {\n\n // If name window in open tab, reuse that tab. Otherwise, open new window.\n const named = options.name && this.find(options.name.toString());\n if (named) {\n // Select this as the currently open tab. Changing the location would then\n // select a different window.\n this._current = named;\n if (options.url)\n this._current.location = options.url;\n return this._current;\n }\n\n // When window changes we need to change tab slot. We can't keep the index\n // around, since tab order changes, so we look up the currently known\n // active window and switch that around.\n let active = null;\n const open = createHistory(this._browser, (window)=> {\n // Focus changes to different window, make it the active window\n if (!Tabs.sameWindow(window, active)) {\n const index = this._indexOf(active);\n if (index >= 0)\n this[index] = window;\n this.current = active = window;\n }\n if (window)\n this._browser._eventLoop.setActiveWindow(window);\n });\n\n const name = options.name === '_blank' ? '' : (options.name || '');\n options.name = name;\n const window = open(options);\n this.push(window);\n if (name && (this.propertyIsEnumerable(name) || !this[name]))\n this[name] = window;\n // Select this as the currently open tab\n this.current = active = window;\n return window;\n }\n\n // Close an open tab.\n //\n // With no argument, closes the currently open tab (tabs.current).\n //\n // Argument can be the window, window name or tab position (same as find).\n close(nameOrWindow) {\n const window = nameOrWindow ? this.find(nameOrWindow) : this._current;\n if (this._indexOf(window) >= 0)\n window.close();\n }\n\n // Closes all open tabs/windows.\n closeAll() {\n const tabs = this.slice();\n this._current = null;\n for (let tab of tabs)\n tab.close();\n }\n\n // Dump list of all open tabs to stdout or output stream.\n dump(output = process.stdout) {\n if (this.length === 0) {\n output.write('No open tabs.\\n');\n return;\n }\n for (let tab of this)\n output.write(`Window ${tab.name || 'unnamed'} open to ${tab.location.href}\\n`);\n }\n\n\n // Find the position of this window in the tabs array\n _indexOf(window) {\n if (!window)\n return -1;\n return this.slice().map(tab => tab._globalProxy).indexOf(window._globalProxy);\n }\n\n // Called when window closed to remove it from tabs list.\n _closed(window) {\n const index = this._indexOf(window);\n if (index >= 0) {\n this._browser.emit('inactive', window);\n\n this.splice(index, 1);\n if (this.propertyIsEnumerable(window.name))\n delete this[window.name];\n\n // If we closed the currently open tab, need to select another window.\n if (Tabs.sameWindow(window, this._current)) {\n // Don't emit inactive event for closed window.\n this._current = this[index - 1] || this[0];\n if (this._current)\n this._browser.emit('active', this._current);\n }\n }\n\n }\n\n // Determine if two windows are the same\n static sameWindow(a, b) {\n return a && b && a._globalProxy === b._globalProxy;\n }\n};\n"]}