本文整理汇总了C++中nsTArray::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ nsTArray::Length方法的具体用法?C++ nsTArray::Length怎么用?C++ nsTArray::Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsTArray
的用法示例。
在下文中一共展示了nsTArray::Length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: opaqueRenderer
void
ThebesLayerD3D9::DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode,
const nsTArray<ReadbackProcessor::Update>& aReadbackUpdates)
{
HRESULT hr;
nsIntRect visibleRect = mVisibleRegion.GetBounds();
nsRefPtr<gfxASurface> destinationSurface;
nsIntRect bounds = aRegion.GetBounds();
nsRefPtr<IDirect3DTexture9> tmpTexture;
OpaqueRenderer opaqueRenderer(aRegion);
OpaqueRenderer opaqueRendererOnWhite(aRegion);
switch (aMode)
{
case SurfaceMode::SURFACE_OPAQUE:
destinationSurface = opaqueRenderer.Begin(this);
break;
case SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA: {
hr = device()->CreateTexture(bounds.width, bounds.height, 1,
0, D3DFMT_A8R8G8B8,
D3DPOOL_SYSTEMMEM, getter_AddRefs(tmpTexture), nullptr);
if (FAILED(hr)) {
ReportFailure(NS_LITERAL_CSTRING("Failed to create temporary texture in system memory."), hr);
return;
}
// XXX - We may consider retaining a SYSTEMMEM texture texture the size
// of our DEFAULT texture and then use UpdateTexture and add dirty rects
// to update in a single call.
nsRefPtr<gfxWindowsSurface> dest = new gfxWindowsSurface(
gfxIntSize(bounds.width, bounds.height), gfxImageFormat::ARGB32);
// If the contents of this layer don't require component alpha in the
// end of rendering, it's safe to enable Cleartype since all the Cleartype
// glyphs must be over (or under) opaque pixels.
dest->SetSubpixelAntialiasingEnabled(!(mContentFlags & CONTENT_COMPONENT_ALPHA));
destinationSurface = dest.forget();
break;
}
case SurfaceMode::SURFACE_COMPONENT_ALPHA: {
nsRefPtr<gfxWindowsSurface> onBlack = opaqueRenderer.Begin(this);
nsRefPtr<gfxWindowsSurface> onWhite = opaqueRendererOnWhite.Begin(this);
if (onBlack && onWhite) {
FillSurface(onBlack, aRegion, bounds.TopLeft(), gfxRGBA(0.0, 0.0, 0.0, 1.0));
FillSurface(onWhite, aRegion, bounds.TopLeft(), gfxRGBA(1.0, 1.0, 1.0, 1.0));
gfxASurface* surfaces[2] = { onBlack.get(), onWhite.get() };
destinationSurface = new gfxTeeSurface(surfaces, ArrayLength(surfaces));
// Using this surface as a source will likely go horribly wrong, since
// only the onBlack surface will really be used, so alpha information will
// be incorrect.
destinationSurface->SetAllowUseAsSource(false);
}
break;
}
}
if (!destinationSurface)
return;
nsRefPtr<gfxContext> context;
if (gfxPlatform::GetPlatform()->SupportsAzureContentForType(BackendType::CAIRO)) {
RefPtr<DrawTarget> dt =
gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(destinationSurface,
IntSize(destinationSurface->GetSize().width,
destinationSurface->GetSize().height));
context = new gfxContext(dt);
} else {
context = new gfxContext(destinationSurface);
}
context->Translate(gfxPoint(-bounds.x, -bounds.y));
LayerManagerD3D9::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
cbInfo.Callback(this, context, aRegion, DrawRegionClip::CLIP_NONE, nsIntRegion(), cbInfo.CallbackData);
for (uint32_t i = 0; i < aReadbackUpdates.Length(); ++i) {
NS_ASSERTION(aMode == SurfaceMode::SURFACE_OPAQUE,
"Transparent surfaces should not be used for readback");
const ReadbackProcessor::Update& update = aReadbackUpdates[i];
nsIntPoint offset = update.mLayer->GetBackgroundLayerOffset();
nsRefPtr<gfxContext> ctx =
update.mLayer->GetSink()->BeginUpdate(update.mUpdateRect + offset,
update.mSequenceCounter);
if (ctx) {
ctx->Translate(gfxPoint(offset.x, offset.y));
ctx->SetSource(destinationSurface, gfxPoint(bounds.x, bounds.y));
ctx->Paint();
update.mLayer->GetSink()->EndUpdate(ctx, update.mUpdateRect + offset);
}
}
// Release the cairo d3d9 surface before we try to composite it
context = nullptr;
nsAutoTArray<IDirect3DTexture9*,2> srcTextures;
nsAutoTArray<IDirect3DTexture9*,2> destTextures;
switch (aMode)
//.........这里部分代码省略.........
示例2: request
bool
JavaScriptChild::AnswerCall(const ObjectId &objId, const nsTArray<JSParam> &argv, ReturnStatus *rs,
JSVariant *result, nsTArray<JSParam> *outparams)
{
AutoSafeJSContext cx;
JSAutoRequest request(cx);
// The outparam will be written to the buffer, so it must be set even if
// the parent won't read it.
*result = void_t();
RootedObject obj(cx, findObject(objId));
if (!obj)
return false;
MOZ_ASSERT(argv.Length() >= 2);
RootedValue objv(cx);
if (!toValue(cx, argv[0], &objv))
return fail(cx, rs);
JSAutoCompartment comp(cx, &objv.toObject());
*result = JSVariant(void_t());
AutoValueVector vals(cx);
AutoValueVector outobjects(cx);
for (size_t i = 0; i < argv.Length(); i++) {
if (argv[i].type() == JSParam::Tvoid_t) {
// This is an outparam.
JSCompartment *compartment = js::GetContextCompartment(cx);
RootedObject global(cx, JS_GetGlobalForCompartmentOrNull(cx, compartment));
RootedObject obj(cx, xpc::NewOutObject(cx, global));
if (!obj)
return fail(cx, rs);
if (!outobjects.append(ObjectValue(*obj)))
return fail(cx, rs);
if (!vals.append(ObjectValue(*obj)))
return fail(cx, rs);
} else {
RootedValue v(cx);
if (!toValue(cx, argv[i].get_JSVariant(), &v))
return fail(cx, rs);
if (!vals.append(v))
return fail(cx, rs);
}
}
uint32_t oldOpts =
JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_DONT_REPORT_UNCAUGHT);
RootedValue rval(cx);
bool success = JS::Call(cx, vals[1], vals[0], vals.length() - 2, vals.begin() + 2, &rval);
JS_SetOptions(cx, oldOpts);
if (!success)
return fail(cx, rs);
if (!toVariant(cx, rval, result))
return fail(cx, rs);
// Prefill everything with a dummy jsval.
for (size_t i = 0; i < outobjects.length(); i++)
outparams->AppendElement(JSParam(void_t()));
// Go through each argument that was an outparam, retrieve the "value"
// field, and add it to a temporary list. We need to do this separately
// because the outparams vector is not rooted.
vals.clear();
for (size_t i = 0; i < outobjects.length(); i++) {
RootedObject obj(cx, &outobjects[i].toObject());
jsval v;
JSBool found;
if (JS_HasProperty(cx, obj, "value", &found)) {
if (!JS_GetProperty(cx, obj, "value", &v))
return fail(cx, rs);
} else {
v = UndefinedValue();
}
if (!vals.append(v))
return fail(cx, rs);
}
// Copy the outparams. If any outparam is already set to a void_t, we
// treat this as the outparam never having been set.
for (size_t i = 0; i < vals.length(); i++) {
JSVariant variant;
if (!toVariant(cx, vals[i], &variant))
return fail(cx, rs);
outparams->ReplaceElementAt(i, JSParam(variant));
}
return ok(rs);
}
示例3: ToHexString
nsCString
ToHexString(const nsTArray<uint8_t>& aBytes)
{
return ToHexString(aBytes.Elements(), aBytes.Length());
}
示例4: request
bool
WrapperAnswer::AnswerCallOrConstruct(const ObjectId &objId,
const nsTArray<JSParam> &argv,
const bool &construct,
ReturnStatus *rs,
JSVariant *result,
nsTArray<JSParam> *outparams)
{
AutoSafeJSContext cx;
JSAutoRequest request(cx);
// The outparam will be written to the buffer, so it must be set even if
// the parent won't read it.
*result = UndefinedVariant();
RootedObject obj(cx, findObjectById(cx, objId));
if (!obj)
return fail(cx, rs);
JSAutoCompartment comp(cx, obj);
MOZ_ASSERT(argv.Length() >= 2);
RootedValue objv(cx);
if (!fromVariant(cx, argv[0], &objv))
return fail(cx, rs);
*result = JSVariant(UndefinedVariant());
AutoValueVector vals(cx);
AutoValueVector outobjects(cx);
for (size_t i = 0; i < argv.Length(); i++) {
if (argv[i].type() == JSParam::Tvoid_t) {
// This is an outparam.
JSCompartment *compartment = js::GetContextCompartment(cx);
RootedObject global(cx, JS_GetGlobalForCompartmentOrNull(cx, compartment));
RootedObject obj(cx, xpc::NewOutObject(cx, global));
if (!obj)
return fail(cx, rs);
if (!outobjects.append(ObjectValue(*obj)))
return fail(cx, rs);
if (!vals.append(ObjectValue(*obj)))
return fail(cx, rs);
} else {
RootedValue v(cx);
if (!fromVariant(cx, argv[i].get_JSVariant(), &v))
return fail(cx, rs);
if (!vals.append(v))
return fail(cx, rs);
}
}
RootedValue rval(cx);
{
AutoSaveContextOptions asco(cx);
ContextOptionsRef(cx).setDontReportUncaught(true);
HandleValueArray args = HandleValueArray::subarray(vals, 2, vals.length() - 2);
bool success;
if (construct)
success = JS::Construct(cx, vals[0], args, &rval);
else
success = JS::Call(cx, vals[1], vals[0], args, &rval);
if (!success)
return fail(cx, rs);
}
if (!toVariant(cx, rval, result))
return fail(cx, rs);
// Prefill everything with a dummy jsval.
for (size_t i = 0; i < outobjects.length(); i++)
outparams->AppendElement(JSParam(void_t()));
// Go through each argument that was an outparam, retrieve the "value"
// field, and add it to a temporary list. We need to do this separately
// because the outparams vector is not rooted.
vals.clear();
for (size_t i = 0; i < outobjects.length(); i++) {
RootedObject obj(cx, &outobjects[i].toObject());
RootedValue v(cx);
bool found;
if (JS_HasProperty(cx, obj, "value", &found)) {
if (!JS_GetProperty(cx, obj, "value", &v))
return fail(cx, rs);
} else {
v = UndefinedValue();
}
if (!vals.append(v))
return fail(cx, rs);
}
// Copy the outparams. If any outparam is already set to a void_t, we
// treat this as the outparam never having been set.
for (size_t i = 0; i < vals.length(); i++) {
JSVariant variant;
if (!toVariant(cx, vals[i], &variant))
return fail(cx, rs);
outparams->ReplaceElementAt(i, JSParam(variant));
//.........这里部分代码省略.........
示例5: while
nsresult
HTMLFormControlsCollection::GetSortedControls(
nsTArray<nsGenericHTMLFormElement*>& aControls) const
{
#ifdef DEBUG
HTMLFormElement::AssertDocumentOrder(mElements, mForm);
HTMLFormElement::AssertDocumentOrder(mNotInElements, mForm);
#endif
aControls.Clear();
// Merge the elements list and the not in elements list. Both lists are
// already sorted.
uint32_t elementsLen = mElements.Length();
uint32_t notInElementsLen = mNotInElements.Length();
aControls.SetCapacity(elementsLen + notInElementsLen);
uint32_t elementsIdx = 0;
uint32_t notInElementsIdx = 0;
while (elementsIdx < elementsLen || notInElementsIdx < notInElementsLen) {
// Check whether we're done with mElements
if (elementsIdx == elementsLen) {
NS_ASSERTION(notInElementsIdx < notInElementsLen,
"Should have remaining not-in-elements");
// Append the remaining mNotInElements elements
if (!aControls.AppendElements(mNotInElements.Elements() +
notInElementsIdx,
notInElementsLen -
notInElementsIdx)) {
return NS_ERROR_OUT_OF_MEMORY;
}
break;
}
// Check whether we're done with mNotInElements
if (notInElementsIdx == notInElementsLen) {
NS_ASSERTION(elementsIdx < elementsLen,
"Should have remaining in-elements");
// Append the remaining mElements elements
if (!aControls.AppendElements(mElements.Elements() +
elementsIdx,
elementsLen -
elementsIdx)) {
return NS_ERROR_OUT_OF_MEMORY;
}
break;
}
// Both lists have elements left.
NS_ASSERTION(mElements[elementsIdx] &&
mNotInElements[notInElementsIdx],
"Should have remaining elements");
// Determine which of the two elements should be ordered
// first and add it to the end of the list.
nsGenericHTMLFormElement* elementToAdd;
if (HTMLFormElement::CompareFormControlPosition(
mElements[elementsIdx], mNotInElements[notInElementsIdx], mForm) < 0) {
elementToAdd = mElements[elementsIdx];
++elementsIdx;
} else {
elementToAdd = mNotInElements[notInElementsIdx];
++notInElementsIdx;
}
// Add the first element to the list.
if (!aControls.AppendElement(elementToAdd)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
NS_ASSERTION(aControls.Length() == elementsLen + notInElementsLen,
"Not all form controls were added to the sorted list");
#ifdef DEBUG
HTMLFormElement::AssertDocumentOrder(aControls, mForm);
#endif
return NS_OK;
}
示例6:
nsresult
nsTextAttrsMgr::GetRange(const nsTArray<nsITextAttr*>& aTextAttrArray,
PRInt32 *aStartHTOffset, PRInt32 *aEndHTOffset)
{
PRUint32 attrLen = aTextAttrArray.Length();
// Navigate backward from anchor accessible to find start offset.
for (PRInt32 childIdx = mOffsetAccIdx - 1; childIdx >= 0; childIdx--) {
nsAccessible *currAcc = mHyperTextAcc->GetChildAt(childIdx);
// Stop on embedded accessible since embedded accessibles are combined into
// own range.
if (nsAccUtils::IsEmbeddedObject(currAcc))
break;
nsIContent *currElm = nsCoreUtils::GetDOMElementFor(currAcc->GetContent());
NS_ENSURE_STATE(currElm);
bool offsetFound = false;
for (PRUint32 attrIdx = 0; attrIdx < attrLen; attrIdx++) {
nsITextAttr *textAttr = aTextAttrArray[attrIdx];
if (!textAttr->Equal(currElm)) {
offsetFound = true;
break;
}
}
if (offsetFound)
break;
*(aStartHTOffset) -= nsAccUtils::TextLength(currAcc);
}
// Navigate forward from anchor accessible to find end offset.
PRInt32 childLen = mHyperTextAcc->GetChildCount();
for (PRInt32 childIdx = mOffsetAccIdx + 1; childIdx < childLen; childIdx++) {
nsAccessible *currAcc = mHyperTextAcc->GetChildAt(childIdx);
if (nsAccUtils::IsEmbeddedObject(currAcc))
break;
nsIContent *currElm = nsCoreUtils::GetDOMElementFor(currAcc->GetContent());
NS_ENSURE_STATE(currElm);
bool offsetFound = false;
for (PRUint32 attrIdx = 0; attrIdx < attrLen; attrIdx++) {
nsITextAttr *textAttr = aTextAttrArray[attrIdx];
// Alter the end offset when text attribute changes its value and stop
// the search.
if (!textAttr->Equal(currElm)) {
offsetFound = true;
break;
}
}
if (offsetFound)
break;
(*aEndHTOffset) += nsAccUtils::TextLength(currAcc);
}
return NS_OK;
}
示例7: GetCasingFor
bool
nsCaseTransformTextRunFactory::TransformString(
const nsAString& aString,
nsString& aConvertedString,
bool aAllUppercase,
const nsIAtom* aLanguage,
nsTArray<bool>& aCharsToMergeArray,
nsTArray<bool>& aDeletedCharsArray,
nsTransformedTextRun* aTextRun,
nsTArray<uint8_t>* aCanBreakBeforeArray,
nsTArray<nsStyleContext*>* aStyleArray)
{
NS_PRECONDITION(!aTextRun || (aCanBreakBeforeArray && aStyleArray),
"either none or all three optional parameters required");
uint32_t length = aString.Length();
const char16_t* str = aString.BeginReading();
bool mergeNeeded = false;
bool capitalizeDutchIJ = false;
bool prevIsLetter = false;
bool ntPrefix = false; // true immediately after a word-initial 'n' or 't'
// when doing Irish lowercasing
uint32_t sigmaIndex = uint32_t(-1);
nsIUGenCategory::nsUGenCategory cat;
uint8_t style = aAllUppercase ? NS_STYLE_TEXT_TRANSFORM_UPPERCASE : 0;
const nsIAtom* lang = aLanguage;
LanguageSpecificCasingBehavior languageSpecificCasing = GetCasingFor(lang);
mozilla::GreekCasing::State greekState;
mozilla::IrishCasing::State irishState;
uint32_t irishMark = uint32_t(-1); // location of possible prefix letter(s)
for (uint32_t i = 0; i < length; ++i) {
uint32_t ch = str[i];
nsStyleContext* styleContext;
if (aTextRun) {
styleContext = aTextRun->mStyles[i];
style = aAllUppercase ? NS_STYLE_TEXT_TRANSFORM_UPPERCASE :
styleContext->StyleText()->mTextTransform;
const nsStyleFont* styleFont = styleContext->StyleFont();
nsIAtom* newLang = styleFont->mExplicitLanguage
? styleFont->mLanguage : nullptr;
if (lang != newLang) {
lang = newLang;
languageSpecificCasing = GetCasingFor(lang);
greekState.Reset();
irishState.Reset();
irishMark = uint32_t(-1);
}
}
int extraChars = 0;
const mozilla::unicode::MultiCharMapping *mcm;
bool inhibitBreakBefore = false; // have we just deleted preceding hyphen?
if (NS_IS_HIGH_SURROGATE(ch) && i < length - 1 &&
NS_IS_LOW_SURROGATE(str[i + 1])) {
ch = SURROGATE_TO_UCS4(ch, str[i + 1]);
}
switch (style) {
case NS_STYLE_TEXT_TRANSFORM_LOWERCASE:
if (languageSpecificCasing == eLSCB_Turkish) {
if (ch == 'I') {
ch = LATIN_SMALL_LETTER_DOTLESS_I;
prevIsLetter = true;
sigmaIndex = uint32_t(-1);
break;
}
if (ch == LATIN_CAPITAL_LETTER_I_WITH_DOT_ABOVE) {
ch = 'i';
prevIsLetter = true;
sigmaIndex = uint32_t(-1);
break;
}
}
cat = mozilla::unicode::GetGenCategory(ch);
if (languageSpecificCasing == eLSCB_Irish &&
cat == nsIUGenCategory::kLetter) {
// See bug 1018805 for Irish lowercasing requirements
if (!prevIsLetter && (ch == 'n' || ch == 't')) {
ntPrefix = true;
} else {
if (ntPrefix && mozilla::IrishCasing::IsUpperVowel(ch)) {
aConvertedString.Append('-');
++extraChars;
}
ntPrefix = false;
}
} else {
ntPrefix = false;
}
//.........这里部分代码省略.........
示例8: GetFileSize
HRESULT STDMETHODCALLTYPE DWriteFontFileStream::GetFileSize(UINT64* fileSize) {
*fileSize = mData.Length();
return S_OK;
}
示例9: HandleEventTargetChain
void
nsEventTargetChainItem::HandleEventTargetChain(
nsTArray<nsEventTargetChainItem>& aChain,
nsEventChainPostVisitor& aVisitor,
nsDispatchingCallback* aCallback,
ELMCreationDetector& aCd)
{
// Save the target so that it can be restored later.
nsCOMPtr<EventTarget> firstTarget = aVisitor.mEvent->target;
uint32_t chainLength = aChain.Length();
// Capture
aVisitor.mEvent->mFlags.mInCapturePhase = true;
aVisitor.mEvent->mFlags.mInBubblingPhase = false;
for (uint32_t i = chainLength - 1; i > 0; --i) {
nsEventTargetChainItem& item = aChain[i];
if ((!aVisitor.mEvent->mFlags.mNoContentDispatch ||
item.ForceContentDispatch()) &&
!aVisitor.mEvent->mFlags.mPropagationStopped) {
item.HandleEvent(aVisitor, aCd);
}
if (item.GetNewTarget()) {
// item is at anonymous boundary. Need to retarget for the child items.
for (uint32_t j = i; j > 0; --j) {
uint32_t childIndex = j - 1;
EventTarget* newTarget = aChain[childIndex].GetNewTarget();
if (newTarget) {
aVisitor.mEvent->target = newTarget;
break;
}
}
}
}
// Target
aVisitor.mEvent->mFlags.mInBubblingPhase = true;
nsEventTargetChainItem& targetItem = aChain[0];
if (!aVisitor.mEvent->mFlags.mPropagationStopped &&
(!aVisitor.mEvent->mFlags.mNoContentDispatch ||
targetItem.ForceContentDispatch())) {
targetItem.HandleEvent(aVisitor, aCd);
}
if (aVisitor.mEvent->mFlags.mInSystemGroup) {
targetItem.PostHandleEvent(aVisitor);
}
// Bubble
aVisitor.mEvent->mFlags.mInCapturePhase = false;
for (uint32_t i = 1; i < chainLength; ++i) {
nsEventTargetChainItem& item = aChain[i];
EventTarget* newTarget = item.GetNewTarget();
if (newTarget) {
// Item is at anonymous boundary. Need to retarget for the current item
// and for parent items.
aVisitor.mEvent->target = newTarget;
}
if (aVisitor.mEvent->mFlags.mBubbles || newTarget) {
if ((!aVisitor.mEvent->mFlags.mNoContentDispatch ||
item.ForceContentDispatch()) &&
!aVisitor.mEvent->mFlags.mPropagationStopped) {
item.HandleEvent(aVisitor, aCd);
}
if (aVisitor.mEvent->mFlags.mInSystemGroup) {
item.PostHandleEvent(aVisitor);
}
}
}
aVisitor.mEvent->mFlags.mInBubblingPhase = false;
if (!aVisitor.mEvent->mFlags.mInSystemGroup) {
// Dispatch to the system event group. Make sure to clear the
// STOP_DISPATCH flag since this resets for each event group.
aVisitor.mEvent->mFlags.mPropagationStopped = false;
aVisitor.mEvent->mFlags.mImmediatePropagationStopped = false;
// Setting back the original target of the event.
aVisitor.mEvent->target = aVisitor.mEvent->originalTarget;
// Special handling if PresShell (or some other caller)
// used a callback object.
if (aCallback) {
aCallback->HandleEvent(aVisitor);
}
// Retarget for system event group (which does the default handling too).
// Setting back the target which was used also for default event group.
aVisitor.mEvent->target = firstTarget;
aVisitor.mEvent->mFlags.mInSystemGroup = true;
HandleEventTargetChain(aChain,
aVisitor,
aCallback,
aCd);
aVisitor.mEvent->mFlags.mInSystemGroup = false;
// After dispatch, clear all the propagation flags so that
// system group listeners don't affect to the event.
aVisitor.mEvent->mFlags.mPropagationStopped = false;
aVisitor.mEvent->mFlags.mImmediatePropagationStopped = false;
//.........这里部分代码省略.........
示例10: PodZero
nsresult
AppleATDecoder::GetInputAudioDescription(AudioStreamBasicDescription& aDesc,
const nsTArray<uint8_t>& aExtraData)
{
// Request the properties from CoreAudio using the codec magic cookie
AudioFormatInfo formatInfo;
PodZero(&formatInfo.mASBD);
formatInfo.mASBD.mFormatID = mFormatID;
if (mFormatID == kAudioFormatMPEG4AAC) {
formatInfo.mASBD.mFormatFlags = mConfig.extended_profile;
}
formatInfo.mMagicCookieSize = aExtraData.Length();
formatInfo.mMagicCookie = aExtraData.Elements();
UInt32 formatListSize;
// Attempt to retrieve the default format using
// kAudioFormatProperty_FormatInfo method.
// This method only retrieves the FramesPerPacket information required
// by the decoder, which depends on the codec type and profile.
aDesc.mFormatID = mFormatID;
aDesc.mChannelsPerFrame = mConfig.channel_count;
aDesc.mSampleRate = mConfig.samples_per_second;
UInt32 inputFormatSize = sizeof(aDesc);
OSStatus rv = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
0,
NULL,
&inputFormatSize,
&aDesc);
if (NS_WARN_IF(rv)) {
return NS_ERROR_FAILURE;
}
// If any of the methods below fail, we will return the default format as
// created using kAudioFormatProperty_FormatInfo above.
rv = AudioFormatGetPropertyInfo(kAudioFormatProperty_FormatList,
sizeof(formatInfo),
&formatInfo,
&formatListSize);
if (rv || (formatListSize % sizeof(AudioFormatListItem))) {
return NS_OK;
}
size_t listCount = formatListSize / sizeof(AudioFormatListItem);
nsAutoArrayPtr<AudioFormatListItem> formatList(
new AudioFormatListItem[listCount]);
rv = AudioFormatGetProperty(kAudioFormatProperty_FormatList,
sizeof(formatInfo),
&formatInfo,
&formatListSize,
formatList);
if (rv) {
return NS_OK;
}
LOG("found %u available audio stream(s)",
formatListSize / sizeof(AudioFormatListItem));
// Get the index number of the first playable format.
// This index number will be for the highest quality layer the platform
// is capable of playing.
UInt32 itemIndex;
UInt32 indexSize = sizeof(itemIndex);
rv = AudioFormatGetProperty(kAudioFormatProperty_FirstPlayableFormatFromList,
formatListSize,
formatList,
&indexSize,
&itemIndex);
if (rv) {
return NS_OK;
}
aDesc = formatList[itemIndex].mASBD;
return NS_OK;
}
示例11: GetSize
NS_IMETHODIMP
nsDOMMultipartBlob::MozSlice(PRInt64 aStart, PRInt64 aEnd,
const nsAString& aContentType,
PRUint8 optional_argc,
nsIDOMBlob **aBlob)
{
nsresult rv;
*aBlob = nsnull;
// Truncate aStart and aEnd so that we stay within this file.
PRUint64 thisLength;
rv = GetSize(&thisLength);
NS_ENSURE_SUCCESS(rv, rv);
if (!optional_argc) {
aEnd = (PRInt64)thisLength;
}
// Modifies aStart and aEnd.
ParseSize((PRInt64)thisLength, aStart, aEnd);
// If we clamped to nothing we create an empty blob
nsTArray<nsCOMPtr<nsIDOMBlob> > blobs;
PRUint64 length = aEnd - aStart;
PRUint64 skipStart = aStart;
NS_ABORT_IF_FALSE(PRUint64(aStart) + length <= thisLength, "Er, what?");
// Prune the list of blobs if we can
PRUint32 i;
for (i = 0; length && skipStart && i < mBlobs.Length(); i++) {
nsIDOMBlob* blob = mBlobs[i].get();
PRUint64 l;
rv = blob->GetSize(&l);
NS_ENSURE_SUCCESS(rv, rv);
if (skipStart < l) {
PRUint64 upperBound = NS_MIN<PRUint64>(l - skipStart, length);
nsCOMPtr<nsIDOMBlob> firstBlob;
rv = mBlobs.ElementAt(i)->MozSlice(skipStart, skipStart + upperBound,
aContentType, 2,
getter_AddRefs(firstBlob));
NS_ENSURE_SUCCESS(rv, rv);
// Avoid wrapping a single blob inside an nsDOMMultipartBlob
if (length == upperBound) {
firstBlob.forget(aBlob);
return NS_OK;
}
blobs.AppendElement(firstBlob);
length -= upperBound;
i++;
break;
}
skipStart -= l;
}
// Now append enough blobs until we're done
for (; length && i < mBlobs.Length(); i++) {
nsIDOMBlob* blob = mBlobs[i].get();
PRUint64 l;
rv = blob->GetSize(&l);
NS_ENSURE_SUCCESS(rv, rv);
if (length < l) {
nsCOMPtr<nsIDOMBlob> lastBlob;
rv = mBlobs.ElementAt(i)->MozSlice(0, length, aContentType, 2,
getter_AddRefs(lastBlob));
NS_ENSURE_SUCCESS(rv, rv);
blobs.AppendElement(lastBlob);
} else {
blobs.AppendElement(blob);
}
length -= NS_MIN<PRUint64>(l, length);
}
// we can create our blob now
nsCOMPtr<nsIDOMBlob> blob = new nsDOMMultipartBlob(blobs, aContentType);
blob.forget(aBlob);
return NS_OK;
}
示例12: ParseDriverVersion
int32_t
GfxInfoBase::FindBlocklistedDeviceInList(const nsTArray<GfxDriverInfo>& info,
nsAString& aSuggestedVersion,
int32_t aFeature,
OperatingSystem os)
{
int32_t status = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
nsAutoString adapterVendorID;
nsAutoString adapterDeviceID;
nsAutoString adapterDriverVersionString;
if (NS_FAILED(GetAdapterVendorID(adapterVendorID)) ||
NS_FAILED(GetAdapterDeviceID(adapterDeviceID)) ||
NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString)))
{
return 0;
}
uint64_t driverVersion;
ParseDriverVersion(adapterDriverVersionString, &driverVersion);
uint32_t i = 0;
for (; i < info.Length(); i++) {
if (info[i].mOperatingSystem != DRIVER_OS_ALL &&
info[i].mOperatingSystem != os)
{
continue;
}
if (info[i].mOperatingSystemVersion && info[i].mOperatingSystemVersion != OperatingSystemVersion()) {
continue;
}
if (!info[i].mAdapterVendor.Equals(GfxDriverInfo::GetDeviceVendor(VendorAll), nsCaseInsensitiveStringComparator()) &&
!info[i].mAdapterVendor.Equals(adapterVendorID, nsCaseInsensitiveStringComparator())) {
continue;
}
if (info[i].mDevices != GfxDriverInfo::allDevices && info[i].mDevices->Length()) {
bool deviceMatches = false;
for (uint32_t j = 0; j < info[i].mDevices->Length(); j++) {
if ((*info[i].mDevices)[j].Equals(adapterDeviceID, nsCaseInsensitiveStringComparator())) {
deviceMatches = true;
break;
}
}
if (!deviceMatches) {
continue;
}
}
bool match = false;
if (!info[i].mHardware.IsEmpty() && !info[i].mHardware.Equals(Hardware())) {
continue;
}
if (!info[i].mModel.IsEmpty() && !info[i].mModel.Equals(Model())) {
continue;
}
if (!info[i].mProduct.IsEmpty() && !info[i].mProduct.Equals(Product())) {
continue;
}
if (!info[i].mManufacturer.IsEmpty() && !info[i].mManufacturer.Equals(Manufacturer())) {
continue;
}
#if defined(XP_WIN) || defined(ANDROID)
switch (info[i].mComparisonOp) {
case DRIVER_LESS_THAN:
match = driverVersion < info[i].mDriverVersion;
break;
case DRIVER_LESS_THAN_OR_EQUAL:
match = driverVersion <= info[i].mDriverVersion;
break;
case DRIVER_GREATER_THAN:
match = driverVersion > info[i].mDriverVersion;
break;
case DRIVER_GREATER_THAN_OR_EQUAL:
match = driverVersion >= info[i].mDriverVersion;
break;
case DRIVER_EQUAL:
match = driverVersion == info[i].mDriverVersion;
break;
case DRIVER_NOT_EQUAL:
match = driverVersion != info[i].mDriverVersion;
break;
case DRIVER_BETWEEN_EXCLUSIVE:
match = driverVersion > info[i].mDriverVersion && driverVersion < info[i].mDriverVersionMax;
break;
case DRIVER_BETWEEN_INCLUSIVE:
match = driverVersion >= info[i].mDriverVersion && driverVersion <= info[i].mDriverVersionMax;
break;
case DRIVER_BETWEEN_INCLUSIVE_START:
match = driverVersion >= info[i].mDriverVersion && driverVersion < info[i].mDriverVersionMax;
break;
case DRIVER_COMPARISON_IGNORED:
// We don't have a comparison op, so we match everything.
match = true;
break;
//.........这里部分代码省略.........
示例13: RemoveAll
nsresult
nsDOMStoragePersistentDB::RemoveOwners(const nsTArray<nsString> &aOwners,
bool aIncludeSubDomains,
bool aMatch)
{
if (aOwners.Length() == 0) {
if (aMatch) {
return NS_OK;
}
return RemoveAll();
}
// Using nsString here because it is going to be very long
nsCString expression;
if (aMatch) {
expression.AppendLiteral("DELETE FROM webappsstore2_view WHERE scope IN (");
} else {
expression.AppendLiteral("DELETE FROM webappsstore2_view WHERE scope NOT IN (");
}
for (PRUint32 i = 0; i < aOwners.Length(); i++) {
if (i)
expression.AppendLiteral(" UNION ");
expression.AppendLiteral(
"SELECT DISTINCT scope FROM webappsstore2_temp WHERE scope GLOB :scope");
expression.AppendInt(i);
expression.AppendLiteral(" UNION ");
expression.AppendLiteral(
"SELECT DISTINCT scope FROM webappsstore2 WHERE scope GLOB :scope");
expression.AppendInt(i);
}
expression.AppendLiteral(");");
nsCOMPtr<mozIStorageStatement> statement;
nsresult rv;
rv = MaybeCommitInsertTransaction();
NS_ENSURE_SUCCESS(rv, rv);
rv = mConnection->CreateStatement(expression,
getter_AddRefs(statement));
NS_ENSURE_SUCCESS(rv, rv);
for (PRUint32 i = 0; i < aOwners.Length(); i++) {
nsCAutoString quotaKey;
rv = nsDOMStorageDBWrapper::CreateDomainScopeDBKey(
NS_ConvertUTF16toUTF8(aOwners[i]), quotaKey);
if (DomainMaybeCached(quotaKey)) {
mCachedUsage = 0;
mCachedOwner.Truncate();
}
if (!aIncludeSubDomains)
quotaKey.AppendLiteral(":");
quotaKey.AppendLiteral("*");
nsCAutoString paramName;
paramName.Assign("scope");
paramName.AppendInt(i);
rv = statement->BindUTF8StringByName(paramName, quotaKey);
NS_ENSURE_SUCCESS(rv, rv);
}
rv = statement->Execute();
NS_ENSURE_SUCCESS(rv, rv);
MarkAllScopesDirty();
return NS_OK;
}
示例14: GetLastResultIndex
nsresult
nsSVGFilterInstance::BuildPrimitives(nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
nsTArray<RefPtr<SourceSurface>>& aInputImages)
{
mSourceGraphicIndex = GetLastResultIndex(aPrimitiveDescrs);
// Clip previous filter's output to this filter's filter region.
if (mSourceGraphicIndex >= 0) {
FilterPrimitiveDescription& sourceDescr = aPrimitiveDescrs[mSourceGraphicIndex];
sourceDescr.SetPrimitiveSubregion(sourceDescr.PrimitiveSubregion().Intersect(mFilterSpaceBounds));
}
// Get the filter primitive elements.
nsTArray<RefPtr<nsSVGFE> > primitives;
for (nsIContent* child = mFilterElement->nsINode::GetFirstChild();
child;
child = child->GetNextSibling()) {
RefPtr<nsSVGFE> primitive;
CallQueryInterface(child, (nsSVGFE**)getter_AddRefs(primitive));
if (primitive) {
primitives.AppendElement(primitive);
}
}
// Maps source image name to source index.
nsDataHashtable<nsStringHashKey, int32_t> imageTable(8);
// The principal that we check principals of any loaded images against.
nsCOMPtr<nsIPrincipal> principal = mTargetContent->NodePrincipal();
bool filterInputIsTainted = IsFilterInputTainted(mTargetContent);
for (uint32_t primitiveElementIndex = 0;
primitiveElementIndex < primitives.Length();
++primitiveElementIndex) {
nsSVGFE* filter = primitives[primitiveElementIndex];
AutoTArray<int32_t,2> sourceIndices;
nsresult rv = GetSourceIndices(filter, aPrimitiveDescrs, imageTable, sourceIndices);
if (NS_FAILED(rv)) {
return rv;
}
IntRect primitiveSubregion =
ComputeFilterPrimitiveSubregion(filter, aPrimitiveDescrs, sourceIndices);
nsTArray<bool> sourcesAreTainted;
GetInputsAreTainted(aPrimitiveDescrs, sourceIndices, filterInputIsTainted, sourcesAreTainted);
FilterPrimitiveDescription descr =
filter->GetPrimitiveDescription(this, primitiveSubregion, sourcesAreTainted, aInputImages);
descr.SetIsTainted(filter->OutputIsTainted(sourcesAreTainted, principal));
descr.SetFilterSpaceBounds(mFilterSpaceBounds);
descr.SetPrimitiveSubregion(primitiveSubregion.Intersect(descr.FilterSpaceBounds()));
for (uint32_t i = 0; i < sourceIndices.Length(); i++) {
int32_t inputIndex = sourceIndices[i];
descr.SetInputPrimitive(i, inputIndex);
ColorSpace inputColorSpace = inputIndex >= 0
? aPrimitiveDescrs[inputIndex].OutputColorSpace()
: ColorSpace(ColorSpace::SRGB);
ColorSpace desiredInputColorSpace = filter->GetInputColorSpace(i, inputColorSpace);
descr.SetInputColorSpace(i, desiredInputColorSpace);
if (i == 0) {
// the output color space is whatever in1 is if there is an in1
descr.SetOutputColorSpace(desiredInputColorSpace);
}
}
if (sourceIndices.Length() == 0) {
descr.SetOutputColorSpace(filter->GetOutputColorSpace());
}
aPrimitiveDescrs.AppendElement(descr);
uint32_t primitiveDescrIndex = aPrimitiveDescrs.Length() - 1;
nsAutoString str;
filter->GetResultImageName().GetAnimValue(str, filter);
imageTable.Put(str, primitiveDescrIndex);
}
return NS_OK;
}
示例15: slot
// A U2F Sign operation creates a signature over the "param" arguments (plus
// some other stuff) using the private key indicated in the key handle argument.
//
// The format of the signed data is as follows:
//
// 32 Application parameter
// 1 User presence (0x01)
// 4 Counter
// 32 Challenge parameter
//
// The format of the signature data is as follows:
//
// 1 User presence
// 4 Counter
// * Signature
//
nsresult
U2FSoftTokenManager::Sign(nsTArray<uint8_t>& aApplication,
nsTArray<uint8_t>& aChallenge,
nsTArray<uint8_t>& aKeyHandle,
nsTArray<uint8_t>& aSignature)
{
nsNSSShutDownPreventionLock locker;
if (NS_WARN_IF(isAlreadyShutDown())) {
return NS_ERROR_NOT_AVAILABLE;
}
MOZ_ASSERT(mInitialized);
if (NS_WARN_IF(!mInitialized)) {
nsresult rv = Init();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
MOZ_ASSERT(mWrappingKey);
UniquePK11SlotInfo slot(PK11_GetInternalSlot());
MOZ_ASSERT(slot.get());
if (NS_WARN_IF((aChallenge.Length() != kParamLen) || (aApplication.Length() != kParamLen))) {
MOZ_LOG(gNSSTokenLog, LogLevel::Warning,
("Parameter lengths are wrong! challenge=%d app=%d expected=%d",
(uint32_t)aChallenge.Length(), (uint32_t)aApplication.Length(), kParamLen));
return NS_ERROR_ILLEGAL_VALUE;
}
// Decode the key handle
UniqueSECKEYPrivateKey privKey = PrivateKeyFromKeyHandle(slot, mWrappingKey,
aKeyHandle.Elements(),
aKeyHandle.Length(),
aApplication.Elements(),
aApplication.Length(),
locker);
if (NS_WARN_IF(!privKey.get())) {
MOZ_LOG(gNSSTokenLog, LogLevel::Warning, ("Couldn't get the priv key!"));
return NS_ERROR_FAILURE;
}
// Increment the counter and turn it into a SECItem
mCounter += 1;
ScopedAutoSECItem counterItem(4);
counterItem.data[0] = (mCounter >> 24) & 0xFF;
counterItem.data[1] = (mCounter >> 16) & 0xFF;
counterItem.data[2] = (mCounter >> 8) & 0xFF;
counterItem.data[3] = (mCounter >> 0) & 0xFF;
uint32_t counter = mCounter;
AbstractThread::MainThread()->Dispatch(NS_NewRunnableFunction(
[counter] () {
MOZ_ASSERT(NS_IsMainThread());
Preferences::SetUint(PREF_U2F_NSSTOKEN_COUNTER, counter);
}));
// Compute the signature
mozilla::dom::CryptoBuffer signedDataBuf;
if (NS_WARN_IF(!signedDataBuf.SetCapacity(1 + 4 + (2 * kParamLen), mozilla::fallible))) {
return NS_ERROR_OUT_OF_MEMORY;
}
// It's OK to ignore the return values here because we're writing into
// pre-allocated space
signedDataBuf.AppendElements(aApplication.Elements(), aApplication.Length(),
mozilla::fallible);
signedDataBuf.AppendElement(0x01, mozilla::fallible);
signedDataBuf.AppendSECItem(counterItem);
signedDataBuf.AppendElements(aChallenge.Elements(), aChallenge.Length(),
mozilla::fallible);
if (MOZ_LOG_TEST(gNSSTokenLog, LogLevel::Debug)) {
nsAutoCString base64;
nsresult rv = Base64URLEncode(signedDataBuf.Length(), signedDataBuf.Elements(),
Base64URLEncodePaddingPolicy::Omit, base64);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_FAILURE;
}
MOZ_LOG(gNSSTokenLog, LogLevel::Debug,
("U2F Token signing bytes (base64): %s", base64.get()));
}
//.........这里部分代码省略.........