utils.js (1399B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 // Number of terminal entries for the self-xss prevention to go away 8 const CONSOLE_ENTRY_THRESHOLD = 5; 9 10 var WebConsoleUtils = { 11 CONSOLE_ENTRY_THRESHOLD, 12 13 /** 14 * Wrap a string in an nsISupportsString object. 15 * 16 * @param string string 17 * @return nsISupportsString 18 */ 19 supportsString(string) { 20 const str = Cc["@mozilla.org/supports-string;1"].createInstance( 21 Ci.nsISupportsString 22 ); 23 str.data = string; 24 return str; 25 }, 26 27 /** 28 * Value of devtools.selfxss.count preference 29 * 30 * @type number 31 * @private 32 */ 33 _usageCount: 0, 34 get usageCount() { 35 if (WebConsoleUtils._usageCount < CONSOLE_ENTRY_THRESHOLD) { 36 WebConsoleUtils._usageCount = Services.prefs.getIntPref( 37 "devtools.selfxss.count" 38 ); 39 if (Services.prefs.getBoolPref("devtools.chrome.enabled")) { 40 WebConsoleUtils.usageCount = CONSOLE_ENTRY_THRESHOLD; 41 } 42 } 43 return WebConsoleUtils._usageCount; 44 }, 45 set usageCount(newUC) { 46 if (newUC <= CONSOLE_ENTRY_THRESHOLD) { 47 WebConsoleUtils._usageCount = newUC; 48 Services.prefs.setIntPref("devtools.selfxss.count", newUC); 49 } 50 }, 51 }; 52 53 exports.Utils = WebConsoleUtils;