Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / android_webview / browser / net / aw_network_delegate.cc
blobb82d3aa229e39b9cfb3045aeba1f4617595936ee
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "android_webview/browser/net/aw_network_delegate.h"
7 #include "android_webview/browser/aw_browser_context.h"
8 #include "android_webview/browser/aw_contents_io_thread_client.h"
9 #include "android_webview/browser/aw_cookie_access_policy.h"
10 #include "base/android/build_info.h"
11 #include "components/policy/core/browser/url_blacklist_manager.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/resource_request_info.h"
14 #include "net/base/completion_callback.h"
15 #include "net/base/net_errors.h"
16 #include "net/http/http_response_headers.h"
17 #include "net/proxy/proxy_info.h"
18 #include "net/proxy/proxy_server.h"
19 #include "net/url_request/url_request.h"
21 using content::BrowserThread;
23 namespace android_webview {
25 AwNetworkDelegate::AwNetworkDelegate() : url_blacklist_manager_(nullptr) {
28 AwNetworkDelegate::~AwNetworkDelegate() {
31 int AwNetworkDelegate::OnBeforeURLRequest(
32 net::URLRequest* request,
33 const net::CompletionCallback& callback,
34 GURL* new_url) {
35 if (!url_blacklist_manager_) {
36 url_blacklist_manager_ =
37 AwBrowserContext::GetDefault()->GetURLBlacklistManager();
39 if (url_blacklist_manager_->IsURLBlocked(request->url()))
40 return net::ERR_BLOCKED_BY_ADMINISTRATOR;
42 return net::OK;
45 int AwNetworkDelegate::OnBeforeSendHeaders(
46 net::URLRequest* request,
47 const net::CompletionCallback& callback,
48 net::HttpRequestHeaders* headers) {
50 DCHECK(headers);
51 headers->SetHeaderIfMissing(
52 "X-Requested-With",
53 base::android::BuildInfo::GetInstance()->package_name());
54 return net::OK;
57 void AwNetworkDelegate::OnSendHeaders(net::URLRequest* request,
58 const net::HttpRequestHeaders& headers) {
61 int AwNetworkDelegate::OnHeadersReceived(
62 net::URLRequest* request,
63 const net::CompletionCallback& callback,
64 const net::HttpResponseHeaders* original_response_headers,
65 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
66 GURL* allowed_unsafe_redirect_url) {
67 DCHECK_CURRENTLY_ON(BrowserThread::IO);
68 int render_process_id, render_frame_id;
69 if (original_response_headers->response_code() >= 400 &&
70 content::ResourceRequestInfo::GetRenderFrameForRequest(
71 request, &render_process_id, &render_frame_id)) {
72 scoped_ptr<AwContentsIoThreadClient> io_thread_client =
73 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id);
74 if (io_thread_client.get()) {
75 io_thread_client->OnReceivedHttpError(request, original_response_headers);
78 return net::OK;
81 void AwNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
82 const GURL& new_location) {
85 void AwNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
88 void AwNetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {
91 void AwNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
94 void AwNetworkDelegate::OnPACScriptError(int line_number,
95 const base::string16& error) {
98 net::NetworkDelegate::AuthRequiredResponse AwNetworkDelegate::OnAuthRequired(
99 net::URLRequest* request,
100 const net::AuthChallengeInfo& auth_info,
101 const AuthCallback& callback,
102 net::AuthCredentials* credentials) {
103 return AUTH_REQUIRED_RESPONSE_NO_ACTION;
106 bool AwNetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
107 const net::CookieList& cookie_list) {
108 return AwCookieAccessPolicy::GetInstance()->OnCanGetCookies(request,
109 cookie_list);
112 bool AwNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
113 const std::string& cookie_line,
114 net::CookieOptions* options) {
115 return AwCookieAccessPolicy::GetInstance()->OnCanSetCookie(request,
116 cookie_line,
117 options);
120 bool AwNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
121 const base::FilePath& path) const {
122 return true;
125 } // namespace android_webview