Bug 1208772 - Always use a full URL for links in the console even when the text is shortened. r=bgrins

This commit is contained in:
Ori Avtalion
2016-01-15 19:13:32 +02:00
parent e5e4e43ed4
commit c5ae4592cc
3 changed files with 68 additions and 17 deletions

View File

@@ -1185,6 +1185,8 @@ Messages.Extended.prototype = Heritage.extend(Messages.Simple.prototype,
* grip. This is typically set to true when the object needs to be
* displayed in an array preview, or as a property value in object
* previews, etc.
* - shorten - boolean that tells the renderer to display a truncated
* grip.
* @return DOMElement
* The DOM element that displays the given grip.
*/
@@ -1209,10 +1211,15 @@ Messages.Extended.prototype = Heritage.extend(Messages.Simple.prototype,
}
}
let unshortenedGrip = grip;
if (options.shorten) {
grip = this.shortenValueGrip(grip)
}
let result = this.document.createElementNS(XHTML_NS, "span");
if (isPrimitive) {
if (Widgets.URLString.prototype.containsURL.call(Widgets.URLString.prototype, grip)) {
let widget = new Widgets.URLString(this, grip, options).render();
let widget = new Widgets.URLString(this, grip, unshortenedGrip).render();
return widget.element;
}
@@ -2199,11 +2206,14 @@ Widgets.MessageTimestamp.prototype = Heritage.extend(Widgets.BaseWidget.prototyp
* The owning message.
* @param string str
* The string, which contains at least one valid URL.
* @param string unshortenedStr
* The unshortened form of the string, if it was shortened.
*/
Widgets.URLString = function(message, str)
Widgets.URLString = function(message, str, unshortenedStr)
{
Widgets.BaseWidget.call(this, message);
this.str = str;
this.unshortenedStr = unshortenedStr;
};
Widgets.URLString.prototype = Heritage.extend(Widgets.BaseWidget.prototype,
@@ -2228,16 +2238,23 @@ Widgets.URLString.prototype = Heritage.extend(Widgets.BaseWidget.prototype,
this.element.appendChild(this._renderText("\""));
// As we walk through the tokens of the source string, we make sure to preserve
// the original whitespace that seperated the tokens.
// the original whitespace that separated the tokens.
let tokens = this.str.split(/\s+/);
let textStart = 0;
let tokenStart;
for (let token of tokens) {
for (let i = 0; i < tokens.length; i++) {
let token = tokens[i];
let unshortenedToken;
tokenStart = this.str.indexOf(token, textStart);
if (this._isURL(token)) {
// The last URL in the string might be shortened. If so, get the
// real URL so the rendered link can point to it.
if (i === tokens.length - 1 && this.unshortenedStr) {
unshortenedToken = this.unshortenedStr.slice(tokenStart).split(/\s+/, 1)[0];
}
this.element.appendChild(this._renderText(this.str.slice(textStart, tokenStart)));
textStart = tokenStart + token.length;
this.element.appendChild(this._renderURL(token));
this.element.appendChild(this._renderURL(token, unshortenedToken));
}
}
@@ -2289,15 +2306,18 @@ Widgets.URLString.prototype = Heritage.extend(Widgets.BaseWidget.prototype,
*
* @param string url
* The string to be rendered as a url.
* @param string fullUrl
* The unshortened form of the URL, if it was shortened.
* @return DOMElement
* An element containing the rendered string.
*/
_renderURL: function(url)
_renderURL: function(url, fullUrl)
{
let unshortened = fullUrl || url;
let result = this.el("a", {
class: "url",
title: url,
href: url,
title: unshortened,
href: unshortened,
draggable: false
}, url);
this.message._addLinkCallback(result);
@@ -2414,8 +2434,7 @@ Widgets.JSObject.prototype = Heritage.extend(Widgets.BaseWidget.prototype,
if (valueIsText) {
this._text(value);
} else {
let shortVal = this.message.shortenValueGrip(value);
let valueElem = this.message._renderValueGrip(shortVal, { concise: true });
let valueElem = this.message._renderValueGrip(value, { concise: true, shorten: true });
container.appendChild(valueElem);
}
},
@@ -2808,8 +2827,7 @@ Widgets.ObjectRenderers.add({
emptySlots = 0;
}
let shortVal = this.message.shortenValueGrip(item);
let elem = this.message._renderValueGrip(shortVal, { concise: true });
let elem = this.message._renderValueGrip(item, { concise: true, shorten: true });
this.element.appendChild(elem);
}
}