Bug 781883 - Move the Content:LocationChange handler into Tabs.java so that we don't miss the event when GeckoApp is torn down and recreated. r=sriram
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 27 Aug 2012 16:44:51 -0400
changeset 105656 12504471edefed3247487d780860893ae84224db
parent 105655 3f301dd62fb244821a2a04fe9f9280d675ad5cd6
child 105657 c7e7eb166dd9ac82b7ecf7b6892eac4fcac43d5c
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewerssriram
bugs781883
milestone18.0a1
Bug 781883 - Move the Content:LocationChange handler into Tabs.java so that we don't miss the event when GeckoApp is torn down and recreated. r=sriram
mobile/android/base/GeckoApp.java
mobile/android/base/Tab.java
mobile/android/base/Tabs.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -664,46 +664,16 @@ abstract public class GeckoApp
         return (Tabs.getInstance().isSelectedTab(tab) || areTabsShown());
     }
 
     public void hideFormAssistPopup() {
         if (mFormAssistPopup != null)
             mFormAssistPopup.hide();
     }
 
-    void handleLocationChange(final int tabId, final String uri,
-                              final String documentURI, final String contentType,
-                              final boolean sameDocument) {
-        final Tab tab = Tabs.getInstance().getTab(tabId);
-        if (tab == null)
-            return;
-
-        tab.updateURL(uri);
-        tab.setDocumentURI(documentURI);
-
-        // We can get a location change event for the same document with an anchor tag
-        if (sameDocument)
-            return;
-
-        tab.setContentType(contentType);
-        tab.clearFavicon();
-        tab.updateTitle(null);
-        tab.updateIdentityData(null);
-        tab.setReaderEnabled(false);
-        tab.setZoomConstraints(new ZoomConstraints(true));
-        tab.setHasTouchListeners(false);
-        tab.setCheckerboardColor(Color.WHITE);
-
-        mMainHandler.post(new Runnable() {
-            public void run() {
-                Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.LOCATION_CHANGE, uri);
-            }
-        });
-    }
-
     void handleSecurityChange(final int tabId, final JSONObject identityData) {
         final Tab tab = Tabs.getInstance().getTab(tabId);
         if (tab == null)
             return;
 
         tab.updateIdentityData(identityData);
     }
 
@@ -879,24 +849,16 @@ abstract public class GeckoApp
                 handleLinkAdded(tabId, rel, href, size);
             } else if (event.equals("DOMWindowClose")) {
                 final int tabId = message.getInt("tabID");
                 handleWindowClose(tabId);
             } else if (event.equals("log")) {
                 // generic log listener
                 final String msg = message.getString("msg");
                 Log.i(LOGTAG, "Log: " + msg);
-            } else if (event.equals("Content:LocationChange")) {
-                final int tabId = message.getInt("tabID");
-                final String uri = message.getString("uri");
-                final String documentURI = message.getString("documentURI");
-                final String contentType = message.getString("contentType");
-                final boolean sameDocument = message.getBoolean("sameDocument");
-                Log.i(LOGTAG, "URI - " + uri);
-                handleLocationChange(tabId, uri, documentURI, contentType, sameDocument);
             } else if (event.equals("Content:SecurityChange")) {
                 final int tabId = message.getInt("tabID");
                 final JSONObject identity = message.getJSONObject("identity");
                 Log.i(LOGTAG, "Security Mode - " + identity.getString("mode"));
                 handleSecurityChange(tabId, identity);
             } else if (event.equals("Content:ReaderEnabled")) {
                 final int tabId = message.getInt("tabID");
                 handleReaderEnabled(tabId);
@@ -1651,17 +1613,16 @@ abstract public class GeckoApp
         Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - UI almost up");
 
         //register for events
         registerEventListener("DOMContentLoaded");
         registerEventListener("DOMTitleChanged");
         registerEventListener("DOMLinkAdded");
         registerEventListener("DOMWindowClose");
         registerEventListener("log");
-        registerEventListener("Content:LocationChange");
         registerEventListener("Content:SecurityChange");
         registerEventListener("Content:ReaderEnabled");
         registerEventListener("Content:StateChange");
         registerEventListener("Content:LoadError");
         registerEventListener("Content:PageShow");
         registerEventListener("Reader:FaviconRequest");
         registerEventListener("Reader:GoToReadingList");
         registerEventListener("onCameraCapture");
@@ -2094,17 +2055,16 @@ abstract public class GeckoApp
         if (isFinishing())
             GeckoAppShell.sendEventToGecko(GeckoEvent.createShutdownEvent());
 
         unregisterEventListener("DOMContentLoaded");
         unregisterEventListener("DOMTitleChanged");
         unregisterEventListener("DOMLinkAdded");
         unregisterEventListener("DOMWindowClose");
         unregisterEventListener("log");
-        unregisterEventListener("Content:LocationChange");
         unregisterEventListener("Content:SecurityChange");
         unregisterEventListener("Content:ReaderEnabled");
         unregisterEventListener("Content:StateChange");
         unregisterEventListener("Content:LoadError");
         unregisterEventListener("Content:PageShow");
         unregisterEventListener("Reader:FaviconRequest");
         unregisterEventListener("Reader:GoToReadingList");
         unregisterEventListener("onCameraCapture");
--- a/mobile/android/base/Tab.java
+++ b/mobile/android/base/Tab.java
@@ -524,16 +524,42 @@ public final class Tab {
             mHistoryIndex -= numEntries;
 
             // If we weren't at the last history entry, mHistoryIndex may have become too small
             if (mHistoryIndex < -1)
                  mHistoryIndex = -1;
         }
     }
 
+    void handleLocationChange(JSONObject message) throws JSONException {
+        final String uri = message.getString("uri");
+        updateURL(uri);
+
+        setDocumentURI(message.getString("documentURI"));
+        if (message.getBoolean("sameDocument")) {
+            // We can get a location change event for the same document with an anchor tag
+            return;
+        }
+
+        setContentType(message.getString("contentType"));
+        clearFavicon();
+        updateTitle(null);
+        updateIdentityData(null);
+        setReaderEnabled(false);
+        setZoomConstraints(new ZoomConstraints(true));
+        setHasTouchListeners(false);
+        setCheckerboardColor(Color.WHITE);
+
+        GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
+            public void run() {
+                Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.LOCATION_CHANGE, uri);
+            }
+        });
+    }
+
     private void saveThumbnailToDB() {
         try {
             String url = getURL();
             if (url == null)
                 return;
 
             BrowserDB.updateThumbnailForUrl(mContentResolver, url, mThumbnail);
         } catch (Exception e) {
--- a/mobile/android/base/Tabs.java
+++ b/mobile/android/base/Tabs.java
@@ -44,16 +44,17 @@ public class Tabs implements GeckoEventL
         registerEventListener("SessionHistory:New");
         registerEventListener("SessionHistory:Back");
         registerEventListener("SessionHistory:Forward");
         registerEventListener("SessionHistory:Goto");
         registerEventListener("SessionHistory:Purge");
         registerEventListener("Tab:Added");
         registerEventListener("Tab:Close");
         registerEventListener("Tab:Select");
+        registerEventListener("Content:LocationChange");
         registerEventListener("Session:RestoreBegin");
         registerEventListener("Session:RestoreEnd");
         registerEventListener("Reader:Added");
         registerEventListener("Reader:Removed");
         registerEventListener("Reader:Share");
     }
 
     public void attachToActivity(GeckoApp activity) {
@@ -248,16 +249,21 @@ public class Tabs implements GeckoEventL
                     tab.setState(Tab.STATE_DELAYED);
                 if (message.getBoolean("desktopMode"))
                     tab.setDesktopMode(true);
             } 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("Content:LocationChange")) {
+                Tab tab = getTab(message.getInt("tabID"));
+                if (tab != null) {
+                    tab.handleLocationChange(message);
+                }
             } else if (event.equals("Session:RestoreBegin")) {
                 mRestoringSession = true;
             } else if (event.equals("Session:RestoreEnd")) {
                 mRestoringSession = false;
                 mActivity.runOnUiThread(new Runnable() {
                     public void run() {
                         notifyListeners(null, TabEvents.RESTORED);
                     }