mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 04:45:45 +00:00
Bug 1144680 - The Reading List URLbar button should handle about:reader urls and filter out other non-http(s) urls, r=markh.
This commit is contained in:
parent
14ff6d0c06
commit
4ba58a55ed
@ -232,12 +232,22 @@ let ReadingListUI = {
|
|||||||
// nothing to do if we have no button.
|
// nothing to do if we have no button.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.enabled || state == "invalid") {
|
|
||||||
|
let uri;
|
||||||
|
if (this.enabled && state == "valid") {
|
||||||
|
uri = gBrowser.currentURI;
|
||||||
|
if (uri.schemeIs("about"))
|
||||||
|
uri = ReaderParent.parseReaderUrl(uri.spec);
|
||||||
|
else if (!uri.schemeIs("http") && !uri.schemeIs("https"))
|
||||||
|
uri = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!uri) {
|
||||||
this.toolbarButton.setAttribute("hidden", true);
|
this.toolbarButton.setAttribute("hidden", true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let isInList = yield ReadingList.containsURL(gBrowser.currentURI);
|
let isInList = yield ReadingList.containsURL(uri);
|
||||||
this.setToolbarButtonState(isInList);
|
this.setToolbarButtonState(isInList);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -268,11 +278,17 @@ let ReadingListUI = {
|
|||||||
* @returns {Promise} Promise resolved when operation has completed.
|
* @returns {Promise} Promise resolved when operation has completed.
|
||||||
*/
|
*/
|
||||||
togglePageByBrowser: Task.async(function* (browser) {
|
togglePageByBrowser: Task.async(function* (browser) {
|
||||||
let item = yield ReadingList.getItemForURL(browser.currentURI);
|
let uri = browser.currentURI;
|
||||||
|
if (uri.spec.startsWith("about:reader?"))
|
||||||
|
uri = ReaderParent.parseReaderUrl(uri.spec);
|
||||||
|
if (!uri)
|
||||||
|
return;
|
||||||
|
|
||||||
|
let item = yield ReadingList.getItemForURL(uri);
|
||||||
if (item) {
|
if (item) {
|
||||||
yield item.delete();
|
yield item.delete();
|
||||||
} else {
|
} else {
|
||||||
yield ReadingList.addItemFromBrowser(browser);
|
yield ReadingList.addItemFromBrowser(browser, uri);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -284,6 +300,9 @@ let ReadingListUI = {
|
|||||||
*/
|
*/
|
||||||
isItemForCurrentBrowser(item) {
|
isItemForCurrentBrowser(item) {
|
||||||
let currentURL = gBrowser.currentURI.spec;
|
let currentURL = gBrowser.currentURI.spec;
|
||||||
|
if (currentURL.startsWith("about:reader?"))
|
||||||
|
currentURL = ReaderParent.parseReaderUrl(currentURL);
|
||||||
|
|
||||||
if (item.url == currentURL || item.resolvedURL == currentURL) {
|
if (item.url == currentURL || item.resolvedURL == currentURL) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -289,13 +289,15 @@ ReadingListImpl.prototype = {
|
|||||||
/**
|
/**
|
||||||
* Add to the ReadingList the page that is loaded in a given browser.
|
* Add to the ReadingList the page that is loaded in a given browser.
|
||||||
*
|
*
|
||||||
* @param {<xul:browser>} browser - Browser element for the document.
|
* @param {<xul:browser>} browser - Browser element for the document,
|
||||||
|
* used to get metadata about the article.
|
||||||
|
* @param {nsIURI/string} url - url to add to the reading list.
|
||||||
* @return {Promise} Promise that is fullfilled with the added item.
|
* @return {Promise} Promise that is fullfilled with the added item.
|
||||||
*/
|
*/
|
||||||
addItemFromBrowser: Task.async(function* (browser) {
|
addItemFromBrowser: Task.async(function* (browser, url) {
|
||||||
let metadata = yield getMetadataFromBrowser(browser);
|
let metadata = yield getMetadataFromBrowser(browser);
|
||||||
let itemData = {
|
let itemData = {
|
||||||
url: browser.currentURI,
|
url: url,
|
||||||
title: metadata.title,
|
title: metadata.title,
|
||||||
resolvedURL: metadata.url,
|
resolvedURL: metadata.url,
|
||||||
excerpt: metadata.description,
|
excerpt: metadata.description,
|
||||||
|
Loading…
Reference in New Issue
Block a user