summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents/infobar_delegate.cc
blob: 671d17bd467143569bcc5ac10ee3456e1a0a0ee6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/tab_contents/infobar_delegate.h"

#include "app/l10n_util.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "grit/generated_resources.h"

// InfoBarDelegate: ------------------------------------------------------------

bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const {
  return false;
}

bool InfoBarDelegate::ShouldExpire(
    const NavigationController::LoadCommittedDetails& details) const {
  bool is_reload =
      PageTransition::StripQualifier(details.entry->transition_type()) ==
          PageTransition::RELOAD;
  return is_reload || (contents_unique_id_ != details.entry->unique_id());
}

SkBitmap* InfoBarDelegate::GetIcon() const {
  return NULL;
}

AlertInfoBarDelegate* InfoBarDelegate::AsAlertInfoBarDelegate() {
  return NULL;
}

LinkInfoBarDelegate* InfoBarDelegate::AsLinkInfoBarDelegate() {
  return NULL;
}

ConfirmInfoBarDelegate* InfoBarDelegate::AsConfirmInfoBarDelegate() {
  return NULL;
}

ThemeInstalledInfoBarDelegate*
InfoBarDelegate::AsThemePreviewInfobarDelegate() {
  return NULL;
}

TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() {
  return NULL;
}

ExtensionInfoBarDelegate* InfoBarDelegate::AsExtensionInfoBarDelegate() {
  return NULL;
}

CrashedExtensionInfoBarDelegate*
InfoBarDelegate::AsCrashedExtensionInfoBarDelegate() {
  return NULL;
}

InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() {
  return WARNING_TYPE;
}

InfoBarDelegate::InfoBarDelegate(TabContents* contents)
    : contents_unique_id_(0) {
  if (contents)
    StoreActiveEntryUniqueID(contents);
}

void InfoBarDelegate::StoreActiveEntryUniqueID(TabContents* contents) {
  NavigationEntry* active_entry = contents->controller().GetActiveEntry();
  contents_unique_id_ = active_entry ? active_entry->unique_id() : 0;
}

// AlertInfoBarDelegate: -------------------------------------------------------

SkBitmap* AlertInfoBarDelegate::GetIcon() const {
  return NULL;
}

bool AlertInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const {
  AlertInfoBarDelegate* alert_delegate = delegate->AsAlertInfoBarDelegate();
  if (!alert_delegate)
    return false;

  return alert_delegate->GetMessageText() == GetMessageText();
}

AlertInfoBarDelegate* AlertInfoBarDelegate::AsAlertInfoBarDelegate() {
  return this;
}

AlertInfoBarDelegate::AlertInfoBarDelegate(TabContents* contents)
    : InfoBarDelegate(contents) {
}

// LinkInfoBarDelegate: --------------------------------------------------------

string16 LinkInfoBarDelegate::GetMessageTextWithOffset(
    size_t* link_offset) const {
  *link_offset = string16::npos;
  return string16();
}

SkBitmap* LinkInfoBarDelegate::GetIcon() const {
  return NULL;
}

bool LinkInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
  return true;
}

LinkInfoBarDelegate* LinkInfoBarDelegate::AsLinkInfoBarDelegate() {
  return this;
}

LinkInfoBarDelegate::LinkInfoBarDelegate(TabContents* contents)
    : InfoBarDelegate(contents) {
}

// ConfirmInfoBarDelegate: -----------------------------------------------------

int ConfirmInfoBarDelegate::GetButtons() const {
  return BUTTON_NONE;
}

string16 ConfirmInfoBarDelegate::GetButtonLabel(
    InfoBarButton button) const {
  if (button == BUTTON_OK)
    return l10n_util::GetStringUTF16(IDS_OK);
  if (button == BUTTON_CANCEL)
    return l10n_util::GetStringUTF16(IDS_CANCEL);
  NOTREACHED();
  return string16();
}

bool ConfirmInfoBarDelegate::NeedElevation(InfoBarButton button) const {
  return false;
}

bool ConfirmInfoBarDelegate::Accept() {
  return true;
}

bool ConfirmInfoBarDelegate::Cancel() {
  return true;
}

string16 ConfirmInfoBarDelegate::GetLinkText() {
  return string16();
}

bool ConfirmInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
  return true;
}

ConfirmInfoBarDelegate* ConfirmInfoBarDelegate::AsConfirmInfoBarDelegate() {
  return this;
}

ConfirmInfoBarDelegate::ConfirmInfoBarDelegate(TabContents* contents)
    : AlertInfoBarDelegate(contents) {
}

// SimpleAlertInfoBarDelegate: -------------------------------------------------

SimpleAlertInfoBarDelegate::SimpleAlertInfoBarDelegate(
    TabContents* contents,
    const string16& message,
    SkBitmap* icon,
    bool auto_expire)
    : AlertInfoBarDelegate(contents),
      message_(message),
      icon_(icon),
      auto_expire_(auto_expire) {
}

bool SimpleAlertInfoBarDelegate::ShouldExpire(
      const NavigationController::LoadCommittedDetails& details) const {
  if (auto_expire_)
    return AlertInfoBarDelegate::ShouldExpire(details);

  return false;
}

string16 SimpleAlertInfoBarDelegate::GetMessageText() const {
  return message_;
}

SkBitmap* SimpleAlertInfoBarDelegate::GetIcon() const {
  return icon_;
}

void SimpleAlertInfoBarDelegate::InfoBarClosed() {
  delete this;
}