1 /***************************************************************************
3 Description: Control cookie permissions.
5 Homepage: http://addons.mozilla.org
7 Copyright (C) 2007 Ron Beckman
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to:
22 Free Software Foundation, Inc.
27 ***************************************************************************/
30 const CSTEMPEXCEPTIONS_CONTRACTID
= '@mozilla.org/CSTempExceptions;1';
31 const CSTEMPEXCEPTIONS_CID
= Components
.ID('{8742629c-8f6a-4787-9c44-2db49b392531}');
32 const CSTEMPEXCEPTIONS_IID
= Components
.interfaces
.nsICSTempExceptions
;
33 const CSTEMPEXCEPTIONS_SERVICENAME
= 'CS Temp Exceptions';
35 var nsCSTempExceptions
= {
39 testTempExceptions: function(host
) {
40 for (var i
=0; i
<this.hosts
.length
; ++i
) {
41 if (this.hosts
[i
]==host
) return true;
47 getTempExceptions: function() {
48 return this.hosts
.join(' ');
51 addTempExceptions: function(host
) {
52 var found
= this.testTempExceptions(host
);
54 this.hosts
.push(host
);
57 //keep track of temp exceptions in a char pref in case browser
58 //crashes before all of the temp exceptions have been cleared
59 var prefs
= this.getPrefs();
60 prefs
.setCharPref('tempExceptions',this.hosts
.join(' '));
63 removeTempExceptions: function(host
) {
64 this.hosts
= this.hosts
.filter(function(value
) {
68 //keep track of temp exceptions in a char pref in case browser
69 //crashes before all of the temp exceptions have been cleared
70 var prefs
= this.getPrefs();
71 prefs
.setCharPref('tempExceptions',this.hosts
.join(' '));
74 clearTempExceptions: function() {
77 //keep track of temp exceptions in a char pref in case browser
78 //crashes before all of the temp exceptions have been cleared
79 var prefs
= this.getPrefs();
80 prefs
.setCharPref('tempExceptions','');
83 getPrefs: function() {
84 return Components
.classes
["@mozilla.org/preferences-service;1"].
85 getService(Components
.interfaces
.nsIPrefService
).
86 getBranch("cookiesafe.");
89 QueryInterface: function(iid
) {
90 if (!iid
.equals(Components
.interfaces
.nsISupports
) &&
91 !iid
.equals(CSTEMPEXCEPTIONS_IID
))
92 throw Components
.results
.NS_ERROR_NO_INTERFACE
;
97 var nsCSTempExceptionsModule
= {
99 registerSelf: function(compMgr
, fileSpec
, location
, type
) {
100 compMgr
= compMgr
.QueryInterface(Components
.interfaces
.nsIComponentRegistrar
);
101 compMgr
.registerFactoryLocation(CSTEMPEXCEPTIONS_CID
,
102 CSTEMPEXCEPTIONS_SERVICENAME
,
103 CSTEMPEXCEPTIONS_CONTRACTID
,
104 fileSpec
,location
,type
);
107 unregisterSelf: function (compMgr
, fileSpec
, location
) {
108 compMgr
= compMgr
.QueryInterface(Components
.interfaces
.nsIComponentRegistrar
);
109 compMgr
.unregisterFactoryLocation(CSTEMPEXCEPTIONS_CID
,fileSpec
);
112 getClassObject: function(compMgr
, cid
, iid
) {
113 if (!cid
.equals(CSTEMPEXCEPTIONS_CID
))
114 throw Components
.results
.NS_ERROR_NO_INTERFACE
;
115 if (!iid
.equals(Components
.interfaces
.nsIFactory
))
116 throw Components
.results
.NS_ERROR_NOT_IMPLEMENTED
;
117 return this.nsCSTempExceptionsFactory
;
120 canUnload: function(compMgr
) {
124 nsCSTempExceptionsFactory
: {
126 createInstance: function(outer
, iid
) {
128 throw Components
.results
.NS_ERROR_NO_AGGREGATION
;
129 if (!iid
.equals(CSTEMPEXCEPTIONS_IID
) &&
130 !iid
.equals(Components
.interfaces
.nsISupports
))
131 throw Components
.results
.NS_ERROR_INVALID_ARG
;
132 return nsCSTempExceptions
;
137 function NSGetModule(comMgr
, fileSpec
) { return nsCSTempExceptionsModule
; }