Bug 1539524 - BroadcastChannel must bind itself to valid nsIGlobalObject in workers, r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D25082

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-03-28 22:12:27 +00:00
Родитель df4f2bc264
Коммит 3eb9182bd3
2 изменённых файлов: 17 добавлений и 10 удалений

Просмотреть файл

@ -198,11 +198,10 @@ class TeardownRunnableOnWorker final : public WorkerControlRunnable,
} // namespace
BroadcastChannel::BroadcastChannel(nsPIDOMWindowInner* aWindow,
BroadcastChannel::BroadcastChannel(nsIGlobalObject* aGlobal,
const nsAString& aChannel)
: DOMEventTargetHelper(aWindow), mChannel(aChannel), mState(StateActive) {
// Window can be null in workers
: DOMEventTargetHelper(aGlobal), mChannel(aChannel), mState(StateActive) {
MOZ_ASSERT(aGlobal);
KeepAliveIfHasListenersFor(NS_LITERAL_STRING("message"));
}
@ -219,16 +218,24 @@ JSObject* BroadcastChannel::WrapObject(JSContext* aCx,
/* static */
already_AddRefed<BroadcastChannel> BroadcastChannel::Constructor(
const GlobalObject& aGlobal, const nsAString& aChannel, ErrorResult& aRv) {
nsCOMPtr<nsPIDOMWindowInner> window =
do_QueryInterface(aGlobal.GetAsSupports());
// Window is null in workers.
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
if (NS_WARN_IF(!global)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
RefPtr<BroadcastChannel> bc = new BroadcastChannel(window, aChannel);
RefPtr<BroadcastChannel> bc = new BroadcastChannel(global, aChannel);
nsAutoCString origin;
PrincipalInfo principalInfo;
if (NS_IsMainThread()) {
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global);
if (NS_WARN_IF(!window)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsCOMPtr<nsIGlobalObject> incumbent = mozilla::dom::GetIncumbentGlobal();
if (!incumbent) {

Просмотреть файл

@ -13,7 +13,7 @@
#include "nsTArray.h"
#include "mozilla/RefPtr.h"
class nsPIDOMWindowInner;
class nsIGlobalObject;
namespace mozilla {
@ -57,7 +57,7 @@ class BroadcastChannel final : public DOMEventTargetHelper {
void Shutdown();
private:
BroadcastChannel(nsPIDOMWindowInner* aWindow, const nsAString& aChannel);
BroadcastChannel(nsIGlobalObject* aGlobal, const nsAString& aChannel);
~BroadcastChannel();