Bug 1535384 part 1. Eliminate some easy cases of MOZ_CAN_RUN_SCRIPT_BOUNDARY on webidl callbacks. r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D23771

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-03-19 05:24:39 +00:00
parent cdd51a7d35
commit 1c3e10afc5
27 changed files with 53 additions and 35 deletions

View File

@ -460,7 +460,8 @@ void DOMIntersectionObserver::Notify() {
}
}
mQueuedEntries.Clear();
mCallback->Call(this, entries, *this);
RefPtr<dom::IntersectionCallback> callback(mCallback);
callback->Call(this, entries, *this);
}
} // namespace dom

View File

@ -7,6 +7,7 @@
#ifndef DOMIntersectionObserver_h
#define DOMIntersectionObserver_h
#include "mozilla/Attributes.h"
#include "mozilla/dom/IntersectionObserverBinding.h"
#include "nsStyleCoord.h"
#include "nsTArray.h"
@ -132,7 +133,7 @@ class DOMIntersectionObserver final : public nsISupports,
bool SetRootMargin(const nsAString& aString);
void Update(Document* aDocument, DOMHighResTimeStamp time);
void Notify();
MOZ_CAN_RUN_SCRIPT void Notify();
protected:
void Connect();

View File

@ -48,6 +48,7 @@
#include "nsContentListDeclarations.h"
#include "nsExpirationTracker.h"
#include "nsClassHashtable.h"
#include "mozilla/Attributes.h"
#include "mozilla/CORSMode.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/ContentBlockingLog.h"
@ -3487,7 +3488,7 @@ class Document : public nsINode,
void UpdateIntersectionObservations();
void ScheduleIntersectionObserverNotification();
void NotifyIntersectionObservers();
MOZ_CAN_RUN_SCRIPT void NotifyIntersectionObservers();
// Dispatch a runnable related to the document.
nsresult Dispatch(TaskCategory aCategory,

View File

@ -91,20 +91,23 @@ class EncodingCompleteEvent : public CancelableRunnable {
}
}
// MOZ_CAN_RUN_SCRIPT_BOUNDARY until Runnable::Run is MOZ_CAN_RUN_SCRIPT. See
// bug 1535398.
MOZ_CAN_RUN_SCRIPT_BOUNDARY
NS_IMETHOD Run() override {
nsresult rv = NS_OK;
// We want to null out mEncodeCompleteCallback no matter what.
RefPtr<EncodeCompleteCallback> callback(mEncodeCompleteCallback.forget());
if (!mFailed) {
// The correct parentObject has to be set by the mEncodeCompleteCallback.
RefPtr<Blob> blob =
Blob::CreateMemoryBlob(nullptr, mImgData, mImgSize, mType);
MOZ_ASSERT(blob);
rv = mEncodeCompleteCallback->ReceiveBlob(blob.forget());
rv = callback->ReceiveBlob(blob.forget());
}
mEncodeCompleteCallback = nullptr;
return rv;
}

View File

@ -115,6 +115,7 @@ class EncodeCompleteCallback {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EncodeCompleteCallback)
MOZ_CAN_RUN_SCRIPT
virtual nsresult ReceiveBlob(already_AddRefed<Blob> aBlob) = 0;
protected:

View File

@ -1638,6 +1638,7 @@ class nsINode : public mozilla::dom::EventTarget {
void GenerateXPath(nsAString& aResult);
MOZ_CAN_RUN_SCRIPT
already_AddRefed<mozilla::dom::Promise> Localize(
JSContext* aCx, mozilla::dom::L10nCallback& aCallback,
mozilla::ErrorResult& aRv);

View File

@ -31,16 +31,18 @@ void CanvasRenderingContextHelper::ToBlob(
: mGlobal(aGlobal), mBlobCallback(aCallback) {}
// This is called on main thread.
MOZ_CAN_RUN_SCRIPT
nsresult ReceiveBlob(already_AddRefed<Blob> aBlob) override {
RefPtr<Blob> blob = aBlob;
RefPtr<Blob> newBlob = Blob::Create(mGlobal, blob->Impl());
RefPtr<BlobCallback> callback(mBlobCallback.forget());
ErrorResult rv;
mBlobCallback->Call(newBlob, rv);
callback->Call(newBlob, rv);
mGlobal = nullptr;
mBlobCallback = nullptr;
MOZ_ASSERT(!mBlobCallback);
return rv.StealNSResult();
}

View File

@ -8,7 +8,6 @@ interface nsISupports;
/**
* A callback passed to SessionStoreUtils.forEachNonDynamicChildFrame().
*/
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
callback SessionStoreUtilsFrameCallback = void (WindowProxy frame, unsigned long index);
/**

View File

@ -5,7 +5,6 @@
interface URI;
interface WindowProxy;
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
callback WebExtensionLocalizeCallback = DOMString (DOMString unlocalizedText);
/**

View File

@ -7,6 +7,7 @@
#include "DataTransferItem.h"
#include "DataTransferItemList.h"
#include "mozilla/Attributes.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/EventForwards.h"
#include "mozilla/dom/DataTransferItemBinding.h"
@ -430,15 +431,19 @@ void DataTransferItem::GetAsString(FunctionStringCallback* aCallback,
mCallback(aCallback),
mStringData(aStringData) {}
// MOZ_CAN_RUN_SCRIPT_BOUNDARY until runnables are opted into
// MOZ_CAN_RUN_SCRIPT. See bug 1535398.
MOZ_CAN_RUN_SCRIPT_BOUNDARY
NS_IMETHOD Run() override {
ErrorResult rv;
mCallback->Call(mStringData, rv);
// mCallback is const, so we never null it out until our destructor.
MOZ_KnownLive(mCallback)->Call(mStringData, rv);
NS_WARNING_ASSERTION(!rv.Failed(), "callback failed");
return rv.StealNSResult();
}
private:
RefPtr<FunctionStringCallback> mCallback;
const RefPtr<FunctionStringCallback> mCallback;
nsString mStringData;
};

View File

@ -154,8 +154,8 @@ nsresult JSEventHandler::HandleEvent(Event* aEvent) {
mTypedHandler.OnErrorEventHandler();
ErrorResult rv;
JS::Rooted<JS::Value> retval(RootingCx());
handler->Call(mTarget, msgOrEvent, fileName, lineNumber, columnNumber,
error, &retval, rv);
handler->Call(target, msgOrEvent, fileName, lineNumber, columnNumber, error,
&retval, rv);
if (rv.Failed()) {
return rv.StealNSResult();
}
@ -173,7 +173,7 @@ nsresult JSEventHandler::HandleEvent(Event* aEvent) {
mTypedHandler.OnBeforeUnloadEventHandler();
ErrorResult rv;
nsString retval;
handler->Call(mTarget, *aEvent, retval, rv);
handler->Call(target, *aEvent, retval, rv);
if (rv.Failed()) {
return rv.StealNSResult();
}
@ -202,7 +202,7 @@ nsresult JSEventHandler::HandleEvent(Event* aEvent) {
ErrorResult rv;
RefPtr<EventHandlerNonNull> handler = mTypedHandler.NormalEventHandler();
JS::Rooted<JS::Value> retval(RootingCx());
handler->Call(mTarget, *aEvent, &retval, rv);
handler->Call(target, *aEvent, &retval, rv);
if (rv.Failed()) {
return rv.StealNSResult();
}

View File

@ -492,9 +492,11 @@ nsresult HTMLCanvasElement::DispatchPrintCallback(nsITimerCallback* aCallback) {
return OwnerDoc()->Dispatch(TaskCategory::Other, renderEvent.forget());
}
MOZ_CAN_RUN_SCRIPT
void HTMLCanvasElement::CallPrintCallback() {
ErrorResult rv;
GetMozPrintCallback()->Call(*mPrintState, rv);
RefPtr<PrintCallback> callback = GetMozPrintCallback();
RefPtr<HTMLCanvasPrintState> state = mPrintState;
callback->Call(*state);
}
void HTMLCanvasElement::ResetPrintCallback() {

View File

@ -231,7 +231,7 @@ class NotificationPermissionRequest : public ContentPermissionRequestBase,
protected:
~NotificationPermissionRequest() = default;
nsresult ResolvePromise();
MOZ_CAN_RUN_SCRIPT nsresult ResolvePromise();
nsresult DispatchResolvePromise();
NotificationPermission mPermission;
RefPtr<Promise> mPromise;
@ -561,7 +561,8 @@ nsresult NotificationPermissionRequest::ResolvePromise() {
}
if (mCallback) {
ErrorResult error;
mCallback->Call(mPermission, error);
RefPtr<NotificationPermissionCallback> callback(mCallback);
callback->Call(mPermission, error);
rv = error.StealNSResult();
}
mPromise->MaybeResolve(mPermission);

View File

@ -424,9 +424,13 @@ class NotifyObserversTask final : public CancelableRunnable {
MOZ_ASSERT(mPerformance);
}
// MOZ_CAN_RUN_SCRIPT_BOUNDARY for now until Runnable::Run is
// MOZ_CAN_RUN_SCRIPT.
MOZ_CAN_RUN_SCRIPT_BOUNDARY
NS_IMETHOD Run() override {
MOZ_ASSERT(mPerformance);
mPerformance->NotifyObservers();
RefPtr<Performance> performance(mPerformance);
performance->NotifyObservers();
return NS_OK;
}

View File

@ -79,7 +79,7 @@ class Performance : public DOMEventTargetHelper {
void AddObserver(PerformanceObserver* aObserver);
void RemoveObserver(PerformanceObserver* aObserver);
void NotifyObservers();
MOZ_CAN_RUN_SCRIPT void NotifyObservers();
void CancelNotificationObservers();
virtual PerformanceTiming* Timing() = 0;

View File

@ -106,7 +106,8 @@ void PerformanceObserver::Notify() {
mQueuedEntries.Clear();
ErrorResult rv;
mCallback->Call(this, *list, *this, rv);
RefPtr<PerformanceObserverCallback> callback(mCallback);
callback->Call(this, *list, *this, rv);
if (NS_WARN_IF(rv.Failed())) {
rv.SuppressException();
}

View File

@ -55,7 +55,7 @@ class PerformanceObserver final : public nsISupports, public nsWrapperCache {
void TakeRecords(nsTArray<RefPtr<PerformanceEntry>>& aRetval);
void Notify();
MOZ_CAN_RUN_SCRIPT void Notify();
void QueueEntry(PerformanceEntry* aEntry);
private:

View File

@ -17,7 +17,6 @@ interface DataTransferItem {
File? getAsFile();
};
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
callback FunctionStringCallback = void (DOMString data);
// https://wicg.github.io/entries-api/#idl-index

View File

@ -10,15 +10,15 @@
* Opera Software ASA. You are granted a license to use, reproduce
* and create derivative works of this document.
*/
[TreatNonObjectAsNull, MOZ_CAN_RUN_SCRIPT_BOUNDARY]
[TreatNonObjectAsNull]
callback EventHandlerNonNull = any (Event event);
typedef EventHandlerNonNull? EventHandler;
[TreatNonObjectAsNull, MOZ_CAN_RUN_SCRIPT_BOUNDARY]
[TreatNonObjectAsNull]
callback OnBeforeUnloadEventHandlerNonNull = DOMString? (Event event);
typedef OnBeforeUnloadEventHandlerNonNull? OnBeforeUnloadEventHandler;
[TreatNonObjectAsNull, MOZ_CAN_RUN_SCRIPT_BOUNDARY]
[TreatNonObjectAsNull]
callback OnErrorEventHandlerNonNull = any ((Event or DOMString) event, optional DOMString source, optional unsigned long lineno, optional unsigned long column, optional any error);
typedef OnErrorEventHandlerNonNull? OnErrorEventHandler;

View File

@ -66,8 +66,6 @@ interface MozCanvasPrintState
void done();
};
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
callback PrintCallback = void(MozCanvasPrintState ctx);
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
callback BlobCallback = void(Blob? blob);

View File

@ -44,7 +44,6 @@ interface IntersectionObserver {
readonly attribute IntersectionCallback intersectionCallback;
};
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
callback IntersectionCallback =
void (sequence<IntersectionObserverEntry> entries, IntersectionObserver observer);

View File

@ -34,6 +34,5 @@ dictionary L10nValue {
sequence<AttributeNameValue>? attributes = null;
};
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
callback L10nCallback =
Promise<sequence<L10nValue>> (sequence<L10nElement> l10nElements);

View File

@ -88,7 +88,6 @@ enum NotificationPermission {
"granted"
};
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
callback NotificationPermissionCallback = void (NotificationPermission permission);
enum NotificationDirection {

View File

@ -12,7 +12,6 @@ dictionary PerformanceObserverInit {
boolean buffered = false;
};
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
callback PerformanceObserverCallback = void (PerformanceObserverEntryList entries,
PerformanceObserver observer);

View File

@ -439,7 +439,8 @@ nsCString WebExtensionPolicy::BackgroundPageHTML() const {
void WebExtensionPolicy::Localize(const nsAString& aInput,
nsString& aOutput) const {
mLocalizeCallback->Call(aInput, aOutput);
RefPtr<WebExtensionLocalizeCallback> callback(mLocalizeCallback);
callback->Call(aInput, aOutput);
}
JSObject* WebExtensionPolicy::WrapObject(JSContext* aCx,

View File

@ -94,6 +94,7 @@ class WebExtensionPolicy final : public nsISupports,
nsCString BackgroundPageHTML() const;
MOZ_CAN_RUN_SCRIPT
void Localize(const nsAString& aInput, nsString& aResult) const;
const nsString& Name() const { return mName; }

View File

@ -7,6 +7,7 @@
#ifndef mozilla_dom_SessionStoreUtils_h
#define mozilla_dom_SessionStoreUtils_h
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/SessionStoreUtilsBinding.h"
@ -22,6 +23,7 @@ struct SSScrollPositionDict;
class SessionStoreUtils {
public:
MOZ_CAN_RUN_SCRIPT
static void ForEachNonDynamicChildFrame(
const GlobalObject& aGlobal, WindowProxyHolder& aWindow,
SessionStoreUtilsFrameCallback& aCallback, ErrorResult& aRv);