Backed out changeset 7ee1772ffc10 (bug 1105827)
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Tue, 11 Aug 2015 10:04:35 -0700
changeset 284595 7b6f60b570c212adbefff135e9a8308280174359
parent 284594 44204bf72cbfda72113fe91e017fface0d029170
child 284596 2ec72d95fe874f4c72375ca61eb008ede8f09c09
push id4313
push useralwu@mozilla.com
push dateWed, 12 Aug 2015 06:36:08 +0000
bugs1105827
milestone43.0a1
backs out7ee1772ffc10ba685e52e9c4c4d6a3dc419dec8d
Backed out changeset 7ee1772ffc10 (bug 1105827)
dom/permission/PermissionObserver.cpp
dom/permission/PermissionObserver.h
dom/permission/PermissionStatus.cpp
dom/permission/PermissionStatus.h
dom/permission/moz.build
deleted file mode 100644
--- a/dom/permission/PermissionObserver.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "PermissionObserver.h"
-
-#include "mozilla/dom/PermissionStatus.h"
-#include "mozilla/Services.h"
-#include "mozilla/UniquePtr.h"
-#include "nsIObserverService.h"
-#include "nsIPermission.h"
-#include "PermissionUtils.h"
-
-namespace mozilla {
-namespace dom {
-
-namespace {
-PermissionObserver* gInstance = nullptr;
-} // namespace
-
-NS_IMPL_ISUPPORTS(PermissionObserver,
-                  nsIObserver,
-                  nsISupportsWeakReference)
-
-PermissionObserver::PermissionObserver()
-{
-  MOZ_ASSERT(!gInstance);
-}
-
-PermissionObserver::~PermissionObserver()
-{
-  MOZ_ASSERT(mSinks.IsEmpty());
-  MOZ_ASSERT(gInstance == this);
-
-  gInstance = nullptr;
-}
-
-/* static */ already_AddRefed<PermissionObserver>
-PermissionObserver::GetInstance()
-{
-  nsRefPtr<PermissionObserver> instance = gInstance;
-  if (!instance) {
-    instance = new PermissionObserver();
-
-    nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-    if (NS_WARN_IF(!obs)) {
-      return nullptr;
-    }
-
-    nsresult rv = obs->AddObserver(instance, "perm-changed", true);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return nullptr;
-    }
-
-    gInstance = instance;
-  }
-
-  return instance.forget();
-}
-
-void
-PermissionObserver::AddSink(PermissionStatus* aSink)
-{
-  MOZ_ASSERT(aSink);
-  MOZ_ASSERT(!mSinks.Contains(aSink));
-
-  mSinks.AppendElement(aSink);
-}
-
-void
-PermissionObserver::RemoveSink(PermissionStatus* aSink)
-{
-  MOZ_ASSERT(aSink);
-  MOZ_ASSERT(mSinks.Contains(aSink));
-
-  mSinks.RemoveElement(aSink);
-}
-
-void
-PermissionObserver::Notify(PermissionName aName, nsIPrincipal& aPrincipal)
-{
-  for (auto* sink : mSinks) {
-    if (sink->mName != aName) {
-      continue;
-    }
-
-    nsIPrincipal* sinkPrincipal = sink->GetPrincipal();
-    if (NS_WARN_IF(!sinkPrincipal) || !aPrincipal.Equals(sinkPrincipal)) {
-      continue;
-    }
-
-    sink->PermissionChanged();
-  }
-}
-
-NS_IMETHODIMP
-PermissionObserver::Observe(nsISupports* aSubject,
-                            const char* aTopic,
-                            const char16_t* aData)
-{
-  MOZ_ASSERT(!strcmp(aTopic, "perm-changed"));
-
-  if (mSinks.IsEmpty()) {
-    return NS_OK;
-  }
-
-  nsCOMPtr<nsIPermission> perm = do_QueryInterface(aSubject);
-  if (!perm) {
-    return NS_OK;
-  }
-
-  nsCOMPtr<nsIPrincipal> principal;
-  perm->GetPrincipal(getter_AddRefs(principal));
-  if (!principal) {
-    return NS_OK;
-  }
-
-  nsAutoCString type;
-  perm->GetType(type);
-  Maybe<PermissionName> permission = TypeToPermissionName(type.get());
-  if (permission) {
-    Notify(permission.value(), *principal);
-  }
-
-  return NS_OK;
-}
-
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/permission/PermissionObserver.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_PermissionObserver_h_
-#define mozilla_dom_PermissionObserver_h_
-
-#include "mozilla/dom/PermissionsBinding.h"
-
-#include "nsIObserver.h"
-#include "nsIPrincipal.h"
-#include "nsTArray.h"
-#include "nsWeakReference.h"
-
-namespace mozilla {
-namespace dom {
-
-class PermissionStatus;
-
-// Singleton that watches for perm-changed notifications in order to notify
-// PermissionStatus objects.
-class PermissionObserver final
-  : public nsIObserver
-  , public nsSupportsWeakReference
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIOBSERVER
-
-  static already_AddRefed<PermissionObserver> GetInstance();
-
-  void AddSink(PermissionStatus* aObs);
-  void RemoveSink(PermissionStatus* aObs);
-
-private:
-  PermissionObserver();
-  virtual ~PermissionObserver();
-
-  void Notify(PermissionName aName, nsIPrincipal& aPrincipal);
-
-  nsTArray<PermissionStatus*> mSinks;
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif
--- a/dom/permission/PermissionStatus.cpp
+++ b/dom/permission/PermissionStatus.cpp
@@ -4,71 +4,49 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/PermissionStatus.h"
 
 #include "mozilla/Services.h"
 #include "mozilla/UniquePtr.h"
 #include "nsIPermissionManager.h"
-#include "PermissionObserver.h"
 #include "PermissionUtils.h"
 
 namespace mozilla {
 namespace dom {
 
 /* static */ nsresult
 PermissionStatus::Create(nsPIDOMWindow* aWindow,
                          PermissionName aName,
                          PermissionStatus** aStatus)
 {
   MOZ_ASSERT(aStatus);
   *aStatus = nullptr;
 
   UniquePtr<PermissionStatus> status(new PermissionStatus(aWindow, aName));
-  nsresult rv = status->Init();
+  nsresult rv = status->UpdateState();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   *aStatus = status.release();
   return NS_OK;
 }
 
 PermissionStatus::PermissionStatus(nsPIDOMWindow* aWindow,
                                    PermissionName aName)
   : DOMEventTargetHelper(aWindow)
   , mName(aName)
   , mState(PermissionState::Denied)
 {
 }
 
-nsresult
-PermissionStatus::Init()
-{
-  mObserver = PermissionObserver::GetInstance();
-  if (NS_WARN_IF(!mObserver)) {
-    return NS_ERROR_FAILURE;
-  }
-
-  mObserver->AddSink(this);
-
-  nsresult rv = UpdateState();
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
 PermissionStatus::~PermissionStatus()
 {
-  if (mObserver) {
-    mObserver->RemoveSink(this);
-  }
 }
 
 JSObject*
 PermissionStatus::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return PermissionStatusBinding::Wrap(aCx, this, aGivenProto);
 }
 
@@ -92,26 +70,10 @@ PermissionStatus::UpdateState()
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   mState = ActionToPermissionState(action);
   return NS_OK;
 }
 
-nsIPrincipal*
-PermissionStatus::GetPrincipal() const
-{
-  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(GetOwner());
-  if (NS_WARN_IF(!window)) {
-    return nullptr;
-  }
-
-  nsIDocument* doc = window->GetExtantDoc();
-  if (NS_WARN_IF(!doc)) {
-    return nullptr;
-  }
-
-  return doc->NodePrincipal();
-}
-
 } // namespace dom
 } // namespace mozilla
--- a/dom/permission/PermissionStatus.h
+++ b/dom/permission/PermissionStatus.h
@@ -9,23 +9,19 @@
 
 #include "mozilla/dom/PermissionsBinding.h"
 #include "mozilla/dom/PermissionStatusBinding.h"
 #include "mozilla/DOMEventTargetHelper.h"
 
 namespace mozilla {
 namespace dom {
 
-class PermissionObserver;
-
 class PermissionStatus final
   : public DOMEventTargetHelper
 {
-  friend class PermissionObserver;
-
 public:
   ~PermissionStatus();
 
   static nsresult Create(nsPIDOMWindow* aWindow,
                          PermissionName aName,
                          PermissionStatus** aStatus);
 
   JSObject* WrapObject(JSContext* aCx,
@@ -33,26 +29,18 @@ public:
 
   PermissionState State() const { return mState; }
 
   IMPL_EVENT_HANDLER(change)
 
 private:
   PermissionStatus(nsPIDOMWindow* aWindow, PermissionName aName);
 
-  nsresult Init();
-
   nsresult UpdateState();
 
-  nsIPrincipal* GetPrincipal() const;
-
-  void PermissionChanged() {}
-
   PermissionName mName;
   PermissionState mState;
-
-  nsRefPtr<PermissionObserver> mObserver;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_permissionstatus_h_
--- a/dom/permission/moz.build
+++ b/dom/permission/moz.build
@@ -5,17 +5,16 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXPORTS.mozilla.dom += [
     'Permissions.h',
     'PermissionStatus.h',
 ]
 
 UNIFIED_SOURCES += [
-    'PermissionObserver.cpp',
     'Permissions.cpp',
     'PermissionStatus.cpp',
     'PermissionUtils.cpp',
 ]
 
 EXTRA_COMPONENTS += [
     'PermissionPromptService.js',
     'PermissionPromptService.manifest',