Bug 943515 - Refactor favicon accessors for naming and usage consistency. r=mcomella
This commit is contained in:
@@ -786,7 +786,7 @@ abstract public class BrowserApp extends GeckoApp
|
|||||||
}
|
}
|
||||||
|
|
||||||
final OnFaviconLoadedListener listener = new GeckoAppShell.CreateShortcutFaviconLoadedListener(url, title);
|
final OnFaviconLoadedListener listener = new GeckoAppShell.CreateShortcutFaviconLoadedListener(url, title);
|
||||||
Favicons.getFaviconForSize(url,
|
Favicons.getSizedFavicon(url,
|
||||||
tab.getFaviconURL(),
|
tab.getFaviconURL(),
|
||||||
Integer.MAX_VALUE,
|
Integer.MAX_VALUE,
|
||||||
LoadFaviconTask.FLAG_PERSIST,
|
LoadFaviconTask.FLAG_PERSIST,
|
||||||
@@ -1413,7 +1413,7 @@ abstract public class BrowserApp extends GeckoApp
|
|||||||
final int tabFaviconSize = getResources().getDimensionPixelSize(R.dimen.browser_toolbar_favicon_size);
|
final int tabFaviconSize = getResources().getDimensionPixelSize(R.dimen.browser_toolbar_favicon_size);
|
||||||
|
|
||||||
int flags = (tab.isPrivate() || tab.getErrorType() != Tab.ErrorType.NONE) ? 0 : LoadFaviconTask.FLAG_PERSIST;
|
int flags = (tab.isPrivate() || tab.getErrorType() != Tab.ErrorType.NONE) ? 0 : LoadFaviconTask.FLAG_PERSIST;
|
||||||
int id = Favicons.getFaviconForSize(tab.getURL(), tab.getFaviconURL(), tabFaviconSize, flags, sFaviconLoadedListener);
|
int id = Favicons.getSizedFavicon(tab.getURL(), tab.getFaviconURL(), tabFaviconSize, flags, sFaviconLoadedListener);
|
||||||
|
|
||||||
tab.setFaviconLoadId(id);
|
tab.setFaviconLoadId(id);
|
||||||
|
|
||||||
|
|||||||
@@ -766,7 +766,7 @@ public class Tabs implements GeckoEventListener {
|
|||||||
*/
|
*/
|
||||||
private Bitmap getAboutPageFavicon(final String url) {
|
private Bitmap getAboutPageFavicon(final String url) {
|
||||||
int faviconSize = Math.round(mAppContext.getResources().getDimension(R.dimen.browser_toolbar_favicon_size));
|
int faviconSize = Math.round(mAppContext.getResources().getDimension(R.dimen.browser_toolbar_favicon_size));
|
||||||
return Favicons.getCachedFaviconForSize(url, faviconSize);
|
return Favicons.getSizedFaviconForPageFromCache(url, faviconSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2974,7 +2974,7 @@ public class BrowserProvider extends ContentProvider {
|
|||||||
|
|
||||||
// If no URL is provided, insert using the default one.
|
// If no URL is provided, insert using the default one.
|
||||||
if (TextUtils.isEmpty(faviconUrl) && !TextUtils.isEmpty(pageUrl)) {
|
if (TextUtils.isEmpty(faviconUrl) && !TextUtils.isEmpty(pageUrl)) {
|
||||||
values.put(Favicons.URL, org.mozilla.gecko.favicons.Favicons.guessDefaultFaviconURL(pageUrl));
|
values.put(Favicons.URL, org.mozilla.gecko.favicons.Favicons.guessDefaultFaviconUrl(pageUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class Favicons {
|
|||||||
// doing so is not necessary.
|
// doing so is not necessary.
|
||||||
private static final NonEvictingLruCache<String, String> sPageURLMappings = new NonEvictingLruCache<String, String>(NUM_PAGE_URL_MAPPINGS_TO_STORE);
|
private static final NonEvictingLruCache<String, String> sPageURLMappings = new NonEvictingLruCache<String, String>(NUM_PAGE_URL_MAPPINGS_TO_STORE);
|
||||||
|
|
||||||
public static String getFaviconURLForPageURLFromCache(String pageURL) {
|
public static String getFaviconUrlForPageUrlFromCache(String pageURL) {
|
||||||
return sPageURLMappings.get(pageURL);
|
return sPageURLMappings.get(pageURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ public class Favicons {
|
|||||||
* Insert the given pageUrl->faviconUrl mapping into the memory cache of such mappings.
|
* Insert the given pageUrl->faviconUrl mapping into the memory cache of such mappings.
|
||||||
* Useful for short-circuiting local database access.
|
* Useful for short-circuiting local database access.
|
||||||
*/
|
*/
|
||||||
public static void putFaviconURLForPageURLInCache(String pageURL, String faviconURL) {
|
public static void putFaviconUrlForPageUrlInCache(String pageURL, String faviconURL) {
|
||||||
sPageURLMappings.put(pageURL, faviconURL);
|
sPageURLMappings.put(pageURL, faviconURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ public class Favicons {
|
|||||||
*
|
*
|
||||||
* Returns null otherwise.
|
* Returns null otherwise.
|
||||||
*/
|
*/
|
||||||
public static Bitmap getCachedFaviconForSize(final String pageURL, int targetSize) {
|
public static Bitmap getSizedFaviconForPageFromCache(final String pageURL, int targetSize) {
|
||||||
final String faviconURL = sPageURLMappings.get(pageURL);
|
final String faviconURL = sPageURLMappings.get(pageURL);
|
||||||
if (faviconURL == null) {
|
if (faviconURL == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -134,7 +134,7 @@ public class Favicons {
|
|||||||
* @return The id of the asynchronous task created, NOT_LOADING if none is created, or
|
* @return The id of the asynchronous task created, NOT_LOADING if none is created, or
|
||||||
* LOADED if the value could be dispatched on the current thread.
|
* LOADED if the value could be dispatched on the current thread.
|
||||||
*/
|
*/
|
||||||
public static int getFaviconForSize(String pageURL, String faviconURL, int targetSize, int flags, OnFaviconLoadedListener listener) {
|
public static int getSizedFavicon(String pageURL, String faviconURL, int targetSize, int flags, OnFaviconLoadedListener listener) {
|
||||||
// Do we know the favicon URL for this page already?
|
// Do we know the favicon URL for this page already?
|
||||||
String cacheURL = faviconURL;
|
String cacheURL = faviconURL;
|
||||||
if (cacheURL == null) {
|
if (cacheURL == null) {
|
||||||
@@ -143,7 +143,7 @@ public class Favicons {
|
|||||||
|
|
||||||
// If there's no favicon URL given, try and hit the cache with the default one.
|
// If there's no favicon URL given, try and hit the cache with the default one.
|
||||||
if (cacheURL == null) {
|
if (cacheURL == null) {
|
||||||
cacheURL = guessDefaultFaviconURL(pageURL);
|
cacheURL = guessDefaultFaviconUrl(pageURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's something we can't even figure out a default URL for, just give up.
|
// If it's something we can't even figure out a default URL for, just give up.
|
||||||
@@ -222,6 +222,7 @@ public class Favicons {
|
|||||||
public static int getSizedFaviconForPageFromLocal(final String pageURL, final OnFaviconLoadedListener callback) {
|
public static int getSizedFaviconForPageFromLocal(final String pageURL, final OnFaviconLoadedListener callback) {
|
||||||
return getSizedFaviconForPageFromLocal(pageURL, sDefaultFaviconSize, callback);
|
return getSizedFaviconForPageFromLocal(pageURL, sDefaultFaviconSize, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to determine the URL of the Favicon image for a given page URL by querying the
|
* Helper method to determine the URL of the Favicon image for a given page URL by querying the
|
||||||
* history database. Should only be called from the background thread - does database access.
|
* history database. Should only be called from the background thread - does database access.
|
||||||
@@ -245,7 +246,7 @@ public class Favicons {
|
|||||||
targetURL = BrowserDB.getFaviconUrlForHistoryUrl(sContext.getContentResolver(), pageURL);
|
targetURL = BrowserDB.getFaviconUrlForHistoryUrl(sContext.getContentResolver(), pageURL);
|
||||||
if (targetURL == null) {
|
if (targetURL == null) {
|
||||||
// Nothing in the history database. Fall back to the default URL and hope for the best.
|
// Nothing in the history database. Fall back to the default URL and hope for the best.
|
||||||
targetURL = guessDefaultFaviconURL(pageURL);
|
targetURL = guessDefaultFaviconUrl(pageURL);
|
||||||
}
|
}
|
||||||
return targetURL;
|
return targetURL;
|
||||||
}
|
}
|
||||||
@@ -406,7 +407,7 @@ public class Favicons {
|
|||||||
* @param pageURL Page URL for which a default Favicon URL is requested
|
* @param pageURL Page URL for which a default Favicon URL is requested
|
||||||
* @return The default Favicon URL.
|
* @return The default Favicon URL.
|
||||||
*/
|
*/
|
||||||
public static String guessDefaultFaviconURL(String pageURL) {
|
public static String guessDefaultFaviconUrl(String pageURL) {
|
||||||
// Special-casing for about: pages. The favicon for about:pages which don't provide a link tag
|
// Special-casing for about: pages. The favicon for about:pages which don't provide a link tag
|
||||||
// is bundled in the database, keyed only by page URL, hence the need to return the page URL
|
// is bundled in the database, keyed only by page URL, hence the need to return the page URL
|
||||||
// here. If the database ever migrates to stop being silly in this way, this can plausibly
|
// here. If the database ever migrates to stop being silly in this way, this can plausibly
|
||||||
|
|||||||
@@ -240,14 +240,14 @@ public class LoadFaviconTask extends UiAsyncTask<Void, Void, Bitmap> {
|
|||||||
// If favicon is empty, fall back to the stored one.
|
// If favicon is empty, fall back to the stored one.
|
||||||
if (TextUtils.isEmpty(mFaviconUrl)) {
|
if (TextUtils.isEmpty(mFaviconUrl)) {
|
||||||
// Try to get the favicon URL from the memory cache.
|
// Try to get the favicon URL from the memory cache.
|
||||||
storedFaviconUrl = Favicons.getFaviconURLForPageURLFromCache(mPageUrl);
|
storedFaviconUrl = Favicons.getFaviconUrlForPageUrlFromCache(mPageUrl);
|
||||||
|
|
||||||
// If that failed, try to get the URL from the database.
|
// If that failed, try to get the URL from the database.
|
||||||
if (storedFaviconUrl == null) {
|
if (storedFaviconUrl == null) {
|
||||||
storedFaviconUrl = Favicons.getFaviconUrlForPageUrl(mPageUrl);
|
storedFaviconUrl = Favicons.getFaviconUrlForPageUrl(mPageUrl);
|
||||||
if (storedFaviconUrl != null) {
|
if (storedFaviconUrl != null) {
|
||||||
// If that succeeded, cache the URL loaded from the database in memory.
|
// If that succeeded, cache the URL loaded from the database in memory.
|
||||||
Favicons.putFaviconURLForPageURLInCache(mPageUrl, storedFaviconUrl);
|
Favicons.putFaviconUrlForPageUrlInCache(mPageUrl, storedFaviconUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +256,7 @@ public class LoadFaviconTask extends UiAsyncTask<Void, Void, Bitmap> {
|
|||||||
mFaviconUrl = storedFaviconUrl;
|
mFaviconUrl = storedFaviconUrl;
|
||||||
} else {
|
} else {
|
||||||
// If we don't have a stored one, fall back to the default.
|
// If we don't have a stored one, fall back to the default.
|
||||||
mFaviconUrl = Favicons.guessDefaultFaviconURL(mPageUrl);
|
mFaviconUrl = Favicons.guessDefaultFaviconUrl(mPageUrl);
|
||||||
|
|
||||||
if (TextUtils.isEmpty(mFaviconUrl)) {
|
if (TextUtils.isEmpty(mFaviconUrl)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -335,7 +335,7 @@ public class LoadFaviconTask extends UiAsyncTask<Void, Void, Bitmap> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're not already trying the default URL, try it now.
|
// If we're not already trying the default URL, try it now.
|
||||||
final String guessed = Favicons.guessDefaultFaviconURL(mPageUrl);
|
final String guessed = Favicons.guessDefaultFaviconUrl(mPageUrl);
|
||||||
if (guessed == null) {
|
if (guessed == null) {
|
||||||
Favicons.putFaviconInFailedCache(mFaviconUrl);
|
Favicons.putFaviconInFailedCache(mFaviconUrl);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user