mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-29 21:25:35 +00:00
Bug 804434 - Make Tabs.notifyListeners() run on UI thread. r=mfinkle
This commit is contained in:
parent
175d3a0187
commit
f3c21052fd
@ -806,11 +806,7 @@ abstract public class GeckoApp
|
||||
return;
|
||||
|
||||
// When a load error occurs, the URLBar can get corrupt so we reset it
|
||||
mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.LOAD_ERROR);
|
||||
}
|
||||
});
|
||||
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.LOAD_ERROR);
|
||||
}
|
||||
|
||||
void handlePageShow(final int tabId) { }
|
||||
@ -1187,11 +1183,7 @@ abstract public class GeckoApp
|
||||
tab.setReaderEnabled(false);
|
||||
if (Tabs.getInstance().isSelectedTab(tab))
|
||||
mLayerView.getRenderer().resetCheckerboard();
|
||||
mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.START, showProgress);
|
||||
}
|
||||
});
|
||||
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.START, showProgress);
|
||||
}
|
||||
|
||||
void handleDocumentStop(int tabId, boolean success) {
|
||||
@ -1201,11 +1193,7 @@ abstract public class GeckoApp
|
||||
|
||||
tab.setState(success ? Tab.STATE_SUCCESS : Tab.STATE_ERROR);
|
||||
|
||||
mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.STOP);
|
||||
}
|
||||
});
|
||||
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.STOP);
|
||||
|
||||
final String oldURL = tab.getURL();
|
||||
GeckoAppShell.getHandler().postDelayed(new Runnable() {
|
||||
@ -1250,11 +1238,7 @@ abstract public class GeckoApp
|
||||
if (tab == null)
|
||||
return;
|
||||
|
||||
mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.LOADED);
|
||||
}
|
||||
});
|
||||
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.LOADED);
|
||||
}
|
||||
|
||||
void handleTitleChanged(int tabId, String title) {
|
||||
|
@ -99,7 +99,7 @@ public class Tab {
|
||||
mPluginLayers = new HashMap<Object, Layer>();
|
||||
mState = GeckoApp.shouldShowProgress(url) ? STATE_SUCCESS : STATE_LOADING;
|
||||
mContentResolver = Tabs.getInstance().getContentResolver();
|
||||
mContentObserver = new ContentObserver(GeckoAppShell.getHandler()) {
|
||||
mContentObserver = new ContentObserver(null) {
|
||||
public void onChange(boolean selfChange) {
|
||||
updateBookmark();
|
||||
}
|
||||
@ -109,6 +109,7 @@ public class Tab {
|
||||
|
||||
public void onDestroy() {
|
||||
BrowserDB.unregisterContentObserver(mContentResolver, mContentObserver);
|
||||
Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.CLOSED);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
@ -175,7 +176,6 @@ public class Tab {
|
||||
}
|
||||
|
||||
public void updateThumbnail(final Bitmap b) {
|
||||
final Tab tab = this;
|
||||
GeckoAppShell.getHandler().post(new Runnable() {
|
||||
public void run() {
|
||||
if (b != null) {
|
||||
@ -190,11 +190,8 @@ public class Tab {
|
||||
} else {
|
||||
mThumbnail = null;
|
||||
}
|
||||
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.THUMBNAIL);
|
||||
}
|
||||
});
|
||||
|
||||
Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.THUMBNAIL);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -265,13 +262,7 @@ public class Tab {
|
||||
|
||||
Log.d(LOGTAG, "Updated title for tab with id: " + mId);
|
||||
updateHistory(mUrl, mTitle);
|
||||
final Tab tab = this;
|
||||
|
||||
GeckoAppShell.getMainHandler().post(new Runnable() {
|
||||
public void run() {
|
||||
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.TITLE);
|
||||
}
|
||||
});
|
||||
Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.TITLE);
|
||||
}
|
||||
|
||||
protected void addHistory(final String uri) {
|
||||
@ -360,33 +351,24 @@ public class Tab {
|
||||
|
||||
public void setReaderEnabled(boolean readerEnabled) {
|
||||
mReaderEnabled = readerEnabled;
|
||||
GeckoAppShell.getMainHandler().post(new Runnable() {
|
||||
public void run() {
|
||||
Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.MENU_UPDATED);
|
||||
}
|
||||
});
|
||||
Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.MENU_UPDATED);
|
||||
}
|
||||
|
||||
private void updateBookmark() {
|
||||
final String url = getURL();
|
||||
if (url == null)
|
||||
return;
|
||||
GeckoAppShell.getHandler().post(new Runnable() {
|
||||
public void run() {
|
||||
final String url = getURL();
|
||||
if (url == null)
|
||||
return;
|
||||
|
||||
(new GeckoAsyncTask<Void, Void, Void>(GeckoApp.mAppContext, GeckoAppShell.getHandler()) {
|
||||
@Override
|
||||
public Void doInBackground(Void... params) {
|
||||
if (url.equals(getURL())) {
|
||||
mBookmark = BrowserDB.isBookmark(mContentResolver, url);
|
||||
mReadingListItem = BrowserDB.isReadingListItem(mContentResolver, url);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostExecute(Void result) {
|
||||
Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.MENU_UPDATED);
|
||||
}
|
||||
}).execute();
|
||||
});
|
||||
}
|
||||
|
||||
public void addBookmark() {
|
||||
@ -421,28 +403,6 @@ public class Tab {
|
||||
GeckoAppShell.sendEventToGecko(e);
|
||||
}
|
||||
|
||||
public void removeFromReadingList() {
|
||||
if (!mReaderEnabled)
|
||||
return;
|
||||
|
||||
GeckoAppShell.getHandler().post(new Runnable() {
|
||||
public void run() {
|
||||
String url = getURL();
|
||||
if (url == null)
|
||||
return;
|
||||
|
||||
BrowserDB.removeReadingListItemWithURL(mContentResolver, url);
|
||||
|
||||
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Remove", getURL());
|
||||
GeckoAppShell.sendEventToGecko(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void readerMode() {
|
||||
if (!mReaderEnabled)
|
||||
return;
|
||||
@ -555,11 +515,7 @@ public class Tab {
|
||||
setHasTouchListeners(false);
|
||||
setCheckerboardColor(Color.WHITE);
|
||||
|
||||
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.LOCATION_CHANGE, uri);
|
||||
}
|
||||
});
|
||||
Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.LOCATION_CHANGE, uri);
|
||||
}
|
||||
|
||||
protected void saveThumbnailToDB() {
|
||||
|
@ -101,11 +101,7 @@ public class Tabs implements GeckoEventListener {
|
||||
mOrder.add(tab);
|
||||
|
||||
if (!mRestoringSession) {
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
notifyListeners(tab, TabEvents.ADDED);
|
||||
}
|
||||
});
|
||||
notifyListeners(tab, TabEvents.ADDED);
|
||||
}
|
||||
|
||||
Log.i(LOGTAG, "Added a tab with id: " + id);
|
||||
@ -199,12 +195,7 @@ public class Tabs implements GeckoEventListener {
|
||||
int tabId = tab.getId();
|
||||
removeTab(tabId);
|
||||
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
notifyListeners(tab, TabEvents.CLOSED);
|
||||
tab.onDestroy();
|
||||
}
|
||||
});
|
||||
tab.onDestroy();
|
||||
|
||||
// Pass a message to Gecko to update tab state in BrowserApp
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Closed", String.valueOf(tabId)));
|
||||
@ -297,11 +288,7 @@ public class Tabs implements GeckoEventListener {
|
||||
mRestoringSession = true;
|
||||
} else if (event.equals("Session:RestoreEnd")) {
|
||||
mRestoringSession = false;
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
notifyListeners(null, TabEvents.RESTORED);
|
||||
}
|
||||
});
|
||||
notifyListeners(null, TabEvents.RESTORED);
|
||||
} else if (event.equals("Reader:Added")) {
|
||||
final boolean success = message.getBoolean("success");
|
||||
final String title = message.getString("title");
|
||||
@ -398,16 +385,20 @@ public class Tabs implements GeckoEventListener {
|
||||
notifyListeners(tab, msg, "");
|
||||
}
|
||||
|
||||
public void notifyListeners(Tab tab, TabEvents msg, Object data) {
|
||||
onTabChanged(tab, msg, data);
|
||||
public void notifyListeners(final Tab tab, final TabEvents msg, final Object data) {
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
onTabChanged(tab, msg, data);
|
||||
|
||||
if (mTabsChangedListeners == null)
|
||||
return;
|
||||
if (mTabsChangedListeners == null)
|
||||
return;
|
||||
|
||||
Iterator<OnTabsChangedListener> items = mTabsChangedListeners.iterator();
|
||||
while (items.hasNext()) {
|
||||
items.next().onTabChanged(tab, msg, data);
|
||||
}
|
||||
Iterator<OnTabsChangedListener> items = mTabsChangedListeners.iterator();
|
||||
while (items.hasNext()) {
|
||||
items.next().onTabChanged(tab, msg, data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
|
||||
|
Loading…
Reference in New Issue
Block a user