| OLD | NEW |
| 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/ui/blocked_content/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" | 7 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 #include "ui/gfx/rect.h" | 10 #include "ui/gfx/rect.h" |
| 11 | 11 |
| 12 using content::OpenURLParams; | 12 using content::OpenURLParams; |
| 13 using content::WebContents; | 13 using content::WebContents; |
| 14 | 14 |
| 15 // static | 15 // static |
| 16 const size_t BlockedContentContainer::kImpossibleNumberOfPopups = 30; | 16 const size_t BlockedContentContainer::kImpossibleNumberOfPopups = 30; |
| 17 | 17 |
| 18 struct BlockedContentContainer::BlockedContent { | 18 struct BlockedContentContainer::BlockedContent { |
| 19 BlockedContent(TabContentsWrapper* tab_contents, | 19 BlockedContent(TabContents* tab_contents, |
| 20 WindowOpenDisposition disposition, | 20 WindowOpenDisposition disposition, |
| 21 const gfx::Rect& bounds, | 21 const gfx::Rect& bounds, |
| 22 bool user_gesture) | 22 bool user_gesture) |
| 23 : tab_contents(tab_contents), | 23 : tab_contents(tab_contents), |
| 24 disposition(disposition), | 24 disposition(disposition), |
| 25 bounds(bounds), | 25 bounds(bounds), |
| 26 user_gesture(user_gesture) { | 26 user_gesture(user_gesture) { |
| 27 } | 27 } |
| 28 | 28 |
| 29 TabContentsWrapper* tab_contents; | 29 TabContents* tab_contents; |
| 30 WindowOpenDisposition disposition; | 30 WindowOpenDisposition disposition; |
| 31 gfx::Rect bounds; | 31 gfx::Rect bounds; |
| 32 bool user_gesture; | 32 bool user_gesture; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 BlockedContentContainer::BlockedContentContainer(TabContentsWrapper* owner) | 35 BlockedContentContainer::BlockedContentContainer(TabContents* owner) |
| 36 : owner_(owner) { | 36 : owner_(owner) { |
| 37 } | 37 } |
| 38 | 38 |
| 39 BlockedContentContainer::~BlockedContentContainer() { | 39 BlockedContentContainer::~BlockedContentContainer() { |
| 40 Clear(); | 40 Clear(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void BlockedContentContainer::AddTabContents(TabContentsWrapper* tab_contents, | 43 void BlockedContentContainer::AddTabContents(TabContents* tab_contents, |
| 44 WindowOpenDisposition disposition, | 44 WindowOpenDisposition disposition, |
| 45 const gfx::Rect& bounds, | 45 const gfx::Rect& bounds, |
| 46 bool user_gesture) { | 46 bool user_gesture) { |
| 47 if (blocked_contents_.size() == (kImpossibleNumberOfPopups - 1)) { | 47 if (blocked_contents_.size() == (kImpossibleNumberOfPopups - 1)) { |
| 48 delete tab_contents; | 48 delete tab_contents; |
| 49 VLOG(1) << "Warning: Renderer is sending more popups to us than should be " | 49 VLOG(1) << "Warning: Renderer is sending more popups to us than should be " |
| 50 "possible. Renderer compromised?"; | 50 "possible. Renderer compromised?"; |
| 51 return; | 51 return; |
| 52 } | 52 } |
| 53 | 53 |
| 54 blocked_contents_.push_back( | 54 blocked_contents_.push_back( |
| 55 BlockedContent(tab_contents, disposition, bounds, user_gesture)); | 55 BlockedContent(tab_contents, disposition, bounds, user_gesture)); |
| 56 tab_contents->web_contents()->SetDelegate(this); | 56 tab_contents->web_contents()->SetDelegate(this); |
| 57 tab_contents->blocked_content_tab_helper()->set_delegate(this); | 57 tab_contents->blocked_content_tab_helper()->set_delegate(this); |
| 58 // Since the new tab_contents will not be shown, call WasHidden to change | 58 // Since the new tab_contents will not be shown, call WasHidden to change |
| 59 // its status on both RenderViewHost and RenderView. | 59 // its status on both RenderViewHost and RenderView. |
| 60 tab_contents->web_contents()->WasHidden(); | 60 tab_contents->web_contents()->WasHidden(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void BlockedContentContainer::LaunchForContents( | 63 void BlockedContentContainer::LaunchForContents(TabContents* tab_contents) { |
| 64 TabContentsWrapper* tab_contents) { | |
| 65 // Open the popup. | 64 // Open the popup. |
| 66 for (BlockedContents::iterator i(blocked_contents_.begin()); | 65 for (BlockedContents::iterator i(blocked_contents_.begin()); |
| 67 i != blocked_contents_.end(); ++i) { | 66 i != blocked_contents_.end(); ++i) { |
| 68 if (i->tab_contents == tab_contents) { | 67 if (i->tab_contents == tab_contents) { |
| 69 // 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 |
| 70 // before attempting to add. | 69 // before attempting to add. |
| 71 BlockedContent content(*i); | 70 BlockedContent content(*i); |
| 72 blocked_contents_.erase(i); | 71 blocked_contents_.erase(i); |
| 73 i = blocked_contents_.end(); | 72 i = blocked_contents_.end(); |
| 74 tab_contents->web_contents()->SetDelegate(NULL); | 73 tab_contents->web_contents()->SetDelegate(NULL); |
| 75 tab_contents->blocked_content_tab_helper()->set_delegate(NULL); | 74 tab_contents->blocked_content_tab_helper()->set_delegate(NULL); |
| 76 // We needn't call WasRestored to change its status because the | 75 // We needn't call WasRestored to change its status because the |
| 77 // WebContents::AddNewContents will do it. | 76 // WebContents::AddNewContents will do it. |
| 78 owner_->web_contents()->AddNewContents( | 77 owner_->web_contents()->AddNewContents( |
| 79 tab_contents->web_contents(), | 78 tab_contents->web_contents(), |
| 80 content.disposition, | 79 content.disposition, |
| 81 content.bounds, | 80 content.bounds, |
| 82 content.user_gesture); | 81 content.user_gesture); |
| 83 break; | 82 break; |
| 84 } | 83 } |
| 85 } | 84 } |
| 86 } | 85 } |
| 87 | 86 |
| 88 size_t BlockedContentContainer::GetBlockedContentsCount() const { | 87 size_t BlockedContentContainer::GetBlockedContentsCount() const { |
| 89 return blocked_contents_.size(); | 88 return blocked_contents_.size(); |
| 90 } | 89 } |
| 91 | 90 |
| 92 void BlockedContentContainer::GetBlockedContents( | 91 void BlockedContentContainer::GetBlockedContents( |
| 93 std::vector<TabContentsWrapper*>* blocked_contents) const { | 92 std::vector<TabContents*>* blocked_contents) const { |
| 94 DCHECK(blocked_contents); | 93 DCHECK(blocked_contents); |
| 95 for (BlockedContents::const_iterator i(blocked_contents_.begin()); | 94 for (BlockedContents::const_iterator i(blocked_contents_.begin()); |
| 96 i != blocked_contents_.end(); ++i) | 95 i != blocked_contents_.end(); ++i) |
| 97 blocked_contents->push_back(i->tab_contents); | 96 blocked_contents->push_back(i->tab_contents); |
| 98 } | 97 } |
| 99 | 98 |
| 100 void BlockedContentContainer::Clear() { | 99 void BlockedContentContainer::Clear() { |
| 101 for (BlockedContents::iterator i(blocked_contents_.begin()); | 100 for (BlockedContents::iterator i(blocked_contents_.begin()); |
| 102 i != blocked_contents_.end(); ++i) { | 101 i != blocked_contents_.end(); ++i) { |
| 103 TabContentsWrapper* tab_contents = i->tab_contents; | 102 TabContents* tab_contents = i->tab_contents; |
| 104 tab_contents->web_contents()->SetDelegate(NULL); | 103 tab_contents->web_contents()->SetDelegate(NULL); |
| 105 tab_contents->blocked_content_tab_helper()->set_delegate(NULL); | 104 tab_contents->blocked_content_tab_helper()->set_delegate(NULL); |
| 106 delete tab_contents; | 105 delete tab_contents; |
| 107 } | 106 } |
| 108 blocked_contents_.clear(); | 107 blocked_contents_.clear(); |
| 109 } | 108 } |
| 110 | 109 |
| 111 // Overridden from content::WebContentsDelegate: | 110 // Overridden from content::WebContentsDelegate: |
| 112 | 111 |
| 113 WebContents* BlockedContentContainer::OpenURLFromTab( | 112 WebContents* BlockedContentContainer::OpenURLFromTab( |
| 114 WebContents* source, | 113 WebContents* source, |
| 115 const OpenURLParams& params) { | 114 const OpenURLParams& params) { |
| 116 return owner_->web_contents()->OpenURL(params); | 115 return owner_->web_contents()->OpenURL(params); |
| 117 } | 116 } |
| 118 | 117 |
| 119 void BlockedContentContainer::AddNewContents(WebContents* source, | 118 void BlockedContentContainer::AddNewContents(WebContents* source, |
| 120 WebContents* new_contents, | 119 WebContents* new_contents, |
| 121 WindowOpenDisposition disposition, | 120 WindowOpenDisposition disposition, |
| 122 const gfx::Rect& initial_position, | 121 const gfx::Rect& initial_position, |
| 123 bool user_gesture) { | 122 bool user_gesture) { |
| 124 owner_->web_contents()->AddNewContents( | 123 owner_->web_contents()->AddNewContents( |
| 125 new_contents, disposition, initial_position, user_gesture); | 124 new_contents, disposition, initial_position, user_gesture); |
| 126 } | 125 } |
| 127 | 126 |
| 128 void BlockedContentContainer::CloseContents(WebContents* source) { | 127 void BlockedContentContainer::CloseContents(WebContents* source) { |
| 129 for (BlockedContents::iterator i(blocked_contents_.begin()); | 128 for (BlockedContents::iterator i(blocked_contents_.begin()); |
| 130 i != blocked_contents_.end(); ++i) { | 129 i != blocked_contents_.end(); ++i) { |
| 131 TabContentsWrapper* tab_contents = i->tab_contents; | 130 TabContents* tab_contents = i->tab_contents; |
| 132 if (tab_contents->web_contents() == source) { | 131 if (tab_contents->web_contents() == source) { |
| 133 tab_contents->web_contents()->SetDelegate(NULL); | 132 tab_contents->web_contents()->SetDelegate(NULL); |
| 134 tab_contents->blocked_content_tab_helper()->set_delegate(NULL); | 133 tab_contents->blocked_content_tab_helper()->set_delegate(NULL); |
| 135 blocked_contents_.erase(i); | 134 blocked_contents_.erase(i); |
| 136 delete tab_contents; | 135 delete tab_contents; |
| 137 break; | 136 break; |
| 138 } | 137 } |
| 139 } | 138 } |
| 140 } | 139 } |
| 141 | 140 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 156 // up changing. | 155 // up changing. |
| 157 return true; | 156 return true; |
| 158 } | 157 } |
| 159 | 158 |
| 160 bool BlockedContentContainer::ShouldSuppressDialogs() { | 159 bool BlockedContentContainer::ShouldSuppressDialogs() { |
| 161 // Suppress JavaScript dialogs when inside a constrained popup window (because | 160 // Suppress JavaScript dialogs when inside a constrained popup window (because |
| 162 // that activates them and breaks them out of the constrained window jail). | 161 // that activates them and breaks them out of the constrained window jail). |
| 163 return true; | 162 return true; |
| 164 } | 163 } |
| 165 | 164 |
| 166 TabContentsWrapper* BlockedContentContainer::GetConstrainingContentsWrapper( | 165 TabContents* BlockedContentContainer::GetConstrainingTabContents( |
| 167 TabContentsWrapper* source) { | 166 TabContents* source) { |
| 168 return owner_; | 167 return owner_; |
| 169 } | 168 } |
| OLD | NEW |