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