2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* A namespace class for static content utilities. */
|
|
|
|
|
|
|
|
#ifndef nsContentUtils_h___
|
|
|
|
#define nsContentUtils_h___
|
|
|
|
|
2010-03-01 13:30:23 -08:00
|
|
|
#include <math.h>
|
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
#include <float.h>
|
|
|
|
#endif
|
|
|
|
|
2010-03-29 23:29:59 -07:00
|
|
|
#if defined(SOLARIS)
|
|
|
|
#include <ieeefp.h>
|
|
|
|
#endif
|
|
|
|
|
2011-05-19 12:35:46 -07:00
|
|
|
//A trick to handle IEEE floating point exceptions on FreeBSD - E.D.
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include <ieeefp.h>
|
|
|
|
#ifdef __alpha__
|
|
|
|
static fp_except_t allmask = FP_X_INV|FP_X_OFL|FP_X_UFL|FP_X_DZ|FP_X_IMP;
|
|
|
|
#else
|
|
|
|
static fp_except_t allmask = FP_X_INV|FP_X_OFL|FP_X_UFL|FP_X_DZ|FP_X_IMP|FP_X_DNML;
|
|
|
|
#endif
|
|
|
|
static fp_except_t oldmask = fpsetmask(~allmask);
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsIStatefulFrame.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
2012-07-20 09:42:08 -07:00
|
|
|
#include "nsIXPCScriptable.h"
|
2007-04-02 10:17:36 -07:00
|
|
|
#include "nsDataHashtable.h"
|
2007-12-17 21:41:56 -08:00
|
|
|
#include "nsIDOMEvent.h"
|
2008-04-14 21:16:24 -07:00
|
|
|
#include "nsTArray.h"
|
2008-12-16 18:11:07 -08:00
|
|
|
#include "nsReadableUtils.h"
|
2010-04-19 08:40:17 -07:00
|
|
|
#include "nsINode.h"
|
2011-07-20 12:18:54 -07:00
|
|
|
#include "nsIDOMNode.h"
|
2012-01-20 03:16:27 -08:00
|
|
|
#include "nsHtml5StringParser.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsContentSink.h"
|
2011-08-01 10:43:23 -07:00
|
|
|
#include "nsMathUtils.h"
|
2012-01-20 03:16:27 -08:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsIContent.h"
|
2012-01-04 02:08:00 -08:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2011-11-15 23:50:19 -08:00
|
|
|
|
|
|
|
#include "mozilla/AutoRestore.h"
|
|
|
|
#include "mozilla/GuardObjects.h"
|
2011-09-06 13:14:59 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2007-12-17 21:41:56 -08:00
|
|
|
|
|
|
|
struct nsNativeKeyEvent; // Don't include nsINativeKeyBindings.h here: it will force strange compilation error!
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIDOMScriptObjectFactory;
|
|
|
|
class nsIXPConnect;
|
|
|
|
class nsIContent;
|
2008-09-15 18:37:13 -07:00
|
|
|
class nsIDOMKeyEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIDocument;
|
2009-10-29 18:48:38 -07:00
|
|
|
class nsIDocumentObserver;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIDocShell;
|
|
|
|
class nsINameSpaceManager;
|
2012-07-01 16:45:59 -07:00
|
|
|
class nsIFragmentContentSink;
|
|
|
|
class nsIScriptGlobalObject;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIScriptSecurityManager;
|
2012-07-01 16:45:59 -07:00
|
|
|
class nsTextFragment;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIJSContextStack;
|
|
|
|
class nsIThreadJSContextStack;
|
2012-07-01 16:45:59 -07:00
|
|
|
class nsIParser;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIParserService;
|
|
|
|
class nsIIOService;
|
|
|
|
class nsIURI;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
class imgIContainer;
|
2007-03-22 10:30:00 -07:00
|
|
|
class imgIDecoderObserver;
|
|
|
|
class imgIRequest;
|
|
|
|
class imgILoader;
|
2009-07-07 22:23:20 -07:00
|
|
|
class imgICache;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIImageLoadingContent;
|
|
|
|
class nsIDOMHTMLFormElement;
|
|
|
|
class nsIDOMDocument;
|
|
|
|
class nsIConsoleService;
|
|
|
|
class nsIStringBundleService;
|
|
|
|
class nsIStringBundle;
|
|
|
|
class nsIContentPolicy;
|
|
|
|
class nsILineBreaker;
|
|
|
|
class nsIWordBreaker;
|
|
|
|
class nsIJSRuntimeService;
|
2011-06-23 19:18:01 -07:00
|
|
|
class nsEventListenerManager;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIScriptContext;
|
2008-03-14 16:08:57 -07:00
|
|
|
class nsIRunnable;
|
2008-09-07 18:13:02 -07:00
|
|
|
class nsIInterfaceRequestor;
|
2012-07-01 16:45:59 -07:00
|
|
|
class nsINodeInfo;
|
2007-03-22 10:30:00 -07:00
|
|
|
template<class E> class nsCOMArray;
|
2010-07-31 10:17:49 -07:00
|
|
|
template<class K, class V> class nsRefPtrHashtable;
|
2007-03-22 10:30:00 -07:00
|
|
|
struct JSRuntime;
|
2007-11-16 00:21:44 -08:00
|
|
|
class nsIWidget;
|
2008-08-27 05:07:27 -07:00
|
|
|
class nsIDragSession;
|
2009-06-30 00:56:40 -07:00
|
|
|
class nsIPresShell;
|
2009-08-14 12:00:24 -07:00
|
|
|
class nsIXPConnectJSObjectHolder;
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_XTF
|
|
|
|
class nsIXTFService;
|
|
|
|
#endif
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
class nsIBidiKeyboard;
|
|
|
|
#endif
|
2008-12-16 18:11:07 -08:00
|
|
|
class nsIMIMEHeaderParam;
|
2010-02-24 11:14:14 -08:00
|
|
|
class nsIObserver;
|
2010-04-10 13:10:12 -07:00
|
|
|
class nsPresContext;
|
2010-06-17 04:27:52 -07:00
|
|
|
class nsIChannel;
|
2011-05-09 12:33:04 -07:00
|
|
|
class nsAutoScriptBlockerSuppressNodeRemoved;
|
2010-07-08 09:01:28 -07:00
|
|
|
struct nsIntMargin;
|
2010-09-09 11:18:23 -07:00
|
|
|
class nsPIDOMWindow;
|
2011-04-14 13:58:36 -07:00
|
|
|
class nsIDocumentLoaderFactory;
|
2011-11-20 10:02:47 -08:00
|
|
|
class nsIDOMHTMLInputElement;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-11-09 10:00:53 -08:00
|
|
|
namespace mozilla {
|
2010-04-30 06:12:05 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
class Selection;
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
namespace layers {
|
|
|
|
class LayerManager;
|
|
|
|
} // namespace layers
|
|
|
|
|
2010-04-30 06:12:05 -07:00
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
} // namespace dom
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2010-04-30 06:12:05 -07:00
|
|
|
} // namespace mozilla
|
2009-11-09 10:00:53 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char kLoadAsData[];
|
|
|
|
|
2007-04-02 10:17:36 -07:00
|
|
|
enum EventNameType {
|
|
|
|
EventNameType_None = 0x0000,
|
|
|
|
EventNameType_HTML = 0x0001,
|
|
|
|
EventNameType_XUL = 0x0002,
|
|
|
|
EventNameType_SVGGraphic = 0x0004, // svg graphic elements
|
|
|
|
EventNameType_SVGSVG = 0x0008, // the svg element
|
2010-07-31 00:02:52 -07:00
|
|
|
EventNameType_SMIL = 0x0016, // smil elements
|
2007-04-02 10:17:36 -07:00
|
|
|
|
|
|
|
EventNameType_HTMLXUL = 0x0003,
|
|
|
|
EventNameType_All = 0xFFFF
|
|
|
|
};
|
|
|
|
|
2012-01-30 14:52:11 -08:00
|
|
|
/**
|
|
|
|
* Information retrieved from the <meta name="viewport"> tag. See
|
|
|
|
* GetViewportInfo for more information on this functionality.
|
|
|
|
*/
|
|
|
|
struct ViewportInfo
|
|
|
|
{
|
|
|
|
// Default zoom indicates the level at which the display is 'zoomed in'
|
|
|
|
// initially for the user, upon loading of the page.
|
|
|
|
double defaultZoom;
|
|
|
|
|
|
|
|
// The minimum zoom level permitted by the page.
|
|
|
|
double minZoom;
|
|
|
|
|
|
|
|
// The maximum zoom level permitted by the page.
|
|
|
|
double maxZoom;
|
|
|
|
|
|
|
|
// The width of the viewport, specified by the <meta name="viewport"> tag,
|
|
|
|
// in CSS pixels.
|
|
|
|
PRUint32 width;
|
|
|
|
|
|
|
|
// The height of the viewport, specified by the <meta name="viewport"> tag,
|
|
|
|
// in CSS pixels.
|
|
|
|
PRUint32 height;
|
|
|
|
|
|
|
|
// Whether or not we should automatically size the viewport to the device's
|
|
|
|
// width. This is true if the document has been optimized for mobile, and
|
|
|
|
// the width property of a specified <meta name="viewport"> tag is either
|
|
|
|
// not specified, or is set to the special value 'device-width'.
|
|
|
|
bool autoSize;
|
|
|
|
|
|
|
|
// Whether or not the user can zoom in and out on the page. Default is true.
|
|
|
|
bool allowZoom;
|
|
|
|
|
|
|
|
// This is a holdover from e10s fennec, and might be removed in the future.
|
|
|
|
// It's a hack to work around bugs that didn't allow zooming of documents
|
|
|
|
// from within the parent process. It is still used in native Fennec for XUL
|
|
|
|
// documents, but it should probably be removed.
|
|
|
|
// Currently, from, within GetViewportInfo(), This is only set to false
|
|
|
|
// if the document is a XUL document.
|
|
|
|
bool autoScale;
|
|
|
|
};
|
|
|
|
|
2010-06-22 11:12:12 -07:00
|
|
|
struct EventNameMapping
|
|
|
|
{
|
|
|
|
nsIAtom* mAtom;
|
|
|
|
PRUint32 mId;
|
|
|
|
PRInt32 mType;
|
|
|
|
PRUint32 mStructType;
|
2007-04-02 10:17:36 -07:00
|
|
|
};
|
|
|
|
|
2008-04-14 21:16:24 -07:00
|
|
|
struct nsShortcutCandidate {
|
2011-09-28 23:19:26 -07:00
|
|
|
nsShortcutCandidate(PRUint32 aCharCode, bool aIgnoreShift) :
|
2008-04-14 21:16:24 -07:00
|
|
|
mCharCode(aCharCode), mIgnoreShift(aIgnoreShift)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
PRUint32 mCharCode;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIgnoreShift;
|
2008-04-14 21:16:24 -07:00
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsContentUtils
|
|
|
|
{
|
2011-05-09 12:33:04 -07:00
|
|
|
friend class nsAutoScriptBlockerSuppressNodeRemoved;
|
2010-05-14 10:04:51 -07:00
|
|
|
typedef mozilla::dom::Element Element;
|
2011-09-06 13:14:59 -07:00
|
|
|
typedef mozilla::TimeDuration TimeDuration;
|
2010-05-14 10:04:51 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
static nsresult Init();
|
|
|
|
|
2011-04-24 19:30:54 -07:00
|
|
|
/**
|
|
|
|
* Get a JSContext from the document's scope object.
|
|
|
|
*/
|
|
|
|
static JSContext* GetContextFromDocument(nsIDocument *aDocument);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* When a document's scope changes (e.g., from document.open(), call this
|
|
|
|
* function to move all content wrappers from the old scope to the new one.
|
|
|
|
*/
|
2011-05-19 13:05:46 -07:00
|
|
|
static nsresult ReparentContentWrappersInScope(JSContext *cx,
|
|
|
|
nsIScriptGlobalObject *aOldScope,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIScriptGlobalObject *aNewScope);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsCallerChrome();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsCallerTrustedForRead();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsCallerTrustedForWrite();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-14 22:16:06 -08:00
|
|
|
/**
|
2011-12-30 09:35:39 -08:00
|
|
|
* Check whether a caller has UniversalXPConnect.
|
2007-11-14 22:16:06 -08:00
|
|
|
*/
|
2011-12-30 09:35:39 -08:00
|
|
|
static bool CallerHasUniversalXPConnect();
|
2007-11-14 22:16:06 -08:00
|
|
|
|
2011-10-29 01:18:25 -07:00
|
|
|
static bool IsImageSrcSetDisabled();
|
|
|
|
|
2010-07-16 05:50:28 -07:00
|
|
|
/**
|
|
|
|
* Returns the parent node of aChild crossing document boundaries.
|
|
|
|
*/
|
|
|
|
static nsINode* GetCrossDocParentNode(nsINode* aChild);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Do not ever pass null pointers to this method. If one of your
|
|
|
|
* nsIContents is null, you have to decide for yourself what
|
|
|
|
* "IsDescendantOf" really means.
|
|
|
|
*
|
|
|
|
* @param aPossibleDescendant node to test for being a descendant of
|
|
|
|
* aPossibleAncestor
|
|
|
|
* @param aPossibleAncestor node to test for being an ancestor of
|
|
|
|
* aPossibleDescendant
|
2011-10-17 07:59:28 -07:00
|
|
|
* @return true if aPossibleDescendant is a descendant of
|
|
|
|
* aPossibleAncestor (or is aPossibleAncestor). false
|
2007-03-22 10:30:00 -07:00
|
|
|
* otherwise.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool ContentIsDescendantOf(const nsINode* aPossibleDescendant,
|
2010-05-10 18:12:34 -07:00
|
|
|
const nsINode* aPossibleAncestor);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-27 08:51:41 -07:00
|
|
|
/**
|
|
|
|
* Similar to ContentIsDescendantOf except it crosses document boundaries.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool ContentIsCrossDocDescendantOf(nsINode* aPossibleDescendant,
|
2009-08-27 08:51:41 -07:00
|
|
|
nsINode* aPossibleAncestor);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* This method fills the |aArray| with all ancestor nodes of |aNode|
|
|
|
|
* including |aNode| at the zero index.
|
|
|
|
*/
|
2010-04-30 04:15:09 -07:00
|
|
|
static nsresult GetAncestors(nsINode* aNode,
|
|
|
|
nsTArray<nsINode*>& aArray);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This method fills |aAncestorNodes| with all ancestor nodes of |aNode|
|
|
|
|
* including |aNode| (QI'd to nsIContent) at the zero index.
|
|
|
|
* For each ancestor, there is a corresponding element in |aAncestorOffsets|
|
|
|
|
* which is the IndexOf the child in relation to its parent.
|
|
|
|
*
|
|
|
|
* This method just sucks.
|
|
|
|
*/
|
|
|
|
static nsresult GetAncestorsAndOffsets(nsIDOMNode* aNode,
|
|
|
|
PRInt32 aOffset,
|
2009-03-20 01:15:35 -07:00
|
|
|
nsTArray<nsIContent*>* aAncestorNodes,
|
|
|
|
nsTArray<PRInt32>* aAncestorOffsets);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The out parameter, |aCommonAncestor| will be the closest node, if any,
|
|
|
|
* to both |aNode| and |aOther| which is also an ancestor of each.
|
|
|
|
* Returns an error if the two nodes are disconnected and don't have
|
|
|
|
* a common ancestor.
|
|
|
|
*/
|
|
|
|
static nsresult GetCommonAncestor(nsIDOMNode *aNode,
|
|
|
|
nsIDOMNode *aOther,
|
|
|
|
nsIDOMNode** aCommonAncestor);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the common ancestor, if any, for two nodes. Returns null if the
|
|
|
|
* nodes are disconnected.
|
|
|
|
*/
|
|
|
|
static nsINode* GetCommonAncestor(nsINode* aNode1,
|
|
|
|
nsINode* aNode2);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if aNode1 is before aNode2 in the same connected
|
|
|
|
* tree.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool PositionIsBefore(nsINode* aNode1,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsINode* aNode2)
|
|
|
|
{
|
2011-06-14 00:56:48 -07:00
|
|
|
return (aNode2->CompareDocPosition(aNode1) &
|
|
|
|
(nsIDOMNode::DOCUMENT_POSITION_PRECEDING |
|
|
|
|
nsIDOMNode::DOCUMENT_POSITION_DISCONNECTED)) ==
|
|
|
|
nsIDOMNode::DOCUMENT_POSITION_PRECEDING;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility routine to compare two "points", where a point is a
|
|
|
|
* node/offset pair
|
|
|
|
* Returns -1 if point1 < point2, 1, if point1 > point2,
|
|
|
|
* 0 if error or if point1 == point2.
|
2008-02-24 04:46:09 -08:00
|
|
|
* NOTE! If the two nodes aren't in the same connected subtree,
|
2010-10-18 20:24:39 -07:00
|
|
|
* the result is 1, and the optional aDisconnected parameter
|
2011-10-17 07:59:28 -07:00
|
|
|
* is set to true.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
static PRInt32 ComparePoints(nsINode* aParent1, PRInt32 aOffset1,
|
2008-02-24 04:46:09 -08:00
|
|
|
nsINode* aParent2, PRInt32 aOffset2,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aDisconnected = nsnull);
|
2012-01-28 07:42:14 -08:00
|
|
|
static PRInt32 ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1,
|
|
|
|
nsIDOMNode* aParent2, PRInt32 aOffset2,
|
|
|
|
bool* aDisconnected = nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Brute-force search of the element subtree rooted at aContent for
|
|
|
|
* an element with the given id. aId must be nonempty, otherwise
|
|
|
|
* this method may return nodes even if they have no id!
|
|
|
|
*/
|
2010-05-14 10:04:51 -07:00
|
|
|
static Element* MatchElementId(nsIContent *aContent, const nsAString& aId);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Similar to above, but to be used if one already has an atom for the ID
|
|
|
|
*/
|
2010-10-07 12:19:32 -07:00
|
|
|
static Element* MatchElementId(nsIContent *aContent, const nsIAtom* aId);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverses the document position flags passed in.
|
|
|
|
*
|
|
|
|
* @param aDocumentPosition The document position flags to be reversed.
|
|
|
|
*
|
|
|
|
* @return The reversed document position flags.
|
|
|
|
*
|
|
|
|
* @see nsIDOMNode
|
|
|
|
*/
|
|
|
|
static PRUint16 ReverseDocumentPosition(PRUint16 aDocumentPosition);
|
|
|
|
|
|
|
|
static PRUint32 CopyNewlineNormalizedUnicodeTo(const nsAString& aSource,
|
|
|
|
PRUint32 aSrcOffset,
|
|
|
|
PRUnichar* aDest,
|
|
|
|
PRUint32 aLength,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aLastCharCR);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static PRUint32 CopyNewlineNormalizedUnicodeTo(nsReadingIterator<PRUnichar>& aSrcStart, const nsReadingIterator<PRUnichar>& aSrcEnd, nsAString& aDest);
|
|
|
|
|
|
|
|
static const nsDependentSubstring TrimCharsInSet(const char* aSet,
|
|
|
|
const nsAString& aValue);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
template<bool IsWhitespace(PRUnichar)>
|
2007-03-22 10:30:00 -07:00
|
|
|
static const nsDependentSubstring TrimWhitespace(const nsAString& aStr,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aTrimTrailing = true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-11 17:51:31 -08:00
|
|
|
/**
|
2008-07-02 09:28:43 -07:00
|
|
|
* Returns true if aChar is of class Ps, Pi, Po, Pf, or Pe.
|
2007-11-11 17:51:31 -08:00
|
|
|
*/
|
2012-03-01 00:17:27 -08:00
|
|
|
static bool IsFirstLetterPunctuation(PRUint32 aChar);
|
|
|
|
static bool IsFirstLetterPunctuationAt(const nsTextFragment* aFrag, PRUint32 aOffset);
|
2008-07-02 09:28:43 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if aChar is of class Lu, Ll, Lt, Lm, Lo, Nd, Nl or No
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsAlphanumeric(PRUint32 aChar);
|
|
|
|
static bool IsAlphanumericAt(const nsTextFragment* aFrag, PRUint32 aOffset);
|
2007-11-11 17:51:31 -08:00
|
|
|
|
2008-06-10 17:27:00 -07:00
|
|
|
/*
|
|
|
|
* Is the character an HTML whitespace character?
|
|
|
|
*
|
|
|
|
* We define whitespace using the list in HTML5 and css3-selectors:
|
|
|
|
* U+0009, U+000A, U+000C, U+000D, U+0020
|
|
|
|
*
|
|
|
|
* HTML 4.01 also lists U+200B (zero-width space).
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsHTMLWhitespace(PRUnichar aChar);
|
2008-06-10 17:27:00 -07:00
|
|
|
|
2012-03-08 06:42:27 -08:00
|
|
|
/**
|
|
|
|
* Is the HTML local name a block element?
|
|
|
|
*/
|
|
|
|
static bool IsHTMLBlock(nsIAtom* aLocalName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the HTML local name a void element?
|
|
|
|
*/
|
|
|
|
static bool IsHTMLVoid(nsIAtom* aLocalName);
|
|
|
|
|
2010-06-24 19:01:07 -07:00
|
|
|
/**
|
|
|
|
* Parse a margin string of format 'top, right, bottom, left' into
|
|
|
|
* an nsIntMargin.
|
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @param aResult the resulting integer
|
|
|
|
* @return whether the value could be parsed
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool ParseIntMarginValue(const nsAString& aString, nsIntMargin& aResult);
|
2010-06-24 19:01:07 -07:00
|
|
|
|
2012-04-24 03:57:23 -07:00
|
|
|
/**
|
|
|
|
* Parse the value of the <font size=""> attribute according to the HTML5
|
|
|
|
* spec as of April 16, 2012.
|
|
|
|
*
|
|
|
|
* @param aValue the value to parse
|
|
|
|
* @return 1 to 7, or 0 if the value couldn't be parsed
|
|
|
|
*/
|
|
|
|
static PRInt32 ParseLegacyFontSize(const nsAString& aValue);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
/**
|
2010-02-07 06:20:35 -08:00
|
|
|
* Checks whether two nodes come from the same origin.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-01-12 05:08:44 -08:00
|
|
|
static nsresult CheckSameOrigin(nsINode* aTrustedNode,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDOMNode* aUnTrustedNode);
|
2012-04-03 00:25:38 -07:00
|
|
|
static nsresult CheckSameOrigin(nsINode* aTrustedNode,
|
|
|
|
nsINode* unTrustedNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Check if the (JS) caller can access aNode.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool CanCallerAccess(nsIDOMNode *aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-26 18:03:27 -08:00
|
|
|
// Check if the (JS) caller can access aWindow.
|
|
|
|
// aWindow can be either outer or inner window.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool CanCallerAccess(nsPIDOMWindow* aWindow);
|
2008-02-26 18:03:27 -08:00
|
|
|
|
2010-09-09 11:18:23 -07:00
|
|
|
/**
|
|
|
|
* Get the window through the JS context that's currently on the stack.
|
|
|
|
* If there's no JS context currently on the stack, returns null.
|
|
|
|
*/
|
|
|
|
static nsPIDOMWindow *GetWindowFromCaller();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* The two GetDocumentFrom* functions below allow a caller to get at a
|
|
|
|
* document that is relevant to the currently executing script.
|
|
|
|
*
|
|
|
|
* GetDocumentFromCaller gets its document by looking at the last called
|
|
|
|
* function and finding the document that the function itself relates to.
|
|
|
|
* For example, consider two windows A and B in the same origin. B has a
|
|
|
|
* function which does something that ends up needing the current document.
|
|
|
|
* If a script in window A were to call B's function, GetDocumentFromCaller
|
|
|
|
* would find that function (in B) and return B's document.
|
|
|
|
*
|
|
|
|
* GetDocumentFromContext gets its document by looking at the currently
|
|
|
|
* executing context's global object and returning its document. Thus,
|
|
|
|
* given the example above, GetDocumentFromCaller would see that the
|
|
|
|
* currently executing script was in window A, and return A's document.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Get the document from the currently executing function. This will return
|
|
|
|
* the document that the currently executing function is in/from.
|
|
|
|
*
|
|
|
|
* @return The document or null if no JS Context.
|
|
|
|
*/
|
|
|
|
static nsIDOMDocument *GetDocumentFromCaller();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the document through the JS context that's currently on the stack.
|
|
|
|
* If there's no JS context currently on the stack it will return null.
|
|
|
|
* This will return the document of the calling script.
|
|
|
|
*
|
|
|
|
* @return The document or null if no JS context
|
|
|
|
*/
|
|
|
|
static nsIDOMDocument *GetDocumentFromContext();
|
|
|
|
|
|
|
|
// Check if a node is in the document prolog, i.e. before the document
|
|
|
|
// element.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool InProlog(nsINode *aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static nsIParserService* GetParserService();
|
|
|
|
|
|
|
|
static nsINameSpaceManager* NameSpaceManager()
|
|
|
|
{
|
|
|
|
return sNameSpaceManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIIOService* GetIOService()
|
|
|
|
{
|
|
|
|
return sIOService;
|
|
|
|
}
|
|
|
|
|
|
|
|
static imgILoader* GetImgLoader()
|
|
|
|
{
|
2010-07-02 14:15:52 -07:00
|
|
|
if (!sImgLoaderInitialized)
|
|
|
|
InitImgLoader();
|
2007-03-22 10:30:00 -07:00
|
|
|
return sImgLoader;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_XTF
|
|
|
|
static nsIXTFService* GetXTFService();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
static nsIBidiKeyboard* GetBidiKeyboard();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the cache security manager service. Can return null if the layout
|
|
|
|
* module has been shut down.
|
|
|
|
*/
|
|
|
|
static nsIScriptSecurityManager* GetSecurityManager()
|
|
|
|
{
|
|
|
|
return sSecurityManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult GenerateStateKey(nsIContent* aContent,
|
2010-10-07 12:19:32 -07:00
|
|
|
const nsIDocument* aDocument,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIStatefulFrame::SpecialStateID aID,
|
|
|
|
nsACString& aKey);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new nsIURI from aSpec, using aBaseURI as the base. The
|
|
|
|
* origin charset of the new nsIURI will be the document charset of
|
|
|
|
* aDocument.
|
|
|
|
*/
|
|
|
|
static nsresult NewURIWithDocumentCharset(nsIURI** aResult,
|
|
|
|
const nsAString& aSpec,
|
|
|
|
nsIDocument* aDocument,
|
|
|
|
nsIURI* aBaseURI);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert aInput (in charset aCharset) to UTF16 in aOutput.
|
|
|
|
*
|
|
|
|
* @param aCharset the name of the charset; if empty, we assume UTF8
|
|
|
|
*/
|
|
|
|
static nsresult ConvertStringFromCharset(const nsACString& aCharset,
|
|
|
|
const nsACString& aInput,
|
|
|
|
nsAString& aOutput);
|
|
|
|
|
2007-12-27 13:45:03 -08:00
|
|
|
/**
|
|
|
|
* Determine whether a buffer begins with a BOM for UTF-8, UTF-16LE,
|
2011-03-29 23:35:34 -07:00
|
|
|
* UTF-16BE
|
2007-12-27 13:45:03 -08:00
|
|
|
*
|
|
|
|
* @param aBuffer the buffer to check
|
|
|
|
* @param aLength the length of the buffer
|
|
|
|
* @param aCharset empty if not found
|
|
|
|
* @return boolean indicating whether a BOM was detected.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool CheckForBOM(const unsigned char* aBuffer, PRUint32 aLength,
|
2012-06-03 09:33:52 -07:00
|
|
|
nsACString& aCharset, bool *bigEndian = nsnull);
|
2007-12-27 13:45:03 -08:00
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
static nsresult GuessCharset(const char *aData, PRUint32 aDataLen,
|
|
|
|
nsACString &aCharset);
|
2007-12-27 13:45:03 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Determine whether aContent is in some way associated with aForm. If the
|
|
|
|
* form is a container the only elements that are considered to be associated
|
|
|
|
* with a form are the elements that are contained within the form. If the
|
|
|
|
* form is a leaf element then all elements will be accepted into this list,
|
|
|
|
* since this can happen due to content fixup when a form spans table rows or
|
|
|
|
* table cells.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool BelongsInForm(nsIContent *aForm,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent *aContent);
|
|
|
|
|
|
|
|
static nsresult CheckQName(const nsAString& aQualifiedName,
|
2012-03-29 14:31:40 -07:00
|
|
|
bool aNamespaceAware = true,
|
|
|
|
const PRUnichar** aColon = nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-10-07 12:19:32 -07:00
|
|
|
static nsresult SplitQName(const nsIContent* aNamespaceResolver,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsAFlatString& aQName,
|
|
|
|
PRInt32 *aNamespace, nsIAtom **aLocalName);
|
|
|
|
|
|
|
|
static nsresult GetNodeInfoFromQName(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aQualifiedName,
|
|
|
|
nsNodeInfoManager* aNodeInfoManager,
|
2011-06-14 00:56:49 -07:00
|
|
|
PRUint16 aNodeType,
|
2012-03-28 22:43:09 -07:00
|
|
|
nsINodeInfo** aNodeInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static void SplitExpatName(const PRUnichar *aExpatName, nsIAtom **aPrefix,
|
|
|
|
nsIAtom **aTagName, PRInt32 *aNameSpaceID);
|
|
|
|
|
2012-05-08 14:47:18 -07:00
|
|
|
// Get a permission-manager setting for the given principal and type.
|
2011-10-17 07:59:28 -07:00
|
|
|
// If the pref doesn't exist or if it isn't ALLOW_ACTION, false is
|
2012-05-08 14:47:18 -07:00
|
|
|
// returned, otherwise true is returned. Always returns true for the
|
|
|
|
// system principal, and false for a null principal.
|
|
|
|
static bool IsSitePermAllow(nsIPrincipal* aPrincipal, const char* aType);
|
|
|
|
|
|
|
|
// Get a permission-manager setting for the given principal and type.
|
|
|
|
// If the pref doesn't exist or if it isn't DENY_ACTION, false is
|
|
|
|
// returned, otherwise true is returned. Always returns false for the
|
|
|
|
// system principal, and true for a null principal.
|
|
|
|
static bool IsSitePermDeny(nsIPrincipal* aPrincipal, const char* aType);
|
2010-08-19 16:12:46 -07:00
|
|
|
|
2012-05-21 13:43:36 -07:00
|
|
|
// Returns true if aDoc1 and aDoc2 have equal NodePrincipal()s.
|
|
|
|
static bool HaveEqualPrincipals(nsIDocument* aDoc1, nsIDocument* aDoc2);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsILineBreaker* LineBreaker()
|
|
|
|
{
|
|
|
|
return sLineBreaker;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIWordBreaker* WordBreaker()
|
|
|
|
{
|
|
|
|
return sWordBreaker;
|
|
|
|
}
|
|
|
|
|
2010-02-24 11:14:14 -08:00
|
|
|
/**
|
|
|
|
* Regster aObserver as a shutdown observer. A strong reference is held
|
|
|
|
* to aObserver until UnregisterShutdownObserver is called.
|
|
|
|
*/
|
|
|
|
static void RegisterShutdownObserver(nsIObserver* aObserver);
|
|
|
|
static void UnregisterShutdownObserver(nsIObserver* aObserver);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2011-10-17 07:59:28 -07:00
|
|
|
* @return true if aContent has an attribute aName in namespace aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
* and the attribute value is non-empty.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool HasNonEmptyAttr(const nsIContent* aContent, PRInt32 aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aName);
|
|
|
|
|
2007-07-13 01:49:07 -07:00
|
|
|
/**
|
|
|
|
* Method that gets the primary presContext for the node.
|
|
|
|
*
|
|
|
|
* @param aContent The content node.
|
|
|
|
* @return the presContext, or nsnull if the content is not in a document
|
|
|
|
* (if GetCurrentDoc returns nsnull)
|
|
|
|
*/
|
2010-10-07 12:19:32 -07:00
|
|
|
static nsPresContext* GetContextForContent(const nsIContent* aContent);
|
2007-07-13 01:49:07 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Method to do security and content policy checks on the image URI
|
|
|
|
*
|
|
|
|
* @param aURI uri of the image to be loaded
|
|
|
|
* @param aContext the context the image is loaded in (eg an element)
|
|
|
|
* @param aLoadingDocument the document we belong to
|
2007-07-03 11:45:39 -07:00
|
|
|
* @param aLoadingPrincipal the principal doing the load
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aImageBlockingStatus the nsIContentPolicy blocking status for this
|
|
|
|
* image. This will be set even if a security check fails for the
|
|
|
|
* image, to some reasonable REJECT_* value. This out param will only
|
|
|
|
* be set if it's non-null.
|
2011-10-17 07:59:28 -07:00
|
|
|
* @return true if the load can proceed, or false if it is blocked.
|
2007-03-22 10:30:00 -07:00
|
|
|
* Note that aImageBlockingStatus, if set will always be an ACCEPT
|
2011-10-17 07:59:28 -07:00
|
|
|
* status if true is returned and always be a REJECT_* status if
|
|
|
|
* false is returned.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool CanLoadImage(nsIURI* aURI,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsISupports* aContext,
|
|
|
|
nsIDocument* aLoadingDocument,
|
2007-07-03 11:45:39 -07:00
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt16* aImageBlockingStatus = nsnull);
|
|
|
|
/**
|
|
|
|
* Method to start an image load. This does not do any security checks.
|
2007-10-26 12:54:41 -07:00
|
|
|
* This method will attempt to make aURI immutable; a caller that wants to
|
|
|
|
* keep a mutable version around should pass in a clone.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* @param aURI uri of the image to be loaded
|
|
|
|
* @param aLoadingDocument the document we belong to
|
2007-07-03 11:45:39 -07:00
|
|
|
* @param aLoadingPrincipal the principal doing the load
|
|
|
|
* @param aReferrer the referrer URI
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aObserver the observer for the image load
|
|
|
|
* @param aLoadFlags the load flags to use. See nsIRequest
|
|
|
|
* @return the imgIRequest for the image load
|
|
|
|
*/
|
|
|
|
static nsresult LoadImage(nsIURI* aURI,
|
|
|
|
nsIDocument* aLoadingDocument,
|
2007-07-03 11:45:39 -07:00
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIURI* aReferrer,
|
|
|
|
imgIDecoderObserver* aObserver,
|
|
|
|
PRInt32 aLoadFlags,
|
|
|
|
imgIRequest** aRequest);
|
|
|
|
|
2009-07-07 22:23:20 -07:00
|
|
|
/**
|
|
|
|
* Returns whether the given URI is in the image cache.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsImageInCache(nsIURI* aURI);
|
2009-07-07 22:23:20 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
* Method to get an imgIContainer from an image loading content
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* @param aContent The image loading content. Must not be null.
|
|
|
|
* @param aRequest The image request [out]
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
* @return the imgIContainer corresponding to the first frame of the image
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
static already_AddRefed<imgIContainer> GetImageFromContent(nsIImageLoadingContent* aContent, imgIRequest **aRequest = nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 20:02:13 -08:00
|
|
|
/**
|
|
|
|
* Helper method to call imgIRequest::GetStaticRequest.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<imgIRequest> GetStaticRequest(imgIRequest* aRequest);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Method that decides whether a content node is draggable
|
|
|
|
*
|
|
|
|
* @param aContent The content node to test.
|
|
|
|
* @return whether it's draggable
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool ContentIsDraggable(nsIContent* aContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Method that decides whether a content node is a draggable image
|
|
|
|
*
|
|
|
|
* @param aContent The content node to test.
|
|
|
|
* @return whether it's a draggable image
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsDraggableImage(nsIContent* aContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Method that decides whether a content node is a draggable link
|
|
|
|
*
|
|
|
|
* @param aContent The content node to test.
|
|
|
|
* @return whether it's a draggable link
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsDraggableLink(const nsIContent* aContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method to create a new nodeinfo that differs only by name
|
|
|
|
* from aNodeInfo.
|
|
|
|
*/
|
2012-03-28 22:43:09 -07:00
|
|
|
static nsresult NameChanged(nsINodeInfo *aNodeInfo, nsIAtom *aName,
|
|
|
|
nsINodeInfo** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsNodeInfoManager *niMgr = aNodeInfo->NodeInfoManager();
|
|
|
|
|
2008-09-12 15:32:18 -07:00
|
|
|
*aResult = niMgr->GetNodeInfo(aName, aNodeInfo->GetPrefixAtom(),
|
2011-06-14 00:56:49 -07:00
|
|
|
aNodeInfo->NamespaceID(),
|
|
|
|
aNodeInfo->NodeType(),
|
|
|
|
aNodeInfo->GetExtraName()).get();
|
2008-09-25 15:46:52 -07:00
|
|
|
return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the appropriate event argument names for the specified
|
|
|
|
* namespace and event name. Added because we need to switch between
|
|
|
|
* SVG's "evt" and the rest of the world's "event", and because onerror
|
|
|
|
* takes 3 args.
|
|
|
|
*/
|
|
|
|
static void GetEventArgNames(PRInt32 aNameSpaceID, nsIAtom *aEventName,
|
|
|
|
PRUint32 *aArgCount, const char*** aArgNames);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If aNode is not an element, return true exactly when aContent's binding
|
|
|
|
* parent is null.
|
|
|
|
*
|
|
|
|
* If aNode is an element, return true exactly when aContent's binding parent
|
|
|
|
* is the same as aNode's.
|
|
|
|
*
|
|
|
|
* This method is particularly useful for callers who are trying to ensure
|
|
|
|
* that they are working with a non-anonymous descendant of a given node. If
|
2011-10-17 07:59:28 -07:00
|
|
|
* aContent is a descendant of aNode, a return value of false from this
|
2007-03-22 10:30:00 -07:00
|
|
|
* method means that it's an anonymous descendant from aNode's point of view.
|
|
|
|
*
|
|
|
|
* Both arguments to this method must be non-null.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsInSameAnonymousTree(const nsINode* aNode, const nsIContent* aContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the nsIXPConnect service.
|
|
|
|
*/
|
|
|
|
static nsIXPConnect *XPConnect()
|
|
|
|
{
|
|
|
|
return sXPConnect;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Report a localized error message to the error console.
|
|
|
|
* @param aErrorFlags See nsIScriptError.
|
|
|
|
* @param aCategory Name of module reporting error.
|
2011-12-15 06:47:03 -08:00
|
|
|
* @param aDocument Reference to the document which triggered the message.
|
|
|
|
* @param aFile Properties file containing localized message.
|
|
|
|
* @param aMessageName Name of localized message.
|
|
|
|
* @param [aParams=nsnull] (Optional) Parameters to be substituted into
|
|
|
|
localized message.
|
|
|
|
* @param [aParamsLength=0] (Optional) Length of aParams.
|
|
|
|
* @param [aURI=nsnull] (Optional) URI of resource containing error.
|
|
|
|
* @param [aSourceLine=EmptyString()] (Optional) The text of the line that
|
|
|
|
contains the error (may be empty).
|
|
|
|
* @param [aLineNumber=0] (Optional) Line number within resource
|
|
|
|
containing error.
|
|
|
|
* @param [aColumnNumber=0] (Optional) Column number within resource
|
|
|
|
containing error.
|
|
|
|
If aURI is null, then aDocument->GetDocumentURI() is used.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
enum PropertiesFile {
|
|
|
|
eCSS_PROPERTIES,
|
|
|
|
eXBL_PROPERTIES,
|
|
|
|
eXUL_PROPERTIES,
|
|
|
|
eLAYOUT_PROPERTIES,
|
|
|
|
eFORMS_PROPERTIES,
|
|
|
|
ePRINTING_PROPERTIES,
|
|
|
|
eDOM_PROPERTIES,
|
2011-11-01 04:33:11 -07:00
|
|
|
eHTMLPARSER_PROPERTIES,
|
2007-03-22 10:30:00 -07:00
|
|
|
eSVG_PROPERTIES,
|
|
|
|
eBRAND_PROPERTIES,
|
|
|
|
eCOMMON_DIALOG_PROPERTIES,
|
|
|
|
PropertiesFile_COUNT
|
|
|
|
};
|
2011-12-15 06:47:03 -08:00
|
|
|
static nsresult ReportToConsole(PRUint32 aErrorFlags,
|
2010-12-20 08:21:58 -08:00
|
|
|
const char *aCategory,
|
2011-12-15 06:47:03 -08:00
|
|
|
nsIDocument* aDocument,
|
|
|
|
PropertiesFile aFile,
|
2010-12-20 08:21:58 -08:00
|
|
|
const char *aMessageName,
|
2011-12-15 06:47:03 -08:00
|
|
|
const PRUnichar **aParams = nsnull,
|
|
|
|
PRUint32 aParamsLength = 0,
|
|
|
|
nsIURI* aURI = nsnull,
|
|
|
|
const nsAFlatString& aSourceLine
|
|
|
|
= EmptyString(),
|
|
|
|
PRUint32 aLineNumber = 0,
|
|
|
|
PRUint32 aColumnNumber = 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the localized string named |aKey| in properties file |aFile|.
|
|
|
|
*/
|
|
|
|
static nsresult GetLocalizedString(PropertiesFile aFile,
|
|
|
|
const char* aKey,
|
|
|
|
nsXPIDLString& aResult);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill (with the parameters given) the localized string named |aKey| in
|
|
|
|
* properties file |aFile|.
|
|
|
|
*/
|
2012-03-08 18:22:57 -08:00
|
|
|
private:
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsresult FormatLocalizedString(PropertiesFile aFile,
|
|
|
|
const char* aKey,
|
2012-03-08 18:22:57 -08:00
|
|
|
const PRUnichar** aParams,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 aParamsLength,
|
|
|
|
nsXPIDLString& aResult);
|
2012-03-08 18:22:57 -08:00
|
|
|
|
|
|
|
public:
|
|
|
|
template<PRUint32 N>
|
|
|
|
static nsresult FormatLocalizedString(PropertiesFile aFile,
|
|
|
|
const char* aKey,
|
|
|
|
const PRUnichar* (&aParams)[N],
|
|
|
|
nsXPIDLString& aResult)
|
|
|
|
{
|
|
|
|
return FormatLocalizedString(aFile, aKey, aParams, N, aResult);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if aDocument is a chrome document
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsChromeDoc(nsIDocument *aDocument);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-14 19:20:50 -07:00
|
|
|
/**
|
|
|
|
* Returns true if aDocument is in a docshell whose parent is the same type
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsChildOfSameType(nsIDocument* aDoc);
|
2009-10-14 19:20:50 -07:00
|
|
|
|
2008-11-13 16:00:11 -08:00
|
|
|
/**
|
|
|
|
* Get the script file name to use when compiling the script
|
|
|
|
* referenced by aURI. In cases where there's no need for any extra
|
|
|
|
* security wrapper automation the script file name that's returned
|
|
|
|
* will be the spec in aURI, else it will be the spec in aDocument's
|
2011-10-17 07:59:28 -07:00
|
|
|
* URI followed by aURI's spec, separated by " -> ". Returns true
|
|
|
|
* if the script file name was modified, false if it's aURI's
|
2008-11-13 16:00:11 -08:00
|
|
|
* spec.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool GetWrapperSafeScriptFilename(nsIDocument *aDocument,
|
2008-11-13 16:00:11 -08:00
|
|
|
nsIURI *aURI,
|
|
|
|
nsACString& aScriptURI);
|
|
|
|
|
|
|
|
|
2008-09-28 12:14:28 -07:00
|
|
|
/**
|
|
|
|
* Returns true if aDocument belongs to a chrome docshell for
|
|
|
|
* display purposes. Returns false for null documents or documents
|
|
|
|
* which do not belong to a docshell.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsInChromeDocshell(nsIDocument *aDocument);
|
2008-09-28 12:14:28 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Return the content policy service
|
|
|
|
*/
|
|
|
|
static nsIContentPolicy *GetContentPolicy();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Quick helper to determine whether there are any mutation listeners
|
|
|
|
* of a given type that apply to this content or any of its ancestors.
|
2007-07-04 13:39:10 -07:00
|
|
|
* The method has the side effect to call document's MayDispatchMutationEvent
|
|
|
|
* using aTargetForSubtreeModified as the parameter.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* @param aNode The node to search for listeners
|
|
|
|
* @param aType The type of listener (NS_EVENT_BITS_MUTATION_*)
|
2007-07-04 13:39:10 -07:00
|
|
|
* @param aTargetForSubtreeModified The node which is the target of the
|
|
|
|
* possible DOMSubtreeModified event.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* @return true if there are mutation listeners of the specified type
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool HasMutationListeners(nsINode* aNode,
|
2007-07-04 13:39:10 -07:00
|
|
|
PRUint32 aType,
|
|
|
|
nsINode* aTargetForSubtreeModified);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-09 12:33:03 -07:00
|
|
|
/**
|
|
|
|
* Quick helper to determine whether there are any mutation listeners
|
|
|
|
* of a given type that apply to any content in this document. It is valid
|
|
|
|
* to pass null for aDocument here, in which case this function always
|
2011-10-17 07:59:28 -07:00
|
|
|
* returns true.
|
2011-05-09 12:33:03 -07:00
|
|
|
*
|
|
|
|
* @param aDocument The document to search for listeners
|
|
|
|
* @param aType The type of listener (NS_EVENT_BITS_MUTATION_*)
|
|
|
|
*
|
|
|
|
* @return true if there are mutation listeners of the specified type
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool HasMutationListeners(nsIDocument* aDocument,
|
2011-05-09 12:33:03 -07:00
|
|
|
PRUint32 aType);
|
|
|
|
/**
|
|
|
|
* Synchronously fire DOMNodeRemoved on aChild. Only fires the event if
|
|
|
|
* there really are listeners by checking using the HasMutationListeners
|
|
|
|
* function above. The function makes sure to hold the relevant objects alive
|
|
|
|
* for the duration of the event firing. However there are no guarantees
|
|
|
|
* that any of the objects are alive by the time the function returns.
|
|
|
|
* If you depend on that you need to hold references yourself.
|
|
|
|
*
|
|
|
|
* @param aChild The node to fire DOMNodeRemoved at.
|
|
|
|
* @param aParent The parent of aChild.
|
|
|
|
* @param aOwnerDoc The ownerDocument of aChild.
|
|
|
|
*/
|
|
|
|
static void MaybeFireNodeRemoved(nsINode* aChild, nsINode* aParent,
|
|
|
|
nsIDocument* aOwnerDoc);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* This method creates and dispatches a trusted event.
|
|
|
|
* Works only with events which can be created by calling
|
2011-05-23 09:46:36 -07:00
|
|
|
* nsIDOMDocument::CreateEvent() with parameter "Events".
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aDoc The document which will be used to create the event.
|
|
|
|
* @param aTarget The target of the event, should be QIable to
|
|
|
|
* nsIDOMEventTarget.
|
|
|
|
* @param aEventName The name of the event.
|
|
|
|
* @param aCanBubble Whether the event can bubble.
|
|
|
|
* @param aCancelable Is the event cancelable.
|
|
|
|
* @param aDefaultAction Set to true if default action should be taken,
|
|
|
|
* see nsIDOMEventTarget::DispatchEvent.
|
|
|
|
*/
|
|
|
|
static nsresult DispatchTrustedEvent(nsIDocument* aDoc,
|
|
|
|
nsISupports* aTarget,
|
|
|
|
const nsAString& aEventName,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
|
|
|
bool *aDefaultAction = nsnull);
|
2012-02-13 15:07:04 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method creates and dispatches a untrusted event.
|
|
|
|
* Works only with events which can be created by calling
|
|
|
|
* nsIDOMDocument::CreateEvent() with parameter "Events".
|
|
|
|
* @param aDoc The document which will be used to create the event.
|
|
|
|
* @param aTarget The target of the event, should be QIable to
|
|
|
|
* nsIDOMEventTarget.
|
|
|
|
* @param aEventName The name of the event.
|
|
|
|
* @param aCanBubble Whether the event can bubble.
|
|
|
|
* @param aCancelable Is the event cancelable.
|
|
|
|
* @param aDefaultAction Set to true if default action should be taken,
|
|
|
|
* see nsIDOMEventTarget::DispatchEvent.
|
|
|
|
*/
|
|
|
|
static nsresult DispatchUntrustedEvent(nsIDocument* aDoc,
|
|
|
|
nsISupports* aTarget,
|
|
|
|
const nsAString& aEventName,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
|
|
|
bool *aDefaultAction = nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-22 11:09:10 -08:00
|
|
|
/**
|
|
|
|
* This method creates and dispatches a trusted event to the chrome
|
|
|
|
* event handler.
|
|
|
|
* Works only with events which can be created by calling
|
2011-05-23 09:46:36 -07:00
|
|
|
* nsIDOMDocument::CreateEvent() with parameter "Events".
|
2009-02-22 11:09:10 -08:00
|
|
|
* @param aDocument The document which will be used to create the event,
|
|
|
|
* and whose window's chrome handler will be used to
|
|
|
|
* dispatch the event.
|
|
|
|
* @param aTarget The target of the event, used for event->SetTarget()
|
|
|
|
* @param aEventName The name of the event.
|
|
|
|
* @param aCanBubble Whether the event can bubble.
|
|
|
|
* @param aCancelable Is the event cancelable.
|
|
|
|
* @param aDefaultAction Set to true if default action should be taken,
|
|
|
|
* see nsIDOMEventTarget::DispatchEvent.
|
|
|
|
*/
|
|
|
|
static nsresult DispatchChromeEvent(nsIDocument* aDoc,
|
|
|
|
nsISupports* aTarget,
|
|
|
|
const nsAString& aEventName,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
|
|
|
bool *aDefaultAction = nsnull);
|
2009-02-22 11:09:10 -08:00
|
|
|
|
2007-04-02 10:17:36 -07:00
|
|
|
/**
|
|
|
|
* Determines if an event attribute name (such as onclick) is valid for
|
|
|
|
* a given element type. Types are from the EventNameType enumeration
|
|
|
|
* defined above.
|
|
|
|
*
|
|
|
|
* @param aName the event name to look up
|
|
|
|
* @param aType the type of content
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsEventAttributeName(nsIAtom* aName, PRInt32 aType);
|
2007-04-02 10:17:36 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the event id for the event with the given name. The name is the
|
|
|
|
* event name with the 'on' prefix. Returns NS_USER_DEFINED_EVENT if the
|
|
|
|
* event doesn't match a known event name.
|
|
|
|
*
|
|
|
|
* @param aName the event name to look up
|
|
|
|
*/
|
|
|
|
static PRUint32 GetEventId(nsIAtom* aName);
|
|
|
|
|
2011-04-18 13:57:32 -07:00
|
|
|
/**
|
|
|
|
* Return the category for the event with the given name. The name is the
|
|
|
|
* event name *without* the 'on' prefix. Returns NS_EVENT if the event
|
|
|
|
* is not known to be in any particular category.
|
|
|
|
*
|
|
|
|
* @param aName the event name to look up
|
|
|
|
*/
|
|
|
|
static PRUint32 GetEventCategory(const nsAString& aName);
|
|
|
|
|
2010-06-22 11:12:12 -07:00
|
|
|
/**
|
|
|
|
* Return the event id and atom for the event with the given name.
|
|
|
|
* The name is the event name *without* the 'on' prefix.
|
|
|
|
* Returns NS_USER_DEFINED_EVENT on the aEventID if the
|
|
|
|
* event doesn't match a known event name in the category.
|
|
|
|
*
|
|
|
|
* @param aName the event name to look up
|
|
|
|
* @param aEventStruct only return event id in aEventStruct category
|
|
|
|
*/
|
|
|
|
static nsIAtom* GetEventIdAndAtom(const nsAString& aName,
|
|
|
|
PRUint32 aEventStruct,
|
|
|
|
PRUint32* aEventID);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Used only during traversal of the XPCOM graph by the cycle
|
|
|
|
* collector: push a pointer to the listener manager onto the
|
|
|
|
* children deque, if it exists. Do nothing if there is no listener
|
|
|
|
* manager.
|
|
|
|
*
|
|
|
|
* Crucially: does not perform any refcounting operations.
|
|
|
|
*
|
|
|
|
* @param aNode The node to traverse.
|
|
|
|
* @param children The buffer to push a listener manager pointer into.
|
|
|
|
*/
|
|
|
|
static void TraverseListenerManager(nsINode *aNode,
|
|
|
|
nsCycleCollectionTraversalCallback &cb);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the eventlistener manager for aNode. If a new eventlistener manager
|
2011-10-17 07:59:28 -07:00
|
|
|
* was created, aCreated is set to true.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* @param aNode The node for which to get the eventlistener manager.
|
2011-10-17 07:59:28 -07:00
|
|
|
* @param aCreateIfNotFound If false, returns a listener manager only if
|
2007-03-22 10:30:00 -07:00
|
|
|
* one already exists.
|
|
|
|
*/
|
2011-06-23 19:18:01 -07:00
|
|
|
static nsEventListenerManager* GetListenerManager(nsINode* aNode,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCreateIfNotFound);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-26 06:51:58 -08:00
|
|
|
static void UnmarkGrayJSListenersInCCGenerationDocuments(PRUint32 aGeneration);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Remove the eventlistener manager for aNode.
|
|
|
|
*
|
|
|
|
* @param aNode The node for which to remove the eventlistener manager.
|
|
|
|
*/
|
|
|
|
static void RemoveListenerManager(nsINode *aNode);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsInitialized()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return sInitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the localname/prefix/namespace triple is valid wrt prefix
|
|
|
|
* and namespace according to the Namespaces in XML and DOM Code
|
|
|
|
* specfications.
|
|
|
|
*
|
|
|
|
* @param aLocalname localname of the node
|
|
|
|
* @param aPrefix prefix of the node
|
|
|
|
* @param aNamespaceID namespace of the node
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsValidNodeName(nsIAtom *aLocalName, nsIAtom *aPrefix,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 aNamespaceID);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a DocumentFragment from text using a context node to resolve
|
|
|
|
* namespaces.
|
|
|
|
*
|
2010-09-01 04:41:07 -07:00
|
|
|
* Note! In the HTML case with the HTML5 parser enabled, this is only called
|
|
|
|
* from Range.createContextualFragment() and the implementation here is
|
|
|
|
* quirky accordingly (html context node behaves like a body context node).
|
|
|
|
* If you don't want that quirky behavior, don't use this method as-is!
|
|
|
|
*
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aContextNode the node which is used to resolve namespaces
|
|
|
|
* @param aFragment the string which is parsed to a DocumentFragment
|
2011-08-01 00:48:24 -07:00
|
|
|
* @param aReturn the resulting fragment
|
2011-08-01 00:48:28 -07:00
|
|
|
* @param aPreventScriptExecution whether to mark scripts as already started
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-04-24 03:41:02 -07:00
|
|
|
static nsresult CreateContextualFragment(nsINode* aContextNode,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsAString& aFragment,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aPreventScriptExecution,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDOMDocumentFragment** aReturn);
|
|
|
|
|
2011-08-01 00:48:24 -07:00
|
|
|
/**
|
|
|
|
* Invoke the fragment parsing algorithm (innerHTML) using the HTML parser.
|
|
|
|
*
|
|
|
|
* @param aSourceBuffer the string being set as innerHTML
|
|
|
|
* @param aTargetNode the target container
|
|
|
|
* @param aContextLocalName local name of context node
|
|
|
|
* @param aContextNamespace namespace of context node
|
|
|
|
* @param aQuirks true to make <table> not close <p>
|
|
|
|
* @param aPreventScriptExecution true to prevent scripts from executing;
|
|
|
|
* don't set to false when parsing into a target node that has been
|
|
|
|
* bound to tree.
|
2011-10-14 03:39:19 -07:00
|
|
|
* @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse
|
2012-01-20 04:03:49 -08:00
|
|
|
* fragments is made, NS_ERROR_OUT_OF_MEMORY if aSourceBuffer is too
|
|
|
|
* long and NS_OK otherwise.
|
2011-08-01 00:48:24 -07:00
|
|
|
*/
|
2011-10-14 03:39:19 -07:00
|
|
|
static nsresult ParseFragmentHTML(const nsAString& aSourceBuffer,
|
|
|
|
nsIContent* aTargetNode,
|
|
|
|
nsIAtom* aContextLocalName,
|
|
|
|
PRInt32 aContextNamespace,
|
|
|
|
bool aQuirks,
|
|
|
|
bool aPreventScriptExecution);
|
2011-08-01 00:48:24 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoke the fragment parsing algorithm (innerHTML) using the XML parser.
|
|
|
|
*
|
|
|
|
* @param aSourceBuffer the string being set as innerHTML
|
|
|
|
* @param aTargetNode the target container
|
|
|
|
* @param aTagStack the namespace mapping context
|
2011-08-01 00:48:28 -07:00
|
|
|
* @param aPreventExecution whether to mark scripts as already started
|
2011-08-01 00:48:24 -07:00
|
|
|
* @param aReturn the result fragment
|
2011-10-14 03:39:19 -07:00
|
|
|
* @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse
|
|
|
|
* fragments is made, a return code from the XML parser.
|
2011-08-01 00:48:24 -07:00
|
|
|
*/
|
|
|
|
static nsresult ParseFragmentXML(const nsAString& aSourceBuffer,
|
|
|
|
nsIDocument* aDocument,
|
|
|
|
nsTArray<nsString>& aTagStack,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aPreventScriptExecution,
|
2011-08-01 00:48:24 -07:00
|
|
|
nsIDOMDocumentFragment** aReturn);
|
|
|
|
|
2012-01-20 04:03:49 -08:00
|
|
|
/**
|
|
|
|
* Parse a string into a document using the HTML parser.
|
|
|
|
* Script elements are marked unexecutable.
|
|
|
|
*
|
|
|
|
* @param aSourceBuffer the string to parse as an HTML document
|
|
|
|
* @param aTargetDocument the document object to parse into. Must not have
|
|
|
|
* child nodes.
|
2012-02-27 03:57:48 -08:00
|
|
|
* @param aScriptingEnabledForNoscriptParsing whether <noscript> is parsed
|
|
|
|
* as if scripting was enabled
|
2012-01-20 04:03:49 -08:00
|
|
|
* @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse
|
|
|
|
* fragments is made, NS_ERROR_OUT_OF_MEMORY if aSourceBuffer is too
|
|
|
|
* long and NS_OK otherwise.
|
|
|
|
*/
|
|
|
|
static nsresult ParseDocumentHTML(const nsAString& aSourceBuffer,
|
2012-02-27 03:57:48 -08:00
|
|
|
nsIDocument* aTargetDocument,
|
|
|
|
bool aScriptingEnabledForNoscriptParsing);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts HTML source to plain text by parsing the source and using the
|
|
|
|
* plain text serializer on the resulting tree.
|
|
|
|
*
|
|
|
|
* @param aSourceBuffer the string to parse as an HTML document
|
|
|
|
* @param aResultBuffer the string where the plain text result appears;
|
|
|
|
* may be the same string as aSourceBuffer
|
|
|
|
* @param aFlags Flags from nsIDocumentEncoder.
|
|
|
|
* @param aWrapCol Number of columns after which to line wrap; 0 for no
|
|
|
|
* auto-wrapping
|
|
|
|
* @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse
|
|
|
|
* fragments is made, NS_ERROR_OUT_OF_MEMORY if aSourceBuffer is too
|
|
|
|
* long and NS_OK otherwise.
|
|
|
|
*/
|
|
|
|
static nsresult ConvertToPlainText(const nsAString& aSourceBuffer,
|
|
|
|
nsAString& aResultBuffer,
|
|
|
|
PRUint32 aFlags,
|
|
|
|
PRUint32 aWrapCol);
|
2012-01-20 04:03:49 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-10-01 03:02:32 -07:00
|
|
|
* Creates a new XML document, which is marked to be loaded as data.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* @param aNamespaceURI Namespace for the root element to create and insert in
|
|
|
|
* the document. Only used if aQualifiedName is not
|
|
|
|
* empty.
|
|
|
|
* @param aQualifiedName Qualified name for the root element to create and
|
|
|
|
* insert in the document. If empty no root element will
|
|
|
|
* be created.
|
|
|
|
* @param aDoctype Doctype node to insert in the document.
|
|
|
|
* @param aDocumentURI URI of the document. Must not be null.
|
|
|
|
* @param aBaseURI Base URI of the document. Must not be null.
|
|
|
|
* @param aPrincipal Prinicpal of the document. Must not be null.
|
2007-10-01 03:02:32 -07:00
|
|
|
* @param aScriptObject The object from which the context for event handling
|
|
|
|
* can be got.
|
2011-11-15 23:38:51 -08:00
|
|
|
* @param aFlavor Select the kind of document to create.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aResult [out] The document that was created.
|
|
|
|
*/
|
|
|
|
static nsresult CreateDocument(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aQualifiedName,
|
|
|
|
nsIDOMDocumentType* aDoctype,
|
|
|
|
nsIURI* aDocumentURI,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aPrincipal,
|
2007-10-01 03:02:32 -07:00
|
|
|
nsIScriptGlobalObject* aScriptObject,
|
2011-11-15 23:38:51 -08:00
|
|
|
DocumentFlavor aFlavor,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDOMDocument** aResult);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the text contents of a node by replacing all existing children
|
|
|
|
* with a single text child.
|
|
|
|
*
|
|
|
|
* The function always notifies.
|
|
|
|
*
|
|
|
|
* Will reuse the first text child if one is available. Will not reuse
|
|
|
|
* existing cdata children.
|
|
|
|
*
|
|
|
|
* @param aContent Node to set contents of.
|
|
|
|
* @param aValue Value to set contents to.
|
|
|
|
* @param aTryReuse When true, the function will try to reuse an existing
|
|
|
|
* textnodes rather than always creating a new one.
|
|
|
|
*/
|
|
|
|
static nsresult SetNodeTextContent(nsIContent* aContent,
|
|
|
|
const nsAString& aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aTryReuse);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2007-10-30 00:19:42 -07:00
|
|
|
* Get the textual contents of a node. This is a concatenation of all
|
2007-03-22 10:30:00 -07:00
|
|
|
* textnodes that are direct or (depending on aDeep) indirect children
|
|
|
|
* of the node.
|
|
|
|
*
|
|
|
|
* NOTE! No serialization takes place and <br> elements
|
|
|
|
* are not converted into newlines. Only textnodes and cdata nodes are
|
|
|
|
* added to the result.
|
|
|
|
*
|
|
|
|
* @param aNode Node to get textual contents of.
|
|
|
|
* @param aDeep If true child elements of aNode are recursivly descended
|
|
|
|
* into to find text children.
|
|
|
|
* @param aResult the result. Out param.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static void GetNodeTextContent(nsINode* aNode, bool aDeep,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAString& aResult)
|
|
|
|
{
|
|
|
|
aResult.Truncate();
|
|
|
|
AppendNodeTextContent(aNode, aDeep, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as GetNodeTextContents but appends the result rather than sets it.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static void AppendNodeTextContent(nsINode* aNode, bool aDeep,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAString& aResult);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility method that checks if a given node has any non-empty
|
|
|
|
* children.
|
|
|
|
* NOTE! This method does not descend recursivly into elements.
|
|
|
|
* Though it would be easy to make it so if needed
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool HasNonEmptyTextContent(nsINode* aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete strings allocated for nsContentList matches
|
|
|
|
*/
|
|
|
|
static void DestroyMatchString(void* aData)
|
|
|
|
{
|
|
|
|
if (aData) {
|
2007-07-08 00:08:04 -07:00
|
|
|
nsString* matchString = static_cast<nsString*>(aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
delete matchString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbinds the content from the tree and nulls it out if it's not null.
|
|
|
|
*/
|
|
|
|
static void DestroyAnonymousContent(nsCOMPtr<nsIContent>* aContent);
|
|
|
|
|
2007-10-29 06:45:07 -07:00
|
|
|
/**
|
|
|
|
* Keep the JS objects held by aScriptObjectHolder alive.
|
|
|
|
*
|
|
|
|
* @param aScriptObjectHolder the object that holds JS objects that we want to
|
|
|
|
* keep alive
|
|
|
|
* @param aTracer the tracer for aScriptObject
|
|
|
|
*/
|
|
|
|
static nsresult HoldJSObjects(void* aScriptObjectHolder,
|
|
|
|
nsScriptObjectTracer* aTracer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drop the JS objects held by aScriptObjectHolder.
|
|
|
|
*
|
|
|
|
* @param aScriptObjectHolder the object that holds JS objects that we want to
|
|
|
|
* drop
|
|
|
|
*/
|
|
|
|
static nsresult DropJSObjects(void* aScriptObjectHolder);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-11-29 00:32:39 -08:00
|
|
|
#ifdef DEBUG
|
2012-07-06 10:28:51 -07:00
|
|
|
static bool AreJSObjectsHeld(void* aScriptObjectHolder);
|
|
|
|
|
2009-11-29 00:32:39 -08:00
|
|
|
static void CheckCCWrapperTraversal(nsISupports* aScriptObjectHolder,
|
|
|
|
nsWrapperCache* aCache);
|
|
|
|
#endif
|
|
|
|
|
2009-05-12 13:20:42 -07:00
|
|
|
static void PreserveWrapper(nsISupports* aScriptObjectHolder,
|
|
|
|
nsWrapperCache* aCache)
|
|
|
|
{
|
|
|
|
if (!aCache->PreservingWrapper()) {
|
|
|
|
nsXPCOMCycleCollectionParticipant* participant;
|
|
|
|
CallQueryInterface(aScriptObjectHolder, &participant);
|
|
|
|
HoldJSObjects(aScriptObjectHolder, participant);
|
2011-10-17 07:59:28 -07:00
|
|
|
aCache->SetPreservingWrapper(true);
|
2009-11-29 00:32:39 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Make sure the cycle collector will be able to traverse to the wrapper.
|
|
|
|
CheckCCWrapperTraversal(aScriptObjectHolder, aCache);
|
|
|
|
#endif
|
2009-05-12 13:20:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static void ReleaseWrapper(nsISupports* aScriptObjectHolder,
|
2011-05-26 12:58:35 -07:00
|
|
|
nsWrapperCache* aCache);
|
2009-05-12 13:20:42 -07:00
|
|
|
static void TraceWrapper(nsWrapperCache* aCache, TraceCallback aCallback,
|
2011-05-26 12:58:35 -07:00
|
|
|
void *aClosure);
|
2009-05-12 13:20:42 -07:00
|
|
|
|
2007-05-02 08:34:35 -07:00
|
|
|
/*
|
|
|
|
* Notify when the first XUL menu is opened and when the all XUL menus are
|
|
|
|
* closed. At opening, aInstalling should be TRUE, otherwise, it should be
|
|
|
|
* FALSE.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static void NotifyInstalledMenuKeyboardListener(bool aInstalling);
|
2007-06-12 14:56:06 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Do security checks before loading a resource. Does the following checks:
|
|
|
|
* nsIScriptSecurityManager::CheckLoadURIWithPrincipal
|
|
|
|
* NS_CheckContentLoadPolicy
|
|
|
|
* nsIScriptSecurityManager::CheckSameOriginURI
|
|
|
|
*
|
|
|
|
* You will still need to do at least SameOrigin checks before on redirects.
|
|
|
|
*
|
|
|
|
* @param aURIToLoad URI that is getting loaded.
|
|
|
|
* @param aLoadingPrincipal Principal of the resource that is initiating
|
|
|
|
* the load
|
|
|
|
* @param aCheckLoadFlags Flags to be passed to
|
|
|
|
* nsIScriptSecurityManager::CheckLoadURIWithPrincipal
|
|
|
|
* NOTE: If this contains ALLOW_CHROME the
|
|
|
|
* CheckSameOriginURI check will be skipped if
|
|
|
|
* aURIToLoad is a chrome uri.
|
|
|
|
* @param aAllowData Set to true to skip CheckSameOriginURI check when
|
|
|
|
aURIToLoad is a data uri.
|
|
|
|
* @param aContentPolicyType Type \
|
|
|
|
* @param aContext Context |- to be passed to
|
|
|
|
* @param aMimeGuess Mimetype | NS_CheckContentLoadPolicy
|
|
|
|
* @param aExtra Extra /
|
|
|
|
*/
|
|
|
|
static nsresult CheckSecurityBeforeLoad(nsIURI* aURIToLoad,
|
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
|
|
|
PRUint32 aCheckLoadFlags,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAllowData,
|
2007-06-12 14:56:06 -07:00
|
|
|
PRUint32 aContentPolicyType,
|
|
|
|
nsISupports* aContext,
|
|
|
|
const nsACString& aMimeGuess = EmptyCString(),
|
|
|
|
nsISupports* aExtra = nsnull);
|
|
|
|
|
2010-03-02 11:40:14 -08:00
|
|
|
/**
|
|
|
|
* Returns true if aPrincipal is the system principal.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsSystemPrincipal(nsIPrincipal* aPrincipal);
|
2010-03-02 11:40:14 -08:00
|
|
|
|
2012-04-29 20:11:00 -07:00
|
|
|
/**
|
|
|
|
* *aResourcePrincipal is a principal describing who may access the contents
|
|
|
|
* of a resource. The resource can only be consumed by a principal that
|
|
|
|
* subsumes *aResourcePrincipal. MAKE SURE THAT NOTHING EVER ACTS WITH THE
|
|
|
|
* AUTHORITY OF *aResourcePrincipal.
|
|
|
|
* It may be null to indicate that the resource has no data from any origin
|
|
|
|
* in it yet and anything may access the resource.
|
|
|
|
* Additional data is being mixed into the resource from aExtraPrincipal
|
|
|
|
* (which may be null; if null, no data is being mixed in and this function
|
|
|
|
* will do nothing). Update *aResourcePrincipal to reflect the new data.
|
|
|
|
* If *aResourcePrincipal subsumes aExtraPrincipal, nothing needs to change,
|
|
|
|
* otherwise *aResourcePrincipal is replaced with the system principal.
|
|
|
|
* Returns true if *aResourcePrincipal changed.
|
|
|
|
*/
|
|
|
|
static bool CombineResourcePrincipals(nsCOMPtr<nsIPrincipal>* aResourcePrincipal,
|
|
|
|
nsIPrincipal* aExtraPrincipal);
|
|
|
|
|
2007-07-11 06:05:05 -07:00
|
|
|
/**
|
|
|
|
* Trigger a link with uri aLinkURI. If aClick is false, this triggers a
|
|
|
|
* mouseover on the link, otherwise it triggers a load after doing a
|
|
|
|
* security check using aContent's principal.
|
|
|
|
*
|
|
|
|
* @param aContent the node on which a link was triggered.
|
|
|
|
* @param aPresContext the pres context, must be non-null.
|
|
|
|
* @param aLinkURI the URI of the link, must be non-null.
|
|
|
|
* @param aTargetSpec the target (like target=, may be empty).
|
|
|
|
* @param aClick whether this was a click or not (if false, this method
|
|
|
|
* assumes you just hovered over the link).
|
|
|
|
* @param aIsUserTriggered whether the user triggered the link. This would be
|
|
|
|
* false for loads from auto XLinks or from the
|
|
|
|
* click() method if we ever implement it.
|
2011-10-17 07:59:28 -07:00
|
|
|
* @param aIsTrusted If false, JS Context will be pushed to stack
|
2011-06-30 04:52:11 -07:00
|
|
|
* when the link is triggered.
|
2007-07-11 06:05:05 -07:00
|
|
|
*/
|
|
|
|
static void TriggerLink(nsIContent *aContent, nsPresContext *aPresContext,
|
|
|
|
nsIURI *aLinkURI, const nsString& aTargetSpec,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aClick, bool aIsUserTriggered,
|
|
|
|
bool aIsTrusted);
|
2007-07-11 06:05:05 -07:00
|
|
|
|
2012-05-23 23:57:16 -07:00
|
|
|
/**
|
|
|
|
* Get the link location.
|
|
|
|
*/
|
|
|
|
static void GetLinkLocation(mozilla::dom::Element* aElement,
|
|
|
|
nsString& aLocationString);
|
|
|
|
|
2007-11-16 00:21:44 -08:00
|
|
|
/**
|
|
|
|
* Return top-level widget in the parent chain.
|
|
|
|
*/
|
|
|
|
static nsIWidget* GetTopLevelWidget(nsIWidget* aWidget);
|
2007-10-12 11:37:51 -07:00
|
|
|
|
2007-11-19 02:17:17 -08:00
|
|
|
/**
|
|
|
|
* Return the localized ellipsis for UI.
|
|
|
|
*/
|
|
|
|
static const nsDependentString GetLocalizedEllipsis();
|
|
|
|
|
2007-12-17 21:41:56 -08:00
|
|
|
/**
|
2008-10-15 03:50:42 -07:00
|
|
|
* The routine GetNativeEvent is used to fill nsNativeKeyEvent.
|
|
|
|
* It's also used in DOMEventToNativeKeyEvent.
|
2007-12-17 21:41:56 -08:00
|
|
|
* See bug 406407 for details.
|
|
|
|
*/
|
|
|
|
static nsEvent* GetNativeEvent(nsIDOMEvent* aDOMEvent);
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool DOMEventToNativeKeyEvent(nsIDOMKeyEvent* aKeyEvent,
|
2007-12-17 21:41:56 -08:00
|
|
|
nsNativeKeyEvent* aNativeEvent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aGetCharCode);
|
2007-12-17 21:41:56 -08:00
|
|
|
|
2008-04-14 21:16:24 -07:00
|
|
|
/**
|
2008-09-15 18:37:13 -07:00
|
|
|
* Get the candidates for accelkeys for aDOMKeyEvent.
|
2008-04-14 21:16:24 -07:00
|
|
|
*
|
2008-09-15 18:37:13 -07:00
|
|
|
* @param aDOMKeyEvent [in] the key event for accelkey handling.
|
2008-04-14 21:16:24 -07:00
|
|
|
* @param aCandidates [out] the candidate shortcut key combination list.
|
|
|
|
* the first item is most preferred.
|
|
|
|
*/
|
2008-09-15 18:37:13 -07:00
|
|
|
static void GetAccelKeyCandidates(nsIDOMKeyEvent* aDOMKeyEvent,
|
2008-04-14 21:16:24 -07:00
|
|
|
nsTArray<nsShortcutCandidate>& aCandidates);
|
|
|
|
|
|
|
|
/**
|
2008-09-15 18:37:13 -07:00
|
|
|
* Get the candidates for accesskeys for aNativeKeyEvent.
|
2008-04-14 21:16:24 -07:00
|
|
|
*
|
2008-09-15 18:37:13 -07:00
|
|
|
* @param aNativeKeyEvent [in] the key event for accesskey handling.
|
2008-04-14 21:16:24 -07:00
|
|
|
* @param aCandidates [out] the candidate access key list.
|
|
|
|
* the first item is most preferred.
|
|
|
|
*/
|
|
|
|
static void GetAccessKeyCandidates(nsKeyEvent* aNativeKeyEvent,
|
|
|
|
nsTArray<PRUint32>& aCandidates);
|
|
|
|
|
2008-02-08 12:23:05 -08:00
|
|
|
/**
|
|
|
|
* Hide any XUL popups associated with aDocument, including any documents
|
2009-10-23 13:24:47 -07:00
|
|
|
* displayed in child frames. Does nothing if aDocument is null.
|
2008-02-08 12:23:05 -08:00
|
|
|
*/
|
|
|
|
static void HidePopupsInDocument(nsIDocument* aDocument);
|
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
/**
|
|
|
|
* Retrieve the current drag session, or null if no drag is currently occuring
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsIDragSession> GetDragSession();
|
|
|
|
|
2009-06-24 10:12:33 -07:00
|
|
|
/*
|
|
|
|
* Initialize and set the dataTransfer field of an nsDragEvent.
|
|
|
|
*/
|
|
|
|
static nsresult SetDataTransferInEvent(nsDragEvent* aDragEvent);
|
|
|
|
|
|
|
|
// filters the drag and drop action to fit within the effects allowed and
|
|
|
|
// returns it.
|
|
|
|
static PRUint32 FilterDropEffect(PRUint32 aAction, PRUint32 aEffectAllowed);
|
|
|
|
|
2012-03-20 08:21:41 -07:00
|
|
|
/*
|
|
|
|
* Return true if the target of a drop event is a content document that is
|
|
|
|
* an ancestor of the document for the source of the drag.
|
|
|
|
*/
|
|
|
|
static bool CheckForSubFrameDrop(nsIDragSession* aDragSession,
|
|
|
|
nsDragEvent* aDropEvent);
|
|
|
|
|
2008-03-22 09:50:47 -07:00
|
|
|
/**
|
|
|
|
* Return true if aURI is a local file URI (i.e. file://).
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool URIIsLocalFile(nsIURI *aURI);
|
2008-03-22 09:50:47 -07:00
|
|
|
|
2011-03-31 09:35:04 -07:00
|
|
|
/**
|
|
|
|
* Given a URI, return set beforeHash to the part before the '#', and
|
|
|
|
* afterHash to the remainder of the URI, including the '#'.
|
|
|
|
*/
|
|
|
|
static nsresult SplitURIAtHash(nsIURI *aURI,
|
|
|
|
nsACString &aBeforeHash,
|
|
|
|
nsACString &aAfterHash);
|
|
|
|
|
2008-01-16 13:54:33 -08:00
|
|
|
/**
|
2008-11-05 16:01:07 -08:00
|
|
|
* Get the application manifest URI for this document. The manifest URI
|
2008-01-16 13:54:33 -08:00
|
|
|
* is specified in the manifest= attribute of the root element of the
|
2008-11-05 16:01:07 -08:00
|
|
|
* document.
|
2008-01-16 13:54:33 -08:00
|
|
|
*
|
2008-11-05 16:01:07 -08:00
|
|
|
* @param aDocument The document that lists the manifest.
|
2008-01-16 13:54:33 -08:00
|
|
|
* @param aURI The manifest URI.
|
|
|
|
*/
|
2008-11-05 16:01:07 -08:00
|
|
|
static void GetOfflineAppManifest(nsIDocument *aDocument, nsIURI **aURI);
|
2008-01-16 13:54:33 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether an application should be allowed to use offline APIs.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool OfflineAppAllowed(nsIURI *aURI);
|
2008-01-16 13:54:33 -08:00
|
|
|
|
2008-08-27 18:15:32 -07:00
|
|
|
/**
|
|
|
|
* Check whether an application should be allowed to use offline APIs.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool OfflineAppAllowed(nsIPrincipal *aPrincipal);
|
2008-08-27 18:15:32 -07:00
|
|
|
|
2008-03-14 16:08:57 -07:00
|
|
|
/**
|
|
|
|
* Increases the count of blockers preventing scripts from running.
|
|
|
|
* NOTE: You might want to use nsAutoScriptBlocker rather than calling
|
|
|
|
* this directly
|
|
|
|
*/
|
|
|
|
static void AddScriptBlocker();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decreases the count of blockers preventing scripts from running.
|
|
|
|
* NOTE: You might want to use nsAutoScriptBlocker rather than calling
|
|
|
|
* this directly
|
|
|
|
*
|
|
|
|
* WARNING! Calling this function could synchronously execute scripts.
|
|
|
|
*/
|
|
|
|
static void RemoveScriptBlocker();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a runnable that is to be executed as soon as it's safe to execute
|
|
|
|
* scripts.
|
|
|
|
* NOTE: If it's currently safe to execute scripts, aRunnable will be run
|
|
|
|
* synchronously before the function returns.
|
|
|
|
*
|
|
|
|
* @param aRunnable The nsIRunnable to run as soon as it's safe to execute
|
|
|
|
* scripts. Passing null is allowed and results in nothing
|
|
|
|
* happening. It is also allowed to pass an object that
|
|
|
|
* has not yet been AddRefed.
|
2009-01-29 11:46:17 -08:00
|
|
|
* @return false on out of memory, true otherwise.
|
2008-03-14 16:08:57 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool AddScriptRunner(nsIRunnable* aRunnable);
|
2008-03-14 16:08:57 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if it's safe to execute content script and false otherwise.
|
|
|
|
*
|
|
|
|
* The only known case where this lies is mutation events. They run, and can
|
|
|
|
* run anything else, when this function returns false, but this is ok.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsSafeToRunScript() {
|
2008-03-14 16:08:57 -07:00
|
|
|
return sScriptBlockerCount == 0;
|
|
|
|
}
|
|
|
|
|
2012-01-30 14:52:11 -08:00
|
|
|
/**
|
|
|
|
* Retrieve information about the viewport as a data structure.
|
|
|
|
* This will return information in the viewport META data section
|
|
|
|
* of the document. This can be used in lieu of ProcessViewportInfo(),
|
|
|
|
* which places the viewport information in the document header instead
|
|
|
|
* of returning it directly.
|
|
|
|
*
|
|
|
|
* NOTE: If the site is optimized for mobile (via the doctype), this
|
|
|
|
* will return viewport information that specifies default information.
|
|
|
|
*/
|
|
|
|
static ViewportInfo GetViewportInfo(nsIDocument* aDocument);
|
|
|
|
|
2012-03-31 09:30:13 -07:00
|
|
|
// Call EnterMicroTask when you're entering JS execution.
|
|
|
|
// Usually the best way to do this is to use nsAutoMicroTask.
|
|
|
|
static void EnterMicroTask() { ++sMicroTaskLevel; }
|
|
|
|
static void LeaveMicroTask();
|
|
|
|
|
|
|
|
static bool IsInMicroTask() { return sMicroTaskLevel != 0; }
|
|
|
|
static PRUint32 MicroTaskLevel() { return sMicroTaskLevel; }
|
|
|
|
static void SetMicroTaskLevel(PRUint32 aLevel) { sMicroTaskLevel = aLevel; }
|
|
|
|
|
2008-07-16 20:16:23 -07:00
|
|
|
/* Process viewport META data. This gives us information for the scale
|
|
|
|
* and zoom of a page on mobile devices. We stick the information in
|
|
|
|
* the document header and use it later on after rendering.
|
|
|
|
*
|
|
|
|
* See Bug #436083
|
|
|
|
*/
|
|
|
|
static nsresult ProcessViewportInfo(nsIDocument *aDocument,
|
|
|
|
const nsAString &viewportInfo);
|
|
|
|
|
2009-04-24 02:18:37 -07:00
|
|
|
static nsIScriptContext* GetContextForEventHandlers(nsINode* aNode,
|
|
|
|
nsresult* aRv);
|
2008-09-05 14:51:24 -07:00
|
|
|
|
|
|
|
static JSContext *GetCurrentJSContext();
|
2012-06-20 03:18:39 -07:00
|
|
|
static JSContext *GetSafeJSContext();
|
2008-09-05 14:51:24 -07:00
|
|
|
|
2010-03-08 07:45:00 -08:00
|
|
|
/**
|
|
|
|
* Case insensitive comparison between two strings. However it only ignores
|
|
|
|
* case for ASCII characters a-z.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool EqualsIgnoreASCIICase(const nsAString& aStr1,
|
2012-03-09 21:50:34 -08:00
|
|
|
const nsAString& aStr2);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Case insensitive comparison between a string and an ASCII literal.
|
|
|
|
* This must ONLY be applied to an actual literal string. Do not attempt
|
|
|
|
* to use it with a regular char* pointer, or with a char array variable.
|
|
|
|
* The template trick to acquire the array length at compile time without
|
|
|
|
* using a macro is due to Corey Kosak, which much thanks.
|
|
|
|
*/
|
|
|
|
static bool EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
|
|
|
|
const char* aStr2,
|
|
|
|
const PRUint32 len);
|
|
|
|
#ifdef NS_DISABLE_LITERAL_TEMPLATE
|
|
|
|
static inline bool
|
|
|
|
EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
|
|
|
|
const char* aStr2)
|
|
|
|
{
|
|
|
|
PRUint32 len = strlen(aStr2);
|
|
|
|
return EqualsLiteralIgnoreASCIICase(aStr1, aStr2, len);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
template<int N>
|
|
|
|
static inline bool
|
|
|
|
EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
|
|
|
|
const char (&aStr2)[N])
|
|
|
|
{
|
|
|
|
return EqualsLiteralIgnoreASCIICase(aStr1, aStr2, N-1);
|
|
|
|
}
|
|
|
|
template<int N>
|
|
|
|
static inline bool
|
|
|
|
EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
|
|
|
|
char (&aStr2)[N])
|
|
|
|
{
|
|
|
|
const char* s = aStr2;
|
|
|
|
return EqualsLiteralIgnoreASCIICase(aStr1, s, N-1);
|
|
|
|
}
|
|
|
|
#endif
|
2010-03-08 07:45:00 -08:00
|
|
|
|
2010-02-23 09:38:10 -08:00
|
|
|
/**
|
|
|
|
* Convert ASCII A-Z to a-z.
|
2012-03-20 11:02:38 -07:00
|
|
|
* @return NS_OK on success, or NS_ERROR_OUT_OF_MEMORY if making the string
|
|
|
|
* writable needs to allocate memory and that allocation fails.
|
2010-02-23 09:38:10 -08:00
|
|
|
*/
|
2012-03-20 11:02:38 -07:00
|
|
|
static nsresult ASCIIToLower(nsAString& aStr);
|
|
|
|
static nsresult ASCIIToLower(const nsAString& aSource, nsAString& aDest);
|
2010-02-23 09:38:10 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert ASCII a-z to A-Z.
|
2012-03-20 11:02:38 -07:00
|
|
|
* @return NS_OK on success, or NS_ERROR_OUT_OF_MEMORY if making the string
|
|
|
|
* writable needs to allocate memory and that allocation fails.
|
2010-02-23 09:38:10 -08:00
|
|
|
*/
|
2012-03-20 11:02:38 -07:00
|
|
|
static nsresult ASCIIToUpper(nsAString& aStr);
|
|
|
|
static nsresult ASCIIToUpper(const nsAString& aSource, nsAString& aDest);
|
2010-02-23 09:38:10 -08:00
|
|
|
|
2012-07-13 16:29:14 -07:00
|
|
|
/**
|
|
|
|
* Return whether aStr contains an ASCII uppercase character.
|
|
|
|
*/
|
|
|
|
static bool StringContainsASCIIUpper(const nsAString& aStr);
|
|
|
|
|
2010-12-03 07:46:10 -08:00
|
|
|
// Returns NS_OK for same origin, error (NS_ERROR_DOM_BAD_URI) if not.
|
|
|
|
static nsresult CheckSameOrigin(nsIChannel *aOldChannel, nsIChannel *aNewChannel);
|
2008-09-07 18:13:02 -07:00
|
|
|
static nsIInterfaceRequestor* GetSameOriginChecker();
|
2008-10-08 04:35:29 -07:00
|
|
|
|
|
|
|
static nsIThreadJSContextStack* ThreadJSContextStack()
|
|
|
|
{
|
|
|
|
return sThreadJSContextStack;
|
|
|
|
}
|
2012-03-30 10:22:29 -07:00
|
|
|
|
|
|
|
// Trace the safe JS context of the ThreadJSContextStack.
|
|
|
|
static void TraceSafeJSContext(JSTracer* aTrc);
|
|
|
|
|
2009-01-21 14:50:28 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Origin of the passed in nsIPrincipal or nsIURI. If the passed in
|
|
|
|
* nsIURI or the URI of the passed in nsIPrincipal does not have a host, the
|
|
|
|
* origin is set to 'null'.
|
|
|
|
*
|
|
|
|
* The ASCII versions return a ASCII strings that are puny-code encoded,
|
2010-04-02 09:43:14 -07:00
|
|
|
* suitable for, for example, header values. The UTF versions return strings
|
2009-01-21 14:50:28 -08:00
|
|
|
* containing international characters.
|
|
|
|
*
|
2010-04-02 09:43:14 -07:00
|
|
|
* @pre aPrincipal/aOrigin must not be null.
|
|
|
|
*
|
|
|
|
* @note this should be used for HTML5 origin determination.
|
2009-01-21 14:50:28 -08:00
|
|
|
*/
|
|
|
|
static nsresult GetASCIIOrigin(nsIPrincipal* aPrincipal,
|
|
|
|
nsCString& aOrigin);
|
|
|
|
static nsresult GetASCIIOrigin(nsIURI* aURI, nsCString& aOrigin);
|
|
|
|
static nsresult GetUTFOrigin(nsIPrincipal* aPrincipal,
|
|
|
|
nsString& aOrigin);
|
|
|
|
static nsresult GetUTFOrigin(nsIURI* aURI, nsString& aOrigin);
|
|
|
|
|
2009-06-30 00:56:40 -07:00
|
|
|
/**
|
|
|
|
* This method creates and dispatches "command" event, which implements
|
|
|
|
* nsIDOMXULCommandEvent.
|
|
|
|
* If aShell is not null, dispatching goes via
|
|
|
|
* nsIPresShell::HandleDOMEventWithTarget.
|
|
|
|
*/
|
|
|
|
static nsresult DispatchXULCommand(nsIContent* aTarget,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aTrusted,
|
2009-06-30 00:56:40 -07:00
|
|
|
nsIDOMEvent* aSourceEvent = nsnull,
|
|
|
|
nsIPresShell* aShell = nsnull,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCtrl = false,
|
|
|
|
bool aAlt = false,
|
|
|
|
bool aShift = false,
|
|
|
|
bool aMeta = false);
|
2009-06-30 00:56:40 -07:00
|
|
|
|
2009-06-15 01:27:29 -07:00
|
|
|
/**
|
|
|
|
* Gets the nsIDocument given the script context. Will return nsnull on failure.
|
|
|
|
*
|
|
|
|
* @param aScriptContext the script context to get the document for; can be null
|
|
|
|
*
|
|
|
|
* @return the document associated with the script context
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsIDocument>
|
|
|
|
GetDocumentFromScriptContext(nsIScriptContext *aScriptContext);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool CheckMayLoad(nsIPrincipal* aPrincipal, nsIChannel* aChannel);
|
2010-06-17 04:27:52 -07:00
|
|
|
|
2009-06-28 12:46:52 -07:00
|
|
|
/**
|
|
|
|
* The method checks whether the caller can access native anonymous content.
|
|
|
|
* If there is no JS in the stack or privileged JS is running, this
|
2011-10-17 07:59:28 -07:00
|
|
|
* method returns true, otherwise false.
|
2009-06-28 12:46:52 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool CanAccessNativeAnon();
|
2009-08-14 12:00:24 -07:00
|
|
|
|
|
|
|
static nsresult WrapNative(JSContext *cx, JSObject *scope,
|
|
|
|
nsISupports *native, const nsIID* aIID, jsval *vp,
|
|
|
|
// If non-null aHolder will keep the jsval alive
|
|
|
|
// while there's a ref to it
|
|
|
|
nsIXPConnectJSObjectHolder** aHolder = nsnull,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAllowWrapping = false)
|
2010-05-10 11:53:05 -07:00
|
|
|
{
|
|
|
|
return WrapNative(cx, scope, native, nsnull, aIID, vp, aHolder,
|
|
|
|
aAllowWrapping);
|
|
|
|
}
|
2009-08-14 12:00:24 -07:00
|
|
|
|
|
|
|
// Same as the WrapNative above, but use this one if aIID is nsISupports' IID.
|
|
|
|
static nsresult WrapNative(JSContext *cx, JSObject *scope,
|
2010-05-10 11:53:05 -07:00
|
|
|
nsISupports *native, jsval *vp,
|
|
|
|
// If non-null aHolder will keep the jsval alive
|
|
|
|
// while there's a ref to it
|
|
|
|
nsIXPConnectJSObjectHolder** aHolder = nsnull,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAllowWrapping = false)
|
2010-05-10 11:53:05 -07:00
|
|
|
{
|
|
|
|
return WrapNative(cx, scope, native, nsnull, nsnull, vp, aHolder,
|
|
|
|
aAllowWrapping);
|
|
|
|
}
|
|
|
|
static nsresult WrapNative(JSContext *cx, JSObject *scope,
|
|
|
|
nsISupports *native, nsWrapperCache *cache,
|
|
|
|
jsval *vp,
|
2009-08-14 12:00:24 -07:00
|
|
|
// If non-null aHolder will keep the jsval alive
|
|
|
|
// while there's a ref to it
|
|
|
|
nsIXPConnectJSObjectHolder** aHolder = nsnull,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAllowWrapping = false)
|
2009-08-14 12:00:24 -07:00
|
|
|
{
|
2010-05-10 11:53:05 -07:00
|
|
|
return WrapNative(cx, scope, native, cache, nsnull, vp, aHolder,
|
|
|
|
aAllowWrapping);
|
2009-08-14 12:00:24 -07:00
|
|
|
}
|
|
|
|
|
2011-12-15 15:19:01 -08:00
|
|
|
/**
|
|
|
|
* Creates an arraybuffer from a binary string.
|
|
|
|
*/
|
|
|
|
static nsresult CreateArrayBuffer(JSContext *aCx, const nsACString& aData,
|
|
|
|
JSObject** aResult);
|
|
|
|
|
2010-03-03 04:41:57 -08:00
|
|
|
static void StripNullChars(const nsAString& aInStr, nsAString& aOutStr);
|
2010-03-17 12:55:45 -07:00
|
|
|
|
2010-02-22 16:15:56 -08:00
|
|
|
/**
|
|
|
|
* Strip all \n, \r and nulls from the given string
|
|
|
|
* @param aString the string to remove newlines from [in/out]
|
|
|
|
*/
|
|
|
|
static void RemoveNewlines(nsString &aString);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert Windows and Mac platform linebreaks to \n.
|
|
|
|
* @param aString the string to convert the newlines inside [in/out]
|
|
|
|
*/
|
|
|
|
static void PlatformToDOMLineBreaks(nsString &aString);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsHandlingKeyBoardEvent()
|
2010-04-24 03:40:48 -07:00
|
|
|
{
|
|
|
|
return sIsHandlingKeyBoardEvent;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static void SetIsHandlingKeyBoardEvent(bool aHandling)
|
2010-04-24 03:40:48 -07:00
|
|
|
{
|
|
|
|
sIsHandlingKeyBoardEvent = aHandling;
|
|
|
|
}
|
2010-04-19 08:41:37 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility method for getElementsByClassName. aRootNode is the node (either
|
|
|
|
* document or element), which getElementsByClassName was called on.
|
|
|
|
*/
|
|
|
|
static nsresult GetElementsByClassName(nsINode* aRootNode,
|
|
|
|
const nsAString& aClasses,
|
|
|
|
nsIDOMNodeList** aReturn);
|
|
|
|
|
2012-01-31 13:55:54 -08:00
|
|
|
/**
|
|
|
|
* Returns the widget for this document if there is one. Looks at all ancestor
|
|
|
|
* documents to try to find a widget, so for example this can still find a
|
|
|
|
* widget for documents in display:none frames that have no presentation.
|
|
|
|
*/
|
|
|
|
static nsIWidget *WidgetForDocument(nsIDocument *aDoc);
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
/**
|
|
|
|
* Returns a layer manager to use for the given document. Basically we
|
|
|
|
* look up the document hierarchy for the first document which has
|
|
|
|
* a presentation with an associated widget, and use that widget's
|
|
|
|
* layer manager.
|
|
|
|
*
|
|
|
|
* @param aDoc the document for which to return a layer manager.
|
2011-03-02 00:53:27 -08:00
|
|
|
* @param aAllowRetaining an outparam that states whether the returned
|
|
|
|
* layer manager should be used for retained layers
|
2010-05-17 21:04:22 -07:00
|
|
|
*/
|
|
|
|
static already_AddRefed<mozilla::layers::LayerManager>
|
2011-03-02 00:53:27 -08:00
|
|
|
LayerManagerForDocument(nsIDocument *aDoc, bool *aAllowRetaining = nsnull);
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2010-12-06 18:05:52 -08:00
|
|
|
/**
|
|
|
|
* Returns a layer manager to use for the given document. Basically we
|
|
|
|
* look up the document hierarchy for the first document which has
|
|
|
|
* a presentation with an associated widget, and use that widget's
|
|
|
|
* layer manager. In addition to the normal layer manager lookup this will
|
|
|
|
* specifically request a persistent layer manager. This means that the layer
|
|
|
|
* manager is expected to remain the layer manager for the document in the
|
|
|
|
* forseeable future. This function should be used carefully as it may change
|
|
|
|
* the document's layer manager.
|
|
|
|
*
|
|
|
|
* @param aDoc the document for which to return a layer manager.
|
2011-03-02 00:53:27 -08:00
|
|
|
* @param aAllowRetaining an outparam that states whether the returned
|
|
|
|
* layer manager should be used for retained layers
|
2010-12-06 18:05:52 -08:00
|
|
|
*/
|
|
|
|
static already_AddRefed<mozilla::layers::LayerManager>
|
2011-03-02 00:53:27 -08:00
|
|
|
PersistentLayerManagerForDocument(nsIDocument *aDoc, bool *aAllowRetaining = nsnull);
|
2010-12-06 18:05:52 -08:00
|
|
|
|
2010-04-21 13:17:41 -07:00
|
|
|
/**
|
|
|
|
* Determine whether a content node is focused or not,
|
|
|
|
*
|
|
|
|
* @param aContent the content node to check
|
|
|
|
* @return true if the content node is focused, false otherwise.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsFocusedContent(const nsIContent *aContent);
|
2010-10-08 03:20:20 -07:00
|
|
|
|
2011-09-04 13:39:05 -07:00
|
|
|
/**
|
2011-10-17 07:59:28 -07:00
|
|
|
* Returns true if the DOM full-screen API is enabled.
|
2011-09-04 13:39:05 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsFullScreenApiEnabled();
|
2011-09-04 13:39:05 -07:00
|
|
|
|
2011-09-04 13:40:18 -07:00
|
|
|
/**
|
2011-10-17 07:59:28 -07:00
|
|
|
* Returns true if requests for full-screen are allowed in the current
|
2011-09-04 13:40:18 -07:00
|
|
|
* context. Requests are only allowed if the user initiated them (like with
|
|
|
|
* a mouse-click or key press), unless this check has been disabled by
|
|
|
|
* setting the pref "full-screen-api.allow-trusted-requests-only" to false.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsRequestFullScreenAllowed();
|
2011-09-04 13:40:18 -07:00
|
|
|
|
2012-06-29 01:32:21 -07:00
|
|
|
/**
|
|
|
|
* Returns true if the idle observers API is enabled.
|
|
|
|
*/
|
|
|
|
static bool IsIdleObserverAPIEnabled() { return sIsIdleObserverAPIEnabled; }
|
|
|
|
|
2011-10-26 19:57:09 -07:00
|
|
|
/**
|
2011-11-15 18:09:01 -08:00
|
|
|
* Returns true if the doc tree branch which contains aDoc contains any
|
|
|
|
* plugins which we don't control event dispatch for, i.e. do any plugins
|
|
|
|
* in the same tab as this document receive key events outside of our
|
|
|
|
* control? This always returns false on MacOSX.
|
2011-10-26 19:57:09 -07:00
|
|
|
*/
|
|
|
|
static bool HasPluginWithUncontrolledEventDispatch(nsIDocument* aDoc);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the content is in a document and contains a plugin
|
|
|
|
* which we don't control event dispatch for, i.e. do any plugins in this
|
|
|
|
* doc tree receive key events outside of our control? This always returns
|
|
|
|
* false on MacOSX.
|
|
|
|
*/
|
|
|
|
static bool HasPluginWithUncontrolledEventDispatch(nsIContent* aContent);
|
|
|
|
|
2011-11-14 12:33:37 -08:00
|
|
|
/**
|
|
|
|
* Returns the root document in a document hierarchy. Normally this will
|
|
|
|
* be the chrome document.
|
|
|
|
*/
|
|
|
|
static nsIDocument* GetRootDocument(nsIDocument* aDoc);
|
|
|
|
|
2011-09-06 13:14:59 -07:00
|
|
|
/**
|
|
|
|
* Returns the time limit on handling user input before
|
2011-10-17 07:59:28 -07:00
|
|
|
* nsEventStateManager::IsHandlingUserInput() stops returning true.
|
2011-09-06 13:14:59 -07:00
|
|
|
* This enables us to detect long running user-generated event handlers.
|
|
|
|
*/
|
|
|
|
static TimeDuration HandlingUserInputTimeout();
|
|
|
|
|
2011-07-31 12:43:54 -07:00
|
|
|
static void GetShiftText(nsAString& text);
|
|
|
|
static void GetControlText(nsAString& text);
|
|
|
|
static void GetMetaText(nsAString& text);
|
2012-07-18 18:28:16 -07:00
|
|
|
static void GetOSText(nsAString& text);
|
2011-07-31 12:43:54 -07:00
|
|
|
static void GetAltText(nsAString& text);
|
|
|
|
static void GetModifierSeparatorText(nsAString& text);
|
|
|
|
|
2010-10-08 03:20:20 -07:00
|
|
|
/**
|
|
|
|
* Returns if aContent has a tabbable subdocument.
|
|
|
|
* A sub document isn't tabbable when it's a zombie document.
|
|
|
|
*
|
|
|
|
* @param aElement element to test.
|
|
|
|
*
|
|
|
|
* @return Whether the subdocument is tabbable.
|
|
|
|
*/
|
|
|
|
static bool IsSubDocumentTabbable(nsIContent* aContent);
|
2010-11-03 05:57:15 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flushes the layout tree (recursively)
|
|
|
|
*
|
|
|
|
* @param aWindow the window the flush should start at
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void FlushLayoutForTree(nsIDOMWindow* aWindow);
|
2010-04-21 13:17:41 -07:00
|
|
|
|
2010-11-23 00:50:55 -08:00
|
|
|
/**
|
|
|
|
* Returns true if content with the given principal is allowed to use XUL
|
|
|
|
* and XBL and false otherwise.
|
|
|
|
*/
|
|
|
|
static bool AllowXULXBLForPrincipal(nsIPrincipal* aPrincipal);
|
|
|
|
|
2011-08-01 00:48:24 -07:00
|
|
|
/**
|
|
|
|
* Perform cleanup that's appropriate for XPCOM shutdown.
|
|
|
|
*/
|
|
|
|
static void XPCOMShutdown();
|
|
|
|
|
2011-04-14 13:58:36 -07:00
|
|
|
enum ContentViewerType
|
|
|
|
{
|
|
|
|
TYPE_UNSUPPORTED,
|
|
|
|
TYPE_CONTENT,
|
|
|
|
TYPE_PLUGIN,
|
|
|
|
TYPE_UNKNOWN
|
|
|
|
};
|
|
|
|
|
|
|
|
static already_AddRefed<nsIDocumentLoaderFactory>
|
|
|
|
FindInternalContentViewer(const char* aType,
|
|
|
|
ContentViewerType* aLoaderType = nsnull);
|
|
|
|
|
2011-04-28 10:21:37 -07:00
|
|
|
/**
|
|
|
|
* This helper method returns true if the aPattern pattern matches aValue.
|
|
|
|
* aPattern should not contain leading and trailing slashes (/).
|
|
|
|
* The pattern has to match the entire value not just a subset.
|
|
|
|
* aDocument must be a valid pointer (not null).
|
|
|
|
*
|
|
|
|
* This is following the HTML5 specification:
|
|
|
|
* http://dev.w3.org/html5/spec/forms.html#attr-input-pattern
|
|
|
|
*
|
|
|
|
* WARNING: This method mutates aPattern and aValue!
|
|
|
|
*
|
|
|
|
* @param aValue the string to check.
|
|
|
|
* @param aPattern the string defining the pattern.
|
|
|
|
* @param aDocument the owner document of the element.
|
|
|
|
* @result whether the given string is matches the pattern.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsPatternMatching(nsAString& aValue, nsAString& aPattern,
|
2011-04-28 10:21:37 -07:00
|
|
|
nsIDocument* aDocument);
|
|
|
|
|
2011-04-26 05:30:17 -07:00
|
|
|
/**
|
|
|
|
* Calling this adds support for
|
|
|
|
* ontouch* event handler DOM attributes.
|
|
|
|
*/
|
|
|
|
static void InitializeTouchEventTable();
|
2011-06-25 02:52:00 -07:00
|
|
|
|
2011-09-20 14:00:42 -07:00
|
|
|
/**
|
|
|
|
* Test whether the given URI always inherits a security context
|
|
|
|
* from the document it comes from.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static nsresult URIInheritsSecurityContext(nsIURI *aURI, bool *aResult);
|
2011-09-20 14:00:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the given principal as the owner of the given channel, if
|
|
|
|
* needed. aURI must be the URI of aChannel. aPrincipal may be
|
|
|
|
* null. If aSetUpForAboutBlank is true, then about:blank will get
|
|
|
|
* the principal set up on it.
|
|
|
|
*
|
|
|
|
* The return value is whether the principal was set up as the owner
|
|
|
|
* of the channel.
|
|
|
|
*/
|
|
|
|
static bool SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsIURI* aURI,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aSetUpForAboutBlank);
|
2011-09-20 14:00:42 -07:00
|
|
|
|
2011-06-25 02:52:00 -07:00
|
|
|
static nsresult Btoa(const nsAString& aBinaryData,
|
|
|
|
nsAString& aAsciiBase64String);
|
|
|
|
|
|
|
|
static nsresult Atob(const nsAString& aAsciiString,
|
|
|
|
nsAString& aBinaryData);
|
2011-11-20 10:02:47 -08:00
|
|
|
|
2012-03-31 09:30:13 -07:00
|
|
|
/** If aJSArray is a Javascript array, this method iterates over its
|
|
|
|
* elements and appends values to aRetVal as nsIAtoms.
|
|
|
|
* @throw NS_ERROR_ILLEGAL_VALUE if aJSArray isn't a JS array.
|
|
|
|
*/
|
|
|
|
static nsresult JSArrayToAtomArray(JSContext* aCx, const JS::Value& aJSArray,
|
|
|
|
nsCOMArray<nsIAtom>& aRetVal);
|
|
|
|
|
2011-11-20 10:02:47 -08:00
|
|
|
/**
|
|
|
|
* Returns whether the input element passed in parameter has the autocomplete
|
|
|
|
* functionnality enabled. It is taking into account the form owner.
|
|
|
|
* NOTE: the caller has to make sure autocomplete makes sense for the
|
|
|
|
* element's type.
|
|
|
|
*
|
|
|
|
* @param aInput the input element to check. NOTE: aInput can't be null.
|
|
|
|
* @return whether the input element has autocomplete enabled.
|
|
|
|
*/
|
|
|
|
static bool IsAutocompleteEnabled(nsIDOMHTMLInputElement* aInput);
|
|
|
|
|
2012-01-10 09:57:39 -08:00
|
|
|
/**
|
|
|
|
* If the URI is chrome, return true unconditionarlly.
|
|
|
|
*
|
|
|
|
* Otherwise, get the contents of the given pref, and treat it as a
|
|
|
|
* comma-separated list of URIs. Return true if the given URI's prepath is
|
|
|
|
* in the list, and false otherwise.
|
|
|
|
*
|
|
|
|
* Comparisons are case-insensitive, and whitespace between elements of the
|
|
|
|
* comma-separated list is ignored.
|
|
|
|
*/
|
|
|
|
static bool URIIsChromeOrInPref(nsIURI *aURI, const char *aPref);
|
|
|
|
|
2012-02-27 03:57:48 -08:00
|
|
|
/**
|
|
|
|
* This will parse aSource, to extract the value of the pseudo attribute
|
|
|
|
* with the name specified in aName. See
|
|
|
|
* http://www.w3.org/TR/xml-stylesheet/#NT-StyleSheetPI for the specification
|
|
|
|
* which is used to parse aSource.
|
|
|
|
*
|
|
|
|
* @param aSource the string to parse
|
|
|
|
* @param aName the name of the attribute to get the value for
|
|
|
|
* @param aValue [out] the value for the attribute with name specified in
|
|
|
|
* aAttribute. Empty if the attribute isn't present.
|
|
|
|
* @return true if the attribute exists and was successfully parsed.
|
|
|
|
* false if the attribute doesn't exist, or has a malformed
|
|
|
|
* value, such as an unknown or unterminated entity.
|
|
|
|
*/
|
|
|
|
static bool GetPseudoAttributeValue(const nsString& aSource, nsIAtom *aName,
|
|
|
|
nsAString& aValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the language name is a version of JavaScript and
|
|
|
|
* false otherwise
|
|
|
|
*/
|
|
|
|
static bool IsJavaScriptLanguage(const nsString& aName, PRUint32 *aVerFlags);
|
|
|
|
|
|
|
|
static void SplitMimeType(const nsAString& aValue, nsString& aType,
|
|
|
|
nsString& aParams);
|
|
|
|
|
2012-06-29 01:32:21 -07:00
|
|
|
/**
|
|
|
|
* Function checks if the user is idle.
|
|
|
|
*
|
|
|
|
* @param aRequestedIdleTimeInMS The idle observer's requested idle time.
|
|
|
|
* @param aUserIsIdle boolean indicating if the user
|
|
|
|
* is currently idle or not. *
|
|
|
|
* @return NS_OK NS_OK returned if the requested idle service and
|
|
|
|
* the current idle time were successfully obtained.
|
|
|
|
* NS_ERROR_FAILURE returned if the the requested
|
|
|
|
* idle service or the current idle were not obtained.
|
|
|
|
*/
|
|
|
|
static nsresult IsUserIdle(PRUint32 aRequestedIdleTimeInMS, bool* aUserIsIdle);
|
|
|
|
|
2012-05-23 21:02:23 -07:00
|
|
|
/**
|
|
|
|
* Takes a window and a string to check prefs against. Assumes that
|
|
|
|
* the window is an app window, and that the pref is a comma
|
|
|
|
* seperated list of app urls that have permission to use whatever
|
|
|
|
* the preference refers to (for example, does the current window
|
|
|
|
* have access to mozTelephony). Chrome is always given permissions
|
|
|
|
* for the requested preference. Sets aAllowed based on preference.
|
|
|
|
*
|
|
|
|
* @param aWindow Current window asking for preference permission
|
|
|
|
* @param aPrefURL Preference name
|
|
|
|
* @param aAllowed [out] outparam on whether or not window is allowed
|
|
|
|
* to access pref
|
|
|
|
*
|
|
|
|
* @return NS_OK on successful preference lookup, error code otherwise
|
|
|
|
*/
|
|
|
|
static nsresult IsOnPrefWhitelist(nsPIDOMWindow* aWindow,
|
|
|
|
const char* aPrefURL, bool *aAllowed);
|
2012-06-10 16:44:50 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a selection, and a text control element (<input> or <textarea>), and
|
|
|
|
* returns the offsets in the text content corresponding to the selection.
|
|
|
|
* The selection's anchor and focus must both be in the root node passed or a
|
|
|
|
* descendant.
|
|
|
|
*
|
|
|
|
* @param aSelection Selection to check
|
|
|
|
* @param aRoot Root <input> or <textarea> element
|
|
|
|
* @param aOutStartOffset Output start offset
|
|
|
|
* @param aOutEndOffset Output end offset
|
|
|
|
*/
|
|
|
|
static void GetSelectionInTextControl(mozilla::Selection* aSelection,
|
|
|
|
Element* aRoot,
|
|
|
|
PRInt32& aOutStartOffset,
|
|
|
|
PRInt32& aOutEndOffset);
|
2012-06-22 23:58:04 -07:00
|
|
|
|
|
|
|
static nsIEditor* GetHTMLEditor(nsPresContext* aPresContext);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool InitializeEventTable();
|
2007-04-02 10:17:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsresult EnsureStringBundle(PropertiesFile aFile);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool CanCallerAccess(nsIPrincipal* aSubjectPrincipal,
|
2008-02-26 18:03:27 -08:00
|
|
|
nsIPrincipal* aPrincipal);
|
|
|
|
|
2010-05-10 11:53:05 -07:00
|
|
|
static nsresult WrapNative(JSContext *cx, JSObject *scope,
|
|
|
|
nsISupports *native, nsWrapperCache *cache,
|
|
|
|
const nsIID* aIID, jsval *vp,
|
|
|
|
nsIXPConnectJSObjectHolder** aHolder,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAllowWrapping);
|
2012-02-13 15:07:04 -08:00
|
|
|
|
|
|
|
static nsresult DispatchEvent(nsIDocument* aDoc,
|
|
|
|
nsISupports* aTarget,
|
|
|
|
const nsAString& aEventName,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
|
|
|
bool aTrusted,
|
|
|
|
bool *aDefaultAction = nsnull);
|
2010-05-10 11:53:05 -07:00
|
|
|
|
2011-07-31 12:43:54 -07:00
|
|
|
static void InitializeModifierStrings();
|
|
|
|
|
2011-08-01 00:48:24 -07:00
|
|
|
static void DropFragmentParsers();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsIDOMScriptObjectFactory *sDOMScriptObjectFactory;
|
|
|
|
|
|
|
|
static nsIXPConnect *sXPConnect;
|
|
|
|
|
|
|
|
static nsIScriptSecurityManager *sSecurityManager;
|
|
|
|
|
|
|
|
static nsIThreadJSContextStack *sThreadJSContextStack;
|
|
|
|
|
|
|
|
static nsIParserService *sParserService;
|
|
|
|
|
|
|
|
static nsINameSpaceManager *sNameSpaceManager;
|
|
|
|
|
|
|
|
static nsIIOService *sIOService;
|
|
|
|
|
|
|
|
#ifdef MOZ_XTF
|
|
|
|
static nsIXTFService *sXTFService;
|
|
|
|
#endif
|
|
|
|
|
2010-07-02 14:15:52 -07:00
|
|
|
static bool sImgLoaderInitialized;
|
|
|
|
static void InitImgLoader();
|
|
|
|
|
|
|
|
// The following two members are initialized lazily
|
2007-03-22 10:30:00 -07:00
|
|
|
static imgILoader* sImgLoader;
|
2009-07-07 22:23:20 -07:00
|
|
|
static imgICache* sImgCache;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static nsIConsoleService* sConsoleService;
|
|
|
|
|
2010-06-22 11:12:12 -07:00
|
|
|
static nsDataHashtable<nsISupportsHashKey, EventNameMapping>* sAtomEventTable;
|
|
|
|
static nsDataHashtable<nsStringHashKey, EventNameMapping>* sStringEventTable;
|
|
|
|
static nsCOMArray<nsIAtom>* sUserDefinedEvents;
|
2007-04-02 10:17:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsIStringBundleService* sStringBundleService;
|
|
|
|
static nsIStringBundle* sStringBundles[PropertiesFile_COUNT];
|
|
|
|
|
|
|
|
static nsIContentPolicy* sContentPolicyService;
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool sTriedToGetContentPolicy;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static nsILineBreaker* sLineBreaker;
|
|
|
|
static nsIWordBreaker* sWordBreaker;
|
|
|
|
|
2007-10-29 06:45:07 -07:00
|
|
|
static PRUint32 sJSGCThingRootCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
static nsIBidiKeyboard* sBidiKeyboard;
|
|
|
|
#endif
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool sInitialized;
|
2008-03-14 16:08:57 -07:00
|
|
|
static PRUint32 sScriptBlockerCount;
|
2011-05-09 12:33:04 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
static PRUint32 sDOMNodeRemovedSuppressCount;
|
|
|
|
#endif
|
2012-03-31 09:30:13 -07:00
|
|
|
static PRUint32 sMicroTaskLevel;
|
2011-08-03 11:32:32 -07:00
|
|
|
// Not an nsCOMArray because removing elements from those is slower
|
|
|
|
static nsTArray< nsCOMPtr<nsIRunnable> >* sBlockedScriptRunners;
|
2008-03-14 16:08:57 -07:00
|
|
|
static PRUint32 sRunnersCountAtFirstBlocker;
|
2010-01-11 13:45:20 -08:00
|
|
|
static PRUint32 sScriptBlockerCountWhereRunnersPrevented;
|
2008-09-07 18:13:02 -07:00
|
|
|
|
|
|
|
static nsIInterfaceRequestor* sSameOriginChecker;
|
2010-04-24 03:40:48 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool sIsHandlingKeyBoardEvent;
|
|
|
|
static bool sAllowXULXBL_for_file;
|
|
|
|
static bool sIsFullScreenApiEnabled;
|
|
|
|
static bool sTrustedFullScreenOnly;
|
2011-09-06 13:14:59 -07:00
|
|
|
static PRUint32 sHandlingInputTimeout;
|
2012-06-29 01:32:21 -07:00
|
|
|
static bool sIsIdleObserverAPIEnabled;
|
2011-07-31 12:43:54 -07:00
|
|
|
|
2012-01-20 03:16:27 -08:00
|
|
|
static nsHtml5StringParser* sHTMLFragmentParser;
|
2011-08-01 00:48:24 -07:00
|
|
|
static nsIParser* sXMLFragmentParser;
|
|
|
|
static nsIFragmentContentSink* sXMLFragmentSink;
|
|
|
|
|
2011-10-14 03:39:19 -07:00
|
|
|
/**
|
|
|
|
* True if there's a fragment parser activation on the stack.
|
|
|
|
*/
|
|
|
|
static bool sFragmentParsingActive;
|
|
|
|
|
2011-07-31 12:43:54 -07:00
|
|
|
static nsString* sShiftText;
|
|
|
|
static nsString* sControlText;
|
|
|
|
static nsString* sMetaText;
|
2012-07-18 18:28:16 -07:00
|
|
|
static nsString* sOSText;
|
2011-07-31 12:43:54 -07:00
|
|
|
static nsString* sAltText;
|
|
|
|
static nsString* sModifierSeparator;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-01-04 02:08:00 -08:00
|
|
|
typedef nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>
|
|
|
|
HTMLSplitOnSpacesTokenizer;
|
|
|
|
|
2007-10-29 06:45:07 -07:00
|
|
|
#define NS_HOLD_JS_OBJECTS(obj, clazz) \
|
|
|
|
nsContentUtils::HoldJSObjects(NS_CYCLE_COLLECTION_UPCAST(obj, clazz), \
|
2012-06-03 23:30:26 -07:00
|
|
|
NS_CYCLE_COLLECTION_PARTICIPANT(clazz))
|
2007-10-29 06:45:07 -07:00
|
|
|
|
|
|
|
#define NS_DROP_JS_OBJECTS(obj, clazz) \
|
|
|
|
nsContentUtils::DropJSObjects(NS_CYCLE_COLLECTION_UPCAST(obj, clazz))
|
|
|
|
|
|
|
|
|
2008-06-30 18:03:50 -07:00
|
|
|
class NS_STACK_CLASS nsCxPusher
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2007-10-01 03:02:32 -07:00
|
|
|
nsCxPusher();
|
|
|
|
~nsCxPusher(); // Calls Pop();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// Returns false if something erroneous happened.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Push(nsIDOMEventTarget *aCurrentTarget);
|
2009-05-14 00:03:15 -07:00
|
|
|
// If nothing has been pushed to stack, this works like Push.
|
|
|
|
// Otherwise if context will change, Pop and Push will be called.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool RePush(nsIDOMEventTarget *aCurrentTarget);
|
2009-02-16 06:11:41 -08:00
|
|
|
// If a null JSContext is passed to Push(), that will cause no
|
2009-02-16 10:53:11 -08:00
|
|
|
// push to happen and false to be returned.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Push(JSContext *cx, bool aRequiresScriptContext = true);
|
2009-02-16 06:11:41 -08:00
|
|
|
// Explicitly push a null JSContext on the the stack
|
2011-09-28 23:19:26 -07:00
|
|
|
bool PushNull();
|
2009-02-16 06:11:41 -08:00
|
|
|
|
|
|
|
// Pop() will be a no-op if Push() or PushNull() fail
|
2007-03-22 10:30:00 -07:00
|
|
|
void Pop();
|
|
|
|
|
2009-10-24 08:52:29 -07:00
|
|
|
nsIScriptContext* GetCurrentScriptContext() { return mScx; }
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2009-02-16 06:11:41 -08:00
|
|
|
// Combined code for PushNull() and Push(JSContext*)
|
2011-09-28 23:19:26 -07:00
|
|
|
bool DoPush(JSContext* cx);
|
2009-02-16 06:11:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIScriptContext> mScx;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mScriptIsRunning;
|
|
|
|
bool mPushedSomething;
|
2009-02-16 06:11:41 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
JSContext* mPushedContext;
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2010-04-04 11:15:18 -07:00
|
|
|
class NS_STACK_CLASS nsAutoScriptBlocker {
|
2008-03-14 16:08:57 -07:00
|
|
|
public:
|
2012-01-09 21:29:30 -08:00
|
|
|
nsAutoScriptBlocker(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2008-03-14 16:08:57 -07:00
|
|
|
nsContentUtils::AddScriptBlocker();
|
|
|
|
}
|
|
|
|
~nsAutoScriptBlocker() {
|
|
|
|
nsContentUtils::RemoveScriptBlocker();
|
|
|
|
}
|
2010-04-04 11:15:18 -07:00
|
|
|
private:
|
2012-01-09 21:29:30 -08:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2008-03-14 16:08:57 -07:00
|
|
|
};
|
|
|
|
|
2011-05-09 12:33:04 -07:00
|
|
|
class NS_STACK_CLASS nsAutoScriptBlockerSuppressNodeRemoved :
|
|
|
|
public nsAutoScriptBlocker {
|
|
|
|
public:
|
|
|
|
nsAutoScriptBlockerSuppressNodeRemoved() {
|
|
|
|
#ifdef DEBUG
|
|
|
|
++nsContentUtils::sDOMNodeRemovedSuppressCount;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
~nsAutoScriptBlockerSuppressNodeRemoved() {
|
|
|
|
#ifdef DEBUG
|
|
|
|
--nsContentUtils::sDOMNodeRemovedSuppressCount;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-31 09:30:13 -07:00
|
|
|
class NS_STACK_CLASS nsAutoMicroTask
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsAutoMicroTask()
|
|
|
|
{
|
|
|
|
nsContentUtils::EnterMicroTask();
|
|
|
|
}
|
|
|
|
~nsAutoMicroTask()
|
|
|
|
{
|
|
|
|
nsContentUtils::LeaveMicroTask();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#define NS_INTERFACE_MAP_ENTRY_TEAROFF(_interface, _allocator) \
|
|
|
|
if (aIID.Equals(NS_GET_IID(_interface))) { \
|
2007-07-11 01:46:44 -07:00
|
|
|
foundInterface = static_cast<_interface *>(_allocator); \
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!foundInterface) { \
|
|
|
|
*aInstancePtr = nsnull; \
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY; \
|
|
|
|
} \
|
|
|
|
} else
|
|
|
|
|
2008-04-08 04:47:57 -07:00
|
|
|
/*
|
|
|
|
* In the following helper macros we exploit the fact that the result of a
|
|
|
|
* series of additions will not be finite if any one of the operands in the
|
|
|
|
* series is not finite.
|
|
|
|
*/
|
|
|
|
#define NS_ENSURE_FINITE(f, rv) \
|
2011-08-01 10:43:23 -07:00
|
|
|
if (!NS_finite(f)) { \
|
2008-04-08 04:47:57 -07:00
|
|
|
return (rv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_ENSURE_FINITE2(f1, f2, rv) \
|
2011-08-01 10:43:23 -07:00
|
|
|
if (!NS_finite((f1)+(f2))) { \
|
2008-04-08 04:47:57 -07:00
|
|
|
return (rv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_ENSURE_FINITE3(f1, f2, f3, rv) \
|
2011-08-01 10:43:23 -07:00
|
|
|
if (!NS_finite((f1)+(f2)+(f3))) { \
|
2008-04-08 04:47:57 -07:00
|
|
|
return (rv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_ENSURE_FINITE4(f1, f2, f3, f4, rv) \
|
2011-08-01 10:43:23 -07:00
|
|
|
if (!NS_finite((f1)+(f2)+(f3)+(f4))) { \
|
2008-04-08 04:47:57 -07:00
|
|
|
return (rv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_ENSURE_FINITE5(f1, f2, f3, f4, f5, rv) \
|
2011-08-01 10:43:23 -07:00
|
|
|
if (!NS_finite((f1)+(f2)+(f3)+(f4)+(f5))) { \
|
2008-04-08 04:47:57 -07:00
|
|
|
return (rv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_ENSURE_FINITE6(f1, f2, f3, f4, f5, f6, rv) \
|
2011-08-01 10:43:23 -07:00
|
|
|
if (!NS_finite((f1)+(f2)+(f3)+(f4)+(f5)+(f6))) { \
|
2008-04-08 04:47:57 -07:00
|
|
|
return (rv); \
|
|
|
|
}
|
|
|
|
|
2008-12-15 03:33:56 -08:00
|
|
|
// Deletes a linked list iteratively to avoid blowing up the stack (bug 460444).
|
|
|
|
#define NS_CONTENT_DELETE_LIST_MEMBER(type_, ptr_, member_) \
|
|
|
|
{ \
|
|
|
|
type_ *cur = (ptr_)->member_; \
|
|
|
|
(ptr_)->member_ = nsnull; \
|
|
|
|
while (cur) { \
|
|
|
|
type_ *next = cur->member_; \
|
|
|
|
cur->member_ = nsnull; \
|
|
|
|
delete cur; \
|
|
|
|
cur = next; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2008-12-16 18:11:07 -08:00
|
|
|
class nsContentTypeParser {
|
|
|
|
public:
|
|
|
|
nsContentTypeParser(const nsAString& aString);
|
|
|
|
~nsContentTypeParser();
|
|
|
|
|
|
|
|
nsresult GetParameter(const char* aParameterName, nsAString& aResult);
|
|
|
|
nsresult GetType(nsAString& aResult)
|
|
|
|
{
|
|
|
|
return GetParameter(nsnull, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
NS_ConvertUTF16toUTF8 mString;
|
|
|
|
nsIMIMEHeaderParam* mService;
|
|
|
|
};
|
|
|
|
|
2011-12-15 07:10:36 -08:00
|
|
|
class nsDocElementCreatedNotificationRunner : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDocElementCreatedNotificationRunner(nsIDocument* aDoc)
|
|
|
|
: mDoc(aDoc)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
nsContentSink::NotifyDocElementCreated(mDoc);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> mDoc;
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* nsContentUtils_h___ */
|