| 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_UI_COCOA_INFOBARS_INFOBAR_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_H_ | 6 #define CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/logging.h" // for DCHECK | 9 #include "base/logging.h" // for DCHECK |
| 10 | 10 |
| 11 #if defined(__OBJC__) |
| 11 @class InfoBarController; | 12 @class InfoBarController; |
| 13 #else |
| 14 class InfoBarController; |
| 15 #endif |
| 12 | 16 |
| 13 // A C++ wrapper around an Objective-C InfoBarController. This class | 17 // A C++ wrapper around an Objective-C InfoBarController. This class |
| 14 // exists solely to be the return value for InfoBarDelegate::CreateInfoBar(), | 18 // exists solely to be the return value for InfoBarDelegate::CreateInfoBar(), |
| 15 // as defined in chrome/browser/tab_contents/confirm_infobar_delegate.h. This | 19 // as defined in chrome/browser/tab_contents/confirm_infobar_delegate.h. This |
| 16 // class would be analogous to the various bridge classes we already | 20 // class would be analogous to the various bridge classes we already |
| 17 // have, but since there is no pre-defined InfoBar interface, it is | 21 // have, but since there is no pre-defined InfoBar interface, it is |
| 18 // easier to simply throw away this object and deal with the | 22 // easier to simply throw away this object and deal with the |
| 19 // controller directly rather than pass messages through a bridge. | 23 // controller directly rather than pass messages through a bridge. |
| 20 // | 24 // |
| 21 // Callers should delete the returned InfoBar immediately after | 25 // Callers should delete the returned InfoBar immediately after |
| 22 // calling CreateInfoBar(), as the returned InfoBar* object is not | 26 // calling CreateInfoBar(), as the returned InfoBar* object is not |
| 23 // pointed to by anyone. Expected usage: | 27 // pointed to by anyone. Expected usage: |
| 24 // | 28 // |
| 25 // scoped_ptr<InfoBar> infobar(delegate->CreateInfoBar()); | 29 // scoped_ptr<InfoBar> infobar(delegate->CreateInfoBar()); |
| 26 // InfoBarController* controller = infobar->controller(); | 30 // InfoBarController* controller = infobar->controller(); |
| 27 // // Do something with the controller, and save a pointer so it can be | 31 // // Do something with the controller, and save a pointer so it can be |
| 28 // // deleted later. |infobar| will be deleted automatically. | 32 // // deleted later. |infobar| will be deleted automatically. |
| 29 | 33 |
| 30 class InfoBar { | 34 class InfoBar { |
| 31 public: | 35 public: |
| 32 InfoBar(InfoBarController* controller) { | 36 InfoBar(InfoBarController* controller, InfoBarDelegate* delegate) |
| 37 : controller_(controller), delegate_(delegate) { |
| 33 DCHECK(controller); | 38 DCHECK(controller); |
| 34 controller_ = controller; | 39 DCHECK(delegate); |
| 35 } | 40 } |
| 36 | 41 |
| 37 InfoBarController* controller() { | 42 InfoBarController* controller() { |
| 38 return controller_; | 43 return controller_; |
| 39 } | 44 } |
| 40 | 45 |
| 46 InfoBarDelegate* delegate() { |
| 47 return delegate_; |
| 48 } |
| 49 |
| 41 private: | 50 private: |
| 42 // Pointer to the infobar controller. Is never null. | 51 // Pointer to the infobar controller. Is never null. |
| 43 InfoBarController* controller_; // weak | 52 InfoBarController* controller_; // weak |
| 53 InfoBarDelegate* delegate_; |
| 44 | 54 |
| 45 DISALLOW_COPY_AND_ASSIGN(InfoBar); | 55 DISALLOW_COPY_AND_ASSIGN(InfoBar); |
| 46 }; | 56 }; |
| 47 | 57 |
| 48 #endif // CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_H_ | 58 #endif // CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_H_ |
| OLD | NEW |