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