Files
palemoon27/dom/base/nsScriptElement.cpp
T
roytam1 34aef48624 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 895274 part.44 Rename NS_POINTER_ENTER to ePointerEnter r=smaug (2055d66902)
- Bug 895274 part.45 Rename NS_POINTER_OUT to ePointerOut r=smaug (efc0b6b1f5)
- Bug 895274 part.46 Rename NS_POINTER_OVER to ePointerOver r=smaug (06898047f7)
- Bug 895274 part.47 Rename NS_POINTER_DOWN to ePointerDown r=smaug (eadcd864c2)
- Bug 895274 part.48 Rename NS_POINTER_UP to ePointerUp r=smaug (9a04678318)
- Bug 895274 part.49 Rename NS_POINTER_MOVE to ePointerMove r=smaug (8963a5e5e3)
- Bug 895274 part.50 Rename NS_CONTEXTMENU_MESSAGE_START to eContextMenuFirst r=smaug (5eea077f97)
- Bug 895274 part.51 Rename NS_CONTEXTMENU to eContextMenu r=smaug (df9153a883)
- Bug 895274 part.52 Get rid of NS_PAGE_RESTORE due to unused r=smaug (5555386a4f)
- Bug 895274 part.53 Rename NS_STREAM_EVENT_START to eStreamEventFirst r=smaug (873f2e5b5c)
- Bug 895274 part.54 Rename NS_READYSTATECHANGE to eReadyStateChange r=smaug (21d91c9a87)
- Bug 895274 part.55 Rename NS_BEFORE_PAGE_UNLOAD to eBeforeUnload r=smaug (1da6db3491)
- Bug 1203272 - Fix build of nsMemoryReporterManager on linux systems without mallinfo(). r=glandium,njn. (4a99986dc4)
- Bug 895274 part.56 Rename NS_POPSTATE to ePopState r=smaug (c51dbbb2e0)
- Bug 895274 part.57 Rename NS_LOAD_ERROR to eLoadError r=smaug (e4b267ec78)
- Bug 895274 part.58 Rename NS_IMAGE_ABORT to eImageAbort r=smaug (88a62156dd)
- Bug 895274 part.59 Rename NS_HASHCHANGE to eHashChange r=smaug (7552f57017)
- Bug 895274 part.60 Rename NS_PAGE_UNLOAD to eUnload r=smaug (20153f814e)
- Bug 895274 part.61 Rename NS_LOAD to eLoad r=smaug (1072bcbb81)
- Bug 895274 part.62 Rename NS_FORM_EVENT_START to eFormEventFirst r=smaug (e99f85df0c)
- Bug 895274 part.63 Rename NS_FORM_SUBMIT to eFormSubmit r=smaug (b7ebab7fe0)
- Bug 895274 part.64 Rename NS_FORM_RESET to eFormReset r=smaug (74a3518bf6)
- Bug 895274 part.65 Rename NS_FORM_CHANGE to eFormChange r=smaug (64dafe9aaa)
- Bug 895274 part.66 Rename NS_FORM_SELECTED to eFormSelect r=smaug (4437b9a60c)
- Bug 895274 part.67 Rename NS_FORM_INVALID to eFormInvalid r=smaug (8122f6e301)
- Bug 895274 part.68 Rename NS_FOCUS_EVENT_START to eFocusEventFirst r=smaug (5066c46dc1)
- Bug 895274 part.69 Rename NS_FOCUS_CONTENT to eFocus r=smaug (79a443a14c)
- Bug 895274 part.70 Rename NS_BLUR_CONTENT to eBlur r=smaug (64515beb6a)
- Bug 895274 part.71 Rename NS_UI_EVENT_START to eLegacyUIEventFirst r=smaug (02b8a5cccd)
- Bug 895274 part.72 Rename NS_UI_ACTIVATE to eLegacyDOMActivate r=smaug (884aa917ec)
- Bug 895274 part.73 Rename NS_UI_FOCUSIN to eLegacyDOMFocusIn r=smaug (905f681593)
- Bug 895274 part.74 Rename NS_UI_FOCUSOUT to eLegacyDOMFocusOut r=smaug (b38a2ab56c)
- Bug 895274 part.75 Rename NS_DRAGDROP_EVENT_START to eDragDropEventFirst, define eDragDropEventLast and correct the type and name of event message in DataTransfer r=smaug (e8ac6a9112)
- Bug 895274 part.76 Rename NS_DRAGDROP_LEAVE to eDragLeave r=smaug (6948c3cddc)
- Bug 895274 part.77 Rename NS_DRAGDROP_DROP to eDrop r=smaug (9e67b051ee)
- Bug 895274 part.78 Rename NS_DRAGDROP_START to eDragStart r=smaug (f13fc7cf41)
- Bug 1184967 P1 Set RequestMode based on LoadInfo securityMode and client request content policy. r=nsm (b6d7f3fed7)
- Bug 1173934 Disable broken fetch-frame-resources.https.html wpt tests. r=jgraham (7d8e203c6a)
- Bug 1187722 Fix bad origins, error page handling, and spec issues in fetch-frame-resources.https.html. r=jgraham (fecdaeddfc)
- Bug 1184967 P2 Update fetch-frame-resource.https.html CORS checks to expect pass. r=jgraham (7550cba86d)
- Bug 1184967 P3 Switch mochitest redirect tests back to returning a CORS Response. r=nsm (2f803e26ac)
- spacing (21c5e1f343)
2022-04-25 09:31:40 +08:00

144 lines
4.3 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 "nsScriptElement.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/dom/Element.h"
#include "nsContentUtils.h"
#include "nsPresContext.h"
#include "nsScriptLoader.h"
#include "nsIParser.h"
#include "nsAutoPtr.h"
#include "nsGkAtoms.h"
#include "nsContentSink.h"
using namespace mozilla;
using namespace mozilla::dom;
NS_IMETHODIMP
nsScriptElement::ScriptAvailable(nsresult aResult,
nsIScriptElement *aElement,
bool aIsInline,
nsIURI *aURI,
int32_t aLineNo)
{
if (!aIsInline && NS_FAILED(aResult)) {
return FireErrorEvent();
}
return NS_OK;
}
/* virtual */ nsresult
nsScriptElement::FireErrorEvent()
{
nsCOMPtr<nsIContent> cont =
do_QueryInterface((nsIScriptElement*) this);
return nsContentUtils::DispatchTrustedEvent(cont->OwnerDoc(),
cont,
NS_LITERAL_STRING("error"),
false /* bubbles */,
false /* cancelable */);
}
NS_IMETHODIMP
nsScriptElement::ScriptEvaluated(nsresult aResult,
nsIScriptElement *aElement,
bool aIsInline)
{
nsresult rv = NS_OK;
if (!aIsInline) {
nsCOMPtr<nsIContent> cont =
do_QueryInterface((nsIScriptElement*) this);
nsRefPtr<nsPresContext> presContext =
nsContentUtils::GetContextForContent(cont);
nsEventStatus status = nsEventStatus_eIgnore;
EventMessage message = NS_SUCCEEDED(aResult) ? eLoad : eLoadError;
WidgetEvent event(true, message);
// Load event doesn't bubble.
event.mFlags.mBubbles = (message != eLoad);
EventDispatcher::Dispatch(cont, presContext, &event, nullptr, &status);
}
return rv;
}
void
nsScriptElement::CharacterDataChanged(nsIDocument *aDocument,
nsIContent* aContent,
CharacterDataChangeInfo* aInfo)
{
MaybeProcessScript();
}
void
nsScriptElement::AttributeChanged(nsIDocument* aDocument,
Element* aElement,
int32_t aNameSpaceID,
nsIAtom* aAttribute,
int32_t aModType,
const nsAttrValue* aOldValue)
{
MaybeProcessScript();
}
void
nsScriptElement::ContentAppended(nsIDocument* aDocument,
nsIContent* aContainer,
nsIContent* aFirstNewContent,
int32_t aNewIndexInContainer)
{
MaybeProcessScript();
}
void
nsScriptElement::ContentInserted(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aChild,
int32_t aIndexInContainer)
{
MaybeProcessScript();
}
bool
nsScriptElement::MaybeProcessScript()
{
nsCOMPtr<nsIContent> cont =
do_QueryInterface((nsIScriptElement*) this);
NS_ASSERTION(cont->DebugGetSlots()->mMutationObservers.Contains(this),
"You forgot to add self as observer");
if (mAlreadyStarted || !mDoneAddingChildren ||
!cont->GetCrossShadowCurrentDoc() || mMalformed || !HasScriptContent()) {
return false;
}
FreezeUriAsyncDefer();
mAlreadyStarted = true;
nsIDocument* ownerDoc = cont->OwnerDoc();
nsCOMPtr<nsIParser> parser = ((nsIScriptElement*) this)->GetCreatorParser();
if (parser) {
nsCOMPtr<nsIContentSink> sink = parser->GetContentSink();
if (sink) {
nsCOMPtr<nsIDocument> parserDoc = do_QueryInterface(sink->GetTarget());
if (ownerDoc != parserDoc) {
// Willful violation of HTML5 as of 2010-12-01
return false;
}
}
}
nsRefPtr<nsScriptLoader> loader = ownerDoc->ScriptLoader();
return loader->ProcessScriptElement(this);
}