| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ | 6 #define CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace gfx { | 22 namespace gfx { |
| 23 class Image; | 23 class Image; |
| 24 } | 24 } |
| 25 | 25 |
| 26 // An interface implemented by objects wishing to control an InfoBar. | 26 // An interface implemented by objects wishing to control an InfoBar. |
| 27 // Implementing this interface is not sufficient to use an InfoBar, since it | 27 // Implementing this interface is not sufficient to use an InfoBar, since it |
| 28 // does not map to a specific InfoBar type. Instead, you must implement either | 28 // does not map to a specific InfoBar type. Instead, you must implement either |
| 29 // LinkInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own | 29 // LinkInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own |
| 30 // delegate for your own InfoBar variety. | 30 // delegate for your own InfoBar variety. |
| 31 // | |
| 32 // --- WARNING --- | |
| 33 // When creating your InfoBarDelegate subclass, it is recommended that you | |
| 34 // design it such that you instantiate a brand new delegate for every call to | |
| 35 // AddInfoBar, rather than re-using/sharing a delegate object. Otherwise, | |
| 36 // you need to consider the fact that more than one InfoBar instance can exist | |
| 37 // and reference the same delegate -- even though it is also true that we only | |
| 38 // ever fully show one infobar (they don't stack). The dual-references occur | |
| 39 // because a second InfoBar can be added while the first one is in the process | |
| 40 // of closing (the animations). This can cause problems because when the first | |
| 41 // one does finally fully close InfoBarDelegate::InfoBarClosed() is called, | |
| 42 // and the delegate is free to clean itself up or reset state, which may have | |
| 43 // fatal consequences for the InfoBar that was in the process of opening (or is | |
| 44 // now fully opened) -- it is referencing a delegate that may not even exist | |
| 45 // anymore. | |
| 46 // As such, it is generally much safer to dedicate a delegate instance to | |
| 47 // AddInfoBar! | |
| 48 class InfoBarDelegate { | 31 class InfoBarDelegate { |
| 49 public: | 32 public: |
| 50 // The type of the infobar. It controls its appearance, such as its background | 33 // The type of the infobar. It controls its appearance, such as its background |
| 51 // color. | 34 // color. |
| 52 enum Type { | 35 enum Type { |
| 53 WARNING_TYPE, | 36 WARNING_TYPE, |
| 54 PAGE_ACTION_TYPE, | 37 PAGE_ACTION_TYPE, |
| 55 }; | 38 }; |
| 56 | 39 |
| 57 virtual ~InfoBarDelegate(); | 40 virtual ~InfoBarDelegate(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 70 | 53 |
| 71 // Returns true if the InfoBar should be closed automatically after the page | 54 // Returns true if the InfoBar should be closed automatically after the page |
| 72 // is navigated. The default behavior is to return true if the page is | 55 // is navigated. The default behavior is to return true if the page is |
| 73 // navigated somewhere else or reloaded. | 56 // navigated somewhere else or reloaded. |
| 74 virtual bool ShouldExpire( | 57 virtual bool ShouldExpire( |
| 75 const NavigationController::LoadCommittedDetails& details) const; | 58 const NavigationController::LoadCommittedDetails& details) const; |
| 76 | 59 |
| 77 // Called when the user clicks on the close button to dismiss the infobar. | 60 // Called when the user clicks on the close button to dismiss the infobar. |
| 78 virtual void InfoBarDismissed(); | 61 virtual void InfoBarDismissed(); |
| 79 | 62 |
| 80 // Called after the InfoBar is closed. The delegate is free to delete itself | 63 // Called after the InfoBar is closed. Deletes |this|. |
| 81 // at this point. | 64 // TODO(pkasting): Get rid of this and delete delegates directly. |
| 82 virtual void InfoBarClosed(); | 65 void InfoBarClosed(); |
| 83 | 66 |
| 84 // Return the icon to be shown for this InfoBar. If the returned Image is | 67 // Return the icon to be shown for this InfoBar. If the returned Image is |
| 85 // NULL, no icon is shown. | 68 // NULL, no icon is shown. |
| 86 virtual gfx::Image* GetIcon() const; | 69 virtual gfx::Image* GetIcon() const; |
| 87 | 70 |
| 88 // Returns the type of the infobar. The type determines the appearance (such | 71 // Returns the type of the infobar. The type determines the appearance (such |
| 89 // as background color) of the infobar. | 72 // as background color) of the infobar. |
| 90 virtual Type GetInfoBarType() const; | 73 virtual Type GetInfoBarType() const; |
| 91 | 74 |
| 92 // Type-checking downcast routines: | 75 // Type-checking downcast routines: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 110 | 93 |
| 111 private: | 94 private: |
| 112 // The unique id of the active NavigationEntry of the TabContents that we were | 95 // The unique id of the active NavigationEntry of the TabContents that we were |
| 113 // opened for. Used to help expire on navigations. | 96 // opened for. Used to help expire on navigations. |
| 114 int contents_unique_id_; | 97 int contents_unique_id_; |
| 115 | 98 |
| 116 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); | 99 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); |
| 117 }; | 100 }; |
| 118 | 101 |
| 119 #endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ | 102 #endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ |
| OLD | NEW |