Bug 1805492 - Avoid firing WebExtension content script error on the content window. r=evilpie

I'm also removing AssociatedWindowOrNull as this was the only usage of it.

Differential Revision: https://phabricator.services.mozilla.com/D164608
This commit is contained in:
Alexandre Poirot 2022-12-21 17:35:51 +00:00
parent 68e935a7d0
commit 7dc932df03
3 changed files with 10 additions and 22 deletions

View File

@ -515,14 +515,19 @@ void AutoJSAPI::ReportException() {
if (mIsMainThread) {
RefPtr<xpc::ErrorReport> xpcReport = new xpc::ErrorReport();
// We aren't using WindowOrNull as we also want to match web extension
// content scripts against the related window their sandbox executes
// against.
RefPtr<nsGlobalWindowInner> inner =
xpc::AssociatedWindowOrNull(errorGlobal, cx());
RefPtr<nsGlobalWindowInner> inner = xpc::WindowOrNull(errorGlobal);
// For WebExtension content script, `WindowOrNull` method will return
// null, whereas we would still like to flag the exception with the
// related WindowGlobal the content script executed against. So we only
// update the `innerWindowID` and not `inner` as we don't want to dispatch
// exceptions caused by the content script to the webpage.
uint64_t innerWindowID = 0;
if (inner) {
innerWindowID = inner->WindowID();
} else if (nsGlobalWindowInner* win = xpc::SandboxWindowOrNull(
JS::GetNonCCWObjectGlobal(errorGlobal), cx())) {
innerWindowID = win->WindowID();
}
bool isChrome =

View File

@ -627,14 +627,6 @@ nsGlobalWindowInner* WindowGlobalOrNull(JSObject* aObj) {
return WindowOrNull(glob);
}
nsGlobalWindowInner* AssociatedWindowOrNull(JSObject* aObj, JSContext* aCx) {
nsGlobalWindowInner* win = WindowOrNull(aObj);
if (win) {
return win;
}
return SandboxWindowOrNull(JS::GetNonCCWObjectGlobal(aObj), aCx);
}
nsGlobalWindowInner* SandboxWindowOrNull(JSObject* aObj, JSContext* aCx) {
MOZ_ASSERT(aObj);

View File

@ -553,15 +553,6 @@ nsGlobalWindowInner* WindowOrNull(JSObject* aObj);
*/
nsGlobalWindowInner* WindowGlobalOrNull(JSObject* aObj);
/**
* If |aObj| is a window, returns the associated nsGlobalWindow,
* or, if |aObj| is a Sandbox associated with a DOMWindow via a
* sandboxPrototype, then return that DOMWindow. Otherwise, returns null.
*
* |aCx| is used for checked unwrapping of the Window.
*/
nsGlobalWindowInner* AssociatedWindowOrNull(JSObject* aObj, JSContext* aCx);
/**
* If |aObj| is a Sandbox object associated with a DOMWindow via a
* sandboxPrototype, then return that DOMWindow.