Bug 1359419 - Add GeckoView.preload() r=esawin draft
authorJames Willcox <snorp@snorp.net>
Tue, 25 Apr 2017 09:15:06 -0500
changeset 567757 7c1e677feecc64076312a01553223bf1afa1a5a5
parent 567756 2f06771b3ce1cd210dfab17a7d7d246ebc8867e3
child 567758 a30e1341bd34ea454f0dea1a63d39abc00606c09
push id55687
push userbmo:snorp@snorp.net
push dateTue, 25 Apr 2017 14:19:41 +0000
reviewersesawin
bugs1359419
milestone55.0a1
Bug 1359419 - Add GeckoView.preload() r=esawin MozReview-Commit-ID: 6DYq2oiz1Ug
mobile/android/geckoview/proguard-rules.txt
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
--- a/mobile/android/geckoview/proguard-rules.txt
+++ b/mobile/android/geckoview/proguard-rules.txt
@@ -3,17 +3,17 @@
 # Preserve all annotations.
 
 -keepattributes *Annotation*
 
 # Preserve all public classes, and their public and protected fields and
 # methods.
 
 -keep public class * {
-    public protected *;
+    static public protected *;
 }
 
 # Preserve all .class method names.
 
 -keepclassmembernames class * {
     java.lang.Class class$(java.lang.String);
     java.lang.Class class$(java.lang.String, boolean);
 }
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
@@ -262,35 +262,40 @@ public class GeckoView extends LayerView
 
     public GeckoView(Context context, AttributeSet attrs, final GeckoViewSettings settings) {
         super(context, attrs);
 
         final GeckoViewSettings newSettings = new GeckoViewSettings(settings, getEventDispatcher());
         init(context, newSettings);
     }
 
-    private void init(final Context context, final GeckoViewSettings settings) {
+    public static void preload(Context context) {
+        final GeckoProfile profile = GeckoProfile.get(
+            context.getApplicationContext());
+
         if (GeckoAppShell.getApplicationContext() == null) {
             GeckoAppShell.setApplicationContext(context.getApplicationContext());
         }
+        GeckoAppShell.setApplicationContext(context.getApplicationContext());
+        if (GeckoThread.initMainProcess(profile,
+                                        /* args */ null,
+                                        /* debugging */ false)) {
+            GeckoThread.launch();
+        }
+    }
 
+    private void init(final Context context, final GeckoViewSettings settings) {
         // Set the GeckoInterface if the context is an activity and the
         // GeckoInterface has not already been set
         if (context instanceof Activity && getGeckoInterface() == null) {
             setGeckoInterface(new BaseGeckoInterface(context));
             GeckoAppShell.setContextGetter(this);
         }
 
-        final GeckoProfile profile = GeckoProfile.get(
-            context.getApplicationContext());
-        if (GeckoThread.initMainProcess(profile,
-                                        /* args */ null,
-                                        /* debugging */ false)) {
-            GeckoThread.launch();
-        }
+        preload(context);
 
         // Perform common initialization for Fennec/GeckoView.
         GeckoAppShell.setLayerView(this);
 
         initializeView();
         mListener.registerListeners();
 
         if (settings == null) {