/* -*- 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/. */
NS_IMETHODIMP
PushNotifier::NotifyPushWithData(const nsACString& aScope,
nsIPrincipal* aPrincipal, const nsAString& aMessageId, const nsTArray<uint8_t>& aData) {
NS_ENSURE_ARG(aPrincipal); // We still need to do this copying business, if we want the copy to be // fallible. Just passing Some(aData) would do an infallible copy at the // point where the Some() call happens.
nsTArray<uint8_t> data; if (!data.AppendElements(aData, fallible)) { return NS_ERROR_OUT_OF_MEMORY;
}
PushMessageDispatcher dispatcher(aScope, aPrincipal, aMessageId,
Some(std::move(data))); return Dispatch(dispatcher);
}
nsresult PushNotifier::Dispatch(PushDispatcher& aDispatcher) { if (XRE_IsParentProcess()) { // Always notify XPCOM observers in the parent process.
Unused << NS_WARN_IF(NS_FAILED(aDispatcher.NotifyObservers()));
// e10s is disabled; notify workers in the parent. return aDispatcher.NotifyWorkers();
}
// Otherwise, we're in the content process, so e10s must be enabled. Notify // observers and workers, then send a message to notify observers in the // parent.
MOZ_ASSERT(XRE_IsContentProcess());
bool PushDispatcher::ShouldNotifyWorkers() { if (NS_WARN_IF(!mPrincipal)) { returnfalse;
}
// System subscriptions use observer notifications instead of service worker // events. The `testing.notifyWorkers` pref disables worker events for // non-system subscriptions. if (mPrincipal->IsSystemPrincipal() ||
!Preferences::GetBool("dom.push.testing.notifyWorkers", true)) { returnfalse;
}
// If e10s is off, no need to worry about processes. if (!BrowserTabsRemoteAutostart()) { returntrue;
}
// We only want to notify in the parent process. bool isContentProcess = XRE_GetProcessType() == GeckoProcessType_Content; return !isContentProcess;
}
nsresult PushDispatcher::DoNotifyObservers(nsISupports* aSubject, constchar* aTopic, const nsACString& aScope) {
nsCOMPtr<nsIObserverService> obsService =
mozilla::services::GetObserverService(); if (!obsService) { return NS_ERROR_FAILURE;
} // If there's a service for this push category, make sure it is alive.
nsCOMPtr<nsICategoryManager> catMan =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID); if (catMan) {
nsCString contractId;
nsresult rv = catMan->GetCategoryEntry("push", mScope, contractId); if (NS_SUCCEEDED(rv)) { // Ensure the service is created - we don't need to do anything with // it though - we assume the service constructor attaches a listener.
nsCOMPtr<nsISupports> service = do_GetService(contractId.get());
}
} return obsService->NotifyObservers(aSubject, aTopic,
NS_ConvertUTF8toUTF16(mScope).get());
}
nsresult PushErrorDispatcher::HandleNoChildProcesses() { // Report to the console if no content processes are active.
nsCOMPtr<nsIURI> scopeURI;
nsresult rv = NS_NewURI(getter_AddRefs(scopeURI), mScope); if (NS_WARN_IF(NS_FAILED(rv))) { return rv;
} return nsContentUtils::ReportToConsoleNonLocalized(
mMessage, mFlags, "Push"_ns, /* aDocument = */ nullptr,
SourceLocation(scopeURI.get()));
}
} // namespace mozilla::dom
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.13Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.