| Index: chrome/browser/ui/android/infobars/document_mode_opt_out_infobar_delegate.cc
|
| diff --git a/chrome/browser/android/fullscreen/fullscreen_infobar_delegate.cc b/chrome/browser/ui/android/infobars/document_mode_opt_out_infobar_delegate.cc
|
| similarity index 22%
|
| copy from chrome/browser/android/fullscreen/fullscreen_infobar_delegate.cc
|
| copy to chrome/browser/ui/android/infobars/document_mode_opt_out_infobar_delegate.cc
|
| index cf96e89c653626556c07e72e032b23465c90e879..b989007bd620c6c1cf5cf9590fd86dd3f8b21b4a 100644
|
| --- a/chrome/browser/android/fullscreen/fullscreen_infobar_delegate.cc
|
| +++ b/chrome/browser/ui/android/infobars/document_mode_opt_out_infobar_delegate.cc
|
| @@ -2,95 +2,104 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/android/fullscreen/fullscreen_infobar_delegate.h"
|
| +#include "chrome/browser/ui/android/infobars/document_mode_opt_out_infobar_delegate.h"
|
|
|
| -#include "base/android/jni_string.h"
|
| -#include "base/memory/scoped_ptr.h"
|
| -#include "base/prefs/pref_service.h"
|
| +#include "base/metrics/sparse_histogram.h"
|
| #include "chrome/browser/android/android_theme_resources.h"
|
| #include "chrome/browser/android/tab_android.h"
|
| #include "chrome/browser/infobars/infobar_service.h"
|
| -#include "chrome/browser/profiles/profile_manager.h"
|
| -#include "chrome/common/pref_names.h"
|
| #include "chrome/grit/generated_resources.h"
|
| #include "components/infobars/core/infobar.h"
|
| -#include "components/url_formatter/elide_url.h"
|
| -#include "grit/components_strings.h"
|
| -#include "jni/FullscreenInfoBarDelegate_jni.h"
|
| +#include "jni/DocumentModeOptOutInfoBarDelegate_jni.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| -#include "url/gurl.h"
|
| +
|
| +namespace {
|
| +
|
| +// Keep in sync with the values defined in histograms.xml.
|
| +enum InfoBarEvent {
|
| + SHOWN = 0,
|
| + ACCEPTED,
|
| + DENIED,
|
| + DISMISSED
|
| +};
|
| +
|
| +} // namespace
|
|
|
| // static
|
| -jlong LaunchFullscreenInfoBar(JNIEnv* env,
|
| - const JavaParamRef<jobject>& obj,
|
| - const JavaParamRef<jobject>& tab) {
|
| - TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab);
|
| - GURL origin = tab_android->GetURL().GetOrigin();
|
| - FullscreenInfoBarDelegate* delegate = new FullscreenInfoBarDelegate(
|
| - env, obj, origin);
|
| - InfoBarService* infobar_service =
|
| - InfoBarService::FromWebContents(tab_android->web_contents());
|
| +jlong ShowDocumentModeOptOutInfoBar(JNIEnv* env,
|
| + const JavaParamRef<jobject>& jcaller,
|
| + const JavaParamRef<jobject>& tab) {
|
| + UMA_HISTOGRAM_SPARSE_SLOWLY("DocumentModeOptOutInfoBar", InfoBarEvent::SHOWN);
|
| +
|
| + DocumentModeOptOutInfoBarDelegate* delegate =
|
| + new DocumentModeOptOutInfoBarDelegate(env, jcaller);
|
| + InfoBarService* infobar_service = InfoBarService::FromWebContents(
|
| + TabAndroid::GetNativeTab(env, tab)->web_contents());
|
| infobar_service->AddInfoBar(
|
| infobar_service->CreateConfirmInfoBar(make_scoped_ptr(delegate)));
|
| return reinterpret_cast<intptr_t>(delegate);
|
| }
|
|
|
| -bool FullscreenInfoBarDelegate::RegisterFullscreenInfoBarDelegate(JNIEnv* env) {
|
| +// static
|
| +bool DocumentModeOptOutInfoBarDelegate::
|
| + RegisterDocumentModeOptOutInfoBarDelegate(JNIEnv* env) {
|
| return RegisterNativesImpl(env);
|
| }
|
|
|
| -FullscreenInfoBarDelegate::FullscreenInfoBarDelegate(
|
| - JNIEnv* env, jobject obj, GURL origin)
|
| - : origin_(origin) {
|
| +DocumentModeOptOutInfoBarDelegate::DocumentModeOptOutInfoBarDelegate(
|
| + JNIEnv* env, jobject obj)
|
| + : ConfirmInfoBarDelegate() {
|
| j_delegate_.Reset(env, obj);
|
| }
|
|
|
| -FullscreenInfoBarDelegate::~FullscreenInfoBarDelegate() {
|
| - if (!j_delegate_.is_null()) {
|
| - Java_FullscreenInfoBarDelegate_onInfoBarDismissed(
|
| - base::android::AttachCurrentThread(), j_delegate_.obj());
|
| - }
|
| +DocumentModeOptOutInfoBarDelegate::~DocumentModeOptOutInfoBarDelegate() {
|
| +}
|
| +
|
| +int DocumentModeOptOutInfoBarDelegate::GetIconId() const {
|
| + return IDR_ANDROID_INFOBAR_DOCUMENT_MODE_OPT_OUT;
|
| +}
|
| +
|
| +bool DocumentModeOptOutInfoBarDelegate::ShouldExpire(
|
| + const NavigationDetails& details) const {
|
| + return false;
|
| }
|
|
|
| -void FullscreenInfoBarDelegate::CloseFullscreenInfoBar(
|
| - JNIEnv* env, jobject obj) {
|
| - j_delegate_.Reset();
|
| - if (infobar() && infobar()->owner())
|
| - infobar()->owner()->RemoveInfoBar(infobar());
|
| +void DocumentModeOptOutInfoBarDelegate::InfoBarDismissed() {
|
| + UMA_HISTOGRAM_SPARSE_SLOWLY("DocumentModeOptOutInfoBar",
|
| + InfoBarEvent::DISMISSED);
|
| }
|
|
|
| -int FullscreenInfoBarDelegate::GetIconId() const {
|
| - return IDR_ANDROID_INFOBAR_FULLSCREEN;
|
| +base::string16 DocumentModeOptOutInfoBarDelegate::GetMessageText() const {
|
| + return l10n_util::GetStringUTF16(IDS_DOCUMENT_MODE_OPT_OUT_INFOBAR_TEXT);
|
| }
|
|
|
| -base::string16 FullscreenInfoBarDelegate::GetMessageText() const {
|
| - Profile* profile =
|
| - ProfileManager::GetActiveUserProfile()->GetOriginalProfile();
|
| - std::string language =
|
| - profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
|
| - return l10n_util::GetStringFUTF16(
|
| - IDS_FULLSCREEN_INFOBAR_TEXT,
|
| - url_formatter::FormatUrlForSecurityDisplay(origin_, language));
|
| +int DocumentModeOptOutInfoBarDelegate::GetButtons() const {
|
| + return BUTTON_OK | BUTTON_CANCEL;
|
| }
|
|
|
| -base::string16 FullscreenInfoBarDelegate::GetButtonLabel(
|
| +base::string16 DocumentModeOptOutInfoBarDelegate::GetButtonLabel(
|
| InfoBarButton button) const {
|
| - return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
|
| - IDS_FULLSCREEN_INFOBAR_ALLOW_BUTTON :
|
| - IDS_FULLSCREEN_INFOBAR_EXIT_FULLSCREEN_BUTTON);
|
| + DCHECK(button == BUTTON_OK || button == BUTTON_CANCEL);
|
| + return l10n_util::GetStringUTF16(
|
| + button == BUTTON_OK ? IDS_SHOW : IDS_NO_THANKS);
|
| }
|
|
|
| -bool FullscreenInfoBarDelegate::Accept() {
|
| - JNIEnv* env = base::android::AttachCurrentThread();
|
| - ScopedJavaLocalRef<jstring> j_origin =
|
| - base::android::ConvertUTF8ToJavaString(env, origin_.spec());
|
| - Java_FullscreenInfoBarDelegate_onFullscreenAllowed(
|
| - env, j_delegate_.obj(), j_origin.obj());
|
| - return true;
|
| +bool DocumentModeOptOutInfoBarDelegate::Accept() {
|
| + UMA_HISTOGRAM_SPARSE_SLOWLY("DocumentModeOptOutInfoBar",
|
| + InfoBarEvent::ACCEPTED);
|
| + Java_DocumentModeOptOutInfoBarDelegate_accept(
|
| + base::android::AttachCurrentThread(), j_delegate_.obj());
|
| +
|
| + // Chrome is restarting in tabbed mode so we don't need to close.
|
| + // The visual difference is that, if we return true here, InfoBar starts to
|
| + // slide down and Chrome is restarted before the sliding is finished.
|
| + return false;
|
| }
|
|
|
| -bool FullscreenInfoBarDelegate::Cancel() {
|
| - Java_FullscreenInfoBarDelegate_onFullscreenCancelled(
|
| +bool DocumentModeOptOutInfoBarDelegate::Cancel() {
|
| + UMA_HISTOGRAM_SPARSE_SLOWLY("DocumentModeOptOutInfoBar",
|
| + InfoBarEvent::DENIED);
|
| + Java_DocumentModeOptOutInfoBarDelegate_cancel(
|
| base::android::AttachCurrentThread(), j_delegate_.obj());
|
| return true;
|
| }
|
|
|