diff --git a/accessible/windows/ia2/moz.build b/accessible/windows/ia2/moz.build index b2664226ea..dae2c36f0b 100644 --- a/accessible/windows/ia2/moz.build +++ b/accessible/windows/ia2/moz.build @@ -47,6 +47,9 @@ LOCAL_INCLUDES += [ FINAL_LIBRARY = 'xul' +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + # The midl generated code include Windows headers which defines min and max # macros which conflicts with std::min/max. Suppress the macros: if CONFIG['OS_ARCH'] == 'WINNT': diff --git a/accessible/windows/msaa/moz.build b/accessible/windows/msaa/moz.build index 9a7bbf11b6..ad8169f4f6 100644 --- a/accessible/windows/msaa/moz.build +++ b/accessible/windows/msaa/moz.build @@ -60,3 +60,6 @@ LOCAL_INCLUDES += [ include('/ipc/chromium/chromium-config.mozbuild') FINAL_LIBRARY = 'xul' + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/accessible/windows/sdn/moz.build b/accessible/windows/sdn/moz.build index 6bbe061942..afc5e36604 100644 --- a/accessible/windows/sdn/moz.build +++ b/accessible/windows/sdn/moz.build @@ -24,3 +24,6 @@ LOCAL_INCLUDES += [ DEFINES['NOMINMAX'] = True FINAL_LIBRARY = 'xul' + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/b2g/app/moz.build b/b2g/app/moz.build index 7a6494c191..9a5c971973 100644 --- a/b2g/app/moz.build +++ b/b2g/app/moz.build @@ -75,6 +75,9 @@ if CONFIG['OS_ARCH'] == 'WINNT': 'version', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + JS_PREFERENCE_FILES += [ 'b2g.js', ] diff --git a/browser/app/moz.build b/browser/app/moz.build index 630a6a2889..89c2ae6129 100644 --- a/browser/app/moz.build +++ b/browser/app/moz.build @@ -91,3 +91,6 @@ if CONFIG['HAVE_CLOCK_MONOTONIC']: OS_LIBS += CONFIG['REALTIME_LIBS'] JAR_MANIFESTS += ['jar.mn'] + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/browser/components/dirprovider/DirectoryProvider.cpp b/browser/components/dirprovider/DirectoryProvider.cpp index 4d3993b7f4..d47830c724 100644 --- a/browser/components/dirprovider/DirectoryProvider.cpp +++ b/browser/components/dirprovider/DirectoryProvider.cpp @@ -28,8 +28,8 @@ namespace mozilla { namespace browser { NS_IMPL_ISUPPORTS(DirectoryProvider, - nsIDirectoryServiceProvider, - nsIDirectoryServiceProvider2) + nsIDirectoryServiceProvider, + nsIDirectoryServiceProvider2) NS_IMETHODIMP DirectoryProvider::GetFile(const char *aKey, bool *aPersist, nsIFile* *aResult) diff --git a/browser/locales/Makefile.in b/browser/locales/Makefile.in index f8d393c660..fba8c878ed 100644 --- a/browser/locales/Makefile.in +++ b/browser/locales/Makefile.in @@ -43,7 +43,7 @@ ifneq (,$(filter cocoa,$(MOZ_WIDGET_TOOLKIT))) MOZ_PKG_MAC_DSSTORE=$(_ABS_DIST)/branding/dsstore MOZ_PKG_MAC_BACKGROUND=$(_ABS_DIST)/branding/background.png MOZ_PKG_MAC_ICON=$(_ABS_DIST)/branding/disk.icns -MOZ_PKG_MAC_EXTRA=--symlink "/Applications:/ " +MOZ_PKG_MAC_EXTRA=--symlink '/Applications:/ ' endif ifeq (WINNT,$(OS_ARCH)) @@ -54,10 +54,10 @@ UNINSTALLER_PACKAGE_HOOK = $(RM) -r $(STAGEDIST)/uninstall; \ cp ../installer/windows/l10ngen/setup.exe $(_ABS_DIST)/l10n-stage; \ $(NULL) -STUB_HOOK = $(NSINSTALL) -D "$(_ABS_DIST)/$(PKG_INST_PATH)"; \ - $(RM) "$(_ABS_DIST)/$(PKG_INST_PATH)$(PKG_STUB_BASENAME).exe"; \ - cp ../installer/windows/l10ngen/stub.exe "$(_ABS_DIST)/$(PKG_INST_PATH)$(PKG_STUB_BASENAME).exe"; \ - chmod 0755 "$(_ABS_DIST)/$(PKG_INST_PATH)$(PKG_STUB_BASENAME).exe"; \ +STUB_HOOK = $(NSINSTALL) -D '$(_ABS_DIST)/$(PKG_INST_PATH)'; \ + $(RM) '$(_ABS_DIST)/$(PKG_INST_PATH)$(PKG_STUB_BASENAME).exe'; \ + cp ../installer/windows/l10ngen/stub.exe '$(_ABS_DIST)/$(PKG_INST_PATH)$(PKG_STUB_BASENAME).exe'; \ + chmod 0755 '$(_ABS_DIST)/$(PKG_INST_PATH)$(PKG_STUB_BASENAME).exe'; \ $(NULL) endif @@ -138,20 +138,20 @@ libs-%: repackage-win32-installer: WIN32_INSTALLER_OUT=$(_ABS_DIST)/$(PKG_INST_PATH)$(PKG_INST_BASENAME).exe repackage-win32-installer: $(call ESCAPE_WILDCARD,$(WIN32_INSTALLER_IN)) $(SUBMAKEFILES) libs-$(AB_CD) - @echo "Repackaging $(WIN32_INSTALLER_IN) into $(WIN32_INSTALLER_OUT)." + @echo 'Repackaging $(WIN32_INSTALLER_IN) into $(WIN32_INSTALLER_OUT).' $(MAKE) -C $(DEPTH)/$(MOZ_BRANDING_DIRECTORY) export $(MAKE) -C ../installer/windows CONFIG_DIR=l10ngen l10ngen/setup.exe l10ngen/7zSD.sfx $(MAKE) repackage-zip \ AB_CD=$(AB_CD) \ MOZ_PKG_FORMAT=SFX7Z \ - ZIP_IN="$(WIN32_INSTALLER_IN)" \ - ZIP_OUT="$(WIN32_INSTALLER_OUT)" \ - SFX_HEADER="$(PWD)/../installer/windows/l10ngen/7zSD.sfx \ - $(topsrcdir)/browser/installer/windows/app.tag" + ZIP_IN='$(WIN32_INSTALLER_IN)' \ + ZIP_OUT='$(WIN32_INSTALLER_OUT)' \ + SFX_HEADER='$(PWD)/../installer/windows/l10ngen/7zSD.sfx \ + $(topsrcdir)/browser/installer/windows/app.tag' ifeq (WINNT,$(OS_ARCH)) repackage-win32-installer-%: $(STAGEDIST) - @$(MAKE) repackage-win32-installer AB_CD=$* WIN32_INSTALLER_IN="$(WIN32_INSTALLER_IN)" + @$(MAKE) repackage-win32-installer AB_CD=$* WIN32_INSTALLER_IN='$(WIN32_INSTALLER_IN)' repackage-zip-%: repackage-win32-installer-% else @@ -179,7 +179,7 @@ langpack: langpack-$(AB_CD) # tinderbox scripts. Alter it with caution. installers-%: clobber-% langpack-% repackage-win32-installer-% repackage-zip-% - @echo "repackaging done" + @echo 'repackaging done' ifdef MOZ_UPDATER # Note that we want updater.ini to be in the top directory, not the browser/ @@ -187,22 +187,22 @@ ifdef MOZ_UPDATER libs:: $(call MERGE_FILE,updater/updater.ini) $(call mkdir_deps,$(DIST)/bin) ifeq ($(OS_ARCH),WINNT) cat $< $(srcdir)/../installer/windows/nsis/updater_append.ini | \ - sed -e "s/^InfoText=/Info=/" -e "s/^TitleText=/Title=/" | \ - sed -e "s/%MOZ_APP_DISPLAYNAME%/$(MOZ_APP_DISPLAYNAME)/" > \ + sed -e 's/^InfoText=/Info=/' -e 's/^TitleText=/Title=/' | \ + sed -e 's/%MOZ_APP_DISPLAYNAME%/$(MOZ_APP_DISPLAYNAME)/' > \ $(FINAL_TARGET)/../updater.ini else cat $< | \ - sed -e "s/^InfoText=/Info=/" -e "s/^TitleText=/Title=/" | \ - sed -e "s/%MOZ_APP_DISPLAYNAME%/$(MOZ_APP_DISPLAYNAME)/" > \ + sed -e 's/^InfoText=/Info=/' -e 's/^TitleText=/Title=/' | \ + sed -e 's/%MOZ_APP_DISPLAYNAME%/$(MOZ_APP_DISPLAYNAME)/' > \ $(FINAL_TARGET)/../updater.ini endif endif ident: - @printf "fx_revision " + @printf 'fx_revision ' @$(PYTHON) $(topsrcdir)/config/printconfigsetting.py \ $(STAGEDIST)/application.ini App SourceStamp - @printf "buildid " + @printf 'buildid ' @$(PYTHON) $(topsrcdir)/config/printconfigsetting.py \ $(STAGEDIST)/application.ini App BuildID @@ -219,7 +219,7 @@ l10n-check:: INNER_UNMAKE_PACKAGE=true l10n-check:: $(RM) -rf x-test $(NSINSTALL) -D x-test/toolkit - echo "#define MOZ_LANG_TITLE Just testing" > x-test/toolkit/defines.inc - $(MAKE) installers-x-test L10NBASEDIR="$(PWD)" LOCALE_MERGEDIR="$(PWD)/mergedir" + echo '#define MOZ_LANG_TITLE Just testing' > x-test/toolkit/defines.inc + $(MAKE) installers-x-test L10NBASEDIR='$(PWD)' LOCALE_MERGEDIR='$(PWD)/mergedir' $(PYTHON) $(topsrcdir)/toolkit/mozapps/installer/unpack.py $(DIST)/l10n-stage/$(STAGEPATH)$(MOZ_PKG_DIR)$(_BINPATH) cd $(DIST)/l10n-stage && test $$(cat $(STAGEPATH)$(MOZ_PKG_DIR)$(_BINPATH)/update.locale) = x-test diff --git a/build/mozconfig.cache b/build/mozconfig.cache index c003f5f6ea..56bb6bce91 100644 --- a/build/mozconfig.cache +++ b/build/mozconfig.cache @@ -60,7 +60,7 @@ else ac_add_options "--with-compiler-wrapper=python2.7 $topsrcdir/sccache/sccache.py" mk_add_options MOZ_PREFLIGHT_ALL+=build/sccache.mk mk_add_options MOZ_POSTFLIGHT_ALL+=build/sccache.mk - mk_add_options "export UPLOAD_EXTRA_FILES+=sccache.log.gz" + mk_add_options "UPLOAD_EXTRA_FILES+=sccache.log.gz" case "$platform" in win*) # sccache supports a special flag to create depfiles. diff --git a/client.mk b/client.mk index b9c6b61718..54c0cffe7e 100644 --- a/client.mk +++ b/client.mk @@ -190,9 +190,10 @@ WANT_MOZCONFIG_MK = 1 endif ifdef WANT_MOZCONFIG_MK -# For now, only output "export" lines from mach environment --format=client.mk output. -MOZCONFIG_MK_LINES := $(filter export||%,$(MOZCONFIG_OUT_LINES)) -$(OBJDIR)/.mozconfig.mk: $(FOUND_MOZCONFIG) $(call mkdir_deps,$(OBJDIR)) $(OBJDIR)/CLOBBER +# For now, only output "export" lines and lines containing UPLOAD_EXTRA_FILES +# from mach environment --format=client.mk output. +MOZCONFIG_MK_LINES := $(filter export||% UPLOAD_EXTRA_FILES% %UPLOAD_EXTRA_FILES%,$(MOZCONFIG_OUT_LINES)) +$(OBJDIR)/.mozconfig.mk: $(TOPSRCDIR)/client.mk $(FOUND_MOZCONFIG) $(call mkdir_deps,$(OBJDIR)) $(OBJDIR)/CLOBBER $(if $(MOZCONFIG_MK_LINES),( $(foreach line,$(MOZCONFIG_MK_LINES), echo '$(subst ||, ,$(line))';) )) > $@ # Include that makefile so that it is created. This should not actually change @@ -201,12 +202,6 @@ $(OBJDIR)/.mozconfig.mk: $(FOUND_MOZCONFIG) $(call mkdir_deps,$(OBJDIR)) $(OBJDI include $(OBJDIR)/.mozconfig.mk endif -# UPLOAD_EXTRA_FILES is appended to and exported from mozconfig, which makes -# submakes as well as configure add even more to that, so just unexport it -# for submakes to pick it from .mozconfig.mk and for configure to pick it -# from mach environment. -unexport UPLOAD_EXTRA_FILES - # Print out any options loaded from mozconfig. all realbuild clean distclean export libs install realclean:: ifneq (,$(strip $(MOZCONFIG_OUT_FILTERED))) @@ -356,7 +351,9 @@ endif $(OBJDIR)/.mozconfig.json: $(call mkdir_deps,$(OBJDIR)) ; save-mozconfig: $(FOUND_MOZCONFIG) +ifdef FOUND_MOZCONFIG -cp $(FOUND_MOZCONFIG) $(OBJDIR)/.mozconfig +endif configure:: $(configure-preqs) @echo cd $(OBJDIR); diff --git a/docshell/build/moz.build b/docshell/build/moz.build index 653f4837b6..f766204c04 100644 --- a/docshell/build/moz.build +++ b/docshell/build/moz.build @@ -24,3 +24,6 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa": LOCAL_INCLUDES += ['/uriloader/exthandler/mac'] FINAL_LIBRARY = 'xul' + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/dom/apps/moz.build b/dom/apps/moz.build index 23027a8ee2..c583156556 100644 --- a/dom/apps/moz.build +++ b/dom/apps/moz.build @@ -51,6 +51,9 @@ EXTRA_PP_JS_MODULES += [ 'Webapps.jsm', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + FINAL_LIBRARY = 'xul' LOCAL_INCLUDES += [ diff --git a/dom/archivereader/moz.build b/dom/archivereader/moz.build index f262ccc3c2..dcca7d907b 100644 --- a/dom/archivereader/moz.build +++ b/dom/archivereader/moz.build @@ -21,6 +21,9 @@ UNIFIED_SOURCES += [ 'ArchiveZipFile.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + LOCAL_INCLUDES += [ '../base', ] diff --git a/dom/base/ScreenOrientation.h b/dom/base/ScreenOrientation.h index 40c501f444..ca2cdca5b1 100644 --- a/dom/base/ScreenOrientation.h +++ b/dom/base/ScreenOrientation.h @@ -10,18 +10,18 @@ namespace mozilla { namespace dom { -// Make sure that any change here is also made in -// * mobile/android/base/GeckoScreenOrientationListener.java -typedef uint32_t ScreenOrientation; +// Make sure that any change to ScreenOrientationInternal values are +// also made in mobile/android/base/GeckoScreenOrientation.java +typedef uint32_t ScreenOrientationInternal; -static const ScreenOrientation eScreenOrientation_None = 0; -static const ScreenOrientation eScreenOrientation_PortraitPrimary = 1u << 0; -static const ScreenOrientation eScreenOrientation_PortraitSecondary = 1u << 1; -static const ScreenOrientation eScreenOrientation_LandscapePrimary = 1u << 2; -static const ScreenOrientation eScreenOrientation_LandscapeSecondary = 1u << 3; +static const ScreenOrientationInternal eScreenOrientation_None = 0; +static const ScreenOrientationInternal eScreenOrientation_PortraitPrimary = 1u << 0; +static const ScreenOrientationInternal eScreenOrientation_PortraitSecondary = 1u << 1; +static const ScreenOrientationInternal eScreenOrientation_LandscapePrimary = 1u << 2; +static const ScreenOrientationInternal eScreenOrientation_LandscapeSecondary = 1u << 3; //eScreenOrientation_Default will use the natural orientation for the deivce, //it could be PortraitPrimary or LandscapePrimary depends on display resolution -static const ScreenOrientation eScreenOrientation_Default = 1u << 4; +static const ScreenOrientationInternal eScreenOrientation_Default = 1u << 4; } // namespace dom } // namespace mozilla diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index fec562ab24..8177404c29 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -3893,6 +3893,21 @@ nsDOMWindowUtils::HasRuleProcessorUsedByMultipleStyleSets(uint32_t aSheetType, aRetVal); } +NS_IMETHODIMP +nsDOMWindowUtils::SetNextPaintSyncId(int32_t aSyncId) +{ + MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome()); + if (nsIWidget* widget = GetWidget()) { + nsRefPtr lm = widget->GetLayerManager(); + if (lm && lm->GetBackendType() == LayersBackend::LAYERS_CLIENT) { + ClientLayerManager* clm = static_cast(lm.get()); + clm->SetNextPaintSyncId(aSyncId); + } + } + + return NS_OK; +} + NS_INTERFACE_MAP_BEGIN(nsTranslationNodeList) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_ENTRY(nsITranslationNodeList) diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index f6e32058fb..b28c6dde38 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -1775,14 +1775,15 @@ public: */ void SetDisplayDocument(nsIDocument* aDisplayDocument) { - NS_PRECONDITION(!GetShell() && - !GetContainer() && - !GetWindow(), - "Shouldn't set mDisplayDocument on documents that already " - "have a presentation or a docshell or a window"); - NS_PRECONDITION(aDisplayDocument != this, "Should be different document"); - NS_PRECONDITION(!aDisplayDocument->GetDisplayDocument(), - "Display documents should not nest"); + MOZ_ASSERT(!GetShell() && + !GetContainer() && + !GetWindow(), + "Shouldn't set mDisplayDocument on documents that already " + "have a presentation or a docshell or a window"); + MOZ_ASSERT(aDisplayDocument, "Must not be null"); + MOZ_ASSERT(aDisplayDocument != this, "Should be different document"); + MOZ_ASSERT(!aDisplayDocument->GetDisplayDocument(), + "Display documents should not nest"); mDisplayDocument = aDisplayDocument; mHasDisplayDocument = !!aDisplayDocument; } @@ -1803,7 +1804,7 @@ public: virtual ~ExternalResourceLoad() {} void AddObserver(nsIObserver* aObserver) { - NS_PRECONDITION(aObserver, "Must have observer"); + MOZ_ASSERT(aObserver, "Must have observer"); mObservers.AppendElement(aObserver); } @@ -2794,127 +2795,119 @@ protected: mozilla::dom::VisibilityState mVisibilityState; // True if BIDI is enabled. - bool mBidiEnabled; + bool mBidiEnabled : 1; // True if a MathML element has ever been owned by this document. - bool mMathMLEnabled; + bool mMathMLEnabled : 1; // True if this document is the initial document for a window. This should // basically be true only for documents that exist in newly-opened windows or // documents created to satisfy a GetDocument() on a window when there's no // document in it. - bool mIsInitialDocumentInWindow; + bool mIsInitialDocumentInWindow : 1; // True if we're loaded as data and therefor has any dangerous stuff, such // as scripts and plugins, disabled. - bool mLoadedAsData; + bool mLoadedAsData : 1; // This flag is only set in XMLDocument, for e.g. documents used in XBL. We // don't want animations to play in such documents, so we need to store the // flag here so that we can check it in nsDocument::GetAnimationController. - bool mLoadedAsInteractiveData; + bool mLoadedAsInteractiveData : 1; // If true, whoever is creating the document has gotten it to the // point where it's safe to start layout on it. - bool mMayStartLayout; + bool mMayStartLayout : 1; // True iff we've ever fired a DOMTitleChanged event for this document - bool mHaveFiredTitleChange; + bool mHaveFiredTitleChange : 1; // True iff IsShowing() should be returning true - bool mIsShowing; + bool mIsShowing : 1; // True iff the document "page" is not hidden (i.e. currently in the // bfcache) - bool mVisible; + bool mVisible : 1; // True if our content viewer has been removed from the docshell // (it may still be displayed, but in zombie state). Form control data // has been saved. - bool mRemovedFromDocShell; + bool mRemovedFromDocShell : 1; // True iff DNS prefetch is allowed for this document. Note that if the // document has no window, DNS prefetch won't be performed no matter what. - bool mAllowDNSPrefetch; + bool mAllowDNSPrefetch : 1; // True when this document is a static clone of a normal document - bool mIsStaticDocument; + bool mIsStaticDocument : 1; // True while this document is being cloned to a static document. - bool mCreatingStaticClone; + bool mCreatingStaticClone : 1; // True iff the document is being unlinked or deleted. - bool mInUnlinkOrDeletion; + bool mInUnlinkOrDeletion : 1; // True if document has ever had script handling object. - bool mHasHadScriptHandlingObject; + bool mHasHadScriptHandlingObject : 1; // True if we're an SVG document being used as an image. - bool mIsBeingUsedAsImage; + bool mIsBeingUsedAsImage : 1; // True is this document is synthetic : stand alone image, video, audio // file, etc. - bool mIsSyntheticDocument; + bool mIsSyntheticDocument : 1; // True if this document has links whose state needs updating - bool mHasLinksToUpdate; + bool mHasLinksToUpdate : 1; // True if a layout flush might not be a no-op - bool mNeedLayoutFlush; + bool mNeedLayoutFlush : 1; // True if a style flush might not be a no-op - bool mNeedStyleFlush; + bool mNeedStyleFlush : 1; // True if a DOMMutationObserver is perhaps attached to a node in the document. - bool mMayHaveDOMMutationObservers; + bool mMayHaveDOMMutationObservers : 1; // True if an nsIAnimationObserver is perhaps attached to a node in the document. - bool mMayHaveAnimationObservers; + bool mMayHaveAnimationObservers : 1; // True if a document has loaded Mixed Active Script (see nsMixedContentBlocker.cpp) - bool mHasMixedActiveContentLoaded; + bool mHasMixedActiveContentLoaded : 1; // True if a document has blocked Mixed Active Script (see nsMixedContentBlocker.cpp) - bool mHasMixedActiveContentBlocked; + bool mHasMixedActiveContentBlocked : 1; // True if a document has loaded Mixed Display/Passive Content (see nsMixedContentBlocker.cpp) - bool mHasMixedDisplayContentLoaded; + bool mHasMixedDisplayContentLoaded : 1; // True if a document has blocked Mixed Display/Passive Content (see nsMixedContentBlocker.cpp) - bool mHasMixedDisplayContentBlocked; + bool mHasMixedDisplayContentBlocked : 1; // True if a document has blocked Tracking Content - bool mHasTrackingContentBlocked; + bool mHasTrackingContentBlocked : 1; // True if a document has loaded Tracking Content - bool mHasTrackingContentLoaded; + bool mHasTrackingContentLoaded : 1; // True if DisallowBFCaching has been called on this document. - bool mBFCacheDisallowed; + bool mBFCacheDisallowed : 1; // If true, we have an input encoding. If this is false, then the // document was created entirely in memory - bool mHaveInputEncoding; + bool mHaveInputEncoding : 1; - bool mHasHadDefaultView; + bool mHasHadDefaultView : 1; // Whether style sheet change events will be dispatched for this document - bool mStyleSheetChangeEventsEnabled; + bool mStyleSheetChangeEventsEnabled : 1; // Whether the document was created by a srcdoc iframe. - bool mIsSrcdocDocument; + bool mIsSrcdocDocument : 1; // Records whether we've done a document.open. If this is true, it's possible // for nodes from this document to have outdated wrappers in their wrapper // caches. - bool mDidDocumentOpen; - -#ifdef DEBUG - /** - * This is true while FlushPendingLinkUpdates executes. Calls to - * [Un]RegisterPendingLinkUpdate will assert when this is true. - */ - bool mIsLinkUpdateRegistrationsForbidden; -#endif + bool mDidDocumentOpen : 1; // Whether this document has a display document and thus is considered to // be a resource document. Normally this is the same as !!mDisplayDocument, @@ -2923,13 +2916,13 @@ protected: bool mHasDisplayDocument : 1; // Is the current mFontFaceSet valid? - bool mFontFaceSetDirty; + bool mFontFaceSetDirty : 1; // Has GetUserFontSet() been called? - bool mGetUserFontSetCalled; + bool mGetUserFontSetCalled : 1; // Do we currently have an event posted to call FlushUserFontSet? - bool mPostedFlushUserFontSet; + bool mPostedFlushUserFontSet : 1; enum Type { eUnknown, // should never be used @@ -2940,17 +2933,25 @@ protected: eXUL }; - uint8_t mType; + Type mType; uint8_t mDefaultElementType; - enum { + enum Tri { eTriUnset = 0, eTriFalse, eTriTrue }; - uint8_t mAllowXULXBL; + Tri mAllowXULXBL; + +#ifdef DEBUG + /** + * This is true while FlushPendingLinkUpdates executes. Calls to + * [Un]RegisterPendingLinkUpdate will assert when this is true. + */ + bool mIsLinkUpdateRegistrationsForbidden; +#endif // The document's script global object, the object from which the // document can get its script context and scope. This is the @@ -3030,7 +3031,7 @@ protected: nsTArray mBlockedTrackingNodes; // Weak reference to mScriptGlobalObject QI:d to nsPIDOMWindow, - // updated on every set of mSecriptGlobalObject. + // updated on every set of mScriptGlobalObject. nsPIDOMWindow *mWindow; nsCOMPtr mCachedEncoder; diff --git a/dom/base/nsScreen.cpp b/dom/base/nsScreen.cpp index 3d7fb38b08..0cbba5c5be 100644 --- a/dom/base/nsScreen.cpp +++ b/dom/base/nsScreen.cpp @@ -40,7 +40,7 @@ nsScreen::Create(nsPIDOMWindow* aWindow) hal::RegisterScreenConfigurationObserver(screen); hal::ScreenConfiguration config; hal::GetCurrentScreenConfiguration(&config); - screen->mOrientation = config.orientation(); + screen->mOrientationInternal = config.orientation(); return screen.forget(); } @@ -165,16 +165,16 @@ nsScreen::GetAvailRect(nsRect& aRect) void nsScreen::Notify(const hal::ScreenConfiguration& aConfiguration) { - ScreenOrientation previousOrientation = mOrientation; - mOrientation = aConfiguration.orientation(); + ScreenOrientationInternal previousOrientation = mOrientationInternal; + mOrientationInternal = aConfiguration.orientation(); - NS_ASSERTION(mOrientation == eScreenOrientation_PortraitPrimary || - mOrientation == eScreenOrientation_PortraitSecondary || - mOrientation == eScreenOrientation_LandscapePrimary || - mOrientation == eScreenOrientation_LandscapeSecondary, + NS_ASSERTION(mOrientationInternal == eScreenOrientation_PortraitPrimary || + mOrientationInternal == eScreenOrientation_PortraitSecondary || + mOrientationInternal == eScreenOrientation_LandscapePrimary || + mOrientationInternal == eScreenOrientation_LandscapeSecondary, "Invalid orientation value passed to notify method!"); - if (mOrientation != previousOrientation) { + if (mOrientationInternal != previousOrientation) { DispatchTrustedEvent(NS_LITERAL_STRING("mozorientationchange")); } } @@ -185,7 +185,7 @@ nsScreen::GetMozOrientation(nsString& aOrientation) if (ShouldResistFingerprinting()) { aOrientation.AssignLiteral("landscape-primary"); } else { - switch (mOrientation) { + switch (mOrientationInternal) { case eScreenOrientation_PortraitPrimary: aOrientation.AssignLiteral("portrait-primary"); break; @@ -200,7 +200,7 @@ nsScreen::GetMozOrientation(nsString& aOrientation) break; case eScreenOrientation_None: default: - MOZ_CRASH("Unacceptable mOrientation value"); + MOZ_CRASH("Unacceptable mOrientationInternal value"); } } } @@ -259,7 +259,7 @@ bool nsScreen::MozLockOrientation(const Sequence& aOrientations, ErrorResult& aRv) { - ScreenOrientation orientation = eScreenOrientation_None; + ScreenOrientationInternal orientation = eScreenOrientation_None; for (uint32_t i = 0; i < aOrientations.Length(); ++i) { const nsString& item = aOrientations[i]; diff --git a/dom/base/nsScreen.h b/dom/base/nsScreen.h index d13dc6c0f3..9030bb69d8 100644 --- a/dom/base/nsScreen.h +++ b/dom/base/nsScreen.h @@ -133,7 +133,7 @@ protected: nsresult GetAvailRect(nsRect& aRect); nsresult GetWindowInnerRect(nsRect& aRect); - mozilla::dom::ScreenOrientation mOrientation; + mozilla::dom::ScreenOrientationInternal mOrientationInternal; private: class FullScreenEventListener final : public nsIDOMEventListener diff --git a/dom/canvas/compiledtest/moz.build b/dom/canvas/compiledtest/moz.build index 09b0b05087..4179cfddc4 100644 --- a/dom/canvas/compiledtest/moz.build +++ b/dom/canvas/compiledtest/moz.build @@ -11,6 +11,9 @@ GeckoCppUnitTests([ 'TestWebGLElementArrayCache', ]) +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + LOCAL_INCLUDES += [ '../', ] diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index aace282e18..4cc5e8fd9d 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -49,7 +49,7 @@ interface nsIJSRAIIHelper; interface nsIContentPermissionRequest; interface nsIObserver; -[scriptable, uuid(6af09215-d909-4d4a-866e-bdaed8fdcb96)] +[scriptable, uuid(6ddc9a79-18cd-4dbc-9975-68928e6c9857)] interface nsIDOMWindowUtils : nsISupports { /** @@ -1836,6 +1836,8 @@ interface nsIDOMWindowUtils : nsISupports { * running tests. */ void forceUseCounterFlush(in nsIDOMNode aNode); + + void setNextPaintSyncId(in long aSyncId); }; [scriptable, uuid(c694e359-7227-4392-a138-33c0cc1f15a6)] diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index fcdd22b6e5..f885adcd4f 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -52,7 +52,7 @@ using struct nsRect from "nsRect.h"; using class mozilla::WidgetSelectionEvent from "ipc/nsGUIEventIPC.h"; using class mozilla::WidgetTouchEvent from "ipc/nsGUIEventIPC.h"; using struct mozilla::dom::RemoteDOMEvent from "mozilla/dom/TabMessageUtils.h"; -using mozilla::dom::ScreenOrientation from "mozilla/dom/ScreenOrientation.h"; +using mozilla::dom::ScreenOrientationInternal from "mozilla/dom/ScreenOrientation.h"; using struct mozilla::layers::TextureFactoryIdentifier from "mozilla/layers/CompositorTypes.h"; using mozilla::CSSPoint from "Units.h"; using mozilla::CSSToScreenScale from "Units.h"; @@ -566,7 +566,8 @@ child: CacheFileDescriptor(nsString path, FileDescriptor fd); - UpdateDimensions(CSSRect rect, CSSSize size, ScreenOrientation orientation, + UpdateDimensions(CSSRect rect, CSSSize size, + ScreenOrientationInternal orientation, LayoutDeviceIntPoint chromeDisp) compressall; UpdateFrame(FrameMetrics frame); diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 8c4e8d774e..9ce5dc085c 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -1692,7 +1692,7 @@ TabChild::RecvShow(const ScreenIntSize& aSize, bool TabChild::RecvUpdateDimensions(const CSSRect& rect, const CSSSize& size, - const ScreenOrientation& orientation, + const ScreenOrientationInternal& orientation, const LayoutDeviceIntPoint& chromeDisp) { if (!mRemoteFrame) { diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h index 164630f82b..f9f1dd526e 100644 --- a/dom/ipc/TabChild.h +++ b/dom/ipc/TabChild.h @@ -302,7 +302,7 @@ public: const bool& aParentIsActive) override; virtual bool RecvUpdateDimensions(const CSSRect& rect, const CSSSize& size, - const ScreenOrientation& orientation, + const ScreenOrientationInternal& orientation, const LayoutDeviceIntPoint& chromeDisp) override; virtual bool RecvUpdateFrame(const layers::FrameMetrics& aFrameMetrics) override; virtual bool RecvRequestFlingSnap(const ViewID& aScrollId, @@ -418,7 +418,7 @@ public: void GetMaxTouchPoints(uint32_t* aTouchPoints); - ScreenOrientation GetOrientation() { return mOrientation; } + ScreenOrientationInternal GetOrientation() const { return mOrientation; } void SetBackgroundColor(const nscolor& aColor); @@ -622,7 +622,7 @@ private: bool mDidFakeShow; bool mNotified; bool mTriedBrowserInit; - ScreenOrientation mOrientation; + ScreenOrientationInternal mOrientation; bool mUpdateHitRegion; bool mIgnoreKeyPressEvent; diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index fe1e8127fe..480904bfa5 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -1038,7 +1038,7 @@ TabParent::UpdateDimensions(const nsIntRect& rect, const ScreenIntSize& size) } hal::ScreenConfiguration config; hal::GetCurrentScreenConfiguration(&config); - ScreenOrientation orientation = config.orientation(); + ScreenOrientationInternal orientation = config.orientation(); LayoutDeviceIntPoint chromeOffset = -GetChildProcessOffset(); nsCOMPtr widget = GetWidget(); diff --git a/dom/ipc/TabParent.h b/dom/ipc/TabParent.h index 23e8a4a696..19e6c99314 100644 --- a/dom/ipc/TabParent.h +++ b/dom/ipc/TabParent.h @@ -474,7 +474,7 @@ protected: nsIntRect mRect; ScreenIntSize mDimensions; - ScreenOrientation mOrientation; + ScreenOrientationInternal mOrientation; float mDPI; CSSToLayoutDeviceScale mDefaultScale; bool mUpdatedDimensions; diff --git a/dom/media/webrtc/MediaEngineGonkVideoSource.cpp b/dom/media/webrtc/MediaEngineGonkVideoSource.cpp index 12a103167e..534ceefe43 100644 --- a/dom/media/webrtc/MediaEngineGonkVideoSource.cpp +++ b/dom/media/webrtc/MediaEngineGonkVideoSource.cpp @@ -406,7 +406,7 @@ MediaEngineGonkVideoSource::DeallocImpl() { // The same algorithm from bug 840244 static int -GetRotateAmount(ScreenOrientation aScreen, int aCameraMountAngle, bool aBackCamera) { +GetRotateAmount(ScreenOrientationInternal aScreen, int aCameraMountAngle, bool aBackCamera) { int screenAngle = 0; switch (aScreen) { case eScreenOrientation_PortraitPrimary: diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp index 36c4d4c312..498bb6b525 100644 --- a/dom/promise/Promise.cpp +++ b/dom/promise/Promise.cpp @@ -47,33 +47,33 @@ Atomic gIDGenerator(0); using namespace workers; // This class processes the promise's callbacks with promise's result. -class PromiseCallbackTask final : public nsRunnable +class PromiseReactionJob final : public nsRunnable { public: - PromiseCallbackTask(Promise* aPromise, - PromiseCallback* aCallback, - const JS::Value& aValue) + PromiseReactionJob(Promise* aPromise, + PromiseCallback* aCallback, + const JS::Value& aValue) : mPromise(aPromise) , mCallback(aCallback) , mValue(CycleCollectedJSRuntime::Get()->Runtime(), aValue) { MOZ_ASSERT(aPromise); MOZ_ASSERT(aCallback); - MOZ_COUNT_CTOR(PromiseCallbackTask); + MOZ_COUNT_CTOR(PromiseReactionJob); } virtual - ~PromiseCallbackTask() + ~PromiseReactionJob() { - NS_ASSERT_OWNINGTHREAD(PromiseCallbackTask); - MOZ_COUNT_DTOR(PromiseCallbackTask); + NS_ASSERT_OWNINGTHREAD(PromiseReactionJob); + MOZ_COUNT_DTOR(PromiseReactionJob); } protected: NS_IMETHOD Run() override { - NS_ASSERT_OWNINGTHREAD(PromiseCallbackTask); + NS_ASSERT_OWNINGTHREAD(PromiseReactionJob); ThreadsafeAutoJSContext cx; JS::Rooted wrapper(cx, mPromise->GetWrapper()); MOZ_ASSERT(wrapper); // It was preserved! @@ -174,32 +174,32 @@ GetPromise(JSContext* aCx, JS::Handle aFunc) // Runnable to resolve thenables. // Equivalent to the specification's ResolvePromiseViaThenableTask. -class ThenableResolverTask final : public nsRunnable +class PromiseResolveThenableJob final : public nsRunnable { public: - ThenableResolverTask(Promise* aPromise, - JS::Handle aThenable, - PromiseInit* aThen) + PromiseResolveThenableJob(Promise* aPromise, + JS::Handle aThenable, + PromiseInit* aThen) : mPromise(aPromise) , mThenable(CycleCollectedJSRuntime::Get()->Runtime(), aThenable) , mThen(aThen) { MOZ_ASSERT(aPromise); - MOZ_COUNT_CTOR(ThenableResolverTask); + MOZ_COUNT_CTOR(PromiseResolveThenableJob); } virtual - ~ThenableResolverTask() + ~PromiseResolveThenableJob() { - NS_ASSERT_OWNINGTHREAD(ThenableResolverTask); - MOZ_COUNT_DTOR(ThenableResolverTask); + NS_ASSERT_OWNINGTHREAD(PromiseResolveThenableJob); + MOZ_COUNT_DTOR(PromiseResolveThenableJob); } protected: NS_IMETHOD Run() override { - NS_ASSERT_OWNINGTHREAD(ThenableResolverTask); + NS_ASSERT_OWNINGTHREAD(PromiseResolveThenableJob); ThreadsafeAutoJSContext cx; JS::Rooted wrapper(cx, mPromise->GetWrapper()); MOZ_ASSERT(wrapper); // It was preserved! @@ -275,16 +275,16 @@ private: NS_DECL_OWNINGTHREAD; }; -// Fast version of ThenableResolverTask for use in the cases when we know we're +// Fast version of PromiseResolveThenableJob for use in the cases when we know we're // calling the canonical Promise.prototype.then on an actual DOM Promise. In // that case we can just bypass the jumping into and out of JS and call // AppendCallbacks on that promise directly. -class FastThenableResolverTask final : public nsRunnable +class FastPromiseResolveThenableJob final : public nsRunnable { public: - FastThenableResolverTask(PromiseCallback* aResolveCallback, - PromiseCallback* aRejectCallback, - Promise* aNextPromise) + FastPromiseResolveThenableJob(PromiseCallback* aResolveCallback, + PromiseCallback* aRejectCallback, + Promise* aNextPromise) : mResolveCallback(aResolveCallback) , mRejectCallback(aRejectCallback) , mNextPromise(aNextPromise) @@ -292,21 +292,21 @@ public: MOZ_ASSERT(aResolveCallback); MOZ_ASSERT(aRejectCallback); MOZ_ASSERT(aNextPromise); - MOZ_COUNT_CTOR(FastThenableResolverTask); + MOZ_COUNT_CTOR(FastPromiseResolveThenableJob); } virtual - ~FastThenableResolverTask() + ~FastPromiseResolveThenableJob() { - NS_ASSERT_OWNINGTHREAD(FastThenableResolverTask); - MOZ_COUNT_DTOR(FastThenableResolverTask); + NS_ASSERT_OWNINGTHREAD(FastPromiseResolveThenableJob); + MOZ_COUNT_DTOR(FastPromiseResolveThenableJob); } protected: NS_IMETHOD Run() override { - NS_ASSERT_OWNINGTHREAD(FastThenableResolverTask); + NS_ASSERT_OWNINGTHREAD(FastPromiseResolveThenableJob); mNextPromise->AppendCallbacks(mResolveCallback, mRejectCallback); return NS_OK; } @@ -822,7 +822,7 @@ Promise::Catch(JSContext* aCx, AnyCallback* aRejectCallback, ErrorResult& aRv) /** * The CountdownHolder class encapsulates Promise.all countdown functions and * the countdown holder parts of the Promises spec. It maintains the result - * array and AllResolveHandlers use SetValue() to set the array indices. + * array and AllResolveElementFunctions use SetValue() to set the array indices. */ class CountdownHolder final : public nsISupports { @@ -910,17 +910,18 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CountdownHolder) NS_IMPL_CYCLE_COLLECTION_UNLINK_END /** - * An AllResolveHandler is the per-promise part of the Promise.all() algorithm. + * An AllResolveElementFunction is the per-promise + * part of the Promise.all() algorithm. * Every Promise in the handler is handed an instance of this as a resolution * handler and it sets the relevant index in the CountdownHolder. */ -class AllResolveHandler final : public PromiseNativeHandler +class AllResolveElementFunction final : public PromiseNativeHandler { public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS(AllResolveHandler) + NS_DECL_CYCLE_COLLECTION_CLASS(AllResolveElementFunction) - AllResolveHandler(CountdownHolder* aHolder, uint32_t aIndex) + AllResolveElementFunction(CountdownHolder* aHolder, uint32_t aIndex) : mCountdownHolder(aHolder), mIndex(aIndex) { MOZ_ASSERT(aHolder); @@ -936,11 +937,11 @@ public: RejectedCallback(JSContext* aCx, JS::Handle aValue) override { // Should never be attached to Promise as a reject handler. - MOZ_ASSERT(false, "AllResolveHandler should never be attached to a Promise's reject handler!"); + MOZ_CRASH("AllResolveElementFunction should never be attached to a Promise's reject handler!"); } private: - ~AllResolveHandler() + ~AllResolveElementFunction() { } @@ -948,14 +949,14 @@ private: uint32_t mIndex; }; -NS_IMPL_CYCLE_COLLECTING_ADDREF(AllResolveHandler) -NS_IMPL_CYCLE_COLLECTING_RELEASE(AllResolveHandler) +NS_IMPL_CYCLE_COLLECTING_ADDREF(AllResolveElementFunction) +NS_IMPL_CYCLE_COLLECTING_RELEASE(AllResolveElementFunction) -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AllResolveHandler) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AllResolveElementFunction) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -NS_IMPL_CYCLE_COLLECTION(AllResolveHandler, mCountdownHolder) +NS_IMPL_CYCLE_COLLECTION(AllResolveElementFunction, mCountdownHolder) /* static */ already_AddRefed Promise::All(const GlobalObject& aGlobal, @@ -1019,7 +1020,7 @@ Promise::All(const GlobalObject& aGlobal, for (uint32_t i = 0; i < aPromiseList.Length(); ++i) { nsRefPtr resolveHandler = - new AllResolveHandler(holder, i); + new AllResolveElementFunction(holder, i); nsRefPtr resolveCb = new NativePromiseCallback(resolveHandler, Resolved); @@ -1132,7 +1133,7 @@ Promise::AppendCallbacks(PromiseCallback* aResolveCallback, // callbacks with promise's result. If promise's state is rejected, queue a // task to process our reject callbacks with promise's result. if (mState != Pending) { - EnqueueCallbackTasks(); + TriggerPromiseReactions(); } } @@ -1299,8 +1300,8 @@ Promise::ResolveInternal(JSContext* aCx, Promise* nextPromise; if (PromiseBinding::IsThenMethod(thenObj) && NS_SUCCEEDED(UNWRAP_OBJECT(Promise, valueObj, nextPromise))) { - // If we were taking the codepath that involves ThenableResolverTask and - // PromiseInit below, then eventually, in ThenableResolverTask::Run, we + // If we were taking the codepath that involves PromiseResolveThenableJob and + // PromiseInit below, then eventually, in PromiseResolveThenableJob::Run, we // would create some JSFunctions in the compartment of // this->GetWrapper() and pass them to the PromiseInit. So by the time // we'd see the resolution value it would be wrapped into the @@ -1310,16 +1311,16 @@ Promise::ResolveInternal(JSContext* aCx, JS::Rooted glob(aCx, GlobalJSObject()); nsRefPtr resolveCb = new ResolvePromiseCallback(this, glob); nsRefPtr rejectCb = new RejectPromiseCallback(this, glob); - nsRefPtr task = - new FastThenableResolverTask(resolveCb, rejectCb, nextPromise); + nsRefPtr task = + new FastPromiseResolveThenableJob(resolveCb, rejectCb, nextPromise); DispatchToMicroTask(task); return; } nsRefPtr thenCallback = new PromiseInit(nullptr, thenObj, mozilla::dom::GetIncumbentGlobal()); - nsRefPtr task = - new ThenableResolverTask(this, valueObj, thenCallback); + nsRefPtr task = + new PromiseResolveThenableJob(this, valueObj, thenCallback); DispatchToMicroTask(task); return; } @@ -1387,7 +1388,7 @@ Promise::Settle(JS::Handle aValue, PromiseState aState) } #endif // defined(DOM_PROMISE_DEPRECATED_REPORTING) - EnqueueCallbackTasks(); + TriggerPromiseReactions(); } void @@ -1405,7 +1406,7 @@ Promise::MaybeSettle(JS::Handle aValue, } void -Promise::EnqueueCallbackTasks() +Promise::TriggerPromiseReactions() { nsTArray> callbacks; callbacks.SwapElements(mState == Resolved ? mResolveCallbacks @@ -1414,8 +1415,8 @@ Promise::EnqueueCallbackTasks() mRejectCallbacks.Clear(); for (uint32_t i = 0; i < callbacks.Length(); ++i) { - nsRefPtr task = - new PromiseCallbackTask(this, callbacks[i], mResult); + nsRefPtr task = + new PromiseReactionJob(this, callbacks[i], mResult); DispatchToMicroTask(task); } } @@ -1480,7 +1481,7 @@ Promise::GetDependentPromises(nsTArray>& aPromises) } // A WorkerRunnable to resolve/reject the Promise on the worker thread. - +// Calling thread MUST hold PromiseWorkerProxy's mutex before creating this. class PromiseWorkerProxyRunnable : public workers::WorkerRunnable { public: @@ -1588,12 +1589,24 @@ PromiseWorkerProxy::GetWorkerPrivate() const // the assertion when we should not. MOZ_ASSERT(!mCleanedUp); +#ifdef DEBUG + if (NS_IsMainThread()) { + mCleanUpLock.AssertCurrentThreadOwns(); + } +#endif + return mWorkerPrivate; } Promise* PromiseWorkerProxy::GetWorkerPromise() const { + +#ifdef DEBUG + WorkerPrivate* worker = GetCurrentThreadWorkerPrivate(); + MOZ_ASSERT(worker); + worker->AssertIsOnWorkerThread(); +#endif return mWorkerPromise; } diff --git a/dom/promise/Promise.h b/dom/promise/Promise.h index ff6065b3ef..437183c19d 100644 --- a/dom/promise/Promise.h +++ b/dom/promise/Promise.h @@ -50,8 +50,9 @@ class Promise; #if defined(DOM_PROMISE_DEPRECATED_REPORTING) class PromiseReportRejectFeature : public workers::WorkerFeature { - // The Promise that owns this feature. - Promise* mPromise; + // PromiseReportRejectFeature is held by an nsAutoPtr on the Promise which + // means that this object will be destroyed before the Promise is destroyed. + Promise* MOZ_NON_OWNING_REF mPromise; public: explicit PromiseReportRejectFeature(Promise* aPromise) @@ -74,7 +75,7 @@ class Promise : public nsISupports, public SupportsWeakPtr { friend class NativePromiseCallback; - friend class PromiseCallbackTask; + friend class PromiseReactionJob; friend class PromiseResolverTask; friend class PromiseTask; #if defined(DOM_PROMISE_DEPRECATED_REPORTING) @@ -84,8 +85,8 @@ class Promise : public nsISupports, friend class PromiseWorkerProxyRunnable; friend class RejectPromiseCallback; friend class ResolvePromiseCallback; - friend class ThenableResolverTask; - friend class FastThenableResolverTask; + friend class PromiseResolveThenableJob; + friend class FastPromiseResolveThenableJob; friend class WrapperPromiseCallback; public: @@ -273,8 +274,8 @@ private: // This method enqueues promise's resolve/reject callbacks with promise's // result. It's executed when the resolver.resolve() or resolver.reject() is // called or when the promise already has a result and new callbacks are - // appended by then(), catch() or done(). - void EnqueueCallbackTasks(); + // appended by then() or catch(). + void TriggerPromiseReactions(); void Settle(JS::Handle aValue, Promise::PromiseState aState); void MaybeSettle(JS::Handle aValue, Promise::PromiseState aState); diff --git a/dom/push/PushManager.cpp b/dom/push/PushManager.cpp index df767b0764..1e4e22fbf5 100644 --- a/dom/push/PushManager.cpp +++ b/dom/push/PushManager.cpp @@ -215,38 +215,29 @@ WorkerPushSubscription::Constructor(GlobalObject& aGlobal, const nsAString& aEnd return sub.forget(); } -class MOZ_STACK_CLASS AutoReleasePromiseWorkerProxy final +namespace { +// The caller MUST take ownership of the proxy's lock before it calls this. +void +ReleasePromiseWorkerProxy(already_AddRefed aProxy) { -public: - explicit AutoReleasePromiseWorkerProxy(PromiseWorkerProxy* aProxy) - : mProxy(aProxy) - { - AssertIsOnMainThread(); - MOZ_ASSERT(aProxy); - aProxy->GetCleanUpLock().AssertCurrentThreadOwns(); - if (aProxy->IsClean()) { - mProxy = nullptr; - } + AssertIsOnMainThread(); + nsRefPtr proxy = aProxy; + MOZ_ASSERT(proxy); + proxy->GetCleanUpLock().AssertCurrentThreadOwns(); + if (proxy->IsClean()) { + return; } - ~AutoReleasePromiseWorkerProxy() - { - if (mProxy) { - AutoJSAPI jsapi; - jsapi.Init(); + AutoJSAPI jsapi; + jsapi.Init(); - nsRefPtr cr = - new PromiseWorkerProxyControlRunnable(mProxy->GetWorkerPrivate(), - mProxy); + nsRefPtr cr = + new PromiseWorkerProxyControlRunnable(proxy->GetWorkerPrivate(), + proxy); - DebugOnly ok = cr->Dispatch(jsapi.cx()); - MOZ_ASSERT(ok); - mProxy = nullptr; - } - } -private: - nsRefPtr mProxy; -}; + MOZ_ALWAYS_TRUE(cr->Dispatch(jsapi.cx())); +} +} // anonymous namespace class UnsubscribeResultRunnable final : public WorkerRunnable { @@ -281,12 +272,7 @@ public: } private: ~UnsubscribeResultRunnable() - { - if (mProxy) { - AutoReleasePromiseWorkerProxy autoRelease(mProxy); - mProxy = nullptr; - } - } + {} nsRefPtr mProxy; nsresult mStatus; @@ -322,18 +308,27 @@ public: nsRefPtr r = new UnsubscribeResultRunnable(mProxy, aStatus, aSuccess); - mProxy = nullptr; + if (!r->Dispatch(jsapi.cx())) { + ReleasePromiseWorkerProxy(mProxy.forget()); + } - r->Dispatch(jsapi.cx()); + mProxy = nullptr; return NS_OK; } private: ~WorkerUnsubscribeResultCallback() { + AssertIsOnMainThread(); if (mProxy) { - AutoReleasePromiseWorkerProxy autoRelease(mProxy); - mProxy = nullptr; + MutexAutoLock lock(mProxy->GetCleanUpLock()); + if (!mProxy->IsClean()) { + AutoJSAPI jsapi; + jsapi.Init(); + nsRefPtr cr = + new PromiseWorkerProxyControlRunnable(mProxy->GetWorkerPrivate(), mProxy); + cr->Dispatch(jsapi.cx()); + } } } @@ -363,36 +358,27 @@ public: return NS_OK; } + nsRefPtr callback = + new WorkerUnsubscribeResultCallback(mProxy); + nsCOMPtr client = do_CreateInstance("@mozilla.org/push/PushClient;1"); if (!client) { - AutoJSAPI jsapi; - jsapi.Init(); - - nsRefPtr r = - new UnsubscribeResultRunnable(mProxy, NS_ERROR_FAILURE, false); - mProxy = nullptr; - - r->Dispatch(jsapi.cx()); - return NS_OK; + callback->OnUnsubscribe(NS_ERROR_FAILURE, false); } nsCOMPtr principal = mProxy->GetWorkerPrivate()->GetPrincipal(); - nsRefPtr callback = - new WorkerUnsubscribeResultCallback(mProxy); - mProxy = nullptr; - client->Unsubscribe(mScope, principal, callback); + if (NS_WARN_IF(NS_FAILED(client->Unsubscribe(mScope, principal, callback)))) { + callback->OnUnsubscribe(NS_ERROR_FAILURE, false); + return NS_ERROR_FAILURE; + } return NS_OK; } private: ~UnsubscribeRunnable() - { - if (mProxy) { - AutoReleasePromiseWorkerProxy autoRelease(mProxy); - mProxy = nullptr; - } - } + {} + nsRefPtr mProxy; nsString mScope; }; @@ -418,7 +404,7 @@ WorkerPushSubscription::Unsubscribe(ErrorResult &aRv) nsRefPtr r = new UnsubscribeRunnable(proxy, mScope); - NS_DispatchToMainThread(r); + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(r))); return p.forget(); } @@ -464,9 +450,13 @@ public: nsRefPtr proxy = mProxy.forget(); nsRefPtr promise = proxy->GetWorkerPromise(); if (NS_SUCCEEDED(mStatus)) { - nsRefPtr sub = - new WorkerPushSubscription(mEndpoint, mScope); - promise->MaybeResolve(sub); + if (mEndpoint.IsEmpty()) { + promise->MaybeResolve(JS::NullHandleValue); + } else { + nsRefPtr sub = + new WorkerPushSubscription(mEndpoint, mScope); + promise->MaybeResolve(sub); + } } else { promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR); } @@ -476,12 +466,7 @@ public: } private: ~GetSubscriptionResultRunnable() - { - if (mProxy) { - AutoReleasePromiseWorkerProxy autoRelease(mProxy); - mProxy = nullptr; - } - } + {} nsRefPtr mProxy; nsresult mStatus; @@ -504,6 +489,7 @@ public: OnPushEndpoint(nsresult aStatus, const nsAString& aEndpoint) override { AssertIsOnMainThread(); + if (!mProxy) { return NS_OK; } @@ -518,18 +504,27 @@ public: nsRefPtr r = new GetSubscriptionResultRunnable(mProxy, aStatus, aEndpoint, mScope); - mProxy = nullptr; + if (!r->Dispatch(jsapi.cx())) { + ReleasePromiseWorkerProxy(mProxy.forget()); + } - r->Dispatch(jsapi.cx()); + mProxy = nullptr; return NS_OK; } protected: ~GetSubscriptionCallback() { + AssertIsOnMainThread(); if (mProxy) { - AutoReleasePromiseWorkerProxy autoRelease(mProxy); - mProxy = nullptr; + MutexAutoLock lock(mProxy->GetCleanUpLock()); + if (!mProxy->IsClean()) { + AutoJSAPI jsapi; + jsapi.Init(); + nsRefPtr cr = + new PromiseWorkerProxyControlRunnable(mProxy->GetWorkerPrivate(), mProxy); + cr->Dispatch(jsapi.cx()); + } } } @@ -559,14 +554,12 @@ public: return NS_OK; } + nsRefPtr callback = new GetSubscriptionCallback(mProxy, mScope); + nsCOMPtr permManager = mozilla::services::GetPermissionManager(); - - AutoJSAPI jsapi; - jsapi.Init(); - if (!permManager) { - Fail(jsapi.cx()); + callback->OnPushEndpoint(NS_ERROR_FAILURE, EmptyString()); return NS_OK; } @@ -577,47 +570,38 @@ public: &permission); if (NS_WARN_IF(NS_FAILED(rv)) || permission != nsIPermissionManager::ALLOW_ACTION) { - Fail(jsapi.cx()); + callback->OnPushEndpoint(NS_ERROR_FAILURE, EmptyString()); return NS_OK; } nsCOMPtr client = do_CreateInstance("@mozilla.org/push/PushClient;1"); if (!client) { - Fail(jsapi.cx()); + callback->OnPushEndpoint(NS_ERROR_FAILURE, EmptyString()); return NS_OK; } nsCOMPtr principal = mProxy->GetWorkerPrivate()->GetPrincipal(); - nsRefPtr callback = new GetSubscriptionCallback(mProxy, mScope); mProxy = nullptr; if (mAction == WorkerPushManager::SubscribeAction) { - return client->Subscribe(mScope, principal, callback); + rv = client->Subscribe(mScope, principal, callback); } else { MOZ_ASSERT(mAction == WorkerPushManager::GetSubscriptionAction); - return client->GetSubscription(mScope, principal, callback); + rv = client->GetSubscription(mScope, principal, callback); } + + if (NS_WARN_IF(NS_FAILED(rv))) { + callback->OnPushEndpoint(NS_ERROR_FAILURE, EmptyString()); + return rv; + } + + return NS_OK; } private: - void - Fail(JSContext* aCx) - { - nsRefPtr r = - new GetSubscriptionResultRunnable(mProxy, NS_ERROR_FAILURE, EmptyString(), mScope); - mProxy = nullptr; - - r->Dispatch(aCx); - } - ~GetSubscriptionRunnable() - { - if (mProxy) { - AutoReleasePromiseWorkerProxy autoRelease(mProxy); - mProxy = nullptr; - } - } + {} nsRefPtr mProxy; nsString mScope; @@ -645,7 +629,7 @@ WorkerPushManager::PerformSubscriptionAction(SubscriptionAction aAction, ErrorRe nsRefPtr r = new GetSubscriptionRunnable(proxy, mScope, aAction); - NS_DispatchToMainThread(r); + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(r))); return p.forget(); } @@ -698,12 +682,7 @@ public: private: ~PermissionResultRunnable() - { - if (mProxy) { - AutoReleasePromiseWorkerProxy autoRelease(mProxy); - mProxy = nullptr; - } - } + {} nsRefPtr mProxy; nsresult mStatus; @@ -729,55 +708,46 @@ public: nsCOMPtr permManager = mozilla::services::GetPermissionManager(); + nsresult rv = NS_ERROR_FAILURE; PushPermissionState state = PushPermissionState::Denied; + if (permManager) { + uint32_t permission = nsIPermissionManager::DENY_ACTION; + rv = permManager->TestExactPermissionFromPrincipal( + mProxy->GetWorkerPrivate()->GetPrincipal(), + "push", + &permission); + + if (NS_SUCCEEDED(rv)) { + switch (permission) { + case nsIPermissionManager::ALLOW_ACTION: + state = PushPermissionState::Granted; + break; + case nsIPermissionManager::DENY_ACTION: + state = PushPermissionState::Denied; + break; + case nsIPermissionManager::PROMPT_ACTION: + state = PushPermissionState::Prompt; + break; + default: + MOZ_CRASH("Unexpected case!"); + } + } + } + AutoJSAPI jsapi; jsapi.Init(); - - if (!permManager) { - nsRefPtr r = - new PermissionResultRunnable(mProxy, NS_ERROR_FAILURE, state); - mProxy = nullptr; - - r->Dispatch(jsapi.cx()); - return NS_OK; - } - - uint32_t permission = nsIPermissionManager::DENY_ACTION; - nsresult rv = permManager->TestExactPermissionFromPrincipal( - mProxy->GetWorkerPrivate()->GetPrincipal(), - "push", - &permission); - - switch (permission) { - case nsIPermissionManager::ALLOW_ACTION: - state = PushPermissionState::Granted; - break; - case nsIPermissionManager::DENY_ACTION: - state = PushPermissionState::Denied; - break; - case nsIPermissionManager::PROMPT_ACTION: - state = PushPermissionState::Prompt; - break; - default: - MOZ_CRASH("Unexpected case!"); - } - nsRefPtr r = new PermissionResultRunnable(mProxy, rv, state); - mProxy = nullptr; - r->Dispatch(jsapi.cx()); + if (!r->Dispatch(jsapi.cx())) { + ReleasePromiseWorkerProxy(mProxy.forget()); + } return NS_OK; } private: ~PermissionStateRunnable() - { - if (mProxy) { - AutoReleasePromiseWorkerProxy autoRelease(mProxy); - mProxy = nullptr; - } - } + {} nsRefPtr mProxy; }; diff --git a/dom/push/moz.build b/dom/push/moz.build index 17471715aa..9987f3a5de 100644 --- a/dom/push/moz.build +++ b/dom/push/moz.build @@ -37,6 +37,9 @@ UNIFIED_SOURCES += [ 'PushManager.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + LOCAL_INCLUDES += [ '../workers', ] diff --git a/dom/webidl/Promise.webidl b/dom/webidl/Promise.webidl index a98bca780c..69a768e8cb 100644 --- a/dom/webidl/Promise.webidl +++ b/dom/webidl/Promise.webidl @@ -20,8 +20,6 @@ callback AnyCallback = any (any value); Exposed=(Window,Worker,System)] // Need to escape "Promise" so it's treated as an identifier. interface _Promise { - // TODO bug 875289 - static Promise fulfill(any value); - // Disable the static methods when the interface object is supposed to be // disabled, just in case some code decides to walk over to .constructor from // the proto of a promise object or someone screws up and manages to create a diff --git a/dom/webidl/ServiceWorkerContainer.webidl b/dom/webidl/ServiceWorkerContainer.webidl index 151ece8f2d..080896f02a 100644 --- a/dom/webidl/ServiceWorkerContainer.webidl +++ b/dom/webidl/ServiceWorkerContainer.webidl @@ -37,14 +37,8 @@ interface ServiceWorkerContainer : EventTarget { // Testing only. partial interface ServiceWorkerContainer { - [Throws,Pref="dom.serviceWorkers.testing.enabled"] - Promise clearAllServiceWorkerData(); - [Throws,Pref="dom.serviceWorkers.testing.enabled"] DOMString getScopeForUrl(DOMString url); - - [Throws,Pref="dom.serviceWorkers.testing.enabled"] - DOMString getControllingWorkerScriptURLForPath(DOMString path); }; dictionary RegistrationOptions { diff --git a/dom/workers/ServiceWorkerContainer.cpp b/dom/workers/ServiceWorkerContainer.cpp index 136f4fb1c6..01b449e2b2 100644 --- a/dom/workers/ServiceWorkerContainer.cpp +++ b/dom/workers/ServiceWorkerContainer.cpp @@ -317,14 +317,6 @@ ServiceWorkerContainer::GetReady(ErrorResult& aRv) return mReadyPromise; } -// Testing only. -already_AddRefed -ServiceWorkerContainer::ClearAllServiceWorkerData(ErrorResult& aRv) -{ - aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - return nullptr; -} - // Testing only. void ServiceWorkerContainer::GetScopeForUrl(const nsAString& aUrl, @@ -341,14 +333,5 @@ ServiceWorkerContainer::GetScopeForUrl(const nsAString& aUrl, aUrl, aScope); } -// Testing only. -void -ServiceWorkerContainer::GetControllingWorkerScriptURLForPath( - const nsAString& aPath, - nsString& aScriptURL, - ErrorResult& aRv) -{ - aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); -} } // namespace dom } // namespace mozilla diff --git a/dom/workers/ServiceWorkerContainer.h b/dom/workers/ServiceWorkerContainer.h index a29218faa1..0f7879c47a 100644 --- a/dom/workers/ServiceWorkerContainer.h +++ b/dom/workers/ServiceWorkerContainer.h @@ -58,20 +58,10 @@ public: Promise* GetReady(ErrorResult& aRv); - // Testing only. - already_AddRefed - ClearAllServiceWorkerData(ErrorResult& aRv); - // Testing only. void GetScopeForUrl(const nsAString& aUrl, nsString& aScope, ErrorResult& aRv); - // Testing only. - void - GetControllingWorkerScriptURLForPath(const nsAString& aPath, - nsString& aScriptURL, - ErrorResult& aRv); - // DOMEventTargetHelper void DisconnectFromOwner() override; diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index bda90e989a..a724f45cef 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -4589,9 +4589,9 @@ HasRootDomain(nsIURI* aURI, const nsACString& aDomain) return prevChar == '.'; } -struct UnregisterIfMatchesHostOrPrincipalData +struct UnregisterIfMatchesUserData final { - UnregisterIfMatchesHostOrPrincipalData( + UnregisterIfMatchesUserData( ServiceWorkerManager::RegistrationDataPerPrincipal* aRegistrationData, void* aUserData) : mRegistrationData(aRegistrationData) @@ -4608,8 +4608,8 @@ UnregisterIfMatchesHost(const nsACString& aScope, ServiceWorkerRegistrationInfo* aReg, void* aPtr) { - UnregisterIfMatchesHostOrPrincipalData* data = - static_cast(aPtr); + UnregisterIfMatchesUserData* data = + static_cast(aPtr); // We avoid setting toRemove = aReg by default since there is a possibility // of failure when data->mUserData is passed, in which case we don't want to @@ -4641,25 +4641,76 @@ UnregisterIfMatchesHostPerPrincipal(const nsACString& aKey, ServiceWorkerManager::RegistrationDataPerPrincipal* aData, void* aUserData) { - UnregisterIfMatchesHostOrPrincipalData data(aData, aUserData); + UnregisterIfMatchesUserData data(aData, aUserData); aData->mInfos.EnumerateRead(UnregisterIfMatchesHost, &data); return PL_DHASH_NEXT; } PLDHashOperator -UnregisterIfMatchesPrincipal(const nsACString& aScope, - ServiceWorkerRegistrationInfo* aReg, - void* aPtr) +UnregisterIfMatchesClearPrivateDataParams(const nsACString& aScope, + ServiceWorkerRegistrationInfo* aReg, + void* aPtr) { - UnregisterIfMatchesHostOrPrincipalData* data = - static_cast(aPtr); + UnregisterIfMatchesUserData* data = + static_cast(aPtr); if (data->mUserData) { - nsIPrincipal *principal = static_cast(data->mUserData); - MOZ_ASSERT(principal); + mozIApplicationClearPrivateDataParams *params = + static_cast(data->mUserData); + MOZ_ASSERT(params); MOZ_ASSERT(aReg->mPrincipal); - bool equals; - aReg->mPrincipal->Equals(principal, &equals); + + uint32_t appId; + nsresult rv = params->GetAppId(&appId); + if (NS_WARN_IF(NS_FAILED(rv))) { + return PL_DHASH_NEXT; + } + + bool browserOnly; + rv = params->GetBrowserOnly(&browserOnly); + if (NS_WARN_IF(NS_FAILED(rv))) { + return PL_DHASH_NEXT; + } + + bool equals = false; + + if (browserOnly) { + // When we do a system wide "clear cookies and stored data" on B2G we get + // the "webapps-clear-data" notification with the System app appID and + // the browserOnly flag set to true. + // Web sites registering a service worker on B2G have a principal with the + // following information: web site origin + System app appId + inBrowser=1 + // So we need to check if the service worker registration info contains + // the System app appID and the enabled inBrowser flag and in that case + // remove it from the registry. + equals = (appId == aReg->mPrincipal->GetAppId()) && + aReg->mPrincipal->GetIsInBrowserElement(); + } else { + // If we get the "webapps-clear-data" notification because of an app + // uninstallation, we need to check the full principal to get the match + // in the service workers registry. If we find a match, we unregister the + // worker. + nsCOMPtr appsService = + do_GetService(APPS_SERVICE_CONTRACTID); + if (NS_WARN_IF(!appsService)) { + return PL_DHASH_NEXT; + } + + nsCOMPtr app; + appsService->GetAppByLocalId(appId, getter_AddRefs(app)); + if (NS_WARN_IF(!app)) { + return PL_DHASH_NEXT; + } + + nsCOMPtr principal; + app->GetPrincipal(getter_AddRefs(principal)); + if (NS_WARN_IF(!principal)) { + return PL_DHASH_NEXT; + } + + aReg->mPrincipal->Equals(principal, &equals); + } + if (equals) { nsRefPtr swm = ServiceWorkerManager::GetInstance(); swm->ForceUnregister(data->mRegistrationData, aReg); @@ -4670,15 +4721,16 @@ UnregisterIfMatchesPrincipal(const nsACString& aScope, } PLDHashOperator -UnregisterIfMatchesPrincipal(const nsACString& aKey, +UnregisterIfMatchesClearPrivateDataParams(const nsACString& aKey, ServiceWorkerManager::RegistrationDataPerPrincipal* aData, void* aUserData) { - UnregisterIfMatchesHostOrPrincipalData data(aData, aUserData); + UnregisterIfMatchesUserData data(aData, aUserData); // We can use EnumerateRead because ForceUnregister (and Unregister) are async. // Otherwise doing some R/W operations on an hashtable during an EnumerateRead // will crash. - aData->mInfos.EnumerateRead(UnregisterIfMatchesPrincipal, &data); + aData->mInfos.EnumerateRead(UnregisterIfMatchesClearPrivateDataParams, + &data); return PL_DHASH_NEXT; } @@ -4895,14 +4947,15 @@ UpdateEachRegistration(const nsACString& aKey, } void -ServiceWorkerManager::RemoveAllRegistrations(nsIPrincipal* aPrincipal) +ServiceWorkerManager::RemoveAllRegistrations( + mozIApplicationClearPrivateDataParams* aParams) { AssertIsOnMainThread(); - MOZ_ASSERT(aPrincipal); + MOZ_ASSERT(aParams); - mRegistrationInfos.EnumerateRead(UnregisterIfMatchesPrincipal, - aPrincipal); + mRegistrationInfos.EnumerateRead(UnregisterIfMatchesClearPrivateDataParams, + aParams); } static PLDHashOperator @@ -4950,29 +5003,7 @@ ServiceWorkerManager::Observe(nsISupports* aSubject, return NS_OK; } - uint32_t appId; - nsresult rv = params->GetAppId(&appId); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr appsService = - do_GetService(APPS_SERVICE_CONTRACTID); - if (NS_WARN_IF(!appsService)) { - return NS_OK; - } - - nsCOMPtr app; - appsService->GetAppByLocalId(appId, getter_AddRefs(app)); - if (NS_WARN_IF(!app)) { - return NS_OK; - } - - nsCOMPtr principal; - app->GetPrincipal(getter_AddRefs(principal)); - if (NS_WARN_IF(!principal)) { - return NS_OK; - } - - RemoveAllRegistrations(principal); + RemoveAllRegistrations(params); return NS_OK; } diff --git a/dom/workers/ServiceWorkerManager.h b/dom/workers/ServiceWorkerManager.h index 87097b64c6..08bb802feb 100644 --- a/dom/workers/ServiceWorkerManager.h +++ b/dom/workers/ServiceWorkerManager.h @@ -31,6 +31,8 @@ #include "nsTArrayForwardDeclare.h" #include "nsTObserverArray.h" +class mozIApplicationClearPrivateDataParams; + namespace mozilla { class OriginAttributes; @@ -576,9 +578,10 @@ private: void RemoveRegistrationInternal(ServiceWorkerRegistrationInfo* aRegistration); - // Removes all service worker registrations for a given principal. + // Removes all service worker registrations that matches the given + // mozIApplicationClearPrivateDataParams. void - RemoveAllRegistrations(nsIPrincipal* aPrincipal); + RemoveAllRegistrations(mozIApplicationClearPrivateDataParams* aParams); nsRefPtr mActor; diff --git a/dom/workers/ServiceWorkerWindowClient.cpp b/dom/workers/ServiceWorkerWindowClient.cpp index 525eac8c3a..8e0f531bff 100644 --- a/dom/workers/ServiceWorkerWindowClient.cpp +++ b/dom/workers/ServiceWorkerWindowClient.cpp @@ -7,6 +7,7 @@ #include "ServiceWorkerWindowClient.h" +#include "mozilla/Mutex.h" #include "mozilla/dom/ClientBinding.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/PromiseWorkerProxy.h" @@ -103,6 +104,12 @@ private: void DispatchResult(UniquePtr&& aClientInfo) { + AssertIsOnMainThread(); + MutexAutoLock lock(mPromiseProxy->GetCleanUpLock()); + if (mPromiseProxy->IsClean()) { + return; + } + WorkerPrivate* workerPrivate = mPromiseProxy->GetWorkerPrivate(); MOZ_ASSERT(workerPrivate); diff --git a/dom/xml/moz.build b/dom/xml/moz.build index dcc2ad8cab..68f196d3b7 100644 --- a/dom/xml/moz.build +++ b/dom/xml/moz.build @@ -31,6 +31,9 @@ UNIFIED_SOURCES += [ 'XMLStylesheetProcessingInstruction.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + FINAL_LIBRARY = 'xul' LOCAL_INCLUDES += [ diff --git a/dom/xslt/xml/moz.build b/dom/xslt/xml/moz.build index a4cf57a3c7..7defef0011 100644 --- a/dom/xslt/xml/moz.build +++ b/dom/xslt/xml/moz.build @@ -9,6 +9,9 @@ UNIFIED_SOURCES += [ 'txXMLUtils.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + LOCAL_INCLUDES += [ '../base', '../xpath', diff --git a/gfx/layers/client/ClientLayerManager.cpp b/gfx/layers/client/ClientLayerManager.cpp index 5626de0d9e..0e3c9f8e16 100644 --- a/gfx/layers/client/ClientLayerManager.cpp +++ b/gfx/layers/client/ClientLayerManager.cpp @@ -194,7 +194,7 @@ ClientLayerManager::BeginTransactionWithTarget(gfxContext* aTarget) // If the last transaction was incomplete (a failed DoEmptyTransaction), // don't signal a new transaction to ShadowLayerForwarder. Carry on adding // to the previous transaction. - dom::ScreenOrientation orientation; + dom::ScreenOrientationInternal orientation; if (dom::TabChild* window = mWidget->GetOwningTabChild()) { orientation = window->GetOrientation(); } else { @@ -802,6 +802,12 @@ ClientLayerManager::AsyncPanZoomEnabled() const return mWidget && mWidget->AsyncPanZoomEnabled(); } +void +ClientLayerManager::SetNextPaintSyncId(int32_t aSyncId) +{ + mForwarder->SetPaintSyncId(aSyncId); +} + ClientLayer::~ClientLayer() { if (HasShadow()) { diff --git a/gfx/layers/client/ClientLayerManager.h b/gfx/layers/client/ClientLayerManager.h index 77085de4fc..32e8ba2b2d 100644 --- a/gfx/layers/client/ClientLayerManager.h +++ b/gfx/layers/client/ClientLayerManager.h @@ -253,6 +253,8 @@ public: bool AsyncPanZoomEnabled() const override; + void SetNextPaintSyncId(int32_t aSyncId); + protected: enum TransactionPhase { PHASE_NONE, PHASE_CONSTRUCTION, PHASE_DRAWING, PHASE_FORWARD diff --git a/gfx/layers/client/ClientTiledPaintedLayer.cpp b/gfx/layers/client/ClientTiledPaintedLayer.cpp index e363d15e5e..23e2170a59 100644 --- a/gfx/layers/client/ClientTiledPaintedLayer.cpp +++ b/gfx/layers/client/ClientTiledPaintedLayer.cpp @@ -59,10 +59,10 @@ ClientTiledPaintedLayer::FillSpecificAttributes(SpecificLayerAttributes& aAttrs) aAttrs = PaintedLayerAttributes(GetValidRegion()); } -static LayerRect -ApplyParentLayerToLayerTransform(const gfx::Matrix4x4& aTransform, const ParentLayerRect& aParentLayerRect) +static Maybe +ApplyParentLayerToLayerTransform(const gfx::Matrix4x4& aTransform, const ParentLayerRect& aParentLayerRect, const LayerRect& aClip) { - return TransformTo(aTransform, aParentLayerRect); + return UntransformTo(aTransform, aParentLayerRect, aClip); } static gfx::Matrix4x4 @@ -128,10 +128,7 @@ ClientTiledPaintedLayer::GetAncestorLayers(LayerMetricsWrapper* aOutScrollAncest void ClientTiledPaintedLayer::BeginPaint() { - mPaintData.mLowPrecisionPaintCount = 0; - mPaintData.mPaintFinished = false; - mPaintData.mCompositionBounds.SetEmpty(); - mPaintData.mCriticalDisplayPort.SetEmpty(); + mPaintData.ResetPaintData(); if (!GetBaseTransform().Is2D()) { // Give up if there is a complex CSS transform on the layer. We might @@ -169,6 +166,8 @@ ClientTiledPaintedLayer::BeginPaint() GetTransformToAncestorsParentLayer(this, displayPortAncestor); transformDisplayPortToLayer.Invert(); + LayerRect layerBounds = ViewAs(Rect(GetLayerBounds())); + // Compute the critical display port that applies to this layer in the // LayoutDevice space of this layer, but only if there is no OMT animation // on this layer. If there is an OMT animation then we need to draw the whole @@ -179,8 +178,13 @@ ClientTiledPaintedLayer::BeginPaint() ParentLayerRect criticalDisplayPort = (displayportMetrics.GetCriticalDisplayPort() * displayportMetrics.GetZoom()) + displayportMetrics.GetCompositionBounds().TopLeft(); - mPaintData.mCriticalDisplayPort = RoundedToInt( - ApplyParentLayerToLayerTransform(transformDisplayPortToLayer, criticalDisplayPort)); + Maybe criticalDisplayPortTransformed = + ApplyParentLayerToLayerTransform(transformDisplayPortToLayer, criticalDisplayPort, layerBounds); + if (!criticalDisplayPortTransformed) { + mPaintData.ResetPaintData(); + return; + } + mPaintData.mCriticalDisplayPort = RoundedToInt(*criticalDisplayPortTransformed); } TILING_LOG("TILING %p: Critical displayport %s\n", this, Stringify(mPaintData.mCriticalDisplayPort).c_str()); @@ -194,8 +198,13 @@ ClientTiledPaintedLayer::BeginPaint() GetTransformToAncestorsParentLayer(this, scrollAncestor); gfx::Matrix4x4 transformToBounds = mPaintData.mTransformToCompBounds; transformToBounds.Invert(); - mPaintData.mCompositionBounds = ApplyParentLayerToLayerTransform( - transformToBounds, scrollMetrics.GetCompositionBounds()); + Maybe compositionBoundsTransformed = ApplyParentLayerToLayerTransform( + transformToBounds, scrollMetrics.GetCompositionBounds(), layerBounds); + if (!compositionBoundsTransformed) { + mPaintData.ResetPaintData(); + return; + } + mPaintData.mCompositionBounds = *compositionBoundsTransformed; TILING_LOG("TILING %p: Composition bounds %s\n", this, Stringify(mPaintData.mCompositionBounds).c_str()); // Calculate the scroll offset since the last transaction diff --git a/gfx/layers/client/TiledContentClient.cpp b/gfx/layers/client/TiledContentClient.cpp index 34ec480042..861cfc065c 100644 --- a/gfx/layers/client/TiledContentClient.cpp +++ b/gfx/layers/client/TiledContentClient.cpp @@ -1398,14 +1398,16 @@ ClientMultiTiledLayerBuffer::ValidateTile(TileClient& aTile, * transformed into the painted layer's LayerPixel coordinates, accounting * for the compositor state. */ -static LayerRect +static Maybe GetCompositorSideCompositionBounds(const LayerMetricsWrapper& aScrollAncestor, const Matrix4x4& aTransformToCompBounds, - const ViewTransform& aAPZTransform) + const ViewTransform& aAPZTransform, + const LayerRect& aClip) { Matrix4x4 transform = aTransformToCompBounds * Matrix4x4(aAPZTransform); - return TransformTo(transform.Inverse(), - aScrollAncestor.Metrics().GetCompositionBounds()); + + return UntransformTo(transform.Inverse(), + aScrollAncestor.Metrics().GetCompositionBounds(), aClip); } bool @@ -1484,12 +1486,18 @@ ClientMultiTiledLayerBuffer::ComputeProgressiveUpdateRegion(const nsIntRegion& a } } - LayerRect transformedCompositionBounds = + Maybe transformedCompositionBounds = GetCompositorSideCompositionBounds(scrollAncestor, aPaintData->mTransformToCompBounds, - viewTransform); + viewTransform, + ViewAs(Rect(mPaintedLayer->GetLayerBounds()))); - TILING_LOG("TILING %p: Progressive update transformed compositor bounds %s\n", mPaintedLayer, Stringify(transformedCompositionBounds).c_str()); + if (!transformedCompositionBounds) { + aPaintData->mPaintFinished = true; + return false; + } + + TILING_LOG("TILING %p: Progressive update transformed compositor bounds %s\n", mPaintedLayer, Stringify(*transformedCompositionBounds).c_str()); // Compute a "coherent update rect" that we should paint all at once in a // single transaction. This is to avoid rendering glitches on animated @@ -1502,9 +1510,9 @@ ClientMultiTiledLayerBuffer::ComputeProgressiveUpdateRegion(const nsIntRegion& a // the browser, so we always use the entire user-visible area. IntRect coherentUpdateRect(LayerIntRect::ToUntyped(RoundedOut( #ifdef MOZ_WIDGET_ANDROID - transformedCompositionBounds.Intersect(aPaintData->mCompositionBounds) + transformedCompositionBounds->Intersect(aPaintData->mCompositionBounds) #else - transformedCompositionBounds + *transformedCompositionBounds #endif ))); @@ -1679,5 +1687,14 @@ TiledContentClient::Dump(std::stringstream& aStream, GetTiledBuffer()->Dump(aStream, aPrefix, aDumpHtml); } +void +BasicTiledLayerPaintData::ResetPaintData() +{ + mLowPrecisionPaintCount = 0; + mPaintFinished = false; + mCompositionBounds.SetEmpty(); + mCriticalDisplayPort.SetEmpty(); +} + } // namespace layers } // namespace mozilla diff --git a/gfx/layers/client/TiledContentClient.h b/gfx/layers/client/TiledContentClient.h index 379c045c83..1ce96533a2 100644 --- a/gfx/layers/client/TiledContentClient.h +++ b/gfx/layers/client/TiledContentClient.h @@ -352,6 +352,11 @@ struct BasicTiledLayerPaintData { * progressively. */ bool mPaintFinished : 1; + + /* + * Initializes/clears data to prepare for paint action. + */ + void ResetPaintData(); }; class SharedFrameMetricsHelper diff --git a/gfx/layers/composite/AsyncCompositionManager.cpp b/gfx/layers/composite/AsyncCompositionManager.cpp index 4056c9b32c..a36f01483f 100644 --- a/gfx/layers/composite/AsyncCompositionManager.cpp +++ b/gfx/layers/composite/AsyncCompositionManager.cpp @@ -11,6 +11,7 @@ #include "LayerManagerComposite.h" // for LayerManagerComposite, etc #include "Layers.h" // for Layer, ContainerLayer, etc #include "gfxPoint.h" // for gfxPoint, gfxSize +#include "gfxPrefs.h" // for gfxPrefs #include "mozilla/StyleAnimationValue.h" // for StyleAnimationValue, etc #include "mozilla/WidgetUtils.h" // for ComputeTransformForRotation #include "mozilla/dom/KeyframeEffect.h" // for KeyframeEffectReadOnly @@ -50,7 +51,7 @@ using namespace mozilla::gfx; enum Op { Resolve, Detach }; static bool -IsSameDimension(dom::ScreenOrientation o1, dom::ScreenOrientation o2) +IsSameDimension(dom::ScreenOrientationInternal o1, dom::ScreenOrientationInternal o2) { bool isO1portrait = (o1 == dom::eScreenOrientation_PortraitPrimary || o1 == dom::eScreenOrientation_PortraitSecondary); bool isO2portrait = (o2 == dom::eScreenOrientation_PortraitPrimary || o2 == dom::eScreenOrientation_PortraitSecondary); @@ -73,8 +74,8 @@ WalkTheTree(Layer* aLayer, if (const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(ref->GetReferentId())) { if (Layer* referent = state->mRoot) { if (!ref->GetVisibleRegion().IsEmpty()) { - dom::ScreenOrientation chromeOrientation = aTargetConfig.orientation(); - dom::ScreenOrientation contentOrientation = state->mTargetConfig.orientation(); + dom::ScreenOrientationInternal chromeOrientation = aTargetConfig.orientation(); + dom::ScreenOrientationInternal contentOrientation = state->mTargetConfig.orientation(); if (!IsSameDimension(chromeOrientation, contentOrientation) && ContentMightReflowOnOrientationChange(aTargetConfig.naturalBounds())) { aReady = false; @@ -100,6 +101,7 @@ AsyncCompositionManager::AsyncCompositionManager(LayerManagerComposite* aManager : mLayerManager(aManager) , mIsFirstPaint(true) , mLayersUpdated(false) + , mPaintSyncId(0) , mReadyForCompose(true) { } @@ -142,18 +144,21 @@ AsyncCompositionManager::ComputeRotation() } } -static bool -GetBaseTransform2D(Layer* aLayer, Matrix* aTransform) +static void +GetBaseTransform(Layer* aLayer, Matrix4x4* aTransform) { // Start with the animated transform if there is one - return (aLayer->AsLayerComposite()->GetShadowTransformSetByAnimation() ? - aLayer->GetLocalTransform() : aLayer->GetTransform()).Is2D(aTransform); + *aTransform = + (aLayer->AsLayerComposite()->GetShadowTransformSetByAnimation() + ? aLayer->GetLocalTransform() + : aLayer->GetTransform()); } static void TransformClipRect(Layer* aLayer, const Matrix4x4& aTransform) { + MOZ_ASSERT(aTransform.Is2D()); const Maybe& clipRect = aLayer->AsLayerComposite()->GetShadowClipRect(); if (clipRect) { ParentLayerIntRect transformed = TransformTo(aTransform, *clipRect); @@ -184,9 +189,9 @@ SetShadowTransform(Layer* aLayer, Matrix4x4 aTransform) } static void -TranslateShadowLayer2D(Layer* aLayer, - const gfxPoint& aTranslation, - bool aAdjustClipRect) +TranslateShadowLayer(Layer* aLayer, + const gfxPoint& aTranslation, + bool aAdjustClipRect) { // This layer might also be a scrollable layer and have an async transform. // To make sure we don't clobber that, we start with the shadow transform. @@ -194,49 +199,41 @@ TranslateShadowLayer2D(Layer* aLayer, // Note that the shadow transform is reset on every frame of composition so // we don't have to worry about the adjustments compounding over successive // frames. - Matrix layerTransform; - if (!aLayer->GetLocalTransform().Is2D(&layerTransform)) { - return; - } + Matrix4x4 layerTransform = aLayer->GetLocalTransform(); - // Apply the 2D translation to the layer transform. - layerTransform._31 += aTranslation.x; - layerTransform._32 += aTranslation.y; + // Apply the translation to the layer transform. + layerTransform.PostTranslate(aTranslation.x, aTranslation.y, 0); - SetShadowTransform(aLayer, Matrix4x4::From2D(layerTransform)); + SetShadowTransform(aLayer, layerTransform); aLayer->AsLayerComposite()->SetShadowTransformSetByAnimation(false); if (aAdjustClipRect) { TransformClipRect(aLayer, Matrix4x4::Translation(aTranslation.x, aTranslation.y, 0)); - } - // If a fixed- or sticky-position layer has a mask layer, that mask should - // move along with the layer, so apply the translation to the mask layer too. - if (Layer* maskLayer = aLayer->GetMaskLayer()) { - TranslateShadowLayer2D(maskLayer, aTranslation, false); + // If a fixed- or sticky-position layer has a mask layer, that mask should + // move along with the layer, so apply the translation to the mask layer too. + if (Layer* maskLayer = aLayer->GetMaskLayer()) { + TranslateShadowLayer(maskLayer, aTranslation, false); + } } } -static bool -AccumulateLayerTransforms2D(Layer* aLayer, - Layer* aAncestor, - Matrix& aMatrix) +static void +AccumulateLayerTransforms(Layer* aLayer, + Layer* aAncestor, + Matrix4x4& aMatrix) { // Accumulate the transforms between this layer and the subtree root layer. for (Layer* l = aLayer; l && l != aAncestor; l = l->GetParent()) { - Matrix l2D; - if (!GetBaseTransform2D(l, &l2D)) { - return false; - } - aMatrix *= l2D; + Matrix4x4 transform; + GetBaseTransform(l, &transform); + aMatrix *= transform; } - - return true; } static LayerPoint GetLayerFixedMarginsOffset(Layer* aLayer, - const LayerMargin& aFixedLayerMargins) + const ScreenMargin& aFixedLayerMargins) { // Work out the necessary translation, in root scrollable layer space. // Because fixed layer margins are stored relative to the root scrollable @@ -271,74 +268,124 @@ IntervalOverlap(gfxFloat aTranslation, gfxFloat aMin, gfxFloat aMax) } } +/** + * Finds the metrics on |aLayer| with scroll id |aScrollId|, and returns a + * LayerMetricsWrapper representing the (layer, metrics) pair, or the null + * LayerMetricsWrapper if no matching metrics could be found. + */ +static LayerMetricsWrapper +FindMetricsWithScrollId(Layer* aLayer, FrameMetrics::ViewID aScrollId) +{ + for (uint64_t i = 0; i < aLayer->GetFrameMetricsCount(); ++i) { + if (aLayer->GetFrameMetrics(i).GetScrollId() == aScrollId) { + return LayerMetricsWrapper(aLayer, i); + } + } + return LayerMetricsWrapper(); +} + +/** + * Checks whether the (layer, metrics) pair (aTransformedLayer, aTransformedMetrics) + * is on the path from |aFixedLayer| to the metrics with scroll id + * |aFixedWithRespectTo|, inclusive. + */ +static bool +AsyncTransformShouldBeUnapplied(Layer* aFixedLayer, + FrameMetrics::ViewID aFixedWithRespectTo, + Layer* aTransformedLayer, + FrameMetrics::ViewID aTransformedMetrics) +{ + LayerMetricsWrapper transformed = FindMetricsWithScrollId(aTransformedLayer, aTransformedMetrics); + if (!transformed.IsValid()) { + return false; + } + // It's important to start at the bottom, because the fixed layer itself + // could have the transformed metrics, and they can be at the bottom. + LayerMetricsWrapper current(aFixedLayer, LayerMetricsWrapper::StartAt::BOTTOM); + bool encounteredTransformedLayer = false; + // The transformed layer is on the path from |aFixedLayer| to the fixed-to + // layer if as we walk up the (layer, metrics) tree starting from + // |aFixedLayer|, we *first* encounter the transformed layer, and *then* (or + // at the same time) the fixed-to layer. + while (current) { + if (!encounteredTransformedLayer && current == transformed) { + encounteredTransformedLayer = true; + } + if (current.Metrics().GetScrollId() == aFixedWithRespectTo) { + return encounteredTransformedLayer; + } + current = current.GetParent(); + // It's possible that we reach a layers id boundary before we reach an + // ancestor with the scroll id |aFixedWithRespectTo| (this could happen + // e.g. if the scroll frame with that scroll id uses containerless + // scrolling). In such a case, stop the walk, as a new layers id could + // have a different layer with scroll id |aFixedWithRespectTo| which we + // don't intend to match. + if (current && current.AsRefLayer() != nullptr) { + break; + } + } + return false; +} + void AsyncCompositionManager::AlignFixedAndStickyLayers(Layer* aLayer, Layer* aTransformedSubtreeRoot, FrameMetrics::ViewID aTransformScrollId, const Matrix4x4& aPreviousTransformForRoot, const Matrix4x4& aCurrentTransformForRoot, - const LayerMargin& aFixedLayerMargins) + const ScreenMargin& aFixedLayerMargins) { - // If aLayer == aTransformedSubtreeRoot, then treat aLayer as fixed relative - // to the ancestor scrollable layer rather than relative to itself. - bool isRootFixed = aLayer->GetIsFixedPosition() && - aLayer != aTransformedSubtreeRoot && + FrameMetrics::ViewID fixedTo; // the scroll id of the scroll frame we are fixed/sticky to + bool isRootOfFixedSubtree = aLayer->GetIsFixedPosition() && !aLayer->GetParent()->GetIsFixedPosition(); - bool isStickyForSubtree = aLayer->GetIsStickyPosition() && - aLayer->GetStickyScrollContainerId() == aTransformScrollId; - bool isFixedOrSticky = (isRootFixed || isStickyForSubtree); + if (isRootOfFixedSubtree) { + fixedTo = aLayer->GetFixedPositionScrollContainerId(); + } + bool isSticky = aLayer->GetIsStickyPosition(); + if (isSticky) { + fixedTo = aLayer->GetStickyScrollContainerId(); + } + bool needsAsyncTransformUnapplied = false; + if (isRootOfFixedSubtree || isSticky) { + needsAsyncTransformUnapplied = AsyncTransformShouldBeUnapplied(aLayer, + fixedTo, aTransformedSubtreeRoot, aTransformScrollId); + } - // We want to process all the fixed and sticky children of - // aTransformedSubtreeRoot. Also, once we do encounter such a child, we don't - // need to recurse any deeper because the fixed layers are relative to their - // nearest scrollable layer. - if (!isFixedOrSticky) { - // ApplyAsyncContentTransformToTree will call this function again for - // nested scrollable layers, so we don't need to recurse if the layer is - // scrollable. - if (aLayer == aTransformedSubtreeRoot || !aLayer->HasScrollableFrameMetrics()) { - for (Layer* child = aLayer->GetFirstChild(); child; child = child->GetNextSibling()) { - AlignFixedAndStickyLayers(child, aTransformedSubtreeRoot, aTransformScrollId, - aPreviousTransformForRoot, - aCurrentTransformForRoot, aFixedLayerMargins); - } + // We want to process all the fixed and sticky descendants of + // aTransformedSubtreeRoot. Once we do encounter such a descendant, we don't + // need to recurse any deeper because the adjustment to the fixed or sticky + // layer will apply to its subtree. + if (!needsAsyncTransformUnapplied) { + for (Layer* child = aLayer->GetFirstChild(); child; child = child->GetNextSibling()) { + AlignFixedAndStickyLayers(child, aTransformedSubtreeRoot, aTransformScrollId, + aPreviousTransformForRoot, + aCurrentTransformForRoot, aFixedLayerMargins); } return; } // Insert a translation so that the position of the anchor point is the same // before and after the change to the transform of aTransformedSubtreeRoot. - // This currently only works for fixed layers with 2D transforms. // Accumulate the transforms between this layer and the subtree root layer. - Matrix ancestorTransform; - if (!AccumulateLayerTransforms2D(aLayer->GetParent(), aTransformedSubtreeRoot, - ancestorTransform)) { - return; - } - - Matrix oldRootTransform; - Matrix newRootTransform; - if (!aPreviousTransformForRoot.Is2D(&oldRootTransform) || - !aCurrentTransformForRoot.Is2D(&newRootTransform)) { - return; - } + Matrix4x4 ancestorTransform; + AccumulateLayerTransforms(aLayer->GetParent(), aTransformedSubtreeRoot, + ancestorTransform); // Calculate the cumulative transforms between the subtree root with the // old transform and the current transform. - Matrix oldCumulativeTransform = ancestorTransform * oldRootTransform; - Matrix newCumulativeTransform = ancestorTransform * newRootTransform; + Matrix4x4 oldCumulativeTransform = ancestorTransform * aPreviousTransformForRoot; + Matrix4x4 newCumulativeTransform = ancestorTransform * aCurrentTransformForRoot; if (newCumulativeTransform.IsSingular()) { return; } - Matrix newCumulativeTransformInverse = newCumulativeTransform.Inverse(); + Matrix4x4 newCumulativeTransformInverse = newCumulativeTransform.Inverse(); // Now work out the translation necessary to make sure the layer doesn't // move given the new sub-tree root transform. - Matrix layerTransform; - if (!GetBaseTransform2D(aLayer, &layerTransform)) { - return; - } + Matrix4x4 layerTransform; + GetBaseTransform(aLayer, &layerTransform); // Calculate any offset necessary, in previous transform sub-tree root // space. This is used to make sure fixed position content respects @@ -383,15 +430,19 @@ AsyncCompositionManager::AlignFixedAndStickyLayers(Layer* aLayer, IntervalOverlap(translation.x, stickyInner.x, stickyInner.XMost()); } - // Finally, apply the 2D translation to the layer transform. Note that in + // Finally, apply the translation to the layer transform. Note that in // general we need to apply the same translation to the layer's clip rect, so // that the effective transform on the clip rect takes it back to where it was // originally, had there been no async scroll. In the case where the // fixed/sticky layer is the same as aTransformedSubtreeRoot, then the clip // rect is not affected by the scroll-induced async scroll transform anyway // (since the clip is applied post-transform) so we don't need to make the - // adjustment. - TranslateShadowLayer2D(aLayer, ThebesPoint(translation), aLayer != aTransformedSubtreeRoot); + // adjustment. Also, some layers want async scrolling to move their clip rect + // (IsClipFixed() = false), so we don't make a compensating adjustment for + // those. + bool adjustClipRect = aLayer != aTransformedSubtreeRoot && + aLayer->IsClipFixed(); + TranslateShadowLayer(aLayer, ThebesPoint(translation), adjustClipRect); } static void @@ -604,22 +655,45 @@ AdjustForClip(const Matrix4x4& asyncTransform, Layer* aLayer) return result; } +static void +ExpandRootClipRect(Layer* aLayer, const ScreenMargin& aFixedLayerMargins) +{ + // For Fennec we want to expand the root scrollable layer clip rect based on + // the fixed position margins. In particular, we want this while the dynamic + // toolbar is in the process of sliding offscreen and the area of the + // LayerView visible to the user is larger than the viewport size that Gecko + // knows about (and therefore larger than the clip rect). We could also just + // clear the clip rect on aLayer entirely but this seems more precise. + Maybe rootClipRect = aLayer->AsLayerComposite()->GetShadowClipRect(); + if (rootClipRect && aFixedLayerMargins != ScreenMargin()) { +#ifndef MOZ_WIDGET_ANDROID + // We should never enter here on anything other than Fennec, since + // aFixedLayerMargins should be empty everywhere else. + MOZ_ASSERT(false); +#endif + ParentLayerRect rect(rootClipRect.value()); + rect.Deflate(ViewAs(aFixedLayerMargins, + PixelCastJustification::ScreenIsParentLayerForRoot)); + aLayer->AsLayerComposite()->SetShadowClipRect(Some(RoundedOut(rect))); + } +} + bool -AsyncCompositionManager::ApplyAsyncContentTransformToTree(Layer *aLayer) +AsyncCompositionManager::ApplyAsyncContentTransformToTree(Layer *aLayer, + bool* aOutFoundRoot) { bool appliedTransform = false; for (Layer* child = aLayer->GetFirstChild(); child; child = child->GetNextSibling()) { appliedTransform |= - ApplyAsyncContentTransformToTree(child); + ApplyAsyncContentTransformToTree(child, aOutFoundRoot); } Matrix4x4 oldTransform = aLayer->GetTransform(); - Matrix4x4 combinedAsyncTransformWithoutOverscroll; Matrix4x4 combinedAsyncTransform; bool hasAsyncTransform = false; - LayerMargin fixedLayerMargins(0, 0, 0, 0); + ScreenMargin fixedLayerMargins; // Each layer has multiple clips. Its local clip, which must move with async // transforms, and its scrollframe clips, which are the clips between each @@ -662,32 +736,49 @@ AsyncCompositionManager::ApplyAsyncContentTransformToTree(Layer *aLayer) } const FrameMetrics& metrics = aLayer->GetFrameMetrics(i); - ScreenPoint offset(0, 0); - // TODO: When we enable APZ on Fennec, we'll need to call SyncFrameMetrics here. - // When doing so, it might be useful to look at how it was called here before - // bug 1036967 removed the (dead) call. #if defined(MOZ_ANDROID_APZ) - if (mIsFirstPaint) { - CSSToLayerScale geckoZoom = metrics.LayersPixelsPerCSSPixel().ToScaleFactor(); - LayerIntPoint scrollOffsetLayerPixels = RoundedToInt(metrics.GetScrollOffset() * geckoZoom); - mContentRect = metrics.GetScrollableRect(); - SetFirstPaintViewport(scrollOffsetLayerPixels, - geckoZoom, - mContentRect); + // If we find a metrics which is the root content doc, use that. If not, use + // the root layer. Since this function recurses on children first we should + // only end up using the root layer if the entire tree was devoid of a + // root content metrics. This is a temporary solution; in the long term we + // should not need the root content metrics at all. See bug 1201529 comment + // 6 for details. + if (!(*aOutFoundRoot)) { + *aOutFoundRoot = metrics.IsRootContent() || /* RCD */ + (aLayer->GetParent() == nullptr && /* rootmost metrics */ + i + 1 >= aLayer->GetFrameMetricsCount()); + if (*aOutFoundRoot) { + CSSToLayerScale geckoZoom = metrics.LayersPixelsPerCSSPixel().ToScaleFactor(); + if (mIsFirstPaint) { + LayerIntPoint scrollOffsetLayerPixels = RoundedToInt(metrics.GetScrollOffset() * geckoZoom); + mContentRect = metrics.GetScrollableRect(); + SetFirstPaintViewport(scrollOffsetLayerPixels, + geckoZoom, + mContentRect); + } else { + // Compute the painted displayport in document-relative CSS pixels. + CSSRect displayPort(metrics.GetCriticalDisplayPort().IsEmpty() ? + metrics.GetDisplayPort() : + metrics.GetCriticalDisplayPort()); + displayPort += metrics.GetScrollOffset(); + SyncFrameMetrics(scrollOffset, + geckoZoom * asyncTransformWithoutOverscroll.mScale, + metrics.GetScrollableRect(), displayPort, geckoZoom, mLayersUpdated, + mPaintSyncId, fixedLayerMargins); + } + mIsFirstPaint = false; + mLayersUpdated = false; + mPaintSyncId = 0; + } } #endif - mIsFirstPaint = false; - mLayersUpdated = false; - - // Apply the render offset - mLayerManager->GetCompositor()->SetScreenRenderOffset(offset); - // Transform the current local clip by this APZC's async transform. If we're // using containerful scrolling, then the clip is not part of the scrolled // frame and should not be transformed. if (asyncClip && !metrics.UsesContainerScrolling()) { + MOZ_ASSERT(asyncTransform.Is2D()); asyncClip = Some(TransformTo(asyncTransform, *asyncClip)); } @@ -718,8 +809,22 @@ AsyncCompositionManager::ApplyAsyncContentTransformToTree(Layer *aLayer) ancestorMaskLayers.AppendElement(ancestorMaskLayer); } - combinedAsyncTransformWithoutOverscroll *= asyncTransformWithoutOverscroll; combinedAsyncTransform *= asyncTransform; + + // For the purpose of aligning fixed and sticky layers, we disregard + // the overscroll transform as well as any OMTA transform when computing the + // 'aCurrentTransformForRoot' parameter. This ensures that the overscroll + // and OMTA transforms are not unapplied, and therefore that the visual + // effects apply to fixed and sticky layers. We do this by using + // GetTransform() as the base transform rather than GetLocalTransform(), + // which would include those factors. + Matrix4x4 transformWithoutOverscrollOrOmta = aLayer->GetTransform() * + AdjustForClip(asyncTransformWithoutOverscroll, aLayer); + + // Since fixed/sticky layers are relative to their nearest scrolling ancestor, + // we use the ViewID from the bottommost scrollable metrics here. + AlignFixedAndStickyLayers(aLayer, aLayer, metrics.GetScrollId(), oldTransform, + transformWithoutOverscrollOrOmta, fixedLayerMargins); } if (hasAsyncTransform) { @@ -740,26 +845,11 @@ AsyncCompositionManager::ApplyAsyncContentTransformToTree(Layer *aLayer) maskLayer->GetLocalTransform() * combinedAsyncTransform); } - const FrameMetrics& bottom = LayerMetricsWrapper::BottommostScrollableMetrics(aLayer); - MOZ_ASSERT(bottom.IsScrollable()); // must be true because hasAsyncTransform is true - - // For the purpose of aligning fixed and sticky layers, we disregard - // the overscroll transform as well as any OMTA transform when computing the - // 'aCurrentTransformForRoot' parameter. This ensures that the overscroll - // and OMTA transforms are not unapplied, and therefore that the visual - // effects apply to fixed and sticky layers. We do this by using - // GetTransform() as the base transform rather than GetLocalTransform(), - // which would include those factors. - Matrix4x4 transformWithoutOverscrollOrOmta = aLayer->GetTransform() * - AdjustForClip(combinedAsyncTransformWithoutOverscroll, aLayer); - // Since fixed/sticky layers are relative to their nearest scrolling ancestor, - // we use the ViewID from the bottommost scrollable metrics here. - AlignFixedAndStickyLayers(aLayer, aLayer, bottom.GetScrollId(), oldTransform, - transformWithoutOverscrollOrOmta, fixedLayerMargins); - appliedTransform = true; } + ExpandRootClipRect(aLayer, fixedLayerMargins); + if (aLayer->GetScrollbarDirection() != Layer::NONE) { ApplyAsyncTransformToScrollbar(aLayer); } @@ -884,7 +974,7 @@ ApplyAsyncTransformToScrollbarForContent(Layer* aScrollbar, scrollbarTransform.PostTranslate(xTranslation, 0, 0); } - Matrix4x4 transform = scrollbarTransform * aScrollbar->GetTransform(); + Matrix4x4 transform = aScrollbar->GetLocalTransform() * scrollbarTransform; Matrix4x4 compensation; // If the scrollbar layer is for the root then the content's resolution @@ -914,17 +1004,18 @@ ApplyAsyncTransformToScrollbarForContent(Layer* aScrollbar, Matrix4x4 contentTransform = aContent.GetTransform(); Matrix4x4 contentUntransform = contentTransform.Inverse(); - compensation = compensation - * contentTransform - * asyncUntransform - * contentUntransform; + Matrix4x4 asyncCompensation = contentTransform + * asyncUntransform + * contentUntransform; + + compensation = compensation * asyncCompensation; // We also need to make a corresponding change on the clip rect of all the // layers on the ancestor chain from the scrollbar layer up to but not // including the layer with the async transform. Otherwise the scrollbar // shifts but gets clipped and so appears to flicker. for (Layer* ancestor = aScrollbar; ancestor != aContent.GetLayer(); ancestor = ancestor->GetParent()) { - TransformClipRect(ancestor, compensation); + TransformClipRect(ancestor, asyncCompensation); } } transform = transform * compensation; @@ -1040,8 +1131,7 @@ AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer) ) * geckoZoom); displayPort += scrollOffsetLayerPixels; - LayerMargin fixedLayerMargins(0, 0, 0, 0); - ScreenPoint offset(0, 0); + ScreenMargin fixedLayerMargins(0, 0, 0, 0); // Ideally we would initialize userZoom to AsyncPanZoomController::CalculateResolution(metrics) // but this causes a reftest-ipc test to fail (see bug 883646 comment 27). The reason for this @@ -1053,14 +1143,12 @@ AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer) // for which we can assume that x and y scales are equal. * metrics.GetCumulativeResolution().ToScaleFactor() * LayerToParentLayerScale(1)); - ParentLayerPoint userScroll = metrics.GetScrollOffset() * userZoom; - SyncViewportInfo(displayPort, geckoZoom, mLayersUpdated, - userScroll, userZoom, fixedLayerMargins, - offset); + ParentLayerRect userRect(metrics.GetScrollOffset() * userZoom, + metrics.GetCompositionBounds().Size()); + SyncViewportInfo(displayPort, geckoZoom, mLayersUpdated, mPaintSyncId, + userRect, userZoom, fixedLayerMargins); mLayersUpdated = false; - - // Apply the render offset - mLayerManager->GetCompositor()->SetScreenRenderOffset(offset); + mPaintSyncId = 0; // Handle transformations for asynchronous panning and zooming. We determine the // zoom used by Gecko from the transformation set on the root layer, and we @@ -1074,7 +1162,7 @@ AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer) } LayerToParentLayerScale asyncZoom = userZoom / metrics.LayersPixelsPerCSSPixel().ToScaleFactor(); - ParentLayerPoint translation = userScroll - geckoScroll; + ParentLayerPoint translation = userRect.TopLeft() - geckoScroll; Matrix4x4 treeTransform = ViewTransform(asyncZoom, -translation); // Apply the tree transform on top of GetLocalTransform() here (rather than @@ -1090,17 +1178,15 @@ AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer) // AlignFixedAndStickyLayers. ParentLayerRect contentScreenRect = mContentRect * userZoom; Point3D overscrollTranslation; - if (userScroll.x < contentScreenRect.x) { - overscrollTranslation.x = contentScreenRect.x - userScroll.x; - } else if (userScroll.x + metrics.GetCompositionBounds().width > contentScreenRect.XMost()) { - overscrollTranslation.x = contentScreenRect.XMost() - - (userScroll.x + metrics.GetCompositionBounds().width); + if (userRect.x < contentScreenRect.x) { + overscrollTranslation.x = contentScreenRect.x - userRect.x; + } else if (userRect.XMost() > contentScreenRect.XMost()) { + overscrollTranslation.x = contentScreenRect.XMost() - userRect.XMost(); } - if (userScroll.y < contentScreenRect.y) { - overscrollTranslation.y = contentScreenRect.y - userScroll.y; - } else if (userScroll.y + metrics.GetCompositionBounds().height > contentScreenRect.YMost()) { - overscrollTranslation.y = contentScreenRect.YMost() - - (userScroll.y + metrics.GetCompositionBounds().height); + if (userRect.y < contentScreenRect.y) { + overscrollTranslation.y = contentScreenRect.y - userRect.y; + } else if (userRect.YMost() > contentScreenRect.YMost()) { + overscrollTranslation.y = contentScreenRect.YMost() - userRect.YMost(); } oldTransform.PreTranslate(overscrollTranslation.x, overscrollTranslation.y, @@ -1121,6 +1207,8 @@ AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer) // when we're asynchronously panning or zooming AlignFixedAndStickyLayers(aLayer, aLayer, metrics.GetScrollId(), oldTransform, aLayer->GetLocalTransform(), fixedLayerMargins); + + ExpandRootClipRect(aLayer, fixedLayerMargins); } void @@ -1160,7 +1248,12 @@ AsyncCompositionManager::TransformShadowTree(TimeStamp aCurrentFrame, // its own platform-specific async rendering that is done partially // in Gecko and partially in Java. wantNextFrame |= SampleAPZAnimations(LayerMetricsWrapper(root), aCurrentFrame); - if (!ApplyAsyncContentTransformToTree(root)) { + bool foundRoot = false; + if (ApplyAsyncContentTransformToTree(root, &foundRoot)) { +#if defined(MOZ_ANDROID_APZ) + MOZ_ASSERT(foundRoot); +#endif + } else { nsAutoTArray scrollableLayers; #ifdef MOZ_WIDGET_ANDROID mLayerManager->GetRootScrollableLayers(scrollableLayers); @@ -1211,38 +1304,37 @@ void AsyncCompositionManager::SyncViewportInfo(const LayerIntRect& aDisplayPort, const CSSToLayerScale& aDisplayResolution, bool aLayersUpdated, - ParentLayerPoint& aScrollOffset, + int32_t aPaintSyncId, + ParentLayerRect& aScrollRect, CSSToParentLayerScale& aScale, - LayerMargin& aFixedLayerMargins, - ScreenPoint& aOffset) + ScreenMargin& aFixedLayerMargins) { #ifdef MOZ_WIDGET_ANDROID AndroidBridge::Bridge()->SyncViewportInfo(aDisplayPort, aDisplayResolution, aLayersUpdated, - aScrollOffset, + aPaintSyncId, + aScrollRect, aScale, - aFixedLayerMargins, - aOffset); + aFixedLayerMargins); #endif } void AsyncCompositionManager::SyncFrameMetrics(const ParentLayerPoint& aScrollOffset, - float aZoom, + const CSSToParentLayerScale& aZoom, const CSSRect& aCssPageRect, - bool aLayersUpdated, const CSSRect& aDisplayPort, - const CSSToLayerScale& aDisplayResolution, - bool aIsFirstPaint, - LayerMargin& aFixedLayerMargins, - ScreenPoint& aOffset) + const CSSToLayerScale& aPaintedResolution, + bool aLayersUpdated, + int32_t aPaintSyncId, + ScreenMargin& aFixedLayerMargins) { #ifdef MOZ_WIDGET_ANDROID AndroidBridge::Bridge()->SyncFrameMetrics(aScrollOffset, aZoom, aCssPageRect, - aLayersUpdated, aDisplayPort, - aDisplayResolution, aIsFirstPaint, - aFixedLayerMargins, aOffset); + aDisplayPort, aPaintedResolution, + aLayersUpdated, aPaintSyncId, + aFixedLayerMargins); #endif } diff --git a/gfx/layers/composite/AsyncCompositionManager.h b/gfx/layers/composite/AsyncCompositionManager.h index 0d23cc2c6c..4432b125bd 100644 --- a/gfx/layers/composite/AsyncCompositionManager.h +++ b/gfx/layers/composite/AsyncCompositionManager.h @@ -16,7 +16,7 @@ #include "mozilla/gfx/Matrix.h" // for Matrix4x4 #include "mozilla/layers/FrameUniformityData.h" // For FrameUniformityData #include "mozilla/layers/LayersMessages.h" // for TargetConfig -#include "mozilla/nsRefPtr.h" // for nsRefPtr +#include "mozilla/nsRefPtr.h" // for nsRefPtr #include "nsISupportsImpl.h" // for LayerManager::AddRef, etc namespace mozilla { @@ -98,14 +98,18 @@ public: void ComputeRotation(); // Call after updating our layer tree. - void Updated(bool isFirstPaint, const TargetConfig& aTargetConfig) + void Updated(bool isFirstPaint, const TargetConfig& aTargetConfig, + int32_t aPaintSyncId) { mIsFirstPaint |= isFirstPaint; mLayersUpdated = true; mTargetConfig = aTargetConfig; + if (aPaintSyncId) { + mPaintSyncId = aPaintSyncId; + } } - bool RequiresReorientation(mozilla::dom::ScreenOrientation aOrientation) + bool RequiresReorientation(mozilla::dom::ScreenOrientationInternal aOrientation) const { return mTargetConfig.orientation() != aOrientation; } @@ -124,8 +128,11 @@ public: private: void TransformScrollableLayer(Layer* aLayer); // Return true if an AsyncPanZoomController content transform was - // applied for |aLayer|. - bool ApplyAsyncContentTransformToTree(Layer* aLayer); + // applied for |aLayer|. |*aOutFoundRoot| is set to true on Android only, if + // one of the metrics on one of the layers was determined to be the "root" + // and its state was synced to the Java front-end. |aOutFoundRoot| must be + // non-null. + bool ApplyAsyncContentTransformToTree(Layer* aLayer, bool* aOutFoundRoot); /** * Update the shadow transform for aLayer assuming that is a scrollbar, * so that it stays in sync with the content that is being scrolled by APZ. @@ -139,19 +146,18 @@ private: void SyncViewportInfo(const LayerIntRect& aDisplayPort, const CSSToLayerScale& aDisplayResolution, bool aLayersUpdated, - ParentLayerPoint& aScrollOffset, + int32_t aPaintSyncId, + ParentLayerRect& aScrollRect, CSSToParentLayerScale& aScale, - LayerMargin& aFixedLayerMargins, - ScreenPoint& aOffset); + ScreenMargin& aFixedLayerMargins); void SyncFrameMetrics(const ParentLayerPoint& aScrollOffset, - float aZoom, + const CSSToParentLayerScale& aZoom, const CSSRect& aCssPageRect, - bool aLayersUpdated, const CSSRect& aDisplayPort, - const CSSToLayerScale& aDisplayResolution, - bool aIsFirstPaint, - LayerMargin& aFixedLayerMargins, - ScreenPoint& aOffset); + const CSSToLayerScale& aPaintedResolution, + bool aLayersUpdated, + int32_t aPaintSyncId, + ScreenMargin& aFixedLayerMargins); /** * Adds a translation to the transform of any fixed position (whose parent @@ -172,7 +178,7 @@ private: FrameMetrics::ViewID aTransformScrollId, const gfx::Matrix4x4& aPreviousTransformForRoot, const gfx::Matrix4x4& aCurrentTransformForRoot, - const LayerMargin& aFixedLayerMargins); + const ScreenMargin& aFixedLayerMargins); /** * DRAWING PHASE ONLY @@ -206,6 +212,8 @@ private: // after a layers update has it set. It is cleared after that first composition. bool mLayersUpdated; + int32_t mPaintSyncId; + bool mReadyForCompose; gfx::Matrix mWorldTransform; diff --git a/gfx/layers/ipc/CompositorParent.cpp b/gfx/layers/ipc/CompositorParent.cpp index 459149a4bb..386feb92ee 100644 --- a/gfx/layers/ipc/CompositorParent.cpp +++ b/gfx/layers/ipc/CompositorParent.cpp @@ -1257,7 +1257,8 @@ CompositorParent::ShadowLayersUpdated(LayerTransactionParent* aLayerTree, bool aIsFirstPaint, bool aScheduleComposite, uint32_t aPaintSequenceNumber, - bool aIsRepeatTransaction) + bool aIsRepeatTransaction, + int32_t aPaintSyncId) { ScheduleRotationOnCompositorThread(aTargetConfig, aIsFirstPaint); @@ -1266,8 +1267,9 @@ CompositorParent::ShadowLayersUpdated(LayerTransactionParent* aLayerTree, // race condition. mLayerManager->UpdateRenderBounds(aTargetConfig.naturalBounds()); mLayerManager->SetRegionToClear(aTargetConfig.clearRegion()); + mLayerManager->GetCompositor()->SetScreenRotation(aTargetConfig.rotation()); - mCompositionManager->Updated(aIsFirstPaint, aTargetConfig); + mCompositionManager->Updated(aIsFirstPaint, aTargetConfig, aPaintSyncId); Layer* root = aLayerTree->GetRoot(); mLayerManager->SetRoot(root); @@ -1790,7 +1792,8 @@ public: bool aIsFirstPaint, bool aScheduleComposite, uint32_t aPaintSequenceNumber, - bool aIsRepeatTransaction) override; + bool aIsRepeatTransaction, + int32_t /*aPaintSyncId: unused*/) override; virtual void ForceComposite(LayerTransactionParent* aLayerTree) override; virtual void NotifyClearCachedResources(LayerTransactionParent* aLayerTree) override; virtual bool SetTestSampleTime(LayerTransactionParent* aLayerTree, @@ -2019,7 +2022,8 @@ CrossProcessCompositorParent::ShadowLayersUpdated( bool aIsFirstPaint, bool aScheduleComposite, uint32_t aPaintSequenceNumber, - bool aIsRepeatTransaction) + bool aIsRepeatTransaction, + int32_t /*aPaintSyncId: unused*/) { uint64_t id = aLayerTree->GetId(); diff --git a/gfx/layers/ipc/CompositorParent.h b/gfx/layers/ipc/CompositorParent.h index ef6bf5d18e..5e67d61389 100644 --- a/gfx/layers/ipc/CompositorParent.h +++ b/gfx/layers/ipc/CompositorParent.h @@ -263,7 +263,8 @@ public: bool aIsFirstPaint, bool aScheduleComposite, uint32_t aPaintSequenceNumber, - bool aIsRepeatTransaction) override; + bool aIsRepeatTransaction, + int32_t aPaintSyncId) override; virtual void ForceComposite(LayerTransactionParent* aLayerTree) override; virtual bool SetTestSampleTime(LayerTransactionParent* aLayerTree, const TimeStamp& aTime) override; diff --git a/gfx/layers/ipc/LayerTransactionParent.cpp b/gfx/layers/ipc/LayerTransactionParent.cpp index 05ae142819..238a65c6d0 100644 --- a/gfx/layers/ipc/LayerTransactionParent.cpp +++ b/gfx/layers/ipc/LayerTransactionParent.cpp @@ -197,11 +197,12 @@ LayerTransactionParent::RecvUpdateNoSwap(InfallibleTArray&& cset, const bool& scheduleComposite, const uint32_t& paintSequenceNumber, const bool& isRepeatTransaction, - const mozilla::TimeStamp& aTransactionStart) + const mozilla::TimeStamp& aTransactionStart, + const int32_t& aPaintSyncId) { return RecvUpdate(Move(cset), aTransactionId, targetConfig, Move(aPlugins), isFirstPaint, scheduleComposite, paintSequenceNumber, isRepeatTransaction, - aTransactionStart, nullptr); + aTransactionStart, aPaintSyncId, nullptr); } class MOZ_STACK_CLASS AutoLayerTransactionParentAsyncMessageSender @@ -229,6 +230,7 @@ LayerTransactionParent::RecvUpdate(InfallibleTArray&& cset, const uint32_t& paintSequenceNumber, const bool& isRepeatTransaction, const mozilla::TimeStamp& aTransactionStart, + const int32_t& aPaintSyncId, InfallibleTArray* reply) { profiler_tracing("Paint", "LayerTransaction", TRACING_INTERVAL_START); @@ -245,11 +247,6 @@ LayerTransactionParent::RecvUpdate(InfallibleTArray&& cset, return true; } - if (mLayerManager && mLayerManager->GetCompositor() && - !targetConfig.naturalBounds().IsEmpty()) { - mLayerManager->GetCompositor()->SetScreenRotation(targetConfig.rotation()); - } - EditReplyVector replyv; AutoLayerTransactionParentAsyncMessageSender autoAsyncMessageSender(this); @@ -596,7 +593,8 @@ LayerTransactionParent::RecvUpdate(InfallibleTArray&& cset, mShadowLayersManager->ShadowLayersUpdated(this, aTransactionId, targetConfig, aPlugins, isFirstPaint, scheduleComposite, - paintSequenceNumber, isRepeatTransaction); + paintSequenceNumber, isRepeatTransaction, + aPaintSyncId); { AutoResolveRefLayers resolve(mShadowLayersManager->GetCompositionManager(this)); diff --git a/gfx/layers/ipc/LayerTransactionParent.h b/gfx/layers/ipc/LayerTransactionParent.h index 8e835f7d1d..19464f0292 100644 --- a/gfx/layers/ipc/LayerTransactionParent.h +++ b/gfx/layers/ipc/LayerTransactionParent.h @@ -110,6 +110,7 @@ protected: const uint32_t& paintSequenceNumber, const bool& isRepeatTransaction, const mozilla::TimeStamp& aTransactionStart, + const int32_t& aPaintSyncId, EditReplyArray* reply) override; virtual bool RecvUpdateNoSwap(EditArray&& cset, @@ -120,7 +121,8 @@ protected: const bool& scheduleComposite, const uint32_t& paintSequenceNumber, const bool& isRepeatTransaction, - const mozilla::TimeStamp& aTransactionStart) override; + const mozilla::TimeStamp& aTransactionStart, + const int32_t& aPaintSyncId) override; virtual bool RecvClearCachedResources() override; virtual bool RecvForceComposite() override; diff --git a/gfx/layers/ipc/LayersMessages.ipdlh b/gfx/layers/ipc/LayersMessages.ipdlh index 2ac51a3ef5..13b1d9cfe9 100644 --- a/gfx/layers/ipc/LayersMessages.ipdlh +++ b/gfx/layers/ipc/LayersMessages.ipdlh @@ -29,7 +29,7 @@ using class mozilla::TimeDuration from "mozilla/TimeStamp.h"; using class mozilla::TimeStamp from "mozilla/TimeStamp.h"; using mozilla::ScreenRotation from "mozilla/WidgetUtils.h"; using nsCSSProperty from "nsCSSProperty.h"; -using mozilla::dom::ScreenOrientation from "mozilla/dom/ScreenOrientation.h"; +using mozilla::dom::ScreenOrientationInternal from "mozilla/dom/ScreenOrientation.h"; using struct mozilla::layers::TextureInfo from "mozilla/layers/CompositorTypes.h"; using mozilla::LayerMargin from "Units.h"; using mozilla::LayerPoint from "Units.h"; @@ -49,7 +49,7 @@ namespace layers { struct TargetConfig { IntRect naturalBounds; ScreenRotation rotation; - ScreenOrientation orientation; + ScreenOrientationInternal orientation; nsIntRegion clearRegion; }; diff --git a/gfx/layers/ipc/PLayerTransaction.ipdl b/gfx/layers/ipc/PLayerTransaction.ipdl index 764eb67370..6f36c93715 100644 --- a/gfx/layers/ipc/PLayerTransaction.ipdl +++ b/gfx/layers/ipc/PLayerTransaction.ipdl @@ -57,7 +57,8 @@ parent: sync Update(Edit[] cset, uint64_t id, TargetConfig targetConfig, PluginWindowData[] plugins, bool isFirstPaint, bool scheduleComposite, uint32_t paintSequenceNumber, - bool isRepeatTransaction, TimeStamp transactionStart) + bool isRepeatTransaction, TimeStamp transactionStart, + int32_t paintSyncId) returns (EditReply[] reply); // We don't need to send a sync transaction if @@ -65,7 +66,8 @@ parent: async UpdateNoSwap(Edit[] cset, uint64_t id, TargetConfig targetConfig, PluginWindowData[] plugins, bool isFirstPaint, bool scheduleComposite, uint32_t paintSequenceNumber, - bool isRepeatTransaction, TimeStamp transactionStart); + bool isRepeatTransaction, TimeStamp transactionStart, + int32_t paintSyncId); // Testing APIs diff --git a/gfx/layers/ipc/ShadowLayers.cpp b/gfx/layers/ipc/ShadowLayers.cpp index d9e4f8c6f0..bb8a2c4fe6 100644 --- a/gfx/layers/ipc/ShadowLayers.cpp +++ b/gfx/layers/ipc/ShadowLayers.cpp @@ -60,7 +60,7 @@ public: {} void Begin(const gfx::IntRect& aTargetBounds, ScreenRotation aRotation, - dom::ScreenOrientation aOrientation) + dom::ScreenOrientationInternal aOrientation) { mOpen = true; mTargetBounds = aTargetBounds; @@ -138,7 +138,7 @@ public: ShadowableLayerSet mMutants; gfx::IntRect mTargetBounds; ScreenRotation mTargetRotation; - dom::ScreenOrientation mTargetOrientation; + dom::ScreenOrientationInternal mTargetOrientation; bool mSwapRequired; private: @@ -167,6 +167,7 @@ ShadowLayerForwarder::ShadowLayerForwarder() : mDiagnosticTypes(DiagnosticTypes::NO_DIAGNOSTIC) , mIsFirstPaint(false) , mWindowOverlayChanged(false) + , mPaintSyncId(0) { mTxn = new Transaction(); } @@ -184,7 +185,7 @@ ShadowLayerForwarder::~ShadowLayerForwarder() void ShadowLayerForwarder::BeginTransaction(const gfx::IntRect& aTargetBounds, ScreenRotation aRotation, - dom::ScreenOrientation aOrientation) + dom::ScreenOrientationInternal aOrientation) { MOZ_ASSERT(HasShadowManager(), "no manager to forward to"); MOZ_ASSERT(mTxn->Finished(), "uncommitted txn?"); @@ -663,7 +664,7 @@ ShadowLayerForwarder::EndTransaction(InfallibleTArray* aReplies, !mShadowManager->SendUpdate(cset, aId, targetConfig, mPluginWindowData, mIsFirstPaint, aScheduleComposite, aPaintSequenceNumber, aIsRepeatTransaction, - aTransactionStart, aReplies)) { + aTransactionStart, mPaintSyncId, aReplies)) { MOZ_LAYERS_LOG(("[LayersForwarder] WARNING: sending transaction failed!")); return false; } @@ -677,7 +678,7 @@ ShadowLayerForwarder::EndTransaction(InfallibleTArray* aReplies, !mShadowManager->SendUpdateNoSwap(cset, aId, targetConfig, mPluginWindowData, mIsFirstPaint, aScheduleComposite, aPaintSequenceNumber, aIsRepeatTransaction, - aTransactionStart)) { + aTransactionStart, mPaintSyncId)) { MOZ_LAYERS_LOG(("[LayersForwarder] WARNING: sending transaction failed!")); return false; } @@ -685,6 +686,7 @@ ShadowLayerForwarder::EndTransaction(InfallibleTArray* aReplies, *aSent = true; mIsFirstPaint = false; + mPaintSyncId = 0; MOZ_LAYERS_LOG(("[LayersForwarder] ... done")); return true; } diff --git a/gfx/layers/ipc/ShadowLayers.h b/gfx/layers/ipc/ShadowLayers.h index b06a4071a9..cd38e0cd50 100644 --- a/gfx/layers/ipc/ShadowLayers.h +++ b/gfx/layers/ipc/ShadowLayers.h @@ -155,7 +155,7 @@ public: */ void BeginTransaction(const gfx::IntRect& aTargetBounds, ScreenRotation aRotation, - mozilla::dom::ScreenOrientation aOrientation); + mozilla::dom::ScreenOrientationInternal aOrientation); /** * The following methods may only be called after BeginTransaction() @@ -344,6 +344,8 @@ public: */ void SetIsFirstPaint() { mIsFirstPaint = true; } + void SetPaintSyncId(int32_t aSyncId) { mPaintSyncId = aSyncId; } + static void PlatformSyncBeforeUpdate(); protected: @@ -366,6 +368,7 @@ private: DiagnosticTypes mDiagnosticTypes; bool mIsFirstPaint; bool mWindowOverlayChanged; + int32_t mPaintSyncId; InfallibleTArray mPluginWindowData; }; diff --git a/gfx/layers/ipc/ShadowLayersManager.h b/gfx/layers/ipc/ShadowLayersManager.h index f0240e0fe7..401d5505c0 100644 --- a/gfx/layers/ipc/ShadowLayersManager.h +++ b/gfx/layers/ipc/ShadowLayersManager.h @@ -25,7 +25,8 @@ public: bool aIsFirstPaint, bool aScheduleComposite, uint32_t aPaintSequenceNumber, - bool aIsRepeatTransaction) = 0; + bool aIsRepeatTransaction, + int32_t aPaintSyncId) = 0; virtual AsyncCompositionManager* GetCompositionManager(LayerTransactionParent* aLayerTree) { return nullptr; } diff --git a/gfx/vr/gfxVRCardboard.cpp b/gfx/vr/gfxVRCardboard.cpp index b44ca0e306..ba9a91ea2f 100644 --- a/gfx/vr/gfxVRCardboard.cpp +++ b/gfx/vr/gfxVRCardboard.cpp @@ -42,7 +42,7 @@ namespace { // screen orientation. Similar to what Android SensorManager.remapCoordinateSystem // does, except only for a fixed number of transforms that we need. Matrix4x4 -RemapMatrixForOrientation(ScreenOrientation screenConfig, const Matrix4x4& aMatrix) +RemapMatrixForOrientation(ScreenOrientationInternal screenConfig, const Matrix4x4& aMatrix) { Matrix4x4 out; const float *in = &aMatrix._11; diff --git a/hal/Hal.cpp b/hal/Hal.cpp index f2a290ea19..3a22abe671 100644 --- a/hal/Hal.cpp +++ b/hal/Hal.cpp @@ -712,7 +712,7 @@ NotifyScreenConfigurationChange(const ScreenConfiguration& aScreenConfiguration) } bool -LockScreenOrientation(const dom::ScreenOrientation& aOrientation) +LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation) { AssertMainThread(); RETURN_PROXY_IF_SANDBOXED(LockScreenOrientation(aOrientation), false); diff --git a/hal/Hal.h b/hal/Hal.h index 38503e544f..8b58585e3f 100644 --- a/hal/Hal.h +++ b/hal/Hal.h @@ -394,7 +394,7 @@ void NotifyScreenConfigurationChange(const hal::ScreenConfiguration& aScreenConf * Lock the screen orientation to the specific orientation. * @return Whether the lock has been accepted. */ -bool LockScreenOrientation(const dom::ScreenOrientation& aOrientation); +bool LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation); /** * Unlock the screen orientation. diff --git a/hal/android/AndroidHal.cpp b/hal/android/AndroidHal.cpp index 05b186c707..60c7be8503 100644 --- a/hal/android/AndroidHal.cpp +++ b/hal/android/AndroidHal.cpp @@ -123,21 +123,23 @@ GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) nsIntRect rect; int32_t colorDepth, pixelDepth; - ScreenOrientation orientation; + int16_t angle; + ScreenOrientationInternal orientation; nsCOMPtr screen; screenMgr->GetPrimaryScreen(getter_AddRefs(screen)); screen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height); screen->GetColorDepth(&colorDepth); screen->GetPixelDepth(&pixelDepth); - orientation = static_cast(bridge->GetScreenOrientation()); + orientation = static_cast(bridge->GetScreenOrientation()); + angle = bridge->GetScreenAngle(); *aScreenConfiguration = - hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth); + hal::ScreenConfiguration(rect, orientation, angle, colorDepth, pixelDepth); } bool -LockScreenOrientation(const ScreenOrientation& aOrientation) +LockScreenOrientation(const ScreenOrientationInternal& aOrientation) { switch (aOrientation) { // The Android backend only supports these orientations. diff --git a/hal/fallback/FallbackScreenConfiguration.cpp b/hal/fallback/FallbackScreenConfiguration.cpp index e8905e77a9..cbee955fbc 100644 --- a/hal/fallback/FallbackScreenConfiguration.cpp +++ b/hal/fallback/FallbackScreenConfiguration.cpp @@ -33,7 +33,7 @@ GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration) nsIntRect rect; int32_t colorDepth, pixelDepth; - dom::ScreenOrientation orientation; + dom::ScreenOrientationInternal orientation; nsCOMPtr screen; screenMgr->GetPrimaryScreen(getter_AddRefs(screen)); @@ -45,11 +45,11 @@ GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration) : dom::eScreenOrientation_PortraitPrimary; *aScreenConfiguration = - hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth); + hal::ScreenConfiguration(rect, orientation, 0, colorDepth, pixelDepth); } bool -LockScreenOrientation(const dom::ScreenOrientation& aOrientation) +LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation) { return false; } diff --git a/hal/gonk/GonkHal.cpp b/hal/gonk/GonkHal.cpp index 973e3f070a..43bb5a15ca 100644 --- a/hal/gonk/GonkHal.cpp +++ b/hal/gonk/GonkHal.cpp @@ -941,7 +941,7 @@ GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration) } bool -LockScreenOrientation(const dom::ScreenOrientation& aOrientation) +LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation) { return OrientationObserver::GetInstance()->LockScreenOrientation(aOrientation); } diff --git a/hal/sandbox/PHal.ipdl b/hal/sandbox/PHal.ipdl index 4157b4e6ad..f22448f08e 100644 --- a/hal/sandbox/PHal.ipdl +++ b/hal/sandbox/PHal.ipdl @@ -9,7 +9,7 @@ include protocol PBrowser; include "mozilla/GfxMessageUtils.h"; -using mozilla::dom::ScreenOrientation from "mozilla/dom/ScreenOrientation.h"; +using mozilla::dom::ScreenOrientationInternal from "mozilla/dom/ScreenOrientation.h"; using mozilla::hal::SensorType from "mozilla/HalSensor.h"; using mozilla::hal::SensorAccuracyType from "mozilla/HalSensor.h"; using mozilla::hal::WakeLockControl from "mozilla/HalTypes.h"; @@ -58,7 +58,8 @@ struct WakeLockInformation { struct ScreenConfiguration { nsIntRect rect; - ScreenOrientation orientation; + ScreenOrientationInternal orientation; + uint16_t angle; uint32_t colorDepth; uint32_t pixelDepth; }; @@ -157,7 +158,7 @@ parent: DisableScreenConfigurationNotifications(); prio(urgent) sync GetCurrentScreenConfiguration() returns (ScreenConfiguration aScreenConfiguration); - sync LockScreenOrientation(ScreenOrientation aOrientation) + sync LockScreenOrientation(ScreenOrientationInternal aOrientation) returns (bool allowed); UnlockScreenOrientation(); diff --git a/hal/sandbox/SandboxHal.cpp b/hal/sandbox/SandboxHal.cpp index ba7fb88e9e..65d5c5738b 100644 --- a/hal/sandbox/SandboxHal.cpp +++ b/hal/sandbox/SandboxHal.cpp @@ -122,7 +122,7 @@ GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) } bool -LockScreenOrientation(const dom::ScreenOrientation& aOrientation) +LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation) { bool allowed; Hal()->SendLockScreenOrientation(aOrientation, &allowed); @@ -592,7 +592,7 @@ public: } virtual bool - RecvLockScreenOrientation(const dom::ScreenOrientation& aOrientation, bool* aAllowed) override + RecvLockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation, bool* aAllowed) override { // FIXME/bug 777980: unprivileged content may only lock // orientation while fullscreen. We should check whether the diff --git a/js/src/Makefile.in b/js/src/Makefile.in index 8f2fd1388a..1050db518c 100644 --- a/js/src/Makefile.in +++ b/js/src/Makefile.in @@ -12,8 +12,6 @@ ifneq ($(make_min_ver),$(firstword $(sort $(make_min_ver) $(MAKE_VERSION)))) $(error GNU Make $(make_min_ver) or higher is required) endif -run_for_side_effects := $(shell echo 'MAKE: $(MAKE)') - ifdef JS_HAS_CTYPES ifdef MOZ_NATIVE_FFI LOCAL_INCLUDES = $(MOZ_FFI_CFLAGS) diff --git a/layout/base/UnitTransforms.h b/layout/base/UnitTransforms.h index d927490d46..6d162f307f 100644 --- a/layout/base/UnitTransforms.h +++ b/layout/base/UnitTransforms.h @@ -69,6 +69,14 @@ template gfx::IntRectTyped ViewAs(const gfx::IntRectTyped& aRect, PixelCastJustification) { return gfx::IntRectTyped(aRect.x, aRect.y, aRect.width, aRect.height); } +template +gfx::MarginTyped ViewAs(const gfx::MarginTyped& aMargin, PixelCastJustification) { + return gfx::MarginTyped(aMargin.top, aMargin.right, aMargin.bottom, aMargin.left); +} +template +gfx::IntMarginTyped ViewAs(const gfx::IntMarginTyped& aMargin, PixelCastJustification) { + return gfx::IntMarginTyped(aMargin.top, aMargin.right, aMargin.bottom, aMargin.left); +} template gfx::ScaleFactor ViewTargetAs( const gfx::ScaleFactor& aScaleFactor, @@ -172,6 +180,34 @@ static Maybe> UntransformTo(const gfx::Matrix4x4 } return Some(RoundedToInt(ViewAs(point.As2DPoint()))); } + +// The versions of UntransformTo() that take a rectangle also take a clip, +// which represents the bounds within which the target must fall. The +// result of the transform is intersected with this clip, and is considered +// meaningful if the intersection is not empty. +template +static Maybe> UntransformTo(const gfx::Matrix4x4& aTransform, + const gfx::RectTyped& aRect, + const gfx::RectTyped& aClip) +{ + gfx::Rect rect = aTransform.ProjectRectBounds(aRect.ToUnknownRect(), aClip.ToUnknownRect()); + if (rect.IsEmpty()) { + return Nothing(); + } + return Some(ViewAs(rect)); +} +template +static Maybe> UntransformTo(const gfx::Matrix4x4& aTransform, + const gfx::IntRectTyped& aRect, + const gfx::IntRectTyped& aClip) +{ + gfx::Rect rect = aTransform.ProjectRectBounds(aRect.ToUnknownRect(), aClip.ToUnknownRect()); + if (rect.IsEmpty()) { + return Nothing(); + } + return Some(RoundedToInt(ViewAs(rect))); +} + template static Maybe> UntransformVector(const gfx::Matrix4x4& aTransform, const gfx::PointTyped& aVector, diff --git a/layout/base/gtest/moz.build b/layout/base/gtest/moz.build index 02f81487e3..81a300b18b 100644 --- a/layout/base/gtest/moz.build +++ b/layout/base/gtest/moz.build @@ -15,6 +15,9 @@ LOCAL_INCLUDES += [ '/layout/base' ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + # Workaround bug 1142396. Suppress the warning from gmock library for clang. if CONFIG['CLANG_CXX']: CXXFLAGS += ['-Wno-null-dereference'] diff --git a/layout/inspector/moz.build b/layout/inspector/moz.build index 74fcec6792..b3fe26690d 100644 --- a/layout/inspector/moz.build +++ b/layout/inspector/moz.build @@ -41,6 +41,9 @@ if CONFIG['MOZ_XUL']: 'inDOMView.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + FINAL_LIBRARY = 'xul' LOCAL_INCLUDES += [ '../style', diff --git a/memory/build/moz.build b/memory/build/moz.build index 3d6995b8c8..efeb9c8e42 100644 --- a/memory/build/moz.build +++ b/memory/build/moz.build @@ -62,3 +62,6 @@ if CONFIG['MOZ_MEMORY'] and (CONFIG['OS_TARGET'] in ('WINNT', 'Darwin', 'Android if CONFIG['MOZ_REPLACE_MALLOC'] and CONFIG['OS_TARGET'] == 'Darwin': # The zone allocator for OSX needs some jemalloc internal functions LOCAL_INCLUDES += ['/memory/jemalloc/src/include'] + +if CONFIG['GNU_CC']: + CFLAGS += ['-Wshadow'] diff --git a/memory/mozjemalloc/moz.build b/memory/mozjemalloc/moz.build index 1fefc2d73c..ffd74dbfa5 100644 --- a/memory/mozjemalloc/moz.build +++ b/memory/mozjemalloc/moz.build @@ -45,5 +45,8 @@ LOCAL_INCLUDES += [ # XXX: We should fix these warnings. ALLOW_COMPILER_WARNINGS = True +if CONFIG['GNU_CC']: + CFLAGS += ['-Wshadow'] + if CONFIG['_MSC_VER']: CFLAGS += ['-wd4273'] # inconsistent dll linkage (bug 558163) diff --git a/memory/replace/dummy/moz.build b/memory/replace/dummy/moz.build index 88b7d6fb61..89150974a4 100644 --- a/memory/replace/dummy/moz.build +++ b/memory/replace/dummy/moz.build @@ -12,3 +12,6 @@ SOURCES += [ SharedLibrary('replace_malloc') DISABLE_STL_WRAPPING = True + +if CONFIG['GNU_CC']: + CFLAGS += ['-Wshadow'] diff --git a/memory/replace/jemalloc/moz.build b/memory/replace/jemalloc/moz.build index bf458cbca3..1918de4763 100644 --- a/memory/replace/jemalloc/moz.build +++ b/memory/replace/jemalloc/moz.build @@ -33,3 +33,6 @@ if CONFIG['_MSC_VER']: LOCAL_INCLUDES += ['/memory/jemalloc/src/include/msvc_compat/C99'] DISABLE_STL_WRAPPING = True + +if CONFIG['GNU_CC']: + CFLAGS += ['-Wshadow'] diff --git a/netwerk/protocol/app/moz.build b/netwerk/protocol/app/moz.build index 5622db210a..80b16e3df8 100644 --- a/netwerk/protocol/app/moz.build +++ b/netwerk/protocol/app/moz.build @@ -8,6 +8,9 @@ SOURCES += [ 'AppProtocolHandler.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + FINAL_LIBRARY = 'xul' LOCAL_INCLUDES += [ '/caps', diff --git a/netwerk/protocol/device/moz.build b/netwerk/protocol/device/moz.build index 8975604a2d..037e5537e6 100644 --- a/netwerk/protocol/device/moz.build +++ b/netwerk/protocol/device/moz.build @@ -18,6 +18,9 @@ UNIFIED_SOURCES += [ 'nsDeviceProtocolHandler.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + include('/ipc/chromium/chromium-config.mozbuild') FINAL_LIBRARY = 'xul' diff --git a/netwerk/protocol/viewsource/moz.build b/netwerk/protocol/viewsource/moz.build index f54b4e2900..9de9a73128 100644 --- a/netwerk/protocol/viewsource/moz.build +++ b/netwerk/protocol/viewsource/moz.build @@ -15,6 +15,9 @@ UNIFIED_SOURCES += [ 'nsViewSourceHandler.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + FINAL_LIBRARY = 'xul' LOCAL_INCLUDES += [ '/netwerk/base', diff --git a/netwerk/socket/moz.build b/netwerk/socket/moz.build index c58687b394..ac09c0aa5c 100644 --- a/netwerk/socket/moz.build +++ b/netwerk/socket/moz.build @@ -21,4 +21,7 @@ UNIFIED_SOURCES += [ 'nsUDPSocketProvider.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + FINAL_LIBRARY = 'xul' diff --git a/parser/xml/moz.build b/parser/xml/moz.build index eb6e1982b2..484f6d1fe0 100644 --- a/parser/xml/moz.build +++ b/parser/xml/moz.build @@ -34,3 +34,6 @@ SOURCES += [ ] FINAL_LIBRARY = 'xul' + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/storage/build/moz.build b/storage/build/moz.build index 4ce624b535..e38a6b3352 100644 --- a/storage/build/moz.build +++ b/storage/build/moz.build @@ -12,6 +12,9 @@ SOURCES += [ 'mozStorageModule.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + FINAL_LIBRARY = 'xul' LOCAL_INCLUDES += [ diff --git a/toolkit/components/mediasniffer/moz.build b/toolkit/components/mediasniffer/moz.build index 18fbbaf93b..8b648b79cb 100644 --- a/toolkit/components/mediasniffer/moz.build +++ b/toolkit/components/mediasniffer/moz.build @@ -18,5 +18,9 @@ UNIFIED_SOURCES += [ FINAL_LIBRARY = 'xul' +if CONFIG['GNU_CC']: + CFLAGS += ['-Wshadow'] + CXXFLAGS += ['-Wshadow'] + with Files('**'): BUG_COMPONENT = ('Core', 'Video/Audio') diff --git a/view/moz.build b/view/moz.build index 9eb912620d..19a79c7818 100644 --- a/view/moz.build +++ b/view/moz.build @@ -15,6 +15,9 @@ SOURCES += [ 'nsViewManager.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + FINAL_LIBRARY = 'xul' CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS'] diff --git a/widget/gonk/OrientationObserver.cpp b/widget/gonk/OrientationObserver.cpp index 187ed337eb..1e55404d90 100644 --- a/widget/gonk/OrientationObserver.cpp +++ b/widget/gonk/OrientationObserver.cpp @@ -33,7 +33,7 @@ namespace { struct OrientationMapping { uint32_t mScreenRotation; - ScreenOrientation mDomOrientation; + ScreenOrientationInternal mDomOrientation; }; static OrientationMapping sOrientationMappings[] = { @@ -106,7 +106,7 @@ DetectDefaultOrientation() * @return NS_OK on success. NS_ILLEGAL_VALUE on failure. */ static nsresult -ConvertToScreenRotation(ScreenOrientation aOrientation, uint32_t *aResult) +ConvertToScreenRotation(ScreenOrientationInternal aOrientation, uint32_t *aResult) { for (int i = 0; i < ArrayLength(sOrientationMappings); i++) { if (aOrientation & sOrientationMappings[i].mDomOrientation) { @@ -132,7 +132,7 @@ ConvertToScreenRotation(ScreenOrientation aOrientation, uint32_t *aResult) * @return NS_OK on success. NS_ILLEGAL_VALUE on failure. */ nsresult -ConvertToDomOrientation(uint32_t aRotation, ScreenOrientation *aResult) +ConvertToDomOrientation(uint32_t aRotation, ScreenOrientationInternal *aResult) { for (int i = 0; i < ArrayLength(sOrientationMappings); i++) { if (aRotation == sOrientationMappings[i].mScreenRotation) { @@ -217,7 +217,7 @@ OrientationObserver::Notify(const hal::SensorData& aSensorData) return; } - ScreenOrientation orientation; + ScreenOrientationInternal orientation; if (NS_FAILED(ConvertToDomOrientation(rotation, &orientation))) { return; } @@ -259,7 +259,7 @@ OrientationObserver::DisableAutoOrientation() } bool -OrientationObserver::LockScreenOrientation(ScreenOrientation aOrientation) +OrientationObserver::LockScreenOrientation(ScreenOrientationInternal aOrientation) { MOZ_ASSERT(aOrientation | (eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary | @@ -295,7 +295,7 @@ OrientationObserver::LockScreenOrientation(ScreenOrientation aOrientation) nsresult rv = screen->GetRotation(&currRotation); NS_ENSURE_SUCCESS(rv, false); - ScreenOrientation currOrientation = eScreenOrientation_None; + ScreenOrientationInternal currOrientation = eScreenOrientation_None; rv = ConvertToDomOrientation(currRotation, &currOrientation); NS_ENSURE_SUCCESS(rv, false); @@ -314,7 +314,7 @@ OrientationObserver::LockScreenOrientation(ScreenOrientation aOrientation) NS_ENSURE_SUCCESS(rv, false); // This conversion will disambiguate aOrientation. - ScreenOrientation orientation; + ScreenOrientationInternal orientation; rv = ConvertToDomOrientation(rotation, &orientation); NS_ENSURE_SUCCESS(rv, false); diff --git a/widget/gonk/OrientationObserver.h b/widget/gonk/OrientationObserver.h index 4467daf2e6..c841ea8781 100644 --- a/widget/gonk/OrientationObserver.h +++ b/widget/gonk/OrientationObserver.h @@ -32,7 +32,7 @@ typedef mozilla::Observer ISensorObserver; using mozilla::hal::ISensorObserver; using mozilla::hal::SensorData; -using mozilla::dom::ScreenOrientation; +using mozilla::dom::ScreenOrientationInternal; class OrientationObserver : public ISensorObserver { public: @@ -51,7 +51,7 @@ public: void DisableAutoOrientation(); // Methods called by methods in hal_impl namespace. - bool LockScreenOrientation(ScreenOrientation aOrientation); + bool LockScreenOrientation(ScreenOrientationInternal aOrientation); void UnlockScreenOrientation(); static OrientationObserver* GetInstance(); diff --git a/widget/gonk/nsScreenManagerGonk.cpp b/widget/gonk/nsScreenManagerGonk.cpp index c9630f6767..f32568e41d 100644 --- a/widget/gonk/nsScreenManagerGonk.cpp +++ b/widget/gonk/nsScreenManagerGonk.cpp @@ -293,7 +293,7 @@ nsScreenGonk::EffectiveScreenRotation() // NB: This isn't gonk-specific, but gonk is the only widget backend // that does this calculation itself, currently. -static ScreenOrientation +static ScreenOrientationInternal ComputeOrientation(uint32_t aRotation, const nsIntSize& aScreenSize) { bool naturallyPortrait = (aScreenSize.height > aScreenSize.width); @@ -317,15 +317,24 @@ ComputeOrientation(uint32_t aRotation, const nsIntSize& aScreenSize) } } +static uint16_t +RotationToAngle(uint32_t aRotation) +{ + uint16_t angle = 90 * aRotation; + MOZ_ASSERT(angle == 0 || angle == 90 || angle == 180 || angle == 270); + return angle; +} + ScreenConfiguration nsScreenGonk::GetConfiguration() { - ScreenOrientation orientation = ComputeOrientation(mScreenRotation, - mNaturalBounds.Size()); + ScreenOrientationInternal orientation = ComputeOrientation(mScreenRotation, + mNaturalBounds.Size()); // NB: perpetuating colorDepth == pixelDepth illusion here, for // consistency. return ScreenConfiguration(mVirtualBounds, orientation, + RotationToAngle(mScreenRotation), mColorDepth, mColorDepth); } diff --git a/widget/gtkxtbin/moz.build b/widget/gtkxtbin/moz.build index c9aacf6256..f48932bd25 100644 --- a/widget/gtkxtbin/moz.build +++ b/widget/gtkxtbin/moz.build @@ -17,3 +17,6 @@ FINAL_LIBRARY = 'xul' DEFINES['_IMPL_GTKXTBIN_API'] = True CFLAGS += CONFIG['MOZ_GTK2_CFLAGS'] + +if CONFIG['GNU_CC']: + CFLAGS += ['-Wshadow'] diff --git a/widget/x11/moz.build b/widget/x11/moz.build index 5c7879bd1b..531a62ea5f 100644 --- a/widget/x11/moz.build +++ b/widget/x11/moz.build @@ -12,5 +12,8 @@ FINAL_LIBRARY = 'xul' CXXFLAGS += CONFIG['TK_CFLAGS'] +if CONFIG['GNU_CC']: + CFLAGS += ['-Wshadow'] + if CONFIG['MOZ_X11']: CFLAGS += CONFIG['XCFLAGS'] diff --git a/xpcom/base/SystemMemoryReporter.cpp b/xpcom/base/SystemMemoryReporter.cpp index 37ec77d682..3438686dbd 100644 --- a/xpcom/base/SystemMemoryReporter.cpp +++ b/xpcom/base/SystemMemoryReporter.cpp @@ -144,13 +144,13 @@ public: do { \ size_t amount = _amount; /* evaluate _amount only once */ \ if (amount > 0) { \ - nsresult rv; \ - rv = aHandleReport->Callback(NS_LITERAL_CSTRING("System"), _path, \ + nsresult rvReport; \ + rvReport = aHandleReport->Callback(NS_LITERAL_CSTRING("System"), _path, \ KIND_NONHEAP, _units, amount, _desc, \ aData); \ - if (NS_WARN_IF(NS_FAILED(rv))) { \ + if (NS_WARN_IF(NS_FAILED(rvReport))) { \ _cleanup; \ - return rv; \ + return rvReport; \ } \ } \ } while (0) @@ -373,14 +373,15 @@ private: char devMinor[17]; unsigned int inode; char line[1025]; + // This variable holds the path of the current entry, or is void // if we're scanning for the start of a new entry. - nsAutoCString path; + nsAutoCString currentPath; int pathOffset; - path.SetIsVoid(true); + currentPath.SetIsVoid(true); while (fgets(line, sizeof(line), aFile)) { - if (path.IsVoid()) { + if (currentPath.IsVoid()) { int n = sscanf(line, "%llx-%llx %4s %llx " "%16[0-9a-fA-F]:%16[0-9a-fA-F] %u %n", @@ -388,8 +389,8 @@ private: devMinor, &inode, &pathOffset); if (n >= argCount - 1) { - path.Assign(line + pathOffset); - path.StripChars("\n"); + currentPath.Assign(line + pathOffset); + currentPath.StripChars("\n"); } continue; } @@ -404,14 +405,14 @@ private: size_t pss = pss_kb * 1024; if (pss > 0) { nsAutoCString name, description, tag; - GetReporterNameAndDescription(path.get(), perms, name, description, tag); + GetReporterNameAndDescription(currentPath.get(), perms, name, description, tag); - nsAutoCString path("mem/processes/"); - path.Append(aProcessName); - path.Append('/'); - path.Append(name); + nsAutoCString processMemPath("mem/processes/"); + processMemPath.Append(aProcessName); + processMemPath.Append('/'); + processMemPath.Append(name); - REPORT(path, pss, description); + REPORT(processMemPath, pss, description); // Increment the appropriate aProcessSizes values, and the total. aProcessSizes->Add(tag, pss); @@ -419,7 +420,7 @@ private: } // Now that we've seen the PSS, we're done with this entry. - path.SetIsVoid(true); + currentPath.SetIsVoid(true); } return NS_OK; } diff --git a/xpcom/base/moz.build b/xpcom/base/moz.build index 27383bd4af..bc52cae41d 100644 --- a/xpcom/base/moz.build +++ b/xpcom/base/moz.build @@ -153,3 +153,6 @@ LOCAL_INCLUDES += [ if CONFIG['MOZ_WIDGET_GTK']: CXXFLAGS += CONFIG['TK_CFLAGS'] + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/xpcom/base/nsStatusReporterManager.cpp b/xpcom/base/nsStatusReporterManager.cpp index e851ef7a10..5677b071de 100644 --- a/xpcom/base/nsStatusReporterManager.cpp +++ b/xpcom/base/nsStatusReporterManager.cpp @@ -78,9 +78,9 @@ NS_STATUS_REPORTER_IMPLEMENT(StatusReporter, "StatusReporter State", getStatus) do { \ const char* s2 = (s); \ uint32_t dummy; \ - nsresult rv = (o)->Write((s2), strlen(s2), &dummy); \ - if (NS_WARN_IF(NS_FAILED(rv))) \ - return rv; \ + nsresult rvDump = (o)->Write((s2), strlen(s2), &dummy); \ + if (NS_WARN_IF(NS_FAILED(rvDump))) \ + return rvDump; \ } while (0) static nsresult diff --git a/xpcom/build/moz.build b/xpcom/build/moz.build index 0b3d1b2abb..614fd1a698 100644 --- a/xpcom/build/moz.build +++ b/xpcom/build/moz.build @@ -68,6 +68,10 @@ SOURCES += [ 'Omnijar.cpp', ] +if CONFIG['GNU_CC']: + CFLAGS += ['-Wshadow'] + CXXFLAGS += ['-Wshadow'] + include('/ipc/chromium/chromium-config.mozbuild') FINAL_LIBRARY = 'xul' diff --git a/xpcom/components/moz.build b/xpcom/components/moz.build index be1bede3bb..03a057f8da 100644 --- a/xpcom/components/moz.build +++ b/xpcom/components/moz.build @@ -39,6 +39,9 @@ UNIFIED_SOURCES += [ 'nsNativeModuleLoader.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + FINAL_LIBRARY = 'xul' GENERATED_INCLUDES += ['..'] diff --git a/xpcom/ds/moz.build b/xpcom/ds/moz.build index 257b6540b6..08056079e6 100644 --- a/xpcom/ds/moz.build +++ b/xpcom/ds/moz.build @@ -100,3 +100,6 @@ LOCAL_INCLUDES += [ ] FINAL_LIBRARY = 'xul' + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/xpcom/ds/nsVariant.cpp b/xpcom/ds/nsVariant.cpp index e2cac97e57..5d763b0aeb 100644 --- a/xpcom/ds/nsVariant.cpp +++ b/xpcom/ds/nsVariant.cpp @@ -1016,9 +1016,9 @@ nsDiscriminatedUnion::ConvertToStringWithSize(uint32_t* aSize, char** aStr) cons // *aSize = *mUTF8StringValue->Length(); // *aStr = ToNewCString(*mUTF8StringValue); // But this will have to do for now. - NS_ConvertUTF8toUTF16 tempString(*u.mUTF8StringValue); - *aSize = tempString.Length(); - *aStr = ToNewCString(tempString); + const NS_ConvertUTF8toUTF16 tempString16(*u.mUTF8StringValue); + *aSize = tempString16.Length(); + *aStr = ToNewCString(tempString16); break; } case nsIDataType::VTYPE_CHAR_STR: { diff --git a/xpcom/glue/GenericModule.cpp b/xpcom/glue/GenericModule.cpp index f2260a13f7..0b5cd3a7c2 100644 --- a/xpcom/glue/GenericModule.cpp +++ b/xpcom/glue/GenericModule.cpp @@ -50,17 +50,17 @@ GenericModule::RegisterSelf(nsIComponentManager* aCompMgr, const char* aLoaderStr, const char* aType) { - nsCOMPtr r = do_QueryInterface(aCompMgr); + nsCOMPtr registrar = do_QueryInterface(aCompMgr); for (const Module::CIDEntry* e = mData->mCIDs; e->cid; ++e) { - r->RegisterFactoryLocation(*e->cid, "", nullptr, aLocation, - aLoaderStr, aType); + registrar->RegisterFactoryLocation(*e->cid, "", nullptr, aLocation, + aLoaderStr, aType); } for (const Module::ContractIDEntry* e = mData->mContractIDs; e && e->contractid; ++e) { - r->RegisterFactoryLocation(*e->cid, "", e->contractid, aLocation, - aLoaderStr, aType); + registrar->RegisterFactoryLocation(*e->cid, "", e->contractid, aLocation, + aLoaderStr, aType); } nsCOMPtr catman; @@ -71,9 +71,9 @@ GenericModule::RegisterSelf(nsIComponentManager* aCompMgr, catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID); } - nsAutoCString r; + nsAutoCString prevValue; catman->AddCategoryEntry(e->category, e->entry, e->value, true, true, - getter_Copies(r)); + getter_Copies(prevValue)); } return NS_OK; } diff --git a/xpcom/glue/moz.build b/xpcom/glue/moz.build index de2bdedd2c..d4dddb5f8e 100644 --- a/xpcom/glue/moz.build +++ b/xpcom/glue/moz.build @@ -120,3 +120,6 @@ USE_LIBS += [ NO_EXPAND_LIBS = True DIST_INSTALL = True + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/xpcom/glue/nsCRTGlue.cpp b/xpcom/glue/nsCRTGlue.cpp index d95a0d69e4..1bc4377a3f 100644 --- a/xpcom/glue/nsCRTGlue.cpp +++ b/xpcom/glue/nsCRTGlue.cpp @@ -278,19 +278,19 @@ NS_IsAsciiDigit(char16_t aChar) return aChar >= '0' && aChar <= '9'; } - #ifndef XPCOM_GLUE_AVOID_NSPR -#define TABLE_SIZE 36 -static const char table[] = { - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', - 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', - 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', - '4', '5', '6', '7', '8', '9' -}; void NS_MakeRandomString(char* aBuf, int32_t aBufLen) { +#define TABLE_SIZE 36 + static const char table[] = { + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9' + }; + // turn PR_Now() into milliseconds since epoch // and salt rand with that. static unsigned int seed = 0; @@ -435,5 +435,3 @@ fprintf_stderr(FILE* aFile, const char* aFmt, ...) } va_end(args); } - - diff --git a/xpcom/glue/nsTArray-inl.h b/xpcom/glue/nsTArray-inl.h index dfc6f41af9..db4077b8f4 100644 --- a/xpcom/glue/nsTArray-inl.h +++ b/xpcom/glue/nsTArray-inl.h @@ -284,8 +284,8 @@ nsTArray_base::ShiftData(index_type aStart, aStart *= aElemSize; aNewLen *= aElemSize; aOldLen *= aElemSize; - char* base = reinterpret_cast(mHdr + 1) + aStart; - Copy::MoveElements(base + aNewLen, base + aOldLen, num, aElemSize); + char* baseAddr = reinterpret_cast(mHdr + 1) + aStart; + Copy::MoveElements(baseAddr + aNewLen, baseAddr + aOldLen, num, aElemSize); } } diff --git a/xpcom/glue/standalone/moz.build b/xpcom/glue/standalone/moz.build index f9dbfd979b..a9f1739037 100644 --- a/xpcom/glue/standalone/moz.build +++ b/xpcom/glue/standalone/moz.build @@ -43,6 +43,9 @@ LOCAL_INCLUDES += [ # Don't use STL wrappers here (i.e. wrapped ); they require mozalloc DISABLE_STL_WRAPPING = True +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + # Include fallible for third party code using the xpcom glue USE_LIBS += [ 'fallible', diff --git a/xpcom/glue/standalone/staticruntime/moz.build b/xpcom/glue/standalone/staticruntime/moz.build index f6182825c3..53296a33ce 100644 --- a/xpcom/glue/standalone/staticruntime/moz.build +++ b/xpcom/glue/standalone/staticruntime/moz.build @@ -38,6 +38,9 @@ USE_STATIC_LIBS = True # Don't use STL wrappers here (i.e. wrapped ); they require mozalloc DISABLE_STL_WRAPPING = True +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + # Include fallible for third party code using the xpcom glue USE_LIBS += [ 'fallible', diff --git a/xpcom/glue/tests/gtest/TestThreadUtils.cpp b/xpcom/glue/tests/gtest/TestThreadUtils.cpp index 9884d2b7e8..fc7509972f 100644 --- a/xpcom/glue/tests/gtest/TestThreadUtils.cpp +++ b/xpcom/glue/tests/gtest/TestThreadUtils.cpp @@ -289,20 +289,20 @@ TEST(ThreadUtils, main) // Test legacy functions. - nsCOMPtr r = + nsCOMPtr r1 = NS_NewRunnableMethod(rpt, &ThreadUtilsObject::Test0); - r->Run(); + r1->Run(); EXPECT_EQ(count += 1, rpt->mCount); - r = NS_NewRunnableMethodWithArg(rpt, &ThreadUtilsObject::Test1i, 11); - r->Run(); + r1 = NS_NewRunnableMethodWithArg(rpt, &ThreadUtilsObject::Test1i, 11); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(11, rpt->mA0); // Test variadic function with simple POD arguments. - r = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test0); - r->Run(); + r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test0); + r1->Run(); EXPECT_EQ(count += 1, rpt->mCount); static_assert( @@ -314,29 +314,29 @@ TEST(ThreadUtils, main) StoreCopyPassByValue>::value, "detail::ParameterStorage>::Type should be StoreCopyPassByValue"); - r = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1i, 12); - r->Run(); + r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1i, 12); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(12, rpt->mA0); - r = NS_NewRunnableMethodWithArgs( - rpt, &ThreadUtilsObject::Test2i, 21, 22); - r->Run(); + r1 = NS_NewRunnableMethodWithArgs( + rpt, &ThreadUtilsObject::Test2i, 21, 22); + r1->Run(); EXPECT_EQ(count += 3, rpt->mCount); EXPECT_EQ(21, rpt->mA0); EXPECT_EQ(22, rpt->mA1); - r = NS_NewRunnableMethodWithArgs( - rpt, &ThreadUtilsObject::Test3i, 31, 32, 33); - r->Run(); + r1 = NS_NewRunnableMethodWithArgs( + rpt, &ThreadUtilsObject::Test3i, 31, 32, 33); + r1->Run(); EXPECT_EQ(count += 4, rpt->mCount); EXPECT_EQ(31, rpt->mA0); EXPECT_EQ(32, rpt->mA1); EXPECT_EQ(33, rpt->mA2); - r = NS_NewRunnableMethodWithArgs( - rpt, &ThreadUtilsObject::Test4i, 41, 42, 43, 44); - r->Run(); + r1 = NS_NewRunnableMethodWithArgs( + rpt, &ThreadUtilsObject::Test4i, 41, 42, 43, 44); + r1->Run(); EXPECT_EQ(count += 5, rpt->mCount); EXPECT_EQ(41, rpt->mA0); EXPECT_EQ(42, rpt->mA1); @@ -347,8 +347,8 @@ TEST(ThreadUtils, main) // Passing a short to make sure forwarding works with an inexact type match. short int si = 11; - r = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1i, si); - r->Run(); + r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1i, si); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(si, rpt->mA0); @@ -373,8 +373,8 @@ TEST(ThreadUtils, main) "detail::ParameterStorage::Type::passed_type should be int*"); { int i = 12; - r = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1pi, &i); - r->Run(); + r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1pi, &i); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(i, rpt->mA0); } @@ -400,8 +400,8 @@ TEST(ThreadUtils, main) "detail::ParameterStorage::Type::passed_type should be const int*"); { int i = 1201; - r = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1pci, &i); - r->Run(); + r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1pci, &i); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(i, rpt->mA0); } @@ -415,9 +415,9 @@ TEST(ThreadUtils, main) "StoreCopyPassByPtr::passed_type should be int*"); { int i = 1202; - r = NS_NewRunnableMethodWithArgs>( - rpt, &ThreadUtilsObject::Test1pi, i); - r->Run(); + r1 = NS_NewRunnableMethodWithArgs>( + rpt, &ThreadUtilsObject::Test1pi, i); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(i, rpt->mA0); } @@ -431,9 +431,9 @@ TEST(ThreadUtils, main) "StoreCopyPassByConstPtr::passed_type should be const int*"); { int i = 1203; - r = NS_NewRunnableMethodWithArgs>( - rpt, &ThreadUtilsObject::Test1pci, i); - r->Run(); + r1 = NS_NewRunnableMethodWithArgs>( + rpt, &ThreadUtilsObject::Test1pci, i); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(i, rpt->mA0); } @@ -491,8 +491,8 @@ TEST(ThreadUtils, main) "ParameterStorage::Type::passed_type should be int&"); { int i = 13; - r = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1ri, i); - r->Run(); + r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1ri, i); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(i, rpt->mA0); } @@ -512,10 +512,10 @@ TEST(ThreadUtils, main) "ParameterStorage::Type::passed_type should be int&&"); { int i = 14; - r = NS_NewRunnableMethodWithArgs( + r1 = NS_NewRunnableMethodWithArgs( rpt, &ThreadUtilsObject::Test1rri, mozilla::Move(i)); } - r->Run(); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(14, rpt->mA0); @@ -534,10 +534,10 @@ TEST(ThreadUtils, main) "ParameterStorage&&>::Type::passed_type should be UniquePtr&&"); { mozilla::UniquePtr upi; - r = NS_NewRunnableMethodWithArgs&&>( + r1 = NS_NewRunnableMethodWithArgs&&>( rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); } - r->Run(); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(-1, rpt->mA0); rpt->mA0 = 0; @@ -557,48 +557,48 @@ TEST(ThreadUtils, main) "ParameterStorage>>::Type::passed_type should be UniquePtr&&"); { mozilla::UniquePtr upi; - r = NS_NewRunnableMethodWithArgs - >>( - rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); + r1 = NS_NewRunnableMethodWithArgs + >>( + rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); } - r->Run(); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(-1, rpt->mA0); // Unique pointer as xvalue. { mozilla::UniquePtr upi = mozilla::MakeUnique(1); - r = NS_NewRunnableMethodWithArgs&&>( - rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); + r1 = NS_NewRunnableMethodWithArgs&&>( + rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); } - r->Run(); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(1, rpt->mA0); { mozilla::UniquePtr upi = mozilla::MakeUnique(1); - r = NS_NewRunnableMethodWithArgs - >> - (rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); + r1 = NS_NewRunnableMethodWithArgs + >> + (rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); } - r->Run(); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(1, rpt->mA0); // Unique pointer as prvalue. - r = NS_NewRunnableMethodWithArgs&&>( - rpt, &ThreadUtilsObject::Test1upi, mozilla::MakeUnique(2)); - r->Run(); + r1 = NS_NewRunnableMethodWithArgs&&>( + rpt, &ThreadUtilsObject::Test1upi, mozilla::MakeUnique(2)); + r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(2, rpt->mA0); // Unique pointer as lvalue to lref. { mozilla::UniquePtr upi; - r = NS_NewRunnableMethodWithArgs&>( - rpt, &ThreadUtilsObject::Test1rupi, upi); + r1 = NS_NewRunnableMethodWithArgs&>( + rpt, &ThreadUtilsObject::Test1rupi, upi); // Passed as lref, so Run() must be called while local upi is still alive! - r->Run(); + r1->Run(); } EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(-1, rpt->mA0); @@ -608,15 +608,15 @@ TEST(ThreadUtils, main) Spy::ClearAll(); if (gDebug) { printf("%d - Test: Store copy from lvalue, pass by value\n", __LINE__); } { // Block around nsCOMPtr lifetime. - nsCOMPtr r; + nsCOMPtr r2; { // Block around Spy lifetime. if (gDebug) { printf("%d - Spy s(10)\n", __LINE__); } Spy s(10); EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); - if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs>(&TestByValue, s)\n", __LINE__); } - r = NS_NewRunnableMethodWithArgs>( - rpt, &ThreadUtilsObject::TestByValue, s); + if (gDebug) { printf("%d - r2 = NS_NewRunnableMethodWithArgs>(&TestByValue, s)\n", __LINE__); } + r2 = NS_NewRunnableMethodWithArgs>( + rpt, &ThreadUtilsObject::TestByValue, s); EXPECT_EQ(2, gAlive); EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction. Spy::ClearActions(); @@ -626,7 +626,7 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gAlive); Spy::ClearActions(); if (gDebug) { printf("%d - Run()\n", __LINE__); } - r->Run(); + r2->Run(); EXPECT_LE(1, gCopyConstructions); // Another copy-construction in call. EXPECT_EQ(10, rpt->mSpy.mID); EXPECT_LE(1, gDestructions); @@ -641,8 +641,8 @@ TEST(ThreadUtils, main) Spy::ClearAll(); if (gDebug) { printf("%d - Test: Store copy from prvalue, pass by value\n", __LINE__); } { - if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs>(&TestByValue, Spy(11))\n", __LINE__); } - nsCOMPtr r = + if (gDebug) { printf("%d - r3 = NS_NewRunnableMethodWithArgs>(&TestByValue, Spy(11))\n", __LINE__); } + nsCOMPtr r3 = NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::TestByValue, Spy(11)); EXPECT_EQ(1, gAlive); @@ -650,7 +650,7 @@ TEST(ThreadUtils, main) EXPECT_LE(1, gMoveConstructions); Spy::ClearActions(); if (gDebug) { printf("%d - Run()\n", __LINE__); } - r->Run(); + r3->Run(); EXPECT_LE(1, gCopyConstructions); // Another copy-construction in call. EXPECT_EQ(11, rpt->mSpy.mID); EXPECT_LE(1, gDestructions); @@ -664,13 +664,13 @@ TEST(ThreadUtils, main) Spy::ClearAll(); { // Store copy from xvalue, pass by value. - nsCOMPtr r; + nsCOMPtr r4; { Spy s(12); EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); Spy::ClearActions(); - r = NS_NewRunnableMethodWithArgs>( + r4 = NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::TestByValue, mozilla::Move(s)); EXPECT_LE(1, gMoveConstructions); EXPECT_EQ(1, gAlive); @@ -681,7 +681,7 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gAlive); EXPECT_EQ(0, gZombies); Spy::ClearActions(); - r->Run(); + r4->Run(); EXPECT_LE(1, gCopyConstructions); // Another copy-construction in call. EXPECT_EQ(12, rpt->mSpy.mID); EXPECT_LE(1, gDestructions); @@ -695,15 +695,15 @@ TEST(ThreadUtils, main) Spy::ClearAll(); if (gDebug) { printf("%d - Test: Store copy from lvalue, pass by const lvalue ref\n", __LINE__); } { // Block around nsCOMPtr lifetime. - nsCOMPtr r; + nsCOMPtr r5; { // Block around Spy lifetime. if (gDebug) { printf("%d - Spy s(20)\n", __LINE__); } Spy s(20); EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); - if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs>(&TestByConstLRef, s)\n", __LINE__); } - r = NS_NewRunnableMethodWithArgs>( - rpt, &ThreadUtilsObject::TestByConstLRef, s); + if (gDebug) { printf("%d - r5 = NS_NewRunnableMethodWithArgs>(&TestByConstLRef, s)\n", __LINE__); } + r5 = NS_NewRunnableMethodWithArgs>( + rpt, &ThreadUtilsObject::TestByConstLRef, s); EXPECT_EQ(2, gAlive); EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction. Spy::ClearActions(); @@ -713,7 +713,7 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gAlive); Spy::ClearActions(); if (gDebug) { printf("%d - Run()\n", __LINE__); } - r->Run(); + r5->Run(); EXPECT_EQ(0, gCopyConstructions); // No copies in call. EXPECT_EQ(20, rpt->mSpy.mID); EXPECT_EQ(0, gDestructions); @@ -728,8 +728,8 @@ TEST(ThreadUtils, main) Spy::ClearAll(); if (gDebug) { printf("%d - Test: Store copy from prvalue, pass by const lvalue ref\n", __LINE__); } { - if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs>(&TestByConstLRef, Spy(21))\n", __LINE__); } - nsCOMPtr r = + if (gDebug) { printf("%d - r6 = NS_NewRunnableMethodWithArgs>(&TestByConstLRef, Spy(21))\n", __LINE__); } + nsCOMPtr r6 = NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::TestByConstLRef, Spy(21)); EXPECT_EQ(1, gAlive); @@ -737,7 +737,7 @@ TEST(ThreadUtils, main) EXPECT_LE(1, gMoveConstructions); Spy::ClearActions(); if (gDebug) { printf("%d - Run()\n", __LINE__); } - r->Run(); + r6->Run(); EXPECT_EQ(0, gCopyConstructions); // No copies in call. EXPECT_EQ(21, rpt->mSpy.mID); EXPECT_EQ(0, gDestructions); @@ -752,15 +752,15 @@ TEST(ThreadUtils, main) Spy::ClearAll(); if (gDebug) { printf("%d - Test: Store copy from lvalue, pass by rvalue ref\n", __LINE__); } { // Block around nsCOMPtr lifetime. - nsCOMPtr r; + nsCOMPtr r7; { // Block around Spy lifetime. if (gDebug) { printf("%d - Spy s(30)\n", __LINE__); } Spy s(30); EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); - if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs>(&TestByRRef, s)\n", __LINE__); } - r = NS_NewRunnableMethodWithArgs>( - rpt, &ThreadUtilsObject::TestByRRef, s); + if (gDebug) { printf("%d - r7 = NS_NewRunnableMethodWithArgs>(&TestByRRef, s)\n", __LINE__); } + r7 = NS_NewRunnableMethodWithArgs>( + rpt, &ThreadUtilsObject::TestByRRef, s); EXPECT_EQ(2, gAlive); EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction. Spy::ClearActions(); @@ -770,7 +770,7 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gAlive); Spy::ClearActions(); if (gDebug) { printf("%d - Run()\n", __LINE__); } - r->Run(); + r7->Run(); EXPECT_LE(1, gMoves); // Move in call. EXPECT_EQ(30, rpt->mSpy.mID); EXPECT_EQ(0, gDestructions); @@ -786,8 +786,8 @@ TEST(ThreadUtils, main) Spy::ClearAll(); if (gDebug) { printf("%d - Test: Store copy from prvalue, pass by rvalue ref\n", __LINE__); } { - if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs>(&TestByRRef, Spy(31))\n", __LINE__); } - nsCOMPtr r = + if (gDebug) { printf("%d - r8 = NS_NewRunnableMethodWithArgs>(&TestByRRef, Spy(31))\n", __LINE__); } + nsCOMPtr r8 = NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::TestByRRef, Spy(31)); EXPECT_EQ(1, gAlive); @@ -795,7 +795,7 @@ TEST(ThreadUtils, main) EXPECT_LE(1, gMoveConstructions); Spy::ClearActions(); if (gDebug) { printf("%d - Run()\n", __LINE__); } - r->Run(); + r8->Run(); EXPECT_LE(1, gMoves); // Move in call. EXPECT_EQ(31, rpt->mSpy.mID); EXPECT_EQ(0, gDestructions); @@ -816,8 +816,8 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); Spy::ClearActions(); - if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs(&TestByLRef, s)\n", __LINE__); } - nsCOMPtr r = + if (gDebug) { printf("%d - r9 = NS_NewRunnableMethodWithArgs(&TestByLRef, s)\n", __LINE__); } + nsCOMPtr r9 = NS_NewRunnableMethodWithArgs( rpt, &ThreadUtilsObject::TestByLRef, s); EXPECT_EQ(0, gAllConstructions); @@ -825,7 +825,7 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gAlive); Spy::ClearActions(); if (gDebug) { printf("%d - Run()\n", __LINE__); } - r->Run(); + r9->Run(); EXPECT_LE(1, gAssignments); // Assignment from reference in call. EXPECT_EQ(40, rpt->mSpy.mID); EXPECT_EQ(&s, rpt->mSpyPtr); @@ -841,7 +841,7 @@ TEST(ThreadUtils, main) Spy::ClearAll(); if (gDebug) { printf("%d - Test: Store nsRefPtr, pass by pointer\n", __LINE__); } { // Block around nsCOMPtr lifetime. - nsCOMPtr r; + nsCOMPtr r10; SpyWithISupports* ptr = 0; { // Block around nsRefPtr lifetime. if (gDebug) { printf("%d - nsRefPtr s(new SpyWithISupports(45))\n", __LINE__); } @@ -849,9 +849,9 @@ TEST(ThreadUtils, main) ptr = s.get(); EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); - if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs>(&TestByRRef, s.get())\n", __LINE__); } - r = NS_NewRunnableMethodWithArgs>( - rpt, &ThreadUtilsObject::TestByPointer, s.get()); + if (gDebug) { printf("%d - r10 = NS_NewRunnableMethodWithArgs>(&TestByRRef, s.get())\n", __LINE__); } + r10 = NS_NewRunnableMethodWithArgs>( + rpt, &ThreadUtilsObject::TestByPointer, s.get()); EXPECT_LE(0, gAllConstructions); EXPECT_EQ(1, gAlive); Spy::ClearActions(); @@ -861,7 +861,7 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gAlive); Spy::ClearActions(); if (gDebug) { printf("%d - Run()\n", __LINE__); } - r->Run(); + r10->Run(); EXPECT_LE(1, gAssignments); // Assignment from pointee in call. EXPECT_EQ(45, rpt->mSpy.mID); EXPECT_EQ(ptr, rpt->mSpyPtr); @@ -882,8 +882,8 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); Spy::ClearActions(); - if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs(&TestByPointer, s)\n", __LINE__); } - nsCOMPtr r = + if (gDebug) { printf("%d - r11 = NS_NewRunnableMethodWithArgs(&TestByPointer, s)\n", __LINE__); } + nsCOMPtr r11 = NS_NewRunnableMethodWithArgs( rpt, &ThreadUtilsObject::TestByPointer, &s); EXPECT_EQ(0, gAllConstructions); @@ -891,7 +891,7 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gAlive); Spy::ClearActions(); if (gDebug) { printf("%d - Run()\n", __LINE__); } - r->Run(); + r11->Run(); EXPECT_LE(1, gAssignments); // Assignment from pointee in call. EXPECT_EQ(55, rpt->mSpy.mID); EXPECT_EQ(&s, rpt->mSpyPtr); @@ -912,8 +912,8 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); Spy::ClearActions(); - if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs(&TestByPointer, s)\n", __LINE__); } - nsCOMPtr r = + if (gDebug) { printf("%d - r12 = NS_NewRunnableMethodWithArgs(&TestByPointer, s)\n", __LINE__); } + nsCOMPtr r12 = NS_NewRunnableMethodWithArgs( rpt, &ThreadUtilsObject::TestByPointerToConst, &s); EXPECT_EQ(0, gAllConstructions); @@ -921,7 +921,7 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gAlive); Spy::ClearActions(); if (gDebug) { printf("%d - Run()\n", __LINE__); } - r->Run(); + r12->Run(); EXPECT_LE(1, gAssignments); // Assignment from pointee in call. EXPECT_EQ(60, rpt->mSpy.mID); EXPECT_EQ(&s, rpt->mSpyPtr); diff --git a/xpcom/io/moz.build b/xpcom/io/moz.build index 0d78404ddd..f05e7850c0 100644 --- a/xpcom/io/moz.build +++ b/xpcom/io/moz.build @@ -123,6 +123,10 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': 'CocoaFileUtils.mm', ] +if CONFIG['GNU_CC']: + CFLAGS += ['-Wshadow'] + CXXFLAGS += ['-Wshadow'] + include('/ipc/chromium/chromium-config.mozbuild') FINAL_LIBRARY = 'xul' diff --git a/xpcom/io/nsEscape.cpp b/xpcom/io/nsEscape.cpp index fd719c6c0a..5485dc36d1 100644 --- a/xpcom/io/nsEscape.cpp +++ b/xpcom/io/nsEscape.cpp @@ -12,7 +12,8 @@ #include "nsCRT.h" #include "plstr.h" -static const char hexChars[] = "0123456789ABCDEF"; +static const char hexCharsUpper[] = "0123456789ABCDEF"; +static const char hexCharsUpperLower[] = "0123456789ABCDEFabcdef"; static const int netCharType[256] = /* Bit 0 xalpha -- the alphas @@ -51,8 +52,8 @@ AppendPercentHex(char* aBuffer, unsigned char aChar) { uint32_t i = 0; aBuffer[i++] = '%'; - aBuffer[i++] = hexChars[aChar >> 4]; // high nibble - aBuffer[i++] = hexChars[aChar & 0xF]; // low nibble + aBuffer[i++] = hexCharsUpper[aChar >> 4]; // high nibble + aBuffer[i++] = hexCharsUpper[aChar & 0xF]; // low nibble return i; } @@ -63,11 +64,11 @@ AppendPercentHex(char16_t* aBuffer, char16_t aChar) aBuffer[i++] = '%'; if (aChar & 0xff00) { aBuffer[i++] = 'u'; - aBuffer[i++] = hexChars[aChar >> 12]; // high-byte high nibble - aBuffer[i++] = hexChars[(aChar >> 8) & 0xF]; // high-byte low nibble + aBuffer[i++] = hexCharsUpper[aChar >> 12]; // high-byte high nibble + aBuffer[i++] = hexCharsUpper[(aChar >> 8) & 0xF]; // high-byte low nibble } - aBuffer[i++] = hexChars[(aChar >> 4) & 0xF]; // low-byte high nibble - aBuffer[i++] = hexChars[aChar & 0xF]; // low-byte low nibble + aBuffer[i++] = hexCharsUpper[(aChar >> 4) & 0xF]; // low-byte high nibble + aBuffer[i++] = hexCharsUpper[aChar & 0xF]; // low-byte low nibble return i; } @@ -127,8 +128,8 @@ nsEscapeCount(const char* aStr, nsEscapeMask aFlags, size_t* aOutLen) *dst++ = '+'; /* convert spaces to pluses */ } else { *dst++ = HEX_ESCAPE; - *dst++ = hexChars[c >> 4]; /* high nibble */ - *dst++ = hexChars[c & 0x0f]; /* low nibble */ + *dst++ = hexCharsUpper[c >> 4]; /* high nibble */ + *dst++ = hexCharsUpper[c & 0x0f]; /* low nibble */ } } } else { @@ -138,8 +139,8 @@ nsEscapeCount(const char* aStr, nsEscapeMask aFlags, size_t* aOutLen) *dst++ = c; } else { *dst++ = HEX_ESCAPE; - *dst++ = hexChars[c >> 4]; /* high nibble */ - *dst++ = hexChars[c & 0x0f]; /* low nibble */ + *dst++ = hexCharsUpper[c >> 4]; /* high nibble */ + *dst++ = hexCharsUpper[c & 0x0f]; /* low nibble */ } } } @@ -178,7 +179,6 @@ nsUnescapeCount(char* aStr) { char* src = aStr; char* dst = aStr; - static const char hexChars[] = "0123456789ABCDEFabcdef"; char c1[] = " "; char c2[] = " "; @@ -200,8 +200,8 @@ nsUnescapeCount(char* aStr) c2[0] = *(src + 2); } - if (*src != HEX_ESCAPE || PL_strpbrk(pc1, hexChars) == 0 || - PL_strpbrk(pc2, hexChars) == 0) { + if (*src != HEX_ESCAPE || PL_strpbrk(pc1, hexCharsUpperLower) == 0 || + PL_strpbrk(pc2, hexCharsUpperLower) == 0) { *dst++ = *src++; } else { src++; /* walk over escape */ @@ -501,7 +501,7 @@ NS_EscapeURL(const nsAFlatString& aStr, const nsTArray& aForbidden, nsSubstring& aResult) { bool didEscape = false; - for (size_t i = 0, len = aStr.Length(); i < len; ) { + for (size_t i = 0, strLen = aStr.Length(); i < strLen; ) { size_t j; if (MOZ_UNLIKELY(FindFirstMatchFrom(aStr, i, aForbidden, &j))) { if (i == 0) { @@ -514,14 +514,14 @@ NS_EscapeURL(const nsAFlatString& aStr, const nsTArray& aForbidden, aResult.Append(nsDependentSubstring(aStr, i, j - i)); } char16_t buffer[ENCODE_MAX_LEN]; - uint32_t len = ::AppendPercentHex(buffer, aStr[j]); - MOZ_ASSERT(len <= ENCODE_MAX_LEN, "buffer overflow"); - aResult.Append(buffer, len); + uint32_t bufferLen = ::AppendPercentHex(buffer, aStr[j]); + MOZ_ASSERT(bufferLen <= ENCODE_MAX_LEN, "buffer overflow"); + aResult.Append(buffer, bufferLen); i = j + 1; } else { if (MOZ_UNLIKELY(didEscape)) { // The tail of the string that needs no escaping. - aResult.Append(nsDependentSubstring(aStr, i, len - i)); + aResult.Append(nsDependentSubstring(aStr, i, strLen - i)); } break; } @@ -532,7 +532,7 @@ NS_EscapeURL(const nsAFlatString& aStr, const nsTArray& aForbidden, return aStr; } -#define ISHEX(c) memchr(hexChars, c, sizeof(hexChars)-1) +#define ISHEX(c) memchr(hexCharsUpperLower, c, sizeof(hexCharsUpperLower)-1) bool NS_UnescapeURL(const char* aStr, int32_t aLen, uint32_t aFlags, @@ -552,8 +552,6 @@ NS_UnescapeURL(const char* aStr, int32_t aLen, uint32_t aFlags, bool writing = !!(aFlags & esc_AlwaysCopy); bool skipControl = !!(aFlags & esc_SkipControl); - static const char hexChars[] = "0123456789ABCDEFabcdef"; - const char* last = aStr; const char* p = aStr; diff --git a/xpcom/io/nsLocalFileCommon.cpp b/xpcom/io/nsLocalFileCommon.cpp index 6c2c60c614..acdd7a9436 100644 --- a/xpcom/io/nsLocalFileCommon.cpp +++ b/xpcom/io/nsLocalFileCommon.cpp @@ -138,9 +138,9 @@ nsLocalFile::CreateUnique(uint32_t aType, uint32_t aAttributes) rootName.SetLength(maxRootLength); SetNativeLeafName(rootName + suffix); #endif - nsresult rv = Create(aType, aAttributes); - if (rv != NS_ERROR_FILE_ALREADY_EXISTS) { - return rv; + nsresult rvCreate = Create(aType, aAttributes); + if (rvCreate != NS_ERROR_FILE_ALREADY_EXISTS) { + return rvCreate; } } diff --git a/xpcom/io/nsMultiplexInputStream.cpp b/xpcom/io/nsMultiplexInputStream.cpp index 4b61d5108c..69f63f5c76 100644 --- a/xpcom/io/nsMultiplexInputStream.cpp +++ b/xpcom/io/nsMultiplexInputStream.cpp @@ -99,8 +99,8 @@ AvailableMaybeSeek(nsIInputStream* aStream, uint64_t* aResult) // Seek() could reopen the file if REOPEN_ON_REWIND flag is set. nsCOMPtr seekable = do_QueryInterface(aStream); if (seekable) { - nsresult rv = seekable->Seek(nsISeekableStream::NS_SEEK_CUR, 0); - if (NS_SUCCEEDED(rv)) { + nsresult rvSeek = seekable->Seek(nsISeekableStream::NS_SEEK_CUR, 0); + if (NS_SUCCEEDED(rvSeek)) { rv = aStream->Available(aResult); } } @@ -117,8 +117,8 @@ TellMaybeSeek(nsISeekableStream* aSeekable, int64_t* aResult) // NS_BASE_STREAM_CLOSED. // If nsIFileInputStream is closed in Read() due to CLOSE_ON_EOF flag, // Seek() could reopen the file if REOPEN_ON_REWIND flag is set. - nsresult rv = aSeekable->Seek(nsISeekableStream::NS_SEEK_CUR, 0); - if (NS_SUCCEEDED(rv)) { + nsresult rvSeek = aSeekable->Seek(nsISeekableStream::NS_SEEK_CUR, 0); + if (NS_SUCCEEDED(rvSeek)) { rv = aSeekable->Tell(aResult); } } @@ -828,4 +828,3 @@ nsMultiplexInputStream::Clone(nsIInputStream** aClone) clone.forget(aClone); return NS_OK; } - diff --git a/xpcom/io/nsPipe3.cpp b/xpcom/io/nsPipe3.cpp index 3522d99963..803274acc8 100644 --- a/xpcom/io/nsPipe3.cpp +++ b/xpcom/io/nsPipe3.cpp @@ -81,9 +81,7 @@ public: inline void NotifyInputReady(nsIAsyncInputStream* aStream, nsIInputStreamCallback* aCallback) { - NS_ASSERTION(!mInputCallback, "already have an input event"); - mInputStream = aStream; - mInputCallback = aCallback; + mInputList.AppendElement(InputEntry(aStream, aCallback)); } inline void NotifyOutputReady(nsIAsyncOutputStream* aStream, @@ -95,8 +93,22 @@ public: } private: - nsCOMPtr mInputStream; - nsCOMPtr mInputCallback; + struct InputEntry + { + InputEntry(nsIAsyncInputStream* aStream, nsIInputStreamCallback* aCallback) + : mStream(aStream) + , mCallback(aCallback) + { + MOZ_ASSERT(mStream); + MOZ_ASSERT(mCallback); + } + + nsCOMPtr mStream; + nsCOMPtr mCallback; + }; + + nsTArray mInputList; + nsCOMPtr mOutputStream; nsCOMPtr mOutputCallback; }; @@ -1082,15 +1094,15 @@ nsPipeEvents::~nsPipeEvents() { // dispatch any pending events - if (mInputCallback) { - mInputCallback->OnInputStreamReady(mInputStream); - mInputCallback = 0; - mInputStream = 0; + for (uint32_t i = 0; i < mInputList.Length(); ++i) { + mInputList[i].mCallback->OnInputStreamReady(mInputList[i].mStream); } + mInputList.Clear(); + if (mOutputCallback) { mOutputCallback->OnOutputStreamReady(mOutputStream); - mOutputCallback = 0; - mOutputStream = 0; + mOutputCallback = nullptr; + mOutputStream = nullptr; } } diff --git a/xpcom/libxpcomrt/moz.build b/xpcom/libxpcomrt/moz.build index 8f1c0dec5b..c2e0884ab0 100644 --- a/xpcom/libxpcomrt/moz.build +++ b/xpcom/libxpcomrt/moz.build @@ -138,3 +138,6 @@ DEFINES['MOZILLA_EXTERNAL_LINKAGE'] = True include('/ipc/chromium/chromium-config.mozbuild') SPHINX_TREES['libxpcomrt'] = 'docs' + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/xpcom/reflect/xptcall/md/unix/moz.build b/xpcom/reflect/xptcall/md/unix/moz.build index 62a7e9a27c..8c37b308d3 100644 --- a/xpcom/reflect/xptcall/md/unix/moz.build +++ b/xpcom/reflect/xptcall/md/unix/moz.build @@ -323,3 +323,6 @@ LOCAL_INCLUDES += [ ] NO_PGO = True + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp b/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp index db92c3c3ed..07af453ce9 100644 --- a/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp +++ b/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp @@ -603,11 +603,11 @@ xptiInterfaceEntry::GetInterfaceIsArgNumberForParam(uint16_t methodIndex, return NS_OK; } -nsresult -xptiInterfaceEntry::IsIID(const nsIID * IID, bool *_retval) +nsresult +xptiInterfaceEntry::IsIID(const nsIID * iid, bool *_retval) { // It is not necessary to Resolve because this info is read from manifest. - *_retval = mIID.Equals(*IID); + *_retval = mIID.Equals(*iid); return NS_OK; } diff --git a/xpcom/string/moz.build b/xpcom/string/moz.build index aa3516b752..8e6096a806 100644 --- a/xpcom/string/moz.build +++ b/xpcom/string/moz.build @@ -57,3 +57,6 @@ if CONFIG['INTEL_ARCHITECTURE']: SOURCES['nsUTF8UtilsSSE2.cpp'].flags += CONFIG['SSE2_FLAGS'] FINAL_LIBRARY = 'xul' + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/xpcom/tests/TestHashtables.cpp b/xpcom/tests/TestHashtables.cpp index d6ada3f2a7..43c719c452 100644 --- a/xpcom/tests/TestHashtables.cpp +++ b/xpcom/tests/TestHashtables.cpp @@ -639,10 +639,10 @@ main(void) { printf("FAILED\n"); exit (30); } - - nsAutoCString str; - myEnt->GetString(str); - printf("Found %s\n", str.get()); + + nsAutoCString myEntStr; + myEnt->GetString(myEntStr); + printf("Found %s\n", myEntStr.get()); } printf("Testing nonexistent entries..."); diff --git a/xpcom/tests/TestRacingServiceManager.cpp b/xpcom/tests/TestRacingServiceManager.cpp index 5051b4aabd..b1cb6a033b 100644 --- a/xpcom/tests/TestRacingServiceManager.cpp +++ b/xpcom/tests/TestRacingServiceManager.cpp @@ -259,7 +259,7 @@ int main(int argc, char** argv) ScopedXPCOM xpcom("RacingServiceManager"); NS_ENSURE_FALSE(xpcom.failed(), 1); - AutoCreateAndDestroyReentrantMonitor mon(&gReentrantMonitor); + AutoCreateAndDestroyReentrantMonitor mon1(&gReentrantMonitor); nsRefPtr runnable = new Runnable(); NS_ENSURE_TRUE(runnable, 1); @@ -270,13 +270,13 @@ int main(int argc, char** argv) NS_ENSURE_SUCCESS(rv, 1); { - ReentrantMonitorAutoEnter mon(*gReentrantMonitor); + ReentrantMonitorAutoEnter mon2(*gReentrantMonitor); gMainThreadWaiting = true; - mon.Notify(); + mon2.Notify(); while (!gCreateInstanceCalled) { - mon.Wait(); + mon2.Wait(); } } @@ -292,13 +292,13 @@ int main(int argc, char** argv) NS_ENSURE_SUCCESS(rv, 1); { - ReentrantMonitorAutoEnter mon(*gReentrantMonitor); + ReentrantMonitorAutoEnter mon3(*gReentrantMonitor); gMainThreadWaiting = true; - mon.Notify(); + mon3.Notify(); while (!gCreateInstanceCalled) { - mon.Wait(); + mon3.Wait(); } } diff --git a/xpcom/tests/bug656331_component/moz.build b/xpcom/tests/bug656331_component/moz.build index a8f34881dc..3683f1ac3a 100644 --- a/xpcom/tests/bug656331_component/moz.build +++ b/xpcom/tests/bug656331_component/moz.build @@ -21,3 +21,6 @@ DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % ( # Need to link with CoreFoundation on Mac if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': OS_LIBS += CONFIG['TK_LIBS'] + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/xpcom/tests/gtest/Helpers.cpp b/xpcom/tests/gtest/Helpers.cpp index 8a98a5aa09..e06ef901b8 100644 --- a/xpcom/tests/gtest/Helpers.cpp +++ b/xpcom/tests/gtest/Helpers.cpp @@ -112,4 +112,22 @@ OutputStreamCallback::OnOutputStreamReady(nsIAsyncOutputStream* aStream) return NS_OK; } +NS_IMPL_ISUPPORTS(InputStreamCallback, nsIInputStreamCallback); + +InputStreamCallback::InputStreamCallback() + : mCalled(false) +{ +} + +InputStreamCallback::~InputStreamCallback() +{ +} + +NS_IMETHODIMP +InputStreamCallback::OnInputStreamReady(nsIAsyncInputStream* aStream) +{ + mCalled = true; + return NS_OK; +} + } // namespace testing diff --git a/xpcom/tests/gtest/Helpers.h b/xpcom/tests/gtest/Helpers.h index 186ce5ccd0..a831f6e0ca 100644 --- a/xpcom/tests/gtest/Helpers.h +++ b/xpcom/tests/gtest/Helpers.h @@ -7,6 +7,7 @@ #ifndef __Helpers_h #define __Helpers_h +#include "nsIAsyncInputStream.h" #include "nsIAsyncOutputStream.h" #include "nsString.h" #include @@ -51,6 +52,22 @@ public: NS_DECL_NSIOUTPUTSTREAMCALLBACK }; +class InputStreamCallback final : public nsIInputStreamCallback +{ +public: + InputStreamCallback(); + + bool Called() const { return mCalled; } + +private: + ~InputStreamCallback(); + + bool mCalled; +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIINPUTSTREAMCALLBACK +}; + } // namespace testing #endif // __Helpers_h diff --git a/xpcom/tests/gtest/TestPipes.cpp b/xpcom/tests/gtest/TestPipes.cpp index 5cded29b7b..d17c8b781f 100644 --- a/xpcom/tests/gtest/TestPipes.cpp +++ b/xpcom/tests/gtest/TestPipes.cpp @@ -786,6 +786,88 @@ TEST(Pipes, Write_AsyncWait_Clone_CloseOriginal) ASSERT_TRUE(cb->Called()); } +TEST(Pipes, Read_AsyncWait) +{ + nsCOMPtr reader; + nsCOMPtr writer; + + const uint32_t segmentSize = 1024; + const uint32_t numSegments = 1; + + nsresult rv = NS_NewPipe2(getter_AddRefs(reader), getter_AddRefs(writer), + true, true, // non-blocking - reader, writer + segmentSize, numSegments); + ASSERT_TRUE(NS_SUCCEEDED(rv)); + + nsTArray inputData; + testing::CreateData(segmentSize, inputData); + + nsRefPtr cb = + new testing::InputStreamCallback(); + + rv = reader->AsyncWait(cb, 0, 0, nullptr); + ASSERT_TRUE(NS_SUCCEEDED(rv)); + + ASSERT_FALSE(cb->Called()); + + uint32_t numWritten = 0; + rv = writer->Write(inputData.Elements(), inputData.Length(), &numWritten); + ASSERT_TRUE(NS_SUCCEEDED(rv)); + + ASSERT_TRUE(cb->Called()); + + testing::ConsumeAndValidateStream(reader, inputData); +} + +TEST(Pipes, Read_AsyncWait_Clone) +{ + nsCOMPtr reader; + nsCOMPtr writer; + + const uint32_t segmentSize = 1024; + const uint32_t numSegments = 1; + + nsresult rv = NS_NewPipe2(getter_AddRefs(reader), getter_AddRefs(writer), + true, true, // non-blocking - reader, writer + segmentSize, numSegments); + ASSERT_TRUE(NS_SUCCEEDED(rv)); + + nsCOMPtr clone; + rv = NS_CloneInputStream(reader, getter_AddRefs(clone)); + ASSERT_TRUE(NS_SUCCEEDED(rv)); + + nsCOMPtr asyncClone = do_QueryInterface(clone); + ASSERT_TRUE(asyncClone); + + nsTArray inputData; + testing::CreateData(segmentSize, inputData); + + nsRefPtr cb = + new testing::InputStreamCallback(); + + nsRefPtr cb2 = + new testing::InputStreamCallback(); + + rv = reader->AsyncWait(cb, 0, 0, nullptr); + ASSERT_TRUE(NS_SUCCEEDED(rv)); + + ASSERT_FALSE(cb->Called()); + + rv = asyncClone->AsyncWait(cb2, 0, 0, nullptr); + ASSERT_TRUE(NS_SUCCEEDED(rv)); + + ASSERT_FALSE(cb2->Called()); + + uint32_t numWritten = 0; + rv = writer->Write(inputData.Elements(), inputData.Length(), &numWritten); + ASSERT_TRUE(NS_SUCCEEDED(rv)); + + ASSERT_TRUE(cb->Called()); + ASSERT_TRUE(cb2->Called()); + + testing::ConsumeAndValidateStream(reader, inputData); +} + namespace { NS_METHOD diff --git a/xpcom/tests/gtest/moz.build b/xpcom/tests/gtest/moz.build index b163ad26ad..3ac40f7f5f 100644 --- a/xpcom/tests/gtest/moz.build +++ b/xpcom/tests/gtest/moz.build @@ -28,3 +28,6 @@ UNIFIED_SOURCES += [ ] FINAL_LIBRARY = 'xul-gtest' + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/xpcom/tests/moz.build b/xpcom/tests/moz.build index 7ab1c99dd9..54d2131c58 100644 --- a/xpcom/tests/moz.build +++ b/xpcom/tests/moz.build @@ -105,3 +105,6 @@ LOCAL_INCLUDES += [ RESOURCE_FILES += [ 'test.properties', ] + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/xpcom/tests/nsIFileEnumerator.cpp b/xpcom/tests/nsIFileEnumerator.cpp index fee7314106..471291c3eb 100644 --- a/xpcom/tests/nsIFileEnumerator.cpp +++ b/xpcom/tests/nsIFileEnumerator.cpp @@ -9,11 +9,11 @@ #include "nsISimpleEnumerator.h" #include "nsCOMPtr.h" -bool LoopInDir(nsIFile* file) +static bool LoopInDir(nsIFile* aFile) { nsresult rv; nsCOMPtr entries; - rv = file->GetDirectoryEntries(getter_AddRefs(entries)); + rv = aFile->GetDirectoryEntries(getter_AddRefs(entries)); if(NS_FAILED(rv) || !entries) return false; @@ -24,18 +24,18 @@ bool LoopInDir(nsIFile* file) entries->GetNext(getter_AddRefs(sup)); if(!sup) return false; - - nsCOMPtr file = do_QueryInterface(sup); - if(!file) + + nsCOMPtr nextFile = do_QueryInterface(sup); + if (!nextFile) return false; nsAutoCString name; - if(NS_FAILED(file->GetNativeLeafName(name))) + if(NS_FAILED(nextFile->GetNativeLeafName(name))) return false; bool isDir; printf("%s\n", name.get()); - rv = file->IsDirectory(&isDir); + rv = nextFile->IsDirectory(&isDir); if (NS_FAILED(rv)) { printf("IsDirectory Failed!!!\n"); @@ -44,8 +44,8 @@ bool LoopInDir(nsIFile* file) if (isDir) { - LoopInDir(file); - } + LoopInDir(nextFile); + } } return true; } diff --git a/xpcom/typelib/xpt/moz.build b/xpcom/typelib/xpt/moz.build index 7ee42e9a00..e58f5dee45 100644 --- a/xpcom/typelib/xpt/moz.build +++ b/xpcom/typelib/xpt/moz.build @@ -36,3 +36,6 @@ if CONFIG['_MSC_VER']: DEFINES['MOZ_NO_MOZALLOC'] = True DIST_INSTALL = True + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/xpfe/components/build/moz.build b/xpfe/components/build/moz.build index a98de3b7d4..aec8443035 100644 --- a/xpfe/components/build/moz.build +++ b/xpfe/components/build/moz.build @@ -13,3 +13,6 @@ FINAL_LIBRARY = 'xul' LOCAL_INCLUDES += [ '../directory', ] + +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] diff --git a/xpfe/components/windowds/moz.build b/xpfe/components/windowds/moz.build index 35d6291bd4..6ecbd71d64 100644 --- a/xpfe/components/windowds/moz.build +++ b/xpfe/components/windowds/moz.build @@ -14,4 +14,7 @@ SOURCES += [ 'nsWindowDataSource.cpp', ] +if CONFIG['GNU_CXX']: + CXXFLAGS += ['-Wshadow'] + FINAL_LIBRARY = 'xul'