зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1288475 - Remove code unused in client and server versions of webconsole utils;r=tromey
MozReview-Commit-ID: GcNg9nEI9d4 --HG-- extra : rebase_source : aa23b027673b9bcfcdb9d8751d528335ac5afbaa
This commit is contained in:
Родитель
5a0322040e
Коммит
ebd177e3cd
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -20,17 +20,6 @@ XPCOMUtils.defineLazyServiceGetter(this,
|
|||
"@mozilla.org/serviceworkers/manager;1",
|
||||
"nsIServiceWorkerManager");
|
||||
|
||||
// Match the function name from the result of toString() or toSource().
|
||||
//
|
||||
// Examples:
|
||||
// (function foobar(a, b) { ...
|
||||
// function foobar2(a) { ...
|
||||
// function() { ...
|
||||
const REGEX_MATCH_FUNCTION_NAME = /^\(?function\s+([^(\s]+)\s*\(/;
|
||||
|
||||
// Number of terminal entries for the self-xss prevention to go away
|
||||
const CONSOLE_ENTRY_THRESHOLD = 5;
|
||||
|
||||
const CONSOLE_WORKER_IDS = exports.CONSOLE_WORKER_IDS = [
|
||||
"SharedWorker",
|
||||
"ServiceWorker",
|
||||
|
@ -39,19 +28,6 @@ const CONSOLE_WORKER_IDS = exports.CONSOLE_WORKER_IDS = [
|
|||
|
||||
var WebConsoleUtils = {
|
||||
|
||||
/**
|
||||
* Wrap a string in an nsISupportsString object.
|
||||
*
|
||||
* @param string string
|
||||
* @return nsISupportsString
|
||||
*/
|
||||
supportsString: function (string) {
|
||||
let str = Cc["@mozilla.org/supports-string;1"]
|
||||
.createInstance(Ci.nsISupportsString);
|
||||
str.data = string;
|
||||
return str;
|
||||
},
|
||||
|
||||
/**
|
||||
* Given a message, return one of CONSOLE_WORKER_IDS if it matches
|
||||
* one of those.
|
||||
|
@ -107,23 +83,6 @@ var WebConsoleUtils = {
|
|||
return temp;
|
||||
},
|
||||
|
||||
/**
|
||||
* Copies certain style attributes from one element to another.
|
||||
*
|
||||
* @param nsIDOMNode from
|
||||
* The target node.
|
||||
* @param nsIDOMNode to
|
||||
* The destination node.
|
||||
*/
|
||||
copyTextStyles: function (from, to) {
|
||||
let win = from.ownerDocument.defaultView;
|
||||
let style = win.getComputedStyle(from);
|
||||
to.style.fontFamily = style.getPropertyCSSValue("font-family").cssText;
|
||||
to.style.fontSize = style.getPropertyCSSValue("font-size").cssText;
|
||||
to.style.fontWeight = style.getPropertyCSSValue("font-weight").cssText;
|
||||
to.style.fontStyle = style.getPropertyCSSValue("font-style").cssText;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the ID of the inner window of this DOM window.
|
||||
*
|
||||
|
@ -158,49 +117,6 @@ var WebConsoleUtils = {
|
|||
return ids;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the ID of the outer window of this DOM window.
|
||||
*
|
||||
* @param nsIDOMWindow window
|
||||
* @return integer
|
||||
* Outer ID for the given window.
|
||||
*/
|
||||
getOuterWindowId: function (window) {
|
||||
return window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
|
||||
},
|
||||
|
||||
/**
|
||||
* Tells if the given function is native or not.
|
||||
*
|
||||
* @param function func
|
||||
* The function you want to check if it is native or not.
|
||||
* @return boolean
|
||||
* True if the given function is native, false otherwise.
|
||||
*/
|
||||
isNativeFunction: function (func) {
|
||||
return typeof func == "function" && !("prototype" in func);
|
||||
},
|
||||
|
||||
/**
|
||||
* Tells if the given property of the provided object is a
|
||||
* non-native getter or not.
|
||||
*
|
||||
* @param object object
|
||||
* The object that contains the property.
|
||||
* @param string prop
|
||||
* The property you want to check if it is a getter or not.
|
||||
* @return boolean
|
||||
* True if the given property is a getter, false otherwise.
|
||||
*/
|
||||
isNonNativeGetter: function (object, prop) {
|
||||
if (typeof object != "object") {
|
||||
return false;
|
||||
}
|
||||
let desc = this.getPropertyDescriptor(object, prop);
|
||||
return desc && desc.get && !this.isNativeFunction(desc.get);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the property descriptor for the given object.
|
||||
*
|
||||
|
@ -240,38 +156,6 @@ var WebConsoleUtils = {
|
|||
return desc;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sort function for object properties.
|
||||
*
|
||||
* @param object a
|
||||
* Property descriptor.
|
||||
* @param object b
|
||||
* Property descriptor.
|
||||
* @return integer
|
||||
* -1 if a.name < b.name,
|
||||
* 1 if a.name > b.name,
|
||||
* 0 otherwise.
|
||||
*/
|
||||
propertiesSort: function (a, b) {
|
||||
// Convert the pair.name to a number for later sorting.
|
||||
let number = parseFloat(a.name);
|
||||
let bNumber = parseFloat(b.name);
|
||||
|
||||
// Sort numbers, then string.
|
||||
if (!isNaN(number) && isNaN(bNumber)) {
|
||||
return -1;
|
||||
} else if (isNaN(number) && !isNaN(bNumber)) {
|
||||
return 1;
|
||||
} else if (!isNaN(number) && !isNaN(bNumber)) {
|
||||
return number - bNumber;
|
||||
} else if (a.name < b.name) {
|
||||
return -1;
|
||||
} else if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a grip for the given value. If the value is an object,
|
||||
* an object wrapper will be created.
|
||||
|
@ -317,303 +201,10 @@ var WebConsoleUtils = {
|
|||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if the given object is an iterator or a generator.
|
||||
*
|
||||
* @param object object
|
||||
* The object you want to check.
|
||||
* @return boolean
|
||||
* True if the given object is an iterator or a generator, otherwise
|
||||
* false is returned.
|
||||
*/
|
||||
isIteratorOrGenerator: function (object) {
|
||||
if (object === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof object == "object") {
|
||||
if (typeof object.__iterator__ == "function" ||
|
||||
object.constructor && object.constructor.name == "Iterator") {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
let str = object.toString();
|
||||
if (typeof object.next == "function" &&
|
||||
str.indexOf("[object Generator") == 0) {
|
||||
return true;
|
||||
}
|
||||
} catch (ex) {
|
||||
// window.history.next throws in the typeof check above.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Determine if the given request mixes HTTP with HTTPS content.
|
||||
*
|
||||
* @param string request
|
||||
* Location of the requested content.
|
||||
* @param string location
|
||||
* Location of the current page.
|
||||
* @return boolean
|
||||
* True if the content is mixed, false if not.
|
||||
*/
|
||||
isMixedHTTPSRequest: function (request, location) {
|
||||
try {
|
||||
let requestURI = Services.io.newURI(request, null, null);
|
||||
let contentURI = Services.io.newURI(location, null, null);
|
||||
return (contentURI.scheme == "https" && requestURI.scheme != "https");
|
||||
} catch (ex) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function to deduce the name of the provided function.
|
||||
*
|
||||
* @param funtion function
|
||||
* The function whose name will be returned.
|
||||
* @return string
|
||||
* Function name.
|
||||
*/
|
||||
getFunctionName: function (func) {
|
||||
let name = null;
|
||||
if (func.name) {
|
||||
name = func.name;
|
||||
} else {
|
||||
let desc;
|
||||
try {
|
||||
desc = func.getOwnPropertyDescriptor("displayName");
|
||||
} catch (ex) {
|
||||
// Ignore.
|
||||
}
|
||||
if (desc && typeof desc.value == "string") {
|
||||
name = desc.value;
|
||||
}
|
||||
}
|
||||
if (!name) {
|
||||
try {
|
||||
let str = (func.toString() || func.toSource()) + "";
|
||||
name = (str.match(REGEX_MATCH_FUNCTION_NAME) || [])[1];
|
||||
} catch (ex) {
|
||||
// Ignore.
|
||||
}
|
||||
}
|
||||
return name;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the object class name. For example, the |window| object has the Window
|
||||
* class name (based on [object Window]).
|
||||
*
|
||||
* @param object object
|
||||
* The object you want to get the class name for.
|
||||
* @return string
|
||||
* The object class name.
|
||||
*/
|
||||
getObjectClassName: function (object) {
|
||||
if (object === null) {
|
||||
return "null";
|
||||
}
|
||||
if (object === undefined) {
|
||||
return "undefined";
|
||||
}
|
||||
|
||||
let type = typeof object;
|
||||
if (type != "object") {
|
||||
// Grip class names should start with an uppercase letter.
|
||||
return type.charAt(0).toUpperCase() + type.substr(1);
|
||||
}
|
||||
|
||||
let className;
|
||||
|
||||
try {
|
||||
className = ((object + "").match(/^\[object (\S+)\]$/) || [])[1];
|
||||
if (!className) {
|
||||
className = ((object.constructor + "")
|
||||
.match(/^\[object (\S+)\]$/) || [])[1];
|
||||
}
|
||||
if (!className && typeof object.constructor == "function") {
|
||||
className = this.getFunctionName(object.constructor);
|
||||
}
|
||||
} catch (ex) {
|
||||
// Ignore.
|
||||
}
|
||||
|
||||
return className;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if the given value is a grip with an actor.
|
||||
*
|
||||
* @param mixed grip
|
||||
* Value you want to check if it is a grip with an actor.
|
||||
* @return boolean
|
||||
* True if the given value is a grip with an actor.
|
||||
*/
|
||||
isActorGrip: function (grip) {
|
||||
return grip && typeof (grip) == "object" && grip.actor;
|
||||
},
|
||||
|
||||
/**
|
||||
* Value of devtools.selfxss.count preference
|
||||
*
|
||||
* @type number
|
||||
* @private
|
||||
*/
|
||||
_usageCount: 0,
|
||||
get usageCount() {
|
||||
if (WebConsoleUtils._usageCount < CONSOLE_ENTRY_THRESHOLD) {
|
||||
WebConsoleUtils._usageCount =
|
||||
Services.prefs.getIntPref("devtools.selfxss.count");
|
||||
if (Services.prefs.getBoolPref("devtools.chrome.enabled")) {
|
||||
WebConsoleUtils.usageCount = CONSOLE_ENTRY_THRESHOLD;
|
||||
}
|
||||
}
|
||||
return WebConsoleUtils._usageCount;
|
||||
},
|
||||
set usageCount(newUC) {
|
||||
if (newUC <= CONSOLE_ENTRY_THRESHOLD) {
|
||||
WebConsoleUtils._usageCount = newUC;
|
||||
Services.prefs.setIntPref("devtools.selfxss.count", newUC);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* The inputNode "paste" event handler generator. Helps prevent
|
||||
* self-xss attacks
|
||||
*
|
||||
* @param nsIDOMElement inputField
|
||||
* @param nsIDOMElement notificationBox
|
||||
* @returns A function to be added as a handler to 'paste' and
|
||||
*'drop' events on the input field
|
||||
*/
|
||||
pasteHandlerGen: function (inputField, notificationBox, msg, okstring) {
|
||||
let handler = function (event) {
|
||||
if (WebConsoleUtils.usageCount >= CONSOLE_ENTRY_THRESHOLD) {
|
||||
inputField.removeEventListener("paste", handler);
|
||||
inputField.removeEventListener("drop", handler);
|
||||
return true;
|
||||
}
|
||||
if (notificationBox.getNotificationWithValue("selfxss-notification")) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
}
|
||||
|
||||
let notification = notificationBox.appendNotification(msg,
|
||||
"selfxss-notification", null,
|
||||
notificationBox.PRIORITY_WARNING_HIGH, null,
|
||||
function (eventType) {
|
||||
// Cleanup function if notification is dismissed
|
||||
if (eventType == "removed") {
|
||||
inputField.removeEventListener("keyup", pasteKeyUpHandler);
|
||||
}
|
||||
});
|
||||
|
||||
function pasteKeyUpHandler(event2) {
|
||||
let value = inputField.value || inputField.textContent;
|
||||
if (value.includes(okstring)) {
|
||||
notificationBox.removeNotification(notification);
|
||||
inputField.removeEventListener("keyup", pasteKeyUpHandler);
|
||||
WebConsoleUtils.usageCount = CONSOLE_ENTRY_THRESHOLD;
|
||||
}
|
||||
}
|
||||
inputField.addEventListener("keyup", pasteKeyUpHandler);
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
};
|
||||
return handler;
|
||||
},
|
||||
};
|
||||
|
||||
exports.Utils = WebConsoleUtils;
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
||||
// Localization
|
||||
// ////////////////////////////////////////////////////////////////////////
|
||||
|
||||
WebConsoleUtils.L10n = function (bundleURI) {
|
||||
this._bundleUri = bundleURI;
|
||||
};
|
||||
|
||||
WebConsoleUtils.L10n.prototype = {
|
||||
_stringBundle: null,
|
||||
|
||||
get stringBundle() {
|
||||
if (!this._stringBundle) {
|
||||
this._stringBundle = Services.strings.createBundle(this._bundleUri);
|
||||
}
|
||||
return this._stringBundle;
|
||||
},
|
||||
|
||||
/**
|
||||
* Generates a formatted timestamp string for displaying in console messages.
|
||||
*
|
||||
* @param integer [milliseconds]
|
||||
* Optional, allows you to specify the timestamp in milliseconds since
|
||||
* the UNIX epoch.
|
||||
* @return string
|
||||
* The timestamp formatted for display.
|
||||
*/
|
||||
timestampString: function (milliseconds) {
|
||||
let d = new Date(milliseconds ? milliseconds : null);
|
||||
let hours = d.getHours(), minutes = d.getMinutes();
|
||||
let seconds = d.getSeconds();
|
||||
milliseconds = d.getMilliseconds();
|
||||
let parameters = [hours, minutes, seconds, milliseconds];
|
||||
return this.getFormatStr("timestampFormat", parameters);
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve a localized string.
|
||||
*
|
||||
* @param string name
|
||||
* The string name you want from the Web Console string bundle.
|
||||
* @return string
|
||||
* The localized string.
|
||||
*/
|
||||
getStr: function (name) {
|
||||
let result;
|
||||
try {
|
||||
result = this.stringBundle.GetStringFromName(name);
|
||||
} catch (ex) {
|
||||
console.error("Failed to get string: " + name);
|
||||
throw ex;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve a localized string formatted with values coming from the given
|
||||
* array.
|
||||
*
|
||||
* @param string name
|
||||
* The string name you want from the Web Console string bundle.
|
||||
* @param array array
|
||||
* The array of values you want in the formatted string.
|
||||
* @return string
|
||||
* The formatted local string.
|
||||
*/
|
||||
getFormatStr: function (name, array) {
|
||||
let result;
|
||||
try {
|
||||
result = this.stringBundle.formatStringFromName(name, array,
|
||||
array.length);
|
||||
} catch (ex) {
|
||||
console.error("Failed to format string: " + name);
|
||||
throw ex;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
};
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// The page errors listener
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1474,8 +1065,3 @@ ConsoleReflowListener.prototype =
|
|||
this.listener = this.docshell = null;
|
||||
},
|
||||
};
|
||||
|
||||
function gSequenceId() {
|
||||
return gSequenceId.n++;
|
||||
}
|
||||
gSequenceId.n = 0;
|
||||
|
|
|
@ -88,8 +88,6 @@ function WebConsoleActor(aConnection, aParentActor)
|
|||
};
|
||||
}
|
||||
|
||||
WebConsoleActor.l10n = new WebConsoleUtils.L10n("chrome://global/locale/console.properties");
|
||||
|
||||
WebConsoleActor.prototype =
|
||||
{
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче