system-proxy: Request credentials from browser

When a ProxyConnectJob fails with "proxy auth required", the job will
ask for credentials from the ServerProxy object which owns it.

If the credentials are in the ServerProxy auth cache, the request will
be resolved with those credentials.

If not, the request will be forwarded to the parent process which will
send a dbus call to the browser to notify that it needs credentials for
a specific protection space (proxy_url, scheme, realm).

The browser will then send credentials along with the protection space
via dbus, with empty username and password if the user hasn't entered
them yet.

The dbus response is then forwarded to the ProxyConnectJob which made
the original request.

BUG=chromium:1042642
TEST=unittest

Change-Id: I1f5d43971d18df98aeb7c0b25642ceb29c761915
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2245699
Reviewed-by: Pavol Marko <pmarko@chromium.org>
Tested-by: Andreea-Elena Costinas <acostinas@google.com>
Commit-Queue: Andreea-Elena Costinas <acostinas@google.com>
diff --git a/system-proxy/system_proxy_adaptor.h b/system-proxy/system_proxy_adaptor.h
index 1863f51..c8dec58 100644
--- a/system-proxy/system_proxy_adaptor.h
+++ b/system-proxy/system_proxy_adaptor.h
@@ -14,6 +14,7 @@
 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
 #include <patchpanel/proto_bindings/patchpanel_service.pb.h>
 
+#include "bindings/worker_common.pb.h"
 #include "system_proxy/org.chromium.SystemProxy.h"
 
 namespace brillo {
@@ -54,6 +55,9 @@
       const std::string& target_url,
       const brillo::http::GetChromeProxyServersCallback& callback);
 
+  void RequestAuthenticationCredentials(
+      const worker::ProtectionSpace& protection_space);
+
  protected:
   virtual std::unique_ptr<SandboxedWorker> CreateWorker();
   virtual bool ConnectNamespace(SandboxedWorker* worker, bool user_traffic);
@@ -68,10 +72,11 @@
   FRIEND_TEST(SystemProxyAdaptorTest, ShutDown);
   FRIEND_TEST(SystemProxyAdaptorTest, ConnectNamespace);
   FRIEND_TEST(SystemProxyAdaptorTest, ProxyResolutionFilter);
+  FRIEND_TEST(SystemProxyAdaptorTest, ProtectionSpaceAuthenticationRequired);
+  FRIEND_TEST(SystemProxyAdaptorTest, ProtectionSpaceNoCredentials);
 
   void SetCredentialsTask(SandboxedWorker* worker,
-                          const std::string& username,
-                          const std::string& password);
+                          const worker::Credentials& credentials);
 
   void SetKerberosEnabledTask(SandboxedWorker* worker,
                               bool kerberos_enabled,