Reland of NetworkService: Implement URLLoader::OnAuthRequired

The initial upload patch of this CL is the same as:
https://chromium-review.googlesource.com/c/chromium/src/+/877512

This reland CL addresses comments at:
https://chromium-review.googlesource.com/c/chromium/src/+/877512/19

The initial upload patch of this CL uses empty credential to indicate
that URLRequest::CancelAuth() needs to be called, which is incorrect
because empty credentials are valid. The latest patch of this CL
contains the fix for this issue.

[email protected], [email protected]

Bug: 783990
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: Ifdbab56badaf3e13b5f15f5aa0d31cfb764325c6
Reviewed-on: https://chromium-review.googlesource.com/938960
Commit-Queue: Jun Cai <[email protected]>
Reviewed-by: John Abd-El-Malek <[email protected]>
Reviewed-by: Asanka Herath <[email protected]>
Reviewed-by: Jun Cai <[email protected]>
Cr-Commit-Position: refs/heads/master@{#539903}
diff --git a/content/shell/browser/shell_content_browser_client.h b/content/shell/browser/shell_content_browser_client.h
index 57d81cc..bb3e9a2 100644
--- a/content/shell/browser/shell_content_browser_client.h
+++ b/content/shell/browser/shell_content_browser_client.h
@@ -8,16 +8,17 @@
 #include <memory>
 #include <string>
 
+#include "base/callback.h"
 #include "base/compiler_specific.h"
 #include "base/files/file_path.h"
 #include "build/build_config.h"
 #include "content/public/browser/content_browser_client.h"
-#include "content/shell/browser/shell_resource_dispatcher_host_delegate.h"
 #include "content/shell/browser/shell_speech_recognition_manager_delegate.h"
 #include "services/service_manager/public/cpp/binder_registry.h"
 
 namespace content {
 
+class ResourceDispatcherHostDelegate;
 class ShellBrowserContext;
 class ShellBrowserMainParts;
 
@@ -65,10 +66,17 @@
       override;
   net::NetLog* GetNetLog() override;
   DevToolsManagerDelegate* GetDevToolsManagerDelegate() override;
-
   void OpenURL(BrowserContext* browser_context,
                const OpenURLParams& params,
                const base::Callback<void(WebContents*)>& callback) override;
+  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;
 
 #if defined(OS_LINUX) || defined(OS_ANDROID)
   void GetAdditionalMappedFilesForChildProcess(
@@ -83,7 +91,7 @@
 
   ShellBrowserContext* browser_context();
   ShellBrowserContext* off_the_record_browser_context();
-  ShellResourceDispatcherHostDelegate* resource_dispatcher_host_delegate() {
+  ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate() {
     return resource_dispatcher_host_delegate_.get();
   }
   ShellBrowserMainParts* shell_browser_main_parts() {
@@ -99,28 +107,28 @@
       base::Callback<bool(const service_manager::Identity&)> callback) {
     should_terminate_on_service_quit_callback_ = callback;
   }
+  void set_login_request_callback(
+      base::Callback<void()> login_request_callback) {
+    login_request_callback_ = login_request_callback;
+  }
 
  protected:
   virtual void ExposeInterfacesToFrame(
       service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>*
           registry);
 
-  void set_resource_dispatcher_host_delegate(
-      std::unique_ptr<ShellResourceDispatcherHostDelegate> delegate) {
-    resource_dispatcher_host_delegate_ = std::move(delegate);
-  }
-
   void set_browser_main_parts(ShellBrowserMainParts* parts) {
     shell_browser_main_parts_ = parts;
   }
 
  private:
-  std::unique_ptr<ShellResourceDispatcherHostDelegate>
+  std::unique_ptr<ResourceDispatcherHostDelegate>
       resource_dispatcher_host_delegate_;
 
   base::Closure select_client_certificate_callback_;
   base::Callback<bool(const service_manager::Identity&)>
       should_terminate_on_service_quit_callback_;
+  base::Callback<void()> login_request_callback_;
 
   std::unique_ptr<
       service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>