mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
fb9b106168
- Bug 1154563 - Drop the unused argument of WorkerPrivate::Close(); r=baku (366f353f9f) - Bug 1178721 - Implement SuspendWorkersForWindow;r=khuey (a49bc9a306) - Bug 1207490 - Part 6: Remove use of expression closure from browser/devtools/. r=vporof (1c4d153319) - Bug 1198982: Don't fail the SW load for an importScripts failure. r=bkelly (948f5dca94) - Bug 1160890 - Part 1: Remove unneeded code from ImportScripts(). r=smaug (e31f7c82eb) - Bug 1160890 - Part 2: ImportScripts() should return muted errors with 3rd party scripts. r=smaug (347e54a605) - Bug 1188141: Make Worker error events not bubble. r=baku (509fd46933) - Bug 1160890, r=smaug (0ce3ee09d6) - Bug 1208687: Only discard events from the outermost queue. r=ehsan (bce722c16b) - Bug 949376 - MessageEvent::initMessageEvent, r=smaug (8878e51c91) - Bug 1214772 - Part 2: Make FetchEvent inherit from ExtendableEvent; r=bzbarsky (edff91f7fb) - Bug 1218131 - Mark FetchEvent.request as SameObject; r=bzbarsky (1f79b94838) - Bug 1188545 - Add tests for service workers' lifetime management. r=nsm (9bac3b9f2d) - Bug 1218135 - Remove FetchEvent.client; r=bzbarsky (e95e4e5326) - Bug 1218151 - Make FetchEventInit.isReload default to false; r=bzbarsky (795d597a3b) - Bug 1218621 - Keep the service worker alive while the promise passed to FetchEvent.respondWith() settles; r=catalinb (653633c136) - Bug 1212636 - Add a better error message for the content corrupcted error caused by the Promise being passed to FetchEvent.respondWith; r=bkelly (d6ebabc2f2) - Bug 1215140 P4 Make service worker respondWith() use channel ConsoleReportCollector. r=bz (0e07f364d4) - Bug 1218499 - Make FetchEvent.request nullable; r=bzbarsky (850630ea6d) - Bug 1179397 - Disallow FetchEvent.respondWith() when the dispatch flag is unset; r=jdm (2e57abf1c6) - Bug 1215140 P5 Report the line number where respondWith() was called. r=bz (484e385ce3) - Bug 1161239 - Emit a warning if the respondWith handler is resolved with a non-Object value; r=baku (cf2779f827) - Bug 1181054 - Part 1: Move FormFillIterator and FormDataParser to FetchUtil.cpp; r=bkelly (9f62174f72) - Bug 1181054 - Part 2: Refactor the code to extract an HTTP header from a buffer from FormDataParser; r=bkelly (7f57f76ce1) - Bug 1181054 - Part 3: Correctly handle upload channels that have embedded body headers when dispatching a FetchEvent; r=bkelly (ebbfac4419) - ug 1181054 - Part 4: Make fetch-event.https.html pass; r=bkelly (b2d88a3f5b) - Bug 1215140 P6 Update service worker interception error strings to include detailed parameters. r=bz (7918278f09) - Bug 1219852 P1 Extract common JS values for rejected respondWith() promises. r=bz (12a6beed6c) - Bug 1219852 P2 Report non-response values passed to FetchEvent.respondWith(). r=bz (69fdad9d5f) - Bug 1207068 - Implement ExtendableMessageEvent interface. r=baku (29fd7c1c59) - Bug 1224061: Make Event::InitEvent infallible. r=smaug Bug 1224061 followup to fix bustage. r=me on a CLOSED TREE IGNORE IDL (b4fc91b14b) - Bug 1205109 - Make pushsubscriptionchange extendable. r=mt (abb45ac864) - Bug 1207491 - Part 8: Remove use of expression closure from browser/omponents/nsBrowserContentHandler.js. r=Gijs (98dcb2cbee) - Bug 1182571: Followup bustage fix from merge fail. CLOSED TREE (5062c88996) - Bug 1213646: Allow URI_IS_UI_RESOURCE and safe about: URIs when SEC_ALLOW_CHROME is set. r=bz (6ca4e2322f) - Bug 1191645 - Use channel->asycnOpen2 in dom/base/nsSyncLoadService.cpp. r=sicking (3fbd471f6b) - Bug 1194526 - Use channel->asycnOpen2 in dom/base/nsScriptLoader.cpp (r=sicking) (7207efa45b) - Bug 1084009 - Part 1/3 - Parse sync scripts off the main thread. r=smaug (72f4d5c749) - Bug 1084009 - Part 2/3 - Only parse scripts off-main-thread on multicore systems. r=luke (ffb7e2270e) - Bug 1209193 - Cache PR_GetNumberOfProcessors when checking to do off-main-thread script compilation. r=luke (c514373ad7) - Bug 663570 - MetaCSP Part 7: CSP preload validation (r=bz) (5398116f85) - Bug 1207863 - Fix ScopeIter iterating a strict eval frame that errored out before its CallObject was allocated. (r=jorendorff) (ae38882b7c) - Bug 1223006 - Fix some typo in spidermonkey's comments. r=nbp (7d49536a0f) - Bug 1223490 - Use stable hashing for InnerViewTable; r=jonco (12b4329982)
387 lines
12 KiB
C++
387 lines
12 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "nsContentUtils.h"
|
|
#include "nsIDocument.h"
|
|
#include "prprf.h"
|
|
#include "nsGlobalWindow.h"
|
|
#include "ScriptSettings.h"
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
|
#include "mozilla/EventDispatcher.h"
|
|
#include "mozilla/EventListenerManager.h"
|
|
#include "mozilla/Likely.h"
|
|
|
|
namespace mozilla {
|
|
|
|
using namespace dom;
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMEventTargetHelper)
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(DOMEventTargetHelper)
|
|
if (MOZ_UNLIKELY(cb.WantDebugInfo())) {
|
|
char name[512];
|
|
nsAutoString uri;
|
|
if (tmp->mOwnerWindow && tmp->mOwnerWindow->GetExtantDoc()) {
|
|
tmp->mOwnerWindow->GetExtantDoc()->GetDocumentURI(uri);
|
|
}
|
|
PR_snprintf(name, sizeof(name), "DOMEventTargetHelper %s",
|
|
NS_ConvertUTF16toUTF8(uri).get());
|
|
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name);
|
|
} else {
|
|
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(DOMEventTargetHelper, tmp->mRefCnt.get())
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mListenerManager)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMEventTargetHelper)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mListenerManager)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(DOMEventTargetHelper)
|
|
if (tmp->IsBlack() || tmp->IsCertainlyAliveForCC()) {
|
|
if (tmp->mListenerManager) {
|
|
tmp->mListenerManager->MarkForCC();
|
|
}
|
|
if (!tmp->IsBlack() && tmp->PreservingWrapper()) {
|
|
// This marks the wrapper black.
|
|
tmp->GetWrapper();
|
|
}
|
|
return true;
|
|
}
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(DOMEventTargetHelper)
|
|
return tmp->IsBlackAndDoesNotNeedTracing(tmp);
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(DOMEventTargetHelper)
|
|
return tmp->IsBlack();
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMEventTargetHelper)
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
|
|
NS_INTERFACE_MAP_ENTRY(dom::EventTarget)
|
|
NS_INTERFACE_MAP_ENTRY(DOMEventTargetHelper)
|
|
NS_INTERFACE_MAP_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMEventTargetHelper)
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(DOMEventTargetHelper,
|
|
LastRelease())
|
|
|
|
NS_IMPL_DOMTARGET_DEFAULTS(DOMEventTargetHelper)
|
|
|
|
DOMEventTargetHelper::~DOMEventTargetHelper()
|
|
{
|
|
if (nsPIDOMWindow* owner = GetOwner()) {
|
|
static_cast<nsGlobalWindow*>(owner)->RemoveEventTargetObject(this);
|
|
}
|
|
if (mListenerManager) {
|
|
mListenerManager->Disconnect();
|
|
}
|
|
ReleaseWrapper(this);
|
|
}
|
|
|
|
void
|
|
DOMEventTargetHelper::BindToOwner(nsPIDOMWindow* aOwner)
|
|
{
|
|
MOZ_ASSERT_IF(aOwner, aOwner->IsInnerWindow());
|
|
nsCOMPtr<nsIGlobalObject> glob = do_QueryInterface(aOwner);
|
|
BindToOwner(glob);
|
|
}
|
|
|
|
void
|
|
DOMEventTargetHelper::BindToOwner(nsIGlobalObject* aOwner)
|
|
{
|
|
nsCOMPtr<nsIGlobalObject> parentObject = do_QueryReferent(mParentObject);
|
|
if (parentObject) {
|
|
if (mOwnerWindow) {
|
|
static_cast<nsGlobalWindow*>(mOwnerWindow)->RemoveEventTargetObject(this);
|
|
mOwnerWindow = nullptr;
|
|
}
|
|
mParentObject = nullptr;
|
|
mHasOrHasHadOwnerWindow = false;
|
|
}
|
|
if (aOwner) {
|
|
mParentObject = do_GetWeakReference(aOwner);
|
|
MOZ_ASSERT(mParentObject, "All nsIGlobalObjects must support nsISupportsWeakReference");
|
|
// Let's cache the result of this QI for fast access and off main thread usage
|
|
mOwnerWindow = nsCOMPtr<nsPIDOMWindow>(do_QueryInterface(aOwner)).get();
|
|
if (mOwnerWindow) {
|
|
MOZ_ASSERT(mOwnerWindow->IsInnerWindow());
|
|
mHasOrHasHadOwnerWindow = true;
|
|
static_cast<nsGlobalWindow*>(mOwnerWindow)->AddEventTargetObject(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
DOMEventTargetHelper::BindToOwner(DOMEventTargetHelper* aOther)
|
|
{
|
|
if (mOwnerWindow) {
|
|
static_cast<nsGlobalWindow*>(mOwnerWindow)->RemoveEventTargetObject(this);
|
|
mOwnerWindow = nullptr;
|
|
mParentObject = nullptr;
|
|
mHasOrHasHadOwnerWindow = false;
|
|
}
|
|
if (aOther) {
|
|
mHasOrHasHadOwnerWindow = aOther->HasOrHasHadOwner();
|
|
if (aOther->GetParentObject()) {
|
|
mParentObject = do_GetWeakReference(aOther->GetParentObject());
|
|
MOZ_ASSERT(mParentObject, "All nsIGlobalObjects must support nsISupportsWeakReference");
|
|
// Let's cache the result of this QI for fast access and off main thread usage
|
|
mOwnerWindow = nsCOMPtr<nsPIDOMWindow>(do_QueryInterface(aOther->GetParentObject())).get();
|
|
if (mOwnerWindow) {
|
|
MOZ_ASSERT(mOwnerWindow->IsInnerWindow());
|
|
mHasOrHasHadOwnerWindow = true;
|
|
static_cast<nsGlobalWindow*>(mOwnerWindow)->AddEventTargetObject(this);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
DOMEventTargetHelper::DisconnectFromOwner()
|
|
{
|
|
mOwnerWindow = nullptr;
|
|
mParentObject = nullptr;
|
|
// Event listeners can't be handled anymore, so we can release them here.
|
|
if (mListenerManager) {
|
|
mListenerManager->Disconnect();
|
|
mListenerManager = nullptr;
|
|
}
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DOMEventTargetHelper::RemoveEventListener(const nsAString& aType,
|
|
nsIDOMEventListener* aListener,
|
|
bool aUseCapture)
|
|
{
|
|
EventListenerManager* elm = GetExistingListenerManager();
|
|
if (elm) {
|
|
elm->RemoveEventListener(aType, aListener, aUseCapture);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(DOMEventTargetHelper)
|
|
|
|
NS_IMETHODIMP
|
|
DOMEventTargetHelper::AddEventListener(const nsAString& aType,
|
|
nsIDOMEventListener* aListener,
|
|
bool aUseCapture,
|
|
bool aWantsUntrusted,
|
|
uint8_t aOptionalArgc)
|
|
{
|
|
NS_ASSERTION(!aWantsUntrusted || aOptionalArgc > 1,
|
|
"Won't check if this is chrome, you want to set "
|
|
"aWantsUntrusted to false or make the aWantsUntrusted "
|
|
"explicit by making aOptionalArgc non-zero.");
|
|
|
|
if (aOptionalArgc < 2) {
|
|
nsresult rv = WantsUntrusted(&aWantsUntrusted);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
}
|
|
|
|
EventListenerManager* elm = GetOrCreateListenerManager();
|
|
NS_ENSURE_STATE(elm);
|
|
elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
DOMEventTargetHelper::AddEventListener(const nsAString& aType,
|
|
EventListener* aListener,
|
|
bool aUseCapture,
|
|
const Nullable<bool>& aWantsUntrusted,
|
|
ErrorResult& aRv)
|
|
{
|
|
bool wantsUntrusted;
|
|
if (aWantsUntrusted.IsNull()) {
|
|
nsresult rv = WantsUntrusted(&wantsUntrusted);
|
|
if (NS_FAILED(rv)) {
|
|
aRv.Throw(rv);
|
|
return;
|
|
}
|
|
} else {
|
|
wantsUntrusted = aWantsUntrusted.Value();
|
|
}
|
|
|
|
EventListenerManager* elm = GetOrCreateListenerManager();
|
|
if (!elm) {
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
return;
|
|
}
|
|
elm->AddEventListener(aType, aListener, aUseCapture, wantsUntrusted);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DOMEventTargetHelper::AddSystemEventListener(const nsAString& aType,
|
|
nsIDOMEventListener* aListener,
|
|
bool aUseCapture,
|
|
bool aWantsUntrusted,
|
|
uint8_t aOptionalArgc)
|
|
{
|
|
NS_ASSERTION(!aWantsUntrusted || aOptionalArgc > 1,
|
|
"Won't check if this is chrome, you want to set "
|
|
"aWantsUntrusted to false or make the aWantsUntrusted "
|
|
"explicit by making aOptionalArgc non-zero.");
|
|
|
|
if (aOptionalArgc < 2) {
|
|
nsresult rv = WantsUntrusted(&aWantsUntrusted);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
}
|
|
|
|
return NS_AddSystemEventListener(this, aType, aListener, aUseCapture,
|
|
aWantsUntrusted);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DOMEventTargetHelper::DispatchEvent(nsIDOMEvent* aEvent, bool* aRetVal)
|
|
{
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
nsresult rv =
|
|
EventDispatcher::DispatchDOMEvent(this, nullptr, aEvent, nullptr, &status);
|
|
|
|
*aRetVal = (status != nsEventStatus_eConsumeNoDefault);
|
|
return rv;
|
|
}
|
|
|
|
nsresult
|
|
DOMEventTargetHelper::DispatchTrustedEvent(const nsAString& aEventName)
|
|
{
|
|
RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
|
|
event->InitEvent(aEventName, false, false);
|
|
|
|
return DispatchTrustedEvent(event);
|
|
}
|
|
|
|
nsresult
|
|
DOMEventTargetHelper::DispatchTrustedEvent(nsIDOMEvent* event)
|
|
{
|
|
event->SetTrusted(true);
|
|
|
|
bool dummy;
|
|
return DispatchEvent(event, &dummy);
|
|
}
|
|
|
|
nsresult
|
|
DOMEventTargetHelper::SetEventHandler(nsIAtom* aType,
|
|
JSContext* aCx,
|
|
const JS::Value& aValue)
|
|
{
|
|
RefPtr<EventHandlerNonNull> handler;
|
|
JS::Rooted<JSObject*> callable(aCx);
|
|
if (aValue.isObject() && JS::IsCallable(callable = &aValue.toObject())) {
|
|
handler = new EventHandlerNonNull(aCx, callable, dom::GetIncumbentGlobal());
|
|
}
|
|
SetEventHandler(aType, EmptyString(), handler);
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
DOMEventTargetHelper::GetEventHandler(nsIAtom* aType,
|
|
JSContext* aCx,
|
|
JS::Value* aValue)
|
|
{
|
|
EventHandlerNonNull* handler = GetEventHandler(aType, EmptyString());
|
|
if (handler) {
|
|
*aValue = JS::ObjectValue(*handler->Callable());
|
|
} else {
|
|
*aValue = JS::NullValue();
|
|
}
|
|
}
|
|
|
|
nsresult
|
|
DOMEventTargetHelper::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
|
{
|
|
aVisitor.mCanHandle = true;
|
|
aVisitor.mParentTarget = nullptr;
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
DOMEventTargetHelper::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
DOMEventTargetHelper::DispatchDOMEvent(WidgetEvent* aEvent,
|
|
nsIDOMEvent* aDOMEvent,
|
|
nsPresContext* aPresContext,
|
|
nsEventStatus* aEventStatus)
|
|
{
|
|
return EventDispatcher::DispatchDOMEvent(this, aEvent, aDOMEvent,
|
|
aPresContext, aEventStatus);
|
|
}
|
|
|
|
EventListenerManager*
|
|
DOMEventTargetHelper::GetOrCreateListenerManager()
|
|
{
|
|
if (!mListenerManager) {
|
|
mListenerManager = new EventListenerManager(this);
|
|
}
|
|
|
|
return mListenerManager;
|
|
}
|
|
|
|
EventListenerManager*
|
|
DOMEventTargetHelper::GetExistingListenerManager() const
|
|
{
|
|
return mListenerManager;
|
|
}
|
|
|
|
nsIScriptContext*
|
|
DOMEventTargetHelper::GetContextForEventHandlers(nsresult* aRv)
|
|
{
|
|
*aRv = CheckInnerWindowCorrectness();
|
|
if (NS_FAILED(*aRv)) {
|
|
return nullptr;
|
|
}
|
|
nsPIDOMWindow* owner = GetOwner();
|
|
return owner ? static_cast<nsGlobalWindow*>(owner)->GetContextInternal()
|
|
: nullptr;
|
|
}
|
|
|
|
nsresult
|
|
DOMEventTargetHelper::WantsUntrusted(bool* aRetVal)
|
|
{
|
|
nsresult rv;
|
|
nsIScriptContext* context = GetContextForEventHandlers(&rv);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
nsCOMPtr<nsIDocument> doc =
|
|
nsContentUtils::GetDocumentFromScriptContext(context);
|
|
// We can let listeners on workers to always handle all the events.
|
|
*aRetVal = (doc && !nsContentUtils::IsChromeDoc(doc)) || !NS_IsMainThread();
|
|
return rv;
|
|
}
|
|
|
|
void
|
|
DOMEventTargetHelper::EventListenerAdded(nsIAtom* aType)
|
|
{
|
|
ErrorResult rv;
|
|
EventListenerWasAdded(Substring(nsDependentAtomString(aType), 2), rv);
|
|
}
|
|
|
|
void
|
|
DOMEventTargetHelper::EventListenerRemoved(nsIAtom* aType)
|
|
{
|
|
ErrorResult rv;
|
|
EventListenerWasRemoved(Substring(nsDependentAtomString(aType), 2), rv);
|
|
}
|
|
|
|
} // namespace mozilla
|