| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 16 |
| 17 bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { |
| 18 return false; |
| 19 } |
| 20 |
| 17 bool InfoBarDelegate::ShouldExpire( | 21 bool InfoBarDelegate::ShouldExpire( |
| 18 const NavigationController::LoadCommittedDetails& details) const { | 22 const NavigationController::LoadCommittedDetails& details) const { |
| 19 bool is_reload = | 23 bool is_reload = |
| 20 PageTransition::StripQualifier(details.entry->transition_type()) == | 24 PageTransition::StripQualifier(details.entry->transition_type()) == |
| 21 PageTransition::RELOAD; | 25 PageTransition::RELOAD; |
| 22 return is_reload || (contents_unique_id_ != details.entry->unique_id()); | 26 return is_reload || (contents_unique_id_ != details.entry->unique_id()); |
| 23 } | 27 } |
| 24 | 28 |
| 29 SkBitmap* InfoBarDelegate::GetIcon() const { |
| 30 return NULL; |
| 31 } |
| 32 |
| 33 AlertInfoBarDelegate* InfoBarDelegate::AsAlertInfoBarDelegate() { |
| 34 return NULL; |
| 35 } |
| 36 |
| 37 LinkInfoBarDelegate* InfoBarDelegate::AsLinkInfoBarDelegate() { |
| 38 return NULL; |
| 39 } |
| 40 |
| 41 ConfirmInfoBarDelegate* InfoBarDelegate::AsConfirmInfoBarDelegate() { |
| 42 return NULL; |
| 43 } |
| 44 |
| 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* |
| 59 InfoBarDelegate::AsCrashedExtensionInfoBarDelegate() { |
| 60 return NULL; |
| 61 } |
| 62 |
| 63 InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() { |
| 64 return WARNING_TYPE; |
| 65 } |
| 66 |
| 25 InfoBarDelegate::InfoBarDelegate(TabContents* contents) | 67 InfoBarDelegate::InfoBarDelegate(TabContents* contents) |
| 26 : contents_unique_id_(0) { | 68 : contents_unique_id_(0) { |
| 27 if (contents) | 69 if (contents) |
| 28 StoreActiveEntryUniqueID(contents); | 70 StoreActiveEntryUniqueID(contents); |
| 29 } | 71 } |
| 30 | 72 |
| 31 void InfoBarDelegate::StoreActiveEntryUniqueID(TabContents* contents) { | 73 void InfoBarDelegate::StoreActiveEntryUniqueID(TabContents* contents) { |
| 32 NavigationEntry* active_entry = contents->controller().GetActiveEntry(); | 74 NavigationEntry* active_entry = contents->controller().GetActiveEntry(); |
| 33 contents_unique_id_ = active_entry ? active_entry->unique_id() : 0; | 75 contents_unique_id_ = active_entry ? active_entry->unique_id() : 0; |
| 34 } | 76 } |
| 35 | 77 |
| 36 // AlertInfoBarDelegate: ------------------------------------------------------- | 78 // AlertInfoBarDelegate: ------------------------------------------------------- |
| 37 | 79 |
| 80 SkBitmap* AlertInfoBarDelegate::GetIcon() const { |
| 81 return NULL; |
| 82 } |
| 83 |
| 38 bool AlertInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { | 84 bool AlertInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { |
| 39 AlertInfoBarDelegate* alert_delegate = delegate->AsAlertInfoBarDelegate(); | 85 AlertInfoBarDelegate* alert_delegate = delegate->AsAlertInfoBarDelegate(); |
| 40 if (!alert_delegate) | 86 if (!alert_delegate) |
| 41 return false; | 87 return false; |
| 42 | 88 |
| 43 return alert_delegate->GetMessageText() == GetMessageText(); | 89 return alert_delegate->GetMessageText() == GetMessageText(); |
| 44 } | 90 } |
| 45 | 91 |
| 92 AlertInfoBarDelegate* AlertInfoBarDelegate::AsAlertInfoBarDelegate() { |
| 93 return this; |
| 94 } |
| 95 |
| 46 AlertInfoBarDelegate::AlertInfoBarDelegate(TabContents* contents) | 96 AlertInfoBarDelegate::AlertInfoBarDelegate(TabContents* contents) |
| 47 : InfoBarDelegate(contents) { | 97 : InfoBarDelegate(contents) { |
| 48 } | 98 } |
| 49 | 99 |
| 50 // LinkInfoBarDelegate: -------------------------------------------------------- | 100 // LinkInfoBarDelegate: -------------------------------------------------------- |
| 51 | 101 |
| 102 string16 LinkInfoBarDelegate::GetMessageTextWithOffset( |
| 103 size_t* link_offset) const { |
| 104 *link_offset = string16::npos; |
| 105 return string16(); |
| 106 } |
| 107 |
| 108 SkBitmap* LinkInfoBarDelegate::GetIcon() const { |
| 109 return NULL; |
| 110 } |
| 111 |
| 112 bool LinkInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
| 113 return true; |
| 114 } |
| 115 |
| 116 LinkInfoBarDelegate* LinkInfoBarDelegate::AsLinkInfoBarDelegate() { |
| 117 return this; |
| 118 } |
| 119 |
| 52 LinkInfoBarDelegate::LinkInfoBarDelegate(TabContents* contents) | 120 LinkInfoBarDelegate::LinkInfoBarDelegate(TabContents* contents) |
| 53 : InfoBarDelegate(contents) { | 121 : InfoBarDelegate(contents) { |
| 54 } | 122 } |
| 55 | 123 |
| 56 // ConfirmInfoBarDelegate: ----------------------------------------------------- | 124 // ConfirmInfoBarDelegate: ----------------------------------------------------- |
| 57 | 125 |
| 126 int ConfirmInfoBarDelegate::GetButtons() const { |
| 127 return BUTTON_NONE; |
| 128 } |
| 129 |
| 58 string16 ConfirmInfoBarDelegate::GetButtonLabel( | 130 string16 ConfirmInfoBarDelegate::GetButtonLabel( |
| 59 InfoBarButton button) const { | 131 InfoBarButton button) const { |
| 60 if (button == BUTTON_OK) | 132 if (button == BUTTON_OK) |
| 61 return l10n_util::GetStringUTF16(IDS_OK); | 133 return l10n_util::GetStringUTF16(IDS_OK); |
| 62 if (button == BUTTON_CANCEL) | 134 if (button == BUTTON_CANCEL) |
| 63 return l10n_util::GetStringUTF16(IDS_CANCEL); | 135 return l10n_util::GetStringUTF16(IDS_CANCEL); |
| 64 NOTREACHED(); | 136 NOTREACHED(); |
| 65 return string16(); | 137 return string16(); |
| 66 } | 138 } |
| 67 | 139 |
| 140 bool ConfirmInfoBarDelegate::NeedElevation(InfoBarButton button) const { |
| 141 return false; |
| 142 } |
| 143 |
| 144 bool ConfirmInfoBarDelegate::Accept() { |
| 145 return true; |
| 146 } |
| 147 |
| 148 bool ConfirmInfoBarDelegate::Cancel() { |
| 149 return true; |
| 150 } |
| 151 |
| 152 string16 ConfirmInfoBarDelegate::GetLinkText() { |
| 153 return string16(); |
| 154 } |
| 155 |
| 156 bool ConfirmInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
| 157 return true; |
| 158 } |
| 159 |
| 160 ConfirmInfoBarDelegate* ConfirmInfoBarDelegate::AsConfirmInfoBarDelegate() { |
| 161 return this; |
| 162 } |
| 163 |
| 68 ConfirmInfoBarDelegate::ConfirmInfoBarDelegate(TabContents* contents) | 164 ConfirmInfoBarDelegate::ConfirmInfoBarDelegate(TabContents* contents) |
| 69 : AlertInfoBarDelegate(contents) { | 165 : AlertInfoBarDelegate(contents) { |
| 70 } | 166 } |
| 71 | 167 |
| 72 // SimpleAlertInfoBarDelegate: ------------------------------------------------- | 168 // SimpleAlertInfoBarDelegate: ------------------------------------------------- |
| 73 | 169 |
| 74 SimpleAlertInfoBarDelegate::SimpleAlertInfoBarDelegate( | 170 SimpleAlertInfoBarDelegate::SimpleAlertInfoBarDelegate( |
| 75 TabContents* contents, | 171 TabContents* contents, |
| 76 const string16& message, | 172 const string16& message, |
| 77 SkBitmap* icon, | 173 SkBitmap* icon, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 94 return message_; | 190 return message_; |
| 95 } | 191 } |
| 96 | 192 |
| 97 SkBitmap* SimpleAlertInfoBarDelegate::GetIcon() const { | 193 SkBitmap* SimpleAlertInfoBarDelegate::GetIcon() const { |
| 98 return icon_; | 194 return icon_; |
| 99 } | 195 } |
| 100 | 196 |
| 101 void SimpleAlertInfoBarDelegate::InfoBarClosed() { | 197 void SimpleAlertInfoBarDelegate::InfoBarClosed() { |
| 102 delete this; | 198 delete this; |
| 103 } | 199 } |
| OLD | NEW |