[XML Parser] Allow preserving whitespace when parsing XML

data_decoder::XmlParser is used to parse XML to JSON from C++, and is
used to parse XML (in a separate, sandboxed process) from the browser.
However, it does not preserve whitespace when parsing XML. This works
for most appplications, but will not for use in the extensions omnibox
API, which allows extensions to pass a string with XML-like markup in
order to style content to show in omnibox suggestions. For instance, an
extension may pass the string:

<match>Open</match> <url>http://example.com</url>?

In order to specify that "Open" should be styled as an omnibox match
and "http://example.com" should be styled as a URL. However, if the
whitespace is omitted, this collapses down to "Openhttp://example.com",
because the inner whitespace text node is not included in the parse.

Adjust the XmlParser in data_decoder (both the C++ implementation and
the mojom interface) to allow specification of whitespace behavior and
let callers specify that whitespace should be preserved (this also
requires introducing a new method on the XmlReader in libxml). Update
all existing callers to pass kIgnore, which matches the current
behavior, except the extension omnibox API's suggestion parsing. Add
unit tests for the XML parsing and update the extension API's unittest.

Bug: 1186804
Change-Id: I81b64bc67124cd6e86abd7e0dcdd23f7f6816f39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3462550
Reviewed-by: Stephen Chenney <schenney@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: Vasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: Nicolas Ouellet-Payeur <nicolaso@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: David Tseng <dtseng@chromium.org>
Commit-Queue: Devlin Cronin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#971954}
NOKEYCHECK=True
GitOrigin-RevId: 1dca394cb0656a10018382695072a7fada791a5a
2 files changed