Remove language structure assumptions in bolding logic.

Previously, origin bolding happened by identifying the first space character and making all characters up to that location bold. This means the first word is boldened. This assumption is incorrect, as in some languages the first word is not the origin.

Low coverage due to moving of untested code (Clank prompt creation for SA).

Low-Coverage-Reason: OTHER
Bug: 1512613
Change-Id: I925a2efb9986a0ee365e13ab4e59ce4e545c9b6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5130192
Reviewed-by: Balazs Engedy <[email protected]>
Commit-Queue: Florian Jacky <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1247048}
diff --git a/components/permissions/permission_request.h b/components/permissions/permission_request.h
index cb11a9d..31b7605 100644
--- a/components/permissions/permission_request.h
+++ b/components/permissions/permission_request.h
@@ -21,7 +21,6 @@
 
 namespace permissions {
 enum class RequestType;
-
 // Describes the interface a feature making permission requests should
 // implement. A class of this type is registered with the permission request
 // manager to receive updates about the result of the permissions request
@@ -87,8 +86,33 @@
   virtual bool IsDuplicateOf(PermissionRequest* other_request) const;
 
 #if BUILDFLAG(IS_ANDROID)
+  // A message text with formatting information.
+  struct AnnotatedMessageText {
+    // |text| specifies the text string itself.
+    // |bolded_ranges| defines a (potentially empty) list of ranges represented
+    // as pairs of <textOffset, rangeSize>, which shall be used by the UI to
+    // format the specified ranges as bold text.
+    AnnotatedMessageText(std::u16string text,
+                         std::vector<std::pair<size_t, size_t>> bolded_ranges);
+    ~AnnotatedMessageText();
+    AnnotatedMessageText(const AnnotatedMessageText& other) = delete;
+    AnnotatedMessageText& operator=(const AnnotatedMessageText& other) = delete;
+
+    std::u16string text;
+
+    // A list of ranges defined as pairs of <offset, size> which
+    // will be used by Clank to format the ranges in |text| as bold.
+    std::vector<std::pair<size_t, size_t>> bolded_ranges;
+  };
+
+  virtual AnnotatedMessageText GetDialogAnnotatedMessageText(
+      const GURL& embedding_origin) const;
+
   // Returns prompt text appropriate for displaying in an Android dialog.
-  virtual std::u16string GetDialogMessageText() const;
+  static AnnotatedMessageText GetDialogAnnotatedMessageText(
+      std::u16string requesting_origin_formatted_for_display,
+      int message_id,
+      bool format_origin_bold);
 #endif
 
   // Returns a weak pointer to this instance.