Backed out changeset dcffecae84b7 (bug 1258464)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Wed, 30 Mar 2016 14:02:09 +0200
changeset 290869 d202b268a22881704adae85f42c4473e1b82259c
parent 290868 791698f3f8cfaa225a00339f8b2b963bca71c407
child 290870 7f7a84327477419e181f0369cebd26678cee2e88
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1258464
milestone48.0a1
backs outdcffecae84b741d837295ad77d0dd9e7ece391eb
Backed out changeset dcffecae84b7 (bug 1258464)
mobile/android/base/java/org/mozilla/gecko/GeckoView.java
mobile/android/base/resources/layout/gecko_app.xml
mobile/android/base/resources/values/attrs.xml
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoView.java
@@ -11,26 +11,31 @@ import java.util.List;
 import java.util.Set;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.annotation.ReflectionTarget;
 import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.gfx.GLController;
 import org.mozilla.gecko.gfx.LayerView;
+import org.mozilla.gecko.mozglue.GeckoLoader;
 import org.mozilla.gecko.mozglue.JNIObject;
+import org.mozilla.gecko.util.Clipboard;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.GeckoEventListener;
+import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.NativeEventListener;
 import org.mozilla.gecko.util.NativeJSObject;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.app.Activity;
 import android.content.Context;
+import android.content.Intent;
 import android.content.SharedPreferences;
+import android.content.res.TypedArray;
 import android.os.Binder;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.util.AttributeSet;
 import android.util.DisplayMetrics;
@@ -170,40 +175,103 @@ public class GeckoView extends LayerView
             };
     }
 
     private Window window;
     private boolean stateSaved;
 
     public GeckoView(Context context) {
         super(context);
-        init(context);
+        init(context, null, true);
     }
 
     public GeckoView(Context context, AttributeSet attrs) {
         super(context, attrs);
-        init(context);
+        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GeckoView);
+        String url = a.getString(R.styleable.GeckoView_url);
+        boolean doInit = a.getBoolean(R.styleable.GeckoView_doinit, true);
+        a.recycle();
+        init(context, url, doInit);
     }
 
-    private void init(Context context) {
+    private void init(Context context, String url, boolean doInit) {
+
         if (GeckoAppShell.getApplicationContext() == null) {
             GeckoAppShell.setApplicationContext(context.getApplicationContext());
         }
 
         // 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);
         }
 
         // Perform common initialization for Fennec/GeckoView.
         GeckoAppShell.setLayerView(this);
 
         initializeView(EventDispatcher.getInstance());
+
+        // TODO: Fennec currently takes care of its own initialization, so this
+        // flag is a hack used in Fennec to prevent GeckoView initialization.
+        // This should go away once Fennec also uses GeckoView for
+        // initialization.
+        if (!doInit)
+            return;
+
+        // If running outside of a GeckoActivity (eg, from a library project),
+        // load the native code and disable content providers
+        boolean isGeckoActivity = false;
+        try {
+            isGeckoActivity = context instanceof GeckoActivity;
+        } catch (NoClassDefFoundError ex) {}
+
+        if (!isGeckoActivity) {
+            Clipboard.init(context);
+            HardwareUtils.init(context);
+
+            // If you want to use GeckoNetworkManager, start it.
+
+            final GeckoProfile profile = GeckoProfile.get(context);
+         }
+
+        GeckoThread.ensureInit(null, null);
+        if (url != null) {
+            GeckoAppShell.sendEventToGecko(GeckoEvent.createURILoadEvent(url));
+        }
+
+        if (context instanceof Activity) {
+            Tabs tabs = Tabs.getInstance();
+            tabs.attachToContext(context);
+        }
+
+        EventDispatcher.getInstance().registerGeckoThreadListener(mGeckoEventListener,
+            "Gecko:Ready",
+            "Accessibility:Event",
+            "Content:StateChange",
+            "Content:LoadError",
+            "Content:PageShow",
+            "DOMTitleChanged",
+            "Link:Favicon",
+            "Prompt:Show",
+            "Prompt:ShowTop");
+
+        EventDispatcher.getInstance().registerGeckoThreadListener(mNativeEventListener,
+            "Accessibility:Ready",
+            "GeckoView:Message");
+
+        if (GeckoThread.launch()) {
+            // This is the first launch, so finish initialization and go.
+            GeckoProfile profile = GeckoProfile.get(context).forceCreate();
+
+        } else if (GeckoThread.isRunning()) {
+            // If Gecko is already running, that means the Activity was
+            // destroyed, so we need to re-attach Gecko to this GeckoView.
+            connectToGecko();
+        }
     }
 
     @Override
     protected Parcelable onSaveInstanceState()
     {
         final Parcelable superState = super.onSaveInstanceState();
         stateSaved = true;
         return new StateBinder(superState, this.window);
--- a/mobile/android/base/resources/layout/gecko_app.xml
+++ b/mobile/android/base/resources/layout/gecko_app.xml
@@ -22,16 +22,17 @@
 
         <RelativeLayout android:id="@+id/gecko_layout"
                         android:layout_width="match_parent"
                         android:layout_height="match_parent"
                         android:layout_below="@+id/tablet_tab_strip"
                         android:layout_above="@+id/find_in_page">
 
             <org.mozilla.gecko.GeckoView android:id="@+id/layer_view"
+                                         gecko:doinit="false"
                                          android:layout_width="match_parent"
                                          android:layout_height="match_parent"
                                          android:scrollbars="none"/>
 
             <AbsoluteLayout android:id="@+id/plugin_container"
                             android:background="@android:color/transparent"
                             android:layout_width="match_parent"
                             android:layout_height="match_parent"/>
--- a/mobile/android/base/resources/values/attrs.xml
+++ b/mobile/android/base/resources/values/attrs.xml
@@ -135,16 +135,21 @@
              background is full alpha and we need to copy the background underneath. -->
         <attr name="fadeBackgroundColor" format="dimension"/>
     </declare-styleable>
 
     <declare-styleable name="BookmarkFolderView">
         <attr name="state_open" format="boolean"/>
     </declare-styleable>
 
+    <declare-styleable name="GeckoView">
+        <attr name="url" format="string"/>
+        <attr name="doinit" format="boolean"/>
+    </declare-styleable>
+
     <declare-styleable name="IconTabWidget">
         <attr name="android:layout"/>
 
         <!-- Sets the tab's content type. Defaults to icon. -->
         <attr name="display">
             <enum name="icon" value="0x00" />
             <enum name="text" value="0x01" />
         </attr>