Move basic CreateChooserTitle to //components/permissions

The extensions-specific code stays in chrome, while the non-extensions
code is moved. This will enable weblayer to reuse it.

Bug: 1076462
Change-Id: Ica8a3b7863759a9f282dc1bb298c8fdd5ccd83a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3007957
Commit-Queue: Michael van Ouwerkerk <[email protected]>
Reviewed-by: Colin Blundell <[email protected]>
Cr-Commit-Position: refs/heads/master@{#899988}
diff --git a/chrome/browser/chooser_controller/title_util.cc b/chrome/browser/chooser_controller/title_util.cc
index 4f5fe3f..4b93e85 100644
--- a/chrome/browser/chooser_controller/title_util.cc
+++ b/chrome/browser/chooser_controller/title_util.cc
@@ -5,7 +5,7 @@
 #include "chrome/browser/chooser_controller/title_util.h"
 
 #include "base/strings/utf_string_conversions.h"
-#include "components/url_formatter/elide_url.h"
+#include "components/permissions/chooser_title_util.h"
 #include "content/public/browser/render_frame_host.h"
 #include "content/public/browser/web_contents.h"
 #include "extensions/buildflags/buildflags.h"
@@ -17,15 +17,15 @@
 #include "extensions/common/constants.h"
 #endif
 
-std::u16string CreateChooserTitle(content::RenderFrameHost* render_frame_host,
-                                  int title_string_id_origin,
-                                  int title_string_id_extension) {
+std::u16string CreateExtensionAwareChooserTitle(
+    content::RenderFrameHost* render_frame_host,
+    int title_string_id_origin,
+    int title_string_id_extension) {
   if (!render_frame_host)
     return u"";
 
-  url::Origin origin = render_frame_host->GetLastCommittedOrigin();
-
 #if BUILDFLAG(ENABLE_EXTENSIONS)
+  url::Origin origin = render_frame_host->GetLastCommittedOrigin();
   if (origin.scheme() == extensions::kExtensionScheme) {
     content::WebContents* web_contents =
         content::WebContents::FromRenderFrameHost(render_frame_host);
@@ -44,8 +44,6 @@
   }
 #endif
 
-  return l10n_util::GetStringFUTF16(
-      title_string_id_origin,
-      url_formatter::FormatOriginForSecurityDisplay(
-          origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
+  return permissions::CreateChooserTitle(render_frame_host,
+                                         title_string_id_origin);
 }