| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_tab_helper.h" | 5 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 const gfx::Rect& initial_pos, | 81 const gfx::Rect& initial_pos, |
| 82 bool user_gesture) { | 82 bool user_gesture) { |
| 83 if (!blocked_contents_->GetBlockedContentsCount()) | 83 if (!blocked_contents_->GetBlockedContentsCount()) |
| 84 PopupNotificationVisibilityChanged(true); | 84 PopupNotificationVisibilityChanged(true); |
| 85 SendNotification(new_contents, true); | 85 SendNotification(new_contents, true); |
| 86 blocked_contents_->AddTabContents( | 86 blocked_contents_->AddTabContents( |
| 87 new_contents, disposition, initial_pos, user_gesture); | 87 new_contents, disposition, initial_pos, user_gesture); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void BlockedContentTabHelper::AddPopup(TabContents* new_contents, | 90 void BlockedContentTabHelper::AddPopup(TabContents* new_contents, |
| 91 WindowOpenDisposition disposition, |
| 91 const gfx::Rect& initial_pos, | 92 const gfx::Rect& initial_pos, |
| 92 bool user_gesture) { | 93 bool user_gesture) { |
| 93 // A page can't spawn popups (or do anything else, either) until its load | 94 // A page can't spawn popups (or do anything else, either) until its load |
| 94 // commits, so when we reach here, the popup was spawned by the | 95 // commits, so when we reach here, the popup was spawned by the |
| 95 // NavigationController's last committed entry, not the active entry. For | 96 // NavigationController's last committed entry, not the active entry. For |
| 96 // example, if a page opens a popup in an onunload() handler, then the active | 97 // example, if a page opens a popup in an onunload() handler, then the active |
| 97 // entry is the page to be loaded as we navigate away from the unloading | 98 // entry is the page to be loaded as we navigate away from the unloading |
| 98 // page. For this reason, we can't use GetURL() to get the opener URL, | 99 // page. For this reason, we can't use GetURL() to get the opener URL, |
| 99 // because it returns the active entry. | 100 // because it returns the active entry. |
| 100 NavigationEntry* entry = | 101 NavigationEntry* entry = |
| 101 web_contents()->GetController().GetLastCommittedEntry(); | 102 web_contents()->GetController().GetLastCommittedEntry(); |
| 102 GURL creator = entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); | 103 GURL creator = entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 103 Profile* profile = | 104 Profile* profile = |
| 104 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 105 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 105 | 106 |
| 106 if (creator.is_valid() && | 107 if (creator.is_valid() && |
| 107 profile->GetHostContentSettingsMap()->GetContentSetting( | 108 profile->GetHostContentSettingsMap()->GetContentSetting( |
| 108 creator, | 109 creator, |
| 109 creator, | 110 creator, |
| 110 CONTENT_SETTINGS_TYPE_POPUPS, | 111 CONTENT_SETTINGS_TYPE_POPUPS, |
| 111 "") == CONTENT_SETTING_ALLOW) { | 112 "") == CONTENT_SETTING_ALLOW) { |
| 112 web_contents()->AddNewContents(new_contents->web_contents(), | 113 web_contents()->AddNewContents(new_contents->web_contents(), |
| 113 NEW_POPUP, | 114 disposition, |
| 114 initial_pos, | 115 initial_pos, |
| 115 true); // user_gesture | 116 true); // user_gesture |
| 116 } else { | 117 } else { |
| 117 // Call blocked_contents_->AddTabContents with user_gesture == true | 118 // Call blocked_contents_->AddTabContents with user_gesture == true |
| 118 // so that the contents will not get blocked again. | 119 // so that the contents will not get blocked again. |
| 119 SendNotification(new_contents, true); | 120 SendNotification(new_contents, true); |
| 120 blocked_contents_->AddTabContents(new_contents, | 121 blocked_contents_->AddTabContents(new_contents, |
| 121 NEW_POPUP, | 122 disposition, |
| 122 initial_pos, | 123 initial_pos, |
| 123 true); // user_gesture | 124 true); // user_gesture |
| 124 tab_contents_->content_settings()->OnContentBlocked( | 125 tab_contents_->content_settings()->OnContentBlocked( |
| 125 CONTENT_SETTINGS_TYPE_POPUPS, std::string()); | 126 CONTENT_SETTINGS_TYPE_POPUPS, std::string()); |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 | 129 |
| 129 void BlockedContentTabHelper::LaunchForContents( | 130 void BlockedContentTabHelper::LaunchForContents( |
| 130 TabContents* tab_contents) { | 131 TabContents* tab_contents) { |
| 131 SendNotification(tab_contents, false); | 132 SendNotification(tab_contents, false); |
| 132 blocked_contents_->LaunchForContents(tab_contents); | 133 blocked_contents_->LaunchForContents(tab_contents); |
| 133 if (!blocked_contents_->GetBlockedContentsCount()) | 134 if (!blocked_contents_->GetBlockedContentsCount()) |
| 134 PopupNotificationVisibilityChanged(false); | 135 PopupNotificationVisibilityChanged(false); |
| 135 } | 136 } |
| 136 | 137 |
| 137 size_t BlockedContentTabHelper::GetBlockedContentsCount() const { | 138 size_t BlockedContentTabHelper::GetBlockedContentsCount() const { |
| 138 return blocked_contents_->GetBlockedContentsCount(); | 139 return blocked_contents_->GetBlockedContentsCount(); |
| 139 } | 140 } |
| 140 | 141 |
| 141 void BlockedContentTabHelper::GetBlockedContents( | 142 void BlockedContentTabHelper::GetBlockedContents( |
| 142 std::vector<TabContents*>* blocked_contents) const { | 143 std::vector<TabContents*>* blocked_contents) const { |
| 143 blocked_contents_->GetBlockedContents(blocked_contents); | 144 blocked_contents_->GetBlockedContents(blocked_contents); |
| 144 } | 145 } |
| OLD | NEW |