[email protected] | d3ddb6d | 2012-01-06 02:51:17 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 4a8adfa0 | 2013-03-19 22:37:46 | [diff] [blame] | 5 | #include "chrome/browser/infobars/infobar_delegate.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 6 | |
7 | #include "base/logging.h" | ||||
8 | #include "build/build_config.h" | ||||
[email protected] | 4a8adfa0 | 2013-03-19 22:37:46 | [diff] [blame] | 9 | #include "chrome/browser/infobars/infobar_service.h" |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 10 | #include "content/public/browser/navigation_controller.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 11 | #include "content/public/browser/navigation_details.h" |
[email protected] | ad23a09 | 2011-12-28 07:02:04 | [diff] [blame] | 12 | #include "content/public/browser/navigation_entry.h" |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 13 | #include "content/public/browser/web_contents.h" |
[email protected] | a1c8bae3 | 2013-05-16 19:03:58 | [diff] [blame] | 14 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 15 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 16 | using content::NavigationEntry; |
17 | |||||
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 18 | // InfoBarDelegate ------------------------------------------------------------ |
19 | |||||
[email protected] | a1c8bae3 | 2013-05-16 19:03:58 | [diff] [blame] | 20 | const int InfoBarDelegate::kNoIconID = 0; |
21 | |||||
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 22 | InfoBarDelegate::~InfoBarDelegate() { |
23 | } | ||||
24 | |||||
[email protected] | 1bfe0ab | 2012-04-07 02:13:43 | [diff] [blame] | 25 | InfoBarDelegate::InfoBarAutomationType |
26 | InfoBarDelegate::GetInfoBarAutomationType() const { | ||||
27 | return UNKNOWN_INFOBAR; | ||||
28 | } | ||||
29 | |||||
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 30 | bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { |
31 | return false; | ||||
32 | } | ||||
33 | |||||
34 | bool InfoBarDelegate::ShouldExpire( | ||||
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 35 | const content::LoadCommittedDetails& details) const { |
[email protected] | 4e697b04 | 2011-07-08 06:44:56 | [diff] [blame] | 36 | if (!details.is_navigation_to_different_page()) |
[email protected] | c7e136f | 2011-05-18 06:51:15 | [diff] [blame] | 37 | return false; |
38 | |||||
39 | return ShouldExpireInternal(details); | ||||
40 | } | ||||
41 | |||||
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 42 | void InfoBarDelegate::InfoBarDismissed() { |
43 | } | ||||
44 | |||||
[email protected] | a1c8bae3 | 2013-05-16 19:03:58 | [diff] [blame] | 45 | int InfoBarDelegate::GetIconID() const { |
46 | return kNoIconID; | ||||
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 47 | } |
48 | |||||
49 | InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() const { | ||||
50 | return WARNING_TYPE; | ||||
51 | } | ||||
52 | |||||
[email protected] | 18c39a8 | 2012-06-29 14:23:30 | [diff] [blame] | 53 | AutoLoginInfoBarDelegate* InfoBarDelegate::AsAutoLoginInfoBarDelegate() { |
54 | return NULL; | ||||
55 | } | ||||
56 | |||||
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 57 | ConfirmInfoBarDelegate* InfoBarDelegate::AsConfirmInfoBarDelegate() { |
58 | return NULL; | ||||
59 | } | ||||
60 | |||||
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 61 | ExtensionInfoBarDelegate* InfoBarDelegate::AsExtensionInfoBarDelegate() { |
62 | return NULL; | ||||
63 | } | ||||
64 | |||||
[email protected] | dfd686c8 | 2011-06-23 22:58:12 | [diff] [blame] | 65 | InsecureContentInfoBarDelegate* |
66 | InfoBarDelegate::AsInsecureContentInfoBarDelegate() { | ||||
67 | return NULL; | ||||
68 | } | ||||
69 | |||||
[email protected] | 51d1fc6 | 2012-04-28 03:47:53 | [diff] [blame] | 70 | MediaStreamInfoBarDelegate* InfoBarDelegate::AsMediaStreamInfoBarDelegate() { |
[email protected] | 117b6b4 | 2012-02-29 09:11:08 | [diff] [blame] | 71 | return NULL; |
72 | } | ||||
73 | |||||
[email protected] | d3ddb6d | 2012-01-06 02:51:17 | [diff] [blame] | 74 | RegisterProtocolHandlerInfoBarDelegate* |
75 | InfoBarDelegate::AsRegisterProtocolHandlerInfoBarDelegate() { | ||||
76 | return NULL; | ||||
77 | } | ||||
78 | |||||
[email protected] | f7bbda8 | 2013-02-07 00:32:22 | [diff] [blame] | 79 | ScreenCaptureInfoBarDelegate* |
80 | InfoBarDelegate::AsScreenCaptureInfoBarDelegate() { | ||||
81 | return NULL; | ||||
82 | } | ||||
83 | |||||
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 84 | ThemeInstalledInfoBarDelegate* |
85 | InfoBarDelegate::AsThemePreviewInfobarDelegate() { | ||||
86 | return NULL; | ||||
87 | } | ||||
88 | |||||
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 89 | ThreeDAPIInfoBarDelegate* InfoBarDelegate::AsThreeDAPIInfoBarDelegate() { |
90 | return NULL; | ||||
91 | } | ||||
92 | |||||
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 93 | TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() { |
94 | return NULL; | ||||
95 | } | ||||
96 | |||||
[email protected] | a1c8bae3 | 2013-05-16 19:03:58 | [diff] [blame] | 97 | gfx::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] | 0d3e0954 | 2013-07-09 21:13:11 | [diff] [blame] | 103 | InfoBarDelegate::InfoBarDelegate(InfoBarService* owner) |
[email protected] | 9f507a90 | 2011-07-28 18:45:11 | [diff] [blame] | 104 | : contents_unique_id_(0), |
[email protected] | 0d3e0954 | 2013-07-09 21:13:11 | [diff] [blame] | 105 | owner_(owner) { |
106 | if (owner_) | ||||
[email protected] | 38eb497 | 2013-01-07 18:35:05 | [diff] [blame] | 107 | StoreActiveEntryUniqueID(); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 108 | } |
109 | |||||
[email protected] | 38eb497 | 2013-01-07 18:35:05 | [diff] [blame] | 110 | void InfoBarDelegate::StoreActiveEntryUniqueID() { |
[email protected] | 6dda597 | 2013-04-24 01:48:59 | [diff] [blame] | 111 | DCHECK(web_contents()); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 112 | NavigationEntry* active_entry = |
[email protected] | 6dda597 | 2013-04-24 01:48:59 | [diff] [blame] | 113 | web_contents()->GetController().GetActiveEntry(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 114 | contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0; |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 115 | } |
[email protected] | 9f507a90 | 2011-07-28 18:45:11 | [diff] [blame] | 116 | |
117 | bool InfoBarDelegate::ShouldExpireInternal( | ||||
118 | const content::LoadCommittedDetails& details) const { | ||||
[email protected] | 38eb497 | 2013-01-07 18:35:05 | [diff] [blame] | 119 | // NOTE: If you change this, be sure to check and adjust the behavior of |
120 | // anyone who overrides this as necessary! | ||||
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 121 | return (contents_unique_id_ != details.entry->GetUniqueID()) || |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 122 | (content::PageTransitionStripQualifier( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 123 | details.entry->GetTransitionType()) == |
124 | content::PAGE_TRANSITION_RELOAD); | ||||
[email protected] | 9f507a90 | 2011-07-28 18:45:11 | [diff] [blame] | 125 | } |
126 | |||||
127 | void InfoBarDelegate::RemoveSelf() { | ||||
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 128 | if (owner_) |
129 | owner_->RemoveInfoBar(this); // Clears |owner_|. | ||||
[email protected] | 9f507a90 | 2011-07-28 18:45:11 | [diff] [blame] | 130 | } |