Commit dc725cd5 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

[quickview] Render text files as UTF-8

For files that are known to be text: convert them to a UTF-8 blob, and
use it to source the <webview src="params.contentUrl"> to convince the
<webview> to render UTF-8 (issue 1064855). A follow-up change will add
test coverage.

Files that are not known to be text (issue 772600): continue to render
as before (no UTF-8 support), using the default "browsable" code. This
code is already covered by our test system. Store task verb in a local
variable to aid debugging. Remove local |browsable| variable.

Bug: 1064855
No-try: true
Change-Id: Ic2cb580a97d25d2c90d95a72a954b6aa33b4c6a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2425551
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarJeremie Boulic <jboulic@chromium.org>
Reviewed-by: default avatarFrançois Degros <fdegros@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809732}
parent 563a96d7
...@@ -603,16 +603,40 @@ class QuickViewController { ...@@ -603,16 +603,40 @@ class QuickViewController {
} else { } else {
break; break;
} }
case 'text':
if (typeInfo.subtype === 'TXT') {
return file
.text() // Convert file content to utf-8.
.then(text => {
return new Blob(
[text], {type: 'text/plain;charset=utf-8'});
})
.then(blob => {
params.contentUrl = URL.createObjectURL(blob);
params.browsable = true;
return params;
})
.catch(e => {
console.error(e);
return params;
});
} else {
break;
}
} }
const browsable = tasks.some(task => {
return ['view-in-browser', 'view-pdf'].includes( params.browsable = tasks.some(task => {
task.taskId.split('|')[2]); const verb = task.taskId.split('|')[2];
return ['view-in-browser', 'view-pdf'].includes(verb);
}); });
params.browsable = browsable;
params.contentUrl = browsable ? URL.createObjectURL(file) : ''; if (params.browsable) {
if (params.subtype == 'PDF') { params.contentUrl = URL.createObjectURL(file);
params.contentUrl += '#view=FitH'; if (params.subtype === 'PDF') {
params.contentUrl += '#view=FitH';
}
} }
return params; return params;
}) })
.catch(e => { .catch(e => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment