FileSystemContentTypeGuess.cpp (977B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "FileSystemContentTypeGuess.h" 8 9 #include "ErrorList.h" 10 #include "mozilla/dom/QMResult.h" 11 #include "mozilla/dom/mime_guess_ffi_generated.h" 12 #include "mozilla/dom/quota/QuotaCommon.h" 13 #include "mozilla/dom/quota/ResultExtensions.h" 14 #include "nsString.h" 15 16 namespace mozilla::dom::fs { 17 18 Result<ContentType, QMResult> FileSystemContentTypeGuess::FromPath( 19 const Name& aPath) { 20 NS_ConvertUTF16toUTF8 path(aPath); 21 ContentType contentType; 22 nsresult rv = mimeGuessFromPath(&path, &contentType); 23 24 // QM_TRY is too verbose. 25 if (NS_FAILED(rv)) { 26 return Err(QMResult(rv)); 27 } 28 29 return contentType; 30 } 31 32 } // namespace mozilla::dom::fs