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_CONFIRM_INFOBAR_DELEGATE_H_
      6 #define CHROME_BROWSER_INFOBARS_CONFIRM_INFOBAR_DELEGATE_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "base/strings/string16.h"
     10 #include "chrome/browser/infobars/infobar_delegate.h"
     11 
     12 class InfoBar;
     13 
     14 // An interface derived from InfoBarDelegate implemented by objects wishing to
     15 // control a ConfirmInfoBar.
     16 class ConfirmInfoBarDelegate : public InfoBarDelegate {
     17  public:
     18   enum InfoBarButton {
     19     BUTTON_NONE   = 0,
     20     BUTTON_OK     = 1 << 0,
     21     BUTTON_CANCEL = 1 << 1,
     22   };
     23 
     24   virtual ~ConfirmInfoBarDelegate();
     25 
     26   // Returns the InfoBar type to be displayed for the InfoBar.
     27   virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE;
     28 
     29   // Returns the message string to be displayed for the InfoBar.
     30   virtual base::string16 GetMessageText() const = 0;
     31 
     32   // Return the buttons to be shown for this InfoBar.
     33   virtual int GetButtons() const;
     34 
     35   // Return the label for the specified button. The default implementation
     36   // returns "OK" for the OK button and "Cancel" for the Cancel button.
     37   virtual base::string16 GetButtonLabel(InfoBarButton button) const;
     38 
     39   // Return whether or not the specified button needs elevation.
     40   virtual bool NeedElevation(InfoBarButton button) const;
     41 
     42   // Called when the OK button is pressed. If this function returns true, the
     43   // infobar is then immediately closed. Subclasses MUST NOT return true if in
     44   // handling this call something triggers the infobar to begin closing.
     45   virtual bool Accept();
     46 
     47   // Called when the Cancel button is pressed. If this function returns true,
     48   // the infobar is then immediately closed. Subclasses MUST NOT return true if
     49   // in handling this call something triggers the infobar to begin closing.
     50   virtual bool Cancel();
     51 
     52   // Returns the text of the link to be displayed, if any. Otherwise returns
     53   // and empty string.
     54   virtual base::string16 GetLinkText() const;
     55 
     56   // Called when the Link (if any) is clicked. The |disposition| specifies how
     57   // the resulting document should be loaded (based on the event flags present
     58   // when the link was clicked). If this function returns true, the infobar is
     59   // then immediately closed. Subclasses MUST NOT return true if in handling
     60   // this call something triggers the infobar to begin closing.
     61   virtual bool LinkClicked(WindowOpenDisposition disposition);
     62 
     63  protected:
     64   ConfirmInfoBarDelegate();
     65 
     66   // Returns a confirm infobar that owns |delegate|.
     67   static scoped_ptr<InfoBar> CreateInfoBar(
     68       scoped_ptr<ConfirmInfoBarDelegate> delegate);
     69 
     70   virtual bool ShouldExpireInternal(
     71       const content::LoadCommittedDetails& details) const OVERRIDE;
     72 
     73  private:
     74   // InfoBarDelegate:
     75   virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE;
     76   virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate() OVERRIDE;
     77 
     78   DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBarDelegate);
     79 };
     80 
     81 #endif  // CHROME_BROWSER_INFOBARS_CONFIRM_INFOBAR_DELEGATE_H_
     82