Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / infobars / infobar_delegate.cc
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.
4
5 #include "chrome/browser/infobars/infobar_delegate.h"
6
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"
16
17 using content::NavigationEntry;
18
19 // InfoBarDelegate ------------------------------------------------------------
20
21 const int InfoBarDelegate::kNoIconID = 0;
22
23 InfoBarDelegate::~InfoBarDelegate() {
24 }
25
26 InfoBarDelegate::InfoBarAutomationType
27     InfoBarDelegate::GetInfoBarAutomationType() const {
28   return UNKNOWN_INFOBAR;
29 }
30
31 bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const {
32   return false;
33 }
34
35 bool InfoBarDelegate::ShouldExpire(
36     const content::LoadCommittedDetails& details) const {
37   if (!details.is_navigation_to_different_page())
38     return false;
39
40   return ShouldExpireInternal(details);
41 }
42
43 void InfoBarDelegate::InfoBarDismissed() {
44 }
45
46 int InfoBarDelegate::GetIconID() const {
47   return kNoIconID;
48 }
49
50 InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() const {
51   return WARNING_TYPE;
52 }
53
54 AutoLoginInfoBarDelegate* InfoBarDelegate::AsAutoLoginInfoBarDelegate() {
55   return NULL;
56 }
57
58 ConfirmInfoBarDelegate* InfoBarDelegate::AsConfirmInfoBarDelegate() {
59   return NULL;
60 }
61
62 ExtensionInfoBarDelegate* InfoBarDelegate::AsExtensionInfoBarDelegate() {
63   return NULL;
64 }
65
66 InsecureContentInfoBarDelegate*
67     InfoBarDelegate::AsInsecureContentInfoBarDelegate() {
68   return NULL;
69 }
70
71 MediaStreamInfoBarDelegate* InfoBarDelegate::AsMediaStreamInfoBarDelegate() {
72   return NULL;
73 }
74
75 PopupBlockedInfoBarDelegate* InfoBarDelegate::AsPopupBlockedInfoBarDelegate() {
76   return NULL;
77 }
78
79 RegisterProtocolHandlerInfoBarDelegate*
80     InfoBarDelegate::AsRegisterProtocolHandlerInfoBarDelegate() {
81   return NULL;
82 }
83
84 ScreenCaptureInfoBarDelegate*
85     InfoBarDelegate::AsScreenCaptureInfoBarDelegate() {
86   return NULL;
87 }
88
89 ThemeInstalledInfoBarDelegate*
90     InfoBarDelegate::AsThemePreviewInfobarDelegate() {
91   return NULL;
92 }
93
94 TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() {
95   return NULL;
96 }
97
98 void InfoBarDelegate::StoreActiveEntryUniqueID() {
99   DCHECK(web_contents());
100   NavigationEntry* active_entry =
101       web_contents()->GetController().GetActiveEntry();
102   contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0;
103 }
104
105 gfx::Image InfoBarDelegate::GetIcon() const {
106   int icon_id = GetIconID();
107   return (icon_id == kNoIconID) ? gfx::Image() :
108       ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id);
109 }
110
111 content::WebContents* InfoBarDelegate::web_contents() {
112   return (infobar_ && infobar_->owner()) ?
113       infobar_->owner()->web_contents() : NULL;
114 }
115
116 InfoBarDelegate::InfoBarDelegate() : contents_unique_id_(0) {
117 }
118
119 bool InfoBarDelegate::ShouldExpireInternal(
120     const content::LoadCommittedDetails& details) const {
121   // NOTE: If you change this, be sure to check and adjust the behavior of
122   // anyone who overrides this as necessary!
123   return (contents_unique_id_ != details.entry->GetUniqueID()) ||
124       (content::PageTransitionStripQualifier(
125           details.entry->GetTransitionType()) ==
126               content::PAGE_TRANSITION_RELOAD);
127 }