Porting browser changes from 1599-qrd to 1847

-----
    Added WebsiteSettingsFragment in known fragments

    Missing fragment was causing 'Settings > Advanced > Website settings'
    to crash.

    Change-Id: Iaf99a292293e269a1f359acb52f3448ed90c2abc

-----
   Increase max sandboxed process services to 19
   in SWE Browser manifest matching the content shell.

-----
   Hide title bar feature is enabled and required callbacks are
   implemented.

  - Add a new setting to allow media downloads

    - if audio and video mimetype based urls which do not
      have "Content-Dispostion: attachment" in response header
      should be allowed to download or not

      Change-Id: If5892db0bbfb81eaa6b0ae2a7e1ae81e98d08d33

  - Add "modify audio settings" permission in AndroidManifest for browser

     Change-Id: I68bf299785839cf2b11b78d1d53f6ec03bd10b62

  - Browser to allow adding extra HTTP headers.

     Change-Id: Ibd6b76a0001fd6e08cc0565231b09efe0f63bdf2

  - Allow auto play without Gesture

     Change-Id: I666658ae6955a43ab346d01e733ef6480e615ce1

  - Expose 'def_enable_media_downloads' for clients to override Media download option.

     Change-Id: I026d7982fa2507d5f461bdae04d2f6413f2eb822

  - Hide LIVE_MENU items on non http/https pages

    - Hide the following menu items on non http/https URIs
       - Share page
       - Find on page
       - Request desktop site
       - Save for offline reading

     Change-Id: I54de428130a2aab27d1eb4b67b84d2911ae356b2

   - Enable Save for offline option only after page is fully loaded.

      Change-Id: I876756f412f3c9462042bccf8a4a7f970e801185

   - FetchUrlMimeType was not encoding URL before calling HttpHead.

      Change-Id: Ib389963af0f391a5a59bbbd83feeedcf8e3dfb8d

   - Chinese translation for "Allow Media Downloads"

      Change-Id: I5a8822383d79af33e771db4c9e8ead03ebefe333

   - Show only the partial screenshot instead of the
     whole viewport when switching back to tab.

      Change-Id: I442b1256460ac4da1c40941ea7a1934b8675cb3a

    - Fix navigation screen animation issues

       Height of titlebar was incorrectly added twice to the calculation of
       animation parameters causing: (i) AnimScreen view to be drawed below
       the NavTabView when swithing to navigation screen, and (ii) screen
       flashing when selecting a tab from the navigation screen.

       Change-Id: Ifec1a4a8b5832802cad7658e202f0611fb8c3bfb

     - Fix saving state for tabs purged by memory monitor

        Fetching the incognito property from the Tab's webview was causing Tabs
        whose webview was set to null (e.g. by the memory monitor) to be skipped
        when saving state. The fix uses an existing Tab API that does not presume
        that a Tab has a webview attached.

        Change-Id: I15c8c77431548ea5818ee0572f77afe2e66edf90

     - Fix a continously reloading web page

        Page has JavaScript logic to reload on size change. When titlebar is
        hidden, the content margin is readjusted which is not necessary.
        Fixed by removing the margin adjustment.

        Change-Id: Id26f7785c43dc7a46615dfa03f8fecd77c432dca

     - Fixed browser crash that happened while saving links

        The encodeURL function in FetchUrlMimetype was double encoding
        the URL. This was leading to a corrupted URL. HttpHead was
        throwing an exception due to this.
        The encodeURL was done to fix another problem, where URLs
        with ### characters were causing a crash. Replaced encodeURL
        with URI to check if URL is correct.
        Also, disabled "save link" option for incorrect URLs.

        Change-Id: I99d606c2c59251233fa0ffad9c81138c9baa6342

     - Fix various issues with autohide, quickcontrols and fixed titlebar

        A whitebar is seen when quickcontrols is turned on. Configuring
        to use fixed titlebar doesn't work anymore.  Both issues are fixed
        by repairing the corresponding logic in BaseUi and TitleBar classes.

        A new feature to reveal the titlebar on pageload is added.
        Fullscreen logic is modfied to take into consideration of the state
        of quickcontrols and the fullscreen browser setting.  Without these
        changes, going to fullscreen shows unneeded titlebar.

        Change-Id: I2358f3b8aec5bf28a49870fb1a8c4f49aa168351

     - Use regular tab for loading url in "go live" option

        - This use normal tab for loading live pages instead of
          snapshot tab.

        Change-Id: Iebe8278394d983f461892a91813a35f94fd8bde3

     - Fix for saved pages thumbnails

        - Properly scale down screenshot bitmaps prior to saving as thumbnails.
          Addresses the issue of partially displaying saved pages thumbnails as
          well as UI crashes and slow scrolling when there is a large number of
          saved pages.

        Change-Id: Ib89722da767759740773f0ce3a6f018b5782a8a5

      - Prune bitmap recycle calls

         Remove recycle() calls in preference to setting the bitmap to null
         to avoid accidental deletion of a bitmap when its still in use.

         Change-Id: I7c67eecafdcaf0795de3250fe10650bef7dd76d8

      - Fixes back navigation when UserAgent is changed on new tab

          When clicking a link opens up a new tab, and the user agent is
          changed for this new tab, browser was creating a new navigation
          entry. When user clicked back button the browser was going back
          to the same page, instead of removing the tab.

          For example, the user agent can be change by enabling/disabling
          desktop site.

          Change-Id: Id52fb20e9f056ada7d98c665b3274d85a2252935
-----
     Comment out geolocation changes.

Change-Id: I001bf88e5cb716fcce4b066893631627d2aee76d
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index ea1a60c..5f3402f 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -708,10 +708,6 @@
 
         WebView.disablePlatformNotifications();
         NfcHandler.unregister(mActivity);
-        if (sThumbnailBitmap != null) {
-            sThumbnailBitmap.recycle();
-            sThumbnailBitmap = null;
-        }
     }
 
     @Override
@@ -970,6 +966,8 @@
             Performance.onPageFinished(tab.getUrl());
          }
 
+        tab.onPageFinished();
+
         Performance.tracePageFinished();
     }
 
@@ -1838,11 +1836,17 @@
         boolean canGoForward = false;
         boolean isDesktopUa = false;
         boolean isLive = false;
+        // Following flag is used to identify schemes for which the LIVE_MENU
+        // items defined in res/menu/browser.xml should be enabled
+        boolean isLiveScheme = false;
+        boolean isPageFinished = false;
         if (tab != null) {
             canGoBack = tab.canGoBack();
             canGoForward = tab.canGoForward();
             isDesktopUa = mSettings.hasDesktopUseragent(tab.getWebView());
             isLive = !tab.isSnapshot();
+            isLiveScheme = UrlUtils.isLiveScheme(tab.getWebView().getUrl());
+            isPageFinished = tab.getPageFinishedStatus();
         }
         final MenuItem back = menu.findItem(R.id.back_menu_id);
         back.setEnabled(canGoBack);
@@ -1877,8 +1881,9 @@
         boolean showDebugSettings = mSettings.isDebugEnabled();
         final MenuItem uaSwitcher = menu.findItem(R.id.ua_desktop_menu_id);
         uaSwitcher.setChecked(isDesktopUa);
-        menu.setGroupVisible(R.id.LIVE_MENU, isLive);
+        menu.setGroupVisible(R.id.LIVE_MENU, isLive && isLiveScheme);
         menu.setGroupVisible(R.id.SNAPSHOT_MENU, !isLive);
+        menu.setGroupEnabled(R.id.OFFLINE_READING, isLive && isLiveScheme && isPageFinished);
         // history and snapshots item are the members of COMBO menu group,
         // so if show history item, only make snapshots item invisible.
         menu.findItem(R.id.snapshots_menu_id).setVisible(false);
@@ -2143,7 +2148,7 @@
     public void toggleUserAgent() {
         WebView web = getCurrentWebView();
         mSettings.toggleDesktopUseragent(web);
-        web.loadUrl(web.getOriginalUrl());
+        web.reload();
     }
 
     @Override
@@ -2180,7 +2185,11 @@
 
     private void goLive() {
         SnapshotTab t = (SnapshotTab) getCurrentTab();
-        t.loadUrl(t.getLiveUrl(), null);
+        String url = t.getLiveUrl();
+        // destroy the old snapshot tab
+        closeCurrentTab();
+        Tab liveTab =  createNewTab(false, true, false);
+        loadUrl(liveTab, url);
     }
 
     private void showExitDialog(final Activity activity) {
@@ -2480,11 +2489,6 @@
 
         if (sThumbnailBitmap == null || sThumbnailBitmap.getWidth() != width
                    || sThumbnailBitmap.getHeight() != height) {
-            if (sThumbnailBitmap != null) {
-                sThumbnailBitmap.recycle();
-                sThumbnailBitmap = null;
-            }
-
             sThumbnailBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
         }
 
@@ -2509,8 +2513,6 @@
             new ValueCallback<Bitmap>() {
                 @Override
                 public void onReceiveValue(Bitmap bitmap) {
-                    Log.e("sudheer", "screensot bitmap: w: " + bitmap.getWidth()
-                          + " h: " + bitmap.getHeight());
                     if (bitmap != null)
                         bitmap = bitmap.copy(Bitmap.Config.RGB_565, false);
                     cb.onReceiveValue(bitmap);