summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPale Moon <git-repo@palemoon.org>2016-09-22 23:02:34 +0200
committerPale Moon <git-repo@palemoon.org>2016-09-22 23:02:34 +0200
commit6fbd0de33e0ced5ff3e712d9459eb231b660e67a (patch)
tree64e3c740b7980854b189e6a2fccc4eab711e8f7c
parentea8b1300efa1091c051ccfb807805af881d499ea (diff)
downloadpalemoon-gre-6fbd0de33e0ced5ff3e712d9459eb231b660e67a.tar.gz
Only specify file type when a file is present in DataTransfer.
-rw-r--r--dom/events/DataTransfer.cpp64
-rw-r--r--dom/events/DataTransfer.h2
2 files changed, 39 insertions, 27 deletions
diff --git a/dom/events/DataTransfer.cpp b/dom/events/DataTransfer.cpp
index 639702b2f..56e7079d7 100644
--- a/dom/events/DataTransfer.cpp
+++ b/dom/events/DataTransfer.cpp
@@ -326,25 +326,8 @@ DataTransfer::GetFiles(nsIDOMFileList** aFileList)
already_AddRefed<DOMStringList>
DataTransfer::Types()
{
- nsRefPtr<DOMStringList> types = new DOMStringList();
- if (mItems.Length()) {
- bool addFile = false;
- const nsTArray<TransferItem>& item = mItems[0];
- for (uint32_t i = 0; i < item.Length(); i++) {
- const nsString& format = item[i].mFormat;
- types->Add(format);
- if (!addFile) {
- addFile = format.EqualsASCII(kFileMime) ||
- format.EqualsASCII("application/x-moz-file-promise");
- }
- }
-
- if (addFile) {
- types->Add(NS_LITERAL_STRING("Files"));
- }
- }
-
- return types.forget();
+ ErrorResult rv;
+ return MozTypesAt(0, rv);
}
NS_IMETHODIMP
@@ -524,7 +507,7 @@ DataTransfer::GetMozSourceNode(nsIDOMNode** aSourceNode)
}
already_AddRefed<DOMStringList>
-DataTransfer::MozTypesAt(uint32_t aIndex, ErrorResult& aRv)
+DataTransfer::MozTypesAt(uint32_t aIndex, ErrorResult& aRv) const
{
// Only the first item is valid for clipboard events
if (aIndex > 0 &&
@@ -535,10 +518,28 @@ DataTransfer::MozTypesAt(uint32_t aIndex, ErrorResult& aRv)
nsRefPtr<DOMStringList> types = new DOMStringList();
if (aIndex < mItems.Length()) {
+ bool addFile = false;
// note that you can retrieve the types regardless of their principal
- nsTArray<TransferItem>& item = mItems[aIndex];
- for (uint32_t i = 0; i < item.Length(); i++)
- types->Add(item[i].mFormat);
+ const nsTArray<TransferItem>& item = mItems[aIndex];
+ for (uint32_t i = 0; i < item.Length(); i++) {
+ const nsString& format = item[i].mFormat;
+ types->Add(format);
+ if (!addFile) {
+ addFile = format.EqualsASCII(kFileMime);
+ }
+ }
+
+ if (addFile) {
+ // If this is a content caller, and a file is in the data transfer, remove
+ // the non-file types. This prevents alternate text forms of the file
+ // from being returned.
+ if (!nsContentUtils::IsCallerChrome()) {
+ types->Clear();
+ types->Add(NS_LITERAL_STRING(kFileMime));
+ }
+
+ types->Add(NS_LITERAL_STRING("Files"));
+ }
}
return types.forget();
@@ -572,12 +573,23 @@ DataTransfer::MozGetDataAt(const nsAString& aFormat, uint32_t aIndex,
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}
-
nsAutoString format;
GetRealFormat(aFormat, format);
nsTArray<TransferItem>& item = mItems[aIndex];
+ // If this is a content caller, and a file is in the data transfer, only
+ // return the file type.
+ if (!format.EqualsLiteral(kFileMime) &&
+ !nsContentUtils::IsSystemPrincipal(nsContentUtils::SubjectPrincipal())) {
+ uint32_t count = item.Length();
+ for (uint32_t i = 0; i < count; i++) {
+ if (item[i].mFormat.EqualsLiteral(kFileMime)) {
+ return NS_OK;
+ }
+ }
+ }
+
// Check if the caller is allowed to access the drag data. Callers with
// chrome privileges can always read the data. During the
// drop event, allow retrieving the data except in the case where the
@@ -685,8 +697,8 @@ DataTransfer::MozSetDataAt(const nsAString& aFormat, nsIVariant* aData,
// Don't allow non-chrome to add non-string or file data. We block file
// promises as well which are used internally for drags to the desktop.
if (!nsContentUtils::IsCallerChrome()) {
- if (aFormat.EqualsLiteral("application/x-moz-file-promise") ||
- aFormat.EqualsLiteral("application/x-moz-file")) {
+ if (aFormat.EqualsLiteral(kFilePromiseMime) ||
+ aFormat.EqualsLiteral(kFileMime)) {
return NS_ERROR_DOM_SECURITY_ERR;
}
diff --git a/dom/events/DataTransfer.h b/dom/events/DataTransfer.h
index 68d9ae849..b6d5e3eba 100644
--- a/dom/events/DataTransfer.h
+++ b/dom/events/DataTransfer.h
@@ -158,7 +158,7 @@ public:
}
}
already_AddRefed<DOMStringList> MozTypesAt(uint32_t aIndex,
- mozilla::ErrorResult& aRv);
+ mozilla::ErrorResult& aRv) const;
void MozClearDataAt(const nsAString& aFormat, uint32_t aIndex,
mozilla::ErrorResult& aRv);
void MozSetDataAt(JSContext* aCx, const nsAString& aFormat,