Bug 842883 - (Part 1) Start moving some tab-specific event listeners to Tabs. r=bnicholson

This commit is contained in:
Margaret Leibovic 2013-02-24 20:51:04 -08:00
parent 76e46f4140
commit 7b92d63fba
4 changed files with 27 additions and 55 deletions

View File

@ -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

View File

@ -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");

View File

@ -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) {

View File

@ -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;