Bug 852118. Stop window.name being malloc-happy. r=smaug

This commit is contained in:
Boris Zbarsky 2013-03-19 21:47:47 -04:00
parent d0b977f25f
commit 1cbb1c372e
7 changed files with 22 additions and 25 deletions

View File

@ -1572,7 +1572,7 @@ nsFrameLoader::MaybeCreateDocShell()
}
if (!frameName.IsEmpty()) {
mDocShell->SetName(frameName.get());
mDocShell->SetName(frameName);
}
// If our container is a web-shell, inform it that it has a new

View File

@ -233,7 +233,7 @@ nsGenericHTMLFrameElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsIDocShell *docShell = mFrameLoader ? mFrameLoader->GetExistingDocShell()
: nullptr;
if (docShell) {
docShell->SetName(PromiseFlatString(aValue).get());
docShell->SetName(aValue);
}
}
@ -254,7 +254,7 @@ nsGenericHTMLFrameElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
nsIDocShell *docShell = mFrameLoader ? mFrameLoader->GetExistingDocShell()
: nullptr;
if (docShell) {
docShell->SetName(EmptyString().get());
docShell->SetName(EmptyString());
}
}

View File

@ -2816,17 +2816,16 @@ nsDocShell::GetCurrentDocChannel()
//*****************************************************************************
NS_IMETHODIMP
nsDocShell::GetName(PRUnichar ** aName)
nsDocShell::GetName(nsAString& aName)
{
NS_ENSURE_ARG_POINTER(aName);
*aName = ToNewUnicode(mName);
aName = mName;
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetName(const PRUnichar * aName)
nsDocShell::SetName(const nsAString& aName)
{
mName = aName; // this does a copy of aName
mName = aName;
return NS_OK;
}

View File

@ -15,13 +15,13 @@ interface nsIDocShellTreeOwner;
* node or a leaf.
*/
[scriptable, uuid(09b54ec1-d98a-49a9-bc95-3219e8b55089)]
[scriptable, uuid(e35bbb39-985b-4d62-81da-73c330222e5f)]
interface nsIDocShellTreeItem : nsIDocShellTreeNode
{
/*
name of the DocShellTreeItem
*/
attribute wstring name;
attribute AString name;
/**
* Compares the provided name against the item's name and

View File

@ -3774,11 +3774,9 @@ nsGlobalWindow::GetName(nsAString& aName)
{
FORWARD_TO_OUTER(GetName, (aName), NS_ERROR_NOT_INITIALIZED);
nsXPIDLString name;
if (mDocShell)
mDocShell->GetName(getter_Copies(name));
mDocShell->GetName(aName);
aName.Assign(name);
return NS_OK;
}
@ -3789,7 +3787,7 @@ nsGlobalWindow::SetName(const nsAString& aName)
nsresult result = NS_OK;
if (mDocShell)
result = mDocShell->SetName(PromiseFlatString(aName).get());
result = mDocShell->SetName(aName);
return result;
}

View File

@ -400,19 +400,17 @@ NS_IMETHODIMP nsWebBrowser::SetIsActive(bool aIsActive)
// nsWebBrowser::nsIDocShellTreeItem
//*****************************************************************************
NS_IMETHODIMP nsWebBrowser::GetName(PRUnichar** aName)
NS_IMETHODIMP nsWebBrowser::GetName(nsAString& aName)
{
NS_ENSURE_ARG_POINTER(aName);
if(mDocShell)
mDocShell->GetName(aName);
else
*aName = ToNewUnicode(mInitInfo->name);
aName = mInitInfo->name;
return NS_OK;
}
NS_IMETHODIMP nsWebBrowser::SetName(const PRUnichar* aName)
NS_IMETHODIMP nsWebBrowser::SetName(const nsAString& aName)
{
if(mDocShell)
{
@ -1171,7 +1169,7 @@ NS_IMETHODIMP nsWebBrowser::Create()
docShellParentWidget, mInitInfo->x, mInitInfo->y, mInitInfo->cx,
mInitInfo->cy), NS_ERROR_FAILURE);
mDocShell->SetName(mInitInfo->name.get());
mDocShell->SetName(mInitInfo->name);
if (mContentType == typeChromeWrapper)
{
mDocShell->SetItemType(nsIDocShellTreeItem::typeChrome);

View File

@ -805,11 +805,13 @@ nsWindowWatcher::OpenWindowInternal(nsIDOMWindow *aParent,
/* allow a window that we found by name to keep its name (important for cases
like _self where the given name is different (and invalid)). Also, _blank
is not a window name. */
if (windowNeedsName)
newDocShellItem->SetName(nameSpecified &&
!name.LowerCaseEqualsLiteral("_blank") ?
name.get() : nullptr);
if (windowNeedsName) {
if (nameSpecified && !name.LowerCaseEqualsLiteral("_blank")) {
newDocShellItem->SetName(name);
} else {
newDocShellItem->SetName(EmptyString());
}
}
// Inherit the right character set into the new window to use as a fallback
// in the event the document being loaded does not specify a charset. When