| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 void TranslateCompactInfoBar::ProcessButton(int action) { | 63 void TranslateCompactInfoBar::ProcessButton(int action) { |
| 64 if (!owner()) | 64 if (!owner()) |
| 65 return; // We're closing; don't call anything, it might access the owner. | 65 return; // We're closing; don't call anything, it might access the owner. |
| 66 | 66 |
| 67 // TODO(ramyasharma): Handle other button clicks. | 67 // TODO(ramyasharma): Handle other button clicks. |
| 68 translate::TranslateInfoBarDelegate* delegate = GetDelegate(); | 68 translate::TranslateInfoBarDelegate* delegate = GetDelegate(); |
| 69 if (action == InfoBarAndroid::ACTION_TRANSLATE) { | 69 if (action == InfoBarAndroid::ACTION_TRANSLATE) { |
| 70 delegate->Translate(); | 70 delegate->Translate(); |
| 71 if (!delegate->ShouldAlwaysTranslate() && | 71 if (!delegate->ShouldAlwaysTranslate() && ShouldAutoAlwaysTranslate()) { |
| 72 delegate->ShouldAutoAlwaysTranslate()) { | |
| 73 JNIEnv* env = base::android::AttachCurrentThread(); | 72 JNIEnv* env = base::android::AttachCurrentThread(); |
| 74 Java_TranslateCompactInfoBar_setAutoAlwaysTranslate(env, | 73 Java_TranslateCompactInfoBar_setAutoAlwaysTranslate(env, |
| 75 GetJavaInfoBar()); | 74 GetJavaInfoBar()); |
| 76 } | 75 } |
| 77 } else if (action == InfoBarAndroid::ACTION_TRANSLATE_SHOW_ORIGINAL) { | 76 } else if (action == InfoBarAndroid::ACTION_TRANSLATE_SHOW_ORIGINAL) { |
| 78 delegate->RevertTranslation(); | 77 delegate->RevertTranslation(); |
| 79 } else if (action == InfoBarAndroid::ACTION_CANCEL) { | 78 } else if (action == InfoBarAndroid::ACTION_CANCEL) { |
| 80 delegate->TranslationDeclined(); | 79 delegate->TranslationDeclined(); |
| 81 } else { | 80 } else { |
| 82 DCHECK_EQ(InfoBarAndroid::ACTION_NONE, action); | 81 DCHECK_EQ(InfoBarAndroid::ACTION_NONE, action); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 return; // We're closing; don't call anything, it might access the owner. | 142 return; // We're closing; don't call anything, it might access the owner. |
| 144 | 143 |
| 145 DCHECK(translate_driver_); | 144 DCHECK(translate_driver_); |
| 146 JNIEnv* env = base::android::AttachCurrentThread(); | 145 JNIEnv* env = base::android::AttachCurrentThread(); |
| 147 Java_TranslateCompactInfoBar_onPageTranslated(env, GetJavaInfoBar(), | 146 Java_TranslateCompactInfoBar_onPageTranslated(env, GetJavaInfoBar(), |
| 148 error_type); | 147 error_type); |
| 149 } | 148 } |
| 150 | 149 |
| 151 bool TranslateCompactInfoBar::ShouldAutoAlwaysTranslate() { | 150 bool TranslateCompactInfoBar::ShouldAutoAlwaysTranslate() { |
| 152 translate::TranslateInfoBarDelegate* delegate = GetDelegate(); | 151 translate::TranslateInfoBarDelegate* delegate = GetDelegate(); |
| 153 return delegate->ShouldAutoAlwaysTranslate(); | 152 return (delegate->GetTranslationAcceptedCount() == kAcceptCountThreshold); |
| 153 } |
| 154 |
| 155 jboolean TranslateCompactInfoBar::ShouldAutoNeverTranslate( |
| 156 JNIEnv* env, |
| 157 const base::android::JavaParamRef<jobject>& obj) { |
| 158 translate::TranslateInfoBarDelegate* delegate = GetDelegate(); |
| 159 return (delegate->GetTranslationDeniedCount() == kDeniedCountThreshold); |
| 154 } | 160 } |
| 155 | 161 |
| 156 translate::TranslateInfoBarDelegate* TranslateCompactInfoBar::GetDelegate() { | 162 translate::TranslateInfoBarDelegate* TranslateCompactInfoBar::GetDelegate() { |
| 157 return delegate()->AsTranslateInfoBarDelegate(); | 163 return delegate()->AsTranslateInfoBarDelegate(); |
| 158 } | 164 } |
| 159 | 165 |
| 160 // Native JNI methods --------------------------------------------------------- | 166 // Native JNI methods --------------------------------------------------------- |
| 161 | 167 |
| 162 // static | 168 // static |
| 163 bool RegisterTranslateCompactInfoBar(JNIEnv* env) { | 169 bool RegisterTranslateCompactInfoBar(JNIEnv* env) { |
| 164 return RegisterNativesImpl(env); | 170 return RegisterNativesImpl(env); |
| 165 } | 171 } |
| OLD | NEW |