Commit 1b1daf74 authored by bengr@chromium.org's avatar bengr@chromium.org

Add notification of data reduction proxy field trial

Adds an InfoBar and a description in Settings to inform users
that they are part of a data reduction proxy field trial. This
trial only includes users that enabled the data reduction proxy.

BUG=383988

Review URL: https://codereview.chromium.org/384853002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284254 0039d316-1c4b-4281-b951-d872f2087c98
parent 09b6ce89
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.content.Intent;
import android.preference.PreferenceActivity;
import org.chromium.content_public.browser.WebContents;
/**
* Generates an InfoBar for the data reduction proxy that contains a message and a link to the
* data reduction proxy settings menu.
*/
public class DataReductionProxyInfoBar extends ConfirmInfoBar {
private static String sSettingsClassName;
private static String sDataReductionProxySettingsClassName;
private static String sTitle;
private static String sLinkText;
/**
* Launch a data reduction proxy {@link InfoBar} with the specified title and link
* text. Clicking the link will open the specified settings page.
* @param webContents The {@link WebContents} in which to open the {@link InfoBar}.
* @param settingsClassName. The settings class to open.
* @param drpSettingsClassName The {@link PreferenceActivity} fragment to show.
* @param title The text to display in the {@link InfoBar}.
* @param linkText The text to display in the link in the {@link InfoBar}.
*/
public static void launch(WebContents webContents,
String settingsClassName,
String drpSettingsClassName,
String title,
String linkText) {
sSettingsClassName = settingsClassName;
sDataReductionProxySettingsClassName = drpSettingsClassName;
sTitle = title;
sLinkText = linkText;
DataReductionProxyInfoBarDelegate.launch(webContents);
}
DataReductionProxyInfoBar(long nativeInfoBar, int iconDrawableId) {
super(nativeInfoBar, null, iconDrawableId, sTitle,
sLinkText, null, null);
}
@Override
public void onLinkClicked() {
Context context = getContext();
if (context == null) return;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(context, sSettingsClassName);
intent.setFlags(
Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
sDataReductionProxySettingsClassName);
context.startActivity(intent);
}
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.infobar;
import org.chromium.base.CalledByNative;
import org.chromium.chrome.browser.ResourceId;
import org.chromium.content_public.browser.WebContents;
/**
* Provides JNI methods for DataReductionProxyInfoBars.
*/
public class DataReductionProxyInfoBarDelegate {
/**
* Launches the {@link InfoBar}.
* @param webContents The {@link WebContents} in which to laucnh the {@link InfoBar}.
*/
static void launch(WebContents webContents) {
nativeLaunch(webContents);
}
private DataReductionProxyInfoBarDelegate() {
}
@CalledByNative
public static DataReductionProxyInfoBarDelegate create() {
return new DataReductionProxyInfoBarDelegate();
}
/**
* Creates and begins the process for showing a DataReductionProxyInfoBarDelegate.
* @param nativeInfoBar Pointer to the C++ InfoBar corresponding to the Java InfoBar.
* @param enumeratedIconId ID corresponding to the icon that will be shown for the InfoBar.
* The ID must have been mapped using the ResourceMapper class before
* passing it to this function.
*/
@CalledByNative
InfoBar showDataReductionProxyInfoBar(long nativeInfoBar, int enumeratedIconId) {
int drawableId = ResourceId.mapToDrawableId(enumeratedIconId);
DataReductionProxyInfoBar infoBar = new DataReductionProxyInfoBar(
nativeInfoBar, drawableId);
return infoBar;
}
protected static native void nativeLaunch(WebContents webContents);
}
......@@ -95,6 +95,11 @@ public class DataReductionProxySettings {
return nativeIsDataReductionProxyPromoAllowed(mNativeDataReductionProxySettings);
}
/** Returns true if proxy alternative field trial is running. */
public boolean isIncludedInAltFieldTrial() {
return nativeIsIncludedInAltFieldTrial(mNativeDataReductionProxySettings);
}
/**
* Returns the current data reduction proxy origin.
*/
......@@ -185,6 +190,8 @@ public class DataReductionProxySettings {
long nativeDataReductionProxySettingsAndroid);
private native boolean nativeIsDataReductionProxyPromoAllowed(
long nativeDataReductionProxySettingsAndroid);
private native boolean nativeIsIncludedInAltFieldTrial(
long nativeDataReductionProxySettingsAndroid);
private native String nativeGetDataReductionProxyOrigin(
long nativeDataReductionProxySettingsAndroid);
private native boolean nativeIsDataReductionProxyEnabled(
......
......@@ -363,6 +363,14 @@ You are signing in with a managed account and giving its administrator control o
Cancel
</message>
<!-- Data Reduction Proxy -->
<message name="IDS_DATA_REDUCTION_INFOBAR_TEXT" desc="Text to be displayed in the data reduction proxy infobar" translateable="false">
You are part of a data reduction proxy field trial.
</message>
<message name="IDS_DATA_REDUCTION_INFOBAR_LINK_TEXT" desc="Text to be displayed in the data reduction proxy infobar link" translateable="false">
Settings
</message>
</messages>
</release>
</grit>
......@@ -58,6 +58,7 @@
#include "chrome/browser/ui/android/context_menu_helper.h"
#include "chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/data_reduction_proxy_infobar.h"
#include "chrome/browser/ui/android/infobars/infobar_android.h"
#include "chrome/browser/ui/android/infobars/infobar_container_android.h"
#include "chrome/browser/ui/android/infobars/save_password_infobar.h"
......@@ -126,6 +127,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
{ "ConfirmInfoBarDelegate", RegisterConfirmInfoBarDelegate },
{ "ContentViewUtil", RegisterContentViewUtil },
{ "ContextMenuHelper", RegisterContextMenuHelper },
{ "DataReductionProxyInfoBarDelegate", DataReductionProxyInfoBar::Register },
{ "DataReductionProxySettings", DataReductionProxySettingsAndroid::Register },
{ "DevToolsServer", RegisterDevToolsServer },
{ "DomDistillerServiceFactory",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_infobar_delegate.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_delegate.h"
#include "content/public/browser/web_contents.h"
// static
void DataReductionProxyInfoBarDelegate::Create(
content::WebContents* web_contents) {
InfoBarService::FromWebContents(web_contents)->AddInfoBar(
DataReductionProxyInfoBarDelegate::CreateInfoBar(
scoped_ptr<DataReductionProxyInfoBarDelegate>(
new DataReductionProxyInfoBarDelegate())));
}
#if !defined(OS_ANDROID)
// This infobar currently only supports Android.
// static
scoped_ptr<infobars::InfoBar> DataReductionProxyInfoBarDelegate::CreateInfoBar(
scoped_ptr<DataReductionProxyInfoBarDelegate> delegate) {
return ConfirmInfoBarDelegate::CreateInfoBar(
delegate.PassAs<ConfirmInfoBarDelegate>());
}
#endif
DataReductionProxyInfoBarDelegate::~DataReductionProxyInfoBarDelegate() {
}
DataReductionProxyInfoBarDelegate::DataReductionProxyInfoBarDelegate()
: ConfirmInfoBarDelegate() {
}
bool DataReductionProxyInfoBarDelegate::ShouldExpire(
const NavigationDetails& details) const {
return false;
}
base::string16 DataReductionProxyInfoBarDelegate::GetMessageText() const {
return base::string16();
}
int DataReductionProxyInfoBarDelegate::GetButtons() const {
return BUTTON_NONE;
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_INFOBAR_DELEGATE_H_
#define CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_INFOBAR_DELEGATE_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar_delegate.h"
namespace content {
class WebContents;
}
// Configures an InfoBar with no buttons that stays visible until it is
// explicitly dismissed. This InfoBar is suitable for displaying a message
// and a link, and is used only by an Android field trial.
class DataReductionProxyInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
// Creates the InfoBar and adds it to the provided |web_contents|.
static void Create(content::WebContents* web_contents);
virtual ~DataReductionProxyInfoBarDelegate();
private:
DataReductionProxyInfoBarDelegate();
// Returns a Data Reduction Proxy infobar that owns |delegate|.
static scoped_ptr<infobars::InfoBar> CreateInfoBar(
scoped_ptr<DataReductionProxyInfoBarDelegate> delegate);
// ConfirmInfoBarDelegate
virtual base::string16 GetMessageText() const OVERRIDE;
virtual int GetButtons() const OVERRIDE;
virtual bool ShouldExpire(const NavigationDetails& details) const OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyInfoBarDelegate);
};
#endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_INFOBAR_DELEGATE_H_
......@@ -104,6 +104,11 @@ jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyPromoAllowed(
return params()->promo_allowed();
}
jboolean DataReductionProxySettingsAndroid::IsIncludedInAltFieldTrial(
JNIEnv* env, jobject obj) {
return DataReductionProxyParams::IsIncludedInAlternativeFieldTrial();
}
ScopedJavaLocalRef<jstring>
DataReductionProxySettingsAndroid::GetDataReductionProxyOrigin(
JNIEnv* env, jobject obj) {
......
......@@ -50,6 +50,7 @@ class DataReductionProxySettingsAndroid
// JNI wrapper interfaces to the indentically-named superclass methods.
jboolean IsDataReductionProxyAllowed(JNIEnv* env, jobject obj);
jboolean IsDataReductionProxyPromoAllowed(JNIEnv* env, jobject obj);
jboolean IsIncludedInAltFieldTrial(JNIEnv* env, jobject obj);
ScopedJavaLocalRef<jstring> GetDataReductionProxyOrigin(JNIEnv* env,
jobject obj);
jboolean IsDataReductionProxyEnabled(JNIEnv* env, jobject obj);
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/android/infobars/data_reduction_proxy_infobar.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/logging.h"
#include "chrome/browser/android/resource_mapper.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_infobar_delegate.h"
#include "content/public/browser/web_contents.h"
#include "jni/DataReductionProxyInfoBarDelegate_jni.h"
// DataReductionProxyInfoBar:
// static
void DataReductionProxyInfoBar::Launch(
JNIEnv* env, jclass, jobject jweb_contents) {
content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(jweb_contents);
DCHECK(web_contents);
DataReductionProxyInfoBarDelegate::Create(web_contents);
}
// static
bool DataReductionProxyInfoBar::Register(JNIEnv* env) {
return RegisterNativesImpl(env);
}
DataReductionProxyInfoBar::DataReductionProxyInfoBar(
scoped_ptr<DataReductionProxyInfoBarDelegate> delegate)
: ConfirmInfoBar(delegate.PassAs<ConfirmInfoBarDelegate>()),
java_data_reduction_proxy_delegate_() {
}
DataReductionProxyInfoBar::~DataReductionProxyInfoBar() {
}
base::android::ScopedJavaLocalRef<jobject>
DataReductionProxyInfoBar::CreateRenderInfoBar(JNIEnv* env) {
java_data_reduction_proxy_delegate_.Reset(
Java_DataReductionProxyInfoBarDelegate_create(env));
return Java_DataReductionProxyInfoBarDelegate_showDataReductionProxyInfoBar(
env,
java_data_reduction_proxy_delegate_.obj(),
reinterpret_cast<intptr_t>(this),
GetEnumeratedIconId());
}
DataReductionProxyInfoBarDelegate* DataReductionProxyInfoBar::GetDelegate() {
return static_cast<DataReductionProxyInfoBarDelegate*>(delegate());
}
// DataReductionProxyInfoBarDelegate:
// static
scoped_ptr<infobars::InfoBar> DataReductionProxyInfoBarDelegate::CreateInfoBar(
scoped_ptr<DataReductionProxyInfoBarDelegate> delegate) {
return scoped_ptr<infobars::InfoBar>(
new DataReductionProxyInfoBar(delegate.Pass()));
}
// JNI for DataReductionProxyInfoBarDelegate.
void Launch(JNIEnv* env, jclass clazz, jobject jweb_contents) {
DataReductionProxyInfoBar::Launch(env, clazz, jweb_contents);
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ANDROID_INFOBARS_DATA_REDUCTION_PROXY_INFOBAR_H_
#define CHROME_BROWSER_UI_ANDROID_INFOBARS_DATA_REDUCTION_PROXY_INFOBAR_H_
#include "base/basictypes.h"
#include "base/strings/string16.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_infobar_delegate.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
class DataReductionProxyInfoBar : public ConfirmInfoBar {
public:
static void Launch(JNIEnv* env, jclass, jobject jweb_contents);
static bool Register(JNIEnv* env);
explicit DataReductionProxyInfoBar(
scoped_ptr<DataReductionProxyInfoBarDelegate> delegate);
virtual ~DataReductionProxyInfoBar();
private:
// ConfirmInfoBar:
virtual base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar(
JNIEnv* env) OVERRIDE;
DataReductionProxyInfoBarDelegate* GetDelegate();
base::android::ScopedJavaGlobalRef<jobject>
java_data_reduction_proxy_delegate_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyInfoBar);
};
bool RegisterDataReductionProxyInfoBar(JNIEnv* env);
#endif // CHROME_BROWSER_UI_ANDROID_INFOBARS_DATA_REDUCTION_PROXY_INFOBAR_H_
......@@ -833,6 +833,8 @@
'browser/net/service_providers_win.h',
'browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc',
'browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h',
'browser/net/spdyproxy/data_reduction_proxy_infobar_delegate.cc',
'browser/net/spdyproxy/data_reduction_proxy_infobar_delegate.h',
'browser/net/spdyproxy/data_reduction_proxy_settings_android.cc',
'browser/net/spdyproxy/data_reduction_proxy_settings_android.h',
'browser/net/spdyproxy/data_reduction_proxy_settings_factory_android.cc',
......@@ -2806,6 +2808,7 @@
'android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java',
'android/java/src/org/chromium/chrome/browser/infobar/AutoLoginDelegate.java',
'android/java/src/org/chromium/chrome/browser/infobar/ConfirmInfoBarDelegate.java',
'android/java/src/org/chromium/chrome/browser/infobar/DataReductionProxyInfoBarDelegate.java',
'android/java/src/org/chromium/chrome/browser/infobar/InfoBar.java',
'android/java/src/org/chromium/chrome/browser/infobar/InfoBarContainer.java',
'android/java/src/org/chromium/chrome/browser/infobar/SavePasswordInfoBarDelegate.java',
......
......@@ -24,6 +24,8 @@
'browser/ui/android/infobars/auto_login_prompter.h',
'browser/ui/android/infobars/confirm_infobar.cc',
'browser/ui/android/infobars/confirm_infobar.h',
'browser/ui/android/infobars/data_reduction_proxy_infobar.cc',
'browser/ui/android/infobars/data_reduction_proxy_infobar.h',
'browser/ui/android/infobars/infobar_android.cc',
'browser/ui/android/infobars/infobar_android.h',
'browser/ui/android/infobars/infobar_container_android.cc',
......
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