Backed out changeset cdb510ae73f7 (bug 1189195) for bustage
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Tue, 19 Jan 2016 11:55:11 +0100
changeset 292580 ea1b75e4b851d242182ef0c8a1ade5eb38b2c00f
parent 292579 e8ce75470b3c2210fe8fc74dd5736a503abde06c
child 292581 be1ec31308366db734d15a04db7c4b4697515b20
push id272
push usercbook@mozilla.com
push dateTue, 19 Jan 2016 10:55:34 +0000
bugs1189195
milestone44.0
backs outcdb510ae73f792b363e7d246410b925d1330f32d
Backed out changeset cdb510ae73f7 (bug 1189195) for bustage
dom/base/nsContentPermissionHelper.cpp
dom/base/nsContentPermissionHelper.h
dom/ipc/ContentChild.cpp
dom/ipc/ContentParent.cpp
dom/ipc/PContentPermissionRequest.ipdl
dom/ipc/TabChild.cpp
--- a/dom/base/nsContentPermissionHelper.cpp
+++ b/dom/base/nsContentPermissionHelper.cpp
@@ -121,17 +121,16 @@ class ContentPermissionRequestParent : p
   nsCOMPtr<nsIPrincipal> mPrincipal;
   nsCOMPtr<Element> mElement;
   RefPtr<nsContentPermissionRequestProxy> mProxy;
   nsTArray<PermissionRequest> mRequests;
 
  private:
   virtual bool Recvprompt();
   virtual bool RecvNotifyVisibility(const bool& aIsVisible);
-  virtual bool RecvDestroy();
   virtual void ActorDestroy(ActorDestroyReason why);
 };
 
 ContentPermissionRequestParent::ContentPermissionRequestParent(const nsTArray<PermissionRequest>& aRequests,
                                                                Element* aElement,
                                                                const IPC::Principal& aPrincipal)
 {
   MOZ_COUNT_CTOR(ContentPermissionRequestParent);
@@ -162,23 +161,16 @@ ContentPermissionRequestParent::RecvNoti
 {
   if (!mProxy) {
     return false;
   }
   mProxy->NotifyVisibility(aIsVisible);
   return true;
 }
 
-bool
-ContentPermissionRequestParent::RecvDestroy()
-{
-  Unused << PContentPermissionRequestParent::Send__delete__(this);
-  return true;
-}
-
 void
 ContentPermissionRequestParent::ActorDestroy(ActorDestroyReason why)
 {
   if (mProxy) {
     mProxy->OnParentDestroyed();
   }
 }
 
@@ -303,24 +295,16 @@ nsContentPermissionUtils::ConvertArrayTo
 static std::map<PContentPermissionRequestParent*, TabId>&
 ContentPermissionRequestParentMap()
 {
   MOZ_ASSERT(NS_IsMainThread());
   static std::map<PContentPermissionRequestParent*, TabId> sPermissionRequestParentMap;
   return sPermissionRequestParentMap;
 }
 
-static std::map<PContentPermissionRequestChild*, TabId>&
-ContentPermissionRequestChildMap()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  static std::map<PContentPermissionRequestChild*, TabId> sPermissionRequestChildMap;
-  return sPermissionRequestChildMap;
-}
-
 /* static */ nsresult
 nsContentPermissionUtils::CreatePermissionArray(const nsACString& aType,
                                                 const nsACString& aAccess,
                                                 const nsTArray<nsString>& aOptions,
                                                 nsIArray** aTypesArray)
 {
   nsCOMPtr<nsIMutableArray> types = do_CreateInstance(NS_ARRAY_CONTRACTID);
   RefPtr<ContentPermissionType> permType = new ContentPermissionType(aType,
@@ -374,17 +358,16 @@ nsContentPermissionUtils::AskPermission(
     NS_ENSURE_SUCCESS(rv, rv);
 
     req->IPDLAddRef();
     ContentChild::GetSingleton()->SendPContentPermissionRequestConstructor(
       req,
       permArray,
       IPC::Principal(principal),
       child->GetTabId());
-    ContentPermissionRequestChildMap()[req.get()] = child->GetTabId();
 
     req->Sendprompt();
     return NS_OK;
   }
 
   // for chrome process
   nsCOMPtr<nsIContentPermissionPrompt> prompt =
     do_GetService(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID);
@@ -414,39 +397,16 @@ nsContentPermissionUtils::NotifyRemoveCo
   PContentPermissionRequestParent* aParent)
 {
   auto it = ContentPermissionRequestParentMap().find(aParent);
   MOZ_ASSERT(it != ContentPermissionRequestParentMap().end());
 
   ContentPermissionRequestParentMap().erase(it);
 }
 
-/* static */ nsTArray<PContentPermissionRequestChild*>
-nsContentPermissionUtils::GetContentPermissionRequestChildById(const TabId& aTabId)
-{
-  nsTArray<PContentPermissionRequestChild*> childArray;
-  for (auto& it : ContentPermissionRequestChildMap()) {
-    if (it.second == aTabId) {
-      childArray.AppendElement(it.first);
-    }
-  }
-
-  return Move(childArray);
-}
-
-/* static */ void
-nsContentPermissionUtils::NotifyRemoveContentPermissionRequestChild(
-  PContentPermissionRequestChild* aChild)
-{
-  auto it = ContentPermissionRequestChildMap().find(aChild);
-  MOZ_ASSERT(it != ContentPermissionRequestChildMap().end());
-
-  ContentPermissionRequestChildMap().erase(it);
-}
-
 NS_IMPL_ISUPPORTS(nsContentPermissionRequester, nsIContentPermissionRequester)
 
 nsContentPermissionRequester::nsContentPermissionRequester(nsPIDOMWindow* aWindow)
   : mWindow(aWindow)
 {
   mListener = new VisibilityChangeListener(mWindow);
 }
 
@@ -643,17 +603,17 @@ nsContentPermissionRequestProxy::Cancel(
   // Don't send out the delete message when the managing protocol (PBrowser) is
   // being destroyed and PContentPermissionRequest will soon be.
   if (mParent->IsBeingDestroyed()) {
     return NS_ERROR_FAILURE;
   }
 
   nsTArray<PermissionChoice> emptyChoices;
 
-  Unused << mParent->SendNotifyResult(false, emptyChoices);
+  unused << ContentPermissionRequestParent::Send__delete__(mParent, false, emptyChoices);
   mParent = nullptr;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsContentPermissionRequestProxy::Allow(JS::HandleValue aChoices)
 {
   if (mParent == nullptr) {
@@ -707,17 +667,17 @@ nsContentPermissionRequestProxy::Allow(J
         choices.AppendElement(PermissionChoice(type, choice));
       }
     }
   } else {
     MOZ_ASSERT(false, "SelectedChoices should be undefined or an JS object");
     return NS_ERROR_FAILURE;
   }
 
-  Unused << mParent->SendNotifyResult(true, choices);
+  unused << ContentPermissionRequestParent::Send__delete__(mParent, true, choices);
   mParent = nullptr;
   return NS_OK;
 }
 
 void
 nsContentPermissionRequestProxy::NotifyVisibility(const bool& aIsVisible)
 {
   MOZ_ASSERT(mRequester);
@@ -740,17 +700,16 @@ nsContentPermissionRequestProxy::GetRequ
 NS_IMPL_ISUPPORTS(RemotePermissionRequest, nsIContentPermissionRequestCallback);
 
 RemotePermissionRequest::RemotePermissionRequest(
   nsIContentPermissionRequest* aRequest,
   nsPIDOMWindow* aWindow)
   : mRequest(aRequest)
   , mWindow(aWindow)
   , mIPCOpen(false)
-  , mDestroyed(false)
 {
   mListener = new VisibilityChangeListener(mWindow);
   mListener->SetCallback(this);
 }
 
 void
 RemotePermissionRequest::DoCancel()
 {
@@ -762,20 +721,21 @@ void
 RemotePermissionRequest::DoAllow(JS::HandleValue aChoices)
 {
   NS_ASSERTION(mRequest, "We need a request");
   mRequest->Allow(aChoices);
 }
 
 // PContentPermissionRequestChild
 bool
-RemotePermissionRequest::RecvNotifyResult(const bool& aAllow,
-                                          InfallibleTArray<PermissionChoice>&& aChoices)
+RemotePermissionRequest::Recv__delete__(const bool& aAllow,
+                                        InfallibleTArray<PermissionChoice>&& aChoices)
 {
-  Destroy();
+  mListener->RemoveListener();
+  mListener = nullptr;
 
   if (aAllow && mWindow->IsCurrentInnerWindow()) {
     // Use 'undefined' if no choice is provided.
     if (aChoices.IsEmpty()) {
       DoAllow(JS::UndefinedHandleValue);
       return true;
     }
 
@@ -815,30 +775,18 @@ RemotePermissionRequest::RecvGetVisibili
   }
 
   bool isActive = false;
   docshell->GetIsActive(&isActive);
   unused << SendNotifyVisibility(isActive);
   return true;
 }
 
-void
-RemotePermissionRequest::Destroy()
-{
-  if (!IPCOpen()) {
-    return;
-  }
-  Unused << this->SendDestroy();
-  mListener->RemoveListener();
-  mListener = nullptr;
-  mDestroyed = true;
-}
-
 NS_IMETHODIMP
 RemotePermissionRequest::NotifyVisibility(bool isVisible)
 {
-  if (!IPCOpen()) {
+  if (!mIPCOpen) {
     return NS_OK;
   }
 
   unused << SendNotifyVisibility(isVisible);
   return NS_OK;
 }
--- a/dom/base/nsContentPermissionHelper.h
+++ b/dom/base/nsContentPermissionHelper.h
@@ -103,22 +103,16 @@ public:
   static nsresult
   AskPermission(nsIContentPermissionRequest* aRequest, nsPIDOMWindow* aWindow);
 
   static nsTArray<PContentPermissionRequestParent*>
   GetContentPermissionRequestParentById(const TabId& aTabId);
 
   static void
   NotifyRemoveContentPermissionRequestParent(PContentPermissionRequestParent* aParent);
-
-  static nsTArray<PContentPermissionRequestChild*>
-  GetContentPermissionRequestChildById(const TabId& aTabId);
-
-  static void
-  NotifyRemoveContentPermissionRequestChild(PContentPermissionRequestChild* aChild);
 };
 
 class nsContentPermissionRequester final : public nsIContentPermissionRequester
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSICONTENTPERMISSIONREQUESTER
 
@@ -189,47 +183,42 @@ class RemotePermissionRequest final : pu
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSICONTENTPERMISSIONREQUESTCALLBACK
 
   RemotePermissionRequest(nsIContentPermissionRequest* aRequest,
                           nsPIDOMWindow* aWindow);
 
   // It will be called when prompt dismissed.
-  virtual bool RecvNotifyResult(const bool &aAllow,
-                                InfallibleTArray<PermissionChoice>&& aChoices) override;
+  virtual bool Recv__delete__(const bool &aAllow,
+                              InfallibleTArray<PermissionChoice>&& aChoices) override;
 
   virtual bool RecvGetVisibility() override;
 
   void IPDLAddRef()
   {
     mIPCOpen = true;
     AddRef();
   }
 
   void IPDLRelease()
   {
     mIPCOpen = false;
     Release();
   }
 
-  void Destroy();
-
-  bool IPCOpen() const { return mIPCOpen && !mDestroyed; }
-
 private:
   virtual ~RemotePermissionRequest()
   {
     MOZ_ASSERT(!mIPCOpen, "Protocol must not be open when RemotePermissionRequest is destroyed.");
   }
 
   void DoAllow(JS::HandleValue aChoices);
   void DoCancel();
 
   nsCOMPtr<nsIContentPermissionRequest> mRequest;
   nsCOMPtr<nsPIDOMWindow>               mWindow;
   bool                                  mIPCOpen;
-  bool                                  mDestroyed;
   RefPtr<VisibilityChangeListener>    mListener;
 };
 
 #endif // nsContentPermissionHelper_h
 
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -2956,17 +2956,16 @@ ContentChild::AllocPContentPermissionReq
 {
     NS_RUNTIMEABORT("unused");
     return nullptr;
 }
 
 bool
 ContentChild::DeallocPContentPermissionRequestChild(PContentPermissionRequestChild* actor)
 {
-    nsContentPermissionUtils::NotifyRemoveContentPermissionRequestChild(actor);
     auto child = static_cast<RemotePermissionRequest*>(actor);
     child->IPDLRelease();
     return true;
 }
 
 PWebBrowserPersistDocumentChild*
 ContentChild::AllocPWebBrowserPersistDocumentChild(PBrowserChild* aBrowser,
                                                    const uint64_t& aOuterWindowID)
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -2245,17 +2245,20 @@ ContentParent::NotifyTabDestroyed(const 
         --mNumDestroyingTabs;
     }
 
     nsTArray<PContentPermissionRequestParent*> parentArray =
         nsContentPermissionUtils::GetContentPermissionRequestParentById(aTabId);
 
     // Need to close undeleted ContentPermissionRequestParents before tab is closed.
     for (auto& permissionRequestParent : parentArray) {
-        Unused << PContentPermissionRequestParent::Send__delete__(permissionRequestParent);
+        nsTArray<PermissionChoice> emptyChoices;
+        unused << PContentPermissionRequestParent::Send__delete__(permissionRequestParent,
+                                                                  false,
+                                                                  emptyChoices);
     }
 
     // There can be more than one PBrowser for a given app process
     // because of popup windows.  When the last one closes, shut
     // us down.
     ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
     nsTArray<TabId> tabIds = cpm->GetTabParentsByProcessId(this->ChildID());
     if (tabIds.Length() == 1) {
--- a/dom/ipc/PContentPermissionRequest.ipdl
+++ b/dom/ipc/PContentPermissionRequest.ipdl
@@ -10,19 +10,17 @@ namespace dom {
 
 protocol PContentPermissionRequest
 {
   manager PContent;
 
 parent:
   prompt();
   NotifyVisibility(bool visibility);
-  Destroy();
 
 child:
   GetVisibility();
-  NotifyResult(bool allow, PermissionChoice[] choices);
-  __delete__();
+  __delete__(bool allow, PermissionChoice[] choices);
 };
 
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -91,17 +91,16 @@
 #include "ipc/nsGUIEventIPC.h"
 #include "mozilla/gfx/Matrix.h"
 #include "UnitTransforms.h"
 #include "ClientLayerManager.h"
 #include "LayersLogging.h"
 #include "nsIOService.h"
 #include "nsDOMClassInfoID.h"
 #include "nsColorPickerProxy.h"
-#include "nsContentPermissionHelper.h"
 #include "nsPresShell.h"
 #include "nsIAppsService.h"
 #include "nsNetUtil.h"
 #include "nsIPermissionManager.h"
 #include "nsIScriptError.h"
 #include "mozilla/EventForwards.h"
 #include "nsDeviceContext.h"
 
@@ -2266,16 +2265,17 @@ TabChild::AllocPIndexedDBPermissionReque
             "manually!");
 }
 
 bool
 TabChild::DeallocPIndexedDBPermissionRequestChild(
                                        PIndexedDBPermissionRequestChild* aActor)
 {
   MOZ_ASSERT(aActor);
+
   delete aActor;
   return true;
 }
 
 bool
 TabChild::RecvActivateFrameEvent(const nsString& aType, const bool& capture)
 {
   nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(WebNavigation());
@@ -2377,25 +2377,16 @@ TabChild::RecvHandleAccessKey(nsTArray<u
 }
 
 bool
 TabChild::RecvDestroy()
 {
   MOZ_ASSERT(mDestroyed == false);
   mDestroyed = true;
 
-  nsTArray<PContentPermissionRequestChild*> childArray =
-      nsContentPermissionUtils::GetContentPermissionRequestChildById(GetTabId());
-
-  // Need to close undeleted ContentPermissionRequestChilds before tab is closed.
-  for (auto& permissionRequestChild : childArray) {
-      auto child = static_cast<RemotePermissionRequest*>(permissionRequestChild);
-      child->Destroy();
-  }
-
   while (mActiveSuppressDisplayport > 0) {
     APZCCallbackHelper::SuppressDisplayport(false);
     mActiveSuppressDisplayport--;
   }
 
   if (mTabChildGlobal) {
     // Message handlers are called from the event loop, so it better be safe to
     // run script.