tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ScriptElement.h (2015B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_ScriptElement_h
      8 #define mozilla_dom_ScriptElement_h
      9 
     10 #include "mozilla/Attributes.h"
     11 #include "nsIScriptElement.h"
     12 #include "nsIScriptLoaderObserver.h"
     13 #include "nsStubMutationObserver.h"
     14 
     15 class nsIParser;
     16 
     17 namespace mozilla::dom {
     18 
     19 /**
     20 * Baseclass useful for script elements (such as <xhtml:script> and
     21 * <svg:script>). Currently the class assumes that only the 'src'
     22 * attribute and the children of the class affect what script to execute.
     23 */
     24 
     25 class ScriptElement : public nsIScriptElement, public nsStubMutationObserver {
     26 public:
     27  // nsIScriptLoaderObserver
     28  NS_DECL_NSISCRIPTLOADEROBSERVER
     29 
     30  // nsIMutationObserver
     31  NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
     32  NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
     33  NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
     34  NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
     35  NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
     36 
     37  explicit ScriptElement(FromParser aFromParser)
     38      : nsIScriptElement(aFromParser) {}
     39 
     40  virtual nsresult FireErrorEvent() override;
     41 
     42  virtual bool GetScriptType(nsAString& aType) override;
     43 
     44 protected:
     45  // Internal methods
     46 
     47  /**
     48   * Check if this element contains any linked script.
     49   */
     50  virtual bool HasExternalScriptContent() = 0;
     51 
     52  virtual bool MaybeProcessScript(nsCOMPtr<nsIParser> aParser) override;
     53 
     54  virtual MOZ_CAN_RUN_SCRIPT nsresult
     55  GetTrustedTypesCompliantInlineScriptText(nsString& aSourceText) override;
     56 
     57 private:
     58  // https://github.com/w3c/trusted-types/pull/579
     59  void UpdateTrustWorthiness(MutationEffectOnScript aMutationEffectOnScript);
     60 
     61  bool MaybeProcessScript(const nsAString& aSourceText);
     62 };
     63 
     64 }  // namespace mozilla::dom
     65 
     66 #endif  // mozilla_dom_ScriptElement_h