diff --git a/chrome/nsChromeRegistry.cpp b/chrome/nsChromeRegistry.cpp index 5fa1c59b98..1eb35372f0 100644 --- a/chrome/nsChromeRegistry.cpp +++ b/chrome/nsChromeRegistry.cpp @@ -414,14 +414,12 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow) nsCOMPtr shell = document->GetShell(); if (shell) { // Reload only the chrome URL agent style sheets. - nsCOMArray agentSheets; + nsTArray> agentSheets; rv = shell->GetAgentStyleSheets(agentSheets); NS_ENSURE_SUCCESS(rv, rv); - nsCOMArray newAgentSheets; - for (int32_t l = 0; l < agentSheets.Count(); ++l) { - nsIStyleSheet *sheet = agentSheets[l]; - + nsTArray> newAgentSheets; + for (CSSStyleSheet* sheet : agentSheets) { nsIURI* uri = sheet->GetSheetURI(); if (IsChromeURI(uri)) { @@ -431,12 +429,12 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow) getter_AddRefs(newSheet)); if (NS_FAILED(rv)) return rv; if (newSheet) { - rv = newAgentSheets.AppendObject(newSheet) ? NS_OK : NS_ERROR_FAILURE; + rv = newAgentSheets.AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; } } else { // Just use the same sheet. - rv = newAgentSheets.AppendObject(sheet) ? NS_OK : NS_ERROR_FAILURE; + rv = newAgentSheets.AppendElement(sheet) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; } } @@ -445,27 +443,22 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow) NS_ENSURE_SUCCESS(rv, rv); } - // Build an array of nsIURIs of style sheets we need to load. - nsCOMArray oldSheets; - nsCOMArray newSheets; - int32_t count = document->GetNumberOfStyleSheets(); - // Iterate over the style sheets. - int32_t i; - for (i = 0; i < count; i++) { - // Get the style sheet - nsIStyleSheet *styleSheet = document->GetStyleSheetAt(i); + // Build an array of style sheets we need to reload. + nsTArray> oldSheets(count); + nsTArray> newSheets(count); - if (!oldSheets.AppendObject(styleSheet)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // Iterate over the style sheets. + for (int32_t i = 0; i < count; i++) { + // Get the style sheet + CSSStyleSheet* styleSheet = document->GetStyleSheetAt(i); + oldSheets.AppendElement(styleSheet); } // Iterate over our old sheets and kick off a sync load of the new // sheet if and only if it's a chrome URL. - for (i = 0; i < count; i++) { - RefPtr sheet = do_QueryObject(oldSheets[i]); + for (CSSStyleSheet* sheet : oldSheets) { nsIURI* uri = sheet ? sheet->GetOriginalURI() : nullptr; if (uri && IsChromeURI(uri)) { @@ -475,11 +468,10 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow) // only works by sheer dumb luck. document->LoadChromeSheetSync(uri, false, getter_AddRefs(newSheet)); // Even if it's null, we put in in there. - newSheets.AppendObject(newSheet); - } - else { + newSheets.AppendElement(newSheet); + } else { // Just use the same sheet. - newSheets.AppendObject(sheet); + newSheets.AppendElement(sheet); } } diff --git a/dom/base/FileReader.cpp b/dom/base/FileReader.cpp index e6c255ee49..cabda2fe97 100644 --- a/dom/base/FileReader.cpp +++ b/dom/base/FileReader.cpp @@ -13,6 +13,7 @@ #include "nsIStreamTransportService.h" #include "mozilla/Base64.h" +#include "mozilla/CheckedInt.h" #include "mozilla/dom/DOMError.h" #include "mozilla/dom/EncodingUtils.h" #include "mozilla/dom/File.h" @@ -315,11 +316,17 @@ FileReader::DoReadData(uint64_t aCount) NS_ASSERTION(bytesRead == aCount, "failed to read data"); } else { + CheckedInt size = mDataLen; + size += aCount; + //Update memory buffer to reflect the contents of the file - if (mDataLen + aCount > UINT32_MAX) { - // PR_Realloc doesn't support over 4GB memory size even if 64-bit OS + if (!size.isValid() || + // PR_Realloc doesn't support over 4GB memory size even if 64-bit OS + size.value() > UINT32_MAX || + size.value() > mTotal) { return NS_ERROR_OUT_OF_MEMORY; } + if (mDataFormat != FILE_AS_ARRAYBUFFER) { mFileData = (char *) moz_realloc(mFileData, mDataLen + aCount); NS_ENSURE_TRUE(mFileData, NS_ERROR_OUT_OF_MEMORY); @@ -347,6 +354,14 @@ FileReader::ReadFileContent(Blob& aBlob, Abort(error); error.SuppressException(); + if (mReadyState == LOADING) { + // A nested ReadAsSomething() as been called during one of the events + // dispatched by Abort(). We have to terminate this operation in order to + // continue the nested one. + aRv.Throw(NS_ERROR_ABORT); + return; + } + mError = nullptr; SetDOMStringToNull(mResult); mTransferred = 0; diff --git a/dom/base/FormData.cpp b/dom/base/FormData.cpp index ac5396572f..fd55894bc4 100644 --- a/dom/base/FormData.cpp +++ b/dom/base/FormData.cpp @@ -23,16 +23,17 @@ FormData::FormData(nsISupports* aOwner) namespace { -already_AddRefed -GetBlobForFormDataStorage(Blob& aBlob, const Optional& aFilename, - ErrorResult& aRv) +already_AddRefed +GetOrCreateFileCalledBlob(Blob& aBlob, ErrorResult& aRv) { - if (!aFilename.WasPassed()) { - RefPtr blob = &aBlob; - return blob.forget(); + // If this is file, we can just use it + RefPtr file = aBlob.ToFile(); + if (file) { + return file.forget(); } - RefPtr file = aBlob.ToFile(aFilename.Value(), aRv); + // Forcing 'blob' as filename + file = aBlob.ToFile(NS_LITERAL_STRING("blob"), aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } @@ -40,6 +41,23 @@ GetBlobForFormDataStorage(Blob& aBlob, const Optional& aFilename, return file.forget(); } +already_AddRefed +GetBlobForFormDataStorage(Blob& aBlob, const Optional& aFilename, + ErrorResult& aRv) +{ + // Forcing a filename + if (aFilename.WasPassed()) { + RefPtr file = aBlob.ToFile(aFilename.Value(), aRv); + if (NS_WARN_IF(aRv.Failed())) { + return nullptr; + } + + return file.forget(); + } + + return GetOrCreateFileCalledBlob(aBlob, aRv); +} + } // namespace // ------------------------------------------------------------------------- @@ -102,12 +120,12 @@ FormData::Append(const nsAString& aName, Blob& aBlob, const Optional& aFilename, ErrorResult& aRv) { - RefPtr blob = GetBlobForFormDataStorage(aBlob, aFilename, aRv); + RefPtr file = GetBlobForFormDataStorage(aBlob, aFilename, aRv); if (NS_WARN_IF(aRv.Failed())) { return; } - AddNameBlobPair(aName, blob); + AddNameBlobPair(aName, file); } void @@ -165,8 +183,14 @@ FormData::AddNameBlobPair(const nsAString& aName, Blob* aBlob) { MOZ_ASSERT(aBlob); + ErrorResult rv; + RefPtr file = GetOrCreateFileCalledBlob(*aBlob, rv); + if (NS_WARN_IF(rv.Failed())) { + return rv.StealNSResult(); + } + FormDataTuple* data = mFormData.AppendElement(); - SetNameBlobPair(data, aName, aBlob); + SetNameFilePair(data, aName, file); return NS_OK; } @@ -199,12 +223,12 @@ FormData::Set(const nsAString& aName, Blob& aBlob, { FormDataTuple* tuple = RemoveAllOthersAndGetFirstFormDataTuple(aName); if (tuple) { - RefPtr blob = GetBlobForFormDataStorage(aBlob, aFilename, aRv); + RefPtr file = GetBlobForFormDataStorage(aBlob, aFilename, aRv); if (NS_WARN_IF(aRv.Failed())) { return; } - SetNameBlobPair(tuple, aName, blob); + SetNameFilePair(tuple, aName, file); } else { Append(aName, aBlob, aFilename, aRv); } @@ -253,15 +277,15 @@ FormData::SetNameValuePair(FormDataTuple* aData, } void -FormData::SetNameBlobPair(FormDataTuple* aData, +FormData::SetNameFilePair(FormDataTuple* aData, const nsAString& aName, - Blob* aBlob) + File* aFile) { MOZ_ASSERT(aData); - MOZ_ASSERT(aBlob); + MOZ_ASSERT(aFile); aData->name = aName; - aData->value.SetAsBlob() = aBlob; + aData->value.SetAsBlob() = aFile; } // ------------------------------------------------------------------------- @@ -343,20 +367,7 @@ FormData::GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength, for (uint32_t i = 0; i < mFormData.Length(); ++i) { if (mFormData[i].value.IsBlob()) { - RefPtr file = mFormData[i].value.GetAsBlob()->ToFile(); - if (file) { - fs.AddNameBlobPair(mFormData[i].name, file); - continue; - } - - ErrorResult rv; - file = - mFormData[i].value.GetAsBlob()->ToFile(NS_LITERAL_STRING("blob"), rv); - if (NS_WARN_IF(rv.Failed())) { - return rv.StealNSResult(); - } - - fs.AddNameBlobPair(mFormData[i].name, file); + fs.AddNameBlobPair(mFormData[i].name, mFormData[i].value.GetAsBlob()); } else if (mFormData[i].value.IsUSVString()) { fs.AddNameValuePair(mFormData[i].name, mFormData[i].value.GetAsUSVString()); diff --git a/dom/base/FormData.h b/dom/base/FormData.h index e50cd20960..66373730cb 100644 --- a/dom/base/FormData.h +++ b/dom/base/FormData.h @@ -47,9 +47,9 @@ private: const nsAString& aName, const nsAString& aValue); - void SetNameBlobPair(FormDataTuple* aData, + void SetNameFilePair(FormDataTuple* aData, const nsAString& aName, - Blob* aBlob); + File* aFile); public: explicit FormData(nsISupports* aOwner = nullptr); diff --git a/dom/base/WebSocket.cpp b/dom/base/WebSocket.cpp index 7c23a188b9..972e0aa77a 100644 --- a/dom/base/WebSocket.cpp +++ b/dom/base/WebSocket.cpp @@ -2121,17 +2121,6 @@ public: return true; } - bool Suspend(JSContext* aCx) override - { - { - MutexAutoLock lock(mWebSocketImpl->mMutex); - mWebSocketImpl->mWorkerShuttingDown = true; - } - - mWebSocketImpl->CloseConnection(nsIWebSocketChannel::CLOSE_GOING_AWAY); - return true; - } - private: WebSocketImpl* mWebSocketImpl; }; diff --git a/dom/base/crashtests/1230422.html b/dom/base/crashtests/1230422.html new file mode 100644 index 0000000000..fbaa63d385 --- /dev/null +++ b/dom/base/crashtests/1230422.html @@ -0,0 +1,28 @@ + + + + + + + + diff --git a/dom/base/crashtests/crashtests.list b/dom/base/crashtests/crashtests.list index a4d67018e0..73ad2f1e42 100644 --- a/dom/base/crashtests/crashtests.list +++ b/dom/base/crashtests/crashtests.list @@ -204,3 +204,4 @@ load structured_clone_container_throws.html HTTP(..) load xhr_abortinprogress.html load xhr_empty_datauri.html load xhr_html_nullresponse.html +load 1230422.html diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index b447ad2ca3..233827cdb2 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -99,7 +99,6 @@ #include "mozilla/Preferences.h" #include "nsIContentIterator.h" #include "nsIDOMStyleSheet.h" -#include "nsIStyleSheet.h" #include "nsIStyleSheetService.h" #include "nsContentPermissionHelper.h" #include "nsCSSPseudoElements.h" // for CSSPseudoElementType @@ -3381,7 +3380,7 @@ nsDOMWindowUtils::AddSheet(nsIDOMStyleSheet *aSheet, uint32_t aSheetType) NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); nsIDocument::additionalSheetType type = convertSheetType(aSheetType); - nsCOMPtr sheet = do_QueryInterface(aSheet); + RefPtr sheet = do_QueryObject(aSheet); NS_ENSURE_TRUE(sheet, NS_ERROR_FAILURE); if (sheet->GetOwningDocument()) { return NS_ERROR_INVALID_ARG; diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 88f6cd6138..22e19397cd 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -716,15 +716,6 @@ nsDOMStyleSheetList::Length() // been added or removed. if (-1 == mLength) { mLength = mDocument->GetNumberOfStyleSheets(); - -#ifdef DEBUG - int32_t i; - for (i = 0; i < mLength; i++) { - nsIStyleSheet *sheet = mDocument->GetStyleSheetAt(i); - nsCOMPtr domss(do_QueryInterface(sheet)); - NS_ASSERTION(domss, "All \"normal\" sheets implement nsIDOMStyleSheet"); - } -#endif } return mLength; } @@ -738,7 +729,7 @@ nsDOMStyleSheetList::IndexedGetter(uint32_t aIndex, bool& aFound) } aFound = true; - nsIStyleSheet *sheet = mDocument->GetStyleSheetAt(aIndex); + CSSStyleSheet* sheet = mDocument->GetStyleSheetAt(aIndex); NS_ASSERTION(sheet, "Must have a sheet"); return static_cast(sheet); @@ -751,26 +742,20 @@ nsDOMStyleSheetList::NodeWillBeDestroyed(const nsINode *aNode) } void -nsDOMStyleSheetList::StyleSheetAdded(nsIStyleSheet* aStyleSheet, +nsDOMStyleSheetList::StyleSheetAdded(CSSStyleSheet* aStyleSheet, bool aDocumentSheet) { if (aDocumentSheet && -1 != mLength) { - nsCOMPtr domss(do_QueryInterface(aStyleSheet)); - if (domss) { - mLength++; - } + mLength++; } } void -nsDOMStyleSheetList::StyleSheetRemoved(nsIStyleSheet* aStyleSheet, +nsDOMStyleSheetList::StyleSheetRemoved(CSSStyleSheet* aStyleSheet, bool aDocumentSheet) { if (aDocumentSheet && -1 != mLength) { - nsCOMPtr domss(do_QueryInterface(aStyleSheet)); - if (domss) { - mLength--; - } + mLength--; } } @@ -1333,7 +1318,7 @@ nsDOMStyleSheetSetList::EnsureFresh() int32_t count = mDocument->GetNumberOfStyleSheets(); nsAutoString title; for (int32_t index = 0; index < count; index++) { - nsIStyleSheet* sheet = mDocument->GetStyleSheetAt(index); + CSSStyleSheet* sheet = mDocument->GetStyleSheetAt(index); NS_ASSERTION(sheet, "Null sheet in sheet list!"); sheet->GetTitle(title); if (!title.IsEmpty() && !mNames.Contains(title) && !Add(title)) { @@ -1607,9 +1592,7 @@ nsDocument::~nsDocument() nsAutoScriptBlocker scriptBlocker; - int32_t indx; // must be signed - uint32_t count = mChildren.ChildCount(); - for (indx = int32_t(count) - 1; indx >= 0; --indx) { + for (uint32_t indx = mChildren.ChildCount(); indx-- != 0; ) { mChildren.ChildAt(indx)->UnbindFromTree(); mChildren.RemoveChildAt(indx); } @@ -1617,9 +1600,8 @@ nsDocument::~nsDocument() mCachedRootElement = nullptr; // Let the stylesheets know we're going away - indx = mStyleSheets.Count(); - while (--indx >= 0) { - mStyleSheets[indx]->SetOwningDocument(nullptr); + for (CSSStyleSheet* sheet : mStyleSheets) { + sheet->SetOwningDocument(nullptr); } if (mAttrStyleSheet) { mAttrStyleSheet->SetOwningDocument(nullptr); @@ -2297,9 +2279,7 @@ void nsDocument::RemoveDocStyleSheetsFromStyleSets() { // The stylesheets should forget us - int32_t indx = mStyleSheets.Count(); - while (--indx >= 0) { - nsIStyleSheet* sheet = mStyleSheets[indx]; + for (CSSStyleSheet* sheet : Reversed(mStyleSheets)) { sheet->SetOwningDocument(nullptr); if (sheet->IsApplicable()) { @@ -2313,12 +2293,12 @@ nsDocument::RemoveDocStyleSheetsFromStyleSets() } void -nsDocument::RemoveStyleSheetsFromStyleSets(nsCOMArray& aSheets, SheetType aType) +nsDocument::RemoveStyleSheetsFromStyleSets( + nsTArray>& aSheets, + SheetType aType) { // The stylesheets should forget us - int32_t indx = aSheets.Count(); - while (--indx >= 0) { - nsIStyleSheet* sheet = aSheets[indx]; + for (CSSStyleSheet* sheet : Reversed(aSheets)) { sheet->SetOwningDocument(nullptr); if (sheet->IsApplicable()) { @@ -2327,10 +2307,8 @@ nsDocument::RemoveStyleSheetsFromStyleSets(nsCOMArray& aSheets, S shell->StyleSet()->RemoveStyleSheet(aType, sheet); } } - // XXX Tell observers? } - } void @@ -2385,21 +2363,13 @@ nsDocument::ResetStylesheetsToURI(nsIURI* aURI) } } -static bool -AppendAuthorSheet(nsIStyleSheet *aSheet, void *aData) -{ - nsStyleSet *styleSet = static_cast(aData); - styleSet->AppendStyleSheet(SheetType::Doc, aSheet); - return true; -} - static void AppendSheetsToStyleSet(nsStyleSet* aStyleSet, - const nsCOMArray& aSheets, + const nsTArray>& aSheets, SheetType aType) { - for (int32_t i = aSheets.Count() - 1; i >= 0; --i) { - aStyleSet->AppendStyleSheet(aType, aSheets[i]); + for (CSSStyleSheet* sheet : Reversed(aSheets)) { + aStyleSet->AppendStyleSheet(aType, sheet); } } @@ -2411,9 +2381,7 @@ nsDocument::FillStyleSet(nsStyleSet* aStyleSet) NS_PRECONDITION(aStyleSet->SheetCount(SheetType::Doc) == 0, "Style set already has document sheets?"); - int32_t i; - for (i = mStyleSheets.Count() - 1; i >= 0; --i) { - nsIStyleSheet* sheet = mStyleSheets[i]; + for (CSSStyleSheet* sheet : Reversed(mStyleSheets)) { if (sheet->IsApplicable()) { aStyleSet->AddDocStyleSheet(sheet, this); } @@ -2421,13 +2389,13 @@ nsDocument::FillStyleSet(nsStyleSet* aStyleSet) nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance(); if (sheetService) { - sheetService->AuthorStyleSheets()->EnumerateForwards(AppendAuthorSheet, - aStyleSet); + for (CSSStyleSheet* sheet : *sheetService->AuthorStyleSheets()) { + aStyleSet->AppendStyleSheet(SheetType::Doc, sheet); + } } // Iterate backwards to maintain order - for (i = mOnDemandBuiltInUASheets.Count() - 1; i >= 0; --i) { - nsIStyleSheet* sheet = mOnDemandBuiltInUASheets[i]; + for (CSSStyleSheet* sheet : Reversed(mOnDemandBuiltInUASheets)) { if (sheet->IsApplicable()) { aStyleSet->PrependStyleSheet(SheetType::Agent, sheet); } @@ -4082,8 +4050,7 @@ nsDocument::RemoveChildAt(uint32_t aIndex, bool aNotify) void nsDocument::EnsureOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) { - // Contains() takes nsISupport*, so annoyingly we have to cast here - if (mOnDemandBuiltInUASheets.Contains(static_cast(aSheet))) { + if (mOnDemandBuiltInUASheets.Contains(aSheet)) { return; } BeginUpdate(UPDATE_STYLE); @@ -4094,8 +4061,7 @@ nsDocument::EnsureOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) void nsDocument::AddOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) { - // Contains() takes nsISupport*, so annoyingly we have to cast here - MOZ_ASSERT(!mOnDemandBuiltInUASheets.Contains(static_cast(aSheet))); + MOZ_ASSERT(!mOnDemandBuiltInUASheets.Contains(aSheet)); // Prepend here so that we store the sheets in mOnDemandBuiltInUASheets in // the same order that they should end up in the style set. @@ -4119,24 +4085,23 @@ nsDocument::AddOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) int32_t nsDocument::GetNumberOfStyleSheets() const { - return mStyleSheets.Count(); + return mStyleSheets.Length(); } -nsIStyleSheet* +CSSStyleSheet* nsDocument::GetStyleSheetAt(int32_t aIndex) const { - NS_ENSURE_TRUE(0 <= aIndex && aIndex < mStyleSheets.Count(), nullptr); - return mStyleSheets[aIndex]; + return mStyleSheets.SafeElementAt(aIndex, nullptr); } int32_t -nsDocument::GetIndexOfStyleSheet(nsIStyleSheet* aSheet) const +nsDocument::GetIndexOfStyleSheet(CSSStyleSheet* aSheet) const { return mStyleSheets.IndexOf(aSheet); } void -nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet) +nsDocument::AddStyleSheetToStyleSets(CSSStyleSheet* aSheet) { nsCOMPtr shell = GetShell(); if (shell) { @@ -4146,15 +4111,10 @@ nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet) #define DO_STYLESHEET_NOTIFICATION(className, type, memberName, argName) \ do { \ - RefPtr cssSheet = do_QueryObject(aSheet); \ - if (!cssSheet) { \ - return; \ - } \ - \ className##Init init; \ init.mBubbles = true; \ init.mCancelable = true; \ - init.mStylesheet = cssSheet; \ + init.mStylesheet = aSheet; \ init.memberName = argName; \ \ RefPtr event = \ @@ -4168,7 +4128,7 @@ nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet) } while (0); void -nsDocument::NotifyStyleSheetAdded(nsIStyleSheet* aSheet, bool aDocumentSheet) +nsDocument::NotifyStyleSheetAdded(CSSStyleSheet* aSheet, bool aDocumentSheet) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetAdded, (aSheet, aDocumentSheet)); @@ -4181,7 +4141,7 @@ nsDocument::NotifyStyleSheetAdded(nsIStyleSheet* aSheet, bool aDocumentSheet) } void -nsDocument::NotifyStyleSheetRemoved(nsIStyleSheet* aSheet, bool aDocumentSheet) +nsDocument::NotifyStyleSheetRemoved(CSSStyleSheet* aSheet, bool aDocumentSheet) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetRemoved, (aSheet, aDocumentSheet)); @@ -4194,10 +4154,10 @@ nsDocument::NotifyStyleSheetRemoved(nsIStyleSheet* aSheet, bool aDocumentSheet) } void -nsDocument::AddStyleSheet(nsIStyleSheet* aSheet) +nsDocument::AddStyleSheet(CSSStyleSheet* aSheet) { NS_PRECONDITION(aSheet, "null arg"); - mStyleSheets.AppendObject(aSheet); + mStyleSheets.AppendElement(aSheet); aSheet->SetOwningDocument(this); if (aSheet->IsApplicable()) { @@ -4208,7 +4168,7 @@ nsDocument::AddStyleSheet(nsIStyleSheet* aSheet) } void -nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet) +nsDocument::RemoveStyleSheetFromStyleSets(CSSStyleSheet* aSheet) { nsCOMPtr shell = GetShell(); if (shell) { @@ -4217,12 +4177,12 @@ nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet) } void -nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet) +nsDocument::RemoveStyleSheet(CSSStyleSheet* aSheet) { NS_PRECONDITION(aSheet, "null arg"); - nsCOMPtr sheet = aSheet; // hold ref so it won't die too soon + RefPtr sheet = aSheet; // hold ref so it won't die too soon - if (!mStyleSheets.RemoveObject(aSheet)) { + if (!mStyleSheets.RemoveElement(aSheet)) { NS_ASSERTION(mInUnlinkOrDeletion, "stylesheet not found"); return; } @@ -4239,17 +4199,17 @@ nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet) } void -nsDocument::UpdateStyleSheets(nsCOMArray& aOldSheets, - nsCOMArray& aNewSheets) +nsDocument::UpdateStyleSheets(nsTArray>& aOldSheets, + nsTArray>& aNewSheets) { BeginUpdate(UPDATE_STYLE); // XXX Need to set the sheet on the ownernode, if any - NS_PRECONDITION(aOldSheets.Count() == aNewSheets.Count(), + NS_PRECONDITION(aOldSheets.Length() == aNewSheets.Length(), "The lists must be the same length!"); - int32_t count = aOldSheets.Count(); + int32_t count = aOldSheets.Length(); - nsCOMPtr oldSheet; + RefPtr oldSheet; int32_t i; for (i = 0; i < count; ++i) { oldSheet = aOldSheets[i]; @@ -4260,9 +4220,9 @@ nsDocument::UpdateStyleSheets(nsCOMArray& aOldSheets, RemoveStyleSheet(oldSheet); // This does the right notifications // Now put the new one in its place. If it's null, just ignore it. - nsIStyleSheet* newSheet = aNewSheets[i]; + CSSStyleSheet* newSheet = aNewSheets[i]; if (newSheet) { - mStyleSheets.InsertObjectAt(newSheet, oldIndex); + mStyleSheets.InsertElementAt(oldIndex, newSheet); newSheet->SetOwningDocument(this); if (newSheet->IsApplicable()) { AddStyleSheetToStyleSets(newSheet); @@ -4276,10 +4236,11 @@ nsDocument::UpdateStyleSheets(nsCOMArray& aOldSheets, } void -nsDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, int32_t aIndex) +nsDocument::InsertStyleSheetAt(CSSStyleSheet* aSheet, int32_t aIndex) { NS_PRECONDITION(aSheet, "null ptr"); - mStyleSheets.InsertObjectAt(aSheet, aIndex); + + mStyleSheets.InsertElementAt(aIndex, aSheet); aSheet->SetOwningDocument(this); @@ -4292,13 +4253,13 @@ nsDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, int32_t aIndex) void -nsDocument::SetStyleSheetApplicableState(nsIStyleSheet* aSheet, +nsDocument::SetStyleSheetApplicableState(CSSStyleSheet* aSheet, bool aApplicable) { NS_PRECONDITION(aSheet, "null arg"); // If we're actually in the document style sheet list - if (-1 != mStyleSheets.IndexOf(aSheet)) { + if (mStyleSheets.IndexOf(aSheet) != mStyleSheets.NoIndex) { if (aApplicable) { AddStyleSheetToStyleSets(aSheet); } else { @@ -4358,9 +4319,9 @@ ConvertAdditionalSheetType(nsIDocument::additionalSheetType aType) } static int32_t -FindSheet(const nsCOMArray& aSheets, nsIURI* aSheetURI) +FindSheet(const nsTArray>& aSheets, nsIURI* aSheetURI) { - for (int32_t i = aSheets.Count() - 1; i >= 0; i-- ) { + for (int32_t i = aSheets.Length() - 1; i >= 0; i-- ) { bool bEqual; nsIURI* uri = aSheets[i]->GetSheetURI(); @@ -4414,7 +4375,7 @@ nsDocument::LoadAdditionalStyleSheet(additionalSheetType aType, } nsresult -nsDocument::AddAdditionalStyleSheet(additionalSheetType aType, nsIStyleSheet* aSheet) +nsDocument::AddAdditionalStyleSheet(additionalSheetType aType, CSSStyleSheet* aSheet) { if (mAdditionalSheets[aType].Contains(aSheet)) return NS_ERROR_INVALID_ARG; @@ -4422,7 +4383,7 @@ nsDocument::AddAdditionalStyleSheet(additionalSheetType aType, nsIStyleSheet* aS if (!aSheet->IsApplicable()) return NS_ERROR_INVALID_ARG; - mAdditionalSheets[aType].AppendObject(aSheet); + mAdditionalSheets[aType].AppendElement(aSheet); BeginUpdate(UPDATE_STYLE); nsCOMPtr shell = GetShell(); @@ -4443,12 +4404,12 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet { MOZ_ASSERT(aSheetURI); - nsCOMArray& sheets = mAdditionalSheets[aType]; + nsTArray>& sheets = mAdditionalSheets[aType]; int32_t i = FindSheet(mAdditionalSheets[aType], aSheetURI); if (i >= 0) { - nsCOMPtr sheetRef = sheets[i]; - sheets.RemoveObjectAt(i); + RefPtr sheetRef = sheets[i]; + sheets.RemoveElementAt(i); BeginUpdate(UPDATE_STYLE); if (!mIsGoingAway) { @@ -4469,10 +4430,10 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet } } -nsIStyleSheet* +CSSStyleSheet* nsDocument::FirstAdditionalAuthorSheet() { - return mAdditionalSheets[eAuthorSheet].SafeObjectAt(0); + return mAdditionalSheets[eAuthorSheet].SafeElementAt(0, nullptr); } nsIGlobalObject* @@ -5212,7 +5173,7 @@ nsDocument::DocumentStatesChanged(EventStates aStateMask) } void -nsDocument::StyleRuleChanged(nsIStyleSheet* aSheet, +nsDocument::StyleRuleChanged(CSSStyleSheet* aSheet, css::Rule* aStyleRule) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleChanged, (aSheet)); @@ -5226,7 +5187,7 @@ nsDocument::StyleRuleChanged(nsIStyleSheet* aSheet, } void -nsDocument::StyleRuleAdded(nsIStyleSheet* aSheet, +nsDocument::StyleRuleAdded(CSSStyleSheet* aSheet, css::Rule* aStyleRule) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleAdded, (aSheet)); @@ -5241,7 +5202,7 @@ nsDocument::StyleRuleAdded(nsIStyleSheet* aSheet, } void -nsDocument::StyleRuleRemoved(nsIStyleSheet* aSheet, +nsDocument::StyleRuleRemoved(CSSStyleSheet* aSheet, css::Rule* aStyleRule) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleRemoved, (aSheet)); @@ -6482,13 +6443,11 @@ nsIDocument::GetSelectedStyleSheetSet(nsAString& aSheetSet) int32_t count = GetNumberOfStyleSheets(); nsAutoString title; for (int32_t index = 0; index < count; index++) { - nsIStyleSheet* sheet = GetStyleSheetAt(index); + CSSStyleSheet* sheet = GetStyleSheetAt(index); NS_ASSERTION(sheet, "Null sheet in sheet list!"); - nsCOMPtr domSheet = do_QueryInterface(sheet); - NS_ASSERTION(domSheet, "Sheet must QI to nsIDOMStyleSheet"); bool disabled; - domSheet->GetDisabled(&disabled); + sheet->GetDisabled(&disabled); if (disabled) { // Disabled sheets don't affect the currently selected set continue; @@ -6598,7 +6557,7 @@ nsDocument::EnableStyleSheetsForSetInternal(const nsAString& aSheetSet, int32_t count = GetNumberOfStyleSheets(); nsAutoString title; for (int32_t index = 0; index < count; index++) { - nsIStyleSheet* sheet = GetStyleSheetAt(index); + CSSStyleSheet* sheet = GetStyleSheetAt(index); NS_ASSERTION(sheet, "Null sheet in sheet list!"); sheet->GetTitle(title); if (!title.IsEmpty()) { @@ -10205,7 +10164,7 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer) int32_t sheetsCount = GetNumberOfStyleSheets(); for (int32_t i = 0; i < sheetsCount; ++i) { - RefPtr sheet = do_QueryObject(GetStyleSheetAt(i)); + RefPtr sheet = GetStyleSheetAt(i); if (sheet) { if (sheet->IsApplicable()) { RefPtr clonedSheet = @@ -10218,11 +10177,8 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer) } } - sheetsCount = thisAsDoc->mOnDemandBuiltInUASheets.Count(); // Iterate backwards to maintain order - for (int32_t i = sheetsCount - 1; i >= 0; --i) { - RefPtr sheet = - do_QueryObject(thisAsDoc->mOnDemandBuiltInUASheets[i]); + for (CSSStyleSheet* sheet : Reversed(thisAsDoc->mOnDemandBuiltInUASheets)) { if (sheet) { if (sheet->IsApplicable()) { RefPtr clonedSheet = @@ -12360,7 +12316,7 @@ nsDocument::OnAppThemeChanged() } for (int32_t i = 0; i < GetNumberOfStyleSheets(); i++) { - RefPtr sheet = do_QueryObject(GetStyleSheetAt(i)); + RefPtr sheet = GetStyleSheetAt(i); if (!sheet) { continue; } @@ -12727,15 +12683,19 @@ nsIDocument::DocAddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const } static size_t -SizeOfStyleSheetsElementIncludingThis(nsIStyleSheet* aStyleSheet, - MallocSizeOf aMallocSizeOf, - void* aData) +SizeOfOwnedSheetArrayExcludingThis(const nsTArray>& aSheets, + MallocSizeOf aMallocSizeOf) { - if (!aStyleSheet->GetOwningDocument()) { - // Avoid over-reporting shared sheets. - return 0; + size_t n = 0; + n += aSheets.ShallowSizeOfExcludingThis(aMallocSizeOf); + for (CSSStyleSheet* sheet : aSheets) { + if (!sheet->GetOwningDocument()) { + // Avoid over-reporting shared sheets. + continue; + } + n += sheet->SizeOfIncludingThis(aMallocSizeOf); } - return aStyleSheet->SizeOfIncludingThis(aMallocSizeOf); + return n; } size_t @@ -12786,26 +12746,18 @@ nsDocument::DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const } aWindowSizes->mStyleSheetsSize += - mStyleSheets.SizeOfExcludingThis(SizeOfStyleSheetsElementIncludingThis, - aWindowSizes->mMallocSizeOf); + SizeOfOwnedSheetArrayExcludingThis(mStyleSheets, + aWindowSizes->mMallocSizeOf); // Note that we do not own the sheets pointed to by mOnDemandBuiltInUASheets - // (the nsLayoutStyleSheetCache singleton does) so pass nullptr as the - // aSizeOfElementIncludingThis callback argument. + // (the nsLayoutStyleSheetCache singleton does). aWindowSizes->mStyleSheetsSize += - mOnDemandBuiltInUASheets.SizeOfExcludingThis(nullptr, - aWindowSizes->mMallocSizeOf); - aWindowSizes->mStyleSheetsSize += - mAdditionalSheets[eAgentSheet]. - SizeOfExcludingThis(SizeOfStyleSheetsElementIncludingThis, - aWindowSizes->mMallocSizeOf); - aWindowSizes->mStyleSheetsSize += - mAdditionalSheets[eUserSheet]. - SizeOfExcludingThis(SizeOfStyleSheetsElementIncludingThis, - aWindowSizes->mMallocSizeOf); - aWindowSizes->mStyleSheetsSize += - mAdditionalSheets[eAuthorSheet]. - SizeOfExcludingThis(SizeOfStyleSheetsElementIncludingThis, - aWindowSizes->mMallocSizeOf); + mOnDemandBuiltInUASheets.ShallowSizeOfExcludingThis( + aWindowSizes->mMallocSizeOf); + for (auto& sheetArray : mAdditionalSheets) { + aWindowSizes->mStyleSheetsSize += + SizeOfOwnedSheetArrayExcludingThis(sheetArray, + aWindowSizes->mMallocSizeOf); + } // Lumping in the loader with the style-sheets size is not ideal, // but most of the things in there are in fact stylesheets, so it // doesn't seem worthwhile to separate it out. diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 85b1caeb2f..0f715f7d65 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -775,24 +775,29 @@ public: * These are ordered, highest priority last */ virtual int32_t GetNumberOfStyleSheets() const override; - virtual nsIStyleSheet* GetStyleSheetAt(int32_t aIndex) const override; - virtual int32_t GetIndexOfStyleSheet(nsIStyleSheet* aSheet) const override; - virtual void AddStyleSheet(nsIStyleSheet* aSheet) override; - virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) override; + virtual mozilla::CSSStyleSheet* GetStyleSheetAt(int32_t aIndex) const override; + virtual int32_t GetIndexOfStyleSheet(mozilla::CSSStyleSheet* aSheet) const override; + virtual void AddStyleSheet(mozilla::CSSStyleSheet* aSheet) override; + virtual void RemoveStyleSheet(mozilla::CSSStyleSheet* aSheet) override; - virtual void UpdateStyleSheets(nsCOMArray& aOldSheets, - nsCOMArray& aNewSheets) override; - virtual void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet); - virtual void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet); + virtual void UpdateStyleSheets( + nsTArray>& aOldSheets, + nsTArray>& aNewSheets) override; + virtual void AddStyleSheetToStyleSets(mozilla::CSSStyleSheet* aSheet); + virtual void RemoveStyleSheetFromStyleSets(mozilla::CSSStyleSheet* aSheet); - virtual void InsertStyleSheetAt(nsIStyleSheet* aSheet, int32_t aIndex) override; - virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet, + virtual void InsertStyleSheetAt(mozilla::CSSStyleSheet* aSheet, + int32_t aIndex) override; + virtual void SetStyleSheetApplicableState(mozilla::CSSStyleSheet* aSheet, bool aApplicable) override; - virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheetURI) override; - virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, nsIStyleSheet* aSheet) override; - virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* sheetURI) override; - virtual nsIStyleSheet* FirstAdditionalAuthorSheet() override; + virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, + nsIURI* aSheetURI) override; + virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, + mozilla::CSSStyleSheet* aSheet) override; + virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, + nsIURI* sheetURI) override; + virtual mozilla::CSSStyleSheet* FirstAdditionalAuthorSheet() override; virtual nsIChannel* GetChannel() const override { return mChannel; @@ -852,11 +857,11 @@ public: virtual void DocumentStatesChanged( mozilla::EventStates aStateMask) override; - virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet, + virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) override; - virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet, + virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) override; - virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet, + virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) override; virtual void FlushPendingNotifications(mozFlushType aType) override; @@ -1483,8 +1488,9 @@ protected: nsStyleSet* aStyleSet); void RemoveDocStyleSheetsFromStyleSets(); - void RemoveStyleSheetsFromStyleSets(nsCOMArray& aSheets, - mozilla::SheetType aType); + void RemoveStyleSheetsFromStyleSets( + nsTArray>& aSheets, + mozilla::SheetType aType); void ResetStylesheetsToURI(nsIURI* aURI); void FillStyleSet(nsStyleSet* aStyleSet); @@ -1532,9 +1538,9 @@ protected: // EndLoad() has already happened. nsWeakPtr mWeakSink; - nsCOMArray mStyleSheets; - nsCOMArray mOnDemandBuiltInUASheets; - nsCOMArray mAdditionalSheets[AdditionalSheetTypeCount]; + nsTArray> mStyleSheets; + nsTArray> mOnDemandBuiltInUASheets; + nsTArray> mAdditionalSheets[AdditionalSheetTypeCount]; // Array of observers nsTObserverArray mObservers; @@ -1713,8 +1719,8 @@ private: friend class nsUnblockOnloadEvent; // Recomputes the visibility state but doesn't set the new value. mozilla::dom::VisibilityState GetVisibilityState() const; - void NotifyStyleSheetAdded(nsIStyleSheet* aSheet, bool aDocumentSheet); - void NotifyStyleSheetRemoved(nsIStyleSheet* aSheet, bool aDocumentSheet); + void NotifyStyleSheetAdded(mozilla::CSSStyleSheet* aSheet, bool aDocumentSheet); + void NotifyStyleSheetRemoved(mozilla::CSSStyleSheet* aSheet, bool aDocumentSheet); void PostUnblockOnloadEvent(); void DoUnblockOnload(); diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 5a28e9e4b0..d493932218 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -73,7 +73,6 @@ class nsIRequest; class nsIRunnable; class nsIStreamListener; class nsIStructuredCloneContainer; -class nsIStyleSheet; class nsIURI; class nsIVariant; class nsLocation; @@ -946,7 +945,7 @@ public: * @return the stylesheet at aIndex. Null if aIndex is out of range. * @throws no exceptions */ - virtual nsIStyleSheet* GetStyleSheetAt(int32_t aIndex) const = 0; + virtual mozilla::CSSStyleSheet* GetStyleSheetAt(int32_t aIndex) const = 0; /** * Insert a sheet at a particular spot in the stylesheet list (zero-based) @@ -955,7 +954,8 @@ public: * adjusted for the "special" sheets. * @throws no exceptions */ - virtual void InsertStyleSheetAt(nsIStyleSheet* aSheet, int32_t aIndex) = 0; + virtual void InsertStyleSheetAt(mozilla::CSSStyleSheet* aSheet, + int32_t aIndex) = 0; /** * Get the index of a particular stylesheet. This will _always_ @@ -963,7 +963,7 @@ public: * @param aSheet the sheet to get the index of * @return aIndex the index of the sheet in the full list */ - virtual int32_t GetIndexOfStyleSheet(nsIStyleSheet* aSheet) const = 0; + virtual int32_t GetIndexOfStyleSheet(mozilla::CSSStyleSheet* aSheet) const = 0; /** * Replace the stylesheets in aOldSheets with the stylesheets in @@ -973,24 +973,25 @@ public: * may be null; if so the corresponding sheets in the first list * will simply be removed. */ - virtual void UpdateStyleSheets(nsCOMArray& aOldSheets, - nsCOMArray& aNewSheets) = 0; + virtual void UpdateStyleSheets( + nsTArray>& aOldSheets, + nsTArray>& aNewSheets) = 0; /** * Add a stylesheet to the document */ - virtual void AddStyleSheet(nsIStyleSheet* aSheet) = 0; + virtual void AddStyleSheet(mozilla::CSSStyleSheet* aSheet) = 0; /** * Remove a stylesheet from the document */ - virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) = 0; + virtual void RemoveStyleSheet(mozilla::CSSStyleSheet* aSheet) = 0; /** * Notify the document that the applicable state of the sheet changed * and that observers should be notified and style sets updated */ - virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet, + virtual void SetStyleSheetApplicableState(mozilla::CSSStyleSheet* aSheet, bool aApplicable) = 0; enum additionalSheetType { @@ -1000,10 +1001,13 @@ public: AdditionalSheetTypeCount }; - virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheetURI) = 0; - virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, nsIStyleSheet* aSheet) = 0; - virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* sheetURI) = 0; - virtual nsIStyleSheet* FirstAdditionalAuthorSheet() = 0; + virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, + nsIURI* aSheetURI) = 0; + virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, + mozilla::CSSStyleSheet* aSheet) = 0; + virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, + nsIURI* sheetURI) = 0; + virtual mozilla::CSSStyleSheet* FirstAdditionalAuthorSheet() = 0; /** * Get this document's CSSLoader. This is guaranteed to not return null. @@ -1306,11 +1310,11 @@ public: // Observation hooks for style data to propagate notifications // to document observers - virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet, + virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) = 0; - virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet, + virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) = 0; - virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet, + virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) = 0; /** diff --git a/dom/base/nsIDocumentObserver.h b/dom/base/nsIDocumentObserver.h index 9814ad7865..5d6d2542a2 100644 --- a/dom/base/nsIDocumentObserver.h +++ b/dom/base/nsIDocumentObserver.h @@ -11,10 +11,10 @@ #include "nsIMutationObserver.h" class nsIContent; -class nsIStyleSheet; class nsIDocument; namespace mozilla { +class CSSStyleSheet; namespace css { class Rule; } // namespace css @@ -100,7 +100,7 @@ public: * @param aDocumentSheet True if sheet is in document's style sheet list, * false if sheet is not (i.e., UA or user sheet) */ - virtual void StyleSheetAdded(nsIStyleSheet* aStyleSheet, + virtual void StyleSheetAdded(mozilla::CSSStyleSheet* aStyleSheet, bool aDocumentSheet) = 0; /** @@ -113,7 +113,7 @@ public: * @param aDocumentSheet True if sheet is in document's style sheet list, * false if sheet is not (i.e., UA or user sheet) */ - virtual void StyleSheetRemoved(nsIStyleSheet* aStyleSheet, + virtual void StyleSheetRemoved(mozilla::CSSStyleSheet* aStyleSheet, bool aDocumentSheet) = 0; /** @@ -125,7 +125,7 @@ public: * * @param aStyleSheet the StyleSheet that has changed state */ - virtual void StyleSheetApplicableStateChanged(nsIStyleSheet* aStyleSheet) = 0; + virtual void StyleSheetApplicableStateChanged(mozilla::CSSStyleSheet* aStyleSheet) = 0; /** * A StyleRule has just been modified within a style sheet. @@ -136,7 +136,7 @@ public: * * @param aStyleSheet the StyleSheet that contians the rule */ - virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet) = 0; + virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet) = 0; /** * A StyleRule has just been added to a style sheet. @@ -147,7 +147,7 @@ public: * * @param aStyleSheet the StyleSheet that has been modified */ - virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet) = 0; + virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet) = 0; /** * A StyleRule has just been removed from a style sheet. @@ -158,7 +158,7 @@ public: * * @param aStyleSheet the StyleSheet that has been modified */ - virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet) = 0; + virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet) = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID) @@ -186,24 +186,25 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID) mozilla::EventStates aStateMask) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \ - virtual void StyleSheetAdded(nsIStyleSheet* aStyleSheet, \ + virtual void StyleSheetAdded(mozilla::CSSStyleSheet* aStyleSheet, \ bool aDocumentSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \ - virtual void StyleSheetRemoved(nsIStyleSheet* aStyleSheet, \ + virtual void StyleSheetRemoved(mozilla::CSSStyleSheet* aStyleSheet, \ bool aDocumentSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \ - virtual void StyleSheetApplicableStateChanged(nsIStyleSheet* aStyleSheet) override; + virtual void StyleSheetApplicableStateChanged( \ + mozilla::CSSStyleSheet* aStyleSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \ - virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet) override; + virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \ - virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet) override; + virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \ - virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet) override; + virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER \ NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \ @@ -261,29 +262,29 @@ NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(_class) #define NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(_class) \ void \ -_class::StyleSheetAdded(nsIStyleSheet* aStyleSheet, \ +_class::StyleSheetAdded(mozilla::CSSStyleSheet* aStyleSheet, \ bool aDocumentSheet) \ { \ } \ void \ -_class::StyleSheetRemoved(nsIStyleSheet* aStyleSheet, \ +_class::StyleSheetRemoved(mozilla::CSSStyleSheet* aStyleSheet, \ bool aDocumentSheet) \ { \ } \ void \ -_class::StyleSheetApplicableStateChanged(nsIStyleSheet* aStyleSheet) \ +_class::StyleSheetApplicableStateChanged(mozilla::CSSStyleSheet* aStyleSheet) \ { \ } \ void \ -_class::StyleRuleChanged(nsIStyleSheet* aStyleSheet) \ +_class::StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet) \ { \ } \ void \ -_class::StyleRuleAdded(nsIStyleSheet* aStyleSheet) \ +_class::StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet) \ { \ } \ void \ -_class::StyleRuleRemoved(nsIStyleSheet* aStyleSheet) \ +_class::StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet) \ { \ } diff --git a/dom/base/nsStyleLinkElement.cpp b/dom/base/nsStyleLinkElement.cpp index efd0809a6d..56fc539ef3 100644 --- a/dom/base/nsStyleLinkElement.cpp +++ b/dom/base/nsStyleLinkElement.cpp @@ -285,17 +285,6 @@ UpdateIsElementInStyleScopeFlagOnSubtree(Element* aElement) } } -static Element* -GetScopeElement(nsIStyleSheet* aSheet) -{ - RefPtr cssStyleSheet = do_QueryObject(aSheet); - if (!cssStyleSheet) { - return nullptr; - } - - return cssStyleSheet->GetScopeElement(); -} - nsresult nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument, ShadowRoot* aOldShadowRoot, @@ -327,7 +316,8 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument, return NS_OK; } - Element* oldScopeElement = GetScopeElement(mStyleSheet); + Element* oldScopeElement = + mStyleSheet ? mStyleSheet->GetScopeElement() : nullptr; if (mStyleSheet && (aOldDocument || aOldShadowRoot)) { MOZ_ASSERT(!(aOldDocument && aOldShadowRoot), diff --git a/dom/base/test/browser.ini b/dom/base/test/browser.ini index ad4958f6ff..64a31e34f6 100644 --- a/dom/base/test/browser.ini +++ b/dom/base/test/browser.ini @@ -26,3 +26,5 @@ skip-if = true # Intermittent failures - bug 987493. Restore the skip-if above o [browser_bug1058164.js] skip-if = e10s # We need bug 918634 to land before this can be tested with e10s. [browser_use_counters.js] +[browser_bug1238440.js] +skip-if = e10s diff --git a/dom/base/test/browser_bug1238440.js b/dom/base/test/browser_bug1238440.js new file mode 100644 index 0000000000..cdafe29f15 --- /dev/null +++ b/dom/base/test/browser_bug1238440.js @@ -0,0 +1,76 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +Components.utils.import("resource://gre/modules/NetUtil.jsm"); +Components.utils.import("resource://gre/modules/FileUtils.jsm"); + +waitForExplicitFinish(); + +const PAGE = "data:text/html,"; + +function writeFile(file, text) { + return new Promise((resolve) => { + let converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] + .createInstance(Components.interfaces.nsIScriptableUnicodeConverter); + converter.charset = "UTF-8"; + + let ostream = FileUtils.openSafeFileOutputStream(file); + let istream = converter.convertToInputStream(text); + NetUtil.asyncCopy(istream, ostream, function(status) { + if (!Components.isSuccessCode(status)) throw 'fail'; + resolve(); + }); + }); +} + +function runFileReader(input, status) { + return new Promise((resolve) => { + let fr = new FileReader(); + fr.onload = function() { + ok(status, "FileReader called onload"); + resolve(); + } + + fr.onerror = function(e) { + e.preventDefault(); + ok(!status, "FileReader called onerror"); + resolve(); + } + + fr.readAsArrayBuffer(input); + }); +} + +add_task(function() { + info("Creating a temporary file..."); + let file = FileUtils.getFile("TmpD", ["bug1238440.txt"]); + yield writeFile(file, "hello world"); + + info("Opening a tab..."); + let tab = gBrowser.addTab(PAGE); + gBrowser.selectedTab = tab; + let browser = tab.linkedBrowser; + yield BrowserTestUtils.browserLoaded(browser); + + info("Populating the form..."); + let doc = browser.contentDocument; + let input = doc.querySelector('input'); + input.value = file.path; + + info("Running the FileReader..."); + yield runFileReader(input.files[0], true); + + info("Writing the temporary file again..."); + yield writeFile(file, "hello world-----------------------------"); + + info("Running the FileReader again..."); + yield runFileReader(input.files[0], false); + + info("Closing the tab..."); + gBrowser.removeTab(gBrowser.selectedTab); + + ok(true, "we didn't crash."); +}); diff --git a/dom/base/test/fileutils.js b/dom/base/test/fileutils.js index ecfc801b86..25f6118b26 100644 --- a/dom/base/test/fileutils.js +++ b/dom/base/test/fileutils.js @@ -127,23 +127,6 @@ function testHasRun() { } } -function createFileWithData(fileData) { - var dirSvc = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"].getService(SpecialPowers.Ci.nsIProperties); - var testFile = dirSvc.get("ProfD", SpecialPowers.Ci.nsIFile); - testFile.append("fileAPItestfile2-" + fileNum); - fileNum++; - var outStream = SpecialPowers.Cc["@mozilla.org/network/file-output-stream;1"].createInstance(SpecialPowers.Ci.nsIFileOutputStream); - outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate - 0666, 0); - outStream.write(fileData, fileData.length); - outStream.close(); - - var fileList = document.getElementById('fileList'); - SpecialPowers.wrap(fileList).value = testFile.path; - - return fileList.files[0]; -} - function gc() { window.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor) .getInterface(SpecialPowers.Ci.nsIDOMWindowUtils) diff --git a/dom/base/test/mochitest.ini b/dom/base/test/mochitest.ini index 32a7ffc350..24987fdc11 100644 --- a/dom/base/test/mochitest.ini +++ b/dom/base/test/mochitest.ini @@ -513,7 +513,6 @@ skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop spec [test_bug433533.html] [test_bug433662.html] [test_bug435425.html] -[test_bug438519.html] [test_bug444030.xhtml] [test_bug444322.html] [test_bug444722.html] @@ -732,7 +731,7 @@ skip-if = buildapp == 'b2g' || toolkit == 'android' #bug 904183 # b2g(bug 904183 [test_encodeToStringWithMaxLength.html] [test_fileapi.html] [test_fileapi_slice.html] -skip-if = buildapp == 'b2g' || buildapp == 'mulet' || toolkit == 'android' || e10s #bug 775227 +skip-if = buildapp == 'b2g' || toolkit == 'android' #bug 775227 [test_getElementById.html] [test_html_colors_quirks.html] [test_html_colors_standards.html] diff --git a/dom/base/test/test_bug438519.html b/dom/base/test/test_bug438519.html deleted file mode 100644 index 35508b1a69..0000000000 --- a/dom/base/test/test_bug438519.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - Test for Bug 438519 - - - - -Mozilla Bug 438519 -

- -
-
-
- - - diff --git a/dom/base/test/test_createHTMLDocument.html b/dom/base/test/test_createHTMLDocument.html index 14749a2df8..66b090d189 100644 --- a/dom/base/test/test_createHTMLDocument.html +++ b/dom/base/test/test_createHTMLDocument.html @@ -24,7 +24,6 @@ function checkDoc(title, expectedtitle, normalizedtitle) { is(doc.doctype.name, "html"); is(doc.doctype.publicId, ""); is(doc.doctype.systemId, ""); - is(doc.doctype.internalSubset, null, "internalSubset should be null!"); isElement(doc.documentElement, "html"); isElement(doc.documentElement.firstChild, "head"); if (title !== undefined) { @@ -38,8 +37,7 @@ function checkDoc(title, expectedtitle, normalizedtitle) { } isElement(doc.documentElement.lastChild, "body"); is(doc.documentElement.lastChild.childNodes.length, 0); - ((!title || title.indexOf("\f") === -1) ? is : todo_is) - (doc.title, normalizedtitle); + is(doc.title, normalizedtitle); doc.body.innerHTML = "foo"; is(doc.body.innerHTML, "foo", "innerHTML should work in HTML data documents!"); } diff --git a/dom/base/test/test_fileapi_slice.html b/dom/base/test/test_fileapi_slice.html index 581f3dae6f..efe4aa2592 100644 --- a/dom/base/test/test_fileapi_slice.html +++ b/dom/base/test/test_fileapi_slice.html @@ -54,31 +54,6 @@ cx.fill(); cx.closePath(); -var fileData = - atob(cx.canvas.toDataURL("image/png").substring("data:text/png;base64,".length + 1)); -var memFile = cx.canvas.mozGetAsFile("image/png"); -var fileFile = createFileWithData(fileData); -var size = fileData.length; - -// This might fail if we dramatically improve the png encoder. If that happens -// please increase the complexity or size of the image generated above to ensure -// that we're testing with files that are large enough. -ok(size > 65536, "test data sufficiently large"); - - -// Test that basic properties work -testSlice(memFile, size, "image/png", fileData, "memFile"); -testSlice(fileFile, size, "", fileData, "fileFile"); - - -// Try loading directly from slice into an image -var testBinaryData = ""; -for (var i = 0; i < 256; i++) { - testBinaryData += String.fromCharCode(i); -} -while (testBinaryData.length < 20000) { - testBinaryData += testBinaryData; -} function imageLoadHandler(event) { var origcanvas = $("canvas"); var testcanvas = $("testcanvas"); @@ -100,37 +75,93 @@ function imageLoadHandler(event) { testHasRun(); } -// image in the middle -var imgfile = createFileWithData(testBinaryData + fileData + testBinaryData); -is(imgfile.size, size + testBinaryData.length * 2, "correct file size (middle)"); -var img = new Image; -img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, testBinaryData.length + size)); -img.onload = imageLoadHandler; -expectedTestCount++; +var fileData = + atob(cx.canvas.toDataURL("image/png").substring("data:text/png;base64,".length + 1)); +var size = fileData.length; +var testBinaryData = ""; -// image at start -var imgfile = createFileWithData(fileData + testBinaryData); -is(imgfile.size, size + testBinaryData.length, "correct file size (start)"); -var img = new Image; -img.src = URL.createObjectURL(imgfile.slice(0, size)); -img.onload = imageLoadHandler; -expectedTestCount++; +// This might fail if we dramatically improve the png encoder. If that happens +// please increase the complexity or size of the image generated above to ensure +// that we're testing with files that are large enough. +ok(size > 65536, "test data sufficiently large"); -// image at end -var imgfile = createFileWithData(testBinaryData + fileData); -is(imgfile.size, size + testBinaryData.length, "correct file size (end)"); -var img = new Image; -img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, testBinaryData.length + size)); -img.onload = imageLoadHandler; -expectedTestCount++; +SpecialPowers.createFiles([{name: "basicTestFile", data: fileData}], + basicTest); + +function basicTest(files) { + var fileFile = files[0]; + + // Test that basic properties work + var memFile = cx.canvas.mozGetAsFile("image/png"); + testSlice(memFile, size, "image/png", fileData, "memFile"); + testSlice(fileFile, size, "", fileData, "fileFile"); + + // Try loading directly from slice into an image + for (var i = 0; i < 256; i++) { + testBinaryData += String.fromCharCode(i); + } + while (testBinaryData.length < 20000) { + testBinaryData += testBinaryData; + } + + // image in the middle + SpecialPowers.createFiles([{name: "middleTestFile", + data: testBinaryData + fileData + testBinaryData}], + imageMiddleTest); +} + +function imageMiddleTest(files) { + var imgfile = files[0]; + is(imgfile.size, size + testBinaryData.length * 2, "correct file size (middle)"); + var img = new Image; + img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, testBinaryData.length + size)); + img.onload = imageLoadHandler; + expectedTestCount++; + + // image at start + SpecialPowers.createFiles([{name: "startTestFile", + data: fileData + testBinaryData}], + imageStartTest); +} + +function imageStartTest(files) { + var imgfile = files[0]; + is(imgfile.size, size + testBinaryData.length, "correct file size (start)"); + var img = new Image; + img.src = URL.createObjectURL(imgfile.slice(0, size)); + img.onload = imageLoadHandler; + expectedTestCount++; + + // image at end + SpecialPowers.createFiles([{name: "endTestFile", + data: testBinaryData + fileData}], + imageEndTest); +} + +function imageEndTest(files) { + var imgfile = files[0]; + is(imgfile.size, size + testBinaryData.length, "correct file size (end)"); + var img = new Image; + img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, testBinaryData.length + size)); + img.onload = imageLoadHandler; + expectedTestCount++; + + // image past end + SpecialPowers.createFiles([{name: "pastEndTestFile", + data: testBinaryData + fileData}], + imagePastEndTest); +} + +function imagePastEndTest(files) { + var imgfile = files[0]; + is(imgfile.size, size + testBinaryData.length, "correct file size (past end)"); + var img = new Image; + img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, testBinaryData.length + size + 1000)); + img.onload = imageLoadHandler; + expectedTestCount++; +} -// image past end -var imgfile = createFileWithData(testBinaryData + fileData); -is(imgfile.size, size + testBinaryData.length, "correct file size (past end)"); -var img = new Image; -img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, testBinaryData.length + size + 1000)); -img.onload = imageLoadHandler; -expectedTestCount++; - + + diff --git a/dom/bindings/Errors.msg b/dom/bindings/Errors.msg index 92c725dc62..54da8ba66d 100644 --- a/dom/bindings/Errors.msg +++ b/dom/bindings/Errors.msg @@ -89,3 +89,4 @@ MSG_DEF(MSG_IS_NOT_PROMISE, 1, JSEXN_TYPEERR, "{0} is not a Promise") MSG_DEF(MSG_SW_INSTALL_ERROR, 2, JSEXN_TYPEERR, "ServiceWorker script at {0} for scope {1} encountered an error during installation.") MSG_DEF(MSG_SW_SCRIPT_THREW, 2, JSEXN_TYPEERR, "ServiceWorker script at {0} for scope {1} threw an exception during script evaluation.") MSG_DEF(MSG_TYPEDARRAY_IS_SHARED, 1, JSEXN_TYPEERR, "{0} can't be a typed array on SharedArrayBuffer") +MSG_DEF(MSG_CACHE_ADD_FAILED_RESPONSE, 3, JSEXN_TYPEERR, "Cache got {0} response with bad status {1} while trying to add request {2}") diff --git a/dom/bluetooth/common/webapi/BluetoothAdapter.h b/dom/bluetooth/common/webapi/BluetoothAdapter.h index 2a90e0e8f2..5f2b7be2aa 100644 --- a/dom/bluetooth/common/webapi/BluetoothAdapter.h +++ b/dom/bluetooth/common/webapi/BluetoothAdapter.h @@ -75,7 +75,7 @@ public: return mDiscoverable; } - BluetoothPairingListener* PairingReqs() const + BluetoothPairingListener* GetPairingReqs() const { return mPairingReqs; } diff --git a/dom/browser-element/BrowserElementChildPreload.js b/dom/browser-element/BrowserElementChildPreload.js index 5c2424e823..0e80c0f786 100644 --- a/dom/browser-element/BrowserElementChildPreload.js +++ b/dom/browser-element/BrowserElementChildPreload.js @@ -75,15 +75,6 @@ const OBSERVED_EVENTS = [ 'will-launch-app' ]; -const COMMAND_MAP = { - 'cut': 'cmd_cut', - 'copy': 'cmd_copyAndCollapseToEnd', - 'copyImage': 'cmd_copyImage', - 'copyLink': 'cmd_copyLink', - 'paste': 'cmd_paste', - 'selectall': 'cmd_selectAll' -}; - /** * The BrowserElementChild implements one half of - + + diff --git a/toolkit/devtools/storage/test/storage-secured-iframe.html b/toolkit/devtools/storage/test/storage-secured-iframe.html index dd93442f03..f650166516 100644 --- a/toolkit/devtools/storage/test/storage-secured-iframe.html +++ b/toolkit/devtools/storage/test/storage-secured-iframe.html @@ -8,7 +8,7 @@ Iframe for testing multiple host detetion in storage actor diff --git a/toolkit/devtools/storage/test/storage-unsecured-iframe.html b/toolkit/devtools/storage/test/storage-unsecured-iframe.html index c3a1eeb570..842d80d7aa 100644 --- a/toolkit/devtools/storage/test/storage-unsecured-iframe.html +++ b/toolkit/devtools/storage/test/storage-unsecured-iframe.html @@ -8,20 +8,23 @@ Iframe for testing multiple host detetion in storage actor diff --git a/toolkit/devtools/storage/test/storage-updates.html b/toolkit/devtools/storage/test/storage-updates.html index 626118d000..0392fd665e 100644 --- a/toolkit/devtools/storage/test/storage-updates.html +++ b/toolkit/devtools/storage/test/storage-updates.html @@ -8,10 +8,10 @@ Bug 965872 - Storage inspector actor with cookies, local storage and session sto Storage inspector blank html for tests - diff --git a/toolkit/locales/en-US/chrome/global/devtools/storage.properties b/toolkit/locales/en-US/chrome/global/devtools/storage.properties index f57b243f5d..5f1ebb0b3d 100644 --- a/toolkit/locales/en-US/chrome/global/devtools/storage.properties +++ b/toolkit/locales/en-US/chrome/global/devtools/storage.properties @@ -53,6 +53,7 @@ tree.labels.cookies=Cookies tree.labels.localStorage=Local Storage tree.labels.sessionStorage=Session Storage tree.labels.indexedDB=Indexed DB +tree.labels.Cache=Cache Storage # LOCALIZATION NOTE (table.headers.*.*): # These strings are the header names of the columns in the Storage Table for @@ -83,6 +84,9 @@ table.headers.localStorage.value=Value table.headers.sessionStorage.name=Key table.headers.sessionStorage.value=Value +table.headers.Cache.url=URL +table.headers.Cache.status=Status + table.headers.indexedDB.name=Key table.headers.indexedDB.db=Database Name table.headers.indexedDB.objectStore=Object Store Name diff --git a/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.cpp b/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.cpp index 0e06748045..d8e6c0a3a9 100644 --- a/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.cpp +++ b/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.cpp @@ -42,6 +42,7 @@ GonkBufferQueueProducer::GonkBufferQueueProducer(const sp& mCore(core), mSlots(core->mSlots), mConsumerName(), + mSynchronousMode(true), mStickyTransform(0) {} GonkBufferQueueProducer::~GonkBufferQueueProducer() {} @@ -501,6 +502,22 @@ status_t GonkBufferQueueProducer::attachBuffer(int* outSlot, return returnFlags; } +status_t GonkBufferQueueProducer::setSynchronousMode(bool enabled) { + ALOGV("setSynchronousMode: enabled=%d", enabled); + Mutex::Autolock lock(mCore->mMutex); + + if (mCore->mIsAbandoned) { + ALOGE("setSynchronousMode: BufferQueue has been abandoned!"); + return NO_INIT; + } + + if (mSynchronousMode != enabled) { + mSynchronousMode = enabled; + mCore->mDequeueCondition.broadcast(); + } + return OK; +} + status_t GonkBufferQueueProducer::queueBuffer(int slot, const QueueBufferInput &input, QueueBufferOutput *output) { ATRACE_CALL(); @@ -619,7 +636,7 @@ status_t GonkBufferQueueProducer::queueBuffer(int slot, // When the queue is not empty, we need to look at the front buffer // state to see if we need to replace it GonkBufferQueueCore::Fifo::iterator front(mCore->mQueue.begin()); - if (front->mIsDroppable) { + if (front->mIsDroppable || !mSynchronousMode) { // If the front queued buffer is still being tracked, we first // mark it as freed if (mCore->stillTracking(front)) { @@ -630,6 +647,7 @@ status_t GonkBufferQueueProducer::queueBuffer(int slot, } // Overwrite the droppable buffer with the incoming one *front = item; + listener = mCore->mConsumerListener; } else { mCore->mQueue.push_back(item); listener = mCore->mConsumerListener; diff --git a/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.h b/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.h index 46bd9512e3..a1a22416ad 100644 --- a/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.h +++ b/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.h @@ -172,6 +172,16 @@ public: virtual void allocateBuffers(bool async, uint32_t width, uint32_t height, uint32_t format, uint32_t usage); + // setSynchronousMode sets whether dequeueBuffer is synchronous or + // asynchronous. In synchronous mode, dequeueBuffer blocks until + // a buffer is available, the currently bound buffer can be dequeued and + // queued buffers will be acquired in order. In asynchronous mode, + // a queued buffer may be replaced by a subsequently queued buffer. + // + // The default mode is synchronous. + // This should be called only during initialization. + virtual status_t setSynchronousMode(bool enabled); + private: // This is required by the IBinder::DeathRecipient interface virtual void binderDied(const wp& who); @@ -194,6 +204,9 @@ private: // most updates). String8 mConsumerName; + // mSynchronousMode whether we're in synchronous mode or not + bool mSynchronousMode; + uint32_t mStickyTransform; }; // class GonkBufferQueueProducer diff --git a/widget/gonk/nativewindow/moz.build b/widget/gonk/nativewindow/moz.build index 6b3fe4c64e..96fe175d2c 100644 --- a/widget/gonk/nativewindow/moz.build +++ b/widget/gonk/nativewindow/moz.build @@ -29,6 +29,7 @@ if CONFIG['ANDROID_VERSION'] >= '21': EXPORTS += [ 'GonkBufferQueueLL/GonkBufferQueueDefs.h', 'GonkBufferQueueLL/GonkBufferQueueLL.h', + 'GonkBufferQueueLL/GonkBufferQueueProducer.h', 'GonkBufferQueueLL/GonkBufferSlot.h', 'GonkConsumerBaseLL.h', 'GonkNativeWindowClientLL.h', diff --git a/xpcom/ds/nsStaticNameTable.cpp b/xpcom/ds/nsStaticNameTable.cpp index ae1a3b7b0d..d5fa02356d 100644 --- a/xpcom/ds/nsStaticNameTable.cpp +++ b/xpcom/ds/nsStaticNameTable.cpp @@ -19,48 +19,47 @@ using namespace mozilla; struct NameTableKey { - explicit NameTableKey(const nsAFlatCString* aKeyStr) - : mIsUnichar(false) + NameTableKey(const nsDependentCString aNameArray[], + const nsAFlatCString* aKeyStr) + : mNameArray(aNameArray) + , mIsUnichar(false) { mKeyStr.m1b = aKeyStr; } - explicit NameTableKey(const nsAFlatString* aKeyStr) - : mIsUnichar(true) + NameTableKey(const nsDependentCString aNameArray[], + const nsAFlatString* aKeyStr) + : mNameArray(aNameArray) + , mIsUnichar(true) { mKeyStr.m2b = aKeyStr; } - bool mIsUnichar; + const nsDependentCString* mNameArray; union { const nsAFlatCString* m1b; const nsAFlatString* m2b; } mKeyStr; + bool mIsUnichar; }; struct NameTableEntry : public PLDHashEntryHdr { - // no ownership here! - const nsAFlatCString* mString; int32_t mIndex; }; static bool matchNameKeysCaseInsensitive(PLDHashTable*, const PLDHashEntryHdr* aHdr, - const void* aKey) + const void* aVoidKey) { - const NameTableEntry* entry = static_cast(aHdr); - const NameTableKey* keyValue = static_cast(aKey); - const nsAFlatCString* entryKey = entry->mString; + auto entry = static_cast(aHdr); + auto key = static_cast(aVoidKey); + const nsDependentCString* name = &key->mNameArray[entry->mIndex]; - if (keyValue->mIsUnichar) { - return keyValue->mKeyStr.m2b->LowerCaseEqualsASCII(entryKey->get(), - entryKey->Length()); - } - - return keyValue->mKeyStr.m1b->LowerCaseEqualsASCII(entryKey->get(), - entryKey->Length()); + return key->mIsUnichar + ? key->mKeyStr.m2b->LowerCaseEqualsASCII(name->get(), name->Length()) + : key->mKeyStr.m1b->LowerCaseEqualsASCII(name->get(), name->Length()); } /* @@ -134,16 +133,20 @@ nsStaticCaseInsensitiveNameTable::nsStaticCaseInsensitiveNameTable( nsDependentCString* strPtr = &mNameArray[index]; new (strPtr) nsDependentCString(raw); - NameTableKey key(strPtr); + NameTableKey key(mNameArray, strPtr); auto entry = static_cast(mNameTable.Add(&key, fallible)); if (!entry) { continue; } - NS_ASSERTION(entry->mString == 0, "Entry already exists!"); + // If the entry already exists it's unlikely but possible that its index is + // zero, in which case this assertion won't fail. But if the index is + // non-zero (highly likely) then it will fail. In other words, this + // assertion is likely but not guaranteed to detect if an entry is already + // used. + MOZ_ASSERT(entry->mIndex == 0, "Entry already exists!"); - entry->mString = strPtr; // not owned! entry->mIndex = index; } #ifdef DEBUG @@ -168,7 +171,7 @@ nsStaticCaseInsensitiveNameTable::Lookup(const nsACString& aName) const nsAFlatCString& str = PromiseFlatCString(aName); - NameTableKey key(&str); + NameTableKey key(mNameArray, &str); auto entry = static_cast(mNameTable.Search(&key)); return entry ? entry->mIndex : nsStaticCaseInsensitiveNameTable::NOT_FOUND; @@ -181,7 +184,7 @@ nsStaticCaseInsensitiveNameTable::Lookup(const nsAString& aName) const nsAFlatString& str = PromiseFlatString(aName); - NameTableKey key(&str); + NameTableKey key(mNameArray, &str); auto entry = static_cast(mNameTable.Search(&key)); return entry ? entry->mIndex : nsStaticCaseInsensitiveNameTable::NOT_FOUND; diff --git a/xpcom/glue/FileUtils.cpp b/xpcom/glue/FileUtils.cpp index ad52446299..699812461f 100644 --- a/xpcom/glue/FileUtils.cpp +++ b/xpcom/glue/FileUtils.cpp @@ -188,6 +188,35 @@ mozilla::ReadSysFile( #endif /* ReadSysFile_PRESENT */ +#ifdef WriteSysFile_PRESENT + +bool +mozilla::WriteSysFile( + const char* aFilename, + const char* aBuf) +{ + size_t aBufSize = strlen(aBuf); + int fd = MOZ_TEMP_FAILURE_RETRY(open(aFilename, O_WRONLY)); + if (fd < 0) { + return false; + } + ScopedClose autoClose(fd); + ssize_t bytesWritten; + size_t offset = 0; + do { + bytesWritten = MOZ_TEMP_FAILURE_RETRY(write(fd, aBuf + offset, + aBufSize - offset)); + if (bytesWritten == -1) { + return false; + } + offset += bytesWritten; + } while (bytesWritten > 0 && offset < aBufSize); + MOZ_ASSERT(offset == aBufSize); + return true; +} + +#endif /* WriteSysFile_PRESENT */ + void mozilla::ReadAheadLib(nsIFile* aFile) { diff --git a/xpcom/glue/FileUtils.h b/xpcom/glue/FileUtils.h index f6242c9d8d..aaf912b21b 100644 --- a/xpcom/glue/FileUtils.h +++ b/xpcom/glue/FileUtils.h @@ -171,15 +171,19 @@ void ReadAhead(filedesc_t aFd, const size_t aOffset = 0, })) #endif -/* Define ReadSysFile() only on GONK to avoid unnecessary lubxul bloat. -Also define it in debug builds, so that unit tests for it can be written -and run in non-GONK builds. */ +/* Define ReadSysFile() and WriteSysFile() only on GONK to avoid unnecessary + * libxul bloat. Also define it in debug builds, so that unit tests for it can + * be written and run in non-GONK builds. */ #if (defined(MOZ_WIDGET_GONK) || defined(DEBUG)) && defined(XP_UNIX) #ifndef ReadSysFile_PRESENT #define ReadSysFile_PRESENT #endif /* ReadSysFile_PRESENT */ +#ifndef WriteSysFile_PRESENT +#define WriteSysFile_PRESENT +#endif /* WriteSysFile_PRESENT */ + /** * Read the contents of a file. * This function is intended for reading a single-lined text files from @@ -207,6 +211,8 @@ bool ReadSysFile(const char* aFilename, int* aVal); */ bool ReadSysFile(const char* aFilename, bool* aVal); +bool WriteSysFile(const char* aFilename, const char* aBuf); + #endif /* (MOZ_WIDGET_GONK || DEBUG) && XP_UNIX */ } // namespace mozilla diff --git a/xpcom/glue/nsCOMArray.cpp b/xpcom/glue/nsCOMArray.cpp index c259176392..f07e37f24a 100644 --- a/xpcom/glue/nsCOMArray.cpp +++ b/xpcom/glue/nsCOMArray.cpp @@ -292,23 +292,6 @@ nsCOMArray_base::SetCount(int32_t aNewCount) return true; } -size_t -nsCOMArray_base::SizeOfExcludingThis( - nsBaseArraySizeOfElementIncludingThisFunc aSizeOfElementIncludingThis, - mozilla::MallocSizeOf aMallocSizeOf, void* aData) const -{ - size_t n = mArray.ShallowSizeOfExcludingThis(aMallocSizeOf); - - if (aSizeOfElementIncludingThis) { - for (uint32_t index = 0; index < mArray.Length(); ++index) { - n += aSizeOfElementIncludingThis(mArray[index], aMallocSizeOf, aData); - } - } - - return n; -} - - void nsCOMArray_base::Adopt(nsISupports** aElements, uint32_t aSize) { diff --git a/xpcom/glue/nsCOMArray.h b/xpcom/glue/nsCOMArray.h index 16a4fc1da8..7f9d5d39d1 100644 --- a/xpcom/glue/nsCOMArray.h +++ b/xpcom/glue/nsCOMArray.h @@ -163,15 +163,17 @@ public: void SetCapacity(uint32_t aCapacity) { mArray.SetCapacity(aCapacity); } uint32_t Capacity() { return mArray.Capacity(); } - typedef size_t (*nsBaseArraySizeOfElementIncludingThisFunc)( - nsISupports* aElement, mozilla::MallocSizeOf aMallocSizeOf, void* aData); - - // Measures the size of the array's element storage, and if - // |aSizeOfElement| is non-nullptr, measures the size of things pointed to - // by elements. - size_t SizeOfExcludingThis( - nsBaseArraySizeOfElementIncludingThisFunc aSizeOfElementIncludingThis, - mozilla::MallocSizeOf aMallocSizeOf, void* aData = nullptr) const; + // Measures the size of the array's element storage. If you want to measure + // anything hanging off the array, you must iterate over the elements and + // measure them individually; hence the "Shallow" prefix. Note that because + // each element in an nsCOMArray is actually a T* any such iteration + // should use a SizeOfIncludingThis() function on each element rather than a + // SizeOfExcludingThis() function, so that the memory taken by the T itself + // is included as well as anything it points to. + size_t ShallowSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const + { + return mArray.ShallowSizeOfExcludingThis(aMallocSizeOf); + } private: @@ -402,21 +404,6 @@ public: nsCOMArray_base::SwapElements(aOther); } - // Each element in an nsCOMArray is actually a T*, so this function is - // "IncludingThis" rather than "ExcludingThis" because it needs to measure - // the memory taken by the T itself as well as anything it points to. - typedef size_t (*nsCOMArraySizeOfElementIncludingThisFunc)( - T* aElement, mozilla::MallocSizeOf aMallocSizeOf, void* aData); - - size_t SizeOfExcludingThis( - nsCOMArraySizeOfElementIncludingThisFunc aSizeOfElementIncludingThis, - mozilla::MallocSizeOf aMallocSizeOf, void* aData = nullptr) const - { - return nsCOMArray_base::SizeOfExcludingThis( - nsBaseArraySizeOfElementIncludingThisFunc(aSizeOfElementIncludingThis), - aMallocSizeOf, aData); - } - /** * Adopt parameters that resulted from an XPIDL outparam. The aElements * parameter will be freed as a result of the call. diff --git a/xpcom/glue/staticruntime/moz.build b/xpcom/glue/staticruntime/moz.build index 227e654e9b..bc5a403567 100644 --- a/xpcom/glue/staticruntime/moz.build +++ b/xpcom/glue/staticruntime/moz.build @@ -37,6 +37,9 @@ USE_STATIC_LIBS = True # Don't use STL wrappers here (i.e. wrapped ); they require mozalloc DISABLE_STL_WRAPPING = True +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + # Include fallible for third party code using the xpcom glue USE_LIBS += [ 'fallible', diff --git a/xpcom/string/nsReadableUtils.cpp b/xpcom/string/nsReadableUtils.cpp index d0877d57ee..e76b84400d 100644 --- a/xpcom/string/nsReadableUtils.cpp +++ b/xpcom/string/nsReadableUtils.cpp @@ -1032,6 +1032,17 @@ CountCharInReadable(const nsACString& aStr, char aChar) return count; } +bool +StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring) +{ + nsAString::size_type src_len = aSource.Length(), + sub_len = aSubstring.Length(); + if (sub_len > src_len) { + return false; + } + return Substring(aSource, 0, sub_len).Equals(aSubstring); +} + bool StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring, const nsStringComparator& aComparator) @@ -1044,6 +1055,17 @@ StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring, return Substring(aSource, 0, sub_len).Equals(aSubstring, aComparator); } +bool +StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring) +{ + nsACString::size_type src_len = aSource.Length(), + sub_len = aSubstring.Length(); + if (sub_len > src_len) { + return false; + } + return Substring(aSource, 0, sub_len).Equals(aSubstring); +} + bool StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring, const nsCStringComparator& aComparator) @@ -1056,6 +1078,17 @@ StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring, return Substring(aSource, 0, sub_len).Equals(aSubstring, aComparator); } +bool +StringEndsWith(const nsAString& aSource, const nsAString& aSubstring) +{ + nsAString::size_type src_len = aSource.Length(), + sub_len = aSubstring.Length(); + if (sub_len > src_len) { + return false; + } + return Substring(aSource, src_len - sub_len, sub_len).Equals(aSubstring); +} + bool StringEndsWith(const nsAString& aSource, const nsAString& aSubstring, const nsStringComparator& aComparator) @@ -1069,6 +1102,17 @@ StringEndsWith(const nsAString& aSource, const nsAString& aSubstring, aComparator); } +bool +StringEndsWith(const nsACString& aSource, const nsACString& aSubstring) +{ + nsACString::size_type src_len = aSource.Length(), + sub_len = aSubstring.Length(); + if (sub_len > src_len) { + return false; + } + return Substring(aSource, src_len - sub_len, sub_len).Equals(aSubstring); +} + bool StringEndsWith(const nsACString& aSource, const nsACString& aSubstring, const nsCStringComparator& aComparator) diff --git a/xpcom/string/nsReadableUtils.h b/xpcom/string/nsReadableUtils.h index 6a697d5eae..12b2e67465 100644 --- a/xpcom/string/nsReadableUtils.h +++ b/xpcom/string/nsReadableUtils.h @@ -386,18 +386,18 @@ uint32_t CountCharInReadable(const nsAString& aStr, uint32_t CountCharInReadable(const nsACString& aStr, char aChar); +bool StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring); bool StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring, - const nsStringComparator& aComparator = - nsDefaultStringComparator()); + const nsStringComparator& aComparator); +bool StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring); bool StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring, - const nsCStringComparator& aComparator = - nsDefaultCStringComparator()); + const nsCStringComparator& aComparator); +bool StringEndsWith(const nsAString& aSource, const nsAString& aSubstring); bool StringEndsWith(const nsAString& aSource, const nsAString& aSubstring, - const nsStringComparator& aComparator = - nsDefaultStringComparator()); + const nsStringComparator& aComparator); +bool StringEndsWith(const nsACString& aSource, const nsACString& aSubstring); bool StringEndsWith(const nsACString& aSource, const nsACString& aSubstring, - const nsCStringComparator& aComparator = - nsDefaultCStringComparator()); + const nsCStringComparator& aComparator); const nsAFlatString& EmptyString(); const nsAFlatCString& EmptyCString(); diff --git a/xpcom/string/nsStringObsolete.cpp b/xpcom/string/nsStringObsolete.cpp index 9f8ce35061..bd6daacab3 100644 --- a/xpcom/string/nsStringObsolete.cpp +++ b/xpcom/string/nsStringObsolete.cpp @@ -540,7 +540,7 @@ StripChars2(char16_t* aString,uint32_t aLength,const char* aSet) { /* ***** END RICKG BLOCK ***** */ -static const char* kWhitespace="\b\t\r\n "; +static const char* kWhitespace="\f\t\r\n "; // This function is used to implement FindCharInSet and friends template diff --git a/xpcom/string/nsTSubstring.h b/xpcom/string/nsTSubstring.h index fb6328a3fa..8a2e9a357e 100644 --- a/xpcom/string/nsTSubstring.h +++ b/xpcom/string/nsTSubstring.h @@ -1126,6 +1126,13 @@ operator!=(const nsTSubstring_CharT::base_string_type& aLhs, return !aLhs.Equals(aRhs); } +inline bool +operator!=(const nsTSubstring_CharT::base_string_type& aLhs, + const nsTSubstring_CharT::char_type* aRhs) +{ + return !aLhs.Equals(aRhs); +} + inline bool operator<(const nsTSubstring_CharT::base_string_type& aLhs, const nsTSubstring_CharT::base_string_type& aRhs) diff --git a/xpcom/tests/external/TestMinStringAPI.cpp b/xpcom/tests/external/TestMinStringAPI.cpp index cd0880a739..117d631705 100644 --- a/xpcom/tests/external/TestMinStringAPI.cpp +++ b/xpcom/tests/external/TestMinStringAPI.cpp @@ -265,7 +265,7 @@ static bool test_replace() return true; } -static const char* kWhitespace="\b\t\r\n "; +static const char* kWhitespace="\f\t\r\n "; static void CompressWhitespace(nsACString &str)