Bug 720048 - Move Tab:Foo listeners and associated tab logic into Tabs. r=mbrubeck
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Tue, 24 Jan 2012 09:16:26 -0800
changeset 86475 3a9e2a1b176778b3ef8b38fa708dcfdb105d6781
parent 86474 9be58af4f6a5ebe8e4ab10df0c4d495475158420
child 86476 c375946d50398e1f388ecf92e6e5f500ec7c6757
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs720048
milestone12.0a1
Bug 720048 - Move Tab:Foo listeners and associated tab logic into Tabs. r=mbrubeck
mobile/android/base/GeckoApp.java
mobile/android/base/Tabs.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -945,33 +945,16 @@ abstract public class GeckoApp
             } else if (event.equals("Content:LoadError")) {
                 final int tabId = message.getInt("tabID");
                 final String uri = message.getString("uri");
                 final String title = message.getString("title");
                 handleLoadError(tabId, uri, title);
             } else if (event.equals("onCameraCapture")) {
                 //GeckoApp.mAppContext.doCameraCapture(message.getString("path"));
                 doCameraCapture();
-            } else if (event.equals("Tab:Added")) {
-                Log.i(LOGTAG, "Received message from Gecko: " + SystemClock.uptimeMillis() + " - Tab:Added");
-                Tab tab = Tabs.getInstance().addTab(message);
-                Boolean selected = message.getBoolean("selected");
-                if (selected)
-                    Tabs.getInstance().selectTab(tab.getId());
-            } else if (event.equals("Tab:Close")) {
-                int tabId = message.getInt("tabID");
-                Tab tab = Tabs.getInstance().getTab(tabId);
-                Tabs.getInstance().closeTab(tab);
-            } else if (event.equals("Tab:ScreenshotData")) {
-                int tabId = message.getInt("tabID");
-                Tab tab = Tabs.getInstance().getTab(tabId);
-                processThumbnail(tab, null, Base64.decode(message.getString("data").substring(22), Base64.DEFAULT));
-            } else if (event.equals("Tab:Select")) {
-                int tabId = message.getInt("tabID");
-                Tabs.getInstance().selectTab(tabId);
             } else if (event.equals("Doorhanger:Add")) {
                 handleDoorHanger(message);
             } else if (event.equals("Doorhanger:Remove")) {
                 handleDoorHangerRemove(message);
             } else if (event.equals("Gecko:Ready")) {
                 sIsGeckoReady = true;
                 mMainHandler.post(new Runnable() {
                     public void run() {
@@ -1607,20 +1590,16 @@ abstract public class GeckoApp
         GeckoAppShell.registerGeckoEventListener("DOMLinkAdded", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("DOMWindowClose", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("log", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Content:LocationChange", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Content:SecurityChange", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Content:StateChange", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Content:LoadError", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("onCameraCapture", GeckoApp.mAppContext);
-        GeckoAppShell.registerGeckoEventListener("Tab:Added", GeckoApp.mAppContext);
-        GeckoAppShell.registerGeckoEventListener("Tab:Close", GeckoApp.mAppContext);
-        GeckoAppShell.registerGeckoEventListener("Tab:Select", GeckoApp.mAppContext);
-        GeckoAppShell.registerGeckoEventListener("Tab:ScreenshotData", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Doorhanger:Remove", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Menu:Add", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Menu:Remove", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Gecko:Ready", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Toast:Show", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("ToggleChrome:Hide", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("ToggleChrome:Show", GeckoApp.mAppContext);
@@ -1938,20 +1917,16 @@ abstract public class GeckoApp
         GeckoAppShell.unregisterGeckoEventListener("DOMLinkAdded", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("DOMWindowClose", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("log", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Content:LocationChange", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Content:SecurityChange", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Content:StateChange", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Content:LoadError", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("onCameraCapture", GeckoApp.mAppContext);
-        GeckoAppShell.unregisterGeckoEventListener("Tab:Added", GeckoApp.mAppContext);
-        GeckoAppShell.unregisterGeckoEventListener("Tab:Close", GeckoApp.mAppContext);
-        GeckoAppShell.unregisterGeckoEventListener("Tab:Select", GeckoApp.mAppContext);
-        GeckoAppShell.unregisterGeckoEventListener("Tab:ScreenshotData", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Menu:Add", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Menu:Remove", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Gecko:Ready", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Toast:Show", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("ToggleChrome:Hide", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("ToggleChrome:Show", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("FormAssist:AutoComplete", GeckoApp.mAppContext);
--- a/mobile/android/base/Tabs.java
+++ b/mobile/android/base/Tabs.java
@@ -40,16 +40,18 @@ package org.mozilla.gecko;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 
 import android.content.ContentResolver;
+import android.os.SystemClock;
+import android.util.Base64;
 import android.util.Log;
 
 public class Tabs implements GeckoEventListener {
     private static final String LOGTAG = "GeckoTabs";
 
     private Tab selectedTab;
     private HashMap<Integer, Tab> tabs;
     private ArrayList<Tab> order;
@@ -58,16 +60,20 @@ public class Tabs implements GeckoEventL
     private Tabs() {
         tabs = new HashMap<Integer, Tab>();
         order = new ArrayList<Tab>();
         GeckoAppShell.registerGeckoEventListener("SessionHistory:New", this);
         GeckoAppShell.registerGeckoEventListener("SessionHistory:Back", this);
         GeckoAppShell.registerGeckoEventListener("SessionHistory:Forward", this);
         GeckoAppShell.registerGeckoEventListener("SessionHistory:Goto", this);
         GeckoAppShell.registerGeckoEventListener("SessionHistory:Purge", this);
+        GeckoAppShell.registerGeckoEventListener("Tab:Added", this);
+        GeckoAppShell.registerGeckoEventListener("Tab:Close", this);
+        GeckoAppShell.registerGeckoEventListener("Tab:Select", this);
+        GeckoAppShell.registerGeckoEventListener("Tab:ScreenshotData", this);
     }
 
     public int getCount() {
         return tabs.size();
     }
 
     public Tab addTab(JSONObject params) throws JSONException {
         int id = params.getInt("tabID");
@@ -248,23 +254,38 @@ public class Tabs implements GeckoEventL
 
     public static Tabs getInstance() {
        return Tabs.TabsInstanceHolder.INSTANCE;
     }
 
     // GeckoEventListener implementation
 
     public void handleMessage(String event, JSONObject message) {
+        Log.i(LOGTAG, "Got message: " + event);
         try {
             if (event.startsWith("SessionHistory:")) {
                 Tab tab = getTab(message.getInt("tabID"));
                 if (tab != null) {
                     event = event.substring("SessionHistory:".length());
                     tab.handleSessionHistoryMessage(event, message);
                 }
+            } else if (event.equals("Tab:Added")) {
+                Log.i(LOGTAG, "Received message from Gecko: " + SystemClock.uptimeMillis() + " - Tab:Added");
+                Tab tab = addTab(message);
+                if (message.getBoolean("selected"))
+                    selectTab(tab.getId());
+            } else if (event.equals("Tab:Close")) {
+                Tab tab = getTab(message.getInt("tabID"));
+                closeTab(tab);
+            } else if (event.equals("Tab:Select")) {
+                selectTab(message.getInt("tabID"));
+            } else if (event.equals("Tab:ScreenshotData")) {
+                Tab tab = getTab(message.getInt("tabID"));
+                byte[] compressed = Base64.decode(message.getString("data").substring(22), Base64.DEFAULT);
+                GeckoApp.mAppContext.processThumbnail(tab, null, compressed);
             }
         } catch (Exception e) { 
             Log.i(LOGTAG, "handleMessage throws " + e + " for message: " + event);
         }
     }
 
     public void refreshThumbnails() {
         Iterator<Tab> iterator = tabs.values().iterator();