toolkit/mozapps/extensions/content/setting.xml

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 <?xml version="1.0"?>
     2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
     3    - License, v. 2.0. If a copy of the MPL was not distributed with this
     4    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     6 <!DOCTYPE page [
     7 <!ENTITY % extensionsDTD SYSTEM "chrome://mozapps/locale/extensions/extensions.dtd">
     8 %extensionsDTD;
     9 ]>
    11 <bindings xmlns="http://www.mozilla.org/xbl"
    12           xmlns:xbl="http://www.mozilla.org/xbl"
    13           xmlns:html="http://www.w3.org/1999/xhtml"
    14           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    16   <binding id="settings">
    17     <content orient="vertical">
    18       <xul:label class="settings-title" xbl:inherits="xbl:text=label" flex="1"/>
    19       <children/>
    20     </content>
    21   </binding>
    23   <binding id="setting-base">
    24     <implementation>
    25       <constructor><![CDATA[
    26         this.preferenceChanged();
    28         this.addEventListener("keypress", function(event) {
    29           event.stopPropagation();
    30         }, false);
    32         if (this.usePref)
    33           Services.prefs.addObserver(this.pref, this._observer, true);
    34       ]]></constructor>
    36       <field name="_observer"><![CDATA[({
    37         _self: this,
    39         QueryInterface: function(aIID) {
    40           const Ci = Components.interfaces;
    41           if (aIID.equals(Ci.nsIObserver) ||
    42               aIID.equals(Ci.nsISupportsWeakReference) ||
    43               aIID.equals(Ci.nsISupports))
    44             return this;
    46           throw Components.Exception("No interface", Components.results.NS_ERROR_NO_INTERFACE);
    47         },
    49         observe: function(aSubject, aTopic, aPrefName) {
    50           if (aTopic != "nsPref:changed")
    51             return;
    53           if (this._self.pref == aPrefName)
    54             this._self.preferenceChanged();
    55         }
    56       })]]>
    57       </field>
    59       <method name="fireEvent">
    60         <parameter name="eventName"/>
    61         <parameter name="funcStr"/>
    62         <body>
    63           <![CDATA[
    64             let body = funcStr || this.getAttribute(eventName);
    65             if (!body)
    66               return;
    68             try {
    69               let event = document.createEvent("Events");
    70               event.initEvent(eventName, true, true);
    71               let f = new Function("event", body);
    72               f.call(this, event);
    73             }
    74             catch (e) {
    75               Cu.reportError(e);
    76             }
    77           ]]>
    78         </body>
    79       </method>
    81       <method name="valueFromPreference">
    82         <body>
    83         <![CDATA[
    84           // Should be code to set the from the preference input.value
    85           throw Components.Exception("No valueFromPreference implementation",
    86                                      Components.results.NS_ERROR_NOT_IMPLEMENTED);
    87         ]]>
    88         </body>
    89       </method>
    91       <method name="valueToPreference">
    92         <body>
    93         <![CDATA[
    94           // Should be code to set the input.value from the preference
    95           throw Components.Exception("No valueToPreference implementation",
    96                                      Components.results.NS_ERROR_NOT_IMPLEMENTED);
    97         ]]>
    98         </body>
    99       </method>
   101       <method name="inputChanged">
   102         <body>
   103         <![CDATA[
   104           if (this.usePref && !this._updatingInput) {
   105             this.valueToPreference();
   106             this.fireEvent("oninputchanged");
   107           }
   108         ]]>
   109         </body>
   110       </method>
   112       <method name="preferenceChanged">
   113         <body>
   114         <![CDATA[
   115           if (this.usePref) {
   116             this._updatingInput = true;
   117             try {
   118               this.valueFromPreference();
   119               this.fireEvent("onpreferencechanged");
   120             } catch (e) {}
   121             this._updatingInput = false;
   122           }
   123         ]]>
   124         </body>
   125       </method>
   127       <property name="usePref" readonly="true" onget="return this.hasAttribute('pref');"/>
   128       <property name="pref" readonly="true" onget="return this.getAttribute('pref');"/>
   129       <property name="type" readonly="true" onget="return this.getAttribute('type');"/>
   130       <property name="value" onget="return this.input.value;" onset="return this.input.value = val;"/>
   132       <field name="_updatingInput">false</field>
   133       <field name="input">document.getAnonymousElementByAttribute(this, "anonid", "input");</field>
   134       <field name="settings">
   135         this.parentNode.localName == "settings" ? this.parentNode : null;
   136       </field>
   137     </implementation>
   138   </binding>
   140   <binding id="setting-bool" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   141     <content>
   142       <xul:vbox>
   143         <xul:hbox class="preferences-alignment">
   144           <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   145         </xul:hbox>
   146         <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   147       </xul:vbox>
   148       <xul:hbox class="preferences-alignment">
   149         <xul:checkbox anonid="input" xbl:inherits="disabled,onlabel,offlabel,label=checkboxlabel" oncommand="inputChanged();"/>
   150       </xul:hbox>
   151     </content>
   153     <implementation>
   154       <method name="valueFromPreference">
   155         <body>
   156         <![CDATA[
   157           let val = Services.prefs.getBoolPref(this.pref);
   158           this.value = this.inverted ? !val : val;
   159          ]]>
   160         </body>
   161       </method>
   163       <method name="valueToPreference">
   164         <body>
   165         <![CDATA[
   166           let val = this.value;
   167           Services.prefs.setBoolPref(this.pref, this.inverted ? !val : val);
   168         ]]>
   169         </body>
   170       </method>
   172       <property name="value" onget="return this.input.checked;" onset="return this.input.setChecked(val);"/>
   173       <property name="inverted" readonly="true" onget="return this.getAttribute('inverted');"/>
   174     </implementation>
   175   </binding>
   177   <binding id="setting-boolint" extends="chrome://mozapps/content/extensions/setting.xml#setting-bool">
   178     <implementation>
   179       <method name="valueFromPreference">
   180         <body>
   181         <![CDATA[
   182           let val = Services.prefs.getIntPref(this.pref);
   183           this.value = (val == this.getAttribute("on"));
   184          ]]>
   185         </body>
   186       </method>
   188       <method name="valueToPreference">
   189         <body>
   190         <![CDATA[
   191           Services.prefs.setIntPref(this.pref, this.getAttribute(this.value ? "on" : "off"));
   192         ]]>
   193         </body>
   194       </method>
   195     </implementation>
   196   </binding>
   198   <binding id="setting-localized-bool" extends="chrome://mozapps/content/extensions/setting.xml#setting-bool">
   199     <implementation>
   200       <method name="valueFromPreference">
   201         <body>
   202         <![CDATA[
   203           let val = Services.prefs.getComplexValue(this.pref, Components.interfaces.nsIPrefLocalizedString).data;
   204           if(this.inverted) val = !val;
   205           this.value = (val == "true");
   206          ]]>
   207         </body>
   208       </method>
   210       <method name="valueToPreference">
   211         <body>
   212         <![CDATA[
   213           let val = this.value;
   214           if(this.inverted) val = !val;
   215           let pref = Components.classes["@mozilla.org/pref-localizedstring;1"].createInstance(Components.interfaces.nsIPrefLocalizedString);
   216           pref.data = this.inverted ? (!val).toString() : val.toString();
   217           Services.prefs.setComplexValue(this.pref, Components.interfaces.nsIPrefLocalizedString, pref);
   218         ]]>
   219         </body>
   220       </method>
   221     </implementation>
   222   </binding>
   224   <binding id="setting-integer" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   225     <content>
   226       <xul:vbox>
   227         <xul:hbox class="preferences-alignment">
   228           <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   229         </xul:hbox>
   230         <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   231       </xul:vbox>
   232       <xul:hbox class="preferences-alignment">
   233         <xul:textbox type="number" anonid="input" oninput="inputChanged();" onchange="inputChanged();"
   234                      xbl:inherits="disabled,emptytext,min,max,increment,hidespinbuttons,wraparound,size"/>
   235       </xul:hbox>
   236     </content>
   238     <implementation>
   239       <method name="valueFromPreference">
   240         <body>
   241         <![CDATA[
   242           let val = Services.prefs.getIntPref(this.pref);
   243           this.value = val;
   244          ]]>
   245         </body>
   246       </method>
   248       <method name="valueToPreference">
   249         <body>
   250         <![CDATA[
   251           Services.prefs.setIntPref(this.pref, this.value);
   252         ]]>
   253         </body>
   254       </method>
   255     </implementation>
   256   </binding>
   258   <binding id="setting-control" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   259     <content>
   260       <xul:vbox>
   261         <xul:hbox class="preferences-alignment">
   262           <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   263         </xul:hbox>
   264         <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   265       </xul:vbox>
   266       <xul:hbox class="preferences-alignment">
   267         <children/>
   268       </xul:hbox>
   269     </content>
   270   </binding>
   272   <binding id="setting-string" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   273     <content>
   274       <xul:vbox>
   275         <xul:hbox class="preferences-alignment">
   276           <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   277         </xul:hbox>
   278         <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   279       </xul:vbox>
   280       <xul:hbox class="preferences-alignment">
   281         <xul:textbox anonid="input" flex="1" oninput="inputChanged();"
   282                      xbl:inherits="disabled,emptytext,type=inputtype,min,max,increment,hidespinbuttons,decimalplaces,wraparound"/>
   283       </xul:hbox>
   284     </content>
   286     <implementation>
   287       <method name="valueFromPreference">
   288         <body>
   289         <![CDATA[
   290           const nsISupportsString = Components.interfaces.nsISupportsString;
   291           this.value = Services.prefs.getComplexValue(this.pref, nsISupportsString).data;
   292          ]]>
   293         </body>
   294       </method>
   296       <method name="valueToPreference">
   297         <body>
   298         <![CDATA[
   299           const nsISupportsString = Components.interfaces.nsISupportsString;
   300           let iss = Components.classes["@mozilla.org/supports-string;1"].createInstance(nsISupportsString);
   301           iss.data = this.value;
   302           Services.prefs.setComplexValue(this.pref, nsISupportsString, iss);
   303         ]]>
   304         </body>
   305       </method>
   306     </implementation>
   307   </binding>
   309   <binding id="setting-color" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   310     <content>
   311       <xul:vbox>
   312         <xul:hbox class="preferences-alignment">
   313           <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   314         </xul:hbox>
   315         <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   316       </xul:vbox>
   317       <xul:hbox class="preferences-alignment">
   318         <xul:colorpicker type="button" anonid="input" xbl:inherits="disabled" onchange="document.getBindingParent(this).inputChanged();"/>
   319       </xul:hbox>
   320     </content>
   322     <implementation>
   323       <method name="valueFromPreference">
   324         <body>
   325         <![CDATA[
   326           // We must wait for the colorpicker's binding to be applied before setting the value
   327           if (!this.input.color)
   328             this.input.initialize();
   329           this.value = Services.prefs.getCharPref(this.pref);
   330         ]]>
   331         </body>
   332       </method>
   334       <method name="valueToPreference">
   335         <body>
   336         <![CDATA[
   337           Services.prefs.setCharPref(this.pref, this.value);
   338         ]]>
   339         </body>
   340       </method>
   342       <property name="value" onget="return this.input.color;" onset="return this.input.color = val;"/>
   343     </implementation>
   344   </binding>
   346   <binding id="setting-path" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   347     <content>
   348       <xul:vbox>
   349         <xul:hbox class="preferences-alignment">
   350           <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   351         </xul:hbox>
   352         <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   353       </xul:vbox>
   354       <xul:hbox class="preferences-alignment">
   355         <xul:button type="button" anonid="button" label="&settings.path.button.label;" xbl:inherits="disabled" oncommand="showPicker();"/>
   356         <xul:label anonid="input" flex="1" crop="center" xbl:inherits="disabled"/>
   357       </xul:hbox>
   358     </content>
   360     <implementation>
   361       <method name="showPicker">
   362         <body>
   363         <![CDATA[
   364           var filePicker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
   365           filePicker.init(window, this.getAttribute("title"),
   366                           this.type == "file" ? Ci.nsIFilePicker.modeOpen : Ci.nsIFilePicker.modeGetFolder);
   367           if (this.value) {
   368             try {
   369               let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
   370               file.initWithPath(this.value);
   371               filePicker.displayDirectory = this.type == "file" ? file.parent : file;
   372               if (this.type == "file") {
   373                 filePicker.defaultString = file.leafName;
   374               }
   375             } catch (e) {}
   376           }
   377           if (filePicker.show() != Ci.nsIFilePicker.returnCancel) {
   378             this.value = filePicker.file.path;
   379             this.inputChanged();
   380           }
   381         ]]>
   382         </body>
   383       </method>
   385       <method name="valueFromPreference">
   386         <body>
   387         <![CDATA[
   388           this.value = Services.prefs.getCharPref(this.pref);
   389         ]]>
   390         </body>
   391       </method>
   393       <method name="valueToPreference">
   394         <body>
   395         <![CDATA[
   396           Services.prefs.setCharPref(this.pref, this.value);
   397         ]]>
   398         </body>
   399       </method>
   401       <field name="_value"></field>
   403       <property name="value">
   404         <getter>
   405         <![CDATA[
   406           return this._value;
   407         ]]>
   408         </getter>
   409         <setter>
   410         <![CDATA[
   411           this._value = val;
   412           let label = "";
   413           if (val) {
   414             try {
   415               let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
   416               file.initWithPath(val);
   417               label = this.hasAttribute("fullpath") ? file.path : file.leafName;
   418             } catch (e) {}
   419           }
   420           this.input.tooltipText = val;
   421           return this.input.value = label;
   422        ]]>
   423         </setter>
   424       </property>
   425     </implementation>
   426   </binding>
   428   <binding id="setting-multi" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   429     <content>
   430       <xul:vbox>
   431         <xul:hbox class="preferences-alignment">
   432           <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   433         </xul:hbox>
   434         <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   435       </xul:vbox>
   436       <xul:hbox class="preferences-alignment">
   437         <children includes="radiogroup|menulist"/>
   438       </xul:hbox>
   439     </content>
   441     <implementation>
   442       <constructor>
   443       <![CDATA[
   444         this.control.addEventListener("command", this.inputChanged.bind(this), false);
   445       ]]>
   446       </constructor>
   448       <method name="valueFromPreference">
   449         <body>
   450         <![CDATA[
   451           let val;
   452           switch (Services.prefs.getPrefType(this.pref)) {
   453             case Ci.nsIPrefBranch.PREF_STRING:
   454               val = Services.prefs.getCharPref(this.pref);
   455               break;
   456             case Ci.nsIPrefBranch.PREF_INT:
   457               val = Services.prefs.getIntPref(this.pref);
   458               break;
   459             case Ci.nsIPrefBranch.PREF_BOOL:
   460               val = Services.prefs.getBoolPref(this.pref).toString();
   461               break;
   462             default:
   463               return;
   464           }
   466           if ("itemCount" in this.control) {
   467             for (let i = 0; i < this.control.itemCount; i++) {
   468               if (this.control.getItemAtIndex(i).value == val) {
   469                 this.control.selectedIndex = i;
   470                 break;
   471               }
   472             }
   473           } else {
   474             this.control.setAttribute("value", val);
   475           }
   476         ]]>
   477         </body>
   478       </method>
   480       <method name="valueToPreference">
   481         <body>
   482         <![CDATA[
   483           // We might not have a pref already set, so we guess the type from the value attribute
   484           let val = this.control.selectedItem.value;
   485           if (val == "true" || val == "false")
   486             Services.prefs.setBoolPref(this.pref, val == "true");
   487           else if (/^-?\d+$/.test(val))
   488             Services.prefs.setIntPref(this.pref, val);
   489           else
   490             Services.prefs.setCharPref(this.pref, val);
   491         ]]>
   492         </body>
   493       </method>
   495       <field name="control">this.getElementsByTagName(this.getAttribute("type") == "radio" ? "radiogroup" : "menulist")[0];</field>
   496     </implementation>
   497   </binding>
   498 </bindings>

mercurial