Bug 956015 - Add an infallible nsIDocShellTreeItem::ItemType; r=bz
authorMs2ger <ms2ger@gmail.com>
Mon, 20 Jan 2014 08:58:26 +0100
changeset 164270 49993e01b351fc4de163be15554e45fbcb574d2e
parent 164269 efc86619fcc56c587cc44f0638ab3610da848cc8
child 164271 61875c765ea1c0129a4e166e47a919c867381ec8
push id38658
push userMs2ger@gmail.com
push dateMon, 20 Jan 2014 08:36:21 +0000
treeherdermozilla-inbound@d86d7bf553c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs956015
milestone29.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 956015 - Add an infallible nsIDocShellTreeItem::ItemType; r=bz
accessible/src/base/nsCoreUtils.cpp
accessible/src/generic/Accessible.cpp
accessible/src/generic/DocAccessible.cpp
content/base/src/nsContentAreaDragDrop.cpp
content/base/src/nsContentUtils.cpp
content/base/src/nsCopySupport.cpp
content/base/src/nsDocument.cpp
content/base/src/nsFrameLoader.cpp
docshell/base/nsDocShell.cpp
docshell/base/nsDocShellEnumerator.cpp
docshell/base/nsIDocShellTreeItem.idl
dom/base/nsFocusManager.cpp
dom/base/nsGlobalWindow.cpp
dom/base/nsGlobalWindowCommands.cpp
dom/base/nsScreen.cpp
dom/events/nsEventStateManager.cpp
embedding/browser/webBrowser/nsWebBrowser.cpp
extensions/permissions/nsContentBlocker.cpp
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsDocumentViewer.cpp
layout/base/nsPresContext.cpp
layout/printing/nsPrintObject.cpp
layout/xul/nsMenuPopupFrame.cpp
layout/xul/nsResizerFrame.cpp
layout/xul/nsTitleBarFrame.cpp
security/manager/boot/src/nsSecureBrowserUIImpl.cpp
--- a/accessible/src/base/nsCoreUtils.cpp
+++ b/accessible/src/base/nsCoreUtils.cpp
@@ -411,19 +411,17 @@ nsCoreUtils::IsRootDocument(nsIDocument 
 }
 
 bool
 nsCoreUtils::IsContentDocument(nsIDocument *aDocument)
 {
   nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem = aDocument->GetDocShell();
   NS_ASSERTION(docShellTreeItem, "No document shell tree item for document!");
 
-  int32_t contentType;
-  docShellTreeItem->GetItemType(&contentType);
-  return (contentType == nsIDocShellTreeItem::typeContent);
+  return (docShellTreeItem->ItemType() == nsIDocShellTreeItem::typeContent);
 }
 
 bool
 nsCoreUtils::IsTabDocument(nsIDocument* aDocumentNode)
 {
   nsCOMPtr<nsIDocShellTreeItem> treeItem(aDocumentNode->GetDocShell());
 
   nsCOMPtr<nsIDocShellTreeItem> parentTreeItem;
--- a/accessible/src/generic/Accessible.cpp
+++ b/accessible/src/generic/Accessible.cpp
@@ -378,19 +378,18 @@ Accessible::AccessKey() const
   if (!document)
     return KeyBinding();
 
   nsCOMPtr<nsIDocShellTreeItem> treeItem(document->GetDocShell());
   if (!treeItem)
     return KeyBinding();
 
   nsresult rv = NS_ERROR_FAILURE;
-  int32_t itemType = 0, modifierMask = 0;
-  treeItem->GetItemType(&itemType);
-  switch (itemType) {
+  int32_t modifierMask = 0;
+  switch (treeItem->ItemType()) {
     case nsIDocShellTreeItem::typeChrome:
       rv = Preferences::GetInt("ui.key.chromeAccess", &modifierMask);
       break;
     case nsIDocShellTreeItem::typeContent:
       rv = Preferences::GetInt("ui.key.contentAccess", &modifierMask);
       break;
   }
 
@@ -2115,20 +2114,19 @@ Accessible::RelationByType(RelationType 
         // Walk up the parent chain without crossing the boundary at which item
         // types change, preventing us from walking up out of tab content.
         nsCOMPtr<nsIDocShellTreeItem> root;
         docShell->GetSameTypeRootTreeItem(getter_AddRefs(root));
         if (root) {
           // If the item type is typeContent, we assume we are in browser tab
           // content. Note, this includes content such as about:addons,
           // for consistency.
-          int32_t itemType = 0;
-          root->GetItemType(&itemType);
-          if (itemType == nsIDocShellTreeItem::typeContent)
+          if (root->ItemType() == nsIDocShellTreeItem::typeContent) {
             return Relation(nsAccUtils::GetDocAccessibleFor(root));
+          }
         }
       }
       return  Relation();
     }
 
     case RelationType::CONTAINING_APPLICATION:
       return Relation(ApplicationAcc());
 
--- a/accessible/src/generic/DocAccessible.cpp
+++ b/accessible/src/generic/DocAccessible.cpp
@@ -184,18 +184,17 @@ DocAccessible::Name(nsString& aName)
 // Accessible public method
 role
 DocAccessible::NativeRole()
 {
   nsCOMPtr<nsIDocShell> docShell = nsCoreUtils::GetDocShellFor(mDocumentNode);
   if (docShell) {
     nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
     docShell->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
-    int32_t itemType;
-    docShell->GetItemType(&itemType);
+    int32_t itemType = docShell->ItemType();
     if (sameTypeRoot == docShell) {
       // Root of content or chrome tree
       if (itemType == nsIDocShellTreeItem::typeChrome)
         return roles::CHROME_WINDOW;
 
       if (itemType == nsIDocShellTreeItem::typeContent) {
 #ifdef MOZ_XUL
         nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocumentNode));
@@ -687,19 +686,17 @@ DocAccessible::GetBoundsRect(nsRect& aBo
 // DocAccessible protected member
 nsresult
 DocAccessible::AddEventListeners()
 {
   nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(mDocumentNode->GetDocShell());
 
   // We want to add a command observer only if the document is content and has
   // an editor.
-  int32_t itemType;
-  docShellTreeItem->GetItemType(&itemType);
-  if (itemType == nsIDocShellTreeItem::typeContent) {
+  if (docShellTreeItem->ItemType() == nsIDocShellTreeItem::typeContent) {
     nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(docShellTreeItem);
     if (commandManager)
       commandManager->AddCommandObserver(this, "obs_documentCreated");
   }
 
   SelectionMgr()->AddDocSelectionListener(mPresShell);
 
   // Add document observer.
@@ -719,19 +716,17 @@ DocAccessible::RemoveEventListeners()
 
   if (mDocumentNode) {
     mDocumentNode->RemoveObserver(this);
 
     nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(mDocumentNode->GetDocShell());
     NS_ASSERTION(docShellTreeItem, "doc should support nsIDocShellTreeItem.");
 
     if (docShellTreeItem) {
-      int32_t itemType;
-      docShellTreeItem->GetItemType(&itemType);
-      if (itemType == nsIDocShellTreeItem::typeContent) {
+      if (docShellTreeItem->ItemType() == nsIDocShellTreeItem::typeContent) {
         nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(docShellTreeItem);
         if (commandManager) {
           commandManager->RemoveCommandObserver(this, "obs_documentCreated");
         }
       }
     }
   }
 
@@ -2023,19 +2018,17 @@ DocAccessible::IsLoadEventTarget() const
     // b) frame/iframe document and its parent document is not in loading state
     // Note: we can get notifications while document is loading (and thus
     // while there's no parent document yet).
     DocAccessible* parentDoc = ParentDocument();
     return parentDoc && parentDoc->HasLoadState(eCompletelyLoaded);
   }
 
   // It's content (not chrome) root document.
-  int32_t contentType;
-  treeItem->GetItemType(&contentType);
-  return (contentType == nsIDocShellTreeItem::typeContent);
+  return (treeItem->ItemType() == nsIDocShellTreeItem::typeContent);
 }
 
 PLDHashOperator
 DocAccessible::CycleCollectorTraverseDepIDsEntry(const nsAString& aKey,
                                                  AttrRelProviderArray* aProviders,
                                                  void* aUserArg)
 {
   nsCycleCollectionTraversalCallback* cb =
--- a/content/base/src/nsContentAreaDragDrop.cpp
+++ b/content/base/src/nsContentAreaDragDrop.cpp
@@ -403,26 +403,20 @@ DragDataProducer::Produce(nsDOMDataTrans
       }
       findFormParent = findFormParent->GetParent();
     }
   }
     
   // if set, serialize the content under this node
   nsCOMPtr<nsIContent> nodeToSerialize;
 
-  bool isChromeShell = false;
   nsCOMPtr<nsIWebNavigation> webnav = do_GetInterface(mWindow);
   nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(webnav);
-  if (dsti) {
-    int32_t type = -1;
-    if (NS_SUCCEEDED(dsti->GetItemType(&type)) &&
-        type == nsIDocShellTreeItem::typeChrome) {
-      isChromeShell = true;
-    }
-  }
+  const bool isChromeShell =
+    dsti && dsti->ItemType() == nsIDocShellTreeItem::typeChrome;
 
   // In chrome shells, only allow dragging inside editable areas.
   if (isChromeShell && !editingElement)
     return NS_OK;
 
   if (isChromeShell && textControl) {
     // Only use the selection if the target node is in the selection.
     bool selectionContainsTarget = false;
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -3214,23 +3214,22 @@ nsContentUtils::IsInChromeDocshell(nsIDo
   if (!aDocument) {
     return false;
   }
 
   if (aDocument->GetDisplayDocument()) {
     return IsInChromeDocshell(aDocument->GetDisplayDocument());
   }
 
-  nsCOMPtr<nsIDocShellTreeItem> docShell(aDocument->GetDocShell());
-  int32_t itemType = nsIDocShellTreeItem::typeContent;
-  if (docShell) {
-    docShell->GetItemType(&itemType);
-  }
-
-  return itemType == nsIDocShellTreeItem::typeChrome;
+  nsCOMPtr<nsIDocShellTreeItem> docShell = aDocument->GetDocShell();
+  if (!docShell) {
+    return false;
+  }
+
+  return docShell->ItemType() == nsIDocShellTreeItem::typeChrome;
 }
 
 // static
 nsIContentPolicy*
 nsContentUtils::GetContentPolicy()
 {
   if (!sTriedToGetContentPolicy) {
     CallGetService(NS_CONTENTPOLICY_CONTRACTID, &sContentPolicyService);
@@ -5037,23 +5036,18 @@ nsContentUtils::CheckForSubFrameDrop(nsI
   
   nsIDocument* targetDoc = target->OwnerDoc();
   nsCOMPtr<nsIWebNavigation> twebnav = do_GetInterface(targetDoc->GetWindow());
   nsCOMPtr<nsIDocShellTreeItem> tdsti = do_QueryInterface(twebnav);
   if (!tdsti) {
     return true;
   }
 
-  int32_t type = -1;
-  if (NS_FAILED(tdsti->GetItemType(&type))) {
-    return true;
-  }
-
   // Always allow dropping onto chrome shells.
-  if (type == nsIDocShellTreeItem::typeChrome) {
+  if (tdsti->ItemType() == nsIDocShellTreeItem::typeChrome) {
     return false;
   }
 
   // If there is no source node, then this is a drag from another
   // application, which should be allowed.
   nsCOMPtr<nsIDOMDocument> sourceDocument;
   aDragSession->GetSourceDocument(getter_AddRefs(sourceDocument));
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(sourceDocument);
--- a/content/base/src/nsCopySupport.cpp
+++ b/content/base/src/nsCopySupport.cpp
@@ -632,20 +632,19 @@ nsCopySupport::FireClipboardEvent(int32_
     if (!content)
       return false;
   }
 
   // It seems to be unsafe to fire an event handler during reflow (bug 393696)
   if (!nsContentUtils::IsSafeToRunScript())
     return false;
 
-  int32_t type = -1;
   nsCOMPtr<nsIDocShell> docShell = do_GetInterface(piWindow);
-  bool chromeShell = (docShell && NS_SUCCEEDED(docShell->GetItemType(&type)) &&
-                      type == nsIDocShellTreeItem::typeChrome);
+  const bool chromeShell =
+    docShell && docShell->ItemType() == nsIDocShellTreeItem::typeChrome;
 
   // next, fire the cut, copy or paste event
   bool doDefault = true;
   nsRefPtr<nsDOMDataTransfer> clipboardData;
   if (chromeShell || Preferences::GetBool("dom.event.clipboardevents.enabled", true)) {
     clipboardData = new nsDOMDataTransfer(aType, aType == NS_PASTE, aClipboardType);
 
     nsEventStatus status = nsEventStatus_eIgnore;
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -4253,20 +4253,17 @@ nsIDocument::SetContainer(nsDocShell* aC
   }
 
   EnumerateFreezableElements(NotifyActivityChanged, nullptr);
   if (!aContainer) {
     return;
   }
 
   // Get the Docshell
-  int32_t itemType;
-  aContainer->GetItemType(&itemType);
-  // check itemtype
-  if (itemType == nsIDocShellTreeItem::typeContent) {
+  if (aContainer->ItemType() == nsIDocShellTreeItem::typeContent) {
     // check if same type root
     nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
     aContainer->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
     NS_ASSERTION(sameTypeRoot, "No document shell root tree item from document shell tree item!");
 
     if (sameTypeRoot == aContainer) {
       static_cast<nsDocument*>(this)->SetIsTopLevelContentDocument(true);
     }
--- a/content/base/src/nsFrameLoader.cpp
+++ b/content/base/src/nsFrameLoader.cpp
@@ -778,19 +778,17 @@ AllDescendantsOfType(nsIDocShellTreeItem
 {
   int32_t childCount = 0;
   aParentItem->GetChildCount(&childCount);
 
   for (int32_t i = 0; i < childCount; ++i) {
     nsCOMPtr<nsIDocShellTreeItem> kid;
     aParentItem->GetChildAt(i, getter_AddRefs(kid));
 
-    int32_t kidType;
-    kid->GetItemType(&kidType);
-    if (kidType != aType || !AllDescendantsOfType(kid, aType)) {
+    if (kid->ItemType() != aType || !AllDescendantsOfType(kid, aType)) {
       return false;
     }
   }
 
   return true;
 }
 
 /**
@@ -1085,20 +1083,18 @@ nsFrameLoader::SwapWithOtherLoader(nsFra
   if ((ourRootTreeItem != ourDocshell || otherRootTreeItem != otherDocshell) &&
       (ourHistory || otherHistory)) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   // Also make sure that the two docshells are the same type. Otherwise
   // swapping is certainly not safe. If this needs to be changed then
   // the code below needs to be audited as it assumes identical types.
-  int32_t ourType = nsIDocShellTreeItem::typeChrome;
-  int32_t otherType = nsIDocShellTreeItem::typeChrome;
-  ourDocshell->GetItemType(&ourType);
-  otherDocshell->GetItemType(&otherType);
+  int32_t ourType = ourDocshell->ItemType();
+  int32_t otherType = otherDocshell->ItemType();
   if (ourType != otherType) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   // One more twist here.  Setting up the right treeowners in a heterogeneous
   // tree is a bit of a pain.  So make sure that if ourType is not
   // nsIDocShellTreeItem::typeContent then all of our descendants are the same
   // type as us.
@@ -1118,20 +1114,18 @@ nsFrameLoader::SwapWithOtherLoader(nsFra
   nsCOMPtr<nsIDocShellTreeItem> ourParentItem, otherParentItem;
   ourDocshell->GetParent(getter_AddRefs(ourParentItem));
   otherDocshell->GetParent(getter_AddRefs(otherParentItem));
   if (!ourParentItem || !otherParentItem) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   // Make sure our parents are the same type too
-  int32_t ourParentType = nsIDocShellTreeItem::typeContent;
-  int32_t otherParentType = nsIDocShellTreeItem::typeContent;
-  ourParentItem->GetItemType(&ourParentType);
-  otherParentItem->GetItemType(&otherParentType);
+  int32_t ourParentType = ourParentItem->ItemType();
+  int32_t otherParentType = otherParentItem->ItemType();
   if (ourParentType != otherParentType) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   nsCOMPtr<nsPIDOMWindow> ourWindow = do_GetInterface(ourDocshell);
   nsCOMPtr<nsPIDOMWindow> otherWindow = do_GetInterface(otherDocshell);
 
   nsCOMPtr<Element> ourFrameElement =
@@ -1611,18 +1605,17 @@ nsFrameLoader::MaybeCreateDocShell()
   if (!frameName.IsEmpty()) {
     mDocShell->SetName(frameName);
   }
 
   // Inform our docShell that it has a new child.
   // Note: This logic duplicates a lot of logic in
   // nsSubDocumentFrame::AttributeChanged.  We should fix that.
 
-  int32_t parentType;
-  docShell->GetItemType(&parentType);
+  int32_t parentType = docShell->ItemType();
 
   // XXXbz why is this in content code, exactly?  We should handle
   // this some other way.....  Not sure how yet.
   nsCOMPtr<nsIDocShellTreeOwner> parentTreeOwner;
   docShell->GetTreeOwner(getter_AddRefs(parentTreeOwner));
   NS_ENSURE_STATE(parentTreeOwner);
   mIsTopLevelContent =
     AddTreeItemToTreeOwner(mDocShell, parentTreeOwner, parentType, docShell);
@@ -1748,20 +1741,17 @@ nsFrameLoader::CheckForRecursiveLoad(nsI
 
   // Check that we're still in the docshell tree.
   nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
   mDocShell->GetTreeOwner(getter_AddRefs(treeOwner));
   NS_WARN_IF_FALSE(treeOwner,
                    "Trying to load a new url to a docshell without owner!");
   NS_ENSURE_STATE(treeOwner);
   
-  
-  int32_t ourType;
-  rv = mDocShell->GetItemType(&ourType);
-  if (NS_SUCCEEDED(rv) && ourType != nsIDocShellTreeItem::typeContent) {
+  if (mDocShell->ItemType() != nsIDocShellTreeItem::typeContent) {
     // No need to do recursion-protection here XXXbz why not??  Do we really
     // trust people not to screw up with non-content docshells?
     return NS_OK;
   }
 
   // Bug 8065: Don't exceed some maximum depth in content frames
   // (MAX_DEPTH_CONTENT_FRAMES)
   nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
@@ -2010,20 +2000,17 @@ nsFrameLoader::TryRemoteBrowser()
   if (!parentAsWebNav) {
     return false;
   }
 
   nsCOMPtr<nsIDocShellTreeItem> parentAsItem(do_QueryInterface(parentAsWebNav));
 
   // <iframe mozbrowser> gets to skip these checks.
   if (!OwnerIsBrowserOrAppFrame()) {
-    int32_t parentType;
-    parentAsItem->GetItemType(&parentType);
-
-    if (parentType != nsIDocShellTreeItem::typeChrome) {
+    if (parentAsItem->ItemType() != nsIDocShellTreeItem::typeChrome) {
       return false;
     }
 
     if (!mOwnerContent->IsXUL()) {
       return false;
     }
 
     nsAutoString value;
@@ -2539,20 +2526,17 @@ nsFrameLoader::AttributeChanged(nsIDocum
   }
 
   nsCOMPtr<nsIDocShellTreeItem> parentItem;
   mDocShell->GetParent(getter_AddRefs(parentItem));
   if (!parentItem) {
     return;
   }
 
-  int32_t parentType;
-  parentItem->GetItemType(&parentType);
-
-  if (parentType != nsIDocShellTreeItem::typeChrome) {
+  if (parentItem->ItemType() != nsIDocShellTreeItem::typeChrome) {
     return;
   }
 
   nsCOMPtr<nsIDocShellTreeOwner> parentTreeOwner;
   parentItem->GetTreeOwner(getter_AddRefs(parentTreeOwner));
   if (!parentTreeOwner) {
     return;
   }
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -2834,22 +2834,28 @@ NS_IMETHODIMP
 nsDocShell::NameEquals(const char16_t *aName, bool *_retval)
 {
     NS_ENSURE_ARG_POINTER(aName);
     NS_ENSURE_ARG_POINTER(_retval);
     *_retval = mName.Equals(aName);
     return NS_OK;
 }
 
+/* virtual */ int32_t
+nsDocShell::ItemType()
+{
+   return mItemType;
+}
+
 NS_IMETHODIMP
 nsDocShell::GetItemType(int32_t * aItemType)
 {
     NS_ENSURE_ARG_POINTER(aItemType);
 
-    *aItemType = mItemType;
+    *aItemType = ItemType();
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::SetItemType(int32_t aItemType)
 {
     NS_ENSURE_ARG((aItemType == typeChrome) || (typeContent == aItemType));
 
@@ -3023,40 +3029,34 @@ nsDocShell::GetSameTypeParent(nsIDocShel
         return NS_OK;
     }
 
     nsCOMPtr<nsIDocShellTreeItem> parent =
         do_QueryInterface(GetAsSupports(mParent));
     if (!parent)
         return NS_OK;
 
-    int32_t parentType;
-    NS_ENSURE_SUCCESS(parent->GetItemType(&parentType), NS_ERROR_FAILURE);
-
-    if (parentType == mItemType) {
+    if (parent->ItemType() == mItemType) {
         parent.swap(*aParent);
     }
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetSameTypeParentIgnoreBrowserAndAppBoundaries(nsIDocShell** aParent)
 {
     NS_ENSURE_ARG_POINTER(aParent);
     *aParent = nullptr;
 
     nsCOMPtr<nsIDocShellTreeItem> parent =
         do_QueryInterface(GetAsSupports(mParent));
     if (!parent)
         return NS_OK;
 
-    int32_t parentType;
-    NS_ENSURE_SUCCESS(parent->GetItemType(&parentType), NS_ERROR_FAILURE);
-
-    if (parentType == mItemType) {
+    if (parent->ItemType() == mItemType) {
         nsCOMPtr<nsIDocShell> parentDS = do_QueryInterface(parent);
         parentDS.forget(aParent);
     }
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetRootTreeItem(nsIDocShellTreeItem ** aRootTreeItem)
@@ -3346,19 +3346,17 @@ nsDocShell::DoFindItemWithName(const cha
     // don't have a parent, then we should ask the
     // docShellTreeOwner to do the search.
     nsCOMPtr<nsIDocShellTreeItem> parentAsTreeItem =
         do_QueryInterface(GetAsSupports(mParent));
     if (parentAsTreeItem) {
         if (parentAsTreeItem == reqAsTreeItem)
             return NS_OK;
 
-        int32_t parentType;
-        parentAsTreeItem->GetItemType(&parentType);
-        if (parentType == mItemType) {
+        if (parentAsTreeItem->ItemType() == mItemType) {
             return parentAsTreeItem->
                 FindItemWithName(aName,
                                  static_cast<nsIDocShellTreeItem*>
                                             (this),
                                  aOriginalRequestor,
                                  _retval);
         }
     }
@@ -3458,18 +3456,17 @@ nsDocShell::GetTreeOwner(nsIDocShellTree
 static void 
 PrintDocTree(nsIDocShellTreeItem * aParentNode, int aLevel)
 {
   for (int32_t i=0;i<aLevel;i++) printf("  ");
 
   int32_t childWebshellCount;
   aParentNode->GetChildCount(&childWebshellCount);
   nsCOMPtr<nsIDocShell> parentAsDocShell(do_QueryInterface(aParentNode));
-  int32_t type;
-  aParentNode->GetItemType(&type);
+  int32_t type = aParentNode->ItemType();
   nsCOMPtr<nsIPresShell> presShell = parentAsDocShell->GetPresShell();
   nsRefPtr<nsPresContext> presContext;
   parentAsDocShell->GetPresContext(getter_AddRefs(presContext));
   nsIDocument *doc = presShell->GetDocument();
 
   nsCOMPtr<nsIDOMWindow> domwin(doc->GetWindow());
 
   nsCOMPtr<nsIWidget> widget;
@@ -3551,19 +3548,18 @@ nsDocShell::SetTreeOwner(nsIDocShellTree
     }
 
     mTreeOwner = aTreeOwner;    // Weak reference per API
 
     nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
     while (iter.HasMore()) {
         nsCOMPtr<nsIDocShellTreeItem> child = do_QueryObject(iter.GetNext());
         NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
-        int32_t childType = ~mItemType; // Set it to not us in case the get fails
-        child->GetItemType(&childType); // We don't care if this fails, if it does we won't set the owner
-        if (childType == mItemType)
+        
+        if (child->ItemType() == mItemType)
             child->SetTreeOwner(aTreeOwner);
     }
 
     // Our tree owner has changed. Recompute scriptability.
     //
     // Note that this is near-redundant with the recomputation in
     // SetDocLoaderParent(), but not so for the root DocShell, where the call to
     // SetTreeOwner() happens after the initial AddDocLoaderAsChildOfRoot(),
@@ -3651,23 +3647,19 @@ nsDocShell::AddChild(nsIDocShellTreeItem
     }
     childDocShell->SetChildOffset(dynamic ? -1 : mChildList.Length() - 1);
 
     /* Set the child's global history if the parent has one */
     if (mUseGlobalHistory) {
             childDocShell->SetUseGlobalHistory(true);
     }
 
-
-    int32_t childType = ~mItemType;     // Set it to not us in case the get fails
-    aChild->GetItemType(&childType);
-    if (childType != mItemType)
+    if (aChild->ItemType() != mItemType) {
         return NS_OK;
-    // Everything below here is only done when the child is the same type.
-
+    }
 
     aChild->SetTreeOwner(mTreeOwner);
 
     nsCOMPtr<nsIDocShell> childAsDocShell(do_QueryInterface(aChild));
     if (!childAsDocShell)
         return NS_OK;
 
     // charset, style-disabling, and zoom will be inherited in SetupNewViewer()
@@ -3767,18 +3759,17 @@ nsDocShell::FindChildWithName(const char
     if (!*aName)
         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);
-        int32_t childType;
-        child->GetItemType(&childType);
+        int32_t childType = child->ItemType();
 
         if (aSameType && (childType != mItemType))
             continue;
 
         bool childNameEquals = false;
         child->NameEquals(aName, &childNameEquals);
         if (childNameEquals && ItemIsActive(child) &&
             CanAccessItem(child, aOriginalRequestor)) {
--- a/docshell/base/nsDocShellEnumerator.cpp
+++ b/docshell/base/nsDocShellEnumerator.cpp
@@ -118,21 +118,19 @@ nsresult nsDocShellEnumerator::BuildDocS
   nsCOMPtr<nsIDocShellTreeItem> item = do_QueryReferent(mRootItem);
   return BuildArrayRecursive(item, inItemArray);
 }
 
 nsresult nsDocShellForwardsEnumerator::BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray<nsWeakPtr>& inItemArray)
 {
   nsresult rv;
 
-  int32_t   itemType;
   // add this item to the array
-  if ((mDocShellType == nsIDocShellTreeItem::typeAll) ||
-      (NS_SUCCEEDED(inItem->GetItemType(&itemType)) && (itemType == mDocShellType)))
-  {
+  if (mDocShellType == nsIDocShellTreeItem::typeAll ||
+      inItem->ItemType() == mDocShellType) {
     if (!inItemArray.AppendElement(do_GetWeakReference(inItem)))
       return NS_ERROR_OUT_OF_MEMORY;
   }
 
   int32_t   numChildren;
   rv = inItem->GetChildCount(&numChildren);
   if (NS_FAILED(rv)) return rv;
   
@@ -163,22 +161,17 @@ nsresult nsDocShellBackwardsEnumerator::
     nsCOMPtr<nsIDocShellTreeItem> curChild;
     rv = inItem->GetChildAt(i, getter_AddRefs(curChild));
     if (NS_FAILED(rv)) return rv;
       
     rv = BuildArrayRecursive(curChild, inItemArray);
     if (NS_FAILED(rv)) return rv;
   }
 
-  int32_t   itemType;
   // add this item to the array
-  if ((mDocShellType == nsIDocShellTreeItem::typeAll) ||
-      (NS_SUCCEEDED(inItem->GetItemType(&itemType)) && (itemType == mDocShellType)))
-  {
+  if (mDocShellType == nsIDocShellTreeItem::typeAll ||
+      inItem->ItemType() == mDocShellType) {
     if (!inItemArray.AppendElement(do_GetWeakReference(inItem)))
       return NS_ERROR_OUT_OF_MEMORY;
   }
 
-
   return NS_OK;
 }
-
-
--- a/docshell/base/nsIDocShellTreeItem.idl
+++ b/docshell/base/nsIDocShellTreeItem.idl
@@ -41,16 +41,17 @@ interface nsIDocShellTreeItem : nsISuppo
 	const long typeChromeWrapper=3;     // typeChromeWrapper must equal 3
 
 	const long typeAll=0x7FFFFFFF;
 
 	/*
 	The type this item is.  
 	*/
 	attribute long itemType;
+	[noscript,notxpcom,nostdcall] long ItemType();
 
 	/*
 	Parent DocShell.
 	*/
 	readonly attribute nsIDocShellTreeItem parent;
 
 	/*
 	This getter returns the same thing parent does however if the parent
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -589,23 +589,20 @@ nsFocusManager::GetFocusedElementForWind
     NS_IF_ADDREF(*aFocusedWindow = focusedWindow);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFocusManager::MoveCaretToFocus(nsIDOMWindow* aWindow)
 {
-  int32_t itemType = nsIDocShellTreeItem::typeChrome;
-
   nsCOMPtr<nsIWebNavigation> webnav = do_GetInterface(aWindow);
   nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(webnav);
   if (dsti) {
-    dsti->GetItemType(&itemType);
-    if (itemType != nsIDocShellTreeItem::typeChrome) {
+    if (dsti->ItemType() != nsIDocShellTreeItem::typeChrome) {
       nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(dsti);
       NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
       // don't move the caret for editable documents
       bool isEditable;
       docShell->GetEditable(&isEditable);
       if (isEditable)
         return NS_OK;
@@ -2036,20 +2033,19 @@ nsFocusManager::UpdateCaret(bool aMoveCa
 
   // this is called when a document is focused or when the caretbrowsing
   // preference is changed
   nsCOMPtr<nsIDocShell> focusedDocShell = mFocusedWindow->GetDocShell();
   nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(focusedDocShell);
   if (!dsti)
     return;
 
-  int32_t itemType;
-  dsti->GetItemType(&itemType);
-  if (itemType == nsIDocShellTreeItem::typeChrome)
+  if (dsti->ItemType() == nsIDocShellTreeItem::typeChrome) {
     return;  // Never browse with caret in chrome
+  }
 
   bool browseWithCaret =
     Preferences::GetBool("accessibility.browsewithcaret");
 
   nsCOMPtr<nsIPresShell> presShell = focusedDocShell->GetPresShell();
   if (!presShell)
     return;
 
@@ -2468,19 +2464,17 @@ nsFocusManager::DetermineElementToMoveFo
 #endif
     if (popupFrame) {
       rootContent = popupFrame->GetContent();
       NS_ASSERTION(rootContent, "Popup frame doesn't have a content node");
       startContent = rootContent;
     }
     else {
       // Otherwise, for content shells, start from the location of the caret.
-      int32_t itemType;
-      docShell->GetItemType(&itemType);
-      if (itemType != nsIDocShellTreeItem::typeChrome) {
+      if (docShell->ItemType() != nsIDocShellTreeItem::typeChrome) {
         nsCOMPtr<nsIContent> endSelectionContent;
         GetSelectionLocation(doc, presShell,
                              getter_AddRefs(startContent),
                              getter_AddRefs(endSelectionContent));
         // If the selection is on the rootContent, then there is no selection
         if (startContent == rootContent) {
           startContent = nullptr;
         }
@@ -2986,24 +2980,21 @@ nsFocusManager::GetRootForFocus(nsPIDOMW
     if (docContent) {
       if (docContent->Tag() == nsGkAtoms::iframe)
         return nullptr;
 
       nsIFrame* frame = docContent->GetPrimaryFrame();
       if (!frame || !frame->IsFocusable(nullptr, 0))
         return nullptr;
     }
-  }
-  else  {
-    int32_t itemType;
+  } else {
     nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
-    docShell->GetItemType(&itemType);
-
-    if (itemType == nsIDocShellTreeItem::typeChrome)
+    if (docShell->ItemType() == nsIDocShellTreeItem::typeChrome) {
       return nullptr;
+    }
   }
 
   if (aCheckVisibility && !IsWindowVisible(aWindow))
     return nullptr;
 
   Element *rootElement = aDocument->GetRootElement();
   if (!rootElement) {
     return nullptr;
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -1951,22 +1951,19 @@ nsGlobalWindow::SetInitialPrincipalToSub
   ssm->GetSubjectPrincipal(getter_AddRefs(newWindowPrincipal));
   ssm->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
   if (!newWindowPrincipal) {
     newWindowPrincipal = systemPrincipal;
   }
 
   // Now, if we're about to use the system principal, make sure we're not using
   // it for a content docshell.
-  if (newWindowPrincipal == systemPrincipal) {
-    int32_t itemType;
-    nsresult rv = GetDocShell()->GetItemType(&itemType);
-    if (NS_FAILED(rv) || itemType != nsIDocShellTreeItem::typeChrome) {
-      newWindowPrincipal = nullptr;
-    }
+  if (newWindowPrincipal == systemPrincipal &&
+      GetDocShell()->ItemType() != nsIDocShellTreeItem::typeChrome) {
+    newWindowPrincipal = nullptr;
   }
 
   // If there's an existing document, bail if it either:
   if (mDoc) {
     // (a) is not an initial about:blank document, or
     if (!mDoc->IsInitialDocument())
       return;
     // (b) already has the correct principal.
@@ -2581,22 +2578,18 @@ nsGlobalWindow::SetNewDocument(nsIDocume
   mContext->GC(JS::gcreason::SET_NEW_DOCUMENT);
   mContext->DidInitializeContext();
 
   if (newInnerWindow && !newInnerWindow->mHasNotifiedGlobalCreated && mDoc) {
     // We should probably notify. However if this is the, arguably bad,
     // situation when we're creating a temporary non-chrome-about-blank
     // document in a chrome docshell, don't notify just yet. Instead wait
     // until we have a real chrome doc.
-    int32_t itemType = nsIDocShellTreeItem::typeContent;
-    if (mDocShell) {
-      mDocShell->GetItemType(&itemType);
-    }
-
-    if (itemType != nsIDocShellTreeItem::typeChrome ||
+    if (!mDocShell ||
+        mDocShell->ItemType() != nsIDocShellTreeItem::typeChrome ||
         nsContentUtils::IsSystemPrincipal(mDoc->NodePrincipal())) {
       newInnerWindow->mHasNotifiedGlobalCreated = true;
       nsContentUtils::AddScriptRunner(
         NS_NewRunnableMethod(this, &nsGlobalWindow::DispatchDOMWindowCreated));
     }
   }
 
   PreloadLocalStorage();
@@ -3152,25 +3145,18 @@ nsGlobalWindow::PostHandleEvent(nsEventC
   } else if (aVisitor.mEvent->message == NS_LOAD &&
              aVisitor.mEvent->mFlags.mIsTrusted) {
     // This is page load event since load events don't propagate to |window|.
     // @see nsDocument::PreHandleEvent.
     mIsDocumentLoaded = true;
 
     nsCOMPtr<Element> element = GetFrameElementInternal();
     nsIDocShell* docShell = GetDocShell();
-
-    int32_t itemType = nsIDocShellTreeItem::typeChrome;
-
-    if (docShell) {
-      docShell->GetItemType(&itemType);
-    }
-
     if (element && GetParentInternal() &&
-        itemType != nsIDocShellTreeItem::typeChrome) {
+        docShell && docShell->ItemType() != nsIDocShellTreeItem::typeChrome) {
       // If we're not in chrome, or at a chrome boundary, fire the
       // onload event for the frame element.
 
       nsEventStatus status = nsEventStatus_eIgnore;
       WidgetEvent event(aVisitor.mEvent->mFlags.mIsTrusted, NS_LOAD);
       event.mFlags.mBubbles = false;
 
       // Most of the time we could get a pres context to pass in here,
@@ -5651,19 +5637,17 @@ nsGlobalWindow::SetFullScreenInternal(bo
   nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(rootItem);
   if (!window)
     return NS_ERROR_FAILURE;
   if (rootItem != mDocShell)
     return window->SetFullScreenInternal(aFullScreen, aRequireTrust);
 
   // make sure we don't try to set full screen on a non-chrome window,
   // which might happen in embedding world
-  int32_t itemType;
-  mDocShell->GetItemType(&itemType);
-  if (itemType != nsIDocShellTreeItem::typeChrome)
+  if (mDocShell->ItemType() != nsIDocShellTreeItem::typeChrome)
     return NS_ERROR_FAILURE;
 
   // If we are already in full screen mode, just return.
   if (mFullScreen == aFullScreen)
     return NS_OK;
 
   // dispatch a "fullscreen" DOM event so that XUL apps can
   // respond visually if we are kicked into full screen mode
@@ -6284,19 +6268,17 @@ nsGlobalWindow::Focus(ErrorResult& aErro
     return;
   }
 
   nsCOMPtr<nsIPresShell> presShell;
   // Don't look for a presshell if we're a root chrome window that's got
   // about:blank loaded.  We don't want to focus our widget in that case.
   // XXXbz should we really be checking for IsInitialDocument() instead?
   bool lookForPresShell = true;
-  int32_t itemType = nsIDocShellTreeItem::typeContent;
-  mDocShell->GetItemType(&itemType);
-  if (itemType == nsIDocShellTreeItem::typeChrome &&
+  if (mDocShell->ItemType() == nsIDocShellTreeItem::typeChrome &&
       GetPrivateRoot() == static_cast<nsIDOMWindow*>(this) &&
       mDoc) {
     nsIURI* ourURI = mDoc->GetDocumentURI();
     if (ourURI) {
       lookForPresShell = !NS_IsAboutBlank(ourURI);
     }
   }
 
@@ -7149,20 +7131,19 @@ nsGlobalWindow::PopupWhitelisted()
  */
 PopupControlState
 nsGlobalWindow::RevisePopupAbuseLevel(PopupControlState aControl)
 {
   MOZ_ASSERT(IsOuterWindow());
 
   NS_ASSERTION(mDocShell, "Must have docshell");
   
-  int32_t type = nsIDocShellTreeItem::typeChrome;
-  mDocShell->GetItemType(&type);
-  if (type != nsIDocShellTreeItem::typeContent)
+  if (mDocShell->ItemType() != nsIDocShellTreeItem::typeContent) {
     return openAllowed;
+  }
 
   PopupControlState abuse = aControl;
   switch (abuse) {
   case openControlled:
   case openAbused:
   case openOverridden:
     if (PopupWhitelisted())
       abuse = PopupControlState(abuse - 1);
--- a/dom/base/nsGlobalWindowCommands.cpp
+++ b/dom/base/nsGlobalWindowCommands.cpp
@@ -240,22 +240,18 @@ nsSelectMoveScrollCommand::DoCommand(con
   // the caret is enabled. In particular, this includes caret-browsing mode
   // in non-chrome documents.
   bool caretOn = false;
   selCont->GetCaretEnabled(&caretOn);
   if (!caretOn) {
     caretOn = Preferences::GetBool("accessibility.browsewithcaret");
     if (caretOn) {
       nsCOMPtr<nsIDocShell> docShell = piWindow->GetDocShell();
-      if (docShell) {
-        int32_t itemType;
-        docShell->GetItemType(&itemType);
-        if (itemType == nsIDocShellTreeItem::typeChrome) {
-          caretOn = false;
-        }
+      if (docShell && docShell->ItemType() == nsIDocShellTreeItem::typeChrome) {
+        caretOn = false;
       }
     }
   }
 
   for (size_t i = 0; i < ArrayLength(browseCommands); i++) {
     bool forward = !strcmp(aCommandName, browseCommands[i].forward);
     if (forward || !strcmp(aCommandName, browseCommands[i].reverse)) {
       if (caretOn && browseCommands[i].move &&
--- a/dom/base/nsScreen.cpp
+++ b/dom/base/nsScreen.cpp
@@ -15,32 +15,16 @@
 #include "nsDOMEvent.h"
 #include "nsJSUtils.h"
 #include "mozilla/dom/ScreenBinding.h"
 #include "nsDeviceContext.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
-namespace {
-
-bool
-IsChromeType(nsIDocShell *aDocShell)
-{
-  if (!aDocShell) {
-    return false;
-  }
-
-  int32_t itemType;
-  aDocShell->GetItemType(&itemType);
-  return itemType == nsIDocShellTreeItem::typeChrome;
-}
-
-} // anonymous namespace
-
 /* static */ already_AddRefed<nsScreen>
 nsScreen::Create(nsPIDOMWindow* aWindow)
 {
   MOZ_ASSERT(aWindow);
 
   if (!aWindow->GetDocShell()) {
     return nullptr;
   }
@@ -213,17 +197,18 @@ nsScreen::LockPermission
 nsScreen::GetLockOrientationPermission() const
 {
   nsCOMPtr<nsPIDOMWindow> owner = GetOwner();
   if (!owner) {
     return LOCK_DENIED;
   }
 
   // Chrome can always lock the screen orientation.
-  if (IsChromeType(owner->GetDocShell())) {
+  nsIDocShell* docShell = owner->GetDocShell();
+  if (docShell && docShell->ItemType() == nsIDocShellTreeItem::typeChrome) {
     return LOCK_ALLOWED;
   }
 
   nsCOMPtr<nsIDocument> doc = owner->GetDoc();
   if (!doc || doc->Hidden()) {
     return LOCK_DENIED;
   }
 
--- a/dom/events/nsEventStateManager.cpp
+++ b/dom/events/nsEventStateManager.cpp
@@ -145,18 +145,17 @@ IsMouseEventReal(WidgetEvent* aEvent)
 static void
 PrintDocTree(nsIDocShellTreeItem* aParentItem, int aLevel)
 {
   for (int32_t i=0;i<aLevel;i++) printf("  ");
 
   int32_t childWebshellCount;
   aParentItem->GetChildCount(&childWebshellCount);
   nsCOMPtr<nsIDocShell> parentAsDocShell(do_QueryInterface(aParentItem));
-  int32_t type;
-  aParentItem->GetItemType(&type);
+  int32_t type = aParentItem->ItemType();
   nsCOMPtr<nsIPresShell> presShell = parentAsDocShell->GetPresShell();
   nsRefPtr<nsPresContext> presContext;
   parentAsDocShell->GetPresContext(getter_AddRefs(presContext));
   nsCOMPtr<nsIContentViewer> cv;
   parentAsDocShell->GetContentViewer(getter_AddRefs(cv));
   nsCOMPtr<nsIDOMDocument> domDoc;
   if (cv)
     cv->GetDOMDocument(getter_AddRefs(domDoc));
@@ -1338,20 +1337,17 @@ nsEventStateManager::PreHandleEvent(nsPr
 // static
 int32_t
 nsEventStateManager::GetAccessModifierMaskFor(nsISupports* aDocShell)
 {
   nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(aDocShell));
   if (!treeItem)
     return -1; // invalid modifier
 
-  int32_t itemType;
-  treeItem->GetItemType(&itemType);
-  switch (itemType) {
-
+  switch (treeItem->ItemType()) {
   case nsIDocShellTreeItem::typeChrome:
     return Prefs::ChromeAccessModifierMask();
 
   case nsIDocShellTreeItem::typeContent:
     return Prefs::ContentAccessModifierMask();
 
   default:
     return -1; // invalid modifier
--- a/embedding/browser/webBrowser/nsWebBrowser.cpp
+++ b/embedding/browser/webBrowser/nsWebBrowser.cpp
@@ -424,21 +424,27 @@ NS_IMETHODIMP nsWebBrowser::NameEquals(c
         return mDocShell->NameEquals(aName, _retval);
     }
     else
         *_retval = mInitInfo->name.Equals(aName);
 
     return NS_OK;
 }
 
+/* virtual */ int32_t
+nsWebBrowser::ItemType()
+{
+   return mContentType;
+}
+
 NS_IMETHODIMP nsWebBrowser::GetItemType(int32_t* aItemType)
 {
    NS_ENSURE_ARG_POINTER(aItemType);
 
-   *aItemType = mContentType;
+   *aItemType = ItemType();
    return NS_OK;
 }
 
 NS_IMETHODIMP nsWebBrowser::SetItemType(int32_t aItemType)
 {
     NS_ENSURE_TRUE((aItemType == typeContentWrapper || aItemType == typeChromeWrapper), NS_ERROR_FAILURE);
     mContentType = aItemType;
     if (mDocShell)
--- a/extensions/permissions/nsContentBlocker.cpp
+++ b/extensions/permissions/nsContentBlocker.cpp
@@ -184,23 +184,19 @@ nsContentBlocker::ShouldProcess(uint32_t
                                 int16_t          *aDecision)
 {
   // For loads where aRequestingContext is chrome, we should just
   // accept.  Those are most likely toplevel loads in windows, and
   // chrome generally knows what it's doing anyway.
   nsCOMPtr<nsIDocShellTreeItem> item =
     do_QueryInterface(NS_CP_GetDocShellFromContext(aRequestingContext));
 
-  if (item) {
-    int32_t type;
-    item->GetItemType(&type);
-    if (type == nsIDocShellTreeItem::typeChrome) {
-      *aDecision = nsIContentPolicy::ACCEPT;
-      return NS_OK;
-    }
+  if (item && item->ItemType() == nsIDocShellTreeItem::typeChrome) {
+    *aDecision = nsIContentPolicy::ACCEPT;
+    return NS_OK;
   }
 
   // For objects, we only check policy in shouldProcess, as the final type isn't
   // determined until the channel is open -- We don't want to block images in
   // object tags because plugins are disallowed.
   // NOTE that this bypasses the aContentLocation checks in ShouldLoad - this is
   // intentional, as aContentLocation may be null for plugins that load by type
   // (e.g. java)
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -4082,28 +4082,24 @@ nsCSSFrameConstructor::FindXULDescriptio
 #ifdef XP_MACOSX
 /* static */
 const nsCSSFrameConstructor::FrameConstructionData*
 nsCSSFrameConstructor::FindXULMenubarData(Element* aElement,
                                           nsStyleContext* aStyleContext)
 {
   nsCOMPtr<nsIDocShell> treeItem =
     aStyleContext->PresContext()->GetDocShell();
-  if (treeItem) {
-    int32_t type;
-    treeItem->GetItemType(&type);
-    if (nsIDocShellTreeItem::typeChrome == type) {
-      nsCOMPtr<nsIDocShellTreeItem> parent;
-      treeItem->GetParent(getter_AddRefs(parent));
-      if (!parent) {
-        // This is the root.  Suppress the menubar, since on Mac
-        // window menus are not attached to the window.
-        static const FrameConstructionData sSuppressData = SUPPRESS_FCDATA();
-        return &sSuppressData;
-      }
+  if (treeItem && nsIDocShellTreeItem::typeChrome == treeItem->ItemType()) {
+    nsCOMPtr<nsIDocShellTreeItem> parent;
+    treeItem->GetParent(getter_AddRefs(parent));
+    if (!parent) {
+      // This is the root.  Suppress the menubar, since on Mac
+      // window menus are not attached to the window.
+      static const FrameConstructionData sSuppressData = SUPPRESS_FCDATA();
+      return &sSuppressData;
     }
   }
 
   static const FrameConstructionData sMenubarData =
     SIMPLE_XUL_FCDATA(NS_NewMenuBarFrame);
   return &sMenubarData;
 }
 #endif /* XP_MACOSX */
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -4036,25 +4036,24 @@ nsDocumentViewer::ShouldAttachToTopLevel
 
   // We always attach when using puppet widgets
   if (nsIWidget::UsePuppetWidgets())
     return true;
 
 #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
   // On windows, in the parent process we also attach, but just to
   // chrome items
-  int32_t docType;
   nsWindowType winType;
-  containerItem->GetItemType(&docType);
   mParentWidget->GetWindowType(winType);
   if ((winType == eWindowType_toplevel ||
        winType == eWindowType_dialog ||
        winType == eWindowType_invisible) &&
-      docType == nsIDocShellTreeItem::typeChrome)
+      containerItem->ItemType() == nsIDocShellTreeItem::typeChrome) {
     return true;
+  }
 #endif
 
   return false;
 }
 
 bool CollectDocuments(nsIDocument* aDocument, void* aData)
 {
   if (aDocument) {
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -686,22 +686,19 @@ nsPresContext::GetFontPrefsForLang(nsIAt
 
 void
 nsPresContext::GetDocumentColorPreferences()
 {
   int32_t useAccessibilityTheme = 0;
   bool usePrefColors = true;
   nsCOMPtr<nsIDocShellTreeItem> docShell(mContainer);
   if (docShell) {
-    int32_t docShellType;
-    docShell->GetItemType(&docShellType);
-    if (nsIDocShellTreeItem::typeChrome == docShellType) {
+    if (nsIDocShellTreeItem::typeChrome == docShell->ItemType()) {
       usePrefColors = false;
-    }
-    else {
+    } else {
       useAccessibilityTheme =
         LookAndFeel::GetInt(LookAndFeel::eIntID_UseAccessibilityTheme, 0);
       usePrefColors = !useAccessibilityTheme;
     }
 
   }
   if (usePrefColors) {
     usePrefColors =
@@ -958,21 +955,18 @@ nsPresContext::PreferenceChanged(const c
 }
 
 void
 nsPresContext::UpdateAfterPreferencesChanged()
 {
   mPrefChangedTimer = nullptr;
 
   nsCOMPtr<nsIDocShellTreeItem> docShell(mContainer);
-  if (docShell) {
-    int32_t docShellType;
-    docShell->GetItemType(&docShellType);
-    if (nsIDocShellTreeItem::typeChrome == docShellType)
-      return;
+  if (docShell && nsIDocShellTreeItem::typeChrome == docShell->ItemType()) {
+    return;
   }
 
   // Initialize our state from the user preferences
   GetUserPreferences();
 
   // update the presShell: tell it to set the preference style rules up
   if (mShell) {
     mShell->SetPreferenceStyleRules(true);
@@ -2039,26 +2033,18 @@ nsPresContext::CountReflows(const char *
     mShell->CountReflows(aName, aFrame);
   }
 }
 #endif
 
 bool
 nsPresContext::IsChromeSlow() const
 {
-  bool isChrome = false;
-  nsCOMPtr<nsIDocShellTreeItem> docShell(mContainer);
-  if (docShell) {
-    int32_t docShellType;
-    nsresult result = docShell->GetItemType(&docShellType);
-    if (NS_SUCCEEDED(result)) {
-      isChrome = nsIDocShellTreeItem::typeChrome == docShellType;
-    }
-  }
-  mIsChrome = isChrome;
+  mIsChrome = mContainer &&
+              nsIDocShellTreeItem::typeChrome == mContainer->ItemType();
   mIsChromeIsCached = true;
   return mIsChrome;
 }
 
 void
 nsPresContext::InvalidateIsChromeCacheExternal()
 {
   InvalidateIsChromeCacheInternal();
--- a/layout/printing/nsPrintObject.cpp
+++ b/layout/printing/nsPrintObject.cpp
@@ -53,23 +53,21 @@ nsPrintObject::Init(nsIDocShell* aDocShe
                     bool aPrintPreview)
 {
   mPrintPreview = aPrintPreview;
 
   if (mPrintPreview || mParent) {
     mDocShell = aDocShell;
   } else {
     mTreeOwner = do_GetInterface(aDocShell);
-    int32_t itemType = 0;
-    aDocShell->GetItemType(&itemType);
     // Create a container docshell for printing.
     mDocShell = do_CreateInstance("@mozilla.org/docshell;1");
     NS_ENSURE_TRUE(mDocShell, NS_ERROR_OUT_OF_MEMORY);
     mDidCreateDocShell = true;
-    mDocShell->SetItemType(itemType);
+    mDocShell->SetItemType(aDocShell->ItemType());
     mDocShell->SetTreeOwner(mTreeOwner);
   }
   NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMDocument> dummy = do_GetInterface(mDocShell);
   nsCOMPtr<nsIContentViewer> viewer;
   mDocShell->GetContentViewer(getter_AddRefs(viewer));
   NS_ENSURE_STATE(viewer);
--- a/layout/xul/nsMenuPopupFrame.cpp
+++ b/layout/xul/nsMenuPopupFrame.cpp
@@ -143,20 +143,19 @@ nsMenuPopupFrame::Init(nsIContent*      
 
   if (mPopupType == ePopupTypePanel &&
       aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
                             nsGkAtoms::drag, eIgnoreCase)) {
     mIsDragPopup = true;
   }
 
   nsCOMPtr<nsIDocShellTreeItem> dsti = PresContext()->GetDocShell();
-  int32_t type = -1;
-  if (dsti && NS_SUCCEEDED(dsti->GetItemType(&type)) &&
-      type == nsIDocShellTreeItem::typeChrome)
+  if (dsti && dsti->ItemType() == nsIDocShellTreeItem::typeChrome) {
     mInContentShell = false;
+  }
 
   // To improve performance, create the widget for the popup only if it is not
   // a leaf. Leaf popups such as menus will create their widgets later when
   // the popup opens.
   if (!IsLeaf() && !ourView->HasWidget()) {
     CreateWidgetForView(ourView);
   }
 
--- a/layout/xul/nsResizerFrame.cpp
+++ b/layout/xul/nsResizerFrame.cpp
@@ -332,25 +332,18 @@ nsResizerFrame::GetContentToResize(nsIPr
       nsMenuPopupFrame* popupFrame = do_QueryFrame(popup);
       if (popupFrame) {
         return popupFrame->GetContent();
       }
       popup = popup->GetParent();
     }
 
     // don't allow resizing windows in content shells
-    bool isChromeShell = false;
     nsCOMPtr<nsIDocShellTreeItem> dsti = aPresShell->GetPresContext()->GetDocShell();
-    if (dsti) {
-      int32_t type = -1;
-      isChromeShell = (NS_SUCCEEDED(dsti->GetItemType(&type)) &&
-                       type == nsIDocShellTreeItem::typeChrome);
-    }
-
-    if (!isChromeShell) {
+    if (!dsti || dsti->ItemType() != nsIDocShellTreeItem::typeChrome) {
       // don't allow resizers in content shells, except for the viewport
       // scrollbar which doesn't have a parent
       nsIContent* nonNativeAnon = mContent->FindFirstNonChromeOnlyAccessContent();
       if (!nonNativeAnon || nonNativeAnon->GetParent()) {
         return nullptr;
       }
     }
 
--- a/layout/xul/nsTitleBarFrame.cpp
+++ b/layout/xul/nsTitleBarFrame.cpp
@@ -69,19 +69,17 @@ nsTitleBarFrame::HandleEvent(nsPresConte
 
   switch (aEvent->message) {
 
    case NS_MOUSE_BUTTON_DOWN:  {
        if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
          // titlebar has no effect in non-chrome shells
          nsCOMPtr<nsIDocShellTreeItem> dsti = aPresContext->GetDocShell();
          if (dsti) {
-           int32_t type = -1;
-           if (NS_SUCCEEDED(dsti->GetItemType(&type)) &&
-               type == nsIDocShellTreeItem::typeChrome) {
+           if (dsti->ItemType() == nsIDocShellTreeItem::typeChrome) {
              // we're tracking.
              mTrackingMouseMove = true;
 
              // start capture.
              nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED);
 
              // remember current mouse coordinates.
              mLastPoint = LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint);
--- a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp
+++ b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp
@@ -273,19 +273,18 @@ nsSecureBrowserUIImpl::MapInternalToExte
 
   if (ev && (*aState & STATE_IS_SECURE))
     *aState |= nsIWebProgressListener::STATE_IDENTITY_EV_TOPLEVEL;
 
   nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShell);
   if (!docShell)
     return NS_OK;
 
-  int32_t docShellType;
   // For content docShell's, the mixed content security state is set on the root docShell.
-  if (NS_SUCCEEDED(docShell->GetItemType(&docShellType)) && docShellType == nsIDocShellTreeItem::typeContent) {
+  if (docShell->ItemType() == nsIDocShellTreeItem::typeContent) {
     nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(do_QueryInterface(docShell));
     nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
     docShellTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
     NS_ASSERTION(sameTypeRoot, "No document shell root tree item from document shell tree item!");
     docShell = do_QueryInterface(sameTypeRoot);
     if (!docShell)
       return NS_OK;
   }