Bug 1362192 - Remove GeckoInterface.getDefaultUAString; r=snorp
authorJim Chen <nchen@mozilla.com>
Mon, 15 May 2017 23:11:17 -0400
changeset 406670 e4607267bb9ff933edac5090ef5798d8538cea09
parent 406669 06aae5032411f0d095c9611700fbb8d50ac9bfd7
child 406671 06142f9787e7643cae17dced089d4ebd37ec1bbc
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1362192
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1362192 - Remove GeckoInterface.getDefaultUAString; r=snorp Move GeckoInterface.getDefaultUAString() to GeckoApplication. MozReview-Commit-ID: FHsRrbiqJ3F
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java
mobile/android/base/java/org/mozilla/gecko/icons/loader/IconDownloader.java
mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -2145,22 +2145,16 @@ public abstract class GeckoApp extends G
     public void disableOrientationListener() {
         if (mCameraOrientationEventListener != null) {
             mCameraOrientationEventListener.disable();
             mCameraOrientationEventListener = null;
         }
     }
 
     @Override
-    public String getDefaultUAString() {
-        return HardwareUtils.isTablet() ? AppConstants.USER_AGENT_FENNEC_TABLET :
-                                          AppConstants.USER_AGENT_FENNEC_MOBILE;
-    }
-
-    @Override
     public void createShortcut(final String title, final String url) {
 
         final Tab selectedTab = Tabs.getInstance().getSelectedTab();
         final String manifestUrl = selectedTab.getManifestUrl();
 
         if (manifestUrl != null) {
             // If a page has associated manifest, lets install it
             final GeckoBundle message = new GeckoBundle();
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -88,16 +88,21 @@ public class GeckoApplication extends Ap
             // buildid, so we purge here instead.
             Log.w(LOG_TAG, "STARTUP PERFORMANCE WARNING: un-official build: purging the " +
                            "startup (JavaScript) caches.");
             args = (args != null) ? (args + " -purgecaches") : "-purgecaches";
         }
         return args;
     }
 
+    public static String getDefaultUAString() {
+        return HardwareUtils.isTablet() ? AppConstants.USER_AGENT_FENNEC_TABLET :
+                                          AppConstants.USER_AGENT_FENNEC_MOBILE;
+    }
+
     public static void shutdown(final Intent restartIntent) {
         ThreadUtils.assertOnUiThread();
 
         // Wait for Gecko to handle any pause events.
         if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
             GeckoThread.waitOnGecko();
         }
 
--- a/mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java
+++ b/mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java
@@ -36,16 +36,17 @@ import javax.net.ssl.SSLException;
 import ch.boye.httpclientandroidlib.protocol.HTTP;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.EventDispatcher;
 import org.mozilla.gecko.GeckoAppShell;
+import org.mozilla.gecko.GeckoApplication;
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.annotation.JNITarget;
 import org.mozilla.gecko.util.FileUtils;
 import org.mozilla.gecko.util.GeckoBundle;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.ProxySelector;
 import org.mozilla.gecko.util.ThreadUtils;
@@ -542,25 +543,17 @@ public class Distribution {
         long start = SystemClock.uptimeMillis();
         Log.v(LOGTAG, "Downloading referred distribution: " + uri);
 
         try {
             final HttpURLConnection connection = (HttpURLConnection) ProxySelector.openConnectionWithProxy(uri);
 
             // If the Search Activity starts, and we handle the referrer intent, this'll return
             // null. Recover gracefully in this case.
-            final GeckoAppShell.GeckoInterface geckoInterface = GeckoAppShell.getGeckoInterface();
-            final String ua;
-            if (geckoInterface == null) {
-                // Fall back to GeckoApp's default implementation.
-                ua = HardwareUtils.isTablet() ? AppConstants.USER_AGENT_FENNEC_TABLET :
-                                                AppConstants.USER_AGENT_FENNEC_MOBILE;
-            } else {
-                ua = geckoInterface.getDefaultUAString();
-            }
+            final String ua = GeckoApplication.getDefaultUAString();
 
             connection.setRequestProperty(HTTP.USER_AGENT, ua);
             connection.setRequestProperty("Accept", EXPECTED_CONTENT_TYPE);
 
             try {
                 final JarInputStream distro;
                 try {
                     distro = fetchDistribution(uri, connection);
--- a/mobile/android/base/java/org/mozilla/gecko/icons/loader/IconDownloader.java
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/loader/IconDownloader.java
@@ -7,17 +7,17 @@ package org.mozilla.gecko.icons.loader;
 
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.VisibleForTesting;
 import android.util.Log;
 
-import org.mozilla.gecko.GeckoAppShell;
+import org.mozilla.gecko.GeckoApplication;
 import org.mozilla.gecko.icons.decoders.FaviconDecoder;
 import org.mozilla.gecko.icons.decoders.LoadFaviconResult;
 import org.mozilla.gecko.icons.IconRequest;
 import org.mozilla.gecko.icons.IconResponse;
 import org.mozilla.gecko.icons.storage.FailureCache;
 import org.mozilla.gecko.util.IOUtils;
 import org.mozilla.gecko.util.ProxySelector;
 import org.mozilla.gecko.util.StringUtils;
@@ -181,17 +181,17 @@ public class IconDownloader implements I
     }
 
     @VisibleForTesting
     @NonNull
     HttpURLConnection connectTo(String uri) throws URISyntaxException, IOException {
         final HttpURLConnection connection = (HttpURLConnection) ProxySelector.openConnectionWithProxy(
                 new URI(uri));
 
-        connection.setRequestProperty("User-Agent", GeckoAppShell.getGeckoInterface().getDefaultUAString());
+        connection.setRequestProperty("User-Agent", GeckoApplication.getDefaultUAString());
 
         // We implemented or own way of following redirects back when this code was using HttpClient.
         // Nowadays we should let HttpUrlConnection do the work - assuming that it doesn't follow
         // redirects in loops forever.
         connection.setInstanceFollowRedirects(false);
 
         return connection;
     }
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
@@ -1028,20 +1028,18 @@ public class GeckoPreferences
      * Broadcast the provided value as the value of the
      * <code>PREFS_GEO_REPORTING</code> pref.
      */
     public static void broadcastStumblerPref(final Context context, final boolean value) {
        Intent intent = new Intent(ACTION_STUMBLER_UPLOAD_PREF)
                 .putExtra("pref", PREFS_GEO_REPORTING)
                 .putExtra("branch", GeckoSharedPrefs.APP_PREFS_NAME)
                 .putExtra("enabled", value)
-                .putExtra("moz_mozilla_api_key", AppConstants.MOZ_MOZILLA_API_KEY);
-       if (GeckoAppShell.getGeckoInterface() != null) {
-           intent.putExtra("user_agent", GeckoAppShell.getGeckoInterface().getDefaultUAString());
-       }
+                .putExtra("moz_mozilla_api_key", AppConstants.MOZ_MOZILLA_API_KEY)
+                .putExtra("user_agent", GeckoApplication.getDefaultUAString());
        broadcastAction(context, intent);
     }
 
     /**
      * Broadcast the current value of the
      * <code>PREFS_GEO_REPORTING</code> pref.
      */
     public static void broadcastStumblerPref(final Context context) {
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
@@ -22,22 +22,16 @@ public class BaseGeckoInterface implemen
         eventDispatcher = new EventDispatcher();
     }
 
     @Override
     public EventDispatcher getAppEventDispatcher() {
         return eventDispatcher;
     }
 
-    @Override
-    public String getDefaultUAString() {
-        return HardwareUtils.isTablet() ? BuildConfig.USER_AGENT_GECKOVIEW_TABLET :
-                                          BuildConfig.USER_AGENT_GECKOVIEW_MOBILE;
-    }
-
     // Bug 908779: Implement this
     @Override
     public void addPluginView(final View view) {}
 
     // Bug 908781: Implement this
     @Override
     public void removePluginView(final View view) {}
 
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -1656,17 +1656,16 @@ public class GeckoAppShell
     public interface AppStateListener {
         public void onPause();
         public void onResume();
         public void onOrientationChanged();
     }
 
     public interface GeckoInterface {
         public @NonNull EventDispatcher getAppEventDispatcher();
-        public String getDefaultUAString();
 
         public void addPluginView(View view);
         public void removePluginView(final View view);
         public void enableOrientationListener();
         public void disableOrientationListener();
         public void addAppStateListener(AppStateListener listener);
         public void removeAppStateListener(AppStateListener listener);
         public void notifyWakeLockChanged(String topic, String state);