void TCPSocketParent::FireStringDataEvent(const nsACString& aData, TCPReadyState aReadyState) { SendableData data((nsCString(aData))); MOZ_ASSERT(!mFilter, "Socket filtering doesn't support nsCString"); SendEvent(NS_LITERAL_STRING("data"), data, aReadyState); }
nsresult Convert(const BluetoothRemoteName& aIn, nsAString& aOut) { // We construct an nsCString here because the string // returned from the PDU is not 0-terminated. aOut = NS_ConvertUTF8toUTF16( nsCString(reinterpret_cast<const char*>(aIn.mName), sizeof(aIn.mName))); return NS_OK; }
void GMPDecryptorChild::RejectPromise(uint32_t aPromiseId, GMPDOMException aException, const char* aMessage, uint32_t aMessageLength) { CALL_ON_GMP_THREAD(SendRejectPromise, aPromiseId, aException, nsCString(aMessage, aMessageLength)); }
const nsCString TranslateMimeType(const nsACString& aMimeType) { if (VPXDecoder::IsVPX(aMimeType, VPXDecoder::VP8)) { static NS_NAMED_LITERAL_CSTRING(vp8, "video/x-vnd.on2.vp8"); return vp8; } else if (VPXDecoder::IsVPX(aMimeType, VPXDecoder::VP9)) { static NS_NAMED_LITERAL_CSTRING(vp9, "video/x-vnd.on2.vp9"); return vp9; } return nsCString(aMimeType); }
bool FeatureState::InitOrUpdate(bool aEnable, FeatureStatus aDisableStatus, const char* aDisableMessage) { if (!IsInitialized()) { return SetDefault(aEnable, aDisableStatus, aDisableMessage); } return MaybeSetFailed(aEnable, aDisableStatus, aDisableMessage, nsCString()); }
nsresult DOMStorageDBParent::Observe(const char* aTopic, const nsACString& aScopePrefix) { if (mIPCOpen) { mozilla::unused << SendObserve(nsDependentCString(aTopic), nsCString(aScopePrefix)); } return NS_OK; }
/* static */ bool MediaKeySystemAccess::IsGMPPresentOnDisk(const nsAString& aKeySystem, const nsACString& aVersion, nsACString& aOutMessage) { MOZ_ASSERT(NS_IsMainThread()); if (XRE_GetProcessType() != GeckoProcessType_Default) { // We need to be able to access the filesystem, so call this in the // main process via ContentChild. ContentChild* contentChild = ContentChild::GetSingleton(); if (NS_WARN_IF(!contentChild)) { return false; } nsCString message; bool result = false; bool ok = contentChild->SendIsGMPPresentOnDisk(nsString(aKeySystem), nsCString(aVersion), &result, &message); aOutMessage = message; return ok && result; } bool isPresent = true; #if XP_WIN if (aKeySystem.EqualsLiteral("com.adobe.primetime")) { if (!AdobePluginDLLExists(aVersion)) { NS_WARNING("Adobe EME plugin disappeared from disk!"); aOutMessage = NS_LITERAL_CSTRING("Adobe DLL was expected to be on disk but was not"); isPresent = false; } if (!AdobePluginVoucherExists(aVersion)) { NS_WARNING("Adobe EME voucher disappeared from disk!"); aOutMessage = NS_LITERAL_CSTRING("Adobe plugin voucher was expected to be on disk but was not"); isPresent = false; } if (!isPresent) { // Reset the prefs that Firefox's GMP downloader sets, so that // Firefox will try to download the plugin next time the updater runs. Preferences::ClearUser("media.gmp-eme-adobe.lastUpdate"); Preferences::ClearUser("media.gmp-eme-adobe.version"); } else if (!EMEVoucherFileExists()) { // Gecko doesn't have a voucher file for the plugin-container. // Adobe EME isn't going to work, so don't advertise that it will. aOutMessage = NS_LITERAL_CSTRING("Plugin-container voucher not present"); isPresent = false; } } #endif return isPresent; }
nsCString GMPInfoFileParser::Get(const nsCString& aKey) const { MOZ_ASSERT(Contains(aKey)); nsCString key(aKey); ToLowerCase(key); nsCString* p = nullptr; if (mValues.Get(key, &p)) { return nsCString(*p); } return EmptyCString(); }
NS_IMETHODIMP nsMsgIdentity::SetCharAttribute(const char *aName, const nsACString& val) { if (!mPrefBranch) return NS_ERROR_NOT_INITIALIZED; if (!val.IsEmpty()) return mPrefBranch->SetCharPref(aName, nsCString(val).get()); mPrefBranch->ClearUserPref(aName); return NS_OK; }
NS_IMETHODIMP csTpConnectionManagerImp::Init(const nsACString& aName) { if (m_Proxy) return NS_ERROR_ALREADY_INITIALIZED; m_Proxy = tp_connection_manager_new(m_BusDaemon, nsCString(aName).get(), NULL, NULL); if (!m_Proxy) return NS_ERROR_FAILURE; return NS_OK; }
void AndroidMediaPluginHost::DestroyDecoder(Decoder *aDecoder) { aDecoder->DestroyDecoder(aDecoder); char* resource = GetResource(aDecoder); if (resource) { // resource *shouldn't* be null, but check anyway just in case the plugin // decoder does something stupid. mResourceServer->RemoveResource(nsCString(resource)); free(resource); } delete aDecoder; }
/* void setColorForKey (in ACString key, in ACString color); */ NS_IMETHODIMP nsMsgTagService::SetColorForKey(const nsACString & key, const nsACString & color) { nsCAutoString prefName(key); ToLowerCase(prefName); prefName.AppendLiteral(TAG_PREF_SUFFIX_COLOR); if (color.IsEmpty()) { m_tagPrefBranch->ClearUserPref(prefName.get()); return NS_OK; } return m_tagPrefBranch->SetCharPref(prefName.get(), nsCString(color).get()); }
/* void setOrdinalForKey (in ACString key, in ACString ordinal); */ NS_IMETHODIMP nsMsgTagService::SetOrdinalForKey(const nsACString & key, const nsACString & ordinal) { nsCAutoString prefName(key); ToLowerCase(prefName); prefName.AppendLiteral(TAG_PREF_SUFFIX_ORDINAL); if (ordinal.IsEmpty()) { m_tagPrefBranch->ClearUserPref(prefName.get()); return NS_OK; } return m_tagPrefBranch->SetCharPref(prefName.get(), nsCString(ordinal).get()); }
void SplitAt(const char* aDelims, const nsACString& aInput, nsTArray<nsCString>& aOutTokens) { nsAutoCString str(aInput); char* end = str.BeginWriting(); const char* start = nullptr; while (!!(start = NS_strtok(aDelims, &end))) { aOutTokens.AppendElement(nsCString(start)); } }
nsresult WebCL_parseOpenCLVersion (nsCString const& aVersionStr, int& aVersionMajorOut, int& aVersionMinorOut, nsCString& aVendorSpecificInfoOut) { D_METHOD_START; // Sanity check: make sure the OpenCL version string is something valid. // It must begin with "OpenCL " PRInt32 m1 = aVersionStr.FindChar (' '); if (!nsCString(aVersionStr.get(), m1).EqualsLiteral("OpenCL")) { D_LOG (LOG_LEVEL_WARNING, "Version string does not begin with \"OpenCL\"."); return NS_ERROR_FAILURE; } // Major version PRInt32 m2 = aVersionStr.FindChar('.', m1 + 1); nsresult rv; nsCOMPtr<nsIWritableVariant> variant = do_CreateInstance(NS_VARIANT_CONTRACTID, &rv); rv = variant->SetAsACString (nsCString(aVersionStr.get() + m1, m2-m1)); NS_ENSURE_SUCCESS (rv, rv); rv = variant->GetAsInt32 (&aVersionMajorOut); NS_ENSURE_SUCCESS (rv, rv); // Minor version m1 = m2+1; m2 = aVersionStr.FindChar(' ', m1); rv = variant->SetAsACString (nsCString(aVersionStr.get() + m1, m2-m1)); NS_ENSURE_SUCCESS (rv, rv); rv = variant->GetAsInt32 (&aVersionMinorOut); NS_ENSURE_SUCCESS (rv, rv); // Vendor specific information aVendorSpecificInfoOut = nsCString (aVersionStr.get() + m2 + 1); return NS_OK; }
// A general purpose helper function to check permission against the origin // rather than mozIApplication. static bool CheckOriginPermission(const nsACString& aOrigin, const char* aPermission) { LOG("CheckOriginPermission: %s, %s\n", nsCString(aOrigin).get(), aPermission); nsIScriptSecurityManager *securityManager = nsContentUtils::GetSecurityManager(); nsCOMPtr<nsIPrincipal> principal; securityManager->CreateCodebasePrincipalFromOrigin(aOrigin, getter_AddRefs(principal)); nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager(); NS_ENSURE_TRUE(permMgr, false); uint32_t perm; nsresult rv = permMgr->TestExactPermissionFromPrincipal(principal, aPermission, &perm); NS_ENSURE_SUCCESS(rv, false); LOG("Permission %s for %s: %d\n", aPermission, nsCString(aOrigin).get(), perm); return nsIPermissionManager::ALLOW_ACTION == perm; }
void GMPDecryptorChild::KeyStatusChanged(const char* aSessionId, uint32_t aSessionIdLength, const uint8_t* aKeyId, uint32_t aKeyIdLength, GMPMediaKeyStatus aStatus) { AutoTArray<uint8_t, 16> kid; kid.AppendElements(aKeyId, aKeyIdLength); CALL_ON_GMP_THREAD(SendKeyStatusChanged, nsCString(aSessionId, aSessionIdLength), kid, aStatus); }
void GMPDecryptorChild::SessionMessage(const char* aSessionId, uint32_t aSessionIdLength, GMPSessionMessageType aMessageType, const uint8_t* aMessage, uint32_t aMessageLength) { nsTArray<uint8_t> msg; msg.AppendElements(aMessage, aMessageLength); CALL_ON_GMP_THREAD(SendSessionMessage, nsCString(aSessionId, aSessionIdLength), aMessageType, Move(msg)); }
/* static */ const Maybe<nsCString> GMPDecoderModule::PreferredGMP(const nsACString& aMimeType) { Maybe<nsCString> rv; if (aMimeType.EqualsLiteral("audio/mp4a-latm")) { switch (MediaPrefs::GMPAACPreferred()) { case 1: rv.emplace(nsCString(kEMEKeySystemClearkey)); break; case 2: rv.emplace(nsCString(kEMEKeySystemPrimetime)); break; default: break; } } if (MP4Decoder::IsH264(aMimeType)) { switch (MediaPrefs::GMPH264Preferred()) { case 1: rv.emplace(nsCString(kEMEKeySystemClearkey)); break; case 2: rv.emplace(nsCString(kEMEKeySystemPrimetime)); break; default: break; } } return rv; }
NS_IMETHODIMP Dashboard::RemoveHost(const nsACString& aHost, uint32_t aSerial) { if (mEnableLogging) { mozilla::MutexAutoLock lock(mWs.lock); int32_t index = mWs.IndexOf(nsCString(aHost), aSerial); if (index == -1) return NS_ERROR_FAILURE; mWs.data.RemoveElementAt(index); return NS_OK; } return NS_ERROR_FAILURE; }
NS_IMETHODIMP PresentationParent::NotifyMessage(const nsAString& aSessionId, const nsACString& aData, bool aIsBinary) { if (NS_WARN_IF(mActorDestroyed || !SendNotifyMessage(nsString(aSessionId), nsCString(aData), aIsBinary))) { return NS_ERROR_FAILURE; } return NS_OK; }
nsresult nsDragServiceProxy::InvokeDragSessionImpl(nsISupportsArray* aArrayTransferables, nsIScriptableRegion* aRegion, uint32_t aActionType) { nsCOMPtr<nsIDocument> doc = do_QueryInterface(mSourceDocument); NS_ENSURE_STATE(doc->GetDocShell()); mozilla::dom::TabChild* child = mozilla::dom::TabChild::GetFrom(doc->GetDocShell()); NS_ENSURE_STATE(child); nsTArray<mozilla::dom::IPCDataTransfer> dataTransfers; nsContentUtils::TransferablesToIPCTransferables(aArrayTransferables, dataTransfers, false, child->Manager(), nullptr); if (mHasImage || mSelection) { nsIntRect dragRect; nsPresContext* pc; RefPtr<mozilla::gfx::SourceSurface> surface; DrawDrag(mSourceNode, aRegion, mScreenX, mScreenY, &dragRect, &surface, &pc); if (surface) { RefPtr<mozilla::gfx::DataSourceSurface> dataSurface = surface->GetDataSurface(); mozilla::gfx::IntSize size = dataSurface->GetSize(); size_t length; int32_t stride; mozilla::UniquePtr<char[]> surfaceData = nsContentUtils::GetSurfaceData(dataSurface, &length, &stride); nsDependentCString dragImage(surfaceData.get(), length); mozilla::unused << child->SendInvokeDragSession(dataTransfers, aActionType, dragImage, size.width, size.height, stride, static_cast<uint8_t>(dataSurface->GetFormat()), dragRect.x, dragRect.y); StartDragSession(); return NS_OK; } } mozilla::unused << child->SendInvokeDragSession(dataTransfers, aActionType, nsCString(), 0, 0, 0, 0, 0, 0); StartDragSession(); return NS_OK; }
nsresult UDPSocketParent::BindInternal(const nsCString& aHost, const uint16_t& aPort, const bool& aAddressReuse, const bool& aLoopback) { nsresult rv; UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, nsCString(aHost).get(), aPort)); nsCOMPtr<nsIUDPSocket> sock = do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } if (aHost.IsEmpty()) { rv = sock->Init(aPort, false, mPrincipal, aAddressReuse, /* optional_argc = */ 1); } else { PRNetAddr prAddr; PR_InitializeNetAddr(PR_IpAddrAny, aPort, &prAddr); PRStatus status = PR_StringToNetAddr(aHost.BeginReading(), &prAddr); if (status != PR_SUCCESS) { return NS_ERROR_FAILURE; } mozilla::net::NetAddr addr; PRNetAddrToNetAddr(&prAddr, &addr); rv = sock->InitWithAddress(&addr, mPrincipal, aAddressReuse, /* optional_argc = */ 1); } if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } rv = sock->SetMulticastLoopback(aLoopback); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } // register listener rv = sock->AsyncListen(this); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } mSocket = sock; return NS_OK; }
void SubstitutingProtocolHandler::CollectSubstitutions(InfallibleTArray<SubstitutionMapping>& aMappings) { for (auto iter = mSubstitutions.ConstIter(); !iter.Done(); iter.Next()) { nsCOMPtr<nsIURI> uri = iter.Data(); SerializedURI serialized; if (uri) { uri->GetSpec(serialized.spec); uri->GetOriginCharset(serialized.charset); } SubstitutionMapping substitution = { mScheme, nsCString(iter.Key()), serialized }; aMappings.AppendElement(substitution); } }
NS_IMETHODIMP Dashboard::NewMsgReceived(const nsACString& aHost, uint32_t aSerial, uint32_t aLength) { if (mEnableLogging) { mozilla::MutexAutoLock lock(mWs.lock); int32_t index = mWs.IndexOf(nsCString(aHost), aSerial); if (index == -1) return NS_ERROR_FAILURE; mWs.data[index].mMsgReceived++; mWs.data[index].mSizeReceived += aLength; return NS_OK; } return NS_ERROR_FAILURE; }
bool OggCodecState::AddVorbisComment(MetadataTags* aTags, const char* aComment, uint32_t aLength) { const char* div = (const char*)memchr(aComment, '=', aLength); if (!div) { LOG(PR_LOG_DEBUG, ("Skipping comment: no separator")); return false; } nsCString key = nsCString(aComment, div-aComment); if (!IsValidVorbisTagName(key)) { LOG(PR_LOG_DEBUG, ("Skipping comment: invalid tag name")); return false; } uint32_t valueLength = aLength - (div-aComment); nsCString value = nsCString(div + 1, valueLength); if (!IsUTF8(value)) { LOG(PR_LOG_DEBUG, ("Skipping comment: invalid UTF-8 in value")); return false; } aTags->Put(key, value); return true; }
nsresult PinCodeToString(const BluetoothPinCode& aPinCode, nsAString& aString) { if (aPinCode.mLength > sizeof(aPinCode.mPinCode)) { BT_LOGR("Pin-code string too long"); return NS_ERROR_ILLEGAL_VALUE; } aString = NS_ConvertUTF8toUTF16( nsCString(reinterpret_cast<const char*>(aPinCode.mPinCode), aPinCode.mLength)); return NS_OK; }
NS_IMETHODIMP Dashboard::AddHost(const nsACString& aHost, uint32_t aSerial, bool aEncrypted) { if (mEnableLogging) { mozilla::MutexAutoLock lock(mWs.lock); LogData data(nsCString(aHost), aSerial, aEncrypted); if (mWs.data.Contains(data)) return NS_OK; if (!mWs.data.AppendElement(data)) return NS_ERROR_OUT_OF_MEMORY; return NS_OK; } return NS_ERROR_FAILURE; }
nsresult nsEudoraFilters::CreateNewFilter(const char* pName) { nsresult rv; rv = m_pFilterArray->Clear(); NS_ENSURE_SUCCESS(rv, rv); nsAutoString unicodeName; NS_CopyNativeToUnicode(nsCString(pName), unicodeName); uint32_t numServers; rv = m_pServerArray->GetLength(&numServers); NS_ENSURE_SUCCESS(rv, rv); for (uint32_t serverIndex = 0; serverIndex < numServers; serverIndex++) { nsCOMPtr<nsIMsgIncomingServer> server = do_QueryElementAt(m_pServerArray, serverIndex, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr <nsIMsgFilterList> filterList; rv = server->GetFilterList(nullptr, getter_AddRefs(filterList)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIMsgFilter> newFilter; rv = filterList->CreateFilter(unicodeName, getter_AddRefs(newFilter)); NS_ENSURE_SUCCESS(rv, rv); rv = newFilter->SetEnabled(false); NS_ENSURE_SUCCESS(rv, rv); uint32_t count; rv = filterList->GetFilterCount(&count); NS_ENSURE_SUCCESS(rv, rv); rv = filterList->InsertFilterAt(count, newFilter); NS_ENSURE_SUCCESS(rv, rv); m_pFilterArray->AppendElement(newFilter, false); } m_isAnd = false; m_isUnless = false; m_ignoreTerm = false; m_isIncoming = false; m_addedAction = false; m_hasTransfer = false; m_hasStop = false; m_termNotGroked = false; return NS_OK; }
void ResolveReplyRunnable::Reply(DNSServiceRef aSdRef, DNSServiceFlags aFlags, uint32_t aInterfaceIndex, DNSServiceErrorType aErrorCode, const char* aFullName, const char* aHostTarget, uint16_t aPort, uint16_t aTxtLen, const unsigned char* aTxtRecord, void* aContext) { MOZ_ASSERT(OnSocketThread(), "not on socket thread"); ResolveOperator* obj(reinterpret_cast<ResolveOperator*>(aContext)); if (!obj) { return; } nsCOMPtr<nsIThread> thread(obj->GetThread()); if (!thread) { return; } thread->Dispatch(new ResolveReplyRunnable(aSdRef, aFlags, aInterfaceIndex, aErrorCode, nsCString(aFullName), nsCString(aHostTarget), NativeEndian::swapFromNetworkOrder(aPort), aTxtLen, aTxtRecord, obj), NS_DISPATCH_NORMAL); }