author Matt Woodrow <>
Mon, 15 Apr 2013 18:55:34 +1200
changeset 135530 3b0cda3057dfc1a3c9a2342ad938a8a7ea6bcf32
parent 126716 a874d2756f6530a8ee7c8dc6dbcb7102944d5127
child 147459 489046125fa6eb98fe20d73460f4b0e641cfe037
permissions -rw-r--r--
Bug 859526 - Null check parent frames when wrapping preserve-3d display lists. r=roc

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at

from xml.dom.minidom import Document

VALID_PREF_TYPES = ['bool', 'boolint', 'integer', 'string', 'color', 'file',
                    'directory', 'control', 'menulist', 'radio']

class Error(Exception):

class BadPrefTypeError(Error):

class MissingPrefAttr(Error):

def validate_prefs(options):
    for pref in options:
        # Make sure there is a 'title'
        if ("title" not in pref):
            raise MissingPrefAttr("The '%s' pref requires a 'title'" % (pref["name"]))

        # Make sure that the pref type is a valid inline pref type
        if (pref["type"] not in VALID_PREF_TYPES):
            raise BadPrefTypeError('%s is not a valid inline pref type' % (pref["type"]))

        # Make sure the 'control' type has a 'label'
        if (pref["type"] == "control"):
            if ("label" not in pref):
                raise MissingPrefAttr("The 'control' inline pref type requires a 'label'")

        # Make sure the 'menulist' type has a 'menulist'
        if (pref["type"] == "menulist" or pref["type"] == "radio"):
            if ("options" not in pref):
                raise MissingPrefAttr("The 'menulist' and the 'radio' inline pref types requires a 'options'")

            # Make sure each option has a 'value' and a 'label'
            for item in pref["options"]:
                if ("value" not in item):
                    raise MissingPrefAttr("'options' requires a 'value'")
                if ("label" not in item):
                    raise MissingPrefAttr("'options' requires a 'label'")

        # TODO: Check that pref["type"] matches default value type

def parse_options(options, jetpack_id):
    doc = Document()
    root = doc.createElement("vbox")
    root.setAttribute("xmlns", "")

    for pref in options:
        setting = doc.createElement("setting")
        setting.setAttribute("pref-name", pref["name"])
        setting.setAttribute("data-jetpack-id", jetpack_id)
        setting.setAttribute("pref", "extensions." + jetpack_id + "." + pref["name"])
        setting.setAttribute("type", pref["type"])
        setting.setAttribute("title", pref["title"])

        if ("description" in pref):

        if (pref["type"] == "control"):
            button = doc.createElement("button")
            button.setAttribute("pref-name", pref["name"])
            button.setAttribute("data-jetpack-id", jetpack_id)
            button.setAttribute("label", pref["label"])
            button.setAttribute("oncommand", "Services.obs.notifyObservers(null, '" +
                                              jetpack_id + "-cmdPressed', '" +
                                              pref["name"] + "');");
        elif (pref["type"] == "boolint"):
            setting.setAttribute("on", pref["on"])
            setting.setAttribute("off", pref["off"])
        elif (pref["type"] == "menulist"):
            menulist = doc.createElement("menulist")
            menupopup = doc.createElement("menupopup")
            for item in pref["options"]:
                menuitem = doc.createElement("menuitem")
                menuitem.setAttribute("value", item["value"])
                menuitem.setAttribute("label", item["label"])
        elif (pref["type"] == "radio"):
            radiogroup = doc.createElement("radiogroup")
            for item in pref["options"]:
                radio = doc.createElement("radio")
                radio.setAttribute("value", item["value"])
                radio.setAttribute("label", item["label"])


    return doc.toprettyxml(indent="  ")