Bug 1123910 - Display original article URL in urlbar when in reader mode (instead of about:reader). r=Unfocused

--HG--
extra : rebase_source : 0d9a2b146e4ffd2724205c5fcd1ffb80fcd0e7af
This commit is contained in:
Margaret Leibovic 2015-02-04 18:27:39 -08:00
Родитель 3700baf4a5
Коммит f92e0f6e25
3 изменённых файлов: 28 добавлений и 5 удалений

Просмотреть файл

@ -33,9 +33,13 @@ add_task(function* () {
readerButton.click();
yield promiseTabLoadEvent(tab);
ok(gBrowser.selectedBrowser.currentURI.spec.startsWith("about:reader"), "about:reader loaded after clicking reader mode button");
let readerUrl = gBrowser.selectedBrowser.currentURI.spec;
ok(readerUrl.startsWith("about:reader"), "about:reader loaded after clicking reader mode button");
is_element_visible(readerButton, "Reader mode button is present on about:reader");
is(gURLBar.value, readerUrl, "gURLBar value is about:reader URL");
is(gURLBar.textValue, url.substring("http://".length), "gURLBar is displaying original article URL");
readerButton.click();
yield promiseTabLoadEvent(tab);
is(gBrowser.selectedBrowser.currentURI.spec, url, "Original page loaded after clicking active reader mode button");

Просмотреть файл

@ -160,6 +160,11 @@
break;
}
}
} else {
let originalUrl = ReaderParent.parseReaderUrl(aValue);
if (originalUrl) {
returnValue = originalUrl;
}
}
// Set the actiontype only if the user is not overriding actions.

Просмотреть файл

@ -112,23 +112,37 @@ let ReaderParent = {
let win = event.target.ownerDocument.defaultView;
let url = win.gBrowser.selectedBrowser.currentURI.spec;
if (url.startsWith("about:reader")) {
win.openUILinkIn(this._getOriginalUrl(url), "current");
let originalURL = this._getOriginalUrl(url);
if (!originalURL) {
Cu.reportError("Error finding original URL for about:reader URL: " + url);
} else {
win.openUILinkIn(originalURL, "current");
}
} else {
win.openUILinkIn("about:reader?url=" + encodeURIComponent(url), "current");
}
},
parseReaderUrl: function(url) {
if (!url.startsWith("about:reader?")) {
return null;
}
return this._getOriginalUrl(url);
},
/**
* Returns original URL from an about:reader URL.
*
* @param url An about:reader URL.
* @return The original URL for the article, or null if we did not find
* a properly formatted about:reader URL.
*/
_getOriginalUrl: function(url) {
let searchParams = new URLSearchParams(url.split("?")[1]);
let searchParams = new URLSearchParams(url.substring("about:reader?".length));
if (!searchParams.has("url")) {
Cu.reportError("Error finding original URL for about:reader URL: " + url);
return url;
return null;
}
return decodeURIComponent(searchParams.get("url"));
},