already_AddRefed<ProgressTracker> RequestBehaviour::GetProgressTracker() const { // NOTE: It's possible that our mOwner has an Image that it didn't notify // us about, if we were Canceled before its Image was constructed. // (Canceling removes us as an observer, so mOwner has no way to notify us). // That's why this method uses mOwner->GetProgressTracker() instead of just // mOwner->mProgressTracker -- we might have a null mImage and yet have an // mOwner with a non-null mImage (and a null mProgressTracker pointer). return mOwner->GetProgressTracker(); }
PLDHashOperator gfxPlatformFontList::FindFontForCharProc(nsStringHashKey::KeyType aKey, nsRefPtr<gfxFontFamily>& aFamilyEntry, void *userArg) { GlobalFontMatch *data = static_cast<GlobalFontMatch*>(userArg); // evaluate all fonts in this family for a match aFamilyEntry->FindFontForChar(data); return PL_DHASH_NEXT; }
void CompareCache::RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) { AssertIsOnMainThread(); if (mAborted) { return; } mManager->CacheFinished(NS_ERROR_FAILURE, false); }
InputBlockState::InputBlockState(const nsRefPtr<AsyncPanZoomController>& aTargetApzc, bool aTargetConfirmed) : mTargetApzc(aTargetApzc) , mTargetConfirmed(aTargetConfirmed) , mBlockId(sBlockCounter++) , mTransformToApzc(aTargetApzc->GetTransformToThis()) { // We should never be constructed with a nullptr target. MOZ_ASSERT(mTargetApzc); mOverscrollHandoffChain = mTargetApzc->BuildOverscrollHandoffChain(); }
NS_IMETHODIMP nsPrefetchQueueEnumerator::GetNext(nsISupports **aItem) { if (!mCurrent) return NS_ERROR_FAILURE; NS_ADDREF(*aItem = static_cast<nsIDOMLoadStatus*>(mCurrent.get())); Increment(); return NS_OK; }
void MediaDecodeTask::SampleDecoded(AudioData* aData) { MOZ_ASSERT(!NS_IsMainThread()); mAudioQueue.Push(aData); if (!mFirstFrameDecoded) { mDecoderReader->ReadUpdatedMetadata(&mMediaInfo); mFirstFrameDecoded = true; } RequestSample(); }
TemporaryRef<gfx::SourceSurface> GLImage::GetAsSourceSurface() { MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread"); if (!sSnapshotContext) { sSnapshotContext = GLContextProvider::CreateHeadless(); if (!sSnapshotContext) { NS_WARNING("Failed to create snapshot GLContext"); return nullptr; } } sSnapshotContext->MakeCurrent(); ScopedTexture scopedTex(sSnapshotContext); ScopedBindTexture boundTex(sSnapshotContext, scopedTex.Texture()); gfx::IntSize size = GetSize(); sSnapshotContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA, size.width, size.height, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, nullptr); ScopedFramebufferForTexture fb(sSnapshotContext, scopedTex.Texture()); GLBlitHelper helper(sSnapshotContext); helper.BlitImageToFramebuffer(this, size, fb.FB(), false); ScopedBindFramebuffer bind(sSnapshotContext, fb.FB()); RefPtr<gfx::DataSourceSurface> source = gfx::Factory::CreateDataSourceSurface(size, gfx::SurfaceFormat::B8G8R8A8); if (NS_WARN_IF(!source)) { return nullptr; } ReadPixelsIntoDataSurface(sSnapshotContext, source); return source.forget(); }
bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override { MOZ_ASSERT(aWorkerPrivate); aWorkerPrivate->AssertIsOnWorkerThread(); MOZ_ASSERT(aWorkerPrivate == mResolver->GetWorkerPrivate()); nsRefPtr<Promise> promise = mResolver->mFetchPromise.forget(); if (mInternalResponse->Type() != ResponseType::Error) { nsRefPtr<nsIGlobalObject> global = aWorkerPrivate->GlobalScope(); mResolver->mResponse = new Response(global, mInternalResponse); promise->MaybeResolve(mResolver->mResponse); } else { ErrorResult result; result.ThrowTypeError(MSG_FETCH_FAILED); promise->MaybeReject(result); } return true; }
virtual ~TestBinding() { { nsRefPtr<MediaTaskQueue> queue = reader->GetTaskQueue(); queue->Dispatch(NS_NewRunnableMethod(reader, &MP4Reader::Shutdown)); queue->AwaitShutdownAndIdle(); } decoder = nullptr; resource = nullptr; reader = nullptr; SharedThreadPool::SpinUntilShutdown(); }
NS_IMETHOD Run() { MOZ_ASSERT(!NS_IsMainThread()); while (!sStopSendingRingFlag) { sInstance->SendLine("RING"); usleep(kRingInterval); } return NS_OK; }
PLDHashOperator CacheFile::WriteAllCachedChunks(const uint32_t& aIdx, nsRefPtr<CacheFileChunk>& aChunk, void* aClosure) { CacheFile *file = static_cast<CacheFile*>(aClosure); LOG(("CacheFile::WriteAllCachedChunks() [this=%p, idx=%d, chunk=%p]", file, aIdx, aChunk.get())); file->mChunks.Put(aIdx, aChunk); aChunk->mFile = file; aChunk->mRemovingChunk = false; MOZ_ASSERT(aChunk->IsReady()); NS_ADDREF(aChunk); file->ReleaseOutsideLock(aChunk); return PL_DHASH_REMOVE; }
void txDriver::StartElement(const XML_Char *aName, const XML_Char **aAtts) { PRInt32 attcount = 0; const XML_Char** atts = aAtts; while (*atts) { ++atts; ++attcount; } PRInt32 idOffset = XML_GetIdAttributeIndex(mExpatParser); nsresult rv = mCompiler->startElement(static_cast<const PRUnichar*>(aName), static_cast<const PRUnichar**>(aAtts), attcount/2, idOffset); if (NS_FAILED(rv)) { PR_LOG(txLog::xslt, PR_LOG_ALWAYS, ("compile failed at %i with %x\n", XML_GetCurrentLineNumber(mExpatParser), rv)); mCompiler->cancel(rv); } }
// runs on separate thread nsresult AsyncFontInfoLoader::Run() { // load platform-specific font info mFontInfo->Load(); // post a completion event that transfer the data to the fontlist NS_DispatchToMainThread(mCompleteEvent); mFontInfo = nullptr; return NS_OK; }
void MediaDecodeTask::SampleNotDecoded(MediaDecoderReader::NotDecodedReason aReason) { MOZ_ASSERT(!NS_IsMainThread()); if (aReason == MediaDecoderReader::DECODE_ERROR) { mDecoderReader->Shutdown(); ReportFailureOnMainThread(WebAudioDecodeJob::InvalidContent); } else { MOZ_ASSERT(aReason == MediaDecoderReader::END_OF_STREAM); FinishDecode(); } }
nsresult nsDOMEventTargetHelper::GetInnerEventListener(nsRefPtr<nsDOMEventListenerWrapper>& aWrapper, nsIDOMEventListener** aListener) { NS_ENSURE_ARG_POINTER(aListener); if (aWrapper) { NS_ADDREF(*aListener = aWrapper->GetInner()); } else { *aListener = nsnull; } return NS_OK; }
bool MediaDecodeTask::CreateReader() { MOZ_ASSERT(NS_IsMainThread()); nsCOMPtr<nsIPrincipal> principal; nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(mDecodeJob.mContext->GetParentObject()); if (sop) { principal = sop->GetPrincipal(); } nsRefPtr<BufferMediaResource> resource = new BufferMediaResource(static_cast<uint8_t*> (mBuffer), mLength, principal, mContentType); MOZ_ASSERT(!mBufferDecoder); mBufferDecoder = new BufferDecoder(resource); // If you change this list to add support for new decoders, please consider // updating HTMLMediaElement::CreateDecoder as well. mDecoderReader = DecoderTraits::CreateReader(mContentType, mBufferDecoder); if (!mDecoderReader) { return false; } nsresult rv = mDecoderReader->Init(nullptr); if (NS_FAILED(rv)) { return false; } if (!mDecoderReader->EnsureTaskQueue()) { return false; } return true; }
void APZCCallbackHelper::SendSetAllowedTouchBehaviorNotification( nsIWidget* aWidget, const WidgetTouchEvent& aEvent, uint64_t aInputBlockId, const nsRefPtr<SetAllowedTouchBehaviorCallback>& aCallback) { nsTArray<TouchBehaviorFlags> flags; for (uint32_t i = 0; i < aEvent.touches.Length(); i++) { flags.AppendElement(widget::ContentHelper::GetAllowedTouchBehavior(aWidget, aEvent.touches[i]->mRefPoint)); } aCallback->Run(aInputBlockId, flags); }
NS_IMETHODIMP DispatchAsyncScrollEventRunnable::Run() { nsCOMPtr<Element> frameElement = mTabParent->GetOwnerElement(); // Create the event's detail object. nsRefPtr<nsAsyncScrollEventDetail> detail = new nsAsyncScrollEventDetail(mContentRect.x, mContentRect.y, mContentRect.width, mContentRect.height, mContentSize.width, mContentSize.height); DispatchCustomDOMEvent(frameElement, NS_LITERAL_STRING("mozbrowserasyncscroll"), detail); return NS_OK; }
static PLDHashOperator FontListHashEnumFunc(nsStringHashKey::KeyType aKey, nsRefPtr<FontFamily>& aFontFamily, void* userArg) { FontListData *data = (FontListData*)userArg; // use the first variation for now. This data should be the same // for all the variations and should probably be moved up to // the Family gfxFontStyle style; style.language = data->mLangGroup; nsRefPtr<FontEntry> aFontEntry = aFontFamily->FindFontEntry(style); NS_ASSERTION(aFontEntry, "couldn't find any font entry in family"); if (!aFontEntry) return PL_DHASH_NEXT; data->mStringArray.AppendElement(aFontFamily->Name()); return PL_DHASH_NEXT; }
NS_IMETHODIMP nsFileUploadContentStream::ReadSegments(nsWriteSegmentFun fun, void *closure, uint32_t count, uint32_t *result) { *result = 0; // nothing is ever actually read from this stream if (IsClosed()) return NS_OK; if (IsNonBlocking()) { // Inform the caller that they will have to wait for the copy operation to // complete asynchronously. We'll kick of the copy operation once they // call AsyncWait. return NS_BASE_STREAM_WOULD_BLOCK; } // Perform copy synchronously, and then close out the stream. mCopyEvent->DoCopy(); nsresult status = mCopyEvent->Status(); CloseWithStatus(NS_FAILED(status) ? status : NS_BASE_STREAM_CLOSED); return status; }
static PLDHashOperator AddFamilyToFontList(nsStringHashKey::KeyType aKey, nsRefPtr<gfxFontFamily>& aFamily, void* aUserArg) { InfallibleTArray<FontListEntry>* fontlist = reinterpret_cast<InfallibleTArray<FontListEntry>*>(aUserArg); FT2FontFamily *family = static_cast<FT2FontFamily*>(aFamily.get()); family->AddFacesToFontList(fontlist); return PL_DHASH_NEXT; }
SharedTextureHandle CreateSharedHandle() { MutexAutoLock lock(mLock); if (!EnsureGLContext()) return 0; if (mTextureInfo.mWidth == 0 || mTextureInfo.mHeight == 0) return 0; SharedTextureHandle handle = sPluginContext->CreateSharedHandle(GLContext::SameProcess, (void*)mTextureInfo.mTexture, GLContext::TextureID); // We want forget about this now, so delete the texture. Assigning it to zero // ensures that we create a new one in Lock() sPluginContext->fDeleteTextures(1, &mTextureInfo.mTexture); mTextureInfo.mTexture = 0; return handle; }
nsEventStatus InputQueue::ReceiveScrollWheelInput(const nsRefPtr<AsyncPanZoomController>& aTarget, bool aTargetConfirmed, const ScrollWheelInput& aEvent, uint64_t* aOutInputBlockId) { WheelBlockState* block = nullptr; if (!mInputBlockQueue.IsEmpty()) { block = mInputBlockQueue.LastElement()->AsWheelBlock(); // If the block is not accepting new events we'll create a new input block // (and therefore a new wheel transaction). if (block && (!block->ShouldAcceptNewEvent() || block->MaybeTimeout(aEvent))) { block = nullptr; } } MOZ_ASSERT(!block || block->InTransaction()); if (!block) { block = new WheelBlockState(aTarget, aTargetConfirmed, aEvent); INPQ_LOG("started new scroll wheel block %p for target %p\n", block, aTarget.get()); SweepDepletedBlocks(); mInputBlockQueue.AppendElement(block); CancelAnimationsForNewBlock(block); MaybeRequestContentResponse(aTarget, block); } else { INPQ_LOG("received new event in block %p\n", block); } if (aOutInputBlockId) { *aOutInputBlockId = block->GetBlockId(); } block->Update(aEvent); // Note that the |aTarget| the APZCTM sent us may contradict the confirmed // target set on the block. In this case the confirmed target (which may be // null) should take priority. This is equivalent to just always using the // target (confirmed or not) from the block, which is what // MaybeHandleCurrentBlock() does. if (!MaybeHandleCurrentBlock(block, aEvent)) { block->AddEvent(aEvent.AsScrollWheelInput()); } return nsEventStatus_eConsumeDoDefault; }
static PLDHashOperator FlushSkinSheets(nsIURI* aKey, nsRefPtr<nsCSSStyleSheet>& aSheet, void* aClosure) { nsCAutoString str; aSheet->GetSheetURI()->GetPath(str); PLDHashOperator ret = PL_DHASH_NEXT; if (!strncmp(str.get(), "/skin", 5)) { // This is a skin binding. Add the key to the list. ret = PL_DHASH_REMOVE; } return ret; }
NS_IMPL_CYCLE_COLLECTION_UNLINK_END PLDHashOperator TraverseMapEntry(nsAttrHashKey::KeyType aKey, nsRefPtr<Attr>& aData, void* aUserArg) { nsCycleCollectionTraversalCallback *cb = static_cast<nsCycleCollectionTraversalCallback*>(aUserArg); cb->NoteXPCOMChild(static_cast<nsINode*>(aData.get())); return PL_DHASH_NEXT; }
nsresult nsPluginNativeWindowQt::CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance) { if (aPluginInstance) { if (type == NPWindowTypeWindow) { return NS_ERROR_FAILURE; } // NPWindowTypeWindow aPluginInstance->SetWindow(this); } else if (mPluginInstance) mPluginInstance->SetWindow(nullptr); SetPluginInstance(aPluginInstance); return NS_OK; }
// This may be called before or after OnLookupComplete void PendingPACQuery::Complete(nsresult status, const nsCString &pacString) { if (!mCallback) return; mCallback->OnQueryComplete(status, pacString); mCallback = nsnull; if (mDNSRequest) { mDNSRequest->Cancel(NS_ERROR_ABORT); mDNSRequest = nsnull; } }
NS_IMETHODIMP CompareNetwork::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext) { AssertIsOnMainThread(); // If no channel, Abort() has been called. if (!mChannel) { return NS_OK; } #ifdef DEBUG nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest); MOZ_ASSERT(channel == mChannel); #endif mManager->InitChannelInfo(mChannel); nsresult rv = mManager->SetPrincipalInfo(mChannel); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } return NS_OK; }
nsresult PluginStreamListener::SetupPlugin() { NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE); mPluginDoc->StartLayout(); nsCOMPtr<nsIContent> embed = mPluginDoc->GetPluginContent(); // Now we have a frame for our <embed>, start the load nsCOMPtr<nsIPresShell> shell = mDocument->GetShell(); if (!shell) { // Can't instantiate w/o a shell mPluginDoc->AllowNormalInstantiation(); return NS_BINDING_ABORTED; } // Flush out layout before we go to instantiate, because some // plug-ins depend on NPP_SetWindow() being called early enough and // nsObjectFrame does that at the end of reflow. shell->FlushPendingNotifications(Flush_Layout); nsCOMPtr<nsIObjectLoadingContent> olc(do_QueryInterface(embed)); if (!olc) { return NS_ERROR_UNEXPECTED; } nsObjectLoadingContent* olcc = static_cast<nsObjectLoadingContent*>(olc.get()); nsresult rv = olcc->InstantiatePluginInstance(); if (NS_FAILED(rv)) { return rv; } // Now that we're done, allow normal instantiation in the future // (say if there's a reframe of this entire presentation). mPluginDoc->AllowNormalInstantiation(); return NS_OK; }
NS_IMETHODIMP nsUrlClassifierLookupCallback::LookupComplete(nsTArray<LookupResult>* results) { NS_ASSERTION(mResults == nsnull, "Should only get one set of results per nsUrlClassifierLookupCallback!"); if (!results) { HandleResults(); return NS_OK; } mResults = results; // Check the results entries that need to be completed. for (PRUint32 i = 0; i < results->Length(); i++) { LookupResult& result = results->ElementAt(i); // We will complete partial matches and matches that are stale. if (!result.Confirmed()) { nsCOMPtr<nsIUrlClassifierHashCompleter> completer; if (mDBService->GetCompleter(result.mTableName, getter_AddRefs(completer))) { nsCAutoString partialHash; partialHash.Assign(reinterpret_cast<char*>(&result.hash.prefix), PREFIX_SIZE); nsresult rv = completer->Complete(partialHash, this); if (NS_SUCCEEDED(rv)) { mPendingCompletions++; } } else { // For tables with no hash completer, a complete hash match is // good enough, we'll consider it fresh. if (result.Complete()) { result.mFresh = true; } else { NS_WARNING("Partial match in a table without a valid completer, ignoring partial match."); } } } } if (mPendingCompletions == 0) { // All results were complete, we're ready! HandleResults(); } return NS_OK; }