JSBool JavaObject::getPropertyWrapper(JSContext* ctx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) { jsval rval; JSBool result = JavaObject::getProperty(ctx, obj.get(), id.get(), &rval); vp.set(rval); return result; }
// static nsresult IDBKeyRange::FromJSVal(JSContext* aCx, JS::Handle<JS::Value> aVal, IDBKeyRange** aKeyRange) { nsRefPtr<IDBKeyRange> keyRange; if (aVal.isNullOrUndefined()) { // undefined and null returns no IDBKeyRange. keyRange.forget(aKeyRange); return NS_OK; } JS::Rooted<JSObject*> obj(aCx, aVal.isObject() ? &aVal.toObject() : nullptr); if (aVal.isPrimitive() || JS_IsArrayObject(aCx, obj) || JS_ObjectIsDate(aCx, obj)) { // A valid key returns an 'only' IDBKeyRange. keyRange = new IDBKeyRange(nullptr, false, false, true); nsresult rv = GetKeyFromJSVal(aCx, aVal, keyRange->Lower()); if (NS_FAILED(rv)) { return rv; } } else { MOZ_ASSERT(aVal.isObject()); // An object is not permitted unless it's another IDBKeyRange. if (NS_FAILED(UNWRAP_OBJECT(IDBKeyRange, obj, keyRange))) { return NS_ERROR_DOM_INDEXEDDB_DATA_ERR; } } keyRange.forget(aKeyRange); return NS_OK; }
NS_IMETHODIMP nsBinaryInputStream::ReadArrayBuffer(uint32_t aLength, JS::Handle<JS::Value> aBuffer, JSContext* cx) { if (!aBuffer.isObject()) { return NS_ERROR_FAILURE; } JS::RootedObject buffer(cx, &aBuffer.toObject()); if (!JS_IsArrayBufferObject(buffer) || JS_GetArrayBufferByteLength(buffer) < aLength) { return NS_ERROR_FAILURE; } uint8_t* data = JS_GetStableArrayBufferData(cx, buffer); if (!data) { return NS_ERROR_FAILURE; } uint32_t bytesRead; nsresult rv = Read(reinterpret_cast<char*>(data), aLength, &bytesRead); if (NS_WARN_IF(NS_FAILED(rv))) return rv; if (bytesRead != aLength) { return NS_ERROR_FAILURE; } return NS_OK; }
NS_IMETHODIMP GonkGPSGeolocationProvider::Handle(const nsAString& aName, JS::Handle<JS::Value> aResult) { #ifdef MOZ_B2G_RIL if (aName.EqualsLiteral("ril.supl.apn")) { // When we get the APN, we attempt to call data_call_open of AGPS. if (aResult.isString()) { JSContext *cx = nsContentUtils::GetCurrentJSContext(); NS_ENSURE_TRUE(cx, NS_OK); // NB: No need to enter a compartment to read the contents of a string. nsAutoJSString apn; if (!apn.init(cx, aResult.toString())) { return NS_ERROR_FAILURE; } if (!apn.IsEmpty()) { SetAGpsDataConn(apn); } } } else #endif // MOZ_B2G_RIL if (aName.EqualsLiteral(SETTING_DEBUG_ENABLED)) { gGPSDebugging = aResult.isBoolean() ? aResult.toBoolean() : false; return NS_OK; } return NS_OK; }
// PromiseNativeHandler void PresentationResponderInfo::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) { MOZ_ASSERT(NS_IsMainThread()); if (NS_WARN_IF(!aValue.isObject())) { ReplyError(NS_ERROR_NOT_AVAILABLE); return; } JS::Rooted<JSObject*> obj(aCx, &aValue.toObject()); if (NS_WARN_IF(!obj)) { ReplyError(NS_ERROR_NOT_AVAILABLE); return; } // Start to listen to document state change event |STATE_TRANSFERRING|. HTMLIFrameElement* frame = nullptr; nsresult rv = UNWRAP_OBJECT(HTMLIFrameElement, obj, frame); if (NS_WARN_IF(!frame)) { ReplyError(NS_ERROR_NOT_AVAILABLE); return; } nsCOMPtr<nsIFrameLoaderOwner> owner = do_QueryInterface((nsIFrameLoaderOwner*) frame); if (NS_WARN_IF(!owner)) { ReplyError(NS_ERROR_NOT_AVAILABLE); return; } nsCOMPtr<nsIFrameLoader> frameLoader; rv = owner->GetFrameLoader(getter_AddRefs(frameLoader)); if (NS_WARN_IF(NS_FAILED(rv))) { ReplyError(rv); return; } nsRefPtr<TabParent> tabParent = TabParent::GetFrom(frameLoader); if (tabParent) { // OOP frame nsCOMPtr<nsIContentParent> cp = tabParent->Manager(); NS_WARN_IF(!static_cast<ContentParent*>(cp.get())->SendNotifyPresentationReceiverLaunched(tabParent, mSessionId)); } else { // In-process frame nsCOMPtr<nsIDocShell> docShell; rv = frameLoader->GetDocShell(getter_AddRefs(docShell)); if (NS_WARN_IF(NS_FAILED(rv))) { ReplyError(rv); return; } mLoadingCallback = new PresentationResponderLoadingCallback(mSessionId); rv = mLoadingCallback->Init(docShell); if (NS_WARN_IF(NS_FAILED(rv))) { ReplyError(rv); return; } } }
NS_IMETHODIMP ArrayBufferInputStream::SetData(JS::Handle<JS::Value> aBuffer, uint32_t aByteOffset, uint32_t aLength, JSContext* aCx) { if (!aBuffer.isObject()) { return NS_ERROR_FAILURE; } JS::RootedObject arrayBuffer(aCx, &aBuffer.toObject()); if (!JS_IsArrayBufferObject(arrayBuffer)) { return NS_ERROR_FAILURE; } mArrayBuffer.construct(aCx, aBuffer); uint32_t buflen = JS_GetArrayBufferByteLength(arrayBuffer); mOffset = std::min(buflen, aByteOffset); mBufferLength = std::min(buflen - mOffset, aLength); mBuffer = JS_GetStableArrayBufferData(aCx, arrayBuffer); if (!mBuffer) { return NS_ERROR_FAILURE; } return NS_OK; }
bool FieldSetterImpl(JSContext *cx, JS::CallArgs args) { JS::Handle<JS::Value> thisv = args.thisv(); MOZ_ASSERT(ValueHasISupportsPrivate(thisv)); JS::Rooted<JSObject*> thisObj(cx, &thisv.toObject()); // We should be in the compartment of |this|. If we got here via nativeCall, // |this| is not same-compartment with |callee|, and it's possible via // asymmetric security semantics that |args.calleev()| is actually a security // wrapper. In this case, we know we want to do an unsafe unwrap, and // InstallXBLField knows how to handle cross-compartment pointers. bool installed = false; JS::Rooted<JSObject*> callee(cx, js::UncheckedUnwrap(&args.calleev().toObject())); JS::Rooted<jsid> id(cx); if (!InstallXBLField(cx, callee, thisObj, &id, &installed)) { return false; } if (installed) { if (!::JS_SetPropertyById(cx, thisObj, id, args.get(0))) { return false; } } args.rval().setUndefined(); return true; }
NS_IMETHODIMP TCPSocketParent::InitJS(JS::Handle<JS::Value> aIntermediary, JSContext* aCx) { MOZ_ASSERT(aIntermediary.isObject()); mIntermediaryObj = &aIntermediary.toObject(); return NS_OK; }
NS_IMETHOD Handle(const nsAString& aName, JS::Handle<JS::Value> aResult) { RefPtr<AudioManager> audioManager = AudioManager::GetInstance(); MOZ_ASSERT(audioManager); for (uint32_t idx = 0; idx < MOZ_ARRAY_LENGTH(gVolumeData); ++idx) { NS_ConvertASCIItoUTF16 volumeType(gVolumeData[idx].mChannelName); if (StringBeginsWith(aName, volumeType)) { uint32_t device = GetDeviceFromSettingName(aName); MOZ_ASSERT(device != AUDIO_DEVICE_NONE); if (aResult.isInt32()) { int32_t stream = gVolumeData[idx].mStreamType; uint32_t volIndex = aResult.toInt32(); nsresult rv = audioManager->ValidateVolumeIndex(stream, volIndex); if (NS_WARN_IF(NS_FAILED(rv))) { mPromiseHolder.Reject("Error : invalid volume index.", __func__); return rv; } audioManager->SetStreamVolumeForDevice(stream, volIndex, device); } if (++mInitCounter == MOZ_ARRAY_LENGTH(kAudioDeviceInfos) * MOZ_ARRAY_LENGTH(gVolumeData)) { mPromiseHolder.Resolve(true, __func__); } return NS_OK; } } mPromiseHolder.Reject("Error : unexpected audio init event.", __func__); return NS_OK; }
NS_IMETHODIMP nsBinaryInputStream::ReadArrayBuffer(uint32_t aLength, JS::Handle<JS::Value> aBuffer, JSContext* aCx, uint32_t* aReadLength) { if (!aBuffer.isObject()) { return NS_ERROR_FAILURE; } JS::RootedObject buffer(aCx, &aBuffer.toObject()); if (!JS_IsArrayBufferObject(buffer)) { return NS_ERROR_FAILURE; } uint32_t bufferLength = JS_GetArrayBufferByteLength(buffer); if (bufferLength < aLength) { return NS_ERROR_FAILURE; } uint32_t bufSize = std::min<uint32_t>(aLength, 4096); UniquePtr<char[]> buf = MakeUnique<char[]>(bufSize); uint32_t pos = 0; *aReadLength = 0; do { // Read data into temporary buffer. uint32_t bytesRead; uint32_t amount = std::min(aLength - pos, bufSize); nsresult rv = Read(buf.get(), amount, &bytesRead); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } MOZ_ASSERT(bytesRead <= amount); if (bytesRead == 0) { break; } // Copy data into actual buffer. JS::AutoCheckCannotGC nogc; bool isShared; if (bufferLength != JS_GetArrayBufferByteLength(buffer)) { return NS_ERROR_FAILURE; } char* data = reinterpret_cast<char*>(JS_GetArrayBufferData(buffer, &isShared, nogc)); MOZ_ASSERT(!isShared); // Implied by JS_GetArrayBufferData() if (!data) { return NS_ERROR_FAILURE; } *aReadLength += bytesRead; PodCopy(data + pos, buf.get(), bytesRead); pos += bytesRead; } while (pos < aLength); return NS_OK; }
NS_IMETHODIMP nsSpeechTask::SendAudio(JS::Handle<JS::Value> aData, JS::Handle<JS::Value> aLandmarks, JSContext* aCx) { MOZ_ASSERT(XRE_IsParentProcess()); if(NS_WARN_IF(!(mStream))) { return NS_ERROR_NOT_AVAILABLE; } if(NS_WARN_IF(mStream->IsDestroyed())) { return NS_ERROR_NOT_AVAILABLE; } if(NS_WARN_IF(!(mChannels))) { return NS_ERROR_FAILURE; } if(NS_WARN_IF(!(aData.isObject()))) { return NS_ERROR_INVALID_ARG; } if (mIndirectAudio) { NS_WARNING("Can't call SendAudio from an indirect audio speech service."); return NS_ERROR_FAILURE; } JS::Rooted<JSObject*> darray(aCx, &aData.toObject()); JSAutoCompartment ac(aCx, darray); JS::Rooted<JSObject*> tsrc(aCx, nullptr); // Allow either Int16Array or plain JS Array if (JS_IsInt16Array(darray)) { tsrc = darray; } else { bool isArray; if (!JS_IsArrayObject(aCx, darray, &isArray)) { return NS_ERROR_UNEXPECTED; } if (isArray) { tsrc = JS_NewInt16ArrayFromArray(aCx, darray); } } if (!tsrc) { return NS_ERROR_DOM_TYPE_MISMATCH_ERR; } uint32_t dataLen = JS_GetTypedArrayLength(tsrc); RefPtr<mozilla::SharedBuffer> samples; { JS::AutoCheckCannotGC nogc; samples = makeSamples(JS_GetInt16ArrayData(tsrc, nogc), dataLen); } SendAudioImpl(samples, dataLen); return NS_OK; }
static already_AddRefed<EventListener> ToEventListener(JSContext* aCx, JS::Handle<JS::Value> aValue) { if (NS_WARN_IF(!aValue.isObject())) { return nullptr; } JS::Rooted<JSObject*> obj(aCx, &aValue.toObject()); RefPtr<EventListener> listener = new EventListener(aCx, obj, GetIncumbentGlobal()); return listener.forget(); }
NS_IMETHODIMP GonkGPSGeolocationProvider::Handle(const nsAString& aName, JS::Handle<JS::Value> aResult) { #ifdef MOZ_B2G_RIL if (aName.EqualsLiteral("ril.supl.apn")) { // When we get the APN, we attempt to call data_call_open of AGPS. if (aResult.isString()) { JSContext *cx = nsContentUtils::GetCurrentJSContext(); NS_ENSURE_TRUE(cx, NS_OK); // NB: No need to enter a compartment to read the contents of a string. nsAutoJSString apn; if (!apn.init(cx, aResult.toString())) { return NS_ERROR_FAILURE; } if (!apn.IsEmpty()) { SetAGpsDataConn(apn); } } } else if (aName.EqualsASCII(kSettingRilDefaultServiceId)) { uint32_t id = 0; JSContext *cx = nsContentUtils::GetCurrentJSContext(); NS_ENSURE_TRUE(cx, NS_OK); if (!JS::ToUint32(cx, aResult, &id)) { return NS_ERROR_FAILURE; } if (!IsValidRilServiceId(id)) { return NS_ERROR_UNEXPECTED; } mRilDataServiceId = id; UpdateRadioInterface(); MOZ_ASSERT(!mObservingNetworkConnStateChange); // Now we know which service ID to deal with, observe necessary topic then nsCOMPtr<nsIObserverService> obs = services::GetObserverService(); NS_ENSURE_TRUE(obs, NS_OK); if (NS_FAILED(obs->AddObserver(this, kNetworkConnStateChangedTopic, false))) { NS_WARNING("Failed to add network state changed observer!"); } else { mObservingNetworkConnStateChange = true; } } #endif // MOZ_B2G_RIL return NS_OK; }
NS_IMETHODIMP SmsFilter::SetRead(JSContext* aCx, JS::Handle<JS::Value> aRead) { if (aRead.isNull()) { mData.read() = eReadState_Unknown; return NS_OK; } if (!aRead.isBoolean()) { return NS_ERROR_INVALID_ARG; } mData.read() = aRead.toBoolean() ? eReadState_Read : eReadState_Unread; return NS_OK; }
NS_IMETHODIMP WebVTTListener::OnRegion(JS::Handle<JS::Value> aRegion, JSContext* aCx) { if (!aRegion.isObject()) { return NS_ERROR_FAILURE; } TextTrackRegion* region; nsresult rv = UNWRAP_OBJECT(VTTRegion, &aRegion.toObject(), region); NS_ENSURE_SUCCESS(rv, rv); mElement->mTrack->AddRegion(*region); return NS_OK; }
js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg, JS::Handle<js::PropertyDescriptor> descriptor, bool *bp) { RootedObject obj(cx, objArg); RootedId id(cx, idArg); js::AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, obj, id, descriptor.value()); if (descriptor.hasGetterObject()) assertSameCompartment(cx, descriptor.getterObject()); if (descriptor.hasSetterObject()) assertSameCompartment(cx, descriptor.setterObject()); return DefineOwnProperty(cx, HandleObject(obj), id, descriptor, bp); }
already_AddRefed<Promise> JSWindowActor::SendQuery( JSContext* aCx, const nsAString& aMessageName, JS::Handle<JS::Value> aObj, JS::Handle<JS::Value> aTransfers, ErrorResult& aRv) { ipc::StructuredCloneData data; if (!aObj.isUndefined() && !nsFrameMessageManager::GetParamsForMessage( aCx, aObj, aTransfers, data)) { aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR); return nullptr; } nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx); if (NS_WARN_IF(!global)) { aRv.Throw(NS_ERROR_UNEXPECTED); return nullptr; } RefPtr<Promise> promise = Promise::Create(global, aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } JSWindowActorMessageMeta meta; meta.actorName() = mName; meta.messageName() = aMessageName; meta.queryId() = mNextQueryId++; meta.kind() = JSWindowActorMessageKind::Query; mPendingQueries.Put(meta.queryId(), promise); SendRawMessage(meta, std::move(data), aRv); return promise.forget(); }
NS_IMETHODIMP MobileConnectionRequestParent::NotifyGetCallForwardingSuccess(JS::Handle<JS::Value> aResults) { uint32_t length; AutoSafeJSContext cx; JS::Rooted<JSObject*> object(cx, &aResults.toObject()); nsTArray<IPC::MozCallForwardingOptions> results; if (!JS_IsArrayObject(cx, object) || !JS_GetArrayLength(cx, object, &length)) { return NS_ERROR_TYPE_ERR; } for (uint32_t i = 0; i < length; i++) { JS::Rooted<JS::Value> entry(cx); IPC::MozCallForwardingOptions info; if (!JS_GetElement(cx, object, i, &entry) || !info.Init(cx, entry)) { return NS_ERROR_TYPE_ERR; } results.AppendElement(info); } return SendReply(MobileConnectionReplySuccessCallForwarding(results)); }
NS_IMETHODIMP WebVTTListener::OnCue(JS::Handle<JS::Value> aCue, JSContext* aCx) { if (!aCue.isObject()) { return NS_ERROR_FAILURE; } TextTrackCue* cue = nullptr; nsresult rv = UNWRAP_OBJECT(VTTCue, &aCue.toObject(), cue); NS_ENSURE_SUCCESS(rv, rv); cue->SetTrackElement(mElement); mElement->mTrack->AddCue(*cue); return NS_OK; }
js::GetObjectProto(JSContext *cx, JS::Handle<JSObject*> obj, JS::MutableHandle<JSObject*> proto) { if (IsProxy(obj)) return JS_GetPrototype(cx, obj, proto); proto.set(reinterpret_cast<const shadow::Object*>(obj.get())->type->proto); return true; }
bool ValueHasISupportsPrivate(JS::Handle<JS::Value> v) { if (!v.isObject()) { return false; } const DOMJSClass* domClass = GetDOMClass(&v.toObject()); if (domClass) { return domClass->mDOMObjectIsISupports; } const JSClass* clasp = ::JS_GetClass(&v.toObject()); const uint32_t HAS_PRIVATE_NSISUPPORTS = JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS; return (clasp->flags & HAS_PRIVATE_NSISUPPORTS) == HAS_PRIVATE_NSISUPPORTS; }
void GetEntryHelper::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) { if(NS_WARN_IF(!aValue.isObject())) { return; } JS::Rooted<JSObject*> obj(aCx, &aValue.toObject()); // This is not the last part of the path. if (!mParts.IsEmpty()) { ContinueRunning(obj); return; } CompleteOperation(obj); }
void nsDOMCameraControl::StartRecording(JSContext* aCx, JS::Handle<JS::Value> aOptions, nsDOMDeviceStorage& storageArea, const nsAString& filename, nsICameraStartRecordingCallback* onSuccess, const Optional<nsICameraErrorCallback*>& onError, ErrorResult& aRv) { MOZ_ASSERT(onSuccess, "no onSuccess handler passed"); mozilla::idl::CameraStartRecordingOptions options; // Default values, until the dictionary parser can handle them. options.rotation = 0; options.maxFileSizeBytes = 0; options.maxVideoLengthMs = 0; aRv = options.Init(aCx, aOptions.address()); if (aRv.Failed()) { return; } nsCOMPtr<nsIObserverService> obs = services::GetObserverService(); if (!obs) { NS_WARNING("Could not get the Observer service for CameraControl::StartRecording."); aRv.Throw(NS_ERROR_FAILURE); return; } obs->NotifyObservers(nullptr, "recording-device-events", NS_LITERAL_STRING("starting").get()); // Forward recording events to parent process. // The events are gathered in chrome process and used for recording indicator if (XRE_GetProcessType() != GeckoProcessType_Default) { unused << ContentChild::GetSingleton()->SendRecordingDeviceEvents(NS_LITERAL_STRING("starting")); } #ifdef MOZ_B2G if (!mAudioChannelAgent) { mAudioChannelAgent = do_CreateInstance("@mozilla.org/audiochannelagent;1"); if (mAudioChannelAgent) { // Camera app will stop recording when it falls to the background, so no callback is necessary. mAudioChannelAgent->Init(AUDIO_CHANNEL_CONTENT, nullptr); // Video recording doesn't output any sound, so it's not necessary to check canPlay. bool canPlay; mAudioChannelAgent->StartPlaying(&canPlay); } } #endif nsCOMPtr<nsIFile> folder; aRv = storageArea.GetRootDirectoryForFile(filename, getter_AddRefs(folder)); if (aRv.Failed()) { return; } aRv = mCameraControl->StartRecording(&options, folder, filename, onSuccess, onError.WasPassed() ? onError.Value() : nullptr); }
bool JSCompartment::addToVarNames(JSContext* cx, JS::Handle<JSAtom*> name) { if (varNames_.put(name.get())) return true; ReportOutOfMemory(cx); return false; }
NS_DECL_ISUPPORTS NS_IMETHOD Handle(const nsAString& aName, JS::Handle<JS::Value> aResult) { MOZ_ASSERT(NS_IsMainThread()); if (!aResult.isBoolean()) { BT_WARNING("Setting for '" BLUETOOTH_ENABLED_SETTING "' is not a boolean!"); return NS_OK; } // It is theoretically possible to shut down before the first settings check // has completed (though extremely unlikely). if (sBluetoothService) { return sBluetoothService->HandleStartupSettingsCheck(aResult.toBoolean()); } return NS_OK; }
/* static */ void ThreadSafeChromeUtils::NondeterministicGetWeakSetKeys(GlobalObject& aGlobal, JS::Handle<JS::Value> aSet, JS::MutableHandle<JS::Value> aRetval, ErrorResult& aRv) { if (!aSet.isObject()) { aRetval.setUndefined(); } else { JSContext* cx = aGlobal.Context(); JS::Rooted<JSObject*> objRet(cx); JS::Rooted<JSObject*> setObj(cx, &aSet.toObject()); if (!JS_NondeterministicGetWeakSetKeys(cx, setObj, &objRet)) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY); } else { aRetval.set(objRet ? JS::ObjectValue(*objRet) : JS::UndefinedValue()); } } }
NS_IMETHODIMP SmsFilter::SetNumbers(JSContext* aCx, JS::Handle<JS::Value> aNumbers) { if (aNumbers.isNull()) { mData.numbers().Clear(); return NS_OK; } if (!aNumbers.isObject()) { return NS_ERROR_INVALID_ARG; } JS::Rooted<JSObject*> obj(aCx, &aNumbers.toObject()); if (!JS_IsArrayObject(aCx, obj)) { return NS_ERROR_INVALID_ARG; } uint32_t size; JS_ALWAYS_TRUE(JS_GetArrayLength(aCx, obj, &size)); nsTArray<nsString> numbers; for (uint32_t i=0; i<size; ++i) { JS::Rooted<JS::Value> jsNumber(aCx); if (!JS_GetElement(aCx, obj, i, &jsNumber)) { return NS_ERROR_INVALID_ARG; } if (!jsNumber.isString()) { return NS_ERROR_INVALID_ARG; } nsDependentJSString number; number.init(aCx, jsNumber.toString()); numbers.AppendElement(number); } mData.numbers().Clear(); mData.numbers().AppendElements(numbers); return NS_OK; }
bool CallbackObject::CallSetup::ShouldRethrowException(JS::Handle<JS::Value> aException) { if (mExceptionHandling == eRethrowExceptions) { if (!mCompartment) { // Caller didn't ask us to filter for only exceptions we subsume. return true; } // On workers, we don't have nsIPrincipals to work with. But we also only // have one compartment, so check whether mCompartment is the same as the // current compartment of mCx. if (mCompartment == js::GetContextCompartment(mCx)) { return true; } MOZ_ASSERT(NS_IsMainThread()); // At this point mCx is in the compartment of our unwrapped callback, so // just check whether the principal of mCompartment subsumes that of the // current compartment/global of mCx. nsIPrincipal* callerPrincipal = nsJSPrincipals::get(JS_GetCompartmentPrincipals(mCompartment)); nsIPrincipal* calleePrincipal = nsContentUtils::SubjectPrincipal(); if (callerPrincipal->SubsumesConsideringDomain(calleePrincipal)) { return true; } } MOZ_ASSERT(mCompartment); // Now we only want to throw an exception to the caller if the object that was // thrown is in the caller compartment (which we stored in mCompartment). if (!aException.isObject()) { return false; } JS::Rooted<JSObject*> obj(mCx, &aException.toObject()); obj = js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false); return js::GetObjectCompartment(obj) == mCompartment; }
void RespondWithHandler::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) { AutoCancel autoCancel(this); if (!aValue.isObject()) { return; } nsRefPtr<Response> response; nsresult rv = UNWRAP_OBJECT(Response, &aValue.toObject(), response); if (NS_FAILED(rv)) { return; } nsCOMPtr<nsIInputStream> body; response->GetBody(getter_AddRefs(body)); if (NS_WARN_IF(!body) || NS_WARN_IF(response->BodyUsed())) { return; } response->SetBodyUsed(); nsCOMPtr<nsIOutputStream> responseBody; rv = mInterceptedChannel->GetResponseBody(getter_AddRefs(responseBody)); if (NS_WARN_IF(NS_FAILED(rv))) { return; } nsAutoPtr<RespondWithClosure> closure(new RespondWithClosure(mInterceptedChannel)); nsCOMPtr<nsIEventTarget> stsThread = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv); if (NS_WARN_IF(!stsThread)) { return; } rv = NS_AsyncCopy(body, responseBody, stsThread, NS_ASYNCCOPY_VIA_READSEGMENTS, 4096, RespondWithCopyComplete, closure.forget()); if (NS_WARN_IF(NS_FAILED(rv))) { return; } autoCancel.Reset(); }
NS_DECL_ISUPPORTS NS_IMETHOD Handle(const nsAString& aName, JS::Handle<JS::Value> aResult) { MOZ_ASSERT(NS_IsMainThread()); JSContext *cx = nsContentUtils::GetCurrentJSContext(); NS_ENSURE_TRUE(cx, NS_OK); if (!aResult.isNumber()) { BT_WARNING("'" AUDIO_VOLUME_BT_SCO_ID "' is not a number!"); return NS_OK; } BluetoothHfpManager* hfp = BluetoothHfpManager::Get(); hfp->mCurrentVgs = aResult.toNumber(); return NS_OK; }