| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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_TAB_CONTENTS_INFOBAR_DELEGATE_H_ | |
| 6 #define CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "content/browser/tab_contents/infobar_delegate.h" | |
| 10 | |
| 11 // An interface derived from InfoBarDelegate implemented by objects wishing to | |
| 12 // control a LinkInfoBar. | |
| 13 class LinkInfoBarDelegate : public InfoBarDelegate { | |
| 14 public: | |
| 15 // Returns the message string to be displayed in the InfoBar. |link_offset| | |
| 16 // is the position where the link should be inserted. | |
| 17 virtual string16 GetMessageTextWithOffset(size_t* link_offset) const = 0; | |
| 18 | |
| 19 // Returns the text of the link to be displayed. | |
| 20 virtual string16 GetLinkText() const = 0; | |
| 21 | |
| 22 // Called when the Link is clicked. The |disposition| specifies how the | |
| 23 // resulting document should be loaded (based on the event flags present when | |
| 24 // the link was clicked). This function returns true if the InfoBar should be | |
| 25 // closed now or false if it should remain until the user explicitly closes | |
| 26 // it. | |
| 27 virtual bool LinkClicked(WindowOpenDisposition disposition); | |
| 28 | |
| 29 protected: | |
| 30 explicit LinkInfoBarDelegate(TabContents* contents); | |
| 31 virtual ~LinkInfoBarDelegate(); | |
| 32 | |
| 33 private: | |
| 34 // InfoBarDelegate: | |
| 35 virtual InfoBar* CreateInfoBar(); | |
| 36 virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate(); | |
| 37 | |
| 38 DISALLOW_COPY_AND_ASSIGN(LinkInfoBarDelegate); | |
| 39 }; | |
| 40 | |
| 41 // An interface derived from InfoBarDelegate implemented by objects wishing to | |
| 42 // control a ConfirmInfoBar. | |
| 43 class ConfirmInfoBarDelegate : public InfoBarDelegate { | |
| 44 public: | |
| 45 enum InfoBarButton { | |
| 46 BUTTON_NONE = 0, | |
| 47 BUTTON_OK = 1 << 0, | |
| 48 BUTTON_CANCEL = 1 << 1, | |
| 49 }; | |
| 50 | |
| 51 // Returns the message string to be displayed for the InfoBar. | |
| 52 virtual string16 GetMessageText() const = 0; | |
| 53 | |
| 54 // Return the buttons to be shown for this InfoBar. | |
| 55 virtual int GetButtons() const; | |
| 56 | |
| 57 // Return the label for the specified button. The default implementation | |
| 58 // returns "OK" for the OK button and "Cancel" for the Cancel button. | |
| 59 virtual string16 GetButtonLabel(InfoBarButton button) const; | |
| 60 | |
| 61 // Return whether or not the specified button needs elevation. | |
| 62 virtual bool NeedElevation(InfoBarButton button) const; | |
| 63 | |
| 64 // Called when the OK button is pressed. If the function returns true, the | |
| 65 // InfoBarDelegate should be removed from the associated TabContents. | |
| 66 virtual bool Accept(); | |
| 67 | |
| 68 // Called when the Cancel button is pressed. If the function returns true, | |
| 69 // the InfoBarDelegate should be removed from the associated TabContents. | |
| 70 virtual bool Cancel(); | |
| 71 | |
| 72 // Returns the text of the link to be displayed, if any. Otherwise returns | |
| 73 // and empty string. | |
| 74 virtual string16 GetLinkText(); | |
| 75 | |
| 76 // Called when the Link is clicked. The |disposition| specifies how the | |
| 77 // resulting document should be loaded (based on the event flags present when | |
| 78 // the link was clicked). This function returns true if the InfoBar should be | |
| 79 // closed now or false if it should remain until the user explicitly closes | |
| 80 // it. | |
| 81 // Will only be called if GetLinkText() returns non-empty string. | |
| 82 virtual bool LinkClicked(WindowOpenDisposition disposition); | |
| 83 | |
| 84 protected: | |
| 85 explicit ConfirmInfoBarDelegate(TabContents* contents); | |
| 86 virtual ~ConfirmInfoBarDelegate(); | |
| 87 | |
| 88 private: | |
| 89 // InfoBarDelegate: | |
| 90 virtual InfoBar* CreateInfoBar(); | |
| 91 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; | |
| 92 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate(); | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBarDelegate); | |
| 95 }; | |
| 96 | |
| 97 // Simple implementations for common use cases --------------------------------- | |
| 98 | |
| 99 class SimpleAlertInfoBarDelegate : public ConfirmInfoBarDelegate { | |
| 100 public: | |
| 101 SimpleAlertInfoBarDelegate(TabContents* contents, | |
| 102 SkBitmap* icon, // May be NULL. | |
| 103 const string16& message, | |
| 104 bool auto_expire); | |
| 105 | |
| 106 private: | |
| 107 virtual ~SimpleAlertInfoBarDelegate(); | |
| 108 | |
| 109 // ConfirmInfoBarDelegate: | |
| 110 virtual bool ShouldExpire( | |
| 111 const NavigationController::LoadCommittedDetails& details) const; | |
| 112 virtual void InfoBarClosed(); | |
| 113 virtual SkBitmap* GetIcon() const; | |
| 114 virtual string16 GetMessageText() const; | |
| 115 virtual int GetButtons() const; | |
| 116 | |
| 117 SkBitmap* icon_; | |
| 118 string16 message_; | |
| 119 bool auto_expire_; // Should it expire automatically on navigation? | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(SimpleAlertInfoBarDelegate); | |
| 122 }; | |
| 123 | |
| 124 #endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ | |
| OLD | NEW |