Bug 1666287 - Remove pref dom.datatransfer.mozAtAPIs and make relevant APIs ChromeOnly, r=nika

Make mozItemCount, mozTypesAt, mozClearDataAt, mozSetDataAt, mozGetDataAt
DataTransfer APIs ChromeOnly

Differential Revision: https://phabricator.services.mozilla.com/D91017
This commit is contained in:
Anny Gakhokidze 2020-09-22 16:16:29 +00:00
parent 562a1bf962
commit 5842740ef5
6 changed files with 5 additions and 58 deletions

View File

@ -1540,12 +1540,5 @@ void DataTransfer::SetMode(DataTransfer::Mode aMode) {
}
}
/* static */
bool DataTransfer::MozAtAPIsEnabled(JSContext* aCx, JSObject* aObj /*unused*/) {
// We can expose moz* APIs if we are chrome code or if pref is enabled
return nsContentUtils::IsSystemCaller(aCx) ||
StaticPrefs::dom_datatransfer_mozAtAPIs_DoNotUseDirectly();
}
} // namespace dom
} // namespace mozilla

View File

@ -395,12 +395,6 @@ class DataTransfer final : public nsISupports, public nsWrapperCache {
bool aPlainTextOnly,
nsTArray<nsCString>* aResult);
// Returns true if moz* APIs should be exposed (true for chrome code or if
// dom.datatransfer.moz pref is enabled).
// The affected moz* APIs are mozItemCount, mozTypesAt, mozClearDataAt,
// mozSetDataAt, mozGetDataAt
static bool MozAtAPIsEnabled(JSContext* cx, JSObject* obj);
protected:
// caches text and uri-list data formats that exist in the drag service or
// clipboard for retrieval later.

View File

@ -80,7 +80,6 @@ skip-if = headless # bug 1403542
[test_consoleAPI.html]
[test_contentViewer_overrideDPPX.html]
[test_CCW_optimization.html]
[test_datatransfer_disallowed.html]
[test_devicePixelRatio_with_zoom.html]
[test_DOMMatrix.html]
[test_domWindowUtils.html]

View File

@ -1,31 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for DataTransfer moz* APIs</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script>
function run_test()
{
SpecialPowers.pushPrefEnv({"set": [
["dom.datatransfer.mozAtAPIs", false],
]}, function() {
let hiddenMethods = ["mozTypesAt", "mozClearDataAt", "mozGetDataAt", "mozSetDataAt", "mozItemCount"];
let exposedMethods = Object.getOwnPropertyNames(DataTransfer.prototype);
for (var idx in hiddenMethods) {
if (exposedMethods.includes(hiddenMethods[idx])) {
ok(false, hiddenMethods[idx] + " should not be exposed");
} else {
ok(true, hiddenMethods[idx] + " was not exposed");
}
}
SimpleTest.finish();
});
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(run_test);
</script>

View File

@ -57,7 +57,7 @@ partial interface DataTransfer {
/**
* The number of items being dragged.
*/
[Func="DataTransfer::MozAtAPIsEnabled"]
[ChromeOnly]
readonly attribute unsigned long mozItemCount;
/**
@ -80,7 +80,7 @@ partial interface DataTransfer {
* at the specified index. If the index is not in the range from 0 to
* itemCount - 1, an empty string list is returned.
*/
[Throws, NeedsCallerType, Func="DataTransfer::MozAtAPIsEnabled"]
[Throws, NeedsCallerType, ChromeOnly]
DOMStringList mozTypesAt(unsigned long index);
/**
@ -97,7 +97,7 @@ partial interface DataTransfer {
* @throws NS_ERROR_DOM_INDEX_SIZE_ERR if index is greater or equal than itemCount
* @throws NO_MODIFICATION_ALLOWED_ERR if the item cannot be modified
*/
[Throws, NeedsSubjectPrincipal, Func="DataTransfer::MozAtAPIsEnabled"]
[Throws, NeedsSubjectPrincipal, ChromeOnly]
void mozClearDataAt(DOMString format, unsigned long index);
/*
@ -121,7 +121,7 @@ partial interface DataTransfer {
* @throws NS_ERROR_DOM_INDEX_SIZE_ERR if index is greater than itemCount
* @throws NO_MODIFICATION_ALLOWED_ERR if the item cannot be modified
*/
[Throws, NeedsSubjectPrincipal, Func="DataTransfer::MozAtAPIsEnabled"]
[Throws, NeedsSubjectPrincipal, ChromeOnly]
void mozSetDataAt(DOMString format, any data, unsigned long index);
/**
@ -133,7 +133,7 @@ partial interface DataTransfer {
* @returns the data of the given format, or null if it doesn't exist.
* @throws NS_ERROR_DOM_INDEX_SIZE_ERR if index is greater or equal than itemCount
*/
[Throws, NeedsSubjectPrincipal, Func="DataTransfer::MozAtAPIsEnabled"]
[Throws, NeedsSubjectPrincipal, ChromeOnly]
any mozGetDataAt(DOMString format, unsigned long index);
/**

View File

@ -1572,14 +1572,6 @@
value: false
mirror: always
# Disable moz* APIs in DataTransfer.
# Should be accessed via DataTransfer::MozAtAPIsEnabled.
- name: dom.datatransfer.mozAtAPIs
type: bool
value: false
mirror: always
do_not_use_directly: true
# Any how many seconds we allow external protocol URLs in iframe when not in
# single events
- name: dom.delay.block_external_protocol_in_iframes