Commit 9841fcd5 authored by John Abd-El-Malek's avatar John Abd-El-Malek Committed by Commit Bot

Remove ResourceThrottles in src/chrome.

These aren't used anymore.

Bug: 934009
Change-Id: Icb32638c0ce817c769b3dfd1c8a33e3a3021b8e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1638918
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Commit-Queue: Robbie McElrath <rmcelrath@chromium.org>
Auto-Submit: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarRobbie McElrath <rmcelrath@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665250}
parent 1294d248
...@@ -313,8 +313,6 @@ jumbo_split_static_library("browser") { ...@@ -313,8 +313,6 @@ jumbo_split_static_library("browser") {
"component_updater/chrome_component_updater_configurator.h", "component_updater/chrome_component_updater_configurator.h",
"component_updater/component_updater_prefs.cc", "component_updater/component_updater_prefs.cc",
"component_updater/component_updater_prefs.h", "component_updater/component_updater_prefs.h",
"component_updater/component_updater_resource_throttle.cc",
"component_updater/component_updater_resource_throttle.h",
"component_updater/component_updater_utils.cc", "component_updater/component_updater_utils.cc",
"component_updater/component_updater_utils.h", "component_updater/component_updater_utils.h",
"component_updater/crl_set_component_installer.cc", "component_updater/crl_set_component_installer.cc",
...@@ -433,8 +431,6 @@ jumbo_split_static_library("browser") { ...@@ -433,8 +431,6 @@ jumbo_split_static_library("browser") {
"download/download_query.h", "download/download_query.h",
"download/download_request_limiter.cc", "download/download_request_limiter.cc",
"download/download_request_limiter.h", "download/download_request_limiter.h",
"download/download_resource_throttle.cc",
"download/download_resource_throttle.h",
"download/download_service_factory.cc", "download/download_service_factory.cc",
"download/download_service_factory.h", "download/download_service_factory.h",
"download/download_started_animation.h", "download/download_started_animation.h",
...@@ -2326,8 +2322,6 @@ jumbo_split_static_library("browser") { ...@@ -2326,8 +2322,6 @@ jumbo_split_static_library("browser") {
"android/download/download_utils.h", "android/download/download_utils.h",
"android/download/duplicate_download_infobar_delegate.cc", "android/download/duplicate_download_infobar_delegate.cc",
"android/download/duplicate_download_infobar_delegate.h", "android/download/duplicate_download_infobar_delegate.h",
"android/download/intercept_download_resource_throttle.cc",
"android/download/intercept_download_resource_throttle.h",
"android/download/intercept_oma_download_navigation_throttle.cc", "android/download/intercept_oma_download_navigation_throttle.cc",
"android/download/intercept_oma_download_navigation_throttle.h", "android/download/intercept_oma_download_navigation_throttle.h",
"android/download/items/offline_content_aggregator_factory_android.cc", "android/download/items/offline_content_aggregator_factory_android.cc",
...@@ -4487,8 +4481,6 @@ jumbo_split_static_library("browser") { ...@@ -4487,8 +4481,6 @@ jumbo_split_static_library("browser") {
"offline_pages/background_loader_offliner.h", "offline_pages/background_loader_offliner.h",
"offline_pages/download_archive_manager.cc", "offline_pages/download_archive_manager.cc",
"offline_pages/download_archive_manager.h", "offline_pages/download_archive_manager.h",
"offline_pages/downloads/resource_throttle.cc",
"offline_pages/downloads/resource_throttle.h",
"offline_pages/fresh_offline_content_observer.cc", "offline_pages/fresh_offline_content_observer.cc",
"offline_pages/fresh_offline_content_observer.h", "offline_pages/fresh_offline_content_observer.h",
"offline_pages/offline_page_bookmark_observer.cc", "offline_pages/offline_page_bookmark_observer.cc",
......
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/android/download/intercept_download_resource_throttle.h"
#include "base/bind.h"
#include "base/strings/string_util.h"
#include "chrome/browser/android/download/download_controller_base.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_store.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle(
net::URLRequest* request,
const content::ResourceRequestInfo::WebContentsGetter& wc_getter)
: request_(request),
wc_getter_(wc_getter),
weak_factory_(this) {
}
InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() =
default;
void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) {
if (request_->url_chain().empty())
return;
GURL url = request_->url_chain().back();
if (!url.SchemeIsHTTPOrHTTPS())
return;
if (request_->method() != net::HttpRequestHeaders::kGetMethod)
return;
net::HttpRequestHeaders headers;
if (!request_->GetFullRequestHeaders(&headers))
return;
std::string mime_type;
request_->response_headers()->GetMimeType(&mime_type);
if (!base::EqualsCaseInsensitiveASCII(mime_type, kOMADrmMessageMimeType) &&
!base::EqualsCaseInsensitiveASCII(mime_type, kOMADrmContentMimeType) &&
!base::EqualsCaseInsensitiveASCII(mime_type, kOMADrmRightsMimeType1) &&
!base::EqualsCaseInsensitiveASCII(mime_type, kOMADrmRightsMimeType2)) {
return;
}
net::CookieStore* cookie_store = request_->context()->cookie_store();
if (cookie_store) {
// Cookie is obtained via asynchonous call. Setting |*defer| to true
// keeps the throttle alive in the meantime.
*defer = true;
net::CookieOptions options;
options.set_include_httponly();
cookie_store->GetCookieListWithOptionsAsync(
request_->url(), options,
base::BindOnce(&InterceptDownloadResourceThrottle::CheckCookiePolicy,
weak_factory_.GetWeakPtr()));
} else {
// Can't get any cookies, start android download.
StartDownload(DownloadInfo(request_));
}
}
const char* InterceptDownloadResourceThrottle::GetNameForLogging() {
return "InterceptDownloadResourceThrottle";
}
void InterceptDownloadResourceThrottle::CheckCookiePolicy(
const net::CookieList& cookie_list,
const net::CookieStatusList& excluded_cookies) {
DownloadInfo info(request_);
if (request_->context()->network_delegate()->CanGetCookies(
*request_, cookie_list,
/*allowed_from_caller=*/true)) {
std::string cookie = net::CanonicalCookie::BuildCookieLine(cookie_list);
if (!cookie.empty())
info.cookie = cookie;
}
StartDownload(info);
}
void InterceptDownloadResourceThrottle::StartDownload(
const DownloadInfo& info) {
DownloadControllerBase::Get()->CreateAndroidDownload(wc_getter_, info);
Cancel();
}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_DOWNLOAD_INTERCEPT_DOWNLOAD_RESOURCE_THROTTLE_H_
#define CHROME_BROWSER_ANDROID_DOWNLOAD_INTERCEPT_DOWNLOAD_RESOURCE_THROTTLE_H_
#include "base/memory/weak_ptr.h"
#include "chrome/browser/android/download/download_controller_base.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/browser/resource_throttle.h"
#include "net/cookies/canonical_cookie.h"
namespace net {
class URLRequest;
}
// InterceptDownloadResourceThrottle checks if a download request should be
// handled by Chrome or passsed to the Android Download Manager.
class InterceptDownloadResourceThrottle : public content::ResourceThrottle {
public:
InterceptDownloadResourceThrottle(
net::URLRequest* request,
const content::ResourceRequestInfo::WebContentsGetter& wc_getter);
~InterceptDownloadResourceThrottle() override;
// content::ResourceThrottle implementation:
void WillProcessResponse(bool* defer) override;
const char* GetNameForLogging() override;
private:
void CheckCookiePolicy(const net::CookieList& cookie_list,
const net::CookieStatusList& excluded_cookies);
void StartDownload(const DownloadInfo& info);
const net::URLRequest* request_;
content::ResourceRequestInfo::WebContentsGetter wc_getter_;
base::WeakPtrFactory<InterceptDownloadResourceThrottle> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(InterceptDownloadResourceThrottle);
};
#endif // CHROME_BROWSER_ANDROID_DOWNLOAD_INTERCEPT_DOWNLOAD_RESOURCE_THROTTLE_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/component_updater/component_updater_resource_throttle.h"
#include <vector>
#include "base/bind.h"
#include "base/location.h"
#include "base/memory/weak_ptr.h"
#include "base/task/post_task.h"
#include "components/component_updater/component_updater_service.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_throttle.h"
using content::BrowserThread;
namespace component_updater {
namespace {
///////////////////////////////////////////////////////////////////////////////
// In charge of blocking url requests until the |crx_id| component has been
// updated. This class is touched solely from the IO thread. The UI thread
// can post tasks to it via weak pointers. By default the request is blocked
// unless the CrxUpdateService calls Unblock().
// The lifetime is controlled by Chrome's resource loader so the component
// updater cannot touch objects from this class except via weak pointers.
class CUResourceThrottle : public content::ResourceThrottle,
public base::SupportsWeakPtr<CUResourceThrottle> {
public:
CUResourceThrottle();
~CUResourceThrottle() override;
// Overriden from ResourceThrottle.
void WillStartRequest(bool* defer) override;
void WillRedirectRequest(const net::RedirectInfo& redirect_info,
bool* defer) override;
const char* GetNameForLogging() override;
// Component updater calls this function via PostTask to unblock the request.
void Unblock();
typedef std::vector<base::WeakPtr<CUResourceThrottle> > WeakPtrVector;
private:
enum State { NEW, BLOCKED, UNBLOCKED };
State state_;
};
CUResourceThrottle::CUResourceThrottle() : state_(NEW) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
}
CUResourceThrottle::~CUResourceThrottle() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
}
void CUResourceThrottle::WillStartRequest(bool* defer) {
if (state_ != UNBLOCKED) {
state_ = BLOCKED;
*defer = true;
} else {
*defer = false;
}
}
void CUResourceThrottle::WillRedirectRequest(
const net::RedirectInfo& redirect_info, bool* defer) {
WillStartRequest(defer);
}
const char* CUResourceThrottle::GetNameForLogging() {
return "ComponentUpdateResourceThrottle";
}
void CUResourceThrottle::Unblock() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (state_ == BLOCKED)
Resume();
state_ = UNBLOCKED;
}
void UnblockThrottleOnUIThread(base::WeakPtr<CUResourceThrottle> rt) {
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO})
->PostTask(FROM_HERE, base::BindOnce(&CUResourceThrottle::Unblock, rt));
}
} // namespace
content::ResourceThrottle* GetOnDemandResourceThrottle(
ComponentUpdateService* cus,
const std::string& crx_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// We give the raw pointer to the caller, who will delete it at will
// and we keep for ourselves a weak pointer to it so we can post tasks
// from the UI thread without having to track lifetime directly.
CUResourceThrottle* rt = new CUResourceThrottle;
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI})
->PostTask(FROM_HERE,
base::BindOnce(&ComponentUpdateService::MaybeThrottle,
base::Unretained(cus), crx_id,
base::BindOnce(&UnblockThrottleOnUIThread,
rt->AsWeakPtr())));
return rt;
}
} // namespace component_updater
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_RESOURCE_THROTTLE_H_
#define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_RESOURCE_THROTTLE_H_
#include <string>
namespace content {
class ResourceThrottle;
}
namespace component_updater {
class ComponentUpdateService;
// Returns a network resource throttle. It means that a component will be
// downloaded and installed before the resource is unthrottled. This function
// can be called from the IO thread.
content::ResourceThrottle* GetOnDemandResourceThrottle(
ComponentUpdateService* cus,
const std::string& crx_id);
} // namespace component_updater
#endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_RESOURCE_THROTTLE_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/download/download_resource_throttle.h"
#include <utility>
#include "base/bind.h"
#include "base/task/post_task.h"
#include "build/build_config.h"
#include "chrome/browser/download/download_stats.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#if defined(OS_ANDROID)
#include "chrome/browser/android/download/download_controller_base.h"
#include "content/public/browser/render_view_host.h"
#endif
using content::BrowserThread;
namespace {
void OnCanDownloadDecided(base::WeakPtr<DownloadResourceThrottle> throttle,
bool storage_permission_granted, bool allow) {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&DownloadResourceThrottle::ContinueDownload, throttle,
storage_permission_granted, allow));
}
void CanDownload(
std::unique_ptr<DownloadResourceThrottle::DownloadRequestInfo> info) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
info->limiter->CanDownload(info->web_contents_getter, info->url,
info->request_method,
base::Bind(info->continue_callback, true));
}
#if defined(OS_ANDROID)
void OnThrottleAcquireFileAccessPermissionDone(
std::unique_ptr<DownloadResourceThrottle::DownloadRequestInfo> info,
bool granted) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (granted)
CanDownload(std::move(info));
else
info->continue_callback.Run(false, false);
}
#endif
void CanDownloadOnUIThread(
std::unique_ptr<DownloadResourceThrottle::DownloadRequestInfo> info) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
#if defined(OS_ANDROID)
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter =
info->web_contents_getter;
DownloadControllerBase::Get()->AcquireFileAccessPermission(
web_contents_getter,
base::Bind(&OnThrottleAcquireFileAccessPermissionDone,
base::Passed(std::move(info))));
#else
CanDownload(std::move(info));
#endif
}
} // namespace
DownloadResourceThrottle::DownloadRequestInfo::DownloadRequestInfo(
scoped_refptr<DownloadRequestLimiter> limiter,
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
const GURL& url,
const std::string& request_method,
const DownloadRequestInfo::Callback& continue_callback)
: limiter(limiter),
web_contents_getter(web_contents_getter),
url(url),
request_method(request_method),
continue_callback(continue_callback) {}
DownloadResourceThrottle::DownloadRequestInfo::~DownloadRequestInfo() {}
DownloadResourceThrottle::DownloadResourceThrottle(
scoped_refptr<DownloadRequestLimiter> limiter,
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
const GURL& url,
const std::string& request_method)
: querying_limiter_(true),
request_allowed_(false),
request_deferred_(false) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(
&CanDownloadOnUIThread,
std::unique_ptr<DownloadRequestInfo>(new DownloadRequestInfo(
limiter, web_contents_getter, url, request_method,
base::Bind(&OnCanDownloadDecided, AsWeakPtr())))));
}
DownloadResourceThrottle::~DownloadResourceThrottle() {
}
void DownloadResourceThrottle::WillStartRequest(bool* defer) {
WillDownload(defer);
}
void DownloadResourceThrottle::WillRedirectRequest(
const net::RedirectInfo& redirect_info,
bool* defer) {
WillDownload(defer);
}
void DownloadResourceThrottle::WillProcessResponse(bool* defer) {
WillDownload(defer);
}
const char* DownloadResourceThrottle::GetNameForLogging() {
return "DownloadResourceThrottle";
}
void DownloadResourceThrottle::WillDownload(bool* defer) {
DCHECK(!request_deferred_);
// Defer the download until we have the DownloadRequestLimiter result.
if (querying_limiter_) {
request_deferred_ = true;
*defer = true;
return;
}
if (!request_allowed_) {
RecordDownloadCount(CHROME_DOWNLOAD_COUNT_BLOCKED_BY_THROTTLING);
Cancel();
}
}
void DownloadResourceThrottle::ContinueDownload(
bool storage_permission_granted, bool allow) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
querying_limiter_ = false;
request_allowed_ = allow;
if (!storage_permission_granted) {
// UMA for this will be recorded in MobileDownload.StoragePermission.
} else if (allow) {
// Presumes all downloads initiated by navigation use this throttle and
// nothing else does.
RecordDownloadSource(DOWNLOAD_INITIATED_BY_NAVIGATION);
} else {
RecordDownloadCount(CHROME_DOWNLOAD_COUNT_BLOCKED_BY_THROTTLING);
}
if (request_deferred_) {
request_deferred_ = false;
if (allow) {
Resume();
} else {
Cancel();
}
}
}
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// 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_RESOURCE_THROTTLE_H_
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/download/download_request_limiter.h"
#include "content/public/browser/resource_throttle.h"
class GURL;
// DownloadResourceThrottle is used to determine if a download should be
// allowed. When a DownloadResourceThrottle is created it pauses the download
// and asks the DownloadRequestLimiter if the download should be allowed. The
// DownloadRequestLimiter notifies us asynchronously as to whether the download
// is allowed or not. If the download is allowed the request is resumed. If
// the download is not allowed the request is canceled.
class DownloadResourceThrottle
: public content::ResourceThrottle,
public base::SupportsWeakPtr<DownloadResourceThrottle> {
public:
// Information passed between callbacks to check whether download can proceed.
struct DownloadRequestInfo {
// Callback that is called on whether download can proceed.
// The boolean parameters indicate whether or not the download is allowed,
// and whether storage permission is granted
typedef base::Callback<void(
bool /* storage permission granted */, bool /*allow*/)> Callback;
DownloadRequestInfo(
scoped_refptr<DownloadRequestLimiter> limiter,
const content::ResourceRequestInfo::WebContentsGetter&
web_contents_getter,
const GURL& url,
const std::string& request_method,
const Callback& continue_callback);
~DownloadRequestInfo();
scoped_refptr<DownloadRequestLimiter> limiter;
content::ResourceRequestInfo::WebContentsGetter web_contents_getter;
GURL url;
std::string request_method;
Callback continue_callback;
private:
DISALLOW_COPY_AND_ASSIGN(DownloadRequestInfo);
};
DownloadResourceThrottle(
scoped_refptr<DownloadRequestLimiter> limiter,
const content::ResourceRequestInfo::WebContentsGetter&
web_contents_getter,
const GURL& url,
const std::string& request_method);
~DownloadResourceThrottle() override;
// content::ResourceThrottle implementation:
void WillStartRequest(bool* defer) override;
void WillRedirectRequest(const net::RedirectInfo& redirect_info,
bool* defer) override;
void WillProcessResponse(bool* defer) override;
const char* GetNameForLogging() override;
void ContinueDownload(bool storage_permission_granted, bool allow);
private:
void WillDownload(bool* defer);
// Set to true when we are querying the DownloadRequestLimiter.
bool querying_limiter_;
// Set to true when we know that the request is allowed to start.
bool request_allowed_;
// Set to true when we have deferred the request.
bool request_deferred_;
DISALLOW_COPY_AND_ASSIGN(DownloadResourceThrottle);
};
#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_THROTTLE_H_
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/download/download_resource_throttle.h"
#include "base/bind.h"
#include "base/run_loop.h"
#include "base/task/post_task.h"
#include "chrome/browser/download/download_request_limiter.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/resource_throttle.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_ANDROID)
#include "chrome/browser/android/download/mock_download_controller.h"
#endif
namespace {
const char kTestUrl[] = "http://www.example.com/";
} // namespace
class MockWebContentsDelegate : public content::WebContentsDelegate {
public:
MockWebContentsDelegate() {}
~MockWebContentsDelegate() override {}
};
class MockResourceThrottleDelegate
: public content::ResourceThrottle::Delegate {
public:
MOCK_METHOD0(Cancel, void());
MOCK_METHOD0(CancelAndIgnore, void());
MOCK_METHOD1(CancelWithError, void(int));
MOCK_METHOD0(Resume, void());
};
// Posts |quit_closure| to UI thread.
ACTION_P(QuitLoop, quit_closure) {
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI},
quit_closure);
}
class DownloadResourceThrottleTest : public ChromeRenderViewHostTestHarness {
public:
DownloadResourceThrottleTest()
: ChromeRenderViewHostTestHarness(
content::TestBrowserThreadBundle::REAL_IO_THREAD),
throttle_(nullptr),
limiter_(new DownloadRequestLimiter()) {}
~DownloadResourceThrottleTest() override {}
void SetUp() override {
ChromeRenderViewHostTestHarness::SetUp();
web_contents()->SetDelegate(&delegate_);
run_loop_.reset(new base::RunLoop());
#if defined(OS_ANDROID)
DownloadControllerBase::SetDownloadControllerBase(&download_controller_);
#endif
}
void TearDown() override {
content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
throttle_);
#if defined(OS_ANDROID)
DownloadControllerBase::SetDownloadControllerBase(nullptr);
#endif
ChromeRenderViewHostTestHarness::TearDown();
}
void StartThrottleOnIOThread(int process_id, int render_view_id) {
throttle_ = new DownloadResourceThrottle(
limiter_,
base::Bind(&tab_util::GetWebContentsByID, process_id, render_view_id),
GURL(kTestUrl), "GET");
throttle_->set_delegate_for_testing(&resource_throttle_delegate_);
bool defer;
throttle_->WillStartRequest(&defer);
EXPECT_EQ(true, defer);
}
void StartThrottle() {
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(
&DownloadResourceThrottleTest::StartThrottleOnIOThread,
base::Unretained(this),
web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
web_contents()->GetRenderViewHost()->GetRoutingID()));
run_loop_->Run();
}
protected:
content::ResourceThrottle* throttle_;
MockWebContentsDelegate delegate_;
scoped_refptr<DownloadRequestLimiter> limiter_;
::testing::NiceMock<MockResourceThrottleDelegate> resource_throttle_delegate_;
std::unique_ptr<base::RunLoop> run_loop_;
#if defined(OS_ANDROID)
chrome::android::MockDownloadController download_controller_;
#endif
};
TEST_F(DownloadResourceThrottleTest, StartDownloadThrottle_Basic) {
EXPECT_CALL(resource_throttle_delegate_, Resume())
.WillOnce(QuitLoop(run_loop_->QuitClosure()));
StartThrottle();
}
#if defined(OS_ANDROID)
TEST_F(DownloadResourceThrottleTest, DownloadWithFailedFileAcecssRequest) {
DownloadControllerBase::Get()
->SetApproveFileAccessRequestForTesting(false);
EXPECT_CALL(resource_throttle_delegate_, Cancel())
.WillOnce(QuitLoop(run_loop_->QuitClosure()));
StartThrottle();
}
#endif
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/loader/safe_browsing_resource_throttle.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/safe_browsing/ui_manager.h"
#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "components/safe_browsing/db/database_manager.h"
#include "components/safe_browsing/db/v4_protocol_manager_util.h"
content::ResourceThrottle* MaybeCreateSafeBrowsingResourceThrottle(
net::URLRequest* request,
content::ResourceType resource_type,
safe_browsing::SafeBrowsingService* sb_service,
const ProfileIOData* io_data) {
if (!sb_service->database_manager()->IsSupported())
return nullptr;
// No need to create resource throttle if request url is whitelisted by
// enterprise policy.
if (io_data &&
safe_browsing::IsURLWhitelistedByPolicy(
request->url(), io_data->safe_browsing_whitelist_domains())) {
return nullptr;
}
return new SafeBrowsingParallelResourceThrottle(request, resource_type,
sb_service);
}
SafeBrowsingParallelResourceThrottle::SafeBrowsingParallelResourceThrottle(
const net::URLRequest* request,
content::ResourceType resource_type,
safe_browsing::SafeBrowsingService* sb_service)
: safe_browsing::BaseParallelResourceThrottle(
request,
resource_type,
base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
sb_service->database_manager(),
sb_service->ui_manager())) {}
SafeBrowsingParallelResourceThrottle::~SafeBrowsingParallelResourceThrottle() =
default;
const char* SafeBrowsingParallelResourceThrottle::GetNameForLogging() {
return "SafeBrowsingParallelResourceThrottle";
}
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_LOADER_SAFE_BROWSING_RESOURCE_THROTTLE_H_
#define CHROME_BROWSER_LOADER_SAFE_BROWSING_RESOURCE_THROTTLE_H_
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "components/safe_browsing/browser/base_parallel_resource_throttle.h"
#include "content/public/browser/resource_throttle.h"
#include "content/public/common/resource_type.h"
namespace net {
class URLRequest;
}
namespace safe_browsing {
class SafeBrowsingService;
}
class ProfileIOData;
// Contructs a resource throttle for SafeBrowsing.
// It could return nullptr if URL checking is not supported on this
// build+device.
content::ResourceThrottle* MaybeCreateSafeBrowsingResourceThrottle(
net::URLRequest* request,
content::ResourceType resource_type,
safe_browsing::SafeBrowsingService* sb_service,
const ProfileIOData* io_data);
// SafeBrowsingParallelResourceThrottle uses a Chrome-specific
// safe_browsing::UrlCheckerDelegate implementation with its base class
// safe_browsing::BaseParallelResourceThrottle.
class SafeBrowsingParallelResourceThrottle
: public safe_browsing::BaseParallelResourceThrottle {
private:
friend content::ResourceThrottle* MaybeCreateSafeBrowsingResourceThrottle(
net::URLRequest* request,
content::ResourceType resource_type,
safe_browsing::SafeBrowsingService* sb_service,
const ProfileIOData* io_data);
SafeBrowsingParallelResourceThrottle(
const net::URLRequest* request,
content::ResourceType resource_type,
safe_browsing::SafeBrowsingService* sb_service);
~SafeBrowsingParallelResourceThrottle() override;
const char* GetNameForLogging() override;
DISALLOW_COPY_AND_ASSIGN(SafeBrowsingParallelResourceThrottle);
};
#endif // CHROME_BROWSER_LOADER_SAFE_BROWSING_RESOURCE_THROTTLE_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/offline_pages/downloads/resource_throttle.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/task/post_task.h"
#include "chrome/browser/offline_pages/offline_page_utils.h"
#include "components/offline_pages/core/client_namespace_constants.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_request_utils.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/browser/web_contents.h"
namespace {
void WillStartOfflineRequestOnUIThread(
const GURL& url,
const std::string& request_origin,
const content::ResourceRequestInfo::WebContentsGetter& contents_getter) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::WebContents* web_contents = contents_getter.Run();
if (!web_contents)
return;
offline_pages::OfflinePageUtils::ScheduleDownload(
web_contents, offline_pages::kDownloadNamespace, url,
offline_pages::OfflinePageUtils::DownloadUIActionFlags::ALL,
request_origin);
}
} // namespace
namespace offline_pages {
namespace downloads {
ResourceThrottle::ResourceThrottle(const net::URLRequest* request)
: request_(request) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
}
ResourceThrottle::~ResourceThrottle() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
}
void ResourceThrottle::WillProcessResponse(bool* defer) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
std::string mime_type;
request_->GetMimeType(&mime_type);
if (offline_pages::OfflinePageUtils::CanDownloadAsOfflinePage(request_->url(),
mime_type)) {
content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request_);
if (!info)
return;
std::string request_origin =
content::DownloadRequestUtils::GetRequestOriginFromRequest(request_);
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&WillStartOfflineRequestOnUIThread, request_->url(),
request_origin, info->GetWebContentsGetterForRequest()));
Cancel();
}
}
const char* ResourceThrottle::GetNameForLogging() {
return "offline_pages::downloads::ResourceThrottle";
}
} // namespace downloads
} // namespace offline_pages
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_OFFLINE_PAGES_DOWNLOADS_RESOURCE_THROTTLE_H_
#define CHROME_BROWSER_OFFLINE_PAGES_DOWNLOADS_RESOURCE_THROTTLE_H_
#include "content/public/browser/resource_throttle.h"
#include "net/url_request/url_request.h"
namespace offline_pages {
namespace downloads {
// This ResourceThrottle is used to hook up into the loading process at the
// moment when headers are available (WillProcessResponse) to determine if the
// download has text/html mime type and should be canceled as a download and
// re-scheduled as a OfflinePage download request. This will be handled by
// Offline Page backend as a full page download rather than a single .html
// file download.
class ResourceThrottle : public content::ResourceThrottle {
public:
explicit ResourceThrottle(const net::URLRequest* request);
~ResourceThrottle() override;
// content::ResourceThrottle implementation:
void WillProcessResponse(bool* defer) override;
const char* GetNameForLogging() override;
private:
const net::URLRequest* request_;
DISALLOW_COPY_AND_ASSIGN(ResourceThrottle);
};
} // namespace downloads
} // namespace offline_pages
#endif // CHROME_BROWSER_OFFLINE_PAGES_DOWNLOADS_RESOURCE_THROTTLE_H_
...@@ -112,8 +112,6 @@ jumbo_static_library("safe_browsing") { ...@@ -112,8 +112,6 @@ jumbo_static_library("safe_browsing") {
sources += [ sources += [
"../download/download_completion_blocker.cc", "../download/download_completion_blocker.cc",
"../download/download_completion_blocker.h", "../download/download_completion_blocker.h",
"../loader/safe_browsing_resource_throttle.cc",
"../loader/safe_browsing_resource_throttle.h",
"browser_feature_extractor.cc", "browser_feature_extractor.cc",
"browser_feature_extractor.h", "browser_feature_extractor.h",
"browser_features.cc", "browser_features.cc",
...@@ -219,8 +217,6 @@ jumbo_static_library("safe_browsing") { ...@@ -219,8 +217,6 @@ jumbo_static_library("safe_browsing") {
} }
} else if (safe_browsing_mode == 2) { } else if (safe_browsing_mode == 2) {
sources += [ sources += [
"../loader/safe_browsing_resource_throttle.cc",
"../loader/safe_browsing_resource_throttle.h",
"android/file_type_policies.cc", "android/file_type_policies.cc",
"android/services_delegate_android.cc", "android/services_delegate_android.cc",
"android/services_delegate_android.h", "android/services_delegate_android.h",
...@@ -233,8 +229,6 @@ jumbo_static_library("safe_browsing") { ...@@ -233,8 +229,6 @@ jumbo_static_library("safe_browsing") {
] ]
} else if (safe_browsing_mode == 3) { } else if (safe_browsing_mode == 3) {
sources += [ sources += [
"../loader/safe_browsing_resource_throttle.cc",
"../loader/safe_browsing_resource_throttle.h",
"android/file_type_policies.cc", "android/file_type_policies.cc",
"android/services_delegate_android.cc", "android/services_delegate_android.cc",
"android/services_delegate_android.h", "android/services_delegate_android.h",
......
...@@ -2709,7 +2709,6 @@ test("unit_tests") { ...@@ -2709,7 +2709,6 @@ test("unit_tests") {
"../browser/download/download_prefs_unittest.cc", "../browser/download/download_prefs_unittest.cc",
"../browser/download/download_query_unittest.cc", "../browser/download/download_query_unittest.cc",
"../browser/download/download_request_limiter_unittest.cc", "../browser/download/download_request_limiter_unittest.cc",
"../browser/download/download_resource_throttle_unittest.cc",
"../browser/download/download_status_updater_unittest.cc", "../browser/download/download_status_updater_unittest.cc",
"../browser/download/download_target_determiner_unittest.cc", "../browser/download/download_target_determiner_unittest.cc",
"../browser/download/download_ui_controller_unittest.cc", "../browser/download/download_ui_controller_unittest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment