summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/icons/preparation/AddDefaultIconUrl.java
blob: 5bc7d1c1f25f93eb2105a89f3f890b1a13a3d96f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.gecko.icons.preparation;

import android.text.TextUtils;

import org.mozilla.gecko.icons.IconDescriptor;
import org.mozilla.gecko.icons.IconRequest;
import org.mozilla.gecko.icons.IconsHelper;
import org.mozilla.gecko.util.StringUtils;

/**
 * Preparer to add the "default/guessed" favicon URL (domain/favicon.ico) to the list of URLs to
 * try loading the favicon from.
 *
 * The default URL will be added with a very low priority so that we will only try to load from this
 * URL if all other options failed.
 */
public class AddDefaultIconUrl implements Preparer {
    @Override
    public void prepare(IconRequest request) {
        if (!StringUtils.isHttpOrHttps(request.getPageUrl())) {
            return;
        }

        final String defaultFaviconUrl = IconsHelper.guessDefaultFaviconURL(request.getPageUrl());
        if (TextUtils.isEmpty(defaultFaviconUrl)) {
            // We couldn't generate a default favicon URL for this URL. Nothing to do here.
            return;
        }

        request.modify()
                .icon(IconDescriptor.createGenericIcon(defaultFaviconUrl))
                .deferBuild();
    }
}