/src/mozilla-central/dom/html/nsGenericHTMLFrameElement.h
Line | Count | Source (jump to first uncovered line) |
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 "mozilla/Attributes.h" |
11 | | #include "mozilla/ErrorResult.h" |
12 | | #include "mozilla/dom/nsBrowserElement.h" |
13 | | |
14 | | #include "nsFrameLoader.h" |
15 | | #include "nsGenericHTMLElement.h" |
16 | | #include "nsIDOMEventListener.h" |
17 | | #include "nsIFrameLoaderOwner.h" |
18 | | #include "nsIMozBrowserFrame.h" |
19 | | |
20 | | namespace mozilla { |
21 | | namespace dom { |
22 | | class XULFrameElement; |
23 | | } |
24 | | } |
25 | | |
26 | | #define NS_GENERICHTMLFRAMEELEMENT_IID \ |
27 | | { 0x8190db72, 0xdab0, 0x4d72, \ |
28 | | { 0x94, 0x26, 0x87, 0x5f, 0x5a, 0x8a, 0x2a, 0xe5 } } |
29 | | |
30 | | /** |
31 | | * A helper class for frame elements |
32 | | */ |
33 | | class nsGenericHTMLFrameElement : public nsGenericHTMLElement, |
34 | | public nsIFrameLoaderOwner, |
35 | | public mozilla::nsBrowserElement, |
36 | | public nsIMozBrowserFrame |
37 | | { |
38 | | public: |
39 | | nsGenericHTMLFrameElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, |
40 | | mozilla::dom::FromParser aFromParser) |
41 | | : nsGenericHTMLElement(std::move(aNodeInfo)) |
42 | | , nsBrowserElement() |
43 | | , mSrcLoadHappened(false) |
44 | | , mNetworkCreated(aFromParser == mozilla::dom::FROM_PARSER_NETWORK) |
45 | | , mBrowserFrameListenersRegistered(false) |
46 | | , mFrameLoaderCreationDisallowed(false) |
47 | | , mReallyIsBrowser(false) |
48 | 0 | { |
49 | 0 | } |
50 | | |
51 | | NS_DECL_ISUPPORTS_INHERITED |
52 | | |
53 | | NS_DECL_NSIFRAMELOADEROWNER |
54 | | NS_DECL_NSIDOMMOZBROWSERFRAME |
55 | | NS_DECL_NSIMOZBROWSERFRAME |
56 | | |
57 | | NS_DECLARE_STATIC_IID_ACCESSOR(NS_GENERICHTMLFRAMEELEMENT_IID) |
58 | | |
59 | | // nsIContent |
60 | | virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, int32_t *aTabIndex) override; |
61 | | virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, |
62 | | nsIContent* aBindingParent) override; |
63 | | virtual void UnbindFromTree(bool aDeep = true, |
64 | | bool aNullParent = true) override; |
65 | | virtual void DestroyContent() override; |
66 | | |
67 | | nsresult CopyInnerTo(mozilla::dom::Element* aDest); |
68 | | |
69 | | virtual int32_t TabIndexDefault() override; |
70 | | |
71 | 0 | virtual nsIMozBrowserFrame* GetAsMozBrowserFrame() override { return this; } |
72 | | |
73 | | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsGenericHTMLFrameElement, |
74 | | nsGenericHTMLElement) |
75 | | |
76 | | void SwapFrameLoaders(mozilla::dom::HTMLIFrameElement& aOtherLoaderOwner, |
77 | | mozilla::ErrorResult& aError); |
78 | | |
79 | | void SwapFrameLoaders(mozilla::dom::XULFrameElement& aOtherLoaderOwner, |
80 | | mozilla::ErrorResult& aError); |
81 | | |
82 | | void SwapFrameLoaders(nsIFrameLoaderOwner* aOtherLoaderOwner, |
83 | | mozilla::ErrorResult& rv); |
84 | | |
85 | | void PresetOpenerWindow(mozIDOMWindowProxy* aOpenerWindow, |
86 | | mozilla::ErrorResult& aRv); |
87 | | |
88 | | static void InitStatics(); |
89 | | static bool BrowserFramesEnabled(); |
90 | | |
91 | | /** |
92 | | * Helper method to map a HTML 'scrolling' attribute value to a nsIScrollable |
93 | | * enum value. scrolling="no" (and its synonyms) maps to |
94 | | * nsIScrollable::Scrollbar_Never, and anything else (including nullptr) maps |
95 | | * to nsIScrollable::Scrollbar_Auto. |
96 | | * @param aValue the attribute value to map or nullptr |
97 | | * @return nsIScrollable::Scrollbar_Never or nsIScrollable::Scrollbar_Auto |
98 | | */ |
99 | | static int32_t MapScrollingAttribute(const nsAttrValue* aValue); |
100 | | |
101 | | nsIPrincipal* GetSrcTriggeringPrincipal() const |
102 | 0 | { |
103 | 0 | return mSrcTriggeringPrincipal; |
104 | 0 | } |
105 | | |
106 | | protected: |
107 | | virtual ~nsGenericHTMLFrameElement(); |
108 | | |
109 | | // This doesn't really ensure a frame loader in all cases, only when |
110 | | // it makes sense. |
111 | | void EnsureFrameLoader(); |
112 | | void LoadSrc(); |
113 | | nsIDocument* GetContentDocument(nsIPrincipal& aSubjectPrincipal); |
114 | | already_AddRefed<nsPIDOMWindowOuter> GetContentWindow(); |
115 | | |
116 | | virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, |
117 | | const nsAttrValue* aValue, |
118 | | const nsAttrValue* aOldValue, |
119 | | nsIPrincipal* aSubjectPrincipal, |
120 | | bool aNotify) override; |
121 | | virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName, |
122 | | const nsAttrValueOrString& aValue, |
123 | | bool aNotify) override; |
124 | | |
125 | | RefPtr<nsFrameLoader> mFrameLoader; |
126 | | nsCOMPtr<nsPIDOMWindowOuter> mOpenerWindow; |
127 | | |
128 | | nsCOMPtr<nsIPrincipal> mSrcTriggeringPrincipal; |
129 | | |
130 | | /** |
131 | | * True if we have already loaded the frame's original src |
132 | | */ |
133 | | bool mSrcLoadHappened; |
134 | | |
135 | | /** |
136 | | * True when the element is created by the parser using the |
137 | | * NS_FROM_PARSER_NETWORK flag. |
138 | | * If the element is modified, it may lose the flag. |
139 | | */ |
140 | | bool mNetworkCreated; |
141 | | |
142 | | bool mBrowserFrameListenersRegistered; |
143 | | bool mFrameLoaderCreationDisallowed; |
144 | | bool mReallyIsBrowser; |
145 | | |
146 | | // This flag is only used by <iframe>. See HTMLIFrameElement:: |
147 | | // FullscreenFlag() for details. It is placed here so that we |
148 | | // do not bloat any struct. |
149 | | bool mFullscreenFlag = false; |
150 | | |
151 | | private: |
152 | | void GetManifestURL(nsAString& aOut); |
153 | | |
154 | | /** |
155 | | * This function is called by AfterSetAttr and OnAttrSetButNotChanged. |
156 | | * It will be called whether the value is being set or unset. |
157 | | * |
158 | | * @param aNamespaceID the namespace of the attr being set |
159 | | * @param aName the localname of the attribute being set |
160 | | * @param aValue the value being set or null if the value is being unset |
161 | | * @param aNotify Whether we plan to notify document observers. |
162 | | */ |
163 | | void AfterMaybeChangeAttr(int32_t aNamespaceID, nsAtom* aName, |
164 | | const nsAttrValueOrString* aValue, |
165 | | nsIPrincipal* aMaybeScriptedPrincipal, |
166 | | bool aNotify); |
167 | | }; |
168 | | |
169 | | NS_DEFINE_STATIC_IID_ACCESSOR(nsGenericHTMLFrameElement, |
170 | | NS_GENERICHTMLFRAMEELEMENT_IID) |
171 | | |
172 | | #endif // nsGenericHTMLFrameElement_h |