Convert env to a defaultdict in run_executable() to fix other callers of that function.
[chromium-blink-merge.git] / extensions / shell / browser / shell_network_delegate.cc
blobb148bc3d68b7c904c4acfc34803fafb0dbcbad71
1 // Copyright 2014 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 "extensions/shell/browser/shell_network_delegate.h"
7 #include "content/public/browser/render_frame_host.h"
8 #include "content/public/browser/resource_request_info.h"
9 #include "extensions/browser/api/web_request/web_request_api.h"
10 #include "extensions/browser/extension_system.h"
11 #include "extensions/browser/extensions_browser_client.h"
12 #include "extensions/browser/process_manager.h"
13 #include "net/url_request/url_request.h"
15 namespace extensions {
17 namespace {
18 bool g_accept_all_cookies = true;
21 ShellNetworkDelegate::ShellNetworkDelegate(
22 void* browser_context, InfoMap* extension_info_map) {
23 browser_context_ = browser_context;
24 extension_info_map_ = extension_info_map;
27 ShellNetworkDelegate::~ShellNetworkDelegate() {}
29 void ShellNetworkDelegate::SetAcceptAllCookies(bool accept) {
30 g_accept_all_cookies = accept;
33 int ShellNetworkDelegate::OnBeforeURLRequest(
34 net::URLRequest* request,
35 const net::CompletionCallback& callback,
36 GURL* new_url) {
37 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest(
38 browser_context_, extension_info_map_.get(), request, callback, new_url);
41 int ShellNetworkDelegate::OnBeforeSendHeaders(
42 net::URLRequest* request,
43 const net::CompletionCallback& callback,
44 net::HttpRequestHeaders* headers) {
45 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders(
46 browser_context_, extension_info_map_.get(), request, callback, headers);
49 void ShellNetworkDelegate::OnSendHeaders(
50 net::URLRequest* request,
51 const net::HttpRequestHeaders& headers) {
52 ExtensionWebRequestEventRouter::GetInstance()->OnSendHeaders(
53 browser_context_, extension_info_map_.get(), request, headers);
56 int ShellNetworkDelegate::OnHeadersReceived(
57 net::URLRequest* request,
58 const net::CompletionCallback& callback,
59 const net::HttpResponseHeaders* original_response_headers,
60 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
61 GURL* allowed_unsafe_redirect_url) {
62 return ExtensionWebRequestEventRouter::GetInstance()->OnHeadersReceived(
63 browser_context_,
64 extension_info_map_.get(),
65 request,
66 callback,
67 original_response_headers,
68 override_response_headers,
69 allowed_unsafe_redirect_url);
72 void ShellNetworkDelegate::OnBeforeRedirect(
73 net::URLRequest* request,
74 const GURL& new_location) {
75 ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRedirect(
76 browser_context_, extension_info_map_.get(), request, new_location);
80 void ShellNetworkDelegate::OnResponseStarted(
81 net::URLRequest* request) {
82 ExtensionWebRequestEventRouter::GetInstance()->OnResponseStarted(
83 browser_context_, extension_info_map_.get(), request);
86 void ShellNetworkDelegate::OnCompleted(
87 net::URLRequest* request,
88 bool started) {
89 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
90 bool is_redirect = request->response_headers() &&
91 net::HttpResponseHeaders::IsRedirectResponseCode(
92 request->response_headers()->response_code());
93 if (!is_redirect) {
94 ExtensionWebRequestEventRouter::GetInstance()->OnCompleted(
95 browser_context_, extension_info_map_.get(), request);
97 return;
100 if (request->status().status() == net::URLRequestStatus::FAILED ||
101 request->status().status() == net::URLRequestStatus::CANCELED) {
102 ExtensionWebRequestEventRouter::GetInstance()->OnErrorOccurred(
103 browser_context_, extension_info_map_.get(), request, started);
104 return;
107 NOTREACHED();
110 void ShellNetworkDelegate::OnURLRequestDestroyed(
111 net::URLRequest* request) {
112 ExtensionWebRequestEventRouter::GetInstance()->OnURLRequestDestroyed(
113 browser_context_, request);
116 void ShellNetworkDelegate::OnPACScriptError(
117 int line_number,
118 const base::string16& error) {
121 net::NetworkDelegate::AuthRequiredResponse
122 ShellNetworkDelegate::OnAuthRequired(
123 net::URLRequest* request,
124 const net::AuthChallengeInfo& auth_info,
125 const AuthCallback& callback,
126 net::AuthCredentials* credentials) {
127 return ExtensionWebRequestEventRouter::GetInstance()->OnAuthRequired(
128 browser_context_, extension_info_map_.get(), request, auth_info, callback,
129 credentials);
132 } // namespace extensions