mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1088220 - Switch to using DoorhangerConfig. r=margaret
This commit is contained in:
parent
4de91f73a1
commit
45d4382eea
@ -16,13 +16,13 @@ import org.mozilla.gecko.prompts.PromptInput;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.widget.AnchoredPopup;
|
||||
import org.mozilla.gecko.widget.DefaultDoorHanger;
|
||||
import org.mozilla.gecko.widget.DoorHanger;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import org.mozilla.gecko.widget.DoorhangerConfig;
|
||||
|
||||
public class DoorHangerPopup extends AnchoredPopup
|
||||
implements GeckoEventListener,
|
||||
@ -77,16 +77,12 @@ public class DoorHangerPopup extends AnchoredPopup
|
||||
public void handleMessage(String event, JSONObject geckoObject) {
|
||||
try {
|
||||
if (event.equals("Doorhanger:Add")) {
|
||||
final int tabId = geckoObject.getInt("tabID");
|
||||
final String value = geckoObject.getString("value");
|
||||
final String message = geckoObject.getString("message");
|
||||
final JSONArray buttons = geckoObject.getJSONArray("buttons");
|
||||
final JSONObject options = geckoObject.getJSONObject("options");
|
||||
final DoorhangerConfig config = makeConfigFromJSON(geckoObject);
|
||||
|
||||
ThreadUtils.postToUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addDoorHanger(tabId, value, message, buttons, options);
|
||||
addDoorHanger(config);
|
||||
}
|
||||
});
|
||||
} else if (event.equals("Doorhanger:Remove")) {
|
||||
@ -110,6 +106,22 @@ public class DoorHangerPopup extends AnchoredPopup
|
||||
}
|
||||
}
|
||||
|
||||
private DoorhangerConfig makeConfigFromJSON(JSONObject json) throws JSONException {
|
||||
final int tabId = json.getInt("tabID");
|
||||
final String id = json.getString("value");
|
||||
final DoorhangerConfig config = new DoorhangerConfig(tabId, id);
|
||||
|
||||
config.setMessage(json.getString("message"));
|
||||
config.setButtons(json.getJSONArray("buttons"));
|
||||
config.setOptions(json.getJSONObject("options"));
|
||||
final String typeString = json.optString("category");
|
||||
if (DoorHanger.Type.PASSWORD.toString().equals(typeString)) {
|
||||
config.setType(DoorHanger.Type.PASSWORD);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
// This callback is automatically executed on the UI thread.
|
||||
@Override
|
||||
public void onTabChanged(final Tab tab, final Tabs.TabEvents msg, final Object data) {
|
||||
@ -150,15 +162,15 @@ public class DoorHangerPopup extends AnchoredPopup
|
||||
*
|
||||
* This method must be called on the UI thread.
|
||||
*/
|
||||
void addDoorHanger(final int tabId, final String value, final String message,
|
||||
final JSONArray buttons, final JSONObject options) {
|
||||
void addDoorHanger(DoorhangerConfig config) {
|
||||
final int tabId = config.getTabId();
|
||||
// Don't add a doorhanger for a tab that doesn't exist
|
||||
if (Tabs.getInstance().getTab(tabId) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace the doorhanger if it already exists
|
||||
DoorHanger oldDoorHanger = getDoorHanger(tabId, value);
|
||||
DoorHanger oldDoorHanger = getDoorHanger(tabId, config.getId());
|
||||
if (oldDoorHanger != null) {
|
||||
removeDoorHanger(oldDoorHanger);
|
||||
}
|
||||
@ -167,10 +179,9 @@ public class DoorHangerPopup extends AnchoredPopup
|
||||
init();
|
||||
}
|
||||
|
||||
final DoorHanger newDoorHanger = new DefaultDoorHanger(mContext, tabId, value);
|
||||
newDoorHanger.setMessage(message);
|
||||
newDoorHanger.setOptions(options);
|
||||
final DoorHanger newDoorHanger = DoorHanger.Get(mContext, config);
|
||||
|
||||
final JSONArray buttons = config.getButtons();
|
||||
for (int i = 0; i < buttons.length(); i++) {
|
||||
try {
|
||||
JSONObject buttonObject = buttons.getJSONObject(i);
|
||||
|
@ -15,7 +15,6 @@ import org.mozilla.gecko.SiteIdentity.TrackingMode;
|
||||
import org.mozilla.gecko.Tab;
|
||||
import org.mozilla.gecko.Tabs;
|
||||
import org.mozilla.gecko.widget.AnchoredPopup;
|
||||
import org.mozilla.gecko.widget.DefaultDoorHanger;
|
||||
import org.mozilla.gecko.widget.DoorHanger;
|
||||
import org.mozilla.gecko.widget.DoorHanger.OnButtonClickListener;
|
||||
import org.json.JSONException;
|
||||
@ -28,6 +27,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import org.mozilla.gecko.widget.DoorhangerConfig;
|
||||
|
||||
/**
|
||||
* SiteIdentityPopup is a singleton class that displays site identity data in
|
||||
@ -141,22 +141,22 @@ public class SiteIdentityPopup extends AnchoredPopup {
|
||||
private void addMixedContentNotification(boolean blocked) {
|
||||
// Remove any existing mixed content notification.
|
||||
removeMixedContentNotification();
|
||||
mMixedContentNotification = new DefaultDoorHanger(mContext, DoorHanger.Type.SITE);
|
||||
|
||||
final DoorhangerConfig config = new DoorhangerConfig();
|
||||
int icon;
|
||||
String message;
|
||||
if (blocked) {
|
||||
icon = R.drawable.shield_enabled_doorhanger;
|
||||
message = mContext.getString(R.string.blocked_mixed_content_message_top) + "\n\n" +
|
||||
mContext.getString(R.string.blocked_mixed_content_message_bottom);
|
||||
config.setMessage(mContext.getString(R.string.blocked_mixed_content_message_top) + "\n\n" +
|
||||
mContext.getString(R.string.blocked_mixed_content_message_bottom));
|
||||
} else {
|
||||
icon = R.drawable.shield_disabled_doorhanger;
|
||||
message = mContext.getString(R.string.loaded_mixed_content_message);
|
||||
config.setMessage(mContext.getString(R.string.loaded_mixed_content_message));
|
||||
}
|
||||
|
||||
config.setLink(mContext.getString(R.string.learn_more), MIXED_CONTENT_SUPPORT_URL, "\n\n");
|
||||
config.setType(DoorHanger.Type.SITE);
|
||||
mMixedContentNotification = DoorHanger.Get(mContext, config);
|
||||
mMixedContentNotification.setIcon(icon);
|
||||
mMixedContentNotification.setMessage(message);
|
||||
mMixedContentNotification.addLink(mContext.getString(R.string.learn_more), MIXED_CONTENT_SUPPORT_URL, "\n\n");
|
||||
|
||||
addNotificationButtons(mMixedContentNotification, blocked);
|
||||
|
||||
@ -174,23 +174,25 @@ public class SiteIdentityPopup extends AnchoredPopup {
|
||||
private void addTrackingContentNotification(boolean blocked) {
|
||||
// Remove any existing tracking content notification.
|
||||
removeTrackingContentNotification();
|
||||
mTrackingContentNotification = new DefaultDoorHanger(mContext, DoorHanger.Type.SITE);
|
||||
|
||||
final DoorhangerConfig config = new DoorhangerConfig();
|
||||
|
||||
int icon;
|
||||
String message;
|
||||
if (blocked) {
|
||||
icon = R.drawable.shield_enabled_doorhanger;
|
||||
message = mContext.getString(R.string.blocked_tracking_content_message_top) + "\n\n" +
|
||||
mContext.getString(R.string.blocked_tracking_content_message_bottom);
|
||||
config.setMessage(mContext.getString(R.string.blocked_tracking_content_message_top) + "\n\n" +
|
||||
mContext.getString(R.string.blocked_tracking_content_message_bottom));
|
||||
} else {
|
||||
icon = R.drawable.shield_disabled_doorhanger;
|
||||
message = mContext.getString(R.string.loaded_tracking_content_message_top) + "\n\n" +
|
||||
mContext.getString(R.string.loaded_tracking_content_message_bottom);
|
||||
config.setMessage(mContext.getString(R.string.loaded_tracking_content_message_top) + "\n\n" +
|
||||
mContext.getString(R.string.loaded_tracking_content_message_bottom));
|
||||
}
|
||||
|
||||
config.setLink(mContext.getString(R.string.learn_more), TRACKING_CONTENT_SUPPORT_URL, "\n\n");
|
||||
config.setType(DoorHanger.Type.SITE);
|
||||
mTrackingContentNotification = DoorHanger.Get(mContext, config);
|
||||
|
||||
mTrackingContentNotification.setIcon(icon);
|
||||
mTrackingContentNotification.setMessage(message);
|
||||
mTrackingContentNotification.addLink(mContext.getString(R.string.learn_more), TRACKING_CONTENT_SUPPORT_URL, "\n\n");
|
||||
|
||||
addNotificationButtons(mTrackingContentNotification, blocked);
|
||||
|
||||
@ -206,6 +208,7 @@ public class SiteIdentityPopup extends AnchoredPopup {
|
||||
}
|
||||
|
||||
private void addNotificationButtons(DoorHanger dh, boolean blocked) {
|
||||
// TODO: Add support for buttons in DoorHangerConfig.
|
||||
if (blocked) {
|
||||
dh.addButton(mContext.getString(R.string.disable_protection), "disable", mButtonClickListener);
|
||||
dh.addButton(mContext.getString(R.string.keep_blocking), "keepBlocking", mButtonClickListener);
|
||||
|
@ -31,30 +31,38 @@ public class DefaultDoorHanger extends DoorHanger {
|
||||
private List<PromptInput> mInputs;
|
||||
private CheckBox mCheckBox;
|
||||
|
||||
public DefaultDoorHanger(Context context) {
|
||||
|
||||
this(context, 0, null);
|
||||
public DefaultDoorHanger(Context context, DoorhangerConfig config) {
|
||||
this(context, config, Type.DEFAULT);
|
||||
}
|
||||
|
||||
public DefaultDoorHanger(Context context, Type type) {
|
||||
this(context, 0, null, type);
|
||||
}
|
||||
|
||||
public DefaultDoorHanger(Context context, int tabId, String id) {
|
||||
this(context, tabId, id, Type.DEFAULT);
|
||||
}
|
||||
|
||||
public DefaultDoorHanger(Context context, int tabId, String id, Type type) {
|
||||
|
||||
super(context, tabId, id, type);
|
||||
public DefaultDoorHanger(Context context, DoorhangerConfig config, Type type) {
|
||||
super(context, config, type);
|
||||
|
||||
mResources = getResources();
|
||||
|
||||
if (sSpinnerTextColor == -1) {
|
||||
sSpinnerTextColor = getResources().getColor(R.color.text_color_primary_disable_only);
|
||||
}
|
||||
loadConfig(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadConfig(DoorhangerConfig config) {
|
||||
final String message = config.getMessage();
|
||||
if (message != null) {
|
||||
setMessage(message);
|
||||
}
|
||||
|
||||
final JSONObject options = config.getOptions();
|
||||
if (options != null) {
|
||||
setOptions(options);
|
||||
}
|
||||
|
||||
final DoorhangerConfig.Link link = config.getLink();
|
||||
if (link != null) {
|
||||
addLink(link.label, link.url, link.delimiter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PromptInput> getInputs() {
|
||||
|
@ -3,7 +3,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.widget;
|
||||
package org.mozilla.gecko.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Html;
|
||||
@ -28,7 +28,21 @@ import java.util.List;
|
||||
|
||||
public abstract class DoorHanger extends LinearLayout {
|
||||
|
||||
public static DoorHanger Get(Context context, DoorhangerConfig config) {
|
||||
final Type type = config.getType();
|
||||
if (type != null) {
|
||||
switch (type) {
|
||||
case PASSWORD:
|
||||
case SITE:
|
||||
return new DefaultDoorHanger(context, config, type);
|
||||
}
|
||||
}
|
||||
|
||||
return new DefaultDoorHanger(context, config);
|
||||
}
|
||||
|
||||
public static enum Type { DEFAULT, PASSWORD, SITE }
|
||||
|
||||
public interface OnButtonClickListener {
|
||||
public void onButtonClick(DoorHanger dh, String tag);
|
||||
}
|
||||
@ -54,28 +68,19 @@ public abstract class DoorHanger extends LinearLayout {
|
||||
private final ImageView mIcon;
|
||||
private final TextView mMessage;
|
||||
|
||||
protected Context mContext;
|
||||
|
||||
protected int mDividerColor;
|
||||
|
||||
protected boolean mPersistWhileVisible;
|
||||
protected int mPersistenceCount;
|
||||
protected long mTimeout;
|
||||
|
||||
public DoorHanger(Context context) {
|
||||
this(context, 0, null);
|
||||
}
|
||||
|
||||
public DoorHanger(Context context, int tabId, String id) {
|
||||
this(context, tabId, id, Type.DEFAULT);
|
||||
}
|
||||
public DoorHanger(Context context, int tabId, String id, Type type) {
|
||||
this(context, tabId, id, type, null);
|
||||
}
|
||||
|
||||
public DoorHanger(Context context, int tabId, String id, Type type, JSONObject options) {
|
||||
protected DoorHanger(Context context, DoorhangerConfig config, Type type) {
|
||||
super(context);
|
||||
|
||||
mTabId = tabId;
|
||||
mIdentifier = id;
|
||||
mContext = context;
|
||||
mTabId = config.getTabId();
|
||||
mIdentifier = config.getId();
|
||||
|
||||
int resource;
|
||||
switch (type) {
|
||||
@ -97,15 +102,12 @@ public abstract class DoorHanger extends LinearLayout {
|
||||
mButtonsContainer = (LinearLayout) findViewById(R.id.doorhanger_buttons);
|
||||
|
||||
mDividerColor = getResources().getColor(R.color.divider_light);
|
||||
|
||||
if (options != null) {
|
||||
setOptions(options);
|
||||
}
|
||||
|
||||
setOrientation(VERTICAL);
|
||||
}
|
||||
|
||||
public void setOptions(final JSONObject options) {
|
||||
abstract protected void loadConfig(DoorhangerConfig config);
|
||||
|
||||
protected void setOptions(final JSONObject options) {
|
||||
final int persistence = options.optInt("persistence");
|
||||
if (persistence > 0) {
|
||||
mPersistenceCount = persistence;
|
||||
@ -140,13 +142,12 @@ public abstract class DoorHanger extends LinearLayout {
|
||||
mIcon.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
protected void setMessage(String message) {
|
||||
Spanned markupMessage = Html.fromHtml(message);
|
||||
mMessage.setText(markupMessage);
|
||||
mMessage.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
public void addLink(String label, String url, String delimiter) {
|
||||
protected void addLink(String label, String url, String delimiter) {
|
||||
String title = mMessage.getText().toString();
|
||||
SpannableString titleWithLink = new SpannableString(title + delimiter + label);
|
||||
URLSpan linkSpan = new URLSpan(url) {
|
||||
|
Loading…
Reference in New Issue
Block a user