Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / android / infobars / infobar_android.h
blobbf2f9cca0437fa90d995bececd522d2f03bf63bf
1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_UI_ANDROID_INFOBARS_INFOBAR_ANDROID_H_
6 #define CHROME_BROWSER_UI_ANDROID_INFOBARS_INFOBAR_ANDROID_H_
8 #include <string>
10 #include "base/android/jni_weak_ref.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "components/infobars/core/infobar.h"
16 class InfoBarService;
18 namespace infobars {
19 class InfoBarDelegate;
22 class InfoBarAndroid : public infobars::InfoBar {
23 public:
25 // A Java counterpart will be generated for this enum.
26 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.infobar
27 // GENERATED_JAVA_PREFIX_TO_STRIP: ACTION_
28 enum ActionType {
29 ACTION_NONE = 0,
30 // Confirm infobar
31 ACTION_OK = 1,
32 ACTION_CANCEL = 2,
33 // Translate infobar
34 ACTION_TRANSLATE = 3,
35 ACTION_TRANSLATE_SHOW_ORIGINAL = 4,
36 // Download overwrite infobar
37 ACTION_OVERWRITE = 5,
38 ACTION_CREATE_NEW_FILE = 6,
41 explicit InfoBarAndroid(scoped_ptr<infobars::InfoBarDelegate> delegate);
42 ~InfoBarAndroid() override;
44 // InfoBar:
45 virtual base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar(
46 JNIEnv* env) = 0;
48 virtual void SetJavaInfoBar(
49 const base::android::JavaRef<jobject>& java_info_bar);
50 jobject GetJavaInfoBar();
51 bool HasSetJavaInfoBar() const;
53 // Tells the Java-side counterpart of this InfoBar to point to the replacement
54 // InfoBar instead of this one.
55 void ReassignJavaInfoBar(InfoBarAndroid* replacement);
57 virtual void OnLinkClicked(JNIEnv* env, jobject obj) {}
58 void OnButtonClicked(JNIEnv* env,
59 jobject obj,
60 jint action,
61 jstring action_value);
62 void OnCloseButtonClicked(JNIEnv* env, jobject obj);
64 void CloseJavaInfoBar();
66 // Maps from a Chromium ID (IDR_TRANSLATE) to a enum value that Java code can
67 // translate into a Drawable ID using the ResourceId class.
68 int GetEnumeratedIconId();
70 // Acquire the java infobar from a different one. This is used to do in-place
71 // replacements.
72 virtual void PassJavaInfoBar(InfoBarAndroid* source) {}
74 protected:
75 // Derived classes must implement this method to process the corresponding
76 // action.
77 virtual void ProcessButton(int action,
78 const std::string& action_value) = 0;
79 void CloseInfoBar();
80 InfoBarAndroid* infobar_android() { return this; }
82 private:
83 base::android::ScopedJavaGlobalRef<jobject> java_info_bar_;
85 DISALLOW_COPY_AND_ASSIGN(InfoBarAndroid);
88 // Registers the NativeInfoBar's native methods through JNI.
89 bool RegisterNativeInfoBar(JNIEnv* env);
91 #endif // CHROME_BROWSER_UI_ANDROID_INFOBARS_INFOBAR_ANDROID_H_