| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/popup_blocker_tab_helper.h" | 5 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.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_window_params.h" | 11 #include "chrome/browser/ui/blocked_content/blocked_window_params.h" |
| 12 #include "chrome/browser/ui/browser_navigator.h" | 12 #include "chrome/browser/ui/browser_navigator.h" |
| 13 #include "chrome/browser/ui/browser_navigator_params.h" | 13 #include "chrome/browser/ui/browser_navigator_params.h" |
| 14 #include "chrome/common/features.h" | |
| 15 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
| 16 #include "components/content_settings/core/browser/host_content_settings_map.h" | 15 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
| 19 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 20 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 22 #include "third_party/WebKit/public/web/WebWindowFeatures.h" | 21 #include "third_party/WebKit/public/web/WebWindowFeatures.h" |
| 23 | 22 |
| 24 #if BUILDFLAG(ANDROID_JAVA_UI) | 23 #if defined(OS_ANDROID) |
| 25 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 24 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 26 #endif | 25 #endif |
| 27 | 26 |
| 28 using blink::WebWindowFeatures; | 27 using blink::WebWindowFeatures; |
| 29 | 28 |
| 30 const size_t kMaximumNumberOfPopups = 25; | 29 const size_t kMaximumNumberOfPopups = 25; |
| 31 | 30 |
| 32 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PopupBlockerTabHelper); | 31 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PopupBlockerTabHelper); |
| 33 | 32 |
| 34 struct PopupBlockerTabHelper::BlockedRequest { | 33 struct PopupBlockerTabHelper::BlockedRequest { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 TabSpecificContentSettings::FromWebContents(web_contents())-> | 113 TabSpecificContentSettings::FromWebContents(web_contents())-> |
| 115 OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS); | 114 OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS); |
| 116 } | 115 } |
| 117 | 116 |
| 118 void PopupBlockerTabHelper::ShowBlockedPopup(int32_t id) { | 117 void PopupBlockerTabHelper::ShowBlockedPopup(int32_t id) { |
| 119 BlockedRequest* popup = blocked_popups_.Lookup(id); | 118 BlockedRequest* popup = blocked_popups_.Lookup(id); |
| 120 if (!popup) | 119 if (!popup) |
| 121 return; | 120 return; |
| 122 // We set user_gesture to true here, so the new popup gets correctly focused. | 121 // We set user_gesture to true here, so the new popup gets correctly focused. |
| 123 popup->params.user_gesture = true; | 122 popup->params.user_gesture = true; |
| 124 #if BUILDFLAG(ANDROID_JAVA_UI) | 123 #if defined(OS_ANDROID) |
| 125 TabModelList::HandlePopupNavigation(&popup->params); | 124 TabModelList::HandlePopupNavigation(&popup->params); |
| 126 #else | 125 #else |
| 127 chrome::Navigate(&popup->params); | 126 chrome::Navigate(&popup->params); |
| 128 #endif | 127 #endif |
| 129 if (popup->params.target_contents) { | 128 if (popup->params.target_contents) { |
| 130 popup->params.target_contents->Send(new ChromeViewMsg_SetWindowFeatures( | 129 popup->params.target_contents->Send(new ChromeViewMsg_SetWindowFeatures( |
| 131 popup->params.target_contents->GetRenderViewHost()->GetRoutingID(), | 130 popup->params.target_contents->GetRenderViewHost()->GetRoutingID(), |
| 132 popup->window_features)); | 131 popup->window_features)); |
| 133 } | 132 } |
| 134 blocked_popups_.Remove(id); | 133 blocked_popups_.Remove(id); |
| 135 if (blocked_popups_.IsEmpty()) | 134 if (blocked_popups_.IsEmpty()) |
| 136 PopupNotificationVisibilityChanged(false); | 135 PopupNotificationVisibilityChanged(false); |
| 137 } | 136 } |
| 138 | 137 |
| 139 size_t PopupBlockerTabHelper::GetBlockedPopupsCount() const { | 138 size_t PopupBlockerTabHelper::GetBlockedPopupsCount() const { |
| 140 return blocked_popups_.size(); | 139 return blocked_popups_.size(); |
| 141 } | 140 } |
| 142 | 141 |
| 143 PopupBlockerTabHelper::PopupIdMap | 142 PopupBlockerTabHelper::PopupIdMap |
| 144 PopupBlockerTabHelper::GetBlockedPopupRequests() { | 143 PopupBlockerTabHelper::GetBlockedPopupRequests() { |
| 145 PopupIdMap result; | 144 PopupIdMap result; |
| 146 for (IDMap<std::unique_ptr<BlockedRequest>>::const_iterator iter( | 145 for (IDMap<std::unique_ptr<BlockedRequest>>::const_iterator iter( |
| 147 &blocked_popups_); | 146 &blocked_popups_); |
| 148 !iter.IsAtEnd(); | 147 !iter.IsAtEnd(); |
| 149 iter.Advance()) { | 148 iter.Advance()) { |
| 150 result[iter.GetCurrentKey()] = iter.GetCurrentValue()->params.url; | 149 result[iter.GetCurrentKey()] = iter.GetCurrentValue()->params.url; |
| 151 } | 150 } |
| 152 return result; | 151 return result; |
| 153 } | 152 } |
| OLD | NEW |