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 #ifndef CHROME_BROWSER_UI_ANDROID_INFOBARS_TRANSLATE_COMPACT_INFOBAR_H_ | 5 #ifndef CHROME_BROWSER_UI_ANDROID_INFOBARS_TRANSLATE_COMPACT_INFOBAR_H_ |
6 #define CHROME_BROWSER_UI_ANDROID_INFOBARS_TRANSLATE_COMPACT_INFOBAR_H_ | 6 #define CHROME_BROWSER_UI_ANDROID_INFOBARS_TRANSLATE_COMPACT_INFOBAR_H_ |
7 | 7 |
8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "chrome/browser/translate/chrome_translate_client.h" | 10 #include "chrome/browser/translate/chrome_translate_client.h" |
11 #include "chrome/browser/ui/android/infobars/infobar_android.h" | 11 #include "chrome/browser/ui/android/infobars/infobar_android.h" |
12 #include "components/translate/content/browser/content_translate_driver.h" | 12 #include "components/translate/core/browser/translate_infobar_delegate.h" |
13 #include "components/translate/core/browser/translate_step.h" | |
14 #include "components/translate/core/common/translate_errors.h" | |
13 | 15 |
14 namespace translate { | 16 namespace translate { |
15 class TranslateInfoBarDelegate; | 17 class TranslateInfoBarDelegate; |
16 } | 18 } |
17 | 19 |
18 class TranslateCompactInfoBar | 20 class TranslateCompactInfoBar |
19 : public InfoBarAndroid, | 21 : public InfoBarAndroid, |
20 public translate::ContentTranslateDriver::Observer { | 22 public translate::TranslateInfoBarDelegate::Responder { |
21 public: | 23 public: |
22 explicit TranslateCompactInfoBar( | 24 explicit TranslateCompactInfoBar( |
23 std::unique_ptr<translate::TranslateInfoBarDelegate> delegate); | 25 std::unique_ptr<translate::TranslateInfoBarDelegate> delegate); |
24 ~TranslateCompactInfoBar() override; | 26 ~TranslateCompactInfoBar() override; |
25 | 27 |
26 // JNI method specific to string settings in translate. | 28 // JNI method specific to string settings in translate. |
27 void ApplyStringTranslateOption( | 29 void ApplyStringTranslateOption( |
28 JNIEnv* env, | 30 JNIEnv* env, |
29 const base::android::JavaParamRef<jobject>& obj, | 31 const base::android::JavaParamRef<jobject>& obj, |
30 int option, | 32 int option, |
31 const base::android::JavaParamRef<jstring>& value); | 33 const base::android::JavaParamRef<jstring>& value); |
32 | 34 |
33 // JNI method specific to boolean settings in translate. | 35 // JNI method specific to boolean settings in translate. |
34 void ApplyBoolTranslateOption(JNIEnv* env, | 36 void ApplyBoolTranslateOption(JNIEnv* env, |
35 const base::android::JavaParamRef<jobject>& obj, | 37 const base::android::JavaParamRef<jobject>& obj, |
36 int option, | 38 int option, |
37 jboolean value); | 39 jboolean value); |
38 | 40 |
39 // Check whether we should automatically trigger "Always Translate". | 41 // Check whether we should automatically trigger "Always Translate". |
40 bool ShouldAutoAlwaysTranslate(); | 42 bool ShouldAutoAlwaysTranslate(); |
41 | 43 |
42 // Check whether we should automatically trigger "Never Translate Language". | 44 // Check whether we should automatically trigger "Never Translate Language". |
43 jboolean ShouldAutoNeverTranslate( | 45 jboolean ShouldAutoNeverTranslate( |
44 JNIEnv* env, | 46 JNIEnv* env, |
45 const base::android::JavaParamRef<jobject>& obj); | 47 const base::android::JavaParamRef<jobject>& obj); |
46 | 48 |
47 // ContentTranslateDriver::Observer implementation. | 49 // TranslateInfoBarDelegate::Responder implementation. |
48 void OnPageTranslated(const std::string& original_lang, | 50 void ActionOnStep(translate::TranslateStep step, |
49 const std::string& translated_lang, | 51 translate::TranslateErrors::Type error_type) override; |
50 translate::TranslateErrors::Type error_type) override; | 52 bool Declined() override; |
51 | 53 |
52 private: | 54 private: |
53 // InfoBarAndroid: | 55 // InfoBarAndroid: |
54 base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar( | 56 base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar( |
55 JNIEnv* env) override; | 57 JNIEnv* env) override; |
56 void ProcessButton(int action) override; | 58 void ProcessButton(int action) override; |
57 void SetJavaInfoBar( | 59 void SetJavaInfoBar( |
58 const base::android::JavaRef<jobject>& java_info_bar) override; | 60 const base::android::JavaRef<jobject>& java_info_bar) override; |
59 | 61 |
60 translate::TranslateInfoBarDelegate* GetDelegate(); | 62 translate::TranslateInfoBarDelegate* GetDelegate(); |
61 translate::ContentTranslateDriver* translate_driver_; | 63 |
64 // Bits for trace user actions. | |
65 unsigned int action_flags; | |
napper
2017/05/19 00:17:50
action_flags_;
Leo
2017/05/19 03:30:23
Acknowledged.
| |
66 | |
67 // Action flags | |
napper
2017/05/19 00:17:50
Add '.' at end of comment
Leo
2017/05/19 03:30:24
Acknowledged.
| |
68 const int FLAG_TRANSLATE = 1 << 0; | |
napper
2017/05/19 00:17:50
Consider making these an enum
Leo
2017/05/19 03:30:24
Done.
| |
69 const int FLAG_REVERT = 1 << 1; | |
70 const int FLAG_ALWAYS_TRANSLATE = 1 << 2; | |
71 const int FLAG_NEVER_LANGUAGE = 1 << 3; | |
72 const int FLAG_NEVER_SITE = 1 << 4; | |
62 | 73 |
63 // If number of consecutive translations is equal to this number, infobar will | 74 // If number of consecutive translations is equal to this number, infobar will |
64 // automatically trigger "Always Translate". | 75 // automatically trigger "Always Translate". |
65 const int kAcceptCountThreshold = 5; | 76 const int kAcceptCountThreshold = 5; |
66 // If number of consecutive denied is equal to this number, infobar will | 77 // If number of consecutive denied is equal to this number, infobar will |
67 // automatically trigger "Never Translate Language". | 78 // automatically trigger "Never Translate Language". |
68 const int kDeniedCountThreshold = 7; | 79 const int kDeniedCountThreshold = 7; |
69 | 80 |
70 DISALLOW_COPY_AND_ASSIGN(TranslateCompactInfoBar); | 81 DISALLOW_COPY_AND_ASSIGN(TranslateCompactInfoBar); |
71 }; | 82 }; |
72 | 83 |
73 // Registers the native methods through JNI. | 84 // Registers the native methods through JNI. |
74 bool RegisterTranslateCompactInfoBar(JNIEnv* env); | 85 bool RegisterTranslateCompactInfoBar(JNIEnv* env); |
75 | 86 |
76 #endif // CHROME_BROWSER_UI_ANDROID_INFOBARS_TRANSLATE_COMPACT_INFOBAR_H_ | 87 #endif // CHROME_BROWSER_UI_ANDROID_INFOBARS_TRANSLATE_COMPACT_INFOBAR_H_ |
OLD | NEW |