| Index: chrome/browser/renderer_host/data_reduction_proxy_navigation_throttle_android.cc
|
| diff --git a/chrome/browser/renderer_host/data_reduction_proxy_navigation_throttle_android.cc b/chrome/browser/renderer_host/data_reduction_proxy_navigation_throttle_android.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..608c84e05541dc32b7be682f77183f6885b12d80
|
| --- /dev/null
|
| +++ b/chrome/browser/renderer_host/data_reduction_proxy_navigation_throttle_android.cc
|
| @@ -0,0 +1,146 @@
|
| +// 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 "chrome/browser/renderer_host/data_reduction_proxy_navigation_throttle_android.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/prefs/pref_service.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/prerender/prerender_contents.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/renderer_host/data_reduction_proxy_throttling_utils_android.h"
|
| +#include "chrome/browser/safe_browsing/ui_manager.h"
|
| +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
|
| +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/navigation_handle.h"
|
| +#include "content/public/browser/render_process_host.h"
|
| +#include "content/public/browser/render_view_host.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "net/http/http_response_headers.h"
|
| +
|
| +using content::BrowserThread;
|
| +using content::NavigationThrottle;
|
| +
|
| +// static
|
| +scoped_ptr<NavigationThrottle>
|
| +DataReductionProxyNavigationThrottle::MaybeCreate(
|
| + content::NavigationHandle* navigation_handle,
|
| + safe_browsing::SafeBrowsingService* sb_service) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| +
|
| + content::BrowserContext* browser_context =
|
| + navigation_handle->GetWebContents()->GetBrowserContext();
|
| + DCHECK(browser_context);
|
| + Profile* profile = Profile::FromBrowserContext(browser_context);
|
| + DCHECK(profile);
|
| +
|
| + bool is_data_reduction_proxy_available =
|
| + !profile->GetPrefs()->GetBoolean(
|
| + data_reduction_proxy::prefs::kDataReductionProxyEnabled) ||
|
| + data_reduction_proxy::params::ShouldForceEnableDataReductionProxy();
|
| + if (!data_reduction_proxy_throttling_utils::CanCreateThrottle(
|
| + profile->GetProfileType() == Profile::INCOGNITO_PROFILE,
|
| + is_data_reduction_proxy_available, navigation_handle->GetURL())) {
|
| + return nullptr;
|
| + }
|
| +
|
| + return scoped_ptr<NavigationThrottle>(
|
| + new DataReductionProxyNavigationThrottle(navigation_handle, sb_service));
|
| +}
|
| +
|
| +DataReductionProxyNavigationThrottle::DataReductionProxyNavigationThrottle(
|
| + content::NavigationHandle* navigation_handle,
|
| + safe_browsing::SafeBrowsingService* sb_service)
|
| + : NavigationThrottle(navigation_handle),
|
| + state_(STATE_NONE),
|
| + safe_browsing_(sb_service) {}
|
| +
|
| +DataReductionProxyNavigationThrottle::~DataReductionProxyNavigationThrottle() {}
|
| +
|
| +NavigationThrottle::ThrottleCheckResult
|
| +DataReductionProxyNavigationThrottle::WillRedirectRequest() {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + CHECK(state_ == STATE_NONE);
|
| +
|
| + // Save the redirect urls for possible malware detail reporting later.
|
| + redirect_urls_.push_back(navigation_handle()->GetURL());
|
| +
|
| + // We need to check the new URL before following the redirect.
|
| + safe_browsing::SBThreatType threat_type =
|
| + data_reduction_proxy_throttling_utils::CheckHeaders(
|
| + navigation_handle()->GetResponseHeaders());
|
| + if (threat_type == safe_browsing::SB_THREAT_TYPE_SAFE)
|
| + return NavigationThrottle::PROCEED;
|
| +
|
| + // If safe browsing is disabled and the request is sent to the DRP server,
|
| + // we need to break the redirect loop by setting the extra header.
|
| + if (!safe_browsing_->enabled()) {
|
| + AddExtraHeader(
|
| + data_reduction_proxy_throttling_utils::kUnsafeUrlProceedHeader, "1");
|
| + return NavigationThrottle::PROCEED;
|
| + }
|
| +
|
| + if (navigation_handle()->IsPrefetch()) {
|
| + return NavigationThrottle::CANCEL;
|
| + }
|
| +
|
| + prerender::PrerenderContents* prerender_contents =
|
| + prerender::PrerenderContents::FromWebContents(
|
| + navigation_handle()->GetWebContents());
|
| + if (prerender_contents) {
|
| + // This does not destroy the WebContents backing the PrerenderContents in
|
| + // this iteration of the MessageLoop, making it safe to call from a
|
| + // NavigationThrottle.
|
| + prerender_contents->Destroy(prerender::FINAL_STATUS_SAFE_BROWSING);
|
| + return NavigationThrottle::CANCEL;
|
| + }
|
| +
|
| + state_ = STATE_DISPLAYING_BLOCKING_PAGE;
|
| + safe_browsing::SafeBrowsingUIManager::UnsafeResource unsafe_resource;
|
| + unsafe_resource.url = navigation_handle()->GetURL();
|
| + unsafe_resource.original_url = navigation_handle()->GetOriginalURL();
|
| + unsafe_resource.redirect_urls = redirect_urls_;
|
| + unsafe_resource.is_subresource = !navigation_handle()->IsInMainFrame();
|
| + unsafe_resource.is_subframe = !navigation_handle()->IsInMainFrame();
|
| + unsafe_resource.threat_type = threat_type;
|
| + unsafe_resource.callback =
|
| + base::Bind(&DataReductionProxyNavigationThrottle::OnBlockingPageComplete,
|
| + AsWeakPtr());
|
| + unsafe_resource.callback_thread =
|
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
|
| +
|
| + // Add the route id and process id for the WebContents current RenderView. It
|
| + // is used later to find the WebContents again.
|
| + unsafe_resource.render_process_host_id = navigation_handle()
|
| + ->GetWebContents()
|
| + ->GetRenderViewHost()
|
| + ->GetProcess()
|
| + ->GetID();
|
| + unsafe_resource.render_view_id =
|
| + navigation_handle()->GetWebContents()->GetRoutingID();
|
| + unsafe_resource.threat_source = safe_browsing::ThreatSource::DATA_SAVER;
|
| +
|
| + safe_browsing_->ui_manager()->DisplayBlockingPage(unsafe_resource);
|
| + return NavigationThrottle::DEFER;
|
| +}
|
| +
|
| +// SafeBrowsingService::UrlCheckCallback implementation, called on the UI
|
| +// thread when the user has decided to proceed with the current request, or
|
| +// go back.
|
| +void DataReductionProxyNavigationThrottle::OnBlockingPageComplete(
|
| + bool proceed) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + CHECK(state_ == STATE_DISPLAYING_BLOCKING_PAGE);
|
| + state_ = STATE_NONE;
|
| +
|
| + if (proceed) {
|
| + // Inject the header before resuming the request.
|
| + AddExtraHeader(
|
| + data_reduction_proxy_throttling_utils::kUnsafeUrlProceedHeader, "1");
|
| + navigation_handle()->Resume();
|
| + } else {
|
| + navigation_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL);
|
| + }
|
| +}
|
|
|