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
|
// Copyright (c) 2010 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/blocked_content_container.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "gfx/rect.h"
// static
const size_t BlockedContentContainer::kImpossibleNumberOfPopups = 30;
struct BlockedContentContainer::BlockedContent {
BlockedContent(TabContents* tab_contents,
WindowOpenDisposition disposition,
const gfx::Rect& bounds,
bool user_gesture)
: tab_contents(tab_contents),
disposition(disposition),
bounds(bounds),
user_gesture(user_gesture) {
}
TabContents* tab_contents;
WindowOpenDisposition disposition;
gfx::Rect bounds;
bool user_gesture;
};
BlockedContentContainer::BlockedContentContainer(TabContents* owner)
: owner_(owner) {
}
BlockedContentContainer::~BlockedContentContainer() {}
void BlockedContentContainer::AddTabContents(TabContents* tab_contents,
WindowOpenDisposition disposition,
const gfx::Rect& bounds,
bool user_gesture) {
if (blocked_contents_.size() == (kImpossibleNumberOfPopups - 1)) {
delete tab_contents;
VLOG(1) << "Warning: Renderer is sending more popups to us than should be "
"possible. Renderer compromised?";
return;
}
blocked_contents_.push_back(
BlockedContent(tab_contents, disposition, bounds, user_gesture));
tab_contents->set_delegate(this);
// Since the new tab_contents will not be showed, call WasHidden to change
// its status on both RenderViewHost and RenderView.
tab_contents->WasHidden();
if (blocked_contents_.size() == 1)
owner_->PopupNotificationVisibilityChanged(true);
}
void BlockedContentContainer::LaunchForContents(TabContents* tab_contents) {
// Open the popup.
for (BlockedContents::iterator i(blocked_contents_.begin());
i != blocked_contents_.end(); ++i) {
if (i->tab_contents == tab_contents) {
// To support the owner blocking the content again we copy and erase
// before attempting to add.
BlockedContent content(*i);
blocked_contents_.erase(i);
i = blocked_contents_.end();
tab_contents->set_delegate(NULL);
// We needn't call WasRestored to change its status because the
// TabContents::AddNewContents will do it.
owner_->AddNewContents(tab_contents, content.disposition, content.bounds,
content.user_gesture);
break;
}
}
if (blocked_contents_.empty())
Destroy();
}
size_t BlockedContentContainer::GetBlockedContentsCount() const {
return blocked_contents_.size();
}
void BlockedContentContainer::GetBlockedContents(
std::vector<TabContents*>* blocked_contents) const {
DCHECK(blocked_contents);
for (BlockedContents::const_iterator i(blocked_contents_.begin());
i != blocked_contents_.end(); ++i)
blocked_contents->push_back(i->tab_contents);
}
void BlockedContentContainer::Destroy() {
for (BlockedContents::iterator i(blocked_contents_.begin());
i != blocked_contents_.end(); ++i) {
TabContents* tab_contents = i->tab_contents;
tab_contents->set_delegate(NULL);
delete tab_contents;
}
blocked_contents_.clear();
owner_->WillCloseBlockedContentContainer(this);
delete this;
}
// Overridden from TabContentsDelegate:
void BlockedContentContainer::OpenURLFromTab(TabContents* source,
const GURL& url,
const GURL& referrer,
WindowOpenDisposition disposition,
PageTransition::Type transition) {
owner_->OpenURL(url, referrer, disposition, transition);
}
void BlockedContentContainer::AddNewContents(TabContents* source,
TabContents* new_contents,
WindowOpenDisposition disposition,
const gfx::Rect& initial_position,
bool user_gesture) {
owner_->AddNewContents(new_contents, disposition, initial_position,
user_gesture);
}
void BlockedContentContainer::CloseContents(TabContents* source) {
for (BlockedContents::iterator i(blocked_contents_.begin());
i != blocked_contents_.end(); ++i) {
TabContents* tab_contents = i->tab_contents;
if (tab_contents == source) {
tab_contents->set_delegate(NULL);
blocked_contents_.erase(i);
delete tab_contents;
break;
}
}
}
void BlockedContentContainer::MoveContents(TabContents* source,
const gfx::Rect& new_bounds) {
for (BlockedContents::iterator i(blocked_contents_.begin());
i != blocked_contents_.end(); ++i) {
if (i->tab_contents == source) {
i->bounds = new_bounds;
break;
}
}
}
bool BlockedContentContainer::IsPopup(const TabContents* source) const {
// Assume everything added is a popup. This may turn out to be wrong, but
// callers don't cache this information so it should be fine if the value ends
// up changing.
return true;
}
TabContents* BlockedContentContainer::GetConstrainingContents(
TabContents* source) {
return owner_;
}
|