2013-01-05 01:41:27 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et 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 "nsGkAtoms.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsUnicharUtils.h" // for nsCaseInsensitiveStringComparator()
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsIArray.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsDOMJSUtils.h"
|
2013-08-07 13:23:08 -07:00
|
|
|
#include "nsISupportsImpl.h"
|
2013-01-05 01:41:27 -08:00
|
|
|
#include "mozilla/dom/HTMLScriptElement.h"
|
2013-01-05 01:41:28 -08:00
|
|
|
#include "mozilla/dom/HTMLScriptElementBinding.h"
|
2013-01-05 01:41:27 -08:00
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Script)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-01-05 01:41:28 -08:00
|
|
|
JSObject*
|
2014-04-08 15:27:17 -07:00
|
|
|
HTMLScriptElement::WrapNode(JSContext *aCx)
|
2013-01-05 01:41:28 -08:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return HTMLScriptElementBinding::Wrap(aCx, this);
|
2013-01-05 01:41:28 -08:00
|
|
|
}
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
HTMLScriptElement::HTMLScriptElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
|
2013-01-05 01:41:27 -08:00
|
|
|
FromParser aFromParser)
|
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
|
|
, nsScriptElement(aFromParser)
|
|
|
|
{
|
|
|
|
AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLScriptElement::~HTMLScriptElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(HTMLScriptElement, nsGenericHTMLElement,
|
|
|
|
nsIDOMHTMLScriptElement,
|
|
|
|
nsIScriptLoaderObserver,
|
|
|
|
nsIScriptElement,
|
|
|
|
nsIMutationObserver)
|
2013-01-05 01:41:27 -08:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLScriptElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-06-07 01:42:54 -07:00
|
|
|
if (GetCrossShadowCurrentDoc()) {
|
2013-01-05 01:41:27 -08:00
|
|
|
MaybeProcessScript();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HTMLScriptElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None &&
|
|
|
|
aAttribute == nsGkAtoms::crossorigin) {
|
|
|
|
ParseCORSValue(aValue, aResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-06-19 19:01:40 -07:00
|
|
|
HTMLScriptElement::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const
|
2013-01-05 01:41:27 -08:00
|
|
|
{
|
|
|
|
*aResult = nullptr;
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo> ni = nsRefPtr<mozilla::dom::NodeInfo>(aNodeInfo).forget();
|
2014-03-15 12:00:17 -07:00
|
|
|
HTMLScriptElement* it = new HTMLScriptElement(ni, NOT_FROM_PARSER);
|
2013-01-05 01:41:27 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsINode> kungFuDeathGrip = it;
|
|
|
|
nsresult rv = const_cast<HTMLScriptElement*>(this)->CopyInnerTo(it);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// The clone should be marked evaluated if we are.
|
|
|
|
it->mAlreadyStarted = mAlreadyStarted;
|
|
|
|
it->mLineNumber = mLineNumber;
|
|
|
|
it->mMalformed = mMalformed;
|
|
|
|
|
|
|
|
kungFuDeathGrip.swap(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLScriptElement::GetText(nsAString& aValue)
|
|
|
|
{
|
2014-03-20 12:51:16 -07:00
|
|
|
if (!nsContentUtils::GetNodeTextContent(this, false, aValue)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2013-01-05 01:41:27 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLScriptElement::SetText(const nsAString& aValue)
|
|
|
|
{
|
2013-01-05 01:41:28 -08:00
|
|
|
ErrorResult rv;
|
|
|
|
SetText(aValue, rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLScriptElement::SetText(const nsAString& aValue, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
rv = nsContentUtils::SetNodeTextContent(this, aValue, true);
|
2013-01-05 01:41:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLScriptElement, Charset, charset)
|
|
|
|
NS_IMPL_BOOL_ATTR(HTMLScriptElement, Defer, defer)
|
|
|
|
NS_IMPL_URI_ATTR(HTMLScriptElement, Src, src)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLScriptElement, Type, type)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLScriptElement, HtmlFor, _for)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLScriptElement, Event, event)
|
|
|
|
|
2013-01-05 01:41:28 -08:00
|
|
|
void
|
|
|
|
HTMLScriptElement::SetCharset(const nsAString& aCharset, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::charset, aCharset, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLScriptElement::SetDefer(bool aDefer, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::defer, aDefer, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HTMLScriptElement::Defer()
|
|
|
|
{
|
|
|
|
return GetBoolAttr(nsGkAtoms::defer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLScriptElement::SetSrc(const nsAString& aSrc, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
rv = SetAttrHelper(nsGkAtoms::src, aSrc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLScriptElement::SetType(const nsAString& aType, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::type, aType, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLScriptElement::SetHtmlFor(const nsAString& aHtmlFor, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::_for, aHtmlFor, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLScriptElement::SetEvent(const nsAString& aEvent, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::event, aEvent, rv);
|
|
|
|
}
|
|
|
|
|
2013-01-05 01:41:27 -08:00
|
|
|
nsresult
|
|
|
|
HTMLScriptElement::GetAsync(bool* aValue)
|
|
|
|
{
|
2013-01-05 01:41:28 -08:00
|
|
|
*aValue = Async();
|
2013-01-05 01:41:27 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-05 01:41:28 -08:00
|
|
|
bool
|
|
|
|
HTMLScriptElement::Async()
|
|
|
|
{
|
|
|
|
return mForceAsync || GetBoolAttr(nsGkAtoms::async);
|
|
|
|
}
|
|
|
|
|
2013-01-05 01:41:27 -08:00
|
|
|
nsresult
|
|
|
|
HTMLScriptElement::SetAsync(bool aValue)
|
2013-01-05 01:41:28 -08:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
SetAsync(aValue, rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLScriptElement::SetAsync(bool aValue, ErrorResult& rv)
|
2013-01-05 01:41:27 -08:00
|
|
|
{
|
|
|
|
mForceAsync = false;
|
2013-01-05 01:41:28 -08:00
|
|
|
SetHTMLBoolAttr(nsGkAtoms::async, aValue, rv);
|
2013-01-05 01:41:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLScriptElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
|
|
|
{
|
|
|
|
if (nsGkAtoms::async == aName && kNameSpaceID_None == aNamespaceID) {
|
|
|
|
mForceAsync = false;
|
|
|
|
}
|
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, aValue,
|
|
|
|
aNotify);
|
|
|
|
}
|
|
|
|
|
2013-10-08 12:25:01 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLScriptElement::GetInnerHTML(nsAString& aInnerHTML)
|
2013-01-05 01:41:27 -08:00
|
|
|
{
|
2014-03-19 10:05:03 -07:00
|
|
|
if (!nsContentUtils::GetNodeTextContent(this, false, aInnerHTML)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2013-10-08 12:25:01 -07:00
|
|
|
return NS_OK;
|
2013-01-05 01:41:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLScriptElement::SetInnerHTML(const nsAString& aInnerHTML,
|
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
|
|
|
aError = nsContentUtils::SetNodeTextContent(this, aInnerHTML, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// variation of this code in nsSVGScriptElement - check if changes
|
|
|
|
// need to be transfered when modifying
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLScriptElement::GetScriptType(nsAString& type)
|
|
|
|
{
|
|
|
|
GetType(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLScriptElement::GetScriptText(nsAString& text)
|
|
|
|
{
|
|
|
|
GetText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLScriptElement::GetScriptCharset(nsAString& charset)
|
|
|
|
{
|
|
|
|
GetCharset(charset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLScriptElement::FreezeUriAsyncDefer()
|
|
|
|
{
|
|
|
|
if (mFrozen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// variation of this code in nsSVGScriptElement - check if changes
|
|
|
|
// need to be transfered when modifying
|
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::src)) {
|
|
|
|
nsAutoString src;
|
|
|
|
GetSrc(src);
|
|
|
|
NS_NewURI(getter_AddRefs(mUri), src);
|
|
|
|
// At this point mUri will be null for invalid URLs.
|
|
|
|
mExternal = true;
|
|
|
|
|
|
|
|
bool defer, async;
|
|
|
|
GetAsync(&async);
|
|
|
|
GetDefer(&defer);
|
|
|
|
|
|
|
|
mDefer = !async && defer;
|
|
|
|
mAsync = async;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrozen = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CORSMode
|
|
|
|
HTMLScriptElement::GetCORSMode() const
|
|
|
|
{
|
|
|
|
return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HTMLScriptElement::HasScriptContent()
|
|
|
|
{
|
|
|
|
return (mFrozen ? mExternal : HasAttr(kNameSpaceID_None, nsGkAtoms::src)) ||
|
|
|
|
nsContentUtils::HasNonEmptyTextContent(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|