Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java |
| index 85ac454794ae1e2190a2d84960910d15d3046766..eb32e3a813bbeca78f27e548adf84ae2e13ec405 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java |
| @@ -7,13 +7,20 @@ package org.chromium.chrome.browser.infobar; |
| import android.content.Context; |
| import android.content.pm.PackageInfo; |
| import android.content.pm.PackageManager.NameNotFoundException; |
| +import android.graphics.Bitmap; |
| +import android.graphics.BitmapFactory; |
| +import android.text.SpannableString; |
| +import org.chromium.base.CommandLine; |
| import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.UrlConstants; |
| +import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; |
| import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
| import org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoUtils; |
| +import org.chromium.chrome.browser.preferences.datareduction.DataReductionProxyUma; |
| import org.chromium.content_public.browser.WebContents; |
| import org.chromium.net.GURLUtils; |
| +import org.chromium.ui.widget.Toast; |
| import java.net.HttpURLConnection; |
| import java.sql.Date; |
| @@ -22,11 +29,14 @@ import java.util.TimeZone; |
| /** |
| * Generates an InfoBar to promote the data reduction proxy. The InfoBar contains a message and a |
|
Raj
2016/06/25 01:21:10
nit: /s/data reduction proxy/data reduction proxy
megjablon
2016/06/27 19:57:09
Done.
|
| - * button to enable the proxy. |
| + * button to enable the proxy. The InfoBar is displayed when it has not been shown previously, the |
| + * page is HTTP pages, andr certain milestone restrictions are met. |
|
Raj
2016/06/25 01:21:10
nit: pls add
Once the proxy is enabled from the in
megjablon
2016/06/27 19:57:09
Done.
|
| */ |
| -public class DataReductionPromoInfoBar { |
| +public class DataReductionPromoInfoBar extends ConfirmInfoBar { |
| private static final String M48_STABLE_RELEASE_DATE = "2016-01-26"; |
| + private static final String ENABLE_INFOBAR_SWITCH = "enable-data-reduction-promo-infobar"; |
| + private static Bitmap sIcon; |
| private static String sTitle; |
| private static String sText; |
| private static String sPrimaryButtonText; |
| @@ -83,11 +93,15 @@ public class DataReductionPromoInfoBar { |
| } |
| // Only show the promo if the current version is at least two milestones after the last |
| - // promo was displayed. If the last promo was shown before M51 then |lastPromoMilestone| |
| - // will be -1 and it is safe to show the InfoBar promo. |
| - if (lastPromoMilestone != -1 && currentMilestone < lastPromoMilestone + 2) return; |
| + // promo was displayed or the command line switch is on. If the last promo was shown before |
| + // M51 then |lastPromoMilestone| will be -1 and it is safe to show the InfoBar promo. |
| + if (!CommandLine.getInstance().hasSwitch(ENABLE_INFOBAR_SWITCH) |
| + && lastPromoMilestone != -1 && currentMilestone < lastPromoMilestone + 2) { |
| + return; |
| + } |
| DataReductionPromoInfoBar.launch(webContents, |
| + BitmapFactory.decodeResource(context.getResources(), R.mipmap.app_icon), |
| context.getString(R.string.data_reduction_promo_infobar_title), |
| context.getString(R.string.data_reduction_promo_infobar_text), |
| context.getString(R.string.data_reduction_promo_infobar_button), |
| @@ -144,11 +158,14 @@ public class DataReductionPromoInfoBar { |
| * text. Clicking the link will open the specified settings page. |
| * |
| * @param webContents The {@link WebContents} in which to open the {@link InfoBar}. |
| - * @param title The text to display in the {@link InfoBar}. |
| + * @param icon Bitmap to use for the InfoBar icon. |
| + * @param title The title to display in the {@link InfoBar}. |
| + * @param text The text to display in the {@link InfoBar}. |
| * @param primaryButtonText The text to display on the primary button. |
| * @param secondaryButtonText The text to display on the secondary button. |
| */ |
| private static void launch(WebContents webContents, |
| + Bitmap icon, |
| String title, |
| String text, |
| String primaryButtonText, |
| @@ -157,7 +174,42 @@ public class DataReductionPromoInfoBar { |
| sText = text; |
| sPrimaryButtonText = primaryButtonText; |
| sSecondaryButtonText = secondaryButtonText; |
| - // TODO(megjablon): Show infobar. |
| + sIcon = icon; |
| + DataReductionPromoInfoBarDelegate.launch(webContents); |
| DataReductionPromoUtils.saveInfoBarPromoDisplayed(); |
| } |
| + |
| + DataReductionPromoInfoBar() { |
| + super(0, sIcon, sTitle, null, sPrimaryButtonText, sSecondaryButtonText); |
| + } |
| + |
| + @Override |
| + public void onButtonClicked(boolean isPrimaryButton) { |
| + super.onButtonClicked(isPrimaryButton); |
| + if (isPrimaryButton) { |
| + DataReductionProxyUma |
| + .dataReductionProxyUIAction(DataReductionProxyUma.ACTION_INFOBAR_ENABLED); |
| + DataReductionProxySettings.getInstance().setDataReductionProxyEnabled( |
| + getContext(), true); |
| + Toast.makeText(getContext(), |
| + getContext().getString(R.string.data_reduction_enabled_toast), |
| + Toast.LENGTH_LONG).show(); |
| + } |
| + } |
| + |
| + @Override |
| + public void onInfoBarClosed() { |
| + super.onInfoBarClosed(); |
| + if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) return; |
| + DataReductionProxyUma |
| + .dataReductionProxyUIAction(DataReductionProxyUma.ACTION_INFOBAR_DISMISSED); |
| + } |
| + |
| + @Override |
| + public void createContent(InfoBarLayout layout) { |
| + super.createContent(layout); |
| + InfoBarControlLayout control = layout.addControlLayout(); |
| + SpannableString text = new SpannableString(sText); |
| + control.addDescription(text); |
| + } |
| } |