diff options
Diffstat (limited to 'src/com/android/browser/Controller.java')
| -rw-r--r-- | src/com/android/browser/Controller.java | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java index b9bd9d73e..23921032f 100644 --- a/src/com/android/browser/Controller.java +++ b/src/com/android/browser/Controller.java @@ -548,13 +548,15 @@ public class Controller Log.e(LOGTAG, "BrowserActivity is already paused."); return; } - mTabControl.pauseCurrentTab(); mActivityPaused = true; - if (mTabControl.getCurrentIndex() >= 0 && - !pauseWebViewTimers(mActivityPaused)) { - mWakeLock.acquire(); - mHandler.sendMessageDelayed(mHandler - .obtainMessage(RELEASE_WAKELOCK), WAKELOCK_TIMEOUT); + Tab tab = mTabControl.getCurrentTab(); + if (tab != null) { + tab.pause(); + if (!pauseWebViewTimers(tab)) { + mWakeLock.acquire(); + mHandler.sendMessageDelayed(mHandler + .obtainMessage(RELEASE_WAKELOCK), WAKELOCK_TIMEOUT); + } } mUi.onPause(); mNetworkHandler.onPause(); @@ -580,10 +582,12 @@ public class Controller Log.e(LOGTAG, "BrowserActivity is already resumed."); return; } - mTabControl.resumeCurrentTab(); mActivityPaused = false; - resumeWebViewTimers(); - + Tab current = mTabControl.getCurrentTab(); + if (current != null) { + current.resume(); + resumeWebViewTimers(current); + } if (mWakeLock.isHeld()) { mHandler.removeMessages(RELEASE_WAKELOCK); mWakeLock.release(); @@ -593,9 +597,11 @@ public class Controller WebView.enablePlatformNotifications(); } - private void resumeWebViewTimers() { - Tab tab = mTabControl.getCurrentTab(); - if (tab == null) return; // monkey can trigger this + /** + * resume all WebView timers using the WebView instance of the given tab + * @param tab guaranteed non-null + */ + private void resumeWebViewTimers(Tab tab) { boolean inLoad = tab.inPageLoad(); if ((!mActivityPaused && !inLoad) || (mActivityPaused && inLoad)) { CookieSyncManager.getInstance().startSync(); @@ -606,19 +612,23 @@ public class Controller } } - private boolean pauseWebViewTimers(boolean activityPaused) { - Tab tab = mTabControl.getCurrentTab(); - boolean inLoad = tab.inPageLoad(); - if (activityPaused && !inLoad) { + /** + * Pause all WebView timers using the WebView of the given tab + * @param tab + * @return true if the timers are paused or tab is null + */ + private boolean pauseWebViewTimers(Tab tab) { + if (tab == null) { + return true; + } else if (!tab.inPageLoad()) { CookieSyncManager.getInstance().stopSync(); WebView w = getCurrentWebView(); if (w != null) { w.pauseTimers(); } return true; - } else { - return false; } + return false; } void onDestroy() { @@ -713,7 +723,7 @@ public class Controller // to start the timer. As we won't switch tabs while an activity is in // pause state, we can ensure calling resume and pause in pair. if (mActivityPaused) { - resumeWebViewTimers(); + resumeWebViewTimers(tab); } mLoadStopped = false; if (!mNetworkHandler.isNetworkUp()) { @@ -754,7 +764,7 @@ public class Controller } // pause the WebView timer and release the wake lock if it is finished // while BrowserActivity is in pause state. - if (mActivityPaused && pauseWebViewTimers(mActivityPaused)) { + if (mActivityPaused && pauseWebViewTimers(tab)) { if (mWakeLock.isHeld()) { mHandler.removeMessages(RELEASE_WAKELOCK); mWakeLock.release(); @@ -2317,7 +2327,7 @@ public class Controller // force the tab's inLoad() to be false as we are going to // either finish the activity or remove the tab. This will // ensure pauseWebViewTimers() taking action. - mTabControl.getCurrentTab().clearInPageLoad(); + current.clearInPageLoad(); if (mTabControl.getTabCount() == 1) { mActivity.finish(); return; @@ -2326,7 +2336,7 @@ public class Controller Log.e(LOGTAG, "BrowserActivity is already paused " + "while handing goBackOnePageOrQuit."); } - pauseWebViewTimers(true); + pauseWebViewTimers(current); removeTab(current); } /* |
