summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/icons/preparation
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /mobile/android/base/java/org/mozilla/gecko/icons/preparation
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'mobile/android/base/java/org/mozilla/gecko/icons/preparation')
-rw-r--r--mobile/android/base/java/org/mozilla/gecko/icons/preparation/AboutPagesPreparer.java39
-rw-r--r--mobile/android/base/java/org/mozilla/gecko/icons/preparation/AddDefaultIconUrl.java39
-rw-r--r--mobile/android/base/java/org/mozilla/gecko/icons/preparation/FilterKnownFailureUrls.java29
-rw-r--r--mobile/android/base/java/org/mozilla/gecko/icons/preparation/FilterMimeTypes.java39
-rw-r--r--mobile/android/base/java/org/mozilla/gecko/icons/preparation/FilterPrivilegedUrls.java30
-rw-r--r--mobile/android/base/java/org/mozilla/gecko/icons/preparation/LookupIconUrl.java56
-rw-r--r--mobile/android/base/java/org/mozilla/gecko/icons/preparation/Preparer.java19
7 files changed, 251 insertions, 0 deletions
diff --git a/mobile/android/base/java/org/mozilla/gecko/icons/preparation/AboutPagesPreparer.java b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/AboutPagesPreparer.java
new file mode 100644
index 000000000..d335cbf51
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/AboutPagesPreparer.java
@@ -0,0 +1,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 org.mozilla.gecko.AboutPages;
+import org.mozilla.gecko.icons.IconDescriptor;
+import org.mozilla.gecko.icons.IconRequest;
+import org.mozilla.gecko.util.GeckoJarReader;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Preparer implementation for adding the omni.ja URL for internal about: pages.
+ */
+public class AboutPagesPreparer implements Preparer {
+ private Set<String> aboutUrls;
+
+ public AboutPagesPreparer() {
+ aboutUrls = new HashSet<>();
+
+ Collections.addAll(aboutUrls, AboutPages.DEFAULT_ICON_PAGES);
+ }
+
+ @Override
+ public void prepare(IconRequest request) {
+ if (aboutUrls.contains(request.getPageUrl())) {
+ final String iconUrl = GeckoJarReader.getJarURL(request.getContext(), "chrome/chrome/content/branding/favicon64.png");
+
+ request.modify()
+ .icon(IconDescriptor.createLookupIcon(iconUrl))
+ .deferBuild();
+ }
+ }
+}
diff --git a/mobile/android/base/java/org/mozilla/gecko/icons/preparation/AddDefaultIconUrl.java b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/AddDefaultIconUrl.java
new file mode 100644
index 000000000..5bc7d1c1f
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/AddDefaultIconUrl.java
@@ -0,0 +1,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();
+ }
+}
diff --git a/mobile/android/base/java/org/mozilla/gecko/icons/preparation/FilterKnownFailureUrls.java b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/FilterKnownFailureUrls.java
new file mode 100644
index 000000000..effd31a03
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/FilterKnownFailureUrls.java
@@ -0,0 +1,29 @@
+/* -*- 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 org.mozilla.gecko.icons.IconDescriptor;
+import org.mozilla.gecko.icons.IconRequest;
+import org.mozilla.gecko.icons.storage.FailureCache;
+
+import java.util.Iterator;
+
+public class FilterKnownFailureUrls implements Preparer {
+ @Override
+ public void prepare(IconRequest request) {
+ final FailureCache failureCache = FailureCache.get();
+ final Iterator<IconDescriptor> iterator = request.getIconIterator();
+
+ while (iterator.hasNext()) {
+ final IconDescriptor descriptor = iterator.next();
+
+ if (failureCache.isKnownFailure(descriptor.getUrl())) {
+ // Loading from this URL has failed in the past. Do not try again.
+ iterator.remove();
+ }
+ }
+ }
+}
diff --git a/mobile/android/base/java/org/mozilla/gecko/icons/preparation/FilterMimeTypes.java b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/FilterMimeTypes.java
new file mode 100644
index 000000000..a12dad2ad
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/FilterMimeTypes.java
@@ -0,0 +1,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 java.util.Iterator;
+
+/**
+ * Preparer implementation to filter unknown MIME types to avoid loading images that we cannot decode.
+ */
+public class FilterMimeTypes implements Preparer {
+ @Override
+ public void prepare(IconRequest request) {
+ final Iterator<IconDescriptor> iterator = request.getIconIterator();
+
+ while (iterator.hasNext()) {
+ final IconDescriptor descriptor = iterator.next();
+ final String mimeType = descriptor.getMimeType();
+
+ if (TextUtils.isEmpty(mimeType)) {
+ // We do not have a MIME type for this icon, so we cannot know in advance if we are able
+ // to decode it. Let's just continue.
+ continue;
+ }
+
+ if (!IconsHelper.canDecodeType(mimeType)) {
+ iterator.remove();
+ }
+ }
+ }
+}
diff --git a/mobile/android/base/java/org/mozilla/gecko/icons/preparation/FilterPrivilegedUrls.java b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/FilterPrivilegedUrls.java
new file mode 100644
index 000000000..abf34c038
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/FilterPrivilegedUrls.java
@@ -0,0 +1,30 @@
+package org.mozilla.gecko.icons.preparation;
+
+import org.mozilla.gecko.icons.IconDescriptor;
+import org.mozilla.gecko.icons.IconRequest;
+import org.mozilla.gecko.util.StringUtils;
+
+import java.util.Iterator;
+
+/**
+ * Filter non http/https URLs if the request is not from privileged code.
+ */
+public class FilterPrivilegedUrls implements Preparer {
+ @Override
+ public void prepare(IconRequest request) {
+ if (request.isPrivileged()) {
+ // This request is privileged. No need to filter anything.
+ return;
+ }
+
+ final Iterator<IconDescriptor> iterator = request.getIconIterator();
+
+ while (iterator.hasNext()) {
+ IconDescriptor descriptor = iterator.next();
+
+ if (!StringUtils.isHttpOrHttps(descriptor.getUrl())) {
+ iterator.remove();
+ }
+ }
+ }
+}
diff --git a/mobile/android/base/java/org/mozilla/gecko/icons/preparation/LookupIconUrl.java b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/LookupIconUrl.java
new file mode 100644
index 000000000..0c7641112
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/LookupIconUrl.java
@@ -0,0 +1,56 @@
+/* -*- 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 org.mozilla.gecko.icons.IconDescriptor;
+import org.mozilla.gecko.icons.IconRequest;
+import org.mozilla.gecko.icons.storage.DiskStorage;
+import org.mozilla.gecko.icons.storage.MemoryStorage;
+
+/**
+ * Preparer implementation to lookup the icon URL for the page URL in the request. This class tries
+ * to locate the icon URL by looking through previously stored mappings on disk and in memory.
+ */
+public class LookupIconUrl implements Preparer {
+ @Override
+ public void prepare(IconRequest request) {
+ if (lookupFromMemory(request)) {
+ return;
+ }
+
+ lookupFromDisk(request);
+ }
+
+ private boolean lookupFromMemory(IconRequest request) {
+ final String iconUrl = MemoryStorage.get()
+ .getMapping(request.getPageUrl());
+
+ if (iconUrl != null) {
+ request.modify()
+ .icon(IconDescriptor.createLookupIcon(iconUrl))
+ .deferBuild();
+
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean lookupFromDisk(IconRequest request) {
+ final String iconUrl = DiskStorage.get(request.getContext())
+ .getMapping(request.getPageUrl());
+
+ if (iconUrl != null) {
+ request.modify()
+ .icon(IconDescriptor.createLookupIcon(iconUrl))
+ .deferBuild();
+
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/mobile/android/base/java/org/mozilla/gecko/icons/preparation/Preparer.java b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/Preparer.java
new file mode 100644
index 000000000..466307ead
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/preparation/Preparer.java
@@ -0,0 +1,19 @@
+/* -*- 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 org.mozilla.gecko.icons.IconRequest;
+
+/**
+ * Generic interface for a class "preparing" a request before we try to load icons. A class
+ * implementing this interface can modify the request (e.g. filter or add icon URLs).
+ */
+public interface Preparer {
+ /**
+ * Inspects or modifies the request before any icon is loaded.
+ */
+ void prepare(IconRequest request);
+}