Bug 1472491: Part 1 - Add [ChromeOnly] wantUntrusted event listener option. r=bz

This is the same as the non-standard 4th addEventListener argument, but in a
more standard place. Aside from being easier for readers to understand, this
makes it much easier to define a set of DOM events an IPC actor needs to
handle, without adding extra hacks to handle untrusted listeners.

MozReview-Commit-ID: H6KxjSHtQrY

--HG--
extra : rebase_source : 2d07a77f0cc22df59e19740d8ef538da06e763d3
This commit is contained in:
Kris Maglione 2018-07-29 18:51:00 -07:00
parent f1e256e606
commit 57d6fb6016
3 changed files with 17 additions and 3 deletions

View File

@ -29,8 +29,16 @@ EventTarget::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
bool
EventTarget::ComputeWantsUntrusted(const Nullable<bool>& aWantsUntrusted,
const AddEventListenerOptionsOrBoolean* aOptions,
ErrorResult& aRv)
{
if (aOptions && aOptions->IsAddEventListenerOptions()) {
const auto& options = aOptions->GetAsAddEventListenerOptions();
if (options.mWantUntrusted.WasPassed()) {
return options.mWantUntrusted.Value();
}
}
if (!aWantsUntrusted.IsNull()) {
return aWantsUntrusted.Value();
}
@ -50,7 +58,7 @@ EventTarget::AddEventListener(const nsAString& aType,
const Nullable<bool>& aWantsUntrusted,
ErrorResult& aRv)
{
bool wantsUntrusted = ComputeWantsUntrusted(aWantsUntrusted, aRv);
bool wantsUntrusted = ComputeWantsUntrusted(aWantsUntrusted, &aOptions, aRv);
if (aRv.Failed()) {
return;
}
@ -71,7 +79,7 @@ EventTarget::AddEventListener(const nsAString& aType,
const Nullable<bool>& aWantsUntrusted)
{
ErrorResult rv;
bool wantsUntrusted = ComputeWantsUntrusted(aWantsUntrusted, rv);
bool wantsUntrusted = ComputeWantsUntrusted(aWantsUntrusted, nullptr, rv);
if (rv.Failed()) {
return rv.StealNSResult();
}
@ -112,7 +120,7 @@ EventTarget::AddSystemEventListener(const nsAString& aType,
const Nullable<bool>& aWantsUntrusted)
{
ErrorResult rv;
bool wantsUntrusted = ComputeWantsUntrusted(aWantsUntrusted, rv);
bool wantsUntrusted = ComputeWantsUntrusted(aWantsUntrusted, nullptr, rv);
if (rv.Failed()) {
return rv.StealNSResult();
}

View File

@ -289,8 +289,12 @@ protected:
/**
* A method to compute the right wantsUntrusted value for AddEventListener.
* This will call the above hook as needed.
*
* If aOptions is non-null, and it contains a value for mWantUntrusted, that
* value takes precedence over aWantsUntrusted.
*/
bool ComputeWantsUntrusted(const Nullable<bool>& aWantsUntrusted,
const AddEventListenerOptionsOrBoolean* aOptions,
ErrorResult& aRv);
/**

View File

@ -21,6 +21,8 @@ dictionary EventListenerOptions {
dictionary AddEventListenerOptions : EventListenerOptions {
boolean passive;
boolean once = false;
[ChromeOnly]
boolean wantUntrusted;
};
[Constructor,