Bug 1310345 - Change FindChildWithName and related methods to take nsAString& instead of char16_t*, r=bz

MozReview-Commit-ID: 4aQwYX9ObcN
This commit is contained in:
Michael Layzell 2016-10-14 18:00:47 -04:00
parent de29c95ed2
commit 76969f2737
14 changed files with 55 additions and 75 deletions

View File

@ -1543,7 +1543,7 @@ nsDocShell::LoadURI(nsIURI* aURI,
triggeringPrincipal,
principalToInherit,
flags,
target.get(),
target,
nullptr, // No type hint
NullString(), // No forced download
postStream,
@ -3149,9 +3149,8 @@ nsDocShell::SetName(const nsAString& aName)
}
NS_IMETHODIMP
nsDocShell::NameEquals(const char16_t* aName, bool* aResult)
nsDocShell::NameEquals(const nsAString& aName, bool* aResult)
{
NS_ENSURE_ARG_POINTER(aName);
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mName.Equals(aName);
return NS_OK;
@ -3650,18 +3649,17 @@ ItemIsActive(nsIDocShellTreeItem* aItem)
}
NS_IMETHODIMP
nsDocShell::FindItemWithName(const char16_t* aName,
nsDocShell::FindItemWithName(const nsAString& aName,
nsISupports* aRequestor,
nsIDocShellTreeItem* aOriginalRequestor,
nsIDocShellTreeItem** aResult)
{
NS_ENSURE_ARG(aName);
NS_ENSURE_ARG_POINTER(aResult);
// If we don't find one, we return NS_OK and a null result
*aResult = nullptr;
if (!*aName) {
if (aName.IsEmpty()) {
return NS_OK;
}
@ -3675,19 +3673,18 @@ nsDocShell::FindItemWithName(const char16_t* aName,
// for a null aRequestor.
nsCOMPtr<nsIDocShellTreeItem> foundItem;
nsDependentString name(aName);
if (name.LowerCaseEqualsLiteral("_self")) {
if (aName.LowerCaseEqualsLiteral("_self")) {
foundItem = this;
} else if (name.LowerCaseEqualsLiteral("_blank")) {
} else if (aName.LowerCaseEqualsLiteral("_blank")) {
// Just return null. Caller must handle creating a new window with
// a blank name himself.
return NS_OK;
} else if (name.LowerCaseEqualsLiteral("_parent")) {
} else if (aName.LowerCaseEqualsLiteral("_parent")) {
GetSameTypeParent(getter_AddRefs(foundItem));
if (!foundItem) {
foundItem = this;
}
} else if (name.LowerCaseEqualsLiteral("_top")) {
} else if (aName.LowerCaseEqualsLiteral("_top")) {
GetSameTypeRootTreeItem(getter_AddRefs(foundItem));
NS_ASSERTION(foundItem, "Must have this; worst case it's us!");
} else {
@ -3722,7 +3719,7 @@ nsDocShell::AssertOriginAttributesMatchPrivateBrowsing() {
}
nsresult
nsDocShell::DoFindItemWithName(const char16_t* aName,
nsDocShell::DoFindItemWithName(const nsAString& aName,
nsISupports* aRequestor,
nsIDocShellTreeItem* aOriginalRequestor,
nsIDocShellTreeItem** aResult)
@ -4169,19 +4166,18 @@ nsDocShell::GetChildAt(int32_t aIndex, nsIDocShellTreeItem** aChild)
}
NS_IMETHODIMP
nsDocShell::FindChildWithName(const char16_t* aName,
nsDocShell::FindChildWithName(const nsAString& aName,
bool aRecurse, bool aSameType,
nsIDocShellTreeItem* aRequestor,
nsIDocShellTreeItem* aOriginalRequestor,
nsIDocShellTreeItem** aResult)
{
NS_ENSURE_ARG(aName);
NS_ENSURE_ARG_POINTER(aResult);
// if we don't find one, we return NS_OK and a null result
*aResult = nullptr;
if (!*aName) {
if (aName.IsEmpty()) {
return NS_OK;
}
@ -5351,7 +5347,7 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
return InternalLoad(errorPageURI, nullptr, false, nullptr,
mozilla::net::RP_Default,
nullptr, nullptr, INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL, nullptr,
nullptr, nullptr, INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL, EmptyString(),
nullptr, NullString(), nullptr, nullptr, LOAD_ERROR_PAGE,
nullptr, true, NullString(), this, nullptr, nullptr,
nullptr);
@ -5431,7 +5427,7 @@ nsDocShell::Reload(uint32_t aReloadFlags)
principal,
principal,
flags,
nullptr, // No window target
EmptyString(), // No window target
NS_LossyConvertUTF16toASCII(contentTypeHint).get(),
NullString(), // No forced download
nullptr, // No post data
@ -9573,7 +9569,7 @@ public:
mReferrer,
mReferrerPolicy,
mTriggeringPrincipal, mPrincipalToInherit,
mFlags, nullptr, mTypeHint.get(),
mFlags, EmptyString(), mTypeHint.get(),
NullString(), mPostData, mHeadersData,
mLoadType, mSHEntry, mFirstParty,
mSrcdoc, mSourceDocShell, mBaseURI,
@ -9663,7 +9659,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit,
uint32_t aFlags,
const char16_t* aWindowTarget,
const nsAString& aWindowTarget,
const char* aTypeHint,
const nsAString& aFileName,
nsIInputStream* aPostData,
@ -9736,15 +9732,14 @@ nsDocShell::InternalLoad(nsIURI* aURI,
bool isTargetTopLevelDocShell = false;
nsCOMPtr<nsIDocShell> targetDocShell;
if (aWindowTarget && *aWindowTarget) {
if (!aWindowTarget.IsEmpty()) {
// Locate the target DocShell.
nsCOMPtr<nsIDocShellTreeItem> targetItem;
nsDependentString name(aWindowTarget);
// Only _self, _parent, and _top are supported in noopener case.
if (!(aFlags & INTERNAL_LOAD_FLAGS_NO_OPENER) ||
name.LowerCaseEqualsLiteral("_self") ||
name.LowerCaseEqualsLiteral("_parent") ||
name.LowerCaseEqualsLiteral("_top")) {
aWindowTarget.LowerCaseEqualsLiteral("_self") ||
aWindowTarget.LowerCaseEqualsLiteral("_parent") ||
aWindowTarget.LowerCaseEqualsLiteral("_top")) {
rv = FindItemWithName(aWindowTarget, nullptr, this,
getter_AddRefs(targetItem));
NS_ENSURE_SUCCESS(rv, rv);
@ -9945,7 +9940,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
// If the load has been targeted to another DocShell, then transfer the
// load to it...
//
if (aWindowTarget && *aWindowTarget) {
if (!aWindowTarget.IsEmpty()) {
// We've already done our owner-inheriting. Mask out that bit, so we
// don't try inheriting an owner from the target window if we came up
// with a null owner above.
@ -9970,7 +9965,6 @@ nsDocShell::InternalLoad(nsIURI* aURI,
nsCOMPtr<nsPIDOMWindowOuter> win = GetWindow();
NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE);
nsDependentString name(aWindowTarget);
nsCOMPtr<nsPIDOMWindowOuter> newWin;
nsAutoCString spec;
if (aURI) {
@ -10015,7 +10009,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
loadInfo->SetLoadType(ConvertLoadTypeToDocShellLoadInfo(LOAD_LINK));
rv = win->Open(NS_ConvertUTF8toUTF16(spec),
name, // window name
aWindowTarget, // window name
EmptyString(), // Features
loadInfo,
true, // aForceNoOpener
@ -10025,7 +10019,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
}
rv = win->OpenNoNavigate(NS_ConvertUTF8toUTF16(spec),
name, // window name
aWindowTarget, // window name
EmptyString(), // Features
getter_AddRefs(newWin));
@ -10058,7 +10052,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
aTriggeringPrincipal,
principalToInherit,
aFlags,
nullptr, // No window target
EmptyString(), // No window target
aTypeHint,
NullString(), // No forced download
aPostData,
@ -10122,7 +10116,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
if (mFiredUnloadEvent) {
if (IsOKToLoadURI(aURI)) {
NS_PRECONDITION(!aWindowTarget || !*aWindowTarget,
NS_PRECONDITION(aWindowTarget.IsEmpty(),
"Shouldn't have a window target here!");
// If this is a replace load, make whatever load triggered
@ -12525,7 +12519,7 @@ nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry, uint32_t aLoadType)
triggeringPrincipal,
principalToInherit,
flags,
nullptr, // No window target
EmptyString(), // No window target
contentType.get(), // Type hint
NullString(), // No forced file download
postData, // Post data stream
@ -14016,7 +14010,7 @@ nsDocShell::OnLinkClickSync(nsIContent* aContent,
// principal
aContent->NodePrincipal(),
flags,
target.get(), // Window target
target, // Window target
NS_LossyConvertUTF16toASCII(typeHint).get(),
aFileName, // Download as file
aPostDataStream, // Post data stream

View File

@ -1037,7 +1037,7 @@ private:
// Separate function to do the actual name (i.e. not _top, _self etc.)
// searching for FindItemWithName.
nsresult DoFindItemWithName(const char16_t* aName,
nsresult DoFindItemWithName(const nsAString& aName,
nsISupports* aRequestor,
nsIDocShellTreeItem* aOriginalRequestor,
nsIDocShellTreeItem** aResult);

View File

@ -190,7 +190,7 @@ interface nsIDocShell : nsIDocShellTreeItem
in nsIPrincipal aTriggeringPrincipal,
in nsIPrincipal aPrincipalToInherit,
in uint32_t aFlags,
in wstring aWindowTarget,
in AString aWindowTarget,
in string aTypeHint,
in AString aFileName,
in nsIInputStream aPostDataStream,

View File

@ -32,7 +32,7 @@ interface nsIDocShellTreeItem : nsISupports
* @return <CODE>PR_TRUE</CODE> if names match;
* <CODE>PR_FALSE</CODE> otherwise.
*/
boolean nameEquals(in wstring name);
boolean nameEquals(in AString name);
/*
Definitions for the item types.
@ -104,7 +104,7 @@ interface nsIDocShellTreeItem : nsISupports
aOriginalRequestor - The original treeitem that made the request, if any.
This is used to ensure that we don't run into cross-site issues.
*/
nsIDocShellTreeItem findItemWithName(in wstring name,
nsIDocShellTreeItem findItemWithName(in AString name,
in nsISupports aRequestor,
in nsIDocShellTreeItem aOriginalRequestor);
@ -172,7 +172,7 @@ interface nsIDocShellTreeItem : nsISupports
Note the search is depth first when recursing.
*/
nsIDocShellTreeItem findChildWithName(in wstring aName,
nsIDocShellTreeItem findChildWithName(in AString aName,
in boolean aRecurse,
in boolean aSameType,
in nsIDocShellTreeItem aRequestor,

View File

@ -116,7 +116,7 @@ TabGroup::Leave(nsPIDOMWindowOuter* aWindow)
}
nsresult
TabGroup::FindItemWithName(const char16_t* aName,
TabGroup::FindItemWithName(const nsAString& aName,
nsIDocShellTreeItem* aRequestor,
nsIDocShellTreeItem* aOriginalRequestor,
nsIDocShellTreeItem** aFoundItem)
@ -124,13 +124,10 @@ TabGroup::FindItemWithName(const char16_t* aName,
NS_ENSURE_ARG_POINTER(aFoundItem);
*aFoundItem = nullptr;
#ifdef DEBUG
nsDependentString name(aName);
MOZ_ASSERT(!name.LowerCaseEqualsLiteral("_blank") &&
!name.LowerCaseEqualsLiteral("_top") &&
!name.LowerCaseEqualsLiteral("_parent") &&
!name.LowerCaseEqualsLiteral("_self"));
#endif
MOZ_ASSERT(!aName.LowerCaseEqualsLiteral("_blank") &&
!aName.LowerCaseEqualsLiteral("_top") &&
!aName.LowerCaseEqualsLiteral("_parent") &&
!aName.LowerCaseEqualsLiteral("_self"));
for (nsPIDOMWindowOuter* outerWindow : mWindows) {
// Ignore non-toplevel windows

View File

@ -131,7 +131,7 @@ public:
// It is illegal to pass in the special case-insensitive names "_blank",
// "_self", "_parent" or "_top", as those should be handled elsewhere.
nsresult
FindItemWithName(const char16_t* aName,
FindItemWithName(const nsAString& aName,
nsIDocShellTreeItem* aRequestor,
nsIDocShellTreeItem* aOriginalRequestor,
nsIDocShellTreeItem** aFoundItem);

View File

@ -114,8 +114,7 @@ nsDOMWindowList::NamedItem(const nsAString& aName, mozIDOMWindowProxy** aReturn)
EnsureFresh();
if (mDocShellNode) {
mDocShellNode->FindChildWithName(PromiseFlatString(aName).get(),
false, false, nullptr,
mDocShellNode->FindChildWithName(aName, false, false, nullptr,
nullptr, getter_AddRefs(item));
nsCOMPtr<nsIScriptGlobalObject> globalObject(do_GetInterface(item));

View File

@ -5999,8 +5999,7 @@ nsGlobalWindow::GetChildWindow(const nsAString& aName)
NS_ENSURE_TRUE(docShell, nullptr);
nsCOMPtr<nsIDocShellTreeItem> child;
docShell->FindChildWithName(PromiseFlatString(aName).get(),
false, true, nullptr, nullptr,
docShell->FindChildWithName(aName, false, true, nullptr, nullptr,
getter_AddRefs(child));
return child ? child->GetWindow() : nullptr;
@ -6110,7 +6109,7 @@ nsGlobalWindow::WindowExists(const nsAString& aName,
}
nsCOMPtr<nsIDocShellTreeItem> namedItem;
mDocShell->FindItemWithName(PromiseFlatString(aName).get(), nullptr, caller,
mDocShell->FindItemWithName(aName, nullptr, caller,
getter_AddRefs(namedItem));
return namedItem != nullptr;
}

View File

@ -168,7 +168,7 @@ PluginDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr<nsIDocShellTreeItem> dsti (do_QueryInterface(aContainer));
if (dsti) {
bool isMsgPane = false;
dsti->NameEquals(u"messagepane", &isMsgPane);
dsti->NameEquals(NS_LITERAL_STRING("messagepane"), &isMsgPane);
if (isMsgPane) {
return NS_ERROR_FAILURE;
}

View File

@ -424,9 +424,8 @@ nsWebBrowser::SetName(const nsAString& aName)
}
NS_IMETHODIMP
nsWebBrowser::NameEquals(const char16_t* aName, bool* aResult)
nsWebBrowser::NameEquals(const nsAString& aName, bool* aResult)
{
NS_ENSURE_ARG_POINTER(aName);
NS_ENSURE_ARG_POINTER(aResult);
if (mDocShell) {
return mDocShell->NameEquals(aName, aResult);
@ -519,7 +518,7 @@ nsWebBrowser::GetSameTypeRootTreeItem(nsIDocShellTreeItem** aRootTreeItem)
}
NS_IMETHODIMP
nsWebBrowser::FindItemWithName(const char16_t* aName,
nsWebBrowser::FindItemWithName(const nsAString& aName,
nsISupports* aRequestor,
nsIDocShellTreeItem* aOriginalRequestor,
nsIDocShellTreeItem** aResult)
@ -599,7 +598,7 @@ nsWebBrowser::GetChildAt(int32_t aIndex, nsIDocShellTreeItem** aChild)
}
NS_IMETHODIMP
nsWebBrowser::FindChildWithName(const char16_t* aName,
nsWebBrowser::FindChildWithName(const nsAString& aName,
bool aRecurse,
bool aSameType,
nsIDocShellTreeItem* aRequestor,

View File

@ -148,7 +148,7 @@ interface nsIWindowWatcher : nsISupports {
frame with the given window name. Make sure you understand the
security implications of this before using this method!
*/
mozIDOMWindowProxy getWindowByName(in wstring aTargetName,
mozIDOMWindowProxy getWindowByName(in AString aTargetName,
in mozIDOMWindowProxy aCurrentWindow);
/** The Watcher serves as a global storage facility for the current active

View File

@ -139,7 +139,7 @@ interface nsPIWindowWatcher : nsISupports
* @see findItemWithName methods on nsIDocShellTreeItem and
* nsIDocShellTreeOwner
*/
nsIDocShellTreeItem findItemWithName(in wstring aName,
nsIDocShellTreeItem findItemWithName(in AString aName,
in nsIDocShellTreeItem aRequestor,
in nsIDocShellTreeItem aOriginalRequestor);
};

View File

@ -1639,7 +1639,7 @@ nsWindowWatcher::GetChromeForWindow(mozIDOMWindowProxy* aWindow,
}
NS_IMETHODIMP
nsWindowWatcher::GetWindowByName(const char16_t* aTargetName,
nsWindowWatcher::GetWindowByName(const nsAString& aTargetName,
mozIDOMWindowProxy* aCurrentWindow,
mozIDOMWindowProxy** aResult)
{
@ -2056,21 +2056,20 @@ nsWindowWatcher::WinHasOption(const nsACString& aOptions, const char* aName,
necessarily return a failure method value. check aFoundItem.
*/
NS_IMETHODIMP
nsWindowWatcher::FindItemWithName(const char16_t* aName,
nsWindowWatcher::FindItemWithName(const nsAString& aName,
nsIDocShellTreeItem* aRequestor,
nsIDocShellTreeItem* aOriginalRequestor,
nsIDocShellTreeItem** aFoundItem)
{
*aFoundItem = nullptr;
if (!aName || !*aName) {
if (aName.IsEmpty()) {
return NS_OK;
}
nsDependentString name(aName);
if (name.LowerCaseEqualsLiteral("_blank") ||
name.LowerCaseEqualsLiteral("_top") ||
name.LowerCaseEqualsLiteral("_parent") ||
name.LowerCaseEqualsLiteral("_self")) {
if (aName.LowerCaseEqualsLiteral("_blank") ||
aName.LowerCaseEqualsLiteral("_top") ||
aName.LowerCaseEqualsLiteral("_parent") ||
aName.LowerCaseEqualsLiteral("_self")) {
return NS_OK;
}
@ -2113,14 +2112,12 @@ nsWindowWatcher::SafeGetWindowByName(const nsAString& aName,
nsCOMPtr<nsIDocShellTreeItem> callerItem = GetCallerTreeItem(startItem);
const nsAFlatString& flatName = PromiseFlatString(aName);
nsCOMPtr<nsIDocShellTreeItem> foundItem;
if (startItem) {
startItem->FindItemWithName(flatName.get(), nullptr, callerItem,
startItem->FindItemWithName(aName, nullptr, callerItem,
getter_AddRefs(foundItem));
} else {
FindItemWithName(flatName.get(), nullptr, callerItem,
FindItemWithName(aName, nullptr, callerItem,
getter_AddRefs(foundItem));
}

View File

@ -1,5 +0,0 @@
[window-null-names.html]
type: testharness
[Named access with null characters]
expected: FAIL