Bug 1464474 - Some cleanup in nsFrameMessageManager. r=bz.

--HG--
extra : rebase_source : e081a086588e52dbe9363c8c622522adbff537e5
This commit is contained in:
Peter Van der Beken 2018-05-17 16:42:13 +02:00
Родитель b47af51698
Коммит 188ac76110
3 изменённых файлов: 18 добавлений и 76 удалений

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

@ -157,18 +157,17 @@ NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFrameMessageManager)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFrameMessageManager)
nsresult
MessageManagerCallback::DoGetRemoteType(nsAString& aRemoteType) const
void
MessageManagerCallback::DoGetRemoteType(nsAString& aRemoteType,
ErrorResult& aError) const
{
aRemoteType.Truncate();
mozilla::dom::ChromeMessageSender* parent = GetProcessMessageManager();
if (!parent) {
return NS_OK;
return;
}
ErrorResult rv;
parent->GetRemoteType(aRemoteType, rv);
return rv.StealNSResult();
parent->GetRemoteType(aRemoteType, aError);
}
bool
@ -408,26 +407,6 @@ nsFrameMessageManager::GetDelayedScripts(JSContext* aCx,
}
}
nsresult
nsFrameMessageManager::GetDelayedScripts(JSContext* aCx,
JS::MutableHandle<JS::Value> aList)
{
ErrorResult rv;
nsTArray<nsTArray<JS::Value>> list;
SequenceRooter<nsTArray<JS::Value>> listRooter(aCx, &list);
GetDelayedScripts(aCx, list, rv);
rv.WouldReportJSException();
if (rv.Failed()) {
return rv.StealNSResult();
}
if (!ToJSValue(aCx, list, aList)) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
static bool
JSONCreator(const char16_t* aBuf, uint32_t aLen, void* aData)
{
@ -523,6 +502,11 @@ nsFrameMessageManager::SendMessage(JSContext* aCx,
nsTArray<JS::Value>& aResult,
ErrorResult& aError)
{
NS_ASSERTION(!IsGlobal(), "Should not call SendSyncMessage in chrome");
NS_ASSERTION(!IsBroadcaster(), "Should not call SendSyncMessage in chrome");
NS_ASSERTION(!GetParentManager(),
"Should not have parent manager in content!");
AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING(
"nsFrameMessageManager::SendMessage", EVENTS, aMessageName);
@ -539,36 +523,17 @@ nsFrameMessageManager::SendMessage(JSContext* aCx,
return;
}
SendMessage(aCx, aMessageName, data, aObjects, aPrincipal, aIsSync, aResult,
aError);
}
void
nsFrameMessageManager::SendMessage(JSContext* aCx,
const nsAString& aMessageName,
StructuredCloneData& aData,
JS::Handle<JSObject*> aObjects,
nsIPrincipal* aPrincipal,
bool aIsSync,
nsTArray<JS::Value>& aResult,
ErrorResult& aError)
{
NS_ASSERTION(!IsGlobal(), "Should not call SendSyncMessage in chrome");
NS_ASSERTION(!IsBroadcaster(), "Should not call SendSyncMessage in chrome");
NS_ASSERTION(!GetParentManager(),
"Should not have parent manager in content!");
#ifdef FUZZING
if (aData.DataLength() > 0) {
if (data.DataLength() > 0) {
MessageManagerFuzzer::TryMutate(
aCx,
aMessageName,
&aData,
&data,
JS::UndefinedHandleValue);
}
#endif
if (!AllowMessage(aData.DataLength(), aMessageName)) {
if (!AllowMessage(data.DataLength(), aMessageName)) {
aError.Throw(NS_ERROR_FAILURE);
return;
}
@ -582,7 +547,7 @@ nsFrameMessageManager::SendMessage(JSContext* aCx,
TimeStamp start = TimeStamp::Now();
sSendingSyncMessage |= aIsSync;
bool ok = mCallback->DoSendBlockingMessage(aCx, aMessageName, aData, aObjects,
bool ok = mCallback->DoSendBlockingMessage(aCx, aMessageName, data, aObjects,
aPrincipal, &retval, aIsSync);
if (aIsSync) {
sSendingSyncMessage = false;
@ -1050,7 +1015,7 @@ nsFrameMessageManager::GetRemoteType(nsAString& aRemoteType, ErrorResult& aError
{
aRemoteType.Truncate();
if (mCallback) {
aError = mCallback->DoGetRemoteType(aRemoteType);
mCallback->DoGetRemoteType(aRemoteType, aError);
}
}

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

@ -101,7 +101,8 @@ public:
return nullptr;
}
virtual nsresult DoGetRemoteType(nsAString& aRemoteType) const;
virtual void DoGetRemoteType(nsAString& aRemoteType,
ErrorResult& aError) const;
protected:
bool BuildClonedMessageDataForParent(nsIContentParent* aParent,
@ -303,22 +304,10 @@ protected:
JS::Handle<JS::Value> aTransfers,
mozilla::ErrorResult& aError);
nsresult SendMessage(const nsAString& aMessageName,
JS::Handle<JS::Value> aJSON,
JS::Handle<JS::Value> aObjects,
nsIPrincipal* aPrincipal,
JSContext* aCx,
uint8_t aArgc,
JS::MutableHandle<JS::Value> aRetval,
bool aIsSync);
void SendMessage(JSContext* aCx, const nsAString& aMessageName,
JS::Handle<JS::Value> aObj, JS::Handle<JSObject*> aObjects,
nsIPrincipal* aPrincipal, bool aIsSync, nsTArray<JS::Value>& aResult,
mozilla::ErrorResult& aError);
void SendMessage(JSContext* aCx, const nsAString& aMessageName,
StructuredCloneData& aData, JS::Handle<JSObject*> aObjects,
nsIPrincipal* aPrincipal, bool aIsSync,
nsTArray<JS::Value>& aResult, mozilla::ErrorResult& aError);
void ReceiveMessage(nsISupports* aTarget, nsFrameLoader* aTargetFrameLoader,
bool aTargetClosed, const nsAString& aMessage, bool aIsSync,
@ -329,20 +318,9 @@ protected:
void LoadScript(const nsAString& aURL, bool aAllowDelayedLoad,
bool aRunInGlobalScope, mozilla::ErrorResult& aError);
void RemoveDelayedScript(const nsAString& aURL);
nsresult GetDelayedScripts(JSContext* aCx,
JS::MutableHandle<JS::Value> aList);
void GetDelayedScripts(JSContext* aCx, nsTArray<nsTArray<JS::Value>>& aList,
mozilla::ErrorResult& aError);
enum ProcessCheckerType {
PROCESS_CHECKER_PERMISSION,
PROCESS_CHECKER_MANIFEST_URL,
ASSERT_APP_HAS_PERMISSION
};
bool AssertProcessInternal(ProcessCheckerType aType,
const nsAString& aCapability,
mozilla::ErrorResult& aError);
// We keep the message listeners as arrays in a hastable indexed by the
// message name. That gives us fast lookups in ReceiveMessage().
nsClassHashtable<nsStringHashKey,

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

@ -199,10 +199,9 @@ public:
const nsAString& GetRemoteType() const;
virtual nsresult DoGetRemoteType(nsAString& aRemoteType) const override
virtual void DoGetRemoteType(nsAString& aRemoteType, ErrorResult& aError) const override
{
aRemoteType = GetRemoteType();
return NS_OK;
}
enum CPIteratorPolicy {