зеркало из https://github.com/mozilla/gecko-dev.git
display link tag's title attribute on microsummary menu item while downloading generator
Patch by Justin Dolske. bug=342231 r=myk
This commit is contained in:
Родитель
d94a17c8fc
Коммит
65847c39bb
|
@ -207,8 +207,8 @@ var MicrosummaryPicker = {
|
||||||
if (microsummary.content != null)
|
if (microsummary.content != null)
|
||||||
menuItem.setAttribute("label", microsummary.content);
|
menuItem.setAttribute("label", microsummary.content);
|
||||||
else {
|
else {
|
||||||
menuItem.setAttribute("label", microsummary.generator ? microsummary.generator.name
|
menuItem.setAttribute("label", microsummary.generator.name ?
|
||||||
: microsummary.generatorURI.spec);
|
microsummary.generator.name : microsummary.generator.uri.spec);
|
||||||
microsummary.update();
|
microsummary.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,12 @@ interface nsIMicrosummaryObserver : nsISupports
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
[scriptable, uuid(ff3eba15-81de-4c24-bfcf-c8180dc3c00a)]
|
[scriptable, uuid(67ffe6b0-d4db-485c-ba20-5e2e8319b78d)]
|
||||||
interface nsIMicrosummaryGenerator : nsISupports
|
interface nsIMicrosummaryGenerator : nsISupports
|
||||||
{
|
{
|
||||||
|
// Has the generator itself, which may be a remote resource, been loaded.
|
||||||
|
readonly attribute boolean loaded;
|
||||||
|
|
||||||
// An arbitrary descriptive name for this microsummary generator.
|
// An arbitrary descriptive name for this microsummary generator.
|
||||||
readonly attribute AUTF8String name;
|
readonly attribute AUTF8String name;
|
||||||
|
|
||||||
|
@ -85,17 +88,13 @@ interface nsIMicrosummaryGenerator : nsISupports
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
[scriptable, uuid(f9d1a73c-e147-46f3-ba61-4f0bd33f5d47)]
|
[scriptable, uuid(1b1f232d-e65f-446a-9984-786578526072)]
|
||||||
interface nsIMicrosummary : nsISupports
|
interface nsIMicrosummary : nsISupports
|
||||||
{
|
{
|
||||||
// the URI of the page being summarized
|
// the URI of the page being summarized
|
||||||
readonly attribute nsIURI pageURI;
|
readonly attribute nsIURI pageURI;
|
||||||
|
|
||||||
// The URI of the generator that generates this microsummary.
|
// The generator that generates this microsummary. May need to be loaded.
|
||||||
readonly attribute nsIURI generatorURI;
|
|
||||||
|
|
||||||
// The generator that generates this microsummary.
|
|
||||||
// Since generators can be remote resources, this may not always be available.
|
|
||||||
attribute nsIMicrosummaryGenerator generator;
|
attribute nsIMicrosummaryGenerator generator;
|
||||||
|
|
||||||
// The content of the microsummary.
|
// The content of the microsummary.
|
||||||
|
|
|
@ -465,8 +465,7 @@ MicrosummaryService.prototype = {
|
||||||
var generator = this._localGenerators[genURISpec];
|
var generator = this._localGenerators[genURISpec];
|
||||||
|
|
||||||
if (generator.appliesToURI(pageURI)) {
|
if (generator.appliesToURI(pageURI)) {
|
||||||
var microsummary = new Microsummary(pageURI, generator.uri);
|
var microsummary = new Microsummary(pageURI, generator);
|
||||||
microsummary.generator = generator;
|
|
||||||
|
|
||||||
// If this is the current microsummary for this bookmark, load the content
|
// If this is the current microsummary for this bookmark, load the content
|
||||||
// from the datastore so it shows up immediately in microsummary picking UI.
|
// from the datastore so it shows up immediately in microsummary picking UI.
|
||||||
|
@ -754,9 +753,11 @@ MicrosummaryService.prototype = {
|
||||||
var pageURI = this._getPageForBookmark(bookmarkID);
|
var pageURI = this._getPageForBookmark(bookmarkID);
|
||||||
var generatorURI = this._uri(this._getField(bookmarkID, FIELD_MICSUM_GEN_URI));
|
var generatorURI = this._uri(this._getField(bookmarkID, FIELD_MICSUM_GEN_URI));
|
||||||
|
|
||||||
var microsummary = new Microsummary(pageURI, generatorURI);
|
var localGenerator = this._localGenerators[generatorURI.spec];
|
||||||
if (this._localGenerators[generatorURI.spec])
|
|
||||||
microsummary.generator = this._localGenerators[generatorURI.spec];
|
var microsummary = new Microsummary(pageURI, localGenerator);
|
||||||
|
if (!localGenerator)
|
||||||
|
microsummary.generator.uri = generatorURI;
|
||||||
|
|
||||||
return microsummary;
|
return microsummary;
|
||||||
},
|
},
|
||||||
|
@ -772,7 +773,7 @@ MicrosummaryService.prototype = {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
setMicrosummary: function MSS_setMicrosummary(bookmarkID, microsummary) {
|
setMicrosummary: function MSS_setMicrosummary(bookmarkID, microsummary) {
|
||||||
this._setField(bookmarkID, FIELD_MICSUM_GEN_URI, microsummary.generatorURI.spec);
|
this._setField(bookmarkID, FIELD_MICSUM_GEN_URI, microsummary.generator.uri.spec);
|
||||||
if (microsummary.content)
|
if (microsummary.content)
|
||||||
this._updateMicrosummary(bookmarkID, microsummary);
|
this._updateMicrosummary(bookmarkID, microsummary);
|
||||||
else
|
else
|
||||||
|
@ -833,7 +834,7 @@ MicrosummaryService.prototype = {
|
||||||
|
|
||||||
var currentGen = this._getField(bookmarkID, FIELD_MICSUM_GEN_URI);
|
var currentGen = this._getField(bookmarkID, FIELD_MICSUM_GEN_URI);
|
||||||
|
|
||||||
if (microsummary.generatorURI.equals(this._uri(currentGen)))
|
if (microsummary.generator.uri.equals(this._uri(currentGen)))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -863,9 +864,12 @@ MicrosummaryService.prototype = {
|
||||||
|
|
||||||
var pageURI = this._getPageForBookmark(bookmarkID);
|
var pageURI = this._getPageForBookmark(bookmarkID);
|
||||||
var generatorURI = this._uri(this._getField(bookmarkID, FIELD_MICSUM_GEN_URI));
|
var generatorURI = this._uri(this._getField(bookmarkID, FIELD_MICSUM_GEN_URI));
|
||||||
var microsummary = new Microsummary(pageURI, generatorURI);
|
|
||||||
if (this._localGenerators[generatorURI.spec])
|
var localGenerator = this._localGenerators[generatorURI.spec];
|
||||||
microsummary.generator = this._localGenerators[generatorURI.spec];
|
|
||||||
|
var microsummary = new Microsummary(pageURI, localGenerator);
|
||||||
|
if (!localGenerator)
|
||||||
|
microsummary.generator.uri = generatorURI;
|
||||||
|
|
||||||
// A microsummary observer that calls the microsummary service
|
// A microsummary observer that calls the microsummary service
|
||||||
// to update the datastore when the microsummary finishes loading.
|
// to update the datastore when the microsummary finishes loading.
|
||||||
|
@ -897,10 +901,10 @@ MicrosummaryService.prototype = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Microsummary(pageURI, generatorURI) {
|
function Microsummary(pageURI, generator) {
|
||||||
this._observers = [];
|
this._observers = [];
|
||||||
this.pageURI = pageURI;
|
this.pageURI = pageURI;
|
||||||
this.generatorURI = generatorURI;
|
this.generator = generator ? generator : new MicrosummaryGenerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
Microsummary.prototype = {
|
Microsummary.prototype = {
|
||||||
|
@ -922,7 +926,7 @@ Microsummary.prototype = {
|
||||||
get content() {
|
get content() {
|
||||||
// If we have everything we need to generate the content, generate it.
|
// If we have everything we need to generate the content, generate it.
|
||||||
if (this._content == null &&
|
if (this._content == null &&
|
||||||
this.generator &&
|
this.generator.loaded &&
|
||||||
(this.pageContent || !this.generator.needsPageContent)) {
|
(this.pageContent || !this.generator.needsPageContent)) {
|
||||||
this._content = this.generator.generateMicrosummary(this.pageContent);
|
this._content = this.generator.generateMicrosummary(this.pageContent);
|
||||||
this.updateInterval = this.generator.calculateUpdateInterval(this.pageContent);
|
this.updateInterval = this.generator.calculateUpdateInterval(this.pageContent);
|
||||||
|
@ -937,10 +941,6 @@ Microsummary.prototype = {
|
||||||
},
|
},
|
||||||
set content(newValue) { this._content = newValue },
|
set content(newValue) { this._content = newValue },
|
||||||
|
|
||||||
_generatorURI: null,
|
|
||||||
get generatorURI() { return this._generatorURI },
|
|
||||||
set generatorURI(newValue) { this._generatorURI = newValue },
|
|
||||||
|
|
||||||
_generator: null,
|
_generator: null,
|
||||||
get generator() { return this._generator },
|
get generator() { return this._generator },
|
||||||
set generator(newValue) { this._generator = newValue },
|
set generator(newValue) { this._generator = newValue },
|
||||||
|
@ -996,20 +996,20 @@ Microsummary.prototype = {
|
||||||
*/
|
*/
|
||||||
update: function MS_update() {
|
update: function MS_update() {
|
||||||
LOG("microsummary.update called for page:\n " + this.pageURI.spec +
|
LOG("microsummary.update called for page:\n " + this.pageURI.spec +
|
||||||
"\nwith generator:\n " + this.generatorURI.spec);
|
"\nwith generator:\n " + this.generator.uri.spec);
|
||||||
|
|
||||||
var t = this;
|
var t = this;
|
||||||
|
|
||||||
// If we don't have the generator, download it now. After it downloads,
|
// If we don't have the generator, download it now. After it downloads,
|
||||||
// we'll re-call this method to continue updating the microsummary.
|
// we'll re-call this method to continue updating the microsummary.
|
||||||
if (!this.generator) {
|
if (!this.generator.loaded) {
|
||||||
LOG("generator not yet loaded; downloading it");
|
LOG("generator not yet loaded; downloading it");
|
||||||
var generatorCallback =
|
var generatorCallback =
|
||||||
function MS_generatorCallback(resource) {
|
function MS_generatorCallback(resource) {
|
||||||
try { t._handleGeneratorLoad(resource) }
|
try { t._handleGeneratorLoad(resource) }
|
||||||
finally { resource.destroy() }
|
finally { resource.destroy() }
|
||||||
};
|
};
|
||||||
var resource = new MicrosummaryResource(this.generatorURI);
|
var resource = new MicrosummaryResource(this.generator.uri);
|
||||||
resource.load(generatorCallback);
|
resource.load(generatorCallback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1042,20 +1042,19 @@ Microsummary.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleGeneratorLoad: function MS__handleGeneratorLoad(resource) {
|
_handleGeneratorLoad: function MS__handleGeneratorLoad(resource) {
|
||||||
var generator = new MicrosummaryGenerator();
|
LOG(this.generator.uri.spec + " microsummary generator downloaded");
|
||||||
generator.uri = resource.uri;
|
|
||||||
LOG(generator.uri.spec + " microsummary generator downloaded");
|
|
||||||
if (resource.isXML)
|
if (resource.isXML)
|
||||||
generator.initFromXML(resource.content);
|
this.generator.initFromXML(resource.content);
|
||||||
else if (resource.contentType == "text/plain")
|
else if (resource.contentType == "text/plain")
|
||||||
generator.initFromText(resource.content);
|
this.generator.initFromText(resource.content);
|
||||||
else if (resource.contentType == "text/html")
|
else if (resource.contentType == "text/html")
|
||||||
generator.initFromText(resource.content.body.textContent);
|
this.generator.initFromText(resource.content.body.textContent);
|
||||||
else
|
else
|
||||||
throw("generator is neither XML nor plain text");
|
throw("generator is neither XML nor plain text");
|
||||||
|
|
||||||
this.generator = generator;
|
// Only trigger a [content] update if we were able to init the generator.
|
||||||
this.update();
|
if (this.generator.loaded)
|
||||||
|
this.update();
|
||||||
},
|
},
|
||||||
|
|
||||||
_handlePageLoad: function MS__handlePageLoad(resource) {
|
_handlePageLoad: function MS__handlePageLoad(resource) {
|
||||||
|
@ -1125,6 +1124,10 @@ MicrosummaryGenerator.prototype = {
|
||||||
get content() { return this._content },
|
get content() { return this._content },
|
||||||
set content(newValue) { this._content = newValue },
|
set content(newValue) { this._content = newValue },
|
||||||
|
|
||||||
|
_loaded: false,
|
||||||
|
get loaded() { return this._loaded },
|
||||||
|
set loaded(newValue) { this._loaded = newValue },
|
||||||
|
|
||||||
_rules: null,
|
_rules: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1181,6 +1184,7 @@ MicrosummaryGenerator.prototype = {
|
||||||
*/
|
*/
|
||||||
initFromText: function(text) {
|
initFromText: function(text) {
|
||||||
this.content = text;
|
this.content = text;
|
||||||
|
this.loaded = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1273,6 +1277,8 @@ MicrosummaryGenerator.prototype = {
|
||||||
|| templateNode.getElementsByTagNameNS(XSLT_NS, "stylesheet")[0];
|
|| templateNode.getElementsByTagNameNS(XSLT_NS, "stylesheet")[0];
|
||||||
}
|
}
|
||||||
// XXX Make sure the template is a valid XSL transform sheet.
|
// XXX Make sure the template is a valid XSL transform sheet.
|
||||||
|
|
||||||
|
this.loaded = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
generateMicrosummary: function MSD_generateMicrosummary(pageContent) {
|
generateMicrosummary: function MSD_generateMicrosummary(pageContent) {
|
||||||
|
@ -1426,6 +1432,10 @@ MicrosummarySet.prototype = {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
|
// Look for a TITLE attribute to give the generator a nice name in the UI.
|
||||||
|
var linkTitle = link.getAttribute("title");
|
||||||
|
|
||||||
|
|
||||||
// Unlike the "href" attribute, the "href" property contains
|
// Unlike the "href" attribute, the "href" property contains
|
||||||
// an absolute URI spec, so we use it here to create the URI.
|
// an absolute URI spec, so we use it here to create the URI.
|
||||||
var generatorURI = this._ios.newURI(link.href,
|
var generatorURI = this._ios.newURI(link.href,
|
||||||
|
@ -1445,7 +1455,9 @@ MicrosummarySet.prototype = {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var microsummary = new Microsummary(resource.uri, generatorURI);
|
var microsummary = new Microsummary(resource.uri, null);
|
||||||
|
microsummary.generator.name = linkTitle;
|
||||||
|
microsummary.generator.uri = generatorURI;
|
||||||
this.AppendElement(microsummary);
|
this.AppendElement(microsummary);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Загрузка…
Ссылка в новой задаче