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