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 \
|
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-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 {
|
|
|
|
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
|
2013-04-04 13:27:06 +04:00
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsIGlobalObject()
|
|
|
|
: mIsDying(false)
|
|
|
|
{}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-07-27 18:05:36 +03:00
|
|
|
// GetGlobalJSObject may return a gray object. If this ever changes so that
|
|
|
|
// it stops doing that, please simplify the code in FindAssociatedGlobal in
|
|
|
|
// BindingUtils.h that does JS::ExposeObjectToActiveJS on the return value of
|
2016-07-27 18:05:36 +03:00
|
|
|
// GetGlobalJSObject. Also, in that case the JS::ExposeObjectToActiveJS in
|
2016-08-02 21:06:25 +03:00
|
|
|
// AutoJSAPI::InitInternal can probably be removed. And also the similar
|
|
|
|
// calls in XrayWrapper and nsGlobalWindow.
|
2013-04-04 13:27:06 +04:00
|
|
|
virtual JSObject* GetGlobalJSObject() = 0;
|
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);
|
|
|
|
|
|
|
|
// Any CC class inheriting nsIGlobalObject should call these 2 methods if it
|
|
|
|
// exposes the URL API.
|
|
|
|
void UnlinkHostObjectURIs();
|
|
|
|
void TraverseHostObjectURIs(nsCycleCollectionTraversalCallback &aCb);
|
|
|
|
|
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.
|
|
|
|
void
|
2018-02-21 21:53:53 +03:00
|
|
|
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; }
|
|
|
|
|
2018-01-12 04:46:08 +03:00
|
|
|
virtual mozilla::Maybe<mozilla::dom::ClientInfo>
|
|
|
|
GetClientInfo() const;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
|
|
|
|
void
|
|
|
|
DisconnectEventTargetObjects();
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ShallowSizeOfExcludingThis(mozilla::MallocSizeOf aSizeOf) const;
|
2013-04-04 13:27:06 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsIGlobalObject,
|
|
|
|
NS_IGLOBALOBJECT_IID)
|
|
|
|
|
|
|
|
#endif // nsIGlobalObject_h__
|