<commit_before>const {classes: Cc, interfaces: Ci, utils: Cu} = Components;

var EXPORTED_SYMBOLS = ["CCK2"];

Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
try {
  Cu.import("resource://gre/modules/Timer.jsm");  
} catch (ex) {
  Cu.import("resource://cck2/Timer.jsm");  
}
Cu.import("resource://cck2/Preferences.jsm");
Cu.import("resource://cck2/CTPPermissions.jsm");
Cu.import("resource://cck2/CAPSClipboard.jsm");
Cu.import("resource://cck2/CAPSCheckLoadURI.jsm");
Cu.import("resource:///modules/distribution.js");

XPCOMUtils.defineLazyServiceGetter(this, "bmsvc",
    "@mozilla.org/browser/nav-bookmarks-service;1", "nsINavBookmarksService");
XPCOMUtils.defineLazyServiceGetter(this, "annos",
    "@mozilla.org/browser/annotation-service;1", "nsIAnnotationService");
XPCOMUtils.defineLazyServiceGetter(this, "override",
    "@mozilla.org/security/certoverride;1", "nsICertOverrideService");
XPCOMUtils.defineLazyServiceGetter(this, "uuid",
    "@mozilla.org/uuid-generator;1", "nsIUUIDGenerator");

/* Hack to work around bug that AutoConfig is loaded in the wrong charset */
var fixupUTF8 = null;

if (''[0] != '') {
  fixupUTF8 = function(str) {
    if (!str) {
      return null;
    }
    var out, i, len, c;
    var char2, char3;
  
    out = "";
    len = str.length;
    i = 0;
    while(i < len) {
      c = str.charCodeAt(i++);
      switch(c >> 4)
      { 
        case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
          // 0xxxxxxx
          out += str.charAt(i-1);
          break;
        case 12: case 13:
          // 110x xxxx   10xx xxxx
          char2 = str.charCodeAt(i++);
          out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
          break;
        case 14:
          // 1110 xxxx  10xx xxxx  10xx xxxx
          char2 = str.charCodeAt(i++);
          char3 = str.charCodeAt(i++);
          out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));  
          break;
      }
    }
  
    return out;
  };
} else {
  fixupUTF8 = function(str) { return str };
}

/* Crazy hack to work around distribution.ini bug */
/* Basically if the distribution can't be parsed,  make it null */
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
             getService(Ci.nsIProperties);
let iniFile = dirSvc.get("XREExeF", Ci.nsIFile);
iniFile.leafName = "distribution";
iniFile.append("distribution.ini");
if (iniFile.exists()) {
  try {
    let ini = Cc["@mozilla.org/xpcom/ini-parser-factory;1"].
                 getService(Ci.nsIINIParserFactory).
                 createINIParser(iniFile);
  } catch (e) {
    DistributionCustomizer.prototype.__defineGetter__("_iniFile", function() null);
  }
}

var networkPrefMapping = {
  proxyType: "network.proxy.type",
  proxyHTTP: "network.proxy.http",
  proxyHTTPPort: "network.proxy.http_port",
  proxySSL: "network.proxy.ssl",
  proxySSLPort: "network.proxy.ssl_port",
  proxyFTP: "network.proxy.ftp",
  proxyFTPPort: "network.proxy.ftp_port",
  proxySOCKS: "network.proxy.socks",
  proxySOCKSPort: "network.proxy.socks_port",
  proxySocksVersion: "network.proxy.socks_version",
  proxyNone: "network.proxy.no_proxies_on",
  proxyAutoConfig: "network.proxy.autoconfig_url",
  shareAllProxies: "network.proxy.share_proxy_settings",
  proxySOCKSRemoteDNS: "network.proxy.socks_remote_dns",
  proxyAutologin: "signon.autologin.proxy"
}


function alert(string) {
  Services.prompt.alert(Services.wm.getMostRecentWindow("navigator:browser"), "", string);
} 

var CCK2 = {
  configs: {},
  firstrun: false,
  upgrade: false,
  installedVersion: null,
  initialized: false,
  aboutFactories: [],
  init: function(config) {
    try {
      for (var id in this.configs) {
        if (id == config.id) {
          // We've already processed this config
          return;
        }
      }
      if (!config) {
        // Try to get config from default preference. If it is there, default
        // preference always wins
        var configJSON = Preferences.defaults.get("extensions.cck2.config");
        if (!configJSON) {
          configJSON = Preferences.defaults.get("extensions.cck2.config");
        }
        if (!configJSON) {
          // Try something else. Grou policy?
        }
        try {
          config = JSON.parse(configJSON);
        } catch (ex) {
          return;
        }
      }
  
      // We don't handle in content preferences right now, so make sure they
      // can't be used. We redirect this to an invalid about: page so
      // it doesn't look like the admin disabled it.
      Preferences.lock("browser.preferences.inContent", false);
      var aboutPreferences = {};
      aboutPreferences.classID = Components.ID(uuid.generateUUID().toString());
      aboutPreferences.factory = disableAbout(aboutPreferences.classID,
                                              "",
                                              "preferences");
      CCK2.aboutFactories.push(aboutPreferences);
  
      if (!config)
        return;
      if (!config.id) {
        alert("Missing ID in config");
      }
      config.firstrun = Preferences.get("extensions.cck2." + config.id + ".firstrun", true);
      Preferences.set("extensions.cck2." + config.id + ".firstrun", false);
      if (!config.firstrun) {
        config.installedVersion = Preferences.get("extensions.cck2." + config.id + ".installedVersion");
        config.upgrade = (config.installedVersion != config.version);
      }
      Preferences.set("extensions.cck2." + config.id + ".installedVersion", config.version);
      Preferences.lock("distribution.id", config.id);
      Preferences.lock("distribution.version", config.version + " (CCK2)");
//      Preferences.lock("distribution.about", String(config.id + " - " + config.version + " (CCK2)"));

      if (config.noAddonCompatibilityCheck) {
        Preferences.reset("extensions.lastAppVersion");
      }
      if (config.preferences) {
        for (var i in config.preferences) {
          // Ugly, but we need special handling for this pref
          // since Firefox doesn't honor the default pref
          // So we set a regular pref if first run
          if (i == "plugin.disable_full_page_plugin_for_types") {
            if (this.firstrun) {
              Preferences.set(i, config.preferences[i].value);
            }
            continue;
          }
          // Workaround bug where this pref is coming is as a string from import
          if (i == "toolkit.telemetry.prompted") {
            config.preferences[i].value = parseInt(config.preferences[i].value);
          }
          if (config.preferences[i].locked) {
            Preferences.lock(i, config.preferences[i].value);
          } else if (config.preferences[i].userset) {
            Preferences.set(i, config.preferences[i].value);
          } else {
            if (Preferences.defaults.has(i)) {
              try {
                // If it's a complex preference, we need to set it differently
                Services.prefs.getComplexValue(i, Ci.nsIPrefLocalizedString).data;
                Preferences.defaults.set(i, "data:text/plain," + i + "=" + config.preferences[i].value);
              } catch (ex) {
                Preferences.defaults.set(i, config.preferences[i].value);
              }
            } else {<commit_msg>Fix bug where setting disable full page plugin didn't work<commit_after>const {classes: Cc, interfaces: Ci, utils: Cu} = Components;

var EXPORTED_SYMBOLS = ["CCK2"];

Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
try {
  Cu.import("resource://gre/modules/Timer.jsm");  
} catch (ex) {
  Cu.import("resource://cck2/Timer.jsm");  
}
Cu.import("resource://cck2/Preferences.jsm");
Cu.import("resource://cck2/CTPPermissions.jsm");
Cu.import("resource://cck2/CAPSClipboard.jsm");
Cu.import("resource://cck2/CAPSCheckLoadURI.jsm");
Cu.import("resource:///modules/distribution.js");

XPCOMUtils.defineLazyServiceGetter(this, "bmsvc",
    "@mozilla.org/browser/nav-bookmarks-service;1", "nsINavBookmarksService");
XPCOMUtils.defineLazyServiceGetter(this, "annos",
    "@mozilla.org/browser/annotation-service;1", "nsIAnnotationService");
XPCOMUtils.defineLazyServiceGetter(this, "override",
    "@mozilla.org/security/certoverride;1", "nsICertOverrideService");
XPCOMUtils.defineLazyServiceGetter(this, "uuid",
    "@mozilla.org/uuid-generator;1", "nsIUUIDGenerator");

/* Hack to work around bug that AutoConfig is loaded in the wrong charset */
var fixupUTF8 = null;

if (''[0] != '') {
  fixupUTF8 = function(str) {
    if (!str) {
      return null;
    }
    var out, i, len, c;
    var char2, char3;
  
    out = "";
    len = str.length;
    i = 0;
    while(i < len) {
      c = str.charCodeAt(i++);
      switch(c >> 4)
      { 
        case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
          // 0xxxxxxx
          out += str.charAt(i-1);
          break;
        case 12: case 13:
          // 110x xxxx   10xx xxxx
          char2 = str.charCodeAt(i++);
          out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
          break;
        case 14:
          // 1110 xxxx  10xx xxxx  10xx xxxx
          char2 = str.charCodeAt(i++);
          char3 = str.charCodeAt(i++);
          out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));  
          break;
      }
    }
  
    return out;
  };
} else {
  fixupUTF8 = function(str) { return str };
}

/* Crazy hack to work around distribution.ini bug */
/* Basically if the distribution can't be parsed,  make it null */
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
             getService(Ci.nsIProperties);
let iniFile = dirSvc.get("XREExeF", Ci.nsIFile);
iniFile.leafName = "distribution";
iniFile.append("distribution.ini");
if (iniFile.exists()) {
  try {
    let ini = Cc["@mozilla.org/xpcom/ini-parser-factory;1"].
                 getService(Ci.nsIINIParserFactory).
                 createINIParser(iniFile);
  } catch (e) {
    DistributionCustomizer.prototype.__defineGetter__("_iniFile", function() null);
  }
}

var networkPrefMapping = {
  proxyType: "network.proxy.type",
  proxyHTTP: "network.proxy.http",
  proxyHTTPPort: "network.proxy.http_port",
  proxySSL: "network.proxy.ssl",
  proxySSLPort: "network.proxy.ssl_port",
  proxyFTP: "network.proxy.ftp",
  proxyFTPPort: "network.proxy.ftp_port",
  proxySOCKS: "network.proxy.socks",
  proxySOCKSPort: "network.proxy.socks_port",
  proxySocksVersion: "network.proxy.socks_version",
  proxyNone: "network.proxy.no_proxies_on",
  proxyAutoConfig: "network.proxy.autoconfig_url",
  shareAllProxies: "network.proxy.share_proxy_settings",
  proxySOCKSRemoteDNS: "network.proxy.socks_remote_dns",
  proxyAutologin: "signon.autologin.proxy"
}


function alert(string) {
  Services.prompt.alert(Services.wm.getMostRecentWindow("navigator:browser"), "", string);
} 

var CCK2 = {
  configs: {},
  firstrun: false,
  upgrade: false,
  installedVersion: null,
  initialized: false,
  aboutFactories: [],
  init: function(config) {
    try {
      for (var id in this.configs) {
        if (id == config.id) {
          // We've already processed this config
          return;
        }
      }
      if (!config) {
        // Try to get config from default preference. If it is there, default
        // preference always wins
        var configJSON = Preferences.defaults.get("extensions.cck2.config");
        if (!configJSON) {
          configJSON = Preferences.defaults.get("extensions.cck2.config");
        }
        if (!configJSON) {
          // Try something else. Grou policy?
        }
        try {
          config = JSON.parse(configJSON);
        } catch (ex) {
          return;
        }
      }
  
      // We don't handle in content preferences right now, so make sure they
      // can't be used. We redirect this to an invalid about: page so
      // it doesn't look like the admin disabled it.
      Preferences.lock("browser.preferences.inContent", false);
      var aboutPreferences = {};
      aboutPreferences.classID = Components.ID(uuid.generateUUID().toString());
      aboutPreferences.factory = disableAbout(aboutPreferences.classID,
                                              "",
                                              "preferences");
      CCK2.aboutFactories.push(aboutPreferences);
  
      if (!config)
        return;
      if (!config.id) {
        alert("Missing ID in config");
      }
      config.firstrun = Preferences.get("extensions.cck2." + config.id + ".firstrun", true);
      Preferences.set("extensions.cck2." + config.id + ".firstrun", false);
      if (!config.firstrun) {
        config.installedVersion = Preferences.get("extensions.cck2." + config.id + ".installedVersion");
        config.upgrade = (config.installedVersion != config.version);
      }
      Preferences.set("extensions.cck2." + config.id + ".installedVersion", config.version);
      Preferences.lock("distribution.id", config.id);
      Preferences.lock("distribution.version", config.version + " (CCK2)");
//      Preferences.lock("distribution.about", String(config.id + " - " + config.version + " (CCK2)"));

      if (config.noAddonCompatibilityCheck) {
        Preferences.reset("extensions.lastAppVersion");
      }
      if (config.preferences) {
        for (var i in config.preferences) {
          // Ugly, but we need special handling for this pref
          // since Firefox doesn't honor the default pref
          // So we set a regular pref if first run or if user set
          if (i == "plugin.disable_full_page_plugin_for_types") {
            if (config.firstrun || config.preferences[i].userset) {
              Preferences.set(i, config.preferences[i].value);
            }
            continue;
          }
          // Workaround bug where this pref is coming is as a string from import
          if (i == "toolkit.telemetry.prompted") {
            config.preferences[i].value = parseInt(config.preferences[i].value);
          }
          if (config.preferences[i].locked) {
            Preferences.lock(i, config.preferences[i].value);
          } else if (config.preferences[i].userset) {
            Preferences.set(i, config.preferences[i].value);
          } else {
            if (Preferences.defaults.has(i)) {
              try {
                // If it's a complex preference, we need to set it differently
                Services.prefs.getComplexValue(i, Ci.nsIPrefLocalizedString).data;
                Preferences.defaults.set(i, "data:text/plain," + i + "=" + config.preferences[i].value);
              } catch (ex) {
                Preferences.defaults.set(i, config.preferences[i].value);
              }
            } else {
{'fraction_non_alphanumeric': 0.1403285283271874, 'fraction_numerical': 0.010727455581629233, 'mean_word_length': 2.5565092989985696, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '619818', 'n_tokens_mistral': 4782, 'n_tokens_neox': 4606, 'n_words': 956}