Bug: Findbar auto case sensitivity doesn't work in PDF viewer pages
Status: NEW
Priority: P3
Created: 2024-02-16 03:22:14+00:00
Resolved: 2024-03-04 21:13:04+00:00

#### Steps to reproduce the problem:
1. Set `accessibility.typeaheadfind.casesensitive` to `2` (this sets it to [auto](https://searchfox.org/mozilla-central/rev/a7809ff8b0a6d98e6df3183d3ca99c77ef2f983e/modules/libpref/init/all.js#547-551))
2. Open any PDF file with text
3. Open the findbar (Ctrl+F)
4. Look for a string in the PDF that has uppercase letters. For example, in my testing, I found the word "MAP" in my PDF
5. For the string you found, type it into the findbar, but lowercase. So for the word "MAP", I searched "map"

#### What is the expected behavior?
The finder should find uppercase instances of the string you typed into the findbar

#### What went wrong?
The finder does not find uppercase instances. It behaves as if case sensitivity is set to `1` (sensitive) — and in fact, it effectively is. You can test this by opening the browser console while the PDF viewer tab is active, and entering `gFindBar.browser.finder._caseSensitive` into the console. It returns `true`, which is incorrect.

Case sensitivity is supposed to work [like this](https://searchfox.org/mozilla-central/rev/a7809ff8b0a6d98e6df3183d3ca99c77ef2f983e/toolkit/content/widgets/findbar.js#815-824). When the pref is set to 2, it should be insensitive by default, and only be sensitive when there are uppercase letters in the findbar search string. And in these STR, we typed a lowercase string into the findbar, so it should be insensitive. On normal tabs (not PDF viewer), if you repeat those steps, it returns `false`. So this problem is specific to the PDF viewer.

The [PDFJs actor](https://searchfox.org/mozilla-central/rev/a7809ff8b0a6d98e6df3183d3ca99c77ef2f983e/toolkit/components/pdfjs/content/PdfjsParent.sys.mjs#196) and [viewer.mjs](https://searchfox.org/mozilla-central/rev/a7809ff8b0a6d98e6df3183d3ca99c77ef2f983e/toolkit/components/pdfjs/content/web/viewer.mjs#3650) have special finder handling, so I suspect the issue is in there. It seems like the viewer.mjs code reads the `checked` state of the findbar's checkboxes, rather than reading the [internal state](https://searchfox.org/mozilla-central/rev/a7809ff8b0a6d98e6df3183d3ca99c77ef2f983e/toolkit/content/widgets/findbar.js#576) of the browser's [Finder](https://searchfox.org/mozilla-central/rev/a7809ff8b0a6d98e6df3183d3ca99c77ef2f983e/toolkit/modules/Finder.sys.mjs#151-157) instance. So that might be related. But if that was the only issue, I would still expect "auto" not to work, but I would expect it to always behave _insensitively_, since the checkbox is not checked; but instead, the opposite is happening: it is always case _sensitive_, no matter what is typed in the findbar.

Thank you! Let me know if you need any more info from me. I am happy to help with debugging.

Edit: By the way, I don't have an easy way of testing this, but I suspect the same problem might be happening with "Match Diacritics." Unlike "Highlight All" and "Whole Words," the "Case Sensitive" and "Match Diacritics" settings are not boolean; they have 3 possible values: on, off, and auto/smart. Their behavior is [very similar](https://searchfox.org/mozilla-central/rev/a7809ff8b0a6d98e6df3183d3ca99c77ef2f983e/modules/libpref/init/all.js#547-551,569-573):

- 0 = ignore case/diacritics
- 1 = match case/diacritics
- 2 = ignore case/diacritics in the content unless the search string contains uppercase/diacritics

So if there's a problem with `accessibility.typeaheadfind.casesensitive = 2`, then I'd also double check for a problem with `findbar.matchdiacritics = 2`