Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve favicons support in private:… bookmarks #147

Closed
Infocatcher opened this issue May 22, 2014 · 1 comment
Closed

Improve favicons support in private:… bookmarks #147

Infocatcher opened this issue May 22, 2014 · 1 comment

Comments

@Infocatcher
Copy link
Owner

Requested here: https://addons.mozilla.org/addon/private-tab/reviews/591920/

We currently use hardcoded /favicon.ico link (like https://www.google.com/favicon.ico):
https://github.com/Infocatcher/Private_Tab/blob/0.1.7.2/protocolRedirect.html#L85-L89

We should try to use something like mozIAsyncFavicons.getFaviconURLForPage() -> setAndFetchFaviconForPage()
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/mozIAsyncFavicons

Testcase with custom favicon:
http://infocatcher.ucoz.net/test/favicon.html
http://fiddle.jshell.net/93Gy3/2/show/

<!DOCTYPE html>
<meta charset="utf-8"/>
<title>Favicon test</title>
<!-- Icon: https://www.iconfinder.com/icons/65007/world_icon (http://fatcow.com/free-icons/) -->
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAzBJREFUeNpkk3toVnUYxz/nPWfvbRfbpVmb25yXaIvVjJh0swbpkhIrRCRwQaMRNSILSukC5YgC+yNoEQz8R4ICCQ2lvVPYIh2mzVxuk5ps76Z7t3dX3+u5n9PvvDaY9YMHzu93fs/n9zzf53kk/rPWftLfZdryq7YjBcP5BeiqiuJDk33W0ZmPn3xz9V3XdZFWNhWdvTtUQ44890Q3L21ZZmPZPGkjxvXkPPHlIP1Db/H7yIv4lWzLzQ+f7r0DUNkZ2WG4UqR9+8N8sLWPRTOPkbmdTCf8jCcguKaZe4v7GRxv5vjZLwkoyRzEA/g8gG5akf3NTbzWUMpU9h5upELEUn5sZZCm+xpYTLVyKdpOY00f+7a/gmmFIiuR+yoO93RtqK1lz/1rWNBT6NIllNC3VFc8y90lbcypDhvK32Akdoij53+jft1VHtj8IxWHz3XlAI5tt9VWrhUfLvFsIX/PHSDrTAkbYzJZB8ooV2OfoxpVLGfr+HnkII/WfYVjy205gCtJgdJwiFnVZkGFmQxk3QnS9jSF4e/Bgcc3vU1hcBSfrDIwcZDKUg2EnwdQwuEibqRhIumg2TbkXURjCdP7KySWhV2MvssttUaonsDns7g2u1Gcm7c1yGR0djW+wLmYQzRhMRp/SMDxap8z24WB60ewHB1DPOA4Gt+c70WRjdsAGdf4I9pCQaifyYTGfDrAXzPPi1JBZPg407e2UV50mpSWR0YPkLU8qiaCs3IEhXT8RN9gy97i8nL8ksjNtekZ7uYx9R2eqd/DqaFutlR9RnF+Ewk1REn4CicvdGIlFk78myXV6zp7Ju+q2kReIChUdXFcBd0KoJphWurb2Lr+O9ErIlzx+E+XX+bK0Ovc/GhbjWikKa+RprThXzqS0+MkM2lSui1CVVGthIAsEV18UORLzgbGmrlw+QDq8JkOz28lAm8Vle07tD+/4amv7fwSrEABpqSIjhMKiZq0PtLOr3+2Eo81Yl473bH0w6fHhE/yjmHyIMI2V7537H2lqGy3JEl+wxdEzikvG3Zy7uTskb1fiDtjnvP/pnHVqhZW6lVo1ZloJxZXwl49zv8IMAD7FG+TXRG19AAAAABJRU5ErkJggg==">
@Infocatcher
Copy link
Owner Author

mozIAsyncFavicons.getFaviconURLForPage() works only if page was already loaded in non-private mode. :(

Testcase for protocolRedirect.html:

    var uri = Services.io.newURI(spec, null, null); // We accept only valid URIs

    //try {
    //  setFavicon(uri.scheme + "://" + uri.hostPort + "/favicon.ico");
    //}
    //catch(e2) {
    //}
    if(location.protocol == "private:")
        setBookmarkFavicon(document.documentURIObject, uri);
    location.replace(spec);
...
function setBookmarkFavicon(bookmarkURI, pageURI) {
    try {
        // Note: works only if that page was already loaded in non-preivate mode
        var faviconService = Components.classes["@mozilla.org/browser/favicon-service;1"]
            .getService(Components.interfaces.mozIAsyncFavicons);
        faviconService.getFaviconURLForPage(pageURI, {
            onComplete: function(uri, dataLen, data, mimeType) {
                uri && faviconService.setAndFetchFaviconForPage(
                    bookmarkURI,
                    uri,
                    false /*aForceReload*/,
                    faviconService.FAVICON_LOAD_PRIVATE
                );
            }
        });
    }
    catch(e) {
        Components.utils.reportError(e);
    }
}

(and the same with true /*aForceReload*/)

Infocatcher added a commit that referenced this issue May 22, 2014
Infocatcher added a commit that referenced this issue Aug 9, 2014
See view-source:chrome://browser/content/tabbrowser.xml
<method name="setIcon">
            if (sizedIconUrl) {
              let size = Math.round(16 * window.devicePixelRatio);
              sizedIconUrl += (sizedIconUrl.contains("#") ? "&" : "#") +
                              "-moz-resolution=" + size + "," + size;
            }
(#147)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant