1 // Copyright 2014 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 "components/infobars/core/infobar_delegate.h"
7 #include "base/logging.h"
8 #include "build/build_config.h"
9 #include "components/infobars/core/infobar.h"
10 #include "components/infobars/core/infobar_manager.h"
11 #include "ui/base/resource/material_design/material_design_controller.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/vector_icons_public.h"
15 #if !defined(OS_MACOSX) && !defined(OS_IOS) && !defined(OS_ANDROID)
16 #include "ui/gfx/paint_vector_icon.h"
17 #include "ui/native_theme/common_theme.h"
18 #include "ui/native_theme/native_theme.h"
23 const int InfoBarDelegate::kNoIconID
= 0;
25 InfoBarDelegate::~InfoBarDelegate() {
28 InfoBarDelegate::InfoBarAutomationType
29 InfoBarDelegate::GetInfoBarAutomationType() const {
30 return UNKNOWN_INFOBAR
;
33 InfoBarDelegate::Type
InfoBarDelegate::GetInfoBarType() const {
37 int InfoBarDelegate::GetIconId() const {
41 gfx::VectorIconId
InfoBarDelegate::GetVectorIconId() const {
42 return gfx::VectorIconId::VECTOR_ICON_NONE
;
45 gfx::Image
InfoBarDelegate::GetIcon() const {
46 #if !defined(OS_MACOSX) && !defined(OS_IOS) && !defined(OS_ANDROID)
47 if (ui::MaterialDesignController::IsModeMaterial()) {
48 gfx::VectorIconId vector_id
= GetVectorIconId();
49 if (vector_id
!= gfx::VectorIconId::VECTOR_ICON_NONE
) {
51 if (GetInfoBarType() == WARNING_TYPE
) {
52 icon_color
= SkColorSetRGB(0xFF, 0x6F, 0x00);
54 ui::CommonThemeGetSystemColor(ui::NativeTheme::kColorId_GoogleBlue
,
57 return gfx::Image(gfx::CreateVectorIcon(vector_id
, 16, icon_color
));
62 int icon_id
= GetIconId();
63 return icon_id
== kNoIconID
? gfx::Image() :
64 ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id
);
67 bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate
* delegate
) const {
71 bool InfoBarDelegate::ShouldExpire(const NavigationDetails
& details
) const {
72 return details
.is_navigation_to_different_page
&&
73 !details
.did_replace_entry
&&
74 // This next condition ensures a navigation that passes the above
75 // conditions doesn't dismiss infobars added while that navigation was
76 // already in process. We carve out an exception for reloads since we
77 // want reloads to dismiss infobars, but they will have unchanged entry
79 ((nav_entry_id_
!= details
.entry_id
) || details
.is_reload
);
82 void InfoBarDelegate::InfoBarDismissed() {
85 ConfirmInfoBarDelegate
* InfoBarDelegate::AsConfirmInfoBarDelegate() {
89 HungRendererInfoBarDelegate
* InfoBarDelegate::AsHungRendererInfoBarDelegate() {
93 InsecureContentInfoBarDelegate
*
94 InfoBarDelegate::AsInsecureContentInfoBarDelegate() {
98 MediaStreamInfoBarDelegate
* InfoBarDelegate::AsMediaStreamInfoBarDelegate() {
102 NativeAppInfoBarDelegate
* InfoBarDelegate::AsNativeAppInfoBarDelegate() {
106 PermissionInfobarDelegate
* InfoBarDelegate::AsPermissionInfobarDelegate() {
110 PopupBlockedInfoBarDelegate
* InfoBarDelegate::AsPopupBlockedInfoBarDelegate() {
114 RegisterProtocolHandlerInfoBarDelegate
*
115 InfoBarDelegate::AsRegisterProtocolHandlerInfoBarDelegate() {
119 ScreenCaptureInfoBarDelegate
*
120 InfoBarDelegate::AsScreenCaptureInfoBarDelegate() {
124 ThemeInstalledInfoBarDelegate
*
125 InfoBarDelegate::AsThemePreviewInfobarDelegate() {
129 ThreeDAPIInfoBarDelegate
* InfoBarDelegate::AsThreeDAPIInfoBarDelegate() {
133 translate::TranslateInfoBarDelegate
*
134 InfoBarDelegate::AsTranslateInfoBarDelegate() {
138 InfoBarDelegate::InfoBarDelegate() : nav_entry_id_(0) {
141 } // namespace infobars