Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsXBLBinding_h_
7 #define nsXBLBinding_h_
9 #include "nsXBLService.h"
10 #include "nsCOMPtr.h"
11 #include "nsAutoPtr.h"
12 #include "nsINodeList.h"
13 #include "nsIStyleRuleProcessor.h"
14 #include "nsClassHashtable.h"
15 #include "nsTArray.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "nsISupportsImpl.h"
18 #include "js/TypeDecls.h"
20 class nsXBLPrototypeBinding;
21 class nsIContent;
22 class nsIAtom;
23 class nsIDocument;
24 class nsIScriptContext;
26 namespace mozilla {
27 namespace dom {
29 class ShadowRoot;
30 class XBLChildrenElement;
32 } // namespace dom
33 } // namespace mozilla
35 class nsAnonymousContentList;
37 // *********************************************************************/
38 // The XBLBinding class
40 class nsXBLBinding MOZ_FINAL
41 {
42 public:
43 nsXBLBinding(nsXBLPrototypeBinding* aProtoBinding);
44 nsXBLBinding(mozilla::dom::ShadowRoot* aShadowRoot, nsXBLPrototypeBinding* aProtoBinding);
45 ~nsXBLBinding();
47 /**
48 * XBLBindings are refcounted. They are held onto in 3 ways:
49 * 1. The binding manager's binding table holds onto all bindings that are
50 * currently attached to a content node.
51 * 2. Bindings hold onto their base binding. This is important since
52 * the base binding itself may not be attached to anything.
53 * 3. The binding manager holds an additional reference to bindings
54 * which are queued to fire their constructors.
55 */
57 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsXBLBinding)
59 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLBinding)
61 nsXBLPrototypeBinding* PrototypeBinding() const { return mPrototypeBinding; }
62 nsIContent* GetAnonymousContent() { return mContent.get(); }
63 nsXBLBinding* GetBindingWithContent();
65 nsXBLBinding* GetBaseBinding() const { return mNextBinding; }
66 void SetBaseBinding(nsXBLBinding *aBinding);
68 nsIContent* GetBoundElement() { return mBoundElement; }
69 void SetBoundElement(nsIContent *aElement);
71 /*
72 * Does a lookup for a method or attribute provided by one of the bindings'
73 * prototype implementation. If found, |desc| will be set up appropriately,
74 * and wrapped into cx->compartment.
75 *
76 * May only be called when XBL code is being run in a separate scope, because
77 * otherwise we don't have untainted data with which to do a proper lookup.
78 */
79 bool LookupMember(JSContext* aCx, JS::Handle<jsid> aId,
80 JS::MutableHandle<JSPropertyDescriptor> aDesc);
82 /*
83 * Determines whether the binding has a field with the given name.
84 */
85 bool HasField(nsString& aName);
87 protected:
89 /*
90 * Internal version. Requires that aCx is in appropriate xbl scope.
91 */
92 bool LookupMemberInternal(JSContext* aCx, nsString& aName,
93 JS::Handle<jsid> aNameAsId,
94 JS::MutableHandle<JSPropertyDescriptor> aDesc,
95 JS::Handle<JSObject*> aXBLScope);
97 public:
99 void MarkForDeath();
100 bool MarkedForDeath() const { return mMarkedForDeath; }
102 bool HasStyleSheets() const;
103 bool InheritsStyle() const;
104 bool ImplementsInterface(REFNSIID aIID) const;
106 void GenerateAnonymousContent();
107 void InstallAnonymousContent(nsIContent* aAnonParent, nsIContent* aElement,
108 bool aNativeAnon);
109 static void UninstallAnonymousContent(nsIDocument* aDocument,
110 nsIContent* aAnonParent);
111 void InstallEventHandlers();
112 nsresult InstallImplementation();
114 void ExecuteAttachedHandler();
115 void ExecuteDetachedHandler();
116 void UnhookEventHandlers();
118 nsIAtom* GetBaseTag(int32_t* aNameSpaceID);
119 nsXBLBinding* RootBinding();
121 // Resolve all the fields for this binding and all ancestor bindings on the
122 // object |obj|. False return means a JS exception was set.
123 bool ResolveAllFields(JSContext *cx, JS::Handle<JSObject*> obj) const;
125 void AttributeChanged(nsIAtom* aAttribute, int32_t aNameSpaceID,
126 bool aRemoveFlag, bool aNotify);
128 void ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument);
130 void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData);
132 static nsresult DoInitJSClass(JSContext *cx, JS::Handle<JSObject*> obj,
133 const nsAFlatCString& aClassName,
134 nsXBLPrototypeBinding* aProtoBinding,
135 JS::MutableHandle<JSObject*> aClassObject,
136 bool* aNew);
138 bool AllowScripts();
140 mozilla::dom::XBLChildrenElement* FindInsertionPointFor(nsIContent* aChild);
142 bool HasFilteredInsertionPoints()
143 {
144 return !mInsertionPoints.IsEmpty();
145 }
147 mozilla::dom::XBLChildrenElement* GetDefaultInsertionPoint()
148 {
149 return mDefaultInsertionPoint;
150 }
152 // Removes all inserted node from <xbl:children> insertion points under us.
153 void ClearInsertionPoints();
155 // Returns a live node list that iterates over the anonymous nodes generated
156 // by this binding.
157 nsAnonymousContentList* GetAnonymousNodeList();
159 // MEMBER VARIABLES
160 protected:
162 bool mMarkedForDeath;
163 bool mUsingXBLScope;
165 nsXBLPrototypeBinding* mPrototypeBinding; // Weak, but we're holding a ref to the docinfo
166 nsCOMPtr<nsIContent> mContent; // Strong. Our anonymous content stays around with us.
167 nsRefPtr<nsXBLBinding> mNextBinding; // Strong. The derived binding owns the base class bindings.
169 nsIContent* mBoundElement; // [WEAK] We have a reference, but we don't own it.
171 // The <xbl:children> elements that we found in our <xbl:content> when we
172 // processed this binding. The default insertion point has no includes
173 // attribute and all other insertion points must have at least one includes
174 // attribute. These points must be up-to-date with respect to their parent's
175 // children, even if their parent has another binding attached to it,
176 // preventing us from rendering their contents directly.
177 nsRefPtr<mozilla::dom::XBLChildrenElement> mDefaultInsertionPoint;
178 nsTArray<nsRefPtr<mozilla::dom::XBLChildrenElement> > mInsertionPoints;
179 nsRefPtr<nsAnonymousContentList> mAnonymousContentList;
181 mozilla::dom::XBLChildrenElement* FindInsertionPointForInternal(nsIContent* aChild);
182 };
184 #endif // nsXBLBinding_h_