Bug 1322414 - part 2: use a separate 'primary' attribute for primary child browsers, r?bz draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 09 Dec 2016 09:23:24 -1000
changeset 448282 bec2276053b06534ae9b4bae5d485273c39d02a4
parent 448262 3d63ad47ad8c301f193d126782d1d2960e21767c
child 448283 df74e2409a1528c09d567aca88b489673cf3f41d
push id38300
push usergijskruitbosch@gmail.com
push dateFri, 09 Dec 2016 19:26:07 +0000
reviewersbz
bugs1322414
milestone53.0a1
Bug 1322414 - part 2: use a separate 'primary' attribute for primary child browsers, r?bz MozReview-Commit-ID: LeSUtzM5Nkg
dom/base/nsFrameLoader.cpp
dom/xul/nsXULElement.cpp
layout/tools/layout-debug/ui/content/layoutdebug.xul
layout/tools/recording/recording.xul
toolkit/components/viewsource/content/viewPartialSource.xul
toolkit/components/viewsource/content/viewSource.xul
--- a/dom/base/nsFrameLoader.cpp
+++ b/dom/base/nsFrameLoader.cpp
@@ -909,26 +909,18 @@ nsFrameLoader::AddTreeItemToTreeOwner(ns
                                       nsIDocShellTreeOwner* aOwner,
                                       int32_t aParentType,
                                       nsIDocShell* aParentNode)
 {
   NS_PRECONDITION(aItem, "Must have docshell treeitem");
   NS_PRECONDITION(mOwnerContent, "Must have owning content");
 
   nsAutoString value;
-  bool isContent = false;
-  mOwnerContent->GetAttr(kNameSpaceID_None, TypeAttrName(), value);
-
-  // we accept "content" and "content-xxx" values.
-  // at time of writing, we expect "xxx" to be "primary" or "targetable", but
-  // someday it might be an integer expressing priority or something else.
-
-  isContent = value.LowerCaseEqualsLiteral("content") ||
-    StringBeginsWith(value, NS_LITERAL_STRING("content-"),
-                     nsCaseInsensitiveStringComparator());
+  bool isContent = mOwnerContent->AttrValueIs(
+    kNameSpaceID_None, TypeAttrName(), nsGkAtoms::content, eIgnoreCase);
 
   // Force mozbrowser frames to always be typeContent, even if the
   // mozbrowser interfaces are disabled.
   nsCOMPtr<nsIDOMMozBrowserFrame> mozbrowser =
     do_QueryInterface(mOwnerContent);
   if (mozbrowser) {
     bool isMozbrowser = false;
     mozbrowser->GetMozbrowser(&isMozbrowser);
@@ -951,18 +943,19 @@ nsFrameLoader::AddTreeItemToTreeOwner(ns
   if (aParentNode) {
     aParentNode->AddChild(aItem);
   }
 
   bool retval = false;
   if (aParentType == nsIDocShellTreeItem::typeChrome && isContent) {
     retval = true;
 
-    bool is_primary = value.LowerCaseEqualsLiteral("content-primary");
-
+    bool is_primary =
+      mOwnerContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::primary,
+                                 nsGkAtoms::_true, eIgnoreCase);
     if (aOwner) {
       mOwnerContent->AddMutationObserver(this);
       mObservingOwnerContent = true;
       aOwner->ContentShellAdded(aItem, is_primary);
     }
   }
 
   return retval;
@@ -2809,22 +2802,18 @@ nsFrameLoader::TryRemoteBrowser()
         return false;
       }
     }
 
     if (!mOwnerContent->IsXULElement()) {
       return false;
     }
 
-    nsAutoString value;
-    mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::type, value);
-
-    if (!value.LowerCaseEqualsLiteral("content") &&
-        !StringBeginsWith(value, NS_LITERAL_STRING("content-"),
-                          nsCaseInsensitiveStringComparator())) {
+    if (!mOwnerContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
+                                    nsGkAtoms::content, eIgnoreCase)) {
       return false;
     }
 
     // Try to get the related content parent from our browser element.
     openerContentParent = GetContentParent(mOwnerContent);
   }
 
   uint32_t chromeFlags = 0;
@@ -3225,17 +3214,18 @@ nsFrameLoader::AttributeChanged(nsIDocum
                                 mozilla::dom::Element* aElement,
                                 int32_t      aNameSpaceID,
                                 nsIAtom*     aAttribute,
                                 int32_t      aModType,
                                 const nsAttrValue* aOldValue)
 {
   MOZ_ASSERT(mObservingOwnerContent);
 
-  if (aNameSpaceID != kNameSpaceID_None || aAttribute != TypeAttrName()) {
+  if (aNameSpaceID != kNameSpaceID_None ||
+      (aAttribute != TypeAttrName() && aAttribute != nsGkAtoms::primary)) {
     return;
   }
 
   if (aElement != mOwnerContent) {
     return;
   }
 
   // Note: This logic duplicates a lot of logic in
@@ -3260,35 +3250,30 @@ nsFrameLoader::AttributeChanged(nsIDocum
   }
 
   nsCOMPtr<nsIDocShellTreeOwner> parentTreeOwner;
   parentItem->GetTreeOwner(getter_AddRefs(parentTreeOwner));
   if (!parentTreeOwner) {
     return;
   }
 
-  nsAutoString value;
-  aElement->GetAttr(kNameSpaceID_None, TypeAttrName(), value);
-
-  bool is_primary = value.LowerCaseEqualsLiteral("content-primary");
+  bool is_primary =
+    aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::primary, nsGkAtoms::_true, eIgnoreCase);
 
 #ifdef MOZ_XUL
   // when a content panel is no longer primary, hide any open popups it may have
   if (!is_primary) {
     nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
     if (pm)
       pm->HidePopupsInDocShell(mDocShell);
   }
 #endif
 
   parentTreeOwner->ContentShellRemoved(mDocShell);
-  if (value.LowerCaseEqualsLiteral("content") ||
-      StringBeginsWith(value, NS_LITERAL_STRING("content-"),
-                       nsCaseInsensitiveStringComparator())) {
-
+  if (aElement->AttrValueIs(kNameSpaceID_None, TypeAttrName(), nsGkAtoms::content, eIgnoreCase)) {
     parentTreeOwner->ContentShellAdded(mDocShell, is_primary);
   }
 }
 
 /**
  * Send the RequestNotifyAfterRemotePaint message to the current Tab.
  */
 NS_IMETHODIMP
@@ -3488,20 +3473,18 @@ nsFrameLoader::MaybeUpdatePrimaryTabPare
     if (!mObservingOwnerContent) {
       mOwnerContent->AddMutationObserver(this);
       mObservingOwnerContent = true;
     }
 
     parentTreeOwner->TabParentRemoved(mRemoteBrowser);
     if (aChange == eTabParentChanged) {
       bool isPrimary =
-        mOwnerContent->AttrValueIs(kNameSpaceID_None,
-                                   TypeAttrName(),
-                                   NS_LITERAL_STRING("content-primary"),
-                                   eIgnoreCase);
+        mOwnerContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::primary,
+                                   nsGkAtoms::_true, eIgnoreCase);
       parentTreeOwner->TabParentAdded(mRemoteBrowser, isPrimary);
     }
   }
 }
 
 nsresult
 nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
                                 nsIURI* aURI)
--- a/dom/xul/nsXULElement.cpp
+++ b/dom/xul/nsXULElement.cpp
@@ -1604,20 +1604,20 @@ nsXULElement::LoadSrc()
         return NS_OK;
     }
     RefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
     if (!frameLoader) {
         // Check if we have an opener we need to be setting
         nsXULSlots* slots = static_cast<nsXULSlots*>(Slots());
         nsCOMPtr<nsPIDOMWindowOuter> opener = do_QueryInterface(slots->mFrameLoaderOrOpener);
         if (!opener) {
-            // If we are a content-primary xul-browser, we want to take the opener property!
+            // If we are a primary xul-browser, we want to take the opener property!
             nsCOMPtr<nsIDOMChromeWindow> chromeWindow = do_QueryInterface(OwnerDoc()->GetWindow());
-            if (AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
-                            NS_LITERAL_STRING("content-primary"), eIgnoreCase) &&
+            if (AttrValueIs(kNameSpaceID_None, nsGkAtoms::primary,
+                            nsGkAtoms::_true, eIgnoreCase) &&
                 chromeWindow) {
                 nsCOMPtr<mozIDOMWindowProxy> wp;
                 chromeWindow->TakeOpenerForInitialContentBrowser(getter_AddRefs(wp));
                 opener = nsPIDOMWindowOuter::From(wp);
             }
         }
 
         // false as the last parameter so that xul:iframe/browser/editor
--- a/layout/tools/layout-debug/ui/content/layoutdebug.xul
+++ b/layout/tools/layout-debug/ui/content/layoutdebug.xul
@@ -172,16 +172,16 @@
                        oncommand="gBrowser.stop();" />
 
         <textbox id="urlbar" flex="1"
                  onkeypress="if (event.keyCode == 13)
                                gBrowser.loadURI(this.value);" />
       </toolbar>
     </toolbox>
 
-    <browser flex="1" id="browser" type="content-primary"
+    <browser flex="1" id="browser" type="content" primary="true"
              homepage="about:blank" />
 
     <hbox>
       <description id="status-text" value="" />
     </hbox>
   </vbox>
 </window>
--- a/layout/tools/recording/recording.xul
+++ b/layout/tools/recording/recording.xul
@@ -4,10 +4,10 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         id="recording-window"
         hidechrome="true"
         onload="OnRecordingLoad();"
         style="background:white; overflow:hidden; width:800px; height:600px;"
         >
     <script type="application/ecmascript" src="recording.js" />
-  <browser id="browser" type="content-primary" style="min-width: 1024px; min-height: 768px; max-width: 1024px; max-height: 768px"/>
+  <browser id="browser" type="content" primary="true" style="min-width: 1024px; min-height: 768px; max-width: 1024px; max-height: 768px"/>
 </window>
--- a/toolkit/components/viewsource/content/viewPartialSource.xul
+++ b/toolkit/components/viewsource/content/viewPartialSource.xul
@@ -150,14 +150,14 @@
           <menuitem type="checkbox" id="menu_highlightSyntax" command="cmd_highlightSyntax"
                     label="&menu_highlightSyntax.label;" accesskey="&menu_highlightSyntax.accesskey;"/>
         </menupopup>
       </menu>
     </menubar>
   </toolbox>
 
   <vbox id="appcontent" flex="1">
-    <browser id="content" type="content-primary" name="content" src="about:blank" flex="1"
+    <browser id="content" type="content" primary="true" name="content" src="about:blank" flex="1"
              disablehistory="true" context="viewSourceContextMenu" />
     <findbar id="FindToolbar" browserid="content"/>
   </vbox>
 
 </window>
--- a/toolkit/components/viewsource/content/viewSource.xul
+++ b/toolkit/components/viewsource/content/viewSource.xul
@@ -218,17 +218,18 @@
                     label="&menu_highlightSyntax.label;" accesskey="&menu_highlightSyntax.accesskey;"/>
         </menupopup>
       </menu>
     </menubar>
   </toolbox>
 
   <vbox id="appcontent" flex="1">
 
-    <browser id="content" type="content-primary" name="content" src="about:blank" flex="1"
+    <browser id="content" type="content" name="content" src="about:blank" flex="1"
+             primary="true"
              context="viewSourceContextMenu" showcaret="true" tooltip="aHTMLTooltip" />
     <findbar id="FindToolbar" browserid="content"/>
   </vbox>
 
   <statusbar id="status-bar" class="chromeclass-status">
     <statusbarpanel id="statusbar-line-col" label="" flex="1"/>
   </statusbar>