43 const Cc = Components.classes;
44 const Ci = Components.interfaces;
50 if (!this._bundleBrowser)
51 this._bundleBrowser = document.getElementById(
"bundleBrowser");
52 return this._bundleBrowser;
55 get selectedTimespan()
57 var durList = document.getElementById(
"sanitizeDurationChoice");
58 return parseInt(durList.value);
61 get sanitizePreferences()
63 if (!this._sanitizePreferences) {
64 this._sanitizePreferences =
65 document.getElementById(
"sanitizePreferences");
67 return this._sanitizePreferences;
72 return document.getElementById(
"sanitizeEverythingWarningBox");
81 s.prefDomain =
"privacy.cpd.";
82 for (let
i = 0;
i < this.sanitizePreferences.childNodes.length; ++
i) {
83 var preference = this.sanitizePreferences.childNodes[
i];
84 var
name = s.getNameFromPreference(preference.name);
85 if (!s.canClearItem(name))
86 preference.disabled =
true;
89 document.documentElement.getButton(
"accept").label =
90 this.bundleBrowser.getString(
"sanitizeButtonOK");
92 if (this.selectedTimespan ===
Sanitizer.TIMESPAN_EVERYTHING) {
93 this.prepareWarning();
94 this.warningBox.hidden =
false;
97 this.warningBox.hidden =
true;
100 selectByTimespan:
function ()
107 var warningBox = this.warningBox;
110 if (this.selectedTimespan ===
Sanitizer.TIMESPAN_EVERYTHING) {
111 this.prepareWarning();
112 if (warningBox.hidden) {
113 warningBox.hidden =
false;
114 window.resizeBy(0, warningBox.boxObject.height);
117 this.bundleBrowser.getString(
"sanitizeDialog2.everything.title");
122 if (!warningBox.hidden) {
123 window.resizeBy(0, -warningBox.boxObject.height);
124 warningBox.hidden =
true;
127 window.document.documentElement.getAttribute(
"noneverythingtitle");
135 s.prefDomain =
"privacy.cpd.";
137 s.range =
Sanitizer.getClearRange(this.selectedTimespan);
138 s.ignoreTimespan = !s.range;
143 Components.utils.reportError(
"Exception during sanitize: " + er);
156 prepareWarning:
function (aDontShowItemList) {
162 if (this.hasNonSelectedItems()) {
163 warningStringID =
"sanitizeSelectedWarning";
164 if (!aDontShowItemList)
168 warningStringID =
"sanitizeEverythingWarning2";
171 var warningDesc = document.getElementById(
"sanitizeEverythingWarning");
172 warningDesc.textContent =
173 this.bundleBrowser.getString(warningStringID);
180 onReadGeneric:
function ()
186 while (!found && i < this.sanitizePreferences.childNodes.length) {
187 var preference = this.sanitizePreferences.childNodes[
i];
189 found = !!preference.value &&
190 !preference.disabled;
195 document.documentElement.getButton(
"accept").disabled = !found;
200 this.prepareWarning(
true);
213 updatePrefs :
function ()
215 var tsPref = document.getElementById(
"privacy.sanitize.timeSpan");
216 Sanitizer.prefs.setIntPref(
"timeSpan", this.selectedTimespan);
219 document.getElementById(
"privacy.cpd.downloads").value =
220 document.getElementById(
"privacy.cpd.history").value;
224 var
prefs = this.sanitizePreferences.rootBranch;
225 for (let
i = 0;
i < this.sanitizePreferences.childNodes.length; ++
i) {
226 var
p = this.sanitizePreferences.childNodes[
i];
227 prefs.setBoolPref(p.name, p.value);
234 hasNonSelectedItems:
function () {
235 let checkboxes = document.querySelectorAll(
"#itemList > [preference]");
236 for (let
i = 0;
i < checkboxes.length; ++
i) {
247 showItemList:
function () {
248 var itemList = document.getElementById(
"itemList");
249 var expanderButton = document.getElementById(
"detailsExpander");
251 if (itemList.collapsed) {
252 expanderButton.className =
"expander-up";
253 itemList.setAttribute(
"collapsed",
"false");
254 if (document.documentElement.boxObject.height)
255 window.resizeBy(0, itemList.boxObject.height);
262 hideItemList:
function () {
263 var itemList = document.getElementById(
"itemList");
264 var expanderButton = document.getElementById(
"detailsExpander");
266 if (!itemList.collapsed) {
267 expanderButton.className =
"expander-down";
268 window.resizeBy(0, -itemList.boxObject.height);
269 itemList.setAttribute(
"collapsed",
"true");
276 toggleItemList:
function ()
278 var itemList = document.getElementById(
"itemList");
280 if (itemList.collapsed)
286 #ifdef CRH_DIALOG_TREE_VIEW
290 get TIMESPAN_CUSTOM()
297 if (!this._placesTree)
298 this._placesTree = document.getElementById(
"placesTree");
299 return this._placesTree;
308 s.prefDomain =
"privacy.cpd.";
309 for (let
i = 0;
i < this.sanitizePreferences.childNodes.length; ++
i) {
310 var preference = this.sanitizePreferences.childNodes[
i];
311 var
name = s.getNameFromPreference(preference.name);
312 if (!s.canClearItem(name))
313 preference.disabled =
true;
316 document.documentElement.getButton(
"accept").label =
317 this.bundleBrowser.getString(
"sanitizeButtonOK");
319 this.selectByTimespan();
328 initDurationDropdown:
function ()
331 this.durationStartTimes = {};
333 var durPopup = document.getElementById(
"sanitizeDurationPopup");
334 var durMenuitems = durPopup.childNodes;
335 for (let
i = 0;
i < durMenuitems.length;
i++) {
336 let durMenuitem = durMenuitems[
i];
337 let durVal = parseInt(durMenuitem.value);
338 if (durMenuitem.localName ===
"menuitem" &&
339 durVal !==
Sanitizer.TIMESPAN_EVERYTHING &&
340 durVal !==
this.TIMESPAN_CUSTOM) {
341 durVals.push(durVal);
342 let durTimes =
Sanitizer.getClearRange(durVal);
343 this.durationStartTimes[durVal] = durTimes[0];
355 this.durationRowsToVals = {};
356 this.durationValsToRows = {};
357 var view = this.placesTree.view;
359 for (let
i = 0;
i < view.rowCount - 1;
i++) {
360 let unfoundDurVals = [];
361 let nodeTime = view.QueryInterface(
Ci.nsINavHistoryResultTreeViewer).
362 nodeForTreeIndex(
i).time;
366 for (let j = 0; j < durVals.length; j++) {
367 let durVal = durVals[j];
368 let durStartTime = this.durationStartTimes[durVal];
369 if (nodeTime < durStartTime) {
370 this.durationValsToRows[durVal] =
i - 1;
371 this.durationRowsToVals[
i - 1] = durVal;
374 unfoundDurVals.push(durVal);
376 durVals = unfoundDurVals;
382 for (let
i = 0;
i < durVals.length;
i++) {
383 let durVal = durVals[
i];
384 this.durationValsToRows[durVal] = view.rowCount - 2;
385 this.durationRowsToVals[view.rowCount - 2] = durVal;
392 ensurePlacesTreeIsInited:
function ()
394 if (this._placesTreeIsInited)
397 this._placesTreeIsInited =
true;
405 if (times[1] - times[0] < 14400000000) {
409 var histServ =
Cc[
"@mozilla.org/browser/nav-history-service;1"].
411 var query = histServ.getNewQuery();
412 query.beginTimeReference = query.TIME_RELATIVE_EPOCH;
413 query.beginTime = times[0];
414 query.endTimeReference = query.TIME_RELATIVE_EPOCH;
415 query.endTime = times[1];
416 var opts = histServ.getNewQueryOptions();
417 opts.sortingMode = opts.SORT_BY_DATE_DESCENDING;
418 opts.queryType = opts.QUERY_TYPE_HISTORY;
419 var result = histServ.executeQuery(query, opts);
421 var view = gContiguousSelectionTreeHelper.setTree(this.placesTree,
423 result.viewer = view;
424 this.initDurationDropdown();
433 selectByTimespan:
function ()
440 var durDeck = document.getElementById(
"durationDeck");
441 var durList = document.getElementById(
"sanitizeDurationChoice");
442 var durVal = parseInt(durList.value);
443 var durCustom = document.getElementById(
"sanitizeDurationCustom");
449 if (durVal === this.TIMESPAN_CUSTOM) {
450 durCustom.hidden =
false;
453 durCustom.hidden =
true;
456 if (durVal ===
Sanitizer.TIMESPAN_EVERYTHING) {
457 this.prepareWarning();
458 durDeck.selectedIndex = 1;
460 this.bundleBrowser.getString(
"sanitizeDialog2.everything.title");
461 document.documentElement.getButton(
"accept").disabled =
false;
467 this.ensurePlacesTreeIsInited();
468 durDeck.selectedIndex = 0;
470 window.document.documentElement.getAttribute(
"noneverythingtitle");
471 var durRow = this.durationValsToRows[durVal];
472 gContiguousSelectionTreeHelper.rangedSelect(durRow);
473 gContiguousSelectionTreeHelper.scrollToGrippy();
477 document.documentElement.getButton(
"accept").disabled = durRow < 0;
485 s.prefDomain =
"privacy.cpd.";
487 var durList = document.getElementById(
"sanitizeDurationChoice");
488 var durValue = parseInt(durList.value);
489 s.ignoreTimespan = durValue ===
Sanitizer.TIMESPAN_EVERYTHING;
492 if (!s.ignoreTimespan) {
494 if (durValue === this.TIMESPAN_CUSTOM) {
495 var view = this.placesTree.view;
496 var
now = Date.now() * 1000;
499 if (view.selection.getRangeCount() === 0)
500 s.range = [now, now];
502 var startIndexRef = {};
504 view.selection.getRangeAt(0, {}, startIndexRef);
505 view.QueryInterface(
Ci.nsINavHistoryResultTreeViewer);
506 var startNode = view.nodeForTreeIndex(startIndexRef.value);
507 s.range = [startNode.time,
now];
512 s.range = [this.durationStartTimes[durValue], Date.now() * 1000];
518 Components.utils.reportError(
"Exception during sanitize: " + er);
530 var view = this.placesTree.view;
531 view.QueryInterface(
Ci.nsINavHistoryResultViewer).result.viewer =
null;
532 this.placesTree.view =
null;
546 grippyMoved:
function (aEventName, aEvent)
548 gContiguousSelectionTreeHelper[aEventName](aEvent);
549 var lastSelRow = gContiguousSelectionTreeHelper.getGrippyRow() - 1;
550 var durList = document.getElementById(
"sanitizeDurationChoice");
551 var durValue = parseInt(durList.value);
555 if ((durValue !== this.TIMESPAN_CUSTOM ||
556 lastSelRow in this.durationRowsToVals) &&
557 (durValue === this.TIMESPAN_CUSTOM ||
558 this.durationValsToRows[durValue] !== lastSelRow)) {
561 if (lastSelRow in this.durationRowsToVals)
562 durList.value = this.durationRowsToVals[lastSelRow];
564 durList.value = this.TIMESPAN_CUSTOM;
568 document.documentElement.getButton(
"accept").disabled = lastSelRow < 0;
575 #ifdef CRH_DIALOG_TREE_VIEW
579 var gContiguousSelectionTreeHelper = {
602 setTree:
function CSTH_setTree(aTreeElement, aProtoTreeView)
604 this._tree = aTreeElement;
605 var newView = this._makeTreeView(aProtoTreeView || aTreeElement.view);
606 aTreeElement.view = newView;
617 getGrippyRow:
function CSTH_getGrippyRow()
619 var sel = this.tree.view.selection;
620 var rangeCount = sel.getRangeCount();
621 if (rangeCount === 0)
623 if (rangeCount !== 1) {
624 throw "contiguous selection tree helper: getGrippyRow called with " +
625 "multiple selection ranges";
628 sel.getRangeAt(0, {}, max);
629 return max.value + 1;
639 ondragover:
function CSTH_ondragover(aEvent)
643 var ds =
Cc[
"@mozilla.org/widget/dragservice;1"].
649 var tbo = this.tree.treeBoxObject;
650 aEvent.QueryInterface(
Ci.nsIDOMMouseEvent);
651 var hoverRow = tbo.getRowAt(aEvent.clientX, aEvent.clientY);
656 this.rangedSelect(hoverRow - 1);
666 ondragstart:
function CSTH_ondragstart(aEvent)
668 var tbo = this.tree.treeBoxObject;
669 var clickedRow = tbo.getRowAt(aEvent.clientX, aEvent.clientY);
671 if (clickedRow !== this.getGrippyRow())
678 var arr =
Cc[
"@mozilla.org/supports-array;1"].
680 var trans =
Cc[
"@mozilla.org/widget/transferable;1"].
682 trans.setTransferData(
'dummy-flavor',
null, 0);
683 arr.AppendElement(trans);
684 var reg =
Cc[
"@mozilla.org/gfx/region;1"].
686 reg.setToRect(Infinity, Infinity, 1, 1);
687 var ds =
Cc[
"@mozilla.org/widget/dragservice;1"].
689 ds.invokeDragSession(aEvent.target, arr, reg, ds.DRAGDROP_ACTION_MOVE);
700 onkeypress:
function CSTH_onkeypress(aEvent)
702 var grippyRow = this.getGrippyRow();
703 var tbo = this.tree.treeBoxObject;
705 switch (aEvent.keyCode) {
706 case aEvent.DOM_VK_HOME:
709 case aEvent.DOM_VK_PAGE_UP:
710 rangeEnd = grippyRow - tbo.getPageLength();
712 case aEvent.DOM_VK_UP:
713 rangeEnd = grippyRow - 2;
715 case aEvent.DOM_VK_DOWN:
716 rangeEnd = grippyRow;
718 case aEvent.DOM_VK_PAGE_DOWN:
719 rangeEnd = grippyRow + tbo.getPageLength();
721 case aEvent.DOM_VK_END:
722 rangeEnd = this.tree.view.rowCount - 2;
729 aEvent.stopPropagation();
735 else if (this.tree.view.rowCount - 2 < rangeEnd)
736 rangeEnd = this.tree.view.rowCount - 2;
739 this.rangedSelect(rangeEnd);
743 if (rangeEnd < grippyRow)
744 tbo.ensureRowIsVisible(rangeEnd < 0 ? 0 : rangeEnd);
746 if (rangeEnd + 2 < this.tree.view.rowCount)
747 tbo.ensureRowIsVisible(rangeEnd + 2);
748 else if (rangeEnd + 1 < this.tree.view.rowCount)
749 tbo.ensureRowIsVisible(rangeEnd + 1);
761 onmousedown:
function CSTH_onmousedown(aEvent)
763 var tbo = this.tree.treeBoxObject;
764 var clickedRow = tbo.getRowAt(aEvent.clientX, aEvent.clientY);
766 if (clickedRow < 0 || clickedRow >= this.tree.view.rowCount)
769 if (clickedRow < this.getGrippyRow())
770 this.rangedSelect(clickedRow);
771 else if (clickedRow > this.getGrippyRow())
772 this.rangedSelect(clickedRow - 1);
783 rangedSelect:
function CSTH_rangedSelect(aEndRow)
785 var tbo = this.tree.treeBoxObject;
787 this.tree.view.selection.clearSelection();
789 this.tree.view.selection.rangedSelect(0, aEndRow,
false);
790 tbo.invalidateRange(tbo.getFirstVisibleRow(), tbo.getLastVisibleRow());
796 scrollToGrippy:
function CSTH_scrollToGrippy()
798 var rowCount = this.tree.view.rowCount;
799 var tbo = this.tree.treeBoxObject;
800 var pageLen = tbo.getPageLength() ||
801 parseInt(this.tree.getAttribute(
"rows")) ||
805 if (rowCount <= pageLen)
808 var scrollToRow = this.getGrippyRow() - Math.ceil(pageLen / 2.0);
815 else if (rowCount < scrollToRow + pageLen)
816 scrollToRow = rowCount - pageLen;
818 tbo.scrollToRow(scrollToRow);
829 _makeTreeView:
function CSTH__makeTreeView(aProtoTreeView)
831 var atomServ =
Cc[
"@mozilla.org/atom-service;1"].
834 var view = aProtoTreeView;
839 view.isSeparator =
function CSTH_View_isSeparator(aRow)
841 return aRow === that.getGrippyRow();
845 view.__defineGetter__(
"_rowCount", view.__lookupGetter__(
"rowCount"));
846 view.__defineGetter__(
"rowCount",
847 function CSTH_View_rowCount()
849 return this._rowCount + 1;
854 view.canDrop =
function CSTH_View_canDrop() {
return false; };
857 view.cycleHeader =
function CSTH_View_cycleHeader() {};
858 view.sortingChanged =
function CSTH_View_sortingChanged() {};
862 view._getCellProperties = view.getCellProperties;
863 view.getCellProperties =
864 function CSTH_View_getCellProperties(aRow, aCol, aProps)
866 var grippyRow = that.getGrippyRow();
867 if (aRow === grippyRow)
868 aProps.AppendElement(atomServ.getAtom(
"grippyRow"));
869 else if (aRow < grippyRow)
870 this._getCellProperties(aRow, aCol, aProps);
872 this._getCellProperties(aRow - 1, aCol, aProps);
875 view._getRowProperties = view.getRowProperties;
876 view.getRowProperties =
877 function CSTH_View_getRowProperties(aRow, aProps)
879 var grippyRow = that.getGrippyRow();
880 if (aRow === grippyRow)
881 aProps.AppendElement(atomServ.getAtom(
"grippyRow"));
882 else if (aRow < grippyRow)
883 this._getRowProperties(aRow, aProps);
885 this._getRowProperties(aRow - 1, aProps);
888 view._getCellText = view.getCellText;
890 function CSTH_View_getCellText(aRow, aCol)
892 var grippyRow = that.getGrippyRow();
893 if (aRow === grippyRow)
895 aRow = aRow < grippyRow ? aRow : aRow - 1;
896 return this._getCellText(aRow, aCol);
899 view._getImageSrc = view.getImageSrc;
901 function CSTH_View_getImageSrc(aRow, aCol)
903 var grippyRow = that.getGrippyRow();
904 if (aRow === grippyRow)
906 aRow = aRow < grippyRow ? aRow : aRow - 1;
907 return this._getImageSrc(aRow, aCol);
910 view.isContainer =
function CSTH_View_isContainer(aRow) {
return false; };
911 view.getParentIndex =
function CSTH_View_getParentIndex(aRow) {
return -1; };
912 view.getLevel =
function CSTH_View_getLevel(aRow) {
return 0; };
913 view.hasNextSibling =
function CSTH_View_hasNextSibling(aRow, aAfterIndex)
915 return aRow < this.rowCount - 1;
getService(Ci.sbIFaceplateManager)
var gSanitizePromptDialog
return aWindow document documentElement getAttribute(aAttribute)||dimension
function PlacesTreeView(aFlatList, aOnOpenFlatContainer)
_getSelectedPageStyle s i