Bug 1238160 - Set frame type on TabContext. r=billm,mayhemer
authorJ. Ryan Stinnett <jryans@gmail.com>
Wed, 17 Feb 2016 22:35:45 -0600
changeset 286475 76944f0d24abc3e3d968f324f18a8a3835e535dc
parent 286474 981fee6f681f8e24aa8ea37c39ab74f91c7c5ede
child 286476 80f7b29a27f17f06c02e7b11b2507857332d56c3
push id30050
push usercbook@mozilla.com
push dateThu, 03 Mar 2016 10:54:59 +0000
treeherdermozilla-central@2b5237c178ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm, mayhemer
bugs1238160
milestone47.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 1238160 - Set frame type on TabContext. r=billm,mayhemer This change renames TabContext::IsBrowserElement to IsIsolatedMozBrowserElement. Other methods that pass these values around also have name changes. Adds TabContext::IsMozBrowserElement which is set by the frame loader for all browser frames. This is in contrast to its previous implementation, which has since been renamed IsIsolatedMozBrowserElement, since it checks isolated state in OriginAttributes. TabContext methods related to browser elements (and their callers) are updated to use IsIsolatedMozBrowserElement when check isolation / origins and IsMozBrowserElement when checking frame types. MozReview-Commit-ID: DDMZTkSn5yd
dom/base/nsFrameLoader.cpp
dom/ipc/ContentChild.cpp
dom/ipc/ContentParent.cpp
dom/ipc/PTabContext.ipdlh
dom/ipc/TabChild.cpp
dom/ipc/TabContext.cpp
dom/ipc/TabContext.h
dom/ipc/nsIContentParent.cpp
dom/network/TCPServerSocket.cpp
dom/network/TCPServerSocketParent.cpp
dom/network/TCPServerSocketParent.h
dom/network/TCPSocket.cpp
dom/network/TCPSocket.h
dom/network/TCPSocketParent.cpp
dom/network/TCPSocketParent.h
dom/workers/ServiceWorkerManagerService.cpp
netwerk/ipc/NeckoParent.cpp
--- a/dom/base/nsFrameLoader.cpp
+++ b/dom/base/nsFrameLoader.cpp
@@ -3113,13 +3113,17 @@ nsFrameLoader::GetNewTabContext(MutableT
   if (!userContextIdStr.IsEmpty()) {
     nsresult err;
     uint32_t userContextId = userContextIdStr.ToInteger(&err);
     NS_ENSURE_SUCCESS(err, err);
     attrs.mUserContextId = userContextId;
   }
 
   bool tabContextUpdated =
-    aTabContext->SetTabContext(ownApp, containingApp, attrs, signedPkgOrigin);
+    aTabContext->SetTabContext(OwnerIsMozBrowserFrame(),
+                               ownApp,
+                               containingApp,
+                               attrs,
+                               signedPkgOrigin);
   NS_ENSURE_STATE(tabContextUpdated);
 
   return NS_OK;
 }
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -801,17 +801,17 @@ ContentChild::ProvideWindowCommon(TabChi
 
   nsAutoPtr<IPCTabContext> ipcContext;
   TabId openerTabId = TabId(0);
 
   if (aTabOpener) {
     PopupIPCTabContext context;
     openerTabId = aTabOpener->GetTabId();
     context.opener() = openerTabId;
-    context.isBrowserElement() = aTabOpener->IsBrowserElement();
+    context.isMozBrowserElement() = aTabOpener->IsMozBrowserElement();
     ipcContext = new IPCTabContext(context);
   } else {
     // It's possible to not have a TabChild opener in the case
     // of ServiceWorker::OpenWindow.
     UnsafeIPCTabContext unsafeTabContext;
     ipcContext = new IPCTabContext(unsafeTabContext);
   }
 
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -1117,29 +1117,29 @@ ContentParent::CreateBrowserOrApp(const 
   TabId tabId;
 
   nsIDocShell* docShell = GetOpenerDocShellHelper(aFrameElement);
   TabId openerTabId;
   if (docShell) {
     openerTabId = TabParent::GetTabIdFrom(docShell);
   }
 
-  if (aContext.IsBrowserElement() || !aContext.HasOwnApp()) {
+  if (aContext.IsMozBrowserElement() || !aContext.HasOwnApp()) {
     RefPtr<TabParent> tp;
     RefPtr<nsIContentParent> constructorSender;
     if (isInContentProcess) {
-      MOZ_ASSERT(aContext.IsBrowserElement());
+      MOZ_ASSERT(aContext.IsMozBrowserElement());
       constructorSender = CreateContentBridgeParent(aContext, initialPriority,
                                                     openerTabId, &tabId);
     } else {
       if (aOpenerContentParent) {
         constructorSender = aOpenerContentParent;
       } else {
         constructorSender =
-          GetNewOrUsedBrowserProcess(aContext.IsBrowserElement(),
+          GetNewOrUsedBrowserProcess(aContext.IsMozBrowserElement(),
                                      initialPriority);
         if (!constructorSender) {
           return nullptr;
         }
       }
       tabId = AllocateTabId(openerTabId,
                             aContext.AsIPCTabContext(),
                            constructorSender->ChildID());
@@ -5329,17 +5329,17 @@ ContentParent::RecvCreateWindow(PBrowser
       return false;
   }
 
   TabParent* thisTabParent = nullptr;
   if (aThisTab) {
     thisTabParent = TabParent::GetFrom(aThisTab);
   }
 
-  if (NS_WARN_IF(thisTabParent && thisTabParent->IsBrowserOrApp())) {
+  if (NS_WARN_IF(thisTabParent && thisTabParent->IsMozBrowserOrApp())) {
     return false;
   }
 
   nsCOMPtr<nsPIWindowWatcher> pwwatch =
     do_GetService(NS_WINDOWWATCHER_CONTRACTID, aResult);
 
   if (NS_WARN_IF(NS_FAILED(*aResult))) {
     return true;
--- a/dom/ipc/PTabContext.ipdlh
+++ b/dom/ipc/PTabContext.ipdlh
@@ -8,45 +8,50 @@ include protocol PBrowser;
 include PBrowserOrId;
 
 namespace mozilla {
 namespace dom {
 
 // An IPCTabContext which corresponds to a PBrowser opened by a child when it
 // receives window.open().
 //
-// If isBrowserElement is false, this PopupIPCTabContext corresponds to an app
-// frame, and the frame's app-id and app-frame-owner-app-id will be equal to the
-// opener's values.
+// If isMozBrowserElement is false, this PopupIPCTabContext is either a
+// <xul:browser> or an app frame.  The frame's app-id and app-frame-owner-app-id
+// will be equal to the opener's values.  For a <xul:browser>, those app IDs
+// will be NO_APP_ID.
 //
-// If isBrowserElement is true, the frame's browserFrameOwnerAppId will be equal
-// to the opener's app-id.
+// If isMozBrowserElement is true, the frame's browserFrameOwnerAppId will be
+// equal to the opener's app-id.
 //
-// It's an error to set isBrowserElement == false if opener is a browser
+// It's an error to set isMozBrowserElement == false if opener is a mozbrowser
 // element.  Such a PopupIPCTabContext should be rejected by code which receives
 // it.
 struct PopupIPCTabContext
 {
   PBrowserOrId opener;
-  bool isBrowserElement;
+  bool isMozBrowserElement;
 };
 
 // An IPCTabContext which corresponds to an app, browser, or normal frame.
 struct FrameIPCTabContext
 {
   // The stringified originAttributes dictionary.
   nsCString originSuffix;
 
   // The ID of the app containing this app/browser frame, if applicable.
   uint32_t frameOwnerAppId;
 
   // The origin without originAttribute suffix for a signed package.
   // This value would be empty if the TabContext doesn't own a signed
   // package.
   nsCString signedPkgOriginNoSuffix;
+
+  // Whether this is a mozbrowser frame.  <iframe mozbrowser mozapp> and
+  // <xul:browser> are not considered to be mozbrowser frames.
+  bool isMozBrowserElement;
 };
 
 // XXXcatalinb: This is only used by ServiceWorkerClients::OpenWindow.
 // Because service workers don't have an associated TabChild
 // we can't satisfy the security constraints on b2g. As such, the parent
 // process will accept this tab context only on desktop.
 struct UnsafeIPCTabContext
 { };
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -544,17 +544,17 @@ TabChild::PreloadSlowThings()
 /*static*/ already_AddRefed<TabChild>
 TabChild::Create(nsIContentChild* aManager,
                  const TabId& aTabId,
                  const TabContext &aContext,
                  uint32_t aChromeFlags)
 {
     if (sPreallocatedTab &&
         sPreallocatedTab->mChromeFlags == aChromeFlags &&
-        aContext.IsBrowserOrApp()) {
+        aContext.IsMozBrowserOrApp()) {
 
         RefPtr<TabChild> child = sPreallocatedTab.get();
         sPreallocatedTab = nullptr;
 
         MOZ_ASSERT(!child->mTriedBrowserInit);
 
         child->mManager = aManager;
         child->SetTabId(aTabId);
@@ -860,21 +860,19 @@ void
 TabChild::NotifyTabContextUpdated()
 {
     nsCOMPtr<nsIDocShell> docShell = do_GetInterface(WebNavigation());
     MOZ_ASSERT(docShell);
 
     if (docShell) {
         // nsDocShell will do the right thing if we pass NO_APP_ID or
         // UNKNOWN_APP_ID for aOwnOrContainingAppId.
-        if (IsBrowserElement()) {
+        if (IsMozBrowserElement()) {
           docShell->SetIsBrowserInsideApp(BrowserOwnerAppId());
-          // TODO: Wants to call TabContext::IsIsolatedMozBrowserElement() based
-          // on isolation in principal, which is added in a later patch.
-          docShell->SetIsInIsolatedMozBrowserElement(IsBrowserElement());
+          docShell->SetIsInIsolatedMozBrowserElement(IsIsolatedMozBrowserElement());
         } else {
           docShell->SetIsApp(OwnAppId());
         }
 
         OriginAttributes attrs = OriginAttributesRef();
         docShell->SetIsSignedPackage(attrs.mSignedPkg);
         docShell->SetUserContextId(attrs.mUserContextId);
     }
@@ -1501,17 +1499,17 @@ TabChild::ApplyShowInfo(const ShowInfo& 
     // Once we've got one ShowInfo from parent, no need to update the values
     // anymore.
     mDidSetRealShowInfo = true;
   }
 
   nsCOMPtr<nsIDocShell> docShell = do_GetInterface(WebNavigation());
   if (docShell) {
     nsCOMPtr<nsIDocShellTreeItem> item = do_GetInterface(docShell);
-    if (IsBrowserOrApp()) {
+    if (IsMozBrowserOrApp()) {
       // B2G allows window.name to be set by changing the name attribute on the
       // <iframe mozbrowser> element. window.open calls cause this attribute to
       // be set to the correct value. A normal <xul:browser> element has no such
       // attribute. The data we get here comes from reading the attribute, so we
       // shouldn't trust it for <xul:browser> elements.
       item->SetName(aInfo.name());
     }
     docShell->SetFullscreenAllowed(aInfo.fullscreenAllowed());
@@ -1538,17 +1536,17 @@ TabChild::ApplyShowInfo(const ShowInfo& 
 }
 
 #ifdef MOZ_WIDGET_GONK
 void
 TabChild::MaybeRequestPreinitCamera()
 {
     // Check if this tab is an app (not a browser frame) and will use the
     // `camera` permission,
-    if (IsBrowserElement()) {
+    if (IsIsolatedMozBrowserElement()) {
       return;
     }
 
     nsCOMPtr<nsIAppsService> appsService = do_GetService("@mozilla.org/AppsService;1");
     if (NS_WARN_IF(!appsService)) {
       return;
     }
 
@@ -2523,17 +2521,17 @@ TabChild::InitTabChildGlobal(FrameScript
     NS_ENSURE_TRUE(root, false);
     root->SetParentTarget(scope);
   }
 
   if (aScriptLoading != DONT_LOAD_SCRIPTS && !mTriedBrowserInit) {
     mTriedBrowserInit = true;
     // Initialize the child side of the browser element machinery,
     // if appropriate.
-    if (IsBrowserOrApp()) {
+    if (IsMozBrowserOrApp()) {
       RecvLoadRemoteScript(BROWSER_ELEMENT_CHILD_SCRIPT, true);
     }
   }
 
   return true;
 }
 
 bool
--- a/dom/ipc/TabContext.cpp
+++ b/dom/ipc/TabContext.cpp
@@ -17,31 +17,38 @@
 using namespace mozilla::dom::ipc;
 using namespace mozilla::layout;
 
 namespace mozilla {
 namespace dom {
 
 TabContext::TabContext()
   : mInitialized(false)
+  , mIsMozBrowserElement(false)
   , mContainingAppId(NO_APP_ID)
   , mOriginAttributes()
 {
 }
 
 bool
-TabContext::IsBrowserElement() const
+TabContext::IsMozBrowserElement() const
+{
+  return mIsMozBrowserElement;
+}
+
+bool
+TabContext::IsIsolatedMozBrowserElement() const
 {
   return mOriginAttributes.mInIsolatedMozBrowser;
 }
 
 bool
-TabContext::IsBrowserOrApp() const
+TabContext::IsMozBrowserOrApp() const
 {
-  return HasOwnApp() || IsBrowserElement();
+  return HasOwnApp() || IsMozBrowserElement();
 }
 
 uint32_t
 TabContext::OwnAppId() const
 {
   return mOriginAttributes.mAppId;
 }
 
@@ -57,27 +64,27 @@ TabContext::HasOwnApp() const
 {
   nsCOMPtr<mozIApplication> ownApp = GetOwnApp();
   return !!ownApp;
 }
 
 uint32_t
 TabContext::BrowserOwnerAppId() const
 {
-  if (IsBrowserElement()) {
+  if (IsMozBrowserElement()) {
     return mContainingAppId;
   }
   return NO_APP_ID;
 }
 
 already_AddRefed<mozIApplication>
 TabContext::GetBrowserOwnerApp() const
 {
   nsCOMPtr<mozIApplication> ownerApp;
-  if (IsBrowserElement()) {
+  if (IsMozBrowserElement()) {
     ownerApp = mContainingApp;
   }
   return ownerApp.forget();
 }
 
 bool
 TabContext::HasBrowserOwnerApp() const
 {
@@ -160,17 +167,18 @@ TabContext::OriginAttributesRef() const
 
 const nsACString&
 TabContext::SignedPkgOriginNoSuffix() const
 {
   return mSignedPkgOriginNoSuffix;
 }
 
 bool
-TabContext::SetTabContext(mozIApplication* aOwnApp,
+TabContext::SetTabContext(bool aIsMozBrowserElement,
+                          mozIApplication* aOwnApp,
                           mozIApplication* aAppFrameOwnerApp,
                           const DocShellOriginAttributes& aOriginAttributes,
                           const nsACString& aSignedPkgOriginNoSuffix)
 {
   NS_ENSURE_FALSE(mInitialized, false);
 
   // Get ids for both apps and only write to our member variables after we've
   // verified that this worked.
@@ -189,32 +197,34 @@ TabContext::SetTabContext(mozIApplicatio
   }
 
   // Veryify that app id matches mAppId passed in originAttributes
   MOZ_RELEASE_ASSERT((aOwnApp && aOriginAttributes.mAppId == ownAppId) ||
                      (aAppFrameOwnerApp && aOriginAttributes.mAppId == containingAppId) ||
                      aOriginAttributes.mAppId == NO_APP_ID);
 
   mInitialized = true;
+  mIsMozBrowserElement = aIsMozBrowserElement;
   mOriginAttributes = aOriginAttributes;
   mContainingAppId = containingAppId;
   mOwnApp = aOwnApp;
   mContainingApp = aAppFrameOwnerApp;
   mSignedPkgOriginNoSuffix = aSignedPkgOriginNoSuffix;
   return true;
 }
 
 IPCTabContext
 TabContext::AsIPCTabContext() const
 {
   nsAutoCString originSuffix;
   mOriginAttributes.CreateSuffix(originSuffix);
   return IPCTabContext(FrameIPCTabContext(originSuffix,
                                           mContainingAppId,
-                                          mSignedPkgOriginNoSuffix));
+                                          mSignedPkgOriginNoSuffix,
+                                          mIsMozBrowserElement));
 }
 
 static already_AddRefed<mozIApplication>
 GetAppForId(uint32_t aAppId)
 {
   nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
   NS_ENSURE_TRUE(appsService, nullptr);
 
@@ -222,29 +232,31 @@ GetAppForId(uint32_t aAppId)
   appsService->GetAppByLocalId(aAppId, getter_AddRefs(app));
 
   return app.forget();
 }
 
 MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
   : mInvalidReason(nullptr)
 {
+  bool isMozBrowserElement = false;
   uint32_t containingAppId = NO_APP_ID;
   DocShellOriginAttributes originAttributes;
   nsAutoCString originSuffix;
   nsAutoCString signedPkgOriginNoSuffix;
 
   switch(aParams.type()) {
     case IPCTabContext::TPopupIPCTabContext: {
       const PopupIPCTabContext &ipcContext = aParams.get_PopupIPCTabContext();
 
       TabContext *context;
       if (ipcContext.opener().type() == PBrowserOrId::TPBrowserParent) {
         context = TabParent::GetFrom(ipcContext.opener().get_PBrowserParent());
-        if (context->IsBrowserElement() && !ipcContext.isBrowserElement()) {
+        if (context->IsMozBrowserElement() &&
+            !ipcContext.isMozBrowserElement()) {
           // If the TabParent corresponds to a browser element, then it can only
           // open other browser elements, for security reasons.  We should have
           // checked this before calling the TabContext constructor, so this is
           // a fatal error.
           mInvalidReason = "Child is-browser process tried to "
                            "open a non-browser tab.";
           return;
         }
@@ -264,28 +276,30 @@ MaybeInvalidTabContext::MaybeInvalidTabC
 
       // Browser elements can't nest other browser elements.  So if
       // our opener is browser element, we must be a new DOM window
       // opened by it.  In that case we inherit our containing app ID
       // (if any).
       //
       // Otherwise, we're a new app window and we inherit from our
       // opener app.
+      isMozBrowserElement = ipcContext.isMozBrowserElement();
       originAttributes = context->mOriginAttributes;
-      if (ipcContext.isBrowserElement()) {
+      if (isMozBrowserElement) {
         containingAppId = context->OwnOrContainingAppId();
       } else {
         containingAppId = context->mContainingAppId;
       }
       break;
     }
     case IPCTabContext::TFrameIPCTabContext: {
       const FrameIPCTabContext &ipcContext =
         aParams.get_FrameIPCTabContext();
 
+      isMozBrowserElement = ipcContext.isMozBrowserElement();
       containingAppId = ipcContext.frameOwnerAppId();
       signedPkgOriginNoSuffix = ipcContext.signedPkgOriginNoSuffix();
       originSuffix = ipcContext.originSuffix();
       originAttributes.PopulateFromSuffix(originSuffix);
       break;
     }
     case IPCTabContext::TUnsafeIPCTabContext: {
       // XXXcatalinb: This used *only* by ServiceWorkerClients::OpenWindow.
@@ -305,34 +319,35 @@ MaybeInvalidTabContext::MaybeInvalidTabC
       break;
     }
     default: {
       MOZ_CRASH();
     }
   }
 
   nsCOMPtr<mozIApplication> ownApp;
-  if (!originAttributes.mInIsolatedMozBrowser) {
-    // mAppId corresponds to OwnOrContainingAppId; if mInIsolatedMozBrowser is
+  if (!isMozBrowserElement) {
+    // mAppId corresponds to OwnOrContainingAppId; if isMozBrowserElement is
     // false then it's ownApp otherwise it's containingApp
     ownApp = GetAppForId(originAttributes.mAppId);
     if ((ownApp == nullptr) != (originAttributes.mAppId == NO_APP_ID)) {
       mInvalidReason = "Got an ownAppId that didn't correspond to an app.";
       return;
     }
   }
 
   nsCOMPtr<mozIApplication> containingApp = GetAppForId(containingAppId);
   if ((containingApp == nullptr) != (containingAppId == NO_APP_ID)) {
     mInvalidReason = "Got a containingAppId that didn't correspond to an app.";
     return;
   }
 
   bool rv;
-  rv = mTabContext.SetTabContext(ownApp,
+  rv = mTabContext.SetTabContext(isMozBrowserElement,
+                                 ownApp,
                                  containingApp,
                                  originAttributes,
                                  signedPkgOriginNoSuffix);
   if (!rv) {
     mInvalidReason = "Couldn't initialize TabContext.";
   }
 }
 
--- a/dom/ipc/TabContext.h
+++ b/dom/ipc/TabContext.h
@@ -37,47 +37,61 @@ public:
 
   /**
    * Generates IPCTabContext of type BrowserFrameIPCTabContext or
    * AppFrameIPCTabContext from this TabContext's information.
    */
   IPCTabContext AsIPCTabContext() const;
 
   /**
-   * Does this TabContext correspond to a mozbrowser?  (<iframe mozbrowser
-   * mozapp> is not a browser.)
+   * Does this TabContext correspond to a mozbrowser?
    *
-   * If IsBrowserElement() is true, HasOwnApp() and HasAppOwnerApp() are
+   * <iframe mozbrowser mozapp> and <xul:browser> are not considered to be
+   * mozbrowser elements.
+   *
+   * If IsMozBrowserElement() is true, HasOwnApp() and HasAppOwnerApp() are
    * guaranteed to be false.
    *
-   * If IsBrowserElement() is false, HasBrowserOwnerApp() is guaranteed to be
+   * If IsMozBrowserElement() is false, HasBrowserOwnerApp() is guaranteed to be
    * false.
    */
-  bool IsBrowserElement() const;
+  bool IsMozBrowserElement() const;
+
+  /**
+   * Does this TabContext correspond to an isolated mozbrowser?
+   *
+   * <iframe mozbrowser mozapp> and <xul:browser> are not considered to be
+   * mozbrowser elements.  <iframe mozbrowser noisolation> does not count as
+   * isolated since isolation is disabled.  Isolation can only be disabled by
+   * chrome pages.
+   */
+  bool IsIsolatedMozBrowserElement() const;
 
   /**
    * Does this TabContext correspond to a mozbrowser or mozapp?  This is
-   * equivalent to IsBrowserElement() || HasOwnApp().
+   * equivalent to IsMozBrowserElement() || HasOwnApp().  Returns false for
+   * <xul:browser>, which is neither a mozbrowser nor a mozapp.
    */
-  bool IsBrowserOrApp() const;
+  bool IsMozBrowserOrApp() const;
 
   /**
    * OwnAppId() returns the id of the app which directly corresponds to this
    * context's frame.  GetOwnApp() returns the corresponding app object, and
    * HasOwnApp() returns true iff GetOwnApp() would return a non-null value.
    *
-   * If HasOwnApp() is true, IsBrowserElement() is guaranteed to be false.
+   * If HasOwnApp() is true, IsMozBrowserElement() is guaranteed to be
+   * false.
    */
   uint32_t OwnAppId() const;
   already_AddRefed<mozIApplication> GetOwnApp() const;
   bool HasOwnApp() const;
 
   /**
    * BrowserOwnerAppId() gets the ID of the app which contains this browser
-   * frame.  If this is not a browser frame (i.e., if !IsBrowserElement()), then
+   * frame.  If this is not a mozbrowser frame (if !IsMozBrowserElement()), then
    * BrowserOwnerAppId() is guaranteed to return NO_APP_ID.
    *
    * Even if we are a browser frame, BrowserOwnerAppId() may still return
    * NO_APP_ID, if this browser frame is not contained inside an app.
    */
   uint32_t BrowserOwnerAppId() const;
   already_AddRefed<mozIApplication> GetBrowserOwnerApp() const;
   bool HasBrowserOwnerApp() const;
@@ -135,37 +149,46 @@ protected:
 
   /**
    * Set the TabContext for this frame. This can either be:
    *  - an app frame (with the given own app) inside the given owner app. Either
    *    apps can be null.
    *  - a browser frame inside the given owner app (which may be null).
    *  - a non-browser, non-app frame. Both own app and owner app should be null.
    */
-  bool SetTabContext(mozIApplication* aOwnApp,
+  bool SetTabContext(bool aIsMozBrowserElement,
+                     mozIApplication* aOwnApp,
                      mozIApplication* aAppFrameOwnerApp,
                      const DocShellOriginAttributes& aOriginAttributes,
                      const nsACString& aSignedPkgOriginNoSuffix);
 
 private:
   /**
    * Has this TabContext been initialized?  If so, mutator methods will fail.
    */
   bool mInitialized;
 
   /**
+   * Whether this TabContext corresponds to a mozbrowser.
+   *
+   * <iframe mozbrowser mozapp> and <xul:browser> are not considered to be
+   * mozbrowser elements.
+   */
+  bool mIsMozBrowserElement;
+
+  /**
    * This TabContext's own app.  If this is non-null, then this
-   * TabContext corresponds to an app, and mIsBrowser must be false.
+   * TabContext corresponds to an app, and mIsMozBrowserElement must be false.
    */
   nsCOMPtr<mozIApplication> mOwnApp;
 
   /**
-   * This TabContext's containing app.  If mIsBrowser, this corresponds to the
-   * app which contains the browser frame; otherwise, this corresponds to the
-   * app which contains the app frame.
+   * This TabContext's containing app.  If mIsMozBrowserElement, this
+   * corresponds to the app which contains the browser frame; otherwise, this
+   * corresponds to the app which contains the app frame.
    */
   nsCOMPtr<mozIApplication> mContainingApp;
 
   /*
    * Cache of mContainingApp->GetLocalId().
    */
   uint32_t mContainingAppId;
 
@@ -192,22 +215,24 @@ class MutableTabContext : public TabCont
 {
 public:
   bool SetTabContext(const TabContext& aContext)
   {
     return TabContext::SetTabContext(aContext);
   }
 
   bool
-  SetTabContext(mozIApplication* aOwnApp,
+  SetTabContext(bool aIsMozBrowserElement,
+                mozIApplication* aOwnApp,
                 mozIApplication* aAppFrameOwnerApp,
                 const DocShellOriginAttributes& aOriginAttributes,
                 const nsACString& aSignedPkgOriginNoSuffix = EmptyCString())
   {
-    return TabContext::SetTabContext(aOwnApp,
+    return TabContext::SetTabContext(aIsMozBrowserElement,
+                                     aOwnApp,
                                      aAppFrameOwnerApp,
                                      aOriginAttributes,
                                      aSignedPkgOriginNoSuffix);
   }
 };
 
 /**
  * MaybeInvalidTabContext is a simple class that lets you transform an
--- a/dom/ipc/nsIContentParent.cpp
+++ b/dom/ipc/nsIContentParent.cpp
@@ -89,20 +89,20 @@ nsIContentParent::CanOpenBrowser(const I
     }
 
     auto opener = TabParent::GetFrom(popupContext.opener().get_PBrowserParent());
     if (!opener) {
       ASSERT_UNLESS_FUZZING("Got null opener from child; aborting AllocPBrowserParent.");
       return false;
     }
 
-    // Popup windows of isBrowser frames must be isBrowser if the parent
-    // isBrowser.  Allocating a !isBrowser frame with same app ID would allow
-    // the content to access data it's not supposed to.
-    if (!popupContext.isBrowserElement() && opener->IsBrowserElement()) {
+    // Popup windows of isMozBrowserElement frames must be isMozBrowserElement if
+    // the parent isMozBrowserElement.  Allocating a !isMozBrowserElement frame with
+    // same app ID would allow the content to access data it's not supposed to.
+    if (!popupContext.isMozBrowserElement() && opener->IsMozBrowserElement()) {
       ASSERT_UNLESS_FUZZING("Child trying to escalate privileges!  Aborting AllocPBrowserParent.");
       return false;
     }
   }
 
   MaybeInvalidTabContext tc(aContext);
   if (!tc.IsValid()) {
     NS_ERROR(nsPrintfCString("Child passed us an invalid TabContext.  (%s)  "
--- a/dom/network/TCPServerSocket.cpp
+++ b/dom/network/TCPServerSocket.cpp
@@ -143,17 +143,17 @@ TCPServerSocket::FireEvent(const nsAStri
 
 NS_IMETHODIMP
 TCPServerSocket::OnSocketAccepted(nsIServerSocket* aServer, nsISocketTransport* aTransport)
 {
   nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
   RefPtr<TCPSocket> socket = TCPSocket::CreateAcceptedSocket(global, aTransport, mUseArrayBuffers);
   if (mServerBridgeParent) {
     socket->SetAppIdAndBrowser(mServerBridgeParent->GetAppId(),
-                               mServerBridgeParent->GetInBrowser());
+                               mServerBridgeParent->GetInIsolatedMozBrowser());
   }
   FireEvent(NS_LITERAL_STRING("connect"), socket);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 TCPServerSocket::OnStopListening(nsIServerSocket* aServer, nsresult aStatus)
 {
--- a/dom/network/TCPServerSocketParent.cpp
+++ b/dom/network/TCPServerSocketParent.cpp
@@ -70,22 +70,22 @@ TCPServerSocketParent::GetAppId()
     TabParent *tab = TabParent::GetFrom(browser);
     return tab->OwnAppId();
   } else {
     return nsIScriptSecurityManager::UNKNOWN_APP_ID;
   }
 }
 
 bool
-TCPServerSocketParent::GetInBrowser()
+TCPServerSocketParent::GetInIsolatedMozBrowser()
 {
   const PContentParent *content = Manager()->Manager();
   if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) {
     TabParent *tab = TabParent::GetFrom(browser);
-    return tab->IsBrowserElement();
+    return tab->IsIsolatedMozBrowserElement();
   } else {
     return false;
   }
 }
 
 nsresult
 TCPServerSocketParent::SendCallbackAccept(TCPSocketParent *socket)
 {
@@ -145,17 +145,17 @@ TCPServerSocketParent::RecvRequestDelete
   mozilla::Unused << Send__delete__(this);
   return true;
 }
 
 void
 TCPServerSocketParent::OnConnect(TCPServerSocketEvent* event)
 {
   RefPtr<TCPSocket> socket = event->Socket();
-  socket->SetAppIdAndBrowser(GetAppId(), GetInBrowser());
+  socket->SetAppIdAndBrowser(GetAppId(), GetInIsolatedMozBrowser());
 
   RefPtr<TCPSocketParent> socketParent = new TCPSocketParent();
   socketParent->SetSocket(socket);
 
   socket->SetSocketBridgeParent(socketParent);
 
   SendCallbackAccept(socketParent);
 }
--- a/dom/network/TCPServerSocketParent.h
+++ b/dom/network/TCPServerSocketParent.h
@@ -30,17 +30,17 @@ public:
                         uint16_t aBacklog, bool aUseArrayBuffers);
 
   void Init();
 
   virtual bool RecvClose() override;
   virtual bool RecvRequestDelete() override;
 
   uint32_t GetAppId();
-  bool GetInBrowser();
+  bool GetInIsolatedMozBrowser();
 
   void AddIPDLReference();
   void ReleaseIPDLReference();
 
   void OnConnect(TCPServerSocketEvent* event);
 
 private:
   ~TCPServerSocketParent();
--- a/dom/network/TCPSocket.cpp
+++ b/dom/network/TCPSocket.cpp
@@ -161,17 +161,17 @@ TCPSocket::TCPSocket(nsIGlobalObject* aG
   , mBufferedAmount(0)
   , mSuspendCount(0)
   , mTrackingNumber(0)
   , mWaitingForStartTLS(false)
 #ifdef MOZ_WIDGET_GONK
   , mTxBytes(0)
   , mRxBytes(0)
   , mAppId(nsIScriptSecurityManager::UNKNOWN_APP_ID)
-  , mInBrowser(false)
+  , mInIsolatedMozBrowser(false)
 #endif
 {
   if (aGlobal) {
     nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal);
     if (window) {
       mInnerWindowID = window->WindowID();
     }
   }
@@ -1095,21 +1095,21 @@ TCPSocket::OnStopRequest(nsIRequest* aRe
 
 void
 TCPSocket::SetSocketBridgeParent(TCPSocketParent* aBridgeParent)
 {
   mSocketBridgeParent = aBridgeParent;
 }
 
 void
-TCPSocket::SetAppIdAndBrowser(uint32_t aAppId, bool aInBrowser)
+TCPSocket::SetAppIdAndBrowser(uint32_t aAppId, bool aInIsolatedMozBrowser)
 {
 #ifdef MOZ_WIDGET_GONK
   mAppId = aAppId;
-  mInBrowser = aInBrowser;
+  mInIsolatedMozBrowser = aInIsolatedMozBrowser;
 #endif
 }
 
 NS_IMETHODIMP
 TCPSocket::UpdateReadyState(uint32_t aReadyState)
 {
   MOZ_ASSERT(mSocketBridgeChild);
   mReadyState = static_cast<TCPReadyState>(aReadyState);
@@ -1150,18 +1150,18 @@ TCPSocket::SaveNetworkStats(bool aEnforc
   }
 
   nsCOMPtr<nsINetworkStatsServiceProxy> nssProxy =
     do_GetService("@mozilla.org/networkstatsServiceProxy;1");
   if (!nssProxy) {
     return;
   }
 
-  nssProxy->SaveAppStats(mAppId, mInBrowser, mActiveNetworkInfo, PR_Now(),
-                         mRxBytes, mTxBytes, false, nullptr);
+  nssProxy->SaveAppStats(mAppId, mInIsolatedMozBrowser, mActiveNetworkInfo,
+                         PR_Now(), mRxBytes, mTxBytes, false, nullptr);
 
   // Reset the counters once the statistics is saved to NetworkStatsServiceProxy.
   mTxBytes = mRxBytes = 0;
 }
 #endif
 
 NS_IMETHODIMP
 TCPSocket::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
--- a/dom/network/TCPSocket.h
+++ b/dom/network/TCPSocket.h
@@ -237,18 +237,18 @@ private:
 
 #ifdef MOZ_WIDGET_GONK
   // Number of bytes sent.
   uint32_t mTxBytes;
   // Number of bytes received.
   uint32_t mRxBytes;
   // The app that owns this socket.
   uint32_t mAppId;
-  // Was this socket created inside of a mozbrowser frame?
-  bool mInBrowser;
+  // Was this socket created inside of an isolated browser frame?
+  bool mInIsolatedMozBrowser;
   // The name of the active network used by this socket.
   nsCOMPtr<nsINetworkInfo> mActiveNetworkInfo;
 #endif
 };
 
 } // namespace dom
 } // namespace mozilla
 
--- a/dom/network/TCPSocketParent.cpp
+++ b/dom/network/TCPSocketParent.cpp
@@ -72,22 +72,22 @@ TCPSocketParent::GetAppId()
     TabParent *tab = TabParent::GetFrom(browser);
     return tab->OwnAppId();
   } else {
     return nsIScriptSecurityManager::UNKNOWN_APP_ID;
   }
 };
 
 bool
-TCPSocketParent::GetInBrowser()
+TCPSocketParent::GetInIsolatedMozBrowser()
 {
   const PContentParent *content = Manager()->Manager();
   if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) {
     TabParent *tab = TabParent::GetFrom(browser);
-    return tab->IsBrowserElement();
+    return tab->IsIsolatedMozBrowserElement();
   } else {
     return false;
   }
 }
 
 nsresult
 TCPSocketParent::OfflineNotification(nsISupports *aSubject)
 {
@@ -150,26 +150,26 @@ TCPSocketParent::RecvOpen(const nsString
   if (net::UsingNeckoIPCSecurity() &&
       !AssertAppProcessPermission(Manager()->Manager(), "tcp-socket")) {
     FireInteralError(this, __LINE__);
     return true;
   }
 
   // Obtain App ID
   uint32_t appId = GetAppId();
-  bool     inBrowser = GetInBrowser();
+  bool     inIsolatedMozBrowser = GetInIsolatedMozBrowser();
 
   if (NS_IsAppOffline(appId)) {
     NS_ERROR("Can't open socket because app is offline");
     FireInteralError(this, __LINE__);
     return true;
   }
 
   mSocket = new TCPSocket(nullptr, aHost, aPort, aUseSSL, aUseArrayBuffers);
-  mSocket->SetAppIdAndBrowser(appId, inBrowser);
+  mSocket->SetAppIdAndBrowser(appId, inIsolatedMozBrowser);
   mSocket->SetSocketBridgeParent(this);
   NS_ENSURE_SUCCESS(mSocket->Init(), true);
   return true;
 }
 
 bool
 TCPSocketParent::RecvOpenBind(const nsCString& aRemoteHost,
                               const uint16_t& aRemotePort,
@@ -216,28 +216,28 @@ TCPSocketParent::RecvOpenBind(const nsCS
   rv = socketTransport->Bind(&addr);
   if (NS_FAILED(rv)) {
     FireInteralError(this, __LINE__);
     return true;
   }
 
   // Obtain App ID
   uint32_t appId = nsIScriptSecurityManager::NO_APP_ID;
-  bool     inBrowser = false;
+  bool     inIsolatedMozBrowser = false;
   const PContentParent *content = Manager()->Manager();
   if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) {
     // appId's are for B2G only currently, where managees.Count() == 1
     // This is not guaranteed currently in Desktop, so skip this there.
     TabParent *tab = TabParent::GetFrom(browser);
     appId = tab->OwnAppId();
-    inBrowser = tab->IsBrowserElement();
+    inIsolatedMozBrowser = tab->IsIsolatedMozBrowserElement();
   }
 
   mSocket = new TCPSocket(nullptr, NS_ConvertUTF8toUTF16(aRemoteHost), aRemotePort, aUseSSL, aUseArrayBuffers);
-  mSocket->SetAppIdAndBrowser(appId, inBrowser);
+  mSocket->SetAppIdAndBrowser(appId, inIsolatedMozBrowser);
   mSocket->SetSocketBridgeParent(this);
   rv = mSocket->InitWithUnconnectedTransport(socketTransport);
   NS_ENSURE_SUCCESS(rv, true);
   return true;
 }
 
 bool
 TCPSocketParent::RecvStartTLS()
--- a/dom/network/TCPSocketParent.h
+++ b/dom/network/TCPSocketParent.h
@@ -63,17 +63,17 @@ public:
   virtual bool RecvSuspend() override;
   virtual bool RecvResume() override;
   virtual bool RecvClose() override;
   virtual bool RecvData(const SendableData& aData,
                         const uint32_t& aTrackingNumber) override;
   virtual bool RecvRequestDelete() override;
   virtual nsresult OfflineNotification(nsISupports *) override;
   virtual uint32_t GetAppId() override;
-  bool GetInBrowser();
+  bool GetInIsolatedMozBrowser();
 
   void FireErrorEvent(const nsAString& aName, const nsAString& aType, TCPReadyState aReadyState);
   void FireEvent(const nsAString& aType, TCPReadyState aReadyState);
   void FireArrayBufferDataEvent(nsTArray<uint8_t>& aBuffer, TCPReadyState aReadyState);
   void FireStringDataEvent(const nsACString& aData, TCPReadyState aReadyState);
 
   void SetSocket(TCPSocket *socket);
   nsresult GetHost(nsAString& aHost);
--- a/dom/workers/ServiceWorkerManagerService.cpp
+++ b/dom/workers/ServiceWorkerManagerService.cpp
@@ -63,17 +63,17 @@ public:
         // mContentParent needs to be released in the main thread.
         data.mContentParent = nullptr;
         // We only send the notification about the soft update to the
         // tabs/apps with the same appId and inIsolatedMozBrowser values.
         // Sending a notification to the wrong process will make the process
         // to be killed.
         for (uint32_t j = 0; j < contextArray.Length(); ++j) {
           if ((contextArray[j].OwnOrContainingAppId() == mOriginAttributes.mAppId) &&
-              (contextArray[j].IsBrowserElement() == mOriginAttributes.mInIsolatedMozBrowser)) {
+              (contextArray[j].IsIsolatedMozBrowserElement() == mOriginAttributes.mInIsolatedMozBrowser)) {
             continue;
           }
           // Array entries with no mParent won't receive any notification.
           data.mParent = nullptr;
         }
       }
       nsresult rv = mBackgroundThread->Dispatch(this, NS_DISPATCH_NORMAL);
       MOZ_ALWAYS_TRUE(NS_SUCCEEDED(rv));
--- a/netwerk/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -123,27 +123,27 @@ NeckoParent::GetValidatedAppInfo(const S
 
   nsTArray<TabContext> contextArray =
     static_cast<ContentParent*>(aContent)->GetManagedTabContext();
   for (uint32_t i = 0; i < contextArray.Length(); i++) {
     TabContext tabContext = contextArray[i];
     uint32_t appId = tabContext.OwnOrContainingAppId();
     bool inBrowserElement = aSerialized.IsNotNull() ?
                               aSerialized.mOriginAttributes.mInIsolatedMozBrowser :
-                              tabContext.IsBrowserElement();
+                              tabContext.IsIsolatedMozBrowserElement();
 
     if (appId == NECKO_UNKNOWN_APP_ID) {
       continue;
     }
     // We may get appID=NO_APP if child frame is neither a browser nor an app
     if (appId == NECKO_NO_APP_ID) {
       if (tabContext.HasOwnApp()) {
         continue;
       }
-      if (UsingNeckoIPCSecurity() && tabContext.IsBrowserElement()) {
+      if (UsingNeckoIPCSecurity() && tabContext.IsIsolatedMozBrowserElement()) {
         // <iframe mozbrowser> which doesn't have an <iframe mozapp> above it.
         // This is not supported now, and we'll need to do a code audit to make
         // sure we can handle it (i.e don't short-circuit using separate
         // namespace if just appID==0)
         continue;
       }
     }