permissions.js
Go to the documentation of this file.
1 # ***** BEGIN LICENSE BLOCK *****
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 #
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 # http://www.mozilla.org/MPL/
8 #
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
12 # License.
13 #
14 # The Original Code is the permission tab for Page Info.
15 #
16 # The Initial Developer of the Original Code is
17 # Florian QUEZE <f.qu@queze.net>
18 # Portions created by the Initial Developer are Copyright (C) 2006
19 # the Initial Developer. All Rights Reserved.
20 #
21 # Contributor(s):
22 #
23 # Alternatively, the contents of this file may be used under the terms of
24 # either the GNU General Public License Version 2 or later (the "GPL"), or
25 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 # in which case the provisions of the GPL or the LGPL are applicable instead
27 # of those above. If you wish to allow use of your version of this file only
28 # under the terms of either the GPL or the LGPL, and not to allow others to
29 # use your version of this file under the terms of the MPL, indicate your
30 # decision by deleting the provisions above and replace them with the notice
31 # and other provisions required by the LGPL or the GPL. If you do not delete
32 # the provisions above, a recipient may use your version of this file under
33 # the terms of any one of the MPL, the GPL or the LGPL.
34 #
35 # ***** END LICENSE BLOCK *****
36 const ALLOW = nsIPermissionManager.ALLOW_ACTION; // 1
37 const BLOCK = nsIPermissionManager.DENY_ACTION; // 2
38 const SESSION = nsICookiePermission.ACCESS_SESSION;// 8
40 var gPrefs;
41 
42 var gPermObj = {
43  image: function getImageDefaultPermission()
44  {
45  if (gPrefs.getIntPref("permissions.default.image") == 2)
46  return BLOCK;
47  return ALLOW;
48  },
49  cookie: function getCookieDefaultPermission()
50  {
51  if (gPrefs.getIntPref("network.cookie.cookieBehavior") == 2)
52  return BLOCK;
53 
54  if (gPrefs.getIntPref("network.cookie.lifetimePolicy") == 2)
55  return SESSION;
56  return ALLOW;
57  },
58  popup: function getPopupDefaultPermission()
59  {
60  if (gPrefs.getBoolPref("dom.disable_open_during_load"))
61  return BLOCK;
62  return ALLOW;
63  },
64  install: function getInstallDefaultPermission()
65  {
66  if (gPrefs.getBoolPref("xpinstall.whitelist.required"))
67  return BLOCK;
68  return ALLOW;
69  },
70  geo: function getGeoDefaultPermissions()
71  {
72  return BLOCK;
73  }
74 };
75 
77  observe: function (aSubject, aTopic, aData)
78  {
79  if (aTopic == "perm-changed") {
80  var permission = aSubject.QueryInterface(Components.interfaces.nsIPermission);
81  if (permission.host == gPermURI.host && permission.type in gPermObj)
82  initRow(permission.type);
83  }
84  }
85 };
86 
87 function onLoadPermission()
88 {
89  gPrefs = Components.classes[PREFERENCES_CONTRACTID]
90  .getService(Components.interfaces.nsIPrefBranch2);
91 
92  var uri = gDocument.documentURIObject;
93  var permTab = document.getElementById("permTab");
94  if(/^https?/.test(uri.scheme)) {
95  gPermURI = uri;
96  var hostText = document.getElementById("hostText");
97  hostText.value = gPermURI.host;
98 
99  for (var i in gPermObj)
100  initRow(i);
101  var os = Components.classes["@mozilla.org/observer-service;1"]
102  .getService(Components.interfaces.nsIObserverService);
103  os.addObserver(permissionObserver, "perm-changed", false);
105  permTab.hidden = false;
106  }
107  else
108  permTab.hidden = true;
109 }
110 
112 {
113  var os = Components.classes["@mozilla.org/observer-service;1"]
114  .getService(Components.interfaces.nsIObserverService);
115  os.removeObserver(permissionObserver, "perm-changed");
116 }
117 
118 function initRow(aPartId)
119 {
120  var permissionManager = Components.classes[PERMISSION_CONTRACTID]
121  .getService(nsIPermissionManager);
122 
123  var checkbox = document.getElementById(aPartId + "Def");
124  var command = document.getElementById("cmd_" + aPartId + "Toggle");
125  var perm = permissionManager.testPermission(gPermURI, aPartId);
126  if (perm) {
127  checkbox.checked = false;
128  command.removeAttribute("disabled");
129  }
130  else {
131  checkbox.checked = true;
132  command.setAttribute("disabled", "true");
133  perm = gPermObj[aPartId]();
134  }
135  setRadioState(aPartId, perm);
136 }
137 
138 function onCheckboxClick(aPartId)
139 {
140  var permissionManager = Components.classes[PERMISSION_CONTRACTID]
141  .getService(nsIPermissionManager);
142 
143  var command = document.getElementById("cmd_" + aPartId + "Toggle");
144  var checkbox = document.getElementById(aPartId + "Def");
145  if (checkbox.checked) {
146  permissionManager.remove(gPermURI.host, aPartId);
147  command.setAttribute("disabled", "true");
148  var perm = gPermObj[aPartId]();
149  setRadioState(aPartId, perm);
150  }
151  else {
152  onRadioClick(aPartId);
153  command.removeAttribute("disabled");
154  }
155 }
156 
157 function onRadioClick(aPartId)
158 {
159  var permissionManager = Components.classes[PERMISSION_CONTRACTID]
160  .getService(nsIPermissionManager);
161 
162  var radioGroup = document.getElementById(aPartId + "RadioGroup");
163  var id = radioGroup.selectedItem.id;
164  var permission = id.split('#')[1];
165  permissionManager.add(gPermURI, aPartId, permission);
166 }
167 
168 function setRadioState(aPartId, aValue)
169 {
170  var radio = document.getElementById(aPartId + "#" + aValue);
171  radio.radioGroup.selectedItem = radio;
172 }
const PREFERENCES_CONTRACTID
Definition: pageInfo.js:188
const nsIPermissionManager
Definition: permissions.js:40
onPageChanged aValue
Definition: FeedWriter.js:1395
function onCheckboxClick(aPartId)
Definition: permissions.js:138
var gDocument
Definition: pageInfo.js:150
function onRadioClick(aPartId)
Definition: permissions.js:157
var gPermObj
Definition: permissions.js:42
var gPrefs
Definition: permissions.js:40
function onUnloadPermission()
Definition: permissions.js:111
function initRow(aPartId)
Definition: permissions.js:118
const BLOCK
Definition: permissions.js:37
var os
function onLoadPermission()
Definition: permissions.js:87
var onUnloadRegistry
Definition: pageInfo.js:261
var uri
Definition: FeedWriter.js:1135
var gPermURI
Definition: permissions.js:39
const PERMISSION_CONTRACTID
Definition: pageInfo.js:187
function setRadioState(aPartId, aValue)
Definition: permissions.js:168
const nsICookiePermission
Definition: permissions.js:41
const ALLOW
Definition: permissions.js:36
_getSelectedPageStyle s i
var permissionObserver
Definition: permissions.js:76
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe
const SESSION
Definition: permissions.js:38