tor-browser

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

nsGenericHTMLFrameElement.h (5074B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef nsGenericHTMLFrameElement_h
      8 #define nsGenericHTMLFrameElement_h
      9 
     10 #include "nsFrameLoader.h"
     11 #include "nsFrameLoaderOwner.h"
     12 #include "nsGenericHTMLElement.h"
     13 
     14 namespace mozilla {
     15 class ErrorResult;
     16 
     17 namespace dom {
     18 class BrowserParent;
     19 template <typename>
     20 struct Nullable;
     21 class WindowProxyHolder;
     22 class XULFrameElement;
     23 }  // namespace dom
     24 }  // namespace mozilla
     25 
     26 #define NS_GENERICHTMLFRAMEELEMENT_IID \
     27  {0x8190db72, 0xdab0, 0x4d72, {0x94, 0x26, 0x87, 0x5f, 0x5a, 0x8a, 0x2a, 0xe5}}
     28 
     29 /**
     30 * A helper class for frame elements
     31 */
     32 class nsGenericHTMLFrameElement : public nsGenericHTMLElement,
     33                                  public nsFrameLoaderOwner {
     34 public:
     35  nsGenericHTMLFrameElement(
     36      already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
     37      mozilla::dom::FromParser aFromParser)
     38      : nsGenericHTMLElement(std::move(aNodeInfo)),
     39        mSrcLoadHappened(false),
     40        mNetworkCreated(aFromParser == mozilla::dom::FROM_PARSER_NETWORK) {}
     41 
     42  NS_DECL_ISUPPORTS_INHERITED
     43 
     44  NS_INLINE_DECL_STATIC_IID(NS_GENERICHTMLFRAMEELEMENT_IID)
     45 
     46  // nsIContent
     47  bool IsHTMLFocusable(mozilla::IsFocusableFlags, bool* aIsFocusable,
     48                       int32_t* aTabIndex) override;
     49  nsresult BindToTree(BindContext&, nsINode& aParent) override;
     50  void UnbindFromTree(UnbindContext&) override;
     51  void DestroyContent() override;
     52 
     53  nsresult CopyInnerTo(mozilla::dom::Element* aDest);
     54 
     55  int32_t TabIndexDefault() override;
     56 
     57  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsGenericHTMLFrameElement,
     58                                           nsGenericHTMLElement)
     59 
     60  void SwapFrameLoaders(mozilla::dom::HTMLIFrameElement& aOtherLoaderOwner,
     61                        mozilla::ErrorResult& aError);
     62 
     63  void SwapFrameLoaders(mozilla::dom::XULFrameElement& aOtherLoaderOwner,
     64                        mozilla::ErrorResult& aError);
     65 
     66  void SwapFrameLoaders(nsFrameLoaderOwner* aOtherLoaderOwner,
     67                        mozilla::ErrorResult& rv);
     68 
     69  /**
     70   * Helper method to map a HTML 'scrolling' attribute value (which can be null)
     71   * to a ScrollbarPreference value value.  scrolling="no" (and its synonyms)
     72   * map to Never, and anything else to Auto.
     73   */
     74  static mozilla::ScrollbarPreference MapScrollingAttribute(const nsAttrValue*);
     75 
     76  nsIPrincipal* GetSrcTriggeringPrincipal() const {
     77    return mSrcTriggeringPrincipal;
     78  }
     79 
     80 protected:
     81  virtual ~nsGenericHTMLFrameElement();
     82 
     83  // This doesn't really ensure a frame loader in all cases, only when
     84  // it makes sense.
     85  void EnsureFrameLoader();
     86  void LoadSrc();
     87  Document* GetContentDocument(nsIPrincipal& aSubjectPrincipal);
     88  mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetContentWindow();
     89 
     90  virtual void AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
     91                            const nsAttrValue* aValue,
     92                            const nsAttrValue* aOldValue,
     93                            nsIPrincipal* aSubjectPrincipal,
     94                            bool aNotify) override;
     95  virtual void OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName,
     96                                      const nsAttrValueOrString& aValue,
     97                                      bool aNotify) override;
     98 
     99  nsCOMPtr<nsIPrincipal> mSrcTriggeringPrincipal;
    100 
    101  /**
    102   * True if we have already loaded the frame's original src
    103   */
    104  bool mSrcLoadHappened;
    105 
    106  /**
    107   * True when the element is created by the parser using the
    108   * NS_FROM_PARSER_NETWORK flag.
    109   * If the element is modified, it may lose the flag.
    110   */
    111  bool mNetworkCreated;
    112 
    113  // This flag is only used by <iframe>. See HTMLIFrameElement::
    114  // FullscreenFlag() for details. It is placed here so that we
    115  // do not bloat any struct.
    116  bool mFullscreenFlag = false;
    117 
    118  /**
    119   * Represents the iframe is deferred loading until this element gets visible.
    120   * We just do not load if set and leave specific elements to set it (see
    121   * HTMLIFrameElement).
    122   */
    123  bool mLazyLoading = false;
    124 
    125 private:
    126  void GetManifestURL(nsAString& aOut);
    127 
    128  /**
    129   * This function is called by AfterSetAttr and OnAttrSetButNotChanged.
    130   * It will be called whether the value is being set or unset.
    131   *
    132   * @param aNamespaceID the namespace of the attr being set
    133   * @param aName the localname of the attribute being set
    134   * @param aValue the value being set or null if the value is being unset
    135   * @param aNotify Whether we plan to notify document observers.
    136   */
    137  void AfterMaybeChangeAttr(int32_t aNamespaceID, nsAtom* aName,
    138                            const nsAttrValueOrString* aValue,
    139                            nsIPrincipal* aMaybeScriptedPrincipal,
    140                            bool aNotify);
    141 
    142  mozilla::dom::BrowsingContext* GetContentWindowInternal();
    143 };
    144 
    145 #endif  // nsGenericHTMLFrameElement_h