tor-browser

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

HTMLObjectElement.h (7517B)


      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_HTMLObjectElement_h
      8 #define mozilla_dom_HTMLObjectElement_h
      9 
     10 #include "mozilla/dom/ConstraintValidation.h"
     11 #include "nsGenericHTMLElement.h"
     12 #include "nsObjectLoadingContent.h"
     13 
     14 namespace mozilla::dom {
     15 
     16 class FormData;
     17 template <typename T>
     18 struct Nullable;
     19 class WindowProxyHolder;
     20 
     21 class HTMLObjectElement final : public nsGenericHTMLFormControlElement,
     22                                public nsObjectLoadingContent,
     23                                public ConstraintValidation {
     24 public:
     25  explicit HTMLObjectElement(
     26      already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
     27      FromParser aFromParser = NOT_FROM_PARSER);
     28 
     29  // nsISupports
     30  NS_DECL_ISUPPORTS_INHERITED
     31 
     32  NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLObjectElement, object)
     33  int32_t TabIndexDefault() override;
     34 
     35  // nsObjectLoadingContent
     36  const Element* AsElement() const final { return this; }
     37 
     38  // Element
     39  bool IsInteractiveHTMLContent() const override;
     40 
     41  nsresult BindToTree(BindContext&, nsINode& aParent) override;
     42  void UnbindFromTree(UnbindContext&) override;
     43 
     44  bool IsHTMLFocusable(IsFocusableFlags, bool* aIsFocusable,
     45                       int32_t* aTabIndex) override;
     46 
     47  // Overriden nsIFormControl methods
     48  NS_IMETHOD Reset() override { return NS_OK; }
     49 
     50  NS_IMETHOD SubmitNamesValues(FormData* aFormData) override { return NS_OK; }
     51 
     52  void DoneAddingChildren(bool aHaveNotified) override;
     53 
     54  bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
     55                      const nsAString& aValue,
     56                      nsIPrincipal* aMaybeScriptedPrincipal,
     57                      nsAttrValue& aResult) override;
     58  nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
     59  NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
     60  void DestroyContent() override;
     61 
     62  // nsObjectLoadingContent
     63  uint32_t GetCapabilities() const override;
     64  nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
     65 
     66  nsresult CopyInnerTo(Element* aDest);
     67 
     68  void StartObjectLoad() { StartObjectLoad(true, false); }
     69 
     70  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLObjectElement,
     71                                           nsGenericHTMLFormControlElement)
     72 
     73  // Web IDL binding methods
     74  void GetData(DOMString& aValue) {
     75    GetURIAttr(nsGkAtoms::data, nsGkAtoms::codebase, aValue);
     76  }
     77  void SetData(const nsAString& aValue, ErrorResult& aRv) {
     78    SetHTMLAttr(nsGkAtoms::data, aValue, aRv);
     79  }
     80  void GetType(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::type, aValue); }
     81  void SetType(const nsAString& aValue, ErrorResult& aRv) {
     82    SetHTMLAttr(nsGkAtoms::type, aValue, aRv);
     83  }
     84  void GetName(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::name, aValue); }
     85  void SetName(const nsAString& aValue, ErrorResult& aRv) {
     86    SetHTMLAttr(nsGkAtoms::name, aValue, aRv);
     87  }
     88  void GetUseMap(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::usemap, aValue); }
     89  void SetUseMap(const nsAString& aValue, ErrorResult& aRv) {
     90    SetHTMLAttr(nsGkAtoms::usemap, aValue, aRv);
     91  }
     92  void GetWidth(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::width, aValue); }
     93  void SetWidth(const nsAString& aValue, ErrorResult& aRv) {
     94    SetHTMLAttr(nsGkAtoms::width, aValue, aRv);
     95  }
     96  void GetHeight(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::height, aValue); }
     97  void SetHeight(const nsAString& aValue, ErrorResult& aRv) {
     98    SetHTMLAttr(nsGkAtoms::height, aValue, aRv);
     99  }
    100  using nsObjectLoadingContent::GetContentDocument;
    101 
    102  Nullable<WindowProxyHolder> GetContentWindow(nsIPrincipal& aSubjectPrincipal);
    103 
    104  using ConstraintValidation::GetValidationMessage;
    105  using ConstraintValidation::SetCustomValidity;
    106  void GetAlign(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::align, aValue); }
    107  void SetAlign(const nsAString& aValue, ErrorResult& aRv) {
    108    SetHTMLAttr(nsGkAtoms::align, aValue, aRv);
    109  }
    110  void GetArchive(DOMString& aValue) {
    111    GetHTMLAttr(nsGkAtoms::archive, aValue);
    112  }
    113  void SetArchive(const nsAString& aValue, ErrorResult& aRv) {
    114    SetHTMLAttr(nsGkAtoms::archive, aValue, aRv);
    115  }
    116  void GetCode(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::code, aValue); }
    117  void SetCode(const nsAString& aValue, ErrorResult& aRv) {
    118    SetHTMLAttr(nsGkAtoms::code, aValue, aRv);
    119  }
    120  bool Declare() { return GetBoolAttr(nsGkAtoms::declare); }
    121  void SetDeclare(bool aValue, ErrorResult& aRv) {
    122    SetHTMLBoolAttr(nsGkAtoms::declare, aValue, aRv);
    123  }
    124  uint32_t Hspace() {
    125    return GetDimensionAttrAsUnsignedInt(nsGkAtoms::hspace, 0);
    126  }
    127  void SetHspace(uint32_t aValue, ErrorResult& aRv) {
    128    SetUnsignedIntAttr(nsGkAtoms::hspace, aValue, 0, aRv);
    129  }
    130  void GetStandby(DOMString& aValue) {
    131    GetHTMLAttr(nsGkAtoms::standby, aValue);
    132  }
    133  void SetStandby(const nsAString& aValue, ErrorResult& aRv) {
    134    SetHTMLAttr(nsGkAtoms::standby, aValue, aRv);
    135  }
    136  uint32_t Vspace() {
    137    return GetDimensionAttrAsUnsignedInt(nsGkAtoms::vspace, 0);
    138  }
    139  void SetVspace(uint32_t aValue, ErrorResult& aRv) {
    140    SetUnsignedIntAttr(nsGkAtoms::vspace, aValue, 0, aRv);
    141  }
    142  void GetCodeBase(DOMString& aValue) {
    143    GetURIAttr(nsGkAtoms::codebase, nullptr, aValue);
    144  }
    145  void SetCodeBase(const nsAString& aValue, ErrorResult& aRv) {
    146    SetHTMLAttr(nsGkAtoms::codebase, aValue, aRv);
    147  }
    148  void GetCodeType(DOMString& aValue) {
    149    GetHTMLAttr(nsGkAtoms::codetype, aValue);
    150  }
    151  void SetCodeType(const nsAString& aValue, ErrorResult& aRv) {
    152    SetHTMLAttr(nsGkAtoms::codetype, aValue, aRv);
    153  }
    154  void GetBorder(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::border, aValue); }
    155  void SetBorder(const nsAString& aValue, ErrorResult& aRv) {
    156    SetHTMLAttr(nsGkAtoms::border, aValue, aRv);
    157  }
    158 
    159  Document* GetSVGDocument(nsIPrincipal& aSubjectPrincipal) {
    160    return GetContentDocument(aSubjectPrincipal);
    161  }
    162 
    163  /**
    164   * Calls LoadObject with the correct arguments to start the plugin load.
    165   */
    166  void StartObjectLoad(bool aNotify, bool aForceLoad);
    167 
    168 protected:
    169  void AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
    170                    const nsAttrValue* aValue, const nsAttrValue* aOldValue,
    171                    nsIPrincipal* aSubjectPrincipal, bool aNotify) override;
    172  void OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName,
    173                              const nsAttrValueOrString& aValue,
    174                              bool aNotify) override;
    175 
    176 private:
    177  nsContentPolicyType GetContentPolicyType() const override {
    178    return nsIContentPolicy::TYPE_INTERNAL_OBJECT;
    179  }
    180 
    181  virtual ~HTMLObjectElement();
    182 
    183  JSObject* WrapNode(JSContext* aCx,
    184                     JS::Handle<JSObject*> aGivenProto) override;
    185 
    186  static void MapAttributesIntoRule(MappedDeclarationsBuilder&);
    187 
    188  /**
    189   * This function is called by AfterSetAttr and OnAttrSetButNotChanged.
    190   * This function will be called by AfterSetAttr whether the attribute is being
    191   * set or unset.
    192   *
    193   * @param aNamespaceID the namespace of the attr being set
    194   * @param aName the localname of the attribute being set
    195   * @param aNotify Whether we plan to notify document observers.
    196   */
    197  void AfterMaybeChangeAttr(int32_t aNamespaceID, nsAtom* aName, bool aNotify);
    198 
    199  bool mIsDoneAddingChildren;
    200 };
    201 
    202 }  // namespace mozilla::dom
    203 
    204 #endif  // mozilla_dom_HTMLObjectElement_h