Bug 1202052 - Bypass cache on reload button long press. r=margaret, a=lizzard
authorSebastian Kaspari <s.kaspari@gmail.com>
Thu, 24 Sep 2015 15:27:56 +0200
changeset 606977 4d84411677226f6c48e7f688acd8ba93bf2e3632
parent 606976 a3080512e7a6a2c00a7e3c1415e98f8fea064254
child 606978 9872ab4aa51149d870ee97be5c090d7b12d279fe
push id93006
push userjyavenard@mozilla.com
push dateThu, 15 Oct 2015 05:15:33 +0000
treeherdertry@45ea2a01301e [default view] [failures only]
reviewersmargaret, lizzard
bugs1202052
milestone43.0a2
Bug 1202052 - Bypass cache on reload button long press. r=margaret, a=lizzard
mobile/android/base/BrowserApp.java
mobile/android/base/GeckoView.java
mobile/android/base/Tab.java
mobile/android/base/menu/GeckoMenu.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -665,17 +665,17 @@ public class BrowserApp extends GeckoApp
                     tab.doBack();
                     return true;
 
                 case KeyEvent.KEYCODE_RIGHT_BRACKET:
                     tab.doForward();
                     return true;
 
                 case KeyEvent.KEYCODE_R:
-                    tab.doReload();
+                    tab.doReload(false);
                     return true;
 
                 case KeyEvent.KEYCODE_PERIOD:
                     tab.doStop();
                     return true;
 
                 case KeyEvent.KEYCODE_T:
                     addTab();
@@ -3385,17 +3385,17 @@ public class BrowserApp extends GeckoApp
         if (itemId == R.id.share) {
             shareCurrentUrl();
             return true;
         }
 
         if (itemId == R.id.reload) {
             tab = Tabs.getInstance().getSelectedTab();
             if (tab != null)
-                tab.doReload();
+                tab.doReload(false);
             return true;
         }
 
         if (itemId == R.id.back) {
             tab = Tabs.getInstance().getSelectedTab();
             if (tab != null)
                 tab.doBack();
             return true;
@@ -3502,16 +3502,31 @@ public class BrowserApp extends GeckoApp
         // a chance.
         if (onContextItemSelected(item)) {
             return true;
         }
 
         return super.onOptionsItemSelected(item);
     }
 
+    @Override
+    public boolean onMenuItemLongClick(MenuItem item) {
+        if (item.getItemId() == R.id.reload) {
+            Tab tab = Tabs.getInstance().getSelectedTab();
+            if (tab != null) {
+                tab.doReload(true);
+
+                Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.MENU, "reload_force");
+            }
+            return true;
+        }
+
+        return super.onMenuItemLongClick(item);
+    }
+
     public void showGuestModeDialog(final GuestModeDialog type) {
         final Prompt ps = new Prompt(this, new Prompt.PromptCallback() {
             @Override
             public void onPromptFinished(String result) {
                 try {
                     int itemId = new JSONObject(result).getInt("button");
                     if (itemId == 0) {
                         String args = "";
--- a/mobile/android/base/GeckoView.java
+++ b/mobile/android/base/GeckoView.java
@@ -429,17 +429,17 @@ public class GeckoView extends LayerView
 
         /**
         * Reload the current URL resource into the Browser. The URL is force loaded from the
         * network and is not pulled from cache.
         */
         public void reload() {
             Tab tab = Tabs.getInstance().getTab(mId);
             if (tab != null) {
-                tab.doReload();
+                tab.doReload(true);
             }
         }
 
         /**
         * Stop the current loading operation.
         */
         public void stop() {
             Tab tab = Tabs.getInstance().getTab(mId);
--- a/mobile/android/base/Tab.java
+++ b/mobile/android/base/Tab.java
@@ -609,18 +609,18 @@ public class Tab {
             }
         });
     }
 
     public boolean isEnteringReaderMode() {
         return mEnteringReaderMode;
     }
 
-    public void doReload() {
-        GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Reload", "");
+    public void doReload(boolean bypassCache) {
+        GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Reload", "{\"bypassCache\":" + String.valueOf(bypassCache) + "}");
         GeckoAppShell.sendEventToGecko(e);
     }
 
     // Our version of nsSHistory::GetCanGoBack
     public boolean canDoBack() {
         return mCanDoBack;
     }
 
--- a/mobile/android/base/menu/GeckoMenu.java
+++ b/mobile/android/base/menu/GeckoMenu.java
@@ -1,15 +1,16 @@
 /* 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.menu;
 
 import org.mozilla.gecko.AppConstants;
+import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.util.ThreadUtils.AssertBehavior;
 import org.mozilla.gecko.widget.GeckoActionProvider;
 
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -251,31 +252,39 @@ public class GeckoMenu extends ListView
             ((MenuItemActionBar) actionView).setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View view) {
                     handleMenuItemClick(menuItem);
                 }
             });
             ((MenuItemActionBar) actionView).setOnLongClickListener(new View.OnLongClickListener() {
                 @Override
-                public boolean onLongClick(View v) {
-                    return handleMenuItemLongClick(menuItem);
+                public boolean onLongClick(View view) {
+                    if (handleMenuItemLongClick(menuItem)) {
+                        GeckoAppShell.vibrateOnHapticFeedbackEnabled(getResources().getIntArray(R.array.long_press_vibrate_msec));
+                        return true;
+                    }
+                    return false;
                 }
             });
         } else if (actionView instanceof MenuItemActionView) {
             ((MenuItemActionView) actionView).setMenuItemClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View view) {
                     handleMenuItemClick(menuItem);
                 }
             });
             ((MenuItemActionView) actionView).setMenuItemLongClickListener(new View.OnLongClickListener() {
                 @Override
                 public boolean onLongClick(View view) {
-                    return handleMenuItemLongClick(menuItem);
+                    if (handleMenuItemLongClick(menuItem)) {
+                        GeckoAppShell.vibrateOnHapticFeedbackEnabled(getResources().getIntArray(R.array.long_press_vibrate_msec));
+                        return true;
+                    }
+                    return false;
                 }
             });
         }
 
         return added;
     }
 
     @Override
@@ -639,22 +648,25 @@ public class GeckoMenu extends ListView
             showMenu(subMenu);
         } else {
             close();
             mCallback.onMenuItemClick(item);
         }
     }
 
     boolean handleMenuItemLongClick(GeckoMenuItem item) {
-        if(!item.isEnabled()) {
+        if (!item.isEnabled()) {
             return false;
         }
 
-        if(mCallback != null) {
-            return mCallback.onMenuItemLongClick(item);
+        if (mCallback != null) {
+            if (mCallback.onMenuItemLongClick(item)) {
+                close();
+                return true;
+            }
         }
         return false;
     }
 
     public Callback getCallback() {
         return mCallback;
     }
 
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -1721,16 +1721,21 @@ var BrowserApp = {
           break;
 
       case "Session:Reload": {
         let flags = Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
 
         // Check to see if this is a message to enable/disable mixed content blocking.
         if (aData) {
           let data = JSON.parse(aData);
+
+          if (data.bypassCache) {
+            flags |= Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
+          }
+
           if (data.contentType === "tracking") {
             // Convert document URI into the format used by
             // nsChannelClassifier::ShouldEnableTrackingProtection
             // (any scheme turned into https is correct)
             let normalizedUrl = Services.io.newURI("https://" + browser.currentURI.hostPort, null, null);
             if (data.allowContent) {
               // Add the current host in the 'trackingprotection' consumer of
               // the permission manager using a normalized URI. This effectively