fix: add method and referrer properties to app login event (backport: 3-0-x) (#14277)
* refactor: remove brightray/network_delegate.{cc|h} * refactor: respond to http requests through network delegate
This commit is contained in:
parent
ba703deee2
commit
635c3f53d8
17 changed files with 258 additions and 404 deletions
|
@ -667,17 +667,17 @@ void App::OnNewWindowForTab() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void App::OnLogin(LoginHandler* login_handler,
|
void App::OnLogin(scoped_refptr<LoginHandler> login_handler,
|
||||||
const base::DictionaryValue& request_details) {
|
const base::DictionaryValue& request_details) {
|
||||||
v8::Locker locker(isolate());
|
v8::Locker locker(isolate());
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
bool prevent_default = false;
|
bool prevent_default = false;
|
||||||
content::WebContents* web_contents = login_handler->GetWebContents();
|
content::WebContents* web_contents = login_handler->GetWebContents();
|
||||||
if (web_contents) {
|
if (web_contents) {
|
||||||
prevent_default =
|
prevent_default = Emit(
|
||||||
Emit("login", WebContents::CreateFrom(isolate(), web_contents),
|
"login", WebContents::CreateFrom(isolate(), web_contents),
|
||||||
request_details, login_handler->auth_info(),
|
request_details, login_handler->auth_info(),
|
||||||
base::Bind(&PassLoginInformation, WrapRefCounted(login_handler)));
|
base::Bind(&PassLoginInformation, base::RetainedRef(login_handler)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default behavior is to always cancel the auth.
|
// Default behavior is to always cancel the auth.
|
||||||
|
|
|
@ -98,7 +98,7 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
void OnActivate(bool has_visible_windows) override;
|
void OnActivate(bool has_visible_windows) override;
|
||||||
void OnWillFinishLaunching() override;
|
void OnWillFinishLaunching() override;
|
||||||
void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
|
void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
|
||||||
void OnLogin(LoginHandler* login_handler,
|
void OnLogin(scoped_refptr<LoginHandler> login_handler,
|
||||||
const base::DictionaryValue& request_details) override;
|
const base::DictionaryValue& request_details) override;
|
||||||
void OnAccessibilitySupportChanged() override;
|
void OnAccessibilitySupportChanged() override;
|
||||||
void OnPreMainMessageLoopRun() override;
|
void OnPreMainMessageLoopRun() override;
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
|
#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
|
||||||
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
|
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
|
||||||
#include "atom/browser/child_web_contents_tracker.h"
|
#include "atom/browser/child_web_contents_tracker.h"
|
||||||
#include "atom/browser/login_handler.h"
|
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
#include "atom/browser/session_preferences.h"
|
#include "atom/browser/session_preferences.h"
|
||||||
#include "atom/browser/web_contents_permission_helper.h"
|
#include "atom/browser/web_contents_permission_helper.h"
|
||||||
|
@ -495,19 +494,6 @@ std::unique_ptr<net::ClientCertStore> AtomBrowserClient::CreateClientCertStore(
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
content::ResourceDispatcherHostLoginDelegate*
|
|
||||||
AtomBrowserClient::CreateLoginDelegate(
|
|
||||||
net::AuthChallengeInfo* auth_info,
|
|
||||||
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
|
|
||||||
bool is_main_frame,
|
|
||||||
const GURL& url,
|
|
||||||
bool first_auth_attempt,
|
|
||||||
const base::Callback<void(const base::Optional<net::AuthCredentials>&)>&
|
|
||||||
auth_required_callback) {
|
|
||||||
return new LoginHandler(auth_info, web_contents_getter, url,
|
|
||||||
auth_required_callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
|
brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
|
||||||
const content::MainFunctionParams&) {
|
const content::MainFunctionParams&) {
|
||||||
v8::V8::Initialize(); // Init V8 before creating main parts.
|
v8::V8::Initialize(); // Init V8 before creating main parts.
|
||||||
|
|
|
@ -106,14 +106,6 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
||||||
void SiteInstanceDeleting(content::SiteInstance* site_instance) override;
|
void SiteInstanceDeleting(content::SiteInstance* site_instance) override;
|
||||||
std::unique_ptr<net::ClientCertStore> CreateClientCertStore(
|
std::unique_ptr<net::ClientCertStore> CreateClientCertStore(
|
||||||
content::ResourceContext* resource_context) override;
|
content::ResourceContext* resource_context) override;
|
||||||
content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
|
|
||||||
net::AuthChallengeInfo* auth_info,
|
|
||||||
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
|
|
||||||
bool is_main_frame,
|
|
||||||
const GURL& url,
|
|
||||||
bool first_auth_attempt,
|
|
||||||
const base::Callback<void(const base::Optional<net::AuthCredentials>&)>&
|
|
||||||
auth_required_callback) override;
|
|
||||||
|
|
||||||
// brightray::BrowserClient:
|
// brightray::BrowserClient:
|
||||||
brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "atom/browser/atom_browser_main_parts.h"
|
#include "atom/browser/atom_browser_main_parts.h"
|
||||||
#include "atom/browser/browser_observer.h"
|
#include "atom/browser/browser_observer.h"
|
||||||
|
#include "atom/browser/login_handler.h"
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
#include "atom/browser/window_list.h"
|
#include "atom/browser/window_list.h"
|
||||||
#include "base/files/file_util.h"
|
#include "base/files/file_util.h"
|
||||||
|
@ -164,7 +165,7 @@ void Browser::OnAccessibilitySupportChanged() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::RequestLogin(
|
void Browser::RequestLogin(
|
||||||
LoginHandler* login_handler,
|
scoped_refptr<LoginHandler> login_handler,
|
||||||
std::unique_ptr<base::DictionaryValue> request_details) {
|
std::unique_ptr<base::DictionaryValue> request_details) {
|
||||||
for (BrowserObserver& observer : observers_)
|
for (BrowserObserver& observer : observers_)
|
||||||
observer.OnLogin(login_handler, *(request_details.get()));
|
observer.OnLogin(login_handler, *(request_details.get()));
|
||||||
|
|
|
@ -33,7 +33,6 @@ class Image;
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class AtomMenuModel;
|
class AtomMenuModel;
|
||||||
class LoginHandler;
|
|
||||||
|
|
||||||
// This class is used for control application-wide operations.
|
// This class is used for control application-wide operations.
|
||||||
class Browser : public WindowListObserver {
|
class Browser : public WindowListObserver {
|
||||||
|
@ -229,7 +228,7 @@ class Browser : public WindowListObserver {
|
||||||
void OnAccessibilitySupportChanged();
|
void OnAccessibilitySupportChanged();
|
||||||
|
|
||||||
// Request basic auth login.
|
// Request basic auth login.
|
||||||
void RequestLogin(LoginHandler* login_handler,
|
void RequestLogin(scoped_refptr<LoginHandler> login_handler,
|
||||||
std::unique_ptr<base::DictionaryValue> request_details);
|
std::unique_ptr<base::DictionaryValue> request_details);
|
||||||
|
|
||||||
void PreMainMessageLoopRun();
|
void PreMainMessageLoopRun();
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "atom/browser/login_handler.h"
|
||||||
|
#include "base/memory/scoped_refptr.h"
|
||||||
#include "build/build_config.h"
|
#include "build/build_config.h"
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
|
@ -15,8 +17,6 @@ class DictionaryValue;
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class LoginHandler;
|
|
||||||
|
|
||||||
class BrowserObserver {
|
class BrowserObserver {
|
||||||
public:
|
public:
|
||||||
// The browser is about to close all windows.
|
// The browser is about to close all windows.
|
||||||
|
@ -49,7 +49,7 @@ class BrowserObserver {
|
||||||
virtual void OnFinishLaunching(const base::DictionaryValue& launch_info) {}
|
virtual void OnFinishLaunching(const base::DictionaryValue& launch_info) {}
|
||||||
|
|
||||||
// The browser requests HTTP login.
|
// The browser requests HTTP login.
|
||||||
virtual void OnLogin(LoginHandler* login_handler,
|
virtual void OnLogin(scoped_refptr<LoginHandler> login_handler,
|
||||||
const base::DictionaryValue& request_details) {}
|
const base::DictionaryValue& request_details) {}
|
||||||
|
|
||||||
// The browser's accessibility suppport has changed.
|
// The browser's accessibility suppport has changed.
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "atom/browser/login_handler.h"
|
#include "atom/browser/login_handler.h"
|
||||||
|
|
||||||
#include "atom/browser/browser.h"
|
#include "atom/browser/browser.h"
|
||||||
|
#include "atom/common/native_mate_converters/net_converter.h"
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
|
@ -15,78 +16,75 @@ using content::BrowserThread;
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
LoginHandler::LoginHandler(
|
LoginHandler::LoginHandler(
|
||||||
net::AuthChallengeInfo* auth_info,
|
net::URLRequest* request,
|
||||||
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
|
const net::AuthChallengeInfo& auth_info,
|
||||||
const GURL& url,
|
const net::NetworkDelegate::AuthCallback& callback,
|
||||||
const base::Callback<void(const base::Optional<net::AuthCredentials>&)>&
|
net::AuthCredentials* credentials,
|
||||||
auth_required_callback)
|
const content::ResourceRequestInfo* resource_request_info)
|
||||||
: auth_info_(auth_info),
|
: credentials_(credentials),
|
||||||
web_contents_getter_(web_contents_getter),
|
auth_info_(auth_info),
|
||||||
auth_required_callback_(auth_required_callback) {
|
auth_callback_(std::move(callback)),
|
||||||
// Fill request details on IO thread.
|
weak_factory_(this) {
|
||||||
// TODO(deepak1556): Fill in method and referrer details to
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||||
// avoid breaking the app login event.
|
|
||||||
std::unique_ptr<base::DictionaryValue> request_details(
|
std::unique_ptr<base::DictionaryValue> request_details(
|
||||||
new base::DictionaryValue);
|
new base::DictionaryValue);
|
||||||
request_details->SetKey("url", base::Value(url.spec()));
|
FillRequestDetails(request_details.get(), request);
|
||||||
|
|
||||||
|
web_contents_getter_ =
|
||||||
|
resource_request_info->GetWebContentsGetterForRequest();
|
||||||
|
|
||||||
BrowserThread::PostTask(
|
BrowserThread::PostTask(
|
||||||
BrowserThread::UI, FROM_HERE,
|
BrowserThread::UI, FROM_HERE,
|
||||||
base::BindOnce(&Browser::RequestLogin, base::Unretained(Browser::Get()),
|
base::BindOnce(&Browser::RequestLogin, base::Unretained(Browser::Get()),
|
||||||
base::RetainedRef(WrapRefCounted(this)),
|
base::RetainedRef(this), std::move(request_details)));
|
||||||
std::move(request_details)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginHandler::~LoginHandler() {}
|
LoginHandler::~LoginHandler() {}
|
||||||
|
|
||||||
|
void LoginHandler::Login(const base::string16& username,
|
||||||
|
const base::string16& password) {
|
||||||
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
|
||||||
|
BrowserThread::PostTask(
|
||||||
|
BrowserThread::IO, FROM_HERE,
|
||||||
|
base::BindOnce(&LoginHandler::DoLogin, weak_factory_.GetWeakPtr(),
|
||||||
|
username, password));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginHandler::CancelAuth() {
|
||||||
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
|
||||||
|
BrowserThread::PostTask(
|
||||||
|
BrowserThread::IO, FROM_HERE,
|
||||||
|
base::BindOnce(&LoginHandler::DoCancelAuth, weak_factory_.GetWeakPtr()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginHandler::NotifyRequestDestroyed() {
|
||||||
|
auth_callback_.Reset();
|
||||||
|
credentials_ = nullptr;
|
||||||
|
weak_factory_.InvalidateWeakPtrs();
|
||||||
|
}
|
||||||
|
|
||||||
content::WebContents* LoginHandler::GetWebContents() const {
|
content::WebContents* LoginHandler::GetWebContents() const {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
return web_contents_getter_.Run();
|
return web_contents_getter_.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginHandler::Login(const base::string16& username,
|
|
||||||
const base::string16& password) {
|
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
||||||
if (TestAndSetAuthHandled())
|
|
||||||
return;
|
|
||||||
BrowserThread::PostTask(
|
|
||||||
BrowserThread::IO, FROM_HERE,
|
|
||||||
base::BindOnce(&LoginHandler::DoLogin, this, username, password));
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoginHandler::CancelAuth() {
|
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
||||||
if (TestAndSetAuthHandled())
|
|
||||||
return;
|
|
||||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
|
||||||
base::BindOnce(&LoginHandler::DoCancelAuth, this));
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoginHandler::OnRequestCancelled() {
|
|
||||||
TestAndSetAuthHandled();
|
|
||||||
auth_required_callback_.Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Marks authentication as handled and returns the previous handled state.
|
|
||||||
bool LoginHandler::TestAndSetAuthHandled() {
|
|
||||||
base::AutoLock lock(handled_auth_lock_);
|
|
||||||
bool was_handled = handled_auth_;
|
|
||||||
handled_auth_ = true;
|
|
||||||
return was_handled;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoginHandler::DoCancelAuth() {
|
void LoginHandler::DoCancelAuth() {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||||
if (!auth_required_callback_.is_null())
|
if (!auth_callback_.is_null())
|
||||||
std::move(auth_required_callback_).Run(base::nullopt);
|
std::move(auth_callback_)
|
||||||
|
.Run(net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginHandler::DoLogin(const base::string16& username,
|
void LoginHandler::DoLogin(const base::string16& username,
|
||||||
const base::string16& password) {
|
const base::string16& password) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||||
if (!auth_required_callback_.is_null()) {
|
if (!auth_callback_.is_null()) {
|
||||||
std::move(auth_required_callback_)
|
credentials_->Set(username, password);
|
||||||
.Run(net::AuthCredentials(username, password));
|
std::move(auth_callback_)
|
||||||
|
.Run(net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,72 +6,65 @@
|
||||||
#define ATOM_BROWSER_LOGIN_HANDLER_H_
|
#define ATOM_BROWSER_LOGIN_HANDLER_H_
|
||||||
|
|
||||||
#include "base/callback.h"
|
#include "base/callback.h"
|
||||||
#include "base/optional.h"
|
#include "base/memory/ref_counted.h"
|
||||||
|
#include "base/memory/weak_ptr.h"
|
||||||
#include "base/strings/string16.h"
|
#include "base/strings/string16.h"
|
||||||
#include "base/synchronization/lock.h"
|
|
||||||
#include "content/public/browser/resource_dispatcher_host_login_delegate.h"
|
|
||||||
#include "content/public/browser/resource_request_info.h"
|
#include "content/public/browser/resource_request_info.h"
|
||||||
|
#include "net/base/network_delegate.h"
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
class WebContents;
|
class WebContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace net {
|
|
||||||
class AuthChallengeInfo;
|
|
||||||
class AuthCredentials;
|
|
||||||
} // namespace net
|
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
// Handles the HTTP basic auth, must be created on IO thread.
|
// Handles the HTTP basic auth, must be created on IO thread.
|
||||||
class LoginHandler : public content::ResourceDispatcherHostLoginDelegate {
|
class LoginHandler : public base::RefCountedThreadSafe<LoginHandler> {
|
||||||
public:
|
public:
|
||||||
LoginHandler(
|
LoginHandler(net::URLRequest* request,
|
||||||
net::AuthChallengeInfo* auth_info,
|
const net::AuthChallengeInfo& auth_info,
|
||||||
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
|
const net::NetworkDelegate::AuthCallback& callback,
|
||||||
const GURL& url,
|
net::AuthCredentials* credentials,
|
||||||
const base::Callback<void(const base::Optional<net::AuthCredentials>&)>&
|
const content::ResourceRequestInfo* resource_request_info);
|
||||||
auth_required_callback);
|
|
||||||
|
// The auth is cancelled, must be called on UI thread.
|
||||||
|
void CancelAuth();
|
||||||
|
|
||||||
|
// The URLRequest associated with the auth is destroyed.
|
||||||
|
void NotifyRequestDestroyed();
|
||||||
|
|
||||||
|
// Login with |username| and |password|, must be called on UI thread.
|
||||||
|
void Login(const base::string16& username, const base::string16& password);
|
||||||
|
|
||||||
// Returns the WebContents associated with the request, must be called on UI
|
// Returns the WebContents associated with the request, must be called on UI
|
||||||
// thread.
|
// thread.
|
||||||
content::WebContents* GetWebContents() const;
|
content::WebContents* GetWebContents() const;
|
||||||
|
|
||||||
// The auth is cancelled, must be called on UI thread.
|
const net::AuthChallengeInfo* auth_info() const { return &auth_info_; }
|
||||||
void CancelAuth();
|
|
||||||
|
|
||||||
// Login with |username| and |password|, must be called on UI thread.
|
|
||||||
void Login(const base::string16& username, const base::string16& password);
|
|
||||||
|
|
||||||
const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
~LoginHandler() override;
|
|
||||||
|
|
||||||
// content::ResourceDispatcherHostLoginDelegate:
|
|
||||||
void OnRequestCancelled() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class base::RefCountedThreadSafe<LoginHandler>;
|
||||||
|
friend class base::DeleteHelper<LoginHandler>;
|
||||||
|
|
||||||
|
~LoginHandler();
|
||||||
|
|
||||||
// Must be called on IO thread.
|
// Must be called on IO thread.
|
||||||
void DoCancelAuth();
|
void DoCancelAuth();
|
||||||
void DoLogin(const base::string16& username, const base::string16& password);
|
void DoLogin(const base::string16& username, const base::string16& password);
|
||||||
|
|
||||||
// Marks authentication as handled and returns the previous handled
|
// Credentials to be used for the auth.
|
||||||
// state.
|
net::AuthCredentials* credentials_;
|
||||||
bool TestAndSetAuthHandled();
|
|
||||||
|
|
||||||
// True if we've handled auth (Login or CancelAuth has been called).
|
|
||||||
bool handled_auth_ = false;
|
|
||||||
mutable base::Lock handled_auth_lock_;
|
|
||||||
|
|
||||||
// Who/where/what asked for the authentication.
|
// Who/where/what asked for the authentication.
|
||||||
scoped_refptr<net::AuthChallengeInfo> auth_info_;
|
const net::AuthChallengeInfo& auth_info_;
|
||||||
|
|
||||||
// WebContents associated with the login request.
|
// WebContents associated with the login request.
|
||||||
content::ResourceRequestInfo::WebContentsGetter web_contents_getter_;
|
content::ResourceRequestInfo::WebContentsGetter web_contents_getter_;
|
||||||
|
|
||||||
base::Callback<void(const base::Optional<net::AuthCredentials>&)>
|
// Called with preferred value of net::NetworkDelegate::AuthRequiredResponse.
|
||||||
auth_required_callback_;
|
net::NetworkDelegate::AuthCallback auth_callback_;
|
||||||
|
|
||||||
|
base::WeakPtrFactory<LoginHandler> weak_factory_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(LoginHandler);
|
DISALLOW_COPY_AND_ASSIGN(LoginHandler);
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,11 +7,17 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "atom/browser/api/atom_api_web_contents.h"
|
#include "atom/browser/api/atom_api_web_contents.h"
|
||||||
|
#include "atom/browser/login_handler.h"
|
||||||
#include "atom/common/native_mate_converters/net_converter.h"
|
#include "atom/common/native_mate_converters/net_converter.h"
|
||||||
|
#include "atom/common/options_switches.h"
|
||||||
|
#include "base/command_line.h"
|
||||||
#include "base/stl_util.h"
|
#include "base/stl_util.h"
|
||||||
#include "base/strings/string_util.h"
|
#include "base/strings/string_util.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/browser/render_frame_host.h"
|
#include "content/public/browser/render_frame_host.h"
|
||||||
|
#include "content/public/browser/resource_request_info.h"
|
||||||
|
#include "net/base/load_flags.h"
|
||||||
|
#include "net/base/net_errors.h"
|
||||||
#include "net/url_request/url_request.h"
|
#include "net/url_request/url_request.h"
|
||||||
#include "services/network/throttling/throttling_network_transaction.h"
|
#include "services/network/throttling/throttling_network_transaction.h"
|
||||||
|
|
||||||
|
@ -231,7 +237,15 @@ AtomNetworkDelegate::ResponseListenerInfo::ResponseListenerInfo(
|
||||||
AtomNetworkDelegate::ResponseListenerInfo::ResponseListenerInfo() = default;
|
AtomNetworkDelegate::ResponseListenerInfo::ResponseListenerInfo() = default;
|
||||||
AtomNetworkDelegate::ResponseListenerInfo::~ResponseListenerInfo() = default;
|
AtomNetworkDelegate::ResponseListenerInfo::~ResponseListenerInfo() = default;
|
||||||
|
|
||||||
AtomNetworkDelegate::AtomNetworkDelegate() {}
|
AtomNetworkDelegate::AtomNetworkDelegate() {
|
||||||
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||||
|
if (command_line->HasSwitch(switches::kIgnoreConnectionsLimit)) {
|
||||||
|
std::string value =
|
||||||
|
command_line->GetSwitchValueASCII(switches::kIgnoreConnectionsLimit);
|
||||||
|
ignore_connections_limit_domains_ = base::SplitString(
|
||||||
|
value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AtomNetworkDelegate::~AtomNetworkDelegate() {}
|
AtomNetworkDelegate::~AtomNetworkDelegate() {}
|
||||||
|
|
||||||
|
@ -262,9 +276,17 @@ int AtomNetworkDelegate::OnBeforeURLRequest(
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
const net::CompletionCallback& callback,
|
const net::CompletionCallback& callback,
|
||||||
GURL* new_url) {
|
GURL* new_url) {
|
||||||
if (!base::ContainsKey(response_listeners_, kOnBeforeRequest))
|
if (!base::ContainsKey(response_listeners_, kOnBeforeRequest)) {
|
||||||
return brightray::NetworkDelegate::OnBeforeURLRequest(request, callback,
|
for (const auto& domain : ignore_connections_limit_domains_) {
|
||||||
new_url);
|
if (request->url().DomainIs(domain)) {
|
||||||
|
// Allow unlimited concurrent connections.
|
||||||
|
request->SetPriority(net::MAXIMUM_PRIORITY);
|
||||||
|
request->SetLoadFlags(request->load_flags() | net::LOAD_IGNORE_LIMITS);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return net::OK;
|
||||||
|
}
|
||||||
|
|
||||||
return HandleResponseEvent(kOnBeforeRequest, request, callback, new_url);
|
return HandleResponseEvent(kOnBeforeRequest, request, callback, new_url);
|
||||||
}
|
}
|
||||||
|
@ -278,8 +300,7 @@ int AtomNetworkDelegate::OnBeforeStartTransaction(
|
||||||
kDevToolsEmulateNetworkConditionsClientId,
|
kDevToolsEmulateNetworkConditionsClientId,
|
||||||
client_id_);
|
client_id_);
|
||||||
if (!base::ContainsKey(response_listeners_, kOnBeforeSendHeaders))
|
if (!base::ContainsKey(response_listeners_, kOnBeforeSendHeaders))
|
||||||
return brightray::NetworkDelegate::OnBeforeStartTransaction(
|
return net::OK;
|
||||||
request, callback, headers);
|
|
||||||
|
|
||||||
return HandleResponseEvent(kOnBeforeSendHeaders, request, callback, headers,
|
return HandleResponseEvent(kOnBeforeSendHeaders, request, callback, headers,
|
||||||
*headers);
|
*headers);
|
||||||
|
@ -288,10 +309,8 @@ int AtomNetworkDelegate::OnBeforeStartTransaction(
|
||||||
void AtomNetworkDelegate::OnStartTransaction(
|
void AtomNetworkDelegate::OnStartTransaction(
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
const net::HttpRequestHeaders& headers) {
|
const net::HttpRequestHeaders& headers) {
|
||||||
if (!base::ContainsKey(simple_listeners_, kOnSendHeaders)) {
|
if (!base::ContainsKey(simple_listeners_, kOnSendHeaders))
|
||||||
brightray::NetworkDelegate::OnStartTransaction(request, headers);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
HandleSimpleEvent(kOnSendHeaders, request, headers);
|
HandleSimpleEvent(kOnSendHeaders, request, headers);
|
||||||
}
|
}
|
||||||
|
@ -303,8 +322,7 @@ int AtomNetworkDelegate::OnHeadersReceived(
|
||||||
scoped_refptr<net::HttpResponseHeaders>* override,
|
scoped_refptr<net::HttpResponseHeaders>* override,
|
||||||
GURL* allowed) {
|
GURL* allowed) {
|
||||||
if (!base::ContainsKey(response_listeners_, kOnHeadersReceived))
|
if (!base::ContainsKey(response_listeners_, kOnHeadersReceived))
|
||||||
return brightray::NetworkDelegate::OnHeadersReceived(
|
return net::OK;
|
||||||
request, callback, original, override, allowed);
|
|
||||||
|
|
||||||
return HandleResponseEvent(
|
return HandleResponseEvent(
|
||||||
kOnHeadersReceived, request, callback,
|
kOnHeadersReceived, request, callback,
|
||||||
|
@ -313,10 +331,8 @@ int AtomNetworkDelegate::OnHeadersReceived(
|
||||||
|
|
||||||
void AtomNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
|
void AtomNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
|
||||||
const GURL& new_location) {
|
const GURL& new_location) {
|
||||||
if (!base::ContainsKey(simple_listeners_, kOnBeforeRedirect)) {
|
if (!base::ContainsKey(simple_listeners_, kOnBeforeRedirect))
|
||||||
brightray::NetworkDelegate::OnBeforeRedirect(request, new_location);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
HandleSimpleEvent(kOnBeforeRedirect, request, new_location,
|
HandleSimpleEvent(kOnBeforeRedirect, request, new_location,
|
||||||
request->response_headers(), request->GetSocketAddress(),
|
request->response_headers(), request->GetSocketAddress(),
|
||||||
|
@ -325,10 +341,8 @@ void AtomNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
|
||||||
|
|
||||||
void AtomNetworkDelegate::OnResponseStarted(net::URLRequest* request,
|
void AtomNetworkDelegate::OnResponseStarted(net::URLRequest* request,
|
||||||
int net_error) {
|
int net_error) {
|
||||||
if (!base::ContainsKey(simple_listeners_, kOnResponseStarted)) {
|
if (!base::ContainsKey(simple_listeners_, kOnResponseStarted))
|
||||||
brightray::NetworkDelegate::OnResponseStarted(request, net_error);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (request->status().status() != net::URLRequestStatus::SUCCESS)
|
if (request->status().status() != net::URLRequestStatus::SUCCESS)
|
||||||
return;
|
return;
|
||||||
|
@ -346,33 +360,109 @@ void AtomNetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {
|
||||||
// Error event.
|
// Error event.
|
||||||
OnErrorOccurred(request, started);
|
OnErrorOccurred(request, started);
|
||||||
return;
|
return;
|
||||||
} else if (request->response_headers() &&
|
}
|
||||||
|
|
||||||
|
if (request->response_headers() &&
|
||||||
net::HttpResponseHeaders::IsRedirectResponseCode(
|
net::HttpResponseHeaders::IsRedirectResponseCode(
|
||||||
request->response_headers()->response_code())) {
|
request->response_headers()->response_code())) {
|
||||||
// Redirect event.
|
// Redirect event.
|
||||||
brightray::NetworkDelegate::OnCompleted(request, started);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!base::ContainsKey(simple_listeners_, kOnCompleted)) {
|
if (!base::ContainsKey(simple_listeners_, kOnCompleted))
|
||||||
brightray::NetworkDelegate::OnCompleted(request, started);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
HandleSimpleEvent(kOnCompleted, request, request->response_headers(),
|
HandleSimpleEvent(kOnCompleted, request, request->response_headers(),
|
||||||
request->was_cached());
|
request->was_cached());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
|
void AtomNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
|
||||||
|
const auto& it = login_handler_map_.find(request->identifier());
|
||||||
|
if (it != login_handler_map_.end()) {
|
||||||
|
it->second->NotifyRequestDestroyed();
|
||||||
|
it->second = nullptr;
|
||||||
|
login_handler_map_.erase(it);
|
||||||
|
}
|
||||||
callbacks_.erase(request->identifier());
|
callbacks_.erase(request->identifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
net::NetworkDelegate::AuthRequiredResponse AtomNetworkDelegate::OnAuthRequired(
|
||||||
|
net::URLRequest* request,
|
||||||
|
const net::AuthChallengeInfo& auth_info,
|
||||||
|
const AuthCallback& callback,
|
||||||
|
net::AuthCredentials* credentials) {
|
||||||
|
auto* resource_request_info =
|
||||||
|
content::ResourceRequestInfo::ForRequest(request);
|
||||||
|
if (!resource_request_info)
|
||||||
|
return AUTH_REQUIRED_RESPONSE_NO_ACTION;
|
||||||
|
login_handler_map_.emplace(
|
||||||
|
request->identifier(),
|
||||||
|
new LoginHandler(request, auth_info, std::move(callback), credentials,
|
||||||
|
resource_request_info));
|
||||||
|
return AUTH_REQUIRED_RESPONSE_IO_PENDING;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AtomNetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
|
||||||
|
const net::CookieList& cookie_list) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AtomNetworkDelegate::OnCanSetCookie(
|
||||||
|
const net::URLRequest& request,
|
||||||
|
const net::CanonicalCookie& cookie_line,
|
||||||
|
net::CookieOptions* options) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AtomNetworkDelegate::OnCanAccessFile(
|
||||||
|
const net::URLRequest& request,
|
||||||
|
const base::FilePath& original_path,
|
||||||
|
const base::FilePath& absolute_path) const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AtomNetworkDelegate::OnCanEnablePrivacyMode(
|
||||||
|
const GURL& url,
|
||||||
|
const GURL& first_party_for_cookies) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AtomNetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AtomNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
|
||||||
|
const net::URLRequest& request,
|
||||||
|
const GURL& target_url,
|
||||||
|
const GURL& referrer_url) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(deepak1556) : Enable after hooking into the reporting service
|
||||||
|
// https://crbug.com/704259
|
||||||
|
bool AtomNetworkDelegate::OnCanQueueReportingReport(
|
||||||
|
const url::Origin& origin) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AtomNetworkDelegate::OnCanSendReportingReports(
|
||||||
|
std::set<url::Origin> origins,
|
||||||
|
base::OnceCallback<void(std::set<url::Origin>)> result_callback) const {}
|
||||||
|
|
||||||
|
bool AtomNetworkDelegate::OnCanSetReportingClient(const url::Origin& origin,
|
||||||
|
const GURL& endpoint) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AtomNetworkDelegate::OnCanUseReportingClient(const url::Origin& origin,
|
||||||
|
const GURL& endpoint) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void AtomNetworkDelegate::OnErrorOccurred(net::URLRequest* request,
|
void AtomNetworkDelegate::OnErrorOccurred(net::URLRequest* request,
|
||||||
bool started) {
|
bool started) {
|
||||||
if (!base::ContainsKey(simple_listeners_, kOnErrorOccurred)) {
|
if (!base::ContainsKey(simple_listeners_, kOnErrorOccurred))
|
||||||
brightray::NetworkDelegate::OnCompleted(request, started);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
HandleSimpleEvent(kOnErrorOccurred, request, request->was_cached(),
|
HandleSimpleEvent(kOnErrorOccurred, request, request->was_cached(),
|
||||||
request->status());
|
request->status());
|
||||||
|
|
|
@ -8,14 +8,14 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "base/callback.h"
|
#include "base/callback.h"
|
||||||
#include "base/synchronization/lock.h"
|
#include "base/synchronization/lock.h"
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "brightray/browser/network_delegate.h"
|
|
||||||
#include "content/public/browser/resource_request_info.h"
|
#include "content/public/browser/resource_request_info.h"
|
||||||
#include "extensions/common/url_pattern.h"
|
#include "extensions/common/url_pattern.h"
|
||||||
#include "net/base/net_errors.h"
|
#include "net/base/network_delegate.h"
|
||||||
#include "net/http/http_request_headers.h"
|
#include "net/http/http_request_headers.h"
|
||||||
#include "net/http/http_response_headers.h"
|
#include "net/http/http_response_headers.h"
|
||||||
|
|
||||||
|
@ -27,7 +27,9 @@ using URLPatterns = std::set<URLPattern>;
|
||||||
|
|
||||||
const char* ResourceTypeToString(content::ResourceType type);
|
const char* ResourceTypeToString(content::ResourceType type);
|
||||||
|
|
||||||
class AtomNetworkDelegate : public brightray::NetworkDelegate {
|
class LoginHandler;
|
||||||
|
|
||||||
|
class AtomNetworkDelegate : public net::NetworkDelegate {
|
||||||
public:
|
public:
|
||||||
using ResponseCallback = base::Callback<void(const base::DictionaryValue&)>;
|
using ResponseCallback = base::Callback<void(const base::DictionaryValue&)>;
|
||||||
using SimpleListener = base::Callback<void(const base::DictionaryValue&)>;
|
using SimpleListener = base::Callback<void(const base::DictionaryValue&)>;
|
||||||
|
@ -86,6 +88,10 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
|
||||||
int OnBeforeStartTransaction(net::URLRequest* request,
|
int OnBeforeStartTransaction(net::URLRequest* request,
|
||||||
const net::CompletionCallback& callback,
|
const net::CompletionCallback& callback,
|
||||||
net::HttpRequestHeaders* headers) override;
|
net::HttpRequestHeaders* headers) override;
|
||||||
|
void OnBeforeSendHeaders(net::URLRequest* request,
|
||||||
|
const net::ProxyInfo& proxy_info,
|
||||||
|
const net::ProxyRetryInfoMap& proxy_retry_info,
|
||||||
|
net::HttpRequestHeaders* headers) override {}
|
||||||
void OnStartTransaction(net::URLRequest* request,
|
void OnStartTransaction(net::URLRequest* request,
|
||||||
const net::HttpRequestHeaders& headers) override;
|
const net::HttpRequestHeaders& headers) override;
|
||||||
int OnHeadersReceived(
|
int OnHeadersReceived(
|
||||||
|
@ -97,8 +103,43 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
|
||||||
void OnBeforeRedirect(net::URLRequest* request,
|
void OnBeforeRedirect(net::URLRequest* request,
|
||||||
const GURL& new_location) override;
|
const GURL& new_location) override;
|
||||||
void OnResponseStarted(net::URLRequest* request, int net_error) override;
|
void OnResponseStarted(net::URLRequest* request, int net_error) override;
|
||||||
|
void OnNetworkBytesReceived(net::URLRequest* request,
|
||||||
|
int64_t bytes_read) override {}
|
||||||
|
void OnNetworkBytesSent(net::URLRequest* request,
|
||||||
|
int64_t bytes_sent) override {}
|
||||||
void OnCompleted(net::URLRequest* request, bool started) override;
|
void OnCompleted(net::URLRequest* request, bool started) override;
|
||||||
void OnURLRequestDestroyed(net::URLRequest* request) override;
|
void OnURLRequestDestroyed(net::URLRequest* request) override;
|
||||||
|
void OnPACScriptError(int line_number, const base::string16& error) override {
|
||||||
|
}
|
||||||
|
AuthRequiredResponse OnAuthRequired(
|
||||||
|
net::URLRequest* request,
|
||||||
|
const net::AuthChallengeInfo& auth_info,
|
||||||
|
const AuthCallback& callback,
|
||||||
|
net::AuthCredentials* credentials) override;
|
||||||
|
bool OnCanGetCookies(const net::URLRequest& request,
|
||||||
|
const net::CookieList& cookie_list) override;
|
||||||
|
bool OnCanSetCookie(const net::URLRequest& request,
|
||||||
|
const net::CanonicalCookie& cookie_line,
|
||||||
|
net::CookieOptions* options) override;
|
||||||
|
bool OnCanAccessFile(const net::URLRequest& request,
|
||||||
|
const base::FilePath& original_path,
|
||||||
|
const base::FilePath& absolute_path) const override;
|
||||||
|
bool OnCanEnablePrivacyMode(
|
||||||
|
const GURL& url,
|
||||||
|
const GURL& first_party_for_cookies) const override;
|
||||||
|
bool OnAreExperimentalCookieFeaturesEnabled() const override;
|
||||||
|
bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
|
||||||
|
const net::URLRequest& request,
|
||||||
|
const GURL& target_url,
|
||||||
|
const GURL& referrer_url) const override;
|
||||||
|
bool OnCanQueueReportingReport(const url::Origin& origin) const override;
|
||||||
|
void OnCanSendReportingReports(std::set<url::Origin> origins,
|
||||||
|
base::OnceCallback<void(std::set<url::Origin>)>
|
||||||
|
result_callback) const override;
|
||||||
|
bool OnCanSetReportingClient(const url::Origin& origin,
|
||||||
|
const GURL& endpoint) const override;
|
||||||
|
bool OnCanUseReportingClient(const url::Origin& origin,
|
||||||
|
const GURL& endpoint) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnErrorOccurred(net::URLRequest* request, bool started);
|
void OnErrorOccurred(net::URLRequest* request, bool started);
|
||||||
|
@ -124,9 +165,11 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
|
||||||
T out,
|
T out,
|
||||||
const base::DictionaryValue& response);
|
const base::DictionaryValue& response);
|
||||||
|
|
||||||
|
std::map<uint64_t, scoped_refptr<LoginHandler>> login_handler_map_;
|
||||||
std::map<SimpleEvent, SimpleListenerInfo> simple_listeners_;
|
std::map<SimpleEvent, SimpleListenerInfo> simple_listeners_;
|
||||||
std::map<ResponseEvent, ResponseListenerInfo> response_listeners_;
|
std::map<ResponseEvent, ResponseListenerInfo> response_listeners_;
|
||||||
std::map<uint64_t, net::CompletionCallback> callbacks_;
|
std::map<uint64_t, net::CompletionCallback> callbacks_;
|
||||||
|
std::vector<std::string> ignore_connections_limit_domains_;
|
||||||
|
|
||||||
// Client id for devtools network emulation.
|
// Client id for devtools network emulation.
|
||||||
std::string client_id_;
|
std::string client_id_;
|
||||||
|
|
|
@ -218,6 +218,9 @@ const char kWidevineCdmVersion[] = "widevine-cdm-version";
|
||||||
// Forces the maximum disk space to be used by the disk cache, in bytes.
|
// Forces the maximum disk space to be used by the disk cache, in bytes.
|
||||||
const char kDiskCacheSize[] = "disk-cache-size";
|
const char kDiskCacheSize[] = "disk-cache-size";
|
||||||
|
|
||||||
|
// Ignore the limit of 6 connections per host.
|
||||||
|
const char kIgnoreConnectionsLimit[] = "ignore-connections-limit";
|
||||||
|
|
||||||
} // namespace switches
|
} // namespace switches
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -113,6 +113,7 @@ extern const char kWidevineCdmPath[];
|
||||||
extern const char kWidevineCdmVersion[];
|
extern const char kWidevineCdmVersion[];
|
||||||
|
|
||||||
extern const char kDiskCacheSize[];
|
extern const char kDiskCacheSize[];
|
||||||
|
extern const char kIgnoreConnectionsLimit[];
|
||||||
|
|
||||||
} // namespace switches
|
} // namespace switches
|
||||||
|
|
||||||
|
|
|
@ -1,161 +0,0 @@
|
||||||
// Copyright (c) 2012 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-CHROMIUM file.
|
|
||||||
|
|
||||||
#include "brightray/browser/network_delegate.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "base/command_line.h"
|
|
||||||
#include "base/strings/string_split.h"
|
|
||||||
#include "net/base/load_flags.h"
|
|
||||||
#include "net/base/net_errors.h"
|
|
||||||
#include "net/url_request/url_request.h"
|
|
||||||
|
|
||||||
namespace brightray {
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// Ignore the limit of 6 connections per host.
|
|
||||||
const char kIgnoreConnectionsLimit[] = "ignore-connections-limit";
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
NetworkDelegate::NetworkDelegate() {
|
|
||||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
|
||||||
if (command_line->HasSwitch(kIgnoreConnectionsLimit)) {
|
|
||||||
std::string value =
|
|
||||||
command_line->GetSwitchValueASCII(kIgnoreConnectionsLimit);
|
|
||||||
ignore_connections_limit_domains_ = base::SplitString(
|
|
||||||
value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkDelegate::~NetworkDelegate() {}
|
|
||||||
|
|
||||||
int NetworkDelegate::OnBeforeURLRequest(net::URLRequest* request,
|
|
||||||
const net::CompletionCallback& callback,
|
|
||||||
GURL* new_url) {
|
|
||||||
for (const auto& domain : ignore_connections_limit_domains_) {
|
|
||||||
if (request->url().DomainIs(domain)) {
|
|
||||||
// Allow unlimited concurrent connections.
|
|
||||||
request->SetPriority(net::MAXIMUM_PRIORITY);
|
|
||||||
request->SetLoadFlags(request->load_flags() | net::LOAD_IGNORE_LIMITS);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return net::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int NetworkDelegate::OnBeforeStartTransaction(
|
|
||||||
net::URLRequest* request,
|
|
||||||
const net::CompletionCallback& callback,
|
|
||||||
net::HttpRequestHeaders* headers) {
|
|
||||||
return net::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnStartTransaction(
|
|
||||||
net::URLRequest* request,
|
|
||||||
const net::HttpRequestHeaders& headers) {}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnBeforeSendHeaders(
|
|
||||||
net::URLRequest* request,
|
|
||||||
const net::ProxyInfo& proxy_info,
|
|
||||||
const net::ProxyRetryInfoMap& proxy_retry_info,
|
|
||||||
net::HttpRequestHeaders* headers) {}
|
|
||||||
|
|
||||||
int NetworkDelegate::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 net::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
|
|
||||||
const GURL& new_location) {}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnResponseStarted(net::URLRequest* request,
|
|
||||||
int net_error) {}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request,
|
|
||||||
int64_t bytes_read) {}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnNetworkBytesSent(net::URLRequest* request,
|
|
||||||
int64_t bytes_sent) {}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnPACScriptError(int line_number,
|
|
||||||
const base::string16& error) {}
|
|
||||||
|
|
||||||
NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired(
|
|
||||||
net::URLRequest* request,
|
|
||||||
const net::AuthChallengeInfo& auth_info,
|
|
||||||
const AuthCallback& callback,
|
|
||||||
net::AuthCredentials* credentials) {
|
|
||||||
return AUTH_REQUIRED_RESPONSE_NO_ACTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
|
|
||||||
const net::CookieList& cookie_list) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
|
|
||||||
const net::CanonicalCookie& cookie_line,
|
|
||||||
net::CookieOptions* options) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NetworkDelegate::OnCanAccessFile(
|
|
||||||
const net::URLRequest& request,
|
|
||||||
const base::FilePath& original_path,
|
|
||||||
const base::FilePath& absolute_path) const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NetworkDelegate::OnCanEnablePrivacyMode(
|
|
||||||
const GURL& url,
|
|
||||||
const GURL& first_party_for_cookies) const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
|
|
||||||
const net::URLRequest& request,
|
|
||||||
const GURL& target_url,
|
|
||||||
const GURL& referrer_url) const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(deepak1556) : Enable after hooking into the reporting service
|
|
||||||
// https://crbug.com/704259
|
|
||||||
bool NetworkDelegate::OnCanQueueReportingReport(
|
|
||||||
const url::Origin& origin) const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnCanSendReportingReports(
|
|
||||||
std::set<url::Origin> origins,
|
|
||||||
base::OnceCallback<void(std::set<url::Origin>)> result_callback) const {}
|
|
||||||
|
|
||||||
bool NetworkDelegate::OnCanSetReportingClient(const url::Origin& origin,
|
|
||||||
const GURL& endpoint) const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NetworkDelegate::OnCanUseReportingClient(const url::Origin& origin,
|
|
||||||
const GURL& endpoint) const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace brightray
|
|
|
@ -1,88 +0,0 @@
|
||||||
// Copyright (c) 2012 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-CHROMIUM file.
|
|
||||||
|
|
||||||
#ifndef BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_
|
|
||||||
#define BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_
|
|
||||||
|
|
||||||
#include <set>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "net/base/network_delegate.h"
|
|
||||||
|
|
||||||
namespace brightray {
|
|
||||||
|
|
||||||
class NetworkDelegate : public net::NetworkDelegate {
|
|
||||||
public:
|
|
||||||
NetworkDelegate();
|
|
||||||
~NetworkDelegate() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
int OnBeforeURLRequest(net::URLRequest* request,
|
|
||||||
const net::CompletionCallback& callback,
|
|
||||||
GURL* new_url) override;
|
|
||||||
int OnBeforeStartTransaction(net::URLRequest* request,
|
|
||||||
const net::CompletionCallback& callback,
|
|
||||||
net::HttpRequestHeaders* headers) override;
|
|
||||||
void OnBeforeSendHeaders(net::URLRequest* request,
|
|
||||||
const net::ProxyInfo& proxy_info,
|
|
||||||
const net::ProxyRetryInfoMap& proxy_retry_info,
|
|
||||||
net::HttpRequestHeaders* headers) override;
|
|
||||||
void OnStartTransaction(net::URLRequest* request,
|
|
||||||
const net::HttpRequestHeaders& headers) override;
|
|
||||||
int 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) override;
|
|
||||||
void OnBeforeRedirect(net::URLRequest* request,
|
|
||||||
const GURL& new_location) override;
|
|
||||||
void OnResponseStarted(net::URLRequest* request, int net_error) override;
|
|
||||||
void OnNetworkBytesReceived(net::URLRequest* request,
|
|
||||||
int64_t bytes_read) override;
|
|
||||||
void OnNetworkBytesSent(net::URLRequest* request,
|
|
||||||
int64_t bytes_sent) override;
|
|
||||||
void OnCompleted(net::URLRequest* request, bool started) override;
|
|
||||||
void OnURLRequestDestroyed(net::URLRequest* request) override;
|
|
||||||
void OnPACScriptError(int line_number, const base::string16& error) override;
|
|
||||||
AuthRequiredResponse OnAuthRequired(
|
|
||||||
net::URLRequest* request,
|
|
||||||
const net::AuthChallengeInfo& auth_info,
|
|
||||||
const AuthCallback& callback,
|
|
||||||
net::AuthCredentials* credentials) override;
|
|
||||||
bool OnCanGetCookies(const net::URLRequest& request,
|
|
||||||
const net::CookieList& cookie_list) override;
|
|
||||||
bool OnCanSetCookie(const net::URLRequest& request,
|
|
||||||
const net::CanonicalCookie& cookie_line,
|
|
||||||
net::CookieOptions* options) override;
|
|
||||||
bool OnCanAccessFile(const net::URLRequest& request,
|
|
||||||
const base::FilePath& original_path,
|
|
||||||
const base::FilePath& absolute_path) const override;
|
|
||||||
bool OnCanEnablePrivacyMode(
|
|
||||||
const GURL& url,
|
|
||||||
const GURL& first_party_for_cookies) const override;
|
|
||||||
bool OnAreExperimentalCookieFeaturesEnabled() const override;
|
|
||||||
bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
|
|
||||||
const net::URLRequest& request,
|
|
||||||
const GURL& target_url,
|
|
||||||
const GURL& referrer_url) const override;
|
|
||||||
bool OnCanQueueReportingReport(const url::Origin& origin) const override;
|
|
||||||
void OnCanSendReportingReports(std::set<url::Origin> origins,
|
|
||||||
base::OnceCallback<void(std::set<url::Origin>)>
|
|
||||||
result_callback) const override;
|
|
||||||
bool OnCanSetReportingClient(const url::Origin& origin,
|
|
||||||
const GURL& endpoint) const override;
|
|
||||||
bool OnCanUseReportingClient(const url::Origin& origin,
|
|
||||||
const GURL& endpoint) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<std::string> ignore_connections_limit_domains_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(NetworkDelegate);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace brightray
|
|
||||||
|
|
||||||
#endif // BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include "brightray/browser/browser_context.h"
|
#include "brightray/browser/browser_context.h"
|
||||||
#include "brightray/browser/net/require_ct_delegate.h"
|
#include "brightray/browser/net/require_ct_delegate.h"
|
||||||
#include "brightray/browser/net_log.h"
|
#include "brightray/browser/net_log.h"
|
||||||
#include "brightray/browser/network_delegate.h"
|
|
||||||
#include "brightray/common/switches.h"
|
#include "brightray/common/switches.h"
|
||||||
#include "components/network_session_configurator/common/network_switches.h"
|
#include "components/network_session_configurator/common/network_switches.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
|
|
|
@ -51,8 +51,6 @@
|
||||||
'browser/net/require_ct_delegate.h',
|
'browser/net/require_ct_delegate.h',
|
||||||
'browser/net_log.cc',
|
'browser/net_log.cc',
|
||||||
'browser/net_log.h',
|
'browser/net_log.h',
|
||||||
'browser/network_delegate.cc',
|
|
||||||
'browser/network_delegate.h',
|
|
||||||
'browser/notification_delegate.h',
|
'browser/notification_delegate.h',
|
||||||
'browser/notification_presenter.cc',
|
'browser/notification_presenter.cc',
|
||||||
'browser/notification_presenter.h',
|
'browser/notification_presenter.h',
|
||||||
|
|
Loading…
Reference in a new issue