diff options
Diffstat (limited to 'comm/suite/components/sanitize/content')
-rw-r--r-- | comm/suite/components/sanitize/content/sanitizeDialog.js | 111 | ||||
-rw-r--r-- | comm/suite/components/sanitize/content/sanitizeDialog.xul | 154 |
2 files changed, 265 insertions, 0 deletions
diff --git a/comm/suite/components/sanitize/content/sanitizeDialog.js b/comm/suite/components/sanitize/content/sanitizeDialog.js new file mode 100644 index 0000000000..aadc73ad10 --- /dev/null +++ b/comm/suite/components/sanitize/content/sanitizeDialog.js @@ -0,0 +1,111 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); +var { Sanitizer } = ChromeUtils.import("resource:///modules/Sanitizer.jsm"); + +var gSanitizePromptDialog = { + + get bundleSanitize() { + if (!this._bundleSanitize) + this._bundleSanitize = document.getElementById("bundleSanitize"); + return this._bundleSanitize; + }, + + get selectedTimespan() { + var durList = document.getElementById("sanitizeDurationChoice"); + return parseInt(durList.value); + }, + + get sanitizePreferences() { + if (!this._sanitizePreferences) { + this._sanitizePreferences = + document.getElementById("sanitizePreferences"); + } + return this._sanitizePreferences; + }, + + init() { + document.documentElement.getButton("accept").label = + this.bundleSanitize.getString("sanitizeButtonOK"); + }, + + sanitize() { + // Update pref values before handing off to the sanitizer. + this.updatePrefs(); + + // As the sanitize is async, we disable the buttons, update the label on + // the 'accept' button to indicate things are happening and return false. + // Once the async operation completes (either with or without errors) + // we close the window. + let docElt = document.documentElement; + let acceptButton = docElt.getButton("accept"); + acceptButton.disabled = true; + acceptButton.setAttribute("label", + this.bundleSanitize + .getString("sanitizeButtonClearing")); + docElt.getButton("cancel").disabled = true; + + try { + let range = Sanitizer.getClearRange(this.selectedTimespan); + let options = { + ignoreTimespan: !range, + range, + }; + Sanitizer.sanitize(null, options) + .catch(Cu.reportError) + .then(() => window.close()) + .catch(Cu.reportError); + return false; + } catch (er) { + Cu.reportError("Exception during sanitize: " + er); + return true; // We *do* want to close immediately on error. + } + }, + + /** + * Called when the value of a preference element is synced from the actual + * pref. Enables or disables the OK button appropriately. + */ + onReadGeneric() { + var found = false; + + // Find any other pref that's checked and enabled. + var i = 0; + while (!found && i < this.sanitizePreferences.childNodes.length) { + var preference = this.sanitizePreferences.childNodes[i]; + + found = !!preference.value && + !preference.disabled; + i++; + } + + try { + document.documentElement.getButton("accept").disabled = !found; + } catch (e) { } + + return undefined; + }, + + /** + * Sanitizer.prototype.sanitize() requires the prefs to be up-to-date. + * Because the type of this prefwindow is "child" -- and that's needed + * because without it the dialog has no OK and Cancel buttons -- the + * prefs are not updated on dialogaccept on platforms that don't support + * instant-apply (i.e., Windows). We must therefore manually set the prefs + * from their corresponding preference elements. + */ + updatePrefs() { + Services.prefs.setIntPref(Sanitizer.PREF_TIMESPAN, this.selectedTimespan); + + // Now manually set the prefs from their corresponding preference + // elements. + var prefs = this.sanitizePreferences.rootBranch; + for (let i = 0; i < this.sanitizePreferences.childNodes.length; ++i) { + var p = this.sanitizePreferences.childNodes[i]; + prefs.setBoolPref(p.name, p.value); + } + }, +}; diff --git a/comm/suite/components/sanitize/content/sanitizeDialog.xul b/comm/suite/components/sanitize/content/sanitizeDialog.xul new file mode 100644 index 0000000000..86c641751c --- /dev/null +++ b/comm/suite/components/sanitize/content/sanitizeDialog.xul @@ -0,0 +1,154 @@ +<?xml version="1.0"?> + +<!-- This Source Code Form is subject to the terms of the Mozilla Public + - License, v. 2.0. If a copy of the MPL was not distributed with this + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> + +<?xml-stylesheet href="chrome://global/skin/"?> +<?xml-stylesheet href="chrome://communicator/skin/sanitizeDialog.css"?> + +<!DOCTYPE prefwindow [ + <!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd"> + %brandDTD; + <!ENTITY % sanitizeDTD SYSTEM "chrome://communicator/locale/sanitize.dtd"> + %sanitizeDTD; +]> + +<dialog id="SanitizeDialog" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + title="&sanitizeDialog.title;" + dlgbuttons="accept,cancel" + style="width: &sanitizeDialog.width;;" + onload="gSanitizePromptDialog.init();" + ondialogaccept="return gSanitizePromptDialog.sanitize();"> + + <script src="chrome://communicator/content/sanitizeDialog.js"/> + <stringbundle id="bundleSanitize" + src="chrome://communicator/locale/sanitize.properties"/> + + <prefpane id="SanitizeDialogPane"> + <preferences id="sanitizePreferences"> + <preference id="privacy.cpd.history" + name="privacy.cpd.history" + type="bool"/> + <preference id="privacy.cpd.urlbar" + name="privacy.cpd.urlbar" + type="bool"/> + <preference id="privacy.cpd.downloads" + name="privacy.cpd.downloads" + type="bool"/> + <preference id="privacy.cpd.formdata" + name="privacy.cpd.formdata" + type="bool"/> + <preference id="privacy.cpd.cache" + name="privacy.cpd.cache" + type="bool"/> + <preference id="privacy.cpd.cookies" + name="privacy.cpd.cookies" + type="bool"/> + <preference id="privacy.cpd.offlineApps" + name="privacy.cpd.offlineApps" + type="bool"/> + <preference id="privacy.cpd.passwords" + name="privacy.cpd.passwords" + type="bool"/> + <preference id="privacy.cpd.sessions" + name="privacy.cpd.sessions" + type="bool"/> + <preference id="privacy.cpd.siteSettings" + name="privacy.cpd.siteSettings" + type="bool"/> + </preferences> + + <preferences id="nonItemPreferences"> + <preference id="privacy.sanitize.timeSpan" + name="privacy.sanitize.timeSpan" + type="int"/> + </preferences> + + <vbox id="sanitizeWarningBox"> + <spacer flex="1"/> + <hbox align="center"> + <image id="sanitizeWarningIcon"/> + <vbox id="sanitizeWarningDescBox" flex="1"> + <description id="sanitizeSelectedWarning"> + &sanitizeSelectedWarning; + </description> + <description id="sanitizeUndoWarning"> + &sanitizeUndoWarning; + </description> + </vbox> + </hbox> + <spacer flex="1"/> + </vbox> + + <separator class="thin"/> + + <hbox id="SanitizeDurationBox" align="center"> + <label id="sanitizeDurationLabel" + value="&clearTimeDuration.label;" + accesskey="&clearTimeDuration.accesskey;" + control="sanitizeDurationChoice"/> + <menulist id="sanitizeDurationChoice" + preference="privacy.sanitize.timeSpan" + flex="1"> + <menupopup id="sanitizeDurationPopup"> + <menuitem label="&clearTimeDuration.lastHour;" value="1"/> + <menuitem label="&clearTimeDuration.last2Hours;" value="2"/> + <menuitem label="&clearTimeDuration.last4Hours;" value="3"/> + <menuitem label="&clearTimeDuration.today;" value="4"/> + <menuseparator/> + <menuitem label="&clearTimeDuration.everything;" value="0"/> + </menupopup> + </menulist> + <label id="sanitizeDurationSuffixLabel" + value="&clearTimeDuration.suffix;"/> + </hbox> + + <separator class="thin"/> + + <groupbox id="itemList" flex="1"> + <caption label="&sanitizeItems.label;"/> + <checkbox label="&itemHistory.label;" + accesskey="&itemHistory.accesskey;" + preference="privacy.cpd.history" + onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/> + <checkbox label="&itemUrlBar.label;" + accesskey="&itemUrlBar.accesskey;" + preference="privacy.cpd.urlbar" + onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/> + <checkbox label="&itemDownloads.label;" + accesskey="&itemDownloads.accesskey;" + preference="privacy.cpd.downloads" + onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/> + <checkbox label="&itemFormSearchHistory.label;" + accesskey="&itemFormSearchHistory.accesskey;" + preference="privacy.cpd.formdata" + onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/> + <checkbox label="&itemCache.label;" + accesskey="&itemCache.accesskey;" + preference="privacy.cpd.cache" + onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/> + <checkbox label="&itemCookies.label;" + accesskey="&itemCookies.accesskey;" + preference="privacy.cpd.cookies" + onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/> + <checkbox label="&itemOfflineApps.label;" + accesskey="&itemOfflineApps.accesskey;" + preference="privacy.cpd.offlineApps" + onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/> + <checkbox label="&itemPasswords.label;" + accesskey="&itemPasswords.accesskey;" + preference="privacy.cpd.passwords" + onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/> + <checkbox label="&itemSessions.label;" + accesskey="&itemSessions.accesskey;" + preference="privacy.cpd.sessions" + onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/> + <checkbox label="&itemSitePreferences.label;" + accesskey="&itemSitePreferences.accesskey;" + preference="privacy.cpd.siteSettings" + onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/> + </groupbox> + </prefpane> +</dialog> |