| 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 #include "chrome/browser/tab_contents/infobar_delegate.h" | 5 #include "content/browser/tab_contents/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/tab_contents/navigation_entry.h" | 9 #include "content/browser/tab_contents/navigation_entry.h" |
| 10 #include "chrome/browser/tab_contents/navigation_controller.h" | 10 #include "content/browser/tab_contents/navigation_controller.h" |
| 11 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "content/browser/tab_contents/tab_contents.h" |
| 12 #include "grit/generated_resources.h" | |
| 13 #include "ui/base/l10n/l10n_util.h" | |
| 14 | 12 |
| 15 // InfoBarDelegate ------------------------------------------------------------ | 13 // InfoBarDelegate ------------------------------------------------------------ |
| 16 | 14 |
| 17 InfoBarDelegate::~InfoBarDelegate() { | 15 InfoBarDelegate::~InfoBarDelegate() { |
| 18 } | 16 } |
| 19 | 17 |
| 20 bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { | 18 bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { |
| 21 return false; | 19 return false; |
| 22 } | 20 } |
| 23 | 21 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 InfoBarDelegate::InfoBarDelegate(TabContents* contents) | 74 InfoBarDelegate::InfoBarDelegate(TabContents* contents) |
| 77 : contents_unique_id_(0) { | 75 : contents_unique_id_(0) { |
| 78 if (contents) | 76 if (contents) |
| 79 StoreActiveEntryUniqueID(contents); | 77 StoreActiveEntryUniqueID(contents); |
| 80 } | 78 } |
| 81 | 79 |
| 82 void InfoBarDelegate::StoreActiveEntryUniqueID(TabContents* contents) { | 80 void InfoBarDelegate::StoreActiveEntryUniqueID(TabContents* contents) { |
| 83 NavigationEntry* active_entry = contents->controller().GetActiveEntry(); | 81 NavigationEntry* active_entry = contents->controller().GetActiveEntry(); |
| 84 contents_unique_id_ = active_entry ? active_entry->unique_id() : 0; | 82 contents_unique_id_ = active_entry ? active_entry->unique_id() : 0; |
| 85 } | 83 } |
| 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 |