2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2001-02-17 12:53:29 +03:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
/* A namespace class for static content utilities. */
|
2001-02-17 12:53:29 +03:00
|
|
|
|
|
|
|
#ifndef nsContentUtils_h___
|
|
|
|
#define nsContentUtils_h___
|
|
|
|
|
2014-02-11 02:57:01 +04:00
|
|
|
#if defined(XP_WIN)
|
2010-03-02 00:30:23 +03:00
|
|
|
# include <float.h>
|
|
|
|
#endif
|
|
|
|
|
2010-03-30 10:29:59 +04:00
|
|
|
#if defined(SOLARIS)
|
|
|
|
# include <ieeefp.h>
|
|
|
|
#endif
|
|
|
|
|
2013-08-28 06:59:14 +04:00
|
|
|
#include "js/TypeDecls.h"
|
2013-10-12 09:02:40 +04:00
|
|
|
#include "js/Value.h"
|
2013-03-17 11:55:15 +04:00
|
|
|
#include "js/RootingAPI.h"
|
2017-10-11 01:25:10 +03:00
|
|
|
#include "mozilla/dom/FromParser.h"
|
2017-06-17 06:37:23 +03:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2018-01-31 19:10:01 +03:00
|
|
|
#include "mozilla/CORSMode.h"
|
2013-09-24 14:04:14 +04:00
|
|
|
#include "mozilla/EventForwards.h"
|
2013-03-17 11:55:08 +04:00
|
|
|
#include "mozilla/GuardObjects.h"
|
2018-09-15 21:38:44 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2017-04-04 02:28:41 +03:00
|
|
|
#include "mozilla/TaskCategory.h"
|
2013-03-17 11:55:08 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-03-17 11:55:11 +04:00
|
|
|
#include "nsContentListDeclarations.h"
|
2011-08-01 21:43:23 +04:00
|
|
|
#include "nsMathUtils.h"
|
2014-03-15 23:00:17 +04:00
|
|
|
#include "nsTArrayForwardDeclare.h"
|
2013-09-03 23:12:24 +04:00
|
|
|
#include "Units.h"
|
2014-07-09 11:01:00 +04:00
|
|
|
#include "mozilla/dom/AutocompleteInfoBinding.h"
|
2016-12-17 08:25:52 +03:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h" // For CallerType
|
2014-08-15 05:47:15 +04:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2014-10-01 13:26:00 +04:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2017-12-14 07:17:32 +03:00
|
|
|
#include "mozilla/intl/LineBreaker.h"
|
2017-12-14 07:17:38 +03:00
|
|
|
#include "mozilla/intl/WordBreaker.h"
|
2014-11-18 16:46:53 +03:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2016-01-07 00:18:29 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2016-05-27 02:49:25 +03:00
|
|
|
#include "mozilla/NotNull.h"
|
2017-05-15 13:15:48 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2017-10-02 17:58:29 +03:00
|
|
|
#include "mozilla/RangeBoundary.h"
|
2014-08-20 01:49:14 +04:00
|
|
|
#include "nsIContentPolicy.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2016-06-09 14:59:31 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2017-05-02 10:21:04 +03:00
|
|
|
#include "nsRFPService.h"
|
2011-11-16 11:50:19 +04:00
|
|
|
|
2013-12-02 14:26:11 +04:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
// Undefine LoadImage to prevent naming conflict with Windows.
|
|
|
|
# undef LoadImage
|
|
|
|
#endif
|
|
|
|
|
2013-03-17 11:55:08 +04:00
|
|
|
class imgICache;
|
|
|
|
class imgIContainer;
|
|
|
|
class imgINotificationObserver;
|
2013-03-17 11:55:15 +04:00
|
|
|
class imgIRequest;
|
2013-03-17 11:55:08 +04:00
|
|
|
class imgLoader;
|
|
|
|
class imgRequestProxy;
|
|
|
|
class nsAutoScriptBlockerSuppressNodeRemoved;
|
2017-07-26 09:34:00 +03:00
|
|
|
class nsCacheableFuncStringHTMLCollection;
|
2013-03-17 11:55:09 +04:00
|
|
|
class nsHtml5StringParser;
|
2017-10-03 01:05:19 +03:00
|
|
|
class nsAtom;
|
2013-03-17 11:55:08 +04:00
|
|
|
class nsIChannel;
|
|
|
|
class nsIConsoleService;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
class nsIContent;
|
2013-03-17 11:55:08 +04:00
|
|
|
class nsIContentPolicy;
|
2013-08-07 06:46:05 +04:00
|
|
|
class nsIContentSecurityPolicy;
|
2015-05-07 18:43:40 +03:00
|
|
|
class nsIDocShellTreeItem;
|
2013-03-17 11:55:08 +04:00
|
|
|
class nsIDocumentLoaderFactory;
|
|
|
|
class nsIDragSession;
|
2017-04-04 02:28:41 +03:00
|
|
|
class nsIEventTarget;
|
2012-07-02 03:45:59 +04:00
|
|
|
class nsIFragmentContentSink;
|
2013-06-23 11:15:49 +04:00
|
|
|
class nsIFrame;
|
2013-03-17 11:55:08 +04:00
|
|
|
class nsIImageLoadingContent;
|
|
|
|
class nsIInterfaceRequestor;
|
|
|
|
class nsIIOService;
|
2017-03-24 01:31:00 +03:00
|
|
|
class nsILoadInfo;
|
2015-06-26 21:18:18 +03:00
|
|
|
class nsILoadGroup;
|
2014-02-28 03:04:46 +04:00
|
|
|
class nsNameSpaceManager;
|
2013-03-17 11:55:08 +04:00
|
|
|
class nsIObserver;
|
2012-07-02 03:45:59 +04:00
|
|
|
class nsIParser;
|
2015-05-20 16:30:05 +03:00
|
|
|
class nsIPluginTag;
|
2013-03-17 11:55:08 +04:00
|
|
|
class nsIPresShell;
|
2013-03-17 11:55:15 +04:00
|
|
|
class nsIPrincipal;
|
2014-09-24 05:29:31 +04:00
|
|
|
class nsIRequest;
|
2008-03-15 02:08:57 +03:00
|
|
|
class nsIRunnable;
|
2013-03-17 11:55:08 +04:00
|
|
|
class nsIScriptContext;
|
|
|
|
class nsIScriptSecurityManager;
|
|
|
|
class nsIStringBundle;
|
|
|
|
class nsIStringBundleService;
|
2013-03-17 11:55:16 +04:00
|
|
|
class nsISupportsHashKey;
|
2013-03-17 11:55:08 +04:00
|
|
|
class nsIURI;
|
2015-06-17 13:44:27 +03:00
|
|
|
class nsIUUIDGenerator;
|
2007-11-16 11:21:44 +03:00
|
|
|
class nsIWidget;
|
2013-03-17 11:55:08 +04:00
|
|
|
class nsIXPConnect;
|
2013-03-17 11:55:15 +04:00
|
|
|
class nsNodeInfoManager;
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowInner;
|
|
|
|
class nsPIDOMWindowOuter;
|
2010-04-11 00:10:12 +04:00
|
|
|
class nsPresContext;
|
2013-09-10 21:03:28 +04:00
|
|
|
class nsStringBuffer;
|
2013-03-17 11:55:16 +04:00
|
|
|
class nsStringHashKey;
|
2013-03-17 11:55:08 +04:00
|
|
|
class nsTextFragment;
|
2015-04-15 10:08:55 +03:00
|
|
|
class nsView;
|
2013-03-17 11:55:08 +04:00
|
|
|
class nsViewportInfo;
|
2013-06-23 11:15:49 +04:00
|
|
|
class nsWrapperCache;
|
2013-12-20 01:35:25 +04:00
|
|
|
class nsAttrValue;
|
2015-04-16 22:38:12 +03:00
|
|
|
class nsITransferable;
|
2015-06-08 08:39:39 +03:00
|
|
|
class nsPIWindowRoot;
|
2015-10-30 02:30:57 +03:00
|
|
|
class nsIWindowProvider;
|
2013-03-17 11:55:08 +04:00
|
|
|
|
|
|
|
struct JSRuntime;
|
2001-02-17 12:53:29 +03:00
|
|
|
|
2013-03-17 11:55:08 +04:00
|
|
|
template <class E>
|
|
|
|
class nsCOMArray;
|
2013-03-17 11:55:16 +04:00
|
|
|
template <class K, class V>
|
|
|
|
class nsDataHashtable;
|
2013-03-17 11:55:08 +04:00
|
|
|
template <class K, class V>
|
|
|
|
class nsRefPtrHashtable;
|
2013-08-21 23:28:26 +04:00
|
|
|
template <class T>
|
|
|
|
class nsReadingIterator;
|
2012-12-18 01:24:41 +04:00
|
|
|
|
2009-11-09 21:00:53 +03:00
|
|
|
namespace mozilla {
|
2017-03-24 01:31:00 +03:00
|
|
|
class Dispatcher;
|
2013-03-17 11:55:15 +04:00
|
|
|
class ErrorResult;
|
2014-03-17 10:56:53 +04:00
|
|
|
class EventListenerManager;
|
2017-08-07 10:33:59 +03:00
|
|
|
class HTMLEditor;
|
2018-11-21 06:59:02 +03:00
|
|
|
class TextEditor;
|
2012-06-11 03:44:50 +04:00
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
namespace dom {
|
2018-08-03 06:49:09 +03:00
|
|
|
class ContentFrameMessageManager;
|
2016-08-30 06:48:53 +03:00
|
|
|
struct CustomElementDefinition;
|
2019-02-19 09:33:42 +03:00
|
|
|
class DataTransfer;
|
2013-02-07 16:09:41 +04:00
|
|
|
class DocumentFragment;
|
2010-04-30 17:12:05 +04:00
|
|
|
class Element;
|
2018-04-20 19:55:30 +03:00
|
|
|
class Event;
|
2013-04-06 04:44:26 +04:00
|
|
|
class EventTarget;
|
2018-02-21 01:10:44 +03:00
|
|
|
class HTMLInputElement;
|
2015-04-08 21:48:11 +03:00
|
|
|
class IPCDataTransfer;
|
2016-02-24 03:31:29 +03:00
|
|
|
class IPCDataTransferItem;
|
2016-08-30 06:48:53 +03:00
|
|
|
struct LifecycleCallbackArgs;
|
2017-10-02 07:42:00 +03:00
|
|
|
struct LifecycleAdoptedCallbackArgs;
|
2018-04-16 16:18:48 +03:00
|
|
|
class MessageBroadcaster;
|
2014-06-20 06:01:40 +04:00
|
|
|
class NodeInfo;
|
2019-02-25 23:04:49 +03:00
|
|
|
class ContentChild;
|
2019-02-25 23:04:47 +03:00
|
|
|
class ContentParent;
|
2016-08-31 04:30:45 +03:00
|
|
|
class TabChild;
|
2014-04-10 20:09:40 +04:00
|
|
|
class Selection;
|
2014-11-27 16:28:26 +03:00
|
|
|
class TabParent;
|
2010-04-30 17:12:05 +04:00
|
|
|
} // namespace dom
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2016-06-15 15:49:13 +03:00
|
|
|
namespace ipc {
|
|
|
|
class Shmem;
|
|
|
|
class IShmemAllocator;
|
|
|
|
} // namespace ipc
|
|
|
|
|
2015-04-16 22:38:12 +03:00
|
|
|
namespace gfx {
|
|
|
|
class DataSourceSurface;
|
|
|
|
} // namespace gfx
|
|
|
|
|
2013-03-17 11:55:08 +04:00
|
|
|
namespace layers {
|
|
|
|
class LayerManager;
|
|
|
|
} // namespace layers
|
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
} // namespace mozilla
|
2009-11-09 21:00:53 +03:00
|
|
|
|
2013-03-17 11:55:08 +04:00
|
|
|
class nsIBidiKeyboard;
|
|
|
|
|
2006-06-16 00:30:44 +04:00
|
|
|
extern const char kLoadAsData[];
|
|
|
|
|
2013-08-21 23:28:26 +04:00
|
|
|
// Stolen from nsReadableUtils, but that's OK, since we can declare the same
|
|
|
|
// name multiple times.
|
2017-06-20 12:19:05 +03:00
|
|
|
const nsString& EmptyString();
|
|
|
|
const nsCString& EmptyCString();
|
2013-08-21 23:28:26 +04:00
|
|
|
|
2007-04-02 21:17:36 +04:00
|
|
|
enum EventNameType {
|
|
|
|
EventNameType_None = 0x0000,
|
|
|
|
EventNameType_HTML = 0x0001,
|
|
|
|
EventNameType_XUL = 0x0002,
|
|
|
|
EventNameType_SVGGraphic = 0x0004, // svg graphic elements
|
|
|
|
EventNameType_SVGSVG = 0x0008, // the svg element
|
2012-11-16 02:09:30 +04:00
|
|
|
EventNameType_SMIL = 0x0010, // smil elements
|
2012-11-14 22:05:41 +04:00
|
|
|
EventNameType_HTMLBodyOrFramesetOnly = 0x0020,
|
2018-11-08 17:46:45 +03:00
|
|
|
EventNameType_HTMLMarqueeOnly = 0x0040,
|
2007-04-02 21:17:36 +04:00
|
|
|
|
|
|
|
EventNameType_HTMLXUL = 0x0003,
|
|
|
|
EventNameType_All = 0xFFFF
|
|
|
|
};
|
|
|
|
|
2010-06-22 22:12:12 +04:00
|
|
|
struct EventNameMapping {
|
2015-01-18 22:01:31 +03:00
|
|
|
// This holds pointers to nsGkAtoms members, and is therefore safe as a
|
|
|
|
// non-owning reference.
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* MOZ_NON_OWNING_REF mAtom;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mType;
|
2015-08-26 15:56:59 +03:00
|
|
|
mozilla::EventMessage mMessage;
|
2014-08-04 09:28:58 +04:00
|
|
|
mozilla::EventClassID mEventClassID;
|
2016-05-20 12:15:05 +03:00
|
|
|
// True if mAtom is possibly used by special SVG/SMIL events, but
|
|
|
|
// mMessage is eUnidentifiedEvent. See EventNameList.h
|
|
|
|
bool mMaybeSpecialSVGorSMILEvent;
|
2007-04-02 21:17:36 +04:00
|
|
|
};
|
|
|
|
|
2016-05-11 15:56:42 +03:00
|
|
|
typedef bool (*CallOnRemoteChildFunction)(mozilla::dom::TabParent* aTabParent,
|
2014-11-27 16:28:26 +03:00
|
|
|
void* aArg);
|
|
|
|
|
2001-02-17 12:53:29 +03:00
|
|
|
class nsContentUtils {
|
2011-05-09 23:33:04 +04:00
|
|
|
friend class nsAutoScriptBlockerSuppressNodeRemoved;
|
2010-05-14 21:04:51 +04:00
|
|
|
typedef mozilla::dom::Element Element;
|
2019-01-02 16:05:23 +03:00
|
|
|
typedef mozilla::dom::Document Document;
|
2018-06-25 19:23:50 +03:00
|
|
|
typedef mozilla::Cancelable Cancelable;
|
|
|
|
typedef mozilla::CanBubble CanBubble;
|
2018-09-14 03:05:39 +03:00
|
|
|
typedef mozilla::Composed Composed;
|
2018-06-25 19:23:50 +03:00
|
|
|
typedef mozilla::ChromeOnlyDispatch ChromeOnlyDispatch;
|
|
|
|
typedef mozilla::EventMessage EventMessage;
|
2011-09-07 00:14:59 +04:00
|
|
|
typedef mozilla::TimeDuration TimeDuration;
|
2018-06-25 19:23:50 +03:00
|
|
|
typedef mozilla::Trusted Trusted;
|
2010-05-14 21:04:51 +04:00
|
|
|
|
2001-02-17 12:53:29 +03:00
|
|
|
public:
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
static nsresult Init();
|
|
|
|
|
2018-09-27 22:00:33 +03:00
|
|
|
static bool IsCallerChrome();
|
|
|
|
static bool ThreadsafeIsCallerChrome();
|
|
|
|
static bool IsCallerContentXBL();
|
2018-11-03 08:31:05 +03:00
|
|
|
static bool IsCallerUAWidget();
|
2018-09-27 22:00:33 +03:00
|
|
|
static bool IsFuzzingEnabled()
|
|
|
|
#ifndef FUZZING
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static bool IsCallerChromeOrFuzzingEnabled(JSContext* aCx, JSObject*) {
|
|
|
|
return ThreadsafeIsSystemCaller(aCx) || IsFuzzingEnabled();
|
|
|
|
}
|
2002-06-26 00:03:06 +04:00
|
|
|
|
2016-11-19 00:13:06 +03:00
|
|
|
// The APIs for checking whether the caller is system (in the sense of system
|
|
|
|
// principal) should only be used when the JSContext is known to accurately
|
|
|
|
// represent the caller. In practice, that means you should only use them in
|
|
|
|
// two situations at the moment:
|
|
|
|
//
|
|
|
|
// 1) Functions used in WebIDL Func annotations.
|
2016-11-19 00:13:07 +03:00
|
|
|
// 2) Bindings code or other code called directly from the JS engine.
|
2016-11-19 00:13:06 +03:00
|
|
|
//
|
|
|
|
// Use pretty much anywhere else is almost certainly wrong and should be
|
|
|
|
// replaced with [NeedsCallerType] annotations in bindings.
|
|
|
|
|
|
|
|
// Check whether the caller is system if you know you're on the main thread.
|
|
|
|
static bool IsSystemCaller(JSContext* aCx);
|
|
|
|
|
2018-04-06 09:53:25 +03:00
|
|
|
// Check whether the caller is system if you might be on a worker or worklet
|
|
|
|
// thread.
|
2016-11-19 00:13:06 +03:00
|
|
|
static bool ThreadsafeIsSystemCaller(JSContext* aCx);
|
|
|
|
|
2014-09-25 12:56:33 +04:00
|
|
|
// In the traditional Gecko architecture, both C++ code and untrusted JS code
|
|
|
|
// needed to rely on the same XPCOM method/getter/setter to get work done.
|
|
|
|
// This required lots of security checks in the various exposed methods, which
|
|
|
|
// in turn created difficulty in determining whether the caller was script
|
|
|
|
// (whose access needed to be checked) and internal C++ platform code (whose
|
|
|
|
// access did not need to be checked). To address this problem, Gecko had a
|
|
|
|
// convention whereby the absence of script on the stack was interpretted as
|
|
|
|
// "System Caller" and always granted unfettered access.
|
|
|
|
//
|
|
|
|
// Unfortunately, this created a bunch of footguns. For example, when the
|
|
|
|
// implementation of a DOM method wanted to perform a privileged
|
|
|
|
// sub-operation, it needed to "hide" the presence of script on the stack in
|
|
|
|
// order for that sub-operation to be allowed. Additionally, if script could
|
|
|
|
// trigger an API entry point to be invoked in some asynchronous way without
|
|
|
|
// script on the stack, it could potentially perform privilege escalation.
|
|
|
|
//
|
|
|
|
// In the modern world, untrusted script should interact with the platform
|
|
|
|
// exclusively over WebIDL APIs, and platform code has a lot more flexibility
|
|
|
|
// in deciding whether or not to use XPCOM. This gives us the flexibility to
|
|
|
|
// do something better.
|
|
|
|
//
|
|
|
|
// Going forward, APIs should be designed such that any security checks that
|
|
|
|
// ask the question "is my caller allowed to do this?" should live in WebIDL
|
|
|
|
// API entry points, with a separate method provided for internal callers
|
|
|
|
// that just want to get the job done.
|
|
|
|
//
|
|
|
|
// To enforce this and catch bugs, nsContentUtils::SubjectPrincipal will crash
|
|
|
|
// if it is invoked without script on the stack. To land that transition, it
|
|
|
|
// was necessary to go through and whitelist a bunch of callers that were
|
|
|
|
// depending on the old behavior. Those callers should be fixed up, and these
|
|
|
|
// methods should not be used by new code without review from bholley or bz.
|
|
|
|
static bool LegacyIsCallerNativeCode() { return !GetCurrentJSContext(); }
|
|
|
|
static bool LegacyIsCallerChromeOrNativeCode() {
|
|
|
|
return LegacyIsCallerNativeCode() || IsCallerChrome();
|
|
|
|
}
|
|
|
|
static nsIPrincipal* SubjectPrincipalOrSystemIfNativeCaller() {
|
|
|
|
if (!GetCurrentJSContext()) {
|
|
|
|
return GetSystemPrincipal();
|
|
|
|
}
|
|
|
|
return SubjectPrincipal();
|
|
|
|
}
|
|
|
|
|
2013-02-08 18:24:21 +04:00
|
|
|
static bool LookupBindingMember(
|
|
|
|
JSContext* aCx, nsIContent* aContent, JS::Handle<jsid> aId,
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::MutableHandle<JS::PropertyDescriptor> aDesc);
|
2013-02-08 18:24:21 +04:00
|
|
|
|
2015-06-07 16:02:00 +03:00
|
|
|
// Check whether we should avoid leaking distinguishing information to JS/CSS.
|
2017-06-15 11:48:27 +03:00
|
|
|
// This function can be called both in the main thread and worker threads.
|
2017-03-29 10:43:54 +03:00
|
|
|
static bool ShouldResistFingerprinting();
|
2015-06-07 16:02:00 +03:00
|
|
|
static bool ShouldResistFingerprinting(nsIDocShell* aDocShell);
|
2019-03-06 02:13:34 +03:00
|
|
|
static bool ShouldResistFingerprinting(nsIPrincipal* aPrincipal);
|
2019-02-19 14:17:28 +03:00
|
|
|
static bool ShouldResistFingerprinting(const Document* aDoc);
|
2015-06-07 16:02:00 +03:00
|
|
|
|
2019-02-06 11:45:44 +03:00
|
|
|
// Prevent system colors from being exposed to CSS or canvas.
|
|
|
|
static bool UseStandinsForNativeColors();
|
|
|
|
|
2017-03-29 10:43:56 +03:00
|
|
|
// A helper function to calculate the rounded window size for fingerprinting
|
|
|
|
// resistance. The rounded size is based on the chrome UI size and available
|
|
|
|
// screen size. If the inputWidth/Height is greater than the available content
|
|
|
|
// size, this will report the available content size. Otherwise, it will
|
|
|
|
// round the size to the nearest upper 200x100.
|
|
|
|
static void CalcRoundedWindowSizeForResistingFingerprinting(
|
|
|
|
int32_t aChromeWidth, int32_t aChromeHeight, int32_t aScreenWidth,
|
|
|
|
int32_t aScreenHeight, int32_t aInputWidth, int32_t aInputHeight,
|
|
|
|
bool aSetOuterWidth, bool aSetOuterHeight, int32_t* aOutputWidth,
|
|
|
|
int32_t* aOutputHeight);
|
|
|
|
|
2010-07-16 16:50:28 +04:00
|
|
|
/**
|
|
|
|
* Returns the parent node of aChild crossing document boundaries.
|
2014-10-02 12:31:45 +04:00
|
|
|
* Uses the parent node in the composed document.
|
2010-07-16 16:50:28 +04:00
|
|
|
*/
|
|
|
|
static nsINode* GetCrossDocParentNode(nsINode* aChild);
|
|
|
|
|
2002-06-28 05:30:09 +04: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 18:59:28 +04:00
|
|
|
* @return true if aPossibleDescendant is a descendant of
|
|
|
|
* aPossibleAncestor (or is aPossibleAncestor). false
|
2002-06-28 05:30:09 +04:00
|
|
|
* otherwise.
|
2005-06-03 03:36:08 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ContentIsDescendantOf(const nsINode* aPossibleDescendant,
|
2010-05-11 05:12:34 +04:00
|
|
|
const nsINode* aPossibleAncestor);
|
2005-06-03 03:36:08 +04:00
|
|
|
|
2013-03-26 11:15:23 +04:00
|
|
|
/**
|
|
|
|
* Similar to ContentIsDescendantOf, except will treat an HTMLTemplateElement
|
|
|
|
* or ShadowRoot as an ancestor of things in the corresponding
|
|
|
|
* DocumentFragment. See the concept of "host-including inclusive ancestor" in
|
|
|
|
* the DOM specification.
|
|
|
|
*/
|
|
|
|
static bool ContentIsHostIncludingDescendantOf(
|
|
|
|
const nsINode* aPossibleDescendant, const nsINode* aPossibleAncestor);
|
|
|
|
|
2018-02-15 13:08:42 +03:00
|
|
|
/**
|
|
|
|
* Similar to above, but does special case only ShadowRoot,
|
|
|
|
* not HTMLTemplateElement.
|
|
|
|
*/
|
|
|
|
static bool ContentIsShadowIncludingDescendantOf(
|
|
|
|
const nsINode* aPossibleDescendant, const nsINode* aPossibleAncestor);
|
|
|
|
|
2009-08-27 19:51:41 +04:00
|
|
|
/**
|
2014-08-27 07:19:56 +04:00
|
|
|
* Similar to ContentIsDescendantOf except it crosses document boundaries,
|
2014-10-02 12:31:45 +04:00
|
|
|
* this function uses ancestor/descendant relations in the composed document
|
|
|
|
* (see shadow DOM spec).
|
2009-08-27 19:51:41 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ContentIsCrossDocDescendantOf(nsINode* aPossibleDescendant,
|
2009-08-27 19:51:41 +04:00
|
|
|
nsINode* aPossibleAncestor);
|
|
|
|
|
2017-04-26 07:00:10 +03:00
|
|
|
/**
|
|
|
|
* As with ContentIsCrossDocDescendantOf but crosses shadow boundaries but not
|
|
|
|
* cross document boundaries.
|
|
|
|
*
|
|
|
|
* @see nsINode::GetFlattenedTreeParentNode()
|
|
|
|
*/
|
|
|
|
static bool ContentIsFlattenedTreeDescendantOf(
|
|
|
|
const nsINode* aPossibleDescendant, const nsINode* aPossibleAncestor);
|
|
|
|
|
2017-08-31 20:42:06 +03:00
|
|
|
/**
|
|
|
|
* Same as `ContentIsFlattenedTreeDescendantOf`, but from the flattened tree
|
|
|
|
* point of view of the style system
|
|
|
|
*
|
|
|
|
* @see nsINode::GetFlattenedTreeParentNodeForStyle()
|
|
|
|
*/
|
|
|
|
static bool ContentIsFlattenedTreeDescendantOfForStyle(
|
|
|
|
const nsINode* aPossibleDescendant, const nsINode* aPossibleAncestor);
|
|
|
|
|
2018-02-15 13:08:42 +03:00
|
|
|
/**
|
|
|
|
* Retarget an object A against an object B
|
|
|
|
* @see https://dom.spec.whatwg.org/#retarget
|
|
|
|
*/
|
|
|
|
static nsINode* Retarget(nsINode* aTargetA, nsINode* aTargetB);
|
|
|
|
|
2002-06-26 00:03:06 +04:00
|
|
|
/*
|
|
|
|
* This method fills the |aArray| with all ancestor nodes of |aNode|
|
|
|
|
* including |aNode| at the zero index.
|
|
|
|
*/
|
2010-04-30 15:15:09 +04:00
|
|
|
static nsresult GetAncestors(nsINode* aNode, nsTArray<nsINode*>& aArray);
|
2002-06-26 00:03:06 +04: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.
|
|
|
|
*/
|
2018-05-30 05:58:49 +03:00
|
|
|
static nsresult GetAncestorsAndOffsets(nsINode* aNode, int32_t aOffset,
|
2009-03-20 11:15:35 +03:00
|
|
|
nsTArray<nsIContent*>* aAncestorNodes,
|
2012-08-22 19:56:38 +04:00
|
|
|
nsTArray<int32_t>* aAncestorOffsets);
|
2002-06-26 00:03:06 +04:00
|
|
|
|
2006-05-16 18:51:52 +04:00
|
|
|
/**
|
2017-05-03 13:57:53 +03:00
|
|
|
* Returns the common ancestor, if any, for two nodes.
|
|
|
|
*
|
|
|
|
* Returns null if the nodes are disconnected.
|
2002-06-26 00:03:06 +04:00
|
|
|
*/
|
2017-07-29 04:37:27 +03:00
|
|
|
static nsINode* GetCommonAncestor(nsINode* aNode1, nsINode* aNode2) {
|
|
|
|
if (aNode1 == aNode2) {
|
|
|
|
return aNode1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetCommonAncestorHelper(aNode1, aNode2);
|
|
|
|
}
|
2017-05-03 13:57:53 +03:00
|
|
|
|
2017-05-03 13:58:34 +03:00
|
|
|
/**
|
|
|
|
* Returns the common flattened tree ancestor, if any, for two given content
|
|
|
|
* nodes.
|
|
|
|
*/
|
|
|
|
static nsIContent* GetCommonFlattenedTreeAncestor(nsIContent* aContent1,
|
2017-07-29 04:37:27 +03:00
|
|
|
nsIContent* aContent2) {
|
|
|
|
if (aContent1 == aContent2) {
|
|
|
|
return aContent1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetCommonFlattenedTreeAncestorHelper(aContent1, aContent2);
|
|
|
|
}
|
2002-12-04 08:18:39 +03:00
|
|
|
|
2017-08-31 10:42:24 +03:00
|
|
|
/**
|
|
|
|
* Returns the common flattened tree ancestor from the point of view of the
|
|
|
|
* style system, if any, for two given content nodes.
|
|
|
|
*/
|
|
|
|
static Element* GetCommonFlattenedTreeAncestorForStyle(Element* aElement1,
|
|
|
|
Element* aElement2);
|
|
|
|
|
2018-12-12 00:35:40 +03:00
|
|
|
/**
|
|
|
|
* Returns the common ancestor under interactive content, if any.
|
|
|
|
* If neither one has interactive content as ancestor, common ancestor will be
|
|
|
|
* returned. If only one has interactive content as ancestor, null will be
|
|
|
|
* returned. If the nodes are the same, that node is returned.
|
|
|
|
*/
|
|
|
|
static nsINode* GetCommonAncestorUnderInteractiveContent(nsINode* aNode1,
|
|
|
|
nsINode* aNode2);
|
|
|
|
|
2006-05-16 18:51:52 +04:00
|
|
|
/**
|
|
|
|
* Returns true if aNode1 is before aNode2 in the same connected
|
|
|
|
* tree.
|
2018-09-05 00:31:57 +03:00
|
|
|
* aNode1Index and aNode2Index are in/out arguments. If non-null, and value is
|
|
|
|
* not -1, that value is used instead of calling slow ComputeIndexOf on the
|
|
|
|
* parent node. If value is -1, the value will be set to the return value of
|
|
|
|
* ComputeIndexOf.
|
2006-05-16 18:51:52 +04:00
|
|
|
*/
|
2018-09-05 00:31:57 +03:00
|
|
|
static bool PositionIsBefore(nsINode* aNode1, nsINode* aNode2,
|
|
|
|
int32_t* aNode1Index = nullptr,
|
|
|
|
int32_t* aNode2Index = nullptr);
|
2002-12-04 08:18:39 +03:00
|
|
|
|
2018-10-31 01:28:34 +03:00
|
|
|
struct ComparePointsCache {
|
|
|
|
int32_t ComputeIndexOf(nsINode* aParent, nsINode* aChild) {
|
|
|
|
if (aParent == mParent && aChild == mChild) {
|
|
|
|
return mIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
mIndex = aParent->ComputeIndexOf(aChild);
|
|
|
|
mParent = aParent;
|
|
|
|
mChild = aChild;
|
|
|
|
return mIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsINode* mParent = nullptr;
|
|
|
|
nsINode* mChild = nullptr;
|
|
|
|
int32_t mIndex = 0;
|
|
|
|
};
|
|
|
|
|
2006-10-21 05:30:54 +04: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 15:46:09 +03:00
|
|
|
* NOTE! If the two nodes aren't in the same connected subtree,
|
2010-10-19 07:24:39 +04:00
|
|
|
* the result is 1, and the optional aDisconnected parameter
|
2011-10-17 18:59:28 +04:00
|
|
|
* is set to true.
|
2017-07-19 16:49:52 +03:00
|
|
|
*
|
2018-10-31 01:28:34 +03:00
|
|
|
* Pass a cache object as aParent1Cache if you expect to repeatedly
|
|
|
|
* call this function with the same value as aParent1.
|
|
|
|
*
|
2017-07-19 16:49:52 +03:00
|
|
|
* XXX aOffset1 and aOffset2 should be uint32_t since valid offset value is
|
|
|
|
* between 0 - UINT32_MAX. However, these methods work even with
|
|
|
|
* negative offset values! E.g., when aOffset1 is -1 and aOffset is 0,
|
|
|
|
* these methods return -1. Some root callers depend on this behavior.
|
|
|
|
* On the other hand, nsINode can have ATTRCHILD_ARRAY_MAX_CHILD_COUN
|
|
|
|
* (0x3FFFFF) at most. Therefore, they can be int32_t for now.
|
2006-10-21 05:30:54 +04:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t ComparePoints(nsINode* aParent1, int32_t aOffset1,
|
|
|
|
nsINode* aParent2, int32_t aOffset2,
|
2018-10-31 01:28:34 +03:00
|
|
|
bool* aDisconnected = nullptr,
|
|
|
|
ComparePointsCache* aParent1Cache = nullptr);
|
2017-10-02 17:58:29 +03:00
|
|
|
static int32_t ComparePoints(const mozilla::RawRangeBoundary& aFirst,
|
|
|
|
const mozilla::RawRangeBoundary& aSecond,
|
|
|
|
bool* aDisconnected = nullptr);
|
2006-10-21 05:30:54 +04:00
|
|
|
|
2005-10-19 00:33:35 +04:00
|
|
|
/**
|
|
|
|
* Brute-force search of the element subtree rooted at aContent for
|
2005-10-21 19:17:15 +04:00
|
|
|
* an element with the given id. aId must be nonempty, otherwise
|
|
|
|
* this method may return nodes even if they have no id!
|
2005-10-19 00:33:35 +04:00
|
|
|
*/
|
2010-05-14 21:04:51 +04:00
|
|
|
static Element* MatchElementId(nsIContent* aContent, const nsAString& aId);
|
2005-10-19 00:33:35 +04:00
|
|
|
|
2005-11-16 05:55:29 +03:00
|
|
|
/**
|
|
|
|
* Similar to above, but to be used if one already has an atom for the ID
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
static Element* MatchElementId(nsIContent* aContent, const nsAtom* aId);
|
2005-11-16 05:55:29 +03:00
|
|
|
|
2002-12-04 08:18:39 +03:00
|
|
|
/**
|
|
|
|
* Reverses the document position flags passed in.
|
|
|
|
*
|
|
|
|
* @param aDocumentPosition The document position flags to be reversed.
|
|
|
|
*
|
|
|
|
* @return The reversed document position flags.
|
|
|
|
*
|
2018-05-30 05:58:49 +03:00
|
|
|
* @see Node
|
2002-12-04 08:18:39 +03:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint16_t ReverseDocumentPosition(uint16_t aDocumentPosition);
|
2002-04-12 14:11:00 +04:00
|
|
|
|
2015-08-06 17:44:16 +03:00
|
|
|
/**
|
|
|
|
* Returns a subdocument for aDocument with a particular outer window ID.
|
|
|
|
*
|
|
|
|
* @param aDocument
|
|
|
|
* The document whose subdocuments will be searched.
|
|
|
|
* @param aOuterWindowID
|
|
|
|
* The outer window ID for the subdocument to be found. This must
|
|
|
|
* be a value greater than 0.
|
2019-01-02 16:05:23 +03:00
|
|
|
* @return Document*
|
|
|
|
* A pointer to the found Document. nullptr if the subdocument
|
2015-08-06 17:44:16 +03:00
|
|
|
* cannot be found, or if either aDocument or aOuterWindowId were
|
|
|
|
* invalid. If the outer window ID belongs to aDocument itself, this
|
|
|
|
* will return a pointer to aDocument.
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static Document* GetSubdocumentWithOuterWindowId(Document* aDocument,
|
|
|
|
uint64_t aOuterWindowId);
|
2015-08-06 17:44:16 +03:00
|
|
|
|
2002-06-12 03:23:12 +04:00
|
|
|
static const nsDependentSubstring TrimCharsInSet(const char* aSet,
|
|
|
|
const nsAString& aValue);
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
template <bool IsWhitespace(char16_t)>
|
2003-02-27 03:49:36 +03:00
|
|
|
static const nsDependentSubstring TrimWhitespace(const nsAString& aStr,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aTrimTrailing = true);
|
2003-02-27 03:49:36 +03:00
|
|
|
|
2007-11-12 04:51:31 +03:00
|
|
|
/**
|
2008-07-02 20:28:43 +04:00
|
|
|
* Returns true if aChar is of class Ps, Pi, Po, Pf, or Pe.
|
2007-11-12 04:51:31 +03:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static bool IsFirstLetterPunctuation(uint32_t aChar);
|
|
|
|
static bool IsFirstLetterPunctuationAt(const nsTextFragment* aFrag,
|
|
|
|
uint32_t aOffset);
|
2016-05-06 11:13:45 +03:00
|
|
|
|
2008-07-02 20:28:43 +04:00
|
|
|
/**
|
|
|
|
* Returns true if aChar is of class Lu, Ll, Lt, Lm, Lo, Nd, Nl or No
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static bool IsAlphanumeric(uint32_t aChar);
|
|
|
|
static bool IsAlphanumericAt(const nsTextFragment* aFrag, uint32_t aOffset);
|
2007-11-12 04:51:31 +03:00
|
|
|
|
2008-06-11 04:27:00 +04: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).
|
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
static bool IsHTMLWhitespace(char16_t aChar);
|
2008-06-11 04:27:00 +04:00
|
|
|
|
2013-03-22 21:52:52 +04:00
|
|
|
/*
|
|
|
|
* Returns whether the character is an HTML whitespace (see IsHTMLWhitespace)
|
|
|
|
* or a nbsp character (U+00A0).
|
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
static bool IsHTMLWhitespaceOrNBSP(char16_t aChar);
|
2013-03-22 21:52:52 +04:00
|
|
|
|
2012-03-08 18:42:27 +04:00
|
|
|
/**
|
|
|
|
* Is the HTML local name a block element?
|
|
|
|
*/
|
2015-03-03 14:09:00 +03:00
|
|
|
static bool IsHTMLBlock(nsIContent* aContent);
|
2012-03-08 18:42:27 +04:00
|
|
|
|
2014-05-01 03:07:48 +04:00
|
|
|
enum ParseHTMLIntegerResultFlags {
|
|
|
|
eParseHTMLInteger_NoFlags = 0,
|
|
|
|
eParseHTMLInteger_IsPercent = 1 << 0,
|
2015-03-13 04:46:57 +03:00
|
|
|
// eParseHTMLInteger_NonStandard is set if the string representation of the
|
|
|
|
// integer was not the canonical one (e.g. had extra leading '+' or '0').
|
2014-05-01 03:07:48 +04:00
|
|
|
eParseHTMLInteger_NonStandard = 1 << 1,
|
|
|
|
eParseHTMLInteger_DidNotConsumeAllInput = 1 << 2,
|
|
|
|
// Set if one or more error flags were set.
|
|
|
|
eParseHTMLInteger_Error = 1 << 3,
|
|
|
|
eParseHTMLInteger_ErrorNoValue = 1 << 4,
|
2017-05-18 00:24:34 +03:00
|
|
|
eParseHTMLInteger_ErrorOverflow = 1 << 5,
|
|
|
|
// Use this flag to detect the difference between overflow and underflow
|
|
|
|
eParseHTMLInteger_Negative = 1 << 6,
|
2014-05-01 03:07:48 +04:00
|
|
|
};
|
|
|
|
static int32_t ParseHTMLInteger(const nsAString& aValue,
|
|
|
|
ParseHTMLIntegerResultFlags* aResult);
|
|
|
|
|
2010-06-25 06:01:07 +04: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-29 10:19:26 +04:00
|
|
|
static bool ParseIntMarginValue(const nsAString& aString,
|
|
|
|
nsIntMargin& aResult);
|
2010-06-25 06:01:07 +04:00
|
|
|
|
2012-04-24 14:57:23 +04: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
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t ParseLegacyFontSize(const nsAString& aValue);
|
2012-04-24 14:57:23 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
static void Shutdown();
|
2005-06-03 03:36:08 +04:00
|
|
|
|
2002-07-18 09:53:28 +04:00
|
|
|
/**
|
2010-02-07 17:20:35 +03:00
|
|
|
* Checks whether two nodes come from the same origin.
|
2002-07-18 09:53:28 +04:00
|
|
|
*/
|
2012-12-22 12:27:27 +04:00
|
|
|
static nsresult CheckSameOrigin(const nsINode* aTrustedNode,
|
|
|
|
const nsINode* unTrustedNode);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2002-07-16 17:09:15 +04:00
|
|
|
// Check if the (JS) caller can access aNode.
|
2018-11-26 23:11:12 +03:00
|
|
|
static bool CanCallerAccess(const nsINode* aNode);
|
2002-07-16 17:09:15 +04:00
|
|
|
|
2008-02-27 05:03:27 +03:00
|
|
|
// Check if the (JS) caller can access aWindow.
|
|
|
|
// aWindow can be either outer or inner window.
|
2016-01-30 20:05:36 +03:00
|
|
|
static bool CanCallerAccess(nsPIDOMWindowInner* aWindow);
|
2008-02-27 05:03:27 +03:00
|
|
|
|
2017-02-09 17:09:22 +03:00
|
|
|
// Check if the principal is chrome or an addon with the permission.
|
2017-10-03 01:05:19 +03:00
|
|
|
static bool PrincipalHasPermission(nsIPrincipal* aPrincipal,
|
|
|
|
const nsAtom* aPerm);
|
2017-02-09 17:09:22 +03:00
|
|
|
|
2017-02-01 23:47:59 +03:00
|
|
|
// Check if the JS caller is chrome or an addon with the permission.
|
2017-10-03 01:05:19 +03:00
|
|
|
static bool CallerHasPermission(JSContext* aCx, const nsAtom* aPerm);
|
2017-02-01 23:47:59 +03:00
|
|
|
|
2017-10-03 06:28:32 +03:00
|
|
|
/**
|
|
|
|
* Returns the triggering principal which should be used for the given URL
|
|
|
|
* attribute value with the given subject principal.
|
|
|
|
*
|
|
|
|
* If the attribute value is not an absolute URL, the subject principal will
|
|
|
|
* be ignored, and the node principal of aContent will be used instead.
|
|
|
|
* If aContent is non-null, this function will always return a principal.
|
|
|
|
* Otherewise, it may return null if aSubjectPrincipal is null or is rejected
|
|
|
|
* based on the attribute value.
|
|
|
|
*
|
|
|
|
* @param aContent The content on which the attribute is being set.
|
|
|
|
* @param aAttrValue The URL value of the attribute. For parsed attribute
|
|
|
|
* values, such as `srcset`, this function should be called separately
|
|
|
|
* for each URL value it contains.
|
|
|
|
* @param aSubjectPrincipal The subject principal of the scripted caller
|
|
|
|
* responsible for setting the attribute, or null if no scripted caller
|
|
|
|
* can be determined.
|
|
|
|
*/
|
|
|
|
static nsIPrincipal* GetAttrTriggeringPrincipal(
|
|
|
|
nsIContent* aContent, const nsAString& aAttrValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given string is guaranteed to be treated as an absolute
|
|
|
|
* URL, rather than a relative URL. In practice, this means any complete URL
|
|
|
|
* as supported by nsStandardURL, or any string beginning with a valid scheme
|
|
|
|
* which is known to the IO service, and has the URI_NORELATIVE flag.
|
|
|
|
*
|
|
|
|
* If the URL may be treated as absolute in some cases, but relative in others
|
|
|
|
* (for instance, "http:foo", which can be either an absolute or relative URL,
|
|
|
|
* depending on the context), this function returns false.
|
|
|
|
*/
|
|
|
|
static bool IsAbsoluteURL(const nsACString& aURL);
|
|
|
|
|
2002-09-04 10:57:25 +04:00
|
|
|
// Check if a node is in the document prolog, i.e. before the document
|
|
|
|
// element.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool InProlog(nsINode* aNode);
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
static nsNameSpaceManager* NameSpaceManager() { return sNameSpaceManager; }
|
2002-11-30 02:44:07 +03:00
|
|
|
|
2005-09-11 14:08:43 +04:00
|
|
|
static nsIIOService* GetIOService() { return sIOService; }
|
2005-02-03 20:23:35 +03:00
|
|
|
|
2006-08-08 09:14:52 +04:00
|
|
|
static nsIBidiKeyboard* GetBidiKeyboard();
|
2014-04-24 05:15:29 +04:00
|
|
|
|
2005-10-14 13:07:29 +04:00
|
|
|
/**
|
|
|
|
* Get the cache security manager service. Can return null if the layout
|
|
|
|
* module has been shut down.
|
|
|
|
*/
|
|
|
|
static nsIScriptSecurityManager* GetSecurityManager() {
|
2003-10-22 02:11:49 +04:00
|
|
|
return sSecurityManager;
|
|
|
|
}
|
2005-06-03 03:36:08 +04:00
|
|
|
|
2017-02-06 01:19:26 +03:00
|
|
|
// Returns the subject principal from the JSContext. May only be called
|
|
|
|
// from the main thread and assumes an existing compartment.
|
|
|
|
static nsIPrincipal* SubjectPrincipal(JSContext* aCx);
|
|
|
|
|
2012-10-19 03:37:14 +04:00
|
|
|
// Returns the subject principal. Guaranteed to return non-null. May only
|
|
|
|
// be called when nsContentUtils is initialized.
|
2014-05-13 13:58:00 +04:00
|
|
|
static nsIPrincipal* SubjectPrincipal();
|
|
|
|
|
|
|
|
// Returns the prinipal of the given JS object. This may only be called on
|
2018-08-10 12:57:39 +03:00
|
|
|
// the main thread for objects from the main thread's JSRuntime. The object
|
|
|
|
// must not be a cross-compartment wrapper, because CCWs are not associated
|
|
|
|
// with a single realm.
|
2014-05-13 13:58:00 +04:00
|
|
|
static nsIPrincipal* ObjectPrincipal(JSObject* aObj);
|
2013-01-17 06:50:25 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
static nsresult GenerateStateKey(nsIContent* aContent, Document* aDocument,
|
2003-05-30 04:21:01 +04:00
|
|
|
nsACString& aKey);
|
|
|
|
|
2003-07-08 09:35:04 +04:00
|
|
|
/**
|
2003-07-08 13:23:32 +04:00
|
|
|
* 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.
|
2003-07-08 09:35:04 +04:00
|
|
|
*/
|
|
|
|
static nsresult NewURIWithDocumentCharset(nsIURI** aResult,
|
|
|
|
const nsAString& aSpec,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDocument,
|
2003-07-08 09:35:04 +04:00
|
|
|
nsIURI* aBaseURI);
|
2003-07-15 06:07:55 +04:00
|
|
|
|
2018-05-11 22:44:46 +03:00
|
|
|
/**
|
|
|
|
* Returns true if |aName| is a name with dashes.
|
|
|
|
*/
|
|
|
|
static bool IsNameWithDash(nsAtom* aName);
|
|
|
|
|
2014-02-24 01:01:26 +04:00
|
|
|
/**
|
|
|
|
* Returns true if |aName| is a valid name to be registered via
|
2017-11-16 07:23:15 +03:00
|
|
|
* customElements.define.
|
2014-02-24 01:01:26 +04:00
|
|
|
*/
|
2018-03-29 19:34:56 +03:00
|
|
|
static bool IsCustomElementName(nsAtom* aName, uint32_t aNameSpaceID);
|
2014-02-24 01:01:26 +04:00
|
|
|
|
2004-02-10 13:58:13 +03:00
|
|
|
static nsresult CheckQName(const nsAString& aQualifiedName,
|
2012-03-30 01:31:40 +04:00
|
|
|
bool aNamespaceAware = true,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t** aColon = nullptr);
|
2004-02-10 13:58:13 +03:00
|
|
|
|
2010-10-07 23:19:32 +04:00
|
|
|
static nsresult SplitQName(const nsIContent* aNamespaceResolver,
|
2017-06-20 12:19:05 +03:00
|
|
|
const nsString& aQName, int32_t* aNamespace,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom** aLocalName);
|
2005-01-01 21:02:03 +03:00
|
|
|
|
2004-02-10 13:58:13 +03:00
|
|
|
static nsresult GetNodeInfoFromQName(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aQualifiedName,
|
2004-06-25 16:26:02 +04:00
|
|
|
nsNodeInfoManager* aNodeInfoManager,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t aNodeType,
|
2014-06-20 06:01:40 +04:00
|
|
|
mozilla::dom::NodeInfo** aNodeInfo);
|
2004-02-10 13:58:13 +03:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
static void SplitExpatName(const char16_t* aExpatName, nsAtom** aPrefix,
|
|
|
|
nsAtom** aTagName, int32_t* aNameSpaceID);
|
2004-12-15 18:37:23 +03:00
|
|
|
|
2012-05-09 01:47:18 +04:00
|
|
|
// Get a permission-manager setting for the given principal and type.
|
2011-10-17 18:59:28 +04:00
|
|
|
// If the pref doesn't exist or if it isn't ALLOW_ACTION, false is
|
2012-05-09 01:47:18 +04:00
|
|
|
// returned, otherwise true is returned. Always returns true for the
|
|
|
|
// system principal, and false for a null principal.
|
2019-02-22 01:54:28 +03:00
|
|
|
static bool IsSitePermAllow(nsIPrincipal* aPrincipal,
|
|
|
|
const nsACString& aType);
|
2012-05-09 01:47:18 +04:00
|
|
|
|
|
|
|
// 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.
|
2019-02-22 01:54:28 +03:00
|
|
|
static bool IsSitePermDeny(nsIPrincipal* aPrincipal, const nsACString& aType);
|
2012-09-25 23:33:01 +04:00
|
|
|
|
|
|
|
// Get a permission-manager setting for the given principal and type.
|
|
|
|
// If the pref doesn't exist or if it isn't ALLOW_ACTION, false is
|
|
|
|
// returned, otherwise true is returned. Always returns true for the
|
|
|
|
// system principal, and false for a null principal.
|
|
|
|
// This version checks the permission for an exact host match on
|
|
|
|
// the principal
|
2019-02-22 01:54:28 +03:00
|
|
|
static bool IsExactSitePermAllow(nsIPrincipal* aPrincipal,
|
|
|
|
const nsACString& aType);
|
2012-09-25 23:33:01 +04:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
// This version checks the permission for an exact host match on
|
|
|
|
// the principal
|
2019-02-22 01:54:28 +03:00
|
|
|
static bool IsExactSitePermDeny(nsIPrincipal* aPrincipal,
|
|
|
|
const nsACString& aType);
|
2010-08-20 03:12:46 +04:00
|
|
|
|
2012-05-22 00:43:36 +04:00
|
|
|
// Returns true if aDoc1 and aDoc2 have equal NodePrincipal()s.
|
2019-01-02 16:05:23 +03:00
|
|
|
static bool HaveEqualPrincipals(Document* aDoc1, Document* aDoc2);
|
2012-05-22 00:43:36 +04:00
|
|
|
|
2017-12-14 07:17:32 +03:00
|
|
|
static mozilla::intl::LineBreaker* LineBreaker() {
|
|
|
|
return sLineBreaker.get();
|
2005-08-22 07:00:06 +04:00
|
|
|
}
|
|
|
|
|
2017-12-14 07:17:38 +03:00
|
|
|
static mozilla::intl::WordBreaker* WordBreaker() {
|
|
|
|
return sWordBreaker.get();
|
2005-08-22 07:00:06 +04:00
|
|
|
}
|
|
|
|
|
2010-02-24 22:14:14 +03: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);
|
|
|
|
|
2006-01-18 07:09:33 +03:00
|
|
|
/**
|
2011-10-17 18:59:28 +04:00
|
|
|
* @return true if aContent has an attribute aName in namespace aNameSpaceID,
|
2006-01-18 07:09:33 +03:00
|
|
|
* and the attribute value is non-empty.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static bool HasNonEmptyAttr(const nsIContent* aContent, int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aName);
|
2006-01-18 07:09:33 +03:00
|
|
|
|
2007-07-13 12:49:07 +04:00
|
|
|
/**
|
|
|
|
* Method that gets the primary presContext for the node.
|
2016-07-23 00:11:41 +03:00
|
|
|
*
|
2007-07-13 12:49:07 +04:00
|
|
|
* @param aContent The content node.
|
2012-07-30 18:20:58 +04:00
|
|
|
* @return the presContext, or nullptr if the content is not in a document
|
2018-01-29 08:19:25 +03:00
|
|
|
* (if GetComposedDoc returns nullptr)
|
2007-07-13 12:49:07 +04:00
|
|
|
*/
|
2010-10-07 23:19:32 +04:00
|
|
|
static nsPresContext* GetContextForContent(const nsIContent* aContent);
|
2007-07-13 12:49:07 +04:00
|
|
|
|
2018-01-29 08:19:25 +03:00
|
|
|
/**
|
|
|
|
* Method that gets the pres shell for the node.
|
|
|
|
*
|
|
|
|
* @param aContent The content node.
|
|
|
|
* @return the pres shell, or nullptr if the content is not in a document
|
|
|
|
* (if GetComposedDoc returns nullptr)
|
|
|
|
*/
|
2019-03-29 17:14:26 +03:00
|
|
|
static nsIPresShell* GetPresShellForContent(const nsIContent* aContent);
|
2018-01-29 08:19:25 +03:00
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
/**
|
|
|
|
* Method to do security and content policy checks on the image URI
|
|
|
|
*
|
|
|
|
* @param aURI uri of the image to be loaded
|
2018-03-29 13:16:23 +03:00
|
|
|
* @param aNode, the context the image is loaded in (eg an element)
|
2004-03-09 06:57:51 +03:00
|
|
|
* @param aLoadingDocument the document we belong to
|
2007-07-03 22:45:39 +04:00
|
|
|
* @param aLoadingPrincipal the principal doing the load
|
2015-09-21 00:55:59 +03:00
|
|
|
* @param [aContentPolicyType=nsIContentPolicy::TYPE_INTERNAL_IMAGE]
|
2014-08-20 01:49:14 +04:00
|
|
|
* (Optional) The CP content type to use
|
2005-03-02 07:05:12 +03: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 18:59:28 +04:00
|
|
|
* @return true if the load can proceed, or false if it is blocked.
|
2005-03-02 07:05:12 +03:00
|
|
|
* Note that aImageBlockingStatus, if set will always be an ACCEPT
|
2011-10-17 18:59:28 +04:00
|
|
|
* status if true is returned and always be a REJECT_* status if
|
|
|
|
* false is returned.
|
2004-03-09 06:57:51 +03:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool CanLoadImage(nsIURI* aURI, nsINode* aNode,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aLoadingDocument,
|
2018-05-30 22:21:17 +03:00
|
|
|
nsIPrincipal* aLoadingPrincipal);
|
2014-08-20 01:49:14 +04:00
|
|
|
|
2015-02-13 05:44:32 +03:00
|
|
|
/**
|
|
|
|
* Returns true if objects in aDocument shouldn't initiate image loads.
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static bool DocumentInactiveForImageLoads(Document* aDocument);
|
2015-02-13 05:44:32 +03:00
|
|
|
|
2018-01-31 19:10:01 +03:00
|
|
|
/**
|
|
|
|
* Convert a CORSMode into the corresponding imgILoader flags for
|
|
|
|
* passing to LoadImage.
|
|
|
|
* @param aMode CORS mode to convert
|
|
|
|
* @return a bitfield suitable to bitwise OR with other nsIRequest flags
|
|
|
|
*/
|
|
|
|
static int32_t CORSModeToLoadImageFlags(mozilla::CORSMode aMode);
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
/**
|
|
|
|
* Method to start an image load. This does not do any security checks.
|
2007-10-26 23:54:41 +04:00
|
|
|
* This method will attempt to make aURI immutable; a caller that wants to
|
|
|
|
* keep a mutable version around should pass in a clone.
|
2004-03-09 06:57:51 +03:00
|
|
|
*
|
|
|
|
* @param aURI uri of the image to be loaded
|
2016-04-11 11:58:03 +03:00
|
|
|
* @param aContext element of document where the result of this request
|
|
|
|
* will be used.
|
2004-03-09 06:57:51 +03:00
|
|
|
* @param aLoadingDocument the document we belong to
|
2007-07-03 22:45:39 +04:00
|
|
|
* @param aLoadingPrincipal the principal doing the load
|
|
|
|
* @param aReferrer the referrer URI
|
2014-11-18 16:46:53 +03:00
|
|
|
* @param aReferrerPolicy the referrer-sending policy to use on channel
|
|
|
|
* creation
|
2004-03-09 06:57:51 +03:00
|
|
|
* @param aObserver the observer for the image load
|
|
|
|
* @param aLoadFlags the load flags to use. See nsIRequest
|
2015-09-21 00:55:59 +03:00
|
|
|
* @param [aContentPolicyType=nsIContentPolicy::TYPE_INTERNAL_IMAGE]
|
2014-08-20 01:49:14 +04:00
|
|
|
* (Optional) The CP content type to use
|
2017-04-25 04:17:38 +03:00
|
|
|
* @param aUseUrgentStartForChannel,(Optional) a flag to mark on channel if it
|
|
|
|
* is triggered by user input events.
|
2004-03-09 06:57:51 +03:00
|
|
|
* @return the imgIRequest for the image load
|
|
|
|
*/
|
|
|
|
static nsresult LoadImage(
|
2019-01-02 16:05:23 +03:00
|
|
|
nsIURI* aURI, nsINode* aContext, Document* aLoadingDocument,
|
2007-07-03 22:45:39 +04:00
|
|
|
nsIPrincipal* aLoadingPrincipal, uint64_t aRequestContextID,
|
2014-11-18 16:46:53 +03:00
|
|
|
nsIURI* aReferrer, mozilla::net::ReferrerPolicy aReferrerPolicy,
|
2012-10-12 20:11:22 +04:00
|
|
|
imgINotificationObserver* aObserver, int32_t aLoadFlags,
|
2013-10-16 05:35:44 +04:00
|
|
|
const nsAString& initiatorType, imgRequestProxy** aRequest,
|
2017-04-25 04:17:38 +03:00
|
|
|
uint32_t aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE,
|
|
|
|
bool aUseUrgentStartForChannel = false);
|
2004-06-25 16:26:02 +04:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
/**
|
|
|
|
* Obtain an image loader that respects the given document/channel's privacy
|
|
|
|
* status. Null document/channel arguments return the public image loader.
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static imgLoader* GetImgLoaderForDocument(Document* aDoc);
|
2015-02-13 05:44:32 +03:00
|
|
|
static imgLoader* GetImgLoaderForChannel(nsIChannel* aChannel,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aContext);
|
2012-06-26 08:20:12 +04:00
|
|
|
|
2009-07-08 09:23:20 +04:00
|
|
|
/**
|
|
|
|
* Returns whether the given URI is in the image cache.
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static bool IsImageInCache(nsIURI* aURI, Document* aDocument);
|
2009-07-08 09:23:20 +04:00
|
|
|
|
2004-07-30 10:04:57 +04: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-21 05:50:15 +04:00
|
|
|
* Method to get an imgIContainer from an image loading content
|
2004-07-30 10:04:57 +04:00
|
|
|
*
|
|
|
|
* @param aContent The image loading content. Must not be null.
|
2005-02-08 01:20:14 +03:00
|
|
|
* @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-21 05:50:15 +04:00
|
|
|
* @return the imgIContainer corresponding to the first frame of the image
|
2004-07-30 10:04:57 +04:00
|
|
|
*/
|
2012-07-30 18:20:58 +04:00
|
|
|
static already_AddRefed<imgIContainer> GetImageFromContent(
|
|
|
|
nsIImageLoadingContent* aContent, imgIRequest** aRequest = nullptr);
|
2004-07-30 10:04:57 +04:00
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
/**
|
|
|
|
* Helper method to call imgIRequest::GetStaticRequest.
|
|
|
|
*/
|
2017-07-19 21:15:11 +03:00
|
|
|
static already_AddRefed<imgRequestProxy> GetStaticRequest(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aLoadingDocument, imgRequestProxy* aRequest);
|
2009-12-11 07:02:13 +03:00
|
|
|
|
2004-07-30 10:04:57 +04:00
|
|
|
/**
|
|
|
|
* Method that decides whether a content node is draggable
|
|
|
|
*
|
|
|
|
* @param aContent The content node to test.
|
|
|
|
* @return whether it's draggable
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ContentIsDraggable(nsIContent* aContent);
|
2004-07-30 10:04:57 +04: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-29 10:19:26 +04:00
|
|
|
static bool IsDraggableImage(nsIContent* aContent);
|
2004-07-30 10:04:57 +04: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-29 10:19:26 +04:00
|
|
|
static bool IsDraggableLink(const nsIContent* aContent);
|
2004-07-30 10:04:57 +04:00
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
/**
|
2017-02-21 06:44:00 +03:00
|
|
|
* Convenience method to create a new nodeinfo that differs only by prefix and
|
|
|
|
* name from aNodeInfo. The new nodeinfo's name is set to aName, and prefix is
|
|
|
|
* set to null.
|
2004-06-25 16:26:02 +04:00
|
|
|
*/
|
2017-02-21 06:44:00 +03:00
|
|
|
static nsresult QNameChanged(mozilla::dom::NodeInfo* aNodeInfo, nsAtom* aName,
|
|
|
|
mozilla::dom::NodeInfo** aResult);
|
2004-06-25 16:26:02 +04:00
|
|
|
|
2004-07-22 20:38:05 +04:00
|
|
|
/**
|
2006-06-13 07:07:47 +04: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
|
2014-05-09 06:20:54 +04:00
|
|
|
* on window takes 5 args.
|
2004-07-22 20:38:05 +04:00
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
static void GetEventArgNames(int32_t aNameSpaceID, nsAtom* aEventName,
|
2014-05-09 06:20:54 +04:00
|
|
|
bool aIsForWindow, uint32_t* aArgCount,
|
2012-08-22 19:56:38 +04:00
|
|
|
const char*** aArgNames);
|
2004-07-22 20:38:05 +04:00
|
|
|
|
2016-09-20 04:13:00 +03:00
|
|
|
/**
|
|
|
|
* Returns origin attributes of the document.
|
|
|
|
**/
|
2019-01-02 16:05:23 +03:00
|
|
|
static mozilla::OriginAttributes GetOriginAttributes(Document* aDoc);
|
2016-09-20 04:13:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns origin attributes of the load group.
|
|
|
|
**/
|
2017-01-12 19:38:48 +03:00
|
|
|
static mozilla::OriginAttributes GetOriginAttributes(
|
2016-09-20 04:13:00 +03:00
|
|
|
nsILoadGroup* aLoadGroup);
|
|
|
|
|
2017-02-06 18:37:15 +03:00
|
|
|
/**
|
|
|
|
* Returns true if this document is in a Private Browsing window.
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static bool IsInPrivateBrowsing(Document* aDoc);
|
2017-02-06 18:37:15 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this loadGroup uses Private Browsing.
|
|
|
|
*/
|
|
|
|
static bool IsInPrivateBrowsing(nsILoadGroup* aLoadGroup);
|
|
|
|
|
2007-01-30 08:48:22 +03:00
|
|
|
/**
|
|
|
|
* 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 18:59:28 +04:00
|
|
|
* aContent is a descendant of aNode, a return value of false from this
|
2007-01-30 08:48:22 +03: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-29 10:19:26 +04:00
|
|
|
static bool IsInSameAnonymousTree(const nsINode* aNode,
|
|
|
|
const nsIContent* aContent);
|
2007-01-30 08:48:22 +03:00
|
|
|
|
2019-02-08 02:23:45 +03:00
|
|
|
/*
|
|
|
|
* Traverse the parent chain from aElement up to aStop, and return true if
|
|
|
|
* there's an interactive html content; false otherwise.
|
|
|
|
*
|
|
|
|
* Note: This crosses shadow boundaries but not document boundaries.
|
|
|
|
*/
|
|
|
|
static bool IsInInteractiveHTMLContent(const Element* aElement,
|
|
|
|
const Element* aStop);
|
|
|
|
|
2004-09-01 20:50:12 +04:00
|
|
|
/**
|
|
|
|
* Return the nsIXPConnect service.
|
|
|
|
*/
|
|
|
|
static nsIXPConnect* XPConnect() { return sXPConnect; }
|
|
|
|
|
2013-09-26 22:07:29 +04:00
|
|
|
/**
|
|
|
|
* Report simple error message to the browser console
|
|
|
|
* @param aErrorText the error message
|
|
|
|
* @param classification Name of the module reporting error
|
|
|
|
*/
|
|
|
|
static void LogSimpleConsoleError(const nsAString& aErrorText,
|
2018-03-13 08:40:38 +03:00
|
|
|
const char* classification,
|
2019-03-26 21:27:55 +03:00
|
|
|
bool aFromPrivateWindow);
|
2013-09-26 22:07:29 +04:00
|
|
|
|
2012-10-31 08:15:24 +04:00
|
|
|
/**
|
|
|
|
* Report a non-localized error message to the error console.
|
|
|
|
* @param aErrorText the error message
|
|
|
|
* @param aErrorFlags See nsIScriptError.
|
|
|
|
* @param aCategory Name of module reporting error.
|
|
|
|
* @param aDocument Reference to the document which triggered the message.
|
|
|
|
* @param [aURI=nullptr] (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.
|
2016-03-11 07:28:41 +03:00
|
|
|
* @param [aLocationMode] (Optional) Specifies the behavior if
|
|
|
|
error location information is omitted.
|
|
|
|
*/
|
|
|
|
enum MissingErrorLocationMode {
|
|
|
|
// Don't show location information in the error console.
|
|
|
|
eOMIT_LOCATION,
|
|
|
|
// Get location information from the currently executing script.
|
|
|
|
eUSE_CALLING_LOCATION
|
|
|
|
};
|
2012-10-31 08:15:24 +04:00
|
|
|
static nsresult ReportToConsoleNonLocalized(
|
|
|
|
const nsAString& aErrorText, uint32_t aErrorFlags,
|
2019-01-02 16:05:23 +03:00
|
|
|
const nsACString& aCategory, const Document* aDocument,
|
2017-06-20 12:19:05 +03:00
|
|
|
nsIURI* aURI = nullptr, const nsString& aSourceLine = EmptyString(),
|
2016-03-11 07:28:41 +03:00
|
|
|
uint32_t aLineNumber = 0, uint32_t aColumnNumber = 0,
|
|
|
|
MissingErrorLocationMode aLocationMode = eUSE_CALLING_LOCATION);
|
2012-10-31 08:15:24 +04:00
|
|
|
|
2017-02-06 04:19:34 +03:00
|
|
|
/**
|
|
|
|
* Report a non-localized error message to the error console base on the
|
|
|
|
* innerWindowID.
|
|
|
|
* @param aErrorText the error message
|
|
|
|
* @param aErrorFlags See nsIScriptError.
|
|
|
|
* @param aCategory Name of module reporting error.
|
|
|
|
* @param [aInnerWindowID] Inner window ID for document which triggered the
|
|
|
|
* message.
|
|
|
|
* @param [aURI=nullptr] (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.
|
|
|
|
* @param [aLocationMode] (Optional) Specifies the behavior if
|
|
|
|
error location information is omitted.
|
|
|
|
*/
|
|
|
|
static nsresult ReportToConsoleByWindowID(
|
|
|
|
const nsAString& aErrorText, uint32_t aErrorFlags,
|
|
|
|
const nsACString& aCategory, uint64_t aInnerWindowID,
|
2017-06-20 12:19:05 +03:00
|
|
|
nsIURI* aURI = nullptr, const nsString& aSourceLine = EmptyString(),
|
2017-02-06 04:19:34 +03:00
|
|
|
uint32_t aLineNumber = 0, uint32_t aColumnNumber = 0,
|
|
|
|
MissingErrorLocationMode aLocationMode = eUSE_CALLING_LOCATION);
|
|
|
|
|
2004-09-14 21:26:35 +04:00
|
|
|
/**
|
|
|
|
* Report a localized error message to the error console.
|
|
|
|
* @param aErrorFlags See nsIScriptError.
|
|
|
|
* @param aCategory Name of module reporting error.
|
2011-12-15 18:47:03 +04:00
|
|
|
* @param aDocument Reference to the document which triggered the message.
|
|
|
|
* @param aFile Properties file containing localized message.
|
|
|
|
* @param aMessageName Name of localized message.
|
2012-07-30 18:20:58 +04:00
|
|
|
* @param [aParams=nullptr] (Optional) Parameters to be substituted into
|
2011-12-15 18:47:03 +04:00
|
|
|
localized message.
|
|
|
|
* @param [aParamsLength=0] (Optional) Length of aParams.
|
2012-07-30 18:20:58 +04:00
|
|
|
* @param [aURI=nullptr] (Optional) URI of resource containing error.
|
2011-12-15 18:47:03 +04:00
|
|
|
* @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.
|
2004-09-14 21:26:35 +04:00
|
|
|
*/
|
|
|
|
enum PropertiesFile {
|
|
|
|
eCSS_PROPERTIES,
|
|
|
|
eXBL_PROPERTIES,
|
|
|
|
eXUL_PROPERTIES,
|
2004-11-23 20:45:37 +03:00
|
|
|
eLAYOUT_PROPERTIES,
|
2004-12-17 23:40:48 +03:00
|
|
|
eFORMS_PROPERTIES,
|
|
|
|
ePRINTING_PROPERTIES,
|
|
|
|
eDOM_PROPERTIES,
|
2011-11-01 15:33:11 +04:00
|
|
|
eHTMLPARSER_PROPERTIES,
|
2006-07-27 15:58:05 +04:00
|
|
|
eSVG_PROPERTIES,
|
2005-04-03 21:16:28 +04:00
|
|
|
eBRAND_PROPERTIES,
|
2006-02-14 05:06:48 +03:00
|
|
|
eCOMMON_DIALOG_PROPERTIES,
|
2012-12-27 20:12:06 +04:00
|
|
|
eMATHML_PROPERTIES,
|
2013-04-23 05:08:18 +04:00
|
|
|
eSECURITY_PROPERTIES,
|
2014-10-10 23:19:14 +04:00
|
|
|
eNECKO_PROPERTIES,
|
2004-09-14 21:26:35 +04:00
|
|
|
PropertiesFile_COUNT
|
|
|
|
};
|
2012-08-22 19:56:38 +04:00
|
|
|
static nsresult ReportToConsole(
|
2013-08-02 11:09:11 +04:00
|
|
|
uint32_t aErrorFlags, const nsACString& aCategory,
|
2019-01-02 16:05:23 +03:00
|
|
|
const Document* aDocument, PropertiesFile aFile, const char* aMessageName,
|
|
|
|
const char16_t** aParams = nullptr, uint32_t aParamsLength = 0,
|
|
|
|
nsIURI* aURI = nullptr, const nsString& aSourceLine = EmptyString(),
|
|
|
|
uint32_t aLineNumber = 0, uint32_t aColumnNumber = 0);
|
2004-09-14 21:26:35 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
static void ReportEmptyGetElementByIdArg(const Document* aDoc);
|
2017-12-20 08:46:01 +03:00
|
|
|
|
2016-01-04 20:32:21 +03:00
|
|
|
static void LogMessageToConsole(const char* aMsg);
|
|
|
|
|
2004-12-17 23:40:48 +03:00
|
|
|
/**
|
|
|
|
* Get the localized string named |aKey| in properties file |aFile|.
|
|
|
|
*/
|
|
|
|
static nsresult GetLocalizedString(PropertiesFile aFile, const char* aKey,
|
2017-08-04 07:40:52 +03:00
|
|
|
nsAString& aResult);
|
2004-12-17 23:40:48 +03:00
|
|
|
|
2016-06-29 17:48:44 +03:00
|
|
|
/**
|
|
|
|
* A helper function that parses a sandbox attribute (of an <iframe> or a CSP
|
|
|
|
* directive) and converts it to the set of flags used internally.
|
|
|
|
*
|
|
|
|
* @param aSandboxAttr the sandbox attribute
|
|
|
|
* @return the set of flags (SANDBOXED_NONE if aSandboxAttr is
|
|
|
|
* null)
|
|
|
|
*/
|
|
|
|
static uint32_t ParseSandboxAttributeToFlags(const nsAttrValue* aSandboxAttr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper function that checks if a string matches a valid sandbox flag.
|
|
|
|
*
|
|
|
|
* @param aFlag the potential sandbox flag.
|
|
|
|
* @return true if the flag is a sandbox flag.
|
|
|
|
*/
|
|
|
|
static bool IsValidSandboxFlag(const nsAString& aFlag);
|
|
|
|
|
2016-06-19 22:34:08 +03:00
|
|
|
/**
|
|
|
|
* A helper function that returns a string attribute corresponding to the
|
|
|
|
* sandbox flags.
|
|
|
|
*
|
|
|
|
* @param aFlags the sandbox flags
|
|
|
|
* @param aString the attribute corresponding to the flags (null if aFlags
|
|
|
|
* is zero)
|
|
|
|
*/
|
|
|
|
static void SandboxFlagsToString(uint32_t aFlags, nsAString& aString);
|
|
|
|
|
2015-06-17 13:44:27 +03:00
|
|
|
/**
|
|
|
|
* Helper function that generates a UUID.
|
|
|
|
*/
|
|
|
|
static nsresult GenerateUUIDInPlace(nsID& aUUID);
|
|
|
|
|
2017-07-10 16:05:56 +03:00
|
|
|
static bool PrefetchPreloadEnabled(nsIDocShell* aDocShell);
|
2012-08-20 22:34:32 +04:00
|
|
|
|
2017-12-13 03:20:06 +03:00
|
|
|
static void ExtractErrorValues(JSContext* aCx, JS::Handle<JS::Value> aValue,
|
|
|
|
nsAString& aSourceSpecOut, uint32_t* aLineOut,
|
|
|
|
uint32_t* aColumnOut, nsString& aMessageOut);
|
|
|
|
|
|
|
|
// Variant on `ExtractErrorValues` with a `nsACString`. This
|
|
|
|
// method is provided for backwards compatibility. Prefer the
|
|
|
|
// faster method above for your code.
|
2017-08-11 04:04:56 +03:00
|
|
|
static void ExtractErrorValues(JSContext* aCx, JS::Handle<JS::Value> aValue,
|
|
|
|
nsACString& aSourceSpecOut, uint32_t* aLineOut,
|
|
|
|
uint32_t* aColumnOut, nsString& aMessageOut);
|
|
|
|
|
2018-07-18 02:02:51 +03:00
|
|
|
static nsresult CalculateBufferSizeForImage(
|
|
|
|
const uint32_t& aStride, const mozilla::gfx::IntSize& aImageSize,
|
|
|
|
const mozilla::gfx::SurfaceFormat& aFormat, size_t* aMaxBufferSize,
|
|
|
|
size_t* aUsedBufferSize);
|
|
|
|
|
2018-11-14 09:29:51 +03:00
|
|
|
// Returns true if the URI's host is contained in a list which is a comma
|
|
|
|
// separated domain list. Each item may start with "*.". If starts with
|
|
|
|
// "*.", it matches any sub-domains.
|
|
|
|
// The aList argument must be a lower-case string.
|
|
|
|
static bool IsURIInList(nsIURI* aURI, const nsCString& aList);
|
|
|
|
|
2018-11-13 11:51:14 +03:00
|
|
|
// Returns true if the URI's host is contained in a pref list which is a comma
|
|
|
|
// separated domain list. Each item may start with "*.". If starts with
|
|
|
|
// "*.", it matches any sub-domains.
|
|
|
|
static bool IsURIInPrefList(nsIURI* aURI, const char* aPrefName);
|
|
|
|
|
2018-07-18 02:02:51 +03:00
|
|
|
private:
|
2004-12-17 23:40:48 +03:00
|
|
|
/**
|
|
|
|
* Fill (with the parameters given) the localized string named |aKey| in
|
|
|
|
* properties file |aFile|.
|
|
|
|
*/
|
|
|
|
static nsresult FormatLocalizedString(PropertiesFile aFile, const char* aKey,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t** aParams,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aParamsLength,
|
2017-08-04 07:40:52 +03:00
|
|
|
nsAString& aResult);
|
2016-05-06 11:13:45 +03:00
|
|
|
|
2012-03-09 06:22:57 +04:00
|
|
|
public:
|
2012-08-22 19:56:38 +04:00
|
|
|
template <uint32_t N>
|
2012-03-09 06:22:57 +04:00
|
|
|
static nsresult FormatLocalizedString(PropertiesFile aFile, const char* aKey,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* (&aParams)[N],
|
2017-08-04 07:40:52 +03:00
|
|
|
nsAString& aResult) {
|
2012-03-09 06:22:57 +04:00
|
|
|
return FormatLocalizedString(aFile, aKey, aParams, N, aResult);
|
|
|
|
}
|
2004-12-17 23:40:48 +03:00
|
|
|
|
2016-07-05 23:47:10 +03:00
|
|
|
/**
|
|
|
|
* Fill (with the parameters given) the localized string named |aKey| in
|
|
|
|
* properties file |aFile| consuming an nsTArray of nsString parameters rather
|
|
|
|
* than a char16_t** for the sake of avoiding use-after-free errors involving
|
|
|
|
* temporaries.
|
|
|
|
*/
|
|
|
|
static nsresult FormatLocalizedString(PropertiesFile aFile, const char* aKey,
|
|
|
|
const nsTArray<nsString>& aParamArray,
|
2017-08-04 07:40:52 +03:00
|
|
|
nsAString& aResult);
|
2016-07-05 23:47:10 +03:00
|
|
|
|
2005-06-03 03:36:08 +04:00
|
|
|
/**
|
|
|
|
* Returns true if aDocument is a chrome document
|
|
|
|
*/
|
2019-02-20 01:53:40 +03:00
|
|
|
static bool IsChromeDoc(const Document* aDocument) {
|
|
|
|
return aDocument && aDocument->NodePrincipal() == sSystemPrincipal;
|
|
|
|
}
|
2004-12-17 23:40:48 +03:00
|
|
|
|
2009-10-15 06:20:50 +04:00
|
|
|
/**
|
|
|
|
* Returns true if aDocument is in a docshell whose parent is the same type
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static bool IsChildOfSameType(Document* aDoc);
|
2009-10-15 06:20:50 +04:00
|
|
|
|
2013-03-20 00:30:53 +04:00
|
|
|
/**
|
2016-06-09 14:29:30 +03:00
|
|
|
* Returns true if the content-type will be rendered as plain-text.
|
2013-03-20 00:30:53 +04:00
|
|
|
*/
|
|
|
|
static bool IsPlainTextType(const nsACString& aContentType);
|
2016-06-09 14:29:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true iff the type is rendered as plain text and doesn't support
|
|
|
|
* non-UTF-8 encodings.
|
|
|
|
*/
|
|
|
|
static bool IsUtf8OnlyPlainTextType(const nsACString& aContentType);
|
2013-03-20 00:30:53 +04:00
|
|
|
|
2008-09-28 23:14:28 +04: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.
|
|
|
|
*/
|
2019-02-20 01:53:40 +03:00
|
|
|
static bool IsInChromeDocshell(const Document* aDocument) {
|
|
|
|
return aDocument && aDocument->IsInChromeDocShell();
|
|
|
|
}
|
2008-09-28 23:14:28 +04:00
|
|
|
|
2005-08-19 19:00:01 +04:00
|
|
|
/**
|
|
|
|
* Return the content policy service
|
|
|
|
*/
|
2005-08-24 01:00:00 +04:00
|
|
|
static nsIContentPolicy* GetContentPolicy();
|
2005-08-25 01:01:51 +04:00
|
|
|
|
2015-06-12 23:52:07 +03:00
|
|
|
/**
|
|
|
|
* Map internal content policy types to external ones.
|
|
|
|
*/
|
2017-05-18 08:05:55 +03:00
|
|
|
static inline nsContentPolicyType InternalContentPolicyTypeToExternal(
|
|
|
|
nsContentPolicyType aType);
|
2015-06-12 23:52:07 +03:00
|
|
|
|
2015-09-21 00:55:44 +03:00
|
|
|
/**
|
|
|
|
* Map internal content policy types to external ones or preload types:
|
|
|
|
* * TYPE_INTERNAL_SCRIPT_PRELOAD
|
|
|
|
* * TYPE_INTERNAL_IMAGE_PRELOAD
|
|
|
|
* * TYPE_INTERNAL_STYLESHEET_PRELOAD
|
|
|
|
*
|
|
|
|
* Note: DO NOT call this function unless you know what you're doing!
|
|
|
|
*/
|
2017-05-18 08:05:55 +03:00
|
|
|
static inline nsContentPolicyType
|
|
|
|
InternalContentPolicyTypeToExternalOrPreload(nsContentPolicyType aType);
|
2015-09-21 00:55:44 +03:00
|
|
|
|
2015-10-29 02:32:27 +03:00
|
|
|
/**
|
|
|
|
* Map internal content policy types to external ones, worker, or preload
|
|
|
|
* types:
|
|
|
|
* * TYPE_INTERNAL_WORKER
|
|
|
|
* * TYPE_INTERNAL_SHARED_WORKER
|
|
|
|
* * TYPE_INTERNAL_SERVICE_WORKER
|
|
|
|
*
|
|
|
|
* Note: DO NOT call this function unless you know what you're doing!
|
|
|
|
*/
|
|
|
|
static nsContentPolicyType InternalContentPolicyTypeToExternalOrWorker(
|
|
|
|
nsContentPolicyType aType);
|
|
|
|
|
2015-11-15 06:29:18 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the content policy type is any of:
|
|
|
|
* * TYPE_INTERNAL_SCRIPT_PRELOAD
|
|
|
|
* * TYPE_INTERNAL_IMAGE_PRELOAD
|
|
|
|
* * TYPE_INTERNAL_STYLESHEET_PRELOAD
|
|
|
|
*/
|
|
|
|
static bool IsPreloadType(nsContentPolicyType aType);
|
|
|
|
|
2018-02-05 18:37:27 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the pref "security.mixed_content.upgrade_display_content"
|
|
|
|
* is true and the content policy type is any of:
|
|
|
|
* * TYPE_IMAGE
|
|
|
|
* * TYPE_MEDIA
|
|
|
|
*/
|
|
|
|
static bool IsUpgradableDisplayType(nsContentPolicyType aType);
|
|
|
|
|
2006-04-24 23:52:21 +04:00
|
|
|
/**
|
|
|
|
* 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-05 00:39:10 +04:00
|
|
|
* The method has the side effect to call document's MayDispatchMutationEvent
|
|
|
|
* using aTargetForSubtreeModified as the parameter.
|
2006-04-24 23:52:21 +04:00
|
|
|
*
|
2006-06-02 04:58:04 +04:00
|
|
|
* @param aNode The node to search for listeners
|
|
|
|
* @param aType The type of listener (NS_EVENT_BITS_MUTATION_*)
|
2007-07-05 00:39:10 +04:00
|
|
|
* @param aTargetForSubtreeModified The node which is the target of the
|
|
|
|
* possible DOMSubtreeModified event.
|
2006-04-24 23:52:21 +04:00
|
|
|
*
|
|
|
|
* @return true if there are mutation listeners of the specified type
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool HasMutationListeners(nsINode* aNode, uint32_t aType,
|
2007-07-05 00:39:10 +04:00
|
|
|
nsINode* aTargetForSubtreeModified);
|
2006-04-24 23:52:21 +04:00
|
|
|
|
2011-05-09 23:33:03 +04: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 18:59:28 +04:00
|
|
|
* returns true.
|
2011-05-09 23:33:03 +04: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
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static bool HasMutationListeners(Document* aDocument, uint32_t aType);
|
2011-05-09 23:33:03 +04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-05-13 00:46:45 +03:00
|
|
|
static void MaybeFireNodeRemoved(nsINode* aChild, nsINode* aParent);
|
2011-05-09 23:33:03 +04:00
|
|
|
|
2005-10-10 22:38:57 +04:00
|
|
|
/**
|
2018-11-21 06:59:02 +03:00
|
|
|
* These methods create and dispatch a trusted event.
|
2005-10-10 22:38:57 +04:00
|
|
|
* Works only with events which can be created by calling
|
2019-01-02 16:05:23 +03:00
|
|
|
* Document::CreateEvent() with parameter "Events".
|
2018-11-21 06:59:02 +03:00
|
|
|
* Note that don't use these methods for "input" event. Use
|
|
|
|
* DispatchInputEvent() instead.
|
|
|
|
*
|
2005-10-10 22:38:57 +04:00
|
|
|
* @param aDoc The document which will be used to create the event.
|
|
|
|
* @param aTarget The target of the event, should be QIable to
|
2018-04-20 07:49:30 +03:00
|
|
|
* EventTarget.
|
2005-10-10 22:38:57 +04:00
|
|
|
* @param aEventName The name of the event.
|
|
|
|
* @param aCanBubble Whether the event can bubble.
|
|
|
|
* @param aCancelable Is the event cancelable.
|
2018-09-14 03:05:39 +03:00
|
|
|
* @param aCopmosed Is the event composed.
|
2005-10-10 22:38:57 +04:00
|
|
|
* @param aDefaultAction Set to true if default action should be taken,
|
2018-04-20 07:49:30 +03:00
|
|
|
* see EventTarget::DispatchEvent.
|
2005-10-10 22:38:57 +04:00
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static nsresult DispatchTrustedEvent(Document* aDoc, nsISupports* aTarget,
|
2005-10-10 22:38:57 +04:00
|
|
|
const nsAString& aEventName, CanBubble,
|
2018-06-25 19:23:50 +03:00
|
|
|
Cancelable,
|
2018-09-14 03:05:39 +03:00
|
|
|
Composed aComposed = Composed::eDefault,
|
2018-06-25 19:23:50 +03:00
|
|
|
bool* aDefaultAction = nullptr);
|
2013-04-22 05:25:28 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
static nsresult DispatchTrustedEvent(Document* aDoc, nsISupports* aTarget,
|
2018-09-14 03:05:39 +03:00
|
|
|
const nsAString& aEventName,
|
|
|
|
CanBubble aCanBubble,
|
|
|
|
Cancelable aCancelable,
|
|
|
|
bool* aDefaultAction) {
|
|
|
|
return DispatchTrustedEvent(aDoc, aTarget, aEventName, aCanBubble,
|
|
|
|
aCancelable, Composed::eDefault,
|
|
|
|
aDefaultAction);
|
|
|
|
}
|
|
|
|
|
2017-06-17 06:37:23 +03:00
|
|
|
/**
|
|
|
|
* This method creates and dispatches a trusted event using an event message.
|
|
|
|
* @param aDoc The document which will be used to create the event.
|
|
|
|
* @param aTarget The target of the event, should be QIable to
|
|
|
|
* EventTarget.
|
|
|
|
* @param aEventMessage The event message.
|
|
|
|
* @param aCanBubble Whether the event can bubble.
|
|
|
|
* @param aCancelable Is the event cancelable.
|
|
|
|
* @param aDefaultAction Set to true if default action should be taken,
|
2018-04-20 07:49:30 +03:00
|
|
|
* see EventTarget::DispatchEvent.
|
2017-06-17 06:37:23 +03:00
|
|
|
*/
|
|
|
|
template <class WidgetEventType>
|
2018-06-25 19:23:50 +03:00
|
|
|
static nsresult DispatchTrustedEvent(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDoc, nsISupports* aTarget, EventMessage aEventMessage,
|
2018-06-25 19:23:50 +03:00
|
|
|
CanBubble aCanBubble, Cancelable aCancelable,
|
|
|
|
bool* aDefaultAction = nullptr,
|
|
|
|
ChromeOnlyDispatch aOnlyChromeDispatch = ChromeOnlyDispatch::eNo) {
|
2017-06-17 06:37:23 +03:00
|
|
|
WidgetEventType event(true, aEventMessage);
|
|
|
|
MOZ_ASSERT(GetEventClassIDFromMessage(aEventMessage) == event.mClass);
|
|
|
|
return DispatchEvent(aDoc, aTarget, event, aEventMessage, aCanBubble,
|
2018-06-25 19:23:50 +03:00
|
|
|
aCancelable, Trusted::eYes, aDefaultAction,
|
2017-06-17 06:37:23 +03:00
|
|
|
aOnlyChromeDispatch);
|
|
|
|
}
|
|
|
|
|
2018-11-21 06:59:02 +03:00
|
|
|
/**
|
|
|
|
* This method dispatches "input" event with proper event class. If it's
|
|
|
|
* unsafe to dispatch, this put the event into the script runner queue.
|
|
|
|
* Input Events spec defines as:
|
|
|
|
* Input events are dispatched on elements that act as editing hosts,
|
|
|
|
* including elements with the contenteditable attribute set, textarea
|
|
|
|
* elements, and input elements that permit text input.
|
|
|
|
*
|
|
|
|
* @param aEventTarget The event target element of the "input" event.
|
|
|
|
* Must not be nullptr.
|
2019-01-07 13:10:57 +03:00
|
|
|
* @param aEditorInputType The inputType value of InputEvent.
|
|
|
|
* If aEventTarget won't dispatch "input" event
|
|
|
|
* with InputEvent, set EditorInputType::eUnknown.
|
2018-11-21 06:59:02 +03:00
|
|
|
* @param aTextEditor Optional. If this is called by editor,
|
|
|
|
* editor should set this. Otherwise, leave
|
|
|
|
* nullptr.
|
2019-02-19 09:28:19 +03:00
|
|
|
* @param aOptions Optional. If aEditorInputType value requires
|
|
|
|
* some additional data, they should be properly
|
|
|
|
* set with this argument.
|
2018-11-21 06:59:02 +03:00
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-03-13 05:34:48 +03:00
|
|
|
static nsresult DispatchInputEvent(Element* aEventTarget) {
|
|
|
|
return DispatchInputEvent(aEventTarget, mozilla::EditorInputType::eUnknown,
|
|
|
|
nullptr, InputEventOptions());
|
|
|
|
}
|
2019-02-19 09:28:19 +03:00
|
|
|
struct MOZ_STACK_CLASS InputEventOptions final {
|
|
|
|
InputEventOptions() = default;
|
2019-02-19 09:33:42 +03:00
|
|
|
explicit InputEventOptions(const nsAString& aData)
|
|
|
|
: mData(aData), mDataTransfer(nullptr) {}
|
|
|
|
explicit InputEventOptions(mozilla::dom::DataTransfer* aDataTransfer);
|
2019-02-19 09:28:19 +03:00
|
|
|
|
|
|
|
nsString mData;
|
2019-02-19 09:33:42 +03:00
|
|
|
mozilla::dom::DataTransfer* mDataTransfer;
|
2019-02-19 09:28:19 +03:00
|
|
|
};
|
2018-11-21 06:59:02 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
static nsresult DispatchInputEvent(Element* aEventTarget,
|
2019-01-07 13:10:57 +03:00
|
|
|
mozilla::EditorInputType aEditorInputType,
|
2019-02-19 09:28:19 +03:00
|
|
|
mozilla::TextEditor* aTextEditor,
|
|
|
|
const InputEventOptions& aOptions);
|
2018-11-21 06:59:02 +03:00
|
|
|
|
2012-02-14 03:07:04 +04:00
|
|
|
/**
|
|
|
|
* This method creates and dispatches a untrusted event.
|
|
|
|
* Works only with events which can be created by calling
|
2019-01-02 16:05:23 +03:00
|
|
|
* Document::CreateEvent() with parameter "Events".
|
2012-02-14 03:07:04 +04:00
|
|
|
* @param aDoc The document which will be used to create the event.
|
|
|
|
* @param aTarget The target of the event, should be QIable to
|
2018-04-20 07:49:30 +03:00
|
|
|
* EventTarget.
|
2012-02-14 03:07:04 +04:00
|
|
|
* @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,
|
2018-04-20 07:49:30 +03:00
|
|
|
* see EventTarget::DispatchEvent.
|
2012-02-14 03:07:04 +04:00
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static nsresult DispatchUntrustedEvent(Document* aDoc, nsISupports* aTarget,
|
2012-02-14 03:07:04 +04:00
|
|
|
const nsAString& aEventName, CanBubble,
|
2018-06-25 19:23:50 +03:00
|
|
|
Cancelable,
|
|
|
|
bool* aDefaultAction = nullptr);
|
2005-10-10 22:38:57 +04:00
|
|
|
|
2017-06-17 06:37:23 +03:00
|
|
|
/**
|
|
|
|
* This method creates and dispatches a untrusted event using an event
|
|
|
|
* message.
|
|
|
|
* @param aDoc The document which will be used to create the event.
|
|
|
|
* @param aTarget The target of the event, should be QIable to
|
|
|
|
* EventTarget.
|
|
|
|
* @param aEventMessage The event message.
|
|
|
|
* @param aCanBubble Whether the event can bubble.
|
|
|
|
* @param aCancelable Is the event cancelable.
|
|
|
|
* @param aDefaultAction Set to true if default action should be taken,
|
2018-04-20 07:49:30 +03:00
|
|
|
* see EventTarget::DispatchEvent.
|
2017-06-17 06:37:23 +03:00
|
|
|
*/
|
|
|
|
template <class WidgetEventType>
|
2018-06-25 19:23:50 +03:00
|
|
|
static nsresult DispatchUntrustedEvent(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDoc, nsISupports* aTarget, EventMessage aEventMessage,
|
2018-06-25 19:23:50 +03:00
|
|
|
CanBubble aCanBubble, Cancelable aCancelable,
|
|
|
|
bool* aDefaultAction = nullptr,
|
|
|
|
ChromeOnlyDispatch aOnlyChromeDispatch = ChromeOnlyDispatch::eNo) {
|
2017-06-17 06:37:23 +03:00
|
|
|
WidgetEventType event(false, aEventMessage);
|
|
|
|
MOZ_ASSERT(GetEventClassIDFromMessage(aEventMessage) == event.mClass);
|
|
|
|
return DispatchEvent(aDoc, aTarget, event, aEventMessage, aCanBubble,
|
2018-06-25 19:23:50 +03:00
|
|
|
aCancelable, Trusted::eNo, aDefaultAction,
|
2017-06-17 06:37:23 +03:00
|
|
|
aOnlyChromeDispatch);
|
|
|
|
}
|
|
|
|
|
2009-02-22 22:09:10 +03:00
|
|
|
/**
|
|
|
|
* This method creates and dispatches a trusted event to the chrome
|
2015-01-21 14:45:47 +03:00
|
|
|
* event handler (the parent object of the DOM Window in the event target
|
|
|
|
* chain). Note, chrome event handler is used even if aTarget is a chrome
|
|
|
|
* object. Use DispatchEventOnlyToChrome if the normal event dispatching is
|
|
|
|
* wanted in case aTarget is a chrome object.
|
2009-02-22 22:09:10 +03:00
|
|
|
* Works only with events which can be created by calling
|
2019-01-02 16:05:23 +03:00
|
|
|
* Document::CreateEvent() with parameter "Events".
|
2009-02-22 22:09:10 +03: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,
|
2018-04-20 07:49:30 +03:00
|
|
|
* see EventTarget::DispatchEvent.
|
2009-02-22 22:09:10 +03:00
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static nsresult DispatchChromeEvent(Document* aDoc, nsISupports* aTarget,
|
2009-02-22 22:09:10 +03:00
|
|
|
const nsAString& aEventName, CanBubble,
|
2018-06-25 19:23:50 +03:00
|
|
|
Cancelable,
|
|
|
|
bool* aDefaultAction = nullptr);
|
2009-02-22 22:09:10 +03:00
|
|
|
|
2016-03-31 17:06:00 +03:00
|
|
|
/**
|
2017-03-23 10:59:01 +03:00
|
|
|
* Helper function for dispatching a "DOMWindowFocus" event to
|
2016-03-31 17:06:00 +03:00
|
|
|
* the chrome event handler of the given DOM Window. This has the effect
|
|
|
|
* of focusing the corresponding tab and bringing the browser window
|
|
|
|
* to the foreground.
|
|
|
|
*/
|
|
|
|
static nsresult DispatchFocusChromeEvent(nsPIDOMWindowOuter* aWindow);
|
2015-01-21 14:45:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method creates and dispatches a trusted event.
|
|
|
|
* If aTarget is not a chrome object, the nearest chrome object in the
|
|
|
|
* propagation path will be used as the start of the event target chain.
|
|
|
|
* This method is different than DispatchChromeEvent, which always dispatches
|
|
|
|
* events to chrome event handler. DispatchEventOnlyToChrome works like
|
|
|
|
* DispatchTrustedEvent in the case aTarget is a chrome object.
|
|
|
|
* Works only with events which can be created by calling
|
2019-01-02 16:05:23 +03:00
|
|
|
* Document::CreateEvent() with parameter "Events".
|
2015-01-21 14:45:47 +03:00
|
|
|
* @param aDoc The document which will be used to create the event.
|
|
|
|
* @param aTarget The target of the event, should be QIable to
|
2018-04-20 07:49:30 +03:00
|
|
|
* EventTarget.
|
2015-01-21 14:45:47 +03:00
|
|
|
* @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,
|
2018-04-20 07:49:30 +03:00
|
|
|
* see EventTarget::DispatchEvent.
|
2015-01-21 14:45:47 +03:00
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static nsresult DispatchEventOnlyToChrome(Document* aDoc,
|
2015-01-21 14:45:47 +03:00
|
|
|
nsISupports* aTarget,
|
|
|
|
const nsAString& aEventName,
|
2018-06-25 19:23:50 +03:00
|
|
|
CanBubble, Cancelable,
|
|
|
|
bool* aDefaultAction = nullptr);
|
2015-01-21 14:45:47 +03:00
|
|
|
|
2007-04-02 21:17:36 +04: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
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
static bool IsEventAttributeName(nsAtom* aName, int32_t aType);
|
2007-04-02 21:17:36 +04:00
|
|
|
|
|
|
|
/**
|
2015-08-26 15:56:59 +03:00
|
|
|
* Return the event message for the event with the given name. The name is
|
2015-09-10 04:40:04 +03:00
|
|
|
* the event name with the 'on' prefix. Returns eUnidentifiedEvent if the
|
2007-04-02 21:17:36 +04:00
|
|
|
* event doesn't match a known event name.
|
|
|
|
*
|
|
|
|
* @param aName the event name to look up
|
|
|
|
*/
|
2018-06-25 19:23:50 +03:00
|
|
|
static EventMessage GetEventMessage(nsAtom* aName);
|
2007-04-02 21:17:36 +04:00
|
|
|
|
2016-05-20 12:15:05 +03:00
|
|
|
/**
|
2017-10-03 01:05:19 +03:00
|
|
|
* Returns the EventMessage and nsAtom to be used for event listener
|
2016-05-20 12:15:05 +03:00
|
|
|
* registration.
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
static EventMessage GetEventMessageAndAtomForListener(const nsAString& aName,
|
|
|
|
nsAtom** aOnName);
|
2016-05-20 12:15:05 +03:00
|
|
|
|
2011-04-19 00:57:32 +04:00
|
|
|
/**
|
2014-08-04 09:28:58 +04:00
|
|
|
* Return the EventClassID for the event with the given name. The name is the
|
2014-08-04 09:28:58 +04:00
|
|
|
* event name *without* the 'on' prefix. Returns eBasicEventClass if the event
|
2014-08-04 09:28:58 +04:00
|
|
|
* is not known to be of any particular event class.
|
2011-04-19 00:57:32 +04:00
|
|
|
*
|
|
|
|
* @param aName the event name to look up
|
|
|
|
*/
|
2014-08-04 09:28:58 +04:00
|
|
|
static mozilla::EventClassID GetEventClassID(const nsAString& aName);
|
2011-04-19 00:57:32 +04:00
|
|
|
|
2010-06-22 22:12:12 +04:00
|
|
|
/**
|
2015-08-26 15:56:59 +03:00
|
|
|
* Return the event message and atom for the event with the given name.
|
2010-06-22 22:12:12 +04:00
|
|
|
* The name is the event name *without* the 'on' prefix.
|
2015-09-10 04:40:04 +03:00
|
|
|
* Returns eUnidentifiedEvent on the aEventID if the
|
2010-06-22 22:12:12 +04:00
|
|
|
* event doesn't match a known event name in the category.
|
|
|
|
*
|
|
|
|
* @param aName the event name to look up
|
2014-08-04 09:28:58 +04:00
|
|
|
* @param aEventClassID only return event id for aEventClassID
|
2010-06-22 22:12:12 +04:00
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
static nsAtom* GetEventMessageAndAtom(const nsAString& aName,
|
2018-06-25 19:23:50 +03:00
|
|
|
mozilla::EventClassID aEventClassID,
|
|
|
|
EventMessage* aEventMessage);
|
2010-06-22 22:12:12 +04:00
|
|
|
|
2007-01-05 01:31:26 +03: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);
|
|
|
|
|
2006-02-07 17:34:10 +03:00
|
|
|
/**
|
2013-10-23 03:32:04 +04:00
|
|
|
* Get the eventlistener manager for aNode, creating it if it does not
|
|
|
|
* already exist.
|
2006-02-07 17:34:10 +03:00
|
|
|
*
|
2006-05-15 11:03:15 +04:00
|
|
|
* @param aNode The node for which to get the eventlistener manager.
|
2006-02-07 17:34:10 +03:00
|
|
|
*/
|
2014-03-17 10:56:53 +04:00
|
|
|
static mozilla::EventListenerManager* GetListenerManagerForNode(
|
|
|
|
nsINode* aNode);
|
2013-10-23 03:32:04 +04:00
|
|
|
/**
|
|
|
|
* Get the eventlistener manager for aNode, returning null if it does not
|
|
|
|
* already exist.
|
|
|
|
*
|
|
|
|
* @param aNode The node for which to get the eventlistener manager.
|
|
|
|
*/
|
2014-03-17 10:56:53 +04:00
|
|
|
static mozilla::EventListenerManager* GetExistingListenerManagerForNode(
|
|
|
|
const nsINode* aNode);
|
2006-02-07 17:34:10 +03:00
|
|
|
|
2015-06-10 23:07:40 +03:00
|
|
|
static void UnmarkGrayJSListenersInCCGenerationDocuments();
|
2012-01-26 18:51:58 +04:00
|
|
|
|
2006-02-07 17:34:10 +03:00
|
|
|
/**
|
2006-05-15 11:03:15 +04:00
|
|
|
* Remove the eventlistener manager for aNode.
|
2006-02-07 17:34:10 +03:00
|
|
|
*
|
2006-05-15 11:03:15 +04:00
|
|
|
* @param aNode The node for which to remove the eventlistener manager.
|
2006-02-07 17:34:10 +03:00
|
|
|
*/
|
2006-05-15 11:03:15 +04:00
|
|
|
static void RemoveListenerManager(nsINode* aNode);
|
2006-02-07 17:34:10 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsInitialized() { return sInitialized; }
|
2006-02-07 17:34:10 +03:00
|
|
|
|
2006-04-17 21:13:11 +04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
static bool IsValidNodeName(nsAtom* aLocalName, nsAtom* aPrefix,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNamespaceID);
|
2006-04-17 21:13:11 +04:00
|
|
|
|
2006-06-06 00:32:48 +04:00
|
|
|
/**
|
|
|
|
* Creates a DocumentFragment from text using a context node to resolve
|
|
|
|
* namespaces.
|
|
|
|
*
|
2018-05-28 23:55:52 +03:00
|
|
|
* Please note that for safety reasons, if the node principal of
|
|
|
|
* aContextNode is the system principal, this function will automatically
|
|
|
|
* sanitize its input using nsTreeSanitizer.
|
|
|
|
*
|
2010-09-01 15:41:07 +04: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!
|
|
|
|
*
|
2006-06-06 00:32:48 +04:00
|
|
|
* @param aContextNode the node which is used to resolve namespaces
|
|
|
|
* @param aFragment the string which is parsed to a DocumentFragment
|
2011-08-01 11:48:24 +04:00
|
|
|
* @param aReturn the resulting fragment
|
2011-08-01 11:48:28 +04:00
|
|
|
* @param aPreventScriptExecution whether to mark scripts as already started
|
2006-06-06 00:32:48 +04:00
|
|
|
*/
|
2013-02-07 16:09:41 +04:00
|
|
|
static already_AddRefed<mozilla::dom::DocumentFragment>
|
|
|
|
CreateContextualFragment(nsINode* aContextNode, const nsAString& aFragment,
|
|
|
|
bool aPreventScriptExecution,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2006-06-06 00:32:48 +04:00
|
|
|
|
2011-08-01 11:48:24 +04:00
|
|
|
/**
|
|
|
|
* Invoke the fragment parsing algorithm (innerHTML) using the HTML parser.
|
|
|
|
*
|
2018-05-28 23:55:52 +03:00
|
|
|
* Please note that for safety reasons, if the node principal of aTargetNode
|
|
|
|
* is the system principal, this function will automatically sanitize its
|
|
|
|
* input using nsTreeSanitizer.
|
|
|
|
*
|
2011-08-01 11:48:24 +04:00
|
|
|
* @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 14:39:19 +04:00
|
|
|
* @return NS_ERROR_DOM_INVALID_STATE_ERR if a re-entrant attempt to parse
|
2012-01-20 16:03:49 +04:00
|
|
|
* fragments is made, NS_ERROR_OUT_OF_MEMORY if aSourceBuffer is too
|
|
|
|
* long and NS_OK otherwise.
|
2011-08-01 11:48:24 +04:00
|
|
|
*/
|
2011-10-14 14:39:19 +04:00
|
|
|
static nsresult ParseFragmentHTML(const nsAString& aSourceBuffer,
|
|
|
|
nsIContent* aTargetNode,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aContextLocalName,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aContextNamespace, bool aQuirks,
|
2018-05-28 23:55:52 +03:00
|
|
|
bool aPreventScriptExecution);
|
2011-08-01 11:48:24 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoke the fragment parsing algorithm (innerHTML) using the XML parser.
|
|
|
|
*
|
2018-05-28 23:55:52 +03:00
|
|
|
* Please note that for safety reasons, if the node principal of aDocument
|
|
|
|
* is the system principal, this function will automatically sanitize its
|
|
|
|
* input using nsTreeSanitizer.
|
|
|
|
*
|
2011-08-01 11:48:24 +04:00
|
|
|
* @param aSourceBuffer the string being set as innerHTML
|
2018-05-28 23:55:52 +03:00
|
|
|
* @param aDocument the target document
|
2011-08-01 11:48:24 +04:00
|
|
|
* @param aTagStack the namespace mapping context
|
2011-08-01 11:48:28 +04:00
|
|
|
* @param aPreventExecution whether to mark scripts as already started
|
2011-08-01 11:48:24 +04:00
|
|
|
* @param aReturn the result fragment
|
2011-10-14 14:39:19 +04: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 11:48:24 +04:00
|
|
|
*/
|
|
|
|
static nsresult ParseFragmentXML(const nsAString& aSourceBuffer,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDocument,
|
2011-08-01 11:48:24 +04:00
|
|
|
nsTArray<nsString>& aTagStack,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aPreventScriptExecution,
|
2018-05-28 23:55:52 +03:00
|
|
|
mozilla::dom::DocumentFragment** aReturn);
|
2011-08-01 11:48:24 +04:00
|
|
|
|
2012-01-20 16:03:49 +04: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 15:57:48 +04:00
|
|
|
* @param aScriptingEnabledForNoscriptParsing whether <noscript> is parsed
|
|
|
|
* as if scripting was enabled
|
2012-01-20 16:03:49 +04: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,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aTargetDocument,
|
2012-02-27 15:57:48 +04:00
|
|
|
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, uint32_t aFlags,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aWrapCol);
|
2012-01-20 16:03:49 +04:00
|
|
|
|
2006-09-15 23:54:45 +04:00
|
|
|
/**
|
|
|
|
* 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, bool aTryReuse);
|
|
|
|
|
|
|
|
/**
|
2007-10-30 10:19:42 +03:00
|
|
|
* Get the textual contents of a node. This is a concatenation of all
|
2006-09-15 23:54:45 +04: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.
|
|
|
|
*
|
2015-09-01 02:24:37 +03:00
|
|
|
* @see nsLayoutUtils::GetFrameTextContent
|
|
|
|
*
|
2006-09-15 23:54:45 +04:00
|
|
|
* @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.
|
2014-03-19 21:05:03 +04:00
|
|
|
* @return false on out of memory errors, true otherwise.
|
2006-09-15 23:54:45 +04:00
|
|
|
*/
|
2016-04-27 07:16:50 +03:00
|
|
|
MOZ_MUST_USE
|
2014-03-19 21:05:03 +04:00
|
|
|
static bool GetNodeTextContent(nsINode* aNode, bool aDeep, nsAString& aResult,
|
2015-05-22 21:16:20 +03:00
|
|
|
const mozilla::fallible_t&);
|
|
|
|
|
|
|
|
static void GetNodeTextContent(nsINode* aNode, bool aDeep,
|
2015-03-19 10:46:40 +03:00
|
|
|
nsAString& aResult);
|
2006-09-15 23:54:45 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as GetNodeTextContents but appends the result rather than sets it.
|
|
|
|
*/
|
2014-03-19 21:05:02 +04:00
|
|
|
static bool AppendNodeTextContent(nsINode* aNode, bool aDeep,
|
|
|
|
nsAString& aResult,
|
|
|
|
const mozilla::fallible_t&);
|
2006-09-15 23:54:45 +04:00
|
|
|
|
2006-11-09 03:02:21 +03:00
|
|
|
/**
|
2014-10-29 02:28:00 +03:00
|
|
|
* Utility method that checks if a given node has any non-empty children. This
|
|
|
|
* method does not descend recursively into children by default.
|
|
|
|
*
|
|
|
|
* @param aDiscoverMode Set to eRecurseIntoChildren to descend recursively
|
|
|
|
* into children.
|
2006-11-09 03:02:21 +03:00
|
|
|
*/
|
2015-01-21 16:35:19 +03:00
|
|
|
enum TextContentDiscoverMode : uint8_t {
|
2014-10-29 02:28:00 +03:00
|
|
|
eRecurseIntoChildren,
|
|
|
|
eDontRecurseIntoChildren
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool HasNonEmptyTextContent(
|
|
|
|
nsINode* aNode,
|
|
|
|
TextContentDiscoverMode aDiscoverMode = eDontRecurseIntoChildren);
|
2006-11-09 03:02:21 +03:00
|
|
|
|
2007-02-01 18:14:00 +03:00
|
|
|
/**
|
|
|
|
* Delete strings allocated for nsContentList matches
|
|
|
|
*/
|
2013-08-21 23:28:26 +04:00
|
|
|
static void DestroyMatchString(void* aData);
|
2007-02-01 18:14:00 +03:00
|
|
|
|
2007-05-02 19:34:35 +04: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-29 10:19:26 +04:00
|
|
|
static void NotifyInstalledMenuKeyboardListener(bool aInstalling);
|
2007-06-13 01:56:06 +04:00
|
|
|
|
2017-09-26 03:21:01 +03:00
|
|
|
/**
|
|
|
|
* Check whether the nsIURI uses the given scheme.
|
|
|
|
*
|
|
|
|
* Note that this will check the innermost URI rather than that of
|
|
|
|
* the nsIURI itself.
|
|
|
|
*/
|
|
|
|
static bool SchemeIs(nsIURI* aURI, const char* aScheme);
|
|
|
|
|
2010-03-02 22:40:14 +03:00
|
|
|
/**
|
|
|
|
* Returns true if aPrincipal is the system principal.
|
2019-01-03 23:55:38 +03:00
|
|
|
*
|
|
|
|
* @deprecated Use nsIPrincipal::IsSystemPrincipal instead!
|
|
|
|
* https://bugzilla.mozilla.org/show_bug.cgi?id=1517588 tracks removing this.
|
2010-03-02 22:40:14 +03:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsSystemPrincipal(nsIPrincipal* aPrincipal);
|
2010-03-02 22:40:14 +03:00
|
|
|
|
2013-07-08 21:05:31 +04:00
|
|
|
/**
|
2017-03-22 13:38:17 +03:00
|
|
|
* Returns true if aPrincipal is an ExpandedPrincipal.
|
2013-07-08 21:05:31 +04:00
|
|
|
*/
|
|
|
|
static bool IsExpandedPrincipal(nsIPrincipal* aPrincipal);
|
|
|
|
|
2014-04-17 00:29:12 +04:00
|
|
|
/**
|
2017-03-22 13:38:17 +03:00
|
|
|
* Returns true if aPrincipal is the system or an ExpandedPrincipal.
|
2014-04-17 00:29:12 +04:00
|
|
|
*/
|
|
|
|
static bool IsSystemOrExpandedPrincipal(nsIPrincipal* aPrincipal) {
|
|
|
|
return IsSystemPrincipal(aPrincipal) || IsExpandedPrincipal(aPrincipal);
|
|
|
|
}
|
|
|
|
|
2013-04-04 13:27:38 +04:00
|
|
|
/**
|
|
|
|
* Gets the system principal from the security manager.
|
|
|
|
*/
|
|
|
|
static nsIPrincipal* GetSystemPrincipal();
|
|
|
|
|
2014-05-21 09:52:20 +04:00
|
|
|
/**
|
|
|
|
* Gets the null subject principal singleton. This is only useful for
|
|
|
|
* assertions.
|
|
|
|
*/
|
|
|
|
static nsIPrincipal* GetNullSubjectPrincipal() {
|
|
|
|
return sNullSubjectPrincipal;
|
|
|
|
}
|
|
|
|
|
2012-04-30 07:11:00 +04: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 17:05:05 +04: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).
|
2011-10-17 18:59:28 +04:00
|
|
|
* @param aIsTrusted If false, JS Context will be pushed to stack
|
2011-06-30 15:52:11 +04:00
|
|
|
* when the link is triggered.
|
2007-07-11 17:05:05 +04:00
|
|
|
*/
|
|
|
|
static void TriggerLink(nsIContent* aContent, nsPresContext* aPresContext,
|
|
|
|
nsIURI* aLinkURI, const nsString& aTargetSpec,
|
2018-05-02 21:08:44 +03:00
|
|
|
bool aClick, bool aIsTrusted);
|
2007-07-11 17:05:05 +04:00
|
|
|
|
2012-05-24 10:57:16 +04:00
|
|
|
/**
|
|
|
|
* Get the link location.
|
|
|
|
*/
|
|
|
|
static void GetLinkLocation(mozilla::dom::Element* aElement,
|
|
|
|
nsString& aLocationString);
|
|
|
|
|
2007-11-16 11:21:44 +03:00
|
|
|
/**
|
|
|
|
* Return top-level widget in the parent chain.
|
|
|
|
*/
|
|
|
|
static nsIWidget* GetTopLevelWidget(nsIWidget* aWidget);
|
2007-10-12 22:37:51 +04:00
|
|
|
|
2007-11-19 13:17:17 +03:00
|
|
|
/**
|
|
|
|
* Return the localized ellipsis for UI.
|
|
|
|
*/
|
|
|
|
static const nsDependentString GetLocalizedEllipsis();
|
|
|
|
|
2008-02-08 23:23:05 +03:00
|
|
|
/**
|
|
|
|
* Hide any XUL popups associated with aDocument, including any documents
|
2009-10-24 00:24:47 +04:00
|
|
|
* displayed in child frames. Does nothing if aDocument is null.
|
2008-02-08 23:23:05 +03:00
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static void HidePopupsInDocument(Document* aDocument);
|
2008-02-08 23:23:05 +03:00
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
/**
|
|
|
|
* Retrieve the current drag session, or null if no drag is currently occuring
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsIDragSession> GetDragSession();
|
|
|
|
|
2009-06-24 21:12:33 +04:00
|
|
|
/*
|
2013-10-01 11:23:02 +04:00
|
|
|
* Initialize and set the dataTransfer field of an WidgetDragEvent.
|
2009-06-24 21:12:33 +04:00
|
|
|
*/
|
2013-10-01 11:23:02 +04:00
|
|
|
static nsresult SetDataTransferInEvent(mozilla::WidgetDragEvent* aDragEvent);
|
2009-06-24 21:12:33 +04:00
|
|
|
|
|
|
|
// filters the drag and drop action to fit within the effects allowed and
|
|
|
|
// returns it.
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t FilterDropEffect(uint32_t aAction, uint32_t aEffectAllowed);
|
2009-06-24 21:12:33 +04:00
|
|
|
|
2012-03-20 19:21:41 +04: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,
|
2013-10-01 11:23:02 +04:00
|
|
|
mozilla::WidgetDragEvent* aDropEvent);
|
2012-03-20 19:21:41 +04:00
|
|
|
|
2008-03-22 19:50:47 +03:00
|
|
|
/**
|
|
|
|
* Return true if aURI is a local file URI (i.e. file://).
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool URIIsLocalFile(nsIURI* aURI);
|
2008-03-22 19:50:47 +03:00
|
|
|
|
2008-01-17 00:54:33 +03:00
|
|
|
/**
|
2008-11-06 03:01:07 +03:00
|
|
|
* Get the application manifest URI for this document. The manifest URI
|
2008-01-17 00:54:33 +03:00
|
|
|
* is specified in the manifest= attribute of the root element of the
|
2008-11-06 03:01:07 +03:00
|
|
|
* document.
|
2008-01-17 00:54:33 +03:00
|
|
|
*
|
2008-11-06 03:01:07 +03:00
|
|
|
* @param aDocument The document that lists the manifest.
|
2008-01-17 00:54:33 +03:00
|
|
|
* @param aURI The manifest URI.
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static void GetOfflineAppManifest(Document* aDocument, nsIURI** aURI);
|
2008-01-17 00:54:33 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether an application should be allowed to use offline APIs.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool OfflineAppAllowed(nsIURI* aURI);
|
2008-01-17 00:54:33 +03:00
|
|
|
|
2008-08-28 05:15:32 +04:00
|
|
|
/**
|
|
|
|
* Check whether an application should be allowed to use offline APIs.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool OfflineAppAllowed(nsIPrincipal* aPrincipal);
|
2008-08-28 05:15:32 +04:00
|
|
|
|
2013-08-16 13:34:21 +04:00
|
|
|
/**
|
|
|
|
* If offline-apps.allow_by_default is true, we set offline-app permission
|
|
|
|
* for the principal and return true. Otherwise false.
|
|
|
|
*/
|
2016-01-30 20:05:36 +03:00
|
|
|
static bool MaybeAllowOfflineAppByDefault(nsIPrincipal* aPrincipal);
|
2013-08-16 13:34:21 +04:00
|
|
|
|
2008-03-15 02:08:57 +03: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.
|
|
|
|
*/
|
2016-05-06 11:09:03 +03:00
|
|
|
static void AddScriptRunner(already_AddRefed<nsIRunnable> aRunnable);
|
|
|
|
static void AddScriptRunner(nsIRunnable* aRunnable);
|
2008-03-15 02:08:57 +03: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-29 10:19:26 +04:00
|
|
|
static bool IsSafeToRunScript() {
|
2018-04-05 20:42:40 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
|
|
"This static variable only makes sense on the main thread!");
|
2008-03-15 02:08:57 +03:00
|
|
|
return sScriptBlockerCount == 0;
|
|
|
|
}
|
|
|
|
|
2015-10-30 02:30:57 +03:00
|
|
|
// XXXcatalinb: workaround for weird include error when trying to reference
|
|
|
|
// ipdl types in WindowWatcher.
|
|
|
|
static nsIWindowProvider* GetWindowProviderForContentProcess();
|
|
|
|
|
2015-12-11 21:32:15 +03:00
|
|
|
// Returns the browser window with the most recent time stamp that is
|
|
|
|
// not in private browsing mode.
|
2016-01-30 20:05:36 +03:00
|
|
|
static already_AddRefed<nsPIDOMWindowOuter> GetMostRecentNonPBWindow();
|
2015-12-11 21:32:15 +03:00
|
|
|
|
2014-08-06 08:44:13 +04:00
|
|
|
/**
|
|
|
|
* Call this function if !IsSafeToRunScript() and we fail to run the script
|
|
|
|
* (rather than using AddScriptRunner as we usually do). |aDocument| is
|
|
|
|
* optional as it is only used for showing the URL in the console.
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static void WarnScriptWasIgnored(Document* aDocument);
|
2014-08-06 08:44:13 +04:00
|
|
|
|
2015-06-05 07:19:37 +03:00
|
|
|
/**
|
|
|
|
* Add a "synchronous section", in the form of an nsIRunnable run once the
|
|
|
|
* event loop has reached a "stable state". |aRunnable| must not cause any
|
|
|
|
* queued events to be processed (i.e. must not spin the event loop).
|
|
|
|
* We've reached a stable state when the currently executing task/event has
|
|
|
|
* finished, see
|
|
|
|
* http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#synchronous-section
|
|
|
|
* In practice this runs aRunnable once the currently executing event
|
|
|
|
* finishes. If called multiple times per task/event, all the runnables will
|
|
|
|
* be executed, in the order in which RunInStableState() was called.
|
|
|
|
*/
|
Bug 1179909: Refactor stable state handling. r=smaug
This is motivated by three separate but related problems:
1. Our concept of recursion depth is broken for things that run from AfterProcessNextEvent observers (e.g. Promises). We decrement the recursionDepth counter before firing observers, so a Promise callback running at the lowest event loop depth has a recursion depth of 0 (whereas a regular nsIRunnable would be 1). This is a problem because it's impossible to distinguish a Promise running after a sync XHR's onreadystatechange handler from a top-level event (since the former runs with depth 2 - 1 = 1, and the latter runs with just 1).
2. The nsIThreadObserver mechanism that is used by a lot of code to run "after" the current event is a poor fit for anything that runs script. First, the order the observers fire in is the order they were added, not anything fixed by spec. Additionally, running script can cause the event loop to spin, which is a big source of pain here (bholley has some nasty bug caused by this).
3. We run Promises from different points in the code for workers and main thread. The latter runs from XPConnect's nsIThreadObserver callbacks, while the former runs from a hardcoded call to run Promises in the worker event loop. What workers do is particularly problematic because it means we can't get the right recursion depth no matter what we do to nsThread.
The solve this, this patch does the following:
1. Consolidate some handling of microtasks and all handling of stable state from appshell and WorkerPrivate into CycleCollectedJSRuntime.
2. Make the recursionDepth counter only available to CycleCollectedJSRuntime (and its consumers) and remove it from the nsIThreadInternal and nsIThreadObserver APIs.
3. Adjust the recursionDepth counter so that microtasks run with the recursionDepth of the task they are associated with.
4. Introduce the concept of metastable state to replace appshell's RunBeforeNextEvent. Metastable state is reached after every microtask or task is completed. This provides the semantics that bent and I want for IndexedDB, where transactions autocommit at the end of a microtask and do not "spill" from one microtask into a subsequent microtask. This differs from appshell's RunBeforeNextEvent in two ways:
a) It fires between microtasks, which was the motivation for starting this.
b) It no longer ensures that we're at the same event loop depth in the native event queue. bent decided we don't care about this.
5. Reorder stable state to happen after microtasks such as Promises, per HTML. Right now we call the regular thread observers, including appshell, before the main thread observer (XPConnect), so stable state tasks happen before microtasks.
2015-08-11 16:10:46 +03:00
|
|
|
static void RunInStableState(already_AddRefed<nsIRunnable> aRunnable);
|
|
|
|
|
2017-11-17 06:01:27 +03:00
|
|
|
/* Add a pending IDBTransaction to be cleaned up at the end of performing a
|
|
|
|
* microtask checkpoint.
|
|
|
|
* See the step of "Cleanup Indexed Database Transactions" in
|
|
|
|
* https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint
|
|
|
|
*/
|
|
|
|
static void AddPendingIDBTransaction(
|
|
|
|
already_AddRefed<nsIRunnable> aTransaction);
|
2015-06-05 07:19:37 +03:00
|
|
|
|
2017-10-19 13:20:31 +03:00
|
|
|
/**
|
|
|
|
* Returns true if we are doing StableState/MetastableState.
|
|
|
|
*/
|
|
|
|
static bool IsInStableOrMetaStableState();
|
|
|
|
|
2008-07-17 07:16:23 +04: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
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static nsresult ProcessViewportInfo(Document* aDocument,
|
2008-07-17 07:16:23 +04:00
|
|
|
const nsAString& viewportInfo);
|
|
|
|
|
2008-09-06 01:51:24 +04:00
|
|
|
static JSContext* GetCurrentJSContext();
|
|
|
|
|
2018-11-13 15:47:40 +03:00
|
|
|
/**
|
|
|
|
* Case insensitive comparison between two atoms.
|
|
|
|
*/
|
|
|
|
static bool EqualsIgnoreASCIICase(nsAtom* aAtom1, nsAtom* aAtom2) {
|
|
|
|
if (aAtom1 == aAtom2) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If both are ascii lowercase already, we know that the slow comparison
|
|
|
|
// below is going to return false.
|
|
|
|
if (aAtom1->IsAsciiLowercase() && aAtom2->IsAsciiLowercase()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EqualsIgnoreASCIICase(nsDependentAtomString(aAtom1),
|
|
|
|
nsDependentAtomString(aAtom2));
|
|
|
|
}
|
|
|
|
|
2010-03-08 18:45:00 +03:00
|
|
|
/**
|
|
|
|
* Case insensitive comparison between two strings. However it only ignores
|
|
|
|
* case for ASCII characters a-z.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool EqualsIgnoreASCIICase(const nsAString& aStr1,
|
2012-03-10 09:50:34 +04:00
|
|
|
const nsAString& aStr2);
|
|
|
|
|
2010-02-23 20:38:10 +03:00
|
|
|
/**
|
|
|
|
* Convert ASCII A-Z to a-z.
|
|
|
|
*/
|
2014-08-13 15:53:32 +04:00
|
|
|
static void ASCIIToLower(nsAString& aStr);
|
2016-07-08 19:51:09 +03:00
|
|
|
static void ASCIIToLower(nsACString& aStr);
|
2014-08-13 15:53:32 +04:00
|
|
|
static void ASCIIToLower(const nsAString& aSource, nsAString& aDest);
|
2016-07-08 19:51:09 +03:00
|
|
|
static void ASCIIToLower(const nsACString& aSource, nsACString& aDest);
|
2010-02-23 20:38:10 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert ASCII a-z to A-Z.
|
|
|
|
*/
|
2014-08-13 15:53:32 +04:00
|
|
|
static void ASCIIToUpper(nsAString& aStr);
|
2016-07-08 19:51:09 +03:00
|
|
|
static void ASCIIToUpper(nsACString& aStr);
|
2014-08-13 15:53:32 +04:00
|
|
|
static void ASCIIToUpper(const nsAString& aSource, nsAString& aDest);
|
2016-07-08 19:51:09 +03:00
|
|
|
static void ASCIIToUpper(const nsACString& aSource, nsACString& aDest);
|
2010-02-23 20:38:10 +03:00
|
|
|
|
2012-07-14 03:29:14 +04:00
|
|
|
/**
|
|
|
|
* Return whether aStr contains an ASCII uppercase character.
|
|
|
|
*/
|
|
|
|
static bool StringContainsASCIIUpper(const nsAString& aStr);
|
|
|
|
|
2010-12-03 18:46:10 +03:00
|
|
|
// Returns NS_OK for same origin, error (NS_ERROR_DOM_BAD_URI) if not.
|
|
|
|
static nsresult CheckSameOrigin(nsIChannel* aOldChannel,
|
|
|
|
nsIChannel* aNewChannel);
|
2015-01-26 20:28:15 +03:00
|
|
|
static nsIInterfaceRequestor* SameOriginChecker();
|
2008-10-08 15:35:29 +04:00
|
|
|
|
2009-01-22 01:50:28 +03: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 20:43:14 +04:00
|
|
|
* suitable for, for example, header values. The UTF versions return strings
|
2009-01-22 01:50:28 +03:00
|
|
|
* containing international characters.
|
|
|
|
*
|
2010-04-02 20:43:14 +04:00
|
|
|
* @pre aPrincipal/aOrigin must not be null.
|
|
|
|
*
|
|
|
|
* @note this should be used for HTML5 origin determination.
|
2009-01-22 01:50:28 +03:00
|
|
|
*/
|
|
|
|
static nsresult GetASCIIOrigin(nsIPrincipal* aPrincipal, nsACString& aOrigin);
|
2015-02-27 22:10:20 +03:00
|
|
|
static nsresult GetASCIIOrigin(nsIURI* aURI, nsACString& aOrigin);
|
2009-01-22 01:50:28 +03:00
|
|
|
static nsresult GetUTFOrigin(nsIPrincipal* aPrincipal, nsAString& aOrigin);
|
2015-02-27 22:10:20 +03:00
|
|
|
static nsresult GetUTFOrigin(nsIURI* aURI, nsAString& aOrigin);
|
2009-01-22 01:50:28 +03:00
|
|
|
|
2009-06-30 11:56:40 +04:00
|
|
|
/**
|
|
|
|
* This method creates and dispatches "command" event, which implements
|
2018-03-19 22:50:37 +03:00
|
|
|
* XULCommandEvent.
|
2009-06-30 11:56:40 +04:00
|
|
|
* If aShell is not null, dispatching goes via
|
|
|
|
* nsIPresShell::HandleDOMEventWithTarget.
|
|
|
|
*/
|
|
|
|
static nsresult DispatchXULCommand(
|
|
|
|
nsIContent* aTarget, bool aTrusted,
|
2018-04-20 19:55:30 +03:00
|
|
|
mozilla::dom::Event* aSourceEvent = nullptr,
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIPresShell* aShell = nullptr, bool aCtrl = false, bool aAlt = false,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aShift = false, bool aMeta = false,
|
2018-03-20 07:16:06 +03:00
|
|
|
// Including MouseEventBinding here leads
|
|
|
|
// to incude loops, unfortunately.
|
2018-06-26 00:20:54 +03:00
|
|
|
uint16_t inputSource = 0 /* MouseEvent_Binding::MOZ_SOURCE_UNKNOWN */);
|
2009-06-30 11:56:40 +04:00
|
|
|
|
2012-08-20 22:34:33 +04:00
|
|
|
static bool CheckMayLoad(nsIPrincipal* aPrincipal, nsIChannel* aChannel,
|
|
|
|
bool aAllowIfInheritsPrincipal);
|
2010-06-17 15:27:52 +04:00
|
|
|
|
2009-06-28 23:46:52 +04: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 18:59:28 +04:00
|
|
|
* method returns true, otherwise false.
|
2009-06-28 23:46:52 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool CanAccessNativeAnon();
|
2009-08-14 23:00:24 +04:00
|
|
|
|
2016-04-27 07:16:50 +03:00
|
|
|
MOZ_MUST_USE
|
2014-04-10 08:58:41 +04:00
|
|
|
static nsresult WrapNative(JSContext* cx, nsISupports* native,
|
2014-04-10 22:46:20 +04:00
|
|
|
const nsIID* aIID, JS::MutableHandle<JS::Value> vp,
|
|
|
|
bool aAllowWrapping = true) {
|
|
|
|
return WrapNative(cx, native, nullptr, aIID, vp, aAllowWrapping);
|
2010-05-10 22:53:05 +04:00
|
|
|
}
|
2009-08-14 23:00:24 +04:00
|
|
|
|
|
|
|
// Same as the WrapNative above, but use this one if aIID is nsISupports' IID.
|
2016-04-27 07:16:50 +03:00
|
|
|
MOZ_MUST_USE
|
2014-04-10 08:58:41 +04:00
|
|
|
static nsresult WrapNative(JSContext* cx, nsISupports* native,
|
|
|
|
JS::MutableHandle<JS::Value> vp,
|
2014-02-13 03:19:32 +04:00
|
|
|
bool aAllowWrapping = true) {
|
2014-04-10 08:58:41 +04:00
|
|
|
return WrapNative(cx, native, nullptr, nullptr, vp, aAllowWrapping);
|
2010-05-10 22:53:05 +04:00
|
|
|
}
|
2014-01-06 23:54:43 +04:00
|
|
|
|
2016-04-27 07:16:50 +03:00
|
|
|
MOZ_MUST_USE
|
2014-04-10 08:58:41 +04:00
|
|
|
static nsresult WrapNative(JSContext* cx, nsISupports* native,
|
|
|
|
nsWrapperCache* cache,
|
2013-10-12 09:02:40 +04:00
|
|
|
JS::MutableHandle<JS::Value> vp,
|
2014-02-13 03:19:32 +04:00
|
|
|
bool aAllowWrapping = true) {
|
2014-04-10 08:58:41 +04:00
|
|
|
return WrapNative(cx, native, cache, nullptr, vp, aAllowWrapping);
|
2009-08-14 23:00:24 +04:00
|
|
|
}
|
|
|
|
|
2011-12-16 03:19:01 +04:00
|
|
|
/**
|
|
|
|
* Creates an arraybuffer from a binary string.
|
|
|
|
*/
|
|
|
|
static nsresult CreateArrayBuffer(JSContext* aCx, const nsACString& aData,
|
|
|
|
JSObject** aResult);
|
|
|
|
|
2010-03-03 15:41:57 +03:00
|
|
|
static void StripNullChars(const nsAString& aInStr, nsAString& aOutStr);
|
2010-03-17 22:55:45 +03:00
|
|
|
|
2010-02-23 03:15:56 +03: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);
|
2016-04-27 07:16:50 +03:00
|
|
|
MOZ_MUST_USE
|
2015-03-19 10:46:40 +03:00
|
|
|
static bool PlatformToDOMLineBreaks(nsString& aString,
|
|
|
|
const mozilla::fallible_t&);
|
2010-02-23 03:15:56 +03:00
|
|
|
|
2013-09-10 21:03:28 +04:00
|
|
|
/**
|
|
|
|
* Populates aResultString with the contents of the string-buffer aBuf, up
|
|
|
|
* to aBuf's null-terminator. aBuf must not be null. Ownership of the string
|
|
|
|
* is not transferred.
|
|
|
|
*/
|
|
|
|
static void PopulateStringFromStringBuffer(nsStringBuffer* aBuf,
|
|
|
|
nsAString& aResultString);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsHandlingKeyBoardEvent() { return sIsHandlingKeyBoardEvent; }
|
2010-04-24 14:40:48 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static void SetIsHandlingKeyBoardEvent(bool aHandling) {
|
2010-04-24 14:40:48 +04:00
|
|
|
sIsHandlingKeyBoardEvent = aHandling;
|
|
|
|
}
|
2010-04-19 19:41:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility method for getElementsByClassName. aRootNode is the node (either
|
|
|
|
* document or element), which getElementsByClassName was called on.
|
|
|
|
*/
|
2012-09-26 18:17:47 +04:00
|
|
|
static already_AddRefed<nsContentList> GetElementsByClassName(
|
|
|
|
nsINode* aRootNode, const nsAString& aClasses) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aRootNode, "Must have root node");
|
2012-09-26 18:17:47 +04:00
|
|
|
|
2017-07-26 09:34:00 +03:00
|
|
|
return GetFuncStringContentList<nsCacheableFuncStringHTMLCollection>(
|
|
|
|
aRootNode, MatchClassNames, DestroyClassNameArray,
|
|
|
|
AllocClassMatchingInfo, aClasses);
|
2012-09-26 18:17:47 +04:00
|
|
|
}
|
2010-04-19 19:41:37 +04:00
|
|
|
|
2012-10-08 15:23:11 +04:00
|
|
|
/**
|
|
|
|
* Returns a presshell for this document, if there is one. This will be
|
|
|
|
* aDoc's direct presshell if there is one, otherwise we'll look at all
|
|
|
|
* ancestor documents to try to find a presshell, so for example this can
|
|
|
|
* still find a presshell for documents in display:none frames that have
|
|
|
|
* no presentation. So you have to be careful how you use this presshell ---
|
|
|
|
* getting generic data like a device context or widget from it is OK, but it
|
|
|
|
* might not be this document's actual presentation.
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static nsIPresShell* FindPresShellForDocument(const Document* aDoc);
|
2012-10-08 15:23:11 +04:00
|
|
|
|
2012-02-01 01:55:54 +04: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.
|
2017-04-18 07:41:18 +03:00
|
|
|
*
|
|
|
|
* You should probably use WidgetForContent() instead of this, unless you have
|
|
|
|
* a good reason to do otherwise.
|
2012-02-01 01:55:54 +04:00
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static nsIWidget* WidgetForDocument(const Document* aDoc);
|
2012-02-01 01:55:54 +04:00
|
|
|
|
2017-04-18 07:41:18 +03:00
|
|
|
/**
|
|
|
|
* Returns the appropriate widget for this element, if there is one. Unlike
|
|
|
|
* WidgetForDocument(), this returns the correct widget for content in popups.
|
|
|
|
*
|
|
|
|
* You should probably use this instead of WidgetForDocument().
|
|
|
|
*/
|
|
|
|
static nsIWidget* WidgetForContent(const nsIContent* aContent);
|
|
|
|
|
2010-05-18 08:04:22 +04: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.
|
|
|
|
*
|
2017-04-18 07:41:18 +03:00
|
|
|
* You should probably use LayerManagerForContent() instead of this, unless
|
|
|
|
* you have a good reason to do otherwise.
|
|
|
|
*
|
2010-05-18 08:04:22 +04:00
|
|
|
* @param aDoc the document for which to return a layer manager.
|
2011-03-02 11:53:27 +03:00
|
|
|
* @param aAllowRetaining an outparam that states whether the returned
|
|
|
|
* layer manager should be used for retained layers
|
2010-05-18 08:04:22 +04:00
|
|
|
*/
|
|
|
|
static already_AddRefed<mozilla::layers::LayerManager>
|
2019-01-02 16:05:23 +03:00
|
|
|
LayerManagerForDocument(const Document* aDoc);
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2017-04-18 07:41:18 +03:00
|
|
|
/**
|
|
|
|
* Returns a layer manager to use for the given content. Unlike
|
|
|
|
* LayerManagerForDocument(), this returns the correct layer manager for
|
|
|
|
* content in popups.
|
|
|
|
*
|
|
|
|
* You should probably use this instead of LayerManagerForDocument().
|
|
|
|
*/
|
|
|
|
static already_AddRefed<mozilla::layers::LayerManager> LayerManagerForContent(
|
|
|
|
const nsIContent* aContent);
|
|
|
|
|
2010-12-07 05:05:52 +03: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 11:53:27 +03:00
|
|
|
* @param aAllowRetaining an outparam that states whether the returned
|
|
|
|
* layer manager should be used for retained layers
|
2010-12-07 05:05:52 +03:00
|
|
|
*/
|
|
|
|
static already_AddRefed<mozilla::layers::LayerManager>
|
2019-01-02 16:05:23 +03:00
|
|
|
PersistentLayerManagerForDocument(Document* aDoc);
|
2010-12-07 05:05:52 +03:00
|
|
|
|
2010-04-22 00:17:41 +04: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-29 10:19:26 +04:00
|
|
|
static bool IsFocusedContent(const nsIContent* aContent);
|
2010-10-08 14:20:20 +04:00
|
|
|
|
2011-09-05 00:39:05 +04:00
|
|
|
/**
|
2018-09-12 18:51:30 +03:00
|
|
|
* Returns true if the DOM fullscreen API is enabled.
|
2011-09-05 00:39:05 +04:00
|
|
|
*/
|
2018-09-12 18:51:30 +03:00
|
|
|
static bool IsFullscreenApiEnabled();
|
2011-09-05 00:39:05 +04:00
|
|
|
|
2016-05-02 07:26:04 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the unprefixed fullscreen API is enabled.
|
|
|
|
*/
|
|
|
|
static bool IsUnprefixedFullscreenApiEnabled() {
|
|
|
|
return sIsUnprefixedFullscreenApiEnabled;
|
|
|
|
}
|
|
|
|
|
2011-09-05 00:40:18 +04:00
|
|
|
/**
|
2018-09-12 18:51:30 +03:00
|
|
|
* Returns true if requests for fullscreen are allowed in the current
|
2011-09-05 00:40:18 +04: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.
|
|
|
|
*/
|
2018-09-12 18:51:30 +03:00
|
|
|
static bool IsRequestFullscreenAllowed(mozilla::dom::CallerType aCallerType);
|
2011-09-05 00:40:18 +04:00
|
|
|
|
2015-06-08 01:21:58 +03:00
|
|
|
/**
|
|
|
|
* Returns true if calling execCommand with 'cut' or 'copy' arguments
|
|
|
|
* is restricted to chrome code.
|
|
|
|
*/
|
|
|
|
static bool IsCutCopyRestricted() { return !sIsCutCopyAllowed; }
|
|
|
|
|
2015-05-25 11:09:00 +03:00
|
|
|
/**
|
|
|
|
* Returns true if calling execCommand with 'cut' or 'copy' arguments is
|
2017-02-01 23:43:36 +03:00
|
|
|
* allowed for the given subject principal. These are only allowed if the user
|
|
|
|
* initiated them (like with a mouse-click or key press).
|
2015-05-25 11:09:00 +03:00
|
|
|
*/
|
2017-02-01 23:43:36 +03:00
|
|
|
static bool IsCutCopyAllowed(nsIPrincipal* aSubjectPrincipal);
|
2015-05-25 11:09:00 +03:00
|
|
|
|
2013-05-11 02:57:58 +04:00
|
|
|
/*
|
|
|
|
* Returns true if the performance timing APIs are enabled.
|
|
|
|
*/
|
|
|
|
static bool IsPerformanceTimingEnabled() {
|
|
|
|
return sIsPerformanceTimingEnabled;
|
|
|
|
}
|
2016-05-06 11:13:45 +03:00
|
|
|
|
2013-10-16 05:35:44 +04:00
|
|
|
/*
|
|
|
|
* Returns true if the performance timing APIs are enabled.
|
|
|
|
*/
|
|
|
|
static bool IsResourceTimingEnabled() { return sIsResourceTimingEnabled; }
|
|
|
|
|
2017-10-04 03:48:33 +03:00
|
|
|
/*
|
|
|
|
* Returns true if the performance timing APIs are enabled.
|
|
|
|
*/
|
|
|
|
static bool IsPerformanceNavigationTimingEnabled() {
|
|
|
|
return sIsPerformanceNavigationTimingEnabled;
|
|
|
|
}
|
|
|
|
|
2015-08-01 01:40:08 +03:00
|
|
|
/*
|
|
|
|
* Returns true if notification should be sent for peformance timing events.
|
|
|
|
*/
|
|
|
|
static bool SendPerformanceTimingNotifications() {
|
|
|
|
return sSendPerformanceTimingNotifications;
|
|
|
|
}
|
|
|
|
|
2015-08-21 00:20:33 +03:00
|
|
|
/*
|
|
|
|
* Returns true if the frame timing APIs are enabled.
|
|
|
|
*/
|
|
|
|
static bool IsFrameTimingEnabled();
|
|
|
|
|
2015-06-07 16:02:00 +03:00
|
|
|
/*
|
2016-12-17 08:25:52 +03:00
|
|
|
* Returns true if the browser should attempt to prevent the given caller type
|
2015-06-07 16:02:00 +03:00
|
|
|
* from collecting distinctive information about the browser that could
|
|
|
|
* be used to "fingerprint" and track the user across websites.
|
|
|
|
*/
|
2016-12-17 08:25:52 +03:00
|
|
|
static bool ResistFingerprinting(mozilla::dom::CallerType aCallerType) {
|
|
|
|
return aCallerType != mozilla::dom::CallerType::System &&
|
2017-06-15 11:48:27 +03:00
|
|
|
ShouldResistFingerprinting();
|
2015-06-07 16:02:00 +03:00
|
|
|
}
|
|
|
|
|
2016-08-19 17:43:01 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the browser should show busy cursor when loading page.
|
|
|
|
*/
|
|
|
|
static bool UseActivityCursor() { return sUseActivityCursor; }
|
|
|
|
|
2017-04-07 22:44:57 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the DOM Animations API should be enabled.
|
|
|
|
*/
|
|
|
|
static bool AnimationsAPICoreEnabled() { return sAnimationsAPICoreEnabled; }
|
|
|
|
|
2017-04-07 22:48:24 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the getBoxQuads API should be enabled.
|
|
|
|
*/
|
|
|
|
static bool GetBoxQuadsEnabled() { return sGetBoxQuadsEnabled; }
|
|
|
|
|
2017-04-29 08:54:50 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the requestIdleCallback API should be enabled.
|
|
|
|
*/
|
|
|
|
static bool RequestIdleCallbackEnabled() {
|
|
|
|
return sRequestIdleCallbackEnabled;
|
|
|
|
}
|
|
|
|
|
2016-11-29 10:03:01 +03:00
|
|
|
/**
|
|
|
|
* Returns true if CSSOM origin check should be skipped for WebDriver
|
|
|
|
* based crawl to be able to collect data from cross-origin CSS style
|
|
|
|
* sheets. This can be enabled by setting environment variable
|
|
|
|
* MOZ_BYPASS_CSSOM_ORIGIN_CHECK.
|
|
|
|
*/
|
|
|
|
static bool BypassCSSOMOriginCheck() {
|
|
|
|
#ifdef RELEASE_OR_BETA
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
return sBypassCSSOMOriginCheck;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
/**
|
|
|
|
* Fire mutation events for changes caused by parsing directly into a
|
|
|
|
* context node.
|
|
|
|
*
|
|
|
|
* @param aDoc the document of the node
|
|
|
|
* @param aDest the destination node that got stuff appended to it
|
|
|
|
* @param aOldChildCount the number of children the node had before parsing
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static void FireMutationEventsForDirectParsing(Document* aDoc,
|
2013-12-02 14:26:12 +04:00
|
|
|
nsIContent* aDest,
|
|
|
|
int32_t aOldChildCount);
|
|
|
|
|
2011-10-27 06:57:09 +04:00
|
|
|
/**
|
|
|
|
* 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-15 00:33:37 +04:00
|
|
|
/**
|
2015-05-15 05:39:25 +03:00
|
|
|
* Returns the root document in a document hierarchy. Normally this
|
|
|
|
* will be the chrome document.
|
2011-11-15 00:33:37 +04:00
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static Document* GetRootDocument(Document* aDoc);
|
2011-11-15 00:33:37 +04:00
|
|
|
|
2013-03-24 14:32:44 +04:00
|
|
|
/**
|
|
|
|
* Returns true if aWin and the current pointer lock document
|
|
|
|
* have common scriptable top window.
|
|
|
|
*/
|
2016-01-30 20:05:36 +03:00
|
|
|
static bool IsInPointerLockContext(nsPIDOMWindowOuter* aWin);
|
2013-03-24 14:32:44 +04:00
|
|
|
|
2011-09-07 00:14:59 +04:00
|
|
|
/**
|
|
|
|
* Returns the time limit on handling user input before
|
2014-04-01 08:09:23 +04:00
|
|
|
* EventStateManager::IsHandlingUserInput() stops returning true.
|
2011-09-07 00:14:59 +04:00
|
|
|
* This enables us to detect long running user-generated event handlers.
|
|
|
|
*/
|
|
|
|
static TimeDuration HandlingUserInputTimeout();
|
|
|
|
|
2011-07-31 23:43:54 +04:00
|
|
|
static void GetShiftText(nsAString& text);
|
|
|
|
static void GetControlText(nsAString& text);
|
|
|
|
static void GetMetaText(nsAString& text);
|
2012-07-19 05:28:16 +04:00
|
|
|
static void GetOSText(nsAString& text);
|
2011-07-31 23:43:54 +04:00
|
|
|
static void GetAltText(nsAString& text);
|
|
|
|
static void GetModifierSeparatorText(nsAString& text);
|
|
|
|
|
2010-10-08 14:20:20 +04: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 15:57:15 +03:00
|
|
|
|
2013-11-20 02:21:16 +04:00
|
|
|
/**
|
|
|
|
* Returns if aNode ignores user focus.
|
|
|
|
*
|
|
|
|
* @param aNode node to test
|
|
|
|
*
|
|
|
|
* @return Whether the node ignores user focus.
|
|
|
|
*/
|
|
|
|
static bool IsUserFocusIgnored(nsINode* aNode);
|
|
|
|
|
2013-11-21 00:23:43 +04:00
|
|
|
/**
|
|
|
|
* Returns if aContent has the 'scrollgrab' property.
|
|
|
|
* aContent may be null (in this case false is returned).
|
|
|
|
*/
|
|
|
|
static bool HasScrollgrab(nsIContent* aContent);
|
|
|
|
|
2010-11-03 15:57:15 +03:00
|
|
|
/**
|
|
|
|
* Flushes the layout tree (recursively)
|
|
|
|
*
|
|
|
|
* @param aWindow the window the flush should start at
|
|
|
|
*
|
|
|
|
*/
|
2016-01-30 20:05:36 +03:00
|
|
|
static void FlushLayoutForTree(nsPIDOMWindowOuter* aWindow);
|
2010-04-22 00:17:41 +04:00
|
|
|
|
2010-11-23 11:50:55 +03: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 11:48:24 +04:00
|
|
|
/**
|
|
|
|
* Perform cleanup that's appropriate for XPCOM shutdown.
|
|
|
|
*/
|
|
|
|
static void XPCOMShutdown();
|
|
|
|
|
2015-07-02 19:09:45 +03:00
|
|
|
/**
|
|
|
|
* Checks if internal PDF viewer is enabled.
|
|
|
|
*/
|
|
|
|
static bool IsPDFJSEnabled();
|
|
|
|
|
2015-08-18 19:24:16 +03:00
|
|
|
/**
|
|
|
|
* Checks if internal SWF player is enabled.
|
|
|
|
*/
|
|
|
|
static bool IsSWFPlayerEnabled();
|
|
|
|
|
2011-04-15 00:58:36 +04:00
|
|
|
enum ContentViewerType {
|
|
|
|
TYPE_UNSUPPORTED,
|
|
|
|
TYPE_CONTENT,
|
|
|
|
TYPE_PLUGIN,
|
|
|
|
TYPE_UNKNOWN
|
|
|
|
};
|
|
|
|
|
|
|
|
static already_AddRefed<nsIDocumentLoaderFactory> FindInternalContentViewer(
|
2012-07-30 18:20:58 +04:00
|
|
|
const nsACString& aType, ContentViewerType* aLoaderType = nullptr);
|
2011-04-15 00:58:36 +04:00
|
|
|
|
2011-04-28 21:21:37 +04: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-29 10:19:26 +04:00
|
|
|
static bool IsPatternMatching(nsAString& aValue, nsAString& aPattern,
|
2019-02-19 14:17:28 +03:00
|
|
|
const Document* aDocument);
|
2011-04-28 21:21:37 +04:00
|
|
|
|
2011-04-26 16:30:17 +04:00
|
|
|
/**
|
|
|
|
* Calling this adds support for
|
|
|
|
* ontouch* event handler DOM attributes.
|
|
|
|
*/
|
|
|
|
static void InitializeTouchEventTable();
|
2011-06-25 13:52:00 +04:00
|
|
|
|
2011-09-21 01:00:42 +04:00
|
|
|
/**
|
|
|
|
* Test whether the given URI always inherits a security context
|
|
|
|
* from the document it comes from.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static nsresult URIInheritsSecurityContext(nsIURI* aURI, bool* aResult);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-21 01:00:42 +04:00
|
|
|
/**
|
2014-07-18 03:07:58 +04:00
|
|
|
* Called before a channel is created to query whether the new
|
|
|
|
* channel should inherit the principal.
|
|
|
|
*
|
|
|
|
* The argument aLoadingPrincipal must not be null. The argument
|
|
|
|
* aURI must be the URI of the new channel. If aInheritForAboutBlank
|
|
|
|
* is true, then about:blank will be told to inherit the principal.
|
|
|
|
* If aForceInherit is true, the new channel will be told to inherit
|
|
|
|
* the principal no matter what.
|
|
|
|
*
|
|
|
|
* The return value is whether the new channel should inherit
|
|
|
|
* the principal.
|
|
|
|
*/
|
|
|
|
static bool ChannelShouldInheritPrincipal(nsIPrincipal* aLoadingPrincipal,
|
|
|
|
nsIURI* aURI,
|
|
|
|
bool aInheritForAboutBlank,
|
|
|
|
bool aForceInherit);
|
2011-09-21 01:00:42 +04:00
|
|
|
|
2011-06-25 13:52:00 +04:00
|
|
|
static nsresult Btoa(const nsAString& aBinaryData,
|
|
|
|
nsAString& aAsciiBase64String);
|
|
|
|
|
|
|
|
static nsresult Atob(const nsAString& aAsciiString, nsAString& aBinaryData);
|
2011-11-20 22:02:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the input element passed in parameter has the autocomplete
|
2012-08-20 22:34:32 +04:00
|
|
|
* functionality enabled. It is taking into account the form owner.
|
2011-11-20 22:02:47 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
2018-02-21 01:10:44 +03:00
|
|
|
static bool IsAutocompleteEnabled(mozilla::dom::HTMLInputElement* aInput);
|
2011-11-20 22:02:47 +04:00
|
|
|
|
2015-01-21 16:35:19 +03:00
|
|
|
enum AutocompleteAttrState : uint8_t {
|
2014-06-06 11:25:02 +04:00
|
|
|
eAutocompleteAttrState_Unknown = 1,
|
|
|
|
eAutocompleteAttrState_Invalid,
|
|
|
|
eAutocompleteAttrState_Valid,
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Parses the value of the autocomplete attribute into aResult, ensuring it's
|
|
|
|
* composed of valid tokens, otherwise the value "" is used.
|
|
|
|
* Note that this method is used for form fields, not on a <form> itself.
|
|
|
|
*
|
|
|
|
* @return whether aAttr was valid and can be cached.
|
|
|
|
*/
|
2014-07-09 11:01:00 +04:00
|
|
|
static AutocompleteAttrState SerializeAutocompleteAttribute(
|
|
|
|
const nsAttrValue* aAttr, nsAString& aResult,
|
|
|
|
AutocompleteAttrState aCachedState = eAutocompleteAttrState_Unknown);
|
|
|
|
|
|
|
|
/* Variation that is used to retrieve a dictionary of the parts of the
|
|
|
|
* autocomplete attribute.
|
|
|
|
*
|
|
|
|
* @return whether aAttr was valid and can be cached.
|
|
|
|
*/
|
|
|
|
static AutocompleteAttrState SerializeAutocompleteAttribute(
|
|
|
|
const nsAttrValue* aAttr, mozilla::dom::AutocompleteInfo& aInfo,
|
|
|
|
AutocompleteAttrState aCachedState = eAutocompleteAttrState_Unknown,
|
2017-05-10 05:57:00 +03:00
|
|
|
bool aGrantAllValidValue = false);
|
2014-06-06 11:25:02 +04:00
|
|
|
|
2012-02-27 15:57:48 +04: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.
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
static bool GetPseudoAttributeValue(const nsString& aSource, nsAtom* aName,
|
2012-02-27 15:57:48 +04:00
|
|
|
nsAString& aValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the language name is a version of JavaScript and
|
|
|
|
* false otherwise
|
|
|
|
*/
|
2013-02-05 01:37:21 +04:00
|
|
|
static bool IsJavaScriptLanguage(const nsString& aName);
|
2012-02-27 15:57:48 +04:00
|
|
|
|
2013-08-21 23:28:26 +04:00
|
|
|
static bool IsJavascriptMIMEType(const nsAString& aMIMEType);
|
2012-08-04 11:43:59 +04:00
|
|
|
|
2012-02-27 15:57:48 +04:00
|
|
|
static void SplitMimeType(const nsAString& aValue, nsString& aType,
|
|
|
|
nsString& aParams);
|
|
|
|
|
2012-06-29 12:32:21 +04:00
|
|
|
/**
|
|
|
|
* Function checks if the user is idle.
|
2016-05-06 11:13:45 +03:00
|
|
|
*
|
2012-06-29 12:32:21 +04:00
|
|
|
* @param aRequestedIdleTimeInMS The idle observer's requested idle time.
|
2016-05-06 11:13:45 +03:00
|
|
|
* @param aUserIsIdle boolean indicating if the user
|
2018-11-27 13:08:58 +03:00
|
|
|
* 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.
|
2012-06-29 12:32:21 +04:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static nsresult IsUserIdle(uint32_t aRequestedIdleTimeInMS,
|
|
|
|
bool* aUserIsIdle);
|
2012-06-29 12:32:21 +04:00
|
|
|
|
2012-06-11 03:44:50 +04: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
|
|
|
|
*/
|
2014-04-10 20:09:40 +04:00
|
|
|
static void GetSelectionInTextControl(mozilla::dom::Selection* aSelection,
|
2012-06-11 03:44:50 +04:00
|
|
|
Element* aRoot,
|
2017-03-09 22:44:45 +03:00
|
|
|
uint32_t& aOutStartOffset,
|
|
|
|
uint32_t& aOutEndOffset);
|
2012-06-23 10:58:04 +04:00
|
|
|
|
2013-04-11 19:12:49 +04:00
|
|
|
/**
|
|
|
|
* Takes a frame for anonymous content within a text control (<input> or
|
|
|
|
* <textarea>), and returns an offset in the text content, adjusted for a
|
|
|
|
* trailing <br> frame.
|
|
|
|
*
|
|
|
|
* @param aOffsetFrame Frame for the text content in which the offset
|
|
|
|
* lies
|
|
|
|
* @param aOffset Offset as calculated by GetContentOffsetsFromPoint
|
|
|
|
* @param aOutOffset Output adjusted offset
|
|
|
|
*
|
|
|
|
* @see GetSelectionInTextControl for the original basis of this function.
|
|
|
|
*/
|
|
|
|
static int32_t GetAdjustedOffsetInTextControl(nsIFrame* aOffsetFrame,
|
|
|
|
int32_t aOffset);
|
|
|
|
|
2017-08-07 10:33:59 +03:00
|
|
|
/**
|
|
|
|
* Returns pointer to HTML editor instance for the aPresContext when there is.
|
|
|
|
* The HTML editor is shared by contenteditable elements or used in
|
|
|
|
* designMode. When there are no contenteditable elements and the document
|
|
|
|
* is not in designMode, this returns nullptr.
|
|
|
|
*/
|
|
|
|
static mozilla::HTMLEditor* GetHTMLEditor(nsPresContext* aPresContext);
|
2012-06-23 10:58:04 +04:00
|
|
|
|
2016-06-02 05:22:18 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the privacy.donottrackheader.enabled pref is set.
|
|
|
|
*/
|
|
|
|
static bool DoNotTrackEnabled();
|
|
|
|
|
2016-01-07 00:18:29 +03:00
|
|
|
/**
|
|
|
|
* Returns a LogModule that dump calls from content script are logged to.
|
|
|
|
* This can be enabled with the 'Dump' module, and is useful for synchronizing
|
|
|
|
* content JS to other logging modules.
|
|
|
|
*/
|
|
|
|
static mozilla::LogModule* DOMDumpLog();
|
|
|
|
|
2014-07-09 00:53:56 +04:00
|
|
|
/**
|
|
|
|
* Returns whether a given header is forbidden for an XHR or fetch
|
|
|
|
* request.
|
|
|
|
*/
|
|
|
|
static bool IsForbiddenRequestHeader(const nsACString& aHeader);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether a given header is forbidden for a system XHR
|
|
|
|
* request.
|
|
|
|
*/
|
|
|
|
static bool IsForbiddenSystemRequestHeader(const nsACString& aHeader);
|
|
|
|
|
2018-11-14 14:45:46 +03:00
|
|
|
/**
|
|
|
|
* Returns whether a given header has characters that aren't permitted
|
|
|
|
*/
|
|
|
|
static bool IsCorsUnsafeRequestHeaderValue(const nsACString& aHeaderValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether a given Accept header value is allowed
|
|
|
|
* for a non-CORS XHR or fetch request.
|
|
|
|
*/
|
|
|
|
static bool IsAllowedNonCorsAccept(const nsACString& aHeaderValue);
|
|
|
|
|
2014-07-24 20:38:55 +04:00
|
|
|
/**
|
|
|
|
* Returns whether a given Content-Type header value is allowed
|
|
|
|
* for a non-CORS XHR or fetch request.
|
|
|
|
*/
|
|
|
|
static bool IsAllowedNonCorsContentType(const nsACString& aHeaderValue);
|
|
|
|
|
2018-11-14 14:45:46 +03:00
|
|
|
/**
|
|
|
|
* Returns whether a given Content-Language or accept-language header value is
|
|
|
|
* allowed for a non-CORS XHR or fetch request.
|
|
|
|
*/
|
|
|
|
static bool IsAllowedNonCorsLanguage(const nsACString& aHeaderValue);
|
|
|
|
|
2014-07-09 00:53:56 +04:00
|
|
|
/**
|
|
|
|
* Returns whether a given header is forbidden for an XHR or fetch
|
|
|
|
* response.
|
|
|
|
*/
|
|
|
|
static bool IsForbiddenResponseHeader(const nsACString& aHeader);
|
|
|
|
|
2014-09-24 05:29:31 +04:00
|
|
|
/**
|
2017-02-06 04:19:34 +03:00
|
|
|
* Returns the inner window ID for the window associated with a request.
|
2014-09-24 05:29:31 +04:00
|
|
|
*/
|
|
|
|
static uint64_t GetInnerWindowID(nsIRequest* aRequest);
|
|
|
|
|
2014-10-20 14:46:20 +04:00
|
|
|
/**
|
2017-02-06 04:19:34 +03:00
|
|
|
* Returns the inner window ID for the window associated with a load group.
|
|
|
|
*/
|
|
|
|
static uint64_t GetInnerWindowID(nsILoadGroup* aLoadGroup);
|
|
|
|
|
|
|
|
/**
|
2014-10-20 14:46:20 +04:00
|
|
|
* If the hostname for aURI is an IPv6 it encloses it in brackets,
|
|
|
|
* otherwise it just outputs the hostname in aHost.
|
|
|
|
*/
|
2016-02-10 15:13:00 +03:00
|
|
|
static nsresult GetHostOrIPv6WithBrackets(nsIURI* aURI, nsAString& aHost);
|
|
|
|
static nsresult GetHostOrIPv6WithBrackets(nsIURI* aURI, nsCString& aHost);
|
2014-10-20 14:46:20 +04:00
|
|
|
|
2014-11-27 16:28:26 +03:00
|
|
|
/*
|
|
|
|
* Call the given callback on all remote children of the given top-level
|
2016-05-11 15:56:42 +03:00
|
|
|
* window. Return true from the callback to stop calling further children.
|
2014-11-27 16:28:26 +03:00
|
|
|
*/
|
2016-01-30 20:05:36 +03:00
|
|
|
static void CallOnAllRemoteChildren(nsPIDOMWindowOuter* aWindow,
|
2014-11-27 16:28:26 +03:00
|
|
|
CallOnRemoteChildFunction aCallback,
|
|
|
|
void* aArg);
|
|
|
|
|
2016-06-09 14:59:31 +03:00
|
|
|
/*
|
|
|
|
* Call nsPIDOMWindow::SetKeyboardIndicators all all remote children. This is
|
|
|
|
* in here rather than nsGlobalWindow because TabParent indirectly includes
|
|
|
|
* Windows headers which aren't allowed there.
|
|
|
|
*/
|
|
|
|
static void SetKeyboardIndicatorsOnRemoteChildren(
|
|
|
|
nsPIDOMWindowOuter* aWindow, UIStateChangeType aShowAccelerators,
|
|
|
|
UIStateChangeType aShowFocusRings);
|
|
|
|
|
2015-10-28 00:41:58 +03:00
|
|
|
/**
|
|
|
|
* Given an nsIFile, attempts to read it into aString.
|
|
|
|
*
|
|
|
|
* Note: Use sparingly! This causes main-thread I/O, which causes jank and all
|
|
|
|
* other bad things.
|
|
|
|
*/
|
|
|
|
static nsresult SlurpFileToString(nsIFile* aFile, nsACString& aString);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the mime service thinks this file contains an image.
|
|
|
|
*
|
|
|
|
* The content type is returned in aType.
|
|
|
|
*/
|
|
|
|
static bool IsFileImage(nsIFile* aFile, nsACString& aType);
|
|
|
|
|
2016-02-24 03:31:29 +03:00
|
|
|
/**
|
|
|
|
* Given an IPCDataTransferItem that has a flavor for which IsFlavorImage
|
|
|
|
* returns true and whose IPCDataTransferData is of type nsCString (raw image
|
|
|
|
* data), construct an imgIContainer for the image encoded by the transfer
|
|
|
|
* item.
|
|
|
|
*/
|
|
|
|
static nsresult DataTransferItemToImage(
|
|
|
|
const mozilla::dom::IPCDataTransferItem& aItem,
|
|
|
|
imgIContainer** aContainer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a flavor obtained from an IPCDataTransferItem or nsITransferable,
|
|
|
|
* returns true if we should treat the data as an image.
|
|
|
|
*/
|
|
|
|
static bool IsFlavorImage(const nsACString& aFlavor);
|
2016-08-31 04:30:45 +03:00
|
|
|
|
|
|
|
static nsresult IPCTransferableToTransferable(
|
|
|
|
const mozilla::dom::IPCDataTransfer& aDataTransfer,
|
|
|
|
const bool& aIsPrivateData, nsIPrincipal* aRequestingPrincipal,
|
2018-03-14 11:44:36 +03:00
|
|
|
const nsContentPolicyType& aContentPolicyType,
|
2016-08-31 04:30:45 +03:00
|
|
|
nsITransferable* aTransferable,
|
2019-02-25 23:04:47 +03:00
|
|
|
mozilla::dom::ContentParent* aContentParent,
|
2016-08-31 04:30:45 +03:00
|
|
|
mozilla::dom::TabChild* aTabChild);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-10-18 21:56:20 +03:00
|
|
|
static void TransferablesToIPCTransferables(
|
2015-04-08 21:48:11 +03:00
|
|
|
nsIArray* aTransferables, nsTArray<mozilla::dom::IPCDataTransfer>& aIPC,
|
2019-02-25 23:04:49 +03:00
|
|
|
bool aInSyncMessage, mozilla::dom::ContentChild* aChild,
|
2019-02-25 23:04:47 +03:00
|
|
|
mozilla::dom::ContentParent* aParent);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-04-16 22:38:12 +03:00
|
|
|
static void TransferableToIPCTransferable(
|
|
|
|
nsITransferable* aTransferable,
|
|
|
|
mozilla::dom::IPCDataTransfer* aIPCDataTransfer, bool aInSyncMessage,
|
2019-03-13 12:19:06 +03:00
|
|
|
mozilla::dom::ContentChild* aChild, mozilla::dom::ContentParent* aParent);
|
2015-04-16 22:38:12 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the pixel data from the given source surface and return it as a buffer.
|
|
|
|
* The length and stride will be assigned from the surface.
|
|
|
|
*/
|
2016-05-27 02:49:25 +03:00
|
|
|
static mozilla::UniquePtr<char[]> GetSurfaceData(
|
|
|
|
mozilla::NotNull<mozilla::gfx::DataSourceSurface*> aSurface,
|
|
|
|
size_t* aLength, int32_t* aStride);
|
2015-04-16 22:38:12 +03:00
|
|
|
|
2016-06-15 15:49:13 +03:00
|
|
|
/*
|
|
|
|
* Get the pixel data from the given source surface and fill it in Shmem.
|
|
|
|
* The length and stride will be assigned from the surface.
|
|
|
|
*/
|
2017-05-15 13:15:48 +03:00
|
|
|
static mozilla::Maybe<mozilla::ipc::Shmem> GetSurfaceData(
|
|
|
|
mozilla::gfx::DataSourceSurface* aSurface, size_t* aLength,
|
|
|
|
int32_t* aStride, mozilla::ipc::IShmemAllocator* aAlloc);
|
2016-06-15 15:49:13 +03:00
|
|
|
|
2015-04-15 10:08:55 +03:00
|
|
|
// Helpers shared by the implementations of nsContentUtils methods and
|
|
|
|
// nsIDOMWindowUtils methods.
|
|
|
|
static mozilla::Modifiers GetWidgetModifiers(int32_t aModifiers);
|
|
|
|
static nsIWidget* GetWidget(nsIPresShell* aPresShell, nsPoint* aOffset);
|
|
|
|
static int16_t GetButtonsFlagForButton(int32_t aButton);
|
|
|
|
static mozilla::LayoutDeviceIntPoint ToWidgetPoint(
|
|
|
|
const mozilla::CSSPoint& aPoint, const nsPoint& aOffset,
|
|
|
|
nsPresContext* aPresContext);
|
|
|
|
static nsView* GetViewToDispatchEvent(nsPresContext* aPresContext,
|
|
|
|
nsIPresShell** aPresShell);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synthesize a mouse event to the given widget
|
|
|
|
* (see nsIDOMWindowUtils.sendMouseEvent).
|
|
|
|
*/
|
2018-01-29 22:35:17 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2016-11-15 01:15:46 +03:00
|
|
|
static nsresult SendMouseEvent(
|
|
|
|
const nsCOMPtr<nsIPresShell>& aPresShell, const nsAString& aType,
|
2016-08-18 06:58:48 +03:00
|
|
|
float aX, float aY, int32_t aButton, int32_t aButtons,
|
2015-04-15 10:08:55 +03:00
|
|
|
int32_t aClickCount, int32_t aModifiers, bool aIgnoreRootScrollFrame,
|
|
|
|
float aPressure, unsigned short aInputSourceArg, uint32_t aIdentifier,
|
2016-07-07 10:28:11 +03:00
|
|
|
bool aToWindow, bool* aPreventDefault, bool aIsDOMEventSynthesized,
|
|
|
|
bool aIsWidgetEventSynthesized);
|
2015-04-15 10:08:55 +03:00
|
|
|
|
2015-05-07 18:43:40 +03:00
|
|
|
static void FirePageShowEvent(nsIDocShellTreeItem* aItem,
|
|
|
|
mozilla::dom::EventTarget* aChromeEventHandler,
|
2018-08-16 06:06:49 +03:00
|
|
|
bool aFireIfShowing,
|
|
|
|
bool aOnlySystemGroup = false);
|
2015-05-07 18:43:40 +03:00
|
|
|
|
|
|
|
static void FirePageHideEvent(nsIDocShellTreeItem* aItem,
|
2018-08-16 06:06:49 +03:00
|
|
|
mozilla::dom::EventTarget* aChromeEventHandler,
|
|
|
|
bool aOnlySystemGroup = false);
|
2015-05-07 18:43:40 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
static already_AddRefed<nsPIWindowRoot> GetWindowRoot(Document* aDoc);
|
2015-06-08 08:39:39 +03:00
|
|
|
|
2015-06-05 00:05:00 +03:00
|
|
|
/*
|
|
|
|
* Implements step 3.1 and 3.3 of the Determine request's Referrer algorithm
|
|
|
|
* from the Referrer Policy specification.
|
|
|
|
*
|
|
|
|
* The referrer policy of the document is applied by Necko when using
|
|
|
|
* channels.
|
|
|
|
*
|
|
|
|
* For documents representing an iframe srcdoc attribute, the document sets
|
|
|
|
* its own URI correctly, so this method simply uses the document's original
|
|
|
|
* or current URI as appropriate.
|
|
|
|
*
|
|
|
|
* aDoc may be null.
|
|
|
|
*
|
|
|
|
* https://w3c.github.io/webappsec/specs/referrer-policy/#determine-requests-referrer
|
|
|
|
*/
|
|
|
|
static nsresult SetFetchReferrerURIWithPolicy(
|
2019-01-02 16:05:23 +03:00
|
|
|
nsIPrincipal* aPrincipal, Document* aDoc, nsIHttpChannel* aChannel,
|
2016-02-27 01:36:45 +03:00
|
|
|
mozilla::net::ReferrerPolicy aReferrerPolicy);
|
2015-06-05 00:05:00 +03:00
|
|
|
|
2018-09-17 08:35:26 +03:00
|
|
|
/*
|
|
|
|
* If there is a Referrer-Policy response header in |aChannel|, parse a
|
|
|
|
* referrer policy from the header.
|
|
|
|
*
|
|
|
|
* @param the channel from which to get the Referrer-Policy header
|
|
|
|
* @return referrer policy from the response header in aChannel
|
|
|
|
*/
|
|
|
|
static mozilla::net::ReferrerPolicy GetReferrerPolicyFromChannel(
|
|
|
|
nsIChannel* aChannel);
|
|
|
|
|
2017-05-05 06:30:19 +03:00
|
|
|
/*
|
2016-07-19 10:38:26 +03:00
|
|
|
* Parse a referrer policy from a Referrer-Policy header
|
|
|
|
* https://www.w3.org/TR/referrer-policy/#parse-referrer-policy-from-header
|
|
|
|
*
|
|
|
|
* @param aHeader the response's Referrer-Policy header to parse
|
|
|
|
* @return referrer policy from the response header.
|
|
|
|
*/
|
|
|
|
static mozilla::net::ReferrerPolicy GetReferrerPolicyFromHeader(
|
|
|
|
const nsAString& aHeader);
|
|
|
|
|
2015-10-07 05:35:12 +03:00
|
|
|
static bool IsNonSubresourceRequest(nsIChannel* aChannel);
|
2015-09-17 21:56:41 +03:00
|
|
|
|
2018-01-23 18:38:52 +03:00
|
|
|
static bool IsNonSubresourceInternalPolicyType(nsContentPolicyType aType);
|
|
|
|
|
2015-07-15 23:41:28 +03:00
|
|
|
// The order of these entries matters, as we use std::min for total ordering
|
|
|
|
// of permissions. Private Browsing is considered to be more limiting
|
|
|
|
// then session scoping
|
|
|
|
enum class StorageAccess {
|
2018-11-13 11:51:14 +03:00
|
|
|
// The storage should be partitioned. if the caller is unable to do it, deny
|
|
|
|
// the storage access.
|
|
|
|
ePartitionedOrDeny = -1,
|
2015-07-15 23:41:28 +03:00
|
|
|
// Don't allow access to the storage
|
|
|
|
eDeny = 0,
|
|
|
|
// Allow access to the storage, but only if it is secure to do so in a
|
|
|
|
// private browsing context.
|
|
|
|
ePrivateBrowsing = 1,
|
|
|
|
// Allow access to the storage, but only persist it for the current session
|
|
|
|
eSessionScoped = 2,
|
|
|
|
// Allow access to the storage
|
|
|
|
eAllow = 3,
|
2017-12-12 23:44:46 +03:00
|
|
|
// Keep this at the end. Used for serialization, but not a valid value.
|
|
|
|
eNumValues = 4,
|
2015-07-15 23:41:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks if storage for the given window is permitted by a combination of
|
|
|
|
* the user's preferences, and whether the window is a third-party iframe.
|
|
|
|
*
|
|
|
|
* This logic is intended to be shared between the different forms of
|
|
|
|
* persistent storage which are available to web pages. Cookies don't use
|
|
|
|
* this logic, and security logic related to them must be updated separately.
|
|
|
|
*/
|
2019-01-23 21:19:19 +03:00
|
|
|
static StorageAccess StorageAllowedForWindow(
|
|
|
|
nsPIDOMWindowInner* aWindow, uint32_t* aRejectedReason = nullptr);
|
2015-07-15 23:41:28 +03:00
|
|
|
|
2017-09-20 19:24:07 +03:00
|
|
|
/*
|
|
|
|
* Checks if storage for the given document is permitted by a combination of
|
|
|
|
* the user's preferences, and whether the document's window is a third-party
|
|
|
|
* iframe.
|
|
|
|
*
|
|
|
|
* Note, this may be used on documents during the loading process where
|
|
|
|
* the window's extant document has not been set yet. The code in
|
|
|
|
* StorageAllowedForWindow(), however, will not work in these cases.
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static StorageAccess StorageAllowedForDocument(Document* aDoc);
|
2017-09-20 19:24:07 +03:00
|
|
|
|
2018-01-09 04:25:53 +03:00
|
|
|
/*
|
|
|
|
* Checks if storage should be allowed for a new window with the given
|
|
|
|
* principal, load URI, and parent.
|
|
|
|
*/
|
|
|
|
static StorageAccess StorageAllowedForNewWindow(nsIPrincipal* aPrincipal,
|
|
|
|
nsIURI* aURI,
|
|
|
|
nsPIDOMWindowInner* aParent);
|
|
|
|
|
2018-01-23 18:38:53 +03:00
|
|
|
/*
|
|
|
|
* Checks if storage should be allowed for the given channel. The check will
|
|
|
|
* be based on the channel result principal and, depending on preferences and
|
|
|
|
* permissions, mozIThirdPartyUtil.isThirdPartyChannel().
|
|
|
|
*/
|
|
|
|
static StorageAccess StorageAllowedForChannel(nsIChannel* aChannel);
|
|
|
|
|
2015-07-15 23:41:28 +03:00
|
|
|
/*
|
|
|
|
* Checks if storage for the given principal is permitted by the user's
|
2019-02-05 12:12:11 +03:00
|
|
|
* preferences. This method should be used only by ServiceWorker loading.
|
2015-07-15 23:41:28 +03:00
|
|
|
*/
|
2019-02-05 12:12:11 +03:00
|
|
|
static StorageAccess StorageAllowedForServiceWorker(nsIPrincipal* aPrincipal);
|
2015-07-15 23:41:28 +03:00
|
|
|
|
2018-08-16 01:02:48 +03:00
|
|
|
/*
|
|
|
|
* Returns true if this document should disable storages because of the
|
|
|
|
* anti-tracking feature.
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static bool StorageDisabledByAntiTracking(Document* aDocument, nsIURI* aURI) {
|
2019-01-23 21:19:19 +03:00
|
|
|
uint32_t rejectedReason = 0;
|
2018-08-16 01:02:48 +03:00
|
|
|
// Note that GetChannel() below may return null, but that's OK, since the
|
|
|
|
// callee is able to deal with a null channel argument, and if passed null,
|
|
|
|
// will only fail to notify the UI in case storage gets blocked.
|
2019-01-23 21:19:19 +03:00
|
|
|
return StorageDisabledByAntiTracking(
|
|
|
|
aDocument->GetInnerWindow(), aDocument->GetChannel(),
|
|
|
|
aDocument->NodePrincipal(), aURI, rejectedReason);
|
2018-08-16 01:02:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-06-20 20:38:22 +03:00
|
|
|
/*
|
2018-08-10 22:55:22 +03:00
|
|
|
* Returns true if this window/channel/aPrincipal should disable storages
|
|
|
|
* because of the anti-tracking feature.
|
2018-08-13 22:54:55 +03:00
|
|
|
* Note that either aWindow or aChannel may be null when calling this
|
2018-08-16 00:55:37 +03:00
|
|
|
* function. If the caller wants the UI to be notified when the storage gets
|
|
|
|
* disabled, it must pass a non-null channel object.
|
2018-06-20 20:38:22 +03:00
|
|
|
*/
|
|
|
|
static bool StorageDisabledByAntiTracking(nsPIDOMWindowInner* aWindow,
|
|
|
|
nsIChannel* aChannel,
|
2018-08-10 22:55:22 +03:00
|
|
|
nsIPrincipal* aPrincipal,
|
2019-01-23 21:19:19 +03:00
|
|
|
nsIURI* aURI,
|
|
|
|
uint32_t& aRejectedReason);
|
2018-06-20 20:38:22 +03:00
|
|
|
|
2018-08-16 01:02:48 +03:00
|
|
|
public:
|
2018-07-10 11:09:58 +03:00
|
|
|
/*
|
|
|
|
* Returns true if this window/channel is a 3rd party context.
|
|
|
|
*/
|
|
|
|
static bool IsThirdPartyWindowOrChannel(nsPIDOMWindowInner* aWindow,
|
|
|
|
nsIChannel* aChannel, nsIURI* aURI);
|
|
|
|
|
2018-07-11 13:38:47 +03:00
|
|
|
/*
|
|
|
|
* Returns true if this window's channel has been marked as a tracking
|
|
|
|
* resource.
|
|
|
|
*/
|
|
|
|
static bool IsTrackingResourceWindow(nsPIDOMWindowInner* aWindow);
|
|
|
|
|
2018-11-27 11:59:09 +03:00
|
|
|
/*
|
|
|
|
* Returns true if this window's channel has been marked as a third-party
|
|
|
|
* tracking resource.
|
|
|
|
*/
|
|
|
|
static bool IsThirdPartyTrackingResourceWindow(nsPIDOMWindowInner* aWindow);
|
|
|
|
|
2015-10-08 19:57:40 +03:00
|
|
|
/*
|
|
|
|
* Serializes a HTML nsINode into its markup representation.
|
|
|
|
*/
|
|
|
|
static bool SerializeNodeToMarkup(nsINode* aRoot, bool aDescendentsOnly,
|
|
|
|
nsAString& aOut);
|
|
|
|
|
2016-01-23 04:27:28 +03:00
|
|
|
/*
|
|
|
|
* Returns true iff the provided JSObject is a global, and its URI matches
|
|
|
|
* the provided about: URI.
|
|
|
|
* @param aGlobal the JSObject whose URI to check, if it is a global.
|
|
|
|
* @param aUri the URI to match, e.g. "about:feeds"
|
|
|
|
*/
|
|
|
|
static bool IsSpecificAboutPage(JSObject* aGlobal, const char* aUri);
|
|
|
|
|
2016-03-12 02:10:13 +03:00
|
|
|
static void SetScrollbarsVisibility(nsIDocShell* aDocShell, bool aVisible);
|
|
|
|
|
2016-05-17 06:10:59 +03:00
|
|
|
/*
|
|
|
|
* Return the associated presentation URL of the presented content.
|
|
|
|
* Will return empty string if the docshell is not in a presented content.
|
|
|
|
*/
|
|
|
|
static void GetPresentationURL(nsIDocShell* aDocShell,
|
|
|
|
nsAString& aPresentationUrl);
|
|
|
|
|
2016-07-18 17:26:38 +03:00
|
|
|
/*
|
|
|
|
* Try to find the docshell corresponding to the given event target.
|
|
|
|
*/
|
|
|
|
static nsIDocShell* GetDocShellForEventTarget(
|
|
|
|
mozilla::dom::EventTarget* aTarget);
|
|
|
|
|
2016-08-11 00:01:00 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the "HTTPS state" of the document should be "modern". See:
|
|
|
|
*
|
|
|
|
* https://html.spec.whatwg.org/#concept-document-https-state
|
|
|
|
* https://fetch.spec.whatwg.org/#concept-response-https-state
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static bool HttpsStateIsModern(Document* aDocument);
|
2016-08-11 00:01:00 +03:00
|
|
|
|
2017-11-14 14:25:00 +03:00
|
|
|
/**
|
|
|
|
* Try to upgrade an element.
|
|
|
|
* https://html.spec.whatwg.org/multipage/custom-elements.html#concept-try-upgrade
|
|
|
|
*/
|
|
|
|
static void TryToUpgradeElement(Element* aElement);
|
|
|
|
|
2017-10-11 01:25:10 +03:00
|
|
|
/**
|
|
|
|
* Creates a new XUL or XHTML element applying any appropriate custom element
|
|
|
|
* definition.
|
|
|
|
*/
|
|
|
|
static nsresult NewXULOrHTMLElement(
|
|
|
|
Element** aResult, mozilla::dom::NodeInfo* aNodeInfo,
|
2017-11-24 11:57:00 +03:00
|
|
|
mozilla::dom::FromParser aFromParser, nsAtom* aIsAtom,
|
2017-10-11 01:25:10 +03:00
|
|
|
mozilla::dom::CustomElementDefinition* aDefinition);
|
|
|
|
|
2018-09-22 00:29:25 +03:00
|
|
|
static mozilla::dom::CustomElementRegistry* GetCustomElementRegistry(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document*);
|
2018-09-22 00:29:25 +03:00
|
|
|
|
2016-08-30 06:48:53 +03:00
|
|
|
/**
|
|
|
|
* Looking up a custom element definition.
|
|
|
|
* https://html.spec.whatwg.org/#look-up-a-custom-element-definition
|
|
|
|
*/
|
|
|
|
static mozilla::dom::CustomElementDefinition* LookupCustomElementDefinition(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDoc, nsAtom* aNameAtom, uint32_t aNameSpaceID,
|
2017-11-14 14:23:00 +03:00
|
|
|
nsAtom* aTypeAtom);
|
2016-08-30 06:48:53 +03:00
|
|
|
|
2018-05-23 08:04:18 +03:00
|
|
|
static void RegisterCallbackUpgradeElement(Element* aElement,
|
|
|
|
nsAtom* aTypeName);
|
|
|
|
|
2017-11-14 14:25:00 +03:00
|
|
|
static void RegisterUnresolvedElement(Element* aElement, nsAtom* aTypeName);
|
|
|
|
static void UnregisterUnresolvedElement(Element* aElement);
|
2016-08-30 06:48:53 +03:00
|
|
|
|
2017-09-25 08:33:00 +03:00
|
|
|
static void EnqueueUpgradeReaction(
|
|
|
|
Element* aElement, mozilla::dom::CustomElementDefinition* aDefinition);
|
|
|
|
|
2017-09-26 08:56:00 +03:00
|
|
|
static void EnqueueLifecycleCallback(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document::ElementCallbackType aType, Element* aCustomElement,
|
2016-08-30 06:48:53 +03:00
|
|
|
mozilla::dom::LifecycleCallbackArgs* aArgs = nullptr,
|
2017-10-02 07:42:00 +03:00
|
|
|
mozilla::dom::LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs =
|
|
|
|
nullptr,
|
2016-08-30 06:48:53 +03:00
|
|
|
mozilla::dom::CustomElementDefinition* aDefinition = nullptr);
|
|
|
|
|
2016-10-21 23:56:51 +03:00
|
|
|
static bool AttemptLargeAllocationLoad(nsIHttpChannel* aChannel);
|
|
|
|
|
2016-12-03 04:37:00 +03:00
|
|
|
/**
|
|
|
|
* Appends all "document level" native anonymous content subtree roots for
|
|
|
|
* aDocument to aElements. Document level NAC subtrees are those created
|
|
|
|
* by ancestor frames of the document element's primary frame, such as
|
|
|
|
* the scrollbar elements created by the root scroll frame.
|
|
|
|
*/
|
|
|
|
static void AppendDocumentLevelNativeAnonymousContentTo(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDocument, nsTArray<nsIContent*>& aElements);
|
2016-12-03 04:37:00 +03:00
|
|
|
|
2017-06-18 20:36:32 +03:00
|
|
|
/**
|
|
|
|
* Appends all native anonymous content subtree roots generated by `aContent`
|
|
|
|
* to `aKids`.
|
|
|
|
*
|
|
|
|
* See `AllChildrenIterator` for the description of the `aFlags` parameter.
|
|
|
|
*/
|
|
|
|
static void AppendNativeAnonymousChildren(const nsIContent* aContent,
|
|
|
|
nsTArray<nsIContent*>& aKids,
|
|
|
|
uint32_t aFlags);
|
|
|
|
|
2017-09-15 13:27:47 +03:00
|
|
|
/**
|
2017-10-11 12:07:35 +03:00
|
|
|
* Query triggeringPrincipal if there's a 'triggeringprincipal' attribute on
|
|
|
|
* aLoadingNode, if no such attribute is specified, aDefaultPrincipal is
|
|
|
|
* returned if it is provided, otherwise the NodePrincipal of aLoadingNode is
|
|
|
|
* returned.
|
2017-09-15 13:27:47 +03:00
|
|
|
*
|
2017-10-11 12:07:35 +03:00
|
|
|
* Return true if aLoadingNode has a 'triggeringprincipal' attribute, and
|
|
|
|
* the value 'triggeringprincipal' is also successfully deserialized,
|
2017-09-15 13:27:47 +03:00
|
|
|
* otherwise return false.
|
|
|
|
*/
|
2017-10-11 12:07:35 +03:00
|
|
|
static bool QueryTriggeringPrincipal(nsIContent* aLoadingNode,
|
|
|
|
nsIPrincipal* aDefaultPrincipal,
|
|
|
|
nsIPrincipal** aTriggeringPrincipal);
|
2017-10-03 06:28:32 +03:00
|
|
|
|
2017-10-11 12:07:35 +03:00
|
|
|
static bool QueryTriggeringPrincipal(nsIContent* aLoadingNode,
|
|
|
|
nsIPrincipal** aTriggeringPrincipal) {
|
|
|
|
return QueryTriggeringPrincipal(aLoadingNode, nullptr,
|
|
|
|
aTriggeringPrincipal);
|
2017-10-03 06:28:32 +03:00
|
|
|
}
|
2017-09-15 13:27:47 +03:00
|
|
|
|
2016-12-14 23:52:57 +03:00
|
|
|
/**
|
|
|
|
* Returns the content policy type that should be used for loading images
|
|
|
|
* for displaying in the UI. The sources of such images can be <xul:image>,
|
|
|
|
* <xul:menuitem> on OSX where we load the image through nsMenuItemIconX, etc.
|
|
|
|
*/
|
|
|
|
static void GetContentPolicyTypeForUIImageLoading(
|
2017-10-11 12:07:35 +03:00
|
|
|
nsIContent* aLoadingNode, nsIPrincipal** aTriggeringPrincipal,
|
2017-09-21 03:09:00 +03:00
|
|
|
nsContentPolicyType& aContentPolicyType, uint64_t* aRequestContextID);
|
2016-12-14 23:52:57 +03:00
|
|
|
|
2017-02-03 13:00:38 +03:00
|
|
|
static nsresult CreateJSValueFromSequenceOfObject(
|
|
|
|
JSContext* aCx, const mozilla::dom::Sequence<JSObject*>& aTransfer,
|
|
|
|
JS::MutableHandle<JS::Value> aValue);
|
|
|
|
|
2017-11-10 02:42:39 +03:00
|
|
|
/**
|
|
|
|
* Returns true if reserved key events should be prevented from being sent
|
|
|
|
* to their target. Instead, the key event should be handled by chrome only.
|
|
|
|
*/
|
|
|
|
static bool ShouldBlockReservedKeys(mozilla::WidgetKeyboardEvent* aKeyEvent);
|
|
|
|
|
2015-05-20 16:30:05 +03:00
|
|
|
/**
|
|
|
|
* Returns the nsIPluginTag for the plugin we should try to use for a given
|
|
|
|
* MIME type.
|
|
|
|
*
|
|
|
|
* @param aMIMEType The MIME type of the document being loaded.
|
|
|
|
* @param aNoFakePlugin If false then this method should consider JS plugins.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsIPluginTag> PluginTagForType(
|
|
|
|
const nsCString& aMIMEType, bool aNoFakePlugin);
|
|
|
|
|
2017-03-04 02:18:02 +03:00
|
|
|
/**
|
|
|
|
* Returns one of the nsIObjectLoadingContent::TYPE_ values describing the
|
|
|
|
* content type which will be used for the given MIME type when loaded within
|
|
|
|
* an nsObjectLoadingContent.
|
|
|
|
*
|
|
|
|
* NOTE: This method doesn't take capabilities into account. The caller must
|
|
|
|
* take that into account.
|
|
|
|
*
|
|
|
|
* @param aMIMEType The MIME type of the document being loaded.
|
2015-05-20 16:30:05 +03:00
|
|
|
* @param aNoFakePlugin If false then this method should consider JS plugins.
|
2017-03-04 02:18:02 +03:00
|
|
|
* @param aContent The nsIContent object which is performing the load. May be
|
|
|
|
* nullptr in which case the docshell's plugin permissions
|
|
|
|
* will not be checked.
|
|
|
|
*/
|
|
|
|
static uint32_t HtmlObjectContentTypeForMIMEType(const nsCString& aMIMEType,
|
2015-05-20 16:30:05 +03:00
|
|
|
bool aNoFakePlugin,
|
2017-03-04 02:18:02 +03:00
|
|
|
nsIContent* aContent);
|
|
|
|
|
2017-07-25 00:50:00 +03:00
|
|
|
static already_AddRefed<nsISerialEventTarget> GetEventTargetByLoadInfo(
|
2017-04-04 02:28:41 +03:00
|
|
|
nsILoadInfo* aLoadInfo, mozilla::TaskCategory aCategory);
|
2017-03-24 01:31:00 +03:00
|
|
|
|
2017-04-18 18:35:56 +03:00
|
|
|
/**
|
|
|
|
* Detect whether a string is a local-url.
|
|
|
|
* https://drafts.csswg.org/css-values/#local-urls
|
|
|
|
*/
|
|
|
|
static bool IsLocalRefURL(const nsString& aString);
|
|
|
|
|
2017-04-05 13:42:00 +03:00
|
|
|
/**
|
|
|
|
* Compose a tab id with process id and a serial number.
|
|
|
|
*/
|
|
|
|
static uint64_t GenerateTabId();
|
|
|
|
|
2018-07-26 10:31:00 +03:00
|
|
|
/**
|
|
|
|
* Generate an id for a BrowsingContext using a range of serial
|
|
|
|
* numbers reserved for the current process.
|
|
|
|
*/
|
|
|
|
static uint64_t GenerateBrowsingContextId();
|
|
|
|
|
2017-05-01 20:28:54 +03:00
|
|
|
/**
|
|
|
|
* Check whether we should skip moving the cursor for a same-value .value set
|
|
|
|
* on a text input or textarea.
|
|
|
|
*/
|
|
|
|
static bool SkipCursorMoveForSameValueSet() {
|
|
|
|
return sSkipCursorMoveForSameValueSet;
|
|
|
|
}
|
|
|
|
|
2017-04-24 23:27:35 +03:00
|
|
|
/**
|
|
|
|
* Determine whether or not the user is currently interacting with the web
|
|
|
|
* browser. This method is safe to call from off of the main thread.
|
|
|
|
*/
|
|
|
|
static bool GetUserIsInteracting();
|
|
|
|
|
2017-08-31 13:07:00 +03:00
|
|
|
// Whether tracker tailing is turned on - "network.http.tailing.enabled".
|
|
|
|
static bool IsTailingEnabled() { return sTailingEnabled; }
|
|
|
|
|
2017-06-26 21:53:22 +03:00
|
|
|
// Check pref "dom.placeholder.show_on_focus" to see
|
|
|
|
// if we want to show the placeholder inside input elements
|
|
|
|
// when they have focus.
|
|
|
|
static bool ShowInputPlaceholderOnFocus() {
|
|
|
|
return sShowInputPlaceholderOnFocus;
|
|
|
|
}
|
|
|
|
|
2017-07-02 09:04:24 +03:00
|
|
|
// Check pref "browser.autofocus" to see if we want to enable autofocusing
|
|
|
|
// elements when the page requests it.
|
|
|
|
static bool AutoFocusEnabled() { return sAutoFocusEnabled; }
|
|
|
|
|
2017-06-05 15:06:20 +03:00
|
|
|
// Check pref "dom.script_loader.bytecode_cache.enabled" to see
|
|
|
|
// if we want to cache JS bytecode on the cache entry.
|
|
|
|
static bool IsBytecodeCacheEnabled() { return sIsBytecodeCacheEnabled; }
|
|
|
|
|
|
|
|
// Check pref "dom.script_loader.bytecode_cache.strategy" to see which
|
|
|
|
// heuristic strategy should be used to trigger the caching of the bytecode.
|
|
|
|
static int32_t BytecodeCacheStrategy() { return sBytecodeCacheStrategy; }
|
|
|
|
|
2017-06-09 16:52:52 +03:00
|
|
|
// Alternate data MIME type used by the ScriptLoader to register and read
|
|
|
|
// bytecode out of the nsCacheInfoChannel.
|
|
|
|
static nsCString& JSBytecodeMimeType() { return *sJSBytecodeMimeType; }
|
|
|
|
|
2017-06-05 20:33:11 +03:00
|
|
|
/**
|
|
|
|
* Checks if the passed-in name should override an existing name on the
|
|
|
|
* window. Values which should not override include: "", "_blank", "_top",
|
|
|
|
* "_parent" and "_self".
|
|
|
|
*/
|
|
|
|
static bool IsOverridingWindowName(const nsAString& aName);
|
|
|
|
|
2017-06-29 02:51:46 +03:00
|
|
|
/**
|
|
|
|
* If there is a SourceMap (higher precedence) or X-SourceMap (lower
|
|
|
|
* precedence) response header in |aChannel|, set |aResult| to the
|
|
|
|
* header's value and return true. Otherwise, return false.
|
|
|
|
*
|
|
|
|
* @param aChannel The HTTP channel
|
|
|
|
* @param aResult The string result.
|
|
|
|
*/
|
|
|
|
static bool GetSourceMapURL(nsIHttpChannel* aChannel, nsACString& aResult);
|
|
|
|
|
2017-08-09 23:59:27 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the passed-in mesasge is a pending InputEvent.
|
|
|
|
*
|
|
|
|
* @param aMsg The message to check
|
|
|
|
*/
|
|
|
|
static bool IsMessageInputEvent(const IPC::Message& aMsg);
|
|
|
|
|
2017-09-29 18:54:06 +03:00
|
|
|
static void AsyncPrecreateStringBundles();
|
|
|
|
|
2017-11-18 00:20:16 +03:00
|
|
|
static bool ContentIsLink(nsIContent* aContent);
|
|
|
|
|
2018-08-03 06:49:09 +03:00
|
|
|
static already_AddRefed<mozilla::dom::ContentFrameMessageManager>
|
|
|
|
TryGetTabChildGlobal(nsISupports* aFrom);
|
2017-11-18 00:42:50 +03:00
|
|
|
|
2017-11-22 00:20:45 +03:00
|
|
|
// Get a serial number for a newly created inner or outer window.
|
|
|
|
static uint32_t InnerOrOuterWindowCreated();
|
|
|
|
// Record that an inner or outer window has been destroyed.
|
|
|
|
static void InnerOrOuterWindowDestroyed();
|
|
|
|
// Get the current number of inner or outer windows.
|
|
|
|
static int32_t GetCurrentInnerOrOuterWindowCount() {
|
|
|
|
return sInnerOrOuterWindowCount;
|
|
|
|
}
|
|
|
|
|
2018-08-07 18:49:13 +03:00
|
|
|
/**
|
|
|
|
* Serializes a JSON-like JS::Value into a string.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* nsAutoString serializedValue;
|
|
|
|
* nsContentUtils::StringifyJSON(cx, &value, serializedValue);
|
|
|
|
*/
|
|
|
|
static bool StringifyJSON(JSContext* aCx, JS::MutableHandle<JS::Value> vp,
|
|
|
|
nsAString& aOutStr);
|
|
|
|
|
2019-01-22 02:13:01 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the top level ancestor content document of aDocument hasn't
|
|
|
|
* yet had the first contentful paint and there is a high priority event
|
|
|
|
* pending in the main thread.
|
|
|
|
*/
|
|
|
|
static bool HighPriorityEventPendingForTopLevelDocumentBeforeContentfulPaint(
|
|
|
|
Document* aDocument);
|
|
|
|
|
2004-03-06 05:58:08 +03:00
|
|
|
private:
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool InitializeEventTable();
|
2007-04-02 21:17:36 +04:00
|
|
|
|
2004-12-17 23:40:48 +03:00
|
|
|
static nsresult EnsureStringBundle(PropertiesFile aFile);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool CanCallerAccess(nsIPrincipal* aSubjectPrincipal,
|
2008-02-27 05:03:27 +03:00
|
|
|
nsIPrincipal* aPrincipal);
|
|
|
|
|
2014-04-10 08:58:41 +04:00
|
|
|
static nsresult WrapNative(JSContext* cx, nsISupports* native,
|
|
|
|
nsWrapperCache* cache, const nsIID* aIID,
|
|
|
|
JS::MutableHandle<JS::Value> vp,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aAllowWrapping);
|
2013-05-02 13:12:46 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
static nsresult DispatchEvent(Document* aDoc, nsISupports* aTarget,
|
2012-02-14 03:07:04 +04:00
|
|
|
const nsAString& aEventName, CanBubble,
|
2018-06-25 19:23:50 +03:00
|
|
|
Cancelable, Composed, Trusted,
|
|
|
|
bool* aDefaultAction = nullptr,
|
|
|
|
ChromeOnlyDispatch = ChromeOnlyDispatch::eNo);
|
2010-05-10 22:53:05 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
static nsresult DispatchEvent(Document* aDoc, nsISupports* aTarget,
|
2017-06-17 06:37:23 +03:00
|
|
|
mozilla::WidgetEvent& aWidgetEvent,
|
2018-06-25 19:23:50 +03:00
|
|
|
EventMessage aEventMessage, CanBubble,
|
|
|
|
Cancelable, Trusted,
|
|
|
|
bool* aDefaultAction = nullptr,
|
|
|
|
ChromeOnlyDispatch = ChromeOnlyDispatch::eNo);
|
2017-06-17 06:37:23 +03:00
|
|
|
|
2011-07-31 23:43:54 +04:00
|
|
|
static void InitializeModifierStrings();
|
|
|
|
|
2011-08-01 11:48:24 +04:00
|
|
|
static void DropFragmentParsers();
|
|
|
|
|
2017-02-14 00:06:45 +03:00
|
|
|
static bool MatchClassNames(mozilla::dom::Element* aElement,
|
2017-10-03 01:05:19 +03:00
|
|
|
int32_t aNamespaceID, nsAtom* aAtom, void* aData);
|
2012-09-26 18:17:47 +04:00
|
|
|
static void DestroyClassNameArray(void* aData);
|
|
|
|
static void* AllocClassMatchingInfo(nsINode* aRootNode,
|
|
|
|
const nsString* aClasses);
|
|
|
|
|
2017-06-17 06:37:23 +03:00
|
|
|
static mozilla::EventClassID GetEventClassIDFromMessage(
|
2018-06-25 19:23:50 +03:00
|
|
|
EventMessage aEventMessage);
|
2017-06-17 06:37:23 +03:00
|
|
|
|
2014-07-09 11:01:00 +04:00
|
|
|
// Fills in aInfo with the tokens from the supplied autocomplete attribute.
|
2014-06-06 11:25:02 +04:00
|
|
|
static AutocompleteAttrState InternalSerializeAutocompleteAttribute(
|
2017-05-10 05:57:00 +03:00
|
|
|
const nsAttrValue* aAttrVal, mozilla::dom::AutocompleteInfo& aInfo,
|
|
|
|
bool aGrantAllValidValue = false);
|
2014-06-06 11:25:02 +04:00
|
|
|
|
2018-04-16 16:18:48 +03:00
|
|
|
static bool CallOnAllRemoteChildren(
|
|
|
|
mozilla::dom::MessageBroadcaster* aManager,
|
2014-11-27 16:28:26 +03:00
|
|
|
CallOnRemoteChildFunction aCallback, void* aArg);
|
|
|
|
|
2017-04-13 19:21:34 +03:00
|
|
|
/**
|
2019-03-08 12:00:06 +03:00
|
|
|
* Gets the cookie lifetime policy for a given cookieSettings and a given
|
|
|
|
* principal by checking the permission value.
|
2017-04-13 19:21:34 +03:00
|
|
|
*
|
2019-02-05 12:12:11 +03:00
|
|
|
* Used in the implementation of InternalStorageAllowedCheck.
|
2017-04-13 19:21:34 +03:00
|
|
|
*/
|
2019-03-08 12:00:06 +03:00
|
|
|
static void GetCookieLifetimePolicyFromCookieSettings(
|
|
|
|
nsICookieSettings* aCookieSettings, nsIPrincipal* aPrincipal,
|
|
|
|
uint32_t* aLifetimePolicy);
|
2017-04-13 19:21:34 +03:00
|
|
|
|
2015-07-15 23:41:28 +03:00
|
|
|
/*
|
|
|
|
* Checks if storage for a given principal is permitted by the user's
|
|
|
|
* preferences. If aWindow is non-null, its principal must be passed as
|
|
|
|
* aPrincipal, and the third-party iframe and sandboxing status of the window
|
2018-01-09 04:25:53 +03:00
|
|
|
* are also checked. If aURI is non-null, then it is used as the comparison
|
2018-01-23 18:38:53 +03:00
|
|
|
* against aWindow to determine if this is a third-party load. We also
|
|
|
|
* allow a channel instead of the window reference when determining 3rd party
|
|
|
|
* status.
|
2015-07-15 23:41:28 +03:00
|
|
|
*
|
2019-02-05 12:12:11 +03:00
|
|
|
* Used in the implementation of StorageAllowedForWindow,
|
|
|
|
* StorageAllowedForChannel and StorageAllowedForServiceWorker.
|
2015-07-15 23:41:28 +03:00
|
|
|
*/
|
2019-02-05 12:12:11 +03:00
|
|
|
static StorageAccess InternalStorageAllowedCheck(nsIPrincipal* aPrincipal,
|
|
|
|
nsPIDOMWindowInner* aWindow,
|
|
|
|
nsIURI* aURI,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
uint32_t& aRejectedReason);
|
2015-07-15 23:41:28 +03:00
|
|
|
|
2017-07-29 04:37:27 +03:00
|
|
|
static nsINode* GetCommonAncestorHelper(nsINode* aNode1, nsINode* aNode2);
|
|
|
|
static nsIContent* GetCommonFlattenedTreeAncestorHelper(
|
|
|
|
nsIContent* aContent1, nsIContent* aContent2);
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
static nsIXPConnect* sXPConnect;
|
2002-07-18 09:53:28 +04:00
|
|
|
|
|
|
|
static nsIScriptSecurityManager* sSecurityManager;
|
2014-05-07 02:43:03 +04:00
|
|
|
static nsIPrincipal* sSystemPrincipal;
|
2014-05-21 09:52:20 +04:00
|
|
|
static nsIPrincipal* sNullSubjectPrincipal;
|
2002-08-09 12:45:30 +04:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
static nsNameSpaceManager* sNameSpaceManager;
|
2003-07-08 09:35:04 +04:00
|
|
|
|
|
|
|
static nsIIOService* sIOService;
|
2015-06-17 13:44:27 +03:00
|
|
|
static nsIUUIDGenerator* sUUIDGenerator;
|
2003-10-30 05:53:08 +03:00
|
|
|
|
2004-09-14 21:26:35 +04:00
|
|
|
static nsIConsoleService* sConsoleService;
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
static nsDataHashtable<nsRefPtrHashKey<nsAtom>, EventNameMapping>*
|
|
|
|
sAtomEventTable;
|
2010-06-22 22:12:12 +04:00
|
|
|
static nsDataHashtable<nsStringHashKey, EventNameMapping>* sStringEventTable;
|
2017-10-03 01:05:19 +03:00
|
|
|
static nsTArray<RefPtr<nsAtom>>* sUserDefinedEvents;
|
2007-04-02 21:17:36 +04:00
|
|
|
|
2004-09-14 21:26:35 +04:00
|
|
|
static nsIStringBundleService* sStringBundleService;
|
|
|
|
static nsIStringBundle* sStringBundles[PropertiesFile_COUNT];
|
2018-05-19 02:11:06 +03:00
|
|
|
class nsContentUtilsReporter;
|
2004-09-14 21:26:35 +04:00
|
|
|
|
2005-08-19 19:00:01 +04:00
|
|
|
static nsIContentPolicy* sContentPolicyService;
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sTriedToGetContentPolicy;
|
2005-08-19 19:00:01 +04:00
|
|
|
|
2017-12-14 07:17:32 +03:00
|
|
|
static RefPtr<mozilla::intl::LineBreaker> sLineBreaker;
|
2017-12-14 07:17:38 +03:00
|
|
|
static RefPtr<mozilla::intl::WordBreaker> sWordBreaker;
|
2005-08-22 07:00:06 +04:00
|
|
|
|
2018-09-15 21:38:44 +03:00
|
|
|
static mozilla::StaticRefPtr<nsIBidiKeyboard> sBidiKeyboard;
|
2006-08-08 09:14:52 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sInitialized;
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sScriptBlockerCount;
|
|
|
|
static uint32_t sDOMNodeRemovedSuppressCount;
|
2017-10-05 18:34:12 +03:00
|
|
|
|
2011-08-03 22:32:32 +04:00
|
|
|
// Not an nsCOMArray because removing elements from those is slower
|
2016-05-30 18:47:32 +03:00
|
|
|
static AutoTArray<nsCOMPtr<nsIRunnable>, 8>* sBlockedScriptRunners;
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sRunnersCountAtFirstBlocker;
|
|
|
|
static uint32_t sScriptBlockerCountWhereRunnersPrevented;
|
2008-09-08 05:13:02 +04:00
|
|
|
|
|
|
|
static nsIInterfaceRequestor* sSameOriginChecker;
|
2010-04-24 14:40:48 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sIsHandlingKeyBoardEvent;
|
|
|
|
static bool sAllowXULXBL_for_file;
|
2018-09-12 18:51:30 +03:00
|
|
|
static bool sIsFullscreenApiEnabled;
|
2016-05-02 07:26:04 +03:00
|
|
|
static bool sIsUnprefixedFullscreenApiEnabled;
|
2018-09-12 18:51:30 +03:00
|
|
|
static bool sTrustedFullscreenOnly;
|
2015-06-08 01:21:58 +03:00
|
|
|
static bool sIsCutCopyAllowed;
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sHandlingInputTimeout;
|
2013-05-11 02:57:58 +04:00
|
|
|
static bool sIsPerformanceTimingEnabled;
|
2013-10-16 05:35:44 +04:00
|
|
|
static bool sIsResourceTimingEnabled;
|
2017-10-04 03:48:33 +03:00
|
|
|
static bool sIsPerformanceNavigationTimingEnabled;
|
2018-02-05 18:37:27 +03:00
|
|
|
static bool sIsUpgradableDisplayContentPrefEnabled;
|
2015-08-21 00:20:33 +03:00
|
|
|
static bool sIsFrameTimingPrefEnabled;
|
2017-07-27 06:41:15 +03:00
|
|
|
static bool sIsFormAutofillAutocompleteEnabled;
|
2015-08-01 01:40:08 +03:00
|
|
|
static bool sSendPerformanceTimingNotifications;
|
2016-08-19 17:43:01 +03:00
|
|
|
static bool sUseActivityCursor;
|
2017-04-07 22:44:57 +03:00
|
|
|
static bool sAnimationsAPICoreEnabled;
|
2017-04-07 22:48:24 +03:00
|
|
|
static bool sGetBoxQuadsEnabled;
|
2017-05-01 20:28:54 +03:00
|
|
|
static bool sSkipCursorMoveForSameValueSet;
|
2017-04-29 08:54:50 +03:00
|
|
|
static bool sRequestIdleCallbackEnabled;
|
2017-08-31 13:07:00 +03:00
|
|
|
static bool sTailingEnabled;
|
2017-06-26 21:53:22 +03:00
|
|
|
static bool sShowInputPlaceholderOnFocus;
|
2017-07-02 09:04:24 +03:00
|
|
|
static bool sAutoFocusEnabled;
|
2016-11-29 10:03:01 +03:00
|
|
|
#ifndef RELEASE_OR_BETA
|
|
|
|
static bool sBypassCSSOMOriginCheck;
|
|
|
|
#endif
|
2017-06-05 15:06:20 +03:00
|
|
|
static bool sIsBytecodeCacheEnabled;
|
|
|
|
static int32_t sBytecodeCacheStrategy;
|
2015-07-15 23:41:28 +03:00
|
|
|
static uint32_t sCookiesLifetimePolicy;
|
2018-08-24 02:29:21 +03:00
|
|
|
static bool sAntiTrackingControlCenterUIEnabled;
|
2011-07-31 23:43:54 +04:00
|
|
|
|
2017-03-29 10:43:56 +03:00
|
|
|
static int32_t sPrivacyMaxInnerWidth;
|
|
|
|
static int32_t sPrivacyMaxInnerHeight;
|
|
|
|
|
2017-04-24 23:27:35 +03:00
|
|
|
class UserInteractionObserver;
|
|
|
|
static UserInteractionObserver* sUserInteractionObserver;
|
|
|
|
|
2012-01-20 15:16:27 +04:00
|
|
|
static nsHtml5StringParser* sHTMLFragmentParser;
|
2011-08-01 11:48:24 +04:00
|
|
|
static nsIParser* sXMLFragmentParser;
|
|
|
|
static nsIFragmentContentSink* sXMLFragmentSink;
|
|
|
|
|
2011-10-14 14:39:19 +04:00
|
|
|
/**
|
|
|
|
* True if there's a fragment parser activation on the stack.
|
|
|
|
*/
|
|
|
|
static bool sFragmentParsingActive;
|
|
|
|
|
2011-07-31 23:43:54 +04:00
|
|
|
static nsString* sShiftText;
|
|
|
|
static nsString* sControlText;
|
|
|
|
static nsString* sMetaText;
|
2012-07-19 05:28:16 +04:00
|
|
|
static nsString* sOSText;
|
2011-07-31 23:43:54 +04:00
|
|
|
static nsString* sAltText;
|
|
|
|
static nsString* sModifierSeparator;
|
2013-08-01 04:04:49 +04:00
|
|
|
|
2017-06-09 16:52:52 +03:00
|
|
|
// Alternate data mime type, used by the ScriptLoader to register and read the
|
|
|
|
// bytecode out of the nsCacheInfoChannel.
|
|
|
|
static nsCString* sJSBytecodeMimeType;
|
|
|
|
|
2016-06-02 05:22:18 +03:00
|
|
|
static bool sDoNotTrackEnabled;
|
2016-01-07 00:18:29 +03:00
|
|
|
static mozilla::LazyLogModule sDOMDumpLog;
|
2017-11-18 01:09:20 +03:00
|
|
|
|
2017-11-22 00:20:45 +03:00
|
|
|
static int32_t sInnerOrOuterWindowCount;
|
|
|
|
static uint32_t sInnerOrOuterWindowSerialCounter;
|
2002-08-09 12:45:30 +04:00
|
|
|
};
|
|
|
|
|
2017-05-18 08:05:55 +03:00
|
|
|
/* static */ inline nsContentPolicyType
|
|
|
|
nsContentUtils::InternalContentPolicyTypeToExternal(nsContentPolicyType aType) {
|
|
|
|
switch (aType) {
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD:
|
2019-02-12 16:16:32 +03:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_MODULE:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD:
|
2017-05-18 08:05:55 +03:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_WORKER:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS:
|
|
|
|
return nsIContentPolicy::TYPE_SCRIPT;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-18 08:05:55 +03:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_EMBED:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_OBJECT:
|
|
|
|
return nsIContentPolicy::TYPE_OBJECT;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-18 08:05:55 +03:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_FRAME:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_IFRAME:
|
|
|
|
return nsIContentPolicy::TYPE_SUBDOCUMENT;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-18 08:05:55 +03:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_AUDIO:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_VIDEO:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_TRACK:
|
|
|
|
return nsIContentPolicy::TYPE_MEDIA;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-18 08:05:55 +03:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_EVENTSOURCE:
|
|
|
|
return nsIContentPolicy::TYPE_XMLHTTPREQUEST;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-18 08:05:55 +03:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_IMAGE:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON:
|
|
|
|
return nsIContentPolicy::TYPE_IMAGE;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-18 08:05:55 +03:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD:
|
|
|
|
return nsIContentPolicy::TYPE_STYLESHEET;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-18 08:05:55 +03:00
|
|
|
default:
|
|
|
|
return aType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ inline nsContentPolicyType
|
|
|
|
nsContentUtils::InternalContentPolicyTypeToExternalOrWorker(
|
|
|
|
nsContentPolicyType aType) {
|
|
|
|
switch (aType) {
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_WORKER:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER:
|
|
|
|
return aType;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return InternalContentPolicyTypeToExternal(aType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-03 19:15:23 +03:00
|
|
|
class MOZ_RAII nsAutoScriptBlocker {
|
2008-03-15 02:08:57 +03:00
|
|
|
public:
|
2014-07-28 21:17:51 +04:00
|
|
|
explicit nsAutoScriptBlocker(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) {
|
2012-01-10 09:29:30 +04:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2008-03-15 02:08:57 +03:00
|
|
|
nsContentUtils::AddScriptBlocker();
|
|
|
|
}
|
|
|
|
~nsAutoScriptBlocker() { nsContentUtils::RemoveScriptBlocker(); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-04-04 22:15:18 +04:00
|
|
|
private:
|
2012-01-10 09:29:30 +04:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2008-03-15 02:08:57 +03:00
|
|
|
};
|
|
|
|
|
2013-04-12 07:20:09 +04:00
|
|
|
class MOZ_STACK_CLASS nsAutoScriptBlockerSuppressNodeRemoved
|
2011-05-09 23:33:04 +04:00
|
|
|
: public nsAutoScriptBlocker {
|
|
|
|
public:
|
|
|
|
nsAutoScriptBlockerSuppressNodeRemoved() {
|
|
|
|
++nsContentUtils::sDOMNodeRemovedSuppressCount;
|
|
|
|
}
|
|
|
|
~nsAutoScriptBlockerSuppressNodeRemoved() {
|
|
|
|
--nsContentUtils::sDOMNodeRemovedSuppressCount;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-21 10:43:58 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class TreeOrderComparator {
|
|
|
|
public:
|
|
|
|
bool Equals(nsINode* aElem1, nsINode* aElem2) const {
|
|
|
|
return aElem1 == aElem2;
|
|
|
|
}
|
|
|
|
bool LessThan(nsINode* aElem1, nsINode* aElem2) const {
|
|
|
|
return nsContentUtils::PositionIsBefore(aElem1, aElem2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2004-01-06 03:36:01 +03:00
|
|
|
#define NS_INTERFACE_MAP_ENTRY_TEAROFF(_interface, _allocator) \
|
|
|
|
if (aIID.Equals(NS_GET_IID(_interface))) { \
|
2007-07-11 12:46:44 +04:00
|
|
|
foundInterface = static_cast<_interface*>(_allocator); \
|
2004-01-06 03:36:01 +03:00
|
|
|
if (!foundInterface) { \
|
2014-10-01 13:26:00 +04:00
|
|
|
*aInstancePtr = nullptr; \
|
2004-01-06 03:36:01 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY; \
|
|
|
|
} \
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
} else
|
|
|
|
|
2008-04-08 15:47:57 +04: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) \
|
2014-10-01 13:26:00 +04:00
|
|
|
if (!mozilla::IsFinite(f)) { \
|
2008-04-08 15:47:57 +04:00
|
|
|
return (rv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_ENSURE_FINITE2(f1, f2, rv) \
|
2014-10-01 13:26:00 +04:00
|
|
|
if (!mozilla::IsFinite((f1) + (f2))) { \
|
2008-04-08 15:47:57 +04:00
|
|
|
return (rv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_ENSURE_FINITE4(f1, f2, f3, f4, rv) \
|
2014-10-01 13:26:00 +04:00
|
|
|
if (!mozilla::IsFinite((f1) + (f2) + (f3) + (f4))) { \
|
2008-04-08 15:47:57 +04:00
|
|
|
return (rv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_ENSURE_FINITE5(f1, f2, f3, f4, f5, rv) \
|
2014-10-01 13:26:00 +04:00
|
|
|
if (!mozilla::IsFinite((f1) + (f2) + (f3) + (f4) + (f5))) { \
|
2008-04-08 15:47:57 +04:00
|
|
|
return (rv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_ENSURE_FINITE6(f1, f2, f3, f4, f5, f6, rv) \
|
2014-10-01 13:26:00 +04:00
|
|
|
if (!mozilla::IsFinite((f1) + (f2) + (f3) + (f4) + (f5) + (f6))) { \
|
2008-04-08 15:47:57 +04:00
|
|
|
return (rv); \
|
|
|
|
}
|
|
|
|
|
2008-12-15 14:33:56 +03: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_; \
|
2012-07-30 18:20:58 +04:00
|
|
|
(ptr_)->member_ = nullptr; \
|
2008-12-15 14:33:56 +03:00
|
|
|
while (cur) { \
|
|
|
|
type_* next = cur->member_; \
|
2012-07-30 18:20:58 +04:00
|
|
|
cur->member_ = nullptr; \
|
2008-12-15 14:33:56 +03:00
|
|
|
delete cur; \
|
|
|
|
cur = next; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2001-02-17 12:53:29 +03:00
|
|
|
#endif /* nsContentUtils_h___ */
|