From 7b92d63fba9831ebfe07f3d826b2f66bf19f0bcf Mon Sep 17 00:00:00 2001 From: Margaret Leibovic Date: Sun, 24 Feb 2013 20:51:04 -0800 Subject: [PATCH] Bug 842883 - (Part 1) Start moving some tab-specific event listeners to Tabs. r=bnicholson --- mobile/android/base/BrowserApp.java | 14 +++----- mobile/android/base/GeckoApp.java | 44 ------------------------ mobile/android/base/Tabs.java | 20 ++++++++++- mobile/android/chrome/content/browser.js | 4 +++ 4 files changed, 27 insertions(+), 55 deletions(-) diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 20da97ca058..c6878867075 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -123,6 +123,9 @@ abstract public class BrowserApp extends GeckoApp invalidateOptionsMenu(); } break; + case LINK_ADDED: + handleLinkAdded(tab); + break; } super.onTabChanged(tab, msg, data); } @@ -141,16 +144,7 @@ abstract public class BrowserApp extends GeckoApp }); } - @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 diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index 7249416d3c0..9fd6d6cab62 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -776,19 +776,6 @@ abstract public class GeckoApp 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"); @@ -1102,31 +1089,6 @@ abstract public class GeckoApp 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"); @@ -1766,9 +1728,6 @@ abstract public class GeckoApp //register for events registerEventListener("DOMContentLoaded"); - registerEventListener("DOMTitleChanged"); - registerEventListener("DOMLinkAdded"); - registerEventListener("DOMWindowClose"); registerEventListener("log"); registerEventListener("Content:SecurityChange"); registerEventListener("Content:ReaderEnabled"); @@ -2167,9 +2126,6 @@ abstract public class GeckoApp GeckoAppShell.sendEventToGecko(GeckoEvent.createShutdownEvent()); unregisterEventListener("DOMContentLoaded"); - unregisterEventListener("DOMTitleChanged"); - unregisterEventListener("DOMLinkAdded"); - unregisterEventListener("DOMWindowClose"); unregisterEventListener("log"); unregisterEventListener("Content:SecurityChange"); unregisterEventListener("Content:ReaderEnabled"); diff --git a/mobile/android/base/Tabs.java b/mobile/android/base/Tabs.java index b20211b1fa7..8e4499b0945 100644 --- a/mobile/android/base/Tabs.java +++ b/mobile/android/base/Tabs.java @@ -72,6 +72,9 @@ public class Tabs implements GeckoEventListener { registerEventListener("Reader:Added"); registerEventListener("Reader:Removed"); registerEventListener("Reader:Share"); + registerEventListener("DOMTitleChanged"); + registerEventListener("DOMLinkAdded"); + registerEventListener("DOMWindowClose"); } public void attachToActivity(GeckoApp activity) { @@ -333,6 +336,20 @@ public class Tabs implements GeckoEventListener { 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); @@ -409,7 +426,8 @@ public class Tabs implements GeckoEventListener { ADDED, RESTORED, LOCATION_CHANGE, - MENU_UPDATED + MENU_UPDATED, + LINK_ADDED } public void notifyListeners(Tab tab, TabEvents msg) { diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 95174800e13..30d884569d5 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -3450,6 +3450,10 @@ Tab.prototype = { 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;