Chromium Code Reviews| 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..10ff1512ebe7388ea3c84ceec70bdcc60efafaf6 |
| --- /dev/null |
| +++ b/chrome/browser/ui/android/infobars/tabbed_mode_opt_in_infobar_delegate.cc |
| @@ -0,0 +1,93 @@ |
| +// 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/user_metrics.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" |
| + |
| +// static |
| +jlong LaunchTabbedModeOptInInfoBar(JNIEnv* env, |
| + const JavaParamRef<jobject>& jcaller, |
| + const JavaParamRef<jobject>& tab) { |
| + base::RecordAction(base::UserMetricsAction("TabbedModeOptInInfoBar_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() { |
| + base::RecordAction( |
| + base::UserMetricsAction("TabbedModeOptInInfoBar_UserDismissed")); |
| +} |
| + |
| +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_OK : IDS_NO_THANKS); |
| +} |
| + |
| +bool TabbedModeOptInInfoBarDelegate::Accept() { |
| + base::RecordAction( |
| + base::UserMetricsAction("TabbedModeOptInInfoBar_UserOptIn")); |
| + Java_TabbedModeOptInInfoBarDelegate_accept( |
| + base::android::AttachCurrentThread(), j_delegate_.obj()); |
| + |
| + // Chrome is restarting as tabbed mode so we don't need to close. |
|
gone
2015/11/17 23:18:16
as tabbed mode -> in tabbed mode
Kibeom Kim (inactive)
2015/11/20 11:44:15
Done.
|
| + // The visual difference is that, if we return true here, infobar starts to |
| + // slide down and Chrome is restarted before the sliding is finished. |
|
gone
2015/11/17 23:18:16
infobar -> InfoBar.
Kibeom Kim (inactive)
2015/11/20 11:44:15
Done.
|
| + return false; |
| +} |
| + |
| +bool TabbedModeOptInInfoBarDelegate::Cancel() { |
| + base::RecordAction( |
| + base::UserMetricsAction("TabbedModeOptInInfoBar_UserDenied")); |
| + Java_TabbedModeOptInInfoBarDelegate_cancel( |
| + base::android::AttachCurrentThread(), j_delegate_.obj()); |
| + return true; |
| +} |