Bug 1276170 - Add a pref to disable thumbnail creation. r?Margaret
Thumbnail creation flushes styles or paints. In some layout tests
especially for animations, we check restyle count or computed styles.
If the thumbnail creation happens in those tests, it results unexpected
failures. To prevent such failures we need a pref to disable thumbnail
creation for those kind of tests.
MozReview-Commit-ID: C7wbigRZtii
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -25,16 +25,17 @@ pref("toolkit.browser.contentViewExpire"
pref("toolkit.defaultChromeURI", "chrome://browser/content/browser.xul");
pref("browser.chromeURL", "chrome://browser/content/");
// If a tab has not been active for this long (seconds), then it may be
// turned into a zombie tab to preemptively free up memory. -1 disables time-based
// expiration (but low-memory conditions may still require the tab to be zombified).
pref("browser.tabs.expireTime", 900);
+pref("browser.tabs.disableThumbnailCreation", false);
// Disables zombification of background tabs under memory pressure.
// Intended for use in testing, where we don't want the tab running the
// test harness code to be zombified.
pref("browser.tabs.disableBackgroundZombification", false);
// Control whether tab content should try to load from disk cache when network
// is offline.
--- a/mobile/android/base/java/org/mozilla/gecko/ThumbnailHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/ThumbnailHelper.java
@@ -1,15 +1,16 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; 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;
+import org.mozilla.gecko.PrefsHelper;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.mozglue.DirectBufferAllocator;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.util.Log;
import android.util.TypedValue;
@@ -29,16 +30,23 @@ import java.util.concurrent.atomic.Atomi
*/
public final class ThumbnailHelper {
private static final String LOGTAG = "GeckoThumbnailHelper";
public static final float TABS_PANEL_THUMBNAIL_ASPECT_RATIO = 0.8333333f;
public static final float TOP_SITES_THUMBNAIL_ASPECT_RATIO = 0.571428571f; // this is a 4:7 ratio (as per UX decision)
public static final float THUMBNAIL_ASPECT_RATIO;
+ private final PrefsHelper.PrefHandler mPrefObserver;
+ // Disable thumnail creation if true.
+ // This is only used in some automation tests for layout styling or painting
+ // because thumbnail creation flushes styles or paints, as a result
+ // those tests receive unexpected restyles or paints.
+ private boolean mDisableThumbnailCreation = false;
+
static {
// As we only want to generate one thumbnail for each tab, we calculate the
// largest aspect ratio required and create the thumbnail based off that.
// Any views with a smaller aspect ratio will use a cropped version of the
// same image.
THUMBNAIL_ASPECT_RATIO = Math.max(TABS_PANEL_THUMBNAIL_ASPECT_RATIO, TOP_SITES_THUMBNAIL_ASPECT_RATIO);
}
@@ -71,19 +79,31 @@ public final class ThumbnailHelper {
mPendingThumbnails = new LinkedList<Tab>();
try {
mPendingWidth = new AtomicInteger((int) res.getDimension(R.dimen.tab_thumbnail_width));
} catch (Resources.NotFoundException nfe) { mPendingWidth = new AtomicInteger(0); }
mWidth = -1;
mHeight = -1;
+
+ mPrefObserver = new PrefsHelper.PrefHandlerBase() {
+ @Override
+ public void prefValue(String pref, boolean value) {
+ mDisableThumbnailCreation = value;
+ }
+ };
+ PrefsHelper.addObserver(new String[] { "browser.tabs.disableThumbnailCreation" }, mPrefObserver);
}
public void getAndProcessThumbnailFor(Tab tab) {
+ if (mDisableThumbnailCreation) {
+ return;
+ }
+
if (AboutPages.isAboutHome(tab.getURL()) || AboutPages.isAboutPrivateBrowsing(tab.getURL())) {
tab.updateThumbnail(null, CachePolicy.NO_STORE);
return;
}
synchronized (mPendingThumbnails) {
if (mPendingThumbnails.lastIndexOf(tab) > 0) {
// This tab is already in the queue, so don't add it again.