<commit_before>/**
 * Mailvelope - secure email with OpenPGP encryption for Webmail
 * Copyright (C) 2012-2015 Mailvelope GmbH
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

'use strict';


var mvelo = require('../../mvelo');

mvelo.crx = true;
mvelo.ffa = false;

var dompurify = require('dompurify');

mvelo.data = {};

mvelo.data.url = function(path) {
  return chrome.runtime.getURL(path);
};

mvelo.data.load = function(path) {
  return new Promise(function(resolve, reject) {
    var req = new XMLHttpRequest();
    req.open('GET', chrome.runtime.getURL(path));
    req.responseType = 'text';
    req.onload = function() {
      if (req.status == 200) {
        resolve(req.response);
      } else {
        reject(new Error(req.statusText));
      }
    };
    req.onerror = function() {
      reject(new Error('Network Error'));
    };
    req.send();
  });
};

mvelo.tabs = {};

mvelo.tabs.getActive = function(callback) {
  // get selected tab, "*://*/*" filters out non-http(s)
  chrome.tabs.query({active: true, currentWindow: true, url: "*://*/*"}, function(tabs) {
    callback(tabs[0]);
  });
};

mvelo.tabs.attach = function(tab, options, callback) {
  function executeScript(file, callback) {
    if (file) {
      chrome.tabs.executeScript(tab.id, {file: file, allFrames: true}, function() {
        executeScript(options.contentScriptFile.shift(), callback);
      });
    } else {
      callback(tab);
    }
  }
  executeScript(options.contentScriptFile.shift(), function() {
    if (options.contentScript) {
      chrome.tabs.executeScript(tab.id, {code: options.contentScript, allFrames: true}, callback.bind(this, tab));
    } else {
      callback(tab);
    }
  });
};

mvelo.tabs.query = function(url, callback) {
  if (!/\*$/.test(url)) {
    url += '*';
  }
  chrome.tabs.query({url: url, currentWindow: true}, callback);
};

mvelo.tabs.create = function(url, complete, callback) {
  var newTab;
  if (complete) {
    // wait for tab to be loaded
    chrome.tabs.onUpdated.addListener(function updateListener(tabid, info) {
      if (tabid === newTab.id && info.status === 'complete') {
        chrome.tabs.onUpdated.removeListener(updateListener);
        if (callback) {
          callback(newTab);
        }
      }
    });
  }
  chrome.tabs.create({url: url}, function(tab) {
    if (complete) {
      newTab = tab;
    } else {
      if (callback) {
        callback(tab);
      }
    }
  });
};

mvelo.tabs.activate = function(tab, options, callback) {
  options = $.extend(options, { active: true });
  chrome.tabs.update(tab.id, options, callback);
};

mvelo.tabs.sendMessage = function(tab, msg, callback) {<commit_msg>Remove jQuery dependency from lib-mvelo in Chrome<commit_after>/**
 * Mailvelope - secure email with OpenPGP encryption for Webmail
 * Copyright (C) 2012-2015 Mailvelope GmbH
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

'use strict';


var mvelo = require('../../mvelo');

mvelo.crx = true;
mvelo.ffa = false;

var dompurify = require('dompurify');

mvelo.data = {};

mvelo.data.url = function(path) {
  return chrome.runtime.getURL(path);
};

mvelo.data.load = function(path) {
  return new Promise(function(resolve, reject) {
    var req = new XMLHttpRequest();
    req.open('GET', chrome.runtime.getURL(path));
    req.responseType = 'text';
    req.onload = function() {
      if (req.status == 200) {
        resolve(req.response);
      } else {
        reject(new Error(req.statusText));
      }
    };
    req.onerror = function() {
      reject(new Error('Network Error'));
    };
    req.send();
  });
};

mvelo.tabs = {};

mvelo.tabs.getActive = function(callback) {
  // get selected tab, "*://*/*" filters out non-http(s)
  chrome.tabs.query({active: true, currentWindow: true, url: "*://*/*"}, function(tabs) {
    callback(tabs[0]);
  });
};

mvelo.tabs.attach = function(tab, options, callback) {
  function executeScript(file, callback) {
    if (file) {
      chrome.tabs.executeScript(tab.id, {file: file, allFrames: true}, function() {
        executeScript(options.contentScriptFile.shift(), callback);
      });
    } else {
      callback(tab);
    }
  }
  executeScript(options.contentScriptFile.shift(), function() {
    if (options.contentScript) {
      chrome.tabs.executeScript(tab.id, {code: options.contentScript, allFrames: true}, callback.bind(this, tab));
    } else {
      callback(tab);
    }
  });
};

mvelo.tabs.query = function(url, callback) {
  if (!/\*$/.test(url)) {
    url += '*';
  }
  chrome.tabs.query({url: url, currentWindow: true}, callback);
};

mvelo.tabs.create = function(url, complete, callback) {
  var newTab;
  if (complete) {
    // wait for tab to be loaded
    chrome.tabs.onUpdated.addListener(function updateListener(tabid, info) {
      if (tabid === newTab.id && info.status === 'complete') {
        chrome.tabs.onUpdated.removeListener(updateListener);
        if (callback) {
          callback(newTab);
        }
      }
    });
  }
  chrome.tabs.create({url: url}, function(tab) {
    if (complete) {
      newTab = tab;
    } else {
      if (callback) {
        callback(tab);
      }
    }
  });
};

mvelo.tabs.activate = function(tab, options, callback) {
  options = options || {};
  options.active = true;
  chrome.tabs.update(tab.id, options, callback);
};

mvelo.tabs.sendMessage = function(tab, msg, callback) {
{'fraction_non_alphanumeric': 0.14764478764478764, 'fraction_numerical': 0.004015444015444016, 'mean_word_length': 3.1222151495862507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4710473', 'n_tokens_mistral': 2066, 'n_tokens_neox': 2007, 'n_words': 530}