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