Handle external protocols with the network service.

Bug: 706030
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: I82f817cae6477e2e2bcbb44f266ae0956e55182a
Reviewed-on: https://chromium-review.googlesource.com/956091
Reviewed-by: Jay Civelli <[email protected]>
Commit-Queue: John Abd-El-Malek <[email protected]>
Cr-Commit-Position: refs/heads/master@{#542156}
diff --git a/chrome/browser/external_protocol/external_protocol_handler.cc b/chrome/browser/external_protocol/external_protocol_handler.cc
index 9faf99f..9bd2997 100644
--- a/chrome/browser/external_protocol/external_protocol_handler.cc
+++ b/chrome/browser/external_protocol/external_protocol_handler.cc
@@ -30,6 +30,8 @@
 // each user gesture. This variable should only be accessed from the UI thread.
 bool g_accept_requests = true;
 
+ExternalProtocolHandler::Delegate* g_delegate = nullptr;
+
 constexpr const char* kDeniedSchemes[] = {
     "afp", "data", "disk", "disks",
     // ShellExecuting file:///C:/WINDOWS/system32/notepad.exe will simply
@@ -144,6 +146,11 @@
     "BrowserDialogs.ExternalProtocol.HandleState";
 
 // static
+void ExternalProtocolHandler::SetDelegateForTesting(Delegate* delegate) {
+  g_delegate = delegate;
+}
+
+// static
 ExternalProtocolHandler::BlockState ExternalProtocolHandler::GetBlockState(
     const std::string& scheme,
     Profile* profile) {
@@ -209,13 +216,11 @@
 }
 
 // static
-void ExternalProtocolHandler::LaunchUrlWithDelegate(
-    const GURL& url,
-    int render_process_host_id,
-    int render_view_routing_id,
-    ui::PageTransition page_transition,
-    bool has_user_gesture,
-    Delegate* delegate) {
+void ExternalProtocolHandler::LaunchUrl(const GURL& url,
+                                        int render_process_host_id,
+                                        int render_view_routing_id,
+                                        ui::PageTransition page_transition,
+                                        bool has_user_gesture) {
   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
 
   // Escape the input scheme to be sure that the command does not
@@ -233,10 +238,10 @@
   if (web_contents)  // Maybe NULL during testing.
     profile = Profile::FromBrowserContext(web_contents->GetBrowserContext());
   BlockState block_state =
-      GetBlockStateWithDelegate(escaped_url.scheme(), delegate, profile);
+      GetBlockStateWithDelegate(escaped_url.scheme(), g_delegate, profile);
   if (block_state == BLOCK) {
-    if (delegate)
-      delegate->BlockRequest();
+    if (g_delegate)
+      g_delegate->BlockRequest();
     return;
   }
 
@@ -247,12 +252,12 @@
   shell_integration::DefaultWebClientWorkerCallback callback = base::Bind(
       &OnDefaultProtocolClientWorkerFinished, escaped_url,
       render_process_host_id, render_view_routing_id, block_state == UNKNOWN,
-      page_transition, has_user_gesture, delegate);
+      page_transition, has_user_gesture, g_delegate);
 
   // Start the check process running. This will send tasks to a worker task
   // runner and when the answer is known will send the result back to
   // OnDefaultProtocolClientWorkerFinished().
-  CreateShellWorker(callback, escaped_url.scheme(), delegate)
+  CreateShellWorker(callback, escaped_url.scheme(), g_delegate)
       ->StartCheckIsDefault();
 }