| 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/content_settings/host_content_settings_map_factory.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/tab_contents/tab_util.h" | 13 #include "chrome/browser/tab_contents/tab_util.h" |
| 14 #include "chrome/common/features.h" |
| 14 #include "components/content_settings/core/browser/host_content_settings_map.h" | 15 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 15 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
| 20 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
| 21 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/resource_dispatcher_host.h" | 23 #include "content/public/browser/resource_dispatcher_host.h" |
| 23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/browser/web_contents_delegate.h" | 25 #include "content/public/browser/web_contents_delegate.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 27 #if defined(OS_ANDROID) | 28 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 28 #include "chrome/browser/download/download_request_infobar_delegate_android.h" | 29 #include "chrome/browser/download/download_request_infobar_delegate_android.h" |
| 29 #else | 30 #else |
| 30 #include "chrome/browser/download/download_permission_request.h" | 31 #include "chrome/browser/download/download_permission_request.h" |
| 31 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 32 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 using content::BrowserThread; | 35 using content::BrowserThread; |
| 35 using content::NavigationController; | 36 using content::NavigationController; |
| 36 using content::NavigationEntry; | 37 using content::NavigationEntry; |
| 37 | 38 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 NOTREACHED(); | 93 NOTREACHED(); |
| 93 } | 94 } |
| 94 } | 95 } |
| 95 | 96 |
| 96 void DownloadRequestLimiter::TabDownloadState::DidGetUserGesture() { | 97 void DownloadRequestLimiter::TabDownloadState::DidGetUserGesture() { |
| 97 if (is_showing_prompt()) { | 98 if (is_showing_prompt()) { |
| 98 // Don't change the state if the user clicks on the page somewhere. | 99 // Don't change the state if the user clicks on the page somewhere. |
| 99 return; | 100 return; |
| 100 } | 101 } |
| 101 | 102 |
| 102 #if defined(OS_ANDROID) | 103 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 103 bool promptable = InfoBarService::FromWebContents(web_contents()) != nullptr; | 104 bool promptable = InfoBarService::FromWebContents(web_contents()) != nullptr; |
| 104 #else | 105 #else |
| 105 bool promptable = | 106 bool promptable = |
| 106 PermissionBubbleManager::FromWebContents(web_contents()) != nullptr; | 107 PermissionBubbleManager::FromWebContents(web_contents()) != nullptr; |
| 107 #endif | 108 #endif |
| 108 | 109 |
| 109 // See PromptUserForDownload(): if there's no InfoBarService, then | 110 // See PromptUserForDownload(): if there's no InfoBarService, then |
| 110 // DOWNLOADS_NOT_ALLOWED is functionally equivalent to PROMPT_BEFORE_DOWNLOAD. | 111 // DOWNLOADS_NOT_ALLOWED is functionally equivalent to PROMPT_BEFORE_DOWNLOAD. |
| 111 if ((status_ != DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS) && | 112 if ((status_ != DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS) && |
| 112 (!promptable || | 113 (!promptable || |
| (...skipping 13 matching lines...) Expand all Loading... |
| 126 // WARNING: We've been deleted. | 127 // WARNING: We've been deleted. |
| 127 } | 128 } |
| 128 | 129 |
| 129 void DownloadRequestLimiter::TabDownloadState::PromptUserForDownload( | 130 void DownloadRequestLimiter::TabDownloadState::PromptUserForDownload( |
| 130 const DownloadRequestLimiter::Callback& callback) { | 131 const DownloadRequestLimiter::Callback& callback) { |
| 131 callbacks_.push_back(callback); | 132 callbacks_.push_back(callback); |
| 132 DCHECK(web_contents_); | 133 DCHECK(web_contents_); |
| 133 if (is_showing_prompt()) | 134 if (is_showing_prompt()) |
| 134 return; | 135 return; |
| 135 | 136 |
| 136 #if defined(OS_ANDROID) | 137 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 137 DownloadRequestInfoBarDelegateAndroid::Create( | 138 DownloadRequestInfoBarDelegateAndroid::Create( |
| 138 InfoBarService::FromWebContents(web_contents_), factory_.GetWeakPtr()); | 139 InfoBarService::FromWebContents(web_contents_), factory_.GetWeakPtr()); |
| 139 #else | 140 #else |
| 140 PermissionBubbleManager* bubble_manager = | 141 PermissionBubbleManager* bubble_manager = |
| 141 PermissionBubbleManager::FromWebContents(web_contents_); | 142 PermissionBubbleManager::FromWebContents(web_contents_); |
| 142 if (bubble_manager) { | 143 if (bubble_manager) { |
| 143 bubble_manager->AddRequest(new DownloadPermissionRequest( | 144 bubble_manager->AddRequest(new DownloadPermissionRequest( |
| 144 factory_.GetWeakPtr())); | 145 factory_.GetWeakPtr())); |
| 145 } else { | 146 } else { |
| 146 Cancel(); | 147 Cancel(); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 NOTREACHED(); | 438 NOTREACHED(); |
| 438 } | 439 } |
| 439 } | 440 } |
| 440 | 441 |
| 441 void DownloadRequestLimiter::Remove(TabDownloadState* state, | 442 void DownloadRequestLimiter::Remove(TabDownloadState* state, |
| 442 content::WebContents* contents) { | 443 content::WebContents* contents) { |
| 443 DCHECK(ContainsKey(state_map_, contents)); | 444 DCHECK(ContainsKey(state_map_, contents)); |
| 444 state_map_.erase(contents); | 445 state_map_.erase(contents); |
| 445 delete state; | 446 delete state; |
| 446 } | 447 } |
| OLD | NEW |