<commit_before>/*
 * This Source Code is subject to the terms of the Mozilla Public License
 * version 2.0 (the "License"). You can obtain a copy of the License at
 * http://mozilla.org/MPL/2.0/.
 */

let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});

// Randomize URI to work around bug 719376
let stringBundle = Services.strings.createBundle("chrome://jsdeobfuscator/locale/global.properties?" + Math.random());

let tool = {
  id: "jsdeobfuscator-panel",
  url: "chrome://jsdeobfuscator/content/panel.xul",
  label: stringBundle.GetStringFromName("panel.label"),
  tooltip: stringBundle.GetStringFromName("panel.tooltip"),
  icon: "chrome://jsdeobfuscator/skin/devtools-icon.svg",
  inMenu: true,
  menuLabel: stringBundle.GetStringFromName("menuitem.label"),
  invertIconForLightTheme: true,
  isTargetSupported: target => target.isLocalTab,
  build: (window, toolbox) => {
    return new Panel(window, toolbox).ready;
  }
};

// Frame script URL has to be randomized due to caching
// (see https://bugzilla.mozilla.org/show_bug.cgi?id=1051238)
let frameScript = "chrome://jsdeobfuscator/content/content.js?" + Math.random();

gDevTools.registerTool(tool);
onShutdown.add(() => gDevTools.unregisterTool(tool.id));

function initTarget(messageManager)
{
  return new Promise((resolve, reject) => {
    let listener = () =>
    {
      messageManager.removeMessageListener("<EMAIL>:ready", listener);
      resolve();
    };

    messageManager.loadFrameScript(frameScript, false);
    messageManager.addMessageListener("<EMAIL>:ready", listener);
  });
}

function waitForLoad(window)
{
  return new Promise((resolve, reject) => {
    if (window.document.readyState == "complete")
      resolve();
    else
    {
      let listener = () => {
        window.removeEventListener("load", listener, false);
        resolve();
      };
      window.addEventListener("load", listener, false);
    }
  });
}

function Panel(window, toolbox)
{
  let target = this._target = toolbox.target;

  this._window = window;
  this.ready = new Promise((resolve, reject) => {
    Promise.all([
      waitForLoad(window),
      initTarget(this._messageManager)
    ]).then(() => (window.setTarget(target), resolve(this)), reject);
  });

  this.onNewScript = this.onNewScript.bind(this);
  this.onScriptExecuted = this.onScriptExecuted.bind(this);
  this.onNavigate = this.onNavigate.bind(this);

  this._messageManager.addMessageListener("<EMAIL>:newscript", this.onNewScript);
  this._messageManager.addMessageListener("<EMAIL>:updatescript", this.onScriptExecuted);
  this._messageManager.addMessageListener("<EMAIL>:navigate", this.onNavigate);
}
Panel.prototype = {
  get _messageManager()
  {
    return this._target.tab.linkedBrowser.messageManager;
  },

  destroy: function()
  {
    this._messageManager.removeMessageListener("<EMAIL>:newscript", this.onNewScript);
    this._messageManager.removeMessageListener("<EMAIL>:updatescript", this.onScriptExecuted);
    this._messageManager.removeMessageListener("<EMAIL>:navigate", this.onNavigate);
    this._messageManager.sendAsyncMessage("<EMAIL>:shutdown");
  },

  onNewScript: function(message)
  {
    this._window.addScript(message.data);
  },

  onScriptExecuted: function(message)
  {
    this._window.updateScriptExecTime(message.data.id, message.data.execTime);
  },

  onNavigate: function()
  {
    try
    {
      if (Services.prefs.getBoolPref("devtools.webconsole.persistlog"))
        return;
    }
    catch (e)
    {
    }

    this._messageManager.sendAsyncMessage("<EMAIL>:clear");
    this._window.clearList();
  }
};
<commit_msg>Update dev tools module URL for Firefox 46<commit_after>/*
 * This Source Code is subject to the terms of the Mozilla Public License
 * version 2.0 (the "License"). You can obtain a copy of the License at
 * http://mozilla.org/MPL/2.0/.
 */

let gDevTools;
try
{
  // New URI as of Firefox 44
  ({gDevTools} = Cu.import("resource://devtools/client/framework/gDevTools.jsm", {}));
}
catch (e)
{
  // Old URI
  ({gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {}));
}
let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});

// Randomize URI to work around bug 719376
let stringBundle = Services.strings.createBundle("chrome://jsdeobfuscator/locale/global.properties?" + Math.random());

let tool = {
  id: "jsdeobfuscator-panel",
  url: "chrome://jsdeobfuscator/content/panel.xul",
  label: stringBundle.GetStringFromName("panel.label"),
  tooltip: stringBundle.GetStringFromName("panel.tooltip"),
  icon: "chrome://jsdeobfuscator/skin/devtools-icon.svg",
  inMenu: true,
  menuLabel: stringBundle.GetStringFromName("menuitem.label"),
  invertIconForLightTheme: true,
  isTargetSupported: target => target.isLocalTab,
  build: (window, toolbox) => {
    return new Panel(window, toolbox).ready;
  }
};

// Frame script URL has to be randomized due to caching
// (see https://bugzilla.mozilla.org/show_bug.cgi?id=1051238)
let frameScript = "chrome://jsdeobfuscator/content/content.js?" + Math.random();

gDevTools.registerTool(tool);
onShutdown.add(() => gDevTools.unregisterTool(tool.id));

function initTarget(messageManager)
{
  return new Promise((resolve, reject) => {
    let listener = () =>
    {
      messageManager.removeMessageListener("<EMAIL>:ready", listener);
      resolve();
    };

    messageManager.loadFrameScript(frameScript, false);
    messageManager.addMessageListener("<EMAIL>:ready", listener);
  });
}

function waitForLoad(window)
{
  return new Promise((resolve, reject) => {
    if (window.document.readyState == "complete")
      resolve();
    else
    {
      let listener = () => {
        window.removeEventListener("load", listener, false);
        resolve();
      };
      window.addEventListener("load", listener, false);
    }
  });
}

function Panel(window, toolbox)
{
  let target = this._target = toolbox.target;

  this._window = window;
  this.ready = new Promise((resolve, reject) => {
    Promise.all([
      waitForLoad(window),
      initTarget(this._messageManager)
    ]).then(() => (window.setTarget(target), resolve(this)), reject);
  });

  this.onNewScript = this.onNewScript.bind(this);
  this.onScriptExecuted = this.onScriptExecuted.bind(this);
  this.onNavigate = this.onNavigate.bind(this);

  this._messageManager.addMessageListener("<EMAIL>:newscript", this.onNewScript);
  this._messageManager.addMessageListener("<EMAIL>:updatescript", this.onScriptExecuted);
  this._messageManager.addMessageListener("<EMAIL>:navigate", this.onNavigate);
}
Panel.prototype = {
  get _messageManager()
  {
    return this._target.tab.linkedBrowser.messageManager;
  },

  destroy: function()
  {
    this._messageManager.removeMessageListener("<EMAIL>:newscript", this.onNewScript);
    this._messageManager.removeMessageListener("<EMAIL>:updatescript", this.onScriptExecuted);
    this._messageManager.removeMessageListener("<EMAIL>:navigate", this.onNavigate);
    this._messageManager.sendAsyncMessage("<EMAIL>:shutdown");
  },

  onNewScript: function(message)
  {
    this._window.addScript(message.data);
  },

  onScriptExecuted: function(message)
  {
    this._window.updateScriptExecTime(message.data.id, message.data.execTime);
  },

  onNavigate: function()
  {
    try
    {
      if (Services.prefs.getBoolPref("devtools.webconsole.persistlog"))
        return;
    }
    catch (e)
    {
    }

    this._<EMAIL>Manager.sendAsyncMessage("<EMAIL>:clear");
    this._window.clearList();
  }
};

{'fraction_non_alphanumeric': 0.15005274261603377, 'fraction_numerical': 0.0050105485232067514, 'mean_word_length': 4.278357689631176, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 42, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '1589458', 'n_tokens_mistral': 2398, 'n_tokens_neox': 2347, 'n_words': 401}