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: */
|
2013-04-04 13:27:06 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef nsIGlobalObject_h__
|
|
|
|
#define nsIGlobalObject_h__
|
|
|
|
|
2018-05-04 19:25:05 +03:00
|
|
|
#include "mozilla/LinkedList.h"
|
2018-01-12 04:46:08 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
|
|
|
#include "mozilla/dom/ClientInfo.h"
|
2017-01-31 03:13:18 +03:00
|
|
|
#include "mozilla/dom/DispatcherTrait.h"
|
2018-01-12 04:46:08 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerDescriptor.h"
|
2018-02-21 21:53:22 +03:00
|
|
|
#include "nsHashKeys.h"
|
2013-04-04 13:27:06 +04:00
|
|
|
#include "nsISupports.h"
|
2017-08-17 02:48:52 +03:00
|
|
|
#include "nsStringFwd.h"
|
2015-05-07 10:05:43 +03:00
|
|
|
#include "nsTArray.h"
|
2018-02-21 21:53:22 +03:00
|
|
|
#include "nsTHashtable.h"
|
2013-08-28 06:59:14 +04:00
|
|
|
#include "js/TypeDecls.h"
|
2013-04-04 13:27:06 +04:00
|
|
|
|
2018-01-05 01:32:15 +03:00
|
|
|
// Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
|
2013-04-04 13:27:06 +04:00
|
|
|
#define NS_IGLOBALOBJECT_IID \
|
2018-11-30 13:46:48 +03:00
|
|
|
{ \
|
2015-05-07 10:05:43 +03:00
|
|
|
0x11afa8be, 0xd997, 0x4e07, { \
|
|
|
|
0xa6, 0xa3, 0x6f, 0x87, 0x2e, 0xc3, 0xee, 0x7f \
|
|
|
|
} \
|
|
|
|
}
|
2013-04-04 13:27:06 +04:00
|
|
|
|
2015-05-07 10:05:43 +03:00
|
|
|
class nsCycleCollectionTraversalCallback;
|
2014-01-07 22:53:31 +04:00
|
|
|
class nsIPrincipal;
|
2018-04-04 15:57:17 +03:00
|
|
|
class nsPIDOMWindowInner;
|
2014-01-07 22:53:31 +04:00
|
|
|
|
2018-01-31 20:10:26 +03:00
|
|
|
namespace mozilla {
|
2018-02-21 21:53:22 +03:00
|
|
|
class DOMEventTargetHelper;
|
2018-01-31 20:10:26 +03:00
|
|
|
namespace dom {
|
2019-05-24 11:27:03 +03:00
|
|
|
class VoidFunction;
|
2019-06-17 07:36:29 +03:00
|
|
|
class DebuggerNotificationManager;
|
2020-04-18 15:25:57 +03:00
|
|
|
class Report;
|
|
|
|
class ReportBody;
|
|
|
|
class ReportingObserver;
|
2018-01-31 20:10:26 +03:00
|
|
|
class ServiceWorker;
|
2018-03-03 00:02:49 +03:00
|
|
|
class ServiceWorkerRegistration;
|
|
|
|
class ServiceWorkerRegistrationDescriptor;
|
2018-01-31 20:10:26 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2016-10-29 01:25:08 +03:00
|
|
|
class nsIGlobalObject : public nsISupports,
|
|
|
|
public mozilla::dom::DispatcherTrait {
|
2015-06-29 19:44:18 +03:00
|
|
|
nsTArray<nsCString> mHostObjectURIs;
|
2018-02-21 21:53:22 +03:00
|
|
|
|
|
|
|
// Raw pointers to bound DETH objects. These are added by
|
2018-05-04 19:25:05 +03:00
|
|
|
// AddEventTargetObject().
|
|
|
|
mozilla::LinkedList<mozilla::DOMEventTargetHelper> mEventTargetObjects;
|
2018-02-21 21:53:22 +03:00
|
|
|
|
2015-04-27 22:00:41 +03:00
|
|
|
bool mIsDying;
|
2020-03-28 01:40:58 +03:00
|
|
|
bool mIsScriptForbidden;
|
2015-04-27 22:00:41 +03:00
|
|
|
|
|
|
|
protected:
|
2018-04-04 15:57:17 +03:00
|
|
|
bool mIsInnerWindow;
|
|
|
|
|
2020-04-18 15:25:57 +03:00
|
|
|
nsIGlobalObject();
|
2015-04-27 22:00:41 +03:00
|
|
|
|
2013-04-04 13:27:06 +04:00
|
|
|
public:
|
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IGLOBALOBJECT_IID)
|
|
|
|
|
2015-04-27 22:00:41 +03:00
|
|
|
/**
|
|
|
|
* This check is added to deal with Promise microtask queues. On the main
|
|
|
|
* thread, we do not impose restrictions about when script stops running or
|
|
|
|
* when runnables can no longer be dispatched to the main thread. This means
|
|
|
|
* it is possible for a Promise chain to keep resolving an infinite chain of
|
|
|
|
* promises, preventing the browser from shutting down. See Bug 1058695. To
|
|
|
|
* prevent this, the nsGlobalWindow subclass sets this flag when it is
|
|
|
|
* closed. The Promise implementation checks this and prohibits new runnables
|
|
|
|
* from being dispatched.
|
|
|
|
*
|
|
|
|
* We pair this with checks during processing the promise microtask queue
|
|
|
|
* that pops up the slow script dialog when the Promise queue is preventing
|
|
|
|
* a window from going away.
|
|
|
|
*/
|
|
|
|
bool IsDying() const { return mIsDying; }
|
|
|
|
|
2020-03-28 01:40:58 +03:00
|
|
|
/**
|
|
|
|
* Is it currently forbidden to call into script? JS-implemented WebIDL is
|
|
|
|
* a special case that's always allowed because it has the system principal,
|
|
|
|
* and callers should indicate this.
|
|
|
|
*/
|
|
|
|
bool IsScriptForbidden(JSObject* aCallback,
|
|
|
|
bool aIsJSImplementedWebIDL = false) const;
|
|
|
|
|
2019-05-03 00:36:15 +03:00
|
|
|
/**
|
|
|
|
* Return the JSObject for this global, if it still has one. Otherwise return
|
|
|
|
* null.
|
|
|
|
*
|
|
|
|
* If non-null is returned, then the returned object will have been already
|
|
|
|
* exposed to active JS, so callers do not need to do it.
|
|
|
|
*/
|
2013-04-04 13:27:06 +04:00
|
|
|
virtual JSObject* GetGlobalJSObject() = 0;
|
2014-01-07 22:53:31 +04:00
|
|
|
|
2019-05-03 00:23:35 +03:00
|
|
|
/**
|
|
|
|
* Return the JSObject for this global _without_ exposing it to active JS.
|
|
|
|
* This may return a gray object.
|
|
|
|
*
|
|
|
|
* This method is appropriate to use in assertions (so there is less of a
|
|
|
|
* difference in GC/CC marking between debug and optimized builds) and in
|
|
|
|
* situations where we are sure no CC activity can happen while the return
|
|
|
|
* value is used and the return value does not end up escaping to the heap in
|
|
|
|
* any way. In all other cases, and in particular in cases where the return
|
|
|
|
* value is held in a JS::Rooted or passed to the JSAutoRealm constructor, use
|
|
|
|
* GetGlobalJSObject.
|
|
|
|
*/
|
|
|
|
virtual JSObject* GetGlobalJSObjectPreserveColor() const = 0;
|
|
|
|
|
2019-05-03 00:32:17 +03:00
|
|
|
/**
|
|
|
|
* Check whether this nsIGlobalObject still has a JSObject associated with it,
|
|
|
|
* or whether it's torn-down enough that the JSObject is gone.
|
|
|
|
*/
|
|
|
|
bool HasJSGlobal() const { return GetGlobalJSObjectPreserveColor(); }
|
|
|
|
|
2014-01-07 22:53:31 +04:00
|
|
|
// This method is not meant to be overridden.
|
|
|
|
nsIPrincipal* PrincipalOrNull();
|
2015-04-27 22:00:41 +03:00
|
|
|
|
2015-05-07 10:05:43 +03:00
|
|
|
void RegisterHostObjectURI(const nsACString& aURI);
|
|
|
|
|
|
|
|
void UnregisterHostObjectURI(const nsACString& aURI);
|
|
|
|
|
2020-04-18 15:25:57 +03:00
|
|
|
// Any CC class inheriting nsIGlobalObject should call these 2 methods to
|
|
|
|
// cleanup objects stored in nsIGlobalObject such as blobURLs and Reports.
|
|
|
|
void UnlinkObjectsInGlobal();
|
|
|
|
void TraverseObjectsInGlobal(nsCycleCollectionTraversalCallback& aCb);
|
2015-05-07 10:05:43 +03:00
|
|
|
|
2018-02-21 21:53:22 +03:00
|
|
|
// DETH objects must register themselves on the global when they
|
|
|
|
// bind to it in order to get the DisconnectFromOwner() method
|
|
|
|
// called correctly. RemoveEventTargetObject() must be called
|
|
|
|
// before the DETH object is destroyed.
|
|
|
|
void AddEventTargetObject(mozilla::DOMEventTargetHelper* aObject);
|
|
|
|
void RemoveEventTargetObject(mozilla::DOMEventTargetHelper* aObject);
|
|
|
|
|
|
|
|
// Iterate the registered DETH objects and call the given function
|
|
|
|
// for each one.
|
2018-02-21 21:53:53 +03:00
|
|
|
void ForEachEventTargetObject(
|
|
|
|
const std::function<void(mozilla::DOMEventTargetHelper*, bool* aDoneOut)>&
|
|
|
|
aFunc) const;
|
2018-02-21 21:53:22 +03:00
|
|
|
|
2017-10-05 16:45:26 +03:00
|
|
|
virtual bool IsInSyncOperation() { return false; }
|
|
|
|
|
2019-06-17 07:36:29 +03:00
|
|
|
virtual mozilla::dom::DebuggerNotificationManager*
|
|
|
|
GetOrCreateDebuggerNotificationManager() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual mozilla::dom::DebuggerNotificationManager*
|
|
|
|
GetExistingDebuggerNotificationManager() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-12 04:46:08 +03:00
|
|
|
virtual mozilla::Maybe<mozilla::dom::ClientInfo> GetClientInfo() const;
|
|
|
|
|
2020-02-06 16:45:47 +03:00
|
|
|
virtual mozilla::Maybe<nsID> GetAgentClusterId() const;
|
|
|
|
|
2020-03-25 16:53:46 +03:00
|
|
|
virtual bool CrossOriginIsolated() const { return false; }
|
|
|
|
|
2020-02-06 16:50:11 +03:00
|
|
|
virtual bool IsSharedMemoryAllowed() const { return false; }
|
|
|
|
|
2018-01-12 04:46:08 +03:00
|
|
|
virtual mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> GetController()
|
|
|
|
const;
|
|
|
|
|
2018-01-31 20:10:26 +03:00
|
|
|
// Get the DOM object for the given descriptor or attempt to create one.
|
|
|
|
// Creation can still fail and return nullptr during shutdown, etc.
|
|
|
|
virtual RefPtr<mozilla::dom::ServiceWorker> GetOrCreateServiceWorker(
|
|
|
|
const mozilla::dom::ServiceWorkerDescriptor& aDescriptor);
|
|
|
|
|
2018-07-02 17:44:18 +03:00
|
|
|
// Get the DOM object for the given descriptor or return nullptr if it does
|
|
|
|
// not exist.
|
|
|
|
virtual RefPtr<mozilla::dom::ServiceWorkerRegistration>
|
|
|
|
GetServiceWorkerRegistration(
|
|
|
|
const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor)
|
|
|
|
const;
|
|
|
|
|
2018-03-03 00:02:49 +03:00
|
|
|
// Get the DOM object for the given descriptor or attempt to create one.
|
|
|
|
// Creation can still fail and return nullptr during shutdown, etc.
|
|
|
|
virtual RefPtr<mozilla::dom::ServiceWorkerRegistration>
|
|
|
|
GetOrCreateServiceWorkerRegistration(
|
|
|
|
const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor);
|
|
|
|
|
2018-04-04 15:57:17 +03:00
|
|
|
// Returns a pointer to this object as an inner window if this is one or
|
|
|
|
// nullptr otherwise.
|
|
|
|
nsPIDOMWindowInner* AsInnerWindow();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-05-24 11:27:03 +03:00
|
|
|
void QueueMicrotask(mozilla::dom::VoidFunction& aCallback);
|
|
|
|
|
2020-04-18 15:25:57 +03:00
|
|
|
void RegisterReportingObserver(mozilla::dom::ReportingObserver* aObserver,
|
|
|
|
bool aBuffered);
|
|
|
|
|
|
|
|
void UnregisterReportingObserver(mozilla::dom::ReportingObserver* aObserver);
|
|
|
|
|
|
|
|
void BroadcastReport(mozilla::dom::Report* aReport);
|
|
|
|
|
|
|
|
MOZ_CAN_RUN_SCRIPT void NotifyReportingObservers();
|
|
|
|
|
|
|
|
void RemoveReportRecords();
|
|
|
|
|
2015-05-07 10:05:43 +03:00
|
|
|
protected:
|
|
|
|
virtual ~nsIGlobalObject();
|
|
|
|
|
2015-04-27 22:00:41 +03:00
|
|
|
void StartDying() { mIsDying = true; }
|
2018-02-21 21:53:22 +03:00
|
|
|
|
2020-03-28 01:40:58 +03:00
|
|
|
void StartForbiddingScript() { mIsScriptForbidden = true; }
|
|
|
|
void StopForbiddingScript() { mIsScriptForbidden = false; }
|
|
|
|
|
2018-02-21 21:53:22 +03:00
|
|
|
void DisconnectEventTargetObjects();
|
|
|
|
|
|
|
|
size_t ShallowSizeOfExcludingThis(mozilla::MallocSizeOf aSizeOf) const;
|
2020-04-18 15:25:57 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// List of Report objects for ReportingObservers.
|
|
|
|
nsTArray<RefPtr<mozilla::dom::ReportingObserver>> mReportingObservers;
|
|
|
|
nsTArray<RefPtr<mozilla::dom::Report>> mReportRecords;
|
2013-04-04 13:27:06 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsIGlobalObject, NS_IGLOBALOBJECT_IID)
|
|
|
|
|
|
|
|
#endif // nsIGlobalObject_h__
|