| 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/download/download_request_limiter.h" | 5 #include "chrome/browser/download/download_request_limiter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 11 #include "chrome/browser/download/download_permission_request.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
| 13 #include "chrome/browser/permissions/permission_request_manager.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/tab_contents/tab_util.h" | 15 #include "chrome/browser/tab_contents/tab_util.h" |
| 14 #include "components/content_settings/core/browser/content_settings_details.h" | 16 #include "components/content_settings/core/browser/content_settings_details.h" |
| 15 #include "components/content_settings/core/browser/host_content_settings_map.h" | 17 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 16 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/navigation_controller.h" | 20 #include "content/public/browser/navigation_controller.h" |
| 19 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 20 #include "content/public/browser/navigation_handle.h" | 22 #include "content/public/browser/navigation_handle.h" |
| 21 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 22 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
| 23 #include "content/public/browser/resource_dispatcher_host.h" | 25 #include "content/public/browser/resource_dispatcher_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_contents_delegate.h" | 27 #include "content/public/browser/web_contents_delegate.h" |
| 26 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 27 | 29 |
| 28 #if defined(OS_ANDROID) | 30 #if defined(OS_ANDROID) |
| 29 #include "chrome/browser/download/download_request_infobar_delegate_android.h" | 31 #include "chrome/browser/download/download_request_infobar_delegate_android.h" |
| 30 #else | |
| 31 #include "chrome/browser/download/download_permission_request.h" | |
| 32 #include "chrome/browser/permissions/permission_request_manager.h" | |
| 33 #endif | 32 #endif |
| 34 | 33 |
| 35 using content::BrowserThread; | 34 using content::BrowserThread; |
| 36 using content::NavigationController; | 35 using content::NavigationController; |
| 37 using content::NavigationEntry; | 36 using content::NavigationEntry; |
| 38 | 37 |
| 39 namespace { | 38 namespace { |
| 40 | 39 |
| 41 ContentSetting GetSettingFromStatus( | 40 ContentSetting GetSettingFromStatus( |
| 42 DownloadRequestLimiter::DownloadStatus status) { | 41 DownloadRequestLimiter::DownloadStatus status) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 166 } |
| 168 | 167 |
| 169 void DownloadRequestLimiter::TabDownloadState::DidGetUserInteraction( | 168 void DownloadRequestLimiter::TabDownloadState::DidGetUserInteraction( |
| 170 const blink::WebInputEvent::Type type) { | 169 const blink::WebInputEvent::Type type) { |
| 171 if (is_showing_prompt() || | 170 if (is_showing_prompt() || |
| 172 type == blink::WebInputEvent::kGestureScrollBegin) { | 171 type == blink::WebInputEvent::kGestureScrollBegin) { |
| 173 // Don't change state if a prompt is showing or if the user has scrolled. | 172 // Don't change state if a prompt is showing or if the user has scrolled. |
| 174 return; | 173 return; |
| 175 } | 174 } |
| 176 | 175 |
| 177 #if defined(OS_ANDROID) | 176 bool promptable; |
| 178 bool promptable = InfoBarService::FromWebContents(web_contents()) != nullptr; | 177 if (PermissionRequestManager::IsEnabled()) { |
| 179 #else | 178 promptable = |
| 180 bool promptable = | 179 PermissionRequestManager::FromWebContents(web_contents()) != nullptr; |
| 181 PermissionRequestManager::FromWebContents(web_contents()) != nullptr; | 180 } else { |
| 182 #endif | 181 promptable = InfoBarService::FromWebContents(web_contents()) != nullptr; |
| 182 } |
| 183 | 183 |
| 184 // See PromptUserForDownload(): if there's no InfoBarService, then | 184 // See PromptUserForDownload(): if there's no InfoBarService, then |
| 185 // DOWNLOADS_NOT_ALLOWED is functionally equivalent to PROMPT_BEFORE_DOWNLOAD. | 185 // DOWNLOADS_NOT_ALLOWED is functionally equivalent to PROMPT_BEFORE_DOWNLOAD. |
| 186 if ((status_ != DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS) && | 186 if ((status_ != DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS) && |
| 187 (!promptable || | 187 (!promptable || |
| 188 (status_ != DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED))) { | 188 (status_ != DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED))) { |
| 189 // Revert to default status. | 189 // Revert to default status. |
| 190 host_->Remove(this, web_contents()); | 190 host_->Remove(this, web_contents()); |
| 191 // WARNING: We've been deleted. | 191 // WARNING: We've been deleted. |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 void DownloadRequestLimiter::TabDownloadState::WebContentsDestroyed() { | 195 void DownloadRequestLimiter::TabDownloadState::WebContentsDestroyed() { |
| 196 // Tab closed, no need to handle closing the dialog as it's owned by the | 196 // Tab closed, no need to handle closing the dialog as it's owned by the |
| 197 // WebContents. | 197 // WebContents. |
| 198 | 198 |
| 199 NotifyCallbacks(false); | 199 NotifyCallbacks(false); |
| 200 host_->Remove(this, web_contents()); | 200 host_->Remove(this, web_contents()); |
| 201 // WARNING: We've been deleted. | 201 // WARNING: We've been deleted. |
| 202 } | 202 } |
| 203 | 203 |
| 204 void DownloadRequestLimiter::TabDownloadState::PromptUserForDownload( | 204 void DownloadRequestLimiter::TabDownloadState::PromptUserForDownload( |
| 205 const DownloadRequestLimiter::Callback& callback) { | 205 const DownloadRequestLimiter::Callback& callback) { |
| 206 callbacks_.push_back(callback); | 206 callbacks_.push_back(callback); |
| 207 DCHECK(web_contents_); | 207 DCHECK(web_contents_); |
| 208 if (is_showing_prompt()) | 208 if (is_showing_prompt()) |
| 209 return; | 209 return; |
| 210 | 210 |
| 211 if (PermissionRequestManager::IsEnabled()) { |
| 212 PermissionRequestManager* permission_request_manager = |
| 213 PermissionRequestManager::FromWebContents(web_contents_); |
| 214 if (permission_request_manager) { |
| 215 permission_request_manager->AddRequest( |
| 216 new DownloadPermissionRequest(factory_.GetWeakPtr())); |
| 217 } else { |
| 218 Cancel(); |
| 219 } |
| 220 } else { |
| 211 #if defined(OS_ANDROID) | 221 #if defined(OS_ANDROID) |
| 212 DownloadRequestInfoBarDelegateAndroid::Create( | 222 DownloadRequestInfoBarDelegateAndroid::Create( |
| 213 InfoBarService::FromWebContents(web_contents_), factory_.GetWeakPtr()); | 223 InfoBarService::FromWebContents(web_contents_), factory_.GetWeakPtr()); |
| 214 #else | 224 #endif |
| 215 PermissionRequestManager* permission_request_manager = | |
| 216 PermissionRequestManager::FromWebContents(web_contents_); | |
| 217 if (permission_request_manager) { | |
| 218 permission_request_manager->AddRequest( | |
| 219 new DownloadPermissionRequest(factory_.GetWeakPtr())); | |
| 220 } else { | |
| 221 Cancel(); | |
| 222 } | 225 } |
| 223 #endif | |
| 224 } | 226 } |
| 225 | 227 |
| 226 void DownloadRequestLimiter::TabDownloadState::SetContentSetting( | 228 void DownloadRequestLimiter::TabDownloadState::SetContentSetting( |
| 227 ContentSetting setting) { | 229 ContentSetting setting) { |
| 228 if (!web_contents_) | 230 if (!web_contents_) |
| 229 return; | 231 return; |
| 230 HostContentSettingsMap* settings = | 232 HostContentSettingsMap* settings = |
| 231 DownloadRequestLimiter::GetContentSettings(web_contents_); | 233 DownloadRequestLimiter::GetContentSettings(web_contents_); |
| 232 if (!settings) | 234 if (!settings) |
| 233 return; | 235 return; |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 NOTREACHED(); | 517 NOTREACHED(); |
| 516 } | 518 } |
| 517 } | 519 } |
| 518 | 520 |
| 519 void DownloadRequestLimiter::Remove(TabDownloadState* state, | 521 void DownloadRequestLimiter::Remove(TabDownloadState* state, |
| 520 content::WebContents* contents) { | 522 content::WebContents* contents) { |
| 521 DCHECK(base::ContainsKey(state_map_, contents)); | 523 DCHECK(base::ContainsKey(state_map_, contents)); |
| 522 state_map_.erase(contents); | 524 state_map_.erase(contents); |
| 523 delete state; | 525 delete state; |
| 524 } | 526 } |
| OLD | NEW |