2017-07-19 15:59:02 +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
|
|
|
|
* 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 mozilla_dom_MessageManagerGlobal_h
|
|
|
|
#define mozilla_dom_MessageManagerGlobal_h
|
|
|
|
|
|
|
|
#include "nsFrameMessageManager.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for implementing the WebIDL MessageManagerGlobal class.
|
|
|
|
*/
|
|
|
|
class MessageManagerGlobal {
|
|
|
|
public:
|
|
|
|
// MessageListenerManager
|
|
|
|
void AddMessageListener(const nsAString& aMessageName,
|
|
|
|
MessageListener& aListener, bool aListenWhenClosed,
|
|
|
|
ErrorResult& aError) {
|
|
|
|
if (!mMessageManager) {
|
2019-08-10 01:35:54 +03:00
|
|
|
aError.Throw(NS_ERROR_NOT_INITIALIZED);
|
2017-07-19 15:59:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mMessageManager->AddMessageListener(aMessageName, aListener,
|
|
|
|
aListenWhenClosed, aError);
|
|
|
|
}
|
|
|
|
void RemoveMessageListener(const nsAString& aMessageName,
|
|
|
|
MessageListener& aListener, ErrorResult& aError) {
|
|
|
|
if (!mMessageManager) {
|
2019-08-10 01:35:54 +03:00
|
|
|
aError.Throw(NS_ERROR_NOT_INITIALIZED);
|
2017-07-19 15:59:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mMessageManager->RemoveMessageListener(aMessageName, aListener, aError);
|
|
|
|
}
|
|
|
|
void AddWeakMessageListener(const nsAString& aMessageName,
|
|
|
|
MessageListener& aListener, ErrorResult& aError) {
|
|
|
|
if (!mMessageManager) {
|
2019-08-10 01:35:54 +03:00
|
|
|
aError.Throw(NS_ERROR_NOT_INITIALIZED);
|
2017-07-19 15:59:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mMessageManager->AddWeakMessageListener(aMessageName, aListener, aError);
|
|
|
|
}
|
|
|
|
void RemoveWeakMessageListener(const nsAString& aMessageName,
|
|
|
|
MessageListener& aListener,
|
|
|
|
ErrorResult& aError) {
|
|
|
|
if (!mMessageManager) {
|
2019-08-10 01:35:54 +03:00
|
|
|
aError.Throw(NS_ERROR_NOT_INITIALIZED);
|
2017-07-19 15:59:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mMessageManager->RemoveWeakMessageListener(aMessageName, aListener, aError);
|
|
|
|
}
|
|
|
|
|
|
|
|
// MessageSender
|
|
|
|
void SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName,
|
|
|
|
JS::Handle<JS::Value> aObj,
|
|
|
|
JS::Handle<JS::Value> aTransfers, ErrorResult& aError) {
|
|
|
|
if (!mMessageManager) {
|
2019-08-10 01:35:54 +03:00
|
|
|
aError.Throw(NS_ERROR_NOT_INITIALIZED);
|
2017-07-19 15:59:02 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-04-21 17:07:57 +03:00
|
|
|
mMessageManager->SendAsyncMessage(aCx, aMessageName, aObj, aTransfers,
|
|
|
|
aError);
|
2017-07-19 15:59:02 +03:00
|
|
|
}
|
2018-04-16 16:18:48 +03:00
|
|
|
already_AddRefed<ProcessMessageManager> GetProcessMessageManager(
|
|
|
|
mozilla::ErrorResult& aError) {
|
2017-07-19 15:59:02 +03:00
|
|
|
if (!mMessageManager) {
|
2019-08-10 01:35:54 +03:00
|
|
|
aError.Throw(NS_ERROR_NOT_INITIALIZED);
|
2017-07-19 15:59:02 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mMessageManager->GetProcessMessageManager(aError);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetRemoteType(nsAString& aRemoteType, mozilla::ErrorResult& aError) {
|
|
|
|
if (!mMessageManager) {
|
2019-08-10 01:35:54 +03:00
|
|
|
aError.Throw(NS_ERROR_NOT_INITIALIZED);
|
2017-07-19 15:59:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mMessageManager->GetRemoteType(aRemoteType, aError);
|
|
|
|
}
|
|
|
|
|
|
|
|
// SyncMessageSender
|
|
|
|
void SendSyncMessage(JSContext* aCx, const nsAString& aMessageName,
|
2020-04-21 17:07:57 +03:00
|
|
|
JS::Handle<JS::Value> aObj, nsTArray<JS::Value>& aResult,
|
|
|
|
ErrorResult& aError) {
|
2017-07-19 15:59:02 +03:00
|
|
|
if (!mMessageManager) {
|
2019-08-10 01:35:54 +03:00
|
|
|
aError.Throw(NS_ERROR_NOT_INITIALIZED);
|
2017-07-19 15:59:02 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-04-21 17:07:57 +03:00
|
|
|
mMessageManager->SendSyncMessage(aCx, aMessageName, aObj, aResult, aError);
|
2017-07-19 15:59:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// MessageManagerGlobal
|
2018-03-26 17:10:45 +03:00
|
|
|
void Dump(const nsAString& aStr);
|
|
|
|
void Atob(const nsAString& aAsciiString, nsAString& aBase64Data,
|
|
|
|
ErrorResult& aError);
|
|
|
|
void Btoa(const nsAString& aBase64Data, nsAString& aAsciiString,
|
|
|
|
ErrorResult& aError);
|
2017-07-19 15:59:02 +03:00
|
|
|
|
2018-02-16 17:28:31 +03:00
|
|
|
void MarkForCC() {
|
|
|
|
if (mMessageManager) {
|
|
|
|
mMessageManager->MarkForCC();
|
|
|
|
}
|
2017-07-19 15:59:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit MessageManagerGlobal(nsFrameMessageManager* aMessageManager)
|
|
|
|
: mMessageManager(aMessageManager) {}
|
|
|
|
|
|
|
|
RefPtr<nsFrameMessageManager> mMessageManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_MessageManagerGlobal_h
|