Bug 804174 - Inline CallerHasUniversalXPConnect with IsCallerChrome. r=mccr8

This commit is contained in:
Nikhil Marathe 2012-10-25 16:10:53 -07:00
parent a01b0389bf
commit 453b3dce5f
8 changed files with 22 additions and 35 deletions

View File

@ -207,11 +207,6 @@ public:
static bool IsCallerTrustedForWrite();
/**
* Check whether a caller has UniversalXPConnect.
*/
static bool CallerHasUniversalXPConnect();
static bool IsImageSrcSetDisabled();
/**

View File

@ -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

View File

@ -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();

View File

@ -443,7 +443,7 @@ nsDOMDataTransfer::MozGetDataAt(const nsAString& aFormat,
nsTArray<TransferItem>& 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;
}

View File

@ -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;
}

View File

@ -2604,7 +2604,7 @@ nsGlobalWindow::DialogsAreBeingAbused()
"DialogsAreBeingAbused called with invalid window");
if (mLastDialogQuitTime.IsNull() ||
nsContentUtils::CallerHasUniversalXPConnect()) {
nsContentUtils::IsCallerChrome()) {
return false;
}

View File

@ -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()) {

View File

@ -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();