2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2006-11-04 08:45:02 +03:00
|
|
|
|
2017-05-08 09:24:22 +03:00
|
|
|
#include "ScriptElement.h"
|
|
|
|
#include "ScriptLoader.h"
|
2013-09-25 15:21:22 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2010-08-24 11:05:56 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2007-07-13 12:49:07 +04:00
|
|
|
#include "nsContentUtils.h"
|
2006-11-04 08:45:02 +03:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIParser.h"
|
|
|
|
#include "nsGkAtoms.h"
|
2010-12-08 15:37:19 +03:00
|
|
|
#include "nsContentSink.h"
|
2006-11-04 08:45:02 +03:00
|
|
|
|
2013-10-02 07:46:04 +04:00
|
|
|
using namespace mozilla;
|
2010-08-24 11:05:56 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2006-11-04 08:45:02 +03:00
|
|
|
NS_IMETHODIMP
|
2017-05-08 09:24:22 +03:00
|
|
|
ScriptElement::ScriptAvailable(nsresult aResult,
|
2017-05-08 09:25:03 +03:00
|
|
|
nsIScriptElement* aElement,
|
2017-12-01 16:12:48 +03:00
|
|
|
bool aIsInlineClassicScript,
|
2017-05-08 09:25:03 +03:00
|
|
|
nsIURI* aURI,
|
2017-05-08 09:24:22 +03:00
|
|
|
int32_t aLineNo)
|
2006-11-04 08:45:02 +03:00
|
|
|
{
|
2017-12-01 16:12:48 +03:00
|
|
|
if (!aIsInlineClassicScript && NS_FAILED(aResult)) {
|
2016-09-03 00:55:38 +03:00
|
|
|
nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
|
|
|
|
if (parser) {
|
|
|
|
parser->PushDefinedInsertionPoint();
|
|
|
|
}
|
|
|
|
nsresult rv = FireErrorEvent();
|
|
|
|
if (parser) {
|
|
|
|
parser->PopDefinedInsertionPoint();
|
|
|
|
}
|
|
|
|
return rv;
|
2006-11-04 08:45:02 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-19 07:24:27 +04:00
|
|
|
/* virtual */ nsresult
|
2017-05-08 09:24:22 +03:00
|
|
|
ScriptElement::FireErrorEvent()
|
2012-09-19 07:24:27 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> cont =
|
|
|
|
do_QueryInterface((nsIScriptElement*) this);
|
|
|
|
|
|
|
|
return nsContentUtils::DispatchTrustedEvent(cont->OwnerDoc(),
|
|
|
|
cont,
|
|
|
|
NS_LITERAL_STRING("error"),
|
|
|
|
false /* bubbles */,
|
|
|
|
false /* cancelable */);
|
|
|
|
}
|
|
|
|
|
2006-11-04 08:45:02 +03:00
|
|
|
NS_IMETHODIMP
|
2017-05-08 09:24:22 +03:00
|
|
|
ScriptElement::ScriptEvaluated(nsresult aResult,
|
2017-05-08 09:25:03 +03:00
|
|
|
nsIScriptElement* aElement,
|
2017-05-08 09:24:22 +03:00
|
|
|
bool aIsInline)
|
2006-11-04 08:45:02 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (!aIsInline) {
|
|
|
|
nsCOMPtr<nsIContent> cont =
|
|
|
|
do_QueryInterface((nsIScriptElement*) this);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPresContext> presContext =
|
2007-07-13 12:49:07 +04:00
|
|
|
nsContentUtils::GetContextForContent(cont);
|
2006-11-04 08:45:02 +03:00
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-09-02 09:07:59 +03:00
|
|
|
EventMessage message = NS_SUCCEEDED(aResult) ? eLoad : eLoadError;
|
2015-08-26 15:56:59 +03:00
|
|
|
WidgetEvent event(true, message);
|
2012-12-16 05:26:03 +04:00
|
|
|
// Load event doesn't bubble.
|
2015-09-02 09:07:59 +03:00
|
|
|
event.mFlags.mBubbles = (message != eLoad);
|
2006-11-04 08:45:02 +03:00
|
|
|
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::Dispatch(cont, presContext, &event, nullptr, &status);
|
2006-11-04 08:45:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-05-08 09:25:03 +03:00
|
|
|
ScriptElement::CharacterDataChanged(nsIDocument* aDocument,
|
2017-05-08 09:24:22 +03:00
|
|
|
nsIContent* aContent,
|
2018-02-27 17:30:27 +03:00
|
|
|
const CharacterDataChangeInfo&)
|
2006-11-04 08:45:02 +03:00
|
|
|
{
|
|
|
|
MaybeProcessScript();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-05-08 09:24:22 +03:00
|
|
|
ScriptElement::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2017-05-08 09:24:22 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue)
|
2006-11-04 08:45:02 +03:00
|
|
|
{
|
2006-11-09 03:02:21 +03:00
|
|
|
MaybeProcessScript();
|
2006-11-04 08:45:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-05-08 09:24:22 +03:00
|
|
|
ScriptElement::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
2017-07-27 16:49:52 +03:00
|
|
|
nsIContent* aFirstNewContent)
|
2006-11-04 08:45:02 +03:00
|
|
|
{
|
|
|
|
MaybeProcessScript();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-05-08 09:25:03 +03:00
|
|
|
ScriptElement::ContentInserted(nsIDocument* aDocument,
|
2017-05-08 09:24:22 +03:00
|
|
|
nsIContent* aContainer,
|
2017-07-27 16:49:52 +03:00
|
|
|
nsIContent* aChild)
|
2006-11-04 08:45:02 +03:00
|
|
|
{
|
|
|
|
MaybeProcessScript();
|
|
|
|
}
|
|
|
|
|
2011-11-16 11:50:18 +04:00
|
|
|
bool
|
2017-05-08 09:24:22 +03:00
|
|
|
ScriptElement::MaybeProcessScript()
|
2006-11-04 08:45:02 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> cont =
|
|
|
|
do_QueryInterface((nsIScriptElement*) this);
|
|
|
|
|
|
|
|
NS_ASSERTION(cont->DebugGetSlots()->mMutationObservers.Contains(this),
|
|
|
|
"You forgot to add self as observer");
|
|
|
|
|
2014-06-07 12:42:54 +04:00
|
|
|
if (mAlreadyStarted || !mDoneAddingChildren ||
|
2016-03-31 15:20:14 +03:00
|
|
|
!cont->GetComposedDoc() || mMalformed || !HasScriptContent()) {
|
2011-11-16 11:50:18 +04:00
|
|
|
return false;
|
2009-01-14 15:49:18 +03:00
|
|
|
}
|
|
|
|
|
2018-01-08 18:17:34 +03:00
|
|
|
nsIDocument* ownerDoc = cont->OwnerDoc();
|
|
|
|
FreezeExecutionAttrs(ownerDoc);
|
2009-11-17 11:52:30 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mAlreadyStarted = true;
|
2010-12-08 15:37:19 +03:00
|
|
|
|
2011-04-19 11:10:48 +04:00
|
|
|
nsCOMPtr<nsIParser> parser = ((nsIScriptElement*) this)->GetCreatorParser();
|
2010-12-08 15:37:19 +03:00
|
|
|
if (parser) {
|
2011-04-19 11:10:48 +04:00
|
|
|
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
|
2011-11-16 11:50:18 +04:00
|
|
|
return false;
|
2011-04-19 11:10:48 +04:00
|
|
|
}
|
2010-12-08 15:37:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-08 09:24:22 +03:00
|
|
|
RefPtr<ScriptLoader> loader = ownerDoc->ScriptLoader();
|
2011-11-16 11:50:18 +04:00
|
|
|
return loader->ProcessScriptElement(this);
|
2006-11-04 08:45:02 +03:00
|
|
|
}
|