sanitizeOverlay.js
Go to the documentation of this file.
1 /*
2  //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
27  checkBox: null,
28  prefs: null,
29  webLibrary: null,
30  timeout: null,
31 
32  onLoad: function() { gSongbirdSanitizeOverlay.init(); },
33  onUnload: function(event) { gSongbirdSanitizeOverlay.reset(); },
34  onCommand: function(event) { gSongbirdSanitizeOverlay.onCheckboxChanged(); },
35 
36  init: function() {
37  window.removeEventListener('load', gSongbirdSanitizeOverlay.onLoad, false);
38  window.addEventListener('unload', gSongbirdSanitizeOverlay.onUnload, false);
39  var prefs = Components.classes["@mozilla.org/preferences-service;1"]
40  .getService(Components.interfaces.nsIPrefBranch2);
41  var guid = prefs.getComplexValue("songbird.library.web",
42  Components.interfaces.nsISupportsString);
43 
44  var libraryManager =
45  Components.classes["@songbirdnest.com/Songbird/library/Manager;1"]
46  .getService(Components.interfaces.sbILibraryManager);
47 
48  this.webLibrary = libraryManager.getLibrary(guid);
49  this.webLibrary.addListener(this,
50  false,
51  Components.interfaces.sbIMediaList.LISTENER_FLAGS_ALL,
52  null);
53 
54  var prefpane = document.getElementById("SanitizeDialogPane");
55  if (prefpane) {
56  var children = prefpane.childNodes;
57  for (var i=0;i<children.length;i++) {
58  if (children[i].tagName == "preferences" || children[i].tagName == "xul:preferences") {
59  this.prefs = children[i];
60  }
61  if (!this.checkBox && (children[i].tagName == "checkbox" || children[i].tagName == "xul:checkbox")) {
62  this.checkBox = document.createElement("checkbox");
63  this.checkBox.setAttribute("id", "sanitize.mediaHistory");
64  this.checkBox.setAttribute("label", SBString("sanitize.mediaHistory.label", "Web Media History"));
65  this.checkBox.setAttribute("accesskey", SBString("sanitize.mediaHistory.accesskey", "W"));
66  this.checkBox.setAttribute("oncommand", "gSongbirdSanitizeOverlay.onCommand();");
67  this.updateDisabled();
68  prefpane.insertBefore(this.checkBox, children[i]);
69  continue;
70  }
71  }
72  }
73  if (this.checkBox && this.prefs) {
74  this.checkBox.setAttribute("checked", this.prefs.rootBranch.getBoolPref("privacy.item.mediaHistory"));
75  }
76 
77  var helpButton = document.documentElement.getButton("help");
78  if (helpButton) {
79  // remove the help button from the sanitize prefs dialog (not the do sanitize one)
80  // Would be better to just set the dlgbuttons attribute, but that doesn't work
81  helpButton.collapsed = true;
82  }
83  },
84 
85  updateDisabled: function() {
86  this.checkBox.setAttribute("disabled", this.webLibrary.length > 0 ? "false" : "true");
87  },
88 
89  reset: function() {
90  this.clearUpdateTimeout();
91  this.webLibrary.removeListener(this);
92  window.removeEventListener('unload', gSongbirdSanitizeOverlay.onUnload, false);
93  },
94 
95  onCheckboxChanged: function() {
96  this.prefs.rootBranch.setBoolPref("privacy.item.mediaHistory", this.checkBox.checked);
97  },
98 
99  onWebHistoryChanged: function() {
100  this.clearUpdateTimeout();
101  this.timeout = setTimeout(function(obj) { obj.updateTimeout(); }, 10, this);
102  },
103 
104  clearUpdateTimeout: function() {
105  if (this.timeout) {
106  clearTimeout(this.timeout);
107  this.timeout = null;
108  }
109  },
110 
111  updateTimeout: function() {
112  this.updateDisabled();
113  this.timeout = null;
114  },
115 
116  // mediaListListener
117  onItemAdded: function(aMediaList, aMediaItem, aIndex) { gSongbirdSanitizeOverlay.onWebHistoryChanged(); return true; },
118  onBeforeItemRemoved: function(aMediaList, aMediaItem, aIndex) { return true; },
119  onAfterItemRemoved: function(aMediaList, aMediaItem, aIndex) { gSongbirdSanitizeOverlay.onWebHistoryChanged(); return true; },
120  onItemUpdated: function(aMediaList, aMediaItem, aProperties) { return true; },
121  onItemMoved: function(aMediaList, aFromIndex, aToIndex) { return true; },
122  onBeforeListCleared: function(aMediaList, aExcludeLists) { return true; },
123  onListCleared: function(aMediaList, aExcludeLists) { gSongbirdSanitizeOverlay.onWebHistoryChanged(); return true; },
124  onBatchBegin: function(aMediaList) {},
125  onBatchEnd: function(aMediaList) { gSongbirdSanitizeOverlay.onWebHistoryChanged(); },
126 
127  QueryInterface: function (aIID) {
128  if (aIID.equals(Components.interfaces.nsISupports) ||
129  aIID.equals(Components.interfaces.sbIMediaListListener))
130  {
131  return this;
132  }
133  throw Components.results.NS_ERROR_NO_INTERFACE;
134  }
135 
136 
137 };
138 
139 window.addEventListener('load', gSongbirdSanitizeOverlay.onLoad, false);
var event
sbOSDControlService prototype QueryInterface
function SBString(aKey, aDefault, aStringBundle)
Definition: StringUtils.jsm:93
let window
_window init
Definition: FeedWriter.js:1144
var gSongbirdSanitizeOverlay
Lastfm onLoad
Definition: mini.js:36
var libraryManager
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
return null
Definition: FeedWriter.js:1143
var prefs
Definition: FeedWriter.js:1169
function onUnload()
onUnload - called when the cover preview window unloads.
Definition: coverPreview.js:36
_getSelectedPageStyle s i