/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ 		}
/******/ 	};
/******/
/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 		}
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};
/******/
/******/ 	// create a fake namespace object
/******/ 	// mode & 1: value is a module id, require it
/******/ 	// mode & 2: merge all properties of value into the ns
/******/ 	// mode & 4: return value when already ns object
/******/ 	// mode & 8|1: behave like require
/******/ 	__webpack_require__.t = function(value, mode) {
/******/ 		if(mode & 1) value = __webpack_require__(value);
/******/ 		if(mode & 8) return value;
/******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ 		var ns = Object.create(null);
/******/ 		__webpack_require__.r(ns);
/******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ 		return ns;
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = "./src/background/index.ts");
/******/ })
/************************************************************************/
/******/ ({

/***/ "./src/background/_infra/AifexServiceHTTP.ts":
/*!***************************************************!*\
  !*** ./src/background/_infra/AifexServiceHTTP.ts ***!
  \***************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Website_1 = __importDefault(__webpack_require__(/*! ../domain/Website */ "./src/background/domain/Website.ts"));
const CheckList_1 = __webpack_require__(/*! ../domain/CheckList */ "./src/background/domain/CheckList.ts");
const Session_1 = __importDefault(__webpack_require__(/*! ../domain/Session */ "./src/background/domain/Session.ts"));
const AifexPluginInfo_1 = __importDefault(__webpack_require__(/*! ../domain/AifexPluginInfo */ "./src/background/domain/AifexPluginInfo.ts"));
class AifexServiceHTTP {
    getSession(sessionId) {
        return fetch(`${"http://localhost:5006"}/session/${sessionId}`)
            .then((response) => {
            if (!response.ok) {
                throw new Error(response.statusText);
            }
            return response.json();
        })
            .then((session) => {
            return new Session_1.default(session.id, session.webSite.id, session.baseURL);
        });
    }
    getWebSite(webSiteId) {
        return fetch(`${"http://localhost:5005"}/website/${webSiteId}`)
            .then((response) => {
            if (!response.ok) {
                throw new Error(response.statusText);
            }
            return response.json();
        })
            .then(websiteData => {
            return new Website_1.default(websiteData.id, websiteData.name, websiteData.mappingList);
        });
    }
    getProbabilityMap(connection, exploration) {
        return new Promise((resolve, reject) => {
            const body = {
                interactionList: exploration.toJSON(),
            };
            const option = {
                method: "POST",
                body: JSON.stringify(body),
                headers: { "Content-Type": "application/json" },
            };
            fetch(`${"http://localhost:5007"}/model/${connection.modelId}/getprobabilitymap`, option).then((response) => {
                if (!response.ok) {
                    reject(response);
                }
                return response.json();
            })
                .then((jsonMap) => {
                return resolve(new Map(jsonMap));
            })
                .catch((error) => {
                reject(error);
            });
        });
    }
    addExploration(connection, testerName, exploration) {
        const body = {
            testerName,
            interactionList: exploration.toJSON(),
        };
        const option = {
            method: "POST",
            body: JSON.stringify(body),
            headers: { "Content-Type": "application/json" },
        };
        return fetch(`${"http://localhost:5006"}/session/${connection.sessionId}/exploration/add`, option).then((response) => {
            if (!response.ok) {
                throw new Error(response.statusText);
            }
            return response.json();
        });
    }
    getCommentList(connection, exploration) {
        const body = {
            interactionList: exploration.toJSON()
        };
        const option = {
            method: "POST",
            body: JSON.stringify(body),
            headers: { "Content-Type": "application/json" },
        };
        return fetch(`${"http://localhost:5007"}/model/${connection.modelId}/getcommentlist`, option).then((response) => {
            if (!response.ok) {
                throw new Error(response.statusText);
            }
            return response.json();
        });
    }
    addScreenshotList(connection, explorationNumber, list) {
        const screenshotList = list.map((screenshot) => {
            screenshot.sessionId = connection.sessionId;
            screenshot.explorationNumber = explorationNumber;
            return screenshot;
        });
        const body = {
            screenshotList,
        };
        const option = {
            method: "POST",
            body: JSON.stringify(body),
            headers: { "Content-Type": "application/json" },
        };
        return fetch(`${"http://localhost:5006"}/session/addscreenshotlist`, option).then((response) => {
            if (!response.ok) {
                throw new Error(response.statusText);
            }
            return response.json();
        });
    }
    addVideo(connection, explorationNumber, video) {
        let fd = new FormData();
        fd.append('video', video, 'video.webm');
        const option = {
            method: "POST",
            body: fd
        };
        return fetch(`${"http://localhost:5006"}/session/addVideo/${connection.sessionId}/${explorationNumber}`, option).then((response) => {
            if (!response.ok) {
                throw new Error(response.statusText);
            }
            return response.json();
        });
    }
    getPluginInfo() {
        const option = {
            method: "GET",
            headers: { "Content-Type": "application/json" },
        };
        return fetch(`${"http://localhost"}/plugin-info`, option)
            .then(response => {
            if (!response.ok) {
                throw new Error(response.statusText);
            }
            return response.json();
        })
            .then(details => {
            details.url = `${"http://localhost"}/download`;
            return new AifexPluginInfo_1.default(details.version, details.name, details.description, details.url);
        });
    }
    getObjectiveCheckList(connection) {
        const option = {
            method: "GET",
            headers: { "Content-Type": "application/json" },
        };
        return fetch(`${"http://localhost:5010"}/objective/checklist/${connection.sessionId}`, option)
            .then((response) => {
            if (!response.ok) {
                throw new Error(response.statusText);
            }
            return response.text();
        })
            .then(result => {
            if (!result) {
                return new CheckList_1.CheckList([]);
            }
            const dataJSON = JSON.parse(result);
            const objectives = dataJSON.objectiveList.map(objectiveData => {
                switch (objectiveData.type) {
                    case "step":
                        return new CheckList_1.StepObjective(objectiveData.id, objectiveData.name, false, objectiveData.text);
                    default:
                        return Promise.reject("Invalid objective " + objectiveData);
                }
            });
            return new CheckList_1.CheckList(objectives);
        });
    }
    evaluateSequence(connection, exploration) {
        return new Promise((resolve, reject) => {
            const eventList = exploration.actions.map(action => action.toString());
            const option = {
                method: "POST",
                body: JSON.stringify({
                    sessionId: connection.sessionId,
                    eventList: eventList
                }),
                headers: { "Content-Type": "application/json" },
            };
            fetch(`${"http://localhost:5010"}/objective/evaluateSequence`, option).then((response) => {
                if (!response.ok) {
                    throw new Error(response.statusText);
                }
                return response.json();
            })
                .then(result => {
                console.log(result);
                resolve(result.evaluation);
            })
                .catch((error) => {
                reject(error);
            });
        });
    }
}
exports.default = AifexServiceHTTP;


/***/ }),

/***/ "./src/background/_infra/ChromeBrowserService.ts":
/*!*******************************************************!*\
  !*** ./src/background/_infra/ChromeBrowserService.ts ***!
  \*******************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ChromePromise_1 = __webpack_require__(/*! ./ChromePromise */ "./src/background/_infra/ChromePromise.ts");
const ChromeWindowOption_1 = __importDefault(__webpack_require__(/*! ./ChromeWindowOption */ "./src/background/_infra/ChromeWindowOption.ts"));
const DEFAULT_WINDOW_OPTIONS = { url: 'https://www.aifex.fr' };
class ChromeBrowserService {
    constructor() {
        this.recorder = undefined;
        this.stream = undefined;
        this.recordedChunks = [];
    }
    getExtensionVesion() {
        return chrome.runtime.getManifest().version;
    }
    createWindow(url) {
        const options = Object.assign(DEFAULT_WINDOW_OPTIONS, { url });
        const chromeOptions = new ChromeWindowOption_1.default(options);
        return ChromePromise_1.createWindow(chromeOptions)
            .then(window => {
            return window.id;
        });
    }
    drawAttentionToWindow(windowId) {
        return ChromePromise_1.getWindowById(windowId)
            .then(_window => {
            return ChromePromise_1.updateWindowById(windowId, { drawAttention: true, focused: true });
        });
    }
    closeWindow(windowId) {
        return ChromePromise_1.removeWindowById(windowId);
    }
    runScript(tabId) {
        return ChromePromise_1.executeTabScript(tabId);
    }
    restartWindow(windowId, url) {
        let tabIds;
        return ChromePromise_1.getWindowById(windowId)
            .then((window) => {
            return window.tabs;
        })
            .then((tabs) => {
            tabIds = tabs.map(tab => tab.id);
            return ChromePromise_1.createTab({ windowId, index: 0, url });
        })
            .then(() => {
            return ChromePromise_1.removeTabs(tabIds);
        });
    }
    takeScreenshot() {
        return ChromePromise_1.takeScreenshot();
    }
    attachWindowCreatedHandler(handler) {
        chrome.windows.onCreated.addListener((window) => {
            handler(window.id);
        });
    }
    attachWindowRemovedHandler(handler) {
        chrome.windows.onRemoved.addListener(handler);
    }
    attachTabCreatedHandler(handler) {
        chrome.tabs.onCreated.addListener((tab) => {
            handler(tab.id, tab.windowId);
        });
    }
    attachTabRemovedHandler(handler) {
        chrome.tabs.onRemoved.addListener((tabId, removeInfo) => {
            handler(tabId, removeInfo.windowId);
        });
    }
    attachTabDetachedHandler(handler) {
        chrome.tabs.onDetached.addListener((tabId, detachInfo) => {
            handler(tabId, detachInfo.oldWindowId);
        });
    }
    attachTabAttachedHandler(handler) {
        chrome.tabs.onAttached.addListener((tabId, attachInfo) => {
            handler(tabId, attachInfo.newWindowId);
        });
    }
    attachTabActivatedHandler(handler) {
        chrome.tabs.onActivated.addListener((activeInfo) => {
            handler(activeInfo.tabId, activeInfo.windowId);
        });
    }
    attachOnDomLoadedHandler(handler) {
        chrome.webNavigation.onDOMContentLoaded.addListener(details => {
            const NAVIGATION_OCCURS_IN_TOP_FRAME = 0;
            if (details.frameId === NAVIGATION_OCCURS_IN_TOP_FRAME) {
                handler(details.tabId);
            }
        });
    }
    attachOnCommittedHandler(handler) {
        chrome.webNavigation.onDOMContentLoaded.addListener(details => {
            const NAVIGATION_OCCURS_IN_TOP_FRAME = 0;
            if (details.frameId === NAVIGATION_OCCURS_IN_TOP_FRAME) {
                handler(details.tabId);
            }
        });
    }
}
exports.default = ChromeBrowserService;


/***/ }),

/***/ "./src/background/_infra/ChromePromise.ts":
/*!************************************************!*\
  !*** ./src/background/_infra/ChromePromise.ts ***!
  \************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.takeScreenshot = exports.sendMessageToTab = exports.executeTabScript = exports.highLightTabs = exports.removeTabs = exports.createTab = exports.removeWindowById = exports.getTabById = exports.updateWindowById = exports.getWindowById = exports.getCurrentWindow = exports.createWindow = void 0;
function createWindow(options) {
    return new Promise((resolve, reject) => {
        chrome.windows.create(options, (window) => {
            const error = chrome.runtime.lastError;
            if (error) {
                reject(error);
            }
            else {
                resolve(window);
            }
        });
    });
}
exports.createWindow = createWindow;
function getCurrentWindow() {
    return new Promise((resolve, reject) => {
        chrome.runtime.sendMessage({
            msg: "getWindowId"
        }, undefined, (windowId) => {
            const error = chrome.runtime.lastError;
            if (error) {
                reject(error);
            }
            else {
                chrome.windows.get(windowId, { populate: true }, (window) => {
                    const error = chrome.runtime.lastError;
                    if (error) {
                        reject(error);
                    }
                    resolve(window);
                });
            }
        });
    });
}
exports.getCurrentWindow = getCurrentWindow;
function getWindowById(windowId) {
    return new Promise((resolve, reject) => {
        chrome.windows.get(windowId, { populate: true }, (window) => {
            const error = chrome.runtime.lastError;
            if (error) {
                reject(error);
            }
            else {
                resolve(window);
            }
        });
    });
}
exports.getWindowById = getWindowById;
function updateWindowById(windowId, options) {
    return new Promise((resolve, reject) => {
        chrome.windows.update(windowId, options, (window) => {
            const error = chrome.runtime.lastError;
            if (error) {
                reject(error);
            }
            else {
                resolve();
            }
        });
    });
}
exports.updateWindowById = updateWindowById;
function getTabById(tabId) {
    return new Promise((resolve, reject) => {
        chrome.tabs.get(tabId, (tab) => {
            const error = chrome.runtime.lastError;
            if (error) {
                reject(error);
            }
            else {
                resolve(tab);
            }
        });
    });
}
exports.getTabById = getTabById;
function removeWindowById(windowId) {
    return new Promise((resolve, reject) => {
        chrome.windows.remove(windowId, () => {
            const error = chrome.runtime.lastError;
            if (error) {
                reject(error);
            }
            else {
                resolve();
            }
        });
    });
}
exports.removeWindowById = removeWindowById;
function createTab(options) {
    return new Promise((resolve, reject) => {
        chrome.tabs.create(options, (tab) => {
            const error = chrome.runtime.lastError;
            if (error) {
                reject(error);
            }
            else {
                resolve(tab);
            }
        });
    });
}
exports.createTab = createTab;
function removeTabs(tabIds) {
    return new Promise((resolve, reject) => {
        chrome.tabs.remove(tabIds, () => {
            const error = chrome.runtime.lastError;
            if (error) {
                reject(error);
            }
            else {
                resolve();
            }
        });
    });
}
exports.removeTabs = removeTabs;
function highLightTabs(tabIds) {
    return new Promise((resolve, reject) => {
        chrome.tabs.highlight({ tabs: tabIds }, () => {
            const error = chrome.runtime.lastError;
            if (error) {
                reject(error);
            }
            else {
                resolve();
            }
        });
    });
}
exports.highLightTabs = highLightTabs;
function executeTabScript(tabId) {
    console.log('executre script for id:', tabId);
    return new Promise((resolve, reject) => {
        chrome.tabs.executeScript(tabId, { file: 'tabScript.js' }, () => {
            const error = chrome.runtime.lastError;
            if (error) {
                const errorMsg = error.message;
                const chromeStartPage = 'Cannot access contents of url "chrome-search://local-ntp/local-ntp.html';
                const chromeExtensionPage = 'Cannot access a chrome:// URL';
                if (errorMsg.startsWith(chromeStartPage) || errorMsg.startsWith(chromeExtensionPage)) {
                    resolve(false);
                }
                else {
                    reject(errorMsg);
                }
            }
            else {
                resolve(true);
            }
        });
    });
}
exports.executeTabScript = executeTabScript;
function sendMessageToTab(message = {}, messageKind, tabId) {
    const messageData = Object.assign(message, { kind: messageKind });
    return new Promise((resolve, reject) => {
        chrome.tabs.sendMessage(tabId, messageData, undefined, (response) => {
            const error = chrome.runtime.lastError;
            if (error) {
                reject(error);
            }
            else {
                resolve(response);
            }
        });
    });
}
exports.sendMessageToTab = sendMessageToTab;
function takeScreenshot() {
    return new Promise((resolve, reject) => {
        chrome.tabs.captureVisibleTab(this.WindowId, { format: "jpeg", quality: 100 }, dataImage => {
            const error = chrome.runtime.lastError;
            if (error) {
                console.error(error);
                reject(error);
            }
            else {
                resolve(dataImage);
            }
        });
    });
}
exports.takeScreenshot = takeScreenshot;


/***/ }),

/***/ "./src/background/_infra/ChromeTabScriptService.ts":
/*!*********************************************************!*\
  !*** ./src/background/_infra/ChromeTabScriptService.ts ***!
  \*********************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const ChromePromise_1 = __webpack_require__(/*! ./ChromePromise */ "./src/background/_infra/ChromePromise.ts");
class ChromeTabScriptService {
    reload(tabId, state) {
        const MESSAGE_KIND = "reload";
        return ChromePromise_1.sendMessageToTab(state, MESSAGE_KIND, tabId);
    }
    startExploration(tabId, state) {
        const MESSAGE_KIND = "explorationStarted";
        return ChromePromise_1.sendMessageToTab(state, MESSAGE_KIND, tabId);
    }
    stopExploration(tabId, state) {
        const MESSAGE_KIND = "explorationStopped";
        return ChromePromise_1.sendMessageToTab(state, MESSAGE_KIND, tabId);
    }
}
exports.default = ChromeTabScriptService;


/***/ }),

/***/ "./src/background/_infra/ChromeWindowOption.ts":
/*!*****************************************************!*\
  !*** ./src/background/_infra/ChromeWindowOption.ts ***!
  \*****************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class ChromeWindowOption {
    constructor(options) {
        if (options.url) {
            this.url = options.url;
        }
        if (options.left) {
            this.left = options.left;
        }
        if (options.top) {
            this.top = options.top;
        }
        if (options.incognito) {
            this.incognito = options.incognito;
        }
        if (options.height) {
            this.height = options.height;
        }
        if (options.width) {
            this.width = options.width;
        }
        if (options.type) {
            this.type = options.type;
        }
    }
}
exports.default = ChromeWindowOption;


/***/ }),

/***/ "./src/background/_ui/HandlerOfMessageSentByPopup.ts":
/*!***********************************************************!*\
  !*** ./src/background/_ui/HandlerOfMessageSentByPopup.ts ***!
  \***********************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class HandlerOfMessageSentByPopup {
    constructor(application) {
        this._application = application;
        chrome.runtime.onMessage.addListener(this.handleMessage.bind(this));
    }
    handleMessage(msg, sender, sendResponse) {
        switch (msg.kind) {
            case "checkDeprecated": {
                this._application.makeCompatibilityCheck()
                    .then((compatibilityCheck) => {
                    sendResponse(compatibilityCheck);
                })
                    .catch((error) => {
                    console.log(error);
                    sendResponse(error);
                });
                return true;
            }
            case "getStateForPopup": {
                sendResponse(this._application.getStateForPopup());
                return true;
            }
            case "connect": {
                if (!msg.connectionCode) {
                    sendResponse({ error: "connectionCode required" });
                    return;
                }
                const [sessionId, modelId] = msg.connectionCode.split("$");
                this._application
                    .connect(sessionId, modelId)
                    .then(() => sendResponse("ok"))
                    .catch((error) => console.error(error));
                return true;
            }
            case "disconnect": {
                this._application
                    .disconnect()
                    .then(() => {
                    sendResponse("ok");
                })
                    .catch((error) => {
                    sendResponse({ error });
                    console.error(error);
                });
                return true;
            }
            case "reloadWebSite": {
                this._application
                    .reloadWebsite()
                    .then(() => {
                    sendResponse("ok");
                })
                    .catch((error) => {
                    console.log(error);
                    sendResponse(error);
                });
                return true;
            }
            case "startExploration": {
                this._application
                    .startExploration()
                    .then(() => {
                    sendResponse(this._application.getStateForPopup());
                })
                    .catch((error) => {
                    console.log(error);
                    sendResponse(error);
                });
                return true;
            }
            case "stopExploration": {
                this._application
                    .stopExploration()
                    .then(() => {
                    sendResponse(this._application.getStateForPopup());
                })
                    .catch((error) => {
                    console.log(error);
                    sendResponse(error);
                });
                return true;
            }
            case "removeExploration": {
                this._application
                    .removeExploration()
                    .then(() => {
                    sendResponse(this._application.getStateForPopup());
                }).catch((error) => {
                    console.log(error);
                    sendResponse(error);
                });
                return true;
            }
            case "changeTesterName": {
                this._application.changeTesterName(msg.testerName);
                sendResponse(this._application.getStateForPopup());
                return true;
            }
            case "setIsTabScriptDiplayingComments": {
                this._application.setIsTabScriptDisplayingComments(msg.isTabScriptDisplayingComments);
                sendResponse(this._application.getStateForPopup());
                return true;
            }
            case "restartExploration": {
                this._application
                    .restartExploration()
                    .then(() => {
                    sendResponse(this._application.getStateForPopup());
                })
                    .catch((error) => {
                    console.log(error);
                    sendResponse(error);
                });
                return true;
            }
            case "pushComment": {
                const { kind, value } = msg;
                this._application.addCommentToExploration(kind, value);
                sendResponse("ok");
                return true;
            }
            case "takeScreenshot": {
                this._application.takeScreenShot();
                return true;
            }
            case "openWindow": {
                this._application.drawAttention();
                return true;
            }
            case "setRecordMediaStatus": {
                return true;
            }
        }
    }
}
exports.default = HandlerOfMessageSentByPopup;


/***/ }),

/***/ "./src/background/_ui/HandlerOfMessageSentByTabScript.ts":
/*!***************************************************************!*\
  !*** ./src/background/_ui/HandlerOfMessageSentByTabScript.ts ***!
  \***************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class HandlerOfMessageSentByTabScript {
    constructor(application) {
        this._application = application;
        chrome.runtime.onMessage.addListener(this.handleMessage.bind(this));
    }
    handleMessage(msg, sender, sendResponse) {
        switch (msg.kind) {
            case "getStateForTabScript": {
                sendResponse(this._application.getStateForTabScript());
                return true;
            }
            case "getProbabilities": {
                console.log('getProbabilities');
                this._application.getProbabilities()
                    .then((response) => {
                    if (!response) {
                        console.log('getProbabilities : no answer');
                        sendResponse();
                        return true;
                    }
                    console.log('getProbabilities : answer');
                    sendResponse({
                        state: response.state,
                        probabilityMap: Array.from(response.probabilityMap),
                        followedProbabilityMap: response.followedProbabilityMap ? Array.from(response.followedProbabilityMap) : undefined,
                    });
                })
                    .catch((error) => {
                    console.log('error:', error);
                    sendResponse();
                });
                return true;
            }
            case "getComments": {
                this._application.getComments()
                    .then((response) => {
                    if (!response) {
                        sendResponse();
                        return true;
                    }
                    sendResponse({
                        state: response.state,
                        commentDistributionList: response.commentDistributionList
                    });
                })
                    .catch((error) => {
                    console.log(error);
                    sendResponse();
                });
                return true;
            }
            case "pushAction": {
                const action = msg.action;
                this._application.addActionToExploration(action.prefix, action.suffix);
                sendResponse("ok");
                return true;
            }
            case "upComment": {
                this._application.upComment(msg.type, msg.value);
                sendResponse("ok");
                return true;
            }
            case "setPopupCommentPosition": {
                this._application.setPopupCommentPosition(msg.popupCommentPosition);
                sendResponse("ok");
                return true;
            }
        }
    }
}
exports.default = HandlerOfMessageSentByTabScript;


/***/ }),

/***/ "./src/background/application/BackgroundApplication.ts":
/*!*************************************************************!*\
  !*** ./src/background/application/BackgroundApplication.ts ***!
  \*************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Background_1 = __importDefault(__webpack_require__(/*! ../domain/Background */ "./src/background/domain/Background.ts"));
const ConnectionCode_1 = __importDefault(__webpack_require__(/*! ../domain/ConnectionCode */ "./src/background/domain/ConnectionCode.ts"));
class BackgroundApplication {
    constructor(browserService, aifexService, tabScriptService) {
        this._background = new Background_1.default(aifexService, browserService, tabScriptService);
    }
    getStateForPopup() {
        return this._background.getStateForPopup();
    }
    makeCompatibilityCheck() {
        return this._background.makeCompatibilityCheck();
    }
    connect(sessionId, modelId) {
        const connectionCode = new ConnectionCode_1.default(sessionId, modelId);
        return this._background.connect(connectionCode);
    }
    disconnect() {
        return this._background.disconnect();
    }
    reloadWebsite() {
        return this._background.reloadWebsite();
    }
    startExploration() {
        return this._background.startExploration();
    }
    stopExploration() {
        return this._background.stopExploration();
    }
    changeTesterName(newName) {
        this._background.changeTesterName(newName);
    }
    setIsTabScriptDisplayingComments(isDisplaying) {
        this._background.setIsTabScriptDisplayingComments(isDisplaying);
    }
    restartExploration() {
        return this._background.restartExploration();
    }
    removeExploration() {
        return this._background.removeExploration();
    }
    addCommentToExploration(kind, message) {
        this._background.addCommentToExploration(kind, message);
    }
    takeScreenShot() {
        return this._background.takeScreenShot();
    }
    drawAttention() {
        return this._background.drawAttention();
    }
    setRecordMedia(recordMedia) {
        return this._background.setRecordMedia(recordMedia);
    }
    getStateForTabScript() {
        return this._background.getStateForTabScript();
    }
    getProbabilities() {
        return this._background.getProbabilities();
    }
    getComments() {
        return this._background.getComments();
    }
    addActionToExploration(kind, value) {
        return this._background.addActionToExploration(kind, value);
    }
    upComment(kind, value) {
        return this._background.upComment(kind, value);
    }
    setPopupCommentPosition(position) {
        return this._background.setPopupCommentPosition(position);
    }
}
exports.default = BackgroundApplication;


/***/ }),

/***/ "./src/background/domain/Action.ts":
/*!*****************************************!*\
  !*** ./src/background/domain/Action.ts ***!
  \*****************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class Action {
    constructor(kind, value, index = 0) {
        if (kind === undefined || kind === null) {
            throw new Error('cannot create action without a kind');
        }
        this.kind = kind;
        this.value = value;
        this.index = index;
    }
    toString() {
        if (this.value) {
            return `${this.kind}$${this.value}`;
        }
        else {
            return this.kind;
        }
    }
}
exports.default = Action;


/***/ }),

/***/ "./src/background/domain/AifexPluginInfo.ts":
/*!**************************************************!*\
  !*** ./src/background/domain/AifexPluginInfo.ts ***!
  \**************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class AifexPluginInfo {
    constructor(version, name, description, url) {
        this.version = version;
        this.name = name;
        this.description = description;
        this.url = url;
    }
}
exports.default = AifexPluginInfo;


/***/ }),

/***/ "./src/background/domain/Background.ts":
/*!*********************************************!*\
  !*** ./src/background/domain/Background.ts ***!
  \*********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const CompatibilityCheck_1 = __importDefault(__webpack_require__(/*! ./CompatibilityCheck */ "./src/background/domain/CompatibilityCheck.ts"));
const Exploration_1 = __importDefault(__webpack_require__(/*! ./Exploration */ "./src/background/domain/Exploration.ts"));
const StateForPopup_1 = __importDefault(__webpack_require__(/*! ./StateForPopup */ "./src/background/domain/StateForPopup.ts"));
const WindowManager_1 = __importDefault(__webpack_require__(/*! ./WindowManager */ "./src/background/domain/WindowManager.ts"));
const StateForTabScript_1 = __importDefault(__webpack_require__(/*! ./StateForTabScript */ "./src/background/domain/StateForTabScript.ts"));
const MediaRecorderManager_1 = __importDefault(__webpack_require__(/*! ./MediaRecorderManager */ "./src/background/domain/MediaRecorderManager.ts"));
class Background {
    constructor(aifexService, browserService, tabScriptService) {
        this._aifexService = aifexService;
        this._browserService = browserService;
        this._tabScriptService = tabScriptService;
        this._windowManager = new WindowManager_1.default(browserService);
        this._windowManager.addOnWindoRemovedListener(this.onManagedWindowRemoved.bind(this));
        this._exploration = new Exploration_1.default();
        this._testerName = "anonymous";
        this._isRecording = false;
        this._popupCommentPosition = { x: "75%", y: "75%" };
        this._isTabScriptDisplayingComments = false;
        this._commentsUp = [];
        this._screenshotList = [];
        this._mediaRecordManager = new MediaRecorderManager_1.default();
    }
    makeCompatibilityCheck() {
        return this._aifexService.getPluginInfo()
            .then((pluginInfo) => {
            return new CompatibilityCheck_1.default(this._browserService.getExtensionVesion(), pluginInfo.version, pluginInfo.url);
        });
    }
    connect(connectionCode) {
        this._connectionCode = connectionCode;
        return this._aifexService.getSession(connectionCode.sessionId)
            .then((session) => {
            this._sessionBaseURL = session.baseURL;
            return session.webSiteId;
        })
            .then((webSiteId) => {
            return this._aifexService.getWebSite(webSiteId);
        })
            .then((webSite) => {
            this._webSite = webSite;
        })
            .then(() => {
            this._windowManager.createConnectedWindow(this._sessionBaseURL);
        });
    }
    disconnect() {
        this._connectionCode = undefined;
        this._sessionBaseURL = undefined;
        this._webSite = undefined;
        return this._windowManager.removeConnectedWindow();
    }
    onManagedWindowRemoved() {
        this._connectionCode = undefined;
        this._sessionBaseURL = undefined;
        this._webSite = undefined;
        this._exploration.reset();
        this._commentsUp = [];
        this._isRecording = false;
        this._isTabScriptDisplayingComments = false;
        this._testerName = "anonymous";
        this._screenshotList = [];
    }
    isConnected() {
        return this._connectionCode !== undefined;
    }
    reloadWebsite() {
        return this._aifexService.getWebSite(this._webSite.id)
            .then((webSite) => {
            this._webSite = webSite;
        })
            .then((_) => {
            const state = this.getStateForTabScript();
            const tabIds = this._windowManager.getConnectedTabId();
            console.log('background: reload will send:', tabIds);
            return Promise.all(tabIds.map(id => this._tabScriptService.reload(id, state)));
        })
            .then((_) => { });
    }
    drawAttention() {
        if (this._connectionCode) {
            let id = this._windowManager.getConnectedWindowId();
            if (id !== undefined && id !== null) {
                return this._browserService.drawAttentionToWindow(this._windowManager.getConnectedWindowId());
            }
            else {
                return Promise.resolve();
            }
        }
        else {
            return Promise.resolve();
        }
    }
    startExploration() {
        if (!this._isRecording) {
            this._exploration.reset();
            this._exploration.start();
            this._isRecording = true;
            const state = this.getStateForTabScript();
            const tabIds = this._windowManager.getConnectedTabId();
            return Promise.all(tabIds.map(id => this._tabScriptService.startExploration(id, state)))
                .then((_) => {
            });
        }
    }
    removeExploration() {
        if (this._isRecording) {
            this._exploration.reset();
            this._isRecording = false;
            const state = this.getStateForTabScript();
            const tabIds = this._windowManager.getConnectedTabId();
            return Promise.all(tabIds.map(id => this._tabScriptService.stopExploration(id, state)))
                .then((_) => {
            });
        }
    }
    getProbabilities() {
        if (!this._isRecording || this._exploration.length === 0) {
            return Promise.resolve();
        }
        if (!this._connectionCode) {
            return Promise.reject("Not connected to a model");
        }
        const promises = [];
        promises.push(this._aifexService.getProbabilityMap(this._connectionCode, this._exploration));
        return Promise.all(promises)
            .then((resultList) => {
            const [probabilityMap, followedProbabilityRaw,] = resultList;
            let followedProbabilityMap;
            if (followedProbabilityRaw) {
                followedProbabilityMap = followedProbabilityRaw;
            }
            return {
                state: this.getStateForTabScript(),
                probabilityMap,
                followedProbabilityMap,
            };
        });
    }
    getComments() {
        if (!this._isRecording || this._exploration.length === 0) {
            return Promise.resolve();
        }
        if (!this._connectionCode) {
            return Promise.reject("Not connected to a model");
        }
        return this._aifexService.getCommentList(this._connectionCode, this._exploration)
            .then((commentDistributionList) => {
            return {
                commentDistributionList,
                state: this.getStateForTabScript()
            };
        });
    }
    addActionToExploration(prefix, suffix) {
        if (this._isRecording) {
            this._exploration.addAction(prefix, suffix);
            this._commentsUp = [];
        }
    }
    addCommentToExploration(kind, message) {
        if (this._isRecording) {
            this._exploration.addComment(kind, message);
        }
    }
    upComment(kind, message) {
        if (this._isRecording) {
            if (!this._commentsUp.includes(message)) {
                this.addCommentToExploration(kind, message);
                this._commentsUp.push(message);
            }
        }
    }
    stopExploration() {
        this._exploration.addAction("end");
        const HAS_MORE_THAN_START_END_ACTIONS = this._exploration.length > 2;
        let sendExplorationPromise;
        if (this._isRecording && HAS_MORE_THAN_START_END_ACTIONS) {
            sendExplorationPromise = this.sendExploration();
        }
        else {
            sendExplorationPromise = Promise.resolve();
        }
        return sendExplorationPromise
            .then(() => {
            this._isRecording = false;
            this._exploration.reset();
            this._screenshotList = [];
            this._commentsUp = [];
        })
            .then(() => {
            const state = this.getStateForTabScript();
            const tabIds = this._windowManager.getConnectedTabId();
            return Promise.all(tabIds.map(id => this._tabScriptService.stopExploration(id, state)));
        })
            .then((_) => {
        });
    }
    restartExploration() {
        return this.stopExploration()
            .then(() => {
            this._windowManager.reloadConnectedWindow(this._sessionBaseURL);
        })
            .then(() => {
            return this.startExploration();
        })
            .catch((error) => {
            console.log(error);
        });
    }
    sendExploration() {
        const EXPLORATION_CONTAINS_START_ONLY = this._exploration.length === 1;
        if (!this._isRecording || EXPLORATION_CONTAINS_START_ONLY) {
            return Promise.resolve();
        }
        return this._aifexService.addExploration(this._connectionCode, this._testerName, this._exploration)
            .then((explorationNumber) => {
            this._aifexService.addScreenshotList(this._connectionCode, explorationNumber, this._screenshotList);
        });
    }
    evaluateChecklist() {
        return this._aifexService.evaluateSequence(this._connectionCode, this._exploration)
            .then(checklistEvaluation => {
            console.log(checklistEvaluation);
            return checklistEvaluation;
        });
    }
    changeTesterName(name) {
        this._testerName = name;
    }
    setIsTabScriptDisplayingComments(isTabScriptDisplayingComments) {
        this._isTabScriptDisplayingComments = isTabScriptDisplayingComments;
        const state = this.getStateForTabScript();
        const tabIds = this._windowManager.getConnectedTabId();
        Promise.all(tabIds.map(id => this._tabScriptService.reload(id, state)));
    }
    setPopupCommentPosition(position) {
        this._popupCommentPosition = position;
    }
    getStateForPopup() {
        let state = new StateForPopup_1.default();
        state.connection = this._connectionCode;
        state.isRecording = this._isRecording;
        state.testerName = this._testerName;
        state.isDisplayingComments = this._isTabScriptDisplayingComments;
        state.hasBaseURL = this._sessionBaseURL !== undefined;
        state.managedWindowId = this._windowManager.getConnectedWindowId();
        state.numberOfPerformedInteraction = this._exploration.length;
        return state;
    }
    getStateForTabScript() {
        let state = new StateForTabScript_1.default();
        state.isRecording = this._isRecording,
            state.isDisplayingComments = this._isTabScriptDisplayingComments,
            state.webSite = this._webSite;
        state.popupCommentPosition = this._popupCommentPosition;
        return state;
    }
    takeScreenShot() {
        return this._browserService.takeScreenshot().then(image => {
            this._screenshotList.push({
                image,
                interactionIndex: this._exploration.length - 1,
            });
        });
    }
    setRecordMedia(recordMedia) {
        if (recordMedia) {
            this._mediaRecordManager.startRecording();
        }
        else {
        }
        if (this._isRecording) {
            this.recordMedia();
        }
    }
    recordMedia() {
    }
}
exports.default = Background;


/***/ }),

/***/ "./src/background/domain/CheckList.ts":
/*!********************************************!*\
  !*** ./src/background/domain/CheckList.ts ***!
  \********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.CheckList = exports.StepObjective = exports.Objective = void 0;
class Objective {
    constructor(id, name, status, type, nextActions = [], nextGuards = []) {
        this.id = id;
        this.name = name;
        this.status = status;
        this.type = type;
        this.nextActions = nextActions;
        this.nextGuards = nextGuards;
    }
    static parseObjective(object) {
        if (object.type === "step") {
            return new StepObjective(object.id, object.name, object.status, object.text);
        }
        else {
            throw new Error("Invalid Objective data" + object.toStrin());
        }
    }
}
exports.Objective = Objective;
class StepObjective extends Objective {
    constructor(id, name, status, text) {
        super(id, name, status, "step");
        this.text = text;
    }
}
exports.StepObjective = StepObjective;
class CheckList {
    constructor(objectiveList = []) {
        this.objectiveList = objectiveList;
    }
    update(evaluationDataList) {
    }
    isFulfilled() {
        return this.objectiveList.every(objective => objective.status);
    }
}
exports.CheckList = CheckList;


/***/ }),

/***/ "./src/background/domain/Comment.ts":
/*!******************************************!*\
  !*** ./src/background/domain/Comment.ts ***!
  \******************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class Comment {
    constructor(kind, value, index) {
        this.kind = kind;
        this.value = value;
        this.index = index;
    }
}
exports.default = Comment;


/***/ }),

/***/ "./src/background/domain/CompatibilityCheck.ts":
/*!*****************************************************!*\
  !*** ./src/background/domain/CompatibilityCheck.ts ***!
  \*****************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class CompatibilityCheck {
    constructor(currentVersion, latestVersion, url) {
        this.currentVersion = currentVersion;
        this.latestVersion = latestVersion;
        this.url = url;
    }
}
exports.default = CompatibilityCheck;


/***/ }),

/***/ "./src/background/domain/ConnectionCode.ts":
/*!*************************************************!*\
  !*** ./src/background/domain/ConnectionCode.ts ***!
  \*************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class ConnectionCode {
    constructor(sessionId, modelId) {
        if (sessionId === null || sessionId === undefined) {
            throw new Error('cannot create connection without sessionId');
        }
        this.sessionId = sessionId;
        if (modelId === null || modelId === undefined) {
            throw new Error('cannot create connection without modelId');
        }
        this.modelId = modelId;
    }
    get code() {
        return this.sessionId + "$" + this.modelId;
    }
}
exports.default = ConnectionCode;


/***/ }),

/***/ "./src/background/domain/Exploration.ts":
/*!**********************************************!*\
  !*** ./src/background/domain/Exploration.ts ***!
  \**********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Comment_1 = __importDefault(__webpack_require__(/*! ./Comment */ "./src/background/domain/Comment.ts"));
const Action_1 = __importDefault(__webpack_require__(/*! ./Action */ "./src/background/domain/Action.ts"));
class Exploration {
    constructor() {
        this.interactions = [];
    }
    get length() {
        return this.interactions.length;
    }
    get isEmpty() {
        return this.interactions.length <= 1;
    }
    get actions() {
        return this.interactions.filter(interaction => interaction instanceof Action_1.default);
    }
    addAction(kind, value) {
        this.interactions.push(new Action_1.default(kind, value, this.interactions.length));
    }
    addComment(kind, value) {
        this.interactions.push(new Comment_1.default(kind, value, this.interactions.length));
    }
    reset() {
        this.interactions = [];
    }
    start() {
        if (this.actions.length === 0) {
            this.addAction("start");
        }
    }
    toJSON() {
        return this.interactions.map(interaction => {
            if (interaction instanceof Comment_1.default) {
                return ({
                    concreteType: "Comment",
                    kind: interaction.kind,
                    value: interaction.value
                });
            }
            else if (interaction instanceof Action_1.default) {
                return ({
                    concreteType: "Action",
                    kind: interaction.kind,
                    value: interaction.value
                });
            }
        });
    }
}
exports.default = Exploration;


/***/ }),

/***/ "./src/background/domain/MediaRecorderManager.ts":
/*!*******************************************************!*\
  !*** ./src/background/domain/MediaRecorderManager.ts ***!
  \*******************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class MediaRecorderManager {
    constructor() {
        this._streamedTabs = [];
        this._recordedChunks = [];
    }
    startRecording() {
    }
    pauseRecording() {
    }
    stopRecording() {
    }
    getRecordedChunks() {
    }
}
exports.default = MediaRecorderManager;


/***/ }),

/***/ "./src/background/domain/Session.ts":
/*!******************************************!*\
  !*** ./src/background/domain/Session.ts ***!
  \******************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class Session {
    constructor(id, webSiteId, baseURL) {
        if (id === null || id == undefined) {
            throw new Error('cannot create Session without id');
        }
        this.id = id;
        if (webSiteId === null || webSiteId == undefined) {
            throw new Error('cannot create Session without webSiteId');
        }
        this.webSiteId = webSiteId;
        this.baseURL = baseURL;
    }
}
exports.default = Session;


/***/ }),

/***/ "./src/background/domain/StateForPopup.ts":
/*!************************************************!*\
  !*** ./src/background/domain/StateForPopup.ts ***!
  \************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class StateForPopup {
    constructor() {
        this.isRecording = false;
        this.isDisplayingComments = false;
        this.hasBaseURL = false;
        this.numberOfPerformedInteraction = 0;
        this.testerName = "undefined";
    }
}
exports.default = StateForPopup;


/***/ }),

/***/ "./src/background/domain/StateForTabScript.ts":
/*!****************************************************!*\
  !*** ./src/background/domain/StateForTabScript.ts ***!
  \****************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class StateForTabScript {
    constructor() {
        this.isRecording = false;
        this.isDisplayingComments = false;
    }
}
exports.default = StateForTabScript;


/***/ }),

/***/ "./src/background/domain/Tab.ts":
/*!**************************************!*\
  !*** ./src/background/domain/Tab.ts ***!
  \**************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class Tab {
    constructor(id) {
        if (id === null || id === undefined || isNaN(id)) {
            throw new Error('cannot create ManagedTab without id');
        }
        this._id = id;
        this._isActivated = false;
        this._isConnected = false;
    }
    get id() {
        return this._id;
    }
    get isConnected() {
        return this._isConnected;
    }
    get isActivated() {
        return this._isActivated;
    }
    activate() {
        this._isActivated = true;
    }
    deActivate() {
        this._isActivated = false;
    }
    connect() {
        this._isConnected = true;
    }
    disconnect() {
        this._isConnected = false;
    }
}
exports.default = Tab;


/***/ }),

/***/ "./src/background/domain/Website.ts":
/*!******************************************!*\
  !*** ./src/background/domain/Website.ts ***!
  \******************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
class WebSite {
    constructor(id, name, mappingList) {
        this.id = id;
        this.name = name;
        this.mappingList = mappingList;
    }
}
exports.default = WebSite;


/***/ }),

/***/ "./src/background/domain/Window.ts":
/*!*****************************************!*\
  !*** ./src/background/domain/Window.ts ***!
  \*****************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Tab_1 = __importDefault(__webpack_require__(/*! ./Tab */ "./src/background/domain/Tab.ts"));
class Window {
    constructor(id) {
        if (id === null || id === undefined || isNaN(id)) {
            throw new Error('cannot create ManagedWindow without id');
        }
        this._id = id;
        this._tabs = [];
    }
    get id() {
        return this._id;
    }
    hasTab(tabId) {
        return this._tabs.some(tab => tab.id === tabId);
    }
    connectTab(tabId) {
        let tab = this._tabs.find(tab => tab.id === tabId);
        if (tab) {
            tab.connect();
        }
    }
    getDisconnectedTabIds() {
        return this._tabs.filter(tab => !tab.isConnected).map(tab => tab.id);
    }
    getConnectedTabIds() {
        return this._tabs.filter(tab => tab.isConnected).map(tab => tab.id);
    }
    addTab(tabId) {
        if (!this._tabs.find(tab => tab.id === tabId)) {
            let tab = new Tab_1.default(tabId);
            this._tabs.push(tab);
        }
    }
    removeTab(tabId) {
        let findIndex = this._tabs.findIndex(tab => tab.id === tabId);
        if (findIndex !== -1) {
            this._tabs.splice(findIndex, 1);
        }
    }
    activateTab(tabId) {
        this._tabs.forEach(tab => {
            if (tab.id === tabId) {
                tab.activate();
            }
            else {
                tab.deActivate();
            }
        });
    }
}
exports.default = Window;


/***/ }),

/***/ "./src/background/domain/WindowManager.ts":
/*!************************************************!*\
  !*** ./src/background/domain/WindowManager.ts ***!
  \************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Window_1 = __importDefault(__webpack_require__(/*! ./Window */ "./src/background/domain/Window.ts"));
class WindowManager {
    constructor(browserService) {
        this._browserService = browserService;
        this._connectedWindow = undefined;
        this._lastCreatedWindow = undefined;
        this._onWindowRemovedListener = [];
        this.attachHandlers();
    }
    addOnWindoRemovedListener(listener) {
        this._onWindowRemovedListener.push(listener);
    }
    createConnectedWindow(url) {
        var _a;
        if ((_a = this._connectedWindow) === null || _a === void 0 ? void 0 : _a.id) {
            throw new Error("cannot createConnectedWindow, it already exists");
        }
        return this._browserService.createWindow(url)
            .then((id) => {
            var _a;
            if (((_a = this._lastCreatedWindow) === null || _a === void 0 ? void 0 : _a.id) !== id) {
                this._connectedWindow = new Window_1.default(id);
            }
            else {
                this._connectedWindow = this._lastCreatedWindow;
            }
        });
    }
    removeConnectedWindow() {
        let connectedWindowId = this.getConnectedWindowId();
        if (connectedWindowId) {
            return this._browserService.closeWindow(connectedWindowId)
                .then((_) => {
                this._connectedWindow = undefined;
            });
        }
        else {
            return Promise.resolve();
        }
    }
    reloadConnectedWindow(url) {
        return this._browserService.restartWindow(this._connectedWindow.id, url);
    }
    getConnectedWindowId() {
        var _a;
        return (_a = this._connectedWindow) === null || _a === void 0 ? void 0 : _a.id;
    }
    getConnectedTabId() {
        if (this._connectedWindow) {
            return this._connectedWindow.getConnectedTabIds();
        }
        else {
            return [];
        }
    }
    attachHandlers() {
        this._browserService.attachWindowCreatedHandler(this.onWindowCreated.bind(this));
        this._browserService.attachWindowRemovedHandler(this.onWindowRemoved.bind(this));
        this._browserService.attachTabCreatedHandler(this.onTabCreated.bind(this));
        this._browserService.attachTabRemovedHandler(this.onTabRemoved.bind(this));
        this._browserService.attachTabDetachedHandler(this.onTabDetached.bind(this));
        this._browserService.attachTabAttachedHandler(this.onTabAttached.bind(this));
        this._browserService.attachTabActivatedHandler(this.onTabActivated.bind(this));
        this._browserService.attachOnDomLoadedHandler(this.onNavigationDOMLoaded.bind(this));
        this._browserService.attachOnCommittedHandler(this.onNavigationCommitted.bind(this));
    }
    onWindowCreated(windowId) {
        if (this._connectedWindow === undefined) {
            this._lastCreatedWindow = new Window_1.default(windowId);
        }
    }
    onWindowRemoved(windowId) {
        var _a, _b;
        if (windowId === ((_a = this._connectedWindow) === null || _a === void 0 ? void 0 : _a.id)) {
            this._onWindowRemovedListener.forEach(listener => listener(windowId));
            this._connectedWindow = undefined;
        }
        else {
            if (windowId === ((_b = this._lastCreatedWindow) === null || _b === void 0 ? void 0 : _b.id)) {
                this._lastCreatedWindow = undefined;
            }
        }
    }
    onTabCreated(tabId, windowId) {
        var _a, _b;
        if (windowId === ((_a = this._connectedWindow) === null || _a === void 0 ? void 0 : _a.id)) {
            this._connectedWindow.addTab(tabId);
        }
        else {
            if (windowId === ((_b = this._lastCreatedWindow) === null || _b === void 0 ? void 0 : _b.id)) {
                this._lastCreatedWindow.addTab(tabId);
            }
        }
    }
    onTabRemoved(tabId, windowId) {
        var _a, _b;
        if (windowId === ((_a = this._connectedWindow) === null || _a === void 0 ? void 0 : _a.id)) {
            this._connectedWindow.removeTab(tabId);
        }
        else {
            if (windowId === ((_b = this._lastCreatedWindow) === null || _b === void 0 ? void 0 : _b.id)) {
                this._lastCreatedWindow.removeTab(tabId);
            }
        }
    }
    onTabDetached(tabId, windowId) {
        var _a, _b;
        if (windowId === ((_a = this._connectedWindow) === null || _a === void 0 ? void 0 : _a.id)) {
            this._connectedWindow.removeTab(tabId);
        }
        else {
            if (windowId === ((_b = this._lastCreatedWindow) === null || _b === void 0 ? void 0 : _b.id)) {
                this._lastCreatedWindow.removeTab(tabId);
            }
        }
    }
    onTabAttached(tabId, windowId) {
        var _a, _b;
        if (windowId === ((_a = this._connectedWindow) === null || _a === void 0 ? void 0 : _a.id)) {
            this._connectedWindow.addTab(tabId);
        }
        else {
            if (windowId === ((_b = this._lastCreatedWindow) === null || _b === void 0 ? void 0 : _b.id)) {
                this._lastCreatedWindow.addTab(tabId);
            }
        }
    }
    onTabActivated(tabId, windowId) {
        var _a, _b;
        if (windowId === ((_a = this._connectedWindow) === null || _a === void 0 ? void 0 : _a.id)) {
            this._connectedWindow.activateTab(tabId);
        }
        else {
            if (windowId === ((_b = this._lastCreatedWindow) === null || _b === void 0 ? void 0 : _b.id)) {
                this._lastCreatedWindow.addTab(tabId);
            }
        }
    }
    onNavigationDOMLoaded(tabId) {
        if (this._connectedWindow) {
            if (this._connectedWindow.hasTab(tabId)) {
                this._browserService.runScript(tabId)
                    .then((isRunning) => {
                    if (isRunning) {
                        this._connectedWindow.connectTab(tabId);
                    }
                });
            }
        }
    }
    onNavigationCommitted(tabId) {
        if (this._connectedWindow) {
        }
    }
}
exports.default = WindowManager;


/***/ }),

/***/ "./src/background/index.ts":
/*!*********************************!*\
  !*** ./src/background/index.ts ***!
  \*********************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const BackgroundApplication_1 = __importDefault(__webpack_require__(/*! ./application/BackgroundApplication */ "./src/background/application/BackgroundApplication.ts"));
const AifexServiceHTTP_1 = __importDefault(__webpack_require__(/*! ./_infra/AifexServiceHTTP */ "./src/background/_infra/AifexServiceHTTP.ts"));
const ChromeBrowserService_1 = __importDefault(__webpack_require__(/*! ./_infra/ChromeBrowserService */ "./src/background/_infra/ChromeBrowserService.ts"));
const HandlerOfMessageSentByPopup_1 = __importDefault(__webpack_require__(/*! ./_ui/HandlerOfMessageSentByPopup */ "./src/background/_ui/HandlerOfMessageSentByPopup.ts"));
const ChromeTabScriptService_1 = __importDefault(__webpack_require__(/*! ./_infra/ChromeTabScriptService */ "./src/background/_infra/ChromeTabScriptService.ts"));
const HandlerOfMessageSentByTabScript_1 = __importDefault(__webpack_require__(/*! ./_ui/HandlerOfMessageSentByTabScript */ "./src/background/_ui/HandlerOfMessageSentByTabScript.ts"));
const browserService = new ChromeBrowserService_1.default();
const aifexService = new AifexServiceHTTP_1.default();
const tabScriptService = new ChromeTabScriptService_1.default();
const application = new BackgroundApplication_1.default(browserService, aifexService, tabScriptService);
const handlerOfMessageSentByPopup = new HandlerOfMessageSentByPopup_1.default(application);
const handlerOfMessageSentTabScript = new HandlerOfMessageSentByTabScript_1.default(application);


/***/ })

/******/ });
//# sourceMappingURL=index.js.map