| 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/download/download_permission_request.h" |
| 12 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
| 13 #include "chrome/browser/permissions/permission_request_manager.h" | 13 #include "chrome/browser/permissions/permission_request_manager.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/tab_contents/tab_util.h" | 15 #include "chrome/browser/tab_contents/tab_util.h" |
| 16 #include "components/content_settings/core/browser/content_settings_details.h" | 16 #include "components/content_settings/core/browser/content_settings_details.h" |
| 17 #include "components/content_settings/core/browser/host_content_settings_map.h" | 17 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 18 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/navigation_controller.h" | 20 #include "content/public/browser/navigation_controller.h" |
| 21 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/navigation_handle.h" | 22 #include "content/public/browser/navigation_handle.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
| 25 #include "content/public/browser/resource_dispatcher_host.h" | 25 #include "content/public/browser/resource_dispatcher_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/browser/web_contents_delegate.h" | 27 #include "content/public/browser/web_contents_delegate.h" |
| 28 #include "device/vr/features/features.h" |
| 28 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 29 | 30 |
| 30 #if defined(OS_ANDROID) | 31 #if defined(OS_ANDROID) |
| 31 #include "chrome/browser/download/download_request_infobar_delegate_android.h" | 32 #include "chrome/browser/download/download_request_infobar_delegate_android.h" |
| 32 #endif | 33 |
| 34 #if BUILDFLAG(ENABLE_VR) |
| 35 #include "chrome/browser/android/vr_shell/vr_tab_helper.h" |
| 36 #endif // BUILDFLAG(ENABLE_VR) |
| 37 |
| 38 #endif // defined(OS_ANDROID) |
| 33 | 39 |
| 34 using content::BrowserThread; | 40 using content::BrowserThread; |
| 35 using content::NavigationController; | 41 using content::NavigationController; |
| 36 using content::NavigationEntry; | 42 using content::NavigationEntry; |
| 37 | 43 |
| 38 namespace { | 44 namespace { |
| 39 | 45 |
| 40 ContentSetting GetSettingFromStatus( | 46 ContentSetting GetSettingFromStatus( |
| 41 DownloadRequestLimiter::DownloadStatus status) { | 47 DownloadRequestLimiter::DownloadStatus status) { |
| 42 switch (status) { | 48 switch (status) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // WARNING: We've been deleted. | 207 // WARNING: We've been deleted. |
| 202 } | 208 } |
| 203 | 209 |
| 204 void DownloadRequestLimiter::TabDownloadState::PromptUserForDownload( | 210 void DownloadRequestLimiter::TabDownloadState::PromptUserForDownload( |
| 205 const DownloadRequestLimiter::Callback& callback) { | 211 const DownloadRequestLimiter::Callback& callback) { |
| 206 callbacks_.push_back(callback); | 212 callbacks_.push_back(callback); |
| 207 DCHECK(web_contents_); | 213 DCHECK(web_contents_); |
| 208 if (is_showing_prompt()) | 214 if (is_showing_prompt()) |
| 209 return; | 215 return; |
| 210 | 216 |
| 217 #if BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) |
| 218 if (vr_shell::VrTabHelper::IsInVr(web_contents_)) { |
| 219 Cancel(); |
| 220 return; |
| 221 } |
| 222 #endif |
| 223 |
| 211 if (PermissionRequestManager::IsEnabled()) { | 224 if (PermissionRequestManager::IsEnabled()) { |
| 212 PermissionRequestManager* permission_request_manager = | 225 PermissionRequestManager* permission_request_manager = |
| 213 PermissionRequestManager::FromWebContents(web_contents_); | 226 PermissionRequestManager::FromWebContents(web_contents_); |
| 214 if (permission_request_manager) { | 227 if (permission_request_manager) { |
| 215 permission_request_manager->AddRequest( | 228 permission_request_manager->AddRequest( |
| 216 new DownloadPermissionRequest(factory_.GetWeakPtr())); | 229 new DownloadPermissionRequest(factory_.GetWeakPtr())); |
| 217 } else { | 230 } else { |
| 218 Cancel(); | 231 Cancel(); |
| 219 } | 232 } |
| 220 } else { | 233 } else { |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 NOTREACHED(); | 530 NOTREACHED(); |
| 518 } | 531 } |
| 519 } | 532 } |
| 520 | 533 |
| 521 void DownloadRequestLimiter::Remove(TabDownloadState* state, | 534 void DownloadRequestLimiter::Remove(TabDownloadState* state, |
| 522 content::WebContents* contents) { | 535 content::WebContents* contents) { |
| 523 DCHECK(base::ContainsKey(state_map_, contents)); | 536 DCHECK(base::ContainsKey(state_map_, contents)); |
| 524 state_map_.erase(contents); | 537 state_map_.erase(contents); |
| 525 delete state; | 538 delete state; |
| 526 } | 539 } |
| OLD | NEW |