Browse Source

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
trop[bot] 6 years ago
parent
commit
635c3f53d8

+ 5 - 5
atom/browser/api/atom_api_app.cc

@@ -667,17 +667,17 @@ void App::OnNewWindowForTab() {
 }
 #endif
 
-void App::OnLogin(LoginHandler* login_handler,
+void App::OnLogin(scoped_refptr<LoginHandler> login_handler,
                   const base::DictionaryValue& request_details) {
   v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   bool prevent_default = false;
   content::WebContents* web_contents = login_handler->GetWebContents();
   if (web_contents) {
-    prevent_default =
-        Emit("login", WebContents::CreateFrom(isolate(), web_contents),
-             request_details, login_handler->auth_info(),
-             base::Bind(&PassLoginInformation, WrapRefCounted(login_handler)));
+    prevent_default = Emit(
+        "login", WebContents::CreateFrom(isolate(), web_contents),
+        request_details, login_handler->auth_info(),
+        base::Bind(&PassLoginInformation, base::RetainedRef(login_handler)));
   }
 
   // Default behavior is to always cancel the auth.

+ 1 - 1
atom/browser/api/atom_api_app.h

@@ -98,7 +98,7 @@ class App : public AtomBrowserClient::Delegate,
   void OnActivate(bool has_visible_windows) override;
   void OnWillFinishLaunching() 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;
   void OnAccessibilitySupportChanged() override;
   void OnPreMainMessageLoopRun() override;

+ 0 - 14
atom/browser/atom_browser_client.cc

@@ -17,7 +17,6 @@
 #include "atom/browser/atom_resource_dispatcher_host_delegate.h"
 #include "atom/browser/atom_speech_recognition_manager_delegate.h"
 #include "atom/browser/child_web_contents_tracker.h"
-#include "atom/browser/login_handler.h"
 #include "atom/browser/native_window.h"
 #include "atom/browser/session_preferences.h"
 #include "atom/browser/web_contents_permission_helper.h"
@@ -495,19 +494,6 @@ std::unique_ptr<net::ClientCertStore> AtomBrowserClient::CreateClientCertStore(
 #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(
     const content::MainFunctionParams&) {
   v8::V8::Initialize();  // Init V8 before creating main parts.

+ 0 - 8
atom/browser/atom_browser_client.h

@@ -106,14 +106,6 @@ class AtomBrowserClient : public brightray::BrowserClient,
   void SiteInstanceDeleting(content::SiteInstance* site_instance) override;
   std::unique_ptr<net::ClientCertStore> CreateClientCertStore(
       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::BrowserMainParts* OverrideCreateBrowserMainParts(

+ 2 - 1
atom/browser/browser.cc

@@ -8,6 +8,7 @@
 
 #include "atom/browser/atom_browser_main_parts.h"
 #include "atom/browser/browser_observer.h"
+#include "atom/browser/login_handler.h"
 #include "atom/browser/native_window.h"
 #include "atom/browser/window_list.h"
 #include "base/files/file_util.h"
@@ -164,7 +165,7 @@ void Browser::OnAccessibilitySupportChanged() {
 }
 
 void Browser::RequestLogin(
-    LoginHandler* login_handler,
+    scoped_refptr<LoginHandler> login_handler,
     std::unique_ptr<base::DictionaryValue> request_details) {
   for (BrowserObserver& observer : observers_)
     observer.OnLogin(login_handler, *(request_details.get()));

+ 1 - 2
atom/browser/browser.h

@@ -33,7 +33,6 @@ class Image;
 namespace atom {
 
 class AtomMenuModel;
-class LoginHandler;
 
 // This class is used for control application-wide operations.
 class Browser : public WindowListObserver {
@@ -229,7 +228,7 @@ class Browser : public WindowListObserver {
   void OnAccessibilitySupportChanged();
 
   // Request basic auth login.
-  void RequestLogin(LoginHandler* login_handler,
+  void RequestLogin(scoped_refptr<LoginHandler> login_handler,
                     std::unique_ptr<base::DictionaryValue> request_details);
 
   void PreMainMessageLoopRun();

+ 3 - 3
atom/browser/browser_observer.h

@@ -7,6 +7,8 @@
 
 #include <string>
 
+#include "atom/browser/login_handler.h"
+#include "base/memory/scoped_refptr.h"
 #include "build/build_config.h"
 
 namespace base {
@@ -15,8 +17,6 @@ class DictionaryValue;
 
 namespace atom {
 
-class LoginHandler;
-
 class BrowserObserver {
  public:
   // The browser is about to close all windows.
@@ -49,7 +49,7 @@ class BrowserObserver {
   virtual void OnFinishLaunching(const base::DictionaryValue& launch_info) {}
 
   // The browser requests HTTP login.
-  virtual void OnLogin(LoginHandler* login_handler,
+  virtual void OnLogin(scoped_refptr<LoginHandler> login_handler,
                        const base::DictionaryValue& request_details) {}
 
   // The browser's accessibility suppport has changed.

+ 38 - 40
atom/browser/login_handler.cc

@@ -5,6 +5,7 @@
 #include "atom/browser/login_handler.h"
 
 #include "atom/browser/browser.h"
+#include "atom/common/native_mate_converters/net_converter.h"
 #include "base/values.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/web_contents.h"
@@ -15,78 +16,75 @@ using content::BrowserThread;
 namespace atom {
 
 LoginHandler::LoginHandler(
-    net::AuthChallengeInfo* auth_info,
-    content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
-    const GURL& url,
-    const base::Callback<void(const base::Optional<net::AuthCredentials>&)>&
-        auth_required_callback)
-    : auth_info_(auth_info),
-      web_contents_getter_(web_contents_getter),
-      auth_required_callback_(auth_required_callback) {
-  // Fill request details on IO thread.
-  // TODO(deepak1556): Fill in method and referrer details to
-  // avoid breaking the app login event.
+    net::URLRequest* request,
+    const net::AuthChallengeInfo& auth_info,
+    const net::NetworkDelegate::AuthCallback& callback,
+    net::AuthCredentials* credentials,
+    const content::ResourceRequestInfo* resource_request_info)
+    : credentials_(credentials),
+      auth_info_(auth_info),
+      auth_callback_(std::move(callback)),
+      weak_factory_(this) {
+  DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
   std::unique_ptr<base::DictionaryValue> request_details(
       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::UI, FROM_HERE,
       base::BindOnce(&Browser::RequestLogin, base::Unretained(Browser::Get()),
-                     base::RetainedRef(WrapRefCounted(this)),
-                     std::move(request_details)));
+                     base::RetainedRef(this), std::move(request_details)));
 }
 
 LoginHandler::~LoginHandler() {}
 
-content::WebContents* LoginHandler::GetWebContents() const {
-  DCHECK_CURRENTLY_ON(BrowserThread::UI);
-  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));
+      base::BindOnce(&LoginHandler::DoLogin, weak_factory_.GetWeakPtr(),
+                     username, password));
 }
 
 void LoginHandler::CancelAuth() {
   DCHECK_CURRENTLY_ON(BrowserThread::UI);
-  if (TestAndSetAuthHandled())
-    return;
-  BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
-                          base::BindOnce(&LoginHandler::DoCancelAuth, this));
+
+  BrowserThread::PostTask(
+      BrowserThread::IO, FROM_HERE,
+      base::BindOnce(&LoginHandler::DoCancelAuth, weak_factory_.GetWeakPtr()));
 }
 
-void LoginHandler::OnRequestCancelled() {
-  TestAndSetAuthHandled();
-  auth_required_callback_.Reset();
+void LoginHandler::NotifyRequestDestroyed() {
+  auth_callback_.Reset();
+  credentials_ = nullptr;
+  weak_factory_.InvalidateWeakPtrs();
 }
 
-// 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;
+content::WebContents* LoginHandler::GetWebContents() const {
+  DCHECK_CURRENTLY_ON(BrowserThread::UI);
+  return web_contents_getter_.Run();
 }
 
 void LoginHandler::DoCancelAuth() {
   DCHECK_CURRENTLY_ON(BrowserThread::IO);
-  if (!auth_required_callback_.is_null())
-    std::move(auth_required_callback_).Run(base::nullopt);
+  if (!auth_callback_.is_null())
+    std::move(auth_callback_)
+        .Run(net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH);
 }
 
 void LoginHandler::DoLogin(const base::string16& username,
                            const base::string16& password) {
   DCHECK_CURRENTLY_ON(BrowserThread::IO);
-  if (!auth_required_callback_.is_null()) {
-    std::move(auth_required_callback_)
-        .Run(net::AuthCredentials(username, password));
+  if (!auth_callback_.is_null()) {
+    credentials_->Set(username, password);
+    std::move(auth_callback_)
+        .Run(net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
   }
 }
 

+ 28 - 35
atom/browser/login_handler.h

@@ -6,72 +6,65 @@
 #define ATOM_BROWSER_LOGIN_HANDLER_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/synchronization/lock.h"
-#include "content/public/browser/resource_dispatcher_host_login_delegate.h"
 #include "content/public/browser/resource_request_info.h"
+#include "net/base/network_delegate.h"
 
 namespace content {
 class WebContents;
 }
 
-namespace net {
-class AuthChallengeInfo;
-class AuthCredentials;
-}  // namespace net
-
 namespace atom {
 
 // Handles the HTTP basic auth, must be created on IO thread.
-class LoginHandler : public content::ResourceDispatcherHostLoginDelegate {
+class LoginHandler : public base::RefCountedThreadSafe<LoginHandler> {
  public:
-  LoginHandler(
-      net::AuthChallengeInfo* auth_info,
-      content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
-      const GURL& url,
-      const base::Callback<void(const base::Optional<net::AuthCredentials>&)>&
-          auth_required_callback);
-
-  // Returns the WebContents associated with the request, must be called on UI
-  // thread.
-  content::WebContents* GetWebContents() const;
+  LoginHandler(net::URLRequest* request,
+               const net::AuthChallengeInfo& auth_info,
+               const net::NetworkDelegate::AuthCallback& callback,
+               net::AuthCredentials* credentials,
+               const content::ResourceRequestInfo* resource_request_info);
 
   // 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);
 
-  const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); }
-
- protected:
-  ~LoginHandler() override;
+  // Returns the WebContents associated with the request, must be called on UI
+  // thread.
+  content::WebContents* GetWebContents() const;
 
-  // content::ResourceDispatcherHostLoginDelegate:
-  void OnRequestCancelled() override;
+  const net::AuthChallengeInfo* auth_info() const { return &auth_info_; }
 
  private:
+  friend class base::RefCountedThreadSafe<LoginHandler>;
+  friend class base::DeleteHelper<LoginHandler>;
+
+  ~LoginHandler();
+
   // Must be called on IO thread.
   void DoCancelAuth();
   void DoLogin(const base::string16& username, const base::string16& password);
 
-  // Marks authentication as handled and returns the previous handled
-  // state.
-  bool TestAndSetAuthHandled();
-
-  // True if we've handled auth (Login or CancelAuth has been called).
-  bool handled_auth_ = false;
-  mutable base::Lock handled_auth_lock_;
+  // Credentials to be used for the auth.
+  net::AuthCredentials* credentials_;
 
   // Who/where/what asked for the authentication.
-  scoped_refptr<net::AuthChallengeInfo> auth_info_;
+  const net::AuthChallengeInfo& auth_info_;
 
   // WebContents associated with the login request.
   content::ResourceRequestInfo::WebContentsGetter web_contents_getter_;
 
-  base::Callback<void(const base::Optional<net::AuthCredentials>&)>
-      auth_required_callback_;
+  // Called with preferred value of net::NetworkDelegate::AuthRequiredResponse.
+  net::NetworkDelegate::AuthCallback auth_callback_;
+
+  base::WeakPtrFactory<LoginHandler> weak_factory_;
 
   DISALLOW_COPY_AND_ASSIGN(LoginHandler);
 };

+ 117 - 27
atom/browser/net/atom_network_delegate.cc

@@ -7,11 +7,17 @@
 #include <utility>
 
 #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/options_switches.h"
+#include "base/command_line.h"
 #include "base/stl_util.h"
 #include "base/strings/string_util.h"
 #include "content/public/browser/browser_thread.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 "services/network/throttling/throttling_network_transaction.h"
 
@@ -231,7 +237,15 @@ AtomNetworkDelegate::ResponseListenerInfo::ResponseListenerInfo(
 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() {}
 
@@ -262,9 +276,17 @@ int AtomNetworkDelegate::OnBeforeURLRequest(
     net::URLRequest* request,
     const net::CompletionCallback& callback,
     GURL* new_url) {
-  if (!base::ContainsKey(response_listeners_, kOnBeforeRequest))
-    return brightray::NetworkDelegate::OnBeforeURLRequest(request, callback,
-                                                          new_url);
+  if (!base::ContainsKey(response_listeners_, kOnBeforeRequest)) {
+    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;
+  }
 
   return HandleResponseEvent(kOnBeforeRequest, request, callback, new_url);
 }
@@ -278,8 +300,7 @@ int AtomNetworkDelegate::OnBeforeStartTransaction(
                            kDevToolsEmulateNetworkConditionsClientId,
                        client_id_);
   if (!base::ContainsKey(response_listeners_, kOnBeforeSendHeaders))
-    return brightray::NetworkDelegate::OnBeforeStartTransaction(
-        request, callback, headers);
+    return net::OK;
 
   return HandleResponseEvent(kOnBeforeSendHeaders, request, callback, headers,
                              *headers);
@@ -288,10 +309,8 @@ int AtomNetworkDelegate::OnBeforeStartTransaction(
 void AtomNetworkDelegate::OnStartTransaction(
     net::URLRequest* request,
     const net::HttpRequestHeaders& headers) {
-  if (!base::ContainsKey(simple_listeners_, kOnSendHeaders)) {
-    brightray::NetworkDelegate::OnStartTransaction(request, headers);
+  if (!base::ContainsKey(simple_listeners_, kOnSendHeaders))
     return;
-  }
 
   HandleSimpleEvent(kOnSendHeaders, request, headers);
 }
@@ -303,8 +322,7 @@ int AtomNetworkDelegate::OnHeadersReceived(
     scoped_refptr<net::HttpResponseHeaders>* override,
     GURL* allowed) {
   if (!base::ContainsKey(response_listeners_, kOnHeadersReceived))
-    return brightray::NetworkDelegate::OnHeadersReceived(
-        request, callback, original, override, allowed);
+    return net::OK;
 
   return HandleResponseEvent(
       kOnHeadersReceived, request, callback,
@@ -313,10 +331,8 @@ int AtomNetworkDelegate::OnHeadersReceived(
 
 void AtomNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
                                            const GURL& new_location) {
-  if (!base::ContainsKey(simple_listeners_, kOnBeforeRedirect)) {
-    brightray::NetworkDelegate::OnBeforeRedirect(request, new_location);
+  if (!base::ContainsKey(simple_listeners_, kOnBeforeRedirect))
     return;
-  }
 
   HandleSimpleEvent(kOnBeforeRedirect, request, new_location,
                     request->response_headers(), request->GetSocketAddress(),
@@ -325,10 +341,8 @@ void AtomNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
 
 void AtomNetworkDelegate::OnResponseStarted(net::URLRequest* request,
                                             int net_error) {
-  if (!base::ContainsKey(simple_listeners_, kOnResponseStarted)) {
-    brightray::NetworkDelegate::OnResponseStarted(request, net_error);
+  if (!base::ContainsKey(simple_listeners_, kOnResponseStarted))
     return;
-  }
 
   if (request->status().status() != net::URLRequestStatus::SUCCESS)
     return;
@@ -346,33 +360,109 @@ void AtomNetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {
     // Error event.
     OnErrorOccurred(request, started);
     return;
-  } else if (request->response_headers() &&
-             net::HttpResponseHeaders::IsRedirectResponseCode(
-                 request->response_headers()->response_code())) {
+  }
+
+  if (request->response_headers() &&
+      net::HttpResponseHeaders::IsRedirectResponseCode(
+          request->response_headers()->response_code())) {
     // Redirect event.
-    brightray::NetworkDelegate::OnCompleted(request, started);
     return;
   }
 
-  if (!base::ContainsKey(simple_listeners_, kOnCompleted)) {
-    brightray::NetworkDelegate::OnCompleted(request, started);
+  if (!base::ContainsKey(simple_listeners_, kOnCompleted))
     return;
-  }
 
   HandleSimpleEvent(kOnCompleted, request, request->response_headers(),
                     request->was_cached());
 }
 
 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());
 }
 
+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,
                                           bool started) {
-  if (!base::ContainsKey(simple_listeners_, kOnErrorOccurred)) {
-    brightray::NetworkDelegate::OnCompleted(request, started);
+  if (!base::ContainsKey(simple_listeners_, kOnErrorOccurred))
     return;
-  }
 
   HandleSimpleEvent(kOnErrorOccurred, request, request->was_cached(),
                     request->status());

+ 46 - 3
atom/browser/net/atom_network_delegate.h

@@ -8,14 +8,14 @@
 #include <map>
 #include <set>
 #include <string>
+#include <vector>
 
 #include "base/callback.h"
 #include "base/synchronization/lock.h"
 #include "base/values.h"
-#include "brightray/browser/network_delegate.h"
 #include "content/public/browser/resource_request_info.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_response_headers.h"
 
@@ -27,7 +27,9 @@ using URLPatterns = std::set<URLPattern>;
 
 const char* ResourceTypeToString(content::ResourceType type);
 
-class AtomNetworkDelegate : public brightray::NetworkDelegate {
+class LoginHandler;
+
+class AtomNetworkDelegate : public net::NetworkDelegate {
  public:
   using ResponseCallback = 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,
                                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(
@@ -97,8 +103,43 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
   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:
   void OnErrorOccurred(net::URLRequest* request, bool started);
@@ -124,9 +165,11 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
                             T out,
                             const base::DictionaryValue& response);
 
+  std::map<uint64_t, scoped_refptr<LoginHandler>> login_handler_map_;
   std::map<SimpleEvent, SimpleListenerInfo> simple_listeners_;
   std::map<ResponseEvent, ResponseListenerInfo> response_listeners_;
   std::map<uint64_t, net::CompletionCallback> callbacks_;
+  std::vector<std::string> ignore_connections_limit_domains_;
 
   // Client id for devtools network emulation.
   std::string client_id_;

+ 3 - 0
atom/common/options_switches.cc

@@ -218,6 +218,9 @@ const char kWidevineCdmVersion[] = "widevine-cdm-version";
 // Forces the maximum disk space to be used by the disk cache, in bytes.
 const char kDiskCacheSize[] = "disk-cache-size";
 
+// Ignore the limit of 6 connections per host.
+const char kIgnoreConnectionsLimit[] = "ignore-connections-limit";
+
 }  // namespace switches
 
 }  // namespace atom

+ 1 - 0
atom/common/options_switches.h

@@ -113,6 +113,7 @@ extern const char kWidevineCdmPath[];
 extern const char kWidevineCdmVersion[];
 
 extern const char kDiskCacheSize[];
+extern const char kIgnoreConnectionsLimit[];
 
 }  // namespace switches
 

+ 0 - 161
brightray/browser/network_delegate.cc

@@ -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

+ 0 - 88
brightray/browser/network_delegate.h

@@ -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_

+ 0 - 1
brightray/browser/url_request_context_getter.cc

@@ -15,7 +15,6 @@
 #include "brightray/browser/browser_context.h"
 #include "brightray/browser/net/require_ct_delegate.h"
 #include "brightray/browser/net_log.h"
-#include "brightray/browser/network_delegate.h"
 #include "brightray/common/switches.h"
 #include "components/network_session_configurator/common/network_switches.h"
 #include "content/public/browser/browser_thread.h"

+ 0 - 2
brightray/filenames.gypi

@@ -51,8 +51,6 @@
       'browser/net/require_ct_delegate.h',
       'browser/net_log.cc',
       'browser/net_log.h',
-      'browser/network_delegate.cc',
-      'browser/network_delegate.h',
       'browser/notification_delegate.h',
       'browser/notification_presenter.cc',
       'browser/notification_presenter.h',