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
|
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_
#define CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
namespace content {
class WebContents;
}
class InfoBarDelegate;
// Provides access to creating, removing and enumerating info bars
// attached to a tab.
class InfoBarService : public content::WebContentsObserver,
public content::NotificationObserver,
public content::WebContentsUserData<InfoBarService> {
public:
// Changes whether infobars are enabled. The default is true.
void set_infobars_enabled(bool enabled) { infobars_enabled_ = enabled; }
// Adds an InfoBar for the specified |delegate|.
//
// If infobars are disabled for this tab or the tab already has a delegate
// which returns true for InfoBarDelegate::EqualsDelegate(delegate),
// |delegate| is closed immediately without being added.
//
// Returns the delegate if it was successfully added.
InfoBarDelegate* AddInfoBar(scoped_ptr<InfoBarDelegate> delegate);
// Removes the InfoBar for the specified |delegate|.
//
// If infobars are disabled for this tab, this will do nothing, on the
// assumption that the matching AddInfoBar() call will have already closed the
// delegate (see above).
void RemoveInfoBar(InfoBarDelegate* delegate);
// Replaces one infobar with another, without any animation in between.
//
// If infobars are disabled for this tab, |new_delegate| is closed immediately
// without being added, and nothing else happens.
//
// Returns the new delegate if it was successfully added.
//
// NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar().
InfoBarDelegate* ReplaceInfoBar(InfoBarDelegate* old_delegate,
scoped_ptr<InfoBarDelegate> new_delegate);
// Returns the number of infobars for this tab.
size_t infobar_count() const { return infobars_.size(); }
// Returns the infobar delegate at the given |index|. The InfoBarService
// retains ownership.
//
// Warning: Does not sanity check |index|.
InfoBarDelegate* infobar_at(size_t index) { return infobars_[index]; }
// Retrieve the WebContents for the tab this service is associated with.
content::WebContents* web_contents() {
return content::WebContentsObserver::web_contents();
}
private:
friend class content::WebContentsUserData<InfoBarService>;
typedef std::vector<InfoBarDelegate*> InfoBars;
explicit InfoBarService(content::WebContents* web_contents);
virtual ~InfoBarService();
// content::WebContentsObserver:
virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
void RemoveInfoBarInternal(InfoBarDelegate* delegate, bool animate);
void RemoveAllInfoBars(bool animate);
// Message handlers.
void OnDidBlockDisplayingInsecureContent();
void OnDidBlockRunningInsecureContent();
// Delegates for InfoBars associated with this InfoBarService.
InfoBars infobars_;
bool infobars_enabled_;
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(InfoBarService);
};
#endif // CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_
|