Bug 842883 - (Part 1) Start moving some tab-specific event listeners to Tabs. r=bnicholson
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Sun, 24 Feb 2013 20:51:04 -0800
changeset 122876 e9438169e05035db0c537f6a64872d8f6276e48b
parent 122875 924c07c3cb32d4120380fafec06c1873322e1a63
child 122877 1e3df7da1d11cbe6f52bf9447b8847dc46f5f870
push id1387
push userphilringnalda@gmail.com
push dateTue, 26 Feb 2013 22:32:56 +0000
treeherderfx-team@ad4cc4e97774 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs842883
milestone22.0a1
Bug 842883 - (Part 1) Start moving some tab-specific event listeners to Tabs. r=bnicholson
mobile/android/base/BrowserApp.java
mobile/android/base/GeckoApp.java
mobile/android/base/Tabs.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -118,16 +118,19 @@ abstract public class BrowserApp extends
             case LOAD_ERROR:
             case START:
             case STOP:
             case MENU_UPDATED:
                 if (Tabs.getInstance().isSelectedTab(tab)) {
                     invalidateOptionsMenu();
                 }
                 break;
+            case LINK_ADDED:
+                handleLinkAdded(tab);
+                break;
         }
         super.onTabChanged(tab, msg, data);
     }
 
     @Override
     void handlePageShow(final int tabId) {
         super.handlePageShow(tabId);
         final Tab tab = Tabs.getInstance().getTab(tabId);
@@ -136,26 +139,17 @@ abstract public class BrowserApp extends
 
         mMainHandler.post(new Runnable() {
             public void run() {
                 loadFavicon(tab);
             }
         });
     }
 
-    @Override
-    void handleLinkAdded(final int tabId, String rel, final String href, int size) {
-        super.handleLinkAdded(tabId, rel, href, size);
-        if (rel.indexOf("[icon]") == -1)
-            return;
-
-        final Tab tab = Tabs.getInstance().getTab(tabId);
-        if (tab == null)
-            return;
-
+    void handleLinkAdded(final Tab tab) {
         // If tab is not loading and the favicon is updated, we
         // want to load the image straight away. If tab is still
         // loading, we only load the favicon once the page's content
         // is fully loaded (see handleContentLoaded()).
         if (tab.getState() != Tab.STATE_LOADING) {
             mMainHandler.post(new Runnable() {
                 public void run() {
                     loadFavicon(tab);
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -771,29 +771,16 @@ abstract public class GeckoApp
                 }
 
                 // Sync up the layer view and the tab if the tab is
                 // currently displayed.
                 LayerView layerView = mLayerView;
                 if (layerView != null && Tabs.getInstance().isSelectedTab(tab)) {
                     layerView.setBackgroundColor(tab.getBackgroundColor());
                 }
-            } else if (event.equals("DOMTitleChanged")) {
-                final int tabId = message.getInt("tabID");
-                final String title = message.getString("title");
-                handleTitleChanged(tabId, title);
-            } else if (event.equals("DOMLinkAdded")) {
-                final int tabId = message.getInt("tabID");
-                final String rel = message.getString("rel");
-                final String href = message.getString("href");
-                final int size = message.getInt("size");
-                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.d(LOGTAG, "Log: " + msg);
             } 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"));
@@ -1097,41 +1084,16 @@ abstract public class GeckoApp
     void handleContentLoaded(int tabId) {
         final Tab tab = Tabs.getInstance().getTab(tabId);
         if (tab == null)
             return;
 
         Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.LOADED);
     }
 
-    void handleTitleChanged(int tabId, String title) {
-        final Tab tab = Tabs.getInstance().getTab(tabId);
-        if (tab == null)
-            return;
-
-        tab.updateTitle(title);
-    }
-
-    void handleLinkAdded(final int tabId, String rel, final String href, int size) {
-        if (rel.indexOf("[icon]") == -1)
-            return; 
-
-        final Tab tab = Tabs.getInstance().getTab(tabId);
-        if (tab == null)
-            return;
-
-        tab.updateFaviconURL(href, size);
-    }
-
-    void handleWindowClose(final int tabId) {
-        Tabs tabs = Tabs.getInstance();
-        Tab tab = tabs.getTab(tabId);
-        tabs.closeTab(tab);
-    }
-
     private void addFullScreenPluginView(View view) {
         if (mFullScreenPluginView != null) {
             Log.w(LOGTAG, "Already have a fullscreen plugin view");
             return;
         }
 
         setFullScreen(true);
 
@@ -1761,19 +1723,16 @@ abstract public class GeckoApp
                     GeckoThread.setLaunchState(GeckoThread.LaunchState.Launching);
                     sGeckoThread.start();
                 }
             }, 1000 * 5 /* 5 seconds */);
         }
 
         //register for events
         registerEventListener("DOMContentLoaded");
-        registerEventListener("DOMTitleChanged");
-        registerEventListener("DOMLinkAdded");
-        registerEventListener("DOMWindowClose");
         registerEventListener("log");
         registerEventListener("Content:SecurityChange");
         registerEventListener("Content:ReaderEnabled");
         registerEventListener("Content:StateChange");
         registerEventListener("Content:LoadError");
         registerEventListener("Content:PageShow");
         registerEventListener("Reader:FaviconRequest");
         registerEventListener("Reader:GoToReadingList");
@@ -2162,19 +2121,16 @@ abstract public class GeckoApp
     public void onDestroy()
     {
         // Tell Gecko to shutting down; we'll end up calling System.exit()
         // in onXreExit.
         if (isFinishing())
             GeckoAppShell.sendEventToGecko(GeckoEvent.createShutdownEvent());
 
         unregisterEventListener("DOMContentLoaded");
-        unregisterEventListener("DOMTitleChanged");
-        unregisterEventListener("DOMLinkAdded");
-        unregisterEventListener("DOMWindowClose");
         unregisterEventListener("log");
         unregisterEventListener("Content:SecurityChange");
         unregisterEventListener("Content:ReaderEnabled");
         unregisterEventListener("Content:StateChange");
         unregisterEventListener("Content:LoadError");
         unregisterEventListener("Content:PageShow");
         unregisterEventListener("Reader:FaviconRequest");
         unregisterEventListener("Reader:GoToReadingList");
--- a/mobile/android/base/Tabs.java
+++ b/mobile/android/base/Tabs.java
@@ -67,16 +67,19 @@ public class Tabs implements GeckoEventL
         registerEventListener("Tab:Added");
         registerEventListener("Tab:Close");
         registerEventListener("Tab:Select");
         registerEventListener("Content:LocationChange");
         registerEventListener("Session:RestoreEnd");
         registerEventListener("Reader:Added");
         registerEventListener("Reader:Removed");
         registerEventListener("Reader:Share");
+        registerEventListener("DOMTitleChanged");
+        registerEventListener("DOMLinkAdded");
+        registerEventListener("DOMWindowClose");
     }
 
     public void attachToActivity(GeckoApp activity) {
         mActivity = activity;
         mAccountManager = AccountManager.get(mActivity);
 
         // The listener will run on the background thread (see 2nd argument)
         mAccountManager.addOnAccountsUpdatedListener(mAccountListener = new OnAccountsUpdateListener() {
@@ -328,16 +331,30 @@ public class Tabs implements GeckoEventL
                 final String url = message.getString("url");
                 handleReaderRemoved(url);
             } else if (event.equals("Reader:Share")) {
                 final String title = message.getString("title");
                 final String url = message.getString("url");
 
                 GeckoAppShell.openUriExternal(url, "text/plain", "", "",
                                               Intent.ACTION_SEND, title);
+            } else if (event.equals("DOMTitleChanged")) {
+                Tab tab = getTab(message.getInt("tabID"));
+                if (tab != null) {
+                    tab.updateTitle(message.getString("title"));
+                }
+            } else if (event.equals("DOMLinkAdded")) {
+                Tab tab = getTab(message.getInt("tabID"));
+                if (tab != null) {
+                    tab.updateFaviconURL(message.getString("href"), message.getInt("size"));
+                    notifyListeners(tab, TabEvents.LINK_ADDED);
+                }
+            } else if (event.equals("DOMWindowClose")) {
+                Tab tab = getTab(message.getInt("tabID"));
+                closeTab(tab);
             }
         } catch (Exception e) { 
             Log.w(LOGTAG, "handleMessage threw for " + event, e);
         }
     }
 
     void handleReaderAdded(boolean success, final String title, final String url) {
         if (!success) {
@@ -404,17 +421,18 @@ public class Tabs implements GeckoEventL
         FAVICON,
         THUMBNAIL,
         TITLE,
         SELECTED,
         UNSELECTED,
         ADDED,
         RESTORED,
         LOCATION_CHANGE,
-        MENU_UPDATED
+        MENU_UPDATED,
+        LINK_ADDED
     }
 
     public void notifyListeners(Tab tab, TabEvents msg) {
         notifyListeners(tab, msg, "");
     }
 
     public void notifyListeners(final Tab tab, final TabEvents msg, final Object data) {
         mActivity.runOnUiThread(new Runnable() {
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3445,16 +3445,20 @@ Tab.prototype = {
           list = target.rel.toLowerCase().split(/\s+/);
           let hash = {};
           list.forEach(function(value) { hash[value] = true; });
           list = [];
           for (let rel in hash)
             list.push("[" + rel + "]");
         }
 
+        // We only care about icon links
+        if (list.indexOf("[icon]") == -1)
+          return;
+
         // We want to get the largest icon size possible for our UI.
         let maxSize = 0;
 
         // We use the sizes attribute if available
         // see http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon
         if (target.hasAttribute("sizes")) {
           let sizes = target.getAttribute("sizes").toLowerCase();