1 # -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
15 # The Original Code is the Firefox Preferences System.
17 # The Initial Developer of the Original Code is
19 # Portions created by the Initial Developer are Copyright (C) 2005
20 # the Initial Developer. All Rights Reserved.
23 # Ben Goodger <ben@mozilla.org>
24 # Blake Ross <firefox@blakeross.com>
26 # Alternatively, the contents of this file may be used under the terms of
27 # either the GNU General Public License Version 2 or later (the "GPL"), or
28 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 # in which case the provisions of the GPL or the LGPL are applicable instead
30 # of those above. If you wish to allow use of your version of this file only
31 # under the terms of either the GPL or the LGPL, and not to allow others to
32 # use your version of this file under the terms of the MPL, indicate your
33 # decision by deleting the provisions above and replace them with the notice
34 # and other provisions required by the GPL or the LGPL. If you do not delete
35 # the provisions above, a recipient may use your version of this file under
36 # the terms of any one of the MPL, the GPL or the LGPL.
38 # ***** END LICENSE BLOCK *****
43 function Permission(host, rawHost, type, capability, perm)
46 this.rawHost = rawHost;
48 this.capability = capability;
55 _pm : Components.classes[
"@mozilla.org/permissionmanager;1"]
56 .getService(Components.interfaces.nsIPermissionManager),
64 return this._rowCount;
66 getCellText:
function (aRow, aColumn)
68 if (aColumn.id ==
"siteCol")
70 else if (aColumn.id ==
"statusCol")
75 isSeparator:
function(aIndex) {
return false; },
76 isSorted:
function() {
return false; },
77 isContainer:
function(aIndex) {
return false; },
78 setTree:
function(aTree){},
79 getImageSrc:
function(aRow, aColumn) {},
80 getProgressMode:
function(aRow, aColumn) {},
81 getCellValue:
function(aRow, aColumn) {},
82 cycleHeader:
function(column) {},
83 getRowProperties:
function(row,prop){},
84 getColumnProperties:
function(column,prop){},
86 if (column.element.getAttribute(
"id") ==
"siteCol")
87 prop.AppendElement(
this._ltrAtom);
91 _getCapabilityString:
function (aCapability)
94 switch (aCapability) {
102 stringKey =
"canSession";
105 return this._bundle.getString(stringKey);
108 addPermission:
function (aCapability)
110 var textbox = document.getElementById(
"url");
111 var host = textbox.value.replace(/^\s*([-\w]*:\/+)?/,
"");
113 var
ioService = Components.classes[
"@mozilla.org/network/io-service;1"]
114 .getService(Components.interfaces.nsIIOService);
115 var
uri = ioService.newURI(
"http://"+host,
null,
null);
118 var
promptService = Components.classes[
"@mozilla.org/embedcomp/prompt-service;1"]
119 .getService(Components.interfaces.nsIPromptService);
120 var
message = this._bundle.getString(
"invalidURI");
121 var title = this._bundle.getString(
"invalidURITitle");
122 promptService.alert(
window, title, message);
126 var capabilityString = this._getCapabilityString(aCapability);
130 for (var
i = 0;
i < this._permissions.length; ++
i) {
131 if (this._permissions[
i].rawHost == host) {
135 exists = this._permissions[
i].perm == aCapability;
141 host = (host.charAt(0) ==
".") ? host.substring(1,host.length) : host;
143 this._pm.add(uri, this._type, aCapability);
149 this.onHostInput(textbox);
152 document.getElementById(
"removeAllPermissions").disabled = this._permissions.length == 0;
155 onHostInput:
function (aSiteField)
157 document.getElementById(
"btnSession").disabled = !aSiteField.value;
158 document.getElementById(
"btnBlock").disabled = !aSiteField.value;
159 document.getElementById(
"btnAllow").disabled = !aSiteField.value;
162 onHostKeyPress:
function (aEvent)
164 if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN)
165 document.getElementById(
"btnAllow").click();
170 this._bundle = document.getElementById(
"bundlePreferences");
171 var params =
window.arguments[0];
175 init:
function (aParams)
182 this._type = aParams.permissionType;
183 this._manageCapability = aParams.manageCapability;
185 var permissionsText = document.getElementById(
"permissionsText");
186 while (permissionsText.hasChildNodes())
187 permissionsText.removeChild(permissionsText.firstChild);
188 permissionsText.appendChild(document.createTextNode(aParams.introText));
190 document.title = aParams.windowTitle;
192 document.getElementById(
"btnBlock").hidden = !aParams.blockVisible;
193 document.getElementById(
"btnSession").hidden = !aParams.sessionVisible;
194 document.getElementById(
"btnAllow").hidden = !aParams.allowVisible;
196 var urlFieldVisible = (aParams.blockVisible || aParams.sessionVisible || aParams.allowVisible);
198 var urlField = document.getElementById(
"url");
199 urlField.value = aParams.prefilledHost;
200 urlField.hidden = !urlFieldVisible;
202 this.onHostInput(urlField);
204 var urlLabel = document.getElementById(
"urlLabel");
205 urlLabel.hidden = !urlFieldVisible;
207 var
os = Components.classes[
"@mozilla.org/observer-service;1"]
208 .getService(Components.interfaces.nsIObserverService);
209 os.addObserver(
this,
"perm-changed",
false);
211 if (this._type ==
"install") {
212 var enumerator = this._pm.enumerator;
213 if (!enumerator.hasMoreElements())
214 this._updatePermissions();
217 this._loadPermissions();
221 this._ltrAtom = Components.classes[
"@mozilla.org/atom-service;1"]
222 .getService(Components.interfaces.nsIAtomService)
228 var
os = Components.classes[
"@mozilla.org/observer-service;1"]
229 .getService(Components.interfaces.nsIObserverService);
230 os.removeObserver(
this,
"perm-changed");
235 if (aTopic ==
"perm-changed") {
236 var permission = aSubject.QueryInterface(Components.interfaces.nsIPermission);
237 if (
aData ==
"added") {
238 this._addPermissionToList(permission);
239 ++this._view._rowCount;
240 this._tree.treeBoxObject.rowCountChanged(this._view.rowCount - 1, 1);
242 gTreeUtils.sort(this._tree, this._view, this._permissions,
243 this._lastPermissionSortColumn,
244 this._lastPermissionSortAscending);
246 else if (
aData ==
"changed") {
247 for (var
i = 0;
i < this._permissions.length; ++
i) {
248 if (this._permissions[
i].host == permission.host) {
249 this._permissions[
i].capability = this._getCapabilityString(permission.capability);
256 if (this._lastPermissionSortColumn.id ==
"statusCol") {
257 gTreeUtils.sort(this._tree, this._view, this._permissions,
258 this._lastPermissionSortColumn,
259 this._lastPermissionSortAscending);
261 this._tree.treeBoxObject.invalidate();
270 onPermissionSelected:
function ()
272 var hasSelection = this._tree.view.selection.count > 0;
273 var hasRows = this._tree.view.rowCount > 0;
274 document.getElementById(
"removePermission").disabled = !hasRows || !hasSelection;
275 document.getElementById(
"removeAllPermissions").disabled = !hasRows;
278 onPermissionDeleted:
function ()
280 if (!this._view.rowCount)
282 var removedPermissions = [];
283 gTreeUtils.deleteSelectedItems(this._tree, this._view, this._permissions, removedPermissions);
284 for (var
i = 0;
i < removedPermissions.length; ++
i) {
285 var
p = removedPermissions[
i];
286 this._pm.remove(p.host, p.type);
288 document.getElementById(
"removePermission").disabled = !this._permissions.length;
289 document.getElementById(
"removeAllPermissions").disabled = !this._permissions.length;
292 onAllPermissionsDeleted:
function ()
294 if (!this._view.rowCount)
296 var removedPermissions = [];
297 gTreeUtils.deleteAll(this._tree, this._view, this._permissions, removedPermissions);
298 for (var
i = 0;
i < removedPermissions.length; ++
i) {
299 var
p = removedPermissions[
i];
300 this._pm.remove(p.host, p.type);
302 document.getElementById(
"removePermission").disabled =
true;
303 document.getElementById(
"removeAllPermissions").disabled =
true;
306 onPermissionKeyPress:
function (aEvent)
308 if (aEvent.keyCode == 46)
309 this.onPermissionDeleted();
312 _lastPermissionSortColumn:
"",
313 _lastPermissionSortAscending:
false,
315 onPermissionSort:
function (aColumn)
317 this._lastPermissionSortAscending =
gTreeUtils.sort(this._tree,
321 this._lastPermissionSortColumn,
322 this._lastPermissionSortAscending);
323 this._lastPermissionSortColumn = aColumn;
326 _loadPermissions:
function ()
328 this._tree = document.getElementById(
"permissionsTree");
329 this._permissions = [];
333 var enumerator = this._pm.enumerator;
334 while (enumerator.hasMoreElements()) {
335 var nextPermission = enumerator.getNext().QueryInterface(Components.interfaces.nsIPermission);
336 this._addPermissionToList(nextPermission);
339 this._view._rowCount = this._permissions.length;
342 this._tree.treeBoxObject.view = this._view;
343 this.onPermissionSort(
"rawHost",
false);
346 document.getElementById(
"removeAllPermissions").disabled = this._permissions.length == 0;
349 _addPermissionToList:
function (aPermission)
351 if (aPermission.type ==
this._type &&
352 (!
this._manageCapability ||
353 (aPermission.capability ==
this._manageCapability))) {
355 var host = aPermission.host;
356 var capabilityString = this._getCapabilityString(aPermission.capability);
358 (host.charAt(0) ==
".") ? host.substring(1,host.length) : host,
361 aPermission.capability);
362 this._permissions.push(p);
366 _updatePermissions:
function ()
369 var
ioService = Components.classes[
"@mozilla.org/network/io-service;1"]
370 .getService(Components.interfaces.nsIIOService);
371 var pbi = Components.classes[
"@mozilla.org/preferences-service;1"]
372 .getService(Components.interfaces.nsIPrefBranch2);
377 for (var
i = 0;
i < prefList.length; ++
i) {
380 var hosts = pbi.getCharPref(prefList[
i][0]);
388 hostList = hosts.split(
",");
389 var capability = prefList[
i][1];
390 for (var j = 0; j < hostList.length; ++j) {
392 var host = hostList[j].replace(/^\s*/,
"").replace(/\s*$/,
"");
394 var
uri = ioService.newURI(
"http://" + host,
null,
null);
395 this._pm.add(uri, this._type, capability);
398 pbi.setCharPref(prefList[
i][0],
"");
405 document.getElementById(
"url").value =
aHost;
const nsIPermissionManager
gImageView getCellProperties
function initWithParams(aParams)
function Permission(host, rawHost, type, capability, perm)
const nsICookiePermission
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe