| OLD | NEW |
| 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/tab_contents/infobar_delegate.h" | 5 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/tab_contents/navigation_entry.h" | 10 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 11 #include "chrome/browser/tab_contents/navigation_controller.h" | 11 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
| 13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 14 | 14 |
| 15 // InfoBarDelegate: ------------------------------------------------------------ | 15 // InfoBarDelegate ------------------------------------------------------------ |
| 16 |
| 17 InfoBarDelegate::~InfoBarDelegate() { |
| 18 } |
| 16 | 19 |
| 17 bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { | 20 bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { |
| 18 return false; | 21 return false; |
| 19 } | 22 } |
| 20 | 23 |
| 21 bool InfoBarDelegate::ShouldExpire( | 24 bool InfoBarDelegate::ShouldExpire( |
| 22 const NavigationController::LoadCommittedDetails& details) const { | 25 const NavigationController::LoadCommittedDetails& details) const { |
| 23 bool is_reload = | 26 return (contents_unique_id_ != details.entry->unique_id()) || |
| 24 PageTransition::StripQualifier(details.entry->transition_type()) == | 27 (PageTransition::StripQualifier(details.entry->transition_type()) == |
| 25 PageTransition::RELOAD; | 28 PageTransition::RELOAD); |
| 26 return is_reload || (contents_unique_id_ != details.entry->unique_id()); | 29 } |
| 30 |
| 31 void InfoBarDelegate::InfoBarDismissed() { |
| 32 } |
| 33 |
| 34 void InfoBarDelegate::InfoBarClosed() { |
| 27 } | 35 } |
| 28 | 36 |
| 29 SkBitmap* InfoBarDelegate::GetIcon() const { | 37 SkBitmap* InfoBarDelegate::GetIcon() const { |
| 30 return NULL; | 38 return NULL; |
| 31 } | 39 } |
| 32 | 40 |
| 41 InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() const { |
| 42 return WARNING_TYPE; |
| 43 } |
| 44 |
| 33 AlertInfoBarDelegate* InfoBarDelegate::AsAlertInfoBarDelegate() { | 45 AlertInfoBarDelegate* InfoBarDelegate::AsAlertInfoBarDelegate() { |
| 34 return NULL; | 46 return NULL; |
| 35 } | 47 } |
| 36 | 48 |
| 37 LinkInfoBarDelegate* InfoBarDelegate::AsLinkInfoBarDelegate() { | |
| 38 return NULL; | |
| 39 } | |
| 40 | |
| 41 ConfirmInfoBarDelegate* InfoBarDelegate::AsConfirmInfoBarDelegate() { | 49 ConfirmInfoBarDelegate* InfoBarDelegate::AsConfirmInfoBarDelegate() { |
| 42 return NULL; | 50 return NULL; |
| 43 } | 51 } |
| 44 | 52 |
| 45 ThemeInstalledInfoBarDelegate* | |
| 46 InfoBarDelegate::AsThemePreviewInfobarDelegate() { | |
| 47 return NULL; | |
| 48 } | |
| 49 | |
| 50 TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() { | |
| 51 return NULL; | |
| 52 } | |
| 53 | |
| 54 ExtensionInfoBarDelegate* InfoBarDelegate::AsExtensionInfoBarDelegate() { | |
| 55 return NULL; | |
| 56 } | |
| 57 | |
| 58 CrashedExtensionInfoBarDelegate* | 53 CrashedExtensionInfoBarDelegate* |
| 59 InfoBarDelegate::AsCrashedExtensionInfoBarDelegate() { | 54 InfoBarDelegate::AsCrashedExtensionInfoBarDelegate() { |
| 60 return NULL; | 55 return NULL; |
| 61 } | 56 } |
| 62 | 57 |
| 63 InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() { | 58 ExtensionInfoBarDelegate* InfoBarDelegate::AsExtensionInfoBarDelegate() { |
| 64 return WARNING_TYPE; | 59 return NULL; |
| 60 } |
| 61 |
| 62 LinkInfoBarDelegate* InfoBarDelegate::AsLinkInfoBarDelegate() { |
| 63 return NULL; |
| 64 } |
| 65 |
| 66 ThemeInstalledInfoBarDelegate* |
| 67 InfoBarDelegate::AsThemePreviewInfobarDelegate() { |
| 68 return NULL; |
| 69 } |
| 70 |
| 71 TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() { |
| 72 return NULL; |
| 65 } | 73 } |
| 66 | 74 |
| 67 InfoBarDelegate::InfoBarDelegate(TabContents* contents) | 75 InfoBarDelegate::InfoBarDelegate(TabContents* contents) |
| 68 : contents_unique_id_(0) { | 76 : contents_unique_id_(0) { |
| 69 if (contents) | 77 if (contents) |
| 70 StoreActiveEntryUniqueID(contents); | 78 StoreActiveEntryUniqueID(contents); |
| 71 } | 79 } |
| 72 | 80 |
| 73 void InfoBarDelegate::StoreActiveEntryUniqueID(TabContents* contents) { | 81 void InfoBarDelegate::StoreActiveEntryUniqueID(TabContents* contents) { |
| 74 NavigationEntry* active_entry = contents->controller().GetActiveEntry(); | 82 NavigationEntry* active_entry = contents->controller().GetActiveEntry(); |
| 75 contents_unique_id_ = active_entry ? active_entry->unique_id() : 0; | 83 contents_unique_id_ = active_entry ? active_entry->unique_id() : 0; |
| 76 } | 84 } |
| 77 | 85 |
| 78 // AlertInfoBarDelegate: ------------------------------------------------------- | |
| 79 | 86 |
| 80 SkBitmap* AlertInfoBarDelegate::GetIcon() const { | 87 // AlertInfoBarDelegate ------------------------------------------------------- |
| 81 return NULL; | |
| 82 } | |
| 83 | 88 |
| 84 bool AlertInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { | 89 bool AlertInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { |
| 85 AlertInfoBarDelegate* alert_delegate = delegate->AsAlertInfoBarDelegate(); | 90 AlertInfoBarDelegate* alert_delegate = delegate->AsAlertInfoBarDelegate(); |
| 86 if (!alert_delegate) | 91 return alert_delegate && |
| 87 return false; | 92 (alert_delegate->GetMessageText() == GetMessageText()); |
| 93 } |
| 88 | 94 |
| 89 return alert_delegate->GetMessageText() == GetMessageText(); | 95 AlertInfoBarDelegate::AlertInfoBarDelegate(TabContents* contents) |
| 96 : InfoBarDelegate(contents) { |
| 97 } |
| 98 |
| 99 AlertInfoBarDelegate::~AlertInfoBarDelegate() { |
| 90 } | 100 } |
| 91 | 101 |
| 92 AlertInfoBarDelegate* AlertInfoBarDelegate::AsAlertInfoBarDelegate() { | 102 AlertInfoBarDelegate* AlertInfoBarDelegate::AsAlertInfoBarDelegate() { |
| 93 return this; | 103 return this; |
| 94 } | 104 } |
| 95 | 105 |
| 96 AlertInfoBarDelegate::AlertInfoBarDelegate(TabContents* contents) | |
| 97 : InfoBarDelegate(contents) { | |
| 98 } | |
| 99 | 106 |
| 100 // LinkInfoBarDelegate: -------------------------------------------------------- | 107 // LinkInfoBarDelegate -------------------------------------------------------- |
| 101 | 108 |
| 102 string16 LinkInfoBarDelegate::GetMessageTextWithOffset( | 109 string16 LinkInfoBarDelegate::GetMessageTextWithOffset( |
| 103 size_t* link_offset) const { | 110 size_t* link_offset) const { |
| 104 *link_offset = string16::npos; | 111 *link_offset = string16::npos; |
| 105 return string16(); | 112 return string16(); |
| 106 } | 113 } |
| 107 | 114 |
| 108 SkBitmap* LinkInfoBarDelegate::GetIcon() const { | |
| 109 return NULL; | |
| 110 } | |
| 111 | |
| 112 bool LinkInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | 115 bool LinkInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
| 113 return true; | 116 return true; |
| 114 } | 117 } |
| 115 | 118 |
| 119 LinkInfoBarDelegate::LinkInfoBarDelegate(TabContents* contents) |
| 120 : InfoBarDelegate(contents) { |
| 121 } |
| 122 |
| 123 LinkInfoBarDelegate::~LinkInfoBarDelegate() { |
| 124 } |
| 125 |
| 116 LinkInfoBarDelegate* LinkInfoBarDelegate::AsLinkInfoBarDelegate() { | 126 LinkInfoBarDelegate* LinkInfoBarDelegate::AsLinkInfoBarDelegate() { |
| 117 return this; | 127 return this; |
| 118 } | 128 } |
| 119 | 129 |
| 120 LinkInfoBarDelegate::LinkInfoBarDelegate(TabContents* contents) | |
| 121 : InfoBarDelegate(contents) { | |
| 122 } | |
| 123 | 130 |
| 124 // ConfirmInfoBarDelegate: ----------------------------------------------------- | 131 // ConfirmInfoBarDelegate ----------------------------------------------------- |
| 125 | 132 |
| 126 int ConfirmInfoBarDelegate::GetButtons() const { | 133 int ConfirmInfoBarDelegate::GetButtons() const { |
| 127 return BUTTON_NONE; | 134 return BUTTON_NONE; |
| 128 } | 135 } |
| 129 | 136 |
| 130 string16 ConfirmInfoBarDelegate::GetButtonLabel( | 137 string16 ConfirmInfoBarDelegate::GetButtonLabel(InfoBarButton button) const { |
| 131 InfoBarButton button) const { | 138 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_OK : IDS_CANCEL); |
| 132 if (button == BUTTON_OK) | |
| 133 return l10n_util::GetStringUTF16(IDS_OK); | |
| 134 if (button == BUTTON_CANCEL) | |
| 135 return l10n_util::GetStringUTF16(IDS_CANCEL); | |
| 136 NOTREACHED(); | |
| 137 return string16(); | |
| 138 } | 139 } |
| 139 | 140 |
| 140 bool ConfirmInfoBarDelegate::NeedElevation(InfoBarButton button) const { | 141 bool ConfirmInfoBarDelegate::NeedElevation(InfoBarButton button) const { |
| 141 return false; | 142 return false; |
| 142 } | 143 } |
| 143 | 144 |
| 144 bool ConfirmInfoBarDelegate::Accept() { | 145 bool ConfirmInfoBarDelegate::Accept() { |
| 145 return true; | 146 return true; |
| 146 } | 147 } |
| 147 | 148 |
| 148 bool ConfirmInfoBarDelegate::Cancel() { | 149 bool ConfirmInfoBarDelegate::Cancel() { |
| 149 return true; | 150 return true; |
| 150 } | 151 } |
| 151 | 152 |
| 152 string16 ConfirmInfoBarDelegate::GetLinkText() { | 153 string16 ConfirmInfoBarDelegate::GetLinkText() { |
| 153 return string16(); | 154 return string16(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 bool ConfirmInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | 157 bool ConfirmInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
| 157 return true; | 158 return true; |
| 158 } | 159 } |
| 159 | 160 |
| 161 ConfirmInfoBarDelegate::ConfirmInfoBarDelegate(TabContents* contents) |
| 162 : AlertInfoBarDelegate(contents) { |
| 163 } |
| 164 |
| 165 ConfirmInfoBarDelegate::~ConfirmInfoBarDelegate() { |
| 166 } |
| 167 |
| 160 ConfirmInfoBarDelegate* ConfirmInfoBarDelegate::AsConfirmInfoBarDelegate() { | 168 ConfirmInfoBarDelegate* ConfirmInfoBarDelegate::AsConfirmInfoBarDelegate() { |
| 161 return this; | 169 return this; |
| 162 } | 170 } |
| 163 | 171 |
| 164 ConfirmInfoBarDelegate::ConfirmInfoBarDelegate(TabContents* contents) | |
| 165 : AlertInfoBarDelegate(contents) { | |
| 166 } | |
| 167 | 172 |
| 168 // SimpleAlertInfoBarDelegate: ------------------------------------------------- | 173 // SimpleAlertInfoBarDelegate ------------------------------------------------- |
| 169 | 174 |
| 170 SimpleAlertInfoBarDelegate::SimpleAlertInfoBarDelegate( | 175 SimpleAlertInfoBarDelegate::SimpleAlertInfoBarDelegate( |
| 171 TabContents* contents, | 176 TabContents* contents, |
| 177 SkBitmap* icon, |
| 172 const string16& message, | 178 const string16& message, |
| 173 SkBitmap* icon, | |
| 174 bool auto_expire) | 179 bool auto_expire) |
| 175 : AlertInfoBarDelegate(contents), | 180 : AlertInfoBarDelegate(contents), |
| 181 icon_(icon), |
| 176 message_(message), | 182 message_(message), |
| 177 icon_(icon), | |
| 178 auto_expire_(auto_expire) { | 183 auto_expire_(auto_expire) { |
| 179 } | 184 } |
| 180 | 185 |
| 186 SimpleAlertInfoBarDelegate::~SimpleAlertInfoBarDelegate() { |
| 187 } |
| 188 |
| 181 bool SimpleAlertInfoBarDelegate::ShouldExpire( | 189 bool SimpleAlertInfoBarDelegate::ShouldExpire( |
| 182 const NavigationController::LoadCommittedDetails& details) const { | 190 const NavigationController::LoadCommittedDetails& details) const { |
| 183 if (auto_expire_) | 191 return auto_expire_ && AlertInfoBarDelegate::ShouldExpire(details); |
| 184 return AlertInfoBarDelegate::ShouldExpire(details); | |
| 185 | |
| 186 return false; | |
| 187 } | 192 } |
| 188 | 193 |
| 189 string16 SimpleAlertInfoBarDelegate::GetMessageText() const { | 194 void SimpleAlertInfoBarDelegate::InfoBarClosed() { |
| 190 return message_; | 195 delete this; |
| 191 } | 196 } |
| 192 | 197 |
| 193 SkBitmap* SimpleAlertInfoBarDelegate::GetIcon() const { | 198 SkBitmap* SimpleAlertInfoBarDelegate::GetIcon() const { |
| 194 return icon_; | 199 return icon_; |
| 195 } | 200 } |
| 196 | 201 |
| 197 void SimpleAlertInfoBarDelegate::InfoBarClosed() { | 202 string16 SimpleAlertInfoBarDelegate::GetMessageText() const { |
| 198 delete this; | 203 return message_; |
| 199 } | 204 } |
| OLD | NEW |