Home | History | Annotate | Download | only in infobars
      1 // Copyright (c) 2012 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_INFOBARS_INFOBAR_DELEGATE_H_
      6 #define CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/strings/string16.h"
     10 #include "chrome/browser/infobars/infobar_service.h"
     11 #include "ui/base/window_open_disposition.h"
     12 
     13 class AutoLoginInfoBarDelegate;
     14 class ConfirmInfoBarDelegate;
     15 class ExtensionInfoBarDelegate;
     16 class InfoBar;
     17 class InsecureContentInfoBarDelegate;
     18 class MediaStreamInfoBarDelegate;
     19 class PopupBlockedInfoBarDelegate;
     20 class RegisterProtocolHandlerInfoBarDelegate;
     21 class ScreenCaptureInfoBarDelegate;
     22 class ThemeInstalledInfoBarDelegate;
     23 class ThreeDAPIInfoBarDelegate;
     24 class TranslateInfoBarDelegate;
     25 
     26 namespace gfx {
     27 class Image;
     28 }
     29 
     30 // An interface implemented by objects wishing to control an InfoBar.
     31 // Implementing this interface is not sufficient to use an InfoBar, since it
     32 // does not map to a specific InfoBar type. Instead, you must implement
     33 // ConfirmInfoBarDelegate, or override with your own delegate for your own
     34 // InfoBar variety.
     35 class InfoBarDelegate {
     36  public:
     37   // The type of the infobar. It controls its appearance, such as its background
     38   // color.
     39   enum Type {
     40     WARNING_TYPE,
     41     PAGE_ACTION_TYPE,
     42   };
     43 
     44   enum InfoBarAutomationType {
     45     CONFIRM_INFOBAR,
     46     PASSWORD_INFOBAR,
     47     RPH_INFOBAR,
     48     UNKNOWN_INFOBAR,
     49   };
     50 
     51   // Value to use when the InfoBar has no icon to show.
     52   static const int kNoIconID;
     53 
     54   // Called when the InfoBar that owns this delegate is being destroyed.  At
     55   // this point nothing is visible onscreen.
     56   virtual ~InfoBarDelegate();
     57 
     58   virtual InfoBarAutomationType GetInfoBarAutomationType() const;
     59 
     60   // Returns true if the supplied |delegate| is equal to this one. Equality is
     61   // left to the implementation to define. This function is called by the
     62   // InfoBarService when determining whether or not a delegate should be
     63   // added because a matching one already exists. If this function returns true,
     64   // the InfoBarService will not add the new delegate because it considers
     65   // one to already be present.
     66   virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
     67 
     68   // Returns true if the InfoBar should be closed automatically after the page
     69   // is navigated. By default this returns true if the navigation is to a new
     70   // page (not including reloads).  Subclasses wishing to change this behavior
     71   // can override either this function or ShouldExpireInternal(), depending on
     72   // what level of control they need.
     73   virtual bool ShouldExpire(const content::LoadCommittedDetails& details) const;
     74 
     75   // Called when the user clicks on the close button to dismiss the infobar.
     76   virtual void InfoBarDismissed();
     77 
     78   // Return the resource ID of the icon to be shown for this InfoBar.  If the
     79   // value is equal to |kNoIconID|, no icon is shown.
     80   virtual int GetIconID() const;
     81 
     82   // Returns the type of the infobar.  The type determines the appearance (such
     83   // as background color) of the infobar.
     84   virtual Type GetInfoBarType() const;
     85 
     86   // Type-checking downcast routines:
     87   virtual AutoLoginInfoBarDelegate* AsAutoLoginInfoBarDelegate();
     88   virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate();
     89   virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate();
     90   virtual InsecureContentInfoBarDelegate* AsInsecureContentInfoBarDelegate();
     91   virtual MediaStreamInfoBarDelegate* AsMediaStreamInfoBarDelegate();
     92   virtual PopupBlockedInfoBarDelegate* AsPopupBlockedInfoBarDelegate();
     93   virtual RegisterProtocolHandlerInfoBarDelegate*
     94       AsRegisterProtocolHandlerInfoBarDelegate();
     95   virtual ScreenCaptureInfoBarDelegate* AsScreenCaptureInfoBarDelegate();
     96   virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate();
     97   virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate();
     98   virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate();
     99 
    100   void set_infobar(InfoBar* infobar) { infobar_ = infobar; }
    101 
    102   // Store the unique id for the active entry in our WebContents, to be used
    103   // later upon navigation to determine if this InfoBarDelegate should be
    104   // expired.
    105   void StoreActiveEntryUniqueID();
    106 
    107   // Return the icon to be shown for this InfoBar. If the returned Image is
    108   // empty, no icon is shown.
    109   virtual gfx::Image GetIcon() const;
    110 
    111   // This trivial getter is defined out-of-line in order to avoid needing to
    112   // #include infobar.h, which would lead to circular #includes.
    113   content::WebContents* web_contents();
    114 
    115  protected:
    116   InfoBarDelegate();
    117 
    118   // Returns true if the navigation is to a new URL or a reload occured.
    119   virtual bool ShouldExpireInternal(
    120       const content::LoadCommittedDetails& details) const;
    121 
    122   int contents_unique_id() const { return contents_unique_id_; }
    123   InfoBar* infobar() { return infobar_; }
    124 
    125  private:
    126   // The unique id of the active NavigationEntry of the WebContents that we were
    127   // opened for. Used to help expire on navigations.
    128   int contents_unique_id_;
    129 
    130   // The InfoBar associated with us.
    131   InfoBar* infobar_;
    132 
    133   DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate);
    134 };
    135 
    136 #endif  // CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_
    137