Bug 697087 - Multiple notifications content permission prompt. r=mfinkle

This commit is contained in:
Gian-Carlo Pascutto 2011-11-01 21:26:11 +01:00
parent 361d2bc716
commit b5930981e8
5 changed files with 28 additions and 8 deletions

View File

@ -56,8 +56,17 @@ public class DoorHanger {
mPopups = new ArrayList<DoorHangerPopup>();
}
public DoorHangerPopup getPopup() {
final DoorHangerPopup dhp = new DoorHangerPopup(mContext);
public DoorHangerPopup getPopup(String value) {
// Check for duplicate popups
for (DoorHangerPopup dhp : mPopups) {
if (dhp.getValue().equals(value)) {
// Replace it
dhp = new DoorHangerPopup(mContext, value);
return dhp;
}
}
// No known popup like that, make new one
final DoorHangerPopup dhp = new DoorHangerPopup(mContext, value);
mPopups.add(dhp);
return dhp;
}

View File

@ -57,11 +57,14 @@ public class DoorHangerPopup extends PopupWindow {
private LayoutParams mLayoutParams;
private View popupView;
public int mTabId;
// value used to identify the notification
private String mValue;
private final int POPUP_VERTICAL_SIZE = 100;
public DoorHangerPopup(Context aContext) {
public DoorHangerPopup(Context aContext, String aValue) {
super(aContext);
mContext = aContext;
mValue = aValue;
LayoutInflater inflater =
(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@ -91,6 +94,10 @@ public class DoorHangerPopup extends PopupWindow {
mChoicesLayout.addView(mButton, mLayoutParams);
}
public String getValue() {
return mValue;
}
public void setText(String aText) {
mTextView.setText(aText);
}

View File

@ -779,6 +779,7 @@ abstract public class GeckoApp
void handleDoorHanger(JSONObject geckoObject, final int tabId) throws JSONException {
final String msg = geckoObject.getString("message");
final String value = geckoObject.getString("value");
Log.i(LOG_NAME, "DoorHanger received for tab " + tabId
+ ", msg:" + msg);
final JSONArray buttons = geckoObject.getJSONArray("buttons");
@ -786,7 +787,7 @@ abstract public class GeckoApp
mMainHandler.post(new Runnable() {
public void run() {
DoorHangerPopup dhp =
mAppContext.mDoorHanger.getPopup();
mAppContext.mDoorHanger.getPopup(value);
dhp.setTab(tabId);
for (int i = 0; i < buttons.length(); i++) {
JSONObject jo;

View File

@ -584,7 +584,7 @@ var NativeWindow = {
_callbacks: {},
_callbacksId: 0,
_promptId: 0,
show: function(aMessage, aButtons, aTab) {
show: function(aMessage, aValue, aButtons, aTab) {
// use the current tab if none is provided
let tabID = aTab ? aTab : BrowserApp.selectedTab.id;
aButtons.forEach((function(aButton) {
@ -600,7 +600,8 @@ var NativeWindow = {
message: aMessage,
severity: "PRIORITY_WARNING_MEDIUM",
buttons: aButtons,
tabID: tabID
tabID: tabID,
value: aValue
}
};
sendMessageToJava(json);
@ -1735,7 +1736,7 @@ var XPInstallObserver = {
}
}];
}
NativeWindow.doorhanger.show(messageString, buttons);
NativeWindow.doorhanger.show(messageString, aTopic, buttons);
break;
}
}

View File

@ -160,7 +160,9 @@ ContentPermissionPrompt.prototype = {
let message = browserBundle.formatStringFromName(entityName + ".wantsTo",
[request.uri.host], 1);
chromeWin.NativeWindow.doorhanger.show(message, buttons, tabID);
chromeWin.NativeWindow.doorhanger.show(message,
entityName + request.uri.host,
buttons, tabID);
}
};