home *** CD-ROM | disk | FTP | other *** search
- /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla.org Code.
- *
- * The Initial Developer of the Original Code is
- * Doron Rosenberg.
- * Portions created by the Initial Developer are Copyright (C) 2001
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Jonas J°rgensen <jonasj@jonasj.dk>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
- const pref = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPref);
-
- // need it globally, but can only set it in startup()
- var data;
-
- function changeDisabledState(state){
- //Set the states of the groupbox children state based on the "javascript enabled" checkbox value
- document.getElementById("allowScripts").disabled = state;
- document.getElementById("allowTargetNew").disabled = state;
- document.getElementById("allowWindowMoveResize").disabled = state;
- document.getElementById("allowWindowOpen").disabled = state;
- document.getElementById("allowImageSrcChange").disabled = state;
- document.getElementById("allowDocumentCookieSet").disabled = state;
- document.getElementById("allowDocumentCookieGet").disabled = state;
- document.getElementById("allowWindowStatusChange").disabled = state;
- document.getElementById("allowWindowFlip").disabled = state;
- }
-
- function javascriptEnabledChange(){
- // if javascriptAllowMailNews is overlayed (mailnews is installed), then if javascriptAllowMailnews
- // and javascriptAllowNavigator are unchecked, we disable the tree items.
- // If javascriptAllowMailNews is not available, we only take javascriptAllowNavigator in consideration
-
- if (document.getElementById('javascriptAllowMailNews')){
- if (!document.getElementById('javascriptAllowNavigator').checked && !document.getElementById('javascriptAllowMailNews').checked)
- changeDisabledState(true);
- else changeDisabledState(false);
- } else {
- changeDisabledState(!document.getElementById('javascriptAllowNavigator').checked);
- }
- }
-
- function getPrefValueForCheckbox(prefName){
- var prefValue = false;
-
- try {
- prefValue = pref.GetBoolPref(prefName);
- }
- catch(e) {}
-
- // the prefs are stored in terms of disabling,
- // but we want our value in terms of enabling.
- // so let's invert the prefValue.
- return !prefValue;
- }
-
- function Startup(){
-
- data = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-scripts.xul"];
-
- //If scriptData does not exist, then it is the first time the panel was shown and we default to false
- if (!("scriptData" in data)){
- var changedList = ["allowWindowOpenChanged", "allowTargetNewChanged",
- "allowWindowMoveResizeChanged", "allowWindowStatusChangeChanged",
- "allowWindowFlipChanged", "allowDocumentCookieSetChanged",
- "allowDocumentCookieGetChanged", "allowImageSrcChangeChanged"];
- data.scriptData = [];
- for(var run = 0; run < changedList.length; run++ ){
- data.scriptData[ changedList[run] ] = [];
- data.scriptData[ changedList[run] ].value = false;
- }
-
- document.getElementById("allowWindowOpen").checked = getPrefValueForCheckbox("dom.disable_open_during_load");
- document.getElementById("allowTargetNew").checked = getPrefValueForCheckbox("browser.block.target_new_window");
- document.getElementById("allowWindowMoveResize").checked = getPrefValueForCheckbox("dom.disable_window_move_resize");
- document.getElementById("allowWindowFlip").checked = getPrefValueForCheckbox("dom.disable_window_flip");
- document.getElementById("allowWindowStatusChange").checked = getPrefValueForCheckbox("dom.disable_window_status_change");
- document.getElementById("allowImageSrcChange").checked = getPrefValueForCheckbox("dom.disable_image_src_set");
- document.getElementById("allowDocumentCookieGet").checked = getPrefValueForCheckbox("dom.disable_cookie_get");
- document.getElementById("allowDocumentCookieSet").checked = getPrefValueForCheckbox("dom.disable_cookie_set");
-
- } else { //not first time it was loaded, get default values from data
-
- document.getElementById("allowWindowOpen").checked = data["allowWindowOpen"].checked;
- document.getElementById("allowTargetNew").checked = data["allowTargetNew"].checked;
- document.getElementById("allowWindowMoveResize").checked = data["allowWindowMoveResize"].checked;
- document.getElementById("allowWindowFlip").checked = data["allowWindowFlip"].checked;
- document.getElementById("allowWindowStatusChange").checked = data["allowWindowStatusChange"].checked;
- document.getElementById("allowImageSrcChange").checked = data["allowImageSrcChange"].checked;
- document.getElementById("allowDocumentCookieSet").checked = data["allowDocumentCookieSet"].checked;
- document.getElementById("allowDocumentCookieGet").checked = data["allowDocumentCookieGet"].checked;
- document.getElementById("javascriptAllowNavigator").checked = data["javascriptAllowNavigator"].checked;
-
- if (document.getElementById("javascriptAllowMailnews")) {
- document.getElementById("javascriptAllowMailNews").checked = data["javascriptAllowMailNews"].checked;
- }
- }
-
- javascriptEnabledChange();
-
- document.getElementById("AllowList").addEventListener("CheckboxStateChange", onCheckboxCheck, false);
-
- parent.hPrefWindow.registerOKCallbackFunc(doOnOk);
- }
-
- function doOnOk(){
-
- //If a user makes a change to this panel, goes to another panel, and returns to this panel to
- //make another change, then we cannot use data[elementName]. This is because data[elementName]
- //contains the original xul change and we would loose the new change. Thus we track all changes
- //by using getElementById.
-
- //The nested functions are needed because doOnOk cannot access anything outside of its scope
- //when it is called
- function getCheckboxValue(name){
- if ("onCheckboxCheck" in window)
- return document.getElementById(name).checked;
-
- return data[name].checked;
- }
-
- var data = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-scripts.xul"];
-
- if (data.scriptData["allowWindowOpenChanged"].value){
- parent.hPrefWindow.setPref("bool", "dom.disable_open_during_load",
- !getCheckboxValue('allowWindowOpen'));
- }
-
- if (data.scriptData["allowTargetNewChanged"].value){
- parent.hPrefWindow.setPref("bool", "browser.block.target_new_window",
- !getCheckboxValue('allowTargetNew'));
- }
-
- if (data.scriptData["allowWindowMoveResizeChanged"].value){
- parent.hPrefWindow.setPref("bool", "dom.disable_window_move_resize",
- !getCheckboxValue('allowWindowMoveResize'));
- }
-
- if (data.scriptData["allowWindowStatusChangeChanged"].value){
- parent.hPrefWindow.setPref("bool", "dom.disable_window_status_change",
- !getCheckboxValue("allowWindowStatusChange"));
- }
-
- if (data.scriptData["allowWindowFlipChanged"].value){
- parent.hPrefWindow.setPref("bool", "dom.disable_window_flip",
- !getCheckboxValue("allowWindowFlip"));
- }
-
- if (data.scriptData["allowDocumentCookieSetChanged"].value){
- parent.hPrefWindow.setPref("bool", "dom.disable_cookie_set",
- !getCheckboxValue("allowDocumentCookieSet"));
- }
-
- if (data.scriptData["allowDocumentCookieGetChanged"].value){
- parent.hPrefWindow.setPref("bool", "dom.disable_cookie_get",
- !getCheckboxValue("allowDocumentCookieGet"));
- }
-
- if (data.scriptData["allowImageSrcChangeChanged"].value){
- parent.hPrefWindow.setPref("bool", "dom.disable_image_src_set",
- !getCheckboxValue("allowImageSrcChange"));
- }
- }
-
- function onCheckboxCheck(event)
- {
- data.scriptData[event.target.id+"Changed"].value = !data.scriptData[event.target.id+"Changed"].value;
- }
-