Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: chrome/browser/blocked_content_container.cc

Issue 6854035: Move blocked content from TabContents to TabContentsWrapper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 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/blocked_content_container.h"
6
7 #include "content/browser/tab_contents/tab_contents.h"
8 #include "ui/gfx/rect.h"
9
10 // static
11 const size_t BlockedContentContainer::kImpossibleNumberOfPopups = 30;
12
13 struct BlockedContentContainer::BlockedContent {
14 BlockedContent(TabContents* tab_contents,
15 WindowOpenDisposition disposition,
16 const gfx::Rect& bounds,
17 bool user_gesture)
18 : tab_contents(tab_contents),
19 disposition(disposition),
20 bounds(bounds),
21 user_gesture(user_gesture) {
22 }
23
24 TabContents* tab_contents;
25 WindowOpenDisposition disposition;
26 gfx::Rect bounds;
27 bool user_gesture;
28 };
29
30 BlockedContentContainer::BlockedContentContainer(TabContents* owner)
31 : owner_(owner) {
32 }
33
34 BlockedContentContainer::~BlockedContentContainer() {}
35
36 void BlockedContentContainer::AddTabContents(TabContents* tab_contents,
37 WindowOpenDisposition disposition,
38 const gfx::Rect& bounds,
39 bool user_gesture) {
40 if (blocked_contents_.size() == (kImpossibleNumberOfPopups - 1)) {
41 delete tab_contents;
42 VLOG(1) << "Warning: Renderer is sending more popups to us than should be "
43 "possible. Renderer compromised?";
44 return;
45 }
46
47 blocked_contents_.push_back(
48 BlockedContent(tab_contents, disposition, bounds, user_gesture));
49 tab_contents->set_delegate(this);
50 // Since the new tab_contents will not be showed, call WasHidden to change
51 // its status on both RenderViewHost and RenderView.
52 tab_contents->WasHidden();
53 if (blocked_contents_.size() == 1)
54 owner_->PopupNotificationVisibilityChanged(true);
55 }
56
57 void BlockedContentContainer::LaunchForContents(TabContents* tab_contents) {
58 // Open the popup.
59 for (BlockedContents::iterator i(blocked_contents_.begin());
60 i != blocked_contents_.end(); ++i) {
61 if (i->tab_contents == tab_contents) {
62 // To support the owner blocking the content again we copy and erase
63 // before attempting to add.
64 BlockedContent content(*i);
65 blocked_contents_.erase(i);
66 i = blocked_contents_.end();
67 tab_contents->set_delegate(NULL);
68 // We needn't call WasRestored to change its status because the
69 // TabContents::AddNewContents will do it.
70 owner_->AddNewContents(tab_contents, content.disposition, content.bounds,
71 content.user_gesture);
72 break;
73 }
74 }
75
76 if (blocked_contents_.empty())
77 Destroy();
78 }
79
80 size_t BlockedContentContainer::GetBlockedContentsCount() const {
81 return blocked_contents_.size();
82 }
83
84 void BlockedContentContainer::GetBlockedContents(
85 std::vector<TabContents*>* blocked_contents) const {
86 DCHECK(blocked_contents);
87 for (BlockedContents::const_iterator i(blocked_contents_.begin());
88 i != blocked_contents_.end(); ++i)
89 blocked_contents->push_back(i->tab_contents);
90 }
91
92 void BlockedContentContainer::Destroy() {
93 for (BlockedContents::iterator i(blocked_contents_.begin());
94 i != blocked_contents_.end(); ++i) {
95 TabContents* tab_contents = i->tab_contents;
96 tab_contents->set_delegate(NULL);
97 delete tab_contents;
98 }
99 blocked_contents_.clear();
100 owner_->WillCloseBlockedContentContainer(this);
101 delete this;
102 }
103
104 // Overridden from TabContentsDelegate:
105 void BlockedContentContainer::OpenURLFromTab(TabContents* source,
106 const GURL& url,
107 const GURL& referrer,
108 WindowOpenDisposition disposition,
109 PageTransition::Type transition) {
110 owner_->OpenURL(url, referrer, disposition, transition);
111 }
112
113 void BlockedContentContainer::AddNewContents(TabContents* source,
114 TabContents* new_contents,
115 WindowOpenDisposition disposition,
116 const gfx::Rect& initial_position,
117 bool user_gesture) {
118 owner_->AddNewContents(new_contents, disposition, initial_position,
119 user_gesture);
120 }
121
122 void BlockedContentContainer::CloseContents(TabContents* source) {
123 for (BlockedContents::iterator i(blocked_contents_.begin());
124 i != blocked_contents_.end(); ++i) {
125 TabContents* tab_contents = i->tab_contents;
126 if (tab_contents == source) {
127 tab_contents->set_delegate(NULL);
128 blocked_contents_.erase(i);
129 delete tab_contents;
130 break;
131 }
132 }
133 }
134
135 void BlockedContentContainer::MoveContents(TabContents* source,
136 const gfx::Rect& new_bounds) {
137 for (BlockedContents::iterator i(blocked_contents_.begin());
138 i != blocked_contents_.end(); ++i) {
139 if (i->tab_contents == source) {
140 i->bounds = new_bounds;
141 break;
142 }
143 }
144 }
145
146 bool BlockedContentContainer::IsPopup(const TabContents* source) const {
147 // Assume everything added is a popup. This may turn out to be wrong, but
148 // callers don't cache this information so it should be fine if the value ends
149 // up changing.
150 return true;
151 }
152
153 TabContents* BlockedContentContainer::GetConstrainingContents(
154 TabContents* source) {
155 return owner_;
156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698