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" | 9 #include "chrome/browser/infobars/infobar.h" |
10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
11 #include "content/public/browser/navigation_controller.h" | 11 #include "content/public/browser/navigation_controller.h" |
12 #include "content/public/browser/navigation_details.h" | 12 #include "content/public/browser/navigation_details.h" |
13 #include "content/public/browser/navigation_entry.h" | 13 #include "content/public/browser/navigation_entry.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
16 | 16 |
17 namespace { | |
18 content::WebContents* WebContentsFromInfoBar(InfoBar* infobar) { | |
droger
2014/04/08 15:00:11
The plan would be to make this helper function pub
Peter Kasting
2014/04/08 20:39:56
I didn't go this route for two reasons:
(1) Callsi
droger
2014/04/08 20:54:46
About (2), I don't think we still need to have dif
Peter Kasting
2014/04/08 21:41:35
Right, I was suggesting that the base class route
| |
19 if (!infobar || !infobar->owner()) | |
20 return NULL; | |
21 | |
22 InfoBarService* infobar_service = | |
23 static_cast<InfoBarService*>(infobar->owner()); | |
24 return infobar_service->web_contents(); | |
25 } | |
26 } // namespace | |
27 | |
17 using content::NavigationEntry; | 28 using content::NavigationEntry; |
18 | 29 |
19 // InfoBarDelegate ------------------------------------------------------------ | 30 // InfoBarDelegate ------------------------------------------------------------ |
20 | 31 |
21 const int InfoBarDelegate::kNoIconID = 0; | 32 const int InfoBarDelegate::kNoIconID = 0; |
22 | 33 |
23 InfoBarDelegate::~InfoBarDelegate() { | 34 InfoBarDelegate::~InfoBarDelegate() { |
24 } | 35 } |
25 | 36 |
26 InfoBarDelegate::InfoBarAutomationType | 37 InfoBarDelegate::InfoBarAutomationType |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0; | 112 contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0; |
102 } | 113 } |
103 | 114 |
104 gfx::Image InfoBarDelegate::GetIcon() const { | 115 gfx::Image InfoBarDelegate::GetIcon() const { |
105 int icon_id = GetIconID(); | 116 int icon_id = GetIconID(); |
106 return (icon_id == kNoIconID) ? gfx::Image() : | 117 return (icon_id == kNoIconID) ? gfx::Image() : |
107 ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id); | 118 ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id); |
108 } | 119 } |
109 | 120 |
110 content::WebContents* InfoBarDelegate::web_contents() { | 121 content::WebContents* InfoBarDelegate::web_contents() { |
111 return (infobar_ && infobar_->owner()) ? | 122 return WebContentsFromInfoBar(infobar_); |
112 infobar_->owner()->web_contents() : NULL; | |
113 } | 123 } |
114 | 124 |
115 InfoBarDelegate::InfoBarDelegate() : contents_unique_id_(0) { | 125 InfoBarDelegate::InfoBarDelegate() : contents_unique_id_(0) { |
116 } | 126 } |
117 | 127 |
118 bool InfoBarDelegate::ShouldExpireInternal( | 128 bool InfoBarDelegate::ShouldExpireInternal( |
119 const NavigationDetails& details) const { | 129 const NavigationDetails& details) const { |
120 // NOTE: If you change this, be sure to check and adjust the behavior of | 130 // NOTE: If you change this, be sure to check and adjust the behavior of |
121 // anyone who overrides this as necessary! | 131 // anyone who overrides this as necessary! |
122 return (contents_unique_id_ != details.entry_id) || details.is_reload; | 132 return (contents_unique_id_ != details.entry_id) || details.is_reload; |
123 } | 133 } |
OLD | NEW |