From a302fdb425331e0c9598f8b3f1dc7ac0a35114e8 Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Tue, 14 Feb 2012 20:08:14 -0800 Subject: [PATCH] bug 726929 - large session restore screenshots taken too often r=mfinkle --- mobile/android/base/GeckoApp.java | 36 ++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index ca945f8b5ca6..a06f1cfead98 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -148,6 +148,7 @@ abstract public class GeckoApp private static AbsoluteLayout mPluginContainer; public String mLastTitle; + public String mLastSnapshotUri; public String mLastViewport; public byte[] mLastScreen; public int mOwnActivityDepth = 0; @@ -573,23 +574,32 @@ abstract public class GeckoApp public void run() { synchronized (mSoftwareLayerClient) { - Tab tab = Tabs.getInstance().getSelectedTab(); - if (tab == null) - return; - - HistoryEntry lastHistoryEntry = tab.getLastHistoryEntry(); - if (lastHistoryEntry == null) + if (!Tabs.getInstance().isSelectedTab(mThumbnailTab)) return; if (getLayerController().getLayerClient() != mSoftwareLayerClient) return; - ViewportMetrics viewportMetrics = mSoftwareLayerClient.getGeckoViewportMetrics(); - if (viewportMetrics != null) - mLastViewport = viewportMetrics.toJSON(); + HistoryEntry lastHistoryEntry = mThumbnailTab.getLastHistoryEntry(); + if (lastHistoryEntry == null) + return; + ViewportMetrics viewportMetrics = mSoftwareLayerClient.getGeckoViewportMetrics(); + // If we don't have viewport metrics, the screenshot won't be right so bail + if (viewportMetrics == null) + return; + + String viewportJSON = viewportMetrics.toJSON(); + // If the title, uri and viewport haven't changed, the old screenshot is probably valid + if (viewportJSON.equals(mLastViewport) && + mLastTitle.equals(lastHistoryEntry.mTitle) && + mLastSnapshotUri.equals(lastHistoryEntry.mUri)) + return; + + mLastViewport = viewportJSON; mLastTitle = lastHistoryEntry.mTitle; - getAndProcessThumbnailForTab(tab, true); + mLastSnapshotUri = lastHistoryEntry.mUri; + getAndProcessThumbnailForTab(mThumbnailTab, true); } } } @@ -1309,8 +1319,10 @@ abstract public class GeckoApp } }); - Runnable r = new SessionSnapshotRunnable(tab); - GeckoAppShell.getHandler().postDelayed(r, 500); + if (Tabs.getInstance().isSelectedTab(tab)) { + Runnable r = new SessionSnapshotRunnable(tab); + GeckoAppShell.getHandler().postDelayed(r, 500); + } } void handleShowToast(final String message, final String duration) {