| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/infobars/infobar_delegate.h" | 5 #include "chrome/browser/infobars/infobar_delegate.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "content/public/browser/navigation_controller.h" | 10 #include "content/public/browser/navigation_controller.h" |
| 11 #include "content/public/browser/navigation_details.h" | 11 #include "content/public/browser/navigation_details.h" |
| 12 #include "content/public/browser/navigation_entry.h" | 12 #include "content/public/browser/navigation_entry.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "ui/base/resource/resource_bundle.h" |
| 14 | 15 |
| 15 using content::NavigationEntry; | 16 using content::NavigationEntry; |
| 16 | 17 |
| 17 // InfoBarDelegate ------------------------------------------------------------ | 18 // InfoBarDelegate ------------------------------------------------------------ |
| 18 | 19 |
| 19 InfoBarDelegate::~InfoBarDelegate() { | 20 InfoBarDelegate::~InfoBarDelegate() { |
| 20 } | 21 } |
| 21 | 22 |
| 22 InfoBarDelegate::InfoBarAutomationType | 23 InfoBarDelegate::InfoBarAutomationType |
| 23 InfoBarDelegate::GetInfoBarAutomationType() const { | 24 InfoBarDelegate::GetInfoBarAutomationType() const { |
| 24 return UNKNOWN_INFOBAR; | 25 return UNKNOWN_INFOBAR; |
| 25 } | 26 } |
| 26 | 27 |
| 27 bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { | 28 bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { |
| 28 return false; | 29 return false; |
| 29 } | 30 } |
| 30 | 31 |
| 31 bool InfoBarDelegate::ShouldExpire( | 32 bool InfoBarDelegate::ShouldExpire( |
| 32 const content::LoadCommittedDetails& details) const { | 33 const content::LoadCommittedDetails& details) const { |
| 33 if (!details.is_navigation_to_different_page()) | 34 if (!details.is_navigation_to_different_page()) |
| 34 return false; | 35 return false; |
| 35 | 36 |
| 36 return ShouldExpireInternal(details); | 37 return ShouldExpireInternal(details); |
| 37 } | 38 } |
| 38 | 39 |
| 39 void InfoBarDelegate::InfoBarDismissed() { | 40 void InfoBarDelegate::InfoBarDismissed() { |
| 40 } | 41 } |
| 41 | 42 |
| 42 gfx::Image* InfoBarDelegate::GetIcon() const { | 43 int InfoBarDelegate::GetIconID() const { |
| 43 return NULL; | 44 return kNoIconID; |
| 44 } | 45 } |
| 45 | 46 |
| 46 InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() const { | 47 InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() const { |
| 47 return WARNING_TYPE; | 48 return WARNING_TYPE; |
| 48 } | 49 } |
| 49 | 50 |
| 50 AutoLoginInfoBarDelegate* InfoBarDelegate::AsAutoLoginInfoBarDelegate() { | 51 AutoLoginInfoBarDelegate* InfoBarDelegate::AsAutoLoginInfoBarDelegate() { |
| 51 return NULL; | 52 return NULL; |
| 52 } | 53 } |
| 53 | 54 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 84 } | 85 } |
| 85 | 86 |
| 86 ThreeDAPIInfoBarDelegate* InfoBarDelegate::AsThreeDAPIInfoBarDelegate() { | 87 ThreeDAPIInfoBarDelegate* InfoBarDelegate::AsThreeDAPIInfoBarDelegate() { |
| 87 return NULL; | 88 return NULL; |
| 88 } | 89 } |
| 89 | 90 |
| 90 TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() { | 91 TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() { |
| 91 return NULL; | 92 return NULL; |
| 92 } | 93 } |
| 93 | 94 |
| 95 gfx::Image InfoBarDelegate::GetIcon() const { |
| 96 int icon_id = GetIconID(); |
| 97 return (icon_id == kNoIconID) ? gfx::Image() : |
| 98 ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id); |
| 99 } |
| 100 |
| 94 InfoBarDelegate::InfoBarDelegate(InfoBarService* infobar_service) | 101 InfoBarDelegate::InfoBarDelegate(InfoBarService* infobar_service) |
| 95 : contents_unique_id_(0), | 102 : contents_unique_id_(0), |
| 96 owner_(infobar_service) { | 103 owner_(infobar_service) { |
| 97 if (infobar_service) | 104 if (infobar_service) |
| 98 StoreActiveEntryUniqueID(); | 105 StoreActiveEntryUniqueID(); |
| 99 } | 106 } |
| 100 | 107 |
| 101 void InfoBarDelegate::StoreActiveEntryUniqueID() { | 108 void InfoBarDelegate::StoreActiveEntryUniqueID() { |
| 102 DCHECK(web_contents()); | 109 DCHECK(web_contents()); |
| 103 NavigationEntry* active_entry = | 110 NavigationEntry* active_entry = |
| 104 web_contents()->GetController().GetActiveEntry(); | 111 web_contents()->GetController().GetActiveEntry(); |
| 105 contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0; | 112 contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0; |
| 106 } | 113 } |
| 107 | 114 |
| 108 bool InfoBarDelegate::ShouldExpireInternal( | 115 bool InfoBarDelegate::ShouldExpireInternal( |
| 109 const content::LoadCommittedDetails& details) const { | 116 const content::LoadCommittedDetails& details) const { |
| 110 // NOTE: If you change this, be sure to check and adjust the behavior of | 117 // NOTE: If you change this, be sure to check and adjust the behavior of |
| 111 // anyone who overrides this as necessary! | 118 // anyone who overrides this as necessary! |
| 112 return (contents_unique_id_ != details.entry->GetUniqueID()) || | 119 return (contents_unique_id_ != details.entry->GetUniqueID()) || |
| 113 (content::PageTransitionStripQualifier( | 120 (content::PageTransitionStripQualifier( |
| 114 details.entry->GetTransitionType()) == | 121 details.entry->GetTransitionType()) == |
| 115 content::PAGE_TRANSITION_RELOAD); | 122 content::PAGE_TRANSITION_RELOAD); |
| 116 } | 123 } |
| 117 | 124 |
| 118 void InfoBarDelegate::RemoveSelf() { | 125 void InfoBarDelegate::RemoveSelf() { |
| 119 if (owner_) | 126 if (owner_) |
| 120 owner_->RemoveInfoBar(this); // Clears |owner_|. | 127 owner_->RemoveInfoBar(this); // Clears |owner_|. |
| 121 } | 128 } |
| OLD | NEW |