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
3 // found in the LICENSE file.
5 #include "chrome/browser/infobars/infobar_delegate.h"
7 #include "base/logging.h"
8 #include "build/build_config.h"
9 #include "chrome/browser/infobars/infobar.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "content/public/browser/navigation_controller.h"
12 #include "content/public/browser/navigation_details.h"
13 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/web_contents.h"
15 #include "ui/base/resource/resource_bundle.h"
17 using content::NavigationEntry
;
19 // InfoBarDelegate ------------------------------------------------------------
21 const int InfoBarDelegate::kNoIconID
= 0;
23 InfoBarDelegate::~InfoBarDelegate() {
26 InfoBarDelegate::InfoBarAutomationType
27 InfoBarDelegate::GetInfoBarAutomationType() const {
28 return UNKNOWN_INFOBAR
;
31 bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate
* delegate
) const {
35 bool InfoBarDelegate::ShouldExpire(
36 const content::LoadCommittedDetails
& details
) const {
37 if (!details
.is_navigation_to_different_page())
40 return ShouldExpireInternal(details
);
43 void InfoBarDelegate::InfoBarDismissed() {
46 int InfoBarDelegate::GetIconID() const {
50 InfoBarDelegate::Type
InfoBarDelegate::GetInfoBarType() const {
54 AutoLoginInfoBarDelegate
* InfoBarDelegate::AsAutoLoginInfoBarDelegate() {
58 ConfirmInfoBarDelegate
* InfoBarDelegate::AsConfirmInfoBarDelegate() {
62 ExtensionInfoBarDelegate
* InfoBarDelegate::AsExtensionInfoBarDelegate() {
66 InsecureContentInfoBarDelegate
*
67 InfoBarDelegate::AsInsecureContentInfoBarDelegate() {
71 MediaStreamInfoBarDelegate
* InfoBarDelegate::AsMediaStreamInfoBarDelegate() {
75 PopupBlockedInfoBarDelegate
* InfoBarDelegate::AsPopupBlockedInfoBarDelegate() {
79 RegisterProtocolHandlerInfoBarDelegate
*
80 InfoBarDelegate::AsRegisterProtocolHandlerInfoBarDelegate() {
84 ScreenCaptureInfoBarDelegate
*
85 InfoBarDelegate::AsScreenCaptureInfoBarDelegate() {
89 ThemeInstalledInfoBarDelegate
*
90 InfoBarDelegate::AsThemePreviewInfobarDelegate() {
94 ThreeDAPIInfoBarDelegate
* InfoBarDelegate::AsThreeDAPIInfoBarDelegate() {
98 TranslateInfoBarDelegate
* InfoBarDelegate::AsTranslateInfoBarDelegate() {
102 void InfoBarDelegate::StoreActiveEntryUniqueID() {
103 DCHECK(web_contents());
104 NavigationEntry
* active_entry
=
105 web_contents()->GetController().GetActiveEntry();
106 contents_unique_id_
= active_entry
? active_entry
->GetUniqueID() : 0;
109 gfx::Image
InfoBarDelegate::GetIcon() const {
110 int icon_id
= GetIconID();
111 return (icon_id
== kNoIconID
) ? gfx::Image() :
112 ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id
);
115 content::WebContents
* InfoBarDelegate::web_contents() {
116 return (infobar_
&& infobar_
->owner()) ?
117 infobar_
->owner()->web_contents() : NULL
;
120 InfoBarDelegate::InfoBarDelegate() : contents_unique_id_(0) {
123 bool InfoBarDelegate::ShouldExpireInternal(
124 const content::LoadCommittedDetails
& details
) const {
125 // NOTE: If you change this, be sure to check and adjust the behavior of
126 // anyone who overrides this as necessary!
127 return (contents_unique_id_
!= details
.entry
->GetUniqueID()) ||
128 (content::PageTransitionStripQualifier(
129 details
.entry
->GetTransitionType()) ==
130 content::PAGE_TRANSITION_RELOAD
);