blob: b1c17380c436613fce44b1dd5a57bfd6a63cc191 [file] [log] [blame]
// 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 "extensions/shell/browser/shell_network_delegate.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/resource_request_info.h"
#include "extensions/browser/api/web_request/web_request_api.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/process_manager.h"
#include "net/url_request/url_request.h"
namespace extensions {
namespace {
bool g_accept_all_cookies = true;
}
ShellNetworkDelegate::ShellNetworkDelegate(
void* browser_context, InfoMap* extension_info_map) {
browser_context_ = browser_context;
extension_info_map_ = extension_info_map;
}
ShellNetworkDelegate::~ShellNetworkDelegate() {}
void ShellNetworkDelegate::SetAcceptAllCookies(bool accept) {
g_accept_all_cookies = accept;
}
int ShellNetworkDelegate::OnBeforeURLRequest(
net::URLRequest* request,
const net::CompletionCallback& callback,
GURL* new_url) {
return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest(
browser_context_, extension_info_map_.get(), request, callback, new_url);
}
int ShellNetworkDelegate::OnBeforeStartTransaction(
net::URLRequest* request,
const net::CompletionCallback& callback,
net::HttpRequestHeaders* headers) {
return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders(
browser_context_, extension_info_map_.get(), request, callback, headers);
}
void ShellNetworkDelegate::OnStartTransaction(
net::URLRequest* request,
const net::HttpRequestHeaders& headers) {
ExtensionWebRequestEventRouter::GetInstance()->OnSendHeaders(
browser_context_, extension_info_map_.get(), request, headers);
}
int ShellNetworkDelegate::OnHeadersReceived(
net::URLRequest* request,
const net::CompletionCallback& callback,
const net::HttpResponseHeaders* original_response_headers,
scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
GURL* allowed_unsafe_redirect_url) {
return ExtensionWebRequestEventRouter::GetInstance()->OnHeadersReceived(
browser_context_, extension_info_map_.get(), request, callback,
original_response_headers, override_response_headers,
allowed_unsafe_redirect_url);
}
void ShellNetworkDelegate::OnBeforeRedirect(
net::URLRequest* request,
const GURL& new_location) {
ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRedirect(
browser_context_, extension_info_map_.get(), request, new_location);
}
void ShellNetworkDelegate::OnResponseStarted(net::URLRequest* request,
int net_error) {
ExtensionWebRequestEventRouter::GetInstance()->OnResponseStarted(
browser_context_, extension_info_map_.get(), request, net_error);
}
void ShellNetworkDelegate::OnCompleted(net::URLRequest* request,
bool started,
int net_error) {
DCHECK_NE(net::ERR_IO_PENDING, net_error);
if (net_error == net::OK) {
bool is_redirect = request->response_headers() &&
net::HttpResponseHeaders::IsRedirectResponseCode(
request->response_headers()->response_code());
if (!is_redirect) {
ExtensionWebRequestEventRouter::GetInstance()->OnCompleted(
browser_context_, extension_info_map_.get(), request, net_error);
}
} else {
ExtensionWebRequestEventRouter::GetInstance()->OnErrorOccurred(
browser_context_, extension_info_map_.get(), request, started,
net_error);
}
}
void ShellNetworkDelegate::OnURLRequestDestroyed(
net::URLRequest* request) {
ExtensionWebRequestEventRouter::GetInstance()->OnURLRequestDestroyed(
browser_context_, request);
}
void ShellNetworkDelegate::OnPACScriptError(
int line_number,
const base::string16& error) {
}
net::NetworkDelegate::AuthRequiredResponse
ShellNetworkDelegate::OnAuthRequired(
net::URLRequest* request,
const net::AuthChallengeInfo& auth_info,
const AuthCallback& callback,
net::AuthCredentials* credentials) {
return ExtensionWebRequestEventRouter::GetInstance()->OnAuthRequired(
browser_context_, extension_info_map_.get(), request, auth_info, callback,
credentials);
}
} // namespace extensions