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.
4
5#ifndef CHROME_BROWSER_UI_ANDROID_INFOBARS_INFOBAR_ANDROID_H_
6#define CHROME_BROWSER_UI_ANDROID_INFOBARS_INFOBAR_ANDROID_H_
7
8#include <string>
9
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"
15
16class InfoBarService;
17
18namespace infobars {
19class InfoBarDelegate;
20}
21
22class InfoBarAndroid : public infobars::InfoBar {
23 public:
24
25  // Make sure this set of values is aligned with the java constants defined in
26  // InfoBar.java!
27  enum ActionType {
28    ACTION_NONE = 0,
29    // Confirm infobar
30    ACTION_OK = 1,
31    ACTION_CANCEL = 2,
32    // Translate infobar
33    ACTION_TRANSLATE = 3,
34    ACTION_TRANSLATE_SHOW_ORIGINAL = 4,
35  };
36
37  explicit InfoBarAndroid(scoped_ptr<infobars::InfoBarDelegate> delegate);
38  virtual ~InfoBarAndroid();
39
40  // InfoBar:
41  virtual base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar(
42      JNIEnv* env) = 0;
43
44  void set_java_infobar(const base::android::JavaRef<jobject>& java_info_bar);
45  bool HasSetJavaInfoBar() const;
46
47  // Tells the Java-side counterpart of this InfoBar to point to the replacement
48  // InfoBar instead of this one.
49  void ReassignJavaInfoBar(InfoBarAndroid* replacement);
50
51  virtual void OnLinkClicked(JNIEnv* env, jobject obj) {}
52  void OnButtonClicked(JNIEnv* env,
53                       jobject obj,
54                       jint action,
55                       jstring action_value);
56  void OnCloseButtonClicked(JNIEnv* env, jobject obj);
57
58  void CloseJavaInfoBar();
59
60  // Maps from a Chromium ID (IDR_TRANSLATE) to a enum value that Java code can
61  // translate into a Drawable ID using the ResourceId class.
62  int GetEnumeratedIconId();
63
64  // Acquire the java infobar from a different one.  This is used to do in-place
65  // replacements.
66  virtual void PassJavaInfoBar(InfoBarAndroid* source) {}
67
68 protected:
69  // Derived classes must implement this method to process the corresponding
70  // action.
71  virtual void ProcessButton(int action,
72                             const std::string& action_value) = 0;
73  void CloseInfoBar();
74
75 private:
76  base::android::ScopedJavaGlobalRef<jobject> java_info_bar_;
77
78  DISALLOW_COPY_AND_ASSIGN(InfoBarAndroid);
79};
80
81// Registers the NativeInfoBar's native methods through JNI.
82bool RegisterNativeInfoBar(JNIEnv* env);
83
84#endif  // CHROME_BROWSER_UI_ANDROID_INFOBARS_INFOBAR_ANDROID_H_
85