summaryrefslogtreecommitdiffstats
path: root/netwerk/protocol/data
diff options
context:
space:
mode:
Diffstat (limited to 'netwerk/protocol/data')
-rw-r--r--netwerk/protocol/data/nsDataChannel.cpp5
-rw-r--r--netwerk/protocol/data/nsDataChannel.h4
-rw-r--r--netwerk/protocol/data/nsDataHandler.cpp13
-rw-r--r--netwerk/protocol/data/nsDataHandler.h3
4 files changed, 13 insertions, 12 deletions
diff --git a/netwerk/protocol/data/nsDataChannel.cpp b/netwerk/protocol/data/nsDataChannel.cpp
index 87b00adea3..df40971e1c 100644
--- a/netwerk/protocol/data/nsDataChannel.cpp
+++ b/netwerk/protocol/data/nsDataChannel.cpp
@@ -8,6 +8,7 @@
#include "nsDataChannel.h"
#include "mozilla/Base64.h"
+#include "mozilla/dom/MimeType.h"
#include "nsDataHandler.h"
#include "nsIInputStream.h"
#include "nsEscape.h"
@@ -59,9 +60,10 @@ nsresult nsDataChannel::OpenContentStream(bool async, nsIInputStream** result,
nsCString contentType, contentCharset;
nsDependentCSubstring dataRange;
+ RefPtr<CMimeType> fullMimeType;
bool lBase64;
rv = nsDataHandler::ParsePathWithoutRef(path, contentType, &contentCharset,
- lBase64, &dataRange, &mMimeType);
+ lBase64, &dataRange, &fullMimeType);
if (NS_FAILED(rv)) return rv;
// This will avoid a copy if nothing needs to be unescaped.
@@ -103,6 +105,7 @@ nsresult nsDataChannel::OpenContentStream(bool async, nsIInputStream** result,
SetContentType(contentType);
SetContentCharset(contentCharset);
+ SetFullMimeType(std::move(fullMimeType));
mContentLength = contentLen;
// notify "data-channel-opened" observers
diff --git a/netwerk/protocol/data/nsDataChannel.h b/netwerk/protocol/data/nsDataChannel.h
index d7313d66a0..f7700ff2b4 100644
--- a/netwerk/protocol/data/nsDataChannel.h
+++ b/netwerk/protocol/data/nsDataChannel.h
@@ -16,14 +16,10 @@ class nsDataChannel : public nsBaseChannel {
public:
explicit nsDataChannel(nsIURI* uri) { SetURI(uri); }
- const nsACString& MimeType() const { return mMimeType; }
-
protected:
[[nodiscard]] virtual nsresult OpenContentStream(
bool async, nsIInputStream** result, nsIChannel** channel) override;
- nsCString mMimeType;
-
private:
nsresult MaybeSendDataChannelOpenNotification();
};
diff --git a/netwerk/protocol/data/nsDataHandler.cpp b/netwerk/protocol/data/nsDataHandler.cpp
index d3a5743097..adb86bf484 100644
--- a/netwerk/protocol/data/nsDataHandler.cpp
+++ b/netwerk/protocol/data/nsDataHandler.cpp
@@ -161,7 +161,7 @@ nsresult nsDataHandler::ParsePathWithoutRef(const nsACString& aPath,
nsCString* aContentCharset,
bool& aIsBase64,
nsDependentCSubstring* aDataBuffer,
- nsCString* aMimeType) {
+ RefPtr<CMimeType>* aMimeType) {
static constexpr auto kCharset = "charset"_ns;
// This implements https://fetch.spec.whatwg.org/#data-url-processor
@@ -200,18 +200,18 @@ nsresult nsDataHandler::ParsePathWithoutRef(const nsACString& aPath,
// This also checks for instances of ;base64 in the middle of the MimeType.
// This is against the current spec, but we're doing it because we have
// historically seen webcompat issues relying on this (see bug 781693).
- if (mozilla::UniquePtr<CMimeType> parsed = CMimeType::Parse(mimeType)) {
+ if (RefPtr<CMimeType> parsed = CMimeType::Parse(mimeType)) {
parsed->GetEssence(aContentType);
if (aContentCharset) {
parsed->GetParameterValue(kCharset, *aContentCharset);
}
- if (aMimeType) {
- parsed->Serialize(*aMimeType);
- }
if (parsed->IsBase64() &&
!StaticPrefs::network_url_strict_data_url_base64_placement()) {
aIsBase64 = true;
}
+ if (aMimeType) {
+ *aMimeType = std::move(parsed);
+ }
} else {
// "If mimeTypeRecord is failure, then set mimeTypeRecord to
// text/plain;charset=US-ASCII."
@@ -220,7 +220,8 @@ nsresult nsDataHandler::ParsePathWithoutRef(const nsACString& aPath,
aContentCharset->AssignLiteral("US-ASCII");
}
if (aMimeType) {
- aMimeType->AssignLiteral("text/plain;charset=US-ASCII");
+ *aMimeType = new CMimeType("text"_ns, "plain"_ns);
+ (*aMimeType)->SetParameterValue("charset"_ns, "US-ASCII"_ns);
}
}
diff --git a/netwerk/protocol/data/nsDataHandler.h b/netwerk/protocol/data/nsDataHandler.h
index 4796f0f453..499e73b220 100644
--- a/netwerk/protocol/data/nsDataHandler.h
+++ b/netwerk/protocol/data/nsDataHandler.h
@@ -6,6 +6,7 @@
#ifndef nsDataHandler_h___
#define nsDataHandler_h___
+#include "mozilla/dom/MimeType.h"
#include "nsIProtocolHandler.h"
#include "nsWeakReference.h"
@@ -50,7 +51,7 @@ class nsDataHandler : public nsIProtocolHandler,
[[nodiscard]] static nsresult ParsePathWithoutRef(
const nsACString& aPath, nsCString& aContentType,
nsCString* aContentCharset, bool& aIsBase64,
- nsDependentCSubstring* aDataBuffer, nsCString* aMimeType = nullptr);
+ nsDependentCSubstring* aDataBuffer, RefPtr<CMimeType>* = nullptr);
};
#endif /* nsDataHandler_h___ */