#include "chrome/browser/download/download_request_limiter.h"
#include <iterator>
#include <utility>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "build/build_config.h"
#include "chrome/browser/content_settings/chrome_content_settings_utils.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/download/download_permission_request.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "components/permissions/permission_request_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "url/gurl.h"
BrowserThread;
NavigationController;
NavigationEntry;
namespace {
ContentSetting GetSettingFromDownloadStatus(
DownloadRequestLimiter::DownloadStatus status) { … }
DownloadRequestLimiter::DownloadStatus GetDownloadStatusFromSetting(
ContentSetting setting) { … }
DownloadRequestLimiter::DownloadUiStatus GetUiStatusFromDownloadStatus(
DownloadRequestLimiter::DownloadStatus status,
bool download_seen) { … }
}
DownloadRequestLimiter::TabDownloadState::TabDownloadState(
DownloadRequestLimiter* host,
content::WebContents* contents)
: … { … }
DownloadRequestLimiter::TabDownloadState::~TabDownloadState() { … }
void DownloadRequestLimiter::TabDownloadState::SetDownloadStatusAndNotify(
const url::Origin& request_origin,
DownloadStatus status) { … }
void DownloadRequestLimiter::TabDownloadState::DidStartNavigation(
content::NavigationHandle* navigation_handle) { … }
void DownloadRequestLimiter::TabDownloadState::DidFinishNavigation(
content::NavigationHandle* navigation_handle) { … }
void DownloadRequestLimiter::TabDownloadState::DidGetUserInteraction(
const blink::WebInputEvent& event) { … }
void DownloadRequestLimiter::TabDownloadState::WebContentsDestroyed() { … }
void DownloadRequestLimiter::TabDownloadState::PromptUserForDownload(
DownloadRequestLimiter::Callback callback,
const url::Origin& request_origin) { … }
void DownloadRequestLimiter::TabDownloadState::SetContentSetting(
ContentSetting setting,
const url::Origin& request_origin) { … }
void DownloadRequestLimiter::TabDownloadState::Cancel(
const url::Origin& request_origin) { … }
void DownloadRequestLimiter::TabDownloadState::CancelOnce(
const url::Origin& request_origin) { … }
void DownloadRequestLimiter::TabDownloadState::Accept(
const url::Origin& request_origin) { … }
DownloadRequestLimiter::DownloadStatus
DownloadRequestLimiter::TabDownloadState::GetDownloadStatus(
const url::Origin& request_origin) { … }
DownloadRequestLimiter::TabDownloadState::TabDownloadState()
: … { … }
bool DownloadRequestLimiter::TabDownloadState::is_showing_prompt() const { … }
void DownloadRequestLimiter::TabDownloadState::OnUserInteraction() { … }
void DownloadRequestLimiter::TabDownloadState::OnContentSettingChanged(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsTypeSet content_type_set) { … }
bool DownloadRequestLimiter::TabDownloadState::NotifyCallbacks(bool allow) { … }
void DownloadRequestLimiter::TabDownloadState::SetDownloadStatusAndNotifyImpl(
const url::Origin& request_origin,
DownloadStatus status,
ContentSetting setting) { … }
bool DownloadRequestLimiter::TabDownloadState::shouldClearDownloadState(
content::NavigationHandle* navigation_handle) { … }
DownloadRequestLimiter::DownloadRequestLimiter() { … }
DownloadRequestLimiter::~DownloadRequestLimiter() { … }
DownloadRequestLimiter::DownloadStatus
DownloadRequestLimiter::GetDownloadStatus(content::WebContents* web_contents) { … }
DownloadRequestLimiter::DownloadUiStatus
DownloadRequestLimiter::GetDownloadUiStatus(
content::WebContents* web_contents) { … }
GURL DownloadRequestLimiter::GetDownloadOrigin(
content::WebContents* web_contents) { … }
DownloadRequestLimiter::TabDownloadState*
DownloadRequestLimiter::GetDownloadState(
content::WebContents* web_contents,
bool create) { … }
void DownloadRequestLimiter::CanDownload(
const content::WebContents::Getter& web_contents_getter,
const GURL& url,
const std::string& request_method,
std::optional<url::Origin> request_initiator,
bool from_download_cross_origin_redirect,
Callback callback) { … }
void DownloadRequestLimiter::OnCanDownloadDecided(
const content::WebContents::Getter& web_contents_getter,
const std::string& request_method,
std::optional<url::Origin> request_initiator,
bool from_download_cross_origin_redirect,
Callback orig_callback,
bool allow) { … }
HostContentSettingsMap* DownloadRequestLimiter::GetContentSettings(
content::WebContents* contents) { … }
ContentSetting DownloadRequestLimiter::GetAutoDownloadContentSetting(
content::WebContents* contents,
const GURL& request_initiator) { … }
void DownloadRequestLimiter::CanDownloadImpl(
content::WebContents* originating_contents,
const std::string& request_method,
std::optional<url::Origin> request_initiator,
bool from_download_cross_origin_redirect,
Callback callback) { … }
void DownloadRequestLimiter::Remove(TabDownloadState* state,
content::WebContents* contents) { … }
void DownloadRequestLimiter::SetOnCanDownloadDecidedCallbackForTesting(
CanDownloadDecidedCallback callback) { … }