Bug 1822873 - Avoid mainthread IO in PathUtils.toFileURI r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D173330
This commit is contained in:
Abhishek Tiwari 2023-06-09 19:18:07 +00:00
parent 82c4d9ad65
commit 3e23e936ef
3 changed files with 7 additions and 11 deletions

View File

@ -28,6 +28,7 @@
#include "nsLocalFile.h" #include "nsLocalFile.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsString.h" #include "nsString.h"
#include "nsURLHelper.h"
#include "xpcpublic.h" #include "xpcpublic.h"
namespace mozilla::dom { namespace mozilla::dom {
@ -397,13 +398,8 @@ void PathUtils::ToFileURI(const GlobalObject&, const nsAString& aPath,
return; return;
} }
nsCOMPtr<nsIURI> uri; if (nsresult rv = net_GetURLSpecFromActualFile(path, aResult);
if (nsresult rv = NS_NewFileURI(getter_AddRefs(uri), path); NS_FAILED(rv)) { NS_FAILED(rv)) {
ThrowError(aErr, rv, "Could not initialize File URI"_ns);
return;
}
if (nsresult rv = uri->GetSpec(aResult); NS_FAILED(rv)) {
ThrowError(aErr, rv, "Could not retrieve URI spec"_ns); ThrowError(aErr, rv, "Could not retrieve URI spec"_ns);
return; return;
} }

View File

@ -528,13 +528,13 @@
if (Services.appinfo.OS === "WINNT") { if (Services.appinfo.OS === "WINNT") {
is( is(
PathUtils.toFileURI("C:\\"), PathUtils.toFileURI("C:\\"),
"file:///C:/", "file:///C:",
"PathUtils.toFileURI() with a root path" "PathUtils.toFileURI() with a root path"
); );
is( is(
PathUtils.toFileURI("C:\\Windows\\"), PathUtils.toFileURI("C:\\Windows\\"),
"file:///C:/Windows/", "file:///C:/Windows",
"PathUtils.toFileURI() with a non-root directory path" "PathUtils.toFileURI() with a non-root directory path"
); );
@ -552,7 +552,7 @@
is( is(
PathUtils.toFileURI("/bin"), PathUtils.toFileURI("/bin"),
"file:///bin/", "file:///bin",
"PathUtils.toFileURI() with a non-root directory path" "PathUtils.toFileURI() with a non-root directory path"
); );

View File

@ -153,7 +153,7 @@ add_task(async function test_download_writes_file_in_profile() {
Assert.equal( Assert.equal(
fileURL, fileURL,
PROFILE_URL + "settings/main/some-collection/test_file.pem" PROFILE_URL + "/settings/main/some-collection/test_file.pem"
); );
Assert.ok(await IOUtils.exists(localFilePath)); Assert.ok(await IOUtils.exists(localFilePath));
const stat = await IOUtils.stat(localFilePath); const stat = await IOUtils.stat(localFilePath);