Commit f54b2781 authored by Matthew Jones's avatar Matthew Jones Committed by Commit Bot

Support ad block infobar for touchless

Bug: 973550
Change-Id: I65db611c07f035d657db1b54de12fe82df347762
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1656468
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#668559}
parent 25a933ab
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.infobar;
import android.content.res.Resources;
import android.support.v7.widget.SwitchCompat;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
......@@ -12,12 +13,20 @@ import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ResourceId;
import org.chromium.chrome.browser.touchless.dialog.TouchlessDialogProperties;
import org.chromium.chrome.browser.touchless.dialog.TouchlessDialogProperties.DialogListItemProperties;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.ui.modaldialog.ModalDialogProperties;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.text.NoUnderlineClickableSpan;
import org.chromium.ui.widget.ButtonCompat;
import java.util.ArrayList;
/**
* This infobar appears when ads are being blocked on the page. This occurs after proceeding through
* an interstitial warning that the site shows deceptive content, or when the site is known to show
......@@ -97,7 +106,7 @@ public class AdsBlockedInfoBar extends ConfirmInfoBar implements OnCheckedChange
// If we aren't already showing the explanation, clicking the link should expand to show the
// explanation. If we *are* already showing the explanation, clicking the link (which should
// change to Learn more) should take us to the help page.
if (!mIsShowingExplanation) {
if (!mIsShowingExplanation && !FeatureUtilities.isNoTouchModeEnabled()) {
mIsShowingExplanation = true;
replaceView(createView());
}
......@@ -115,4 +124,52 @@ public class AdsBlockedInfoBar extends ConfirmInfoBar implements OnCheckedChange
mButton.setText(isChecked ? mReloadButtonText : mOKButtonText);
mReloadIsToggled = isChecked;
}
@Override
public boolean supportsTouchlessMode() {
return true;
}
@Override
public PropertyModel createModel() {
PropertyModel model = super.createModel();
Resources res = getContext().getResources();
model.set(ModalDialogProperties.TITLE, res.getString(R.string.blocked_ads_prompt_title));
model.set(ModalDialogProperties.MESSAGE, res.getString(R.string.intrusive_ads_information));
ArrayList<PropertyModel> options = new ArrayList<>();
options.add(new PropertyModel.Builder(DialogListItemProperties.ALL_KEYS)
.with(DialogListItemProperties.TEXT, res.getString(R.string.learn_more))
.with(DialogListItemProperties.CLICK_LISTENER, (v) -> onLinkClicked())
.with(DialogListItemProperties.ICON,
ApiCompatibilityUtils.getDrawable(
res, R.drawable.ic_info_outline_grey))
.build());
// TODO(973601): We should have a better string for "always allow"; at least one that is
// specific to this feature.
options.add(
new PropertyModel.Builder(DialogListItemProperties.ALL_KEYS)
.with(DialogListItemProperties.TEXT,
res.getString(R.string.always_allow_redirects))
.with(DialogListItemProperties.CLICK_LISTENER,
(v) -> {
mReloadIsToggled = true;
onButtonClicked(true);
})
.with(DialogListItemProperties.ICON,
ApiCompatibilityUtils.getDrawable(res, R.drawable.ic_check_circle))
.build());
PropertyModel[] optionModels = new PropertyModel[options.size()];
options.toArray(optionModels);
model.set(TouchlessDialogProperties.LIST_MODELS, optionModels);
// The alt action matches cancel but with a different name.
model.get(TouchlessDialogProperties.ACTION_NAMES).alt = R.string.ok;
model.set(TouchlessDialogProperties.ALT_ACTION,
model.get(TouchlessDialogProperties.CANCEL_ACTION));
return model;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment