// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ #include <stddef.h> #include <map> #include <set> #include <string> #include <vector> #include "base/functional/callback.h" #include "base/gtest_prod_util.h" #include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/scoped_observation.h" #include "components/content_settings/core/browser/content_settings_observer.h" #include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/common/content_settings.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_observer.h" #include "url/origin.h" namespace content { class WebContents; } // DownloadRequestLimiter is responsible for determining whether a download // should be allowed or not. It is designed to keep pages from downloading // multiple files without user interaction. DownloadRequestLimiter is invoked // from ResourceDispatcherHost any time a download begins // (CanDownload). The request is processed on the UI thread, and the // request is notified (back on the IO thread) as to whether the download should // be allowed or denied. // // Invoking CanDownload notifies the callback and may update the // download status. The following details the various states: // . Each NavigationController initially starts out allowing a download // (ALLOW_ONE_DOWNLOAD). // . The first time CanDownload is invoked the download is allowed and // the state changes to PROMPT_BEFORE_DOWNLOAD. // . If the state is PROMPT_BEFORE_DOWNLOAD and the user clicks the mouse, // presses enter, the space bar or navigates to another page the state is // reset to ALLOW_ONE_DOWNLOAD. // . If a download is attempted and the state is PROMPT_BEFORE_DOWNLOAD the user // is prompted as to whether the download is allowed or disallowed. The users // choice stays until the user navigates to a different host. For example, if // the user allowed the download, multiple downloads are allowed without any // user intervention until the user navigates to a different host. // // The DownloadUiStatus indicates whether omnibox UI should be shown for the // current download status. We do not show UI if there has not yet been // a download attempt on the page regardless of the internal download status. class DownloadRequestLimiter : public base::RefCountedThreadSafe<DownloadRequestLimiter> { … }; #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_