| 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" |
| 11 #include "chrome/browser/ui/blocked_content/blocked_content_container.h" | 11 #include "chrome/browser/ui/blocked_content/blocked_content_container.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
| 15 #include "content/public/browser/navigation_details.h" | 15 #include "content/public/browser/navigation_details.h" |
| 16 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
| 17 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/browser/web_contents_delegate.h" |
| 22 | 23 |
| 23 using content::NavigationEntry; | 24 using content::NavigationEntry; |
| 24 | 25 |
| 25 BlockedContentTabHelper::BlockedContentTabHelper(TabContents* tab_contents) | 26 BlockedContentTabHelper::BlockedContentTabHelper(TabContents* tab_contents) |
| 26 : content::WebContentsObserver(tab_contents->web_contents()), | 27 : content::WebContentsObserver(tab_contents->web_contents()), |
| 27 blocked_contents_(new BlockedContentContainer(tab_contents)), | 28 blocked_contents_(new BlockedContentContainer(tab_contents)), |
| 28 all_contents_blocked_(false), | 29 all_contents_blocked_(false), |
| 29 tab_contents_(tab_contents), | 30 tab_contents_(tab_contents), |
| 30 delegate_(NULL) { | 31 delegate_(NULL) { |
| 31 } | 32 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 const gfx::Rect& initial_pos, | 82 const gfx::Rect& initial_pos, |
| 82 bool user_gesture) { | 83 bool user_gesture) { |
| 83 if (!blocked_contents_->GetBlockedContentsCount()) | 84 if (!blocked_contents_->GetBlockedContentsCount()) |
| 84 PopupNotificationVisibilityChanged(true); | 85 PopupNotificationVisibilityChanged(true); |
| 85 SendNotification(new_contents, true); | 86 SendNotification(new_contents, true); |
| 86 blocked_contents_->AddTabContents( | 87 blocked_contents_->AddTabContents( |
| 87 new_contents, disposition, initial_pos, user_gesture); | 88 new_contents, disposition, initial_pos, user_gesture); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void BlockedContentTabHelper::AddPopup(TabContents* new_contents, | 91 void BlockedContentTabHelper::AddPopup(TabContents* new_contents, |
| 92 WindowOpenDisposition disposition, |
| 91 const gfx::Rect& initial_pos, | 93 const gfx::Rect& initial_pos, |
| 92 bool user_gesture) { | 94 bool user_gesture) { |
| 93 // A page can't spawn popups (or do anything else, either) until its load | 95 // 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 | 96 // commits, so when we reach here, the popup was spawned by the |
| 95 // NavigationController's last committed entry, not the active entry. For | 97 // 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 | 98 // 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 | 99 // 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, | 100 // page. For this reason, we can't use GetURL() to get the opener URL, |
| 99 // because it returns the active entry. | 101 // because it returns the active entry. |
| 100 NavigationEntry* entry = | 102 NavigationEntry* entry = |
| 101 web_contents()->GetController().GetLastCommittedEntry(); | 103 web_contents()->GetController().GetLastCommittedEntry(); |
| 102 GURL creator = entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); | 104 GURL creator = entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 103 Profile* profile = | 105 Profile* profile = |
| 104 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 106 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 105 | 107 |
| 106 if (creator.is_valid() && | 108 if (creator.is_valid() && |
| 107 profile->GetHostContentSettingsMap()->GetContentSetting( | 109 profile->GetHostContentSettingsMap()->GetContentSetting( |
| 108 creator, | 110 creator, |
| 109 creator, | 111 creator, |
| 110 CONTENT_SETTINGS_TYPE_POPUPS, | 112 CONTENT_SETTINGS_TYPE_POPUPS, |
| 111 "") == CONTENT_SETTING_ALLOW) { | 113 "") == CONTENT_SETTING_ALLOW) { |
| 112 web_contents()->AddNewContents(new_contents->web_contents(), | 114 content::WebContentsDelegate* delegate = web_contents()->GetDelegate(); |
| 113 NEW_POPUP, | 115 if (delegate) { |
| 114 initial_pos, | 116 delegate->AddNewContents(web_contents(), |
| 115 true); // user_gesture | 117 new_contents->web_contents(), |
| 118 disposition, |
| 119 initial_pos, |
| 120 true, // user_gesture |
| 121 NULL); |
| 122 } |
| 116 } else { | 123 } else { |
| 117 // Call blocked_contents_->AddTabContents with user_gesture == true | 124 // Call blocked_contents_->AddTabContents with user_gesture == true |
| 118 // so that the contents will not get blocked again. | 125 // so that the contents will not get blocked again. |
| 119 SendNotification(new_contents, true); | 126 SendNotification(new_contents, true); |
| 120 blocked_contents_->AddTabContents(new_contents, | 127 blocked_contents_->AddTabContents(new_contents, |
| 121 NEW_POPUP, | 128 disposition, |
| 122 initial_pos, | 129 initial_pos, |
| 123 true); // user_gesture | 130 true); // user_gesture |
| 124 tab_contents_->content_settings()->OnContentBlocked( | 131 tab_contents_->content_settings()->OnContentBlocked( |
| 125 CONTENT_SETTINGS_TYPE_POPUPS, std::string()); | 132 CONTENT_SETTINGS_TYPE_POPUPS, std::string()); |
| 126 } | 133 } |
| 127 } | 134 } |
| 128 | 135 |
| 129 void BlockedContentTabHelper::LaunchForContents( | 136 void BlockedContentTabHelper::LaunchForContents( |
| 130 TabContents* tab_contents) { | 137 TabContents* tab_contents) { |
| 131 SendNotification(tab_contents, false); | 138 SendNotification(tab_contents, false); |
| 132 blocked_contents_->LaunchForContents(tab_contents); | 139 blocked_contents_->LaunchForContents(tab_contents); |
| 133 if (!blocked_contents_->GetBlockedContentsCount()) | 140 if (!blocked_contents_->GetBlockedContentsCount()) |
| 134 PopupNotificationVisibilityChanged(false); | 141 PopupNotificationVisibilityChanged(false); |
| 135 } | 142 } |
| 136 | 143 |
| 137 size_t BlockedContentTabHelper::GetBlockedContentsCount() const { | 144 size_t BlockedContentTabHelper::GetBlockedContentsCount() const { |
| 138 return blocked_contents_->GetBlockedContentsCount(); | 145 return blocked_contents_->GetBlockedContentsCount(); |
| 139 } | 146 } |
| 140 | 147 |
| 141 void BlockedContentTabHelper::GetBlockedContents( | 148 void BlockedContentTabHelper::GetBlockedContents( |
| 142 std::vector<TabContents*>* blocked_contents) const { | 149 std::vector<TabContents*>* blocked_contents) const { |
| 143 blocked_contents_->GetBlockedContents(blocked_contents); | 150 blocked_contents_->GetBlockedContents(blocked_contents); |
| 144 } | 151 } |
| OLD | NEW |