Stop the loading after WAKELOCK_TIMEOUT (5min) when
the Browser is in the background. So we won't continue to
burn the battery if there is some mis-behaved JavaScript
running.

Fix http://b/issue?id=2147840
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index a66334b..78664a0 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -2380,6 +2380,10 @@
                 case RELEASE_WAKELOCK:
                     if (mWakeLock.isHeld()) {
                         mWakeLock.release();
+                        // if we reach here, Browser should be still in the
+                        // background loading after WAKELOCK_TIMEOUT (5-min).
+                        // To avoid burning the battery, stop loading.
+                        mTabControl.stopAllLoading();
                     }
                     break;
 
diff --git a/src/com/android/browser/TabControl.java b/src/com/android/browser/TabControl.java
index 2f15a9c..40f6c31 100644
--- a/src/com/android/browser/TabControl.java
+++ b/src/com/android/browser/TabControl.java
@@ -938,6 +938,16 @@
         return null;
     }
 
+    void stopAllLoading() {
+        final int size = getTabCount();
+        for (int i = 0; i < size; i++) {
+            final WebView webview = getTab(i).getTopWindow();
+            if (webview != null) {
+                webview.stopLoading();
+            }
+        }
+    }
+
     // This method checks if a non-app tab (one created within the browser)
     // matches the given url.
     private boolean tabMatchesUrl(Tab t, String url) {