From 453b3dce5fe07b8420a19b2f1260368833eec221 Mon Sep 17 00:00:00 2001 From: Nikhil Marathe Date: Thu, 25 Oct 2012 16:10:53 -0700 Subject: [PATCH] Bug 804174 - Inline CallerHasUniversalXPConnect with IsCallerChrome. r=mccr8 --- content/base/public/nsContentUtils.h | 5 ----- content/base/src/nsContentUtils.cpp | 15 ++++----------- content/base/src/nsDOMFile.cpp | 4 ++-- content/events/src/nsDOMDataTransfer.cpp | 6 +++--- content/html/content/src/nsHTMLInputElement.cpp | 15 +++++++-------- dom/base/nsGlobalWindow.cpp | 6 +++--- js/xpconnect/loader/mozJSComponentLoader.cpp | 2 +- layout/style/nsComputedDOMStyle.cpp | 4 ++-- 8 files changed, 22 insertions(+), 35 deletions(-) diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 5a83d422169..f8468537b31 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -207,11 +207,6 @@ public: static bool IsCallerTrustedForWrite(); - /** - * Check whether a caller has UniversalXPConnect. - */ - static bool CallerHasUniversalXPConnect(); - static bool IsImageSrcSetDisabled(); /** diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 5d234897ca6..f090d25c946 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -1533,13 +1533,6 @@ nsContentUtils::Shutdown() nsTextEditorState::ShutDown(); } -// static -bool -nsContentUtils::CallerHasUniversalXPConnect() -{ - return IsCallerChrome(); -} - /** * Checks whether two nodes come from the same origin. aTrustedNode is * considered 'safe' in that a user can operate on it and that it isn't @@ -1613,8 +1606,8 @@ nsContentUtils::CanCallerAccess(nsIPrincipal* aSubjectPrincipal, } // The subject doesn't subsume aPrincipal. Allow access only if the subject - // has UniversalXPConnect. - return CallerHasUniversalXPConnect(); + // is chrome. + return IsCallerChrome(); } // static @@ -1789,13 +1782,13 @@ nsContentUtils::IsCallerChrome() bool nsContentUtils::IsCallerTrustedForRead() { - return CallerHasUniversalXPConnect(); + return IsCallerChrome(); } bool nsContentUtils::IsCallerTrustedForWrite() { - return CallerHasUniversalXPConnect(); + return IsCallerChrome(); } bool diff --git a/content/base/src/nsDOMFile.cpp b/content/base/src/nsDOMFile.cpp index 14a2887a639..0cc5a9c3870 100644 --- a/content/base/src/nsDOMFile.cpp +++ b/content/base/src/nsDOMFile.cpp @@ -142,12 +142,12 @@ nsDOMFileBase::GetMozFullPath(nsAString &aFileName) { NS_ASSERTION(mIsFile, "Should only be called on files"); - // It is unsafe to call CallerHasUniversalXPConnect on a non-main thread. If + // It is unsafe to call IsCallerChrome on a non-main thread. If // you hit the following assertion you need to figure out some other way to // determine privileges and call GetMozFullPathInternal. NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - if (nsContentUtils::CallerHasUniversalXPConnect()) { + if (nsContentUtils::IsCallerChrome()) { return GetMozFullPathInternal(aFileName); } aFileName.Truncate(); diff --git a/content/events/src/nsDOMDataTransfer.cpp b/content/events/src/nsDOMDataTransfer.cpp index ab148f587ea..4e35ffade51 100644 --- a/content/events/src/nsDOMDataTransfer.cpp +++ b/content/events/src/nsDOMDataTransfer.cpp @@ -443,7 +443,7 @@ nsDOMDataTransfer::MozGetDataAt(const nsAString& aFormat, nsTArray& item = mItems[aIndex]; // Check if the caller is allowed to access the drag data. Callers with - // UniversalXPConnect privileges can always read the data. During the + // chrome privileges can always read the data. During the // drop event, allow retrieving the data except in the case where the // source of the drag is in a child frame of the caller. In that case, // we only allow access to data of the same principal. During other events, @@ -451,7 +451,7 @@ nsDOMDataTransfer::MozGetDataAt(const nsAString& aFormat, nsIPrincipal* principal = nullptr; if (mIsCrossDomainSubFrameDrop || (mEventType != NS_DRAGDROP_DROP && mEventType != NS_DRAGDROP_DRAGDROP && - !nsContentUtils::CallerHasUniversalXPConnect())) { + !nsContentUtils::IsCallerChrome())) { nsresult rv = NS_OK; principal = GetCurrentPrincipal(&rv); NS_ENSURE_SUCCESS(rv, rv); @@ -520,7 +520,7 @@ nsDOMDataTransfer::MozSetDataAt(const nsAString& aFormat, // XXX perhaps this should also limit any non-string type as well if ((aFormat.EqualsLiteral("application/x-moz-file-promise") || aFormat.EqualsLiteral("application/x-moz-file")) && - !nsContentUtils::CallerHasUniversalXPConnect()) { + !nsContentUtils::IsCallerChrome()) { return NS_ERROR_DOM_SECURITY_ERR; } diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index 1d2928577d3..2e5443eec04 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -990,7 +990,7 @@ nsHTMLInputElement::GetValueInternal(nsAString& aValue) const return NS_OK; case VALUE_MODE_FILENAME: - if (nsContentUtils::CallerHasUniversalXPConnect()) { + if (nsContentUtils::IsCallerChrome()) { if (mFiles.Count()) { return mFiles[0]->GetMozFullPath(aValue); } @@ -1052,9 +1052,9 @@ nsHTMLInputElement::SetValue(const nsAString& aValue) // OK and gives pages a way to clear a file input if necessary. if (mType == NS_FORM_INPUT_FILE) { if (!aValue.IsEmpty()) { - if (!nsContentUtils::CallerHasUniversalXPConnect()) { - // setting the value of a "FILE" input widget requires the - // UniversalXPConnect privilege + if (!nsContentUtils::IsCallerChrome()) { + // setting the value of a "FILE" input widget requires + // chrome privilege return NS_ERROR_DOM_SECURITY_ERR; } const PRUnichar *name = PromiseFlatString(aValue).get(); @@ -1270,7 +1270,7 @@ nsHTMLInputElement::StepUp(int32_t n, uint8_t optional_argc) NS_IMETHODIMP nsHTMLInputElement::MozGetFileNameArray(uint32_t *aLength, PRUnichar ***aFileNames) { - if (!nsContentUtils::CallerHasUniversalXPConnect()) { + if (!nsContentUtils::IsCallerChrome()) { // Since this function returns full paths it's important that normal pages // can't call it. return NS_ERROR_DOM_SECURITY_ERR; @@ -1297,9 +1297,8 @@ nsHTMLInputElement::MozGetFileNameArray(uint32_t *aLength, PRUnichar ***aFileNam NS_IMETHODIMP nsHTMLInputElement::MozSetFileNameArray(const PRUnichar **aFileNames, uint32_t aLength) { - if (!nsContentUtils::CallerHasUniversalXPConnect()) { - // setting the value of a "FILE" input widget requires the - // UniversalXPConnect privilege + if (!nsContentUtils::IsCallerChrome()) { + // setting the value of a "FILE" input widget requires chrome privilege return NS_ERROR_DOM_SECURITY_ERR; } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 16c7cad712d..1dd41c057ca 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -2602,12 +2602,12 @@ nsGlobalWindow::DialogsAreBeingAbused() NS_ASSERTION(GetScriptableTop() && GetScriptableTop()->GetCurrentInnerWindowInternal() == this, "DialogsAreBeingAbused called with invalid window"); - + if (mLastDialogQuitTime.IsNull() || - nsContentUtils::CallerHasUniversalXPConnect()) { + nsContentUtils::IsCallerChrome()) { return false; } - + TimeDuration dialogInterval(TimeStamp::Now() - mLastDialogQuitTime); if (dialogInterval.ToSeconds() < Preferences::GetInt("dom.successive_dialog_time_limit", diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index c1e935d10c3..4a045c53b02 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -970,7 +970,7 @@ mozJSComponentLoader::Import(const nsACString& registryLocation, JS::Value targetVal = targetVal_; JSObject *targetObject = NULL; - MOZ_ASSERT(nsContentUtils::CallerHasUniversalXPConnect()); + MOZ_ASSERT(nsContentUtils::IsCallerChrome()); if (optionalArgc) { // The caller passed in the optional second argument. Get it. if (targetVal.isObject()) { diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index f3205bd24d0..03017ba977b 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -538,9 +538,9 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName, } // mExposeVisitedStyle is set to true only by testing APIs that - // require UniversalXPConnect. + // require chrome privilege. NS_ABORT_IF_FALSE(!mExposeVisitedStyle || - nsContentUtils::CallerHasUniversalXPConnect(), + nsContentUtils::IsCallerChrome(), "mExposeVisitedStyle set incorrectly"); if (mExposeVisitedStyle && mStyleContextHolder->RelevantLinkVisited()) { nsStyleContext *styleIfVisited = mStyleContextHolder->GetStyleIfVisited();