| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/android/infobars/tabbed_mode_opt_in_infobar_delegate
.h" |
| 6 |
| 7 #include "base/metrics/sparse_histogram.h" |
| 8 #include "chrome/browser/android/android_theme_resources.h" |
| 9 #include "chrome/browser/android/tab_android.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/infobars/core/infobar.h" |
| 13 #include "jni/TabbedModeOptInInfoBarDelegate_jni.h" |
| 14 #include "ui/base/l10n/l10n_util.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 // Keep in sync with the values defined in histograms.xml. |
| 19 enum InfoBarEvent { |
| 20 SHOWN = 0, |
| 21 ACCEPTED, |
| 22 DENIED, |
| 23 DISMISSED |
| 24 }; |
| 25 |
| 26 } // namespace |
| 27 |
| 28 // static |
| 29 jlong ShowTabbedModeOptInInfoBar(JNIEnv* env, |
| 30 const JavaParamRef<jobject>& jcaller, |
| 31 const JavaParamRef<jobject>& tab) { |
| 32 UMA_HISTOGRAM_SPARSE_SLOWLY("TabbedModeOptInInfoBar", InfoBarEvent::SHOWN); |
| 33 |
| 34 TabbedModeOptInInfoBarDelegate* delegate = new TabbedModeOptInInfoBarDelegate( |
| 35 env, jcaller); |
| 36 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 37 TabAndroid::GetNativeTab(env, tab)->web_contents()); |
| 38 infobar_service->AddInfoBar( |
| 39 infobar_service->CreateConfirmInfoBar(make_scoped_ptr(delegate))); |
| 40 return reinterpret_cast<intptr_t>(delegate); |
| 41 } |
| 42 |
| 43 // static |
| 44 bool TabbedModeOptInInfoBarDelegate::RegisterTabbedModeOptInInfoBarDelegate( |
| 45 JNIEnv* env) { |
| 46 return RegisterNativesImpl(env); |
| 47 } |
| 48 |
| 49 TabbedModeOptInInfoBarDelegate::TabbedModeOptInInfoBarDelegate(JNIEnv* env, |
| 50 jobject obj) |
| 51 : ConfirmInfoBarDelegate() { |
| 52 j_delegate_.Reset(env, obj); |
| 53 } |
| 54 |
| 55 TabbedModeOptInInfoBarDelegate::~TabbedModeOptInInfoBarDelegate() { |
| 56 } |
| 57 |
| 58 int TabbedModeOptInInfoBarDelegate::GetIconId() const { |
| 59 return IDR_ANDROID_INFOBAR_TABBED_MODE_OPT_IN; |
| 60 } |
| 61 |
| 62 bool TabbedModeOptInInfoBarDelegate::ShouldExpire( |
| 63 const NavigationDetails& details) const { |
| 64 return false; |
| 65 } |
| 66 |
| 67 void TabbedModeOptInInfoBarDelegate::InfoBarDismissed() { |
| 68 UMA_HISTOGRAM_SPARSE_SLOWLY("TabbedModeOptInInfoBar", |
| 69 InfoBarEvent::DISMISSED); |
| 70 } |
| 71 |
| 72 base::string16 TabbedModeOptInInfoBarDelegate::GetMessageText() const { |
| 73 return l10n_util::GetStringUTF16(IDS_TABBED_MODE_OPT_IN_INFOBAR_TEXT); |
| 74 } |
| 75 |
| 76 int TabbedModeOptInInfoBarDelegate::GetButtons() const { |
| 77 return BUTTON_OK | BUTTON_CANCEL; |
| 78 } |
| 79 |
| 80 base::string16 TabbedModeOptInInfoBarDelegate::GetButtonLabel( |
| 81 InfoBarButton button) const { |
| 82 DCHECK(button == BUTTON_OK || button == BUTTON_CANCEL); |
| 83 return l10n_util::GetStringUTF16( |
| 84 button == BUTTON_OK ? IDS_SHOW : IDS_NO_THANKS); |
| 85 } |
| 86 |
| 87 bool TabbedModeOptInInfoBarDelegate::Accept() { |
| 88 UMA_HISTOGRAM_SPARSE_SLOWLY("TabbedModeOptInInfoBar", InfoBarEvent::ACCEPTED); |
| 89 Java_TabbedModeOptInInfoBarDelegate_accept( |
| 90 base::android::AttachCurrentThread(), j_delegate_.obj()); |
| 91 |
| 92 // Chrome is restarting in tabbed mode so we don't need to close. |
| 93 // The visual difference is that, if we return true here, InfoBar starts to |
| 94 // slide down and Chrome is restarted before the sliding is finished. |
| 95 return false; |
| 96 } |
| 97 |
| 98 bool TabbedModeOptInInfoBarDelegate::Cancel() { |
| 99 UMA_HISTOGRAM_SPARSE_SLOWLY("TabbedModeOptInInfoBar", InfoBarEvent::DENIED); |
| 100 Java_TabbedModeOptInInfoBarDelegate_cancel( |
| 101 base::android::AttachCurrentThread(), j_delegate_.obj()); |
| 102 return true; |
| 103 } |
| OLD | NEW |