NS_IMETHODIMP nsAlertsService::CloseAlert(const nsAString& aAlertName, nsIPrincipal* aPrincipal) { if (XRE_GetProcessType() == GeckoProcessType_Content) { ContentChild* cpc = ContentChild::GetSingleton(); cpc->SendCloseAlert(nsAutoString(aAlertName), IPC::Principal(aPrincipal)); return NS_OK; } #ifdef MOZ_WIDGET_ANDROID mozilla::AndroidBridge::Bridge()->CloseNotification(aAlertName); return NS_OK; #else // Try the system notification service. nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_SYSTEMALERTSERVICE_CONTRACTID)); if (sysAlerts) { return sysAlerts->CloseAlert(aAlertName, nullptr); } return mXULAlerts.CloseAlert(aAlertName); #endif // !MOZ_WIDGET_ANDROID }
NS_IMETHODIMP PushNotifier::NotifySubscriptionLost(const nsACString& aScope, nsIPrincipal* aPrincipal, uint16_t aReason) { if (NS_WARN_IF(aReason < nsIPushErrorReporter::UNSUBSCRIBE_MANUAL || aReason > nsIPushErrorReporter::UNSUBSCRIBE_PERMISSION_REVOKED)) { return NS_ERROR_INVALID_ARG; } nsresult rv = NotifySubscriptionLostObservers(aScope, aReason); Unused << NS_WARN_IF(NS_FAILED(rv)); if (XRE_IsContentProcess()) { ContentChild* parentActor = ContentChild::GetSingleton(); if (!NS_WARN_IF(!parentActor)) { Unused << NS_WARN_IF( !parentActor->SendNotifyPushSubscriptionLostObservers( PromiseFlatCString(aScope), aReason)); } } return NS_OK; }
/*static*/ PCrashReporterChild* CrashReporterChild::GetCrashReporter() { const InfallibleTArray<PCrashReporterChild*>* reporters = nsnull; switch (XRE_GetProcessType()) { case GeckoProcessType_Content: { ContentChild* child = ContentChild::GetSingleton(); reporters = &child->ManagedPCrashReporterChild(); break; } case GeckoProcessType_Plugin: { PluginModuleChild* child = PluginModuleChild::current(); reporters = &child->ManagedPCrashReporterChild(); break; } default: break; } if (reporters && reporters->Length() > 0) { return reporters->ElementAt(0); } return nsnull; }
// static nsresult IDBFactory::Create(JSContext* aCx, JSObject* aOwningObject, ContentParent* aContentParent, IDBFactory** aFactory) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(aCx, "Null context!"); NS_ASSERTION(aOwningObject, "Null object!"); NS_ASSERTION(JS_GetGlobalForObject(aCx, aOwningObject) == aOwningObject, "Not a global object!"); NS_ASSERTION(nsContentUtils::IsCallerChrome(), "Only for chrome!"); nsCString origin; nsresult rv = IndexedDatabaseManager::GetASCIIOriginFromWindow(nullptr, origin); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); nsRefPtr<IDBFactory> factory = new IDBFactory(); factory->mASCIIOrigin = origin; factory->mOwningObject = aOwningObject; factory->mContentParent = aContentParent; if (!IndexedDatabaseManager::IsMainProcess()) { ContentChild* contentChild = ContentChild::GetSingleton(); NS_ENSURE_TRUE(contentChild, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); IndexedDBChild* actor = new IndexedDBChild(origin); contentChild->SendPIndexedDBConstructor(actor); actor->SetFactory(factory); } factory.forget(aFactory); return NS_OK; }
NS_IMETHODIMP nsOfflineCacheUpdateService::AllowOfflineApp(nsIPrincipal *aPrincipal) { nsresult rv; if (!sAllowOfflineCache) { return NS_ERROR_NOT_AVAILABLE; } if (GeckoProcessType_Default != XRE_GetProcessType()) { ContentChild* child = ContentChild::GetSingleton(); if (!child->SendSetOfflinePermission(IPC::Principal(aPrincipal))) { return NS_ERROR_FAILURE; } nsAutoCString domain; rv = aPrincipal->GetBaseDomain(domain); NS_ENSURE_SUCCESS(rv, rv); nsOfflineCacheUpdateService::AllowedDomains()->PutEntry(domain); } else { nsCOMPtr<nsIPermissionManager> permissionManager = services::GetPermissionManager(); if (!permissionManager) return NS_ERROR_NOT_AVAILABLE; rv = permissionManager->AddFromPrincipal( aPrincipal, "offline-app", nsIPermissionManager::ALLOW_ACTION, nsIPermissionManager::EXPIRE_NEVER, 0); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; }
void AudioChannelServiceChild::UnregisterAudioChannelAgent(AudioChannelAgent* aAgent) { AudioChannelAgentData *pData; if (!mAgents.Get(aAgent, &pData)) { return; } // We need to keep a copy because unregister will remove the // AudioChannelAgentData object from the hashtable. AudioChannelAgentData data(*pData); AudioChannelService::UnregisterAudioChannelAgent(aAgent); ContentChild *cc = ContentChild::GetSingleton(); if (cc) { cc->SendAudioChannelUnregisterType(data.mType, data.mElementHidden); } nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService(); if (obs) { obs->NotifyObservers(nullptr, "audio-channel-agent-changed", nullptr); } }
NS_IMETHODIMP nsAlertsService::ShowAlert(nsIAlertNotification * aAlert, nsIObserver * aAlertListener) { NS_ENSURE_ARG(aAlert); nsAutoString cookie; nsresult rv = aAlert->GetCookie(cookie); NS_ENSURE_SUCCESS(rv, rv); if (XRE_IsContentProcess()) { ContentChild* cpc = ContentChild::GetSingleton(); if (aAlertListener) cpc->AddRemoteAlertObserver(cookie, aAlertListener); cpc->SendShowAlert(aAlert); return NS_OK; } nsAutoString imageUrl; rv = aAlert->GetImageURL(imageUrl); NS_ENSURE_SUCCESS(rv, rv); nsAutoString title; rv = aAlert->GetTitle(title); NS_ENSURE_SUCCESS(rv, rv); nsAutoString text; rv = aAlert->GetText(text); NS_ENSURE_SUCCESS(rv, rv); nsAutoString name; rv = aAlert->GetName(name); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIPrincipal> principal; rv = aAlert->GetPrincipal(getter_AddRefs(principal)); NS_ENSURE_SUCCESS(rv, rv); #ifdef MOZ_WIDGET_ANDROID mozilla::AndroidBridge::Bridge()->ShowAlertNotification(imageUrl, title, text, cookie, aAlertListener, name, principal); return NS_OK; #else // Check if there is an optional service that handles system-level notifications nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_SYSTEMALERTSERVICE_CONTRACTID)); if (sysAlerts) { rv = sysAlerts->ShowAlert(aAlert, aAlertListener); if (NS_SUCCEEDED(rv)) return NS_OK; } if (!ShouldShowAlert()) { // Do not display the alert. Instead call alertfinished and get out. if (aAlertListener) aAlertListener->Observe(nullptr, "alertfinished", cookie.get()); return NS_OK; } bool textClickable; rv = aAlert->GetTextClickable(&textClickable); NS_ENSURE_SUCCESS(rv, rv); nsAutoString bidi; rv = aAlert->GetDir(bidi); NS_ENSURE_SUCCESS(rv, rv); nsAutoString lang; rv = aAlert->GetLang(lang); NS_ENSURE_SUCCESS(rv, rv); bool inPrivateBrowsing; rv = aAlert->GetInPrivateBrowsing(&inPrivateBrowsing); NS_ENSURE_SUCCESS(rv, rv); // Use XUL notifications as a fallback if above methods have failed. rv = mXULAlerts.ShowAlertNotification(imageUrl, title, text, textClickable, cookie, aAlertListener, name, bidi, lang, principal, inPrivateBrowsing); return rv; #endif // !MOZ_WIDGET_ANDROID }
NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl, const nsAString & aAlertTitle, const nsAString & aAlertText, PRBool aAlertTextClickable, const nsAString & aAlertCookie, nsIObserver * aAlertListener, const nsAString & aAlertName) { if (XRE_GetProcessType() == GeckoProcessType_Content) { ContentChild* cpc = ContentChild::GetSingleton(); if (aAlertListener) cpc->AddRemoteAlertObserver(PromiseFlatString(aAlertCookie), aAlertListener); cpc->SendShowAlertNotification(nsAutoString(aImageUrl), nsAutoString(aAlertTitle), nsAutoString(aAlertText), aAlertTextClickable, nsAutoString(aAlertCookie), nsAutoString(aAlertName)); return NS_OK; } #ifdef ANDROID mozilla::AndroidBridge::Bridge()->ShowAlertNotification(aImageUrl, aAlertTitle, aAlertText, aAlertCookie, aAlertListener, aAlertName); return NS_OK; #else // Check if there is an optional service that handles system-level notifications nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_SYSTEMALERTSERVICE_CONTRACTID)); nsresult rv; if (sysAlerts) { rv = sysAlerts->ShowAlertNotification(aImageUrl, aAlertTitle, aAlertText, aAlertTextClickable, aAlertCookie, aAlertListener, aAlertName); if (NS_SUCCEEDED(rv)) return rv; } nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); nsCOMPtr<nsIDOMWindow> newWindow; nsCOMPtr<nsISupportsArray> argsArray; rv = NS_NewISupportsArray(getter_AddRefs(argsArray)); NS_ENSURE_SUCCESS(rv, rv); // create scriptable versions of our strings that we can store in our nsISupportsArray.... nsCOMPtr<nsISupportsString> scriptableImageUrl (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); NS_ENSURE_TRUE(scriptableImageUrl, NS_ERROR_FAILURE); scriptableImageUrl->SetData(aImageUrl); rv = argsArray->AppendElement(scriptableImageUrl); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISupportsString> scriptableAlertTitle (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); NS_ENSURE_TRUE(scriptableAlertTitle, NS_ERROR_FAILURE); scriptableAlertTitle->SetData(aAlertTitle); rv = argsArray->AppendElement(scriptableAlertTitle); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISupportsString> scriptableAlertText (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); NS_ENSURE_TRUE(scriptableAlertText, NS_ERROR_FAILURE); scriptableAlertText->SetData(aAlertText); rv = argsArray->AppendElement(scriptableAlertText); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISupportsPRBool> scriptableIsClickable (do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID)); NS_ENSURE_TRUE(scriptableIsClickable, NS_ERROR_FAILURE); scriptableIsClickable->SetData(aAlertTextClickable); rv = argsArray->AppendElement(scriptableIsClickable); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISupportsString> scriptableAlertCookie (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); NS_ENSURE_TRUE(scriptableAlertCookie, NS_ERROR_FAILURE); scriptableAlertCookie->SetData(aAlertCookie); rv = argsArray->AppendElement(scriptableAlertCookie); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISupportsPRInt32> scriptableOrigin (do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID)); NS_ENSURE_TRUE(scriptableOrigin, NS_ERROR_FAILURE); nsCOMPtr<nsILookAndFeel> lookAndFeel = do_GetService("@mozilla.org/widget/lookandfeel;1"); if (lookAndFeel) { PRInt32 origin; lookAndFeel->GetMetric(nsILookAndFeel::eMetric_AlertNotificationOrigin, origin); scriptableOrigin->SetData(origin); } rv = argsArray->AppendElement(scriptableOrigin); NS_ENSURE_SUCCESS(rv, rv); if (aAlertListener) { nsCOMPtr<nsISupportsInterfacePointer> ifptr = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISupports> iSupports (do_QueryInterface(aAlertListener)); ifptr->SetData(iSupports); ifptr->SetDataIID(&NS_GET_IID(nsIObserver)); rv = argsArray->AppendElement(ifptr); NS_ENSURE_SUCCESS(rv, rv); } rv = wwatch->OpenWindow(0, ALERT_CHROME_URL, "_blank", "chrome,dialog=yes,titlebar=no,popup=yes", argsArray, getter_AddRefs(newWindow)); return rv; #endif // !ANDROID }
NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl, const nsAString & aAlertTitle, const nsAString & aAlertText, bool aAlertTextClickable, const nsAString & aAlertCookie, nsIObserver * aAlertListener, const nsAString & aAlertName, const nsAString & aBidi, const nsAString & aLang, const nsAString & aData, nsIPrincipal * aPrincipal, bool aInPrivateBrowsing) { if (XRE_IsContentProcess()) { ContentChild* cpc = ContentChild::GetSingleton(); if (aAlertListener) cpc->AddRemoteAlertObserver(PromiseFlatString(aAlertCookie), aAlertListener); cpc->SendShowAlertNotification(PromiseFlatString(aImageUrl), PromiseFlatString(aAlertTitle), PromiseFlatString(aAlertText), aAlertTextClickable, PromiseFlatString(aAlertCookie), PromiseFlatString(aAlertName), PromiseFlatString(aBidi), PromiseFlatString(aLang), PromiseFlatString(aData), IPC::Principal(aPrincipal), aInPrivateBrowsing); return NS_OK; } #ifdef MOZ_WIDGET_ANDROID mozilla::AndroidBridge::Bridge()->ShowAlertNotification(aImageUrl, aAlertTitle, aAlertText, aAlertCookie, aAlertListener, aAlertName); return NS_OK; #else // Check if there is an optional service that handles system-level notifications nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_SYSTEMALERTSERVICE_CONTRACTID)); nsresult rv; if (sysAlerts) { rv = sysAlerts->ShowAlertNotification(aImageUrl, aAlertTitle, aAlertText, aAlertTextClickable, aAlertCookie, aAlertListener, aAlertName, aBidi, aLang, aData, IPC::Principal(aPrincipal), aInPrivateBrowsing); if (NS_SUCCEEDED(rv)) return NS_OK; } if (!ShouldShowAlert()) { // Do not display the alert. Instead call alertfinished and get out. if (aAlertListener) aAlertListener->Observe(nullptr, "alertfinished", PromiseFlatString(aAlertCookie).get()); return NS_OK; } // Use XUL notifications as a fallback if above methods have failed. rv = mXULAlerts.ShowAlertNotification(aImageUrl, aAlertTitle, aAlertText, aAlertTextClickable, aAlertCookie, aAlertListener, aAlertName, aBidi, aLang, aPrincipal, aInPrivateBrowsing); return rv; #endif // !MOZ_WIDGET_ANDROID }