blob: afa5c952a50b408e502d0a48d8c73bb465f1e497 [file] [log] [blame]
[email protected]d3ddb6d2012-01-06 02:51:171// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]0dd3a0ab2011-02-18 08:17:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]4a8adfa02013-03-19 22:37:465#include "chrome/browser/infobars/infobar_delegate.h"
[email protected]0dd3a0ab2011-02-18 08:17:446
7#include "base/logging.h"
8#include "build/build_config.h"
[email protected]4a8adfa02013-03-19 22:37:469#include "chrome/browser/infobars/infobar_service.h"
[email protected]cdcb1dee2012-01-04 00:46:2010#include "content/public/browser/navigation_controller.h"
[email protected]5b96836f2011-12-22 07:39:0011#include "content/public/browser/navigation_details.h"
[email protected]ad23a092011-12-28 07:02:0412#include "content/public/browser/navigation_entry.h"
[email protected]ea049a02011-12-25 21:37:0913#include "content/public/browser/web_contents.h"
[email protected]a1c8bae32013-05-16 19:03:5814#include "ui/base/resource/resource_bundle.h"
[email protected]0dd3a0ab2011-02-18 08:17:4415
[email protected]10f417c52011-12-28 21:04:2316using content::NavigationEntry;
17
[email protected]0dd3a0ab2011-02-18 08:17:4418// InfoBarDelegate ------------------------------------------------------------
19
[email protected]a1c8bae32013-05-16 19:03:5820const int InfoBarDelegate::kNoIconID = 0;
21
[email protected]0dd3a0ab2011-02-18 08:17:4422InfoBarDelegate::~InfoBarDelegate() {
23}
24
[email protected]1bfe0ab2012-04-07 02:13:4325InfoBarDelegate::InfoBarAutomationType
26 InfoBarDelegate::GetInfoBarAutomationType() const {
27 return UNKNOWN_INFOBAR;
28}
29
[email protected]0dd3a0ab2011-02-18 08:17:4430bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const {
31 return false;
32}
33
34bool InfoBarDelegate::ShouldExpire(
[email protected]8286f51a2011-05-31 17:39:1335 const content::LoadCommittedDetails& details) const {
[email protected]4e697b042011-07-08 06:44:5636 if (!details.is_navigation_to_different_page())
[email protected]c7e136f2011-05-18 06:51:1537 return false;
38
39 return ShouldExpireInternal(details);
40}
41
[email protected]0dd3a0ab2011-02-18 08:17:4442void InfoBarDelegate::InfoBarDismissed() {
43}
44
[email protected]a1c8bae32013-05-16 19:03:5845int InfoBarDelegate::GetIconID() const {
46 return kNoIconID;
[email protected]0dd3a0ab2011-02-18 08:17:4447}
48
49InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() const {
50 return WARNING_TYPE;
51}
52
[email protected]18c39a82012-06-29 14:23:3053AutoLoginInfoBarDelegate* InfoBarDelegate::AsAutoLoginInfoBarDelegate() {
54 return NULL;
55}
56
[email protected]0dd3a0ab2011-02-18 08:17:4457ConfirmInfoBarDelegate* InfoBarDelegate::AsConfirmInfoBarDelegate() {
58 return NULL;
59}
60
[email protected]0dd3a0ab2011-02-18 08:17:4461ExtensionInfoBarDelegate* InfoBarDelegate::AsExtensionInfoBarDelegate() {
62 return NULL;
63}
64
[email protected]dfd686c82011-06-23 22:58:1265InsecureContentInfoBarDelegate*
66 InfoBarDelegate::AsInsecureContentInfoBarDelegate() {
67 return NULL;
68}
69
[email protected]51d1fc62012-04-28 03:47:5370MediaStreamInfoBarDelegate* InfoBarDelegate::AsMediaStreamInfoBarDelegate() {
[email protected]117b6b42012-02-29 09:11:0871 return NULL;
72}
73
[email protected]d3ddb6d2012-01-06 02:51:1774RegisterProtocolHandlerInfoBarDelegate*
75 InfoBarDelegate::AsRegisterProtocolHandlerInfoBarDelegate() {
76 return NULL;
77}
78
[email protected]f7bbda82013-02-07 00:32:2279ScreenCaptureInfoBarDelegate*
80 InfoBarDelegate::AsScreenCaptureInfoBarDelegate() {
81 return NULL;
82}
83
[email protected]0dd3a0ab2011-02-18 08:17:4484ThemeInstalledInfoBarDelegate*
85 InfoBarDelegate::AsThemePreviewInfobarDelegate() {
86 return NULL;
87}
88
[email protected]818915cd2012-11-20 13:14:1189ThreeDAPIInfoBarDelegate* InfoBarDelegate::AsThreeDAPIInfoBarDelegate() {
90 return NULL;
91}
92
[email protected]0dd3a0ab2011-02-18 08:17:4493TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() {
94 return NULL;
95}
96
[email protected]a1c8bae32013-05-16 19:03:5897gfx::Image InfoBarDelegate::GetIcon() const {
98 int icon_id = GetIconID();
99 return (icon_id == kNoIconID) ? gfx::Image() :
100 ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id);
101}
102
[email protected]0d3e09542013-07-09 21:13:11103InfoBarDelegate::InfoBarDelegate(InfoBarService* owner)
[email protected]9f507a902011-07-28 18:45:11104 : contents_unique_id_(0),
[email protected]0d3e09542013-07-09 21:13:11105 owner_(owner) {
106 if (owner_)
[email protected]38eb4972013-01-07 18:35:05107 StoreActiveEntryUniqueID();
[email protected]0dd3a0ab2011-02-18 08:17:44108}
109
[email protected]38eb4972013-01-07 18:35:05110void InfoBarDelegate::StoreActiveEntryUniqueID() {
[email protected]6dda5972013-04-24 01:48:59111 DCHECK(web_contents());
[email protected]10f417c52011-12-28 21:04:23112 NavigationEntry* active_entry =
[email protected]6dda5972013-04-24 01:48:59113 web_contents()->GetController().GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51114 contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0;
[email protected]0dd3a0ab2011-02-18 08:17:44115}
[email protected]9f507a902011-07-28 18:45:11116
117bool InfoBarDelegate::ShouldExpireInternal(
118 const content::LoadCommittedDetails& details) const {
[email protected]38eb4972013-01-07 18:35:05119 // NOTE: If you change this, be sure to check and adjust the behavior of
120 // anyone who overrides this as necessary!
[email protected]36fc0392011-12-25 03:59:51121 return (contents_unique_id_ != details.entry->GetUniqueID()) ||
[email protected]2905f742011-10-13 03:51:58122 (content::PageTransitionStripQualifier(
[email protected]36fc0392011-12-25 03:59:51123 details.entry->GetTransitionType()) ==
124 content::PAGE_TRANSITION_RELOAD);
[email protected]9f507a902011-07-28 18:45:11125}
126
127void InfoBarDelegate::RemoveSelf() {
[email protected]95a33ed62011-09-30 15:07:08128 if (owner_)
129 owner_->RemoveInfoBar(this); // Clears |owner_|.
[email protected]9f507a902011-07-28 18:45:11130}