1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : *
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Communicator client code, released
17 : * March 31, 1998.
18 : *
19 : * The Initial Developer of the Original Code is
20 : * Netscape Communications Corporation.
21 : * Portions created by the Initial Developer are Copyright (C) 1998
22 : * the Initial Developer. All Rights Reserved.
23 : *
24 : * Contributor(s):
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : /* A namespace class for static content utilities. */
41 :
42 : #ifndef nsContentUtils_h___
43 : #define nsContentUtils_h___
44 :
45 : #include <math.h>
46 : #if defined(XP_WIN) || defined(XP_OS2)
47 : #include <float.h>
48 : #endif
49 :
50 : #if defined(SOLARIS)
51 : #include <ieeefp.h>
52 : #endif
53 :
54 : //A trick to handle IEEE floating point exceptions on FreeBSD - E.D.
55 : #ifdef __FreeBSD__
56 : #include <ieeefp.h>
57 : #ifdef __alpha__
58 : static fp_except_t allmask = FP_X_INV|FP_X_OFL|FP_X_UFL|FP_X_DZ|FP_X_IMP;
59 : #else
60 : static fp_except_t allmask = FP_X_INV|FP_X_OFL|FP_X_UFL|FP_X_DZ|FP_X_IMP|FP_X_DNML;
61 : #endif
62 : static fp_except_t oldmask = fpsetmask(~allmask);
63 : #endif
64 :
65 : #include "nsAString.h"
66 : #include "nsIStatefulFrame.h"
67 : #include "nsINodeInfo.h"
68 : #include "nsNodeInfoManager.h"
69 : #include "nsContentList.h"
70 : #include "nsDOMClassInfoID.h"
71 : #include "nsIXPCScriptable.h"
72 : #include "nsDataHashtable.h"
73 : #include "nsIScriptRuntime.h"
74 : #include "nsIScriptGlobalObject.h"
75 : #include "nsIDOMEvent.h"
76 : #include "nsTArray.h"
77 : #include "nsTextFragment.h"
78 : #include "nsReadableUtils.h"
79 : #include "nsINode.h"
80 : #include "nsHashtable.h"
81 : #include "nsIDOMNode.h"
82 : #include "nsHtml5StringParser.h"
83 : #include "nsIParser.h"
84 : #include "nsIDocument.h"
85 : #include "nsIFragmentContentSink.h"
86 : #include "nsContentSink.h"
87 : #include "nsMathUtils.h"
88 : #include "nsThreadUtils.h"
89 : #include "nsIContent.h"
90 : #include "nsCharSeparatedTokenizer.h"
91 :
92 : #include "mozilla/AutoRestore.h"
93 : #include "mozilla/GuardObjects.h"
94 : #include "mozilla/TimeStamp.h"
95 :
96 : struct nsNativeKeyEvent; // Don't include nsINativeKeyBindings.h here: it will force strange compilation error!
97 :
98 : class nsIDOMScriptObjectFactory;
99 : class nsIXPConnect;
100 : class nsIContent;
101 : class nsIDOMKeyEvent;
102 : class nsIDocument;
103 : class nsIDocumentObserver;
104 : class nsIDocShell;
105 : class nsINameSpaceManager;
106 : class nsIScriptSecurityManager;
107 : class nsIJSContextStack;
108 : class nsIThreadJSContextStack;
109 : class nsIParserService;
110 : class nsIIOService;
111 : class nsIURI;
112 : class imgIContainer;
113 : class imgIDecoderObserver;
114 : class imgIRequest;
115 : class imgILoader;
116 : class imgICache;
117 : class nsIImageLoadingContent;
118 : class nsIDOMHTMLFormElement;
119 : class nsIDOMDocument;
120 : class nsIConsoleService;
121 : class nsIStringBundleService;
122 : class nsIStringBundle;
123 : class nsIContentPolicy;
124 : class nsILineBreaker;
125 : class nsIWordBreaker;
126 : class nsIJSRuntimeService;
127 : class nsEventListenerManager;
128 : class nsIScriptContext;
129 : class nsIRunnable;
130 : class nsIInterfaceRequestor;
131 : template<class E> class nsCOMArray;
132 : template<class K, class V> class nsRefPtrHashtable;
133 : struct JSRuntime;
134 : class nsIWidget;
135 : class nsIDragSession;
136 : class nsIPresShell;
137 : class nsIXPConnectJSObjectHolder;
138 : #ifdef MOZ_XTF
139 : class nsIXTFService;
140 : #endif
141 : #ifdef IBMBIDI
142 : class nsIBidiKeyboard;
143 : #endif
144 : class nsIMIMEHeaderParam;
145 : class nsIObserver;
146 : class nsPresContext;
147 : class nsIChannel;
148 : class nsAutoScriptBlockerSuppressNodeRemoved;
149 : struct nsIntMargin;
150 : class nsPIDOMWindow;
151 : class nsIDocumentLoaderFactory;
152 : class nsIDOMHTMLInputElement;
153 :
154 : namespace mozilla {
155 :
156 : namespace layers {
157 : class LayerManager;
158 : } // namespace layers
159 :
160 : namespace dom {
161 : class Element;
162 : } // namespace dom
163 :
164 : } // namespace mozilla
165 :
166 : extern const char kLoadAsData[];
167 :
168 : enum EventNameType {
169 : EventNameType_None = 0x0000,
170 : EventNameType_HTML = 0x0001,
171 : EventNameType_XUL = 0x0002,
172 : EventNameType_SVGGraphic = 0x0004, // svg graphic elements
173 : EventNameType_SVGSVG = 0x0008, // the svg element
174 : EventNameType_SMIL = 0x0016, // smil elements
175 :
176 : EventNameType_HTMLXUL = 0x0003,
177 : EventNameType_All = 0xFFFF
178 : };
179 :
180 : /**
181 : * Information retrieved from the <meta name="viewport"> tag. See
182 : * GetViewportInfo for more information on this functionality.
183 : */
184 : struct ViewportInfo
185 : {
186 : // Default zoom indicates the level at which the display is 'zoomed in'
187 : // initially for the user, upon loading of the page.
188 : double defaultZoom;
189 :
190 : // The minimum zoom level permitted by the page.
191 : double minZoom;
192 :
193 : // The maximum zoom level permitted by the page.
194 : double maxZoom;
195 :
196 : // The width of the viewport, specified by the <meta name="viewport"> tag,
197 : // in CSS pixels.
198 : PRUint32 width;
199 :
200 : // The height of the viewport, specified by the <meta name="viewport"> tag,
201 : // in CSS pixels.
202 : PRUint32 height;
203 :
204 : // Whether or not we should automatically size the viewport to the device's
205 : // width. This is true if the document has been optimized for mobile, and
206 : // the width property of a specified <meta name="viewport"> tag is either
207 : // not specified, or is set to the special value 'device-width'.
208 : bool autoSize;
209 :
210 : // Whether or not the user can zoom in and out on the page. Default is true.
211 : bool allowZoom;
212 :
213 : // This is a holdover from e10s fennec, and might be removed in the future.
214 : // It's a hack to work around bugs that didn't allow zooming of documents
215 : // from within the parent process. It is still used in native Fennec for XUL
216 : // documents, but it should probably be removed.
217 : // Currently, from, within GetViewportInfo(), This is only set to false
218 : // if the document is a XUL document.
219 : bool autoScale;
220 : };
221 :
222 : struct EventNameMapping
223 : {
224 : nsIAtom* mAtom;
225 : PRUint32 mId;
226 : PRInt32 mType;
227 : PRUint32 mStructType;
228 : };
229 :
230 0 : struct nsShortcutCandidate {
231 0 : nsShortcutCandidate(PRUint32 aCharCode, bool aIgnoreShift) :
232 0 : mCharCode(aCharCode), mIgnoreShift(aIgnoreShift)
233 : {
234 0 : }
235 : PRUint32 mCharCode;
236 : bool mIgnoreShift;
237 : };
238 :
239 : class nsContentUtils
240 : {
241 : friend class nsAutoScriptBlockerSuppressNodeRemoved;
242 : typedef mozilla::dom::Element Element;
243 : typedef mozilla::TimeDuration TimeDuration;
244 :
245 : public:
246 : static nsresult Init();
247 :
248 : /**
249 : * Get a JSContext from the document's scope object.
250 : */
251 : static JSContext* GetContextFromDocument(nsIDocument *aDocument);
252 :
253 : /**
254 : * Get a scope from aNewDocument. Also get a context through the scope of one
255 : * of the documents, from the stack or the safe context.
256 : *
257 : * @param aOldDocument The document to try to get a context from. May be null.
258 : * @param aNewDocument The document to get aNewScope from.
259 : * @param aCx [out] Context gotten through one of the scopes, from the stack
260 : * or the safe context.
261 : * @param aNewScope [out] Scope gotten from aNewDocument.
262 : */
263 : static nsresult GetContextAndScope(nsIDocument *aOldDocument,
264 : nsIDocument *aNewDocument,
265 : JSContext **aCx, JSObject **aNewScope);
266 :
267 : /**
268 : * When a document's scope changes (e.g., from document.open(), call this
269 : * function to move all content wrappers from the old scope to the new one.
270 : */
271 : static nsresult ReparentContentWrappersInScope(JSContext *cx,
272 : nsIScriptGlobalObject *aOldScope,
273 : nsIScriptGlobalObject *aNewScope);
274 :
275 : static bool IsCallerChrome();
276 :
277 : static bool IsCallerTrustedForRead();
278 :
279 : static bool IsCallerTrustedForWrite();
280 :
281 : /**
282 : * Check whether a caller has UniversalXPConnect.
283 : */
284 : static bool CallerHasUniversalXPConnect();
285 :
286 : static bool IsImageSrcSetDisabled();
287 :
288 : /**
289 : * Returns the parent node of aChild crossing document boundaries.
290 : */
291 : static nsINode* GetCrossDocParentNode(nsINode* aChild);
292 :
293 : /**
294 : * Do not ever pass null pointers to this method. If one of your
295 : * nsIContents is null, you have to decide for yourself what
296 : * "IsDescendantOf" really means.
297 : *
298 : * @param aPossibleDescendant node to test for being a descendant of
299 : * aPossibleAncestor
300 : * @param aPossibleAncestor node to test for being an ancestor of
301 : * aPossibleDescendant
302 : * @return true if aPossibleDescendant is a descendant of
303 : * aPossibleAncestor (or is aPossibleAncestor). false
304 : * otherwise.
305 : */
306 : static bool ContentIsDescendantOf(const nsINode* aPossibleDescendant,
307 : const nsINode* aPossibleAncestor);
308 :
309 : /**
310 : * Similar to ContentIsDescendantOf except it crosses document boundaries.
311 : */
312 : static bool ContentIsCrossDocDescendantOf(nsINode* aPossibleDescendant,
313 : nsINode* aPossibleAncestor);
314 :
315 : /*
316 : * This method fills the |aArray| with all ancestor nodes of |aNode|
317 : * including |aNode| at the zero index.
318 : */
319 : static nsresult GetAncestors(nsINode* aNode,
320 : nsTArray<nsINode*>& aArray);
321 :
322 : /*
323 : * This method fills |aAncestorNodes| with all ancestor nodes of |aNode|
324 : * including |aNode| (QI'd to nsIContent) at the zero index.
325 : * For each ancestor, there is a corresponding element in |aAncestorOffsets|
326 : * which is the IndexOf the child in relation to its parent.
327 : *
328 : * This method just sucks.
329 : */
330 : static nsresult GetAncestorsAndOffsets(nsIDOMNode* aNode,
331 : PRInt32 aOffset,
332 : nsTArray<nsIContent*>* aAncestorNodes,
333 : nsTArray<PRInt32>* aAncestorOffsets);
334 :
335 : /*
336 : * The out parameter, |aCommonAncestor| will be the closest node, if any,
337 : * to both |aNode| and |aOther| which is also an ancestor of each.
338 : * Returns an error if the two nodes are disconnected and don't have
339 : * a common ancestor.
340 : */
341 : static nsresult GetCommonAncestor(nsIDOMNode *aNode,
342 : nsIDOMNode *aOther,
343 : nsIDOMNode** aCommonAncestor);
344 :
345 : /**
346 : * Returns the common ancestor, if any, for two nodes. Returns null if the
347 : * nodes are disconnected.
348 : */
349 : static nsINode* GetCommonAncestor(nsINode* aNode1,
350 : nsINode* aNode2);
351 :
352 : /**
353 : * Returns true if aNode1 is before aNode2 in the same connected
354 : * tree.
355 : */
356 21 : static bool PositionIsBefore(nsINode* aNode1,
357 : nsINode* aNode2)
358 : {
359 21 : return (aNode2->CompareDocPosition(aNode1) &
360 : (nsIDOMNode::DOCUMENT_POSITION_PRECEDING |
361 : nsIDOMNode::DOCUMENT_POSITION_DISCONNECTED)) ==
362 21 : nsIDOMNode::DOCUMENT_POSITION_PRECEDING;
363 : }
364 :
365 : /**
366 : * Utility routine to compare two "points", where a point is a
367 : * node/offset pair
368 : * Returns -1 if point1 < point2, 1, if point1 > point2,
369 : * 0 if error or if point1 == point2.
370 : * NOTE! If the two nodes aren't in the same connected subtree,
371 : * the result is 1, and the optional aDisconnected parameter
372 : * is set to true.
373 : */
374 : static PRInt32 ComparePoints(nsINode* aParent1, PRInt32 aOffset1,
375 : nsINode* aParent2, PRInt32 aOffset2,
376 : bool* aDisconnected = nsnull);
377 : static PRInt32 ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1,
378 : nsIDOMNode* aParent2, PRInt32 aOffset2,
379 : bool* aDisconnected = nsnull);
380 :
381 : /**
382 : * Brute-force search of the element subtree rooted at aContent for
383 : * an element with the given id. aId must be nonempty, otherwise
384 : * this method may return nodes even if they have no id!
385 : */
386 : static Element* MatchElementId(nsIContent *aContent, const nsAString& aId);
387 :
388 : /**
389 : * Similar to above, but to be used if one already has an atom for the ID
390 : */
391 : static Element* MatchElementId(nsIContent *aContent, const nsIAtom* aId);
392 :
393 : /**
394 : * Reverses the document position flags passed in.
395 : *
396 : * @param aDocumentPosition The document position flags to be reversed.
397 : *
398 : * @return The reversed document position flags.
399 : *
400 : * @see nsIDOMNode
401 : */
402 : static PRUint16 ReverseDocumentPosition(PRUint16 aDocumentPosition);
403 :
404 : static PRUint32 CopyNewlineNormalizedUnicodeTo(const nsAString& aSource,
405 : PRUint32 aSrcOffset,
406 : PRUnichar* aDest,
407 : PRUint32 aLength,
408 : bool& aLastCharCR);
409 :
410 : static PRUint32 CopyNewlineNormalizedUnicodeTo(nsReadingIterator<PRUnichar>& aSrcStart, const nsReadingIterator<PRUnichar>& aSrcEnd, nsAString& aDest);
411 :
412 : static nsISupports *
413 : GetClassInfoInstance(nsDOMClassInfoID aID);
414 :
415 : static const nsDependentSubstring TrimCharsInSet(const char* aSet,
416 : const nsAString& aValue);
417 :
418 : template<bool IsWhitespace(PRUnichar)>
419 : static const nsDependentSubstring TrimWhitespace(const nsAString& aStr,
420 : bool aTrimTrailing = true);
421 :
422 : /**
423 : * Returns true if aChar is of class Ps, Pi, Po, Pf, or Pe.
424 : */
425 : static bool IsFirstLetterPunctuation(PRUint32 aChar);
426 : static bool IsFirstLetterPunctuationAt(const nsTextFragment* aFrag, PRUint32 aOffset);
427 :
428 : /**
429 : * Returns true if aChar is of class Lu, Ll, Lt, Lm, Lo, Nd, Nl or No
430 : */
431 : static bool IsAlphanumeric(PRUint32 aChar);
432 : static bool IsAlphanumericAt(const nsTextFragment* aFrag, PRUint32 aOffset);
433 :
434 : /*
435 : * Is the character an HTML whitespace character?
436 : *
437 : * We define whitespace using the list in HTML5 and css3-selectors:
438 : * U+0009, U+000A, U+000C, U+000D, U+0020
439 : *
440 : * HTML 4.01 also lists U+200B (zero-width space).
441 : */
442 : static bool IsHTMLWhitespace(PRUnichar aChar);
443 :
444 : /**
445 : * Is the HTML local name a block element?
446 : */
447 : static bool IsHTMLBlock(nsIAtom* aLocalName);
448 :
449 : /**
450 : * Is the HTML local name a void element?
451 : */
452 : static bool IsHTMLVoid(nsIAtom* aLocalName);
453 :
454 : /**
455 : * Parse a margin string of format 'top, right, bottom, left' into
456 : * an nsIntMargin.
457 : *
458 : * @param aString the string to parse
459 : * @param aResult the resulting integer
460 : * @return whether the value could be parsed
461 : */
462 : static bool ParseIntMarginValue(const nsAString& aString, nsIntMargin& aResult);
463 :
464 : static void Shutdown();
465 :
466 : /**
467 : * Checks whether two nodes come from the same origin.
468 : */
469 : static nsresult CheckSameOrigin(nsINode* aTrustedNode,
470 : nsIDOMNode* aUnTrustedNode);
471 :
472 : // Check if the (JS) caller can access aNode.
473 : static bool CanCallerAccess(nsIDOMNode *aNode);
474 :
475 : // Check if the (JS) caller can access aWindow.
476 : // aWindow can be either outer or inner window.
477 : static bool CanCallerAccess(nsPIDOMWindow* aWindow);
478 :
479 : /**
480 : * Get the window through the JS context that's currently on the stack.
481 : * If there's no JS context currently on the stack, returns null.
482 : */
483 : static nsPIDOMWindow *GetWindowFromCaller();
484 :
485 : /**
486 : * The two GetDocumentFrom* functions below allow a caller to get at a
487 : * document that is relevant to the currently executing script.
488 : *
489 : * GetDocumentFromCaller gets its document by looking at the last called
490 : * function and finding the document that the function itself relates to.
491 : * For example, consider two windows A and B in the same origin. B has a
492 : * function which does something that ends up needing the current document.
493 : * If a script in window A were to call B's function, GetDocumentFromCaller
494 : * would find that function (in B) and return B's document.
495 : *
496 : * GetDocumentFromContext gets its document by looking at the currently
497 : * executing context's global object and returning its document. Thus,
498 : * given the example above, GetDocumentFromCaller would see that the
499 : * currently executing script was in window A, and return A's document.
500 : */
501 : /**
502 : * Get the document from the currently executing function. This will return
503 : * the document that the currently executing function is in/from.
504 : *
505 : * @return The document or null if no JS Context.
506 : */
507 : static nsIDOMDocument *GetDocumentFromCaller();
508 :
509 : /**
510 : * Get the document through the JS context that's currently on the stack.
511 : * If there's no JS context currently on the stack it will return null.
512 : * This will return the document of the calling script.
513 : *
514 : * @return The document or null if no JS context
515 : */
516 : static nsIDOMDocument *GetDocumentFromContext();
517 :
518 : // Check if a node is in the document prolog, i.e. before the document
519 : // element.
520 : static bool InProlog(nsINode *aNode);
521 :
522 : static nsIParserService* GetParserService();
523 :
524 45766 : static nsINameSpaceManager* NameSpaceManager()
525 : {
526 45766 : return sNameSpaceManager;
527 : }
528 :
529 0 : static nsIIOService* GetIOService()
530 : {
531 0 : return sIOService;
532 : }
533 :
534 1 : static imgILoader* GetImgLoader()
535 : {
536 1 : if (!sImgLoaderInitialized)
537 1 : InitImgLoader();
538 1 : return sImgLoader;
539 : }
540 :
541 : #ifdef MOZ_XTF
542 : static nsIXTFService* GetXTFService();
543 : #endif
544 :
545 : #ifdef IBMBIDI
546 : static nsIBidiKeyboard* GetBidiKeyboard();
547 : #endif
548 :
549 : /**
550 : * Get the cache security manager service. Can return null if the layout
551 : * module has been shut down.
552 : */
553 5722 : static nsIScriptSecurityManager* GetSecurityManager()
554 : {
555 5722 : return sSecurityManager;
556 : }
557 :
558 : static nsresult GenerateStateKey(nsIContent* aContent,
559 : const nsIDocument* aDocument,
560 : nsIStatefulFrame::SpecialStateID aID,
561 : nsACString& aKey);
562 :
563 : /**
564 : * Create a new nsIURI from aSpec, using aBaseURI as the base. The
565 : * origin charset of the new nsIURI will be the document charset of
566 : * aDocument.
567 : */
568 : static nsresult NewURIWithDocumentCharset(nsIURI** aResult,
569 : const nsAString& aSpec,
570 : nsIDocument* aDocument,
571 : nsIURI* aBaseURI);
572 :
573 : /**
574 : * Convert aInput (in charset aCharset) to UTF16 in aOutput.
575 : *
576 : * @param aCharset the name of the charset; if empty, we assume UTF8
577 : */
578 : static nsresult ConvertStringFromCharset(const nsACString& aCharset,
579 : const nsACString& aInput,
580 : nsAString& aOutput);
581 :
582 : /**
583 : * Determine whether a buffer begins with a BOM for UTF-8, UTF-16LE,
584 : * UTF-16BE
585 : *
586 : * @param aBuffer the buffer to check
587 : * @param aLength the length of the buffer
588 : * @param aCharset empty if not found
589 : * @return boolean indicating whether a BOM was detected.
590 : */
591 : static bool CheckForBOM(const unsigned char* aBuffer, PRUint32 aLength,
592 : nsACString& aCharset, bool *bigEndian = nsnull);
593 :
594 :
595 : /**
596 : * Determine whether aContent is in some way associated with aForm. If the
597 : * form is a container the only elements that are considered to be associated
598 : * with a form are the elements that are contained within the form. If the
599 : * form is a leaf element then all elements will be accepted into this list,
600 : * since this can happen due to content fixup when a form spans table rows or
601 : * table cells.
602 : */
603 : static bool BelongsInForm(nsIContent *aForm,
604 : nsIContent *aContent);
605 :
606 : static nsresult CheckQName(const nsAString& aQualifiedName,
607 : bool aNamespaceAware = true);
608 :
609 : static nsresult SplitQName(const nsIContent* aNamespaceResolver,
610 : const nsAFlatString& aQName,
611 : PRInt32 *aNamespace, nsIAtom **aLocalName);
612 :
613 : static nsresult GetNodeInfoFromQName(const nsAString& aNamespaceURI,
614 : const nsAString& aQualifiedName,
615 : nsNodeInfoManager* aNodeInfoManager,
616 : PRUint16 aNodeType,
617 : nsINodeInfo** aNodeInfo);
618 :
619 : static void SplitExpatName(const PRUnichar *aExpatName, nsIAtom **aPrefix,
620 : nsIAtom **aTagName, PRInt32 *aNameSpaceID);
621 :
622 : // Get a permission-manager setting for the given uri and type.
623 : // If the pref doesn't exist or if it isn't ALLOW_ACTION, false is
624 : // returned, otherwise true is returned.
625 : static bool IsSitePermAllow(nsIURI* aURI, const char* aType);
626 :
627 12 : static nsILineBreaker* LineBreaker()
628 : {
629 12 : return sLineBreaker;
630 : }
631 :
632 0 : static nsIWordBreaker* WordBreaker()
633 : {
634 0 : return sWordBreaker;
635 : }
636 :
637 : /**
638 : * Regster aObserver as a shutdown observer. A strong reference is held
639 : * to aObserver until UnregisterShutdownObserver is called.
640 : */
641 : static void RegisterShutdownObserver(nsIObserver* aObserver);
642 : static void UnregisterShutdownObserver(nsIObserver* aObserver);
643 :
644 : /**
645 : * @return true if aContent has an attribute aName in namespace aNameSpaceID,
646 : * and the attribute value is non-empty.
647 : */
648 : static bool HasNonEmptyAttr(const nsIContent* aContent, PRInt32 aNameSpaceID,
649 : nsIAtom* aName);
650 :
651 : /**
652 : * Method that gets the primary presContext for the node.
653 : *
654 : * @param aContent The content node.
655 : * @return the presContext, or nsnull if the content is not in a document
656 : * (if GetCurrentDoc returns nsnull)
657 : */
658 : static nsPresContext* GetContextForContent(const nsIContent* aContent);
659 :
660 : /**
661 : * Method to do security and content policy checks on the image URI
662 : *
663 : * @param aURI uri of the image to be loaded
664 : * @param aContext the context the image is loaded in (eg an element)
665 : * @param aLoadingDocument the document we belong to
666 : * @param aLoadingPrincipal the principal doing the load
667 : * @param aImageBlockingStatus the nsIContentPolicy blocking status for this
668 : * image. This will be set even if a security check fails for the
669 : * image, to some reasonable REJECT_* value. This out param will only
670 : * be set if it's non-null.
671 : * @return true if the load can proceed, or false if it is blocked.
672 : * Note that aImageBlockingStatus, if set will always be an ACCEPT
673 : * status if true is returned and always be a REJECT_* status if
674 : * false is returned.
675 : */
676 : static bool CanLoadImage(nsIURI* aURI,
677 : nsISupports* aContext,
678 : nsIDocument* aLoadingDocument,
679 : nsIPrincipal* aLoadingPrincipal,
680 : PRInt16* aImageBlockingStatus = nsnull);
681 : /**
682 : * Method to start an image load. This does not do any security checks.
683 : * This method will attempt to make aURI immutable; a caller that wants to
684 : * keep a mutable version around should pass in a clone.
685 : *
686 : * @param aURI uri of the image to be loaded
687 : * @param aLoadingDocument the document we belong to
688 : * @param aLoadingPrincipal the principal doing the load
689 : * @param aReferrer the referrer URI
690 : * @param aObserver the observer for the image load
691 : * @param aLoadFlags the load flags to use. See nsIRequest
692 : * @return the imgIRequest for the image load
693 : */
694 : static nsresult LoadImage(nsIURI* aURI,
695 : nsIDocument* aLoadingDocument,
696 : nsIPrincipal* aLoadingPrincipal,
697 : nsIURI* aReferrer,
698 : imgIDecoderObserver* aObserver,
699 : PRInt32 aLoadFlags,
700 : imgIRequest** aRequest);
701 :
702 : /**
703 : * Returns whether the given URI is in the image cache.
704 : */
705 : static bool IsImageInCache(nsIURI* aURI);
706 :
707 : /**
708 : * Method to get an imgIContainer from an image loading content
709 : *
710 : * @param aContent The image loading content. Must not be null.
711 : * @param aRequest The image request [out]
712 : * @return the imgIContainer corresponding to the first frame of the image
713 : */
714 : static already_AddRefed<imgIContainer> GetImageFromContent(nsIImageLoadingContent* aContent, imgIRequest **aRequest = nsnull);
715 :
716 : /**
717 : * Helper method to call imgIRequest::GetStaticRequest.
718 : */
719 : static already_AddRefed<imgIRequest> GetStaticRequest(imgIRequest* aRequest);
720 :
721 : /**
722 : * Method that decides whether a content node is draggable
723 : *
724 : * @param aContent The content node to test.
725 : * @return whether it's draggable
726 : */
727 : static bool ContentIsDraggable(nsIContent* aContent);
728 :
729 : /**
730 : * Method that decides whether a content node is a draggable image
731 : *
732 : * @param aContent The content node to test.
733 : * @return whether it's a draggable image
734 : */
735 : static bool IsDraggableImage(nsIContent* aContent);
736 :
737 : /**
738 : * Method that decides whether a content node is a draggable link
739 : *
740 : * @param aContent The content node to test.
741 : * @return whether it's a draggable link
742 : */
743 : static bool IsDraggableLink(const nsIContent* aContent);
744 :
745 : /**
746 : * Convenience method to create a new nodeinfo that differs only by name
747 : * from aNodeInfo.
748 : */
749 0 : static nsresult NameChanged(nsINodeInfo *aNodeInfo, nsIAtom *aName,
750 : nsINodeInfo** aResult)
751 : {
752 0 : nsNodeInfoManager *niMgr = aNodeInfo->NodeInfoManager();
753 :
754 : *aResult = niMgr->GetNodeInfo(aName, aNodeInfo->GetPrefixAtom(),
755 : aNodeInfo->NamespaceID(),
756 0 : aNodeInfo->NodeType(),
757 0 : aNodeInfo->GetExtraName()).get();
758 0 : return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
759 : }
760 :
761 : /**
762 : * Returns the appropriate event argument names for the specified
763 : * namespace and event name. Added because we need to switch between
764 : * SVG's "evt" and the rest of the world's "event", and because onerror
765 : * takes 3 args.
766 : */
767 : static void GetEventArgNames(PRInt32 aNameSpaceID, nsIAtom *aEventName,
768 : PRUint32 *aArgCount, const char*** aArgNames);
769 :
770 : /**
771 : * If aNode is not an element, return true exactly when aContent's binding
772 : * parent is null.
773 : *
774 : * If aNode is an element, return true exactly when aContent's binding parent
775 : * is the same as aNode's.
776 : *
777 : * This method is particularly useful for callers who are trying to ensure
778 : * that they are working with a non-anonymous descendant of a given node. If
779 : * aContent is a descendant of aNode, a return value of false from this
780 : * method means that it's an anonymous descendant from aNode's point of view.
781 : *
782 : * Both arguments to this method must be non-null.
783 : */
784 : static bool IsInSameAnonymousTree(const nsINode* aNode, const nsIContent* aContent);
785 :
786 : /**
787 : * Return the nsIXPConnect service.
788 : */
789 355 : static nsIXPConnect *XPConnect()
790 : {
791 355 : return sXPConnect;
792 : }
793 :
794 : /**
795 : * Report a localized error message to the error console.
796 : * @param aErrorFlags See nsIScriptError.
797 : * @param aCategory Name of module reporting error.
798 : * @param aDocument Reference to the document which triggered the message.
799 : * @param aFile Properties file containing localized message.
800 : * @param aMessageName Name of localized message.
801 : * @param [aParams=nsnull] (Optional) Parameters to be substituted into
802 : localized message.
803 : * @param [aParamsLength=0] (Optional) Length of aParams.
804 : * @param [aURI=nsnull] (Optional) URI of resource containing error.
805 : * @param [aSourceLine=EmptyString()] (Optional) The text of the line that
806 : contains the error (may be empty).
807 : * @param [aLineNumber=0] (Optional) Line number within resource
808 : containing error.
809 : * @param [aColumnNumber=0] (Optional) Column number within resource
810 : containing error.
811 : If aURI is null, then aDocument->GetDocumentURI() is used.
812 : */
813 : enum PropertiesFile {
814 : eCSS_PROPERTIES,
815 : eXBL_PROPERTIES,
816 : eXUL_PROPERTIES,
817 : eLAYOUT_PROPERTIES,
818 : eFORMS_PROPERTIES,
819 : ePRINTING_PROPERTIES,
820 : eDOM_PROPERTIES,
821 : eHTMLPARSER_PROPERTIES,
822 : eSVG_PROPERTIES,
823 : eBRAND_PROPERTIES,
824 : eCOMMON_DIALOG_PROPERTIES,
825 : PropertiesFile_COUNT
826 : };
827 : static nsresult ReportToConsole(PRUint32 aErrorFlags,
828 : const char *aCategory,
829 : nsIDocument* aDocument,
830 : PropertiesFile aFile,
831 : const char *aMessageName,
832 : const PRUnichar **aParams = nsnull,
833 : PRUint32 aParamsLength = 0,
834 : nsIURI* aURI = nsnull,
835 : const nsAFlatString& aSourceLine
836 28 : = EmptyString(),
837 : PRUint32 aLineNumber = 0,
838 : PRUint32 aColumnNumber = 0);
839 :
840 : /**
841 : * Get the localized string named |aKey| in properties file |aFile|.
842 : */
843 : static nsresult GetLocalizedString(PropertiesFile aFile,
844 : const char* aKey,
845 : nsXPIDLString& aResult);
846 :
847 : /**
848 : * Fill (with the parameters given) the localized string named |aKey| in
849 : * properties file |aFile|.
850 : */
851 : private:
852 : static nsresult FormatLocalizedString(PropertiesFile aFile,
853 : const char* aKey,
854 : const PRUnichar** aParams,
855 : PRUint32 aParamsLength,
856 : nsXPIDLString& aResult);
857 :
858 : public:
859 : template<PRUint32 N>
860 0 : static nsresult FormatLocalizedString(PropertiesFile aFile,
861 : const char* aKey,
862 : const PRUnichar* (&aParams)[N],
863 : nsXPIDLString& aResult)
864 : {
865 0 : return FormatLocalizedString(aFile, aKey, aParams, N, aResult);
866 : }
867 :
868 : /**
869 : * Returns true if aDocument is a chrome document
870 : */
871 : static bool IsChromeDoc(nsIDocument *aDocument);
872 :
873 : /**
874 : * Returns true if aDocument is in a docshell whose parent is the same type
875 : */
876 : static bool IsChildOfSameType(nsIDocument* aDoc);
877 :
878 : /**
879 : * Get the script file name to use when compiling the script
880 : * referenced by aURI. In cases where there's no need for any extra
881 : * security wrapper automation the script file name that's returned
882 : * will be the spec in aURI, else it will be the spec in aDocument's
883 : * URI followed by aURI's spec, separated by " -> ". Returns true
884 : * if the script file name was modified, false if it's aURI's
885 : * spec.
886 : */
887 : static bool GetWrapperSafeScriptFilename(nsIDocument *aDocument,
888 : nsIURI *aURI,
889 : nsACString& aScriptURI);
890 :
891 :
892 : /**
893 : * Returns true if aDocument belongs to a chrome docshell for
894 : * display purposes. Returns false for null documents or documents
895 : * which do not belong to a docshell.
896 : */
897 : static bool IsInChromeDocshell(nsIDocument *aDocument);
898 :
899 : /**
900 : * Return the content policy service
901 : */
902 : static nsIContentPolicy *GetContentPolicy();
903 :
904 : /**
905 : * Quick helper to determine whether there are any mutation listeners
906 : * of a given type that apply to this content or any of its ancestors.
907 : * The method has the side effect to call document's MayDispatchMutationEvent
908 : * using aTargetForSubtreeModified as the parameter.
909 : *
910 : * @param aNode The node to search for listeners
911 : * @param aType The type of listener (NS_EVENT_BITS_MUTATION_*)
912 : * @param aTargetForSubtreeModified The node which is the target of the
913 : * possible DOMSubtreeModified event.
914 : *
915 : * @return true if there are mutation listeners of the specified type
916 : */
917 : static bool HasMutationListeners(nsINode* aNode,
918 : PRUint32 aType,
919 : nsINode* aTargetForSubtreeModified);
920 :
921 : /**
922 : * Quick helper to determine whether there are any mutation listeners
923 : * of a given type that apply to any content in this document. It is valid
924 : * to pass null for aDocument here, in which case this function always
925 : * returns true.
926 : *
927 : * @param aDocument The document to search for listeners
928 : * @param aType The type of listener (NS_EVENT_BITS_MUTATION_*)
929 : *
930 : * @return true if there are mutation listeners of the specified type
931 : */
932 : static bool HasMutationListeners(nsIDocument* aDocument,
933 : PRUint32 aType);
934 : /**
935 : * Synchronously fire DOMNodeRemoved on aChild. Only fires the event if
936 : * there really are listeners by checking using the HasMutationListeners
937 : * function above. The function makes sure to hold the relevant objects alive
938 : * for the duration of the event firing. However there are no guarantees
939 : * that any of the objects are alive by the time the function returns.
940 : * If you depend on that you need to hold references yourself.
941 : *
942 : * @param aChild The node to fire DOMNodeRemoved at.
943 : * @param aParent The parent of aChild.
944 : * @param aOwnerDoc The ownerDocument of aChild.
945 : */
946 : static void MaybeFireNodeRemoved(nsINode* aChild, nsINode* aParent,
947 : nsIDocument* aOwnerDoc);
948 :
949 : /**
950 : * This method creates and dispatches a trusted event.
951 : * Works only with events which can be created by calling
952 : * nsIDOMDocument::CreateEvent() with parameter "Events".
953 : * @param aDoc The document which will be used to create the event.
954 : * @param aTarget The target of the event, should be QIable to
955 : * nsIDOMEventTarget.
956 : * @param aEventName The name of the event.
957 : * @param aCanBubble Whether the event can bubble.
958 : * @param aCancelable Is the event cancelable.
959 : * @param aDefaultAction Set to true if default action should be taken,
960 : * see nsIDOMEventTarget::DispatchEvent.
961 : */
962 : static nsresult DispatchTrustedEvent(nsIDocument* aDoc,
963 : nsISupports* aTarget,
964 : const nsAString& aEventName,
965 : bool aCanBubble,
966 : bool aCancelable,
967 : bool *aDefaultAction = nsnull);
968 :
969 : /**
970 : * This method creates and dispatches a untrusted event.
971 : * Works only with events which can be created by calling
972 : * nsIDOMDocument::CreateEvent() with parameter "Events".
973 : * @param aDoc The document which will be used to create the event.
974 : * @param aTarget The target of the event, should be QIable to
975 : * nsIDOMEventTarget.
976 : * @param aEventName The name of the event.
977 : * @param aCanBubble Whether the event can bubble.
978 : * @param aCancelable Is the event cancelable.
979 : * @param aDefaultAction Set to true if default action should be taken,
980 : * see nsIDOMEventTarget::DispatchEvent.
981 : */
982 : static nsresult DispatchUntrustedEvent(nsIDocument* aDoc,
983 : nsISupports* aTarget,
984 : const nsAString& aEventName,
985 : bool aCanBubble,
986 : bool aCancelable,
987 : bool *aDefaultAction = nsnull);
988 :
989 : /**
990 : * This method creates and dispatches a trusted event to the chrome
991 : * event handler.
992 : * Works only with events which can be created by calling
993 : * nsIDOMDocument::CreateEvent() with parameter "Events".
994 : * @param aDocument The document which will be used to create the event,
995 : * and whose window's chrome handler will be used to
996 : * dispatch the event.
997 : * @param aTarget The target of the event, used for event->SetTarget()
998 : * @param aEventName The name of the event.
999 : * @param aCanBubble Whether the event can bubble.
1000 : * @param aCancelable Is the event cancelable.
1001 : * @param aDefaultAction Set to true if default action should be taken,
1002 : * see nsIDOMEventTarget::DispatchEvent.
1003 : */
1004 : static nsresult DispatchChromeEvent(nsIDocument* aDoc,
1005 : nsISupports* aTarget,
1006 : const nsAString& aEventName,
1007 : bool aCanBubble,
1008 : bool aCancelable,
1009 : bool *aDefaultAction = nsnull);
1010 :
1011 : /**
1012 : * Determines if an event attribute name (such as onclick) is valid for
1013 : * a given element type. Types are from the EventNameType enumeration
1014 : * defined above.
1015 : *
1016 : * @param aName the event name to look up
1017 : * @param aType the type of content
1018 : */
1019 : static bool IsEventAttributeName(nsIAtom* aName, PRInt32 aType);
1020 :
1021 : /**
1022 : * Return the event id for the event with the given name. The name is the
1023 : * event name with the 'on' prefix. Returns NS_USER_DEFINED_EVENT if the
1024 : * event doesn't match a known event name.
1025 : *
1026 : * @param aName the event name to look up
1027 : */
1028 : static PRUint32 GetEventId(nsIAtom* aName);
1029 :
1030 : /**
1031 : * Return the category for the event with the given name. The name is the
1032 : * event name *without* the 'on' prefix. Returns NS_EVENT if the event
1033 : * is not known to be in any particular category.
1034 : *
1035 : * @param aName the event name to look up
1036 : */
1037 : static PRUint32 GetEventCategory(const nsAString& aName);
1038 :
1039 : /**
1040 : * Return the event id and atom for the event with the given name.
1041 : * The name is the event name *without* the 'on' prefix.
1042 : * Returns NS_USER_DEFINED_EVENT on the aEventID if the
1043 : * event doesn't match a known event name in the category.
1044 : *
1045 : * @param aName the event name to look up
1046 : * @param aEventStruct only return event id in aEventStruct category
1047 : */
1048 : static nsIAtom* GetEventIdAndAtom(const nsAString& aName,
1049 : PRUint32 aEventStruct,
1050 : PRUint32* aEventID);
1051 :
1052 : /**
1053 : * Used only during traversal of the XPCOM graph by the cycle
1054 : * collector: push a pointer to the listener manager onto the
1055 : * children deque, if it exists. Do nothing if there is no listener
1056 : * manager.
1057 : *
1058 : * Crucially: does not perform any refcounting operations.
1059 : *
1060 : * @param aNode The node to traverse.
1061 : * @param children The buffer to push a listener manager pointer into.
1062 : */
1063 : static void TraverseListenerManager(nsINode *aNode,
1064 : nsCycleCollectionTraversalCallback &cb);
1065 :
1066 : /**
1067 : * Get the eventlistener manager for aNode. If a new eventlistener manager
1068 : * was created, aCreated is set to true.
1069 : *
1070 : * @param aNode The node for which to get the eventlistener manager.
1071 : * @param aCreateIfNotFound If false, returns a listener manager only if
1072 : * one already exists.
1073 : */
1074 : static nsEventListenerManager* GetListenerManager(nsINode* aNode,
1075 : bool aCreateIfNotFound);
1076 :
1077 : static void UnmarkGrayJSListenersInCCGenerationDocuments(PRUint32 aGeneration);
1078 :
1079 : /**
1080 : * Remove the eventlistener manager for aNode.
1081 : *
1082 : * @param aNode The node for which to remove the eventlistener manager.
1083 : */
1084 : static void RemoveListenerManager(nsINode *aNode);
1085 :
1086 0 : static bool IsInitialized()
1087 : {
1088 0 : return sInitialized;
1089 : }
1090 :
1091 : /**
1092 : * Checks if the localname/prefix/namespace triple is valid wrt prefix
1093 : * and namespace according to the Namespaces in XML and DOM Code
1094 : * specfications.
1095 : *
1096 : * @param aLocalname localname of the node
1097 : * @param aPrefix prefix of the node
1098 : * @param aNamespaceID namespace of the node
1099 : */
1100 : static bool IsValidNodeName(nsIAtom *aLocalName, nsIAtom *aPrefix,
1101 : PRInt32 aNamespaceID);
1102 :
1103 : /**
1104 : * Creates a DocumentFragment from text using a context node to resolve
1105 : * namespaces.
1106 : *
1107 : * Note! In the HTML case with the HTML5 parser enabled, this is only called
1108 : * from Range.createContextualFragment() and the implementation here is
1109 : * quirky accordingly (html context node behaves like a body context node).
1110 : * If you don't want that quirky behavior, don't use this method as-is!
1111 : *
1112 : * @param aContextNode the node which is used to resolve namespaces
1113 : * @param aFragment the string which is parsed to a DocumentFragment
1114 : * @param aReturn the resulting fragment
1115 : * @param aPreventScriptExecution whether to mark scripts as already started
1116 : */
1117 : static nsresult CreateContextualFragment(nsINode* aContextNode,
1118 : const nsAString& aFragment,
1119 : bool aPreventScriptExecution,
1120 : nsIDOMDocumentFragment** aReturn);
1121 :
1122 : /**
1123 : * Invoke the fragment parsing algorithm (innerHTML) using the HTML parser.
1124 : *
1125 : * @param aSourceBuffer the string being set as innerHTML
1126 : * @param aTargetNode the target container
1127 : * @param aContextLocalName local name of context node
1128 : * @param aContextNamespace namespace of context node
1129 : * @param aQuirks true to make <table> not close <p>
1130 : * @param aPreventScriptExecution true to prevent scripts from executing;
1131 : * don't set to false when parsing into a target node that has been
1132 : * bound to tree.
1133 : * @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse
1134 : * fragments is made, NS_ERROR_OUT_OF_MEMORY if aSourceBuffer is too
1135 : * long and NS_OK otherwise.
1136 : */
1137 : static nsresult ParseFragmentHTML(const nsAString& aSourceBuffer,
1138 : nsIContent* aTargetNode,
1139 : nsIAtom* aContextLocalName,
1140 : PRInt32 aContextNamespace,
1141 : bool aQuirks,
1142 : bool aPreventScriptExecution);
1143 :
1144 : /**
1145 : * Invoke the fragment parsing algorithm (innerHTML) using the XML parser.
1146 : *
1147 : * @param aSourceBuffer the string being set as innerHTML
1148 : * @param aTargetNode the target container
1149 : * @param aTagStack the namespace mapping context
1150 : * @param aPreventExecution whether to mark scripts as already started
1151 : * @param aReturn the result fragment
1152 : * @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse
1153 : * fragments is made, a return code from the XML parser.
1154 : */
1155 : static nsresult ParseFragmentXML(const nsAString& aSourceBuffer,
1156 : nsIDocument* aDocument,
1157 : nsTArray<nsString>& aTagStack,
1158 : bool aPreventScriptExecution,
1159 : nsIDOMDocumentFragment** aReturn);
1160 :
1161 : /**
1162 : * Parse a string into a document using the HTML parser.
1163 : * Script elements are marked unexecutable.
1164 : *
1165 : * @param aSourceBuffer the string to parse as an HTML document
1166 : * @param aTargetDocument the document object to parse into. Must not have
1167 : * child nodes.
1168 : * @param aScriptingEnabledForNoscriptParsing whether <noscript> is parsed
1169 : * as if scripting was enabled
1170 : * @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse
1171 : * fragments is made, NS_ERROR_OUT_OF_MEMORY if aSourceBuffer is too
1172 : * long and NS_OK otherwise.
1173 : */
1174 : static nsresult ParseDocumentHTML(const nsAString& aSourceBuffer,
1175 : nsIDocument* aTargetDocument,
1176 : bool aScriptingEnabledForNoscriptParsing);
1177 :
1178 : /**
1179 : * Converts HTML source to plain text by parsing the source and using the
1180 : * plain text serializer on the resulting tree.
1181 : *
1182 : * @param aSourceBuffer the string to parse as an HTML document
1183 : * @param aResultBuffer the string where the plain text result appears;
1184 : * may be the same string as aSourceBuffer
1185 : * @param aFlags Flags from nsIDocumentEncoder.
1186 : * @param aWrapCol Number of columns after which to line wrap; 0 for no
1187 : * auto-wrapping
1188 : * @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse
1189 : * fragments is made, NS_ERROR_OUT_OF_MEMORY if aSourceBuffer is too
1190 : * long and NS_OK otherwise.
1191 : */
1192 : static nsresult ConvertToPlainText(const nsAString& aSourceBuffer,
1193 : nsAString& aResultBuffer,
1194 : PRUint32 aFlags,
1195 : PRUint32 aWrapCol);
1196 :
1197 : /**
1198 : * Creates a new XML document, which is marked to be loaded as data.
1199 : *
1200 : * @param aNamespaceURI Namespace for the root element to create and insert in
1201 : * the document. Only used if aQualifiedName is not
1202 : * empty.
1203 : * @param aQualifiedName Qualified name for the root element to create and
1204 : * insert in the document. If empty no root element will
1205 : * be created.
1206 : * @param aDoctype Doctype node to insert in the document.
1207 : * @param aDocumentURI URI of the document. Must not be null.
1208 : * @param aBaseURI Base URI of the document. Must not be null.
1209 : * @param aPrincipal Prinicpal of the document. Must not be null.
1210 : * @param aScriptObject The object from which the context for event handling
1211 : * can be got.
1212 : * @param aFlavor Select the kind of document to create.
1213 : * @param aResult [out] The document that was created.
1214 : */
1215 : static nsresult CreateDocument(const nsAString& aNamespaceURI,
1216 : const nsAString& aQualifiedName,
1217 : nsIDOMDocumentType* aDoctype,
1218 : nsIURI* aDocumentURI,
1219 : nsIURI* aBaseURI,
1220 : nsIPrincipal* aPrincipal,
1221 : nsIScriptGlobalObject* aScriptObject,
1222 : DocumentFlavor aFlavor,
1223 : nsIDOMDocument** aResult);
1224 :
1225 : /**
1226 : * Sets the text contents of a node by replacing all existing children
1227 : * with a single text child.
1228 : *
1229 : * The function always notifies.
1230 : *
1231 : * Will reuse the first text child if one is available. Will not reuse
1232 : * existing cdata children.
1233 : *
1234 : * @param aContent Node to set contents of.
1235 : * @param aValue Value to set contents to.
1236 : * @param aTryReuse When true, the function will try to reuse an existing
1237 : * textnodes rather than always creating a new one.
1238 : */
1239 : static nsresult SetNodeTextContent(nsIContent* aContent,
1240 : const nsAString& aValue,
1241 : bool aTryReuse);
1242 :
1243 : /**
1244 : * Get the textual contents of a node. This is a concatenation of all
1245 : * textnodes that are direct or (depending on aDeep) indirect children
1246 : * of the node.
1247 : *
1248 : * NOTE! No serialization takes place and <br> elements
1249 : * are not converted into newlines. Only textnodes and cdata nodes are
1250 : * added to the result.
1251 : *
1252 : * @param aNode Node to get textual contents of.
1253 : * @param aDeep If true child elements of aNode are recursivly descended
1254 : * into to find text children.
1255 : * @param aResult the result. Out param.
1256 : */
1257 3875 : static void GetNodeTextContent(nsINode* aNode, bool aDeep,
1258 : nsAString& aResult)
1259 : {
1260 3875 : aResult.Truncate();
1261 3875 : AppendNodeTextContent(aNode, aDeep, aResult);
1262 3875 : }
1263 :
1264 : /**
1265 : * Same as GetNodeTextContents but appends the result rather than sets it.
1266 : */
1267 : static void AppendNodeTextContent(nsINode* aNode, bool aDeep,
1268 : nsAString& aResult);
1269 :
1270 : /**
1271 : * Utility method that checks if a given node has any non-empty
1272 : * children.
1273 : * NOTE! This method does not descend recursivly into elements.
1274 : * Though it would be easy to make it so if needed
1275 : */
1276 : static bool HasNonEmptyTextContent(nsINode* aNode);
1277 :
1278 : /**
1279 : * Delete strings allocated for nsContentList matches
1280 : */
1281 82 : static void DestroyMatchString(void* aData)
1282 : {
1283 82 : if (aData) {
1284 82 : nsString* matchString = static_cast<nsString*>(aData);
1285 82 : delete matchString;
1286 : }
1287 82 : }
1288 :
1289 0 : static void DropScriptObject(PRUint32 aLangID, void *aObject,
1290 : const char *name, void *aClosure)
1291 : {
1292 0 : DropScriptObject(aLangID, aObject, aClosure);
1293 0 : }
1294 :
1295 : /**
1296 : * Unbinds the content from the tree and nulls it out if it's not null.
1297 : */
1298 : static void DestroyAnonymousContent(nsCOMPtr<nsIContent>* aContent);
1299 :
1300 : /**
1301 : * Keep script object aNewObject, held by aScriptObjectHolder, alive.
1302 : *
1303 : * NOTE: This currently only supports objects that hold script objects of one
1304 : * scripting language.
1305 : *
1306 : * @param aLangID script language ID of aNewObject
1307 : * @param aScriptObjectHolder the object that holds aNewObject
1308 : * @param aTracer the tracer for aScriptObject
1309 : * @param aNewObject the script object to hold
1310 : * @param aWasHoldingObjects whether aScriptObjectHolder was already holding
1311 : * script objects (ie. HoldScriptObject was called
1312 : * on it before, without a corresponding call to
1313 : * DropScriptObjects)
1314 : */
1315 0 : static nsresult HoldScriptObject(PRUint32 aLangID, void* aScriptObjectHolder,
1316 : nsScriptObjectTracer* aTracer,
1317 : void* aNewObject, bool aWasHoldingObjects)
1318 : {
1319 0 : if (aLangID == nsIProgrammingLanguage::JAVASCRIPT) {
1320 : return aWasHoldingObjects ? NS_OK :
1321 0 : HoldJSObjects(aScriptObjectHolder, aTracer);
1322 : }
1323 :
1324 0 : return HoldScriptObject(aLangID, aNewObject);
1325 : }
1326 :
1327 : /**
1328 : * Drop any script objects that aScriptObjectHolder is holding.
1329 : *
1330 : * NOTE: This currently only supports objects that hold script objects of one
1331 : * scripting language.
1332 : *
1333 : * @param aLangID script language ID of the objects that
1334 : * @param aScriptObjectHolder the object that holds script object that we want
1335 : * to drop
1336 : * @param aTracer the tracer for aScriptObject
1337 : */
1338 0 : static nsresult DropScriptObjects(PRUint32 aLangID, void* aScriptObjectHolder,
1339 : nsScriptObjectTracer* aTracer)
1340 : {
1341 0 : if (aLangID == nsIProgrammingLanguage::JAVASCRIPT) {
1342 0 : return DropJSObjects(aScriptObjectHolder);
1343 : }
1344 :
1345 0 : aTracer->Trace(aScriptObjectHolder, DropScriptObject, nsnull);
1346 :
1347 0 : return NS_OK;
1348 : }
1349 :
1350 : /**
1351 : * Keep the JS objects held by aScriptObjectHolder alive.
1352 : *
1353 : * @param aScriptObjectHolder the object that holds JS objects that we want to
1354 : * keep alive
1355 : * @param aTracer the tracer for aScriptObject
1356 : */
1357 : static nsresult HoldJSObjects(void* aScriptObjectHolder,
1358 : nsScriptObjectTracer* aTracer);
1359 :
1360 : /**
1361 : * Drop the JS objects held by aScriptObjectHolder.
1362 : *
1363 : * @param aScriptObjectHolder the object that holds JS objects that we want to
1364 : * drop
1365 : */
1366 : static nsresult DropJSObjects(void* aScriptObjectHolder);
1367 :
1368 : #ifdef DEBUG
1369 : static void CheckCCWrapperTraversal(nsISupports* aScriptObjectHolder,
1370 : nsWrapperCache* aCache);
1371 : #endif
1372 :
1373 5 : static void PreserveWrapper(nsISupports* aScriptObjectHolder,
1374 : nsWrapperCache* aCache)
1375 : {
1376 5 : if (!aCache->PreservingWrapper()) {
1377 : nsXPCOMCycleCollectionParticipant* participant;
1378 5 : CallQueryInterface(aScriptObjectHolder, &participant);
1379 5 : HoldJSObjects(aScriptObjectHolder, participant);
1380 5 : aCache->SetPreservingWrapper(true);
1381 : #ifdef DEBUG
1382 : // Make sure the cycle collector will be able to traverse to the wrapper.
1383 5 : CheckCCWrapperTraversal(aScriptObjectHolder, aCache);
1384 : #endif
1385 : }
1386 5 : }
1387 : static void ReleaseWrapper(nsISupports* aScriptObjectHolder,
1388 : nsWrapperCache* aCache);
1389 : static void TraceWrapper(nsWrapperCache* aCache, TraceCallback aCallback,
1390 : void *aClosure);
1391 :
1392 : /*
1393 : * Notify when the first XUL menu is opened and when the all XUL menus are
1394 : * closed. At opening, aInstalling should be TRUE, otherwise, it should be
1395 : * FALSE.
1396 : */
1397 : static void NotifyInstalledMenuKeyboardListener(bool aInstalling);
1398 :
1399 : /**
1400 : * Do security checks before loading a resource. Does the following checks:
1401 : * nsIScriptSecurityManager::CheckLoadURIWithPrincipal
1402 : * NS_CheckContentLoadPolicy
1403 : * nsIScriptSecurityManager::CheckSameOriginURI
1404 : *
1405 : * You will still need to do at least SameOrigin checks before on redirects.
1406 : *
1407 : * @param aURIToLoad URI that is getting loaded.
1408 : * @param aLoadingPrincipal Principal of the resource that is initiating
1409 : * the load
1410 : * @param aCheckLoadFlags Flags to be passed to
1411 : * nsIScriptSecurityManager::CheckLoadURIWithPrincipal
1412 : * NOTE: If this contains ALLOW_CHROME the
1413 : * CheckSameOriginURI check will be skipped if
1414 : * aURIToLoad is a chrome uri.
1415 : * @param aAllowData Set to true to skip CheckSameOriginURI check when
1416 : aURIToLoad is a data uri.
1417 : * @param aContentPolicyType Type \
1418 : * @param aContext Context |- to be passed to
1419 : * @param aMimeGuess Mimetype | NS_CheckContentLoadPolicy
1420 : * @param aExtra Extra /
1421 : */
1422 : static nsresult CheckSecurityBeforeLoad(nsIURI* aURIToLoad,
1423 : nsIPrincipal* aLoadingPrincipal,
1424 : PRUint32 aCheckLoadFlags,
1425 : bool aAllowData,
1426 : PRUint32 aContentPolicyType,
1427 : nsISupports* aContext,
1428 0 : const nsACString& aMimeGuess = EmptyCString(),
1429 : nsISupports* aExtra = nsnull);
1430 :
1431 : /**
1432 : * Returns true if aPrincipal is the system principal.
1433 : */
1434 : static bool IsSystemPrincipal(nsIPrincipal* aPrincipal);
1435 :
1436 : /**
1437 : * Trigger a link with uri aLinkURI. If aClick is false, this triggers a
1438 : * mouseover on the link, otherwise it triggers a load after doing a
1439 : * security check using aContent's principal.
1440 : *
1441 : * @param aContent the node on which a link was triggered.
1442 : * @param aPresContext the pres context, must be non-null.
1443 : * @param aLinkURI the URI of the link, must be non-null.
1444 : * @param aTargetSpec the target (like target=, may be empty).
1445 : * @param aClick whether this was a click or not (if false, this method
1446 : * assumes you just hovered over the link).
1447 : * @param aIsUserTriggered whether the user triggered the link. This would be
1448 : * false for loads from auto XLinks or from the
1449 : * click() method if we ever implement it.
1450 : * @param aIsTrusted If false, JS Context will be pushed to stack
1451 : * when the link is triggered.
1452 : */
1453 : static void TriggerLink(nsIContent *aContent, nsPresContext *aPresContext,
1454 : nsIURI *aLinkURI, const nsString& aTargetSpec,
1455 : bool aClick, bool aIsUserTriggered,
1456 : bool aIsTrusted);
1457 :
1458 : /**
1459 : * Return top-level widget in the parent chain.
1460 : */
1461 : static nsIWidget* GetTopLevelWidget(nsIWidget* aWidget);
1462 :
1463 : /**
1464 : * Return the localized ellipsis for UI.
1465 : */
1466 : static const nsDependentString GetLocalizedEllipsis();
1467 :
1468 : /**
1469 : * The routine GetNativeEvent is used to fill nsNativeKeyEvent.
1470 : * It's also used in DOMEventToNativeKeyEvent.
1471 : * See bug 406407 for details.
1472 : */
1473 : static nsEvent* GetNativeEvent(nsIDOMEvent* aDOMEvent);
1474 : static bool DOMEventToNativeKeyEvent(nsIDOMKeyEvent* aKeyEvent,
1475 : nsNativeKeyEvent* aNativeEvent,
1476 : bool aGetCharCode);
1477 :
1478 : /**
1479 : * Get the candidates for accelkeys for aDOMKeyEvent.
1480 : *
1481 : * @param aDOMKeyEvent [in] the key event for accelkey handling.
1482 : * @param aCandidates [out] the candidate shortcut key combination list.
1483 : * the first item is most preferred.
1484 : */
1485 : static void GetAccelKeyCandidates(nsIDOMKeyEvent* aDOMKeyEvent,
1486 : nsTArray<nsShortcutCandidate>& aCandidates);
1487 :
1488 : /**
1489 : * Get the candidates for accesskeys for aNativeKeyEvent.
1490 : *
1491 : * @param aNativeKeyEvent [in] the key event for accesskey handling.
1492 : * @param aCandidates [out] the candidate access key list.
1493 : * the first item is most preferred.
1494 : */
1495 : static void GetAccessKeyCandidates(nsKeyEvent* aNativeKeyEvent,
1496 : nsTArray<PRUint32>& aCandidates);
1497 :
1498 : /**
1499 : * Hide any XUL popups associated with aDocument, including any documents
1500 : * displayed in child frames. Does nothing if aDocument is null.
1501 : */
1502 : static void HidePopupsInDocument(nsIDocument* aDocument);
1503 :
1504 : /**
1505 : * Retrieve the current drag session, or null if no drag is currently occuring
1506 : */
1507 : static already_AddRefed<nsIDragSession> GetDragSession();
1508 :
1509 : /*
1510 : * Initialize and set the dataTransfer field of an nsDragEvent.
1511 : */
1512 : static nsresult SetDataTransferInEvent(nsDragEvent* aDragEvent);
1513 :
1514 : // filters the drag and drop action to fit within the effects allowed and
1515 : // returns it.
1516 : static PRUint32 FilterDropEffect(PRUint32 aAction, PRUint32 aEffectAllowed);
1517 :
1518 : /**
1519 : * Return true if aURI is a local file URI (i.e. file://).
1520 : */
1521 : static bool URIIsLocalFile(nsIURI *aURI);
1522 :
1523 : /**
1524 : * Given a URI, return set beforeHash to the part before the '#', and
1525 : * afterHash to the remainder of the URI, including the '#'.
1526 : */
1527 : static nsresult SplitURIAtHash(nsIURI *aURI,
1528 : nsACString &aBeforeHash,
1529 : nsACString &aAfterHash);
1530 :
1531 : /**
1532 : * Get the application manifest URI for this document. The manifest URI
1533 : * is specified in the manifest= attribute of the root element of the
1534 : * document.
1535 : *
1536 : * @param aDocument The document that lists the manifest.
1537 : * @param aURI The manifest URI.
1538 : */
1539 : static void GetOfflineAppManifest(nsIDocument *aDocument, nsIURI **aURI);
1540 :
1541 : /**
1542 : * Check whether an application should be allowed to use offline APIs.
1543 : */
1544 : static bool OfflineAppAllowed(nsIURI *aURI);
1545 :
1546 : /**
1547 : * Check whether an application should be allowed to use offline APIs.
1548 : */
1549 : static bool OfflineAppAllowed(nsIPrincipal *aPrincipal);
1550 :
1551 : /**
1552 : * Increases the count of blockers preventing scripts from running.
1553 : * NOTE: You might want to use nsAutoScriptBlocker rather than calling
1554 : * this directly
1555 : */
1556 : static void AddScriptBlocker();
1557 :
1558 : /**
1559 : * Decreases the count of blockers preventing scripts from running.
1560 : * NOTE: You might want to use nsAutoScriptBlocker rather than calling
1561 : * this directly
1562 : *
1563 : * WARNING! Calling this function could synchronously execute scripts.
1564 : */
1565 : static void RemoveScriptBlocker();
1566 :
1567 : /**
1568 : * Add a runnable that is to be executed as soon as it's safe to execute
1569 : * scripts.
1570 : * NOTE: If it's currently safe to execute scripts, aRunnable will be run
1571 : * synchronously before the function returns.
1572 : *
1573 : * @param aRunnable The nsIRunnable to run as soon as it's safe to execute
1574 : * scripts. Passing null is allowed and results in nothing
1575 : * happening. It is also allowed to pass an object that
1576 : * has not yet been AddRefed.
1577 : * @return false on out of memory, true otherwise.
1578 : */
1579 : static bool AddScriptRunner(nsIRunnable* aRunnable);
1580 :
1581 : /**
1582 : * Returns true if it's safe to execute content script and false otherwise.
1583 : *
1584 : * The only known case where this lies is mutation events. They run, and can
1585 : * run anything else, when this function returns false, but this is ok.
1586 : */
1587 27347 : static bool IsSafeToRunScript() {
1588 27347 : return sScriptBlockerCount == 0;
1589 : }
1590 :
1591 : /**
1592 : * Retrieve information about the viewport as a data structure.
1593 : * This will return information in the viewport META data section
1594 : * of the document. This can be used in lieu of ProcessViewportInfo(),
1595 : * which places the viewport information in the document header instead
1596 : * of returning it directly.
1597 : *
1598 : * NOTE: If the site is optimized for mobile (via the doctype), this
1599 : * will return viewport information that specifies default information.
1600 : */
1601 : static ViewportInfo GetViewportInfo(nsIDocument* aDocument);
1602 :
1603 : /* Process viewport META data. This gives us information for the scale
1604 : * and zoom of a page on mobile devices. We stick the information in
1605 : * the document header and use it later on after rendering.
1606 : *
1607 : * See Bug #436083
1608 : */
1609 : static nsresult ProcessViewportInfo(nsIDocument *aDocument,
1610 : const nsAString &viewportInfo);
1611 :
1612 : static nsIScriptContext* GetContextForEventHandlers(nsINode* aNode,
1613 : nsresult* aRv);
1614 :
1615 : static JSContext *GetCurrentJSContext();
1616 :
1617 : /**
1618 : * Case insensitive comparison between two strings. However it only ignores
1619 : * case for ASCII characters a-z.
1620 : */
1621 : static bool EqualsIgnoreASCIICase(const nsAString& aStr1,
1622 : const nsAString& aStr2);
1623 :
1624 : /**
1625 : * Case insensitive comparison between a string and an ASCII literal.
1626 : * This must ONLY be applied to an actual literal string. Do not attempt
1627 : * to use it with a regular char* pointer, or with a char array variable.
1628 : * The template trick to acquire the array length at compile time without
1629 : * using a macro is due to Corey Kosak, which much thanks.
1630 : */
1631 : static bool EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
1632 : const char* aStr2,
1633 : const PRUint32 len);
1634 : #ifdef NS_DISABLE_LITERAL_TEMPLATE
1635 : static inline bool
1636 : EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
1637 : const char* aStr2)
1638 : {
1639 : PRUint32 len = strlen(aStr2);
1640 : return EqualsLiteralIgnoreASCIICase(aStr1, aStr2, len);
1641 : }
1642 : #else
1643 : template<int N>
1644 : static inline bool
1645 0 : EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
1646 : const char (&aStr2)[N])
1647 : {
1648 0 : return EqualsLiteralIgnoreASCIICase(aStr1, aStr2, N-1);
1649 : }
1650 : template<int N>
1651 : static inline bool
1652 : EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
1653 : char (&aStr2)[N])
1654 : {
1655 : const char* s = aStr2;
1656 : return EqualsLiteralIgnoreASCIICase(aStr1, s, N-1);
1657 : }
1658 : #endif
1659 :
1660 : /**
1661 : * Convert ASCII A-Z to a-z.
1662 : * @return NS_OK on success, or NS_ERROR_OUT_OF_MEMORY if making the string
1663 : * writable needs to allocate memory and that allocation fails.
1664 : */
1665 : static nsresult ASCIIToLower(nsAString& aStr);
1666 : static nsresult ASCIIToLower(const nsAString& aSource, nsAString& aDest);
1667 :
1668 : /**
1669 : * Convert ASCII a-z to A-Z.
1670 : * @return NS_OK on success, or NS_ERROR_OUT_OF_MEMORY if making the string
1671 : * writable needs to allocate memory and that allocation fails.
1672 : */
1673 : static nsresult ASCIIToUpper(nsAString& aStr);
1674 : static nsresult ASCIIToUpper(const nsAString& aSource, nsAString& aDest);
1675 :
1676 : // Returns NS_OK for same origin, error (NS_ERROR_DOM_BAD_URI) if not.
1677 : static nsresult CheckSameOrigin(nsIChannel *aOldChannel, nsIChannel *aNewChannel);
1678 : static nsIInterfaceRequestor* GetSameOriginChecker();
1679 :
1680 37853 : static nsIThreadJSContextStack* ThreadJSContextStack()
1681 : {
1682 37853 : return sThreadJSContextStack;
1683 : }
1684 :
1685 :
1686 : /**
1687 : * Get the Origin of the passed in nsIPrincipal or nsIURI. If the passed in
1688 : * nsIURI or the URI of the passed in nsIPrincipal does not have a host, the
1689 : * origin is set to 'null'.
1690 : *
1691 : * The ASCII versions return a ASCII strings that are puny-code encoded,
1692 : * suitable for, for example, header values. The UTF versions return strings
1693 : * containing international characters.
1694 : *
1695 : * @pre aPrincipal/aOrigin must not be null.
1696 : *
1697 : * @note this should be used for HTML5 origin determination.
1698 : */
1699 : static nsresult GetASCIIOrigin(nsIPrincipal* aPrincipal,
1700 : nsCString& aOrigin);
1701 : static nsresult GetASCIIOrigin(nsIURI* aURI, nsCString& aOrigin);
1702 : static nsresult GetUTFOrigin(nsIPrincipal* aPrincipal,
1703 : nsString& aOrigin);
1704 : static nsresult GetUTFOrigin(nsIURI* aURI, nsString& aOrigin);
1705 :
1706 : /**
1707 : * This method creates and dispatches "command" event, which implements
1708 : * nsIDOMXULCommandEvent.
1709 : * If aShell is not null, dispatching goes via
1710 : * nsIPresShell::HandleDOMEventWithTarget.
1711 : */
1712 : static nsresult DispatchXULCommand(nsIContent* aTarget,
1713 : bool aTrusted,
1714 : nsIDOMEvent* aSourceEvent = nsnull,
1715 : nsIPresShell* aShell = nsnull,
1716 : bool aCtrl = false,
1717 : bool aAlt = false,
1718 : bool aShift = false,
1719 : bool aMeta = false);
1720 :
1721 : /**
1722 : * Gets the nsIDocument given the script context. Will return nsnull on failure.
1723 : *
1724 : * @param aScriptContext the script context to get the document for; can be null
1725 : *
1726 : * @return the document associated with the script context
1727 : */
1728 : static already_AddRefed<nsIDocument>
1729 : GetDocumentFromScriptContext(nsIScriptContext *aScriptContext);
1730 :
1731 : static bool CheckMayLoad(nsIPrincipal* aPrincipal, nsIChannel* aChannel);
1732 :
1733 : /**
1734 : * The method checks whether the caller can access native anonymous content.
1735 : * If there is no JS in the stack or privileged JS is running, this
1736 : * method returns true, otherwise false.
1737 : */
1738 : static bool CanAccessNativeAnon();
1739 :
1740 0 : static nsresult WrapNative(JSContext *cx, JSObject *scope,
1741 : nsISupports *native, const nsIID* aIID, jsval *vp,
1742 : // If non-null aHolder will keep the jsval alive
1743 : // while there's a ref to it
1744 : nsIXPConnectJSObjectHolder** aHolder = nsnull,
1745 : bool aAllowWrapping = false)
1746 : {
1747 : return WrapNative(cx, scope, native, nsnull, aIID, vp, aHolder,
1748 0 : aAllowWrapping);
1749 : }
1750 :
1751 : // Same as the WrapNative above, but use this one if aIID is nsISupports' IID.
1752 1933 : static nsresult WrapNative(JSContext *cx, JSObject *scope,
1753 : nsISupports *native, jsval *vp,
1754 : // If non-null aHolder will keep the jsval alive
1755 : // while there's a ref to it
1756 : nsIXPConnectJSObjectHolder** aHolder = nsnull,
1757 : bool aAllowWrapping = false)
1758 : {
1759 : return WrapNative(cx, scope, native, nsnull, nsnull, vp, aHolder,
1760 1933 : aAllowWrapping);
1761 : }
1762 0 : static nsresult WrapNative(JSContext *cx, JSObject *scope,
1763 : nsISupports *native, nsWrapperCache *cache,
1764 : jsval *vp,
1765 : // If non-null aHolder will keep the jsval alive
1766 : // while there's a ref to it
1767 : nsIXPConnectJSObjectHolder** aHolder = nsnull,
1768 : bool aAllowWrapping = false)
1769 : {
1770 : return WrapNative(cx, scope, native, cache, nsnull, vp, aHolder,
1771 0 : aAllowWrapping);
1772 : }
1773 :
1774 : /**
1775 : * Creates an arraybuffer from a binary string.
1776 : */
1777 : static nsresult CreateArrayBuffer(JSContext *aCx, const nsACString& aData,
1778 : JSObject** aResult);
1779 :
1780 : static void StripNullChars(const nsAString& aInStr, nsAString& aOutStr);
1781 :
1782 : /**
1783 : * Strip all \n, \r and nulls from the given string
1784 : * @param aString the string to remove newlines from [in/out]
1785 : */
1786 : static void RemoveNewlines(nsString &aString);
1787 :
1788 : /**
1789 : * Convert Windows and Mac platform linebreaks to \n.
1790 : * @param aString the string to convert the newlines inside [in/out]
1791 : */
1792 : static void PlatformToDOMLineBreaks(nsString &aString);
1793 :
1794 0 : static bool IsHandlingKeyBoardEvent()
1795 : {
1796 0 : return sIsHandlingKeyBoardEvent;
1797 : }
1798 :
1799 0 : static void SetIsHandlingKeyBoardEvent(bool aHandling)
1800 : {
1801 0 : sIsHandlingKeyBoardEvent = aHandling;
1802 0 : }
1803 :
1804 : /**
1805 : * Utility method for getElementsByClassName. aRootNode is the node (either
1806 : * document or element), which getElementsByClassName was called on.
1807 : */
1808 : static nsresult GetElementsByClassName(nsINode* aRootNode,
1809 : const nsAString& aClasses,
1810 : nsIDOMNodeList** aReturn);
1811 :
1812 : /**
1813 : * Returns the widget for this document if there is one. Looks at all ancestor
1814 : * documents to try to find a widget, so for example this can still find a
1815 : * widget for documents in display:none frames that have no presentation.
1816 : */
1817 : static nsIWidget *WidgetForDocument(nsIDocument *aDoc);
1818 :
1819 : /**
1820 : * Returns a layer manager to use for the given document. Basically we
1821 : * look up the document hierarchy for the first document which has
1822 : * a presentation with an associated widget, and use that widget's
1823 : * layer manager.
1824 : *
1825 : * @param aDoc the document for which to return a layer manager.
1826 : * @param aAllowRetaining an outparam that states whether the returned
1827 : * layer manager should be used for retained layers
1828 : */
1829 : static already_AddRefed<mozilla::layers::LayerManager>
1830 : LayerManagerForDocument(nsIDocument *aDoc, bool *aAllowRetaining = nsnull);
1831 :
1832 : /**
1833 : * Returns a layer manager to use for the given document. Basically we
1834 : * look up the document hierarchy for the first document which has
1835 : * a presentation with an associated widget, and use that widget's
1836 : * layer manager. In addition to the normal layer manager lookup this will
1837 : * specifically request a persistent layer manager. This means that the layer
1838 : * manager is expected to remain the layer manager for the document in the
1839 : * forseeable future. This function should be used carefully as it may change
1840 : * the document's layer manager.
1841 : *
1842 : * @param aDoc the document for which to return a layer manager.
1843 : * @param aAllowRetaining an outparam that states whether the returned
1844 : * layer manager should be used for retained layers
1845 : */
1846 : static already_AddRefed<mozilla::layers::LayerManager>
1847 : PersistentLayerManagerForDocument(nsIDocument *aDoc, bool *aAllowRetaining = nsnull);
1848 :
1849 : /**
1850 : * Determine whether a content node is focused or not,
1851 : *
1852 : * @param aContent the content node to check
1853 : * @return true if the content node is focused, false otherwise.
1854 : */
1855 : static bool IsFocusedContent(const nsIContent *aContent);
1856 :
1857 : /**
1858 : * Returns true if the DOM full-screen API is enabled.
1859 : */
1860 : static bool IsFullScreenApiEnabled();
1861 :
1862 : /**
1863 : * Returns true if requests for full-screen are allowed in the current
1864 : * context. Requests are only allowed if the user initiated them (like with
1865 : * a mouse-click or key press), unless this check has been disabled by
1866 : * setting the pref "full-screen-api.allow-trusted-requests-only" to false.
1867 : */
1868 : static bool IsRequestFullScreenAllowed();
1869 :
1870 : /**
1871 : * Returns true if key input is restricted in DOM full-screen mode
1872 : * to non-alpha-numeric key codes only. This mirrors the
1873 : * "full-screen-api.key-input-restricted" pref.
1874 : */
1875 : static bool IsFullScreenKeyInputRestricted();
1876 :
1877 : /**
1878 : * Returns true if the doc tree branch which contains aDoc contains any
1879 : * plugins which we don't control event dispatch for, i.e. do any plugins
1880 : * in the same tab as this document receive key events outside of our
1881 : * control? This always returns false on MacOSX.
1882 : */
1883 : static bool HasPluginWithUncontrolledEventDispatch(nsIDocument* aDoc);
1884 :
1885 : /**
1886 : * Returns true if the content is in a document and contains a plugin
1887 : * which we don't control event dispatch for, i.e. do any plugins in this
1888 : * doc tree receive key events outside of our control? This always returns
1889 : * false on MacOSX.
1890 : */
1891 : static bool HasPluginWithUncontrolledEventDispatch(nsIContent* aContent);
1892 :
1893 : /**
1894 : * Returns the root document in a document hierarchy. Normally this will
1895 : * be the chrome document.
1896 : */
1897 : static nsIDocument* GetRootDocument(nsIDocument* aDoc);
1898 :
1899 : /**
1900 : * Returns the time limit on handling user input before
1901 : * nsEventStateManager::IsHandlingUserInput() stops returning true.
1902 : * This enables us to detect long running user-generated event handlers.
1903 : */
1904 : static TimeDuration HandlingUserInputTimeout();
1905 :
1906 : static void GetShiftText(nsAString& text);
1907 : static void GetControlText(nsAString& text);
1908 : static void GetMetaText(nsAString& text);
1909 : static void GetAltText(nsAString& text);
1910 : static void GetModifierSeparatorText(nsAString& text);
1911 :
1912 : /**
1913 : * Returns if aContent has a tabbable subdocument.
1914 : * A sub document isn't tabbable when it's a zombie document.
1915 : *
1916 : * @param aElement element to test.
1917 : *
1918 : * @return Whether the subdocument is tabbable.
1919 : */
1920 : static bool IsSubDocumentTabbable(nsIContent* aContent);
1921 :
1922 : /**
1923 : * Flushes the layout tree (recursively)
1924 : *
1925 : * @param aWindow the window the flush should start at
1926 : *
1927 : */
1928 : static void FlushLayoutForTree(nsIDOMWindow* aWindow);
1929 :
1930 : /**
1931 : * Returns true if content with the given principal is allowed to use XUL
1932 : * and XBL and false otherwise.
1933 : */
1934 : static bool AllowXULXBLForPrincipal(nsIPrincipal* aPrincipal);
1935 :
1936 : /**
1937 : * Perform cleanup that's appropriate for XPCOM shutdown.
1938 : */
1939 : static void XPCOMShutdown();
1940 :
1941 : enum ContentViewerType
1942 : {
1943 : TYPE_UNSUPPORTED,
1944 : TYPE_CONTENT,
1945 : TYPE_PLUGIN,
1946 : TYPE_UNKNOWN
1947 : };
1948 :
1949 : static already_AddRefed<nsIDocumentLoaderFactory>
1950 : FindInternalContentViewer(const char* aType,
1951 : ContentViewerType* aLoaderType = nsnull);
1952 :
1953 : /**
1954 : * This helper method returns true if the aPattern pattern matches aValue.
1955 : * aPattern should not contain leading and trailing slashes (/).
1956 : * The pattern has to match the entire value not just a subset.
1957 : * aDocument must be a valid pointer (not null).
1958 : *
1959 : * This is following the HTML5 specification:
1960 : * http://dev.w3.org/html5/spec/forms.html#attr-input-pattern
1961 : *
1962 : * WARNING: This method mutates aPattern and aValue!
1963 : *
1964 : * @param aValue the string to check.
1965 : * @param aPattern the string defining the pattern.
1966 : * @param aDocument the owner document of the element.
1967 : * @result whether the given string is matches the pattern.
1968 : */
1969 : static bool IsPatternMatching(nsAString& aValue, nsAString& aPattern,
1970 : nsIDocument* aDocument);
1971 :
1972 : /**
1973 : * Calling this adds support for
1974 : * ontouch* event handler DOM attributes.
1975 : */
1976 : static void InitializeTouchEventTable();
1977 :
1978 : /**
1979 : * Test whether the given URI always inherits a security context
1980 : * from the document it comes from.
1981 : */
1982 : static nsresult URIInheritsSecurityContext(nsIURI *aURI, bool *aResult);
1983 :
1984 : /**
1985 : * Set the given principal as the owner of the given channel, if
1986 : * needed. aURI must be the URI of aChannel. aPrincipal may be
1987 : * null. If aSetUpForAboutBlank is true, then about:blank will get
1988 : * the principal set up on it.
1989 : *
1990 : * The return value is whether the principal was set up as the owner
1991 : * of the channel.
1992 : */
1993 : static bool SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
1994 : nsIChannel* aChannel,
1995 : nsIURI* aURI,
1996 : bool aSetUpForAboutBlank);
1997 :
1998 : static nsresult Btoa(const nsAString& aBinaryData,
1999 : nsAString& aAsciiBase64String);
2000 :
2001 : static nsresult Atob(const nsAString& aAsciiString,
2002 : nsAString& aBinaryData);
2003 :
2004 : /**
2005 : * Returns whether the input element passed in parameter has the autocomplete
2006 : * functionnality enabled. It is taking into account the form owner.
2007 : * NOTE: the caller has to make sure autocomplete makes sense for the
2008 : * element's type.
2009 : *
2010 : * @param aInput the input element to check. NOTE: aInput can't be null.
2011 : * @return whether the input element has autocomplete enabled.
2012 : */
2013 : static bool IsAutocompleteEnabled(nsIDOMHTMLInputElement* aInput);
2014 :
2015 : /**
2016 : * If the URI is chrome, return true unconditionarlly.
2017 : *
2018 : * Otherwise, get the contents of the given pref, and treat it as a
2019 : * comma-separated list of URIs. Return true if the given URI's prepath is
2020 : * in the list, and false otherwise.
2021 : *
2022 : * Comparisons are case-insensitive, and whitespace between elements of the
2023 : * comma-separated list is ignored.
2024 : */
2025 : static bool URIIsChromeOrInPref(nsIURI *aURI, const char *aPref);
2026 :
2027 : /**
2028 : * This will parse aSource, to extract the value of the pseudo attribute
2029 : * with the name specified in aName. See
2030 : * http://www.w3.org/TR/xml-stylesheet/#NT-StyleSheetPI for the specification
2031 : * which is used to parse aSource.
2032 : *
2033 : * @param aSource the string to parse
2034 : * @param aName the name of the attribute to get the value for
2035 : * @param aValue [out] the value for the attribute with name specified in
2036 : * aAttribute. Empty if the attribute isn't present.
2037 : * @return true if the attribute exists and was successfully parsed.
2038 : * false if the attribute doesn't exist, or has a malformed
2039 : * value, such as an unknown or unterminated entity.
2040 : */
2041 : static bool GetPseudoAttributeValue(const nsString& aSource, nsIAtom *aName,
2042 : nsAString& aValue);
2043 :
2044 : /**
2045 : * Returns true if the language name is a version of JavaScript and
2046 : * false otherwise
2047 : */
2048 : static bool IsJavaScriptLanguage(const nsString& aName, PRUint32 *aVerFlags);
2049 :
2050 : static void SplitMimeType(const nsAString& aValue, nsString& aType,
2051 : nsString& aParams);
2052 :
2053 : private:
2054 : static bool InitializeEventTable();
2055 :
2056 : static nsresult EnsureStringBundle(PropertiesFile aFile);
2057 :
2058 : static nsIDOMScriptObjectFactory *GetDOMScriptObjectFactory();
2059 :
2060 : static nsresult HoldScriptObject(PRUint32 aLangID, void* aObject);
2061 : static void DropScriptObject(PRUint32 aLangID, void *aObject, void *aClosure);
2062 :
2063 : static bool CanCallerAccess(nsIPrincipal* aSubjectPrincipal,
2064 : nsIPrincipal* aPrincipal);
2065 :
2066 : static nsresult WrapNative(JSContext *cx, JSObject *scope,
2067 : nsISupports *native, nsWrapperCache *cache,
2068 : const nsIID* aIID, jsval *vp,
2069 : nsIXPConnectJSObjectHolder** aHolder,
2070 : bool aAllowWrapping);
2071 :
2072 : static nsresult DispatchEvent(nsIDocument* aDoc,
2073 : nsISupports* aTarget,
2074 : const nsAString& aEventName,
2075 : bool aCanBubble,
2076 : bool aCancelable,
2077 : bool aTrusted,
2078 : bool *aDefaultAction = nsnull);
2079 :
2080 : static void InitializeModifierStrings();
2081 :
2082 : static void DropFragmentParsers();
2083 :
2084 : static nsIDOMScriptObjectFactory *sDOMScriptObjectFactory;
2085 :
2086 : static nsIXPConnect *sXPConnect;
2087 :
2088 : static nsIScriptSecurityManager *sSecurityManager;
2089 :
2090 : static nsIThreadJSContextStack *sThreadJSContextStack;
2091 :
2092 : static nsIParserService *sParserService;
2093 :
2094 : static nsINameSpaceManager *sNameSpaceManager;
2095 :
2096 : static nsIIOService *sIOService;
2097 :
2098 : #ifdef MOZ_XTF
2099 : static nsIXTFService *sXTFService;
2100 : #endif
2101 :
2102 : static bool sImgLoaderInitialized;
2103 : static void InitImgLoader();
2104 :
2105 : // The following two members are initialized lazily
2106 : static imgILoader* sImgLoader;
2107 : static imgICache* sImgCache;
2108 :
2109 : static nsIConsoleService* sConsoleService;
2110 :
2111 : static nsDataHashtable<nsISupportsHashKey, EventNameMapping>* sAtomEventTable;
2112 : static nsDataHashtable<nsStringHashKey, EventNameMapping>* sStringEventTable;
2113 : static nsCOMArray<nsIAtom>* sUserDefinedEvents;
2114 :
2115 : static nsIStringBundleService* sStringBundleService;
2116 : static nsIStringBundle* sStringBundles[PropertiesFile_COUNT];
2117 :
2118 : static nsIContentPolicy* sContentPolicyService;
2119 : static bool sTriedToGetContentPolicy;
2120 :
2121 : static nsILineBreaker* sLineBreaker;
2122 : static nsIWordBreaker* sWordBreaker;
2123 :
2124 : static nsIScriptRuntime* sScriptRuntimes[NS_STID_ARRAY_UBOUND];
2125 : static PRInt32 sScriptRootCount[NS_STID_ARRAY_UBOUND];
2126 : static PRUint32 sJSGCThingRootCount;
2127 :
2128 : #ifdef IBMBIDI
2129 : static nsIBidiKeyboard* sBidiKeyboard;
2130 : #endif
2131 :
2132 : static bool sInitialized;
2133 : static PRUint32 sScriptBlockerCount;
2134 : #ifdef DEBUG
2135 : static PRUint32 sDOMNodeRemovedSuppressCount;
2136 : #endif
2137 : // Not an nsCOMArray because removing elements from those is slower
2138 : static nsTArray< nsCOMPtr<nsIRunnable> >* sBlockedScriptRunners;
2139 : static PRUint32 sRunnersCountAtFirstBlocker;
2140 : static PRUint32 sScriptBlockerCountWhereRunnersPrevented;
2141 :
2142 : static nsIInterfaceRequestor* sSameOriginChecker;
2143 :
2144 : static bool sIsHandlingKeyBoardEvent;
2145 : static bool sAllowXULXBL_for_file;
2146 : static bool sIsFullScreenApiEnabled;
2147 : static bool sTrustedFullScreenOnly;
2148 : static bool sFullScreenKeyInputRestricted;
2149 : static PRUint32 sHandlingInputTimeout;
2150 :
2151 : static nsHtml5StringParser* sHTMLFragmentParser;
2152 : static nsIParser* sXMLFragmentParser;
2153 : static nsIFragmentContentSink* sXMLFragmentSink;
2154 :
2155 : /**
2156 : * True if there's a fragment parser activation on the stack.
2157 : */
2158 : static bool sFragmentParsingActive;
2159 :
2160 : static nsString* sShiftText;
2161 : static nsString* sControlText;
2162 : static nsString* sMetaText;
2163 : static nsString* sAltText;
2164 : static nsString* sModifierSeparator;
2165 : };
2166 :
2167 : typedef nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>
2168 : HTMLSplitOnSpacesTokenizer;
2169 :
2170 : #define NS_HOLD_JS_OBJECTS(obj, clazz) \
2171 : nsContentUtils::HoldJSObjects(NS_CYCLE_COLLECTION_UPCAST(obj, clazz), \
2172 : &NS_CYCLE_COLLECTION_NAME(clazz))
2173 :
2174 : #define NS_DROP_JS_OBJECTS(obj, clazz) \
2175 : nsContentUtils::DropJSObjects(NS_CYCLE_COLLECTION_UPCAST(obj, clazz))
2176 :
2177 :
2178 : class NS_STACK_CLASS nsCxPusher
2179 : {
2180 : public:
2181 : nsCxPusher();
2182 : ~nsCxPusher(); // Calls Pop();
2183 :
2184 : // Returns false if something erroneous happened.
2185 : bool Push(nsIDOMEventTarget *aCurrentTarget);
2186 : // If nothing has been pushed to stack, this works like Push.
2187 : // Otherwise if context will change, Pop and Push will be called.
2188 : bool RePush(nsIDOMEventTarget *aCurrentTarget);
2189 : // If a null JSContext is passed to Push(), that will cause no
2190 : // push to happen and false to be returned.
2191 : bool Push(JSContext *cx, bool aRequiresScriptContext = true);
2192 : // Explicitly push a null JSContext on the the stack
2193 : bool PushNull();
2194 :
2195 : // Pop() will be a no-op if Push() or PushNull() fail
2196 : void Pop();
2197 :
2198 0 : nsIScriptContext* GetCurrentScriptContext() { return mScx; }
2199 : private:
2200 : // Combined code for PushNull() and Push(JSContext*)
2201 : bool DoPush(JSContext* cx);
2202 :
2203 : nsCOMPtr<nsIScriptContext> mScx;
2204 : bool mScriptIsRunning;
2205 : bool mPushedSomething;
2206 : #ifdef DEBUG
2207 : JSContext* mPushedContext;
2208 : #endif
2209 : };
2210 :
2211 : class NS_STACK_CLASS nsAutoScriptBlocker {
2212 : public:
2213 81714 : nsAutoScriptBlocker(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) {
2214 81714 : MOZ_GUARD_OBJECT_NOTIFIER_INIT;
2215 81714 : nsContentUtils::AddScriptBlocker();
2216 81714 : }
2217 163428 : ~nsAutoScriptBlocker() {
2218 81714 : nsContentUtils::RemoveScriptBlocker();
2219 81714 : }
2220 : private:
2221 : MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
2222 : };
2223 :
2224 : class NS_STACK_CLASS nsAutoScriptBlockerSuppressNodeRemoved :
2225 : public nsAutoScriptBlocker {
2226 : public:
2227 0 : nsAutoScriptBlockerSuppressNodeRemoved() {
2228 : #ifdef DEBUG
2229 0 : ++nsContentUtils::sDOMNodeRemovedSuppressCount;
2230 : #endif
2231 0 : }
2232 0 : ~nsAutoScriptBlockerSuppressNodeRemoved() {
2233 : #ifdef DEBUG
2234 0 : --nsContentUtils::sDOMNodeRemovedSuppressCount;
2235 : #endif
2236 0 : }
2237 : };
2238 :
2239 : #define NS_INTERFACE_MAP_ENTRY_TEAROFF(_interface, _allocator) \
2240 : if (aIID.Equals(NS_GET_IID(_interface))) { \
2241 : foundInterface = static_cast<_interface *>(_allocator); \
2242 : if (!foundInterface) { \
2243 : *aInstancePtr = nsnull; \
2244 : return NS_ERROR_OUT_OF_MEMORY; \
2245 : } \
2246 : } else
2247 :
2248 : /**
2249 : * Macros to workaround math-bugs bugs in various platforms
2250 : */
2251 :
2252 : /**
2253 : * Stefan Hanske <sh990154@mail.uni-greifswald.de> reports:
2254 : * ARM is a little endian architecture but 64 bit double words are stored
2255 : * differently: the 32 bit words are in little endian byte order, the two words
2256 : * are stored in big endian`s way.
2257 : */
2258 :
2259 : #if defined(__arm) || defined(__arm32__) || defined(__arm26__) || defined(__arm__)
2260 : #if !defined(__VFP_FP__)
2261 : #define FPU_IS_ARM_FPA
2262 : #endif
2263 : #endif
2264 :
2265 : typedef union dpun {
2266 : struct {
2267 : #if defined(IS_LITTLE_ENDIAN) && !defined(FPU_IS_ARM_FPA)
2268 : PRUint32 lo, hi;
2269 : #else
2270 : PRUint32 hi, lo;
2271 : #endif
2272 : } s;
2273 : PRFloat64 d;
2274 : public:
2275 42 : operator double() const {
2276 42 : return d;
2277 : }
2278 : } dpun;
2279 :
2280 : /**
2281 : * Utility class for doubles
2282 : */
2283 : #if (__GNUC__ == 2 && __GNUC_MINOR__ > 95) || __GNUC__ > 2
2284 : /**
2285 : * This version of the macros is safe for the alias optimizations
2286 : * that gcc does, but uses gcc-specific extensions.
2287 : */
2288 : #define DOUBLE_HI32(x) (__extension__ ({ dpun u; u.d = (x); u.s.hi; }))
2289 : #define DOUBLE_LO32(x) (__extension__ ({ dpun u; u.d = (x); u.s.lo; }))
2290 :
2291 : #else // __GNUC__
2292 :
2293 : /* We don't know of any non-gcc compilers that perform alias optimization,
2294 : * so this code should work.
2295 : */
2296 :
2297 : #if defined(IS_LITTLE_ENDIAN) && !defined(FPU_IS_ARM_FPA)
2298 : #define DOUBLE_HI32(x) (((PRUint32 *)&(x))[1])
2299 : #define DOUBLE_LO32(x) (((PRUint32 *)&(x))[0])
2300 : #else
2301 : #define DOUBLE_HI32(x) (((PRUint32 *)&(x))[0])
2302 : #define DOUBLE_LO32(x) (((PRUint32 *)&(x))[1])
2303 : #endif
2304 :
2305 : #endif // __GNUC__
2306 :
2307 : #define DOUBLE_HI32_SIGNBIT 0x80000000
2308 : #define DOUBLE_HI32_EXPMASK 0x7ff00000
2309 : #define DOUBLE_HI32_MANTMASK 0x000fffff
2310 :
2311 : #define DOUBLE_IS_NaN(x) \
2312 : ((DOUBLE_HI32(x) & DOUBLE_HI32_EXPMASK) == DOUBLE_HI32_EXPMASK && \
2313 : (DOUBLE_LO32(x) || (DOUBLE_HI32(x) & DOUBLE_HI32_MANTMASK)))
2314 :
2315 : #ifdef IS_BIG_ENDIAN
2316 : #define DOUBLE_NaN {{DOUBLE_HI32_EXPMASK | DOUBLE_HI32_MANTMASK, \
2317 : 0xffffffff}}
2318 : #else
2319 : #define DOUBLE_NaN {{0xffffffff, \
2320 : DOUBLE_HI32_EXPMASK | DOUBLE_HI32_MANTMASK}}
2321 : #endif
2322 :
2323 : /*
2324 : * In the following helper macros we exploit the fact that the result of a
2325 : * series of additions will not be finite if any one of the operands in the
2326 : * series is not finite.
2327 : */
2328 : #define NS_ENSURE_FINITE(f, rv) \
2329 : if (!NS_finite(f)) { \
2330 : return (rv); \
2331 : }
2332 :
2333 : #define NS_ENSURE_FINITE2(f1, f2, rv) \
2334 : if (!NS_finite((f1)+(f2))) { \
2335 : return (rv); \
2336 : }
2337 :
2338 : #define NS_ENSURE_FINITE3(f1, f2, f3, rv) \
2339 : if (!NS_finite((f1)+(f2)+(f3))) { \
2340 : return (rv); \
2341 : }
2342 :
2343 : #define NS_ENSURE_FINITE4(f1, f2, f3, f4, rv) \
2344 : if (!NS_finite((f1)+(f2)+(f3)+(f4))) { \
2345 : return (rv); \
2346 : }
2347 :
2348 : #define NS_ENSURE_FINITE5(f1, f2, f3, f4, f5, rv) \
2349 : if (!NS_finite((f1)+(f2)+(f3)+(f4)+(f5))) { \
2350 : return (rv); \
2351 : }
2352 :
2353 : #define NS_ENSURE_FINITE6(f1, f2, f3, f4, f5, f6, rv) \
2354 : if (!NS_finite((f1)+(f2)+(f3)+(f4)+(f5)+(f6))) { \
2355 : return (rv); \
2356 : }
2357 :
2358 : // Deletes a linked list iteratively to avoid blowing up the stack (bug 460444).
2359 : #define NS_CONTENT_DELETE_LIST_MEMBER(type_, ptr_, member_) \
2360 : { \
2361 : type_ *cur = (ptr_)->member_; \
2362 : (ptr_)->member_ = nsnull; \
2363 : while (cur) { \
2364 : type_ *next = cur->member_; \
2365 : cur->member_ = nsnull; \
2366 : delete cur; \
2367 : cur = next; \
2368 : } \
2369 : }
2370 :
2371 : class nsContentTypeParser {
2372 : public:
2373 : nsContentTypeParser(const nsAString& aString);
2374 : ~nsContentTypeParser();
2375 :
2376 : nsresult GetParameter(const char* aParameterName, nsAString& aResult);
2377 0 : nsresult GetType(nsAString& aResult)
2378 : {
2379 0 : return GetParameter(nsnull, aResult);
2380 : }
2381 :
2382 : private:
2383 : NS_ConvertUTF16toUTF8 mString;
2384 : nsIMIMEHeaderParam* mService;
2385 : };
2386 :
2387 : class nsDocElementCreatedNotificationRunner : public nsRunnable
2388 936 : {
2389 : public:
2390 234 : nsDocElementCreatedNotificationRunner(nsIDocument* aDoc)
2391 234 : : mDoc(aDoc)
2392 : {
2393 234 : }
2394 :
2395 234 : NS_IMETHOD Run()
2396 : {
2397 234 : nsContentSink::NotifyDocElementCreated(mDoc);
2398 234 : return NS_OK;
2399 : }
2400 :
2401 : nsCOMPtr<nsIDocument> mDoc;
2402 : };
2403 :
2404 : #endif /* nsContentUtils_h___ */
|