| Index: chrome/browser/infobars/infobar.cc
|
| ===================================================================
|
| --- chrome/browser/infobars/infobar.cc (revision 226624)
|
| +++ chrome/browser/infobars/infobar.cc (working copy)
|
| @@ -12,7 +12,27 @@
|
| #include "chrome/browser/infobars/infobar_service.h"
|
| #include "ui/gfx/animation/slide_animation.h"
|
|
|
| -SkColor GetInfoBarTopColor(InfoBarDelegate::Type infobar_type) {
|
| +InfoBar::InfoBar(scoped_ptr<InfoBarDelegate> delegate)
|
| + : owner_(NULL),
|
| + delegate_(delegate.Pass()),
|
| + container_(NULL),
|
| + animation_(this),
|
| + arrow_height_(0),
|
| + arrow_target_height_(kDefaultArrowTargetHeight),
|
| + arrow_half_width_(0),
|
| + bar_height_(0),
|
| + bar_target_height_(kDefaultBarTargetHeight) {
|
| + DCHECK(delegate_ != NULL);
|
| + animation_.SetTweenType(gfx::Tween::LINEAR);
|
| + delegate_->set_infobar(this);
|
| +}
|
| +
|
| +InfoBar::~InfoBar() {
|
| + DCHECK(!owner_);
|
| +}
|
| +
|
| +// static
|
| +SkColor InfoBar::GetTopColor(InfoBarDelegate::Type infobar_type) {
|
| static const SkColor kWarningBackgroundColorTop =
|
| SkColorSetRGB(255, 242, 183); // Yellow
|
| static const SkColor kPageActionBackgroundColorTop =
|
| @@ -21,7 +41,8 @@
|
| kWarningBackgroundColorTop : kPageActionBackgroundColorTop;
|
| }
|
|
|
| -SkColor GetInfoBarBottomColor(InfoBarDelegate::Type infobar_type) {
|
| +// static
|
| +SkColor InfoBar::GetBottomColor(InfoBarDelegate::Type infobar_type) {
|
| static const SkColor kWarningBackgroundColorBottom =
|
| SkColorSetRGB(250, 230, 145); // Yellow
|
| static const SkColor kPageActionBackgroundColorBottom =
|
| @@ -30,24 +51,13 @@
|
| kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom;
|
| }
|
|
|
| -InfoBar::InfoBar(InfoBarService* owner, InfoBarDelegate* delegate)
|
| - : owner_(owner),
|
| - delegate_(delegate),
|
| - container_(NULL),
|
| - animation_(this),
|
| - arrow_height_(0),
|
| - arrow_target_height_(kDefaultArrowTargetHeight),
|
| - arrow_half_width_(0),
|
| - bar_height_(0),
|
| - bar_target_height_(kDefaultBarTargetHeight) {
|
| - DCHECK(owner_ != NULL);
|
| - DCHECK(delegate_ != NULL);
|
| - animation_.SetTweenType(gfx::Tween::LINEAR);
|
| +void InfoBar::SetOwner(InfoBarService* owner) {
|
| + DCHECK(!owner_);
|
| + owner_ = owner;
|
| + delegate_->StoreActiveEntryUniqueID();
|
| + PlatformSpecificSetOwner();
|
| }
|
|
|
| -InfoBar::~InfoBar() {
|
| -}
|
| -
|
| void InfoBar::Show(bool animate) {
|
| PlatformSpecificShow(animate);
|
| if (animate) {
|
| @@ -88,21 +98,9 @@
|
| MaybeDelete();
|
| }
|
|
|
| -void InfoBar::AnimationProgressed(const gfx::Animation* animation) {
|
| - RecalculateHeights(false);
|
| -}
|
| -
|
| void InfoBar::RemoveSelf() {
|
| - // |owner_| should never be NULL here. If it is, then someone violated what
|
| - // they were supposed to do -- e.g. a ConfirmInfoBarDelegate subclass returned
|
| - // true from Accept() or Cancel() even though the infobar was already closing.
|
| - // In the worst case, if we also switched tabs during that process, then
|
| - // |this| has already been destroyed. But if that's the case, then we're
|
| - // going to deref a garbage |this| pointer here whether we check |owner_| or
|
| - // not, and in other cases (where we're still closing and |this| is valid),
|
| - // checking |owner_| here will avoid a NULL deref.
|
| if (owner_)
|
| - owner_->RemoveInfoBar(delegate_);
|
| + owner_->RemoveInfoBar(this);
|
| }
|
|
|
| void InfoBar::SetBarTargetHeight(int height) {
|
| @@ -112,6 +110,10 @@
|
| }
|
| }
|
|
|
| +void InfoBar::AnimationProgressed(const gfx::Animation* animation) {
|
| + RecalculateHeights(false);
|
| +}
|
| +
|
| int InfoBar::OffsetY(const gfx::Size& prefsize) const {
|
| return arrow_height_ +
|
| std::max((bar_target_height_ - prefsize.height()) / 2, 0) -
|
| @@ -171,10 +173,9 @@
|
| }
|
|
|
| void InfoBar::MaybeDelete() {
|
| - if (!owner_ && delegate_ && (animation_.GetCurrentValue() == 0.0)) {
|
| + if (!owner_ && (animation_.GetCurrentValue() == 0.0)) {
|
| if (container_)
|
| container_->RemoveInfoBar(this);
|
| - delete delegate_;
|
| - delegate_ = NULL;
|
| + delete this;
|
| }
|
| }
|
|
|