Bug 809756 - Backout bug 803665, bug 803668, bug 803666 and bug 803669 on a CLOSED TREE.

This commit is contained in:
Ms2ger 2012-11-08 09:20:25 +01:00
parent dfb7fa0bf4
commit e7adc51bbe
8 changed files with 199 additions and 163 deletions

View File

@ -533,14 +533,6 @@ private:
NS_IMPL_ISUPPORTS2(nsGlobalWindowObserver, nsIObserver, nsIInterfaceRequestor)
nsTimeout::nsTimeout()
: mCleared(false),
mRunning(false),
mIsInterval(false),
mPublicId(0),
mInterval(0),
mFiringDepth(0),
mNestingLevel(0),
mPopupState(openAllowed)
{
#ifdef DEBUG_jst
{
@ -550,6 +542,8 @@ nsTimeout::nsTimeout()
}
#endif
memset(this, 0, sizeof(*this));
MOZ_COUNT_CTOR(nsTimeout);
}
@ -729,6 +723,9 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
// Initialize the PRCList (this).
PR_INIT_CLIST(this);
// Initialize timeout storage
PR_INIT_CLIST(&mTimeouts);
if (aOuterWindow) {
// |this| is an inner window, add this inner window to the outer
// window list of inners.
@ -1317,9 +1314,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mListenerManager,
nsEventListenerManager)
for (nsTimeout* timeout = tmp->mTimeouts.getFirst();
timeout;
timeout = timeout->getNext()) {
for (nsTimeout* timeout = tmp->FirstTimeout();
tmp->IsTimeout(timeout);
timeout = timeout->Next()) {
cb.NoteNativeChild(timeout, NS_CYCLE_COLLECTION_PARTICIPANT(nsTimeout));
}
@ -1424,9 +1421,9 @@ nsGlobalWindow::IsBlackForCC()
void
nsGlobalWindow::UnmarkGrayTimers()
{
for (nsTimeout* timeout = mTimeouts.getFirst();
timeout;
timeout = timeout->getNext()) {
for (nsTimeout* timeout = FirstTimeout();
timeout && IsTimeout(timeout);
timeout = timeout->Next()) {
if (timeout->mScriptHandler) {
JSObject* o = timeout->mScriptHandler->GetScriptObject();
xpc_UnmarkGrayObject(o);
@ -2316,7 +2313,8 @@ nsGlobalWindow::DetachFromDocShell()
// (mJSObject) so that it can be retrieved later (until it is
// finalized by the JS GC).
NS_ASSERTION(mTimeouts.isEmpty(), "Uh, outer window holds timeouts!");
NS_ASSERTION(PR_CLIST_IS_EMPTY(&mTimeouts),
"Uh, outer window holds timeouts!");
// Call FreeInnerObjects on all inner windows, not just the current
// one, since some could be held by WindowStateHolder objects that
@ -9901,7 +9899,7 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
// timeout events fire "early", so we need to test the timer as well
// as the deadline.
last_expired_timeout = nullptr;
for (timeout = mTimeouts.getFirst(); timeout; timeout = timeout->getNext()) {
for (timeout = FirstTimeout(); IsTimeout(timeout); timeout = timeout->Next()) {
if (((timeout == aTimeout) || (timeout->mWhen <= deadline)) &&
(timeout->mFiringDepth == 0)) {
// Mark any timeouts that are on the list to be fired with the
@ -9935,7 +9933,7 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
// list for any timeouts inserted as a result of running a timeout.
dummy_timeout.mFiringDepth = firingDepth;
dummy_timeout.mWhen = now;
last_expired_timeout->setNext(&dummy_timeout);
PR_INSERT_AFTER(&dummy_timeout, last_expired_timeout);
// Don't let ClearWindowTimeouts throw away our stack-allocated
// dummy timeout.
@ -9949,10 +9947,10 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
Telemetry::AutoCounter<Telemetry::DOM_TIMERS_FIRED_PER_NATIVE_TIMEOUT> timeoutsRan;
for (timeout = mTimeouts.getFirst();
for (timeout = FirstTimeout();
timeout != &dummy_timeout && !IsFrozen();
timeout = nextTimeout) {
nextTimeout = timeout->getNext();
nextTimeout = timeout->Next();
if (timeout->mFiringDepth != firingDepth) {
// We skip the timeout since it's on the list to run at another
@ -10016,9 +10014,9 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
// Running a timeout can cause another timeout to be deleted, so
// we need to reset the pointer to the following timeout.
nextTimeout = timeout->getNext();
nextTimeout = timeout->Next();
timeout->remove();
PR_REMOVE_LINK(timeout);
if (needsReinsertion) {
// Insert interval timeout onto list sorted in deadline order.
@ -10031,7 +10029,7 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
}
// Take the dummy timeout off the head of the list
dummy_timeout.remove();
PR_REMOVE_LINK(&dummy_timeout);
mTimeoutInsertionPoint = last_insertion_point;
}
@ -10069,7 +10067,9 @@ nsGlobalWindow::ClearTimeoutOrInterval(int32_t aTimerID)
uint32_t public_id = (uint32_t)aTimerID;
nsTimeout *timeout;
for (timeout = mTimeouts.getFirst(); timeout; timeout = timeout->getNext()) {
for (timeout = FirstTimeout();
IsTimeout(timeout);
timeout = timeout->Next()) {
if (timeout->mPublicId == public_id) {
if (timeout->mRunning) {
/* We're running from inside the timeout. Mark this
@ -10079,7 +10079,7 @@ nsGlobalWindow::ClearTimeoutOrInterval(int32_t aTimerID)
}
else {
/* Delete the timeout from the pending timeout list */
timeout->remove();
PR_REMOVE_LINK(timeout);
if (timeout->mTimer) {
timeout->mTimer->Cancel();
@ -10114,13 +10114,13 @@ nsresult nsGlobalWindow::ResetTimersForNonBackgroundWindow()
// start at the timer after mTimeoutInsertionPoint, if there is one.
// Otherwise, start at the beginning of the list.
for (nsTimeout *timeout = mTimeoutInsertionPoint ?
mTimeoutInsertionPoint->getNext() : mTimeouts.getFirst();
timeout; ) {
mTimeoutInsertionPoint->Next() : FirstTimeout();
IsTimeout(timeout); ) {
// It's important that this check be <= so that we guarantee that
// taking NS_MAX with |now| won't make a quantity equal to
// timeout->mWhen below.
if (timeout->mWhen <= now) {
timeout = timeout->getNext();
timeout = timeout->Next();
continue;
}
@ -10157,14 +10157,14 @@ nsresult nsGlobalWindow::ResetTimersForNonBackgroundWindow()
// Get the pointer to the next timeout now, before we move the
// current timeout in the list.
nsTimeout* nextTimeout = timeout->getNext();
nsTimeout* nextTimeout = timeout->Next();
// It is safe to remove and re-insert because mWhen is now
// strictly smaller than it used to be, so we know we'll insert
// |timeout| before nextTimeout.
NS_ASSERTION(!nextTimeout ||
NS_ASSERTION(!IsTimeout(nextTimeout) ||
timeout->mWhen < nextTimeout->mWhen, "How did that happen?");
timeout->remove();
PR_REMOVE_LINK(timeout);
// InsertTimeoutIntoList will addref |timeout| and reset
// mFiringDepth. Make sure to undo that after calling it.
uint32_t firingDepth = timeout->mFiringDepth;
@ -10181,7 +10181,7 @@ nsresult nsGlobalWindow::ResetTimersForNonBackgroundWindow()
timeout = nextTimeout;
} else {
timeout = timeout->getNext();
timeout = timeout->Next();
}
}
@ -10193,7 +10193,7 @@ nsGlobalWindow::ClearAllTimeouts()
{
nsTimeout *timeout, *nextTimeout;
for (timeout = mTimeouts.getFirst(); timeout; timeout = nextTimeout) {
for (timeout = FirstTimeout(); IsTimeout(timeout); timeout = nextTimeout) {
/* If RunTimeout() is higher up on the stack for this
window, e.g. as a result of document.write from a timeout,
then we need to reset the list insertion point for
@ -10202,7 +10202,7 @@ nsGlobalWindow::ClearAllTimeouts()
if (mRunningTimeout == timeout)
mTimeoutInsertionPoint = nullptr;
nextTimeout = timeout->getNext();
nextTimeout = timeout->Next();
if (timeout->mTimer) {
timeout->mTimer->Cancel();
@ -10222,7 +10222,7 @@ nsGlobalWindow::ClearAllTimeouts()
}
// Clear out our list
mTimeouts.clear();
PR_INIT_CLIST(&mTimeouts);
}
void
@ -10235,23 +10235,19 @@ nsGlobalWindow::InsertTimeoutIntoList(nsTimeout *aTimeout)
// mTimeoutInsertionPoint, though. This optimizes for the common case of
// insertion at the end.
nsTimeout* prevSibling;
for (prevSibling = mTimeouts.getLast();
prevSibling && prevSibling != mTimeoutInsertionPoint &&
for (prevSibling = LastTimeout();
IsTimeout(prevSibling) && prevSibling != mTimeoutInsertionPoint &&
// This condition needs to match the one in SetTimeoutOrInterval that
// determines whether to set mWhen or mTimeRemaining.
((IsFrozen() || mTimeoutsSuspendDepth) ?
prevSibling->mTimeRemaining > aTimeout->mTimeRemaining :
prevSibling->mWhen > aTimeout->mWhen);
prevSibling = prevSibling->getPrevious()) {
prevSibling = prevSibling->Prev()) {
/* Do nothing; just searching */
}
// Now link in aTimeout after prevSibling.
if (prevSibling) {
prevSibling->setNext(aTimeout);
} else {
mTimeouts.insertFront(aTimeout);
}
PR_INSERT_AFTER(aTimeout, prevSibling);
aTimeout->mFiringDepth = 0;
@ -10543,7 +10539,7 @@ nsGlobalWindow::SuspendTimeouts(uint32_t aIncrease,
mozilla::dom::workers::SuspendWorkersForWindow(cx, this);
TimeStamp now = TimeStamp::Now();
for (nsTimeout *t = mTimeouts.getFirst(); t; t = t->getNext()) {
for (nsTimeout *t = FirstTimeout(); IsTimeout(t); t = t->Next()) {
// Set mTimeRemaining to be the time remaining for this timer.
if (t->mWhen > now)
t->mTimeRemaining = t->mWhen - now;
@ -10631,7 +10627,7 @@ nsGlobalWindow::ResumeTimeouts(bool aThawChildren)
bool _seenDummyTimeout = false;
#endif
for (nsTimeout *t = mTimeouts.getFirst(); t; t = t->getNext()) {
for (nsTimeout *t = FirstTimeout(); IsTimeout(t); t = t->Next()) {
// There's a chance we're being called with RunTimeout on the stack in which
// case we have a dummy timeout in the list that *must not* be resumed. It
// can be identified by a null mWindow.

View File

@ -59,7 +59,6 @@
#include "nsIContent.h"
#include "nsIIDBFactory.h"
#include "nsFrameMessageManager.h"
#include "mozilla/LinkedList.h"
#include "mozilla/TimeStamp.h"
#include "nsIDOMTouchEvent.h"
#include "nsIInlineEventHandlers.h"
@ -135,7 +134,7 @@ NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow,
* timeout. Holds a strong reference to an nsIScriptTimeoutHandler, which
* abstracts the language specific cruft.
*/
struct nsTimeout : mozilla::LinkedListElement<nsTimeout>
struct nsTimeout : PRCList
{
nsTimeout();
~nsTimeout();
@ -145,6 +144,16 @@ struct nsTimeout : mozilla::LinkedListElement<nsTimeout>
nsrefcnt Release();
nsrefcnt AddRef();
nsTimeout* Next() {
// Note: might not actually return an nsTimeout. Use IsTimeout to check.
return static_cast<nsTimeout*>(PR_NEXT_LINK(this));
}
nsTimeout* Prev() {
// Note: might not actually return an nsTimeout. Use IsTimeout to check.
return static_cast<nsTimeout*>(PR_PREV_LINK(this));
}
nsresult InitTimer(nsTimerCallbackFunc aFunc, uint64_t delay) {
return mTimer->InitWithFuncCallback(aFunc, this, delay,
nsITimer::TYPE_ONE_SHOT);
@ -863,6 +872,20 @@ protected:
bool IsInModalState();
nsTimeout* FirstTimeout() {
// Note: might not actually return an nsTimeout. Use IsTimeout to check.
return static_cast<nsTimeout*>(PR_LIST_HEAD(&mTimeouts));
}
nsTimeout* LastTimeout() {
// Note: might not actually return an nsTimeout. Use IsTimeout to check.
return static_cast<nsTimeout*>(PR_LIST_TAIL(&mTimeouts));
}
bool IsTimeout(PRCList* aList) {
return aList != &mTimeouts;
}
// Convenience functions for the many methods that need to scale
// from device to CSS pixels or vice versa. Note: if a presentation
// context is not available, they will assume a 1:1 ratio.
@ -1030,7 +1053,7 @@ protected:
// non-null. In that case, the dummy timeout pointed to by
// mTimeoutInsertionPoint may have a later mWhen than some of the timeouts
// that come after it.
mozilla::LinkedList<nsTimeout> mTimeouts;
PRCList mTimeouts;
// If mTimeoutInsertionPoint is non-null, insertions should happen after it.
// This is a dummy timeout at the moment; if that ever changes, the logic in
// ResetTimersForNonBackgroundWindow needs to change.

View File

@ -501,7 +501,8 @@ nsresult nsExtensibleStringBundle::GetSimpleEnumeration(nsISimpleEnumerator ** a
#define MAX_CACHED_BUNDLES 16
struct bundleCacheEntry_t : public LinkedListElement<bundleCacheEntry_t> {
struct bundleCacheEntry_t {
PRCList list;
nsCStringKey *mHashKey;
// do not use a nsCOMPtr - this is a struct not a class!
nsIStringBundle* mBundle;
@ -515,6 +516,7 @@ nsStringBundleService::nsStringBundleService() :
printf("\n++ nsStringBundleService::nsStringBundleService ++\n");
#endif
PR_INIT_CLIST(&mBundleCache);
PL_InitArenaPool(&mCacheEntryPool, "srEntries",
sizeof(bundleCacheEntry_t)*MAX_CACHED_BUNDLES,
sizeof(bundleCacheEntry_t));
@ -580,10 +582,16 @@ nsStringBundleService::flushBundleCache()
// release all bundles in the cache
mBundleMap.Reset();
while (!mBundleCache.isEmpty()) {
bundleCacheEntry_t *cacheEntry = mBundleCache.popFirst();
PRCList *current = PR_LIST_HEAD(&mBundleCache);
while (current != &mBundleCache) {
bundleCacheEntry_t *cacheEntry = (bundleCacheEntry_t*)current;
recycleEntry(cacheEntry);
PRCList *oldItem = current;
current = PR_NEXT_LINK(current);
// will be freed in PL_FreeArenaPool
PR_REMOVE_LINK(oldItem);
}
PL_FreeArenaPool(&mCacheEntryPool);
}
@ -608,7 +616,7 @@ nsStringBundleService::getStringBundle(const char *aURLSpec,
// cache hit!
// remove it from the list, it will later be reinserted
// at the head of the list
cacheEntry->remove();
PR_REMOVE_LINK((PRCList*)cacheEntry);
} else {
@ -625,7 +633,8 @@ nsStringBundleService::getStringBundle(const char *aURLSpec,
// at this point the cacheEntry should exist in the hashtable,
// but is not in the LRU cache.
// put the cache entry at the front of the list
mBundleCache.insertFront(cacheEntry);
PR_INSERT_LINK((PRCList *)cacheEntry, &mBundleCache);
// finally, return the value
*aResult = cacheEntry->mBundle;
@ -645,12 +654,12 @@ nsStringBundleService::insertIntoCache(nsIStringBundle* aBundle,
void *cacheEntryArena;
PL_ARENA_ALLOCATE(cacheEntryArena, &mCacheEntryPool, sizeof(bundleCacheEntry_t));
cacheEntry = new (cacheEntryArena) bundleCacheEntry_t();
cacheEntry = (bundleCacheEntry_t*)cacheEntryArena;
} else {
// cache is full
// take the last entry in the list, and recycle it.
cacheEntry = mBundleCache.getLast();
cacheEntry = (bundleCacheEntry_t*)PR_LIST_TAIL(&mBundleCache);
// remove it from the hash table and linked list
NS_ASSERTION(mBundleMap.Exists(cacheEntry->mHashKey),
@ -661,7 +670,7 @@ nsStringBundleService::insertIntoCache(nsIStringBundle* aBundle,
aHashKey->GetString()).get());
#endif
mBundleMap.Remove(cacheEntry->mHashKey);
cacheEntry->remove();
PR_REMOVE_LINK((PRCList*)cacheEntry);
// free up excess memory
recycleEntry(cacheEntry);

View File

@ -6,6 +6,7 @@
#ifndef nsStringBundleService_h__
#define nsStringBundleService_h__
#include "prclist.h"
#include "plarena.h"
#include "nsCOMPtr.h"
@ -17,8 +18,6 @@
#include "nsIErrorService.h"
#include "nsIStringBundleOverride.h"
#include "mozilla/LinkedList.h"
struct bundleCacheEntry_t;
class nsStringBundleService : public nsIStringBundleService,
@ -49,7 +48,7 @@ private:
static void recycleEntry(bundleCacheEntry_t*);
nsHashtable mBundleMap;
mozilla::LinkedList<bundleCacheEntry_t> mBundleCache;
PRCList mBundleCache;
PLArenaPool mCacheEntryPool;
nsCOMPtr<nsIErrorService> mErrorService;

View File

@ -9,7 +9,7 @@
#include "nsString.h"
#include "nsUnicharUtils.h" // for nsCaseInsensitiveStringComparator
#include "mozilla/LinkedList.h"
#include "prclist.h"
/**
@ -60,7 +60,7 @@ class nsScannerBufferList
* of the data segment is determined by increment the |this| pointer
* by 1 unit.
*/
class Buffer : public mozilla::LinkedListElement<Buffer>
class Buffer : public PRCList
{
public:
@ -75,11 +75,11 @@ class nsScannerBufferList
const PRUnichar* DataEnd() const { return mDataEnd; }
PRUnichar* DataEnd() { return mDataEnd; }
const Buffer* Next() const { return getNext(); }
Buffer* Next() { return getNext(); }
const Buffer* Next() const { return static_cast<const Buffer*>(next); }
Buffer* Next() { return static_cast<Buffer*>(next); }
const Buffer* Prev() const { return getPrevious(); }
Buffer* Prev() { return getPrevious(); }
const Buffer* Prev() const { return static_cast<const Buffer*>(prev); }
Buffer* Prev() { return static_cast<Buffer*>(prev); }
uint32_t DataLength() const { return mDataEnd - DataStart(); }
void SetDataLength(uint32_t len) { mDataEnd = DataStart() + len; }
@ -126,22 +126,23 @@ class nsScannerBufferList
nsScannerBufferList( Buffer* buf )
: mRefCnt(0)
{
mBuffers.insertBack(buf);
PR_INIT_CLIST(&mBuffers);
PR_APPEND_LINK(buf, &mBuffers);
}
void AddRef() { ++mRefCnt; }
void Release() { if (--mRefCnt == 0) delete this; }
void Append( Buffer* buf ) { mBuffers.insertBack(buf); }
void InsertAfter( Buffer* buf, Buffer* prev ) { prev->setNext(buf); }
void Append( Buffer* buf ) { PR_APPEND_LINK(buf, &mBuffers); }
void InsertAfter( Buffer* buf, Buffer* prev ) { PR_INSERT_AFTER(buf, prev); }
void SplitBuffer( const Position& );
void DiscardUnreferencedPrefix( Buffer* );
Buffer* Head() { return mBuffers.getFirst(); }
const Buffer* Head() const { return mBuffers.getFirst(); }
Buffer* Head() { return static_cast<Buffer*>(PR_LIST_HEAD(&mBuffers)); }
const Buffer* Head() const { return static_cast<const Buffer*>(PR_LIST_HEAD(&mBuffers)); }
Buffer* Tail() { return mBuffers.getLast(); }
const Buffer* Tail() const { return mBuffers.getLast(); }
Buffer* Tail() { return static_cast<Buffer*>(PR_LIST_TAIL(&mBuffers)); }
const Buffer* Tail() const { return static_cast<const Buffer*>(PR_LIST_TAIL(&mBuffers)); }
private:
@ -151,7 +152,7 @@ class nsScannerBufferList
void ReleaseAll();
int32_t mRefCnt;
mozilla::LinkedList<Buffer> mBuffers;
PRCList mBuffers;
};

View File

@ -19,13 +19,25 @@ nsScannerBufferList::Buffer*
nsScannerBufferList::AllocBufferFromString( const nsAString& aString )
{
uint32_t len = aString.Length();
Buffer* buf = AllocBuffer(len);
if (len > MAX_CAPACITY)
return nullptr;
Buffer* buf = (Buffer*) malloc(sizeof(Buffer) + (len + 1) * sizeof(PRUnichar));
if (buf)
{
// leave PRCList members of Buffer uninitialized
buf->mUsageCount = 0;
buf->mDataEnd = buf->DataStart() + len;
nsAString::const_iterator source;
aString.BeginReading(source);
nsCharTraits<PRUnichar>::copy(buf->DataStart(), source.get(), len);
// XXX null terminate. this shouldn't be required, but we do it because
// nsScanner erroneously thinks it can dereference DataEnd :-(
*buf->mDataEnd = PRUnichar(0);
}
return buf;
}
@ -36,29 +48,30 @@ nsScannerBufferList::AllocBuffer( uint32_t capacity )
if (capacity > MAX_CAPACITY)
return nullptr;
void* ptr = malloc(sizeof(Buffer) + (capacity + 1) * sizeof(PRUnichar));
if (!ptr)
return nullptr;
Buffer* buf = (Buffer*) malloc(sizeof(Buffer) + (capacity + 1) * sizeof(PRUnichar));
if (buf)
{
// leave PRCList members of Buffer uninitialized
Buffer* buf = new (ptr) Buffer();
buf->mUsageCount = 0;
buf->mDataEnd = buf->DataStart() + capacity;
buf->mUsageCount = 0;
buf->mDataEnd = buf->DataStart() + capacity;
// XXX null terminate. this shouldn't be required, but we do it because
// nsScanner erroneously thinks it can dereference DataEnd :-(
*buf->mDataEnd = PRUnichar(0);
// XXX null terminate. this shouldn't be required, but we do it because
// nsScanner erroneously thinks it can dereference DataEnd :-(
*buf->mDataEnd = PRUnichar(0);
}
return buf;
}
void
nsScannerBufferList::ReleaseAll()
{
while (!mBuffers.isEmpty())
while (!PR_CLIST_IS_EMPTY(&mBuffers))
{
Buffer* node = mBuffers.popFirst();
PRCList* node = PR_LIST_HEAD(&mBuffers);
PR_REMOVE_LINK(node);
//printf(">>> freeing buffer @%p\n", node);
free(node);
free(static_cast<Buffer*>(node));
}
}
@ -93,10 +106,10 @@ nsScannerBufferList::DiscardUnreferencedPrefix( Buffer* aBuf )
{
if (aBuf == Head())
{
while (!mBuffers.isEmpty() && !Head()->IsInUse())
while (!PR_CLIST_IS_EMPTY(&mBuffers) && !Head()->IsInUse())
{
Buffer* buffer = Head();
buffer->remove();
PR_REMOVE_LINK(buffer);
free(buffer);
}
}
@ -263,7 +276,7 @@ nsScannerSubstring::GetNextFragment( nsScannerFragment& frag ) const
if (frag.mBuffer == mEnd.mBuffer)
return false;
frag.mBuffer = frag.mBuffer->getNext();
frag.mBuffer = static_cast<const Buffer*>(PR_NEXT_LINK(frag.mBuffer));
if (frag.mBuffer == mStart.mBuffer)
frag.mFragmentStart = mStart.mPosition;
@ -285,7 +298,7 @@ nsScannerSubstring::GetPrevFragment( nsScannerFragment& frag ) const
if (frag.mBuffer == mStart.mBuffer)
return false;
frag.mBuffer = frag.mBuffer->getPrevious();
frag.mBuffer = static_cast<const Buffer*>(PR_PREV_LINK(frag.mBuffer));
if (frag.mBuffer == mStart.mBuffer)
frag.mFragmentStart = mStart.mPosition;

View File

@ -62,21 +62,64 @@ void GetURIStringFromRequest(nsIRequest* request, nsACString &name)
}
#endif /* DEBUG */
struct nsStatusInfo : public PRCList
{
nsString mStatusMessage;
nsresult mStatusCode;
// Weak mRequest is ok; we'll be told if it decides to go away.
nsIRequest * const mRequest;
nsStatusInfo(nsIRequest *aRequest) :
mRequest(aRequest)
{
MOZ_COUNT_CTOR(nsStatusInfo);
PR_INIT_CLIST(this);
}
~nsStatusInfo()
{
MOZ_COUNT_DTOR(nsStatusInfo);
PR_REMOVE_LINK(this);
}
};
struct nsRequestInfo : public PLDHashEntryHdr
{
nsRequestInfo(const void *key)
: mKey(key), mCurrentProgress(0), mMaxProgress(0), mUploading(false)
, mLastStatus(nullptr)
{
MOZ_COUNT_CTOR(nsRequestInfo);
}
~nsRequestInfo()
{
MOZ_COUNT_DTOR(nsRequestInfo);
}
nsIRequest* Request() {
return static_cast<nsIRequest*>(const_cast<void*>(mKey));
}
const void* mKey; // Must be first for the pldhash stubs to work
int64_t mCurrentProgress;
int64_t mMaxProgress;
bool mUploading;
nsAutoPtr<nsStatusInfo> mLastStatus;
};
bool
nsDocLoader::RequestInfoHashInitEntry(PLDHashTable* table,
PLDHashEntryHdr* entry,
const void* key)
static bool
RequestInfoHashInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
const void *key)
{
// Initialize the entry with placement new
new (entry) nsRequestInfo(key);
return true;
}
void
nsDocLoader::RequestInfoHashClearEntry(PLDHashTable* table,
PLDHashEntryHdr* entry)
static void
RequestInfoHashClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
{
nsRequestInfo* info = static_cast<nsRequestInfo *>(entry);
info->~nsRequestInfo();
@ -135,6 +178,8 @@ nsDocLoader::nsDocLoader()
ClearInternalProgress();
PR_INIT_CLIST(&mStatusInfoList);
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
("DocLoader:%p: created.\n", this));
}
@ -847,8 +892,9 @@ void nsDocLoader::doStopURLLoad(nsIRequest *request, nsresult aStatus)
// Fire a status change message for the most recent unfinished
// request to make sure that the displayed status is not outdated.
if (!mStatusInfoList.isEmpty()) {
nsStatusInfo* statusInfo = mStatusInfoList.getFirst();
if (!PR_CLIST_IS_EMPTY(&mStatusInfoList)) {
nsStatusInfo* statusInfo =
static_cast<nsStatusInfo*>(PR_LIST_HEAD(&mStatusInfoList));
FireOnStatusChange(this, statusInfo->mRequest,
statusInfo->mStatusCode,
statusInfo->mStatusMessage.get());
@ -1133,12 +1179,12 @@ NS_IMETHODIMP nsDocLoader::OnStatus(nsIRequest* aRequest, nsISupports* ctxt,
} else {
// We're going to move it to the front of the list, so remove
// it from wherever it is now.
info->mLastStatus->remove();
PR_REMOVE_LINK(info->mLastStatus);
}
info->mLastStatus->mStatusMessage = msg;
info->mLastStatus->mStatusCode = aStatus;
// Put the info at the front of the list
mStatusInfoList.insertFront(info->mLastStatus);
PR_INSERT_LINK(info->mLastStatus, &mStatusInfoList);
}
FireOnStatusChange(this, aRequest, aStatus, msg);
}
@ -1489,10 +1535,10 @@ void nsDocLoader::RemoveRequestInfo(nsIRequest *aRequest)
PL_DHashTableOperate(&mRequestInfoHash, aRequest, PL_DHASH_REMOVE);
}
nsDocLoader::nsRequestInfo* nsDocLoader::GetRequestInfo(nsIRequest* aRequest)
nsRequestInfo * nsDocLoader::GetRequestInfo(nsIRequest *aRequest)
{
nsRequestInfo* info =
static_cast<nsRequestInfo*>
nsRequestInfo *info =
static_cast<nsRequestInfo *>
(PL_DHashTableOperate(&mRequestInfoHash, aRequest,
PL_DHASH_LOOKUP));
@ -1528,12 +1574,12 @@ void nsDocLoader::ClearRequestInfoHash(void)
}
// PLDHashTable enumeration callback that calculates the max progress.
PLDHashOperator
nsDocLoader::CalcMaxProgressCallback(PLDHashTable* table, PLDHashEntryHdr* hdr,
uint32_t number, void* arg)
static PLDHashOperator
CalcMaxProgressCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
uint32_t number, void *arg)
{
const nsRequestInfo* info = static_cast<const nsRequestInfo*>(hdr);
int64_t* max = static_cast<int64_t* >(arg);
const nsRequestInfo *info = static_cast<const nsRequestInfo *>(hdr);
int64_t *max = static_cast<int64_t *>(arg);
if (info->mMaxProgress < info->mCurrentProgress) {
*max = int64_t(-1);

View File

@ -27,10 +27,10 @@
#include "nsISupportsPriority.h"
#include "nsCOMPtr.h"
#include "pldhash.h"
#include "prclist.h"
#include "nsAutoPtr.h"
#include "mozilla/LinkedList.h"
struct nsRequestInfo;
struct nsListenerInfo;
/****************************************************************************
@ -194,54 +194,6 @@ protected:
}
protected:
struct nsStatusInfo : public mozilla::LinkedListElement<nsStatusInfo>
{
nsString mStatusMessage;
nsresult mStatusCode;
// Weak mRequest is ok; we'll be told if it decides to go away.
nsIRequest * const mRequest;
nsStatusInfo(nsIRequest* aRequest) :
mRequest(aRequest)
{
MOZ_COUNT_CTOR(nsStatusInfo);
}
~nsStatusInfo()
{
MOZ_COUNT_DTOR(nsStatusInfo);
}
};
struct nsRequestInfo : public PLDHashEntryHdr
{
nsRequestInfo(const void* key)
: mKey(key), mCurrentProgress(0), mMaxProgress(0), mUploading(false)
, mLastStatus(nullptr)
{
MOZ_COUNT_CTOR(nsRequestInfo);
}
~nsRequestInfo()
{
MOZ_COUNT_DTOR(nsRequestInfo);
}
nsIRequest* Request() {
return static_cast<nsIRequest*>(const_cast<void*>(mKey));
}
const void* mKey; // Must be first for the pldhash stubs to work
int64_t mCurrentProgress;
int64_t mMaxProgress;
bool mUploading;
nsAutoPtr<nsStatusInfo> mLastStatus;
};
static bool RequestInfoHashInitEntry(PLDHashTable* table, PLDHashEntryHdr* entry,
const void* key);
static void RequestInfoHashClearEntry(PLDHashTable* table, PLDHashEntryHdr* entry);
// IMPORTANT: The ownership implicit in the following member
// variables has been explicitly checked and set using nsCOMPtr
// for owning pointers and raw COM interface pointers for weak
@ -271,7 +223,7 @@ protected:
PLDHashTable mRequestInfoHash;
int64_t mCompletedTotalProgress;
mozilla::LinkedList<nsStatusInfo> mStatusInfoList;
PRCList mStatusInfoList;
/*
* This flag indicates that the loader is loading a document. It is set
@ -316,9 +268,6 @@ private:
nsRequestInfo *GetRequestInfo(nsIRequest* aRequest);
void ClearRequestInfoHash();
int64_t CalculateMaxProgress();
static PLDHashOperator CalcMaxProgressCallback(PLDHashTable* table,
PLDHashEntryHdr* hdr,
uint32_t number, void* arg);
/// void DumpChannelInfo(void);
// used to clear our internal progress state between loads...