<commit_before>from functools import partial
import math

import actions
from actions import _get_as_str
import call_definitions
from call_definitions import xpcom_constructor as xpcom_const, python_wrap
from entity_values import entity
import instanceactions
from jstypes import JSWrapper
from validator.compat import FX40_DEFINITION
from validator.constants import MDN_DOC


# A list of identifiers and member values that may not be used.
BANNED_IDENTIFIERS = {
    u"newThread":
        "Creating threads from JavaScript is a common cause "
        "of crashes and is unsupported in recent versions of the platform",
    u"processNextEvent":
        "Spinning the event loop with processNextEvent is a common cause of "
        "deadlocks, crashes, and other errors due to unintended reentrancy. "
        "Please use asynchronous callbacks instead wherever possible",
}

CUSTOMIZATION_API_HELP = (
    "We are currently working to provide libraries and APIs to allow "
    "extensions to modify these settings in ways that we can guarantee are "
    "in-policy. In the interim, we recommend that you avoid changing these "
    "settings altogether, if at all possible.")

CUSTOMIZATION_PREF_MESSAGE = {
    "description": (
        "Extensions must not alter user preferences such as the current home "
        "page, new tab page, or search engine, without explicit user consent, "
        "in which a user takes a non-default action. Such changes must also "
        "be reverted when the extension is disabled or uninstalled.",
        "In nearly all cases, new values for these preferences should be "
        "set in the default preference branch, rather than the user branch."),
    "signing_help":
        "Add-ons which directly change these preferences must undergo at "
        "manual code review for at least one submission. " +
        CUSTOMIZATION_API_HELP,
    "signing_severity": "high",
}

NETWORK_PREF_MESSAGE = {
    "description":
        "Changing network preferences may be dangerous, and often leads to "
        "performance costs.",
    "signing_help":
        "Changes to these preferences are strongly discouraged. If at all "
        "possible, you should remove any reference to them from "
        "your extension. Extensions which do modify these preferences "
        "must undergo light manual code review for at least one submission.",
    "signing_severity": "low",
}

SEARCH_PREF_MESSAGE = {
    "description":
        "Search engine preferences may not be changed by add-ons directly. "
        "All such changes must be made only via the browser search service, "
        "and only after an explicit opt-in from the user. All such changes "
        "must be reverted when the extension is disabled or uninstalled.",
    "signing_help": (
        "You should remove all references to these preferences from your "
        "code, and interact with search settings only via the "
        "`Services.search` interface. Extensions which interact with these "
        "preferences directly are not acceptable within the Firefox add-on "
        "ecosystem.",
        "Note, however, that extensions which change search settings even via "
        "the search service must undergo manual code review for at least "
        "one submission. " + CUSTOMIZATION_API_HELP),
    "signing_severity": "high",
}

SECURITY_PREF_MESSAGE = {
    "description":
        "Changing this preference may have severe security implications, and "
        "is forbidden under most circumstances.",
    "editors_only": True,
    "signing_help": ("Extensions which alter these settings are allowed "
                     "within the Firefox add-on ecosystem by exception "
                     "only, and under extremely limited circumstances.",
                     "Please remove any reference to these preference names "
                     "from your add-on."),
    "signing_severity": "high",
}

MARIONETTE_MESSAGE = {
    "warning": "Marionette should not be accessed by extensions",
    "description": "References to the Marionette service are not acceptable "
                   "in extensions. Please remove them.",
}


def fuel_error(node, err):
    err.warning("The FUEL library is now deprecated.",
                "The FUEL library is now deprecated. You should use the "
                "add-ons SDK or Services.jsm. See %s for more information."
                % MDN_DOC % "Mozilla/Tech/Toolkit_API/FUEL",
                for_appversions=FX40_DEFINITION,
                tier=5,
                compatibility_type="warning")


BANNED_PREF_BRANCHES = (
    # Security and update preferences<commit_msg> Set err_id for Application compat error (bug 1192213)<commit_after>from functools import partial
import math

import actions
from actions import _get_as_str
import call_definitions
from call_definitions import xpcom_constructor as xpcom_const, python_wrap
from entity_values import entity
import instanceactions
from jstypes import JSWrapper
from validator.compat import FX40_DEFINITION
from validator.constants import MDN_DOC


# A list of identifiers and member values that may not be used.
BANNED_IDENTIFIERS = {
    u"newThread":
        "Creating threads from JavaScript is a common cause "
        "of crashes and is unsupported in recent versions of the platform",
    u"processNextEvent":
        "Spinning the event loop with processNextEvent is a common cause of "
        "deadlocks, crashes, and other errors due to unintended reentrancy. "
        "Please use asynchronous callbacks instead wherever possible",
}

CUSTOMIZATION_API_HELP = (
    "We are currently working to provide libraries and APIs to allow "
    "extensions to modify these settings in ways that we can guarantee are "
    "in-policy. In the interim, we recommend that you avoid changing these "
    "settings altogether, if at all possible.")

CUSTOMIZATION_PREF_MESSAGE = {
    "description": (
        "Extensions must not alter user preferences such as the current home "
        "page, new tab page, or search engine, without explicit user consent, "
        "in which a user takes a non-default action. Such changes must also "
        "be reverted when the extension is disabled or uninstalled.",
        "In nearly all cases, new values for these preferences should be "
        "set in the default preference branch, rather than the user branch."),
    "signing_help":
        "Add-ons which directly change these preferences must undergo at "
        "manual code review for at least one submission. " +
        CUSTOMIZATION_API_HELP,
    "signing_severity": "high",
}

NETWORK_PREF_MESSAGE = {
    "description":
        "Changing network preferences may be dangerous, and often leads to "
        "performance costs.",
    "signing_help":
        "Changes to these preferences are strongly discouraged. If at all "
        "possible, you should remove any reference to them from "
        "your extension. Extensions which do modify these preferences "
        "must undergo light manual code review for at least one submission.",
    "signing_severity": "low",
}

SEARCH_PREF_MESSAGE = {
    "description":
        "Search engine preferences may not be changed by add-ons directly. "
        "All such changes must be made only via the browser search service, "
        "and only after an explicit opt-in from the user. All such changes "
        "must be reverted when the extension is disabled or uninstalled.",
    "signing_help": (
        "You should remove all references to these preferences from your "
        "code, and interact with search settings only via the "
        "`Services.search` interface. Extensions which interact with these "
        "preferences directly are not acceptable within the Firefox add-on "
        "ecosystem.",
        "Note, however, that extensions which change search settings even via "
        "the search service must undergo manual code review for at least "
        "one submission. " + CUSTOMIZATION_API_HELP),
    "signing_severity": "high",
}

SECURITY_PREF_MESSAGE = {
    "description":
        "Changing this preference may have severe security implications, and "
        "is forbidden under most circumstances.",
    "editors_only": True,
    "signing_help": ("Extensions which alter these settings are allowed "
                     "within the Firefox add-on ecosystem by exception "
                     "only, and under extremely limited circumstances.",
                     "Please remove any reference to these preference names "
                     "from your add-on."),
    "signing_severity": "high",
}

MARIONETTE_MESSAGE = {
    "warning": "Marionette should not be accessed by extensions",
    "description": "References to the Marionette service are not acceptable "
                   "in extensions. Please remove them.",
}


def fuel_error(traverse_node, err):
    traverse_node.im_self.warning(
        err_id=("js", "traverser", "dangerous_global"),
        warning="The FUEL library is now deprecated.",
        description="The FUEL library is now deprecated. You should use the "
                    "add-ons SDK or Services.jsm. See %s for more information."
                    % MDN_DOC % "Mozilla/Tech/Toolkit_API/FUEL",
        for_appversions=FX40_DEFINITION,
        tier=5,
        compatibility_type="warning")


BANNED_PREF_BRANCHES = (
    # Security and update preferences
{'fraction_non_alphanumeric': 0.06483551580964549, 'fraction_numerical': 0.0018098584051953583, 'mean_word_length': 2.947058823529412, 'pattern_counts': {'":': 34, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4622277', 'n_tokens_mistral': 2457, 'n_tokens_neox': 2339, 'n_words': 1023}