| Index: chrome/browser/ui/android/infobars/tabbed_mode_opt_in_infobar_delegate.cc
|
| diff --git a/chrome/browser/ui/android/infobars/tabbed_mode_opt_in_infobar_delegate.cc b/chrome/browser/ui/android/infobars/tabbed_mode_opt_in_infobar_delegate.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2da81573bf3a50c81e30cba05c2b3f632d06ea60
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/android/infobars/tabbed_mode_opt_in_infobar_delegate.cc
|
| @@ -0,0 +1,103 @@
|
| +// Copyright 2015 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/tabbed_mode_opt_in_infobar_delegate.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/grit/generated_resources.h"
|
| +#include "components/infobars/core/infobar.h"
|
| +#include "jni/TabbedModeOptInInfoBarDelegate_jni.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| +
|
| +namespace {
|
| +
|
| +// Keep in sync with the values defined in histograms.xml.
|
| +enum InfoBarEvent {
|
| + SHOWN = 0,
|
| + ACCEPTED,
|
| + DENIED,
|
| + DISMISSED
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +jlong ShowTabbedModeOptInInfoBar(JNIEnv* env,
|
| + const JavaParamRef<jobject>& jcaller,
|
| + const JavaParamRef<jobject>& tab) {
|
| + UMA_HISTOGRAM_SPARSE_SLOWLY("TabbedModeOptInInfoBar", InfoBarEvent::SHOWN);
|
| +
|
| + TabbedModeOptInInfoBarDelegate* delegate = new TabbedModeOptInInfoBarDelegate(
|
| + 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);
|
| +}
|
| +
|
| +// static
|
| +bool TabbedModeOptInInfoBarDelegate::RegisterTabbedModeOptInInfoBarDelegate(
|
| + JNIEnv* env) {
|
| + return RegisterNativesImpl(env);
|
| +}
|
| +
|
| +TabbedModeOptInInfoBarDelegate::TabbedModeOptInInfoBarDelegate(JNIEnv* env,
|
| + jobject obj)
|
| + : ConfirmInfoBarDelegate() {
|
| + j_delegate_.Reset(env, obj);
|
| +}
|
| +
|
| +TabbedModeOptInInfoBarDelegate::~TabbedModeOptInInfoBarDelegate() {
|
| +}
|
| +
|
| +int TabbedModeOptInInfoBarDelegate::GetIconId() const {
|
| + return IDR_ANDROID_INFOBAR_TABBED_MODE_OPT_IN;
|
| +}
|
| +
|
| +bool TabbedModeOptInInfoBarDelegate::ShouldExpire(
|
| + const NavigationDetails& details) const {
|
| + return false;
|
| +}
|
| +
|
| +void TabbedModeOptInInfoBarDelegate::InfoBarDismissed() {
|
| + UMA_HISTOGRAM_SPARSE_SLOWLY("TabbedModeOptInInfoBar",
|
| + InfoBarEvent::DISMISSED);
|
| +}
|
| +
|
| +base::string16 TabbedModeOptInInfoBarDelegate::GetMessageText() const {
|
| + return l10n_util::GetStringUTF16(IDS_TABBED_MODE_OPT_IN_INFOBAR_TEXT);
|
| +}
|
| +
|
| +int TabbedModeOptInInfoBarDelegate::GetButtons() const {
|
| + return BUTTON_OK | BUTTON_CANCEL;
|
| +}
|
| +
|
| +base::string16 TabbedModeOptInInfoBarDelegate::GetButtonLabel(
|
| + InfoBarButton button) const {
|
| + DCHECK(button == BUTTON_OK || button == BUTTON_CANCEL);
|
| + return l10n_util::GetStringUTF16(
|
| + button == BUTTON_OK ? IDS_SHOW : IDS_NO_THANKS);
|
| +}
|
| +
|
| +bool TabbedModeOptInInfoBarDelegate::Accept() {
|
| + UMA_HISTOGRAM_SPARSE_SLOWLY("TabbedModeOptInInfoBar", InfoBarEvent::ACCEPTED);
|
| + Java_TabbedModeOptInInfoBarDelegate_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 TabbedModeOptInInfoBarDelegate::Cancel() {
|
| + UMA_HISTOGRAM_SPARSE_SLOWLY("TabbedModeOptInInfoBar", InfoBarEvent::DENIED);
|
| + Java_TabbedModeOptInInfoBarDelegate_cancel(
|
| + base::android::AttachCurrentThread(), j_delegate_.obj());
|
| + return true;
|
| +}
|
|
|