Bug 1310345 - Change FindChildWithName and related methods to take nsAString& instead of char16_t*, r=bz
authorMichael Layzell <michael@thelayzells.com>
Fri, 14 Oct 2016 18:00:47 -0400
changeset 319866 2a31079dae258444321138690fa68de6b3ddf06a
parent 319865 74ef5b08ae25f39a81503cdcb86b12ea3d6312d2
child 319867 c1d12c6ae210912b1e5005ff1cd952cdc605e593
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1310345
milestone52.0a1
Bug 1310345 - Change FindChildWithName and related methods to take nsAString& instead of char16_t*, r=bz MozReview-Commit-ID: 4aQwYX9ObcN
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
docshell/base/nsIDocShell.idl
docshell/base/nsIDocShellTreeItem.idl
dom/base/DocGroup.cpp
dom/base/DocGroup.h
dom/base/nsDOMWindowList.cpp
dom/base/nsGlobalWindow.cpp
dom/html/PluginDocument.cpp
embedding/browser/nsWebBrowser.cpp
embedding/components/windowwatcher/nsIWindowWatcher.idl
embedding/components/windowwatcher/nsPIWindowWatcher.idl
embedding/components/windowwatcher/nsWindowWatcher.cpp
testing/web-platform/meta/html/browsers/the-window-object/named-access-on-the-window-object/window-null-names.html.ini
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -1538,17 +1538,17 @@ nsDocShell::LoadURI(nsIURI* aURI,
   return InternalLoad(aURI,
                       originalURI,
                       loadReplace,
                       referrer,
                       referrerPolicy,
                       triggeringPrincipal,
                       principalToInherit,
                       flags,
-                      target.get(),
+                      target,
                       nullptr,      // No type hint
                       NullString(), // No forced download
                       postStream,
                       headersStream,
                       loadType,
                       nullptr, // No SHEntry
                       aFirstParty,
                       srcdoc,
@@ -3144,19 +3144,18 @@ nsDocShell::GetName(nsAString& aName)
 NS_IMETHODIMP
 nsDocShell::SetName(const nsAString& aName)
 {
   mName = aName;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDocShell::NameEquals(const char16_t* aName, bool* aResult)
-{
-  NS_ENSURE_ARG_POINTER(aName);
+nsDocShell::NameEquals(const nsAString& aName, bool* aResult)
+{
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = mName.Equals(aName);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetCustomUserAgent(nsAString& aCustomUserAgent)
 {
@@ -3645,54 +3644,52 @@ ItemIsActive(nsIDocShellTreeItem* aItem)
       return true;
     }
   }
 
   return false;
 }
 
 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;
   }
 
   if (aRequestor) {
     // If aRequestor is not null we don't need to check special names, so
     // just hand straight off to the search by actual name function.
     return DoFindItemWithName(aName, aRequestor, aOriginalRequestor, aResult);
   } else {
     // This is the entry point into the target-finding algorithm.  Check
     // for special names.  This should only be done once, hence the check
     // 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 {
       // Do the search for item by an actual name.
       DoFindItemWithName(aName, aRequestor, aOriginalRequestor,
                          getter_AddRefs(foundItem));
     }
 
@@ -3717,17 +3714,17 @@ nsDocShell::AssertOriginAttributesMatchP
   if (mItemType == typeChrome) {
     MOZ_DIAGNOSTIC_ASSERT(mOriginAttributes.mPrivateBrowsingId == 0);
   } else {
     MOZ_DIAGNOSTIC_ASSERT(mOriginAttributes.mPrivateBrowsingId == mPrivateBrowsingId);
   }
 }
 
 nsresult
-nsDocShell::DoFindItemWithName(const char16_t* aName,
+nsDocShell::DoFindItemWithName(const nsAString& aName,
                                nsISupports* aRequestor,
                                nsIDocShellTreeItem* aOriginalRequestor,
                                nsIDocShellTreeItem** aResult)
 {
   // First we check our name.
   if (mName.Equals(aName) && ItemIsActive(this) &&
       CanAccessItem(this, aOriginalRequestor)) {
     NS_ADDREF(*aResult = this);
@@ -4164,29 +4161,28 @@ nsDocShell::GetChildAt(int32_t aIndex, n
 
   nsIDocumentLoader* child = ChildAt(aIndex);
   NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED);
 
   return CallQueryInterface(child, 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;
   }
 
   nsXPIDLString childName;
   nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
   while (iter.HasMore()) {
     nsCOMPtr<nsIDocShellTreeItem> child = do_QueryObject(iter.GetNext());
     NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
@@ -5346,17 +5342,17 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, 
   errorPageUrl.AppendASCII(escapedDescription.get());
 
   nsCOMPtr<nsIURI> errorPageURI;
   rv = NS_NewURI(getter_AddRefs(errorPageURI), errorPageUrl);
   NS_ENSURE_SUCCESS(rv, rv);
 
   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);
 }
 
 NS_IMETHODIMP
 nsDocShell::Reload(uint32_t aReloadFlags)
 {
@@ -5426,17 +5422,17 @@ nsDocShell::Reload(uint32_t aReloadFlags
     rv = InternalLoad(mCurrentURI,
                       originalURI,
                       loadReplace,
                       mReferrerURI,
                       mReferrerPolicy,
                       principal,
                       principal,
                       flags,
-                      nullptr,         // No window target
+                      EmptyString(),   // No window target
                       NS_LossyConvertUTF16toASCII(contentTypeHint).get(),
                       NullString(),    // No forced download
                       nullptr,         // No post data
                       nullptr,         // No headers data
                       loadType,        // Load type
                       nullptr,         // No SHEntry
                       true,
                       srcdoc,          // srcdoc argument for iframe
@@ -9568,17 +9564,17 @@ public:
   NS_IMETHOD
   Run() override
   {
     return mDocShell->InternalLoad(mURI, mOriginalURI,
                                    mLoadReplace,
                                    mReferrer,
                                    mReferrerPolicy,
                                    mTriggeringPrincipal, mPrincipalToInherit,
-                                   mFlags, nullptr, mTypeHint.get(),
+                                   mFlags, EmptyString(), mTypeHint.get(),
                                    NullString(), mPostData, mHeadersData,
                                    mLoadType, mSHEntry, mFirstParty,
                                    mSrcdoc, mSourceDocShell, mBaseURI,
                                    nullptr, nullptr);
   }
 
 private:
   // Use IDL strings so .get() returns null by default
@@ -9658,17 +9654,17 @@ NS_IMETHODIMP
 nsDocShell::InternalLoad(nsIURI* aURI,
                          nsIURI* aOriginalURI,
                          bool aLoadReplace,
                          nsIURI* aReferrer,
                          uint32_t aReferrerPolicy,
                          nsIPrincipal* aTriggeringPrincipal,
                          nsIPrincipal* aPrincipalToInherit,
                          uint32_t aFlags,
-                         const char16_t* aWindowTarget,
+                         const nsAString& aWindowTarget,
                          const char* aTypeHint,
                          const nsAString& aFileName,
                          nsIInputStream* aPostData,
                          nsIInputStream* aHeadersData,
                          uint32_t aLoadType,
                          nsISHEntry* aSHEntry,
                          bool aFirstParty,
                          const nsAString& aSrcdoc,
@@ -9731,25 +9727,24 @@ nsDocShell::InternalLoad(nsIURI* aURI,
 
   bool isJavaScript = false;
   if (NS_FAILED(aURI->SchemeIs("javascript", &isJavaScript))) {
     isJavaScript = false;
   }
 
   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);
     }
 
     targetDocShell = do_QueryInterface(targetItem);
     if (targetDocShell) {
       // If the targetDocShell and the rootDocShell are the same, then the
@@ -9940,17 +9935,17 @@ nsDocShell::InternalLoad(nsIURI* aURI,
     }
   }
 
   //
   // Resolve the window target before going any further...
   // 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.
     aFlags = aFlags & ~INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL;
 
     bool isNewWindow = false;
     if (!targetDocShell) {
       // If the docshell's document is sandboxed, only open a new window
@@ -9965,17 +9960,16 @@ nsDocShell::InternalLoad(nsIURI* aURI,
         if (sandboxFlags & SANDBOXED_AUXILIARY_NAVIGATION) {
           return NS_ERROR_DOM_INVALID_ACCESS_ERR;
         }
       }
 
       nsCOMPtr<nsPIDOMWindowOuter> win = GetWindow();
       NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE);
 
-      nsDependentString name(aWindowTarget);
       nsCOMPtr<nsPIDOMWindowOuter> newWin;
       nsAutoCString spec;
       if (aURI) {
         aURI->GetSpec(spec);
       }
       // If we are a noopener load, we just hand the whole thing over to our
       // window.
       if (aFlags & INTERNAL_LOAD_FLAGS_NO_OPENER) {
@@ -10010,27 +10004,27 @@ nsDocShell::InternalLoad(nsIURI* aURI,
         loadInfo->SetInheritPrincipal(
           aFlags & INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL);
         // Explicit principal because we do not want any guesses as to what the
         // principal to inherit is: it should be aTriggeringPrincipal.
         loadInfo->SetPrincipalIsExplicit(true);
         loadInfo->SetLoadType(ConvertLoadTypeToDocShellLoadInfo(LOAD_LINK));
 
         rv = win->Open(NS_ConvertUTF8toUTF16(spec),
-                       name, // window name
+                       aWindowTarget, // window name
                        EmptyString(), // Features
                        loadInfo,
                        true, // aForceNoOpener
                        getter_AddRefs(newWin));
         MOZ_ASSERT(!newWin);
         return rv;
       }
 
       rv = win->OpenNoNavigate(NS_ConvertUTF8toUTF16(spec),
-                               name,  // window name
+                               aWindowTarget,  // window name
                                EmptyString(), // Features
                                getter_AddRefs(newWin));
 
       // In some cases the Open call doesn't actually result in a new
       // window being opened.  We can detect these cases by examining the
       // document in |newWin|, if any.
       nsCOMPtr<nsPIDOMWindowOuter> piNewWin = do_QueryInterface(newWin);
       if (piNewWin) {
@@ -10053,17 +10047,17 @@ nsDocShell::InternalLoad(nsIURI* aURI,
       rv = targetDocShell->InternalLoad(aURI,
                                         aOriginalURI,
                                         aLoadReplace,
                                         aReferrer,
                                         aReferrerPolicy,
                                         aTriggeringPrincipal,
                                         principalToInherit,
                                         aFlags,
-                                        nullptr,         // No window target
+                                        EmptyString(),   // No window target
                                         aTypeHint,
                                         NullString(),    // No forced download
                                         aPostData,
                                         aHeadersData,
                                         aLoadType,
                                         aSHEntry,
                                         aFirstParty,
                                         aSrcdoc,
@@ -10117,17 +10111,17 @@ nsDocShell::InternalLoad(nsIURI* aURI,
 
   rv = CheckLoadingPermissions();
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   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
       // the unload event also a replace load, so we don't
       // create extra history entries.
       if (LOAD_TYPE_HAS_FLAGS(aLoadType, LOAD_FLAGS_REPLACE_HISTORY)) {
         mLoadType = LOAD_NORMAL_REPLACE;
       }
@@ -12520,17 +12514,17 @@ nsDocShell::LoadHistoryEntry(nsISHEntry*
   rv = InternalLoad(uri,
                     originalURI,
                     loadReplace,
                     referrerURI,
                     referrerPolicy,
                     triggeringPrincipal,
                     principalToInherit,
                     flags,
-                    nullptr,            // No window target
+                    EmptyString(),      // No window target
                     contentType.get(),  // Type hint
                     NullString(),       // No forced file download
                     postData,           // Post data stream
                     nullptr,            // No headers stream
                     aLoadType,          // Load type
                     aEntry,             // SHEntry
                     true,
                     srcdoc,
@@ -14011,17 +14005,17 @@ nsDocShell::OnLinkClickSync(nsIContent* 
                              nullptr,                   // Original URI
                              false,                     // LoadReplace
                              referer,                   // Referer URI
                              refererPolicy,             // Referer policy
                              aContent->NodePrincipal(), // Triggering is our node's
                                                         // principal
                              aContent->NodePrincipal(),
                              flags,
-                             target.get(),              // Window target
+                             target,                    // Window target
                              NS_LossyConvertUTF16toASCII(typeHint).get(),
                              aFileName,                 // Download as file
                              aPostDataStream,           // Post data stream
                              aHeadersDataStream,        // Headers stream
                              LOAD_LINK,                 // Load type
                              nullptr,                   // No SHEntry
                              true,                      // first party site
                              NullString(),              // No srcdoc
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -1032,17 +1032,17 @@ private:
   uint32_t mJSRunToCompletionDepth;
 
   // Whether or not touch events are overridden. Possible values are defined
   // as constants in the nsIDocShell.idl file.
   uint32_t mTouchEventsOverride;
 
   // 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);
 
   // Helper assertion to enforce that mInPrivateBrowsing is in sync with
   // OriginAttributes.mPrivateBrowsingId
   void AssertOriginAttributesMatchPrivateBrowsing();
 
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -185,17 +185,17 @@ interface nsIDocShell : nsIDocShellTreeI
   [noscript]void internalLoad(in nsIURI aURI,
                               in nsIURI aOriginalURI,
                               in boolean aLoadReplace,
                               in nsIURI aReferrer,
                               in unsigned long aReferrerPolicy,
                               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,
                               in nsIInputStream aHeadersStream,
                               in unsigned long aLoadFlags,
                               in nsISHEntry aSHEntry,
                               in boolean firstParty,
                               in AString aSrcdoc,
--- a/docshell/base/nsIDocShellTreeItem.idl
+++ b/docshell/base/nsIDocShellTreeItem.idl
@@ -27,17 +27,17 @@ interface nsIDocShellTreeItem : nsISuppo
 
         /**
          * 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.
          */
-        boolean nameEquals(in wstring name);
+        boolean nameEquals(in AString name);
 
 	/*
 	Definitions for the item types.
 	*/
 	const long typeChrome=0;            // typeChrome must equal 0
 	const long typeContent=1;           // typeContent must equal 1
 	const long typeContentWrapper=2;    // typeContentWrapper must equal 2
 	const long typeChromeWrapper=3;     // typeChromeWrapper must equal 3
@@ -99,17 +99,17 @@ interface nsIDocShellTreeItem : nsISuppo
 		a child with the specific name.  The parent uses this parameter to ensure
 		a resursive state does not occur by not again asking the requestor to find
 		a shell by the specified name.  Inversely the child uses it to ensure it
 		does not ask its parent to do the search if its parent is the one that
 		asked it to search.  Children also use this to test against the treeOwner;
 	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);
 
 	/*
 	The owner of the DocShell Tree.  This interface will be called upon when
 	the docshell has things it needs to tell to the owner of the docshell.
 	Note that docShell tree ownership does not cross tree types.  Meaning
 	setting ownership on a chrome tree does not set ownership on the content 
@@ -167,17 +167,17 @@ interface nsIDocShellTreeItem : nsISuppo
 	aRequestor - This is the docshellTreeItem that is requesting the find.  This
 		parameter is used when recursion is being used to avoid searching the same
 		tree again when a child has asked a parent to search for children.
 	aOriginalRequestor - The original treeitem that made the request, if any.
     	This is used to ensure that we don't run into cross-site issues.
 
 	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,
 	                                      in nsIDocShellTreeItem aOriginalRequestor);
 
   [noscript,nostdcall,notxpcom] nsIDocument getDocument();
   [noscript,nostdcall,notxpcom] nsPIDOMWindowOuter getWindow();
 };
--- a/dom/base/DocGroup.cpp
+++ b/dom/base/DocGroup.cpp
@@ -111,31 +111,28 @@ TabGroup::Join(nsPIDOMWindowOuter* aWind
 void
 TabGroup::Leave(nsPIDOMWindowOuter* aWindow)
 {
   MOZ_ASSERT(mWindows.Contains(aWindow));
   mWindows.RemoveElement(aWindow);
 }
 
 nsresult
-TabGroup::FindItemWithName(const char16_t* aName,
+TabGroup::FindItemWithName(const nsAString& aName,
                            nsIDocShellTreeItem* aRequestor,
                            nsIDocShellTreeItem* aOriginalRequestor,
                            nsIDocShellTreeItem** aFoundItem)
 {
   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
     if (outerWindow->GetScriptableParentOrNull()) {
       continue;
     }
 
     nsCOMPtr<nsIDocShellTreeItem> docshell = outerWindow->GetDocShell();
--- a/dom/base/DocGroup.h
+++ b/dom/base/DocGroup.h
@@ -126,17 +126,17 @@ public:
   // and will not search the docShellTreeItem which is passed as aRequestor.
   //
   // This method is used in order to correctly namespace named windows based on
   // their unit of related browsing contexts.
   //
   // 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);
 
 private:
   ~TabGroup();
   DocGroupMap mDocGroups;
   nsTArray<nsPIDOMWindowOuter*> mWindows;
--- a/dom/base/nsDOMWindowList.cpp
+++ b/dom/base/nsDOMWindowList.cpp
@@ -109,18 +109,17 @@ nsDOMWindowList::NamedItem(const nsAStri
 {
   nsCOMPtr<nsIDocShellTreeItem> item;
 
   *aReturn = nullptr;
 
   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));
     if (globalObject) {
       CallQueryInterface(globalObject.get(), aReturn);
     }
   }
 
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -5994,18 +5994,17 @@ nsGlobalWindow::GetTop(mozilla::ErrorRes
 
 nsPIDOMWindowOuter*
 nsGlobalWindow::GetChildWindow(const nsAString& aName)
 {
   nsCOMPtr<nsIDocShell> docShell(GetDocShell());
   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;
 }
 
 bool
 nsGlobalWindow::DispatchCustomEvent(const nsAString& aEventName)
 {
@@ -6105,17 +6104,17 @@ nsGlobalWindow::WindowExists(const nsASt
     caller = GetCallerDocShellTreeItem();
   }
 
   if (!caller) {
     caller = mDocShell;
   }
 
   nsCOMPtr<nsIDocShellTreeItem> namedItem;
-  mDocShell->FindItemWithName(PromiseFlatString(aName).get(), nullptr, caller,
+  mDocShell->FindItemWithName(aName, nullptr, caller,
                               getter_AddRefs(namedItem));
   return namedItem != nullptr;
 }
 
 already_AddRefed<nsIWidget>
 nsGlobalWindow::GetMainWidget()
 {
   FORWARD_TO_OUTER(GetMainWidget, (), nullptr);
--- a/dom/html/PluginDocument.cpp
+++ b/dom/html/PluginDocument.cpp
@@ -163,17 +163,17 @@ PluginDocument::StartDocumentLoad(const 
                                   bool                aReset,
                                   nsIContentSink*     aSink)
 {
   // do not allow message panes to host full-page plugins
   // returning an error causes helper apps to take over
   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;
     }
   }
 
   nsresult rv =
     MediaDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer,
                                      aDocListener, aReset, aSink);
--- a/embedding/browser/nsWebBrowser.cpp
+++ b/embedding/browser/nsWebBrowser.cpp
@@ -419,19 +419,18 @@ nsWebBrowser::SetName(const nsAString& a
   } else {
     mInitInfo->name = aName;
   }
 
   return NS_OK;
 }
 
 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);
   } else {
     *aResult = mInitInfo->name.Equals(aName);
   }
 
   return NS_OK;
@@ -514,17 +513,17 @@ nsWebBrowser::GetSameTypeRootTreeItem(ns
     NS_ENSURE_SUCCESS((*aRootTreeItem)->GetSameTypeParent(getter_AddRefs(parent)),
                       NS_ERROR_FAILURE);
   }
   NS_ADDREF(*aRootTreeItem);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsWebBrowser::FindItemWithName(const char16_t* aName,
+nsWebBrowser::FindItemWithName(const nsAString& aName,
                                nsISupports* aRequestor,
                                nsIDocShellTreeItem* aOriginalRequestor,
                                nsIDocShellTreeItem** aResult)
 {
   NS_ENSURE_STATE(mDocShell);
   NS_ASSERTION(mDocShellTreeOwner,
                "This should always be set when in this situation");
 
@@ -594,17 +593,17 @@ nsWebBrowser::RemoveChild(nsIDocShellTre
 
 NS_IMETHODIMP
 nsWebBrowser::GetChildAt(int32_t aIndex, nsIDocShellTreeItem** aChild)
 {
   return NS_ERROR_UNEXPECTED;
 }
 
 NS_IMETHODIMP
-nsWebBrowser::FindChildWithName(const char16_t* aName,
+nsWebBrowser::FindChildWithName(const nsAString& aName,
                                 bool aRecurse,
                                 bool aSameType,
                                 nsIDocShellTreeItem* aRequestor,
                                 nsIDocShellTreeItem* aOriginalRequestor,
                                 nsIDocShellTreeItem** aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
 
--- a/embedding/components/windowwatcher/nsIWindowWatcher.idl
+++ b/embedding/components/windowwatcher/nsIWindowWatcher.idl
@@ -143,17 +143,17 @@ interface nsIWindowWatcher : nsISupports
       @param aCurrentWindow a starting point in the window hierarchy to
                             begin the search.  If null, each toplevel window
                             will be searched.
 
       Note: This method will search all open windows for any window or
       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
       (frontmost non-floating-palette-type) window, storing and returning
       it on demand. Users must keep this attribute current, including after
       the topmost window is closed. This attribute obviously can return null
       if no windows are open, but should otherwise always return a valid
       window.
--- a/embedding/components/windowwatcher/nsPIWindowWatcher.idl
+++ b/embedding/components/windowwatcher/nsPIWindowWatcher.idl
@@ -134,13 +134,13 @@ interface nsPIWindowWatcher : nsISupport
    * @return the tree item with aName as the name, or null if there
    *         isn't one.  "Special" names, like _self, _top, etc, will be
    *         treated specially only if aRequestor is null; in that case they
    *         will be resolved relative to the first window the windowwatcher
    *         knows about.
    * @see findItemWithName methods on nsIDocShellTreeItem and
    *      nsIDocShellTreeOwner
    */
-  nsIDocShellTreeItem findItemWithName(in wstring aName,
+  nsIDocShellTreeItem findItemWithName(in AString aName,
                                        in nsIDocShellTreeItem aRequestor,
                                        in nsIDocShellTreeItem aOriginalRequestor);
 };
 
--- a/embedding/components/windowwatcher/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/nsWindowWatcher.cpp
@@ -1634,17 +1634,17 @@ nsWindowWatcher::GetChromeForWindow(mozI
     }
     *aResult = info->mChrome;
     NS_IF_ADDREF(*aResult);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsWindowWatcher::GetWindowByName(const char16_t* aTargetName,
+nsWindowWatcher::GetWindowByName(const nsAString& aTargetName,
                                  mozIDOMWindowProxy* aCurrentWindow,
                                  mozIDOMWindowProxy** aResult)
 {
   if (!aResult) {
     return NS_ERROR_INVALID_ARG;
   }
 
   *aResult = nullptr;
@@ -2051,31 +2051,30 @@ nsWindowWatcher::WinHasOption(const nsAC
   return found;
 }
 
 /* try to find an nsIDocShellTreeItem with the given name in any
    known open window. a failure to find the item will not
    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;
   }
 
   // If we are looking for an item and we don't have a docshell we are checking
   // on, let's just look in the chrome tab group!
   return TabGroup::GetChromeTabGroup()->FindItemWithName(aName,
                                                          aRequestor,
                                                          aOriginalRequestor,
@@ -2108,24 +2107,22 @@ nsWindowWatcher::SafeGetWindowByName(con
     }
   }
 
   nsCOMPtr<nsIDocShellTreeItem> startItem;
   GetWindowTreeItem(aCurrentWindow, getter_AddRefs(startItem));
 
   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));
   }
 
   return foundItem ? foundItem->GetWindow() : nullptr;
 }
 
 /* Fetch the nsIDOMWindow corresponding to the given nsIDocShellTreeItem.
    This forces the creation of a script context, if one has not already
deleted file mode 100644
--- a/testing/web-platform/meta/html/browsers/the-window-object/named-access-on-the-window-object/window-null-names.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[window-null-names.html]
-  type: testharness
-  [Named access with null characters]
-    expected: FAIL
-