| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.infobar; | 5 package org.chromium.chrome.browser.infobar; |
| 6 | 6 |
| 7 import android.content.Context; | |
| 8 import android.content.Intent; | |
| 9 import android.preference.PreferenceActivity; | |
| 10 | |
| 11 import org.chromium.content_public.browser.WebContents; | 7 import org.chromium.content_public.browser.WebContents; |
| 12 | 8 |
| 13 /** | 9 /** |
| 14 * Generates an InfoBar for the data reduction proxy that contains a message and
a link to the | 10 * Generates an InfoBar for the data reduction proxy that contains a message and
a link to the |
| 15 * data reduction proxy settings menu. | 11 * data reduction proxy settings menu. |
| 16 */ | 12 */ |
| 17 public class DataReductionProxyInfoBar extends ConfirmInfoBar { | 13 public class DataReductionProxyInfoBar extends ConfirmInfoBar { |
| 18 private static String sSettingsClassName; | 14 private static String sSettingsClassName; |
| 19 private static String sDataReductionProxySettingsClassName; | 15 private static String sDataReductionProxySettingsClassName; |
| 20 private static String sTitle; | 16 private static String sTitle; |
| 21 private static String sLinkText; | 17 private static String sLinkText; |
| 22 | 18 |
| 23 /** | 19 /** |
| 24 * Launch a data reduction proxy {@link InfoBar} with the specified title an
d link | 20 * Launch a data reduction proxy {@link InfoBar} with the specified title an
d link |
| 25 * text. Clicking the link will open the specified settings page. | 21 * text. Clicking the link will open the specified settings page. |
| 26 * @param webContents The {@link WebContents} in which to open the {@link In
foBar}. | 22 * @param webContents The {@link WebContents} in which to open the {@link In
foBar}. |
| 27 * @param settingsClassName. The settings class to open. | 23 * @param settingsClassName The settings class to open. |
| 28 * @param drpSettingsClassName The {@link PreferenceActivity} fragment to sh
ow. | 24 * @param drpSettingsClassName The {@link PreferenceActivity} fragment to sh
ow. |
| 29 * @param title The text to display in the {@link InfoBar}. | 25 * @param title The text to display in the {@link InfoBar}. |
| 30 * @param linkText The text to display in the link in the {@link InfoBar}. | 26 * @param linkText The text to display in the link in the {@link InfoBar}. |
| 27 * @param linkUrl The URL to be loaded when the link text is clicked. |
| 31 */ | 28 */ |
| 32 public static void launch(WebContents webContents, | 29 public static void launch(WebContents webContents, |
| 33 String settingsClassName, | 30 String settingsClassName, |
| 34 String drpSettingsClassName, | 31 String drpSettingsClassName, |
| 35 String title, | 32 String title, |
| 36 String linkText) { | 33 String linkText, |
| 34 String linkUrl) { |
| 37 sSettingsClassName = settingsClassName; | 35 sSettingsClassName = settingsClassName; |
| 38 sDataReductionProxySettingsClassName = drpSettingsClassName; | 36 sDataReductionProxySettingsClassName = drpSettingsClassName; |
| 39 sTitle = title; | 37 sTitle = title; |
| 40 sLinkText = linkText; | 38 sLinkText = linkText; |
| 41 DataReductionProxyInfoBarDelegate.launch(webContents); | 39 DataReductionProxyInfoBarDelegate.launch(webContents, linkUrl); |
| 40 } |
| 41 |
| 42 /** |
| 43 * Callers should now pass a linkUrl, which is loaded when the user clicks o
n linkText. See |
| 44 * {@link #launch} above. See http://crbug.com/383988. |
| 45 */ |
| 46 @Deprecated |
| 47 public static void launch(WebContents webContents, |
| 48 String settingsClassName, |
| 49 String drpSettingsClassName, |
| 50 String title, |
| 51 String linkText) { |
| 52 launch(webContents, settingsClassName, drpSettingsClassName, title, link
Text, ""); |
| 42 } | 53 } |
| 43 | 54 |
| 44 DataReductionProxyInfoBar(long nativeInfoBar, int iconDrawableId) { | 55 DataReductionProxyInfoBar(long nativeInfoBar, int iconDrawableId) { |
| 45 super(nativeInfoBar, null, iconDrawableId, sTitle, | 56 super(nativeInfoBar, null, iconDrawableId, sTitle, |
| 46 sLinkText, null, null); | 57 sLinkText, null, null); |
| 47 } | 58 } |
| 48 | 59 |
| 49 @Override | 60 @Override |
| 50 public void onLinkClicked() { | 61 public void createContent(InfoBarLayout layout) { |
| 51 Context context = getContext(); | 62 layout.setButtons(sLinkText, null); |
| 52 if (context == null) return; | 63 } |
| 53 Intent intent = new Intent(Intent.ACTION_VIEW); | 64 |
| 54 intent.setClassName(context, sSettingsClassName); | 65 @Override |
| 55 intent.setFlags( | 66 public void onButtonClicked(boolean isPrimaryButton) { |
| 56 Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SIN
GLE_TOP); | 67 if (!isPrimaryButton) return; |
| 57 intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, | 68 onLinkClicked(); |
| 58 sDataReductionProxySettingsClassName); | |
| 59 context.startActivity(intent); | |
| 60 } | 69 } |
| 61 } | 70 } |
| OLD | NEW |