Bug 852118. Stop window.name being malloc-happy. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 19 Mar 2013 21:47:47 -0400
changeset 125527 b1af382d57500de4b1703f305c77467cc8f8a9cc
parent 125526 13fb55ee93bbb61f7f571fa315640b40b503e8ce
child 125528 e91747bb94c6c0ebefed6de3b3660b0387ad745f
push id24459
push useremorley@mozilla.com
push dateWed, 20 Mar 2013 11:46:36 +0000
treeherdermozilla-central@1d6fe70c79c5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs852118
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 852118. Stop window.name being malloc-happy. r=smaug
content/base/src/nsFrameLoader.cpp
content/html/content/src/nsGenericHTMLFrameElement.cpp
docshell/base/nsDocShell.cpp
docshell/base/nsIDocShellTreeItem.idl
dom/base/nsGlobalWindow.cpp
embedding/browser/webBrowser/nsWebBrowser.cpp
embedding/components/windowwatcher/src/nsWindowWatcher.cpp
--- a/content/base/src/nsFrameLoader.cpp
+++ b/content/base/src/nsFrameLoader.cpp
@@ -1567,17 +1567,17 @@ nsFrameLoader::MaybeCreateDocShell()
     // XXX if no NAME then use ID, after a transition period this will be
     // changed so that XUL only uses ID too (bug 254284).
     if (frameName.IsEmpty() && namespaceID == kNameSpaceID_XUL) {
       mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::id, frameName);
     }
   }
 
   if (!frameName.IsEmpty()) {
-    mDocShell->SetName(frameName.get());
+    mDocShell->SetName(frameName);
   }
 
   // If our container is a web-shell, inform it that it has a new
   // child. If it's not a web-shell then some things will not operate
   // properly.
 
   nsCOMPtr<nsIDocShellTreeNode> parentAsNode(do_QueryInterface(parentAsWebNav));
   if (parentAsNode) {
--- a/content/html/content/src/nsGenericHTMLFrameElement.cpp
+++ b/content/html/content/src/nsGenericHTMLFrameElement.cpp
@@ -228,17 +228,17 @@ nsGenericHTMLFrameElement::SetAttr(int32
     // what we should reflect.
     LoadSrc();
   } else if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::name) {
     // Propagate "name" to the docshell to make browsing context names live,
     // per HTML5.
     nsIDocShell *docShell = mFrameLoader ? mFrameLoader->GetExistingDocShell()
                                          : nullptr;
     if (docShell) {
-      docShell->SetName(PromiseFlatString(aValue).get());
+      docShell->SetName(aValue);
     }
   }
 
   return NS_OK;
 }
 
 nsresult
 nsGenericHTMLFrameElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
@@ -249,17 +249,17 @@ nsGenericHTMLFrameElement::UnsetAttr(int
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (aNameSpaceID == kNameSpaceID_None && aAttribute == nsGkAtoms::name) {
     // Propagate "name" to the docshell to make browsing context names live,
     // per HTML5.
     nsIDocShell *docShell = mFrameLoader ? mFrameLoader->GetExistingDocShell()
                                          : nullptr;
     if (docShell) {
-      docShell->SetName(EmptyString().get());
+      docShell->SetName(EmptyString());
     }
   }
 
   return NS_OK;
 }
 
 void
 nsGenericHTMLFrameElement::DestroyContent()
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -2811,27 +2811,26 @@ nsDocShell::GetCurrentDocChannel()
     return nullptr;
 }
 
 //*****************************************************************************
 // nsDocShell::nsIDocShellTreeItem
 //*****************************************************************************   
 
 NS_IMETHODIMP
-nsDocShell::GetName(PRUnichar ** aName)
-{
-    NS_ENSURE_ARG_POINTER(aName);
-    *aName = ToNewUnicode(mName);
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDocShell::SetName(const PRUnichar * aName)
-{
-    mName = aName;              // this does a copy of aName
+nsDocShell::GetName(nsAString& aName)
+{
+    aName = mName;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsDocShell::SetName(const nsAString& aName)
+{
+    mName = aName;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::NameEquals(const PRUnichar *aName, bool *_retval)
 {
     NS_ENSURE_ARG_POINTER(aName);
     NS_ENSURE_ARG_POINTER(_retval);
--- a/docshell/base/nsIDocShellTreeItem.idl
+++ b/docshell/base/nsIDocShellTreeItem.idl
@@ -10,23 +10,23 @@ interface nsIDocShellTreeOwner;
 
 
 /**
  * The nsIDocShellTreeItem supplies the methods that are required of any item
  * that wishes to be able to live within the docshell tree either as a middle
  * 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
          * returns the appropriate result.
          *
          * @return <CODE>PR_TRUE</CODE> if names match;
          *         <CODE>PR_FALSE</CODE> otherwise.
          */
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -3769,32 +3769,30 @@ nsGlobalWindow::SetDefaultStatus(const n
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGlobalWindow::GetName(nsAString& aName)
 {
   FORWARD_TO_OUTER(GetName, (aName), NS_ERROR_NOT_INITIALIZED);
 
-  nsXPIDLString name;
   if (mDocShell)
-    mDocShell->GetName(getter_Copies(name));
-
-  aName.Assign(name);
+    mDocShell->GetName(aName);
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGlobalWindow::SetName(const nsAString& aName)
 {
   FORWARD_TO_OUTER(SetName, (aName), NS_ERROR_NOT_INITIALIZED);
 
   nsresult result = NS_OK;
   if (mDocShell)
-    result = mDocShell->SetName(PromiseFlatString(aName).get());
+    result = mDocShell->SetName(aName);
   return result;
 }
 
 // Helper functions used by many methods below.
 int32_t
 nsGlobalWindow::DevToCSSIntPixels(int32_t px)
 {
   if (!mDocShell)
--- a/embedding/browser/webBrowser/nsWebBrowser.cpp
+++ b/embedding/browser/webBrowser/nsWebBrowser.cpp
@@ -395,29 +395,27 @@ NS_IMETHODIMP nsWebBrowser::SetIsActive(
     return mDocShell->SetIsActive(aIsActive);
   return NS_OK;
 }
 
 //*****************************************************************************
 // 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)
       {
       return mDocShell->SetName(aName);
       }
    else
       mInitInfo->name = aName;
 
@@ -1166,17 +1164,17 @@ NS_IMETHODIMP nsWebBrowser::Create()
    (void)mDocShellTreeOwner->QueryInterface(NS_GET_IID(nsIWebProgressListener),
                              static_cast<void**>(getter_AddRefs(supports)));
    (void)BindListener(supports, NS_GET_IID(nsIWebProgressListener));
 
    NS_ENSURE_SUCCESS(mDocShellAsWin->InitWindow(nullptr,
       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);
    }
    else
    {
        mDocShell->SetItemType(nsIDocShellTreeItem::typeContent);
    }
--- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
@@ -800,21 +800,23 @@ nsWindowWatcher::OpenWindowInternal(nsID
 
     rv = piwin->SetArguments(argv, callerPrincipal);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   /* 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
   // aCalledFromJS is true, we want to use the character set of the document in
   // the caller; otherwise we want to use the character set of aParent's
   // docshell. Failing to set this charset is not fatal, so we want to continue
   // in the face of errors.
   nsCOMPtr<nsIContentViewer> newCV;