Files
Masayuki Nakano 976be8097e Bug 1625902 - part 1: Mark nsContentUtils::Dispatch*Event as MOZ_CAN_RUN_SCRIPT except for chrome r=smaug,dom-core-reviewers,geckoview-reviewers,media-playback-reviewers,win-reviewers,padenot,handyman,m_kato
This patch does not fix the methods in xslt and content sink because
they require a lot of `MOZ_CAN_RUN_SCRIPT` but I think most of them
do not make sense because working in a specific period.

Differential Revision: https://phabricator.services.mozilla.com/D310971
2026-08-25 06:57:20 +00:00

66 lines
1.9 KiB
C++

/* 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/. */
#ifndef mozilla_dom_ScriptElement_h
#define mozilla_dom_ScriptElement_h
#include "mozilla/Attributes.h"
#include "nsIScriptElement.h"
#include "nsIScriptLoaderObserver.h"
#include "nsStubMutationObserver.h"
class nsIParser;
namespace mozilla::dom {
/**
* Baseclass useful for script elements (such as <xhtml:script> and
* <svg:script>). Currently the class assumes that only the 'src'
* attribute and the children of the class affect what script to execute.
*/
class ScriptElement : public nsIScriptElement, public nsStubMutationObserver {
public:
// nsIScriptLoaderObserver
NS_DECL_NSISCRIPTLOADEROBSERVER
// nsIMutationObserver
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
explicit ScriptElement(FromParser aFromParser)
: nsIScriptElement(aFromParser) {}
MOZ_CAN_RUN_SCRIPT nsresult FireErrorEvent() override;
virtual bool GetScriptType(nsAString& aType) override;
protected:
// Internal methods
/**
* Check if this element contains any linked script.
*/
virtual bool HasExternalScriptContent() = 0;
MOZ_CAN_RUN_SCRIPT bool MaybeProcessScript(
nsCOMPtr<nsIParser> aParser) override;
MOZ_CAN_RUN_SCRIPT nsresult
GetTrustedTypesCompliantInlineScriptText(nsString& aSourceText) override;
private:
// https://github.com/w3c/trusted-types/pull/579
void UpdateTrustWorthiness(MutationEffectOnScript aMutationEffectOnScript);
MOZ_CAN_RUN_SCRIPT bool MaybeProcessScript(const nsAString& aSourceText);
};
} // namespace mozilla::dom
#endif // mozilla_dom_ScriptElement_h