| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/android/infobars/translate_compact_infobar.h" | 5 #include "chrome/browser/ui/android/infobars/translate_compact_infobar.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 58 } |
| 59 | 59 |
| 60 void TranslateCompactInfoBar::ProcessButton(int action) { | 60 void TranslateCompactInfoBar::ProcessButton(int action) { |
| 61 if (!owner()) | 61 if (!owner()) |
| 62 return; // We're closing; don't call anything, it might access the owner. | 62 return; // We're closing; don't call anything, it might access the owner. |
| 63 | 63 |
| 64 // TODO(ramyasharma): Handle other button clicks. | 64 // TODO(ramyasharma): Handle other button clicks. |
| 65 translate::TranslateInfoBarDelegate* delegate = GetDelegate(); | 65 translate::TranslateInfoBarDelegate* delegate = GetDelegate(); |
| 66 if (action == InfoBarAndroid::ACTION_TRANSLATE) { | 66 if (action == InfoBarAndroid::ACTION_TRANSLATE) { |
| 67 delegate->Translate(); | 67 delegate->Translate(); |
| 68 if (!delegate->ShouldAlwaysTranslate() && | 68 if (!delegate->ShouldAlwaysTranslate() && ShouldAutoAlwaysTranslate()) { |
| 69 delegate->ShouldAutoAlwaysTranslate()) { | |
| 70 JNIEnv* env = base::android::AttachCurrentThread(); | 69 JNIEnv* env = base::android::AttachCurrentThread(); |
| 71 Java_TranslateCompactInfoBar_setAutoAlwaysTranslate(env, | 70 Java_TranslateCompactInfoBar_setAutoAlwaysTranslate(env, |
| 72 GetJavaInfoBar()); | 71 GetJavaInfoBar()); |
| 73 } | 72 } |
| 74 } else if (action == InfoBarAndroid::ACTION_TRANSLATE_SHOW_ORIGINAL) { | 73 } else if (action == InfoBarAndroid::ACTION_TRANSLATE_SHOW_ORIGINAL) { |
| 75 delegate->RevertTranslation(); | 74 delegate->RevertTranslation(); |
| 76 } else if (action == InfoBarAndroid::ACTION_CANCEL) { | 75 } else if (action == InfoBarAndroid::ACTION_CANCEL) { |
| 77 delegate->TranslationDeclined(); | 76 delegate->TranslationDeclined(); |
| 78 } else { | 77 } else { |
| 79 DCHECK_EQ(InfoBarAndroid::ACTION_NONE, action); | 78 DCHECK_EQ(InfoBarAndroid::ACTION_NONE, action); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 return; // We're closing; don't call anything, it might access the owner. | 139 return; // We're closing; don't call anything, it might access the owner. |
| 141 | 140 |
| 142 DCHECK(translate_driver_); | 141 DCHECK(translate_driver_); |
| 143 JNIEnv* env = base::android::AttachCurrentThread(); | 142 JNIEnv* env = base::android::AttachCurrentThread(); |
| 144 Java_TranslateCompactInfoBar_onPageTranslated(env, GetJavaInfoBar(), | 143 Java_TranslateCompactInfoBar_onPageTranslated(env, GetJavaInfoBar(), |
| 145 error_type); | 144 error_type); |
| 146 } | 145 } |
| 147 | 146 |
| 148 bool TranslateCompactInfoBar::ShouldAutoAlwaysTranslate() { | 147 bool TranslateCompactInfoBar::ShouldAutoAlwaysTranslate() { |
| 149 translate::TranslateInfoBarDelegate* delegate = GetDelegate(); | 148 translate::TranslateInfoBarDelegate* delegate = GetDelegate(); |
| 150 return delegate->ShouldAutoAlwaysTranslate(); | 149 return (delegate->GetTranslationAcceptedCount() == kAcceptCountThreshold); |
| 150 } |
| 151 |
| 152 jboolean TranslateCompactInfoBar::ShouldAutoNeverTranslate( |
| 153 JNIEnv* env, |
| 154 const base::android::JavaParamRef<jobject>& obj) { |
| 155 translate::TranslateInfoBarDelegate* delegate = GetDelegate(); |
| 156 return (delegate->GetTranslationDeniedCount() == kDeniedCountThreshold); |
| 151 } | 157 } |
| 152 | 158 |
| 153 translate::TranslateInfoBarDelegate* TranslateCompactInfoBar::GetDelegate() { | 159 translate::TranslateInfoBarDelegate* TranslateCompactInfoBar::GetDelegate() { |
| 154 return delegate()->AsTranslateInfoBarDelegate(); | 160 return delegate()->AsTranslateInfoBarDelegate(); |
| 155 } | 161 } |
| 156 | 162 |
| 157 // Native JNI methods --------------------------------------------------------- | 163 // Native JNI methods --------------------------------------------------------- |
| 158 | 164 |
| 159 // static | 165 // static |
| 160 bool RegisterTranslateCompactInfoBar(JNIEnv* env) { | 166 bool RegisterTranslateCompactInfoBar(JNIEnv* env) { |
| 161 return RegisterNativesImpl(env); | 167 return RegisterNativesImpl(env); |
| 162 } | 168 } |
| OLD | NEW |