Commit 5effca2e authored by megjablon's avatar megjablon Committed by Commit bot

Data Reduction Proxy Interstitials

A resource throttle and ui manager for the Data Reduction Proxy
bypass interstitials. The intersitial is shown when the user
loads a resource that returns a data reduction proxy bypass on http.
The user can choose to continue loading the page or go back to the
previous page. If the user accepts loading the page, the intertitial
will not be shown again for another 5 minutes.

BUG=428408

Review URL: https://codereview.chromium.org/684223003

Cr-Commit-Position: refs/heads/master@{#316330}
parent 9750c6d7
...@@ -6424,6 +6424,12 @@ Keep your key file in a safe place. You will need it to create new versions of y ...@@ -6424,6 +6424,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FLAGS_ENABLE_DATA_REDUCTION_PROXY_DEV_DESCRIPTION" desc="Describes an about:flags experiment to enable/disable the development version of the data reduction proxy"> <message name="IDS_FLAGS_ENABLE_DATA_REDUCTION_PROXY_DEV_DESCRIPTION" desc="Describes an about:flags experiment to enable/disable the development version of the data reduction proxy">
Enable or disable using the development version of the data reduction proxy. Enable or disable using the development version of the data reduction proxy.
</message> </message>
<message name="IDS_FLAGS_ENABLE_DATA_REDUCTION_PROXY_BYPASS_WARNING_NAME" desc="Name of the flag to enable using data reduction proxy warnings">
Data Saver proxy bypass warnings
</message>
<message name="IDS_FLAGS_ENABLE_DATA_REDUCTION_PROXY_BYPASS_WARNING_DESCRIPTION" desc="Description of the flag to enable using data reduction proxy warnings">
Use Data Saver with bypass warnings. The proxy must be enabled in settings for this flag to take effect.
</message>
</if> </if>
<message name="IDS_FLAGS_ENABLE_DATA_REDUCTION_PROXY_LO_FI_NAME" desc="An about::flags experiment title to enable/disable Data Saver Lo-Fi"> <message name="IDS_FLAGS_ENABLE_DATA_REDUCTION_PROXY_LO_FI_NAME" desc="An about::flags experiment title to enable/disable Data Saver Lo-Fi">
Enable Data Saver Lo-Fi mode Enable Data Saver Lo-Fi mode
......
...@@ -602,6 +602,7 @@ static_library("browser") { ...@@ -602,6 +602,7 @@ static_library("browser") {
deps += [ deps += [
":jni_headers", ":jni_headers",
"//components/cdm/browser", "//components/cdm/browser",
"//components/data_reduction_proxy/content/browser",
"//components/enhanced_bookmarks", "//components/enhanced_bookmarks",
"//components/resources:components_resources", "//components/resources:components_resources",
"//components/web_contents_delegate_android", "//components/web_contents_delegate_android",
...@@ -614,6 +615,7 @@ static_library("browser") { ...@@ -614,6 +615,7 @@ static_library("browser") {
"//components/storage_monitor", "//components/storage_monitor",
"//components/web_modal", "//components/web_modal",
] ]
defines += [ "ENABLE_DATA_REDUCTION_PROXY_DEBUGGING" ]
} }
if (is_mac) { if (is_mac) {
......
...@@ -2131,7 +2131,6 @@ const Experiment kExperiments[] = { ...@@ -2131,7 +2131,6 @@ const Experiment kExperiments[] = {
kOsDesktop, kOsDesktop,
SINGLE_VALUE_TYPE(switches::kEnableDelayAgnosticAec) SINGLE_VALUE_TYPE(switches::kEnableDelayAgnosticAec)
}, },
{ {
"mark-non-secure-as", // FLAGS:RECORD_UMA "mark-non-secure-as", // FLAGS:RECORD_UMA
IDS_MARK_NON_SECURE_AS_NAME, IDS_MARK_NON_SECURE_AS_NAME,
...@@ -2139,7 +2138,6 @@ const Experiment kExperiments[] = { ...@@ -2139,7 +2138,6 @@ const Experiment kExperiments[] = {
kOsAll, kOsAll,
MULTI_VALUE_TYPE(kMarkNonSecureAsChoices) MULTI_VALUE_TYPE(kMarkNonSecureAsChoices)
}, },
{ {
"enable-site-per-process", "enable-site-per-process",
IDS_FLAGS_ENABLE_SITE_PER_PROCESS_NAME, IDS_FLAGS_ENABLE_SITE_PER_PROCESS_NAME,
...@@ -2173,6 +2171,16 @@ const Experiment kExperiments[] = { ...@@ -2173,6 +2171,16 @@ const Experiment kExperiments[] = {
SINGLE_VALUE_TYPE(data_reduction_proxy::switches:: SINGLE_VALUE_TYPE(data_reduction_proxy::switches::
kEnableDataReductionProxyLoFi) kEnableDataReductionProxyLoFi)
}, },
#if defined(ENABLE_DATA_REDUCTION_PROXY_DEBUGGING)
{
"enable-data-reduction-proxy-bypass-warnings",
IDS_FLAGS_ENABLE_DATA_REDUCTION_PROXY_BYPASS_WARNING_NAME,
IDS_FLAGS_ENABLE_DATA_REDUCTION_PROXY_BYPASS_WARNING_DESCRIPTION,
kOsAndroid,
SINGLE_VALUE_TYPE(data_reduction_proxy::switches::
kEnableDataReductionProxyBypassWarning)
},
#endif
// NOTE: Adding new command-line switches requires adding corresponding // NOTE: Adding new command-line switches requires adding corresponding
// entries to enum "LoginCustomFlags" in histograms.xml. See note in // entries to enum "LoginCustomFlags" in histograms.xml. See note in
...@@ -2285,26 +2293,40 @@ bool SkipConditionalExperiment(const Experiment& experiment, ...@@ -2285,26 +2293,40 @@ bool SkipConditionalExperiment(const Experiment& experiment,
return true; return true;
} }
#if defined(OS_ANDROID) || defined(ENABLE_DATA_REDUCTION_PROXY_DEBUGGING)
chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
#endif
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// enable-data-reduction-proxy-dev is only available for the Dev/Beta channel. // enable-data-reduction-proxy-dev is only available for the Dev/Beta channel.
if (!strcmp("enable-data-reduction-proxy-dev", experiment.internal_name) && if (!strcmp("enable-data-reduction-proxy-dev", experiment.internal_name) &&
chrome::VersionInfo::GetChannel() != chrome::VersionInfo::CHANNEL_BETA && channel != chrome::VersionInfo::CHANNEL_BETA &&
chrome::VersionInfo::GetChannel() != chrome::VersionInfo::CHANNEL_DEV) { channel != chrome::VersionInfo::CHANNEL_DEV) {
return true; return true;
} }
// enable-data-reduction-proxy-alt is only available for the Dev channel. // enable-data-reduction-proxy-alt is only available for the Dev channel.
if (!strcmp("enable-data-reduction-proxy-alt", experiment.internal_name) && if (!strcmp("enable-data-reduction-proxy-alt", experiment.internal_name) &&
chrome::VersionInfo::GetChannel() != chrome::VersionInfo::CHANNEL_DEV) { channel != chrome::VersionInfo::CHANNEL_DEV) {
return true; return true;
} }
// enable-data-reduction-proxy-lo-fi is only available for Chromium builds and // enable-data-reduction-proxy-lo-fi is only available for Chromium builds and
// the Canary/Dev channel. // the Canary/Dev channel.
if (!strcmp("enable-data-reduction-proxy-lo-fi", experiment.internal_name) && if (!strcmp("enable-data-reduction-proxy-lo-fi", experiment.internal_name) &&
chrome::VersionInfo::GetChannel() != chrome::VersionInfo::CHANNEL_DEV && channel != chrome::VersionInfo::CHANNEL_DEV &&
chrome::VersionInfo::GetChannel() != channel != chrome::VersionInfo::CHANNEL_CANARY &&
chrome::VersionInfo::CHANNEL_CANARY && channel != chrome::VersionInfo::CHANNEL_UNKNOWN) {
chrome::VersionInfo::GetChannel() != return true;
chrome::VersionInfo::CHANNEL_UNKNOWN) { }
#endif
#if defined(ENABLE_DATA_REDUCTION_PROXY_DEBUGGING)
// enable-data-reduction-proxy-bypass-warning is only available for Chromium
// builds and Canary/Dev channel.
if (!strcmp("enable-data-reduction-proxy-bypass-warnings",
experiment.internal_name) &&
channel != chrome::VersionInfo::CHANNEL_UNKNOWN &&
channel != chrome::VersionInfo::CHANNEL_CANARY &&
channel != chrome::VersionInfo::CHANNEL_DEV) {
return true; return true;
} }
#endif #endif
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
#if defined(ENABLE_DATA_REDUCTION_PROXY_DEBUGGING)
#include "components/data_reduction_proxy/content/browser/content_data_reduction_proxy_debug_ui_service.h"
#endif
namespace content { namespace content {
class BrowserContext; class BrowserContext;
} }
...@@ -59,5 +63,18 @@ CreateDataReductionProxyChromeIOData( ...@@ -59,5 +63,18 @@ CreateDataReductionProxyChromeIOData(
ui_task_runner)); ui_task_runner));
data_reduction_proxy_io_data->InitOnUIThread(prefs); data_reduction_proxy_io_data->InitOnUIThread(prefs);
#if defined(ENABLE_DATA_REDUCTION_PROXY_DEBUGGING)
scoped_ptr<data_reduction_proxy::ContentDataReductionProxyDebugUIService>
data_reduction_proxy_ui_service(
new data_reduction_proxy::ContentDataReductionProxyDebugUIService(
base::Bind(&data_reduction_proxy::DataReductionProxyConfigurator::
GetProxyConfigOnIOThread,
base::Unretained(
data_reduction_proxy_io_data->configurator())),
ui_task_runner, io_task_runner));
data_reduction_proxy_io_data->set_debug_ui_service(
data_reduction_proxy_ui_service.Pass());
#endif
return data_reduction_proxy_io_data.Pass(); return data_reduction_proxy_io_data.Pass();
} }
...@@ -257,6 +257,11 @@ class ProfileIOData { ...@@ -257,6 +257,11 @@ class ProfileIOData {
bool IsDataReductionProxyEnabled() const; bool IsDataReductionProxyEnabled() const;
data_reduction_proxy::DataReductionProxyIOData*
data_reduction_proxy_io_data() const {
return data_reduction_proxy_io_data_.get();
}
protected: protected:
// A URLRequestContext for media that owns its HTTP factory, to ensure // A URLRequestContext for media that owns its HTTP factory, to ensure
// it is deleted. // it is deleted.
...@@ -373,11 +378,6 @@ class ProfileIOData { ...@@ -373,11 +378,6 @@ class ProfileIOData {
scoped_ptr<data_reduction_proxy::DataReductionProxyIOData> scoped_ptr<data_reduction_proxy::DataReductionProxyIOData>
data_reduction_proxy_io_data) const; data_reduction_proxy_io_data) const;
data_reduction_proxy::DataReductionProxyIOData*
data_reduction_proxy_io_data() const {
return data_reduction_proxy_io_data_.get();
}
net::FraudulentCertificateReporter* fraudulent_certificate_reporter() const { net::FraudulentCertificateReporter* fraudulent_certificate_reporter() const {
return fraudulent_certificate_reporter_.get(); return fraudulent_certificate_reporter_.get();
} }
......
...@@ -92,6 +92,10 @@ ...@@ -92,6 +92,10 @@
#include "components/navigation_interception/intercept_navigation_delegate.h" #include "components/navigation_interception/intercept_navigation_delegate.h"
#endif #endif
#if defined(ENABLE_DATA_REDUCTION_PROXY_DEBUGGING)
#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.h"
#endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/signin/merge_session_throttle.h" #include "chrome/browser/chromeos/login/signin/merge_session_throttle.h"
// TODO(oshima): Enable this for other platforms. // TODO(oshima): Enable this for other platforms.
...@@ -527,6 +531,15 @@ void ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles( ...@@ -527,6 +531,15 @@ void ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles(
} }
#endif #endif
#if defined(ENABLE_DATA_REDUCTION_PROXY_DEBUGGING)
scoped_ptr<content::ResourceThrottle> data_reduction_proxy_throttle =
data_reduction_proxy::DataReductionProxyDebugResourceThrottle::
MaybeCreate(
request, resource_type, io_data->data_reduction_proxy_io_data());
if (data_reduction_proxy_throttle)
throttles->push_back(data_reduction_proxy_throttle.release());
#endif
#if defined(ENABLE_SUPERVISED_USERS) #if defined(ENABLE_SUPERVISED_USERS)
bool is_subresource_request = bool is_subresource_request =
resource_type != content::RESOURCE_TYPE_MAIN_FRAME; resource_type != content::RESOURCE_TYPE_MAIN_FRAME;
......
...@@ -3371,6 +3371,7 @@ ...@@ -3371,6 +3371,7 @@
['OS=="android"', { ['OS=="android"', {
'dependencies': [ 'dependencies': [
'../components/components.gyp:cdm_browser', '../components/components.gyp:cdm_browser',
'../components/components.gyp:data_reduction_proxy_content',
'../components/components.gyp:enhanced_bookmarks', '../components/components.gyp:enhanced_bookmarks',
'../components/components.gyp:web_contents_delegate_android', '../components/components.gyp:web_contents_delegate_android',
'../components/components_resources.gyp:components_resources', '../components/components_resources.gyp:components_resources',
...@@ -3385,6 +3386,7 @@ ...@@ -3385,6 +3386,7 @@
'../third_party/libaddressinput/libaddressinput.gyp:libaddressinput', '../third_party/libaddressinput/libaddressinput.gyp:libaddressinput',
], ],
'sources': [ '<@(chrome_browser_android_sources)' ], 'sources': [ '<@(chrome_browser_android_sources)' ],
'defines': [ 'ENABLE_DATA_REDUCTION_PROXY_DEBUGGING' ],
}], }],
['OS=="mac"', { ['OS=="mac"', {
'dependencies': [ 'dependencies': [
......
...@@ -627,6 +627,8 @@ ...@@ -627,6 +627,8 @@
}], }],
['OS == "android"', { ['OS == "android"', {
'sources': [ 'sources': [
'data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle_unittest.cc',
'data_reduction_proxy/content/browser/data_reduction_proxy_debug_ui_manager_unittest.cc',
'invalidation/invalidation_service_android_unittest.cc', 'invalidation/invalidation_service_android_unittest.cc',
], ],
'sources!': [ 'sources!': [
...@@ -646,6 +648,7 @@ ...@@ -646,6 +648,7 @@
'web_modal/web_contents_modal_dialog_manager_unittest.cc', 'web_modal/web_contents_modal_dialog_manager_unittest.cc',
], ],
'dependencies': [ 'dependencies': [
'components.gyp:data_reduction_proxy_content',
'../testing/android/native_test.gyp:native_test_native_code', '../testing/android/native_test.gyp:native_test_native_code',
], ],
'dependencies!': [ 'dependencies!': [
......
...@@ -5,6 +5,28 @@ ...@@ -5,6 +5,28 @@
{ {
'targets': [ 'targets': [
{
# GN Version: //components/data_reduction_proxy/content
'target_name': 'data_reduction_proxy_content',
'type': 'static_library',
'dependencies': [
'../base/base.gyp:base',
'../content/content.gyp:content_browser',
'../skia/skia.gyp:skia',
],
'include_dirs': [
'..',
],
'sources': [
# Note: sources list duplicated in GN build.
'data_reduction_proxy/content/browser/content_data_reduction_proxy_debug_ui_service.cc',
'data_reduction_proxy/content/browser/content_data_reduction_proxy_debug_ui_service.h',
'data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.cc',
'data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.h',
'data_reduction_proxy/content/browser/data_reduction_proxy_debug_ui_manager.cc',
'data_reduction_proxy/content/browser/data_reduction_proxy_debug_ui_manager.h',
],
},
{ {
# GN version: //components/data_reduction_proxy/core/browser # GN version: //components/data_reduction_proxy/core/browser
'target_name': 'data_reduction_proxy_core_browser', 'target_name': 'data_reduction_proxy_core_browser',
...@@ -36,6 +58,7 @@ ...@@ -36,6 +58,7 @@
'data_reduction_proxy/core/browser/data_reduction_proxy_config.h', 'data_reduction_proxy/core/browser/data_reduction_proxy_config.h',
'data_reduction_proxy/core/browser/data_reduction_proxy_configurator.cc', 'data_reduction_proxy/core/browser/data_reduction_proxy_configurator.cc',
'data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h', 'data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h',
"data_reduction_proxy/core/browser/data_reduction_proxy_debug_ui_service.h",
'data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc', 'data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc',
'data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h', 'data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h',
'data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.cc', 'data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.cc',
...@@ -96,6 +119,7 @@ ...@@ -96,6 +119,7 @@
'../net/net.gyp:net_test_support', '../net/net.gyp:net_test_support',
'../testing/gmock.gyp:gmock', '../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest', '../testing/gtest.gyp:gtest',
'data_reduction_proxy_content',
'data_reduction_proxy_core_browser', 'data_reduction_proxy_core_browser',
'data_reduction_proxy_core_common', 'data_reduction_proxy_core_common',
], ],
......
...@@ -3,4 +3,8 @@ include_rules = [ ...@@ -3,4 +3,8 @@ include_rules = [
"+crypto", "+crypto",
"+google_apis", "+google_apis",
"+net", "+net",
# Data Reduction Proxy is a layered component; subdirectories must explicitly
# introduce the ability to use the content layer as appropriate.
"-components/data_reduction_proxy/content",
] ]
include_rules = [
"+components/data_reduction_proxy/core/browser",
"+components/data_reduction_proxy/core/common",
"+components/keyed_service",
"+components/user_prefs",
"+content/public/browser",
"+content/public/common",
"+net/base",
]
specific_include_rules = {
'.*_[a-z]*test\.cc': [
"+content/public/test",
"+net/http",
"+net/url_request",
],
}
\ No newline at end of file
# Copyright 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.
static_library("browser") {
sources = [
"content_data_reduction_proxy_debug_ui_service.cc",
"content_data_reduction_proxy_debug_ui_service.h",
"data_reduction_proxy_debug_resource_throttle.cc",
"data_reduction_proxy_debug_resource_throttle.h",
"data_reduction_proxy_debug_ui_manager.cc",
"data_reduction_proxy_debug_ui_manager.h",
]
deps = [
"//base",
"//content/public/browser",
"//skia",
]
}
if (is_android) {
source_set("unit_tests") {
testonly = true
sources = [
"data_reduction_proxy_debug_resource_throttle_unittest.cc",
"data_reduction_proxy_debug_ui_manager_unittest.cc",
]
deps = [
":browser",
"//testing/gtest",
]
}
}
// Copyright 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 "components/data_reduction_proxy/content/browser/content_data_reduction_proxy_debug_ui_service.h"
#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_ui_manager.h"
#include "net/proxy/proxy_config.h"
namespace data_reduction_proxy {
ContentDataReductionProxyDebugUIService::
ContentDataReductionProxyDebugUIService(
const DataReductionProxyNetworkDelegate::ProxyConfigGetter& getter,
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
: proxy_config_getter_(getter) {
ui_manager_ = new DataReductionProxyDebugUIManager(ui_task_runner,
io_task_runner);
}
ContentDataReductionProxyDebugUIService::
~ContentDataReductionProxyDebugUIService() {
}
const net::ProxyConfig&
ContentDataReductionProxyDebugUIService::data_reduction_proxy_config() const {
return proxy_config_getter_.Run();
}
const scoped_refptr<DataReductionProxyDebugUIManager>&
ContentDataReductionProxyDebugUIService::ui_manager() const {
return ui_manager_;
}
} // namespace data_reduction_proxy
// Copyright 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.
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_DATA_REDUCTION_PROXY_DEBUG_UI_SERVICE_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_DATA_REDUCTION_PROXY_DEBUG_UI_SERVICE_H_
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_debug_ui_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace net {
class ProxyConfig;
}
namespace data_reduction_proxy {
class DataReductionProxyDebugUIManager;
// Creates a DataReductionProxyDebugUIManager which handles showing
// interstitials. Also holds a ProxyConfigGetter which the
// DataReductionProxyDebugResourceThrottle uses to decide when to display the
// interstitials.
class ContentDataReductionProxyDebugUIService
: public DataReductionProxyDebugUIService {
public:
// Constructs a ContentDataReductionProxyDebugUIService object. |getter| is
// used to get the Data Reduction Proxy config. |ui_task_runner| and
// |io_task_runner| are used to create a DataReductionDebugProxyUIService.
ContentDataReductionProxyDebugUIService(
const DataReductionProxyNetworkDelegate::ProxyConfigGetter& getter,
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
~ContentDataReductionProxyDebugUIService() override;
const net::ProxyConfig& data_reduction_proxy_config() const override;
const scoped_refptr<DataReductionProxyDebugUIManager>&
ui_manager() const override;
private:
// The UI manager handles showing interstitials. Accessed on both UI and IO
// thread.
scoped_refptr<DataReductionProxyDebugUIManager> ui_manager_;
DataReductionProxyNetworkDelegate::ProxyConfigGetter proxy_config_getter_;
DISALLOW_COPY_AND_ASSIGN(ContentDataReductionProxyDebugUIService);
};
} // namespace data_reduction_proxy
#endif // COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_DATA_REDUCTION_PROXY_DEBUG_UI_SERVICE_H_
// Copyright 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 "components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_debug_ui_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_controller.h"
#include "content/public/browser/resource_request_info.h"
#include "net/base/load_flags.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
namespace data_reduction_proxy {
namespace {
const char kResourceThrottleLogName[] =
"DataReductionProxyDebugResourceThrottle";
} // namespace
// static
scoped_ptr<DataReductionProxyDebugResourceThrottle>
DataReductionProxyDebugResourceThrottle::MaybeCreate(
const net::URLRequest* request,
content::ResourceType resource_type,
const DataReductionProxyIOData* io_data) {
if (io_data->IsEnabled() &&
data_reduction_proxy::DataReductionProxyParams::
WarnIfNoDataReductionProxy()) {
DCHECK(io_data->params());
DCHECK(io_data->debug_ui_service());
DCHECK(request);
return scoped_ptr<DataReductionProxyDebugResourceThrottle>(
new DataReductionProxyDebugResourceThrottle(request, resource_type,
io_data->debug_ui_service(),
io_data->params()));
}
return nullptr;
}
// static
void DataReductionProxyDebugResourceThrottle::StartDisplayingBlockingPage(
scoped_refptr<DataReductionProxyDebugUIManager> ui_manager,
const DataReductionProxyDebugUIManager::BypassResource& resource) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
ui_manager->DisplayBlockingPage(resource);
}
DataReductionProxyDebugResourceThrottle::
DataReductionProxyDebugResourceThrottle(
const net::URLRequest* request,
content::ResourceType resource_type,
const DataReductionProxyDebugUIService* ui_service,
const DataReductionProxyParams* params)
: state_(NOT_BYPASSED),
request_(request),
ui_service_(ui_service),
params_(params),
is_subresource_(resource_type != content::RESOURCE_TYPE_MAIN_FRAME) {
DCHECK(request);
DCHECK(ui_service);
DCHECK(params);
}
DataReductionProxyDebugResourceThrottle::
~DataReductionProxyDebugResourceThrottle() {
}
// Displays an interstitial when the proxy will not be used for a request
// because it isn't configured.
void DataReductionProxyDebugResourceThrottle::WillStartUsingNetwork(
bool* defer) {
DCHECK_EQ(NOT_BYPASSED, state_);
if (!params_->AreDataReductionProxiesBypassed(
*request_, ui_service_->data_reduction_proxy_config(), NULL)) {
return;
}
if (request_->load_flags() & net::LOAD_PREFETCH) {
// Don't prefetch resources that bypass, disallow them.
controller()->Cancel();
return;
}
// Do not display the interstitial if bypassed by local rules.
if (params_->IsBypassedByDataReductionProxyLocalRules(
*request_, ui_service_->data_reduction_proxy_config())) {
state_ = LOCAL_BYPASS;
return;
}
DisplayBlockingPage(defer);
}
// Displays an intersitital when the Data Reduction Proxy explicitly returns a
// response that triggers a bypass.
void DataReductionProxyDebugResourceThrottle::WillRedirectRequest(
const net::RedirectInfo& redirect_info, bool* defer) {
// If the interstitial has already been shown, do not show it again. The
// LOAD_BYPASS_PROXY flag makes it so that proxies are not resolved. This
// override is used when downloading PAC files. If the request does not have
// the LOAD_BYPASS_PROXY flag, do not show the interstitial.
if (state_ != NOT_BYPASSED ||
!(request_->load_flags() & net::LOAD_BYPASS_PROXY)) {
return;
}
DisplayBlockingPage(defer);
}
const char* DataReductionProxyDebugResourceThrottle::GetNameForLogging() const {
return kResourceThrottleLogName;
}
void DataReductionProxyDebugResourceThrottle::DisplayBlockingPage(bool* defer) {
const content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request_);
DCHECK(info);
state_ = REMOTE_BYPASS;
*defer = true;
DataReductionProxyDebugUIManager::BypassResource resource;
resource.url = request_->url();
resource.is_subresource = is_subresource_;
resource.callback = base::Bind(
&DataReductionProxyDebugResourceThrottle::OnBlockingPageComplete,
AsWeakPtr());
resource.render_process_host_id = info->GetChildID();
resource.render_view_id = info->GetRouteID();
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(
&DataReductionProxyDebugResourceThrottle::StartDisplayingBlockingPage,
ui_service_->ui_manager(), resource));
}
void
DataReductionProxyDebugResourceThrottle::OnBlockingPageComplete(bool proceed) {
state_ = NOT_BYPASSED;
if (proceed)
controller()->Resume();
else
controller()->Cancel();
}
} // namespace data_reduction_proxy
// Copyright 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.
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_DEBUG_RESOURCE_THROTTLE_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_DEBUG_RESOURCE_THROTTLE_H_
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_ui_manager.h"
#include "content/public/browser/resource_throttle.h"
#include "content/public/common/resource_type.h"
#include "url/gurl.h"
namespace net {
class URLRequest;
}
namespace data_reduction_proxy {
class DataReductionProxyIOData;
class DataReductionProxyParams;
class DataReductionProxyDebugUIService;
// Gets notified at various points during the process of loading a resource.
// Defers the resource load when the Data Reduction Proxy is not going to be
// used. Resumes or cancels a deferred resource load via the ResourceController.
//
// Displays a warning when the proxy will not be used for a request because it
// isn't configured (a previous bypass) and when the proxy is supposed to be
// used, but there is a connection error. Will not warn when the Data Reduction
// Proxy is bypassed by local rules, or when the url scheme is not proxied by
// the Data Reduction Proxy.
//
// This class is useful, e.g., for users that wish to be warned when
// configurations that are able to go through the Data Reduction Proxy are
// bypassed.
//
// TODO(megjablon): An interstitial cannot be displayed at the time of
// WillProcessResponse. This prevents warning at the time when the Data
// Reduction Proxy returns a response that triggers a bypass. Therefore this
// interstitial is not shown for block=once bypasses. For other bypasses, the
// interstitial is not not shown on the initial bypassed request, but on the
// subsequent request.
class DataReductionProxyDebugResourceThrottle
: public content::ResourceThrottle,
public base::SupportsWeakPtr<DataReductionProxyDebugResourceThrottle> {
public:
static scoped_ptr<DataReductionProxyDebugResourceThrottle> MaybeCreate(
const net::URLRequest* request,
content::ResourceType resource_type,
const DataReductionProxyIOData* io_data);
// Starts displaying the Data Reduction Proxy blocking page if it is not
// prerendering. Must only be called on the UI thread. Takes a bypass
// resource, which is a structure used to pass parameters between the IO and
// UI thread, and shows a DataReductionBlockingPage for the resource using
// the given ui_manager.
static void StartDisplayingBlockingPage(
scoped_refptr<DataReductionProxyDebugUIManager> ui_manager,
const DataReductionProxyDebugUIManager::BypassResource& resource);
// Constructs a DataReductionProxyDebugResourceThrottle object with the given
// request, resource type, ui service, and params.
DataReductionProxyDebugResourceThrottle(
const net::URLRequest* request,
content::ResourceType resource_type,
const DataReductionProxyDebugUIService* ui_service,
const DataReductionProxyParams* params);
~DataReductionProxyDebugResourceThrottle() override;
// content::ResourceThrottle overrides:
void WillStartUsingNetwork(bool* defer) override;
void WillRedirectRequest(const net::RedirectInfo& redirect_info,
bool* defer) override;
const char* GetNameForLogging() const override;
private:
enum State {
NOT_BYPASSED, // A warning has not been shown yet for this request.
LOCAL_BYPASS, // The request was bypassed by local bypass rules.
REMOTE_BYPASS, // The request was bypassed by the Data Reduction Proxy.
};
// Creates a bypass resource and calls StartDisplayingBlockingPage on the UI
// thread. Sets defer to true. A bypass resource is a structure used to pass
// parameters between the IO and UI thread when interacting with the
// interstitial. Virtual for testing.
virtual void DisplayBlockingPage(bool* defer);
// Called on the IO thread when the user has decided to proceed with the
// current request, or go back.
void OnBlockingPageComplete(bool proceed);
// The bypass state of this.
State state_;
// Must outlive |this|.
const net::URLRequest* request_;
// Holds the UI manager that shows interstitials. Must outlive |this|.
const DataReductionProxyDebugUIService* ui_service_;
// Must outlive |this|.
const DataReductionProxyParams* params_;
const bool is_subresource_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyDebugResourceThrottle);
};
} // namespace data_reduction_proxy
#endif // COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_DEBUG_RESOURCE_THROTTLE_H_
// Copyright 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 "components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.h"
#include "base/bind.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "components/data_reduction_proxy/content/browser/content_data_reduction_proxy_debug_ui_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/resource_type.h"
#include "net/base/load_flags.h"
#include "net/proxy/proxy_config.h"
#include "net/url_request/redirect_info.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace base {
class TimeDelta;
}
namespace data_reduction_proxy {
namespace {
class TestDataReductionProxyDebugResourceThrottle
: public DataReductionProxyDebugResourceThrottle {
public:
TestDataReductionProxyDebugResourceThrottle(
net::URLRequest* request,
content::ResourceType resource_type,
DataReductionProxyDebugUIService* ui_service,
const DataReductionProxyParams* params)
: DataReductionProxyDebugResourceThrottle(
request, resource_type, ui_service, params) {
}
~TestDataReductionProxyDebugResourceThrottle() override {
}
private:
void DisplayBlockingPage(bool* defer) override {
*defer = true;
}
DISALLOW_COPY_AND_ASSIGN(TestDataReductionProxyDebugResourceThrottle);
};
} // namespace
class DataReductionProxyDebugResourceThrottleTest : public testing::Test {
public:
DataReductionProxyDebugResourceThrottleTest() : context_(true) {
context_.Init();
// The |test_job_factory_| takes ownership of the interceptor.
test_job_interceptor_ = new net::TestJobInterceptor();
EXPECT_TRUE(test_job_factory_.SetProtocolHandler(url::kHttpScheme,
test_job_interceptor_));
context_.set_job_factory(&test_job_factory_);
request_ = context_.CreateRequest(GURL("http://www.google.com/"), net::IDLE,
&delegate_, NULL);
ui_service_.reset(new ContentDataReductionProxyDebugUIService(
base::Bind(
&DataReductionProxyDebugResourceThrottleTest::
data_reduction_proxy_config,
base::Unretained(this)),
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::UI),
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::IO)));
params_.reset(new TestDataReductionProxyParams(0, 0));
resource_throttle_.reset(new TestDataReductionProxyDebugResourceThrottle(
request_.get(), content::RESOURCE_TYPE_MAIN_FRAME,
ui_service_.get(), params_.get()));
}
const net::ProxyConfig& data_reduction_proxy_config() const {
return proxy_config_;
}
protected:
// Required for base::MessageLoopProxy::current().
base::MessageLoopForIO loop_;
net::TestURLRequestContext context_;
net::TestDelegate delegate_;
// |test_job_interceptor_| is owned by |test_job_factory_|.
net::TestJobInterceptor* test_job_interceptor_;
net::URLRequestJobFactoryImpl test_job_factory_;
net::ProxyConfig proxy_config_;
scoped_ptr<net::URLRequest> request_;
scoped_ptr<ContentDataReductionProxyDebugUIService> ui_service_;
scoped_ptr<TestDataReductionProxyParams> params_;
scoped_ptr<TestDataReductionProxyDebugResourceThrottle> resource_throttle_;
};
// Expect to show the interstitial (defer == true), when the data reduction
// proxy is bypassed by the proxy server, but not when bypassed by local rules
// on the client (even when the proxy has already been bypassed by the server).
TEST_F(DataReductionProxyDebugResourceThrottleTest, WillStartUsingNetwork) {
bool defer = false;
params_->MockAreDataReductionProxiesBypassed(false);
resource_throttle_->WillStartUsingNetwork(&defer);
EXPECT_FALSE(defer);
params_->MockAreDataReductionProxiesBypassed(true);
params_->MockIsBypassedByDataReductionProxyLocalRules(false);
resource_throttle_->WillStartUsingNetwork(&defer);
EXPECT_TRUE(defer);
// Must be tested last because this sets |state_| of |resource_throttle_|
// to LOCAL_BYPASS.
defer = false;
params_->MockAreDataReductionProxiesBypassed(true);
params_->MockIsBypassedByDataReductionProxyLocalRules(true);
resource_throttle_->WillStartUsingNetwork(&defer);
EXPECT_FALSE(defer);
}
// Expect to show the interstitial (defer = true) when the LOAD_BYPASS_PROXY
// flag is not set, but not when it is.
TEST_F(DataReductionProxyDebugResourceThrottleTest, WillRedirectRequest) {
bool defer = false;
resource_throttle_->WillRedirectRequest(net::RedirectInfo(), &defer);
EXPECT_FALSE(defer);
request_->SetLoadFlags(net::LOAD_BYPASS_PROXY);
resource_throttle_->WillRedirectRequest(net::RedirectInfo(), &defer);
EXPECT_TRUE(defer);
}
} // namespace data_reduction_proxy
// Copyright 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 "components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_ui_manager.h"
#include "base/bind.h"
#include "base/single_thread_task_runner.h"
#include "base/time/time.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
namespace data_reduction_proxy {
namespace {
// Once the blocking page is shown, it is not displayed for another five
// minutes.
const int kBlockingPageDelayInMinutes = 5;
}
DataReductionProxyDebugUIManager::BypassResource::BypassResource()
: is_subresource(false),
render_process_host_id(-1),
render_view_id(-1) {
}
DataReductionProxyDebugUIManager::BypassResource::~BypassResource() {
}
DataReductionProxyDebugUIManager::DataReductionProxyDebugUIManager(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
: ui_task_runner_(ui_task_runner),
io_task_runner_(io_task_runner) {
}
DataReductionProxyDebugUIManager::~DataReductionProxyDebugUIManager() {
}
bool DataReductionProxyDebugUIManager::IsTabClosed(
const BypassResource& resource) const {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
// The tab might have been closed.
content::RenderViewHost* render_view_host =
content::RenderViewHost::FromID(resource.render_process_host_id,
resource.render_view_id);
content::WebContents* web_contents = nullptr;
if (render_view_host)
web_contents = content::WebContents::FromRenderViewHost(render_view_host);
if(web_contents)
return false;
return true;
}
void DataReductionProxyDebugUIManager::DisplayBlockingPage(
const BypassResource& resource) {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
// Check if the user has already ignored the warning for this render_view
// and domain.
if (base::Time::Now() - blocking_page_last_shown_ <
base::TimeDelta::FromMinutes(kBlockingPageDelayInMinutes)) {
if (!resource.callback.is_null())
io_task_runner_->PostTask(FROM_HERE, base::Bind(resource.callback, true));
return;
}
if (IsTabClosed(resource)) {
// The tab is gone and there was not a chance to show the interstitial.
// Just act as if "Don't Proceed" were chosen.
io_task_runner_->PostTask(
FROM_HERE,
base::Bind(&DataReductionProxyDebugUIManager::OnBlockingPageDone,
this, resource, false));
return;
}
// TODO(megjablon): Show blocking page. For now, continue on to the page.
io_task_runner_->PostTask(
FROM_HERE,
base::Bind(&DataReductionProxyDebugUIManager::OnBlockingPageDone,
this, resource, true));
}
void DataReductionProxyDebugUIManager::OnBlockingPageDone(
const BypassResource& resource,
bool proceed) {
DCHECK(io_task_runner_->BelongsToCurrentThread());
if (!resource.callback.is_null())
resource.callback.Run(proceed);
if (proceed)
blocking_page_last_shown_ = base::Time::Now();
}
} // namespace data_reduction_proxy
// Copyright 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.
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_DEBUG_UI_MANAGER_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_DEBUG_UI_MANAGER_H_
#include <vector>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/time/time.h"
#include "url/gurl.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace data_reduction_proxy {
// Construction needs to happen on the main thread.
class DataReductionProxyDebugUIManager
: public base::RefCountedThreadSafe<DataReductionProxyDebugUIManager> {
public:
// Passed a boolean indicating whether or not it is OK to proceed with
// loading an URL.
typedef base::Callback<void(bool /*proceed*/)> UrlCheckCallback;
// Structure used to pass parameters between the IO and UI thread when
// interacting with the blocking page.
struct BypassResource {
BypassResource();
~BypassResource();
GURL url;
bool is_subresource;
UrlCheckCallback callback; // This is called back on the IO thread.
int render_process_host_id;
int render_view_id;
};
// The DataReductionProxyDebugUIManager handles displaying blocking pages.
// After a page is loaded from the blocking page, another blocking page will
// not be shown for five minutes.
DataReductionProxyDebugUIManager(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
// Using |resource.render_process_host_id| and |resource.render_view_id|
// checks if WebContents exists for the RenderViewHost retreived from these
// id's.
virtual bool IsTabClosed(const BypassResource& resource) const;
// Called on the UI thread to display a blocking page. |url| is the url
// of the resource that bypassed. If the request contained a chain of
// redirects, |url| is the last url in the chain.
virtual void DisplayBlockingPage(const BypassResource& resource);
// The blocking page on the UI thread has completed.
void OnBlockingPageDone(const BypassResource& resource, bool proceed);
private:
// Ref counted classes have private destructors to avoid any code deleting the
// object accidentally while there are still references to it.
friend class base::RefCountedThreadSafe<DataReductionProxyDebugUIManager>;
friend class TestDataReductionProxyDebugUIManager;
virtual ~DataReductionProxyDebugUIManager();
// Records the last time the blocking page was shown. Once the blocking page
// is shown, it is not displayed for a period of time.
base::Time blocking_page_last_shown_;
// A task runner to ensure that calls to DisplayBlockingPage take place on the
// UI thread.
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
// A task runner to post OnBlockingPageDone to the IO thread.
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyDebugUIManager);
};
} // namespace data_reduction_proxy
#endif // COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_DEBUG_UI_MANAGER_H_
// Copyright 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 "components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_ui_manager.h"
#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace data_reduction_proxy {
namespace {
enum State {
NOT_CALLED,
PROCEED,
DONT_PROCEED,
};
} // namespace
class TestDataReductionProxyDebugUIManager
: public DataReductionProxyDebugUIManager {
public:
TestDataReductionProxyDebugUIManager(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
: DataReductionProxyDebugUIManager(ui_task_runner, io_task_runner) {
}
bool IsTabClosed(const BypassResource& resource) const override {
return is_tab_closed_return_value_;
}
bool is_tab_closed_return_value_;
private:
~TestDataReductionProxyDebugUIManager() override {
}
DISALLOW_COPY_AND_ASSIGN(TestDataReductionProxyDebugUIManager);
};
class DataReductionProxyDebugUIManagerTest
: public testing::Test {
public:
DataReductionProxyDebugUIManagerTest()
: state_(NOT_CALLED),
request_(context_.CreateRequest(GURL(), net::IDLE, &delegate_, NULL)) {
ui_manager_ = new TestDataReductionProxyDebugUIManager(
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::UI),
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::UI));
}
void OnBlockingPageDoneCallback(bool proceed) {
if (proceed)
state_ = PROCEED;
else
state_ = DONT_PROCEED;
}
void ResetState() {
state_ = NOT_CALLED;
}
protected:
State state_;
content::TestBrowserThreadBundle thread_bundle_;
net::TestURLRequestContext context_;
net::TestDelegate delegate_;
scoped_ptr<net::URLRequest> request_;
scoped_refptr<TestDataReductionProxyDebugUIManager> ui_manager_;
};
// Tests that the page is loaded after selecting continue on the blocking page
// and within the five minute window when the warning is not displayed again.
TEST_F(DataReductionProxyDebugUIManagerTest, DisplayBlockingPage) {
DataReductionProxyDebugUIManager::BypassResource resource;
resource.is_subresource = false;
resource.callback = base::Bind(
&DataReductionProxyDebugUIManagerTest::OnBlockingPageDoneCallback,
base::Unretained(this));
resource.render_process_host_id = 0;
resource.render_view_id = 0;
ui_manager_->is_tab_closed_return_value_ = false;
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(&DataReductionProxyDebugUIManager::DisplayBlockingPage,
ui_manager_, resource));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(PROCEED, state_);
// The warning was ignored so for the next five minutes automatically continue
// to the page.
ResetState();
// This value does not matter since it will not be reached. If it is reached
// the state will be DONT_PROCEED.
ui_manager_->is_tab_closed_return_value_ = false;
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(&DataReductionProxyDebugUIManager::DisplayBlockingPage,
ui_manager_, resource));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(PROCEED, state_);
}
// Tests that the blocking page is not shown when the tab is already closed.
TEST_F(DataReductionProxyDebugUIManagerTest, DontDisplayBlockingPage) {
DataReductionProxyDebugUIManager::BypassResource resource;
resource.is_subresource = false;
resource.callback = base::Bind(
&DataReductionProxyDebugUIManagerTest::OnBlockingPageDoneCallback,
base::Unretained(this));
resource.render_process_host_id = 0;
resource.render_view_id = 0;
ui_manager_->is_tab_closed_return_value_ = true;
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(&DataReductionProxyDebugUIManager::DisplayBlockingPage,
ui_manager_, resource));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(DONT_PROCEED, state_);
}
// Tests that OnBlockingPageDone calls the callback of the resource.
TEST_F(DataReductionProxyDebugUIManagerTest, OnBlockingPageDone) {
DataReductionProxyDebugUIManager::BypassResource resource;
resource.is_subresource = false;
resource.callback = base::Bind(
&DataReductionProxyDebugUIManagerTest::OnBlockingPageDoneCallback,
base::Unretained(this));
resource.render_process_host_id = 0;
resource.render_view_id = 0;
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(&DataReductionProxyDebugUIManager::OnBlockingPageDone,
ui_manager_, resource, false));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(DONT_PROCEED, state_);
ResetState();
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(&DataReductionProxyDebugUIManager::OnBlockingPageDone,
ui_manager_, resource, true));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(PROCEED, state_);
}
} // namespace data_reduction_proxy
...@@ -10,6 +10,7 @@ static_library("browser") { ...@@ -10,6 +10,7 @@ static_library("browser") {
"data_reduction_proxy_config.h", "data_reduction_proxy_config.h",
"data_reduction_proxy_configurator.cc", "data_reduction_proxy_configurator.cc",
"data_reduction_proxy_configurator.h", "data_reduction_proxy_configurator.h",
"data_reduction_proxy_debug_ui_service.h",
"data_reduction_proxy_delegate.cc", "data_reduction_proxy_delegate.cc",
"data_reduction_proxy_delegate.h", "data_reduction_proxy_delegate.h",
"data_reduction_proxy_interceptor.cc", "data_reduction_proxy_interceptor.cc",
......
// Copyright 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.
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_DEBUG_UI_SERVICE_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_DEBUG_UI_SERVICE_H_
#include "base/memory/ref_counted.h"
namespace net {
class ProxyConfig;
}
namespace data_reduction_proxy {
class DataReductionProxyDebugUIManager;
// An interface for the ContentDataReductionProxyDebugUIService which creates
// a DataReductionProxyDebugUIManager that handles showing interstitials. Also
// provides a method to get the Data Reduction Proxy config.
class DataReductionProxyDebugUIService {
public:
virtual ~DataReductionProxyDebugUIService() {}
// Returns the Data Reduction Proxy config.
virtual const net::ProxyConfig& data_reduction_proxy_config() const = 0;
// Returns the DataReductionProxyDebugUIManager created and owned by this.
virtual const scoped_refptr<DataReductionProxyDebugUIManager>&
ui_manager() const = 0;
};
} // namespace data_reduction_proxy
#endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_DEBUG_UI_SERVICE_H_
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/prefs/pref_member.h" #include "base/prefs/pref_member.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_debug_ui_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
...@@ -103,6 +104,19 @@ class DataReductionProxyIOData { ...@@ -103,6 +104,19 @@ class DataReductionProxyIOData {
return usage_stats_.get(); return usage_stats_.get();
} }
DataReductionProxyParams* params() const {
return params_.get();
}
DataReductionProxyDebugUIService* debug_ui_service() const {
return debug_ui_service_.get();
}
void set_debug_ui_service(
scoped_ptr<DataReductionProxyDebugUIService> ui_service) const {
debug_ui_service_= ui_service.Pass();
}
private: private:
// The type of Data Reduction Proxy client. // The type of Data Reduction Proxy client.
Client client_; Client client_;
...@@ -112,10 +126,15 @@ class DataReductionProxyIOData { ...@@ -112,10 +126,15 @@ class DataReductionProxyIOData {
// Tracker of compression statistics to be displayed to the user. // Tracker of compression statistics to be displayed to the user.
base::WeakPtr<DataReductionProxyStatisticsPrefs> statistics_prefs_; base::WeakPtr<DataReductionProxyStatisticsPrefs> statistics_prefs_;
// |temporary_statistics_prefs_| is used only until DataReductionProxySettings // |temporary_statistics_prefs_| is used only until DataReductionProxySettings
// initialization and is dead after. // initialization and is dead after.
scoped_ptr<DataReductionProxyStatisticsPrefs> temporary_statistics_prefs_; scoped_ptr<DataReductionProxyStatisticsPrefs> temporary_statistics_prefs_;
// Holds the DataReductionProxyDebugUIManager for Data Reduction Proxy bypass
// interstitials.
mutable scoped_ptr<DataReductionProxyDebugUIService> debug_ui_service_;
// Tracker of Data Reduction Proxy-related events, e.g., for logging. // Tracker of Data Reduction Proxy-related events, e.g., for logging.
scoped_ptr<DataReductionProxyEventStore> event_store_; scoped_ptr<DataReductionProxyEventStore> event_store_;
......
...@@ -102,6 +102,22 @@ bool DataReductionProxyParams::IsIncludedInAndroidOnePromoFieldTrial( ...@@ -102,6 +102,22 @@ bool DataReductionProxyParams::IsIncludedInAndroidOnePromoFieldTrial(
bool DataReductionProxyParams::IsLoFiEnabled() { bool DataReductionProxyParams::IsLoFiEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch( return base::CommandLine::ForCurrentProcess()->HasSwitch(
data_reduction_proxy::switches::kEnableDataReductionProxyLoFi); data_reduction_proxy::switches::kEnableDataReductionProxyLoFi);
}
//static
bool DataReductionProxyParams::WarnIfNoDataReductionProxy() {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
data_reduction_proxy::switches::
kEnableDataReductionProxyBypassWarning)) {
return true;
}
return false;
}
// static
bool DataReductionProxyParams::CanProxyURLScheme(const GURL& url) {
return url.SchemeIs(url::kHttpScheme);
} }
DataReductionProxyTypeInfo::DataReductionProxyTypeInfo() DataReductionProxyTypeInfo::DataReductionProxyTypeInfo()
......
...@@ -103,6 +103,14 @@ class DataReductionProxyParams { ...@@ -103,6 +103,14 @@ class DataReductionProxyParams {
// mode. // mode.
static bool IsLoFiEnabled(); static bool IsLoFiEnabled();
// Returns true if this client has the command line switch to show
// interstitials for data reduction proxy bypasses.
static bool WarnIfNoDataReductionProxy();
// Returns true if the Data Reduction Proxy supports the scheme of the
// provided |url|.
static bool CanProxyURLScheme(const GURL& url);
// Constructs configuration parameters. If |kAllowed|, then the standard // Constructs configuration parameters. If |kAllowed|, then the standard
// data reduction proxy configuration is allowed to be used. If // data reduction proxy configuration is allowed to be used. If
// |kfallbackAllowed| a fallback proxy can be used if the primary proxy is // |kfallbackAllowed| a fallback proxy can be used if the primary proxy is
...@@ -148,8 +156,8 @@ class DataReductionProxyParams { ...@@ -148,8 +156,8 @@ class DataReductionProxyParams {
// Returns true if this request would be bypassed by the data request proxy // Returns true if this request would be bypassed by the data request proxy
// based on applying the |data_reduction_proxy_config| param rules to the // based on applying the |data_reduction_proxy_config| param rules to the
// request URL. // request URL. Virutal for testing.
bool IsBypassedByDataReductionProxyLocalRules( virtual bool IsBypassedByDataReductionProxyLocalRules(
const net::URLRequest& request, const net::URLRequest& request,
const net::ProxyConfig& data_reduction_proxy_config) const; const net::ProxyConfig& data_reduction_proxy_config) const;
...@@ -159,8 +167,8 @@ class DataReductionProxyParams { ...@@ -159,8 +167,8 @@ class DataReductionProxyParams {
// proxies are bypassed, returns the minimum retry delay of the bypassed data // proxies are bypassed, returns the minimum retry delay of the bypassed data
// reduction proxies in min_retry_delay (if not NULL). If there are no // reduction proxies in min_retry_delay (if not NULL). If there are no
// bypassed data reduction proxies for the request scheme, returns false and // bypassed data reduction proxies for the request scheme, returns false and
// does not assign min_retry_delay. // does not assign min_retry_delay. Virtual for testing.
bool AreDataReductionProxiesBypassed( virtual bool AreDataReductionProxiesBypassed(
const net::URLRequest& request, const net::URLRequest& request,
const net::ProxyConfig& data_reduction_proxy_config, const net::ProxyConfig& data_reduction_proxy_config,
base::TimeDelta* min_retry_delay) const; base::TimeDelta* min_retry_delay) const;
......
...@@ -27,7 +27,11 @@ namespace data_reduction_proxy { ...@@ -27,7 +27,11 @@ namespace data_reduction_proxy {
TestDataReductionProxyParams::TestDataReductionProxyParams( TestDataReductionProxyParams::TestDataReductionProxyParams(
int flags, unsigned int has_definitions) int flags, unsigned int has_definitions)
: DataReductionProxyParams(flags, false), : DataReductionProxyParams(flags, false),
has_definitions_(has_definitions) { has_definitions_(has_definitions),
mock_is_bypassed_by_data_reduction_proxy_local_rules_(false),
mock_are_data_reduction_proxies_bypassed_(false),
is_bypassed_by_data_reduction_proxy_local_rules_return_value_(false),
are_data_reduction_proxies_bypassed_return_value_(false) {
init_result_ = Init( init_result_ = Init(
flags & DataReductionProxyParams::kAllowed, flags & DataReductionProxyParams::kAllowed,
flags & DataReductionProxyParams::kFallbackAllowed, flags & DataReductionProxyParams::kFallbackAllowed,
...@@ -39,6 +43,38 @@ bool TestDataReductionProxyParams::init_result() const { ...@@ -39,6 +43,38 @@ bool TestDataReductionProxyParams::init_result() const {
return init_result_; return init_result_;
} }
bool TestDataReductionProxyParams::IsBypassedByDataReductionProxyLocalRules(
const net::URLRequest& request,
const net::ProxyConfig& data_reduction_proxy_config) const {
if (mock_is_bypassed_by_data_reduction_proxy_local_rules_)
return is_bypassed_by_data_reduction_proxy_local_rules_return_value_;
return DataReductionProxyParams::IsBypassedByDataReductionProxyLocalRules(
request, data_reduction_proxy_config);
}
bool TestDataReductionProxyParams::AreDataReductionProxiesBypassed(
const net::URLRequest& request,
const net::ProxyConfig& data_reduction_proxy_config,
base::TimeDelta* min_retry_delay) const {
if (mock_are_data_reduction_proxies_bypassed_)
return are_data_reduction_proxies_bypassed_return_value_;
return DataReductionProxyParams::AreDataReductionProxiesBypassed(
request, data_reduction_proxy_config, min_retry_delay);
}
void TestDataReductionProxyParams::MockAreDataReductionProxiesBypassed(
bool return_value) {
mock_are_data_reduction_proxies_bypassed_ = true;
are_data_reduction_proxies_bypassed_return_value_ = return_value;
}
void
TestDataReductionProxyParams::MockIsBypassedByDataReductionProxyLocalRules(
bool return_value) {
mock_is_bypassed_by_data_reduction_proxy_local_rules_ = true;
is_bypassed_by_data_reduction_proxy_local_rules_return_value_ = return_value;
}
// Test values to replace the values specified in preprocessor defines. // Test values to replace the values specified in preprocessor defines.
std::string TestDataReductionProxyParams::DefaultDevOrigin() { std::string TestDataReductionProxyParams::DefaultDevOrigin() {
return kDefaultDevOrigin; return kDefaultDevOrigin;
......
...@@ -7,8 +7,14 @@ ...@@ -7,8 +7,14 @@
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
namespace base {
class TimeDelta;
}
namespace net { namespace net {
class ProxyConfig;
class ProxyServer; class ProxyServer;
class URLRequest;
} }
namespace data_reduction_proxy { namespace data_reduction_proxy {
...@@ -33,6 +39,19 @@ class TestDataReductionProxyParams : public DataReductionProxyParams { ...@@ -33,6 +39,19 @@ class TestDataReductionProxyParams : public DataReductionProxyParams {
unsigned int has_definitions); unsigned int has_definitions);
bool init_result() const; bool init_result() const;
// Overrides from DataReductionProxyParams.
bool IsBypassedByDataReductionProxyLocalRules(
const net::URLRequest& request,
const net::ProxyConfig& data_reduction_proxy_config) const override;
bool AreDataReductionProxiesBypassed(
const net::URLRequest& request,
const net::ProxyConfig& data_reduction_proxy_config,
base::TimeDelta* min_retry_delay) const override;
// Once called, the mocked method will repeatedly return |return_value|.
void MockIsBypassedByDataReductionProxyLocalRules(bool return_value);
void MockAreDataReductionProxiesBypassed(bool return_value);
// Test values to replace the values specified in preprocessor defines. // Test values to replace the values specified in preprocessor defines.
static std::string DefaultDevOrigin(); static std::string DefaultDevOrigin();
static std::string DefaultDevFallbackOrigin(); static std::string DefaultDevFallbackOrigin();
...@@ -76,6 +95,11 @@ class TestDataReductionProxyParams : public DataReductionProxyParams { ...@@ -76,6 +95,11 @@ class TestDataReductionProxyParams : public DataReductionProxyParams {
unsigned int has_definitions_; unsigned int has_definitions_;
bool init_result_; bool init_result_;
bool mock_is_bypassed_by_data_reduction_proxy_local_rules_;
bool mock_are_data_reduction_proxies_bypassed_;
bool is_bypassed_by_data_reduction_proxy_local_rules_return_value_;
bool are_data_reduction_proxies_bypassed_return_value_;
}; };
} // namespace data_reduction_proxy } // namespace data_reduction_proxy
#endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PARAMS_TEST_UTILS_H_ #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PARAMS_TEST_UTILS_H_
......
...@@ -55,5 +55,9 @@ const char kEnableDataReductionProxyAlt[] = "enable-data-reduction-proxy-alt"; ...@@ -55,5 +55,9 @@ const char kEnableDataReductionProxyAlt[] = "enable-data-reduction-proxy-alt";
const char kEnableDataReductionProxyLoFi[] = const char kEnableDataReductionProxyLoFi[] =
"enable-data-reduction-proxy-lo-fi"; "enable-data-reduction-proxy-lo-fi";
// Enable the data reduction proxy bypass warning.
const char kEnableDataReductionProxyBypassWarning[] =
"enable-data-reduction-proxy-bypass-warning";
} // namespace switches } // namespace switches
} // namespace data_reduction_proxy } // namespace data_reduction_proxy
...@@ -25,6 +25,7 @@ extern const char kEnableDataReductionProxyDev[]; ...@@ -25,6 +25,7 @@ extern const char kEnableDataReductionProxyDev[];
extern const char kEnableDataReductionProxy[]; extern const char kEnableDataReductionProxy[];
extern const char kEnableDataReductionProxyAlt[]; extern const char kEnableDataReductionProxyAlt[];
extern const char kEnableDataReductionProxyLoFi[]; extern const char kEnableDataReductionProxyLoFi[];
extern const char kEnableDataReductionProxyBypassWarning[];
} // namespace switches } // namespace switches
} // namespace data_reduction_proxy } // namespace data_reduction_proxy
......
...@@ -51314,6 +51314,7 @@ To add a new entry, add it with any value and run test to compute valid value. ...@@ -51314,6 +51314,7 @@ To add a new entry, add it with any value and run test to compute valid value.
<int value="-2132591642" label="enable-input-view"/> <int value="-2132591642" label="enable-input-view"/>
<int value="-2117201726" label="disable-gpu-rasterization"/> <int value="-2117201726" label="disable-gpu-rasterization"/>
<int value="-2114831248" label="disable-new-ntp"/> <int value="-2114831248" label="disable-new-ntp"/>
<int value="-2099035488" label="enable-data-reduction-proxy-bypass-warning"/>
<int value="-2098610409" label="disable-lcd-text"/> <int value="-2098610409" label="disable-lcd-text"/>
<int value="-2097515669" label="disable-cast"/> <int value="-2097515669" label="disable-cast"/>
<int value="-2077268643" label="disable-device-enumeration"/> <int value="-2077268643" label="disable-device-enumeration"/>
...@@ -51368,6 +51369,7 @@ To add a new entry, add it with any value and run test to compute valid value. ...@@ -51368,6 +51369,7 @@ To add a new entry, add it with any value and run test to compute valid value.
<int value="-1571841513" label="enable-devtools-experiments"/> <int value="-1571841513" label="enable-devtools-experiments"/>
<int value="-1553477903" label="ash-disable-text-filtering-in-overview-mode"/> <int value="-1553477903" label="ash-disable-text-filtering-in-overview-mode"/>
<int value="-1546903171" label="enable-touch-drag-drop"/> <int value="-1546903171" label="enable-touch-drag-drop"/>
<int value="-1514611301" label="enable-data-reduction-proxy-bypass-warnings"/>
<int value="-1510839574" label="disable-sync-synced-notifications"/> <int value="-1510839574" label="disable-sync-synced-notifications"/>
<int value="-1497338981" label="disable-accelerated-overflow-scroll"/> <int value="-1497338981" label="disable-accelerated-overflow-scroll"/>
<int value="-1482685863" label="enable-request-tablet-site"/> <int value="-1482685863" label="enable-request-tablet-site"/>
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