Bug 778247: mAppContext cleanup: Tabs can avoid it. [r=mbrubeck]

--HG--
extra : rebase_source : 1a5ed5ec5dbfdd72c81877196e3a3f10764e3d07
This commit is contained in:
Sriram Ramasubramanian 2012-07-27 23:31:54 -07:00
parent 3a6da0ed38
commit 5bc1a73c63
3 changed files with 35 additions and 27 deletions

View File

@ -98,9 +98,9 @@ abstract public class GeckoApp
private Favicons mFavicons;
private TextSelection mTextSelection;
public DoorHangerPopup mDoorHangerPopup;
public FormAssistPopup mFormAssistPopup;
public TabsPanel mTabsPanel;
protected DoorHangerPopup mDoorHangerPopup;
protected FormAssistPopup mFormAssistPopup;
protected TabsPanel mTabsPanel;
private LayerController mLayerController;
private GeckoLayerClient mLayerClient;
@ -561,7 +561,7 @@ abstract public class GeckoApp
return metrics;
}
void getAndProcessThumbnailForTab(final Tab tab) {
public void getAndProcessThumbnailForTab(final Tab tab) {
boolean isSelectedTab = Tabs.getInstance().isSelectedTab(tab);
final Bitmap bitmap = isSelectedTab ? mLayerClient.getBitmap() : null;
@ -618,6 +618,11 @@ abstract public class GeckoApp
return (Tabs.getInstance().isSelectedTab(tab) || areTabsShown());
}
public void hideFormAssistPopup() {
if (mFormAssistPopup != null)
mFormAssistPopup.hide();
}
void updatePopups(final Tab tab) {
mDoorHangerPopup.updatePopup();
}
@ -1253,6 +1258,14 @@ abstract public class GeckoApp
}, 500);
}
public void showToast(final int resId, final int duration) {
mMainHandler.post(new Runnable() {
public void run() {
Toast.makeText(mAppContext, resId, duration);
}
});
}
void handleShowToast(final String message, final String duration) {
mMainHandler.post(new Runnable() {
public void run() {
@ -1503,6 +1516,7 @@ abstract public class GeckoApp
GeckoAppShell.registerGlobalExceptionHandler();
mAppContext = this;
Tabs.getInstance().attachToActivity(this);
// Check to see if the activity is restarted after configuration change.
if (getLastNonConfigurationInstance() != null) {

View File

@ -29,6 +29,8 @@ public class Tabs implements GeckoEventListener {
private ContentResolver mResolver;
private boolean mRestoringSession;
private GeckoApp mActivity;
private Tabs() {
mTabs = new HashMap<Integer, Tab>();
mOrder = new ArrayList<Tab>();
@ -46,6 +48,10 @@ public class Tabs implements GeckoEventListener {
GeckoAppShell.registerGeckoEventListener("Reader:Share", this);
}
public void attachToActivity(GeckoApp activity) {
mActivity = activity;
}
public int getCount() {
return mTabs.size();
}
@ -66,7 +72,7 @@ public class Tabs implements GeckoEventListener {
mOrder.add(tab);
if (!mRestoringSession) {
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
mActivity.runOnUiThread(new Runnable() {
public void run() {
notifyListeners(tab, TabEvents.ADDED);
}
@ -99,10 +105,9 @@ public class Tabs implements GeckoEventListener {
return null;
mSelectedTab = tab;
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
mActivity.runOnUiThread(new Runnable() {
public void run() {
if (GeckoApp.mAppContext.mFormAssistPopup != null)
GeckoApp.mAppContext.mFormAssistPopup.hide();
mActivity.hideFormAssistPopup();
if (isSelectedTab(tab)) {
String url = tab.getURL();
notifyListeners(tab, TabEvents.SELECTED);
@ -165,7 +170,7 @@ public class Tabs implements GeckoEventListener {
int tabId = tab.getId();
removeTab(tabId);
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
mActivity.runOnUiThread(new Runnable() {
public void run() {
notifyListeners(tab, TabEvents.CLOSED);
tab.onDestroy();
@ -258,7 +263,7 @@ public class Tabs implements GeckoEventListener {
mRestoringSession = true;
} else if (event.equals("Session:RestoreEnd")) {
mRestoringSession = false;
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
mActivity.runOnUiThread(new Runnable() {
public void run() {
notifyListeners(null, TabEvents.RESTORED);
}
@ -282,25 +287,14 @@ public class Tabs implements GeckoEventListener {
void handleReaderAdded(boolean success, final String title, final String url) {
if (!success) {
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() {
Toast.makeText(GeckoApp.mAppContext,
R.string.reading_list_failed, Toast.LENGTH_SHORT).show();
}
});
mActivity.showToast(R.string.reading_list_failed, Toast.LENGTH_SHORT);
return;
}
GeckoAppShell.getHandler().post(new Runnable() {
public void run() {
BrowserDB.addReadingListItem(GeckoApp.mAppContext.getContentResolver(), title, url);
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() {
Toast.makeText(GeckoApp.mAppContext,
R.string.reading_list_added, Toast.LENGTH_SHORT).show();
}
});
BrowserDB.addReadingListItem(mActivity.getContentResolver(), title, url);
mActivity.showToast(R.string.reading_list_added, Toast.LENGTH_SHORT);
}
});
}
@ -311,7 +305,7 @@ public class Tabs implements GeckoEventListener {
final Tab tab = iterator.next();
GeckoAppShell.getHandler().post(new Runnable() {
public void run() {
GeckoApp.mAppContext.getAndProcessThumbnailForTab(tab);
mActivity.getAndProcessThumbnailForTab(tab);
}
});
}

View File

@ -73,8 +73,8 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback {
requestFocus();
/** We need to manually hide FormAssistPopup because it is not a regular PopupWindow. */
if (GeckoApp.mAppContext != null && GeckoApp.mAppContext.mFormAssistPopup != null)
GeckoApp.mAppContext.mFormAssistPopup.hide();
if (GeckoApp.mAppContext != null)
GeckoApp.mAppContext.hideFormAssistPopup();
return mTouchEventHandler.handleEvent(event);
}