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

Side by Side Diff: chrome/browser/ui/blocked_content/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: rebase again 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/blocked_content_container.h" 5 #include "chrome/browser/ui/blocked_content/blocked_content_container.h"
6 6
7 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
7 #include "content/browser/tab_contents/tab_contents.h" 9 #include "content/browser/tab_contents/tab_contents.h"
8 #include "ui/gfx/rect.h" 10 #include "ui/gfx/rect.h"
9 11
10 // static 12 // static
11 const size_t BlockedContentContainer::kImpossibleNumberOfPopups = 30; 13 const size_t BlockedContentContainer::kImpossibleNumberOfPopups = 30;
12 14
13 struct BlockedContentContainer::BlockedContent { 15 struct BlockedContentContainer::BlockedContent {
14 BlockedContent(TabContents* tab_contents, 16 BlockedContent(TabContentsWrapper* tab_contents,
15 WindowOpenDisposition disposition, 17 WindowOpenDisposition disposition,
16 const gfx::Rect& bounds, 18 const gfx::Rect& bounds,
17 bool user_gesture) 19 bool user_gesture)
18 : tab_contents(tab_contents), 20 : tab_contents(tab_contents),
19 disposition(disposition), 21 disposition(disposition),
20 bounds(bounds), 22 bounds(bounds),
21 user_gesture(user_gesture) { 23 user_gesture(user_gesture) {
22 } 24 }
23 25
24 TabContents* tab_contents; 26 TabContentsWrapper* tab_contents;
25 WindowOpenDisposition disposition; 27 WindowOpenDisposition disposition;
26 gfx::Rect bounds; 28 gfx::Rect bounds;
27 bool user_gesture; 29 bool user_gesture;
28 }; 30 };
29 31
30 BlockedContentContainer::BlockedContentContainer(TabContents* owner) 32 BlockedContentContainer::BlockedContentContainer(TabContentsWrapper* owner)
31 : owner_(owner) { 33 : owner_(owner) {
32 } 34 }
33 35
34 BlockedContentContainer::~BlockedContentContainer() {} 36 BlockedContentContainer::~BlockedContentContainer() {
37 Clear();
38 }
35 39
36 void BlockedContentContainer::AddTabContents(TabContents* tab_contents, 40 void BlockedContentContainer::AddTabContents(TabContentsWrapper* tab_contents,
stevenjb 2011/04/21 19:03:00 nit: tab_contents_wrapper, or maybe just wrapper?
37 WindowOpenDisposition disposition, 41 WindowOpenDisposition disposition,
38 const gfx::Rect& bounds, 42 const gfx::Rect& bounds,
39 bool user_gesture) { 43 bool user_gesture) {
40 if (blocked_contents_.size() == (kImpossibleNumberOfPopups - 1)) { 44 if (blocked_contents_.size() == (kImpossibleNumberOfPopups - 1)) {
41 delete tab_contents; 45 delete tab_contents;
42 VLOG(1) << "Warning: Renderer is sending more popups to us than should be " 46 VLOG(1) << "Warning: Renderer is sending more popups to us than should be "
43 "possible. Renderer compromised?"; 47 "possible. Renderer compromised?";
44 return; 48 return;
45 } 49 }
46 50
47 blocked_contents_.push_back( 51 blocked_contents_.push_back(
48 BlockedContent(tab_contents, disposition, bounds, user_gesture)); 52 BlockedContent(tab_contents, disposition, bounds, user_gesture));
49 tab_contents->set_delegate(this); 53 // TODO(avi): remove once TabContentsDelegate::GetConstrainingContents goes
50 // Since the new tab_contents will not be showed, call WasHidden to change 54 // away.
55 tab_contents->tab_contents()->set_delegate(this);
56 tab_contents->blocked_content_tab_helper()->set_delegate(this);
57 // Since the new tab_contents will not be shown, call WasHidden to change
51 // its status on both RenderViewHost and RenderView. 58 // its status on both RenderViewHost and RenderView.
52 tab_contents->WasHidden(); 59 tab_contents->tab_contents()->WasHidden();
53 if (blocked_contents_.size() == 1)
54 owner_->PopupNotificationVisibilityChanged(true);
55 } 60 }
56 61
57 void BlockedContentContainer::LaunchForContents(TabContents* tab_contents) { 62 void BlockedContentContainer::LaunchForContents(
63 TabContentsWrapper* tab_contents) {
stevenjb 2011/04/21 19:03:00 nit: wrapper?
58 // Open the popup. 64 // Open the popup.
59 for (BlockedContents::iterator i(blocked_contents_.begin()); 65 for (BlockedContents::iterator i(blocked_contents_.begin());
60 i != blocked_contents_.end(); ++i) { 66 i != blocked_contents_.end(); ++i) {
61 if (i->tab_contents == tab_contents) { 67 if (i->tab_contents == tab_contents) {
62 // To support the owner blocking the content again we copy and erase 68 // To support the owner blocking the content again we copy and erase
63 // before attempting to add. 69 // before attempting to add.
64 BlockedContent content(*i); 70 BlockedContent content(*i);
65 blocked_contents_.erase(i); 71 blocked_contents_.erase(i);
66 i = blocked_contents_.end(); 72 i = blocked_contents_.end();
67 tab_contents->set_delegate(NULL); 73 // TODO(avi): remove once TabContentsDelegate::GetConstrainingContents
74 // goes away.
75 tab_contents->tab_contents()->set_delegate(NULL);
76 tab_contents->blocked_content_tab_helper()->set_delegate(NULL);
68 // We needn't call WasRestored to change its status because the 77 // We needn't call WasRestored to change its status because the
69 // TabContents::AddNewContents will do it. 78 // TabContents::AddNewContents will do it.
70 owner_->AddOrBlockNewContents(tab_contents, 79 owner_->tab_contents()->AddNewContents(
71 content.disposition, 80 tab_contents->tab_contents(),
72 content.bounds, 81 content.disposition,
73 content.user_gesture); 82 content.bounds,
83 content.user_gesture);
74 break; 84 break;
75 } 85 }
76 } 86 }
77
78 if (blocked_contents_.empty())
79 Destroy();
80 } 87 }
81 88
82 size_t BlockedContentContainer::GetBlockedContentsCount() const { 89 size_t BlockedContentContainer::GetBlockedContentsCount() const {
83 return blocked_contents_.size(); 90 return blocked_contents_.size();
84 } 91 }
85 92
86 void BlockedContentContainer::GetBlockedContents( 93 void BlockedContentContainer::GetBlockedContents(
87 std::vector<TabContents*>* blocked_contents) const { 94 std::vector<TabContentsWrapper*>* blocked_contents) const {
88 DCHECK(blocked_contents); 95 DCHECK(blocked_contents);
89 for (BlockedContents::const_iterator i(blocked_contents_.begin()); 96 for (BlockedContents::const_iterator i(blocked_contents_.begin());
90 i != blocked_contents_.end(); ++i) 97 i != blocked_contents_.end(); ++i)
91 blocked_contents->push_back(i->tab_contents); 98 blocked_contents->push_back(i->tab_contents);
92 } 99 }
93 100
94 void BlockedContentContainer::Destroy() { 101 void BlockedContentContainer::Clear() {
95 for (BlockedContents::iterator i(blocked_contents_.begin()); 102 for (BlockedContents::iterator i(blocked_contents_.begin());
96 i != blocked_contents_.end(); ++i) { 103 i != blocked_contents_.end(); ++i) {
97 TabContents* tab_contents = i->tab_contents; 104 TabContentsWrapper* tab_contents = i->tab_contents;
98 tab_contents->set_delegate(NULL); 105 // TODO(avi): remove once TabContentsDelegate::GetConstrainingContents goes
106 // away.
107 tab_contents->tab_contents()->set_delegate(NULL);
108 tab_contents->blocked_content_tab_helper()->set_delegate(NULL);
99 delete tab_contents; 109 delete tab_contents;
100 } 110 }
101 blocked_contents_.clear(); 111 blocked_contents_.clear();
102 owner_->WillCloseBlockedContentContainer(this);
103 delete this;
104 } 112 }
105 113
106 // Overridden from TabContentsDelegate: 114 // Overridden from TabContentsDelegate:
107 void BlockedContentContainer::OpenURLFromTab(TabContents* source, 115 void BlockedContentContainer::OpenURLFromTab(TabContents* source,
108 const GURL& url, 116 const GURL& url,
109 const GURL& referrer, 117 const GURL& referrer,
110 WindowOpenDisposition disposition, 118 WindowOpenDisposition disposition,
111 PageTransition::Type transition) { 119 PageTransition::Type transition) {
112 owner_->OpenURL(url, referrer, disposition, transition); 120 owner_->tab_contents()->OpenURL(url, referrer, disposition, transition);
113 } 121 }
114 122
115 void BlockedContentContainer::AddNewContents(TabContents* source, 123 void BlockedContentContainer::AddNewContents(TabContents* source,
116 TabContents* new_contents, 124 TabContents* new_contents,
117 WindowOpenDisposition disposition, 125 WindowOpenDisposition disposition,
118 const gfx::Rect& initial_position, 126 const gfx::Rect& initial_position,
119 bool user_gesture) { 127 bool user_gesture) {
120 owner_->AddOrBlockNewContents( 128 owner_->tab_contents()->AddNewContents(
121 new_contents, disposition, initial_position, user_gesture); 129 new_contents, disposition, initial_position, user_gesture);
122 } 130 }
123 131
124 void BlockedContentContainer::CloseContents(TabContents* source) { 132 void BlockedContentContainer::CloseContents(TabContents* source) {
125 for (BlockedContents::iterator i(blocked_contents_.begin()); 133 for (BlockedContents::iterator i(blocked_contents_.begin());
126 i != blocked_contents_.end(); ++i) { 134 i != blocked_contents_.end(); ++i) {
127 TabContents* tab_contents = i->tab_contents; 135 TabContentsWrapper* tab_contents = i->tab_contents;
stevenjb 2011/04/21 19:03:00 nit: tab_contents_wrapper
128 if (tab_contents == source) { 136 if (tab_contents->tab_contents() == source) {
129 tab_contents->set_delegate(NULL); 137 // TODO(avi): remove once TabContentsDelegate::GetConstrainingContents
138 // goes away.
139 tab_contents->tab_contents()->set_delegate(NULL);
140 tab_contents->blocked_content_tab_helper()->set_delegate(NULL);
130 blocked_contents_.erase(i); 141 blocked_contents_.erase(i);
131 delete tab_contents; 142 delete tab_contents;
132 break; 143 break;
133 } 144 }
134 } 145 }
135 } 146 }
136 147
137 void BlockedContentContainer::MoveContents(TabContents* source, 148 void BlockedContentContainer::MoveContents(TabContents* source,
138 const gfx::Rect& new_bounds) { 149 const gfx::Rect& new_bounds) {
139 for (BlockedContents::iterator i(blocked_contents_.begin()); 150 for (BlockedContents::iterator i(blocked_contents_.begin());
140 i != blocked_contents_.end(); ++i) { 151 i != blocked_contents_.end(); ++i) {
141 if (i->tab_contents == source) { 152 if (i->tab_contents->tab_contents() == source) {
142 i->bounds = new_bounds; 153 i->bounds = new_bounds;
143 break; 154 break;
144 } 155 }
145 } 156 }
146 } 157 }
147 158
148 bool BlockedContentContainer::IsPopup(const TabContents* source) const { 159 bool BlockedContentContainer::IsPopup(const TabContents* source) const {
149 // Assume everything added is a popup. This may turn out to be wrong, but 160 // Assume everything added is a popup. This may turn out to be wrong, but
150 // callers don't cache this information so it should be fine if the value ends 161 // callers don't cache this information so it should be fine if the value ends
151 // up changing. 162 // up changing.
152 return true; 163 return true;
153 } 164 }
154 165
155 TabContents* BlockedContentContainer::GetConstrainingContents( 166 TabContents* BlockedContentContainer::GetConstrainingContents(
156 TabContents* source) { 167 TabContents* source) {
168 return owner_->tab_contents();
169 }
170
171 TabContentsWrapper* BlockedContentContainer::GetConstrainingContents(
172 TabContentsWrapper* source) {
157 return owner_; 173 return owner_;
158 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698