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.h" | |
10 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
11 #include "content/public/browser/navigation_controller.h" | 10 #include "content/public/browser/navigation_controller.h" |
12 #include "content/public/browser/navigation_details.h" | 11 #include "content/public/browser/navigation_details.h" |
13 #include "content/public/browser/navigation_entry.h" | 12 #include "content/public/browser/navigation_entry.h" |
14 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
15 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
16 | 15 |
17 using content::NavigationEntry; | 16 using content::NavigationEntry; |
18 | 17 |
19 // InfoBarDelegate ------------------------------------------------------------ | 18 // InfoBarDelegate ------------------------------------------------------------ |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 91 } |
93 | 92 |
94 ThreeDAPIInfoBarDelegate* InfoBarDelegate::AsThreeDAPIInfoBarDelegate() { | 93 ThreeDAPIInfoBarDelegate* InfoBarDelegate::AsThreeDAPIInfoBarDelegate() { |
95 return NULL; | 94 return NULL; |
96 } | 95 } |
97 | 96 |
98 TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() { | 97 TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() { |
99 return NULL; | 98 return NULL; |
100 } | 99 } |
101 | 100 |
| 101 gfx::Image InfoBarDelegate::GetIcon() const { |
| 102 int icon_id = GetIconID(); |
| 103 return (icon_id == kNoIconID) ? gfx::Image() : |
| 104 ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id); |
| 105 } |
| 106 |
| 107 InfoBarDelegate::InfoBarDelegate(InfoBarService* owner) |
| 108 : contents_unique_id_(0), |
| 109 owner_(owner) { |
| 110 if (owner_) |
| 111 StoreActiveEntryUniqueID(); |
| 112 } |
| 113 |
102 void InfoBarDelegate::StoreActiveEntryUniqueID() { | 114 void InfoBarDelegate::StoreActiveEntryUniqueID() { |
103 DCHECK(web_contents()); | 115 DCHECK(web_contents()); |
104 NavigationEntry* active_entry = | 116 NavigationEntry* active_entry = |
105 web_contents()->GetController().GetActiveEntry(); | 117 web_contents()->GetController().GetActiveEntry(); |
106 contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0; | 118 contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0; |
107 } | 119 } |
108 | 120 |
109 gfx::Image InfoBarDelegate::GetIcon() const { | |
110 int icon_id = GetIconID(); | |
111 return (icon_id == kNoIconID) ? gfx::Image() : | |
112 ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id); | |
113 } | |
114 | |
115 content::WebContents* InfoBarDelegate::web_contents() { | |
116 return (infobar_ && infobar_->owner()) ? | |
117 infobar_->owner()->web_contents() : NULL; | |
118 } | |
119 | |
120 InfoBarDelegate::InfoBarDelegate() : contents_unique_id_(0) { | |
121 } | |
122 | |
123 bool InfoBarDelegate::ShouldExpireInternal( | 121 bool InfoBarDelegate::ShouldExpireInternal( |
124 const content::LoadCommittedDetails& details) const { | 122 const content::LoadCommittedDetails& details) const { |
125 // NOTE: If you change this, be sure to check and adjust the behavior of | 123 // NOTE: If you change this, be sure to check and adjust the behavior of |
126 // anyone who overrides this as necessary! | 124 // anyone who overrides this as necessary! |
127 return (contents_unique_id_ != details.entry->GetUniqueID()) || | 125 return (contents_unique_id_ != details.entry->GetUniqueID()) || |
128 (content::PageTransitionStripQualifier( | 126 (content::PageTransitionStripQualifier( |
129 details.entry->GetTransitionType()) == | 127 details.entry->GetTransitionType()) == |
130 content::PAGE_TRANSITION_RELOAD); | 128 content::PAGE_TRANSITION_RELOAD); |
131 } | 129 } |
| 130 |
| 131 void InfoBarDelegate::RemoveSelf() { |
| 132 if (owner_) |
| 133 owner_->RemoveInfoBar(this); // Clears |owner_|. |
| 134 } |
OLD | NEW |