Merge inbound to central, a=merge

--HG--
extra : commitid : 5s06anNiSWA
This commit is contained in:
Wes Kocher 2015-11-17 13:10:03 -08:00
commit f3c1ddea35
227 changed files with 3620 additions and 2933 deletions

View File

@ -401,14 +401,12 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindow* aWindow)
nsCOMPtr<nsIPresShell> shell = document->GetShell();
if (shell) {
// Reload only the chrome URL agent style sheets.
nsCOMArray<nsIStyleSheet> agentSheets;
nsTArray<RefPtr<CSSStyleSheet>> agentSheets;
rv = shell->GetAgentStyleSheets(agentSheets);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMArray<nsIStyleSheet> newAgentSheets;
for (int32_t l = 0; l < agentSheets.Count(); ++l) {
nsIStyleSheet *sheet = agentSheets[l];
nsTArray<RefPtr<CSSStyleSheet>> newAgentSheets;
for (CSSStyleSheet* sheet : agentSheets) {
nsIURI* uri = sheet->GetSheetURI();
if (IsChromeURI(uri)) {
@ -418,12 +416,12 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindow* 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;
}
}
@ -432,27 +430,22 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindow* aWindow)
NS_ENSURE_SUCCESS(rv, rv);
}
// Build an array of nsIURIs of style sheets we need to load.
nsCOMArray<nsIStyleSheet> oldSheets;
nsCOMArray<nsIStyleSheet> 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<RefPtr<CSSStyleSheet>> oldSheets(count);
nsTArray<RefPtr<CSSStyleSheet>> 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<CSSStyleSheet> sheet = do_QueryObject(oldSheets[i]);
for (CSSStyleSheet* sheet : oldSheets) {
nsIURI* uri = sheet ? sheet->GetOriginalURI() : nullptr;
if (uri && IsChromeURI(uri)) {
@ -462,11 +455,10 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindow* 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);
}
}

View File

@ -1341,7 +1341,6 @@ using namespace devtools;
/* static */ void
ThreadSafeChromeUtils::SaveHeapSnapshot(GlobalObject& global,
JSContext* cx,
const HeapSnapshotBoundaries& boundaries,
nsAString& outFilePath,
ErrorResult& rv)
@ -1360,6 +1359,7 @@ ThreadSafeChromeUtils::SaveHeapSnapshot(GlobalObject& global,
ZeroCopyNSIOutputStream zeroCopyStream(outputStream);
::google::protobuf::io::GzipOutputStream gzipStream(&zeroCopyStream);
JSContext* cx = global.Context();
StreamWriter writer(cx, gzipStream, wantNames);
if (NS_WARN_IF(!writer.init())) {
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
@ -1405,7 +1405,6 @@ ThreadSafeChromeUtils::SaveHeapSnapshot(GlobalObject& global,
/* static */ already_AddRefed<HeapSnapshot>
ThreadSafeChromeUtils::ReadHeapSnapshot(GlobalObject& global,
JSContext* cx,
const nsAString& filePath,
ErrorResult& rv)
{
@ -1423,7 +1422,8 @@ ThreadSafeChromeUtils::ReadHeapSnapshot(GlobalObject& global,
return nullptr;
RefPtr<HeapSnapshot> snapshot = HeapSnapshot::Create(
cx, global, reinterpret_cast<const uint8_t*>(mm.address()), mm.size(), rv);
global.Context(), global, reinterpret_cast<const uint8_t*>(mm.address()),
mm.size(), rv);
if (!rv.Failed())
Telemetry::AccumulateTimeDelta(Telemetry::DEVTOOLS_READ_HEAP_SNAPSHOT_MS,

View File

@ -25,14 +25,12 @@ class ThreadSafeChromeUtils
public:
// Implemented in devtools/shared/heapsnapshot/HeapSnapshot.cpp
static void SaveHeapSnapshot(GlobalObject& global,
JSContext* cx,
const HeapSnapshotBoundaries& boundaries,
nsAString& filePath,
ErrorResult& rv);
// Implemented in devtools/shared/heapsnapshot/HeapSnapshot.cpp
static already_AddRefed<devtools::HeapSnapshot> ReadHeapSnapshot(GlobalObject& global,
JSContext* cx,
const nsAString& filePath,
ErrorResult& rv);

View File

@ -99,7 +99,6 @@
#include "mozilla/Preferences.h"
#include "nsIContentIterator.h"
#include "nsIDOMStyleSheet.h"
#include "nsIStyleSheet.h"
#include "nsIStyleSheetService.h"
#include "nsContentPermissionHelper.h"
#include "nsNetUtil.h"
@ -3244,7 +3243,7 @@ nsDOMWindowUtils::AddSheet(nsIDOMStyleSheet *aSheet, uint32_t aSheetType)
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
nsIDocument::additionalSheetType type = convertSheetType(aSheetType);
nsCOMPtr<nsIStyleSheet> sheet = do_QueryInterface(aSheet);
RefPtr<CSSStyleSheet> sheet = do_QueryObject(aSheet);
NS_ENSURE_TRUE(sheet, NS_ERROR_FAILURE);
if (sheet->GetOwningDocument()) {
return NS_ERROR_INVALID_ARG;

View File

@ -725,15 +725,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<nsIDOMStyleSheet> domss(do_QueryInterface(sheet));
NS_ASSERTION(domss, "All \"normal\" sheets implement nsIDOMStyleSheet");
}
#endif
}
return mLength;
}
@ -747,7 +738,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<CSSStyleSheet*>(sheet);
@ -761,27 +752,21 @@ nsDOMStyleSheetList::NodeWillBeDestroyed(const nsINode *aNode)
void
nsDOMStyleSheetList::StyleSheetAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
CSSStyleSheet* aStyleSheet,
bool aDocumentSheet)
{
if (aDocumentSheet && -1 != mLength) {
nsCOMPtr<nsIDOMStyleSheet> domss(do_QueryInterface(aStyleSheet));
if (domss) {
mLength++;
}
mLength++;
}
}
void
nsDOMStyleSheetList::StyleSheetRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
CSSStyleSheet* aStyleSheet,
bool aDocumentSheet)
{
if (aDocumentSheet && -1 != mLength) {
nsCOMPtr<nsIDOMStyleSheet> domss(do_QueryInterface(aStyleSheet));
if (domss) {
mLength--;
}
mLength--;
}
}
@ -1347,7 +1332,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)) {
@ -1624,9 +1609,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);
}
@ -1634,9 +1617,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);
@ -2296,9 +2278,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()) {
@ -2312,12 +2292,12 @@ nsDocument::RemoveDocStyleSheetsFromStyleSets()
}
void
nsDocument::RemoveStyleSheetsFromStyleSets(nsCOMArray<nsIStyleSheet>& aSheets, SheetType aType)
nsDocument::RemoveStyleSheetsFromStyleSets(
nsTArray<RefPtr<CSSStyleSheet>>& 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()) {
@ -2326,10 +2306,8 @@ nsDocument::RemoveStyleSheetsFromStyleSets(nsCOMArray<nsIStyleSheet>& aSheets, S
shell->StyleSet()->RemoveStyleSheet(aType, sheet);
}
}
// XXX Tell observers?
}
}
void
@ -2379,21 +2357,13 @@ nsDocument::ResetStylesheetsToURI(nsIURI* aURI)
}
}
static bool
AppendAuthorSheet(nsIStyleSheet *aSheet, void *aData)
{
nsStyleSet *styleSet = static_cast<nsStyleSet*>(aData);
styleSet->AppendStyleSheet(SheetType::Doc, aSheet);
return true;
}
static void
AppendSheetsToStyleSet(nsStyleSet* aStyleSet,
const nsCOMArray<nsIStyleSheet>& aSheets,
const nsTArray<RefPtr<CSSStyleSheet>>& 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);
}
}
@ -2405,9 +2375,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);
}
@ -2415,13 +2383,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);
}
@ -4017,8 +3985,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<nsIStyleSheet*>(aSheet))) {
if (mOnDemandBuiltInUASheets.Contains(aSheet)) {
return;
}
BeginUpdate(UPDATE_STYLE);
@ -4029,8 +3996,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<nsIStyleSheet*>(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.
@ -4054,24 +4020,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<nsIPresShell> shell = GetShell();
if (shell) {
@ -4081,15 +4046,10 @@ nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
#define DO_STYLESHEET_NOTIFICATION(className, type, memberName, argName) \
do { \
RefPtr<CSSStyleSheet> 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<className> event = \
@ -4103,7 +4063,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, (this, aSheet, aDocumentSheet));
@ -4116,7 +4076,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, (this, aSheet, aDocumentSheet));
@ -4129,10 +4089,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()) {
@ -4143,7 +4103,7 @@ nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
}
void
nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet)
nsDocument::RemoveStyleSheetFromStyleSets(CSSStyleSheet* aSheet)
{
nsCOMPtr<nsIPresShell> shell = GetShell();
if (shell) {
@ -4152,12 +4112,12 @@ nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet)
}
void
nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
nsDocument::RemoveStyleSheet(CSSStyleSheet* aSheet)
{
NS_PRECONDITION(aSheet, "null arg");
nsCOMPtr<nsIStyleSheet> sheet = aSheet; // hold ref so it won't die too soon
RefPtr<CSSStyleSheet> 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;
}
@ -4174,17 +4134,17 @@ nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
}
void
nsDocument::UpdateStyleSheets(nsCOMArray<nsIStyleSheet>& aOldSheets,
nsCOMArray<nsIStyleSheet>& aNewSheets)
nsDocument::UpdateStyleSheets(nsTArray<RefPtr<CSSStyleSheet>>& aOldSheets,
nsTArray<RefPtr<CSSStyleSheet>>& 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<nsIStyleSheet> oldSheet;
RefPtr<CSSStyleSheet> oldSheet;
int32_t i;
for (i = 0; i < count; ++i) {
oldSheet = aOldSheets[i];
@ -4195,9 +4155,9 @@ nsDocument::UpdateStyleSheets(nsCOMArray<nsIStyleSheet>& 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);
@ -4211,10 +4171,11 @@ nsDocument::UpdateStyleSheets(nsCOMArray<nsIStyleSheet>& 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);
@ -4227,13 +4188,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 {
@ -4294,9 +4255,9 @@ ConvertAdditionalSheetType(nsIDocument::additionalSheetType aType)
}
static int32_t
FindSheet(const nsCOMArray<nsIStyleSheet>& aSheets, nsIURI* aSheetURI)
FindSheet(const nsTArray<RefPtr<CSSStyleSheet>>& 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();
@ -4350,7 +4311,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;
@ -4358,7 +4319,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<nsIPresShell> shell = GetShell();
@ -4379,12 +4340,12 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet
{
MOZ_ASSERT(aSheetURI);
nsCOMArray<nsIStyleSheet>& sheets = mAdditionalSheets[aType];
nsTArray<RefPtr<CSSStyleSheet>>& sheets = mAdditionalSheets[aType];
int32_t i = FindSheet(mAdditionalSheets[aType], aSheetURI);
if (i >= 0) {
nsCOMPtr<nsIStyleSheet> sheetRef = sheets[i];
sheets.RemoveObjectAt(i);
RefPtr<CSSStyleSheet> sheetRef = sheets[i];
sheets.RemoveElementAt(i);
BeginUpdate(UPDATE_STYLE);
if (!mIsGoingAway) {
@ -4405,10 +4366,10 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet
}
}
nsIStyleSheet*
CSSStyleSheet*
nsDocument::FirstAdditionalAuthorSheet()
{
return mAdditionalSheets[eAuthorSheet].SafeObjectAt(0);
return mAdditionalSheets[eAuthorSheet].SafeElementAt(0, nullptr);
}
nsIGlobalObject*
@ -5155,7 +5116,7 @@ nsDocument::DocumentStatesChanged(EventStates aStateMask)
}
void
nsDocument::StyleRuleChanged(nsIStyleSheet* aSheet,
nsDocument::StyleRuleChanged(CSSStyleSheet* aSheet,
css::Rule* aOldStyleRule,
css::Rule* aNewStyleRule)
{
@ -5173,7 +5134,7 @@ nsDocument::StyleRuleChanged(nsIStyleSheet* aSheet,
}
void
nsDocument::StyleRuleAdded(nsIStyleSheet* aSheet,
nsDocument::StyleRuleAdded(CSSStyleSheet* aSheet,
css::Rule* aStyleRule)
{
NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleAdded,
@ -5189,7 +5150,7 @@ nsDocument::StyleRuleAdded(nsIStyleSheet* aSheet,
}
void
nsDocument::StyleRuleRemoved(nsIStyleSheet* aSheet,
nsDocument::StyleRuleRemoved(CSSStyleSheet* aSheet,
css::Rule* aStyleRule)
{
NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleRemoved,
@ -6428,13 +6389,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<nsIDOMStyleSheet> 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;
@ -6544,7 +6503,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()) {
@ -10173,7 +10132,7 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer)
int32_t sheetsCount = GetNumberOfStyleSheets();
for (int32_t i = 0; i < sheetsCount; ++i) {
RefPtr<CSSStyleSheet> sheet = do_QueryObject(GetStyleSheetAt(i));
RefPtr<CSSStyleSheet> sheet = GetStyleSheetAt(i);
if (sheet) {
if (sheet->IsApplicable()) {
RefPtr<CSSStyleSheet> clonedSheet =
@ -10186,11 +10145,8 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer)
}
}
sheetsCount = thisAsDoc->mOnDemandBuiltInUASheets.Count();
// Iterate backwards to maintain order
for (int32_t i = sheetsCount - 1; i >= 0; --i) {
RefPtr<CSSStyleSheet> sheet =
do_QueryObject(thisAsDoc->mOnDemandBuiltInUASheets[i]);
for (CSSStyleSheet* sheet : Reversed(thisAsDoc->mOnDemandBuiltInUASheets)) {
if (sheet) {
if (sheet->IsApplicable()) {
RefPtr<CSSStyleSheet> clonedSheet =
@ -12278,7 +12234,7 @@ nsDocument::OnAppThemeChanged()
}
for (int32_t i = 0; i < GetNumberOfStyleSheets(); i++) {
RefPtr<CSSStyleSheet> sheet = do_QueryObject(GetStyleSheetAt(i));
RefPtr<CSSStyleSheet> sheet = GetStyleSheetAt(i);
if (!sheet) {
continue;
}
@ -12645,15 +12601,19 @@ nsIDocument::DocAddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const
}
static size_t
SizeOfStyleSheetsElementIncludingThis(nsIStyleSheet* aStyleSheet,
MallocSizeOf aMallocSizeOf,
void* aData)
SizeOfOwnedSheetArrayExcludingThis(const nsTArray<RefPtr<CSSStyleSheet>>& 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
@ -12704,26 +12664,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.

View File

@ -801,24 +801,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<nsIStyleSheet>& aOldSheets,
nsCOMArray<nsIStyleSheet>& aNewSheets) override;
virtual void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet);
virtual void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet);
virtual void UpdateStyleSheets(
nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aOldSheets,
nsTArray<RefPtr<mozilla::CSSStyleSheet>>& 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;
@ -878,12 +883,12 @@ public:
virtual void DocumentStatesChanged(
mozilla::EventStates aStateMask) override;
virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet,
virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet,
mozilla::css::Rule* aOldStyleRule,
mozilla::css::Rule* aNewStyleRule) 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;
@ -1494,8 +1499,9 @@ protected:
nsCompatibility aCompatMode);
void RemoveDocStyleSheetsFromStyleSets();
void RemoveStyleSheetsFromStyleSets(nsCOMArray<nsIStyleSheet>& aSheets,
mozilla::SheetType aType);
void RemoveStyleSheetsFromStyleSets(
nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aSheets,
mozilla::SheetType aType);
void ResetStylesheetsToURI(nsIURI* aURI);
void FillStyleSet(nsStyleSet* aStyleSet);
@ -1548,9 +1554,9 @@ protected:
// EndLoad() has already happened.
nsWeakPtr mWeakSink;
nsCOMArray<nsIStyleSheet> mStyleSheets;
nsCOMArray<nsIStyleSheet> mOnDemandBuiltInUASheets;
nsCOMArray<nsIStyleSheet> mAdditionalSheets[AdditionalSheetTypeCount];
nsTArray<RefPtr<mozilla::CSSStyleSheet>> mStyleSheets;
nsTArray<RefPtr<mozilla::CSSStyleSheet>> mOnDemandBuiltInUASheets;
nsTArray<RefPtr<mozilla::CSSStyleSheet>> mAdditionalSheets[AdditionalSheetTypeCount];
// Array of observers
nsTObserverArray<nsIDocumentObserver*> mObservers;
@ -1709,8 +1715,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();

View File

@ -72,7 +72,6 @@ class nsIRequest;
class nsIRunnable;
class nsIStreamListener;
class nsIStructuredCloneContainer;
class nsIStyleSheet;
class nsIURI;
class nsIVariant;
class nsLocation;
@ -156,8 +155,8 @@ typedef CallbackObjectHolder<NodeFilter, nsIDOMNodeFilter> NodeFilterHolder;
} // namespace mozilla
#define NS_IDOCUMENT_IID \
{ 0x4307abe8, 0x5386, 0x4024, \
{ 0xa2, 0xfe, 0x4a, 0x80, 0xe8, 0x47, 0x46, 0x90 } }
{ 0xecc9e376, 0x6c31, 0x4f04, \
{ 0xbe, 0xde, 0xd6, 0x27, 0x61, 0xd7, 0x00, 0x84 } }
// Enum for requesting a particular type of document when creating a doc
enum DocumentFlavor {
@ -925,7 +924,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)
@ -934,7 +933,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_
@ -942,7 +942,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
@ -952,24 +952,25 @@ public:
* may be null; if so the corresponding sheets in the first list
* will simply be removed.
*/
virtual void UpdateStyleSheets(nsCOMArray<nsIStyleSheet>& aOldSheets,
nsCOMArray<nsIStyleSheet>& aNewSheets) = 0;
virtual void UpdateStyleSheets(
nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aOldSheets,
nsTArray<RefPtr<mozilla::CSSStyleSheet>>& 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 {
@ -979,10 +980,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.
@ -1285,12 +1289,12 @@ 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* aOldStyleRule,
mozilla::css::Rule* aNewStyleRule) = 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;
/**

View File

@ -11,18 +11,18 @@
#include "nsIMutationObserver.h"
class nsIContent;
class nsIStyleSheet;
class nsIDocument;
namespace mozilla {
class CSSStyleSheet;
namespace css {
class Rule;
} // namespace css
} // namespace mozilla
#define NS_IDOCUMENT_OBSERVER_IID \
{ 0xce1d53d0, 0x4739, 0x44e5, \
{ 0xb4, 0xae, 0x60, 0xe8, 0x82, 0xcb, 0x73, 0x1b } }
{ 0x21c8ad67, 0x3a7d, 0x4881, \
{ 0xa5, 0x43, 0xcb, 0xa9, 0xbb, 0xe4, 0x9e, 0x39 } }
typedef uint32_t nsUpdateType;
@ -102,7 +102,7 @@ public:
* false if sheet is not (i.e., UA or user sheet)
*/
virtual void StyleSheetAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
mozilla::CSSStyleSheet* aStyleSheet,
bool aDocumentSheet) = 0;
/**
@ -117,7 +117,7 @@ public:
* false if sheet is not (i.e., UA or user sheet)
*/
virtual void StyleSheetRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
mozilla::CSSStyleSheet* aStyleSheet,
bool aDocumentSheet) = 0;
/**
@ -133,7 +133,7 @@ public:
* it is not applicable
*/
virtual void StyleSheetApplicableStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
mozilla::CSSStyleSheet* aStyleSheet,
bool aApplicable) = 0;
/**
@ -160,7 +160,7 @@ public:
* @param aNewStyleRule The rule being added.
*/
virtual void StyleRuleChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
mozilla::CSSStyleSheet* aStyleSheet,
mozilla::css::Rule* aOldStyleRule,
mozilla::css::Rule* aNewStyleRule) = 0;
@ -176,7 +176,7 @@ public:
* @param aStyleRule the rule that was added
*/
virtual void StyleRuleAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
mozilla::CSSStyleSheet* aStyleSheet,
mozilla::css::Rule* aStyleRule) = 0;
/**
@ -191,7 +191,7 @@ public:
* @param aStyleRule the rule that was removed
*/
virtual void StyleRuleRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
mozilla::CSSStyleSheet* aStyleSheet,
mozilla::css::Rule* aStyleRule) = 0;
};
@ -221,33 +221,34 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID)
#define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \
virtual void StyleSheetAdded(nsIDocument* aDocument, \
nsIStyleSheet* aStyleSheet, \
mozilla::CSSStyleSheet* aStyleSheet, \
bool aDocumentSheet) override;
#define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \
virtual void StyleSheetRemoved(nsIDocument* aDocument, \
nsIStyleSheet* aStyleSheet, \
mozilla::CSSStyleSheet* aStyleSheet, \
bool aDocumentSheet) override;
#define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \
virtual void StyleSheetApplicableStateChanged(nsIDocument* aDocument, \
nsIStyleSheet* aStyleSheet,\
bool aApplicable) override;
virtual void StyleSheetApplicableStateChanged( \
nsIDocument* aDocument, \
mozilla::CSSStyleSheet* aStyleSheet, \
bool aApplicable) override;
#define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \
virtual void StyleRuleChanged(nsIDocument* aDocument, \
nsIStyleSheet* aStyleSheet, \
mozilla::CSSStyleSheet* aStyleSheet, \
mozilla::css::Rule* aOldStyleRule, \
mozilla::css::Rule* aNewStyleRule) override;
#define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \
virtual void StyleRuleAdded(nsIDocument* aDocument, \
nsIStyleSheet* aStyleSheet, \
mozilla::CSSStyleSheet* aStyleSheet, \
mozilla::css::Rule* aStyleRule) override;
#define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \
virtual void StyleRuleRemoved(nsIDocument* aDocument, \
nsIStyleSheet* aStyleSheet, \
mozilla::CSSStyleSheet* aStyleSheet, \
mozilla::css::Rule* aStyleRule) override;
#define NS_DECL_NSIDOCUMENTOBSERVER \
@ -307,38 +308,38 @@ NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(_class)
#define NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(_class) \
void \
_class::StyleSheetAdded(nsIDocument* aDocument, \
nsIStyleSheet* aStyleSheet, \
bool aDocumentSheet) \
mozilla::CSSStyleSheet* aStyleSheet, \
bool aDocumentSheet) \
{ \
} \
void \
_class::StyleSheetRemoved(nsIDocument* aDocument, \
nsIStyleSheet* aStyleSheet, \
bool aDocumentSheet) \
mozilla::CSSStyleSheet* aStyleSheet, \
bool aDocumentSheet) \
{ \
} \
void \
_class::StyleSheetApplicableStateChanged(nsIDocument* aDocument, \
nsIStyleSheet* aStyleSheet, \
bool aApplicable) \
mozilla::CSSStyleSheet* aStyleSheet,\
bool aApplicable) \
{ \
} \
void \
_class::StyleRuleChanged(nsIDocument* aDocument, \
nsIStyleSheet* aStyleSheet, \
mozilla::CSSStyleSheet* aStyleSheet, \
mozilla::css::Rule* aOldStyleRule, \
mozilla::css::Rule* aNewStyleRule) \
{ \
} \
void \
_class::StyleRuleAdded(nsIDocument* aDocument, \
nsIStyleSheet* aStyleSheet, \
mozilla::CSSStyleSheet* aStyleSheet, \
mozilla::css::Rule* aStyleRule) \
{ \
} \
void \
_class::StyleRuleRemoved(nsIDocument* aDocument, \
nsIStyleSheet* aStyleSheet, \
mozilla::CSSStyleSheet* aStyleSheet, \
mozilla::css::Rule* aStyleRule) \
{ \
}

View File

@ -184,6 +184,14 @@ nsMappedAttributes::MapRuleInfoInto(nsRuleData* aRuleData)
}
}
/* virtual */ bool
nsMappedAttributes::MightMapInheritedStyleData()
{
// Just assume that we do, rather than adding checks to all of the different
// kinds of attribute mapping functions we have.
return true;
}
#ifdef DEBUG
/* virtual */ void
nsMappedAttributes::List(FILE* out, int32_t aIndent) const

View File

@ -74,6 +74,7 @@ public:
// nsIStyleRule
virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
virtual bool MightMapInheritedStyleData() override;
#ifdef DEBUG
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
#endif

View File

@ -288,17 +288,6 @@ UpdateIsElementInStyleScopeFlagOnSubtree(Element* aElement)
}
}
static Element*
GetScopeElement(nsIStyleSheet* aSheet)
{
RefPtr<CSSStyleSheet> cssStyleSheet = do_QueryObject(aSheet);
if (!cssStyleSheet) {
return nullptr;
}
return cssStyleSheet->GetScopeElement();
}
nsresult
nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
ShadowRoot* aOldShadowRoot,
@ -330,7 +319,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),

View File

@ -1340,7 +1340,6 @@ DOMInterfaces = {
# collection of static methods, so we have this `concrete: False` hack.
'concrete': False,
'headerFile': 'mozilla/dom/ChromeUtils.h',
'implicitJSContext': ['readHeapSnapshot', 'saveHeapSnapshot']
},
'TouchList': {

View File

@ -2388,15 +2388,11 @@ void
nsGonkCameraControl::OnNewPreviewFrame(layers::TextureClient* aBuffer)
{
#ifdef MOZ_WIDGET_GONK
RefPtr<Image> frame = mImageContainer->CreateImage(ImageFormat::GRALLOC_PLANAR_YCBCR);
RefPtr<GrallocImage> frame = new GrallocImage();
GrallocImage* videoImage = static_cast<GrallocImage*>(frame.get());
GrallocImage::GrallocData data;
data.mGraphicBuffer = aBuffer;
data.mPicSize = IntSize(mCurrentConfiguration.mPreviewSize.width,
mCurrentConfiguration.mPreviewSize.height);
videoImage->SetData(data);
IntSize picSize(mCurrentConfiguration.mPreviewSize.width,
mCurrentConfiguration.mPreviewSize.height);
frame->SetData(aBuffer, picSize);
if (mCapturePoster.exchange(false)) {
CreatePoster(frame,

View File

@ -151,15 +151,7 @@ static already_AddRefed<layers::Image>
CreateImageFromSurface(SourceSurface* aSurface, ErrorResult& aRv)
{
MOZ_ASSERT(aSurface);
layers::CairoImage::Data cairoData;
cairoData.mSize = aSurface->GetSize();
cairoData.mSourceSurface = aSurface;
RefPtr<layers::CairoImage> image = new layers::CairoImage();
image->SetData(cairoData);
RefPtr<layers::CairoImage> image = new layers::CairoImage(aSurface->GetSize(), aSurface);
return image.forget();
}

View File

@ -168,6 +168,12 @@ BodyRule::MapRuleInfoInto(nsRuleData* aData)
}
}
/* virtual */ bool
BodyRule::MightMapInheritedStyleData()
{
return false;
}
#ifdef DEBUG
/* virtual */ void
BodyRule::List(FILE* out, int32_t aIndent) const

View File

@ -28,6 +28,7 @@ public:
// nsIStyleRule interface
virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
virtual bool MightMapInheritedStyleData() override;
#ifdef DEBUG
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
#endif

View File

@ -1173,13 +1173,7 @@ void
HTMLCanvasElement::SetFrameCapture(already_AddRefed<SourceSurface> aSurface)
{
RefPtr<SourceSurface> surface = aSurface;
CairoImage::Data imageData;
imageData.mSize = surface->GetSize();
imageData.mSourceSurface = surface;
RefPtr<CairoImage> image = new CairoImage();
image->SetData(imageData);
RefPtr<CairoImage> image = new CairoImage(surface->GetSize(), surface);
// Loop backwards to allow removing elements in the loop.
for (int i = mRequestedFrameListeners.Length() - 1; i >= 0; --i) {

View File

@ -21,7 +21,6 @@
#include "nsIDOMEvent.h"
#include "nsIDOMStyleSheet.h"
#include "nsINode.h"
#include "nsIStyleSheet.h"
#include "nsIStyleSheetLinkingElement.h"
#include "nsIURL.h"
#include "nsPIDOMWindow.h"

View File

@ -979,8 +979,13 @@ void HTMLMediaElement::NotifyMediaTrackEnabled(MediaTrack* aTrack)
if (!aTrack) {
return;
}
#ifdef DEBUG
nsString id;
aTrack->GetId(id);
LOG(LogLevel::Debug, ("MediaElement %p MediaStreamTrack %p enabled", this));
LOG(LogLevel::Debug, ("MediaElement %p MediaStreamTrack enabled with id %s",
this, NS_ConvertUTF16toUTF8(id).get()));
#endif
// TODO: We are dealing with single audio track and video track for now.
if (AudioTrack* track = aTrack->AsAudioTrack()) {

View File

@ -8,7 +8,6 @@
#include "nsGkAtoms.h"
#include "nsStyleConsts.h"
#include "nsIDOMStyleSheet.h"
#include "nsIStyleSheet.h"
#include "nsIDocument.h"
#include "nsUnicharUtils.h"
#include "nsThreadUtils.h"

View File

@ -2641,12 +2641,12 @@ nsHTMLDocument::TearingDownEditor(nsIEditor *aEditor)
if (!presShell)
return;
nsCOMArray<nsIStyleSheet> agentSheets;
nsTArray<RefPtr<CSSStyleSheet>> agentSheets;
presShell->GetAgentStyleSheets(agentSheets);
agentSheets.RemoveObject(nsLayoutStylesheetCache::ContentEditableSheet());
agentSheets.RemoveElement(nsLayoutStylesheetCache::ContentEditableSheet());
if (oldState == eDesignMode)
agentSheets.RemoveObject(nsLayoutStylesheetCache::DesignModeSheet());
agentSheets.RemoveElement(nsLayoutStylesheetCache::DesignModeSheet());
presShell->SetAgentStyleSheets(agentSheets);
@ -2780,18 +2780,15 @@ nsHTMLDocument::EditingStateChanged()
// Before making this window editable, we need to modify UA style sheet
// because new style may change whether focused element will be focusable
// or not.
nsCOMArray<nsIStyleSheet> agentSheets;
nsTArray<RefPtr<CSSStyleSheet>> agentSheets;
rv = presShell->GetAgentStyleSheets(agentSheets);
NS_ENSURE_SUCCESS(rv, rv);
CSSStyleSheet* contentEditableSheet =
nsLayoutStylesheetCache::ContentEditableSheet();
bool result;
if (!agentSheets.Contains(contentEditableSheet)) {
bool result = agentSheets.AppendObject(contentEditableSheet);
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
agentSheets.AppendElement(contentEditableSheet);
}
// Should we update the editable state of all the nodes in the document? We
@ -2802,8 +2799,7 @@ nsHTMLDocument::EditingStateChanged()
CSSStyleSheet* designModeSheet =
nsLayoutStylesheetCache::DesignModeSheet();
if (!agentSheets.Contains(designModeSheet)) {
result = agentSheets.AppendObject(designModeSheet);
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
agentSheets.AppendElement(designModeSheet);
}
updateState = true;
@ -2811,7 +2807,7 @@ nsHTMLDocument::EditingStateChanged()
}
else if (oldState == eDesignMode) {
// designMode is being turned off (contentEditable is still on).
agentSheets.RemoveObject(nsLayoutStylesheetCache::DesignModeSheet());
agentSheets.RemoveElement(nsLayoutStylesheetCache::DesignModeSheet());
updateState = true;
}

View File

@ -57,3 +57,21 @@ interface nsIPushNotificationService : nsISupports
*/
jsval clearForDomain(in string domain);
};
[scriptable, uuid(a2555e70-46f8-4b52-bf02-d978b979d143)]
interface nsIPushQuotaManager : nsISupports
{
/**
* Informs the quota manager that a notification
* for the given origin has been shown. Used to
* determine if push quota should be relaxed.
*/
void notificationForOriginShown(in string origin);
/**
* Informs the quota manager that a notification
* for the given origin has been closed. Used to
* determine if push quota should be relaxed.
*/
void notificationForOriginClosed(in string origin);
};

View File

@ -36,6 +36,7 @@
#include "imgIContainer.h"
#include "mozIApplication.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/CSSStyleSheet.h"
#include "mozilla/DataStorage.h"
#include "mozilla/devtools/HeapSnapshotTempFileHelperParent.h"
#include "mozilla/docshell/OfflineCacheUpdateParent.h"
@ -142,7 +143,6 @@
#include "nsIScriptSecurityManager.h"
#include "nsISiteSecurityService.h"
#include "nsISpellChecker.h"
#include "nsIStyleSheet.h"
#include "nsISupportsPrimitives.h"
#include "nsISystemMessagesInternal.h"
#include "nsITimer.h"
@ -2576,24 +2576,21 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority,
// This looks like a lot of work, but in a normal browser session we just
// send two loads.
nsCOMArray<nsIStyleSheet>& agentSheets = *sheetService->AgentStyleSheets();
for (uint32_t i = 0; i < agentSheets.Length(); i++) {
for (CSSStyleSheet* sheet : *sheetService->AgentStyleSheets()) {
URIParams uri;
SerializeURI(agentSheets[i]->GetSheetURI(), uri);
SerializeURI(sheet->GetSheetURI(), uri);
Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AGENT_SHEET);
}
nsCOMArray<nsIStyleSheet>& userSheets = *sheetService->UserStyleSheets();
for (uint32_t i = 0; i < userSheets.Length(); i++) {
for (CSSStyleSheet* sheet : *sheetService->UserStyleSheets()) {
URIParams uri;
SerializeURI(userSheets[i]->GetSheetURI(), uri);
SerializeURI(sheet->GetSheetURI(), uri);
Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::USER_SHEET);
}
nsCOMArray<nsIStyleSheet>& authorSheets = *sheetService->AuthorStyleSheets();
for (uint32_t i = 0; i < authorSheets.Length(); i++) {
for (CSSStyleSheet* sheet : *sheetService->AuthorStyleSheets()) {
URIParams uri;
SerializeURI(authorSheets[i]->GetSheetURI(), uri);
SerializeURI(sheet->GetSheetURI(), uri);
Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AUTHOR_SHEET);
}
}

View File

@ -1044,10 +1044,9 @@ DOMHwMediaStream::DOMHwMediaStream()
{
#ifdef MOZ_WIDGET_GONK
mImageContainer = LayerManager::CreateImageContainer(ImageContainer::ASYNCHRONOUS_OVERLAY);
RefPtr<Image> img = mImageContainer->CreateImage(ImageFormat::OVERLAY_IMAGE);
mOverlayImage = static_cast<layers::OverlayImage*>(img.get());
mOverlayImage = mImageContainer->CreateOverlayImage();
nsAutoTArray<ImageContainer::NonOwningImage,1> images;
images.AppendElement(ImageContainer::NonOwningImage(img));
images.AppendElement(ImageContainer::NonOwningImage(mOverlayImage));
mImageContainer->SetCurrentImages(images);
#endif
}

View File

@ -312,11 +312,11 @@ VideoData::Create(const VideoInfo& aInfo,
// format.
#ifdef MOZ_WIDGET_GONK
if (IsYV12Format(Y, Cb, Cr) && !IsInEmulator()) {
v->mImage = aContainer->CreateImage(ImageFormat::GRALLOC_PLANAR_YCBCR);
v->mImage = new layers::GrallocImage();
}
#endif
if (!v->mImage) {
v->mImage = aContainer->CreateImage(ImageFormat::PLANAR_YCBCR);
v->mImage = aContainer->CreatePlanarYCbCrImage();
}
} else {
v->mImage = aImage;
@ -328,7 +328,8 @@ VideoData::Create(const VideoInfo& aInfo,
NS_ASSERTION(v->mImage->GetFormat() == ImageFormat::PLANAR_YCBCR ||
v->mImage->GetFormat() == ImageFormat::GRALLOC_PLANAR_YCBCR,
"Wrong format?");
PlanarYCbCrImage* videoImage = static_cast<PlanarYCbCrImage*>(v->mImage.get());
PlanarYCbCrImage* videoImage = v->mImage->AsPlanarYCbCrImage();
MOZ_ASSERT(videoImage);
bool shouldCopyData = (aImage == nullptr);
if (!VideoData::SetVideoDataToImage(videoImage, aInfo, aBuffer, aPicture,
@ -339,11 +340,11 @@ VideoData::Create(const VideoInfo& aInfo,
#ifdef MOZ_WIDGET_GONK
if (!videoImage->IsValid() && !aImage && IsYV12Format(Y, Cb, Cr)) {
// Failed to allocate gralloc. Try fallback.
v->mImage = aContainer->CreateImage(ImageFormat::PLANAR_YCBCR);
v->mImage = aContainer->CreatePlanarYCbCrImage();
if (!v->mImage) {
return nullptr;
}
videoImage = static_cast<PlanarYCbCrImage*>(v->mImage.get());
videoImage = v->mImage->AsPlanarYCbCrImage();
if(!VideoData::SetVideoDataToImage(videoImage, aInfo, aBuffer, aPicture,
true /* aCopyData */)) {
return nullptr;
@ -460,22 +461,9 @@ VideoData::Create(const VideoInfo& aInfo,
aInfo.mDisplay,
0));
v->mImage = aContainer->CreateImage(ImageFormat::GRALLOC_PLANAR_YCBCR);
if (!v->mImage) {
return nullptr;
}
NS_ASSERTION(v->mImage->GetFormat() == ImageFormat::GRALLOC_PLANAR_YCBCR,
"Wrong format?");
typedef mozilla::layers::GrallocImage GrallocImage;
GrallocImage* videoImage = static_cast<GrallocImage*>(v->mImage.get());
GrallocImage::GrallocData data;
data.mPicSize = aPicture.Size();
data.mGraphicBuffer = aBuffer;
if (!videoImage->SetData(data)) {
return nullptr;
}
RefPtr<layers::GrallocImage> image = new layers::GrallocImage();
image->SetData(aBuffer, aPicture.Size());
v->mImage = image;
return v.forget();
}

View File

@ -828,13 +828,11 @@ MediaStreamGraphImpl::PlayVideo(MediaStream* aStream)
if (frame->GetForceBlack()) {
if (!blackImage) {
blackImage = aStream->mVideoOutputs[0]->
GetImageContainer()->CreateImage(ImageFormat::PLANAR_YCBCR);
blackImage = aStream->mVideoOutputs[0]->GetImageContainer()->CreatePlanarYCbCrImage();
if (blackImage) {
// Sets the image to a single black pixel, which will be scaled to
// fill the rendered size.
SetImageToBlackPixel(static_cast<PlanarYCbCrImage*>
(blackImage.get()));
SetImageToBlackPixel(blackImage->AsPlanarYCbCrImage());
}
}
if (blackImage) {

View File

@ -43,17 +43,14 @@ VideoFrame::TakeFrom(VideoFrame* aFrame)
/* static */ already_AddRefed<Image>
VideoFrame::CreateBlackImage(const gfx::IntSize& aSize)
{
RefPtr<ImageContainer> container;
RefPtr<Image> image;
container = LayerManager::CreateImageContainer();
image = container->CreateImage(ImageFormat::PLANAR_YCBCR);
RefPtr<ImageContainer> container = LayerManager::CreateImageContainer();
RefPtr<PlanarYCbCrImage> image = container->CreatePlanarYCbCrImage();
if (!image) {
MOZ_ASSERT(false);
return nullptr;
}
int len = ((aSize.width * aSize.height) * 3 / 2);
PlanarYCbCrImage* planar = static_cast<PlanarYCbCrImage*>(image.get());
// Generate a black image.
ScopedDeletePtr<uint8_t> frame(new uint8_t[len]);
@ -80,7 +77,7 @@ VideoFrame::CreateBlackImage(const gfx::IntSize& aSize)
data.mStereoMode = StereoMode::MONO;
// SetData copies data, so we can free data.
if (!planar->SetData(data)) {
if (!image->SetData(data)) {
MOZ_ASSERT(false);
return nullptr;
}

View File

@ -387,8 +387,8 @@ uint8_t *
AndroidMediaReader::ImageBufferCallback::CreateI420Image(size_t aWidth,
size_t aHeight)
{
mImage = mImageContainer->CreateImage(ImageFormat::PLANAR_YCBCR);
PlanarYCbCrImage *yuvImage = static_cast<PlanarYCbCrImage *>(mImage.get());
RefPtr<PlanarYCbCrImage> yuvImage = mImageContainer->CreatePlanarYCbCrImage();
mImage = yuvImage;
if (!yuvImage) {
NS_WARNING("Could not create I420 image");

View File

@ -45,8 +45,7 @@ GstFlowReturn GStreamerReader::AllocateVideoBufferFull(GstPad* aPad,
if (container == nullptr) {
return GST_FLOW_ERROR;
}
RefPtr<PlanarYCbCrImage> image =
container->CreateImage(ImageFormat::PLANAR_YCBCR).downcast<PlanarYCbCrImage>();
RefPtr<PlanarYCbCrImage> image = container->CreatePlanarYCbCrImage();
/* prepare a GstBuffer pointing to the underlying PlanarYCbCrImage buffer */
GstBuffer* buf = GST_BUFFER(gst_moz_video_buffer_new());

View File

@ -127,14 +127,8 @@ public:
return NS_ERROR_FAILURE;
}
RefPtr<layers::Image> img = mImageContainer->CreateImage(ImageFormat::SURFACE_TEXTURE);
layers::SurfaceTextureImage::Data data;
data.mSurfTex = mSurfaceTexture.get();
data.mSize = mConfig.mDisplay;
data.mOriginPos = gl::OriginPos::BottomLeft;
layers::SurfaceTextureImage* stImg = static_cast<layers::SurfaceTextureImage*>(img.get());
stImg->SetData(data);
RefPtr<layers::Image> img =
new SurfaceTextureImage(mSurfaceTexture.get(), mConfig.mDisplay, gl::OriginPos::BottomLeft);
if (WantCopy()) {
EGLImage eglImage = CopySurface(img);
@ -156,16 +150,10 @@ public:
NS_WARNING("No EGL fence support detected, rendering artifacts may occur!");
}
img = mImageContainer->CreateImage(ImageFormat::EGLIMAGE);
layers::EGLImageImage::Data data;
data.mImage = eglImage;
data.mSync = eglSync;
data.mOwns = true;
data.mSize = mConfig.mDisplay;
data.mOriginPos = gl::OriginPos::TopLeft;
layers::EGLImageImage* typedImg = static_cast<layers::EGLImageImage*>(img.get());
typedImg->SetData(data);
img = new layers::EGLImageImage(
eglImage, eglSync,
mConfig.mDisplay, gl::OriginPos::TopLeft,
true /* owns */);
}
nsresult rv;

View File

@ -397,11 +397,7 @@ AppleVDADecoder::OutputFrame(CVPixelBufferRef aImage,
RefPtr<MacIOSurface> macSurface = new MacIOSurface(surface);
RefPtr<layers::Image> image =
mImageContainer->CreateImage(ImageFormat::MAC_IOSURFACE);
layers::MacIOSurfaceImage* videoImage =
static_cast<layers::MacIOSurfaceImage*>(image.get());
videoImage->SetSurface(macSurface);
RefPtr<layers::Image> image = new MacIOSurfaceImage(macSurface);
data =
VideoData::CreateFromImage(info,

View File

@ -331,10 +331,8 @@ FFmpegH264Decoder<LIBAV_VER>::AllocateYUV420PVideoBuffer(
size_t allocSize = pitch * decodeHeight + (chroma_pitch * chroma_height) * 2;
RefPtr<Image> image =
mImageContainer->CreateImage(ImageFormat::PLANAR_YCBCR);
PlanarYCbCrImage* ycbcr = static_cast<PlanarYCbCrImage*>(image.get());
uint8_t* buffer = ycbcr->AllocateAndGetNewBuffer(allocSize + 64);
RefPtr<PlanarYCbCrImage> image = mImageContainer->CreatePlanarYCbCrImage();
uint8_t* buffer = image->AllocateAndGetNewBuffer(allocSize + 64);
// FFmpeg requires a 16/32 bytes-aligned buffer, align it on 64 to be safe
buffer = reinterpret_cast<uint8_t*>((reinterpret_cast<uintptr_t>(buffer) + 63) & ~63);

View File

@ -420,17 +420,13 @@ D3D9DXVA2Manager::CopyToImage(IMFSample* aSample,
getter_AddRefs(surface));
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
RefPtr<Image> image = aImageContainer->CreateImage(ImageFormat::D3D9_RGB32_TEXTURE);
NS_ENSURE_TRUE(image, E_FAIL);
NS_ASSERTION(image->GetFormat() == ImageFormat::D3D9_RGB32_TEXTURE,
"Wrong format?");
RefPtr<D3D9SurfaceImage> image = new D3D9SurfaceImage(mFirstFrame);
hr = image->AllocateAndCopy(mTextureClientAllocator, surface, aRegion);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
D3D9SurfaceImage* videoImage = static_cast<D3D9SurfaceImage*>(image.get());
hr = videoImage->SetData(D3D9SurfaceImage::Data(surface, aRegion, mTextureClientAllocator, mFirstFrame));
mFirstFrame = false;
image.forget(aOutImage);
return S_OK;
}
@ -714,23 +710,16 @@ D3D11DXVA2Manager::CopyToImage(IMFSample* aVideoSample,
// to create a copy of that frame as a sharable resource, save its share
// handle, and put that handle into the rendering pipeline.
ImageFormat format = ImageFormat::D3D11_SHARE_HANDLE_TEXTURE;
RefPtr<Image> image(aContainer->CreateImage(format));
NS_ENSURE_TRUE(image, E_FAIL);
NS_ASSERTION(image->GetFormat() == ImageFormat::D3D11_SHARE_HANDLE_TEXTURE,
"Wrong format?");
RefPtr<D3D11ShareHandleImage> image =
new D3D11ShareHandleImage(gfx::IntSize(mWidth, mHeight), aRegion);
bool ok = image->AllocateTexture(mTextureClientAllocator);
NS_ENSURE_TRUE(ok, E_FAIL);
D3D11ShareHandleImage* videoImage = static_cast<D3D11ShareHandleImage*>(image.get());
HRESULT hr = videoImage->SetData(D3D11ShareHandleImage::Data(mTextureClientAllocator,
gfx::IntSize(mWidth, mHeight),
aRegion));
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
hr = mTransform->Input(aVideoSample);
HRESULT hr = mTransform->Input(aVideoSample);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
RefPtr<IMFSample> sample;
RefPtr<ID3D11Texture2D> texture = videoImage->GetTexture();
RefPtr<ID3D11Texture2D> texture = image->GetTexture();
hr = CreateOutputSample(sample, texture);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);

View File

@ -367,12 +367,8 @@ WMFVideoMFTManager::ConfigureVideoFrameGeometry()
NS_ENSURE_TRUE(videoFormat == MFVideoFormat_NV12 || !mUseHwAccel, E_FAIL);
NS_ENSURE_TRUE(videoFormat == MFVideoFormat_YV12 || mUseHwAccel, E_FAIL);
UINT32 width = 0, height = 0;
hr = MFGetAttributeSize(mediaType, MF_MT_FRAME_SIZE, &width, &height);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
mVideoInfo.mImage.width = width;
mVideoInfo.mImage.height = height;
UINT32 width = mVideoInfo.mImage.width;
UINT32 height = mVideoInfo.mImage.height;
nsIntRect pictureRegion = mVideoInfo.mImage;
// Calculate and validate the picture region and frame dimensions after
// scaling by the pixel aspect ratio.

View File

@ -72,6 +72,8 @@ skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g(Bug 1021776, too --ing
skip-if = toolkit == 'gonk' # B2G emulator is too slow to handle a two-way audio call reliably
[test_peerConnection_basicAudioRequireEOC.html]
skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
[test_peerConnection_basicAudioPcmaPcmuOnly.html]
skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
[test_peerConnection_basicAudioVideo.html]
skip-if = toolkit == 'gonk' || buildapp == 'mulet' || (android_version == '18' && debug) # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
[test_peerConnection_basicAudioVideoCombined.html]

View File

@ -62,6 +62,7 @@ function PeerConnectionTest(options) {
options.h264 = "h264" in options ? options.h264 : false;
options.bundle = "bundle" in options ? options.bundle : true;
options.rtcpmux = "rtcpmux" in options ? options.rtcpmux : true;
options.opus = "opus" in options ? options.opus : true;
if (typeof turnServers !== "undefined") {
if ((!options.turn_disabled_local) && (turnServers.local)) {

View File

@ -45,6 +45,14 @@ removeBundle: function(sdp) {
return sdp.replace(/a=group:BUNDLE .*\r\n/g, "");
},
reduceAudioMLineToPcmuPcma: function(sdp) {
return sdp.replace(/m=audio .*\r\n/g, "m=audio 9 UDP/TLS/RTP/SAVPF 0 8\r\n");
},
removeAllRtpMaps: function(sdp) {
return sdp.replace(/a=rtpmap:.*\r\n/g, "");
},
verifySdp: function(desc, expectedType, offerConstraintsList, offerOptions,
testOptions) {
info("Examining this SessionDescription: " + JSON.stringify(desc));
@ -76,7 +84,7 @@ verifySdp: function(desc, expectedType, offerConstraintsList, offerOptions,
ok(!desc.sdp.includes("m=audio"), "audio m-line is absent from SDP");
} else {
ok(desc.sdp.includes("m=audio"), "audio m-line is present in SDP");
ok(desc.sdp.includes("a=rtpmap:109 opus/48000/2"), "OPUS codec is present in SDP");
is(testOptions.opus, desc.sdp.includes("a=rtpmap:109 opus/48000/2"), "OPUS codec is present in SDP");
//TODO: ideally the rtcp-mux should be for the m=audio, and not just
// anywhere in the SDP (JS SDP parser bug 1045429)
is(testOptions.rtcpmux, desc.sdp.includes("a=rtcp-mux"), "RTCP Mux is offered in SDP");

View File

@ -0,0 +1,34 @@
<!DOCTYPE HTML>
<html>
<head>
<script type="application/javascript" src="pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
createHTML({
bug: "796892",
title: "Only offer PCMA and PMCU in mline (no rtpmaps)"
});
var test;
runNetworkTest(function (options) {
options = options || { };
options.opus = false;
test = new PeerConnectionTest(options);
test.chain.insertBefore("PC_REMOTE_GET_OFFER", [
function PC_LOCAL_REDUCE_MLINE_REMOVE_RTPMAPS(test) {
test.originalOffer.sdp =
sdputils.reduceAudioMLineToPcmuPcma(test.originalOffer.sdp);
test.originalOffer.sdp =
sdputils.removeAllRtpMaps(test.originalOffer.sdp);
info("SDP without Rtpmaps: " + JSON.stringify(test.originalOffer));
}
]);
test.setMediaConstraints([{audio: true}], [{audio: true}]);
test.run();
});
</script>
</pre>
</body>
</html>

View File

@ -236,9 +236,7 @@ MediaEngineDefaultVideoSource::Notify(nsITimer* aTimer)
}
// Allocate a single solid color image
RefPtr<layers::Image> image = mImageContainer->CreateImage(ImageFormat::PLANAR_YCBCR);
RefPtr<layers::PlanarYCbCrImage> ycbcr_image =
static_cast<layers::PlanarYCbCrImage*>(image.get());
RefPtr<layers::PlanarYCbCrImage> ycbcr_image = mImageContainer->CreatePlanarYCbCrImage();
layers::PlanarYCbCrData data;
AllocateSolidColorFrame(data, mOpts.mWidth, mOpts.mHeight, 0x80, mCb, mCr);

View File

@ -738,9 +738,9 @@ MediaEngineGonkVideoSource::RotateImage(layers::Image* aImage, uint32_t aWidth,
graphicBuffer->lock(GraphicBuffer::USAGE_SW_READ_MASK, &pMem);
uint8_t* srcPtr = static_cast<uint8_t*>(pMem);
// Create a video frame and append it to the track.
ImageFormat format = ImageFormat::GONK_CAMERA_IMAGE;
RefPtr<layers::Image> image = mImageContainer->CreateImage(format);
RefPtr<layers::PlanarYCbCrImage> image = new GonkCameraImage();
uint32_t dstWidth;
uint32_t dstHeight;
@ -755,7 +755,6 @@ MediaEngineGonkVideoSource::RotateImage(layers::Image* aImage, uint32_t aWidth,
uint32_t half_width = dstWidth / 2;
layers::GrallocImage* videoImage = static_cast<layers::GrallocImage*>(image.get());
MOZ_ASSERT(mTextureClientAllocator);
RefPtr<layers::TextureClient> textureClient
= mTextureClientAllocator->CreateOrRecycle(gfx::SurfaceFormat::YUV,
@ -764,8 +763,7 @@ MediaEngineGonkVideoSource::RotateImage(layers::Image* aImage, uint32_t aWidth,
layers::TextureFlags::DEFAULT,
layers::ALLOC_DISALLOW_BUFFERTEXTURECLIENT);
if (textureClient) {
RefPtr<layers::GrallocTextureClientOGL> grallocTextureClient =
static_cast<layers::GrallocTextureClientOGL*>(textureClient.get());
RefPtr<layers::GrallocTextureClientOGL> grallocTextureClient = textureClient->AsGrallocTextureClientOGL();
android::sp<android::GraphicBuffer> destBuffer = grallocTextureClient->GetGraphicBuffer();
@ -788,16 +786,11 @@ MediaEngineGonkVideoSource::RotateImage(layers::Image* aImage, uint32_t aWidth,
libyuv::FOURCC_NV21);
destBuffer->unlock();
layers::GrallocImage::GrallocData data;
data.mPicSize = gfx::IntSize(dstWidth, dstHeight);
data.mGraphicBuffer = textureClient;
videoImage->SetData(data);
image->AsGrallocImage()->SetData(textureClient, gfx::IntSize(dstWidth, dstHeight));
} else {
// Handle out of gralloc case.
image = mImageContainer->CreateImage(ImageFormat::PLANAR_YCBCR);
layers::PlanarYCbCrImage* videoImage = static_cast<layers::PlanarYCbCrImage*>(image.get());
uint8_t* dstPtr = videoImage->AllocateAndGetNewBuffer(size);
image = mImageContainer->CreatePlanarYCbCrImage();
uint8_t* dstPtr = image->AsPlanarYCbCrImage()->AllocateAndGetNewBuffer(size);
libyuv::ConvertToI420(srcPtr, size,
dstPtr, dstWidth,
@ -825,7 +818,7 @@ MediaEngineGonkVideoSource::RotateImage(layers::Image* aImage, uint32_t aWidth,
data.mPicSize = IntSize(dstWidth, dstHeight);
data.mStereoMode = StereoMode::MONO;
videoImage->SetDataNoCopy(data);
image->AsPlanarYCbCrImage()->SetDataNoCopy(data);
}
graphicBuffer->unlock();

View File

@ -294,8 +294,7 @@ MediaEngineRemoteVideoSource::DeliverFrame(unsigned char* buffer,
}
// Create a video frame and append it to the track.
RefPtr<layers::Image> image = mImageContainer->CreateImage(ImageFormat::PLANAR_YCBCR);
layers::PlanarYCbCrImage* videoImage = static_cast<layers::PlanarYCbCrImage*>(image.get());
RefPtr<layers::PlanarYCbCrImage> image = mImageContainer->CreatePlanarYCbCrImage();
uint8_t* frame = static_cast<uint8_t*> (buffer);
const uint8_t lumaBpp = 8;
@ -315,7 +314,7 @@ MediaEngineRemoteVideoSource::DeliverFrame(unsigned char* buffer,
data.mPicSize = IntSize(mWidth, mHeight);
data.mStereoMode = StereoMode::MONO;
if (!videoImage->SetData(data)) {
if (!image->SetData(data)) {
MOZ_ASSERT(false);
return 0;
}

View File

@ -298,13 +298,7 @@ MediaEngineTabVideoSource::Draw() {
return;
}
layers::CairoImage::Data cairoData;
cairoData.mSize = size;
cairoData.mSourceSurface = surface;
RefPtr<layers::CairoImage> image = new layers::CairoImage();
image->SetData(cairoData);
RefPtr<layers::CairoImage> image = new layers::CairoImage(size, surface);
MonitorAutoLock mon(mMonitor);
mImage = image;

View File

@ -51,6 +51,10 @@
#include "nsIDOMDesktopNotification.h"
#endif
#ifndef MOZ_SIMPLEPUSH
#include "nsIPushNotificationService.h"
#endif
namespace mozilla {
namespace dom {
@ -678,6 +682,8 @@ protected:
{
AssertIsOnMainThread();
}
nsresult AdjustPushQuota(const char* aTopic);
};
NS_IMPL_ISUPPORTS(NotificationObserver, nsIObserver)
@ -1173,11 +1179,39 @@ NotificationObserver::Observe(nsISupports* aSubject, const char* aTopic,
ContentChild::GetSingleton()->SendOpenNotificationSettings(
IPC::Principal(mPrincipal));
return NS_OK;
} else if (!strcmp("alertshow", aTopic) ||
!strcmp("alertfinished", aTopic)) {
Unused << NS_WARN_IF(NS_FAILED(AdjustPushQuota(aTopic)));
}
return mObserver->Observe(aSubject, aTopic, aData);
}
nsresult
NotificationObserver::AdjustPushQuota(const char* aTopic)
{
#ifdef MOZ_SIMPLEPUSH
return NS_ERROR_NOT_IMPLEMENTED;
#else
nsCOMPtr<nsIPushQuotaManager> pushQuotaManager =
do_GetService("@mozilla.org/push/NotificationService;1");
if (!pushQuotaManager) {
return NS_ERROR_FAILURE;
}
nsAutoCString origin;
nsresult rv = mPrincipal->GetOrigin(origin);
if (NS_FAILED(rv)) {
return rv;
}
if (!strcmp("alertshow", aTopic)) {
return pushQuotaManager->NotificationForOriginShown(origin.get());
}
return pushQuotaManager->NotificationForOriginClosed(origin.get());
#endif
}
NS_IMETHODIMP
MainThreadNotificationObserver::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData)

View File

@ -179,16 +179,10 @@ AttachToContainerAsEGLImage(ImageContainer* container,
return;
}
RefPtr<Image> img = container->CreateImage(ImageFormat::EGLIMAGE);
EGLImageImage::Data data;
data.mImage = image;
data.mSize = gfx::IntSize(rect.width, rect.height);
data.mOriginPos = instance->OriginPos();
EGLImageImage* typedImg = static_cast<EGLImageImage*>(img.get());
typedImg->SetData(data);
RefPtr<EGLImageImage> img = new EGLImageImage(
image, nullptr,
gfx::IntSize(rect.width, rect.height), instance->OriginPos(),
false /* owns */);
*out_image = img;
}
@ -206,16 +200,10 @@ AttachToContainerAsSurfaceTexture(ImageContainer* container,
return;
}
RefPtr<Image> img = container->CreateImage(ImageFormat::SURFACE_TEXTURE);
SurfaceTextureImage::Data data;
data.mSurfTex = surfTex;
data.mSize = gfx::IntSize(rect.width, rect.height);
data.mOriginPos = instance->OriginPos();
SurfaceTextureImage* typedImg = static_cast<SurfaceTextureImage*>(img.get());
typedImg->SetData(data);
RefPtr<Image> img = new SurfaceTextureImage(
surfTex,
gfx::IntSize(rect.width, rect.height),
instance->OriginPos());
*out_image = img;
}
#endif
@ -1339,16 +1327,10 @@ nsPluginInstanceOwner::GetImageContainerForVideo(nsNPAPIPluginInstance::VideoInf
{
RefPtr<ImageContainer> container = LayerManager::CreateImageContainer();
RefPtr<Image> img = container->CreateImage(ImageFormat::SURFACE_TEXTURE);
SurfaceTextureImage::Data data;
data.mSurfTex = aVideoInfo->mSurfaceTexture;
data.mOriginPos = gl::OriginPos::BottomLeft;
data.mSize = gfx::IntSize(aVideoInfo->mDimensions.width, aVideoInfo->mDimensions.height);
SurfaceTextureImage* typedImg = static_cast<SurfaceTextureImage*>(img.get());
typedImg->SetData(data);
RefPtr<Image> img = new SurfaceTextureImage(
aVideoInfo->mSurfaceTexture,
gfx::IntSize(aVideoInfo->mDimensions.width, aVideoInfo->mDimensions.height),
gl::OriginPos::BottomLeft);
container->SetCurrentImageInTransaction(img);
return container.forget();

View File

@ -615,18 +615,15 @@ PluginInstanceParent::RecvShow(const NPRect& updatedRect,
updatedRect.bottom - updatedRect.top);
surface->MarkDirty(ur);
ImageContainer *container = GetImageContainer();
RefPtr<Image> image = container->CreateImage(ImageFormat::CAIRO_SURFACE);
NS_ASSERTION(image->GetFormat() == ImageFormat::CAIRO_SURFACE, "Wrong format?");
CairoImage* cairoImage = static_cast<CairoImage*>(image.get());
CairoImage::Data cairoData;
cairoData.mSize = surface->GetSize();
cairoData.mSourceSurface = gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(nullptr, surface);
cairoImage->SetData(cairoData);
RefPtr<gfx::SourceSurface> sourceSurface =
gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(nullptr, surface);
RefPtr<CairoImage> image = new CairoImage(surface->GetSize(), sourceSurface);
nsAutoTArray<ImageContainer::NonOwningImage,1> imageList;
imageList.AppendElement(
ImageContainer::NonOwningImage(image));
ImageContainer *container = GetImageContainer();
container->SetCurrentImages(imageList);
}
else if (mImageContainer) {
@ -697,17 +694,8 @@ PluginInstanceParent::GetImageContainer(ImageContainer** aContainer)
#ifdef XP_MACOSX
if (ioSurface) {
RefPtr<Image> image = container->CreateImage(ImageFormat::MAC_IOSURFACE);
if (!image) {
return NS_ERROR_FAILURE;
}
NS_ASSERTION(image->GetFormat() == ImageFormat::MAC_IOSURFACE, "Wrong format?");
MacIOSurfaceImage* pluginImage = static_cast<MacIOSurfaceImage*>(image.get());
pluginImage->SetSurface(ioSurface);
container->SetCurrentImageInTransaction(pluginImage);
RefPtr<Image> image = new MacIOSurfaceImage(ioSurface);
container->SetCurrentImageInTransaction(image);
NS_IF_ADDREF(container);
*aContainer = container;

View File

@ -74,7 +74,8 @@ AddSandboxAllowedFile(vector<std::wstring>& aAllowedFiles, nsIProperties* aDirSv
static void
AddSandboxAllowedFiles(int32_t aSandboxLevel,
vector<std::wstring>& aAllowedFilesRead,
vector<std::wstring>& aAllowedFilesReadWrite)
vector<std::wstring>& aAllowedFilesReadWrite,
vector<std::wstring>& aAllowedDirectories)
{
if (aSandboxLevel < 2) {
return;
@ -95,12 +96,21 @@ AddSandboxAllowedFiles(int32_t aSandboxLevel,
}
// Level 2 and above is now using low integrity, so we need to give write
// access to the Flash directories.
// access to the Flash directories. Access also has to be given to create
// the parent directories as they may not exist.
// This should be made Flash specific (Bug 1171396).
AddSandboxAllowedFile(aAllowedFilesReadWrite, dirSvc, NS_WIN_APPDATA_DIR,
NS_LITERAL_STRING("\\Macromedia\\Flash Player\\*"));
AddSandboxAllowedFile(aAllowedDirectories, dirSvc, NS_WIN_APPDATA_DIR,
NS_LITERAL_STRING("\\Macromedia\\Flash Player"));
AddSandboxAllowedFile(aAllowedDirectories, dirSvc, NS_WIN_APPDATA_DIR,
NS_LITERAL_STRING("\\Macromedia"));
AddSandboxAllowedFile(aAllowedFilesReadWrite, dirSvc, NS_WIN_APPDATA_DIR,
NS_LITERAL_STRING("\\Adobe\\Flash Player\\*"));
AddSandboxAllowedFile(aAllowedDirectories, dirSvc, NS_WIN_APPDATA_DIR,
NS_LITERAL_STRING("\\Adobe\\Flash Player"));
AddSandboxAllowedFile(aAllowedDirectories, dirSvc, NS_WIN_APPDATA_DIR,
NS_LITERAL_STRING("\\Adobe"));
// Write access to the Temp directory is needed in some mochitest crash
// tests.
@ -117,7 +127,7 @@ PluginProcessParent::Launch(mozilla::UniquePtr<LaunchCompleteTask> aLaunchComple
#if defined(XP_WIN) && defined(MOZ_SANDBOX)
mSandboxLevel = aSandboxLevel;
AddSandboxAllowedFiles(mSandboxLevel, mAllowedFilesRead,
mAllowedFilesReadWrite);
mAllowedFilesReadWrite, mAllowedDirectories);
#else
if (aSandboxLevel != 0) {
MOZ_ASSERT(false,

View File

@ -36,7 +36,8 @@ PushNotificationService.prototype = {
_xpcom_factory: XPCOMUtils.generateSingletonFactory(PushNotificationService),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference,
Ci.nsIPushNotificationService]),
Ci.nsIPushNotificationService,
Ci.nsIPushQuotaManager,]),
register: function register(scope, originAttributes) {
return PushService.register({
@ -74,6 +75,26 @@ PushNotificationService.prototype = {
}
break;
}
},
// nsIPushQuotaManager methods
notificationForOriginShown: function(origin) {
if (!isParent) {
Services.cpmm.sendAsyncMessage("Push:NotificationForOriginShown", origin);
return;
}
PushService._notificationForOriginShown(origin);
},
notificationForOriginClosed: function(origin) {
if (!isParent) {
Services.cpmm.sendAsyncMessage("Push:NotificationForOriginClosed", origin);
return;
}
PushService._notificationForOriginClosed(origin);
}
};

View File

@ -65,25 +65,15 @@ PushRecord.prototype = {
this.quota = 0;
return;
}
let currentQuota;
if (lastVisit > this.lastPush) {
// If the user visited the site since the last time we received a
// notification, reset the quota.
let daysElapsed = (Date.now() - lastVisit) / 24 / 60 / 60 / 1000;
currentQuota = Math.min(
this.quota = Math.min(
Math.round(8 * Math.pow(daysElapsed, -0.8)),
prefs.get("maxQuotaPerSubscription")
);
Services.telemetry.getHistogramById("PUSH_API_QUOTA_RESET_TO").add(currentQuota - 1);
} else {
// The user hasn't visited the site since the last notification.
currentQuota = this.quota;
}
this.quota = Math.max(currentQuota - 1, 0);
// We check for ctime > 0 to skip older records that did not have ctime.
if (this.isExpired() && this.ctime > 0) {
let duration = Date.now() - this.ctime;
Services.telemetry.getHistogramById("PUSH_API_QUOTA_EXPIRATION_TIME").add(duration / 1000);
Services.telemetry.getHistogramById("PUSH_API_QUOTA_RESET_TO").add(this.quota);
}
},
@ -93,6 +83,15 @@ PushRecord.prototype = {
this.lastPush = Date.now();
},
reduceQuota() {
this.quota = Math.max(this.quota - 1, 0);
// We check for ctime > 0 to skip older records that did not have ctime.
if (this.isExpired() && this.ctime > 0) {
let duration = Date.now() - this.ctime;
Services.telemetry.getHistogramById("PUSH_API_QUOTA_EXPIRATION_TIME").add(duration / 1000);
}
},
/**
* Queries the Places database for the last time a user visited the site
* associated with a push registration.

View File

@ -45,6 +45,8 @@ const prefs = new Preferences("dom.push.");
const kCHILD_PROCESS_MESSAGES = ["Push:Register", "Push:Unregister",
"Push:Registration", "Push:RegisterEventNotificationListener",
"Push:NotificationForOriginShown",
"Push:NotificationForOriginClosed",
"child-process-shutdown"];
const PUSH_SERVICE_UNINIT = 0;
@ -97,6 +99,11 @@ this.PushService = {
_db: null,
_options: null,
_alarmID: null,
_visibleNotifications: new Map(),
// Callback that is called after attempting to
// reduce the quota for a record. Used for testing purposes.
_updateQuotaTestCallback: null,
_childListeners: [],
@ -883,13 +890,10 @@ this.PushService = {
if (shouldNotify) {
notified = this._notifyApp(record, message);
}
if (record.isExpired()) {
this._recordDidNotNotify(kDROP_NOTIFICATION_REASON_EXPIRED);
// Drop the registration in the background. If the user returns to the
// site, the service worker will be notified on the next `idle-daily`
// event.
this._backgroundUnregister(record);
}
// Update quota after the delay, at which point
// we check for visible notifications.
setTimeout(() => this._updateQuota(keyID),
prefs.get("quotaUpdateDelay"));
return notified;
});
}).catch(error => {
@ -897,6 +901,66 @@ this.PushService = {
});
},
_updateQuota: function(keyID) {
console.debug("updateQuota()");
this._db.update(keyID, record => {
// Record may have expired from an earlier quota update.
if (record.isExpired()) {
console.debug(
"updateQuota: Trying to update quota for expired record", record);
return null;
}
// If there are visible notifications, don't apply the quota penalty
// for the message.
if (!this._visibleNotifications.has(record.uri.prePath)) {
record.reduceQuota();
}
return record;
}).then(record => {
if (record && record.isExpired()) {
this._recordDidNotNotify(kDROP_NOTIFICATION_REASON_EXPIRED);
// Drop the registration in the background. If the user returns to the
// site, the service worker will be notified on the next `idle-daily`
// event.
this._backgroundUnregister(record);
}
if (this._updateQuotaTestCallback) {
// Callback so that test may be notified when the quota update is complete.
this._updateQuotaTestCallback();
}
}).catch(error => {
console.debug("updateQuota: Error while trying to update quota", error);
});
},
_notificationForOriginShown(origin) {
console.debug("notificationForOriginShown()", origin);
let count;
if (this._visibleNotifications.has(origin)) {
count = this._visibleNotifications.get(origin);
} else {
count = 0;
}
this._visibleNotifications.set(origin, count + 1);
},
_notificationForOriginClosed(origin) {
console.debug("notificationForOriginClosed()", origin);
let count;
if (this._visibleNotifications.has(origin)) {
count = this._visibleNotifications.get(origin);
} else {
console.debug("notificationForOriginClosed: closing notification that has not been shown?");
return;
}
if (count > 1) {
this._visibleNotifications.set(origin, count - 1);
} else {
this._visibleNotifications.delete(origin);
}
},
_notifyApp: function(aPushRecord, message) {
if (!aPushRecord || !aPushRecord.scope ||
aPushRecord.originAttributes === undefined) {
@ -1055,6 +1119,20 @@ this.PushService = {
this._childListeners.splice(i, 1);
}
}
console.debug("receiveMessage: Clearing notifications from child");
this._visibleNotifications.clear();
return;
}
if (aMessage.name === "Push:NotificationForOriginShown") {
console.debug("receiveMessage: Notification shown from child");
this._notificationForOriginShown(aMessage.data);
return;
}
if (aMessage.name === "Push:NotificationForOriginClosed") {
console.debug("receiveMessage: Notification closed from child");
this._notificationForOriginClosed(aMessage.data);
return;
}

View File

@ -222,6 +222,7 @@ function setPrefs(prefs = {}) {
'http2.retryInterval': 500,
'http2.reset_retry_count_after_ms': 60000,
maxQuotaPerSubscription: 16,
quotaUpdateDelay: 3000,
}, prefs);
for (let pref in defaultPrefs) {
servicePrefs.set(pref, defaultPrefs[pref]);

View File

@ -0,0 +1,115 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
const {PushDB, PushService, PushServiceWebSocket} = serviceExports;
Cu.import("resource://gre/modules/Task.jsm");
const userAgentID = 'aaabf1f8-2f68-44f1-a920-b88e9e7d7559';
const nsIPushQuotaManager = Components.interfaces.nsIPushQuotaManager;
function run_test() {
do_get_profile();
setPrefs({
userAgentID,
});
run_next_test();
}
add_task(function* test_expiration_origin_threshold() {
let db = PushServiceWebSocket.newPushDB();
do_register_cleanup(() => {
db.drop().then(_ => db.close())
PushService._notificationForOriginClosed("https://example.com");
});
// Simulate a notification being shown for the origin,
// this should relax the quota and allow as many push messages
// as we want.
PushService._notificationForOriginShown("https://example.com");
yield db.put({
channelID: 'f56645a9-1f32-4655-92ad-ddc37f6d54fb',
pushEndpoint: 'https://example.org/push/1',
scope: 'https://example.com/quota',
pushCount: 0,
lastPush: 0,
version: null,
originAttributes: '',
quota: 16,
});
// A visit one day ago should provide a quota of 8 messages.
yield addVisit({
uri: 'https://example.com/login',
title: 'Sign in to see your auctions',
visits: [{
visitDate: (Date.now() - 1 * 24 * 60 * 60 * 1000) * 1000,
transitionType: Ci.nsINavHistoryService.TRANSITION_LINK,
}],
});
let numMessages = 10;
let updates = 0;
let notifyPromise = promiseObserverNotification('push-notification', (subject, data) => {
dump(updates++);
return updates == numMessages;
});
let updateQuotaPromise = new Promise((resolve, reject) => {
let quotaUpdateCount = 0;
PushService._updateQuotaTestCallback = function() {
quotaUpdateCount++;
if (quotaUpdateCount == 10) {
resolve();
}
};
});
PushService.init({
serverURI: 'wss://push.example.org/',
networkInfo: new MockDesktopNetworkInfo(),
db,
makeWebSocket(uri) {
return new MockWebSocket(uri, {
onHello(request) {
this.serverSendMsg(JSON.stringify({
messageType: 'hello',
status: 200,
uaid: userAgentID,
}));
// If the origin has visible notifications, the
// message should not affect quota.
for (let version = 1; version <= 10; version++) {
this.serverSendMsg(JSON.stringify({
messageType: 'notification',
updates: [{
channelID: 'f56645a9-1f32-4655-92ad-ddc37f6d54fb',
version,
}],
}));
}
},
onUnregister(request) {
ok(false, "Channel should not be unregistered.");
},
// We expect to receive acks, but don't care about their
// contents.
onACK(request) {},
});
},
});
yield waitForPromise(notifyPromise, DEFAULT_TIMEOUT,
'Timed out waiting for notifications');
yield waitForPromise(updateQuotaPromise, DEFAULT_TIMEOUT,
'Timed out waiting for quota to be updated');
let expiredRecord = yield db.getByKeyID('f56645a9-1f32-4655-92ad-ddc37f6d54fb');
notStrictEqual(expiredRecord.quota, 0, 'Expired record not updated');
});

View File

@ -17,6 +17,7 @@ run-sequentially = This will delete all existing push subscriptions.
[test_quota_exceeded.js]
[test_quota_observer.js]
[test_quota_with_notification.js]
[test_register_case.js]
[test_register_flush.js]
[test_register_invalid_channel.js]

View File

@ -53,7 +53,6 @@
#include "nsIScriptSecurityManager.h"
#include "nsIServiceManager.h"
#include "mozilla/css/StyleRule.h"
#include "nsIStyleSheet.h"
#include "nsIURL.h"
#include "nsViewManager.h"
#include "nsIWidget.h"

View File

@ -19,10 +19,8 @@
using namespace mozilla;
class nsIStyleSheet;
static void
AddStyleSheet(nsIEditor* aEditor, nsIStyleSheet* aSheet)
AddStyleSheet(nsIEditor* aEditor, CSSStyleSheet* aSheet)
{
nsCOMPtr<nsIDOMDocument> domDoc;
aEditor->GetDocument(getter_AddRefs(domDoc));
@ -35,7 +33,7 @@ AddStyleSheet(nsIEditor* aEditor, nsIStyleSheet* aSheet)
}
static void
RemoveStyleSheet(nsIEditor *aEditor, nsIStyleSheet *aSheet)
RemoveStyleSheet(nsIEditor* aEditor, CSSStyleSheet* aSheet)
{
nsCOMPtr<nsIDOMDocument> domDoc;
aEditor->GetDocument(getter_AddRefs(domDoc));

View File

@ -16,7 +16,6 @@
#include "nsIOutputStream.h"
#include "nsIInputStream.h"
#include "nsIChannel.h"
#include "nsIStyleSheet.h"
#include "nsIDocumentEncoder.h"
#include "nsITransport.h"
#include "nsIProgressEventSink.h"

View File

@ -684,7 +684,7 @@ GLBlitHelper::BlitGrallocImage(layers::GrallocImage* grallocImage)
bool
GLBlitHelper::BlitSurfaceTextureImage(layers::SurfaceTextureImage* stImage)
{
AndroidSurfaceTexture* surfaceTexture = stImage->GetData()->mSurfTex;
AndroidSurfaceTexture* surfaceTexture = stImage->GetSurfaceTexture();
ScopedBindTextureUnit boundTU(mGL, LOCAL_GL_TEXTURE0);
@ -713,8 +713,8 @@ GLBlitHelper::BlitSurfaceTextureImage(layers::SurfaceTextureImage* stImage)
bool
GLBlitHelper::BlitEGLImageImage(layers::EGLImageImage* image)
{
EGLImage eglImage = image->GetData()->mImage;
EGLSync eglSync = image->GetData()->mSync;
EGLImage eglImage = image->GetImage();
EGLSync eglSync = image->GetSync();
if (eglSync) {
EGLint status = sEGLLibrary.fClientWaitSync(EGL_DISPLAY(), eglSync, 0, LOCAL_EGL_FOREVER);
@ -841,13 +841,12 @@ GLBlitHelper::BlitImageToFramebuffer(layers::Image* srcImage,
#ifdef MOZ_WIDGET_ANDROID
case ImageFormat::SURFACE_TEXTURE:
type = ConvertSurfaceTexture;
srcOrigin = static_cast<layers::SurfaceTextureImage*>(srcImage)->GetData()
->mOriginPos;
srcOrigin = srcImage->AsSurfaceTextureImage()->GetOriginPos();
break;
case ImageFormat::EGLIMAGE:
type = ConvertEGLImage;
srcOrigin = static_cast<layers::EGLImageImage*>(srcImage)->GetData()->mOriginPos;
srcOrigin = srcImage->AsEGLImageImage()->GetOriginPos();
break;
#endif
#ifdef XP_MACOSX
@ -893,7 +892,7 @@ GLBlitHelper::BlitImageToFramebuffer(layers::Image* srcImage,
#ifdef XP_MACOSX
case ConvertMacIOSurfaceImage:
return BlitMacIOSurfaceImage(static_cast<layers::MacIOSurfaceImage*>(srcImage));
return BlitMacIOSurfaceImage(srcImage->AsMacIOSurfaceImage());
#endif
default:

View File

@ -16,20 +16,19 @@
namespace mozilla {
namespace layers {
HRESULT
D3D11ShareHandleImage::SetData(const Data& aData)
D3D11ShareHandleImage::D3D11ShareHandleImage(const gfx::IntSize& aSize,
const gfx::IntRect& aRect)
: Image(nullptr, ImageFormat::D3D11_SHARE_HANDLE_TEXTURE),
mSize(aSize),
mPictureRect(aRect)
{
mPictureRect = aData.mRegion;
mSize = aData.mSize;
}
mTextureClient =
aData.mAllocator->CreateOrRecycleClient(gfx::SurfaceFormat::B8G8R8A8,
mSize);
if (!mTextureClient) {
return E_FAIL;
}
return S_OK;
bool
D3D11ShareHandleImage::AllocateTexture(D3D11RecycleAllocator* aAllocator)
{
mTextureClient = aAllocator->CreateOrRecycleClient(gfx::SurfaceFormat::B8G8R8A8, mSize);
return !!mTextureClient;
}
gfx::IntSize

View File

@ -45,40 +45,22 @@ protected:
// passed into SetData(), so that it can be accessed from other D3D devices.
// This class also manages the synchronization of the copy, to ensure the
// resource is ready to use.
class D3D11ShareHandleImage : public Image {
class D3D11ShareHandleImage final : public Image {
public:
D3D11ShareHandleImage(const gfx::IntSize& aSize,
const gfx::IntRect& aRect);
~D3D11ShareHandleImage() override {}
struct Data {
Data(D3D11RecycleAllocator* aAllocator,
const gfx::IntSize& aSize,
const gfx::IntRect& aRegion)
: mAllocator(aAllocator)
, mSize(aSize)
, mRegion(aRegion) {}
RefPtr<D3D11RecycleAllocator> mAllocator;
gfx::IntSize mSize;
gfx::IntRect mRegion;
};
D3D11ShareHandleImage() : Image(NULL, ImageFormat::D3D11_SHARE_HANDLE_TEXTURE), mSize(0, 0) {}
virtual ~D3D11ShareHandleImage() {}
// Copies the surface into a sharable texture's surface, and initializes
// the image.
HRESULT SetData(const Data& aData);
bool AllocateTexture(D3D11RecycleAllocator* aAllocator);
gfx::IntSize GetSize() override;
virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
virtual TextureClient* GetTextureClient(CompositableClient* aClient) override;
virtual gfx::IntRect GetPictureRect() override { return mPictureRect; }
ID3D11Texture2D* GetTexture() const;
virtual gfx::IntRect GetPictureRect() override { return mPictureRect; }
private:
gfx::IntSize mSize;
gfx::IntRect mPictureRect;
RefPtr<TextureClientD3D11> mTextureClient;

View File

@ -15,11 +15,11 @@ namespace mozilla {
namespace layers {
D3D9SurfaceImage::D3D9SurfaceImage()
D3D9SurfaceImage::D3D9SurfaceImage(bool aIsFirstFrame)
: Image(nullptr, ImageFormat::D3D9_RGB32_TEXTURE)
, mSize(0, 0)
, mValid(false)
, mIsFirstFrame(false)
, mIsFirstFrame(aIsFirstFrame)
{}
D3D9SurfaceImage::~D3D9SurfaceImage()
@ -27,11 +27,13 @@ D3D9SurfaceImage::~D3D9SurfaceImage()
}
HRESULT
D3D9SurfaceImage::SetData(const Data& aData)
D3D9SurfaceImage::AllocateAndCopy(D3D9RecycleAllocator* aAllocator,
IDirect3DSurface9* aSurface,
const gfx::IntRect& aRegion)
{
NS_ENSURE_TRUE(aData.mSurface, E_POINTER);
NS_ENSURE_TRUE(aSurface, E_POINTER);
HRESULT hr;
RefPtr<IDirect3DSurface9> surface = aData.mSurface;
RefPtr<IDirect3DSurface9> surface = aSurface;
RefPtr<IDirect3DDevice9> device;
hr = surface->GetDevice(getter_AddRefs(device));
@ -54,10 +56,8 @@ D3D9SurfaceImage::SetData(const Data& aData)
// DXVA surfaces aren't created sharable, so we need to copy the surface
// to a sharable texture to that it's accessible to the layer manager's
// device.
const gfx::IntRect& region = aData.mRegion;
RefPtr<SharedTextureClientD3D9> textureClient =
aData.mAllocator->CreateOrRecycleClient(gfx::SurfaceFormat::B8G8R8X8,
region.Size());
aAllocator->CreateOrRecycleClient(gfx::SurfaceFormat::B8G8R8X8, aRegion.Size());
if (!textureClient) {
return E_FAIL;
}
@ -68,7 +68,7 @@ D3D9SurfaceImage::SetData(const Data& aData)
return E_FAIL;
}
RECT src = { region.x, region.y, region.x+region.width, region.y+region.height };
RECT src = { aRegion.x, aRegion.y, aRegion.x+aRegion.width, aRegion.y+aRegion.height };
hr = device->StretchRect(surface, &src, textureSurface, nullptr, D3DTEXF_NONE);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
@ -82,10 +82,8 @@ D3D9SurfaceImage::SetData(const Data& aData)
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
mTextureClient = textureClient;
mSize = region.Size();
mSize = aRegion.Size();
mQuery = query;
mIsFirstFrame = aData.mIsFirstFrame;
return S_OK;
}

View File

@ -47,30 +47,12 @@ protected:
// resource is ready to use.
class D3D9SurfaceImage : public Image {
public:
struct Data {
Data(IDirect3DSurface9* aSurface,
const gfx::IntRect& aRegion,
D3D9RecycleAllocator* aAllocator,
bool aIsFirstFrame)
: mSurface(aSurface)
, mRegion(aRegion)
, mAllocator(aAllocator)
, mIsFirstFrame(aIsFirstFrame)
{}
RefPtr<IDirect3DSurface9> mSurface;
gfx::IntRect mRegion;
RefPtr<D3D9RecycleAllocator> mAllocator;
bool mIsFirstFrame;
};
D3D9SurfaceImage();
explicit D3D9SurfaceImage(bool aIsFirstFrame);
virtual ~D3D9SurfaceImage();
// Copies the surface into a sharable texture's surface, and initializes
// the image.
HRESULT SetData(const Data& aData);
HRESULT AllocateAndCopy(D3D9RecycleAllocator* aAllocator,
IDirect3DSurface9* aSurface,
const gfx::IntRect& aRegion);
// Returns the description of the shared surface.
const D3DSURFACE_DESC& GetDesc() const;

View File

@ -16,20 +16,32 @@ namespace layers {
static RefPtr<GLContext> sSnapshotContext;
EGLImageImage::EGLImageImage(EGLImage aImage, EGLSync aSync,
const gfx::IntSize& aSize, const gl::OriginPos& aOrigin,
bool aOwns)
: GLImage(ImageFormat::EGLIMAGE),
mImage(aImage),
mSync(aSync),
mSize(aSize),
mPos(aOrigin),
mOwns(aOwns)
{
}
EGLImageImage::~EGLImageImage()
{
if (!mData.mOwns) {
if (!mOwns) {
return;
}
if (mData.mImage) {
sEGLLibrary.fDestroyImage(EGL_DISPLAY(), mData.mImage);
mData.mImage = nullptr;
if (mImage) {
sEGLLibrary.fDestroyImage(EGL_DISPLAY(), mImage);
mImage = nullptr;
}
if (mData.mSync) {
sEGLLibrary.fDestroySync(EGL_DISPLAY(), mData.mSync);
mData.mSync = nullptr;
if (mSync) {
sEGLLibrary.fDestroySync(EGL_DISPLAY(), mSync);
mSync = nullptr;
}
}
@ -82,5 +94,17 @@ GLImage::GetAsSourceSurface()
return source.forget();
}
#ifdef MOZ_WIDGET_ANDROID
SurfaceTextureImage::SurfaceTextureImage(gl::AndroidSurfaceTexture* aSurfTex,
const gfx::IntSize& aSize,
gl::OriginPos aOriginPos)
: GLImage(ImageFormat::SURFACE_TEXTURE),
mSurfaceTexture(aSurfTex),
mSize(aSize),
mOriginPos(aOriginPos)
{
}
#endif
} // namespace layers
} // namespace mozilla

View File

@ -28,52 +28,60 @@ public:
class EGLImageImage : public GLImage {
public:
struct Data {
EGLImage mImage;
EGLSync mSync;
gfx::IntSize mSize;
gl::OriginPos mOriginPos;
bool mOwns;
EGLImageImage(EGLImage aImage, EGLSync aSync,
const gfx::IntSize& aSize, const gl::OriginPos& aOrigin,
bool aOwns);
Data() : mImage(nullptr), mSync(nullptr), mSize(0, 0),
mOriginPos(gl::OriginPos::TopLeft), mOwns(false)
{
}
};
gfx::IntSize GetSize() override { return mSize; }
gl::OriginPos GetOriginPos() const {
return mPos;
}
EGLImage GetImage() const {
return mImage;
}
EGLSync GetSync() const {
return mSync;
}
void SetData(const Data& aData) { mData = aData; }
const Data* GetData() { return &mData; }
gfx::IntSize GetSize() { return mData.mSize; }
EGLImageImage() : GLImage(ImageFormat::EGLIMAGE) {}
EGLImageImage* AsEGLImageImage() override {
return this;
}
protected:
virtual ~EGLImageImage();
private:
Data mData;
EGLImage mImage;
EGLSync mSync;
gfx::IntSize mSize;
gl::OriginPos mPos;
bool mOwns;
};
#ifdef MOZ_WIDGET_ANDROID
class SurfaceTextureImage : public GLImage {
public:
struct Data {
mozilla::gl::AndroidSurfaceTexture* mSurfTex;
gfx::IntSize mSize;
gl::OriginPos mOriginPos;
};
SurfaceTextureImage(gl::AndroidSurfaceTexture* aSurfTex,
const gfx::IntSize& aSize,
gl::OriginPos aOriginPos);
void SetData(const Data& aData) { mData = aData; }
const Data* GetData() { return &mData; }
gfx::IntSize GetSize() override { return mSize; }
gl::AndroidSurfaceTexture* GetSurfaceTexture() const {
return mSurfaceTexture;
}
gl::OriginPos GetOriginPos() const {
return mOriginPos;
}
gfx::IntSize GetSize() { return mData.mSize; }
SurfaceTextureImage() : GLImage(ImageFormat::SURFACE_TEXTURE) {}
SurfaceTextureImage* AsSurfaceTextureImage() override {
return this;
}
private:
Data mData;
gl::AndroidSurfaceTexture* mSurfaceTexture;
gfx::IntSize mSize;
gl::OriginPos mOriginPos;
};
#endif // MOZ_WIDGET_ANDROID

View File

@ -147,11 +147,12 @@ GrallocImage::SetData(const Data& aData)
return true;
}
bool GrallocImage::SetData(const GrallocData& aData)
void
GrallocImage::SetData(TextureClient* aGraphicBuffer, const gfx::IntSize& aSize)
{
mTextureClient = static_cast<GrallocTextureClientOGL*>(aData.mGraphicBuffer.get());
mSize = aData.mPicSize;
return true;
MOZ_ASSERT(aGraphicBuffer->AsGrallocTextureClientOGL());
mTextureClient = aGraphicBuffer->AsGrallocTextureClientOGL();
mSize = aSize;
}
/**

View File

@ -53,11 +53,6 @@ class GrallocImage : public RecyclingPlanarYCbCrImage
typedef PlanarYCbCrData Data;
static int32_t sColorIdMap[];
public:
struct GrallocData {
RefPtr<TextureClient> mGraphicBuffer;
gfx::IntSize mPicSize;
};
GrallocImage();
virtual ~GrallocImage();
@ -72,7 +67,7 @@ public:
* Share the SurfaceDescriptor without making the copy, in order
* to support functioning in all different layer managers.
*/
virtual bool SetData(const GrallocData& aData);
void SetData(TextureClient* aGraphicBuffer, const gfx::IntSize& aSize);
// From [android 4.0.4]/hardware/msm7k/libgralloc-qsd8k/gralloc_priv.h
enum {

View File

@ -17,6 +17,8 @@
#include "mozilla/layers/PImageContainerChild.h"
#include "mozilla/layers/ImageClient.h" // for ImageClient
#include "mozilla/layers/LayersMessages.h"
#include "mozilla/layers/SharedPlanarYCbCrImage.h"
#include "mozilla/layers/SharedRGBImage.h"
#include "nsISupportsUtils.h" // for NS_IF_ADDREF
#include "YCbCrUtils.h" // for YCbCr conversions
#ifdef MOZ_WIDGET_GONK
@ -30,14 +32,11 @@
#ifdef XP_MACOSX
#include "mozilla/gfx/QuartzSupport.h"
#include "MacIOSurfaceImage.h"
#endif
#ifdef XP_WIN
#include "gfxWindowsPlatform.h"
#include <d3d10_1.h>
#include "D3D9SurfaceImage.h"
#include "D3D11ShareHandleImage.h"
#endif
namespace mozilla {
@ -51,63 +50,10 @@ Atomic<int32_t> Image::sSerialCounter(0);
Atomic<uint32_t> ImageContainer::sGenerationCounter(0);
already_AddRefed<Image>
ImageFactory::CreateImage(ImageFormat aFormat,
const gfx::IntSize &,
BufferRecycleBin *aRecycleBin)
RefPtr<PlanarYCbCrImage>
ImageFactory::CreatePlanarYCbCrImage(const gfx::IntSize& aScaleHint, BufferRecycleBin *aRecycleBin)
{
RefPtr<Image> img;
#ifdef MOZ_WIDGET_GONK
if (aFormat == ImageFormat::GRALLOC_PLANAR_YCBCR) {
img = new GrallocImage();
return img.forget();
}
if (aFormat == ImageFormat::OVERLAY_IMAGE) {
img = new OverlayImage();
return img.forget();
}
#endif
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_CAMERA) && defined(MOZ_WEBRTC)
if (aFormat == ImageFormat::GONK_CAMERA_IMAGE) {
img = new GonkCameraImage();
return img.forget();
}
#endif
if (aFormat == ImageFormat::PLANAR_YCBCR) {
img = new RecyclingPlanarYCbCrImage(aRecycleBin);
return img.forget();
}
if (aFormat == ImageFormat::CAIRO_SURFACE) {
img = new CairoImage();
return img.forget();
}
#ifdef MOZ_WIDGET_ANDROID
if (aFormat == ImageFormat::SURFACE_TEXTURE) {
img = new SurfaceTextureImage();
return img.forget();
}
#endif
if (aFormat == ImageFormat::EGLIMAGE) {
img = new EGLImageImage();
return img.forget();
}
#ifdef XP_MACOSX
if (aFormat == ImageFormat::MAC_IOSURFACE) {
img = new MacIOSurfaceImage();
return img.forget();
}
#endif
#ifdef XP_WIN
if (aFormat == ImageFormat::D3D11_SHARE_HANDLE_TEXTURE) {
img = new D3D11ShareHandleImage();
return img.forget();
}
if (aFormat == ImageFormat::D3D9_RGB32_TEXTURE) {
img = new D3D9SurfaceImage();
return img.forget();
}
#endif
return nullptr;
return new RecyclingPlanarYCbCrImage(aRecycleBin);
}
BufferRecycleBin::BufferRecycleBin()
@ -208,31 +154,42 @@ ImageContainer::~ImageContainer()
}
}
already_AddRefed<Image>
ImageContainer::CreateImage(ImageFormat aFormat)
RefPtr<PlanarYCbCrImage>
ImageContainer::CreatePlanarYCbCrImage()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
if (mImageClient && mImageClient->AsImageClientSingle()) {
return new SharedPlanarYCbCrImage(mImageClient);
}
return mImageFactory->CreatePlanarYCbCrImage(mScaleHint, mRecycleBin);
}
RefPtr<SharedRGBImage>
ImageContainer::CreateSharedRGBImage()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
if (!mImageClient || !mImageClient->AsImageClientSingle()) {
return nullptr;
}
return new SharedRGBImage(mImageClient);
}
#ifdef MOZ_WIDGET_GONK
if (aFormat == ImageFormat::OVERLAY_IMAGE) {
if (mImageClient && mImageClient->GetTextureInfo().mCompositableType != CompositableType::IMAGE_OVERLAY) {
// If this ImageContainer is async but the image type mismatch, fix it here
if (ImageBridgeChild::IsCreated()) {
ImageBridgeChild::DispatchReleaseImageClient(mImageClient);
mImageClient = ImageBridgeChild::GetSingleton()->CreateImageClient(
CompositableType::IMAGE_OVERLAY, this).take();
}
RefPtr<OverlayImage>
ImageContainer::CreateOverlayImage()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
if (mImageClient && mImageClient->GetTextureInfo().mCompositableType != CompositableType::IMAGE_OVERLAY) {
// If this ImageContainer is async but the image type mismatch, fix it here
if (ImageBridgeChild::IsCreated()) {
ImageBridgeChild::DispatchReleaseImageClient(mImageClient);
mImageClient = ImageBridgeChild::GetSingleton()->CreateImageClient(
CompositableType::IMAGE_OVERLAY, this).take();
}
}
#endif
if (mImageClient) {
RefPtr<Image> img = mImageClient->CreateImage(aFormat);
if (img) {
return img.forget();
}
}
return mImageFactory->CreateImage(aFormat, mScaleHint, mRecycleBin);
return new OverlayImage();
}
#endif
void
ImageContainer::SetCurrentImageInternal(const nsTArray<NonOwningImage>& aImages)
@ -592,8 +549,10 @@ PlanarYCbCrImage::GetAsSourceSurface()
return surface.forget();
}
CairoImage::CairoImage()
: Image(nullptr, ImageFormat::CAIRO_SURFACE)
CairoImage::CairoImage(const gfx::IntSize& aSize, gfx::SourceSurface* aSourceSurface)
: Image(nullptr, ImageFormat::CAIRO_SURFACE),
mSize(aSize),
mSourceSurface(aSourceSurface)
{}
CairoImage::~CairoImage()

View File

@ -103,6 +103,7 @@ class ImageCompositeNotification;
class ImageContainerChild;
class PImageContainerChild;
class SharedPlanarYCbCrImage;
class PlanarYCbCrImage;
class TextureClient;
class CompositableClient;
class GrallocImage;
@ -115,6 +116,17 @@ protected:
ImageBackendData() {}
};
/* Forward declarations for Image derivatives. */
class EGLImageImage;
class SharedRGBImage;
#ifdef MOZ_WIDGET_ANDROID
class SurfaceTextureImage;
#elif defined(XP_MACOSX)
class MacIOSurfaceImage;
#elif defined(MOZ_WIDGET_GONK)
class OverlayImage;
#endif
/**
* A class representing a buffer of pixel data. The data can be in one
* of various formats including YCbCr.
@ -161,11 +173,21 @@ public:
virtual uint8_t* GetBuffer() { return nullptr; }
/**
* For use with the CompositableClient only (so that the later can
* synchronize the TextureClient with the TextureHost).
*/
* For use with the CompositableClient only (so that the later can
* synchronize the TextureClient with the TextureHost).
*/
virtual TextureClient* GetTextureClient(CompositableClient* aClient) { return nullptr; }
/* Access to derived classes. */
virtual EGLImageImage* AsEGLImageImage() { return nullptr; }
#ifdef MOZ_WIDGET_ANDROID
virtual SurfaceTextureImage* AsSurfaceTextureImage() { return nullptr; }
#endif
#ifdef XP_MACOSX
virtual MacIOSurfaceImage* AsMacIOSurfaceImage() { return nullptr; }
#endif
virtual PlanarYCbCrImage* AsPlanarYCbCrImage() { return nullptr; }
protected:
Image(void* aImplData, ImageFormat aFormat) :
mImplData(aImplData),
@ -252,10 +274,9 @@ protected:
ImageFactory() {}
virtual ~ImageFactory() {}
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat,
const gfx::IntSize &aScaleHint,
BufferRecycleBin *aRecycleBin);
virtual RefPtr<PlanarYCbCrImage> CreatePlanarYCbCrImage(
const gfx::IntSize& aScaleHint,
BufferRecycleBin *aRecycleBin);
};
/**
@ -292,16 +313,14 @@ public:
typedef uint32_t FrameID;
typedef uint32_t ProducerID;
RefPtr<PlanarYCbCrImage> CreatePlanarYCbCrImage();
/**
* Create an Image in one of the given formats.
* Picks the "best" format from the list and creates an Image of that
* format.
* Returns null if this backend does not support any of the formats.
* Can be called on any thread. This method takes mReentrantMonitor
* when accessing thread-shared state.
*/
B2G_ACL_EXPORT already_AddRefed<Image> CreateImage(ImageFormat aFormat);
// Factory methods for shared image types.
RefPtr<SharedRGBImage> CreateSharedRGBImage();
#ifdef MOZ_WIDGET_GONK
RefPtr<OverlayImage> CreateOverlayImage();
#endif
struct NonOwningImage {
explicit NonOwningImage(Image* aImage = nullptr,
@ -704,6 +723,8 @@ public:
virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const = 0;
PlanarYCbCrImage* AsPlanarYCbCrImage() { return this; }
protected:
already_AddRefed<gfx::SourceSurface> GetAsSourceSurface();
@ -748,22 +769,6 @@ protected:
*/
class CairoImage final : public Image {
public:
struct Data {
gfx::IntSize mSize;
RefPtr<gfx::SourceSurface> mSourceSurface;
};
/**
* This can only be called on the main thread. It may add a reference
* to the surface (which will eventually be released on the main thread).
* The surface must not be modified after this call!!!
*/
void SetData(const Data& aData)
{
mSize = aData.mSize;
mSourceSurface = aData.mSourceSurface;
}
virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override
{
RefPtr<gfx::SourceSurface> surface(mSourceSurface);
@ -774,11 +779,11 @@ public:
virtual gfx::IntSize GetSize() override { return mSize; }
CairoImage();
CairoImage(const gfx::IntSize& aSize, gfx::SourceSurface* aSourceSurface);
~CairoImage();
private:
gfx::IntSize mSize;
nsCountedRef<nsMainThreadSourceSurfaceRef> mSourceSurface;
nsDataHashtable<nsUint32HashKey, RefPtr<TextureClient> > mTextureClients;
};

View File

@ -17,7 +17,11 @@ namespace layers {
class MacIOSurfaceImage : public Image {
public:
void SetSurface(MacIOSurface* aSurface) { mSurface = aSurface; }
explicit MacIOSurfaceImage(MacIOSurface* aSurface)
: Image(nullptr, ImageFormat::MAC_IOSURFACE),
mSurface(aSurface)
{}
MacIOSurface* GetSurface() { return mSurface; }
gfx::IntSize GetSize() override {
@ -28,7 +32,9 @@ public:
virtual TextureClient* GetTextureClient(CompositableClient* aClient) override;
MacIOSurfaceImage() : Image(nullptr, ImageFormat::MAC_IOSURFACE) {}
virtual MacIOSurfaceImage* AsMacIOSurfaceImage() override {
return this;
}
private:
RefPtr<MacIOSurface> mSurface;

View File

@ -78,17 +78,10 @@ class BasicImageFactory : public ImageFactory
public:
BasicImageFactory() {}
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat,
const gfx::IntSize &aScaleHint,
BufferRecycleBin *aRecycleBin)
virtual RefPtr<PlanarYCbCrImage>
CreatePlanarYCbCrImage(const gfx::IntSize& aScaleHint, BufferRecycleBin* aRecycleBin)
{
RefPtr<Image> image;
if (aFormat == ImageFormat::PLANAR_YCBCR) {
image = new BasicPlanarYCbCrImage(aScaleHint, gfxPlatform::GetPlatform()->GetOffscreenFormat(), aRecycleBin);
return image.forget();
}
return ImageFactory::CreateImage(aFormat, aScaleHint, aRecycleBin);
return new BasicPlanarYCbCrImage(aScaleHint, gfxPlatform::GetPlatform()->GetOffscreenFormat(), aRecycleBin);
}
};

View File

@ -111,16 +111,18 @@ BasicLayerManager::PushGroupForLayer(gfxContext* aContext, Layer* aLayer, const
IntRect surfRect;
ToRect(rect).ToIntRect(&surfRect);
RefPtr<DrawTarget> dt = aContext->GetDrawTarget()->CreateSimilarDrawTarget(surfRect.Size(), SurfaceFormat::B8G8R8A8);
if (!surfRect.IsEmpty()) {
RefPtr<DrawTarget> dt = aContext->GetDrawTarget()->CreateSimilarDrawTarget(surfRect.Size(), SurfaceFormat::B8G8R8A8);
RefPtr<gfxContext> ctx = new gfxContext(dt, ToRect(rect).TopLeft());
ctx->SetMatrix(oldMat);
RefPtr<gfxContext> ctx = new gfxContext(dt, ToRect(rect).TopLeft());
ctx->SetMatrix(oldMat);
group.mGroupOffset = surfRect.TopLeft();
group.mGroupTarget = ctx;
group.mGroupOffset = surfRect.TopLeft();
group.mGroupTarget = ctx;
group.mMaskSurface = GetMaskForLayer(aLayer, &group.mMaskTransform);
return group;
group.mMaskSurface = GetMaskForLayer(aLayer, &group.mMaskTransform);
return group;
}
}
Matrix maskTransform;

View File

@ -21,8 +21,6 @@
#include "mozilla/layers/ISurfaceAllocator.h"
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc
#include "mozilla/layers/ShadowLayers.h" // for ShadowLayerForwarder
#include "mozilla/layers/SharedPlanarYCbCrImage.h"
#include "mozilla/layers/SharedRGBImage.h"
#include "mozilla/layers/TextureClient.h" // for TextureClient, etc
#include "mozilla/layers/TextureClientOGL.h" // for SurfaceTextureClient
#include "mozilla/mozalloc.h" // for operator delete, etc
@ -204,18 +202,17 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlag
gfx::IntSize size = image->GetSize();
if (image->GetFormat() == ImageFormat::EGLIMAGE) {
EGLImageImage* typedImage = static_cast<EGLImageImage*>(image);
EGLImageImage* typedImage = image->AsEGLImageImage();
texture = new EGLImageTextureClient(GetForwarder(),
mTextureFlags,
typedImage,
size);
#ifdef MOZ_WIDGET_ANDROID
} else if (image->GetFormat() == ImageFormat::SURFACE_TEXTURE) {
SurfaceTextureImage* typedImage = static_cast<SurfaceTextureImage*>(image);
const SurfaceTextureImage::Data* data = typedImage->GetData();
SurfaceTextureImage* typedImage = image->AsSurfaceTextureImage();
texture = new SurfaceTextureClient(GetForwarder(), mTextureFlags,
data->mSurfTex, size,
data->mOriginPos);
typedImage->GetSurfaceTexture(), size,
typedImage->GetOriginPos());
#endif
} else {
MOZ_ASSERT(false, "Bad ImageFormat.");
@ -320,27 +317,6 @@ ImageClientBridge::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlag
return true;
}
already_AddRefed<Image>
ImageClientSingle::CreateImage(ImageFormat aFormat)
{
RefPtr<Image> img;
switch (aFormat) {
case ImageFormat::PLANAR_YCBCR:
img = new SharedPlanarYCbCrImage(this);
return img.forget();
case ImageFormat::SHARED_RGB:
img = new SharedRGBImage(this);
return img.forget();
#ifdef MOZ_WIDGET_GONK
case ImageFormat::GRALLOC_PLANAR_YCBCR:
img = new GrallocImage();
return img.forget();
#endif
default:
return nullptr;
}
}
#ifdef MOZ_WIDGET_GONK
ImageClientOverlay::ImageClientOverlay(CompositableForwarder* aFwd,
TextureFlags aFlags)
@ -375,20 +351,6 @@ ImageClientOverlay::UpdateImage(ImageContainer* aContainer, uint32_t aContentFla
}
return true;
}
already_AddRefed<Image>
ImageClientOverlay::CreateImage(ImageFormat aFormat)
{
RefPtr<Image> img;
switch (aFormat) {
case ImageFormat::OVERLAY_IMAGE:
img = new OverlayImage();
return img.forget();
default:
return nullptr;
}
}
#endif
} // namespace layers
} // namespace mozilla

View File

@ -29,6 +29,7 @@ class AsyncTransactionTracker;
class Image;
class ImageContainer;
class ShadowableLayer;
class ImageClientSingle;
/**
* Image clients are used by basic image layers on the content thread, they
@ -56,8 +57,6 @@ public:
*/
virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags) = 0;
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) = 0;
void SetLayer(ClientLayer* aLayer) { mLayer = aLayer; }
ClientLayer* GetLayer() const { return mLayer; }
@ -72,6 +71,8 @@ public:
void RemoveTextureWithWaiter(TextureClient* aTexture,
AsyncTransactionWaiter* aAsyncTransactionWaiter = nullptr);
virtual ImageClientSingle* AsImageClientSingle() { return nullptr; }
protected:
ImageClient(CompositableForwarder* aFwd, TextureFlags aFlags,
CompositableType aType);
@ -99,10 +100,10 @@ public:
virtual TextureInfo GetTextureInfo() const override;
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) override;
virtual void FlushAllImages(AsyncTransactionWaiter* aAsyncTransactionWaiter) override;
ImageClientSingle* AsImageClientSingle() override { return this; }
protected:
struct Buffer {
RefPtr<TextureClient> mTextureClient;
@ -135,12 +136,6 @@ public:
MOZ_ASSERT(!aChild, "ImageClientBridge should not have IPDL actor");
}
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) override
{
NS_WARNING("Should not create an image through an ImageClientBridge");
return nullptr;
}
protected:
uint64_t mAsyncContainerID;
};
@ -160,7 +155,6 @@ public:
TextureFlags aFlags);
virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags);
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat);
TextureInfo GetTextureInfo() const override
{
return TextureInfo(CompositableType::IMAGE_OVERLAY);

View File

@ -56,6 +56,7 @@ class TextureClientRecycleAllocator;
class TextureClientPool;
#endif
class KeepAlive;
class GrallocTextureClientOGL;
/**
* TextureClient is the abstraction that allows us to share data between the
@ -234,6 +235,7 @@ public:
}
virtual TextureClientYCbCr* AsTextureClientYCbCr() { return nullptr; }
virtual GrallocTextureClientOGL* AsGrallocTextureClientOGL() { return nullptr; }
/**
* Locks the shared data, allowing the caller to get access to it.

View File

@ -41,19 +41,16 @@ CreateSharedRGBImage(ImageContainer *aImageContainer,
return nullptr;
}
RefPtr<Image> image = aImageContainer->CreateImage(ImageFormat::SHARED_RGB);
if (!image) {
RefPtr<SharedRGBImage> rgbImage = aImageContainer->CreateSharedRGBImage();
if (!rgbImage) {
NS_WARNING("Failed to create SharedRGBImage");
return nullptr;
}
RefPtr<SharedRGBImage> rgbImage = static_cast<SharedRGBImage*>(image.get());
if (!rgbImage->Allocate(aSize, gfx::ImageFormatToSurfaceFormat(aImageFormat))) {
NS_WARNING("Failed to allocate a shared image");
return nullptr;
}
return image.forget();
return rgbImage.forget();
}
SharedRGBImage::SharedRGBImage(ImageClient* aCompositable)

View File

@ -64,6 +64,10 @@ public:
virtual void WaitForBufferOwnership(bool aWaitReleaseFence = true) override;
GrallocTextureClientOGL* AsGrallocTextureClientOGL() override {
return this;
}
void SetTextureFlags(TextureFlags aFlags) { AddFlags(aFlags); }
gfx::IntSize GetSize() const override { return mSize; }

View File

@ -34,7 +34,7 @@ EGLImageTextureClient::EGLImageTextureClient(ISurfaceAllocator* aAllocator,
AddFlags(TextureFlags::DEALLOCATE_CLIENT);
if (aImage->GetData()->mOriginPos == gl::OriginPos::BottomLeft) {
if (aImage->GetOriginPos() == gl::OriginPos::BottomLeft) {
AddFlags(TextureFlags::ORIGIN_BOTTOM_LEFT);
}
}
@ -45,10 +45,11 @@ EGLImageTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
MOZ_ASSERT(IsValid());
MOZ_ASSERT(IsAllocated());
const EGLImageImage::Data* data = mImage->GetData();
const bool hasAlpha = true;
aOutDescriptor = EGLImageDescriptor((uintptr_t)data->mImage, (uintptr_t)data->mSync,
mSize, hasAlpha);
aOutDescriptor =
EGLImageDescriptor((uintptr_t)mImage->GetImage(),
(uintptr_t)mImage->GetSync(),
mImage->GetSize(), hasAlpha);
return true;
}

View File

@ -310,6 +310,7 @@ private:
DECL_GFX_PREF(Once, "layers.componentalpha.enabled", ComponentAlphaEnabled, bool, true);
#endif
DECL_GFX_PREF(Live, "layers.composer2d.enabled", Composer2DCompositionEnabled, bool, false);
DECL_GFX_PREF(Live, "layers.screen-recording.enabled", ScreenRecordingEnabled, bool, false);
DECL_GFX_PREF(Once, "layers.d3d11.disable-warp", LayersD3D11DisableWARP, bool, false);
DECL_GFX_PREF(Once, "layers.d3d11.force-warp", LayersD3D11ForceWARP, bool, false);
DECL_GFX_PREF(Live, "layers.deaa.enabled", LayersDEAAEnabled, bool, false);

View File

@ -11,8 +11,7 @@
#include "prinrval.h"
#include "nsString.h"
// Declared in imgRequest.cpp.
extern PRLogModuleInfo* GetImgLog();
static mozilla::LazyLogModule gImgLog("imgRequest");
#define GIVE_ME_MS_NOW() PR_IntervalToMilliseconds(PR_IntervalNow())
@ -21,7 +20,7 @@ using mozilla::LogLevel;
class LogScope {
public:
LogScope(PRLogModuleInfo* aLog, void* aFrom, const char* aFunc)
LogScope(mozilla::LogModule* aLog, void* aFrom, const char* aFunc)
: mLog(aLog)
, mFrom(aFrom)
, mFunc(aFunc)
@ -31,7 +30,7 @@ public:
}
/* const char * constructor */
LogScope(PRLogModuleInfo* aLog, void* from, const char* fn,
LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
const char* paramName, const char* paramValue)
: mLog(aLog)
, mFrom(from)
@ -43,7 +42,7 @@ public:
}
/* void ptr constructor */
LogScope(PRLogModuleInfo* aLog, void* from, const char* fn,
LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
const char* paramName, const void* paramValue)
: mLog(aLog)
, mFrom(from)
@ -55,7 +54,7 @@ public:
}
/* int32_t constructor */
LogScope(PRLogModuleInfo* aLog, void* from, const char* fn,
LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
const char* paramName, int32_t paramValue)
: mLog(aLog)
, mFrom(from)
@ -67,7 +66,7 @@ public:
}
/* uint32_t constructor */
LogScope(PRLogModuleInfo* aLog, void* from, const char* fn,
LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
const char* paramName, uint32_t paramValue)
: mLog(aLog)
, mFrom(from)
@ -85,20 +84,20 @@ public:
}
private:
PRLogModuleInfo* mLog;
mozilla::LogModule* mLog;
void* mFrom;
const char* mFunc;
};
class LogFunc {
public:
LogFunc(PRLogModuleInfo* aLog, void* from, const char* fn)
LogFunc(mozilla::LogModule* aLog, void* from, const char* fn)
{
MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s\n",
GIVE_ME_MS_NOW(), from, fn));
}
LogFunc(PRLogModuleInfo* aLog, void* from, const char* fn,
LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
const char* paramName, const char* paramValue)
{
MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\")\n",
@ -106,7 +105,7 @@ public:
paramName, paramValue));
}
LogFunc(PRLogModuleInfo* aLog, void* from, const char* fn,
LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
const char* paramName, const void* paramValue)
{
MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%p\")\n",
@ -115,7 +114,7 @@ public:
}
LogFunc(PRLogModuleInfo* aLog, void* from, const char* fn,
LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
const char* paramName, uint32_t paramValue)
{
MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%d\")\n",
@ -128,7 +127,7 @@ public:
class LogMessage {
public:
LogMessage(PRLogModuleInfo* aLog, void* from, const char* fn,
LogMessage(mozilla::LogModule* aLog, void* from, const char* fn,
const char* msg)
{
MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s -- %s\n",

View File

@ -157,16 +157,16 @@ ProgressTracker::Notify(IProgressObserver* aObserver)
{
MOZ_ASSERT(NS_IsMainThread());
if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
RefPtr<Image> image = GetImage();
if (image && image->GetURI()) {
RefPtr<ImageURL> uri(image->GetURI());
nsAutoCString spec;
uri->GetSpec(spec);
LOG_FUNC_WITH_PARAM(GetImgLog(),
LOG_FUNC_WITH_PARAM(gImgLog,
"ProgressTracker::Notify async", "uri", spec.get());
} else {
LOG_FUNC_WITH_PARAM(GetImgLog(),
LOG_FUNC_WITH_PARAM(gImgLog,
"ProgressTracker::Notify async", "uri", "<unknown>");
}
}
@ -226,13 +226,13 @@ ProgressTracker::NotifyCurrentState(IProgressObserver* aObserver)
{
MOZ_ASSERT(NS_IsMainThread());
if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
RefPtr<Image> image = GetImage();
nsAutoCString spec;
if (image && image->GetURI()) {
image->GetURI()->GetSpec(spec);
}
LOG_FUNC_WITH_PARAM(GetImgLog(),
LOG_FUNC_WITH_PARAM(gImgLog,
"ProgressTracker::NotifyCurrentState", "uri", spec.get());
}
@ -406,7 +406,7 @@ ProgressTracker::SyncNotify(IProgressObserver* aObserver)
if (image && image->GetURI()) {
image->GetURI()->GetSpec(spec);
}
LOG_SCOPE_WITH_PARAM(GetImgLog(),
LOG_SCOPE_WITH_PARAM(gImgLog,
"ProgressTracker::SyncNotify", "uri", spec.get());
nsIntRect rect;

View File

@ -628,17 +628,11 @@ RasterImage::GetCurrentImage(ImageContainer* aContainer, uint32_t aFlags)
return MakePair(drawResult, RefPtr<layers::Image>());
}
CairoImage::Data cairoData;
GetWidth(&cairoData.mSize.width);
GetHeight(&cairoData.mSize.height);
cairoData.mSourceSurface = surface;
RefPtr<layers::Image> image =
aContainer->CreateImage(ImageFormat::CAIRO_SURFACE);
MOZ_ASSERT(image);
static_cast<CairoImage*>(image.get())->SetData(cairoData);
IntSize size;
GetWidth(&size.width);
GetHeight(&size.height);
RefPtr<layers::Image> image = new layers::CairoImage(size, surface);
return MakePair(drawResult, Move(image));
}
@ -1640,7 +1634,7 @@ RasterImage::DoError()
// Invalidate to get rid of any partially-drawn image content.
NotifyProgress(NoProgress, IntRect(0, 0, mSize.width, mSize.height));
MOZ_LOG(GetImgLog(), LogLevel::Error,
MOZ_LOG(gImgLog, LogLevel::Error,
("RasterImage: [this=%p] Error detected for image\n", this));
}

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
@ -14,7 +15,9 @@
#include <algorithm>
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/Maybe.h"
#include "mozilla/Variant.h"
#include "mozilla/Vector.h"
namespace mozilla {
@ -27,13 +30,12 @@ enum class BufferingStrategy
UNBUFFERED // Data will be processed as it arrives, in multiple chunks.
};
/// @return true if @aState is a terminal state.
template <typename State>
bool IsTerminalState(State aState)
/// The result of a call to StreamingLexer::Lex().
enum class TerminalState
{
return aState == State::SUCCESS ||
aState == State::FAILURE;
}
SUCCESS,
FAILURE
};
/**
* LexerTransition is a type used to give commands to the lexing framework.
@ -45,33 +47,78 @@ template <typename State>
class LexerTransition
{
public:
State NextState() const { return mNextState; }
State UnbufferedState() const { return *mUnbufferedState; }
size_t Size() const { return mSize; }
BufferingStrategy Buffering() const { return mBufferingStrategy; }
// This is implicit so that Terminate{Success,Failure}() can return a
// TerminalState and have it implicitly converted to a
// LexerTransition<State>, which avoids the need for a "<State>"
// qualification to the Terminate{Success,Failure}() callsite.
MOZ_IMPLICIT LexerTransition(TerminalState aFinalState)
: mNextState(aFinalState)
{}
bool NextStateIsTerminal() const
{
return mNextState.template is<TerminalState>();
}
TerminalState NextStateAsTerminal() const
{
return mNextState.template as<TerminalState>();
}
State NextState() const
{
return mNextState.template as<NonTerminalState>().mState;
}
State UnbufferedState() const
{
return *mNextState.template as<NonTerminalState>().mUnbufferedState;
}
size_t Size() const
{
return mNextState.template as<NonTerminalState>().mSize;
}
BufferingStrategy Buffering() const
{
return mNextState.template as<NonTerminalState>().mBufferingStrategy;
}
private:
friend struct Transition;
LexerTransition(const State& aNextState,
LexerTransition(State aNextState,
const Maybe<State>& aUnbufferedState,
size_t aSize,
BufferingStrategy aBufferingStrategy)
: mNextState(aNextState)
, mUnbufferedState(aUnbufferedState)
, mSize(aSize)
, mBufferingStrategy(aBufferingStrategy)
{
MOZ_ASSERT_IF(mBufferingStrategy == BufferingStrategy::UNBUFFERED,
mUnbufferedState);
MOZ_ASSERT_IF(mUnbufferedState,
mBufferingStrategy == BufferingStrategy::UNBUFFERED);
}
: mNextState(NonTerminalState(aNextState, aUnbufferedState, aSize,
aBufferingStrategy))
{}
State mNextState;
Maybe<State> mUnbufferedState;
size_t mSize;
BufferingStrategy mBufferingStrategy;
struct NonTerminalState
{
State mState;
Maybe<State> mUnbufferedState;
size_t mSize;
BufferingStrategy mBufferingStrategy;
NonTerminalState(State aState,
const Maybe<State>& aUnbufferedState,
size_t aSize,
BufferingStrategy aBufferingStrategy)
: mState(aState)
, mUnbufferedState(aUnbufferedState)
, mSize(aSize)
, mBufferingStrategy(aBufferingStrategy)
{
MOZ_ASSERT_IF(mBufferingStrategy == BufferingStrategy::UNBUFFERED,
mUnbufferedState);
MOZ_ASSERT_IF(mUnbufferedState,
mBufferingStrategy == BufferingStrategy::UNBUFFERED);
}
};
Variant<NonTerminalState, TerminalState> mNextState;
};
struct Transition
@ -81,7 +128,6 @@ struct Transition
static LexerTransition<State>
To(const State& aNextState, size_t aSize)
{
MOZ_ASSERT(!IsTerminalState(aNextState));
return LexerTransition<State>(aNextState, Nothing(), aSize,
BufferingStrategy::BUFFERED);
}
@ -102,8 +148,6 @@ struct Transition
const State& aUnbufferedState,
size_t aSize)
{
MOZ_ASSERT(!IsTerminalState(aNextState));
MOZ_ASSERT(!IsTerminalState(aUnbufferedState));
return LexerTransition<State>(aNextState, Some(aUnbufferedState), aSize,
BufferingStrategy::UNBUFFERED);
}
@ -119,23 +163,34 @@ struct Transition
static LexerTransition<State>
ContinueUnbuffered(const State& aUnbufferedState)
{
MOZ_ASSERT(!IsTerminalState(aUnbufferedState));
return LexerTransition<State>(aUnbufferedState, Nothing(), 0,
BufferingStrategy::BUFFERED);
}
/**
* Terminate lexing, ending up in terminal state @aFinalState.
* Terminate lexing, ending up in terminal state SUCCESS. (The implicit
* LexerTransition constructor will convert the result to a LexerTransition
* as needed.)
*
* No more data will be delivered after Terminate() is used.
* No more data will be delivered after this function is used.
*/
template <typename State>
static LexerTransition<State>
Terminate(const State& aFinalState)
static TerminalState
TerminateSuccess()
{
MOZ_ASSERT(IsTerminalState(aFinalState));
return LexerTransition<State>(aFinalState, Nothing(), 0,
BufferingStrategy::BUFFERED);
return TerminalState::SUCCESS;
}
/**
* Terminate lexing, ending up in terminal state FAILURE. (The implicit
* LexerTransition constructor will convert the result to a LexerTransition
* as needed.)
*
* No more data will be delivered after this function is used.
*/
static TerminalState
TerminateFailure()
{
return TerminalState::FAILURE;
}
private:
@ -151,7 +206,7 @@ private:
*
* - Create a State type. This should be an |enum class| listing all of the
* states that you can be in while lexing the image format you're trying to
* read. It must contain the two terminal states SUCCESS and FAILURE.
* read.
*
* - Add an instance of StreamingLexer<State> to your decoder class. Initialize
* it with a Transition::To() the state that you want to start lexing in.
@ -166,9 +221,9 @@ private:
*
* - Write the methods that actually implement lexing for your image format.
* These methods should return either Transition::To(), to move on to another
* state, or Transition::Terminate(), if lexing has terminated in either
* success or failure. (There are also additional transitions for unbuffered
* reads; see below.)
* state, or Transition::Terminate{Success,Failure}(), if lexing has
* terminated in either success or failure. (There are also additional
* transitions for unbuffered reads; see below.)
*
* That's all there is to it. The StreamingLexer will track your position in the
* input and buffer enough data so that your lexing methods can process
@ -208,12 +263,12 @@ public:
{ }
template <typename Func>
Maybe<State> Lex(const char* aInput, size_t aLength, Func aFunc)
Maybe<TerminalState> Lex(const char* aInput, size_t aLength, Func aFunc)
{
if (IsTerminalState(mTransition.NextState())) {
if (mTransition.NextStateIsTerminal()) {
// We've already reached a terminal state. We never deliver any more data
// in this case; just return the terminal state again immediately.
return Some(mTransition.NextState());
return Some(mTransition.NextStateAsTerminal());
}
if (mToReadUnbuffered > 0) {
@ -225,15 +280,15 @@ public:
size_t toRead = std::min(mToReadUnbuffered, aLength);
// Call aFunc with the unbuffered state to indicate that we're in the middle
// of an unbuffered read. We enforce that any state transition passed back
// to us is either a terminal states or takes us back to the unbuffered
// state.
// Call aFunc with the unbuffered state to indicate that we're in the
// middle of an unbuffered read. We enforce that any state transition
// passed back to us is either a terminal state or takes us back to the
// unbuffered state.
LexerTransition<State> unbufferedTransition =
aFunc(mTransition.UnbufferedState(), aInput, toRead);
if (IsTerminalState(unbufferedTransition.NextState())) {
if (unbufferedTransition.NextStateIsTerminal()) {
mTransition = unbufferedTransition;
return Some(mTransition.NextState()); // Done!
return Some(mTransition.NextStateAsTerminal()); // Done!
}
MOZ_ASSERT(mTransition.UnbufferedState() ==
unbufferedTransition.NextState());
@ -247,8 +302,8 @@ public:
// We're done with the unbuffered read, so transition to the next state.
mTransition = aFunc(mTransition.NextState(), nullptr, 0);
if (IsTerminalState(mTransition.NextState())) {
return Some(mTransition.NextState()); // Done!
if (mTransition.NextStateIsTerminal()) {
return Some(mTransition.NextStateAsTerminal()); // Done!
}
} else if (0 < mBuffer.length()) {
// We're continuing a buffered read.
@ -272,8 +327,8 @@ public:
mTransition =
aFunc(mTransition.NextState(), mBuffer.begin(), mBuffer.length());
mBuffer.clear();
if (IsTerminalState(mTransition.NextState())) {
return Some(mTransition.NextState()); // Done!
if (mTransition.NextStateIsTerminal()) {
return Some(mTransition.NextStateAsTerminal()); // Done!
}
}
@ -291,13 +346,13 @@ public:
// Call aFunc with the unbuffered state to indicate that we're in the
// middle of an unbuffered read. We enforce that any state transition
// passed back to us is either a terminal states or takes us back to the
// passed back to us is either a terminal state or takes us back to the
// unbuffered state.
LexerTransition<State> unbufferedTransition =
aFunc(mTransition.UnbufferedState(), aInput, toRead);
if (IsTerminalState(unbufferedTransition.NextState())) {
if (unbufferedTransition.NextStateIsTerminal()) {
mTransition = unbufferedTransition;
return Some(mTransition.NextState()); // Done!
return Some(mTransition.NextStateAsTerminal()); // Done!
}
MOZ_ASSERT(mTransition.UnbufferedState() ==
unbufferedTransition.NextState());
@ -309,8 +364,8 @@ public:
aInput += toRead;
aLength -= toRead;
if (IsTerminalState(mTransition.NextState())) {
return Some(mTransition.NextState()); // Done!
if (mTransition.NextStateIsTerminal()) {
return Some(mTransition.NextStateAsTerminal()); // Done!
}
}
@ -323,9 +378,9 @@ public:
if (mTransition.Buffering() == BufferingStrategy::UNBUFFERED) {
LexerTransition<State> unbufferedTransition =
aFunc(mTransition.UnbufferedState(), aInput, aLength);
if (IsTerminalState(unbufferedTransition.NextState())) {
if (unbufferedTransition.NextStateIsTerminal()) {
mTransition = unbufferedTransition;
return Some(mTransition.NextState()); // Done!
return Some(mTransition.NextStateAsTerminal()); // Done!
}
MOZ_ASSERT(mTransition.UnbufferedState() ==
unbufferedTransition.NextState());
@ -333,11 +388,11 @@ public:
mToReadUnbuffered = mTransition.Size() - aLength;
return Nothing(); // Need more input.
}
// If the next state is buffered, buffer what we can and then wait.
MOZ_ASSERT(mTransition.Buffering() == BufferingStrategy::BUFFERED);
if (!mBuffer.reserve(mTransition.Size())) {
return Some(State::FAILURE); // Done due to allocation failure.
return Some(TerminalState::FAILURE); // Done due to allocation failure.
}
mBuffer.append(aInput, aLength);
return Nothing(); // Need more input.

View File

@ -162,15 +162,7 @@ Set4BitPixel(uint32_t*& aDecoded, uint8_t aData, uint32_t& aCount,
}
}
static PRLogModuleInfo*
GetBMPLog()
{
static PRLogModuleInfo* sBMPLog;
if (!sBMPLog) {
sBMPLog = PR_NewLogModule("BMPDecoder");
}
return sBMPLog;
}
static mozilla::LazyLogModule sBMPLog("BMPDecoder");
// The length of the mBIHSize field in the info header.
static const uint32_t BIHSIZE_FIELD_LENGTH = 4;
@ -437,7 +429,7 @@ nsBMPDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
MOZ_ASSERT(aBuffer);
MOZ_ASSERT(aCount > 0);
Maybe<State> terminalState =
Maybe<TerminalState> terminalState =
mLexer.Lex(aBuffer, aCount, [=](State aState,
const char* aData, size_t aLength) {
switch (aState) {
@ -452,23 +444,13 @@ nsBMPDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
case State::RLE_DELTA: return ReadRLEDelta(aData);
case State::RLE_ABSOLUTE: return ReadRLEAbsolute(aData, aLength);
default:
MOZ_ASSERT_UNREACHABLE("Unknown State");
return Transition::Terminate(State::FAILURE);
MOZ_CRASH("Unknown State");
}
});
if (!terminalState) {
return; // Need more data.
}
if (*terminalState == State::FAILURE) {
if (terminalState == Some(TerminalState::FAILURE)) {
PostDataError();
return;
}
MOZ_ASSERT(*terminalState == State::SUCCESS);
return;
}
LexerTransition<nsBMPDecoder::State>
@ -479,7 +461,7 @@ nsBMPDecoder::ReadFileHeader(const char* aData, size_t aLength)
bool signatureOk = aData[0] == 'B' && aData[1] == 'M';
if (!signatureOk) {
PostDataError();
return Transition::Terminate(State::FAILURE);
return Transition::TerminateFailure();
}
// We ignore the filesize (aData + 2) and reserved (aData + 6) fields.
@ -506,7 +488,7 @@ nsBMPDecoder::ReadInfoHeaderSize(const char* aData, size_t aLength)
mH.mBIHSize <= InfoHeaderLength::OS2_V2_MAX);
if (!bihSizeOk) {
PostDataError();
return Transition::Terminate(State::FAILURE);
return Transition::TerminateFailure();
}
// ICO BMPs must have a WinVMPv3 header. nsICODecoder should have already
// terminated decoding if this isn't the case.
@ -548,7 +530,7 @@ nsBMPDecoder::ReadInfoHeaderRest(const char* aData, size_t aLength)
}
// Run with NSPR_LOG_MODULES=BMPDecoder:4 set to see this output.
MOZ_LOG(GetBMPLog(), LogLevel::Debug,
MOZ_LOG(sBMPLog, LogLevel::Debug,
("BMP: bihsize=%u, %d x %d, bpp=%u, compression=%u, colors=%u\n",
mH.mBIHSize, mH.mWidth, mH.mHeight, uint32_t(mH.mBpp),
mH.mCompression, mH.mNumColors));
@ -561,7 +543,7 @@ nsBMPDecoder::ReadInfoHeaderRest(const char* aData, size_t aLength)
mH.mHeight != INT_MIN;
if (!sizeOk) {
PostDataError();
return Transition::Terminate(State::FAILURE);
return Transition::TerminateFailure();
}
// Check mBpp and mCompression.
@ -575,7 +557,7 @@ nsBMPDecoder::ReadInfoHeaderRest(const char* aData, size_t aLength)
(mH.mBpp == 16 || mH.mBpp == 32));
if (!bppCompressionOk) {
PostDataError();
return Transition::Terminate(State::FAILURE);
return Transition::TerminateFailure();
}
// Post our size to the superclass.
@ -652,7 +634,7 @@ nsBMPDecoder::ReadBitfields(const char* aData, size_t aLength)
// We've now read all the headers. If we're doing a metadata decode, we're
// done.
if (IsMetadataDecode()) {
return Transition::Terminate(State::SUCCESS);
return Transition::TerminateSuccess();
}
// Set up the color table, if present; it'll be filled in by ReadColorTable().
@ -677,7 +659,7 @@ nsBMPDecoder::ReadBitfields(const char* aData, size_t aLength)
IntRect(IntPoint(), targetSize),
SurfaceFormat::B8G8R8A8);
if (NS_FAILED(rv)) {
return Transition::Terminate(State::FAILURE);
return Transition::TerminateFailure();
}
MOZ_ASSERT(mImageData, "Should have a buffer now");
@ -688,7 +670,7 @@ nsBMPDecoder::ReadBitfields(const char* aData, size_t aLength)
mImageData, mMayHaveTransparency,
/* aFlipVertically = */ true);
if (NS_FAILED(rv)) {
return Transition::Terminate(State::FAILURE);
return Transition::TerminateFailure();
}
}
@ -719,7 +701,7 @@ nsBMPDecoder::ReadColorTable(const char* aData, size_t aLength)
// we give up.
if (mPreGapLength > mH.mDataOffset) {
PostDataError();
return Transition::Terminate(State::FAILURE);
return Transition::TerminateFailure();
}
uint32_t gapLength = mH.mDataOffset - mPreGapLength;
return Transition::To(State::GAP, gapLength);
@ -866,7 +848,7 @@ nsBMPDecoder::ReadPixelRow(const char* aData)
FinishRow();
return mCurrentRow == 0
? Transition::Terminate(State::SUCCESS)
? Transition::TerminateSuccess()
: Transition::To(State::PIXEL_ROW, mPixelRowSize);
}
@ -874,7 +856,7 @@ LexerTransition<nsBMPDecoder::State>
nsBMPDecoder::ReadRLESegment(const char* aData)
{
if (mCurrentRow == 0) {
return Transition::Terminate(State::SUCCESS);
return Transition::TerminateSuccess();
}
uint8_t byte1 = uint8_t(aData[0]);
@ -909,12 +891,12 @@ nsBMPDecoder::ReadRLESegment(const char* aData)
mCurrentPos = 0;
FinishRow();
return mCurrentRow == 0
? Transition::Terminate(State::SUCCESS)
? Transition::TerminateSuccess()
: Transition::To(State::RLE_SEGMENT, RLE::SEGMENT_LENGTH);
}
if (byte2 == RLE::ESCAPE_EOF) {
return Transition::Terminate(State::SUCCESS);
return Transition::TerminateSuccess();
}
if (byte2 == RLE::ESCAPE_DELTA) {
@ -972,7 +954,7 @@ nsBMPDecoder::ReadRLEDelta(const char* aData)
}
return mCurrentRow == 0
? Transition::Terminate(State::SUCCESS)
? Transition::TerminateSuccess()
: Transition::To(State::RLE_SEGMENT, RLE::SEGMENT_LENGTH);
}
@ -985,7 +967,7 @@ nsBMPDecoder::ReadRLEAbsolute(const char* aData, size_t aLength)
if (mCurrentPos + n > uint32_t(mH.mWidth)) {
// Bad data. Stop decoding; at least part of the image may have been
// decoded.
return Transition::Terminate(State::SUCCESS);
return Transition::TerminateSuccess();
}
// In absolute mode, n represents the number of pixels that follow, each of

View File

@ -167,9 +167,7 @@ private:
PIXEL_ROW,
RLE_SEGMENT,
RLE_DELTA,
RLE_ABSOLUTE,
SUCCESS,
FAILURE
RLE_ABSOLUTE
};
// This is the constructor used by DecoderFactory.

View File

@ -170,14 +170,14 @@ nsICODecoder::ReadHeader(const char* aData)
{
// If the third byte is 1, this is an icon. If 2, a cursor.
if ((aData[2] != 1) && (aData[2] != 2)) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
mIsCursor = (aData[2] == 2);
// The fifth and sixth bytes specify the number of resources in the file.
mNumIcons = LittleEndian::readUint16(aData + 4);
if (mNumIcons == 0) {
return Transition::Terminate(ICOState::SUCCESS); // Nothing to do.
return Transition::TerminateSuccess(); // Nothing to do.
}
// Downscale-during-decode can end up decoding different resources in the ICO
@ -257,7 +257,7 @@ nsICODecoder::ReadDirEntry(const char* aData)
if (mCurrIcon == mNumIcons) {
// Ensure the resource we selected has an offset past the ICO headers.
if (mDirEntry.mImageOffset < FirstResourceOffset()) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
// If this is a cursor, set the hotspot. We use the hotspot from the biggest
@ -272,7 +272,7 @@ nsICODecoder::ReadDirEntry(const char* aData)
// attempt to *upscale* while decoding.
PostSize(mBiggestResourceSize.width, mBiggestResourceSize.height);
if (IsMetadataDecode()) {
return Transition::Terminate(ICOState::SUCCESS);
return Transition::TerminateSuccess();
}
// If the resource we selected matches the downscaler's target size
@ -309,11 +309,11 @@ nsICODecoder::SniffResource(const char* aData)
mContainedDecoder->Init();
if (!WriteToContainedDecoder(aData, PNGSIGNATURESIZE)) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
if (mDirEntry.mBytesInRes <= PNGSIGNATURESIZE) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
// Read in the rest of the PNG unbuffered.
@ -325,7 +325,7 @@ nsICODecoder::SniffResource(const char* aData)
// Make sure we have a sane size for the bitmap information header.
int32_t bihSize = LittleEndian::readUint32(aData);
if (bihSize != static_cast<int32_t>(BITMAPINFOSIZE)) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
// Buffer the first part of the bitmap information header.
@ -341,13 +341,13 @@ LexerTransition<ICOState>
nsICODecoder::ReadPNG(const char* aData, uint32_t aLen)
{
if (!WriteToContainedDecoder(aData, aLen)) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
// Raymond Chen says that 32bpp only are valid PNG ICOs
// http://blogs.msdn.com/b/oldnewthing/archive/2010/10/22/10079192.aspx
if (!static_cast<nsPNGDecoder*>(mContainedDecoder.get())->IsValidICO()) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
return Transition::ContinueUnbuffered(ICOState::READ_PNG);
@ -372,7 +372,7 @@ nsICODecoder::ReadBIH(const char* aData)
// The color table is present only if BPP is <= 8.
uint16_t numColors = GetNumColors();
if (numColors == (uint16_t)-1) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
dataOffset += 4 * numColors;
}
@ -393,23 +393,23 @@ nsICODecoder::ReadBIH(const char* aData)
// will understand, because the BMP decoder doesn't expect the alpha mask that
// follows the BMP data in an ICO.
if (!FixBitmapHeight(reinterpret_cast<int8_t*>(mBIHraw))) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
// Fix the ICO width from the BIH.
if (!FixBitmapWidth(reinterpret_cast<int8_t*>(mBIHraw))) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
// Write out the BMP's bitmap info header.
if (!WriteToContainedDecoder(mBIHraw, sizeof(mBIHraw))) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
// Check to make sure we have valid color settings.
uint16_t numColors = GetNumColors();
if (numColors == uint16_t(-1)) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
// Do we have an AND mask on this BMP? If so, we need to read it after we read
@ -429,7 +429,7 @@ LexerTransition<ICOState>
nsICODecoder::ReadBMP(const char* aData, uint32_t aLen)
{
if (!WriteToContainedDecoder(aData, aLen)) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
return Transition::ContinueUnbuffered(ICOState::READ_BMP);
@ -466,7 +466,7 @@ nsICODecoder::PrepareForMask()
// we must have a truncated (and therefore corrupt) AND mask.
uint32_t expectedLength = mMaskRowSize * GetRealHeight();
if (maskLength < expectedLength) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
// If we're downscaling, the mask is the wrong size for the surface we've
@ -483,7 +483,7 @@ nsICODecoder::PrepareForMask()
/* aHasAlpha = */ true,
/* aFlipVertically = */ true);
if (NS_FAILED(rv)) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
}
@ -516,7 +516,7 @@ nsICODecoder::ReadMaskRow(const char* aData)
static_cast<nsBMPDecoder*>(mContainedDecoder.get());
uint32_t* imageData = bmpDecoder->GetImageData();
if (!imageData) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
decoded = imageData + mCurrMaskLine * GetRealWidth();
@ -566,7 +566,7 @@ nsICODecoder::FinishMask()
static_cast<nsBMPDecoder*>(mContainedDecoder.get());
uint8_t* imageData = reinterpret_cast<uint8_t*>(bmpDecoder->GetImageData());
if (!imageData) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
// Iterate through the alpha values, copying from mask to image.
@ -596,10 +596,10 @@ nsICODecoder::FinishResource()
// entry. If not, we consider the image corrupt.
if (mContainedDecoder->HasSize() &&
mContainedDecoder->GetSize() != GetRealSize()) {
return Transition::Terminate(ICOState::FAILURE);
return Transition::TerminateFailure();
}
return Transition::Terminate(ICOState::SUCCESS);
return Transition::TerminateSuccess();
}
void
@ -609,7 +609,7 @@ nsICODecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
MOZ_ASSERT(aBuffer);
MOZ_ASSERT(aCount > 0);
Maybe<ICOState> terminalState =
Maybe<TerminalState> terminalState =
mLexer.Lex(aBuffer, aCount,
[=](ICOState aState, const char* aData, size_t aLength) {
switch (aState) {
@ -640,21 +640,13 @@ nsICODecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
case ICOState::FINISHED_RESOURCE:
return FinishResource();
default:
MOZ_ASSERT_UNREACHABLE("Unknown ICOState");
return Transition::Terminate(ICOState::FAILURE);
MOZ_CRASH("Unknown ICOState");
}
});
if (!terminalState) {
return; // Need more data.
}
if (*terminalState == ICOState::FAILURE) {
if (terminalState == Some(TerminalState::FAILURE)) {
PostDataError();
return;
}
MOZ_ASSERT(*terminalState == ICOState::SUCCESS);
}
bool

View File

@ -21,8 +21,6 @@ class RasterImage;
enum class ICOState
{
SUCCESS,
FAILURE,
HEADER,
DIR_ENTRY,
SKIP_TO_RESOURCE,

View File

@ -42,7 +42,7 @@ nsIconDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
MOZ_ASSERT(aBuffer);
MOZ_ASSERT(aCount > 0);
Maybe<State> terminalState =
Maybe<TerminalState> terminalState =
mLexer.Lex(aBuffer, aCount, [=](State aState,
const char* aData, size_t aLength) {
switch (aState) {
@ -53,21 +53,13 @@ nsIconDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
case State::FINISH:
return Finish();
default:
MOZ_ASSERT_UNREACHABLE("Unknown State");
return Transition::Terminate(State::FAILURE);
MOZ_CRASH("Unknown State");
}
});
if (!terminalState) {
return; // Need more data.
}
if (*terminalState == State::FAILURE) {
if (terminalState == Some(TerminalState::FAILURE)) {
PostDataError();
return;
}
MOZ_ASSERT(*terminalState == State::SUCCESS);
}
LexerTransition<nsIconDecoder::State>
@ -88,7 +80,7 @@ nsIconDecoder::ReadHeader(const char* aData)
// If we're doing a metadata decode, we're done.
if (IsMetadataDecode()) {
return Transition::Terminate(State::SUCCESS);
return Transition::TerminateSuccess();
}
MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
@ -97,7 +89,7 @@ nsIconDecoder::ReadHeader(const char* aData)
IntRect(IntPoint(), targetSize),
gfx::SurfaceFormat::B8G8R8A8);
if (NS_FAILED(rv)) {
return Transition::Terminate(State::FAILURE);
return Transition::TerminateFailure();
}
MOZ_ASSERT(mImageData, "Should have a buffer now");
@ -105,7 +97,7 @@ nsIconDecoder::ReadHeader(const char* aData)
nsresult rv = mDownscaler->BeginFrame(GetSize(), Nothing(),
mImageData, /* aHasAlpha = */ true);
if (NS_FAILED(rv)) {
return Transition::Terminate(State::FAILURE);
return Transition::TerminateFailure();
}
}
@ -142,7 +134,7 @@ nsIconDecoder::Finish()
PostFrameStop();
PostDecodeDone();
return Transition::Terminate(State::SUCCESS);
return Transition::TerminateSuccess();
}
} // namespace image

View File

@ -50,9 +50,7 @@ private:
enum class State {
HEADER,
ROW_OF_PIXELS,
FINISH,
SUCCESS,
FAILURE
FINISH
};
LexerTransition<State> ReadHeader(const char* aData);

View File

@ -36,25 +36,9 @@ static void cmyk_convert_rgb(JSAMPROW row, JDIMENSION width);
namespace mozilla {
namespace image {
static PRLogModuleInfo*
GetJPEGLog()
{
static PRLogModuleInfo* sJPEGLog;
if (!sJPEGLog) {
sJPEGLog = PR_NewLogModule("JPEGDecoder");
}
return sJPEGLog;
}
static mozilla::LazyLogModule sJPEGLog("JPEGDecoder");
static PRLogModuleInfo*
GetJPEGDecoderAccountingLog()
{
static PRLogModuleInfo* sJPEGDecoderAccountingLog;
if (!sJPEGDecoderAccountingLog) {
sJPEGDecoderAccountingLog = PR_NewLogModule("JPEGDecoderAccounting");
}
return sJPEGDecoderAccountingLog;
}
static mozilla::LazyLogModule sJPEGDecoderAccountingLog("JPEGDecoderAccounting");
static qcms_profile*
GetICCProfile(struct jpeg_decompress_struct& info)
@ -106,7 +90,7 @@ nsJPEGDecoder::nsJPEGDecoder(RasterImage* aImage,
mCMSMode = 0;
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("nsJPEGDecoder::nsJPEGDecoder: Creating JPEG decoder %p",
this));
}
@ -125,7 +109,7 @@ nsJPEGDecoder::~nsJPEGDecoder()
qcms_profile_release(mInProfile);
}
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("nsJPEGDecoder::~nsJPEGDecoder: Destroying JPEG decoder %p",
this));
}
@ -205,7 +189,7 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
// Error due to corrupt stream - return NS_OK and consume silently
// so that ImageLib doesn't throw away a partial image load
mState = JPEG_SINK_NON_JPEG_TRAILER;
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (setjmp returned NS_ERROR_FAILURE)"));
return;
} else {
@ -214,23 +198,23 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
// mozilla is seconds away from falling flat on its face.
PostDecoderError(error_code);
mState = JPEG_ERROR;
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (setjmp returned an error)"));
return;
}
}
MOZ_LOG(GetJPEGLog(), LogLevel::Debug,
MOZ_LOG(sJPEGLog, LogLevel::Debug,
("[this=%p] nsJPEGDecoder::Write -- processing JPEG data\n", this));
switch (mState) {
case JPEG_HEADER: {
LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::Write -- entering JPEG_HEADER"
LOG_SCOPE((mozilla::LogModule*)sJPEGLog, "nsJPEGDecoder::Write -- entering JPEG_HEADER"
" case");
// Step 3: read file parameters with jpeg_read_header()
if (jpeg_read_header(&mInfo, TRUE) == JPEG_SUSPENDED) {
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (JPEG_SUSPENDED)"));
return; // I/O suspension
}
@ -296,7 +280,7 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
default:
mState = JPEG_ERROR;
PostDataError();
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (unknown colorpsace (1))"));
return;
}
@ -313,7 +297,7 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
default:
mState = JPEG_ERROR;
PostDataError();
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (unknown colorpsace (2))"));
return;
}
@ -372,7 +356,7 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
default:
mState = JPEG_ERROR;
PostDataError();
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (unknown colorpsace (3))"));
return;
}
@ -390,7 +374,7 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
gfx::SurfaceFormat::B8G8R8A8);
if (NS_FAILED(rv)) {
mState = JPEG_ERROR;
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (could not initialize image frame)"));
return;
}
@ -407,7 +391,7 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
}
}
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
(" JPEGDecoderAccounting: nsJPEGDecoder::"
"Write -- created image frame with %ux%u pixels",
mInfo.output_width, mInfo.output_height));
@ -416,7 +400,7 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
}
case JPEG_START_DECOMPRESS: {
LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::Write -- entering"
LOG_SCOPE((mozilla::LogModule*)sJPEGLog, "nsJPEGDecoder::Write -- entering"
" JPEG_START_DECOMPRESS case");
// Step 4: set parameters for decompression
@ -431,7 +415,7 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
// Step 5: Start decompressor
if (jpeg_start_decompress(&mInfo) == FALSE) {
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (I/O suspension after jpeg_start_decompress())"));
return; // I/O suspension
}
@ -443,14 +427,14 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
case JPEG_DECOMPRESS_SEQUENTIAL: {
if (mState == JPEG_DECOMPRESS_SEQUENTIAL) {
LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::Write -- "
LOG_SCOPE((mozilla::LogModule*)sJPEGLog, "nsJPEGDecoder::Write -- "
"JPEG_DECOMPRESS_SEQUENTIAL case");
bool suspend;
OutputScanlines(&suspend);
if (suspend) {
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (I/O suspension after OutputScanlines() - SEQUENTIAL)"));
return; // I/O suspension
}
@ -464,7 +448,7 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
case JPEG_DECOMPRESS_PROGRESSIVE: {
if (mState == JPEG_DECOMPRESS_PROGRESSIVE) {
LOG_SCOPE(GetJPEGLog(),
LOG_SCOPE((mozilla::LogModule*)sJPEGLog,
"nsJPEGDecoder::Write -- JPEG_DECOMPRESS_PROGRESSIVE case");
int status;
@ -486,7 +470,7 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
scan--;
if (!jpeg_start_output(&mInfo, scan)) {
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (I/O suspension after jpeg_start_output() -"
" PROGRESSIVE)"));
return; // I/O suspension
@ -506,14 +490,14 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
// jpeg_start_output() multiple times for the same scan
mInfo.output_scanline = 0xffffff;
}
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (I/O suspension after OutputScanlines() - PROGRESSIVE)"));
return; // I/O suspension
}
if (mInfo.output_scanline == mInfo.output_height) {
if (!jpeg_finish_output(&mInfo)) {
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (I/O suspension after jpeg_finish_output() -"
" PROGRESSIVE)"));
return; // I/O suspension
@ -535,13 +519,13 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
}
case JPEG_DONE: {
LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::ProcessData -- entering"
LOG_SCOPE((mozilla::LogModule*)sJPEGLog, "nsJPEGDecoder::ProcessData -- entering"
" JPEG_DONE case");
// Step 7: Finish decompression
if (jpeg_finish_decompress(&mInfo) == FALSE) {
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (I/O suspension after jpeg_finish_decompress() - DONE)"));
return; // I/O suspension
}
@ -552,7 +536,7 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
break;
}
case JPEG_SINK_NON_JPEG_TRAILER:
MOZ_LOG(GetJPEGLog(), LogLevel::Debug,
MOZ_LOG(sJPEGLog, LogLevel::Debug,
("[this=%p] nsJPEGDecoder::ProcessData -- entering"
" JPEG_SINK_NON_JPEG_TRAILER case\n", this));
@ -564,7 +548,7 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
"decoder");
}
MOZ_LOG(GetJPEGDecoderAccountingLog(), LogLevel::Debug,
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (end of function)"));
return;
}

View File

@ -12,15 +12,7 @@
using namespace mozilla;
static PRLogModuleInfo*
GetPNGEncoderLog()
{
static PRLogModuleInfo* sPNGEncoderLog;
if (!sPNGEncoderLog) {
sPNGEncoderLog = PR_NewLogModule("PNGEncoder");
}
return sPNGEncoderLog;
}
static LazyLogModule sPNGEncoderLog("PNGEncoder");
NS_IMPL_ISUPPORTS(nsPNGEncoder, imgIEncoder, nsIInputStream,
nsIAsyncInputStream)
@ -685,7 +677,7 @@ void
nsPNGEncoder::WarningCallback(png_structp png_ptr,
png_const_charp warning_msg)
{
MOZ_LOG(GetPNGEncoderLog(), LogLevel::Warning,
MOZ_LOG(sPNGEncoderLog, LogLevel::Warning,
("libpng warning: %s\n", warning_msg));
}
@ -696,7 +688,7 @@ void
nsPNGEncoder::ErrorCallback(png_structp png_ptr,
png_const_charp error_msg)
{
MOZ_LOG(GetPNGEncoderLog(), LogLevel::Error, ("libpng error: %s\n", error_msg));
MOZ_LOG(sPNGEncoderLog, LogLevel::Error, ("libpng error: %s\n", error_msg));
png_longjmp(png_ptr, 1);
}

View File

@ -866,13 +866,13 @@ imgCacheEntry::imgCacheEntry(imgLoader* loader, imgRequest* request,
imgCacheEntry::~imgCacheEntry()
{
LOG_FUNC(GetImgLog(), "imgCacheEntry::~imgCacheEntry()");
LOG_FUNC(gImgLog, "imgCacheEntry::~imgCacheEntry()");
}
void
imgCacheEntry::Touch(bool updateTime /* = true */)
{
LOG_SCOPE(GetImgLog(), "imgCacheEntry::Touch");
LOG_SCOPE(gImgLog, "imgCacheEntry::Touch");
if (updateTime) {
mTouchedTime = SecondsFromPRTime(PR_Now());
@ -899,12 +899,12 @@ void imgCacheEntry::UpdateLoadTime()
void
imgCacheEntry::SetHasNoProxies(bool hasNoProxies)
{
if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
if (hasNoProxies) {
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgCacheEntry::SetHasNoProxies true",
LOG_FUNC_WITH_PARAM(gImgLog, "imgCacheEntry::SetHasNoProxies true",
"uri", mRequest->CacheKey().Spec());
} else {
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgCacheEntry::SetHasNoProxies false",
LOG_FUNC_WITH_PARAM(gImgLog, "imgCacheEntry::SetHasNoProxies false",
"uri", mRequest->CacheKey().Spec());
}
}
@ -1027,7 +1027,7 @@ imgLoader::CreateNewProxyForRequest(imgRequest* aRequest,
nsLoadFlags aLoadFlags,
imgRequestProxy** _retval)
{
LOG_SCOPE_WITH_PARAM(GetImgLog(), "imgLoader::CreateNewProxyForRequest",
LOG_SCOPE_WITH_PARAM(gImgLog, "imgLoader::CreateNewProxyForRequest",
"imgRequest", aRequest);
/* XXX If we move decoding onto separate threads, we should save off the
@ -1078,10 +1078,10 @@ imgCacheExpirationTracker::NotifyExpired(imgCacheEntry* entry)
// mechanism doesn't.
RefPtr<imgCacheEntry> kungFuDeathGrip(entry);
if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
RefPtr<imgRequest> req = entry->GetRequest();
if (req) {
LOG_FUNC_WITH_PARAM(GetImgLog(),
LOG_FUNC_WITH_PARAM(gImgLog,
"imgCacheExpirationTracker::NotifyExpired",
"entry", req->CacheKey().Spec());
}
@ -1402,27 +1402,27 @@ imgLoader::PutIntoCache(const ImageCacheKey& aKey, imgCacheEntry* entry)
{
imgCacheTable& cache = GetCache(aKey);
LOG_STATIC_FUNC_WITH_PARAM(GetImgLog(),
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
"imgLoader::PutIntoCache", "uri", aKey.Spec());
// Check to see if this request already exists in the cache. If so, we'll
// replace the old version.
RefPtr<imgCacheEntry> tmpCacheEntry;
if (cache.Get(aKey, getter_AddRefs(tmpCacheEntry)) && tmpCacheEntry) {
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("[this=%p] imgLoader::PutIntoCache -- Element already in the cache",
nullptr));
RefPtr<imgRequest> tmpRequest = tmpCacheEntry->GetRequest();
// If it already exists, and we're putting the same key into the cache, we
// should remove the old version.
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("[this=%p] imgLoader::PutIntoCache -- Replacing cached element",
nullptr));
RemoveFromCache(aKey);
} else {
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("[this=%p] imgLoader::PutIntoCache --"
" Element NOT already in the cache", nullptr));
}
@ -1459,7 +1459,7 @@ imgLoader::PutIntoCache(const ImageCacheKey& aKey, imgCacheEntry* entry)
bool
imgLoader::SetHasNoProxies(imgRequest* aRequest, imgCacheEntry* aEntry)
{
LOG_STATIC_FUNC_WITH_PARAM(GetImgLog(),
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
"imgLoader::SetHasNoProxies", "uri",
aRequest->CacheKey().Spec());
@ -1495,7 +1495,7 @@ imgLoader::SetHasProxies(imgRequest* aRequest)
const ImageCacheKey& key = aRequest->CacheKey();
imgCacheTable& cache = GetCache(key);
LOG_STATIC_FUNC_WITH_PARAM(GetImgLog(),
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
"imgLoader::SetHasProxies", "uri", key.Spec());
RefPtr<imgCacheEntry> entry;
@ -1542,10 +1542,10 @@ imgLoader::CheckCacheLimits(imgCacheTable& cache, imgCacheQueue& queue)
NS_ASSERTION(entry, "imgLoader::CheckCacheLimits -- NULL entry pointer");
if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
RefPtr<imgRequest> req = entry->GetRequest();
if (req) {
LOG_STATIC_FUNC_WITH_PARAM(GetImgLog(),
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
"imgLoader::CheckCacheLimits",
"entry", req->CacheKey().Spec());
}
@ -1704,7 +1704,7 @@ imgLoader::ValidateEntry(imgCacheEntry* aEntry,
nsIPrincipal* aLoadingPrincipal,
int32_t aCORSMode)
{
LOG_SCOPE(GetImgLog(), "imgLoader::ValidateEntry");
LOG_SCOPE(gImgLog, "imgLoader::ValidateEntry");
bool hasExpired;
uint32_t expirationTime = aEntry->GetExpiryTime();
@ -1775,14 +1775,14 @@ imgLoader::ValidateEntry(imgCacheEntry* aEntry,
// Determine whether the cache aEntry must be revalidated...
validateRequest = ShouldRevalidateEntry(aEntry, aLoadFlags, hasExpired);
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("imgLoader::ValidateEntry validating cache entry. "
"validateRequest = %d", validateRequest));
} else if (!key && MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
} else if (!key && MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
nsAutoCString spec;
aURI->GetSpec(spec);
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("imgLoader::ValidateEntry BYPASSING cache validation for %s "
"because of NULL LoadID", spec.get()));
}
@ -1800,7 +1800,7 @@ imgLoader::ValidateEntry(imgCacheEntry* aEntry,
}
if (requestAppCache != groupAppCache) {
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("imgLoader::ValidateEntry - Unable to use cached imgRequest "
"[request=%p] because of mismatched application caches\n",
address_of(request)));
@ -1808,7 +1808,7 @@ imgLoader::ValidateEntry(imgCacheEntry* aEntry,
}
if (validateRequest && aCanMakeNewChannel) {
LOG_SCOPE(GetImgLog(),
LOG_SCOPE(gImgLog,
"imgLoader::ValidateRequest |cache hit| must validate");
return ValidateRequestWithNewChannel(request, aURI, aInitialDocumentURI,
@ -1825,7 +1825,7 @@ imgLoader::ValidateEntry(imgCacheEntry* aEntry,
bool
imgLoader::RemoveFromCache(const ImageCacheKey& aKey)
{
LOG_STATIC_FUNC_WITH_PARAM(GetImgLog(),
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
"imgLoader::RemoveFromCache", "uri", aKey.Spec());
imgCacheTable& cache = GetCache(aKey);
@ -1861,7 +1861,7 @@ imgLoader::RemoveFromCache(const ImageCacheKey& aKey)
bool
imgLoader::RemoveFromCache(imgCacheEntry* entry)
{
LOG_STATIC_FUNC(GetImgLog(), "imgLoader::RemoveFromCache entry");
LOG_STATIC_FUNC(gImgLog, "imgLoader::RemoveFromCache entry");
RefPtr<imgRequest> request = entry->GetRequest();
if (request) {
@ -1869,14 +1869,14 @@ imgLoader::RemoveFromCache(imgCacheEntry* entry)
imgCacheTable& cache = GetCache(key);
imgCacheQueue& queue = GetCacheQueue(key);
LOG_STATIC_FUNC_WITH_PARAM(GetImgLog(),
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
"imgLoader::RemoveFromCache", "entry's uri",
key.Spec());
cache.Remove(key);
if (entry->HasNoProxies()) {
LOG_STATIC_FUNC(GetImgLog(),
LOG_STATIC_FUNC(gImgLog,
"imgLoader::RemoveFromCache removing from tracker");
if (mCacheTracker) {
mCacheTracker->RemoveObject(entry);
@ -1897,7 +1897,7 @@ imgLoader::RemoveFromCache(imgCacheEntry* entry)
nsresult
imgLoader::EvictEntries(imgCacheTable& aCacheToClear)
{
LOG_STATIC_FUNC(GetImgLog(), "imgLoader::EvictEntries table");
LOG_STATIC_FUNC(gImgLog, "imgLoader::EvictEntries table");
// We have to make a temporary, since RemoveFromCache removes the element
// from the queue, invalidating iterators.
@ -1921,7 +1921,7 @@ imgLoader::EvictEntries(imgCacheTable& aCacheToClear)
nsresult
imgLoader::EvictEntries(imgCacheQueue& aQueueToClear)
{
LOG_STATIC_FUNC(GetImgLog(), "imgLoader::EvictEntries queue");
LOG_STATIC_FUNC(gImgLog, "imgLoader::EvictEntries queue");
// We have to make a temporary, since RemoveFromCache removes the element
// from the queue, invalidating iterators.
@ -2026,7 +2026,7 @@ imgLoader::LoadImage(nsIURI* aURI,
nsAutoCString spec;
aURI->GetSpec(spec);
LOG_SCOPE_WITH_PARAM(GetImgLog(), "imgLoader::LoadImage", "aURI", spec.get());
LOG_SCOPE_WITH_PARAM(gImgLog, "imgLoader::LoadImage", "aURI", spec.get());
*_retval = nullptr;
@ -2102,7 +2102,7 @@ imgLoader::LoadImage(nsIURI* aURI,
// If this entry has no proxies, its request has no reference to the
// entry.
if (entry->HasNoProxies()) {
LOG_FUNC_WITH_PARAM(GetImgLog(),
LOG_FUNC_WITH_PARAM(gImgLog,
"imgLoader::LoadImage() adding proxyless entry", "uri", key.Spec());
MOZ_ASSERT(!request->HasCacheEntry(),
"Proxyless entry's request has cache entry!");
@ -2131,7 +2131,7 @@ imgLoader::LoadImage(nsIURI* aURI,
nsCOMPtr<nsIChannel> newChannel;
// If we didn't get a cache hit, we need to load from the network.
if (!request) {
LOG_SCOPE(GetImgLog(), "imgLoader::LoadImage |cache miss|");
LOG_SCOPE(gImgLog, "imgLoader::LoadImage |cache miss|");
bool forcePrincipalCheck;
rv = NewImageChannel(getter_AddRefs(newChannel),
@ -2156,7 +2156,7 @@ imgLoader::LoadImage(nsIURI* aURI,
getter_AddRefs(request),
getter_AddRefs(entry));
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("[this=%p] imgLoader::LoadImage -- Created new imgRequest"
" [request=%p]\n", this, request.get()));
@ -2179,7 +2179,7 @@ imgLoader::LoadImage(nsIURI* aURI,
// request.
nsCOMPtr<nsIStreamListener> listener = pl;
if (corsmode != imgIRequest::CORS_NONE) {
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("[this=%p] imgLoader::LoadImage -- Setting up a CORS load",
this));
bool withCredentials = corsmode == imgIRequest::CORS_USE_CREDENTIALS;
@ -2188,7 +2188,7 @@ imgLoader::LoadImage(nsIURI* aURI,
new nsCORSListenerProxy(pl, aLoadingPrincipal, withCredentials);
rv = corsproxy->Init(newChannel, DataURIHandling::Allow);
if (NS_FAILED(rv)) {
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("[this=%p] imgLoader::LoadImage -- nsCORSListenerProxy "
"creation failed: 0x%x\n", this, rv));
request->CancelAndAbort(rv);
@ -2198,7 +2198,7 @@ imgLoader::LoadImage(nsIURI* aURI,
listener = corsproxy;
}
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("[this=%p] imgLoader::LoadImage -- Calling channel->AsyncOpen()\n",
this));
@ -2208,7 +2208,7 @@ imgLoader::LoadImage(nsIURI* aURI,
nsresult openRes = newChannel->AsyncOpen(listener, nullptr);
if (NS_FAILED(openRes)) {
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("[this=%p] imgLoader::LoadImage -- AsyncOpen() failed: 0x%x\n",
this, openRes));
request->CancelAndAbort(openRes);
@ -2218,7 +2218,7 @@ imgLoader::LoadImage(nsIURI* aURI,
// Try to add the new request into the cache.
PutIntoCache(key, entry);
} else {
LOG_MSG_WITH_PARAM(GetImgLog(),
LOG_MSG_WITH_PARAM(gImgLog,
"imgLoader::LoadImage |cache hit|", "request", request);
}
@ -2237,7 +2237,7 @@ imgLoader::LoadImage(nsIURI* aURI,
// that'll cause us to validate over the network.
request->SetLoadId(aCX);
LOG_MSG(GetImgLog(), "imgLoader::LoadImage", "creating proxy request.");
LOG_MSG(gImgLog, "imgLoader::LoadImage", "creating proxy request.");
rv = CreateNewProxyForRequest(request, aLoadGroup, aObserver,
requestFlags, _retval);
if (NS_FAILED(rv)) {
@ -2366,7 +2366,7 @@ imgLoader::LoadImageWithChannel(nsIChannel* channel,
// If this entry has no proxies, its request has no reference to
// the entry.
if (entry->HasNoProxies()) {
LOG_FUNC_WITH_PARAM(GetImgLog(),
LOG_FUNC_WITH_PARAM(gImgLog,
"imgLoader::LoadImageWithChannel() adding proxyless entry",
"uri", key.Spec());
MOZ_ASSERT(!request->HasCacheEntry(),
@ -2654,7 +2654,7 @@ ProxyListener::CheckListenerChain()
if (retargetableListener) {
rv = retargetableListener->CheckListenerChain();
}
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("ProxyListener::CheckListenerChain %s [this=%p listener=%p rv=%x]",
(NS_SUCCEEDED(rv) ? "success" : "failure"),
this, (nsIStreamListener*)mDestListener, rv));
@ -2780,10 +2780,10 @@ imgCacheValidator::OnStartRequest(nsIRequest* aRequest, nsISupports* ctxt)
uri = imageURL->ToIURI();
}
if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
nsAutoCString spec;
uri->GetSpec(spec);
LOG_MSG_WITH_PARAM(GetImgLog(),
LOG_MSG_WITH_PARAM(gImgLog,
"imgCacheValidator::OnStartRequest creating new request",
"uri", spec.get());
}
@ -2874,7 +2874,7 @@ imgCacheValidator::CheckListenerChain()
if (retargetableListener) {
rv = retargetableListener->CheckListenerChain();
}
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("[this=%p] imgCacheValidator::CheckListenerChain -- rv %d=%s",
this, NS_SUCCEEDED(rv) ? "succeeded" : "failed", rv));
return rv;

View File

@ -40,16 +40,7 @@
using namespace mozilla;
using namespace mozilla::image;
PRLogModuleInfo*
GetImgLog()
{
static PRLogModuleInfo* sImgLog;
if (!sImgLog) {
sImgLog = PR_NewLogModule("imgRequest");
}
return sImgLog;
}
#define LOG_TEST(level) (GetImgLog() && MOZ_LOG_TEST(GetImgLog(), (level)))
#define LOG_TEST(level) (MOZ_LOG_TEST(gImgLog, (level)))
NS_IMPL_ISUPPORTS(imgRequest,
nsIStreamListener, nsIRequestObserver,
@ -86,10 +77,10 @@ imgRequest::~imgRequest()
if (mURI) {
nsAutoCString spec;
mURI->GetSpec(spec);
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequest::~imgRequest()",
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequest::~imgRequest()",
"keyuri", spec.get());
} else
LOG_FUNC(GetImgLog(), "imgRequest::~imgRequest()");
LOG_FUNC(gImgLog, "imgRequest::~imgRequest()");
}
nsresult
@ -106,7 +97,7 @@ imgRequest::Init(nsIURI *aURI,
{
MOZ_ASSERT(NS_IsMainThread(), "Cannot use nsIURI off main thread!");
LOG_FUNC(GetImgLog(), "imgRequest::Init");
LOG_FUNC(gImgLog, "imgRequest::Init");
MOZ_ASSERT(!mImage, "Multiple calls to init");
MOZ_ASSERT(aURI, "No uri");
@ -216,7 +207,7 @@ void
imgRequest::AddProxy(imgRequestProxy* proxy)
{
NS_PRECONDITION(proxy, "null imgRequestProxy passed in");
LOG_SCOPE_WITH_PARAM(GetImgLog(), "imgRequest::AddProxy", "proxy", proxy);
LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequest::AddProxy", "proxy", proxy);
if (!mFirstProxy) {
// Save a raw pointer to the first proxy we see, for use in the network
@ -240,7 +231,7 @@ imgRequest::AddProxy(imgRequestProxy* proxy)
nsresult
imgRequest::RemoveProxy(imgRequestProxy* proxy, nsresult aStatus)
{
LOG_SCOPE_WITH_PARAM(GetImgLog(), "imgRequest::RemoveProxy", "proxy", proxy);
LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequest::RemoveProxy", "proxy", proxy);
// This will remove our animation consumers, so after removing
// this proxy, we don't end up without proxies with observers, but still
@ -266,10 +257,10 @@ imgRequest::RemoveProxy(imgRequestProxy* proxy, nsresult aStatus)
if (mLoader) {
mLoader->SetHasNoProxies(this, mCacheEntry);
}
} else if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
} else if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
nsAutoCString spec;
mURI->GetSpec(spec);
LOG_MSG_WITH_PARAM(GetImgLog(),
LOG_MSG_WITH_PARAM(gImgLog,
"imgRequest::RemoveProxy no cache entry",
"uri", spec.get());
}
@ -282,7 +273,7 @@ imgRequest::RemoveProxy(imgRequestProxy* proxy, nsresult aStatus)
*/
if (!(progressTracker->GetProgress() & FLAG_LAST_PART_COMPLETE) &&
NS_FAILED(aStatus)) {
LOG_MSG(GetImgLog(), "imgRequest::RemoveProxy",
LOG_MSG(gImgLog, "imgRequest::RemoveProxy",
"load in progress. canceling");
this->Cancel(NS_BINDING_ABORTED);
@ -304,7 +295,7 @@ imgRequest::RemoveProxy(imgRequestProxy* proxy, nsresult aStatus)
void
imgRequest::CancelAndAbort(nsresult aStatus)
{
LOG_SCOPE(GetImgLog(), "imgRequest::CancelAndAbort");
LOG_SCOPE(gImgLog, "imgRequest::CancelAndAbort");
Cancel(aStatus);
@ -343,7 +334,7 @@ void
imgRequest::Cancel(nsresult aStatus)
{
/* The Cancel() method here should only be called by this class. */
LOG_SCOPE(GetImgLog(), "imgRequest::Cancel");
LOG_SCOPE(gImgLog, "imgRequest::Cancel");
if (NS_IsMainThread()) {
ContinueCancel(aStatus);
@ -392,7 +383,7 @@ void
imgRequest::EvictFromCache()
{
/* The EvictFromCache() method here should only be called by this class. */
LOG_SCOPE(GetImgLog(), "imgRequest::EvictFromCache");
LOG_SCOPE(gImgLog, "imgRequest::EvictFromCache");
if (NS_IsMainThread()) {
ContinueEvict();
@ -428,7 +419,7 @@ nsresult imgRequest::GetURI(ImageURL** aURI)
{
MOZ_ASSERT(aURI);
LOG_FUNC(GetImgLog(), "imgRequest::GetURI");
LOG_FUNC(gImgLog, "imgRequest::GetURI");
if (mURI) {
*aURI = mURI;
@ -444,7 +435,7 @@ imgRequest::GetCurrentURI(nsIURI** aURI)
{
MOZ_ASSERT(aURI);
LOG_FUNC(GetImgLog(), "imgRequest::GetCurrentURI");
LOG_FUNC(gImgLog, "imgRequest::GetCurrentURI");
if (mCurrentURI) {
*aURI = mCurrentURI;
@ -474,7 +465,7 @@ imgRequest::GetImageErrorCode()
nsresult
imgRequest::GetSecurityInfo(nsISupports** aSecurityInfo)
{
LOG_FUNC(GetImgLog(), "imgRequest::GetSecurityInfo");
LOG_FUNC(gImgLog, "imgRequest::GetSecurityInfo");
// Missing security info means this is not a security load
// i.e. it is not an error when security info is missing
@ -485,7 +476,7 @@ imgRequest::GetSecurityInfo(nsISupports** aSecurityInfo)
void
imgRequest::RemoveFromCache()
{
LOG_SCOPE(GetImgLog(), "imgRequest::RemoveFromCache");
LOG_SCOPE(gImgLog, "imgRequest::RemoveFromCache");
bool isInCache = false;
@ -561,7 +552,7 @@ imgRequest::HasTransferredData() const
void
imgRequest::SetIsInCache(bool aInCache)
{
LOG_FUNC_WITH_PARAM(GetImgLog(),
LOG_FUNC_WITH_PARAM(gImgLog,
"imgRequest::SetIsCacheable", "aInCache", aInCache);
MutexAutoLock lock(mMutex);
mIsInCache = aInCache;
@ -711,7 +702,7 @@ imgRequest::HadInsecureRedirect() const
NS_IMETHODIMP
imgRequest::OnStartRequest(nsIRequest* aRequest, nsISupports* ctxt)
{
LOG_SCOPE(GetImgLog(), "imgRequest::OnStartRequest");
LOG_SCOPE(gImgLog, "imgRequest::OnStartRequest");
RefPtr<Image> image;
@ -786,7 +777,7 @@ imgRequest::OnStartRequest(nsIRequest* aRequest, nsISupports* ctxt)
DecodePool::Singleton()->GetIOEventTarget();
rv = retargetable->RetargetDeliveryTo(target);
}
MOZ_LOG(GetImgLog(), LogLevel::Warning,
MOZ_LOG(gImgLog, LogLevel::Warning,
("[this=%p] imgRequest::OnStartRequest -- "
"RetargetDeliveryTo rv %d=%s\n",
this, rv, NS_SUCCEEDED(rv) ? "succeeded" : "failed"));
@ -799,7 +790,7 @@ NS_IMETHODIMP
imgRequest::OnStopRequest(nsIRequest* aRequest,
nsISupports* ctxt, nsresult status)
{
LOG_FUNC(GetImgLog(), "imgRequest::OnStopRequest");
LOG_FUNC(gImgLog, "imgRequest::OnStopRequest");
MOZ_ASSERT(NS_IsMainThread(), "Can't send notifications off-main-thread");
RefPtr<Image> image = GetImage();
@ -938,7 +929,7 @@ PrepareForNewPart(nsIRequest* aRequest, nsIInputStream* aInStr, uint32_t aCount,
nsresult rv = chan ? chan->GetContentType(result.mContentType)
: NS_ERROR_FAILURE;
if (NS_FAILED(rv)) {
MOZ_LOG(GetImgLog(),
MOZ_LOG(gImgLog,
LogLevel::Error, ("imgRequest::PrepareForNewPart -- "
"Content type unavailable from the channel\n"));
return result;
@ -949,7 +940,7 @@ PrepareForNewPart(nsIRequest* aRequest, nsIInputStream* aInStr, uint32_t aCount,
chan->GetContentDispositionHeader(result.mContentDisposition);
}
MOZ_LOG(GetImgLog(), LogLevel::Debug,
MOZ_LOG(gImgLog, LogLevel::Debug,
("imgRequest::PrepareForNewPart -- Got content type %s\n",
result.mContentType.get()));
@ -1053,7 +1044,7 @@ imgRequest::OnDataAvailable(nsIRequest* aRequest, nsISupports* aContext,
nsIInputStream* aInStr, uint64_t aOffset,
uint32_t aCount)
{
LOG_SCOPE_WITH_PARAM(GetImgLog(), "imgRequest::OnDataAvailable",
LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequest::OnDataAvailable",
"count", aCount);
NS_ASSERTION(aRequest, "imgRequest::OnDataAvailable -- no request!");
@ -1115,7 +1106,7 @@ imgRequest::OnDataAvailable(nsIRequest* aRequest, nsISupports* aContext,
image->OnImageDataAvailable(aRequest, aContext, aInStr, aOffset, aCount);
if (NS_FAILED(rv)) {
MOZ_LOG(GetImgLog(), LogLevel::Warning,
MOZ_LOG(gImgLog, LogLevel::Warning,
("[this=%p] imgRequest::OnDataAvailable -- "
"copy to RasterImage failed\n", this));
Cancel(NS_IMAGELIB_ERROR_FAILURE);
@ -1238,7 +1229,7 @@ imgRequest::OnRedirectVerifyCallback(nsresult result)
if (mCurrentURI) {
mCurrentURI->GetSpec(spec);
}
LOG_MSG_WITH_PARAM(GetImgLog(),
LOG_MSG_WITH_PARAM(gImgLog,
"imgRequest::OnChannelRedirect", "old", spec.get());
}
@ -1276,7 +1267,7 @@ imgRequest::OnRedirectVerifyCallback(nsresult result)
if (mCurrentURI) {
mCurrentURI->GetSpec(spec);
}
LOG_MSG_WITH_PARAM(GetImgLog(), "imgRequest::OnChannelRedirect",
LOG_MSG_WITH_PARAM(gImgLog, "imgRequest::OnChannelRedirect",
"new", spec.get());
}

View File

@ -160,7 +160,7 @@ imgRequestProxy::Init(imgRequest* aOwner,
NS_PRECONDITION(!GetOwner() && !mListener,
"imgRequestProxy is already initialized");
LOG_SCOPE_WITH_PARAM(GetImgLog(), "imgRequestProxy::Init", "request",
LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequestProxy::Init", "request",
aOwner);
MOZ_ASSERT(mAnimationConsumers == 0, "Cannot have animation before Init");
@ -303,7 +303,7 @@ imgRequestProxy::Cancel(nsresult status)
return NS_ERROR_FAILURE;
}
LOG_SCOPE(GetImgLog(), "imgRequestProxy::Cancel");
LOG_SCOPE(gImgLog, "imgRequestProxy::Cancel");
mCanceled = true;
@ -334,7 +334,7 @@ imgRequestProxy::CancelAndForgetObserver(nsresult aStatus)
return NS_ERROR_FAILURE;
}
LOG_SCOPE(GetImgLog(), "imgRequestProxy::CancelAndForgetObserver");
LOG_SCOPE(gImgLog, "imgRequestProxy::CancelAndForgetObserver");
mCanceled = true;
@ -628,7 +628,7 @@ imgRequestProxy::PerformClone(imgINotificationObserver* aObserver,
{
NS_PRECONDITION(aClone, "Null out param");
LOG_SCOPE(GetImgLog(), "imgRequestProxy::Clone");
LOG_SCOPE(gImgLog, "imgRequestProxy::Clone");
*aClone = nullptr;
RefPtr<imgRequestProxy> clone = aAllocFn(this);
@ -778,7 +778,7 @@ imgRequestProxy::Notify(int32_t aType, const mozilla::gfx::IntRect* aRect)
MOZ_ASSERT(aType != imgINotificationObserver::LOAD_COMPLETE,
"Should call OnLoadComplete");
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::Notify", "type",
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::Notify", "type",
NotificationTypeToString(aType));
if (!mListener || mCanceled) {
@ -794,10 +794,10 @@ imgRequestProxy::Notify(int32_t aType, const mozilla::gfx::IntRect* aRect)
void
imgRequestProxy::OnLoadComplete(bool aLastPart)
{
if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
nsAutoCString name;
GetName(name);
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::OnLoadComplete",
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnLoadComplete",
"name", name.get());
}
@ -840,10 +840,10 @@ imgRequestProxy::OnLoadComplete(bool aLastPart)
void
imgRequestProxy::BlockOnload()
{
if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
nsAutoCString name;
GetName(name);
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::BlockOnload",
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::BlockOnload",
"name", name.get());
}
@ -856,10 +856,10 @@ imgRequestProxy::BlockOnload()
void
imgRequestProxy::UnblockOnload()
{
if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
nsAutoCString name;
GetName(name);
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::UnblockOnload",
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::UnblockOnload",
"name", name.get());
}

View File

@ -15,9 +15,7 @@ enum class TestState
ONE,
TWO,
THREE,
UNBUFFERED,
SUCCESS,
FAILURE
UNBUFFERED
};
void
@ -41,10 +39,9 @@ DoLex(TestState aState, const char* aData, size_t aLength)
return Transition::To(TestState::THREE, 3);
case TestState::THREE:
CheckData(aData, aLength);
return Transition::Terminate(TestState::SUCCESS);
return Transition::TerminateSuccess();
default:
EXPECT_TRUE(false); // Shouldn't get here.
return Transition::Terminate(TestState::FAILURE);
MOZ_CRASH("Unknown TestState");
}
}
@ -65,10 +62,9 @@ DoLexWithUnbuffered(TestState aState, const char* aData, size_t aLength,
return Transition::To(TestState::THREE, 3);
case TestState::THREE:
CheckData(aData, aLength);
return Transition::Terminate(TestState::SUCCESS);
return Transition::TerminateSuccess();
default:
EXPECT_TRUE(false);
return Transition::Terminate(TestState::FAILURE);
MOZ_CRASH("Unknown TestState");
}
}
@ -80,10 +76,9 @@ DoLexWithUnbufferedTerminate(TestState aState, const char* aData, size_t aLength
CheckData(aData, aLength);
return Transition::ToUnbuffered(TestState::TWO, TestState::UNBUFFERED, 3);
case TestState::UNBUFFERED:
return Transition::Terminate(TestState::SUCCESS);
return Transition::TerminateSuccess();
default:
EXPECT_TRUE(false);
return Transition::Terminate(TestState::FAILURE);
MOZ_CRASH("Unknown TestState");
}
}
@ -93,9 +88,9 @@ TEST(ImageStreamingLexer, SingleChunk)
char data[9] = { 1, 2, 3, 1, 2, 3, 1, 2, 3 };
// Test delivering all the data at once.
Maybe<TestState> result = lexer.Lex(data, sizeof(data), DoLex);
Maybe<TerminalState> result = lexer.Lex(data, sizeof(data), DoLex);
EXPECT_TRUE(result.isSome());
EXPECT_EQ(TestState::SUCCESS, *result);
EXPECT_EQ(Some(TerminalState::SUCCESS), result);
}
TEST(ImageStreamingLexer, SingleChunkWithUnbuffered)
@ -105,13 +100,13 @@ TEST(ImageStreamingLexer, SingleChunkWithUnbuffered)
Vector<char> unbufferedVector;
// Test delivering all the data at once.
Maybe<TestState> result =
Maybe<TerminalState> result =
lexer.Lex(data, sizeof(data),
[&](TestState aState, const char* aData, size_t aLength) {
return DoLexWithUnbuffered(aState, aData, aLength, unbufferedVector);
});
EXPECT_TRUE(result.isSome());
EXPECT_EQ(TestState::SUCCESS, *result);
EXPECT_EQ(Some(TerminalState::SUCCESS), result);
}
TEST(ImageStreamingLexer, ChunkPerState)
@ -121,11 +116,11 @@ TEST(ImageStreamingLexer, ChunkPerState)
// Test delivering in perfectly-sized chunks, one per state.
for (unsigned i = 0 ; i < 3 ; ++i) {
Maybe<TestState> result = lexer.Lex(data + 3 * i, 3, DoLex);
Maybe<TerminalState> result = lexer.Lex(data + 3 * i, 3, DoLex);
if (i == 2) {
EXPECT_TRUE(result.isSome());
EXPECT_EQ(TestState::SUCCESS, *result);
EXPECT_EQ(Some(TerminalState::SUCCESS), result);
} else {
EXPECT_TRUE(result.isNothing());
}
@ -140,7 +135,7 @@ TEST(ImageStreamingLexer, ChunkPerStateWithUnbuffered)
// Test delivering in perfectly-sized chunks, one per state.
for (unsigned i = 0 ; i < 3 ; ++i) {
Maybe<TestState> result =
Maybe<TerminalState> result =
lexer.Lex(data + 3 * i, 3,
[&](TestState aState, const char* aData, size_t aLength) {
return DoLexWithUnbuffered(aState, aData, aLength, unbufferedVector);
@ -148,7 +143,7 @@ TEST(ImageStreamingLexer, ChunkPerStateWithUnbuffered)
if (i == 2) {
EXPECT_TRUE(result.isSome());
EXPECT_EQ(TestState::SUCCESS, *result);
EXPECT_EQ(Some(TerminalState::SUCCESS), result);
} else {
EXPECT_TRUE(result.isNothing());
}
@ -162,11 +157,11 @@ TEST(ImageStreamingLexer, OneByteChunks)
// Test delivering in one byte chunks.
for (unsigned i = 0 ; i < 9 ; ++i) {
Maybe<TestState> result = lexer.Lex(data + i, 1, DoLex);
Maybe<TerminalState> result = lexer.Lex(data + i, 1, DoLex);
if (i == 8) {
EXPECT_TRUE(result.isSome());
EXPECT_EQ(TestState::SUCCESS, *result);
EXPECT_EQ(Some(TerminalState::SUCCESS), result);
} else {
EXPECT_TRUE(result.isNothing());
}
@ -181,7 +176,7 @@ TEST(ImageStreamingLexer, OneByteChunksWithUnbuffered)
// Test delivering in one byte chunks.
for (unsigned i = 0 ; i < 9 ; ++i) {
Maybe<TestState> result =
Maybe<TerminalState> result =
lexer.Lex(data + i, 1,
[&](TestState aState, const char* aData, size_t aLength) {
return DoLexWithUnbuffered(aState, aData, aLength, unbufferedVector);
@ -189,7 +184,7 @@ TEST(ImageStreamingLexer, OneByteChunksWithUnbuffered)
if (i == 8) {
EXPECT_TRUE(result.isSome());
EXPECT_EQ(TestState::SUCCESS, *result);
EXPECT_EQ(Some(TerminalState::SUCCESS), result);
} else {
EXPECT_TRUE(result.isNothing());
}
@ -202,23 +197,23 @@ TEST(ImageStreamingLexer, TerminateSuccess)
char data[9] = { 1, 2, 3, 1, 2, 3, 1, 2, 3 };
// Test that Terminate is "sticky".
Maybe<TestState> result =
Maybe<TerminalState> result =
lexer.Lex(data, sizeof(data),
[&](TestState aState, const char* aData, size_t aLength) {
EXPECT_TRUE(aState == TestState::ONE);
return Transition::Terminate(TestState::SUCCESS);
return Transition::TerminateSuccess();
});
EXPECT_TRUE(result.isSome());
EXPECT_EQ(TestState::SUCCESS, *result);
EXPECT_EQ(Some(TerminalState::SUCCESS), result);
result =
lexer.Lex(data, sizeof(data),
[&](TestState aState, const char* aData, size_t aLength) {
EXPECT_TRUE(false); // Shouldn't get here.
return Transition::Terminate(TestState::FAILURE);
return Transition::TerminateFailure();
});
EXPECT_TRUE(result.isSome());
EXPECT_EQ(TestState::SUCCESS, *result);
EXPECT_EQ(Some(TerminalState::SUCCESS), result);
}
TEST(ImageStreamingLexer, TerminateFailure)
@ -227,23 +222,23 @@ TEST(ImageStreamingLexer, TerminateFailure)
char data[9] = { 1, 2, 3, 1, 2, 3, 1, 2, 3 };
// Test that Terminate is "sticky".
Maybe<TestState> result =
Maybe<TerminalState> result =
lexer.Lex(data, sizeof(data),
[&](TestState aState, const char* aData, size_t aLength) {
EXPECT_TRUE(aState == TestState::ONE);
return Transition::Terminate(TestState::FAILURE);
return Transition::TerminateFailure();
});
EXPECT_TRUE(result.isSome());
EXPECT_EQ(TestState::FAILURE, *result);
EXPECT_EQ(Some(TerminalState::FAILURE), result);
result =
lexer.Lex(data, sizeof(data),
[&](TestState aState, const char* aData, size_t aLength) {
EXPECT_TRUE(false); // Shouldn't get here.
return Transition::Terminate(TestState::FAILURE);
return Transition::TerminateFailure();
});
EXPECT_TRUE(result.isSome());
EXPECT_EQ(TestState::FAILURE, *result);
EXPECT_EQ(Some(TerminalState::FAILURE), result);
}
TEST(ImageStreamingLexer, TerminateUnbuffered)
@ -253,12 +248,12 @@ TEST(ImageStreamingLexer, TerminateUnbuffered)
// Test that Terminate works during an unbuffered read.
for (unsigned i = 0 ; i < 9 ; ++i) {
Maybe<TestState> result =
Maybe<TerminalState> result =
lexer.Lex(data + i, 1, DoLexWithUnbufferedTerminate);
if (i > 2) {
EXPECT_TRUE(result.isSome());
EXPECT_EQ(TestState::SUCCESS, *result);
EXPECT_EQ(Some(TerminalState::SUCCESS), result);
} else {
EXPECT_TRUE(result.isNothing());
}

View File

@ -949,6 +949,12 @@ GeckoChildProcessHost::PerformAsyncLaunchInternal(std::vector<std::string>& aExt
++it) {
mSandboxBroker.AllowReadWriteFile(it->c_str());
}
for (auto it = mAllowedDirectories.begin();
it != mAllowedDirectories.end();
++it) {
mSandboxBroker.AllowDirectory(it->c_str());
}
}
#endif // XP_WIN && MOZ_SANDBOX

View File

@ -160,6 +160,7 @@ protected:
SandboxBroker mSandboxBroker;
std::vector<std::wstring> mAllowedFilesRead;
std::vector<std::wstring> mAllowedFilesReadWrite;
std::vector<std::wstring> mAllowedDirectories;
bool mEnableSandboxLogging;
int32_t mSandboxLevel;
#endif

View File

@ -737,12 +737,8 @@ CallAsmJS(JSContext* cx, unsigned argc, Value* vp)
// that the optimized asm.js-to-Ion FFI call path (which we want to be
// very fast) can avoid doing so. The JitActivation is marked as
// inactive so stack iteration will skip over it.
//
// We needn't provide an entry script pointer; that's only used for
// reporting entry points to performance-monitoring tools, and asm.js ->
// Ion calls will never be entry points.
AsmJSActivation activation(cx, module);
JitActivation jitActivation(cx, /* entryScript */ nullptr, /* active */ false);
JitActivation jitActivation(cx, /* active */ false);
// Call the per-exported-function trampoline created by GenerateEntry.
AsmJSModule::CodePtr enter = module.entryTrampoline(func);

View File

@ -69,6 +69,7 @@ using mozilla::Maybe;
using mozilla::Move;
using mozilla::PositiveInfinity;
using mozilla::UniquePtr;
using JS::AsmJSOption;
using JS::GenericNaN;
/*****************************************************************************/
@ -172,18 +173,22 @@ VarListHead(ParseNode* pn)
return ListHead(pn);
}
static inline bool
IsDefaultCase(ParseNode* pn)
{
return pn->as<CaseClause>().isDefault();
}
static inline ParseNode*
CaseExpr(ParseNode* pn)
{
MOZ_ASSERT(pn->isKind(PNK_CASE) || pn->isKind(PNK_DEFAULT));
return BinaryLeft(pn);
return pn->as<CaseClause>().caseExpression();
}
static inline ParseNode*
CaseBody(ParseNode* pn)
{
MOZ_ASSERT(pn->isKind(PNK_CASE) || pn->isKind(PNK_DEFAULT));
return BinaryRight(pn);
return pn->as<CaseClause>().statementList();
}
static inline ParseNode*
@ -5907,8 +5912,7 @@ static bool
CheckDefaultAtEnd(FunctionValidator& f, ParseNode* stmt)
{
for (; stmt; stmt = NextNode(stmt)) {
MOZ_ASSERT(stmt->isKind(PNK_CASE) || stmt->isKind(PNK_DEFAULT));
if (stmt->isKind(PNK_DEFAULT) && NextNode(stmt) != nullptr)
if (IsDefaultCase(stmt) && NextNode(stmt) != nullptr)
return f.fail(stmt, "default label must be at the end");
}
@ -5919,7 +5923,7 @@ static bool
CheckSwitchRange(FunctionValidator& f, ParseNode* stmt, int32_t* low, int32_t* high,
int32_t* tableLength)
{
if (stmt->isKind(PNK_DEFAULT)) {
if (IsDefaultCase(stmt)) {
*low = 0;
*high = -1;
*tableLength = 0;
@ -5933,7 +5937,7 @@ CheckSwitchRange(FunctionValidator& f, ParseNode* stmt, int32_t* low, int32_t* h
*low = *high = i;
ParseNode* initialStmt = stmt;
for (stmt = NextNode(stmt); stmt && stmt->isKind(PNK_CASE); stmt = NextNode(stmt)) {
for (stmt = NextNode(stmt); stmt && !IsDefaultCase(stmt); stmt = NextNode(stmt)) {
int32_t i = 0;
if (!CheckCaseExpr(f, CaseExpr(stmt), &i))
return false;
@ -6008,7 +6012,7 @@ CheckSwitch(FunctionValidator& f, ParseNode* switchStmt)
return false;
uint32_t numCases = 0;
for (; stmt && stmt->isKind(PNK_CASE); stmt = NextNode(stmt)) {
for (; stmt && !IsDefaultCase(stmt); stmt = NextNode(stmt)) {
int32_t caseValue = ExtractNumericLiteral(f.m(), CaseExpr(stmt)).toInt32();
unsigned caseIndex = caseValue - low;
@ -6025,7 +6029,7 @@ CheckSwitch(FunctionValidator& f, ParseNode* switchStmt)
}
bool hasDefault = false;
if (stmt && stmt->isKind(PNK_DEFAULT)) {
if (stmt && IsDefaultCase(stmt)) {
hasDefault = true;
if (!CheckStatement(f, CaseBody(stmt)))
return false;
@ -8267,11 +8271,14 @@ EstablishPreconditions(ExclusiveContext* cx, AsmJSParser& parser)
if (cx->gcSystemPageSize() != AsmJSPageSize)
return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by non 4KiB system page size");
if (!parser.options().asmJSOption)
switch (parser.options().asmJSOption) {
case AsmJSOption::Disabled:
return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by javascript.options.asmjs in about:config");
if (cx->compartment()->debuggerObservesAsmJS())
case AsmJSOption::DisabledByDebugger:
return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by debugger");
case AsmJSOption::Enabled:
break;
}
if (parser.pc->isGenerator())
return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by generator context");

View File

@ -8,6 +8,7 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/Move.h"
#include <stdlib.h>
@ -32,6 +33,7 @@ using namespace js::frontend;
using JS::AutoValueArray;
using mozilla::ArrayLength;
using mozilla::DebugOnly;
using mozilla::Forward;
enum class ParseTarget
{
@ -220,6 +222,13 @@ GetPropertyDefault(JSContext* cx, HandleObject obj, HandleId id, HandleValue def
return GetProperty(cx, obj, obj, id, result);
}
enum class GeneratorStyle
{
None,
Legacy,
ES6
};
/*
* Builder class that constructs JavaScript AST node objects. See:
*
@ -296,123 +305,43 @@ class NodeBuilder
}
private:
bool callback(HandleValue fun, TokenPos* pos, MutableHandleValue dst) {
template <size_t N>
bool callbackHelper(HandleValue fun, AutoValueArray<N>& args, size_t i,
TokenPos* pos, MutableHandleValue dst)
{
// The end of the implementation of callback(). All arguments except
// loc have already been stored in range [0, i) or args.
MOZ_ASSERT(i == N - 1);
if (saveLoc) {
RootedValue loc(cx);
if (!newNodeLoc(pos, &loc))
return false;
AutoValueArray<1> argv(cx);
argv[0].set(loc);
return Invoke(cx, userv, fun, argv.length(), argv.begin(), dst);
args[i++].set(loc);
}
AutoValueArray<1> argv(cx);
argv[0].setNull(); /* no zero-length arrays allowed! */
return Invoke(cx, userv, fun, 0, argv.begin(), dst);
return Invoke(cx, userv, fun, N, args.begin(), dst);
}
bool callback(HandleValue fun, HandleValue v1, TokenPos* pos, MutableHandleValue dst) {
if (saveLoc) {
RootedValue loc(cx);
if (!newNodeLoc(pos, &loc))
return false;
AutoValueArray<2> argv(cx);
argv[0].set(v1);
argv[1].set(loc);
return Invoke(cx, userv, fun, argv.length(), argv.begin(), dst);
}
AutoValueArray<1> argv(cx);
argv[0].set(v1);
return Invoke(cx, userv, fun, argv.length(), argv.begin(), dst);
// Helper function for callback(). Note that all Arguments must be types
// that convert to HandleValue, so this is not really as template-y as it
// seems, just variadic.
template <size_t N, typename... Arguments>
bool callbackHelper(HandleValue fun, AutoValueArray<N>& args, size_t i,
HandleValue head, Arguments&&... tail)
{
// Recursive loop to store the arguments in the array. This eventually
// bottoms out in a call to the non-template callbackHelper() above.
args[i].set(head);
return callbackHelper(fun, args, i + 1, Forward<Arguments>(tail)...);
}
bool callback(HandleValue fun, HandleValue v1, HandleValue v2, TokenPos* pos,
MutableHandleValue dst) {
if (saveLoc) {
RootedValue loc(cx);
if (!newNodeLoc(pos, &loc))
return false;
AutoValueArray<3> argv(cx);
argv[0].set(v1);
argv[1].set(v2);
argv[2].set(loc);
return Invoke(cx, userv, fun, argv.length(), argv.begin(), dst);
}
AutoValueArray<2> argv(cx);
argv[0].set(v1);
argv[1].set(v2);
return Invoke(cx, userv, fun, argv.length(), argv.begin(), dst);
}
bool callback(HandleValue fun, HandleValue v1, HandleValue v2, HandleValue v3, TokenPos* pos,
MutableHandleValue dst) {
if (saveLoc) {
RootedValue loc(cx);
if (!newNodeLoc(pos, &loc))
return false;
AutoValueArray<4> argv(cx);
argv[0].set(v1);
argv[1].set(v2);
argv[2].set(v3);
argv[3].set(loc);
return Invoke(cx, userv, fun, argv.length(), argv.begin(), dst);
}
AutoValueArray<3> argv(cx);
argv[0].set(v1);
argv[1].set(v2);
argv[2].set(v3);
return Invoke(cx, userv, fun, argv.length(), argv.begin(), dst);
}
bool callback(HandleValue fun, HandleValue v1, HandleValue v2, HandleValue v3, HandleValue v4,
TokenPos* pos, MutableHandleValue dst) {
if (saveLoc) {
RootedValue loc(cx);
if (!newNodeLoc(pos, &loc))
return false;
AutoValueArray<5> argv(cx);
argv[0].set(v1);
argv[1].set(v2);
argv[2].set(v3);
argv[3].set(v4);
argv[4].set(loc);
return Invoke(cx, userv, fun, argv.length(), argv.begin(), dst);
}
AutoValueArray<4> argv(cx);
argv[0].set(v1);
argv[1].set(v2);
argv[2].set(v3);
argv[3].set(v4);
return Invoke(cx, userv, fun, argv.length(), argv.begin(), dst);
}
bool callback(HandleValue fun, HandleValue v1, HandleValue v2, HandleValue v3, HandleValue v4,
HandleValue v5, TokenPos* pos, MutableHandleValue dst) {
if (saveLoc) {
RootedValue loc(cx);
if (!newNodeLoc(pos, &loc))
return false;
AutoValueArray<6> argv(cx);
argv[0].set(v1);
argv[1].set(v2);
argv[2].set(v3);
argv[3].set(v4);
argv[4].set(v5);
argv[5].set(loc);
return Invoke(cx, userv, fun, argv.length(), argv.begin(), dst);
}
AutoValueArray<5> argv(cx);
argv[0].set(v1);
argv[1].set(v2);
argv[2].set(v3);
argv[3].set(v4);
argv[4].set(v5);
return Invoke(cx, userv, fun, argv.length(), argv.begin(), dst);
// Invoke a user-defined callback. The actual signature is:
//
// bool callback(HandleValue fun, HandleValue... args, TokenPos* pos,
// MutableHandleValue dst);
template <typename... Arguments>
bool callback(HandleValue fun, Arguments&&... args) {
AutoValueArray<sizeof...(args) - 1> argv(cx);
return callbackHelper(fun, argv, 0, Forward<Arguments>(args)...);
}
// WARNING: Returning a Handle is non-standard, but it works in this case
@ -447,117 +376,39 @@ class NodeBuilder
bool newArray(NodeVector& elts, MutableHandleValue dst);
bool newNode(ASTType type, TokenPos* pos, MutableHandleObject dst);
bool createNode(ASTType type, TokenPos* pos, MutableHandleObject dst);
bool newNode(ASTType type, TokenPos* pos, MutableHandleValue dst) {
RootedObject node(cx);
return newNode(type, pos, &node) &&
setResult(node, dst);
bool newNodeHelper(HandleObject obj, MutableHandleValue dst) {
// The end of the implementation of newNode().
MOZ_ASSERT(obj);
dst.setObject(*obj);
return true;
}
bool newNode(ASTType type, TokenPos* pos,
const char* childName, HandleValue child,
MutableHandleValue dst) {
RootedObject node(cx);
return newNode(type, pos, &node) &&
setProperty(node, childName, child) &&
setResult(node, dst);
template <typename... Arguments>
bool newNodeHelper(HandleObject obj, const char *name, HandleValue value,
Arguments&&... rest)
{
// Recursive loop to define properties. Note that the newNodeHelper()
// call below passes two fewer arguments than we received, as we omit
// `name` and `value`. This eventually bottoms out in a call to the
// non-template newNodeHelper() above.
return defineProperty(obj, name, value)
&& newNodeHelper(obj, Forward<Arguments>(rest)...);
}
bool newNode(ASTType type, TokenPos* pos,
const char* childName1, HandleValue child1,
const char* childName2, HandleValue child2,
MutableHandleValue dst) {
// Create a node object with "type" and "loc" properties, as well as zero
// or more properties passed in as arguments. The signature is really more
// like:
//
// bool newNode(ASTType type, TokenPos* pos,
// {const char *name0, HandleValue value0,}...
// MutableHandleValue dst);
template <typename... Arguments>
bool newNode(ASTType type, TokenPos* pos, Arguments&&... args) {
RootedObject node(cx);
return newNode(type, pos, &node) &&
setProperty(node, childName1, child1) &&
setProperty(node, childName2, child2) &&
setResult(node, dst);
}
bool newNode(ASTType type, TokenPos* pos,
const char* childName1, HandleValue child1,
const char* childName2, HandleValue child2,
const char* childName3, HandleValue child3,
MutableHandleValue dst) {
RootedObject node(cx);
return newNode(type, pos, &node) &&
setProperty(node, childName1, child1) &&
setProperty(node, childName2, child2) &&
setProperty(node, childName3, child3) &&
setResult(node, dst);
}
bool newNode(ASTType type, TokenPos* pos,
const char* childName1, HandleValue child1,
const char* childName2, HandleValue child2,
const char* childName3, HandleValue child3,
const char* childName4, HandleValue child4,
MutableHandleValue dst) {
RootedObject node(cx);
return newNode(type, pos, &node) &&
setProperty(node, childName1, child1) &&
setProperty(node, childName2, child2) &&
setProperty(node, childName3, child3) &&
setProperty(node, childName4, child4) &&
setResult(node, dst);
}
bool newNode(ASTType type, TokenPos* pos,
const char* childName1, HandleValue child1,
const char* childName2, HandleValue child2,
const char* childName3, HandleValue child3,
const char* childName4, HandleValue child4,
const char* childName5, HandleValue child5,
MutableHandleValue dst) {
RootedObject node(cx);
return newNode(type, pos, &node) &&
setProperty(node, childName1, child1) &&
setProperty(node, childName2, child2) &&
setProperty(node, childName3, child3) &&
setProperty(node, childName4, child4) &&
setProperty(node, childName5, child5) &&
setResult(node, dst);
}
bool newNode(ASTType type, TokenPos* pos,
const char* childName1, HandleValue child1,
const char* childName2, HandleValue child2,
const char* childName3, HandleValue child3,
const char* childName4, HandleValue child4,
const char* childName5, HandleValue child5,
const char* childName6, HandleValue child6,
MutableHandleValue dst) {
RootedObject node(cx);
return newNode(type, pos, &node) &&
setProperty(node, childName1, child1) &&
setProperty(node, childName2, child2) &&
setProperty(node, childName3, child3) &&
setProperty(node, childName4, child4) &&
setProperty(node, childName5, child5) &&
setProperty(node, childName6, child6) &&
setResult(node, dst);
}
bool newNode(ASTType type, TokenPos* pos,
const char* childName1, HandleValue child1,
const char* childName2, HandleValue child2,
const char* childName3, HandleValue child3,
const char* childName4, HandleValue child4,
const char* childName5, HandleValue child5,
const char* childName6, HandleValue child6,
const char* childName7, HandleValue child7,
MutableHandleValue dst) {
RootedObject node(cx);
return newNode(type, pos, &node) &&
setProperty(node, childName1, child1) &&
setProperty(node, childName2, child2) &&
setProperty(node, childName3, child3) &&
setProperty(node, childName4, child4) &&
setProperty(node, childName5, child5) &&
setProperty(node, childName6, child6) &&
setProperty(node, childName7, child7) &&
setResult(node, dst);
return createNode(type, pos, &node) &&
newNodeHelper(node, Forward<Arguments>(args)...);
}
bool listNode(ASTType type, const char* propName, NodeVector& elts, TokenPos* pos,
@ -573,7 +424,7 @@ class NodeBuilder
return newNode(type, pos, propName, array, dst);
}
bool setProperty(HandleObject obj, const char* name, HandleValue val) {
bool defineProperty(HandleObject obj, const char* name, HandleValue val) {
MOZ_ASSERT_IF(val.isMagic(), val.whyMagic() == JS_SERIALIZE_NO_NODE);
/*
@ -592,12 +443,6 @@ class NodeBuilder
bool setNodeLoc(HandleObject node, TokenPos* pos);
bool setResult(HandleObject obj, MutableHandleValue dst) {
MOZ_ASSERT(obj);
dst.setObject(*obj);
return true;
}
public:
/*
* All of the public builder methods take as their last two
@ -620,8 +465,8 @@ class NodeBuilder
bool function(ASTType type, TokenPos* pos,
HandleValue id, NodeVector& args, NodeVector& defaults,
HandleValue body, HandleValue rest, bool isGenerator, bool isExpression,
MutableHandleValue dst);
HandleValue body, HandleValue rest, GeneratorStyle generatorStyle,
bool isExpression, MutableHandleValue dst);
bool variableDeclarator(HandleValue id, HandleValue init, TokenPos* pos,
MutableHandleValue dst);
@ -788,7 +633,7 @@ class NodeBuilder
} /* anonymous namespace */
bool
NodeBuilder::newNode(ASTType type, TokenPos* pos, MutableHandleObject dst)
NodeBuilder::createNode(ASTType type, TokenPos* pos, MutableHandleObject dst)
{
MOZ_ASSERT(type > AST_ERROR && type < AST_LIMIT);
@ -797,7 +642,7 @@ NodeBuilder::newNode(ASTType type, TokenPos* pos, MutableHandleObject dst)
if (!node ||
!setNodeLoc(node, pos) ||
!atomValue(nodeTypeNames[type], &tv) ||
!setProperty(node, "type", tv)) {
!defineProperty(node, "type", tv)) {
return false;
}
@ -859,28 +704,28 @@ NodeBuilder::newNodeLoc(TokenPos* pos, MutableHandleValue dst)
if (!newObject(&to))
return false;
val.setObject(*to);
if (!setProperty(loc, "start", val))
if (!defineProperty(loc, "start", val))
return false;
val.setNumber(startLineNum);
if (!setProperty(to, "line", val))
if (!defineProperty(to, "line", val))
return false;
val.setNumber(startColumnIndex);
if (!setProperty(to, "column", val))
if (!defineProperty(to, "column", val))
return false;
if (!newObject(&to))
return false;
val.setObject(*to);
if (!setProperty(loc, "end", val))
if (!defineProperty(loc, "end", val))
return false;
val.setNumber(endLineNum);
if (!setProperty(to, "line", val))
if (!defineProperty(to, "line", val))
return false;
val.setNumber(endColumnIndex);
if (!setProperty(to, "column", val))
if (!defineProperty(to, "column", val))
return false;
if (!setProperty(loc, "source", srcval))
if (!defineProperty(loc, "source", srcval))
return false;
return true;
@ -891,13 +736,13 @@ NodeBuilder::setNodeLoc(HandleObject node, TokenPos* pos)
{
if (!saveLoc) {
RootedValue nullVal(cx, NullValue());
setProperty(node, "loc", nullVal);
defineProperty(node, "loc", nullVal);
return true;
}
RootedValue loc(cx);
return newNodeLoc(pos, &loc) &&
setProperty(node, "loc", loc);
defineProperty(node, "loc", loc);
}
bool
@ -1757,7 +1602,7 @@ bool
NodeBuilder::function(ASTType type, TokenPos* pos,
HandleValue id, NodeVector& args, NodeVector& defaults,
HandleValue body, HandleValue rest,
bool isGenerator, bool isExpression,
GeneratorStyle generatorStyle, bool isExpression,
MutableHandleValue dst)
{
RootedValue array(cx), defarray(cx);
@ -1766,6 +1611,7 @@ NodeBuilder::function(ASTType type, TokenPos* pos,
if (!newArray(defaults, &defarray))
return false;
bool isGenerator = generatorStyle != GeneratorStyle::None;
RootedValue isGeneratorVal(cx, BooleanValue(isGenerator));
RootedValue isExpressionVal(cx, BooleanValue(isExpression));
@ -1774,6 +1620,27 @@ NodeBuilder::function(ASTType type, TokenPos* pos,
return callback(cb, opt(id), array, body, isGeneratorVal, isExpressionVal, pos, dst);
}
if (isGenerator) {
// Distinguish ES6 generators from legacy generators.
RootedValue styleVal(cx);
JSAtom* styleStr = generatorStyle == GeneratorStyle::ES6
? Atomize(cx, "es6", 3)
: Atomize(cx, "legacy", 6);
if (!styleStr)
return false;
styleVal.setString(styleStr);
return newNode(type, pos,
"id", id,
"params", array,
"defaults", defarray,
"body", body,
"rest", rest,
"generator", isGeneratorVal,
"style", styleVal,
"expression", isExpressionVal,
dst);
}
return newNode(type, pos,
"id", id,
"params", array,
@ -2387,8 +2254,8 @@ ASTSerializer::switchCase(ParseNode* pn, MutableHandleValue dst)
RootedValue expr(cx);
return optExpression(pn->pn_left, &expr) &&
statements(pn->pn_right, stmts) &&
return optExpression(pn->as<CaseClause>().caseExpression(), &expr) &&
statements(pn->as<CaseClause>().statementList(), stmts) &&
builder.switchCase(expr, stmts, &pn->pn_pos, dst);
}
@ -3395,7 +3262,9 @@ ASTSerializer::property(ParseNode* pn, MutableHandleValue dst)
}
bool isShorthand = pn->isKind(PNK_SHORTHAND);
bool isMethod = pn->pn_right->isKind(PNK_FUNCTION) && kind == PROP_INIT;
bool isMethod =
pn->pn_right->isKind(PNK_FUNCTION) &&
pn->pn_right->pn_funbox->function()->kind() == JSFunction::Method;
RootedValue key(cx), val(cx);
return propertyName(pn->pn_left, &key) &&
expression(pn->pn_right, &val) &&
@ -3567,8 +3436,12 @@ ASTSerializer::function(ParseNode* pn, ASTType type, MutableHandleValue dst)
{
RootedFunction func(cx, pn->pn_funbox->function());
// FIXME: Provide more information (legacy generator vs star generator).
bool isGenerator = pn->pn_funbox->isGenerator();
GeneratorStyle generatorStyle =
pn->pn_funbox->isGenerator()
? (pn->pn_funbox->isLegacyGenerator()
? GeneratorStyle::Legacy
: GeneratorStyle::ES6)
: GeneratorStyle::None;
bool isExpression =
#if JS_HAS_EXPR_CLOSURES
@ -3592,7 +3465,7 @@ ASTSerializer::function(ParseNode* pn, ASTType type, MutableHandleValue dst)
rest.setNull();
return functionArgsAndBody(pn->pn_body, args, defaults, &body, &rest) &&
builder.function(type, &pn->pn_pos, id, args, defaults, body,
rest, isGenerator, isExpression, dst);
rest, generatorStyle, isExpression, dst);
}
bool

View File

@ -83,6 +83,7 @@ if [[ "$OSTYPE" == darwin* ]]; then
if [ "$VARIANT" = "arm-sim-osx" ]; then
USE_64BIT=false
fi
source "$ABSDIR/macbuildenv.sh"
elif [ "$OSTYPE" = "linux-gnu" ]; then
if [ -n "$AUTOMATION" ]; then
GCCDIR="${GCCDIR:-/tools/gcc-4.7.2-0moz1}"
@ -147,7 +148,10 @@ if $USE_64BIT; then
fi
else
NSPR64=""
if [ "$OSTYPE" != "msys" ]; then
if [ "$OSTYPE" == darwin* ]; then
export CC="${CC:-/usr/bin/clang} -arch i386"
export CXX="${CXX:-/usr/bin/clang++} -arch i386"
elif [ "$OSTYPE" != "msys" ]; then
export CC="${CC:-/usr/bin/gcc} -m32"
export CXX="${CXX:-/usr/bin/g++} -m32"
export AR=ar
@ -209,6 +213,7 @@ elif [[ "$VARIANT" = "warnaserr" ||
"$VARIANT" = "plain" ]]; then
export JSTESTS_EXTRA_ARGS=--jitflags=all
elif [[ "$VARIANT" = "arm-sim" ||
"$VARIANT" = "arm-sim-osx" ||
"$VARIANT" = "plaindebug" ]]; then
export JSTESTS_EXTRA_ARGS=--jitflags=debug
elif [[ "$VARIANT" = arm64* ]]; then

View File

@ -0,0 +1,27 @@
# We will be sourcing mozconfig files, which end up calling mk_add_options and
# ac_add_options with various settings. We only need the variable settings they
# create along the way.
mk_add_options() {
: do nothing
}
ac_add_options() {
: do nothing
}
topsrcdir="$SOURCE"
if [ -n "$AUTOMATION" ]; then
# Download clang and some other things from tooltool server.
# This should be done before running mozconfig to make clang detection
# there work properly.
TT_SERVER=${TT_SERVER:-https://api.pub.build.mozilla.org/tooltool/}
( cd $SOURCE/..; \
./scripts/scripts/tooltool/tooltool_wrapper.sh \
$SOURCE/browser/config/tooltool-manifests/macosx64/releng.manifest \
$TT_SERVER \
setup.sh \
$TOOLTOOL_HOME/tooltool.py )
fi
# Setup CC and CXX variables
. $topsrcdir/build/macosx/mozconfig.common

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More