2020-02-11 05:56:09 +00:00
|
|
|
// Copyright (c) 2020 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_NET_WEB_REQUEST_API_INTERFACE_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_NET_WEB_REQUEST_API_INTERFACE_H_
|
2020-02-11 05:56:09 +00:00
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "extensions/browser/api/web_request/web_request_info.h"
|
2020-07-22 05:34:34 +00:00
|
|
|
#include "net/base/completion_once_callback.h"
|
2020-02-11 05:56:09 +00:00
|
|
|
#include "services/network/public/cpp/resource_request.h"
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
// Defines the interface for WebRequest API, implemented by api::WebRequestNS.
|
|
|
|
class WebRequestAPI {
|
|
|
|
public:
|
|
|
|
virtual ~WebRequestAPI() {}
|
|
|
|
|
|
|
|
using BeforeSendHeadersCallback =
|
|
|
|
base::OnceCallback<void(const std::set<std::string>& removed_headers,
|
|
|
|
const std::set<std::string>& set_headers,
|
|
|
|
int error_code)>;
|
|
|
|
|
|
|
|
virtual bool HasListener() const = 0;
|
|
|
|
virtual int OnBeforeRequest(extensions::WebRequestInfo* info,
|
|
|
|
const network::ResourceRequest& request,
|
|
|
|
net::CompletionOnceCallback callback,
|
|
|
|
GURL* new_url) = 0;
|
|
|
|
virtual int OnBeforeSendHeaders(extensions::WebRequestInfo* info,
|
|
|
|
const network::ResourceRequest& request,
|
|
|
|
BeforeSendHeadersCallback callback,
|
|
|
|
net::HttpRequestHeaders* headers) = 0;
|
|
|
|
virtual int OnHeadersReceived(
|
|
|
|
extensions::WebRequestInfo* info,
|
|
|
|
const network::ResourceRequest& request,
|
|
|
|
net::CompletionOnceCallback callback,
|
|
|
|
const net::HttpResponseHeaders* original_response_headers,
|
|
|
|
scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
|
|
|
|
GURL* allowed_unsafe_redirect_url) = 0;
|
|
|
|
virtual void OnSendHeaders(extensions::WebRequestInfo* info,
|
|
|
|
const network::ResourceRequest& request,
|
|
|
|
const net::HttpRequestHeaders& headers) = 0;
|
|
|
|
virtual void OnBeforeRedirect(extensions::WebRequestInfo* info,
|
|
|
|
const network::ResourceRequest& request,
|
|
|
|
const GURL& new_location) = 0;
|
|
|
|
virtual void OnResponseStarted(extensions::WebRequestInfo* info,
|
|
|
|
const network::ResourceRequest& request) = 0;
|
|
|
|
virtual void OnErrorOccurred(extensions::WebRequestInfo* info,
|
|
|
|
const network::ResourceRequest& request,
|
|
|
|
int net_error) = 0;
|
|
|
|
virtual void OnCompleted(extensions::WebRequestInfo* info,
|
|
|
|
const network::ResourceRequest& request,
|
|
|
|
int net_error) = 0;
|
|
|
|
virtual void OnRequestWillBeDestroyed(extensions::WebRequestInfo* info) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_NET_WEB_REQUEST_API_INTERFACE_H_
|