1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/public/nsContentUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,2359 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/* A namespace class for static content utilities. */ 1.11 + 1.12 +#ifndef nsContentUtils_h___ 1.13 +#define nsContentUtils_h___ 1.14 + 1.15 +#if defined(XP_WIN) 1.16 +#include <float.h> 1.17 +#endif 1.18 + 1.19 +#if defined(SOLARIS) 1.20 +#include <ieeefp.h> 1.21 +#endif 1.22 + 1.23 +#include "js/TypeDecls.h" 1.24 +#include "js/Value.h" 1.25 +#include "js/RootingAPI.h" 1.26 +#include "mozilla/EventForwards.h" 1.27 +#include "mozilla/GuardObjects.h" 1.28 +#include "mozilla/TimeStamp.h" 1.29 +#include "nsContentListDeclarations.h" 1.30 +#include "nsMathUtils.h" 1.31 +#include "nsTArrayForwardDeclare.h" 1.32 +#include "Units.h" 1.33 + 1.34 +#if defined(XP_WIN) 1.35 +// Undefine LoadImage to prevent naming conflict with Windows. 1.36 +#undef LoadImage 1.37 +#endif 1.38 + 1.39 +class imgICache; 1.40 +class imgIContainer; 1.41 +class imgINotificationObserver; 1.42 +class imgIRequest; 1.43 +class imgLoader; 1.44 +class imgRequestProxy; 1.45 +class nsAutoScriptBlockerSuppressNodeRemoved; 1.46 +class nsHtml5StringParser; 1.47 +class nsIChannel; 1.48 +class nsIConsoleService; 1.49 +class nsIContent; 1.50 +class nsIContentPolicy; 1.51 +class nsIContentSecurityPolicy; 1.52 +class nsIDocShell; 1.53 +class nsIDocument; 1.54 +class nsIDocumentLoaderFactory; 1.55 +class nsIDocumentObserver; 1.56 +class nsIDOMDocument; 1.57 +class nsIDOMDocumentFragment; 1.58 +class nsIDOMEvent; 1.59 +class nsIDOMHTMLFormElement; 1.60 +class nsIDOMHTMLInputElement; 1.61 +class nsIDOMKeyEvent; 1.62 +class nsIDOMNode; 1.63 +class nsIDOMScriptObjectFactory; 1.64 +class nsIDOMWindow; 1.65 +class nsIDragSession; 1.66 +class nsIEditor; 1.67 +class nsIFragmentContentSink; 1.68 +class nsIFrame; 1.69 +class nsIImageLoadingContent; 1.70 +class nsIInterfaceRequestor; 1.71 +class nsIIOService; 1.72 +class nsIJSRuntimeService; 1.73 +class nsILineBreaker; 1.74 +class nsNameSpaceManager; 1.75 +class nsINodeInfo; 1.76 +class nsIObserver; 1.77 +class nsIParser; 1.78 +class nsIParserService; 1.79 +class nsIPresShell; 1.80 +class nsIPrincipal; 1.81 +class nsIRunnable; 1.82 +class nsIScriptContext; 1.83 +class nsIScriptGlobalObject; 1.84 +class nsIScriptSecurityManager; 1.85 +class nsIStringBundle; 1.86 +class nsIStringBundleService; 1.87 +class nsISupportsHashKey; 1.88 +class nsIURI; 1.89 +class nsIWidget; 1.90 +class nsIWordBreaker; 1.91 +class nsIXPConnect; 1.92 +class nsNodeInfoManager; 1.93 +class nsPIDOMWindow; 1.94 +class nsPresContext; 1.95 +class nsScriptObjectTracer; 1.96 +class nsStringBuffer; 1.97 +class nsStringHashKey; 1.98 +class nsTextFragment; 1.99 +class nsViewportInfo; 1.100 +class nsWrapperCache; 1.101 +class nsAttrValue; 1.102 + 1.103 +struct JSPropertyDescriptor; 1.104 +struct JSRuntime; 1.105 +struct nsIntMargin; 1.106 + 1.107 +template<class E> class nsCOMArray; 1.108 +template<class K, class V> class nsDataHashtable; 1.109 +template<class K, class V> class nsRefPtrHashtable; 1.110 +template<class T> class nsReadingIterator; 1.111 + 1.112 +namespace mozilla { 1.113 +class ErrorResult; 1.114 +class EventListenerManager; 1.115 + 1.116 +namespace dom { 1.117 +class DocumentFragment; 1.118 +class Element; 1.119 +class EventTarget; 1.120 +class Selection; 1.121 +} // namespace dom 1.122 + 1.123 +namespace layers { 1.124 +class LayerManager; 1.125 +} // namespace layers 1.126 + 1.127 +// Called back from DeferredFinalize. Should add 'thing' to the array of smart 1.128 +// pointers in 'pointers', creating the array if 'pointers' is null, and return 1.129 +// the array. 1.130 +typedef void* (*DeferredFinalizeAppendFunction)(void* pointers, void* thing); 1.131 + 1.132 +// Called to finalize a number of objects. Slice is the number of objects 1.133 +// to finalize, or if it's UINT32_MAX, all objects should be finalized. 1.134 +// Return value indicates whether it finalized all objects in the buffer. 1.135 +typedef bool (*DeferredFinalizeFunction)(uint32_t slice, void* data); 1.136 + 1.137 +} // namespace mozilla 1.138 + 1.139 +class nsIBidiKeyboard; 1.140 + 1.141 +extern const char kLoadAsData[]; 1.142 + 1.143 +// Stolen from nsReadableUtils, but that's OK, since we can declare the same 1.144 +// name multiple times. 1.145 +const nsAFlatString& EmptyString(); 1.146 +const nsAFlatCString& EmptyCString(); 1.147 + 1.148 +enum EventNameType { 1.149 + EventNameType_None = 0x0000, 1.150 + EventNameType_HTML = 0x0001, 1.151 + EventNameType_XUL = 0x0002, 1.152 + EventNameType_SVGGraphic = 0x0004, // svg graphic elements 1.153 + EventNameType_SVGSVG = 0x0008, // the svg element 1.154 + EventNameType_SMIL = 0x0010, // smil elements 1.155 + EventNameType_HTMLBodyOrFramesetOnly = 0x0020, 1.156 + 1.157 + EventNameType_HTMLXUL = 0x0003, 1.158 + EventNameType_All = 0xFFFF 1.159 +}; 1.160 + 1.161 +struct EventNameMapping 1.162 +{ 1.163 + nsIAtom* mAtom; 1.164 + uint32_t mId; 1.165 + int32_t mType; 1.166 + uint32_t mStructType; 1.167 +}; 1.168 + 1.169 +struct nsShortcutCandidate { 1.170 + nsShortcutCandidate(uint32_t aCharCode, bool aIgnoreShift) : 1.171 + mCharCode(aCharCode), mIgnoreShift(aIgnoreShift) 1.172 + { 1.173 + } 1.174 + uint32_t mCharCode; 1.175 + bool mIgnoreShift; 1.176 +}; 1.177 + 1.178 +class nsContentUtils 1.179 +{ 1.180 + friend class nsAutoScriptBlockerSuppressNodeRemoved; 1.181 + typedef mozilla::dom::Element Element; 1.182 + typedef mozilla::TimeDuration TimeDuration; 1.183 + 1.184 +public: 1.185 + static nsresult Init(); 1.186 + 1.187 + /** 1.188 + * Get a JSContext from the document's scope object. 1.189 + */ 1.190 + static JSContext* GetContextFromDocument(nsIDocument *aDocument); 1.191 + 1.192 + static bool IsCallerChrome(); 1.193 + static bool ThreadsafeIsCallerChrome(); 1.194 + static bool IsCallerXBL(); 1.195 + 1.196 + static bool IsImageSrcSetDisabled(); 1.197 + 1.198 + static bool LookupBindingMember(JSContext* aCx, nsIContent *aContent, 1.199 + JS::Handle<jsid> aId, 1.200 + JS::MutableHandle<JSPropertyDescriptor> aDesc); 1.201 + 1.202 + /** 1.203 + * Returns the parent node of aChild crossing document boundaries. 1.204 + */ 1.205 + static nsINode* GetCrossDocParentNode(nsINode* aChild); 1.206 + 1.207 + /** 1.208 + * Do not ever pass null pointers to this method. If one of your 1.209 + * nsIContents is null, you have to decide for yourself what 1.210 + * "IsDescendantOf" really means. 1.211 + * 1.212 + * @param aPossibleDescendant node to test for being a descendant of 1.213 + * aPossibleAncestor 1.214 + * @param aPossibleAncestor node to test for being an ancestor of 1.215 + * aPossibleDescendant 1.216 + * @return true if aPossibleDescendant is a descendant of 1.217 + * aPossibleAncestor (or is aPossibleAncestor). false 1.218 + * otherwise. 1.219 + */ 1.220 + static bool ContentIsDescendantOf(const nsINode* aPossibleDescendant, 1.221 + const nsINode* aPossibleAncestor); 1.222 + 1.223 + /** 1.224 + * Similar to ContentIsDescendantOf, except will treat an HTMLTemplateElement 1.225 + * or ShadowRoot as an ancestor of things in the corresponding DocumentFragment. 1.226 + * See the concept of "host-including inclusive ancestor" in the DOM 1.227 + * specification. 1.228 + */ 1.229 + static bool ContentIsHostIncludingDescendantOf( 1.230 + const nsINode* aPossibleDescendant, const nsINode* aPossibleAncestor); 1.231 + 1.232 + /** 1.233 + * Similar to ContentIsDescendantOf except it crosses document boundaries. 1.234 + */ 1.235 + static bool ContentIsCrossDocDescendantOf(nsINode* aPossibleDescendant, 1.236 + nsINode* aPossibleAncestor); 1.237 + 1.238 + /* 1.239 + * This method fills the |aArray| with all ancestor nodes of |aNode| 1.240 + * including |aNode| at the zero index. 1.241 + */ 1.242 + static nsresult GetAncestors(nsINode* aNode, 1.243 + nsTArray<nsINode*>& aArray); 1.244 + 1.245 + /* 1.246 + * This method fills |aAncestorNodes| with all ancestor nodes of |aNode| 1.247 + * including |aNode| (QI'd to nsIContent) at the zero index. 1.248 + * For each ancestor, there is a corresponding element in |aAncestorOffsets| 1.249 + * which is the IndexOf the child in relation to its parent. 1.250 + * 1.251 + * This method just sucks. 1.252 + */ 1.253 + static nsresult GetAncestorsAndOffsets(nsIDOMNode* aNode, 1.254 + int32_t aOffset, 1.255 + nsTArray<nsIContent*>* aAncestorNodes, 1.256 + nsTArray<int32_t>* aAncestorOffsets); 1.257 + 1.258 + /* 1.259 + * The out parameter, |aCommonAncestor| will be the closest node, if any, 1.260 + * to both |aNode| and |aOther| which is also an ancestor of each. 1.261 + * Returns an error if the two nodes are disconnected and don't have 1.262 + * a common ancestor. 1.263 + */ 1.264 + static nsresult GetCommonAncestor(nsIDOMNode *aNode, 1.265 + nsIDOMNode *aOther, 1.266 + nsIDOMNode** aCommonAncestor); 1.267 + 1.268 + /** 1.269 + * Returns the common ancestor, if any, for two nodes. Returns null if the 1.270 + * nodes are disconnected. 1.271 + */ 1.272 + static nsINode* GetCommonAncestor(nsINode* aNode1, 1.273 + nsINode* aNode2); 1.274 + 1.275 + /** 1.276 + * Returns true if aNode1 is before aNode2 in the same connected 1.277 + * tree. 1.278 + */ 1.279 + static bool PositionIsBefore(nsINode* aNode1, nsINode* aNode2); 1.280 + 1.281 + /** 1.282 + * Utility routine to compare two "points", where a point is a 1.283 + * node/offset pair 1.284 + * Returns -1 if point1 < point2, 1, if point1 > point2, 1.285 + * 0 if error or if point1 == point2. 1.286 + * NOTE! If the two nodes aren't in the same connected subtree, 1.287 + * the result is 1, and the optional aDisconnected parameter 1.288 + * is set to true. 1.289 + */ 1.290 + static int32_t ComparePoints(nsINode* aParent1, int32_t aOffset1, 1.291 + nsINode* aParent2, int32_t aOffset2, 1.292 + bool* aDisconnected = nullptr); 1.293 + static int32_t ComparePoints(nsIDOMNode* aParent1, int32_t aOffset1, 1.294 + nsIDOMNode* aParent2, int32_t aOffset2, 1.295 + bool* aDisconnected = nullptr); 1.296 + 1.297 + /** 1.298 + * Brute-force search of the element subtree rooted at aContent for 1.299 + * an element with the given id. aId must be nonempty, otherwise 1.300 + * this method may return nodes even if they have no id! 1.301 + */ 1.302 + static Element* MatchElementId(nsIContent *aContent, const nsAString& aId); 1.303 + 1.304 + /** 1.305 + * Similar to above, but to be used if one already has an atom for the ID 1.306 + */ 1.307 + static Element* MatchElementId(nsIContent *aContent, const nsIAtom* aId); 1.308 + 1.309 + /** 1.310 + * Reverses the document position flags passed in. 1.311 + * 1.312 + * @param aDocumentPosition The document position flags to be reversed. 1.313 + * 1.314 + * @return The reversed document position flags. 1.315 + * 1.316 + * @see nsIDOMNode 1.317 + */ 1.318 + static uint16_t ReverseDocumentPosition(uint16_t aDocumentPosition); 1.319 + 1.320 + static uint32_t CopyNewlineNormalizedUnicodeTo(const nsAString& aSource, 1.321 + uint32_t aSrcOffset, 1.322 + char16_t* aDest, 1.323 + uint32_t aLength, 1.324 + bool& aLastCharCR); 1.325 + 1.326 + static uint32_t CopyNewlineNormalizedUnicodeTo(nsReadingIterator<char16_t>& aSrcStart, const nsReadingIterator<char16_t>& aSrcEnd, nsAString& aDest); 1.327 + 1.328 + static const nsDependentSubstring TrimCharsInSet(const char* aSet, 1.329 + const nsAString& aValue); 1.330 + 1.331 + template<bool IsWhitespace(char16_t)> 1.332 + static const nsDependentSubstring TrimWhitespace(const nsAString& aStr, 1.333 + bool aTrimTrailing = true); 1.334 + 1.335 + /** 1.336 + * Returns true if aChar is of class Ps, Pi, Po, Pf, or Pe. 1.337 + */ 1.338 + static bool IsFirstLetterPunctuation(uint32_t aChar); 1.339 + static bool IsFirstLetterPunctuationAt(const nsTextFragment* aFrag, uint32_t aOffset); 1.340 + 1.341 + /** 1.342 + * Returns true if aChar is of class Lu, Ll, Lt, Lm, Lo, Nd, Nl or No 1.343 + */ 1.344 + static bool IsAlphanumeric(uint32_t aChar); 1.345 + static bool IsAlphanumericAt(const nsTextFragment* aFrag, uint32_t aOffset); 1.346 + 1.347 + /* 1.348 + * Is the character an HTML whitespace character? 1.349 + * 1.350 + * We define whitespace using the list in HTML5 and css3-selectors: 1.351 + * U+0009, U+000A, U+000C, U+000D, U+0020 1.352 + * 1.353 + * HTML 4.01 also lists U+200B (zero-width space). 1.354 + */ 1.355 + static bool IsHTMLWhitespace(char16_t aChar); 1.356 + 1.357 + /* 1.358 + * Returns whether the character is an HTML whitespace (see IsHTMLWhitespace) 1.359 + * or a nbsp character (U+00A0). 1.360 + */ 1.361 + static bool IsHTMLWhitespaceOrNBSP(char16_t aChar); 1.362 + 1.363 + /** 1.364 + * Is the HTML local name a block element? 1.365 + */ 1.366 + static bool IsHTMLBlock(nsIAtom* aLocalName); 1.367 + 1.368 + /** 1.369 + * Is the HTML local name a void element? 1.370 + */ 1.371 + static bool IsHTMLVoid(nsIAtom* aLocalName); 1.372 + 1.373 + /** 1.374 + * Parse a margin string of format 'top, right, bottom, left' into 1.375 + * an nsIntMargin. 1.376 + * 1.377 + * @param aString the string to parse 1.378 + * @param aResult the resulting integer 1.379 + * @return whether the value could be parsed 1.380 + */ 1.381 + static bool ParseIntMarginValue(const nsAString& aString, nsIntMargin& aResult); 1.382 + 1.383 + /** 1.384 + * Parse the value of the <font size=""> attribute according to the HTML5 1.385 + * spec as of April 16, 2012. 1.386 + * 1.387 + * @param aValue the value to parse 1.388 + * @return 1 to 7, or 0 if the value couldn't be parsed 1.389 + */ 1.390 + static int32_t ParseLegacyFontSize(const nsAString& aValue); 1.391 + 1.392 + static void Shutdown(); 1.393 + 1.394 + /** 1.395 + * Checks whether two nodes come from the same origin. 1.396 + */ 1.397 + static nsresult CheckSameOrigin(const nsINode* aTrustedNode, 1.398 + nsIDOMNode* aUnTrustedNode); 1.399 + static nsresult CheckSameOrigin(const nsINode* aTrustedNode, 1.400 + const nsINode* unTrustedNode); 1.401 + 1.402 + // Check if the (JS) caller can access aNode. 1.403 + static bool CanCallerAccess(nsIDOMNode *aNode); 1.404 + static bool CanCallerAccess(nsINode* aNode); 1.405 + 1.406 + // Check if the (JS) caller can access aWindow. 1.407 + // aWindow can be either outer or inner window. 1.408 + static bool CanCallerAccess(nsPIDOMWindow* aWindow); 1.409 + 1.410 + /** 1.411 + * Get the window through the JS context that's currently on the stack. 1.412 + * If there's no JS context currently on the stack, returns null. 1.413 + */ 1.414 + static nsPIDOMWindow *GetWindowFromCaller(); 1.415 + 1.416 + /** 1.417 + * The two GetDocumentFrom* functions below allow a caller to get at a 1.418 + * document that is relevant to the currently executing script. 1.419 + * 1.420 + * GetDocumentFromCaller gets its document by looking at the last called 1.421 + * function and finding the document that the function itself relates to. 1.422 + * For example, consider two windows A and B in the same origin. B has a 1.423 + * function which does something that ends up needing the current document. 1.424 + * If a script in window A were to call B's function, GetDocumentFromCaller 1.425 + * would find that function (in B) and return B's document. 1.426 + * 1.427 + * GetDocumentFromContext gets its document by looking at the currently 1.428 + * executing context's global object and returning its document. Thus, 1.429 + * given the example above, GetDocumentFromCaller would see that the 1.430 + * currently executing script was in window A, and return A's document. 1.431 + */ 1.432 + /** 1.433 + * Get the document from the currently executing function. This will return 1.434 + * the document that the currently executing function is in/from. 1.435 + * 1.436 + * @return The document or null if no JS Context. 1.437 + */ 1.438 + static nsIDocument* GetDocumentFromCaller(); 1.439 + 1.440 + /** 1.441 + * Get the document through the JS context that's currently on the stack. 1.442 + * If there's no JS context currently on the stack it will return null. 1.443 + * This will return the document of the calling script. 1.444 + * 1.445 + * @return The document or null if no JS context 1.446 + */ 1.447 + static nsIDocument* GetDocumentFromContext(); 1.448 + 1.449 + // Check if a node is in the document prolog, i.e. before the document 1.450 + // element. 1.451 + static bool InProlog(nsINode *aNode); 1.452 + 1.453 + static nsIParserService* GetParserService(); 1.454 + 1.455 + static nsNameSpaceManager* NameSpaceManager() 1.456 + { 1.457 + return sNameSpaceManager; 1.458 + } 1.459 + 1.460 + static nsIIOService* GetIOService() 1.461 + { 1.462 + return sIOService; 1.463 + } 1.464 + 1.465 + static nsIBidiKeyboard* GetBidiKeyboard(); 1.466 + 1.467 + /** 1.468 + * Get the cache security manager service. Can return null if the layout 1.469 + * module has been shut down. 1.470 + */ 1.471 + static nsIScriptSecurityManager* GetSecurityManager() 1.472 + { 1.473 + return sSecurityManager; 1.474 + } 1.475 + 1.476 + /** 1.477 + * Get the ContentSecurityPolicy for a JS context. 1.478 + **/ 1.479 + static bool GetContentSecurityPolicy(JSContext* aCx, 1.480 + nsIContentSecurityPolicy** aCSP); 1.481 + 1.482 + // Returns the subject principal. Guaranteed to return non-null. May only 1.483 + // be called when nsContentUtils is initialized. 1.484 + static nsIPrincipal* GetSubjectPrincipal(); 1.485 + 1.486 + // Returns the principal of the given JS object. This should never be null 1.487 + // for any object in the XPConnect runtime. 1.488 + // 1.489 + // In general, being interested in the principal of an object is enough to 1.490 + // guarantee that the return value is non-null. 1.491 + static nsIPrincipal* GetObjectPrincipal(JSObject* aObj); 1.492 + 1.493 + static nsresult GenerateStateKey(nsIContent* aContent, 1.494 + const nsIDocument* aDocument, 1.495 + nsACString& aKey); 1.496 + 1.497 + /** 1.498 + * Create a new nsIURI from aSpec, using aBaseURI as the base. The 1.499 + * origin charset of the new nsIURI will be the document charset of 1.500 + * aDocument. 1.501 + */ 1.502 + static nsresult NewURIWithDocumentCharset(nsIURI** aResult, 1.503 + const nsAString& aSpec, 1.504 + nsIDocument* aDocument, 1.505 + nsIURI* aBaseURI); 1.506 + 1.507 + /** 1.508 + * Convert aInput (in encoding aEncoding) to UTF16 in aOutput. 1.509 + * 1.510 + * @param aEncoding the Gecko-canonical name of the encoding or the empty 1.511 + * string (meaning UTF-8) 1.512 + */ 1.513 + static nsresult ConvertStringFromEncoding(const nsACString& aEncoding, 1.514 + const nsACString& aInput, 1.515 + nsAString& aOutput); 1.516 + 1.517 + /** 1.518 + * Determine whether a buffer begins with a BOM for UTF-8, UTF-16LE, 1.519 + * UTF-16BE 1.520 + * 1.521 + * @param aBuffer the buffer to check 1.522 + * @param aLength the length of the buffer 1.523 + * @param aCharset empty if not found 1.524 + * @return boolean indicating whether a BOM was detected. 1.525 + */ 1.526 + static bool CheckForBOM(const unsigned char* aBuffer, uint32_t aLength, 1.527 + nsACString& aCharset); 1.528 + 1.529 + /** 1.530 + * Returns true if |aName| is a valid name to be registered via 1.531 + * document.registerElement. 1.532 + */ 1.533 + static bool IsCustomElementName(nsIAtom* aName); 1.534 + 1.535 + static nsresult CheckQName(const nsAString& aQualifiedName, 1.536 + bool aNamespaceAware = true, 1.537 + const char16_t** aColon = nullptr); 1.538 + 1.539 + static nsresult SplitQName(const nsIContent* aNamespaceResolver, 1.540 + const nsAFlatString& aQName, 1.541 + int32_t *aNamespace, nsIAtom **aLocalName); 1.542 + 1.543 + static nsresult GetNodeInfoFromQName(const nsAString& aNamespaceURI, 1.544 + const nsAString& aQualifiedName, 1.545 + nsNodeInfoManager* aNodeInfoManager, 1.546 + uint16_t aNodeType, 1.547 + nsINodeInfo** aNodeInfo); 1.548 + 1.549 + static void SplitExpatName(const char16_t *aExpatName, nsIAtom **aPrefix, 1.550 + nsIAtom **aTagName, int32_t *aNameSpaceID); 1.551 + 1.552 + // Get a permission-manager setting for the given principal and type. 1.553 + // If the pref doesn't exist or if it isn't ALLOW_ACTION, false is 1.554 + // returned, otherwise true is returned. Always returns true for the 1.555 + // system principal, and false for a null principal. 1.556 + static bool IsSitePermAllow(nsIPrincipal* aPrincipal, const char* aType); 1.557 + 1.558 + // Get a permission-manager setting for the given principal and type. 1.559 + // If the pref doesn't exist or if it isn't DENY_ACTION, false is 1.560 + // returned, otherwise true is returned. Always returns false for the 1.561 + // system principal, and true for a null principal. 1.562 + static bool IsSitePermDeny(nsIPrincipal* aPrincipal, const char* aType); 1.563 + 1.564 + // Get a permission-manager setting for the given principal and type. 1.565 + // If the pref doesn't exist or if it isn't ALLOW_ACTION, false is 1.566 + // returned, otherwise true is returned. Always returns true for the 1.567 + // system principal, and false for a null principal. 1.568 + // This version checks the permission for an exact host match on 1.569 + // the principal 1.570 + static bool IsExactSitePermAllow(nsIPrincipal* aPrincipal, const char* aType); 1.571 + 1.572 + // Get a permission-manager setting for the given principal and type. 1.573 + // If the pref doesn't exist or if it isn't DENY_ACTION, false is 1.574 + // returned, otherwise true is returned. Always returns false for the 1.575 + // system principal, and true for a null principal. 1.576 + // This version checks the permission for an exact host match on 1.577 + // the principal 1.578 + static bool IsExactSitePermDeny(nsIPrincipal* aPrincipal, const char* aType); 1.579 + 1.580 + // Returns true if aDoc1 and aDoc2 have equal NodePrincipal()s. 1.581 + static bool HaveEqualPrincipals(nsIDocument* aDoc1, nsIDocument* aDoc2); 1.582 + 1.583 + static nsILineBreaker* LineBreaker() 1.584 + { 1.585 + return sLineBreaker; 1.586 + } 1.587 + 1.588 + static nsIWordBreaker* WordBreaker() 1.589 + { 1.590 + return sWordBreaker; 1.591 + } 1.592 + 1.593 + /** 1.594 + * Regster aObserver as a shutdown observer. A strong reference is held 1.595 + * to aObserver until UnregisterShutdownObserver is called. 1.596 + */ 1.597 + static void RegisterShutdownObserver(nsIObserver* aObserver); 1.598 + static void UnregisterShutdownObserver(nsIObserver* aObserver); 1.599 + 1.600 + /** 1.601 + * @return true if aContent has an attribute aName in namespace aNameSpaceID, 1.602 + * and the attribute value is non-empty. 1.603 + */ 1.604 + static bool HasNonEmptyAttr(const nsIContent* aContent, int32_t aNameSpaceID, 1.605 + nsIAtom* aName); 1.606 + 1.607 + /** 1.608 + * Method that gets the primary presContext for the node. 1.609 + * 1.610 + * @param aContent The content node. 1.611 + * @return the presContext, or nullptr if the content is not in a document 1.612 + * (if GetCurrentDoc returns nullptr) 1.613 + */ 1.614 + static nsPresContext* GetContextForContent(const nsIContent* aContent); 1.615 + 1.616 + /** 1.617 + * Method to do security and content policy checks on the image URI 1.618 + * 1.619 + * @param aURI uri of the image to be loaded 1.620 + * @param aContext the context the image is loaded in (eg an element) 1.621 + * @param aLoadingDocument the document we belong to 1.622 + * @param aLoadingPrincipal the principal doing the load 1.623 + * @param aImageBlockingStatus the nsIContentPolicy blocking status for this 1.624 + * image. This will be set even if a security check fails for the 1.625 + * image, to some reasonable REJECT_* value. This out param will only 1.626 + * be set if it's non-null. 1.627 + * @return true if the load can proceed, or false if it is blocked. 1.628 + * Note that aImageBlockingStatus, if set will always be an ACCEPT 1.629 + * status if true is returned and always be a REJECT_* status if 1.630 + * false is returned. 1.631 + */ 1.632 + static bool CanLoadImage(nsIURI* aURI, 1.633 + nsISupports* aContext, 1.634 + nsIDocument* aLoadingDocument, 1.635 + nsIPrincipal* aLoadingPrincipal, 1.636 + int16_t* aImageBlockingStatus = nullptr); 1.637 + /** 1.638 + * Method to start an image load. This does not do any security checks. 1.639 + * This method will attempt to make aURI immutable; a caller that wants to 1.640 + * keep a mutable version around should pass in a clone. 1.641 + * 1.642 + * @param aURI uri of the image to be loaded 1.643 + * @param aLoadingDocument the document we belong to 1.644 + * @param aLoadingPrincipal the principal doing the load 1.645 + * @param aReferrer the referrer URI 1.646 + * @param aObserver the observer for the image load 1.647 + * @param aLoadFlags the load flags to use. See nsIRequest 1.648 + * @return the imgIRequest for the image load 1.649 + */ 1.650 + static nsresult LoadImage(nsIURI* aURI, 1.651 + nsIDocument* aLoadingDocument, 1.652 + nsIPrincipal* aLoadingPrincipal, 1.653 + nsIURI* aReferrer, 1.654 + imgINotificationObserver* aObserver, 1.655 + int32_t aLoadFlags, 1.656 + const nsAString& initiatorType, 1.657 + imgRequestProxy** aRequest); 1.658 + 1.659 + /** 1.660 + * Obtain an image loader that respects the given document/channel's privacy status. 1.661 + * Null document/channel arguments return the public image loader. 1.662 + */ 1.663 + static imgLoader* GetImgLoaderForDocument(nsIDocument* aDoc); 1.664 + static imgLoader* GetImgLoaderForChannel(nsIChannel* aChannel); 1.665 + 1.666 + /** 1.667 + * Returns whether the given URI is in the image cache. 1.668 + */ 1.669 + static bool IsImageInCache(nsIURI* aURI, nsIDocument* aDocument); 1.670 + 1.671 + /** 1.672 + * Method to get an imgIContainer from an image loading content 1.673 + * 1.674 + * @param aContent The image loading content. Must not be null. 1.675 + * @param aRequest The image request [out] 1.676 + * @return the imgIContainer corresponding to the first frame of the image 1.677 + */ 1.678 + static already_AddRefed<imgIContainer> GetImageFromContent(nsIImageLoadingContent* aContent, imgIRequest **aRequest = nullptr); 1.679 + 1.680 + /** 1.681 + * Helper method to call imgIRequest::GetStaticRequest. 1.682 + */ 1.683 + static already_AddRefed<imgRequestProxy> GetStaticRequest(imgRequestProxy* aRequest); 1.684 + 1.685 + /** 1.686 + * Method that decides whether a content node is draggable 1.687 + * 1.688 + * @param aContent The content node to test. 1.689 + * @return whether it's draggable 1.690 + */ 1.691 + static bool ContentIsDraggable(nsIContent* aContent); 1.692 + 1.693 + /** 1.694 + * Method that decides whether a content node is a draggable image 1.695 + * 1.696 + * @param aContent The content node to test. 1.697 + * @return whether it's a draggable image 1.698 + */ 1.699 + static bool IsDraggableImage(nsIContent* aContent); 1.700 + 1.701 + /** 1.702 + * Method that decides whether a content node is a draggable link 1.703 + * 1.704 + * @param aContent The content node to test. 1.705 + * @return whether it's a draggable link 1.706 + */ 1.707 + static bool IsDraggableLink(const nsIContent* aContent); 1.708 + 1.709 + /** 1.710 + * Convenience method to create a new nodeinfo that differs only by name 1.711 + * from aNodeInfo. 1.712 + */ 1.713 + static nsresult NameChanged(nsINodeInfo* aNodeInfo, nsIAtom* aName, 1.714 + nsINodeInfo** aResult); 1.715 + 1.716 + /** 1.717 + * Returns the appropriate event argument names for the specified 1.718 + * namespace and event name. Added because we need to switch between 1.719 + * SVG's "evt" and the rest of the world's "event", and because onerror 1.720 + * takes 3 args. 1.721 + */ 1.722 + static void GetEventArgNames(int32_t aNameSpaceID, nsIAtom *aEventName, 1.723 + uint32_t *aArgCount, const char*** aArgNames); 1.724 + 1.725 + /** 1.726 + * If aNode is not an element, return true exactly when aContent's binding 1.727 + * parent is null. 1.728 + * 1.729 + * If aNode is an element, return true exactly when aContent's binding parent 1.730 + * is the same as aNode's. 1.731 + * 1.732 + * This method is particularly useful for callers who are trying to ensure 1.733 + * that they are working with a non-anonymous descendant of a given node. If 1.734 + * aContent is a descendant of aNode, a return value of false from this 1.735 + * method means that it's an anonymous descendant from aNode's point of view. 1.736 + * 1.737 + * Both arguments to this method must be non-null. 1.738 + */ 1.739 + static bool IsInSameAnonymousTree(const nsINode* aNode, const nsIContent* aContent); 1.740 + 1.741 + /** 1.742 + * Return the nsIXPConnect service. 1.743 + */ 1.744 + static nsIXPConnect *XPConnect() 1.745 + { 1.746 + return sXPConnect; 1.747 + } 1.748 + 1.749 + /** 1.750 + * Report simple error message to the browser console 1.751 + * @param aErrorText the error message 1.752 + * @param classification Name of the module reporting error 1.753 + */ 1.754 + static void LogSimpleConsoleError(const nsAString& aErrorText, 1.755 + const char * classification); 1.756 + 1.757 + /** 1.758 + * Report a non-localized error message to the error console. 1.759 + * @param aErrorText the error message 1.760 + * @param aErrorFlags See nsIScriptError. 1.761 + * @param aCategory Name of module reporting error. 1.762 + * @param aDocument Reference to the document which triggered the message. 1.763 + * @param [aURI=nullptr] (Optional) URI of resource containing error. 1.764 + * @param [aSourceLine=EmptyString()] (Optional) The text of the line that 1.765 + contains the error (may be empty). 1.766 + * @param [aLineNumber=0] (Optional) Line number within resource 1.767 + containing error. 1.768 + * @param [aColumnNumber=0] (Optional) Column number within resource 1.769 + containing error. 1.770 + If aURI is null, then aDocument->GetDocumentURI() is used. 1.771 + */ 1.772 + static nsresult ReportToConsoleNonLocalized(const nsAString& aErrorText, 1.773 + uint32_t aErrorFlags, 1.774 + const nsACString& aCategory, 1.775 + nsIDocument* aDocument, 1.776 + nsIURI* aURI = nullptr, 1.777 + const nsAFlatString& aSourceLine 1.778 + = EmptyString(), 1.779 + uint32_t aLineNumber = 0, 1.780 + uint32_t aColumnNumber = 0); 1.781 + 1.782 + /** 1.783 + * Report a localized error message to the error console. 1.784 + * @param aErrorFlags See nsIScriptError. 1.785 + * @param aCategory Name of module reporting error. 1.786 + * @param aDocument Reference to the document which triggered the message. 1.787 + * @param aFile Properties file containing localized message. 1.788 + * @param aMessageName Name of localized message. 1.789 + * @param [aParams=nullptr] (Optional) Parameters to be substituted into 1.790 + localized message. 1.791 + * @param [aParamsLength=0] (Optional) Length of aParams. 1.792 + * @param [aURI=nullptr] (Optional) URI of resource containing error. 1.793 + * @param [aSourceLine=EmptyString()] (Optional) The text of the line that 1.794 + contains the error (may be empty). 1.795 + * @param [aLineNumber=0] (Optional) Line number within resource 1.796 + containing error. 1.797 + * @param [aColumnNumber=0] (Optional) Column number within resource 1.798 + containing error. 1.799 + If aURI is null, then aDocument->GetDocumentURI() is used. 1.800 + */ 1.801 + enum PropertiesFile { 1.802 + eCSS_PROPERTIES, 1.803 + eXBL_PROPERTIES, 1.804 + eXUL_PROPERTIES, 1.805 + eLAYOUT_PROPERTIES, 1.806 + eFORMS_PROPERTIES, 1.807 + ePRINTING_PROPERTIES, 1.808 + eDOM_PROPERTIES, 1.809 + eHTMLPARSER_PROPERTIES, 1.810 + eSVG_PROPERTIES, 1.811 + eBRAND_PROPERTIES, 1.812 + eCOMMON_DIALOG_PROPERTIES, 1.813 + eMATHML_PROPERTIES, 1.814 + eSECURITY_PROPERTIES, 1.815 + PropertiesFile_COUNT 1.816 + }; 1.817 + static nsresult ReportToConsole(uint32_t aErrorFlags, 1.818 + const nsACString& aCategory, 1.819 + nsIDocument* aDocument, 1.820 + PropertiesFile aFile, 1.821 + const char *aMessageName, 1.822 + const char16_t **aParams = nullptr, 1.823 + uint32_t aParamsLength = 0, 1.824 + nsIURI* aURI = nullptr, 1.825 + const nsAFlatString& aSourceLine 1.826 + = EmptyString(), 1.827 + uint32_t aLineNumber = 0, 1.828 + uint32_t aColumnNumber = 0); 1.829 + 1.830 + static void LogMessageToConsole(const char* aMsg, ...); 1.831 + 1.832 + /** 1.833 + * Get the localized string named |aKey| in properties file |aFile|. 1.834 + */ 1.835 + static nsresult GetLocalizedString(PropertiesFile aFile, 1.836 + const char* aKey, 1.837 + nsXPIDLString& aResult); 1.838 + 1.839 + /** 1.840 + * A helper function that parses a sandbox attribute (of an <iframe> or 1.841 + * a CSP directive) and converts it to the set of flags used internally. 1.842 + * 1.843 + * @param sandboxAttr the sandbox attribute 1.844 + * @return the set of flags (0 if sandboxAttr is null) 1.845 + */ 1.846 + static uint32_t ParseSandboxAttributeToFlags(const nsAttrValue* sandboxAttr); 1.847 + 1.848 + 1.849 + /** 1.850 + * Fill (with the parameters given) the localized string named |aKey| in 1.851 + * properties file |aFile|. 1.852 + */ 1.853 +private: 1.854 + static nsresult FormatLocalizedString(PropertiesFile aFile, 1.855 + const char* aKey, 1.856 + const char16_t** aParams, 1.857 + uint32_t aParamsLength, 1.858 + nsXPIDLString& aResult); 1.859 + 1.860 +public: 1.861 + template<uint32_t N> 1.862 + static nsresult FormatLocalizedString(PropertiesFile aFile, 1.863 + const char* aKey, 1.864 + const char16_t* (&aParams)[N], 1.865 + nsXPIDLString& aResult) 1.866 + { 1.867 + return FormatLocalizedString(aFile, aKey, aParams, N, aResult); 1.868 + } 1.869 + 1.870 + /** 1.871 + * Returns true if aDocument is a chrome document 1.872 + */ 1.873 + static bool IsChromeDoc(nsIDocument *aDocument); 1.874 + 1.875 + /** 1.876 + * Returns true if aDocument is in a docshell whose parent is the same type 1.877 + */ 1.878 + static bool IsChildOfSameType(nsIDocument* aDoc); 1.879 + 1.880 + /** 1.881 + '* Returns true if the content-type will be rendered as plain-text. 1.882 + */ 1.883 + static bool IsPlainTextType(const nsACString& aContentType); 1.884 + 1.885 + /** 1.886 + * Get the script file name to use when compiling the script 1.887 + * referenced by aURI. In cases where there's no need for any extra 1.888 + * security wrapper automation the script file name that's returned 1.889 + * will be the spec in aURI, else it will be the spec in aDocument's 1.890 + * URI followed by aURI's spec, separated by " -> ". Returns true 1.891 + * if the script file name was modified, false if it's aURI's 1.892 + * spec. 1.893 + */ 1.894 + static bool GetWrapperSafeScriptFilename(nsIDocument *aDocument, 1.895 + nsIURI *aURI, 1.896 + nsACString& aScriptURI); 1.897 + 1.898 + 1.899 + /** 1.900 + * Returns true if aDocument belongs to a chrome docshell for 1.901 + * display purposes. Returns false for null documents or documents 1.902 + * which do not belong to a docshell. 1.903 + */ 1.904 + static bool IsInChromeDocshell(nsIDocument *aDocument); 1.905 + 1.906 + /** 1.907 + * Return the content policy service 1.908 + */ 1.909 + static nsIContentPolicy *GetContentPolicy(); 1.910 + 1.911 + /** 1.912 + * Quick helper to determine whether there are any mutation listeners 1.913 + * of a given type that apply to this content or any of its ancestors. 1.914 + * The method has the side effect to call document's MayDispatchMutationEvent 1.915 + * using aTargetForSubtreeModified as the parameter. 1.916 + * 1.917 + * @param aNode The node to search for listeners 1.918 + * @param aType The type of listener (NS_EVENT_BITS_MUTATION_*) 1.919 + * @param aTargetForSubtreeModified The node which is the target of the 1.920 + * possible DOMSubtreeModified event. 1.921 + * 1.922 + * @return true if there are mutation listeners of the specified type 1.923 + */ 1.924 + static bool HasMutationListeners(nsINode* aNode, 1.925 + uint32_t aType, 1.926 + nsINode* aTargetForSubtreeModified); 1.927 + 1.928 + /** 1.929 + * Quick helper to determine whether there are any mutation listeners 1.930 + * of a given type that apply to any content in this document. It is valid 1.931 + * to pass null for aDocument here, in which case this function always 1.932 + * returns true. 1.933 + * 1.934 + * @param aDocument The document to search for listeners 1.935 + * @param aType The type of listener (NS_EVENT_BITS_MUTATION_*) 1.936 + * 1.937 + * @return true if there are mutation listeners of the specified type 1.938 + */ 1.939 + static bool HasMutationListeners(nsIDocument* aDocument, 1.940 + uint32_t aType); 1.941 + /** 1.942 + * Synchronously fire DOMNodeRemoved on aChild. Only fires the event if 1.943 + * there really are listeners by checking using the HasMutationListeners 1.944 + * function above. The function makes sure to hold the relevant objects alive 1.945 + * for the duration of the event firing. However there are no guarantees 1.946 + * that any of the objects are alive by the time the function returns. 1.947 + * If you depend on that you need to hold references yourself. 1.948 + * 1.949 + * @param aChild The node to fire DOMNodeRemoved at. 1.950 + * @param aParent The parent of aChild. 1.951 + * @param aOwnerDoc The ownerDocument of aChild. 1.952 + */ 1.953 + static void MaybeFireNodeRemoved(nsINode* aChild, nsINode* aParent, 1.954 + nsIDocument* aOwnerDoc); 1.955 + 1.956 + /** 1.957 + * This method creates and dispatches a trusted event. 1.958 + * Works only with events which can be created by calling 1.959 + * nsIDOMDocument::CreateEvent() with parameter "Events". 1.960 + * @param aDoc The document which will be used to create the event. 1.961 + * @param aTarget The target of the event, should be QIable to 1.962 + * nsIDOMEventTarget. 1.963 + * @param aEventName The name of the event. 1.964 + * @param aCanBubble Whether the event can bubble. 1.965 + * @param aCancelable Is the event cancelable. 1.966 + * @param aDefaultAction Set to true if default action should be taken, 1.967 + * see nsIDOMEventTarget::DispatchEvent. 1.968 + */ 1.969 + static nsresult DispatchTrustedEvent(nsIDocument* aDoc, 1.970 + nsISupports* aTarget, 1.971 + const nsAString& aEventName, 1.972 + bool aCanBubble, 1.973 + bool aCancelable, 1.974 + bool *aDefaultAction = nullptr); 1.975 + 1.976 + /** 1.977 + * This method creates and dispatches a untrusted event. 1.978 + * Works only with events which can be created by calling 1.979 + * nsIDOMDocument::CreateEvent() with parameter "Events". 1.980 + * @param aDoc The document which will be used to create the event. 1.981 + * @param aTarget The target of the event, should be QIable to 1.982 + * nsIDOMEventTarget. 1.983 + * @param aEventName The name of the event. 1.984 + * @param aCanBubble Whether the event can bubble. 1.985 + * @param aCancelable Is the event cancelable. 1.986 + * @param aDefaultAction Set to true if default action should be taken, 1.987 + * see nsIDOMEventTarget::DispatchEvent. 1.988 + */ 1.989 + static nsresult DispatchUntrustedEvent(nsIDocument* aDoc, 1.990 + nsISupports* aTarget, 1.991 + const nsAString& aEventName, 1.992 + bool aCanBubble, 1.993 + bool aCancelable, 1.994 + bool *aDefaultAction = nullptr); 1.995 + 1.996 + /** 1.997 + * This method creates and dispatches a trusted event to the chrome 1.998 + * event handler. 1.999 + * Works only with events which can be created by calling 1.1000 + * nsIDOMDocument::CreateEvent() with parameter "Events". 1.1001 + * @param aDocument The document which will be used to create the event, 1.1002 + * and whose window's chrome handler will be used to 1.1003 + * dispatch the event. 1.1004 + * @param aTarget The target of the event, used for event->SetTarget() 1.1005 + * @param aEventName The name of the event. 1.1006 + * @param aCanBubble Whether the event can bubble. 1.1007 + * @param aCancelable Is the event cancelable. 1.1008 + * @param aDefaultAction Set to true if default action should be taken, 1.1009 + * see nsIDOMEventTarget::DispatchEvent. 1.1010 + */ 1.1011 + static nsresult DispatchChromeEvent(nsIDocument* aDoc, 1.1012 + nsISupports* aTarget, 1.1013 + const nsAString& aEventName, 1.1014 + bool aCanBubble, 1.1015 + bool aCancelable, 1.1016 + bool *aDefaultAction = nullptr); 1.1017 + 1.1018 + /** 1.1019 + * Determines if an event attribute name (such as onclick) is valid for 1.1020 + * a given element type. Types are from the EventNameType enumeration 1.1021 + * defined above. 1.1022 + * 1.1023 + * @param aName the event name to look up 1.1024 + * @param aType the type of content 1.1025 + */ 1.1026 + static bool IsEventAttributeName(nsIAtom* aName, int32_t aType); 1.1027 + 1.1028 + /** 1.1029 + * Return the event id for the event with the given name. The name is the 1.1030 + * event name with the 'on' prefix. Returns NS_USER_DEFINED_EVENT if the 1.1031 + * event doesn't match a known event name. 1.1032 + * 1.1033 + * @param aName the event name to look up 1.1034 + */ 1.1035 + static uint32_t GetEventId(nsIAtom* aName); 1.1036 + 1.1037 + /** 1.1038 + * Return the category for the event with the given name. The name is the 1.1039 + * event name *without* the 'on' prefix. Returns NS_EVENT if the event 1.1040 + * is not known to be in any particular category. 1.1041 + * 1.1042 + * @param aName the event name to look up 1.1043 + */ 1.1044 + static uint32_t GetEventCategory(const nsAString& aName); 1.1045 + 1.1046 + /** 1.1047 + * Return the event id and atom for the event with the given name. 1.1048 + * The name is the event name *without* the 'on' prefix. 1.1049 + * Returns NS_USER_DEFINED_EVENT on the aEventID if the 1.1050 + * event doesn't match a known event name in the category. 1.1051 + * 1.1052 + * @param aName the event name to look up 1.1053 + * @param aEventStruct only return event id in aEventStruct category 1.1054 + */ 1.1055 + static nsIAtom* GetEventIdAndAtom(const nsAString& aName, 1.1056 + uint32_t aEventStruct, 1.1057 + uint32_t* aEventID); 1.1058 + 1.1059 + /** 1.1060 + * Used only during traversal of the XPCOM graph by the cycle 1.1061 + * collector: push a pointer to the listener manager onto the 1.1062 + * children deque, if it exists. Do nothing if there is no listener 1.1063 + * manager. 1.1064 + * 1.1065 + * Crucially: does not perform any refcounting operations. 1.1066 + * 1.1067 + * @param aNode The node to traverse. 1.1068 + * @param children The buffer to push a listener manager pointer into. 1.1069 + */ 1.1070 + static void TraverseListenerManager(nsINode *aNode, 1.1071 + nsCycleCollectionTraversalCallback &cb); 1.1072 + 1.1073 + /** 1.1074 + * Get the eventlistener manager for aNode, creating it if it does not 1.1075 + * already exist. 1.1076 + * 1.1077 + * @param aNode The node for which to get the eventlistener manager. 1.1078 + */ 1.1079 + static mozilla::EventListenerManager* 1.1080 + GetListenerManagerForNode(nsINode* aNode); 1.1081 + /** 1.1082 + * Get the eventlistener manager for aNode, returning null if it does not 1.1083 + * already exist. 1.1084 + * 1.1085 + * @param aNode The node for which to get the eventlistener manager. 1.1086 + */ 1.1087 + static mozilla::EventListenerManager* 1.1088 + GetExistingListenerManagerForNode(const nsINode* aNode); 1.1089 + 1.1090 + static void UnmarkGrayJSListenersInCCGenerationDocuments(uint32_t aGeneration); 1.1091 + 1.1092 + /** 1.1093 + * Remove the eventlistener manager for aNode. 1.1094 + * 1.1095 + * @param aNode The node for which to remove the eventlistener manager. 1.1096 + */ 1.1097 + static void RemoveListenerManager(nsINode *aNode); 1.1098 + 1.1099 + static bool IsInitialized() 1.1100 + { 1.1101 + return sInitialized; 1.1102 + } 1.1103 + 1.1104 + /** 1.1105 + * Checks if the localname/prefix/namespace triple is valid wrt prefix 1.1106 + * and namespace according to the Namespaces in XML and DOM Code 1.1107 + * specfications. 1.1108 + * 1.1109 + * @param aLocalname localname of the node 1.1110 + * @param aPrefix prefix of the node 1.1111 + * @param aNamespaceID namespace of the node 1.1112 + */ 1.1113 + static bool IsValidNodeName(nsIAtom *aLocalName, nsIAtom *aPrefix, 1.1114 + int32_t aNamespaceID); 1.1115 + 1.1116 + /** 1.1117 + * Creates a DocumentFragment from text using a context node to resolve 1.1118 + * namespaces. 1.1119 + * 1.1120 + * Note! In the HTML case with the HTML5 parser enabled, this is only called 1.1121 + * from Range.createContextualFragment() and the implementation here is 1.1122 + * quirky accordingly (html context node behaves like a body context node). 1.1123 + * If you don't want that quirky behavior, don't use this method as-is! 1.1124 + * 1.1125 + * @param aContextNode the node which is used to resolve namespaces 1.1126 + * @param aFragment the string which is parsed to a DocumentFragment 1.1127 + * @param aReturn the resulting fragment 1.1128 + * @param aPreventScriptExecution whether to mark scripts as already started 1.1129 + */ 1.1130 + static nsresult CreateContextualFragment(nsINode* aContextNode, 1.1131 + const nsAString& aFragment, 1.1132 + bool aPreventScriptExecution, 1.1133 + nsIDOMDocumentFragment** aReturn); 1.1134 + static already_AddRefed<mozilla::dom::DocumentFragment> 1.1135 + CreateContextualFragment(nsINode* aContextNode, const nsAString& aFragment, 1.1136 + bool aPreventScriptExecution, 1.1137 + mozilla::ErrorResult& aRv); 1.1138 + 1.1139 + /** 1.1140 + * Invoke the fragment parsing algorithm (innerHTML) using the HTML parser. 1.1141 + * 1.1142 + * @param aSourceBuffer the string being set as innerHTML 1.1143 + * @param aTargetNode the target container 1.1144 + * @param aContextLocalName local name of context node 1.1145 + * @param aContextNamespace namespace of context node 1.1146 + * @param aQuirks true to make <table> not close <p> 1.1147 + * @param aPreventScriptExecution true to prevent scripts from executing; 1.1148 + * don't set to false when parsing into a target node that has been 1.1149 + * bound to tree. 1.1150 + * @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse 1.1151 + * fragments is made, NS_ERROR_OUT_OF_MEMORY if aSourceBuffer is too 1.1152 + * long and NS_OK otherwise. 1.1153 + */ 1.1154 + static nsresult ParseFragmentHTML(const nsAString& aSourceBuffer, 1.1155 + nsIContent* aTargetNode, 1.1156 + nsIAtom* aContextLocalName, 1.1157 + int32_t aContextNamespace, 1.1158 + bool aQuirks, 1.1159 + bool aPreventScriptExecution); 1.1160 + 1.1161 + /** 1.1162 + * Invoke the fragment parsing algorithm (innerHTML) using the XML parser. 1.1163 + * 1.1164 + * @param aSourceBuffer the string being set as innerHTML 1.1165 + * @param aTargetNode the target container 1.1166 + * @param aTagStack the namespace mapping context 1.1167 + * @param aPreventExecution whether to mark scripts as already started 1.1168 + * @param aReturn the result fragment 1.1169 + * @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse 1.1170 + * fragments is made, a return code from the XML parser. 1.1171 + */ 1.1172 + static nsresult ParseFragmentXML(const nsAString& aSourceBuffer, 1.1173 + nsIDocument* aDocument, 1.1174 + nsTArray<nsString>& aTagStack, 1.1175 + bool aPreventScriptExecution, 1.1176 + nsIDOMDocumentFragment** aReturn); 1.1177 + 1.1178 + /** 1.1179 + * Parse a string into a document using the HTML parser. 1.1180 + * Script elements are marked unexecutable. 1.1181 + * 1.1182 + * @param aSourceBuffer the string to parse as an HTML document 1.1183 + * @param aTargetDocument the document object to parse into. Must not have 1.1184 + * child nodes. 1.1185 + * @param aScriptingEnabledForNoscriptParsing whether <noscript> is parsed 1.1186 + * as if scripting was enabled 1.1187 + * @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse 1.1188 + * fragments is made, NS_ERROR_OUT_OF_MEMORY if aSourceBuffer is too 1.1189 + * long and NS_OK otherwise. 1.1190 + */ 1.1191 + static nsresult ParseDocumentHTML(const nsAString& aSourceBuffer, 1.1192 + nsIDocument* aTargetDocument, 1.1193 + bool aScriptingEnabledForNoscriptParsing); 1.1194 + 1.1195 + /** 1.1196 + * Converts HTML source to plain text by parsing the source and using the 1.1197 + * plain text serializer on the resulting tree. 1.1198 + * 1.1199 + * @param aSourceBuffer the string to parse as an HTML document 1.1200 + * @param aResultBuffer the string where the plain text result appears; 1.1201 + * may be the same string as aSourceBuffer 1.1202 + * @param aFlags Flags from nsIDocumentEncoder. 1.1203 + * @param aWrapCol Number of columns after which to line wrap; 0 for no 1.1204 + * auto-wrapping 1.1205 + * @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse 1.1206 + * fragments is made, NS_ERROR_OUT_OF_MEMORY if aSourceBuffer is too 1.1207 + * long and NS_OK otherwise. 1.1208 + */ 1.1209 + static nsresult ConvertToPlainText(const nsAString& aSourceBuffer, 1.1210 + nsAString& aResultBuffer, 1.1211 + uint32_t aFlags, 1.1212 + uint32_t aWrapCol); 1.1213 + 1.1214 + /** 1.1215 + * Sets the text contents of a node by replacing all existing children 1.1216 + * with a single text child. 1.1217 + * 1.1218 + * The function always notifies. 1.1219 + * 1.1220 + * Will reuse the first text child if one is available. Will not reuse 1.1221 + * existing cdata children. 1.1222 + * 1.1223 + * @param aContent Node to set contents of. 1.1224 + * @param aValue Value to set contents to. 1.1225 + * @param aTryReuse When true, the function will try to reuse an existing 1.1226 + * textnodes rather than always creating a new one. 1.1227 + */ 1.1228 + static nsresult SetNodeTextContent(nsIContent* aContent, 1.1229 + const nsAString& aValue, 1.1230 + bool aTryReuse); 1.1231 + 1.1232 + /** 1.1233 + * Get the textual contents of a node. This is a concatenation of all 1.1234 + * textnodes that are direct or (depending on aDeep) indirect children 1.1235 + * of the node. 1.1236 + * 1.1237 + * NOTE! No serialization takes place and <br> elements 1.1238 + * are not converted into newlines. Only textnodes and cdata nodes are 1.1239 + * added to the result. 1.1240 + * 1.1241 + * @param aNode Node to get textual contents of. 1.1242 + * @param aDeep If true child elements of aNode are recursivly descended 1.1243 + * into to find text children. 1.1244 + * @param aResult the result. Out param. 1.1245 + * @return false on out of memory errors, true otherwise. 1.1246 + */ 1.1247 + static bool GetNodeTextContent(nsINode* aNode, bool aDeep, 1.1248 + nsAString& aResult) NS_WARN_UNUSED_RESULT; 1.1249 + 1.1250 + /** 1.1251 + * Same as GetNodeTextContents but appends the result rather than sets it. 1.1252 + */ 1.1253 + static bool AppendNodeTextContent(nsINode* aNode, bool aDeep, 1.1254 + nsAString& aResult, const mozilla::fallible_t&); 1.1255 + 1.1256 + /** 1.1257 + * Utility method that checks if a given node has any non-empty 1.1258 + * children. 1.1259 + * NOTE! This method does not descend recursivly into elements. 1.1260 + * Though it would be easy to make it so if needed 1.1261 + */ 1.1262 + static bool HasNonEmptyTextContent(nsINode* aNode); 1.1263 + 1.1264 + /** 1.1265 + * Delete strings allocated for nsContentList matches 1.1266 + */ 1.1267 + static void DestroyMatchString(void* aData); 1.1268 + 1.1269 + /** 1.1270 + * Unbinds the content from the tree and nulls it out if it's not null. 1.1271 + */ 1.1272 + static void DestroyAnonymousContent(nsCOMPtr<nsIContent>* aContent); 1.1273 + static void DestroyAnonymousContent(nsCOMPtr<Element>* aElement); 1.1274 + 1.1275 + static void DeferredFinalize(nsISupports* aSupports); 1.1276 + static void DeferredFinalize(mozilla::DeferredFinalizeAppendFunction aAppendFunc, 1.1277 + mozilla::DeferredFinalizeFunction aFunc, 1.1278 + void* aThing); 1.1279 + 1.1280 + /* 1.1281 + * Notify when the first XUL menu is opened and when the all XUL menus are 1.1282 + * closed. At opening, aInstalling should be TRUE, otherwise, it should be 1.1283 + * FALSE. 1.1284 + */ 1.1285 + static void NotifyInstalledMenuKeyboardListener(bool aInstalling); 1.1286 + 1.1287 + /** 1.1288 + * Do security checks before loading a resource. Does the following checks: 1.1289 + * nsIScriptSecurityManager::CheckLoadURIWithPrincipal 1.1290 + * NS_CheckContentLoadPolicy 1.1291 + * nsIScriptSecurityManager::CheckSameOriginURI 1.1292 + * 1.1293 + * You will still need to do at least SameOrigin checks before on redirects. 1.1294 + * 1.1295 + * @param aURIToLoad URI that is getting loaded. 1.1296 + * @param aLoadingPrincipal Principal of the resource that is initiating 1.1297 + * the load 1.1298 + * @param aCheckLoadFlags Flags to be passed to 1.1299 + * nsIScriptSecurityManager::CheckLoadURIWithPrincipal 1.1300 + * NOTE: If this contains ALLOW_CHROME the 1.1301 + * CheckSameOriginURI check will be skipped if 1.1302 + * aURIToLoad is a chrome uri. 1.1303 + * @param aAllowData Set to true to skip CheckSameOriginURI check when 1.1304 + aURIToLoad is a data uri. 1.1305 + * @param aContentPolicyType Type \ 1.1306 + * @param aContext Context |- to be passed to 1.1307 + * @param aMimeGuess Mimetype | NS_CheckContentLoadPolicy 1.1308 + * @param aExtra Extra / 1.1309 + */ 1.1310 + static nsresult CheckSecurityBeforeLoad(nsIURI* aURIToLoad, 1.1311 + nsIPrincipal* aLoadingPrincipal, 1.1312 + uint32_t aCheckLoadFlags, 1.1313 + bool aAllowData, 1.1314 + uint32_t aContentPolicyType, 1.1315 + nsISupports* aContext, 1.1316 + const nsAFlatCString& aMimeGuess = EmptyCString(), 1.1317 + nsISupports* aExtra = nullptr); 1.1318 + 1.1319 + /** 1.1320 + * Returns true if aPrincipal is the system principal. 1.1321 + */ 1.1322 + static bool IsSystemPrincipal(nsIPrincipal* aPrincipal); 1.1323 + 1.1324 + /** 1.1325 + * Returns true if aPrincipal is an nsExpandedPrincipal. 1.1326 + */ 1.1327 + static bool IsExpandedPrincipal(nsIPrincipal* aPrincipal); 1.1328 + 1.1329 + /** 1.1330 + * Returns true if aPrincipal is the system or an nsExpandedPrincipal. 1.1331 + */ 1.1332 + static bool IsSystemOrExpandedPrincipal(nsIPrincipal* aPrincipal) 1.1333 + { 1.1334 + return IsSystemPrincipal(aPrincipal) || IsExpandedPrincipal(aPrincipal); 1.1335 + } 1.1336 + 1.1337 + /** 1.1338 + * Gets the system principal from the security manager. 1.1339 + */ 1.1340 + static nsIPrincipal* GetSystemPrincipal(); 1.1341 + 1.1342 + /** 1.1343 + * *aResourcePrincipal is a principal describing who may access the contents 1.1344 + * of a resource. The resource can only be consumed by a principal that 1.1345 + * subsumes *aResourcePrincipal. MAKE SURE THAT NOTHING EVER ACTS WITH THE 1.1346 + * AUTHORITY OF *aResourcePrincipal. 1.1347 + * It may be null to indicate that the resource has no data from any origin 1.1348 + * in it yet and anything may access the resource. 1.1349 + * Additional data is being mixed into the resource from aExtraPrincipal 1.1350 + * (which may be null; if null, no data is being mixed in and this function 1.1351 + * will do nothing). Update *aResourcePrincipal to reflect the new data. 1.1352 + * If *aResourcePrincipal subsumes aExtraPrincipal, nothing needs to change, 1.1353 + * otherwise *aResourcePrincipal is replaced with the system principal. 1.1354 + * Returns true if *aResourcePrincipal changed. 1.1355 + */ 1.1356 + static bool CombineResourcePrincipals(nsCOMPtr<nsIPrincipal>* aResourcePrincipal, 1.1357 + nsIPrincipal* aExtraPrincipal); 1.1358 + 1.1359 + /** 1.1360 + * Trigger a link with uri aLinkURI. If aClick is false, this triggers a 1.1361 + * mouseover on the link, otherwise it triggers a load after doing a 1.1362 + * security check using aContent's principal. 1.1363 + * 1.1364 + * @param aContent the node on which a link was triggered. 1.1365 + * @param aPresContext the pres context, must be non-null. 1.1366 + * @param aLinkURI the URI of the link, must be non-null. 1.1367 + * @param aTargetSpec the target (like target=, may be empty). 1.1368 + * @param aClick whether this was a click or not (if false, this method 1.1369 + * assumes you just hovered over the link). 1.1370 + * @param aIsUserTriggered whether the user triggered the link. This would be 1.1371 + * false for loads from auto XLinks or from the 1.1372 + * click() method if we ever implement it. 1.1373 + * @param aIsTrusted If false, JS Context will be pushed to stack 1.1374 + * when the link is triggered. 1.1375 + */ 1.1376 + static void TriggerLink(nsIContent *aContent, nsPresContext *aPresContext, 1.1377 + nsIURI *aLinkURI, const nsString& aTargetSpec, 1.1378 + bool aClick, bool aIsUserTriggered, 1.1379 + bool aIsTrusted); 1.1380 + 1.1381 + /** 1.1382 + * Get the link location. 1.1383 + */ 1.1384 + static void GetLinkLocation(mozilla::dom::Element* aElement, 1.1385 + nsString& aLocationString); 1.1386 + 1.1387 + /** 1.1388 + * Return top-level widget in the parent chain. 1.1389 + */ 1.1390 + static nsIWidget* GetTopLevelWidget(nsIWidget* aWidget); 1.1391 + 1.1392 + /** 1.1393 + * Return the localized ellipsis for UI. 1.1394 + */ 1.1395 + static const nsDependentString GetLocalizedEllipsis(); 1.1396 + 1.1397 + /** 1.1398 + * Get the candidates for accelkeys for aDOMKeyEvent. 1.1399 + * 1.1400 + * @param aDOMKeyEvent [in] the key event for accelkey handling. 1.1401 + * @param aCandidates [out] the candidate shortcut key combination list. 1.1402 + * the first item is most preferred. 1.1403 + */ 1.1404 + static void GetAccelKeyCandidates(nsIDOMKeyEvent* aDOMKeyEvent, 1.1405 + nsTArray<nsShortcutCandidate>& aCandidates); 1.1406 + 1.1407 + /** 1.1408 + * Get the candidates for accesskeys for aNativeKeyEvent. 1.1409 + * 1.1410 + * @param aNativeKeyEvent [in] the key event for accesskey handling. 1.1411 + * @param aCandidates [out] the candidate access key list. 1.1412 + * the first item is most preferred. 1.1413 + */ 1.1414 + static void GetAccessKeyCandidates( 1.1415 + mozilla::WidgetKeyboardEvent* aNativeKeyEvent, 1.1416 + nsTArray<uint32_t>& aCandidates); 1.1417 + 1.1418 + /** 1.1419 + * Hide any XUL popups associated with aDocument, including any documents 1.1420 + * displayed in child frames. Does nothing if aDocument is null. 1.1421 + */ 1.1422 + static void HidePopupsInDocument(nsIDocument* aDocument); 1.1423 + 1.1424 + /** 1.1425 + * Retrieve the current drag session, or null if no drag is currently occuring 1.1426 + */ 1.1427 + static already_AddRefed<nsIDragSession> GetDragSession(); 1.1428 + 1.1429 + /* 1.1430 + * Initialize and set the dataTransfer field of an WidgetDragEvent. 1.1431 + */ 1.1432 + static nsresult SetDataTransferInEvent(mozilla::WidgetDragEvent* aDragEvent); 1.1433 + 1.1434 + // filters the drag and drop action to fit within the effects allowed and 1.1435 + // returns it. 1.1436 + static uint32_t FilterDropEffect(uint32_t aAction, uint32_t aEffectAllowed); 1.1437 + 1.1438 + /* 1.1439 + * Return true if the target of a drop event is a content document that is 1.1440 + * an ancestor of the document for the source of the drag. 1.1441 + */ 1.1442 + static bool CheckForSubFrameDrop(nsIDragSession* aDragSession, 1.1443 + mozilla::WidgetDragEvent* aDropEvent); 1.1444 + 1.1445 + /** 1.1446 + * Return true if aURI is a local file URI (i.e. file://). 1.1447 + */ 1.1448 + static bool URIIsLocalFile(nsIURI *aURI); 1.1449 + 1.1450 + /** 1.1451 + * Given a URI, return set beforeHash to the part before the '#', and 1.1452 + * afterHash to the remainder of the URI, including the '#'. 1.1453 + */ 1.1454 + static nsresult SplitURIAtHash(nsIURI *aURI, 1.1455 + nsACString &aBeforeHash, 1.1456 + nsACString &aAfterHash); 1.1457 + 1.1458 + /** 1.1459 + * Get the application manifest URI for this document. The manifest URI 1.1460 + * is specified in the manifest= attribute of the root element of the 1.1461 + * document. 1.1462 + * 1.1463 + * @param aDocument The document that lists the manifest. 1.1464 + * @param aURI The manifest URI. 1.1465 + */ 1.1466 + static void GetOfflineAppManifest(nsIDocument *aDocument, nsIURI **aURI); 1.1467 + 1.1468 + /** 1.1469 + * Check whether an application should be allowed to use offline APIs. 1.1470 + */ 1.1471 + static bool OfflineAppAllowed(nsIURI *aURI); 1.1472 + 1.1473 + /** 1.1474 + * Check whether an application should be allowed to use offline APIs. 1.1475 + */ 1.1476 + static bool OfflineAppAllowed(nsIPrincipal *aPrincipal); 1.1477 + 1.1478 + /** 1.1479 + * If offline-apps.allow_by_default is true, we set offline-app permission 1.1480 + * for the principal and return true. Otherwise false. 1.1481 + */ 1.1482 + static bool MaybeAllowOfflineAppByDefault(nsIPrincipal *aPrincipal, nsIDOMWindow *aWindow); 1.1483 + 1.1484 + /** 1.1485 + * Increases the count of blockers preventing scripts from running. 1.1486 + * NOTE: You might want to use nsAutoScriptBlocker rather than calling 1.1487 + * this directly 1.1488 + */ 1.1489 + static void AddScriptBlocker(); 1.1490 + 1.1491 + /** 1.1492 + * Decreases the count of blockers preventing scripts from running. 1.1493 + * NOTE: You might want to use nsAutoScriptBlocker rather than calling 1.1494 + * this directly 1.1495 + * 1.1496 + * WARNING! Calling this function could synchronously execute scripts. 1.1497 + */ 1.1498 + static void RemoveScriptBlocker(); 1.1499 + 1.1500 + /** 1.1501 + * Add a runnable that is to be executed as soon as it's safe to execute 1.1502 + * scripts. 1.1503 + * NOTE: If it's currently safe to execute scripts, aRunnable will be run 1.1504 + * synchronously before the function returns. 1.1505 + * 1.1506 + * @param aRunnable The nsIRunnable to run as soon as it's safe to execute 1.1507 + * scripts. Passing null is allowed and results in nothing 1.1508 + * happening. It is also allowed to pass an object that 1.1509 + * has not yet been AddRefed. 1.1510 + * @return false on out of memory, true otherwise. 1.1511 + */ 1.1512 + static bool AddScriptRunner(nsIRunnable* aRunnable); 1.1513 + 1.1514 + /** 1.1515 + * Returns true if it's safe to execute content script and false otherwise. 1.1516 + * 1.1517 + * The only known case where this lies is mutation events. They run, and can 1.1518 + * run anything else, when this function returns false, but this is ok. 1.1519 + */ 1.1520 + static bool IsSafeToRunScript() { 1.1521 + return sScriptBlockerCount == 0; 1.1522 + } 1.1523 + 1.1524 + /** 1.1525 + * Retrieve information about the viewport as a data structure. 1.1526 + * This will return information in the viewport META data section 1.1527 + * of the document. This can be used in lieu of ProcessViewportInfo(), 1.1528 + * which places the viewport information in the document header instead 1.1529 + * of returning it directly. 1.1530 + * 1.1531 + * @param aDisplayWidth width of the on-screen display area for this 1.1532 + * document, in device pixels. 1.1533 + * @param aDisplayHeight height of the on-screen display area for this 1.1534 + * document, in device pixels. 1.1535 + * 1.1536 + * NOTE: If the site is optimized for mobile (via the doctype), this 1.1537 + * will return viewport information that specifies default information. 1.1538 + */ 1.1539 + static nsViewportInfo GetViewportInfo(nsIDocument* aDocument, 1.1540 + const mozilla::ScreenIntSize& aDisplaySize); 1.1541 + 1.1542 + // Call EnterMicroTask when you're entering JS execution. 1.1543 + // Usually the best way to do this is to use nsAutoMicroTask. 1.1544 + static void EnterMicroTask(); 1.1545 + static void LeaveMicroTask(); 1.1546 + 1.1547 + static bool IsInMicroTask(); 1.1548 + static uint32_t MicroTaskLevel(); 1.1549 + static void SetMicroTaskLevel(uint32_t aLevel); 1.1550 + 1.1551 + /* Process viewport META data. This gives us information for the scale 1.1552 + * and zoom of a page on mobile devices. We stick the information in 1.1553 + * the document header and use it later on after rendering. 1.1554 + * 1.1555 + * See Bug #436083 1.1556 + */ 1.1557 + static nsresult ProcessViewportInfo(nsIDocument *aDocument, 1.1558 + const nsAString &viewportInfo); 1.1559 + 1.1560 + static nsIScriptContext* GetContextForEventHandlers(nsINode* aNode, 1.1561 + nsresult* aRv); 1.1562 + 1.1563 + static JSContext *GetCurrentJSContext(); 1.1564 + static JSContext *GetSafeJSContext(); 1.1565 + static JSContext *GetCurrentJSContextForThread(); 1.1566 + static JSContext *GetDefaultJSContextForThread(); 1.1567 + 1.1568 + /** 1.1569 + * Case insensitive comparison between two strings. However it only ignores 1.1570 + * case for ASCII characters a-z. 1.1571 + */ 1.1572 + static bool EqualsIgnoreASCIICase(const nsAString& aStr1, 1.1573 + const nsAString& aStr2); 1.1574 + 1.1575 + /** 1.1576 + * Convert ASCII A-Z to a-z. 1.1577 + * @return NS_OK on success, or NS_ERROR_OUT_OF_MEMORY if making the string 1.1578 + * writable needs to allocate memory and that allocation fails. 1.1579 + */ 1.1580 + static nsresult ASCIIToLower(nsAString& aStr); 1.1581 + static nsresult ASCIIToLower(const nsAString& aSource, nsAString& aDest); 1.1582 + 1.1583 + /** 1.1584 + * Convert ASCII a-z to A-Z. 1.1585 + * @return NS_OK on success, or NS_ERROR_OUT_OF_MEMORY if making the string 1.1586 + * writable needs to allocate memory and that allocation fails. 1.1587 + */ 1.1588 + static nsresult ASCIIToUpper(nsAString& aStr); 1.1589 + static nsresult ASCIIToUpper(const nsAString& aSource, nsAString& aDest); 1.1590 + 1.1591 + /** 1.1592 + * Return whether aStr contains an ASCII uppercase character. 1.1593 + */ 1.1594 + static bool StringContainsASCIIUpper(const nsAString& aStr); 1.1595 + 1.1596 + // Returns NS_OK for same origin, error (NS_ERROR_DOM_BAD_URI) if not. 1.1597 + static nsresult CheckSameOrigin(nsIChannel *aOldChannel, nsIChannel *aNewChannel); 1.1598 + static nsIInterfaceRequestor* GetSameOriginChecker(); 1.1599 + 1.1600 + // Trace the safe JS context. 1.1601 + static void TraceSafeJSContext(JSTracer* aTrc); 1.1602 + 1.1603 + 1.1604 + /** 1.1605 + * Get the Origin of the passed in nsIPrincipal or nsIURI. If the passed in 1.1606 + * nsIURI or the URI of the passed in nsIPrincipal does not have a host, the 1.1607 + * origin is set to 'null'. 1.1608 + * 1.1609 + * The ASCII versions return a ASCII strings that are puny-code encoded, 1.1610 + * suitable for, for example, header values. The UTF versions return strings 1.1611 + * containing international characters. 1.1612 + * 1.1613 + * @pre aPrincipal/aOrigin must not be null. 1.1614 + * 1.1615 + * @note this should be used for HTML5 origin determination. 1.1616 + */ 1.1617 + static nsresult GetASCIIOrigin(nsIPrincipal* aPrincipal, 1.1618 + nsCString& aOrigin); 1.1619 + static nsresult GetASCIIOrigin(nsIURI* aURI, nsCString& aOrigin); 1.1620 + static nsresult GetUTFOrigin(nsIPrincipal* aPrincipal, 1.1621 + nsString& aOrigin); 1.1622 + static nsresult GetUTFOrigin(nsIURI* aURI, nsString& aOrigin); 1.1623 + static void GetUTFNonNullOrigin(nsIURI* aURI, nsString& aOrigin); 1.1624 + 1.1625 + /** 1.1626 + * This method creates and dispatches "command" event, which implements 1.1627 + * nsIDOMXULCommandEvent. 1.1628 + * If aShell is not null, dispatching goes via 1.1629 + * nsIPresShell::HandleDOMEventWithTarget. 1.1630 + */ 1.1631 + static nsresult DispatchXULCommand(nsIContent* aTarget, 1.1632 + bool aTrusted, 1.1633 + nsIDOMEvent* aSourceEvent = nullptr, 1.1634 + nsIPresShell* aShell = nullptr, 1.1635 + bool aCtrl = false, 1.1636 + bool aAlt = false, 1.1637 + bool aShift = false, 1.1638 + bool aMeta = false); 1.1639 + 1.1640 + /** 1.1641 + * Gets the nsIDocument given the script context. Will return nullptr on failure. 1.1642 + * 1.1643 + * @param aScriptContext the script context to get the document for; can be null 1.1644 + * 1.1645 + * @return the document associated with the script context 1.1646 + */ 1.1647 + static nsIDocument* 1.1648 + GetDocumentFromScriptContext(nsIScriptContext* aScriptContext); 1.1649 + 1.1650 + static bool CheckMayLoad(nsIPrincipal* aPrincipal, nsIChannel* aChannel, bool aAllowIfInheritsPrincipal); 1.1651 + 1.1652 + /** 1.1653 + * The method checks whether the caller can access native anonymous content. 1.1654 + * If there is no JS in the stack or privileged JS is running, this 1.1655 + * method returns true, otherwise false. 1.1656 + */ 1.1657 + static bool CanAccessNativeAnon(); 1.1658 + 1.1659 + MOZ_WARN_UNUSED_RESULT 1.1660 + static nsresult WrapNative(JSContext *cx, nsISupports *native, 1.1661 + const nsIID* aIID, JS::MutableHandle<JS::Value> vp, 1.1662 + bool aAllowWrapping = true) 1.1663 + { 1.1664 + return WrapNative(cx, native, nullptr, aIID, vp, aAllowWrapping); 1.1665 + } 1.1666 + 1.1667 + // Same as the WrapNative above, but use this one if aIID is nsISupports' IID. 1.1668 + MOZ_WARN_UNUSED_RESULT 1.1669 + static nsresult WrapNative(JSContext *cx, nsISupports *native, 1.1670 + JS::MutableHandle<JS::Value> vp, 1.1671 + bool aAllowWrapping = true) 1.1672 + { 1.1673 + return WrapNative(cx, native, nullptr, nullptr, vp, aAllowWrapping); 1.1674 + } 1.1675 + 1.1676 + MOZ_WARN_UNUSED_RESULT 1.1677 + static nsresult WrapNative(JSContext *cx, nsISupports *native, 1.1678 + nsWrapperCache *cache, 1.1679 + JS::MutableHandle<JS::Value> vp, 1.1680 + bool aAllowWrapping = true) 1.1681 + { 1.1682 + return WrapNative(cx, native, cache, nullptr, vp, aAllowWrapping); 1.1683 + } 1.1684 + 1.1685 + /** 1.1686 + * Creates an arraybuffer from a binary string. 1.1687 + */ 1.1688 + static nsresult CreateArrayBuffer(JSContext *aCx, const nsACString& aData, 1.1689 + JSObject** aResult); 1.1690 + 1.1691 + static nsresult CreateBlobBuffer(JSContext* aCx, 1.1692 + const nsACString& aData, 1.1693 + JS::MutableHandle<JS::Value> aBlob); 1.1694 + 1.1695 + static void StripNullChars(const nsAString& aInStr, nsAString& aOutStr); 1.1696 + 1.1697 + /** 1.1698 + * Strip all \n, \r and nulls from the given string 1.1699 + * @param aString the string to remove newlines from [in/out] 1.1700 + */ 1.1701 + static void RemoveNewlines(nsString &aString); 1.1702 + 1.1703 + /** 1.1704 + * Convert Windows and Mac platform linebreaks to \n. 1.1705 + * @param aString the string to convert the newlines inside [in/out] 1.1706 + */ 1.1707 + static void PlatformToDOMLineBreaks(nsString &aString); 1.1708 + 1.1709 + /** 1.1710 + * Populates aResultString with the contents of the string-buffer aBuf, up 1.1711 + * to aBuf's null-terminator. aBuf must not be null. Ownership of the string 1.1712 + * is not transferred. 1.1713 + */ 1.1714 + static void PopulateStringFromStringBuffer(nsStringBuffer* aBuf, 1.1715 + nsAString& aResultString); 1.1716 + 1.1717 + static bool IsHandlingKeyBoardEvent() 1.1718 + { 1.1719 + return sIsHandlingKeyBoardEvent; 1.1720 + } 1.1721 + 1.1722 + static void SetIsHandlingKeyBoardEvent(bool aHandling) 1.1723 + { 1.1724 + sIsHandlingKeyBoardEvent = aHandling; 1.1725 + } 1.1726 + 1.1727 + /** 1.1728 + * Utility method for getElementsByClassName. aRootNode is the node (either 1.1729 + * document or element), which getElementsByClassName was called on. 1.1730 + */ 1.1731 + static already_AddRefed<nsContentList> 1.1732 + GetElementsByClassName(nsINode* aRootNode, const nsAString& aClasses) 1.1733 + { 1.1734 + NS_PRECONDITION(aRootNode, "Must have root node"); 1.1735 + 1.1736 + return NS_GetFuncStringHTMLCollection(aRootNode, MatchClassNames, 1.1737 + DestroyClassNameArray, 1.1738 + AllocClassMatchingInfo, 1.1739 + aClasses); 1.1740 + } 1.1741 + 1.1742 + /** 1.1743 + * Returns a presshell for this document, if there is one. This will be 1.1744 + * aDoc's direct presshell if there is one, otherwise we'll look at all 1.1745 + * ancestor documents to try to find a presshell, so for example this can 1.1746 + * still find a presshell for documents in display:none frames that have 1.1747 + * no presentation. So you have to be careful how you use this presshell --- 1.1748 + * getting generic data like a device context or widget from it is OK, but it 1.1749 + * might not be this document's actual presentation. 1.1750 + */ 1.1751 + static nsIPresShell* FindPresShellForDocument(const nsIDocument* aDoc); 1.1752 + 1.1753 + /** 1.1754 + * Returns the widget for this document if there is one. Looks at all ancestor 1.1755 + * documents to try to find a widget, so for example this can still find a 1.1756 + * widget for documents in display:none frames that have no presentation. 1.1757 + */ 1.1758 + static nsIWidget* WidgetForDocument(const nsIDocument* aDoc); 1.1759 + 1.1760 + /** 1.1761 + * Returns a layer manager to use for the given document. Basically we 1.1762 + * look up the document hierarchy for the first document which has 1.1763 + * a presentation with an associated widget, and use that widget's 1.1764 + * layer manager. 1.1765 + * 1.1766 + * @param aDoc the document for which to return a layer manager. 1.1767 + * @param aAllowRetaining an outparam that states whether the returned 1.1768 + * layer manager should be used for retained layers 1.1769 + */ 1.1770 + static already_AddRefed<mozilla::layers::LayerManager> 1.1771 + LayerManagerForDocument(const nsIDocument *aDoc, bool *aAllowRetaining = nullptr); 1.1772 + 1.1773 + /** 1.1774 + * Returns a layer manager to use for the given document. Basically we 1.1775 + * look up the document hierarchy for the first document which has 1.1776 + * a presentation with an associated widget, and use that widget's 1.1777 + * layer manager. In addition to the normal layer manager lookup this will 1.1778 + * specifically request a persistent layer manager. This means that the layer 1.1779 + * manager is expected to remain the layer manager for the document in the 1.1780 + * forseeable future. This function should be used carefully as it may change 1.1781 + * the document's layer manager. 1.1782 + * 1.1783 + * @param aDoc the document for which to return a layer manager. 1.1784 + * @param aAllowRetaining an outparam that states whether the returned 1.1785 + * layer manager should be used for retained layers 1.1786 + */ 1.1787 + static already_AddRefed<mozilla::layers::LayerManager> 1.1788 + PersistentLayerManagerForDocument(nsIDocument *aDoc, bool *aAllowRetaining = nullptr); 1.1789 + 1.1790 + /** 1.1791 + * Determine whether a content node is focused or not, 1.1792 + * 1.1793 + * @param aContent the content node to check 1.1794 + * @return true if the content node is focused, false otherwise. 1.1795 + */ 1.1796 + static bool IsFocusedContent(const nsIContent *aContent); 1.1797 + 1.1798 + /** 1.1799 + * Returns true if the DOM full-screen API is enabled. 1.1800 + */ 1.1801 + static bool IsFullScreenApiEnabled(); 1.1802 + 1.1803 + /** 1.1804 + * Returns true if requests for full-screen are allowed in the current 1.1805 + * context. Requests are only allowed if the user initiated them (like with 1.1806 + * a mouse-click or key press), unless this check has been disabled by 1.1807 + * setting the pref "full-screen-api.allow-trusted-requests-only" to false. 1.1808 + */ 1.1809 + static bool IsRequestFullScreenAllowed(); 1.1810 + 1.1811 + /** 1.1812 + * Returns true if the DOM fullscreen API is restricted to content only. 1.1813 + * This mirrors the pref "full-screen-api.content-only". If this is true, 1.1814 + * fullscreen requests in chrome are denied, and fullscreen requests in 1.1815 + * content stop percolating upwards before they reach chrome documents. 1.1816 + * That is, when an element in content requests fullscreen, only its 1.1817 + * containing frames that are in content are also made fullscreen, not 1.1818 + * the containing frame in the chrome document. 1.1819 + * 1.1820 + * Note if the fullscreen API is running in content only mode then multiple 1.1821 + * branches of a doctree can be fullscreen at the same time, but no fullscreen 1.1822 + * document will have a common ancestor with another fullscreen document 1.1823 + * that is also fullscreen (since the only common ancestor they can have 1.1824 + * is the chrome document, and that can't be fullscreen). i.e. multiple 1.1825 + * child documents of the chrome document can be fullscreen, but the chrome 1.1826 + * document won't be fullscreen. 1.1827 + * 1.1828 + * Making the fullscreen API content only is useful on platforms where we 1.1829 + * still want chrome to be visible or accessible while content is 1.1830 + * fullscreen, like on Windows 8 in Metro mode. 1.1831 + * 1.1832 + * Note that if the fullscreen API is content only, chrome can still go 1.1833 + * fullscreen by setting the "fullScreen" attribute on its XUL window. 1.1834 + */ 1.1835 + static bool IsFullscreenApiContentOnly(); 1.1836 + 1.1837 + /** 1.1838 + * Returns true if the idle observers API is enabled. 1.1839 + */ 1.1840 + static bool IsIdleObserverAPIEnabled() { return sIsIdleObserverAPIEnabled; } 1.1841 + 1.1842 + /* 1.1843 + * Returns true if the performance timing APIs are enabled. 1.1844 + */ 1.1845 + static bool IsPerformanceTimingEnabled() 1.1846 + { 1.1847 + return sIsPerformanceTimingEnabled; 1.1848 + } 1.1849 + 1.1850 + /* 1.1851 + * Returns true if the performance timing APIs are enabled. 1.1852 + */ 1.1853 + static bool IsResourceTimingEnabled() 1.1854 + { 1.1855 + return sIsResourceTimingEnabled; 1.1856 + } 1.1857 + 1.1858 + /** 1.1859 + * Returns true if the doc tree branch which contains aDoc contains any 1.1860 + * plugins which we don't control event dispatch for, i.e. do any plugins 1.1861 + * in the same tab as this document receive key events outside of our 1.1862 + * control? This always returns false on MacOSX. 1.1863 + */ 1.1864 + static bool HasPluginWithUncontrolledEventDispatch(nsIDocument* aDoc); 1.1865 + 1.1866 + /** 1.1867 + * Fire mutation events for changes caused by parsing directly into a 1.1868 + * context node. 1.1869 + * 1.1870 + * @param aDoc the document of the node 1.1871 + * @param aDest the destination node that got stuff appended to it 1.1872 + * @param aOldChildCount the number of children the node had before parsing 1.1873 + */ 1.1874 + static void FireMutationEventsForDirectParsing(nsIDocument* aDoc, 1.1875 + nsIContent* aDest, 1.1876 + int32_t aOldChildCount); 1.1877 + 1.1878 + /** 1.1879 + * Returns true if the content is in a document and contains a plugin 1.1880 + * which we don't control event dispatch for, i.e. do any plugins in this 1.1881 + * doc tree receive key events outside of our control? This always returns 1.1882 + * false on MacOSX. 1.1883 + */ 1.1884 + static bool HasPluginWithUncontrolledEventDispatch(nsIContent* aContent); 1.1885 + 1.1886 + /** 1.1887 + * Returns the document that is the closest ancestor to aDoc that is 1.1888 + * fullscreen. If aDoc is fullscreen this returns aDoc. If aDoc is not 1.1889 + * fullscreen and none of aDoc's ancestors are fullscreen this returns 1.1890 + * nullptr. 1.1891 + */ 1.1892 + static nsIDocument* GetFullscreenAncestor(nsIDocument* aDoc); 1.1893 + 1.1894 + /** 1.1895 + * Returns true if aWin and the current pointer lock document 1.1896 + * have common scriptable top window. 1.1897 + */ 1.1898 + static bool IsInPointerLockContext(nsIDOMWindow* aWin); 1.1899 + 1.1900 + /** 1.1901 + * Returns the time limit on handling user input before 1.1902 + * EventStateManager::IsHandlingUserInput() stops returning true. 1.1903 + * This enables us to detect long running user-generated event handlers. 1.1904 + */ 1.1905 + static TimeDuration HandlingUserInputTimeout(); 1.1906 + 1.1907 + static void GetShiftText(nsAString& text); 1.1908 + static void GetControlText(nsAString& text); 1.1909 + static void GetMetaText(nsAString& text); 1.1910 + static void GetOSText(nsAString& text); 1.1911 + static void GetAltText(nsAString& text); 1.1912 + static void GetModifierSeparatorText(nsAString& text); 1.1913 + 1.1914 + /** 1.1915 + * Returns if aContent has a tabbable subdocument. 1.1916 + * A sub document isn't tabbable when it's a zombie document. 1.1917 + * 1.1918 + * @param aElement element to test. 1.1919 + * 1.1920 + * @return Whether the subdocument is tabbable. 1.1921 + */ 1.1922 + static bool IsSubDocumentTabbable(nsIContent* aContent); 1.1923 + 1.1924 + /** 1.1925 + * Returns if aNode ignores user focus. 1.1926 + * 1.1927 + * @param aNode node to test 1.1928 + * 1.1929 + * @return Whether the node ignores user focus. 1.1930 + */ 1.1931 + static bool IsUserFocusIgnored(nsINode* aNode); 1.1932 + 1.1933 + /** 1.1934 + * Returns if aContent has the 'scrollgrab' property. 1.1935 + * aContent may be null (in this case false is returned). 1.1936 + */ 1.1937 + static bool HasScrollgrab(nsIContent* aContent); 1.1938 + 1.1939 + /** 1.1940 + * Flushes the layout tree (recursively) 1.1941 + * 1.1942 + * @param aWindow the window the flush should start at 1.1943 + * 1.1944 + */ 1.1945 + static void FlushLayoutForTree(nsIDOMWindow* aWindow); 1.1946 + 1.1947 + /** 1.1948 + * Returns true if content with the given principal is allowed to use XUL 1.1949 + * and XBL and false otherwise. 1.1950 + */ 1.1951 + static bool AllowXULXBLForPrincipal(nsIPrincipal* aPrincipal); 1.1952 + 1.1953 + /** 1.1954 + * Perform cleanup that's appropriate for XPCOM shutdown. 1.1955 + */ 1.1956 + static void XPCOMShutdown(); 1.1957 + 1.1958 + enum ContentViewerType 1.1959 + { 1.1960 + TYPE_UNSUPPORTED, 1.1961 + TYPE_CONTENT, 1.1962 + TYPE_PLUGIN, 1.1963 + TYPE_UNKNOWN 1.1964 + }; 1.1965 + 1.1966 + static already_AddRefed<nsIDocumentLoaderFactory> 1.1967 + FindInternalContentViewer(const char* aType, 1.1968 + ContentViewerType* aLoaderType = nullptr); 1.1969 + 1.1970 + /** 1.1971 + * This helper method returns true if the aPattern pattern matches aValue. 1.1972 + * aPattern should not contain leading and trailing slashes (/). 1.1973 + * The pattern has to match the entire value not just a subset. 1.1974 + * aDocument must be a valid pointer (not null). 1.1975 + * 1.1976 + * This is following the HTML5 specification: 1.1977 + * http://dev.w3.org/html5/spec/forms.html#attr-input-pattern 1.1978 + * 1.1979 + * WARNING: This method mutates aPattern and aValue! 1.1980 + * 1.1981 + * @param aValue the string to check. 1.1982 + * @param aPattern the string defining the pattern. 1.1983 + * @param aDocument the owner document of the element. 1.1984 + * @result whether the given string is matches the pattern. 1.1985 + */ 1.1986 + static bool IsPatternMatching(nsAString& aValue, nsAString& aPattern, 1.1987 + nsIDocument* aDocument); 1.1988 + 1.1989 + /** 1.1990 + * Calling this adds support for 1.1991 + * ontouch* event handler DOM attributes. 1.1992 + */ 1.1993 + static void InitializeTouchEventTable(); 1.1994 + 1.1995 + /** 1.1996 + * Test whether the given URI always inherits a security context 1.1997 + * from the document it comes from. 1.1998 + */ 1.1999 + static nsresult URIInheritsSecurityContext(nsIURI *aURI, bool *aResult); 1.2000 + 1.2001 + /** 1.2002 + * Set the given principal as the owner of the given channel, if 1.2003 + * needed. aURI must be the URI of aChannel. aPrincipal may be 1.2004 + * null. If aSetUpForAboutBlank is true, then about:blank will get 1.2005 + * the principal set up on it. If aForceOwner is true, the owner 1.2006 + * will be set on the channel, even if the principal can be determined 1.2007 + * from the channel. 1.2008 + * The return value is whether the principal was set up as the owner 1.2009 + * of the channel. 1.2010 + */ 1.2011 + static bool SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal, 1.2012 + nsIChannel* aChannel, 1.2013 + nsIURI* aURI, 1.2014 + bool aSetUpForAboutBlank, 1.2015 + bool aForceOwner = false); 1.2016 + 1.2017 + static nsresult Btoa(const nsAString& aBinaryData, 1.2018 + nsAString& aAsciiBase64String); 1.2019 + 1.2020 + static nsresult Atob(const nsAString& aAsciiString, 1.2021 + nsAString& aBinaryData); 1.2022 + 1.2023 + /** 1.2024 + * Returns whether the input element passed in parameter has the autocomplete 1.2025 + * functionality enabled. It is taking into account the form owner. 1.2026 + * NOTE: the caller has to make sure autocomplete makes sense for the 1.2027 + * element's type. 1.2028 + * 1.2029 + * @param aInput the input element to check. NOTE: aInput can't be null. 1.2030 + * @return whether the input element has autocomplete enabled. 1.2031 + */ 1.2032 + static bool IsAutocompleteEnabled(nsIDOMHTMLInputElement* aInput); 1.2033 + 1.2034 + /** 1.2035 + * This will parse aSource, to extract the value of the pseudo attribute 1.2036 + * with the name specified in aName. See 1.2037 + * http://www.w3.org/TR/xml-stylesheet/#NT-StyleSheetPI for the specification 1.2038 + * which is used to parse aSource. 1.2039 + * 1.2040 + * @param aSource the string to parse 1.2041 + * @param aName the name of the attribute to get the value for 1.2042 + * @param aValue [out] the value for the attribute with name specified in 1.2043 + * aAttribute. Empty if the attribute isn't present. 1.2044 + * @return true if the attribute exists and was successfully parsed. 1.2045 + * false if the attribute doesn't exist, or has a malformed 1.2046 + * value, such as an unknown or unterminated entity. 1.2047 + */ 1.2048 + static bool GetPseudoAttributeValue(const nsString& aSource, nsIAtom *aName, 1.2049 + nsAString& aValue); 1.2050 + 1.2051 + /** 1.2052 + * Returns true if the language name is a version of JavaScript and 1.2053 + * false otherwise 1.2054 + */ 1.2055 + static bool IsJavaScriptLanguage(const nsString& aName); 1.2056 + 1.2057 + /** 1.2058 + * Returns the JSVersion for a string of the form '1.n', n = 0, ..., 8, and 1.2059 + * JSVERSION_UNKNOWN for other strings. 1.2060 + */ 1.2061 + static JSVersion ParseJavascriptVersion(const nsAString& aVersionStr); 1.2062 + 1.2063 + static bool IsJavascriptMIMEType(const nsAString& aMIMEType); 1.2064 + 1.2065 + static void SplitMimeType(const nsAString& aValue, nsString& aType, 1.2066 + nsString& aParams); 1.2067 + 1.2068 + /** 1.2069 + * Function checks if the user is idle. 1.2070 + * 1.2071 + * @param aRequestedIdleTimeInMS The idle observer's requested idle time. 1.2072 + * @param aUserIsIdle boolean indicating if the user 1.2073 + * is currently idle or not. * 1.2074 + * @return NS_OK NS_OK returned if the requested idle service and 1.2075 + * the current idle time were successfully obtained. 1.2076 + * NS_ERROR_FAILURE returned if the the requested 1.2077 + * idle service or the current idle were not obtained. 1.2078 + */ 1.2079 + static nsresult IsUserIdle(uint32_t aRequestedIdleTimeInMS, bool* aUserIsIdle); 1.2080 + 1.2081 + /** 1.2082 + * Takes a selection, and a text control element (<input> or <textarea>), and 1.2083 + * returns the offsets in the text content corresponding to the selection. 1.2084 + * The selection's anchor and focus must both be in the root node passed or a 1.2085 + * descendant. 1.2086 + * 1.2087 + * @param aSelection Selection to check 1.2088 + * @param aRoot Root <input> or <textarea> element 1.2089 + * @param aOutStartOffset Output start offset 1.2090 + * @param aOutEndOffset Output end offset 1.2091 + */ 1.2092 + static void GetSelectionInTextControl(mozilla::dom::Selection* aSelection, 1.2093 + Element* aRoot, 1.2094 + int32_t& aOutStartOffset, 1.2095 + int32_t& aOutEndOffset); 1.2096 + 1.2097 + /** 1.2098 + * Takes a frame for anonymous content within a text control (<input> or 1.2099 + * <textarea>), and returns an offset in the text content, adjusted for a 1.2100 + * trailing <br> frame. 1.2101 + * 1.2102 + * @param aOffsetFrame Frame for the text content in which the offset 1.2103 + * lies 1.2104 + * @param aOffset Offset as calculated by GetContentOffsetsFromPoint 1.2105 + * @param aOutOffset Output adjusted offset 1.2106 + * 1.2107 + * @see GetSelectionInTextControl for the original basis of this function. 1.2108 + */ 1.2109 + static int32_t GetAdjustedOffsetInTextControl(nsIFrame* aOffsetFrame, 1.2110 + int32_t aOffset); 1.2111 + 1.2112 + static nsIEditor* GetHTMLEditor(nsPresContext* aPresContext); 1.2113 + 1.2114 + /** 1.2115 + * Check whether a spec feature/version is supported. 1.2116 + * @param aObject the object, which should support the feature, 1.2117 + * for example nsIDOMNode or nsIDOMDOMImplementation 1.2118 + * @param aFeature the feature ("Views", "Core", "HTML", "Range" ...) 1.2119 + * @param aVersion the version ("1.0", "2.0", ...) 1.2120 + * @return whether the feature is supported or not 1.2121 + */ 1.2122 + static bool InternalIsSupported(nsISupports* aObject, 1.2123 + const nsAString& aFeature, 1.2124 + const nsAString& aVersion); 1.2125 + 1.2126 + /** 1.2127 + * Return true if the browser.dom.window.dump.enabled pref is set. 1.2128 + */ 1.2129 + static bool DOMWindowDumpEnabled(); 1.2130 + 1.2131 + /** 1.2132 + * Returns whether a content is an insertion point for XBL 1.2133 + * bindings or web components ShadowRoot. In web components, 1.2134 + * this corresponds to a <content> element that participates 1.2135 + * in node distribution. In XBL this corresponds to an 1.2136 + * <xbl:children> element in anonymous content. 1.2137 + * 1.2138 + * @param aContent The content to test for being an insertion point. 1.2139 + */ 1.2140 + static bool IsContentInsertionPoint(const nsIContent* aContent); 1.2141 + 1.2142 +private: 1.2143 + static bool InitializeEventTable(); 1.2144 + 1.2145 + static nsresult EnsureStringBundle(PropertiesFile aFile); 1.2146 + 1.2147 + static bool CanCallerAccess(nsIPrincipal* aSubjectPrincipal, 1.2148 + nsIPrincipal* aPrincipal); 1.2149 + 1.2150 + static nsresult WrapNative(JSContext *cx, nsISupports *native, 1.2151 + nsWrapperCache *cache, const nsIID* aIID, 1.2152 + JS::MutableHandle<JS::Value> vp, 1.2153 + bool aAllowWrapping); 1.2154 + 1.2155 + static nsresult DispatchEvent(nsIDocument* aDoc, 1.2156 + nsISupports* aTarget, 1.2157 + const nsAString& aEventName, 1.2158 + bool aCanBubble, 1.2159 + bool aCancelable, 1.2160 + bool aTrusted, 1.2161 + bool *aDefaultAction = nullptr); 1.2162 + 1.2163 + static void InitializeModifierStrings(); 1.2164 + 1.2165 + static void DropFragmentParsers(); 1.2166 + 1.2167 + static bool MatchClassNames(nsIContent* aContent, int32_t aNamespaceID, 1.2168 + nsIAtom* aAtom, void* aData); 1.2169 + static void DestroyClassNameArray(void* aData); 1.2170 + static void* AllocClassMatchingInfo(nsINode* aRootNode, 1.2171 + const nsString* aClasses); 1.2172 + 1.2173 + static nsIXPConnect *sXPConnect; 1.2174 + 1.2175 + static nsIScriptSecurityManager *sSecurityManager; 1.2176 + 1.2177 + static nsIParserService *sParserService; 1.2178 + 1.2179 + static nsNameSpaceManager *sNameSpaceManager; 1.2180 + 1.2181 + static nsIIOService *sIOService; 1.2182 + 1.2183 + static bool sImgLoaderInitialized; 1.2184 + static void InitImgLoader(); 1.2185 + 1.2186 + // The following four members are initialized lazily 1.2187 + static imgLoader* sImgLoader; 1.2188 + static imgLoader* sPrivateImgLoader; 1.2189 + static imgICache* sImgCache; 1.2190 + static imgICache* sPrivateImgCache; 1.2191 + 1.2192 + static nsIConsoleService* sConsoleService; 1.2193 + 1.2194 + static nsDataHashtable<nsISupportsHashKey, EventNameMapping>* sAtomEventTable; 1.2195 + static nsDataHashtable<nsStringHashKey, EventNameMapping>* sStringEventTable; 1.2196 + static nsCOMArray<nsIAtom>* sUserDefinedEvents; 1.2197 + 1.2198 + static nsIStringBundleService* sStringBundleService; 1.2199 + static nsIStringBundle* sStringBundles[PropertiesFile_COUNT]; 1.2200 + 1.2201 + static nsIContentPolicy* sContentPolicyService; 1.2202 + static bool sTriedToGetContentPolicy; 1.2203 + 1.2204 + static nsILineBreaker* sLineBreaker; 1.2205 + static nsIWordBreaker* sWordBreaker; 1.2206 + 1.2207 + static nsIBidiKeyboard* sBidiKeyboard; 1.2208 + 1.2209 + static bool sInitialized; 1.2210 + static uint32_t sScriptBlockerCount; 1.2211 +#ifdef DEBUG 1.2212 + static uint32_t sDOMNodeRemovedSuppressCount; 1.2213 +#endif 1.2214 + static uint32_t sMicroTaskLevel; 1.2215 + // Not an nsCOMArray because removing elements from those is slower 1.2216 + static nsTArray< nsCOMPtr<nsIRunnable> >* sBlockedScriptRunners; 1.2217 + static uint32_t sRunnersCountAtFirstBlocker; 1.2218 + static uint32_t sScriptBlockerCountWhereRunnersPrevented; 1.2219 + 1.2220 + static nsIInterfaceRequestor* sSameOriginChecker; 1.2221 + 1.2222 + static bool sIsHandlingKeyBoardEvent; 1.2223 + static bool sAllowXULXBL_for_file; 1.2224 + static bool sIsFullScreenApiEnabled; 1.2225 + static bool sTrustedFullScreenOnly; 1.2226 + static bool sFullscreenApiIsContentOnly; 1.2227 + static uint32_t sHandlingInputTimeout; 1.2228 + static bool sIsIdleObserverAPIEnabled; 1.2229 + static bool sIsPerformanceTimingEnabled; 1.2230 + static bool sIsResourceTimingEnabled; 1.2231 + 1.2232 + static nsHtml5StringParser* sHTMLFragmentParser; 1.2233 + static nsIParser* sXMLFragmentParser; 1.2234 + static nsIFragmentContentSink* sXMLFragmentSink; 1.2235 + 1.2236 + /** 1.2237 + * True if there's a fragment parser activation on the stack. 1.2238 + */ 1.2239 + static bool sFragmentParsingActive; 1.2240 + 1.2241 + static nsString* sShiftText; 1.2242 + static nsString* sControlText; 1.2243 + static nsString* sMetaText; 1.2244 + static nsString* sOSText; 1.2245 + static nsString* sAltText; 1.2246 + static nsString* sModifierSeparator; 1.2247 + 1.2248 +#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP)) 1.2249 + static bool sDOMWindowDumpEnabled; 1.2250 +#endif 1.2251 +}; 1.2252 + 1.2253 +class MOZ_STACK_CLASS nsAutoScriptBlocker { 1.2254 +public: 1.2255 + nsAutoScriptBlocker(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) { 1.2256 + MOZ_GUARD_OBJECT_NOTIFIER_INIT; 1.2257 + nsContentUtils::AddScriptBlocker(); 1.2258 + } 1.2259 + ~nsAutoScriptBlocker() { 1.2260 + nsContentUtils::RemoveScriptBlocker(); 1.2261 + } 1.2262 +private: 1.2263 + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER 1.2264 +}; 1.2265 + 1.2266 +class MOZ_STACK_CLASS nsAutoScriptBlockerSuppressNodeRemoved : 1.2267 + public nsAutoScriptBlocker { 1.2268 +public: 1.2269 + nsAutoScriptBlockerSuppressNodeRemoved() { 1.2270 +#ifdef DEBUG 1.2271 + ++nsContentUtils::sDOMNodeRemovedSuppressCount; 1.2272 +#endif 1.2273 + } 1.2274 + ~nsAutoScriptBlockerSuppressNodeRemoved() { 1.2275 +#ifdef DEBUG 1.2276 + --nsContentUtils::sDOMNodeRemovedSuppressCount; 1.2277 +#endif 1.2278 + } 1.2279 +}; 1.2280 + 1.2281 +class MOZ_STACK_CLASS nsAutoMicroTask 1.2282 +{ 1.2283 +public: 1.2284 + nsAutoMicroTask() 1.2285 + { 1.2286 + nsContentUtils::EnterMicroTask(); 1.2287 + } 1.2288 + ~nsAutoMicroTask() 1.2289 + { 1.2290 + nsContentUtils::LeaveMicroTask(); 1.2291 + } 1.2292 +}; 1.2293 + 1.2294 +namespace mozilla { 1.2295 +namespace dom { 1.2296 + 1.2297 +class TreeOrderComparator { 1.2298 +public: 1.2299 + bool Equals(nsINode* aElem1, nsINode* aElem2) const { 1.2300 + return aElem1 == aElem2; 1.2301 + } 1.2302 + bool LessThan(nsINode* aElem1, nsINode* aElem2) const { 1.2303 + return nsContentUtils::PositionIsBefore(aElem1, aElem2); 1.2304 + } 1.2305 +}; 1.2306 + 1.2307 +} // namespace dom 1.2308 +} // namespace mozilla 1.2309 + 1.2310 +#define NS_INTERFACE_MAP_ENTRY_TEAROFF(_interface, _allocator) \ 1.2311 + if (aIID.Equals(NS_GET_IID(_interface))) { \ 1.2312 + foundInterface = static_cast<_interface *>(_allocator); \ 1.2313 + if (!foundInterface) { \ 1.2314 + *aInstancePtr = nullptr; \ 1.2315 + return NS_ERROR_OUT_OF_MEMORY; \ 1.2316 + } \ 1.2317 + } else 1.2318 + 1.2319 +/* 1.2320 + * In the following helper macros we exploit the fact that the result of a 1.2321 + * series of additions will not be finite if any one of the operands in the 1.2322 + * series is not finite. 1.2323 + */ 1.2324 +#define NS_ENSURE_FINITE(f, rv) \ 1.2325 + if (!NS_finite(f)) { \ 1.2326 + return (rv); \ 1.2327 + } 1.2328 + 1.2329 +#define NS_ENSURE_FINITE2(f1, f2, rv) \ 1.2330 + if (!NS_finite((f1)+(f2))) { \ 1.2331 + return (rv); \ 1.2332 + } 1.2333 + 1.2334 +#define NS_ENSURE_FINITE4(f1, f2, f3, f4, rv) \ 1.2335 + if (!NS_finite((f1)+(f2)+(f3)+(f4))) { \ 1.2336 + return (rv); \ 1.2337 + } 1.2338 + 1.2339 +#define NS_ENSURE_FINITE5(f1, f2, f3, f4, f5, rv) \ 1.2340 + if (!NS_finite((f1)+(f2)+(f3)+(f4)+(f5))) { \ 1.2341 + return (rv); \ 1.2342 + } 1.2343 + 1.2344 +#define NS_ENSURE_FINITE6(f1, f2, f3, f4, f5, f6, rv) \ 1.2345 + if (!NS_finite((f1)+(f2)+(f3)+(f4)+(f5)+(f6))) { \ 1.2346 + return (rv); \ 1.2347 + } 1.2348 + 1.2349 +// Deletes a linked list iteratively to avoid blowing up the stack (bug 460444). 1.2350 +#define NS_CONTENT_DELETE_LIST_MEMBER(type_, ptr_, member_) \ 1.2351 + { \ 1.2352 + type_ *cur = (ptr_)->member_; \ 1.2353 + (ptr_)->member_ = nullptr; \ 1.2354 + while (cur) { \ 1.2355 + type_ *next = cur->member_; \ 1.2356 + cur->member_ = nullptr; \ 1.2357 + delete cur; \ 1.2358 + cur = next; \ 1.2359 + } \ 1.2360 + } 1.2361 + 1.2362 +#endif /* nsContentUtils_h___ */