Bug 1114890 - Use TabParent::GetFrom everywhere. r=billm
authorKan-Ru Chen (陳侃如) <kanru@kanru.info>
Thu, 05 Feb 2015 16:47:32 -0500
changeset 241254 5a065c4d610eda345b5b539b1b0e6cbf1aa90c64
parent 241253 7fde8710208a926c614005a48a984a21af522367
child 241255 8d8a696af76a5fd8732b9349c967f5452313474b
push id586
push userjames@hoppipolla.co.uk
push dateFri, 06 Feb 2015 11:29:51 +0000
reviewersbillm
bugs1114890
milestone38.0a1
Bug 1114890 - Use TabParent::GetFrom everywhere. r=billm
dom/base/nsContentPermissionHelper.cpp
dom/base/nsContentUtils.cpp
dom/base/nsFrameLoader.cpp
dom/events/EventStateManager.cpp
dom/indexedDB/ActorsParent.cpp
dom/ipc/AppProcessChecker.cpp
dom/ipc/ColorPickerParent.cpp
dom/ipc/ContentParent.cpp
dom/ipc/ContentProcessManager.cpp
dom/ipc/FilePickerParent.cpp
dom/ipc/ProcessHangMonitor.cpp
dom/ipc/ProcessPriorityManager.cpp
dom/ipc/TabContext.cpp
dom/ipc/TabParent.cpp
dom/ipc/TabParent.h
dom/ipc/nsIContentParent.cpp
dom/network/TCPServerSocketParent.cpp
dom/network/TCPSocketParent.cpp
dom/network/UDPSocketParent.cpp
embedding/components/printingui/ipc/PrintingParent.cpp
hal/sandbox/SandboxHal.cpp
layout/ipc/RenderFrameParent.cpp
netwerk/ipc/NeckoParent.cpp
uriloader/exthandler/ExternalHelperAppParent.cpp
--- a/dom/base/nsContentPermissionHelper.cpp
+++ b/dom/base/nsContentPermissionHelper.cpp
@@ -87,17 +87,17 @@ ContentPermissionRequestParent::ActorDes
   }
 }
 
 bool
 ContentPermissionRequestParent::IsBeingDestroyed()
 {
   // When TabParent::Destroy() is called, we are being destroyed. It's unsafe
   // to send out any message now.
-  TabParent* tabParent = static_cast<TabParent*>(Manager());
+  TabParent* tabParent = TabParent::GetFrom(Manager());
   return tabParent->IsDestroyed();
 }
 
 NS_IMPL_ISUPPORTS(ContentPermissionType, nsIContentPermissionType)
 
 ContentPermissionType::ContentPermissionType(const nsACString& aType,
                                              const nsACString& aAccess,
                                              const nsTArray<nsString>& aOptions)
@@ -392,24 +392,22 @@ nsContentPermissionRequestProxy::Allow(J
   }
 
 #ifdef MOZ_WIDGET_GONK
   uint32_t len = mPermissionRequests.Length();
   for (uint32_t i = 0; i < len; i++) {
     if (mPermissionRequests[i].type().EqualsLiteral("audio-capture")) {
       GonkPermissionService::GetInstance()->addGrantInfo(
         "android.permission.RECORD_AUDIO",
-        static_cast<TabParent*>(
-          mParent->Manager())->Manager()->AsContentParent()->Pid());
+        TabParent::GetFrom(mParent->Manager())->Manager()->AsContentParent()->Pid());
     }
     if (mPermissionRequests[i].type().EqualsLiteral("video-capture")) {
       GonkPermissionService::GetInstance()->addGrantInfo(
         "android.permission.CAMERA",
-        static_cast<TabParent*>(
-          mParent->Manager())->Manager()->AsContentParent()->Pid());
+        TabParent::GetFrom(mParent->Manager())->Manager()->AsContentParent()->Pid());
     }
   }
 #endif
 
   nsTArray<PermissionChoice> choices;
   if (aChoices.isNullOrUndefined()) {
     // No choice is specified.
   } else if (aChoices.isObject()) {
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -7159,18 +7159,17 @@ nsContentUtils::CallOnAllRemoteChildren(
     }
 
     nsCOMPtr<nsIMessageSender> tabMM = do_QueryInterface(childMM);
 
     mozilla::dom::ipc::MessageManagerCallback* cb =
      static_cast<nsFrameMessageManager*>(tabMM.get())->GetCallback();
     if (cb) {
       nsFrameLoader* fl = static_cast<nsFrameLoader*>(cb);
-      PBrowserParent* remoteBrowser = fl->GetRemoteBrowser();
-      TabParent* remote = static_cast<TabParent*>(remoteBrowser);
+      TabParent* remote = TabParent::GetFrom(fl);
       if (remote && aCallback) {
         aCallback(remote, aArg);
       }
     }
   }
 }
 
 void
--- a/dom/base/nsFrameLoader.cpp
+++ b/dom/base/nsFrameLoader.cpp
@@ -2093,17 +2093,17 @@ nsFrameLoader::TryRemoteBrowser()
     return false;
   }
 
   nsCOMPtr<nsIDocShell> parentDocShell = parentWin->GetDocShell();
   if (!parentDocShell) {
     return false;
   }
 
-  TabParent* openingTab = static_cast<TabParent*>(parentDocShell->GetOpener());
+  TabParent* openingTab = TabParent::GetFrom(parentDocShell->GetOpener());
   ContentParent* openerContentParent = nullptr;
 
   if (openingTab &&
       openingTab->Manager() &&
       openingTab->Manager()->IsContentParent()) {
     openerContentParent = openingTab->Manager()->AsContentParent();
   }
 
@@ -2299,17 +2299,17 @@ nsFrameLoader::CreateStaticClone(nsIFram
 
   viewer->SetDOMDocument(clonedDOMDoc);
   return NS_OK;
 }
 
 bool
 nsFrameLoader::DoLoadFrameScript(const nsAString& aURL, bool aRunInGlobalScope)
 {
-  auto* tabParent = static_cast<TabParent*>(GetRemoteBrowser());
+  auto* tabParent = TabParent::GetFrom(GetRemoteBrowser());
   if (tabParent) {
     return tabParent->SendLoadRemoteScript(nsString(aURL), aRunInGlobalScope);
   }
   nsRefPtr<nsInProcessTabChildGlobal> tabChild =
     static_cast<nsInProcessTabChildGlobal*>(GetTabChildGlobalAsEventTarget());
   if (tabChild) {
     tabChild->LoadFrameScript(aURL, aRunInGlobalScope);
   }
@@ -2495,17 +2495,17 @@ nsFrameLoader::GetChildID(uint64_t* aChi
 }
 
 void
 nsFrameLoader::SetRemoteBrowser(nsITabParent* aTabParent)
 {
   MOZ_ASSERT(!mRemoteBrowser);
   MOZ_ASSERT(!mCurrentRemoteFrame);
   mRemoteFrame = true;
-  mRemoteBrowser = static_cast<TabParent*>(aTabParent);
+  mRemoteBrowser = TabParent::GetFrom(aTabParent);
   mChildID = mRemoteBrowser ? mRemoteBrowser->Manager()->ChildID() : 0;
   ShowRemoteFrame(nsIntSize(0, 0));
 }
 
 void
 nsFrameLoader::SetDetachedSubdocView(nsView* aDetachedViews,
                                      nsIDocument* aContainerDoc)
 {
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -1083,18 +1083,17 @@ EventStateManager::HandleAccessKey(nsPre
     }
   }// if end. bubble up process
 }// end of HandleAccessKey
 
 bool
 EventStateManager::DispatchCrossProcessEvent(WidgetEvent* aEvent,
                                              nsFrameLoader* aFrameLoader,
                                              nsEventStatus *aStatus) {
-  PBrowserParent* remoteBrowser = aFrameLoader->GetRemoteBrowser();
-  TabParent* remote = static_cast<TabParent*>(remoteBrowser);
+  TabParent* remote = TabParent::GetFrom(aFrameLoader);
   if (!remote) {
     return false;
   }
 
   switch (aEvent->mClass) {
   case eMouseEventClass: {
     return remote->SendRealMouseEvent(*aEvent->AsMouseEvent());
   }
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -10982,17 +10982,17 @@ FactoryOp::CheckAtLeastOneAppHasPermissi
 
     const nsPromiseFlatCString permissionString =
       PromiseFlatCString(aPermissionString);
 
     for (uint32_t index = 0, count = browsers.Length();
          index < count;
          index++) {
       uint32_t appId =
-        static_cast<TabParent*>(browsers[index])->OwnOrContainingAppId();
+        TabParent::GetFrom(browsers[index])->OwnOrContainingAppId();
       MOZ_ASSERT(kUnknownAppId != appId && kNoAppId != appId);
 
       nsCOMPtr<mozIApplication> app;
       nsresult rv = appsService->GetAppByLocalId(appId, getter_AddRefs(app));
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return false;
       }
 
--- a/dom/ipc/AppProcessChecker.cpp
+++ b/dom/ipc/AppProcessChecker.cpp
@@ -78,17 +78,17 @@ AssertAppProcess(PBrowserParent* aActor,
                  AssertAppProcessType aType,
                  const char* aCapability)
 {
   if (!aActor) {
     NS_WARNING("Testing process capability for null actor");
     return false;
   }
 
-  TabParent* tab = static_cast<TabParent*>(aActor);
+  TabParent* tab = TabParent::GetFrom(aActor);
   nsCOMPtr<mozIApplication> app = tab->GetOwnOrContainingApp();
 
   return CheckAppTypeHelper(app, aType, aCapability, tab->IsBrowserElement());
 }
 
 static bool
 CheckAppStatusHelper(mozIApplication* aApp,
                      unsigned short aStatus)
@@ -109,17 +109,17 @@ bool
 AssertAppStatus(PBrowserParent* aActor,
                 unsigned short aStatus)
 {
   if (!aActor) {
     NS_WARNING("Testing process capability for null actor");
     return false;
   }
 
-  TabParent* tab = static_cast<TabParent*>(aActor);
+  TabParent* tab = TabParent::GetFrom(aActor);
   nsCOMPtr<mozIApplication> app = tab->GetOwnOrContainingApp();
 
   return CheckAppStatusHelper(app, aStatus);
 }
 
 bool
 AssertAppProcess(TabContext& aContext,
                  AssertAppProcessType aType,
--- a/dom/ipc/ColorPickerParent.cpp
+++ b/dom/ipc/ColorPickerParent.cpp
@@ -46,17 +46,17 @@ ColorPickerParent::ColorPickerShownCallb
 bool
 ColorPickerParent::CreateColorPicker()
 {
   mPicker = do_CreateInstance("@mozilla.org/colorpicker;1");
   if (!mPicker) {
     return false;
   }
 
-  Element* ownerElement = static_cast<TabParent*>(Manager())->GetOwnerElement();
+  Element* ownerElement = TabParent::GetFrom(Manager())->GetOwnerElement();
   if (!ownerElement) {
     return false;
   }
 
   nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(ownerElement->OwnerDoc()->GetWindow());
   if (!window) {
     return false;
   }
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -1070,17 +1070,17 @@ ContentParent::CreateBrowserOrApp(const 
                 // DeallocPBrowserParent() releases this ref.
                 tp.forget().take(),
                 tabId,
                 aContext.AsIPCTabContext(),
                 chromeFlags,
                 constructorSender->ChildID(),
                 constructorSender->IsForApp(),
                 constructorSender->IsForBrowser());
-            return static_cast<TabParent*>(browser);
+            return TabParent::GetFrom(browser);
         }
         return nullptr;
     }
 
     // If we got here, we have an app and we're not a browser element.  ownApp
     // shouldn't be null, because we otherwise would have gone into the
     // !HasOwnApp() branch above.
     nsRefPtr<nsIContentParent> parent;
@@ -1184,17 +1184,17 @@ ContentParent::CreateBrowserOrApp(const 
         aContext.AsIPCTabContext(),
         chromeFlags,
         parent->ChildID(),
         parent->IsForApp(),
         parent->IsForBrowser());
 
     if (isInContentProcess) {
         // Just return directly without the following check in content process.
-        return static_cast<TabParent*>(browser);
+        return TabParent::GetFrom(browser);
     }
 
     if (!browser) {
         // We failed to actually start the PBrowser.  This can happen if the
         // other process has already died.
         if (!reused) {
             // Don't leave a broken ContentParent in the hashtable.
             parent->AsContentParent()->KillHard("CreateBrowserOrApp");
@@ -1213,17 +1213,17 @@ ContentParent::CreateBrowserOrApp(const 
         }
 
         // Otherwise just give up.
         return nullptr;
     }
 
     parent->AsContentParent()->MaybeTakeCPUWakeLock(aFrameElement);
 
-    return static_cast<TabParent*>(browser);
+    return TabParent::GetFrom(browser);
 }
 
 /*static*/ ContentBridgeParent*
 ContentParent::CreateContentBridgeParent(const TabContext& aContext,
                                          const hal::ProcessPriority& aPriority,
                                          const TabId& aOpenerTabId,
                                          /*out*/ TabId* aTabId)
 {
--- a/dom/ipc/ContentProcessManager.cpp
+++ b/dom/ipc/ContentProcessManager.cpp
@@ -287,17 +287,17 @@ ContentProcessManager::GetTabParentByPro
   if (NS_WARN_IF(iter == mContentParentMap.end())) {
     ASSERT_UNLESS_FUZZING();
     return nullptr;
   }
 
   const InfallibleTArray<PBrowserParent*>& browsers =
     iter->second.mCp->ManagedPBrowserParent();
   for (uint32_t i = 0; i < browsers.Length(); i++) {
-    nsRefPtr<TabParent> tab = static_cast<TabParent*>(browsers[i]);
+    nsRefPtr<TabParent> tab = TabParent::GetFrom(browsers[i]);
     if (tab->GetTabId() == aChildTabId) {
       return tab.forget();
     }
   }
 
   return nullptr;
 }
 
--- a/dom/ipc/FilePickerParent.cpp
+++ b/dom/ipc/FilePickerParent.cpp
@@ -108,17 +108,17 @@ void
 FilePickerParent::FileSizeAndDateRunnable::Destroy()
 {
   mFilePickerParent = nullptr;
 }
 
 void
 FilePickerParent::SendFiles(const nsCOMArray<nsIDOMFile>& aDomfiles)
 {
-  nsIContentParent* parent = static_cast<TabParent*>(Manager())->Manager();
+  nsIContentParent* parent = TabParent::GetFrom(Manager())->Manager();
   InfallibleTArray<PBlobParent*> files;
 
   for (unsigned i = 0; i < aDomfiles.Length(); i++) {
     BlobParent* blob = parent->GetOrCreateActorForBlob(
       static_cast<File*>(aDomfiles[i]));
     if (blob) {
       files.AppendElement(blob);
     }
@@ -178,17 +178,17 @@ FilePickerParent::Done(int16_t aResult)
 bool
 FilePickerParent::CreateFilePicker()
 {
   mFilePicker = do_CreateInstance("@mozilla.org/filepicker;1");
   if (!mFilePicker) {
     return false;
   }
 
-  Element* element = static_cast<TabParent*>(Manager())->GetOwnerElement();
+  Element* element = TabParent::GetFrom(Manager())->GetOwnerElement();
   if (!element) {
     return false;
   }
 
   nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(element->OwnerDoc()->GetWindow());
   if (!window) {
     return false;
   }
--- a/dom/ipc/ProcessHangMonitor.cpp
+++ b/dom/ipc/ProcessHangMonitor.cpp
@@ -614,17 +614,17 @@ HangMonitoredProcess::GetScriptBrowser(n
   TabId tabId = mHangData.get_SlowScriptData().tabId();
   if (!mContentParent) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   nsTArray<PBrowserParent*> tabs;
   mContentParent->ManagedPBrowserParent(tabs);
   for (size_t i = 0; i < tabs.Length(); i++) {
-    TabParent* tp = static_cast<TabParent*>(tabs[i]);
+    TabParent* tp = TabParent::GetFrom(tabs[i]);
     if (tp->GetTabId() == tabId) {
       nsCOMPtr<nsIDOMElement> node = do_QueryInterface(tp->GetOwnerElement());
       node.forget(aBrowser);
       return NS_OK;
     }
   }
 
   *aBrowser = nullptr;
@@ -760,24 +760,23 @@ HangMonitoredProcess::IsReportForBrowser
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
   if (!mActor) {
     *aResult = false;
     return NS_OK;
   }
 
-  nsCOMPtr<nsITabParent> itp;
-  aFrameLoader->GetTabParent(getter_AddRefs(itp));
-  if (!itp) {
+  TabParent* tp = TabParent::GetFrom(aFrameLoader);
+  if (!tp) {
     *aResult = false;
     return NS_OK;
   }
 
-  *aResult = mContentParent == static_cast<TabParent*>(itp.get())->Manager();
+  *aResult = mContentParent == tp->Manager();
   return NS_OK;
 }
 
 ProcessHangMonitor* ProcessHangMonitor::sInstance;
 
 ProcessHangMonitor::ProcessHangMonitor()
  : mCPOWTimeout(false)
 {
--- a/dom/ipc/ProcessPriorityManager.cpp
+++ b/dom/ipc/ProcessPriorityManager.cpp
@@ -808,56 +808,54 @@ ParticularProcessPriorityManager::OnRemo
 
   // Ignore notifications that aren't from a BrowserOrApp
   bool isBrowserOrApp;
   fl->GetOwnerIsBrowserOrAppFrame(&isBrowserOrApp);
   if (!isBrowserOrApp) {
     return;
   }
 
-  nsCOMPtr<nsITabParent> tp;
-  fl->GetTabParent(getter_AddRefs(tp));
+  TabParent* tp = TabParent::GetFrom(fl);
   NS_ENSURE_TRUE_VOID(tp);
 
   MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
-  if (static_cast<TabParent*>(tp.get())->Manager() != mContentParent) {
+  if (tp->Manager() != mContentParent) {
     return;
   }
 
   ResetPriority();
 }
 
 void
 ParticularProcessPriorityManager::OnTabParentDestroyed(nsISupports* aSubject)
 {
   nsCOMPtr<nsITabParent> tp = do_QueryInterface(aSubject);
   NS_ENSURE_TRUE_VOID(tp);
 
   MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
-  if (static_cast<TabParent*>(tp.get())->Manager() != mContentParent) {
+  if (TabParent::GetFrom(tp)->Manager() != mContentParent) {
     return;
   }
 
   ResetPriority();
 }
 
 void
 ParticularProcessPriorityManager::OnFrameloaderVisibleChanged(nsISupports* aSubject)
 {
   nsCOMPtr<nsIFrameLoader> fl = do_QueryInterface(aSubject);
   NS_ENSURE_TRUE_VOID(fl);
 
-  nsCOMPtr<nsITabParent> tp;
-  fl->GetTabParent(getter_AddRefs(tp));
+  TabParent* tp = TabParent::GetFrom(fl);
   if (!tp) {
     return;
   }
 
   MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
-  if (static_cast<TabParent*>(tp.get())->Manager() != mContentParent) {
+  if (tp->Manager() != mContentParent) {
     return;
   }
 
   // Most of the time when something changes in a process we call
   // ResetPriority(), giving a grace period before downgrading its priority.
   // But notice that here don't give a grace period: We call ResetPriorityNow()
   // instead.
   //
@@ -927,32 +925,32 @@ ParticularProcessPriorityManager::Notify
 
 bool
 ParticularProcessPriorityManager::HasAppType(const char* aAppType)
 {
   const InfallibleTArray<PBrowserParent*>& browsers =
     mContentParent->ManagedPBrowserParent();
   for (uint32_t i = 0; i < browsers.Length(); i++) {
     nsAutoString appType;
-    static_cast<TabParent*>(browsers[i])->GetAppType(appType);
+    TabParent::GetFrom(browsers[i])->GetAppType(appType);
     if (appType.EqualsASCII(aAppType)) {
       return true;
     }
   }
 
   return false;
 }
 
 bool
 ParticularProcessPriorityManager::IsExpectingSystemMessage()
 {
   const InfallibleTArray<PBrowserParent*>& browsers =
     mContentParent->ManagedPBrowserParent();
   for (uint32_t i = 0; i < browsers.Length(); i++) {
-    TabParent* tp = static_cast<TabParent*>(browsers[i]);
+    TabParent* tp = TabParent::GetFrom(browsers[i]);
     nsCOMPtr<nsIMozBrowserFrame> bf = do_QueryInterface(tp->GetOwnerElement());
     if (!bf) {
       continue;
     }
 
     if (bf->GetIsExpectingSystemMessage()) {
       return true;
     }
@@ -974,17 +972,17 @@ ParticularProcessPriorityManager::Comput
       HasAppType("critical")) {
     return PROCESS_PRIORITY_FOREGROUND_HIGH;
   }
 
   bool isVisible = false;
   const InfallibleTArray<PBrowserParent*>& browsers =
     mContentParent->ManagedPBrowserParent();
   for (uint32_t i = 0; i < browsers.Length(); i++) {
-    if (static_cast<TabParent*>(browsers[i])->IsVisible()) {
+    if (TabParent::GetFrom(browsers[i])->IsVisible()) {
       isVisible = true;
       break;
     }
   }
 
   if (isVisible) {
     return HasAppType("inputmethod") ?
       PROCESS_PRIORITY_FOREGROUND_KEYBOARD :
--- a/dom/ipc/TabContext.cpp
+++ b/dom/ipc/TabContext.cpp
@@ -252,17 +252,17 @@ MaybeInvalidTabContext::MaybeInvalidTabC
 
   const IPCTabAppBrowserContext& appBrowser = aParams.appBrowserContext();
   switch(appBrowser.type()) {
     case IPCTabAppBrowserContext::TPopupIPCTabContext: {
       const PopupIPCTabContext &ipcContext = appBrowser.get_PopupIPCTabContext();
 
       TabContext *context;
       if (ipcContext.opener().type() == PBrowserOrId::TPBrowserParent) {
-        context = static_cast<TabParent*>(ipcContext.opener().get_PBrowserParent());
+        context = TabParent::GetFrom(ipcContext.opener().get_PBrowserParent());
         if (context->IsBrowserElement() && !ipcContext.isBrowserElement()) {
           // 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;
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -544,17 +544,17 @@ TabParent::RecvCreateWindow(PBrowserPare
     return false;
   }
 
   nsresult rv;
   nsCOMPtr<nsPIWindowWatcher> pwwatch =
     do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, false);
 
-  TabParent* newTab = static_cast<TabParent*>(aNewTab);
+  TabParent* newTab = TabParent::GetFrom(aNewTab);
 
   nsCOMPtr<nsIContent> frame(do_QueryInterface(mFrameElement));
 
   nsCOMPtr<nsIDOMWindow> parent;
   if (frame) {
     parent = do_QueryInterface(frame->OwnerDoc()->GetWindow());
 
     // If our chrome window is in the process of closing, don't try to open a
@@ -648,17 +648,17 @@ TabParent::RecvCreateWindow(PBrowserPare
   NS_ENSURE_TRUE(pwindow, false);
 
   nsRefPtr<nsIDocShell> newDocShell = pwindow->GetDocShell();
   NS_ENSURE_TRUE(newDocShell, false);
 
   nsCOMPtr<nsITabParent> newRemoteTab = newDocShell->GetOpenedRemote();
   NS_ENSURE_TRUE(newRemoteTab, false);
 
-  MOZ_ASSERT(static_cast<TabParent*>(newRemoteTab.get()) == newTab);
+  MOZ_ASSERT(TabParent::GetFrom(newRemoteTab) == newTab);
 
   aFrameScripts->SwapElements(newTab->mDelayedFrameScripts);
   return true;
 }
 
 TabParent* TabParent::sNextTabParent;
 
 /* static */ TabParent*
@@ -2023,16 +2023,36 @@ TabParent::GetFrom(nsFrameLoader* aFrame
   if (!aFrameLoader) {
     return nullptr;
   }
   PBrowserParent* remoteBrowser = aFrameLoader->GetRemoteBrowser();
   return static_cast<TabParent*>(remoteBrowser);
 }
 
 /*static*/ TabParent*
+TabParent::GetFrom(nsIFrameLoader* aFrameLoader)
+{
+  if (!aFrameLoader)
+    return nullptr;
+  return GetFrom(static_cast<nsFrameLoader*>(aFrameLoader));
+}
+
+/*static*/ TabParent*
+TabParent::GetFrom(nsITabParent* aTabParent)
+{
+  return static_cast<TabParent*>(aTabParent);
+}
+
+/*static*/ TabParent*
+TabParent::GetFrom(PBrowserParent* aTabParent)
+{
+  return static_cast<TabParent*>(aTabParent);
+}
+
+/*static*/ TabParent*
 TabParent::GetFrom(nsIContent* aContent)
 {
   nsCOMPtr<nsIFrameLoaderOwner> loaderOwner = do_QueryInterface(aContent);
   if (!loaderOwner) {
     return nullptr;
   }
   nsRefPtr<nsFrameLoader> frameLoader = loaderOwner->GetFrameLoader();
   return GetFrom(frameLoader);
@@ -2420,17 +2440,17 @@ TabParent::MaybeForwardEventToRenderFram
 bool
 TabParent::RecvBrowserFrameOpenWindow(PBrowserParent* aOpener,
                                       const nsString& aURL,
                                       const nsString& aName,
                                       const nsString& aFeatures,
                                       bool* aOutWindowOpened)
 {
   BrowserElementParent::OpenWindowResult opened =
-    BrowserElementParent::OpenWindowOOP(static_cast<TabParent*>(aOpener),
+    BrowserElementParent::OpenWindowOOP(TabParent::GetFrom(aOpener),
                                         this, aURL, aName, aFeatures);
   *aOutWindowOpened = (opened != BrowserElementParent::OPEN_WINDOW_CANCELLED);
   return true;
 }
 
 bool
 TabParent::RecvZoomToRect(const uint32_t& aPresShellId,
                           const ViewID& aViewId,
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -19,16 +19,17 @@
 #include "nsITabParent.h"
 #include "nsIXULBrowserWindow.h"
 #include "nsWeakReference.h"
 #include "Units.h"
 #include "WritingModes.h"
 #include "js/TypeDecls.h"
 
 class nsFrameLoader;
+class nsIFrameLoader;
 class nsIContent;
 class nsIPrincipal;
 class nsIURI;
 class nsIWidget;
 class nsILoadContext;
 class nsIDocShell;
 
 namespace mozilla {
@@ -323,16 +324,19 @@ public:
     NS_DECL_NSISECUREBROWSERUI
 
     static TabParent *GetIMETabParent() { return mIMETabParent; }
     bool HandleQueryContentEvent(mozilla::WidgetQueryContentEvent& aEvent);
     bool SendCompositionEvent(mozilla::WidgetCompositionEvent& event);
     bool SendSelectionEvent(mozilla::WidgetSelectionEvent& event);
 
     static TabParent* GetFrom(nsFrameLoader* aFrameLoader);
+    static TabParent* GetFrom(nsIFrameLoader* aFrameLoader);
+    static TabParent* GetFrom(nsITabParent* aTabParent);
+    static TabParent* GetFrom(PBrowserParent* aTabParent);
     static TabParent* GetFrom(nsIContent* aContent);
     static TabId GetTabIdFrom(nsIDocShell* docshell);
 
     nsIContentParent* Manager() { return mManager; }
 
     /**
      * Let managees query if Destroy() is already called so they don't send out
      * messages when the PBrowser actor is being destroyed.
--- a/dom/ipc/nsIContentParent.cpp
+++ b/dom/ipc/nsIContentParent.cpp
@@ -82,17 +82,17 @@ nsIContentParent::CanOpenBrowser(const I
   }
 
   const PopupIPCTabContext& popupContext = appBrowser.get_PopupIPCTabContext();
   if (popupContext.opener().type() != PBrowserOrId::TPBrowserParent) {
     ASSERT_UNLESS_FUZZING();
     return false;
   }
 
-  auto opener = static_cast<TabParent*>(popupContext.opener().get_PBrowserParent());
+  auto opener = TabParent::GetFrom(popupContext.opener().get_PBrowserParent());
   if (!opener) {
     ASSERT_UNLESS_FUZZING();
     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.
@@ -135,17 +135,17 @@ nsIContentParent::AllocPBrowserParent(co
   // We release this ref in DeallocPBrowserParent()
   NS_ADDREF(parent);
   return parent;
 }
 
 bool
 nsIContentParent::DeallocPBrowserParent(PBrowserParent* aFrame)
 {
-  TabParent* parent = static_cast<TabParent*>(aFrame);
+  TabParent* parent = TabParent::GetFrom(aFrame);
   NS_RELEASE(parent);
   return true;
 }
 
 PBlobParent*
 nsIContentParent::AllocPBlobParent(const BlobConstructorParams& aParams)
 {
   return BlobParent::Create(this, aParams);
--- a/dom/network/TCPServerSocketParent.cpp
+++ b/dom/network/TCPServerSocketParent.cpp
@@ -71,30 +71,30 @@ TCPServerSocketParent::Init(PNeckoParent
 
 uint32_t
 TCPServerSocketParent::GetAppId()
 {
   uint32_t appId = nsIScriptSecurityManager::UNKNOWN_APP_ID;
   const PContentParent *content = Manager()->Manager();
   const InfallibleTArray<PBrowserParent*>& browsers = content->ManagedPBrowserParent();
   if (browsers.Length() > 0) {
-    TabParent *tab = static_cast<TabParent*>(browsers[0]);
+    TabParent *tab = TabParent::GetFrom(browsers[0]);
     appId = tab->OwnAppId();
   }
   return appId;
 };
 
 bool
 TCPServerSocketParent::GetInBrowser()
 {
   bool inBrowser = false;
   const PContentParent *content = Manager()->Manager();
   const InfallibleTArray<PBrowserParent*>& browsers = content->ManagedPBrowserParent();
   if (browsers.Length() > 0) {
-    TabParent *tab = static_cast<TabParent*>(browsers[0]);
+    TabParent *tab = TabParent::GetFrom(browsers[0]);
     inBrowser = tab->IsBrowserElement();
   }
   return inBrowser;
 }
 
 NS_IMETHODIMP
 TCPServerSocketParent::SendCallbackAccept(nsITCPSocketParent *socket)
 {
--- a/dom/network/TCPSocketParent.cpp
+++ b/dom/network/TCPSocketParent.cpp
@@ -82,30 +82,30 @@ TCPSocketParentBase::~TCPSocketParentBas
 
 uint32_t
 TCPSocketParent::GetAppId()
 {
   uint32_t appId = nsIScriptSecurityManager::UNKNOWN_APP_ID;
   const PContentParent *content = Manager()->Manager();
   const InfallibleTArray<PBrowserParent*>& browsers = content->ManagedPBrowserParent();
   if (browsers.Length() > 0) {
-    TabParent *tab = static_cast<TabParent*>(browsers[0]);
+    TabParent *tab = TabParent::GetFrom(browsers[0]);
     appId = tab->OwnAppId();
   }
   return appId;
 };
 
 bool
 TCPSocketParent::GetInBrowser()
 {
   bool inBrowser = false;
   const PContentParent *content = Manager()->Manager();
   const InfallibleTArray<PBrowserParent*>& browsers = content->ManagedPBrowserParent();
   if (browsers.Length() > 0) {
-    TabParent *tab = static_cast<TabParent*>(browsers[0]);
+    TabParent *tab = TabParent::GetFrom(browsers[0]);
     inBrowser = tab->IsBrowserElement();
   }
   return inBrowser;
 }
 
 nsresult
 TCPSocketParent::OfflineNotification(nsISupports *aSubject)
 {
--- a/dom/network/UDPSocketParent.cpp
+++ b/dom/network/UDPSocketParent.cpp
@@ -64,17 +64,17 @@ UDPSocketParent::OfflineNotification(nsI
 
 uint32_t
 UDPSocketParent::GetAppId()
 {
   uint32_t appId = nsIScriptSecurityManager::UNKNOWN_APP_ID;
   const PContentParent *content = Manager()->Manager();
   const InfallibleTArray<PBrowserParent*>& browsers = content->ManagedPBrowserParent();
   if (browsers.Length() > 0) {
-    TabParent *tab = static_cast<TabParent*>(browsers[0]);
+    TabParent *tab = TabParent::GetFrom(browsers[0]);
     appId = tab->OwnAppId();
   }
   return appId;
 }
 
 bool
 UDPSocketParent::Init(const nsACString& aFilter)
 {
--- a/embedding/components/printingui/ipc/PrintingParent.cpp
+++ b/embedding/components/printingui/ipc/PrintingParent.cpp
@@ -138,17 +138,17 @@ PrintingParent::ActorDestroy(ActorDestro
 
 nsIDOMWindow*
 PrintingParent::DOMWindowFromBrowserParent(PBrowserParent* parent)
 {
   if (!parent) {
     return nullptr;
   }
 
-  TabParent* tabParent = static_cast<TabParent*>(parent);
+  TabParent* tabParent = TabParent::GetFrom(parent);
   if (!tabParent) {
     return nullptr;
   }
 
   nsCOMPtr<Element> frameElement = tabParent->GetOwnerElement();
   if (!frameElement) {
     return nullptr;
   }
--- a/hal/sandbox/SandboxHal.cpp
+++ b/hal/sandbox/SandboxHal.cpp
@@ -502,29 +502,29 @@ public:
   }
 
   virtual bool
   RecvVibrate(InfallibleTArray<unsigned int>&& pattern,
               InfallibleTArray<uint64_t>&& id,
               PBrowserParent *browserParent) MOZ_OVERRIDE
   {
     // We give all content vibration permission.
-    TabParent *tabParent = static_cast<TabParent*>(browserParent);
+    TabParent *tabParent = TabParent::GetFrom(browserParent);
     nsCOMPtr<nsIDOMWindow> window =
       do_QueryInterface(tabParent->GetBrowserDOMWindow());
     WindowIdentifier newID(id, window);
     hal::Vibrate(pattern, newID);
     return true;
   }
 
   virtual bool
   RecvCancelVibrate(InfallibleTArray<uint64_t> &&id,
                     PBrowserParent *browserParent) MOZ_OVERRIDE
   {
-    TabParent *tabParent = static_cast<TabParent*>(browserParent);
+    TabParent *tabParent = TabParent::GetFrom(browserParent);
     nsCOMPtr<nsIDOMWindow> window =
       do_QueryInterface(tabParent->GetBrowserDOMWindow());
     WindowIdentifier newID(id, window);
     hal::CancelVibrate(newID);
     return true;
   }
 
   virtual bool
--- a/layout/ipc/RenderFrameParent.cpp
+++ b/layout/ipc/RenderFrameParent.cpp
@@ -87,17 +87,17 @@ public:
     , mRenderFrame(aRenderFrame)
     , mHaveZoomConstraints(false)
   { }
 
   virtual void RequestContentRepaint(const FrameMetrics& aFrameMetrics) MOZ_OVERRIDE
   {
     MOZ_ASSERT(NS_IsMainThread());
     if (mRenderFrame) {
-      TabParent* browser = static_cast<TabParent*>(mRenderFrame->Manager());
+      TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
       browser->UpdateFrame(aFrameMetrics);
     }
   }
 
   virtual void AcknowledgeScrollUpdate(const FrameMetrics::ViewID& aScrollId,
                                        const uint32_t& aScrollGeneration) MOZ_OVERRIDE
   {
     if (MessageLoop::current() != mUILoop) {
@@ -105,17 +105,17 @@ public:
       // thread).
       mUILoop->PostTask(
         FROM_HERE,
         NewRunnableMethod(this, &RemoteContentController::AcknowledgeScrollUpdate,
                           aScrollId, aScrollGeneration));
       return;
     }
     if (mRenderFrame) {
-      TabParent* browser = static_cast<TabParent*>(mRenderFrame->Manager());
+      TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
       browser->AcknowledgeScrollUpdate(aScrollId, aScrollGeneration);
     }
   }
 
   virtual void HandleDoubleTap(const CSSPoint& aPoint,
                                int32_t aModifiers,
                                const ScrollableLayerGuid& aGuid) MOZ_OVERRIDE
   {
@@ -124,17 +124,17 @@ public:
       // thread).
       mUILoop->PostTask(
         FROM_HERE,
         NewRunnableMethod(this, &RemoteContentController::HandleDoubleTap,
                           aPoint, aModifiers, aGuid));
       return;
     }
     if (mRenderFrame) {
-      TabParent* browser = static_cast<TabParent*>(mRenderFrame->Manager());
+      TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
       browser->HandleDoubleTap(aPoint, aModifiers, aGuid);
     }
   }
 
   virtual void HandleSingleTap(const CSSPoint& aPoint,
                                int32_t aModifiers,
                                const ScrollableLayerGuid& aGuid) MOZ_OVERRIDE
   {
@@ -143,17 +143,17 @@ public:
       // thread).
       mUILoop->PostTask(
         FROM_HERE,
         NewRunnableMethod(this, &RemoteContentController::HandleSingleTap,
                           aPoint, aModifiers, aGuid));
       return;
     }
     if (mRenderFrame) {
-      TabParent* browser = static_cast<TabParent*>(mRenderFrame->Manager());
+      TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
       browser->HandleSingleTap(aPoint, aModifiers, aGuid);
     }
   }
 
   virtual void HandleLongTap(const CSSPoint& aPoint,
                              int32_t aModifiers,
                              const ScrollableLayerGuid& aGuid,
                              uint64_t aInputBlockId) MOZ_OVERRIDE
@@ -163,17 +163,17 @@ public:
       // thread).
       mUILoop->PostTask(
         FROM_HERE,
         NewRunnableMethod(this, &RemoteContentController::HandleLongTap,
                           aPoint, aModifiers, aGuid, aInputBlockId));
       return;
     }
     if (mRenderFrame) {
-      TabParent* browser = static_cast<TabParent*>(mRenderFrame->Manager());
+      TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
       browser->HandleLongTap(aPoint, aModifiers, aGuid, aInputBlockId);
     }
   }
 
   virtual void HandleLongTapUp(const CSSPoint& aPoint,
                                int32_t aModifiers,
                                const ScrollableLayerGuid& aGuid) MOZ_OVERRIDE
   {
@@ -182,17 +182,17 @@ public:
       // thread).
       mUILoop->PostTask(
         FROM_HERE,
         NewRunnableMethod(this, &RemoteContentController::HandleLongTapUp,
                           aPoint, aModifiers, aGuid));
       return;
     }
     if (mRenderFrame) {
-      TabParent* browser = static_cast<TabParent*>(mRenderFrame->Manager());
+      TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
       browser->HandleLongTapUp(aPoint, aModifiers, aGuid);
     }
   }
 
   void ClearRenderFrame() { mRenderFrame = nullptr; }
 
   virtual void SendAsyncScrollDOMEvent(bool aIsRoot,
                                        const CSSRect& aContentRect,
@@ -202,17 +202,17 @@ public:
       mUILoop->PostTask(
         FROM_HERE,
         NewRunnableMethod(this,
                           &RemoteContentController::SendAsyncScrollDOMEvent,
                           aIsRoot, aContentRect, aContentSize));
       return;
     }
     if (mRenderFrame && aIsRoot) {
-      TabParent* browser = static_cast<TabParent*>(mRenderFrame->Manager());
+      TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
       BrowserElementParent::DispatchAsyncScrollEvent(browser, aContentRect,
                                                      aContentSize);
     }
   }
 
   virtual void PostDelayedTask(Task* aTask, int aDelayMs) MOZ_OVERRIDE
   {
     MessageLoop::current()->PostDelayedTask(FROM_HERE, aTask, aDelayMs);
@@ -242,17 +242,17 @@ public:
     if (MessageLoop::current() != mUILoop) {
       mUILoop->PostTask(
         FROM_HERE,
         NewRunnableMethod(this, &RemoteContentController::NotifyAPZStateChange,
                           aGuid, aChange, aArg));
       return;
     }
     if (mRenderFrame) {
-      TabParent* browser = static_cast<TabParent*>(mRenderFrame->Manager());
+      TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
       browser->NotifyAPZStateChange(aGuid.mScrollId, aChange, aArg);
     }
   }
 
   // Methods used by RenderFrameParent to set fields stored here.
 
   void SaveZoomConstraints(const ZoomConstraints& aConstraints)
   {
--- a/netwerk/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -177,17 +177,17 @@ NeckoParent::CreateChannelLoadContext(co
 
   // if !UsingNeckoIPCSecurity(), we may not have a LoadContext to set. This is
   // the common case for most xpcshell tests.
   if (aSerialized.IsNotNull()) {
     switch (aBrowser.type()) {
       case PBrowserOrId::TPBrowserParent:
       {
         nsRefPtr<TabParent> tabParent =
-          static_cast<TabParent*>(aBrowser.get_PBrowserParent());
+          TabParent::GetFrom(aBrowser.get_PBrowserParent());
         dom::Element* topFrameElement = nullptr;
         if (tabParent) {
           topFrameElement = tabParent->GetOwnerElement();
         }
         aResult = new LoadContext(aSerialized, topFrameElement,
                                   appId, inBrowser);
         break;
       }
@@ -327,17 +327,17 @@ NeckoParent::AllocPWebSocketParent(const
                                                serialized, loadContext);
   if (error) {
     printf_stderr("NeckoParent::AllocPWebSocketParent: "
                   "FATAL error: %s: KILLING CHILD PROCESS\n",
                   error);
     return nullptr;
   }
 
-  nsRefPtr<TabParent> tabParent = static_cast<TabParent*>(browser.get_PBrowserParent());
+  nsRefPtr<TabParent> tabParent = TabParent::GetFrom(browser.get_PBrowserParent());
   PBOverrideStatus overrideStatus = PBOverrideStatusFromLoadContext(serialized);
   WebSocketChannelParent* p = new WebSocketChannelParent(tabParent, loadContext,
                                                          overrideStatus);
   p->AddRef();
   return p;
 }
 
 bool
--- a/uriloader/exthandler/ExternalHelperAppParent.cpp
+++ b/uriloader/exthandler/ExternalHelperAppParent.cpp
@@ -76,17 +76,17 @@ ExternalHelperAppParent::Init(ContentPar
   }
   else {
     mContentDisposition = aContentDispositionHint;
     mContentDispositionFilename = aContentDispositionFilename;
   }
 
   nsCOMPtr<nsIInterfaceRequestor> window;
   if (aBrowser) {
-    TabParent* tabParent = static_cast<TabParent*>(aBrowser);
+    TabParent* tabParent = TabParent::GetFrom(aBrowser);
     if (tabParent->GetOwnerElement())
       window = do_QueryInterface(tabParent->GetOwnerElement()->OwnerDoc()->GetWindow());
   }
 
   helperAppService->DoContent(aMimeContentType, this, window,
                               aForceSave, nullptr,
                               getter_AddRefs(mListener));
 }