Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBar.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBar.java |
| index ec46847867ac756befc965867f74238d2040e8c7..a2aa6569099b68e4ca0bde1533d2c42c1905f667 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBar.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBar.java |
| @@ -4,26 +4,87 @@ |
| package org.chromium.chrome.browser.infobar; |
| +import android.content.Context; |
| +import android.content.Intent; |
| +import android.os.Bundle; |
| +import android.text.SpannableString; |
| +import android.text.Spanned; |
| +import android.text.TextPaint; |
| +import android.text.style.ClickableSpan; |
| +import android.view.View; |
| + |
| +import org.chromium.base.ContextUtils; |
| import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.chrome.browser.ResourceId; |
| +import org.chromium.chrome.browser.preferences.Preferences; |
| +import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
| +import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; |
| /** |
| * An infobar to disclose to the user that the default search engine has geolocation access by |
| * default. |
| */ |
| public class SearchGeolocationDisclosureInfoBar extends InfoBar { |
| + private final String mMessageText; |
| + private final int mInlineLinkRangeStart; |
| + private final int mInlineLinkRangeEnd; |
| + private final String mSearchUrl; |
| + |
| @CalledByNative |
| - private static InfoBar show(int enumeratedIconId, String message) { |
| + private static InfoBar show(int enumeratedIconId, String messageText, int inlineLinkRangeStart, |
| + int inlineLinkRangeEnd, String searchUrl) { |
| int drawableId = ResourceId.mapToDrawableId(enumeratedIconId); |
| - return new SearchGeolocationDisclosureInfoBar(drawableId, message); |
| + return new SearchGeolocationDisclosureInfoBar( |
| + drawableId, messageText, inlineLinkRangeStart, inlineLinkRangeEnd, searchUrl); |
| } |
| /** |
| * Creates the infobar. |
| * @param iconDrawableId Drawable ID corresponding to the icon that the infobar will show. |
| * @param messageText Message to display in the infobar. |
| + * @param inlineLinkRangeStartBeginning Beginning of the link in the message. |
| + * @param inlineLinkRangeStartEnd End of the link in the message. |
| + * @param searchUrl The URL of the search page the disclosure is being shown for. |
| */ |
| - private SearchGeolocationDisclosureInfoBar(int iconDrawableId, String messageText) { |
| - super(iconDrawableId, null, messageText); |
| + private SearchGeolocationDisclosureInfoBar(int iconDrawableId, String messageText, |
| + int inlineLinkRangeStart, int inlineLinkRangeEnd, String searchUrl) { |
| + super(iconDrawableId, null, null); |
| + mMessageText = messageText; |
| + mInlineLinkRangeStart = inlineLinkRangeStart; |
| + mInlineLinkRangeEnd = inlineLinkRangeEnd; |
| + mSearchUrl = searchUrl; |
| + } |
| + |
| + @Override |
| + public void createContent(InfoBarLayout layout) { |
|
gone
2016/11/08 04:40:28
Currently empty, but call super.createContent(layo
benwells
2016/11/08 11:26:33
Done.
|
| + SpannableString message = new SpannableString(mMessageText); |
| + message.setSpan( |
| + new ClickableSpan() { |
| + @Override |
| + public void onClick(View view) { |
| + onLinkClicked(); |
| + } |
| + |
| + @Override |
| + public void updateDrawState(TextPaint ds) { |
| + super.updateDrawState(ds); |
| + ds.setUnderlineText(false); |
| + } |
| + }, mInlineLinkRangeStart, mInlineLinkRangeEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE); |
| + layout.setMessage(message); |
| + } |
| + |
| + @Override |
| + public void onLinkClicked() { |
|
gone
2016/11/08 04:40:27
Will leave this up to you, but I'd prefer to avoid
benwells
2016/11/08 11:26:34
Done.
|
| + Context context = ContextUtils.getApplicationContext(); |
| + Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage( |
| + context, SingleWebsitePreferences.class.getName()); |
| + Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsForSite(mSearchUrl); |
| + settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs); |
| + context.startActivity(settingsIntent); |
|
gone
2016/11/08 04:40:27
IntentUtils.safeStartActivity(context, settingsInt
benwells
2016/11/08 11:26:34
Done.
|
| + |
| + // Calling the inherited method will cause the native infobar to be notified that the link |
| + // was clicked, and close the infobar. |
| + super.onLinkClicked(); |
| } |
| } |